xref: /llvm-project/llvm/test/ThinLTO/AArch64/cgdata-merge-write.ll (revision d23c5c2d6566fce4380cfa31d438422db19fbce9)
1*d23c5c2dSKyungwoo Lee; This test verifies whether a stable function is encoded into the __llvm_merge section
2*d23c5c2dSKyungwoo Lee; when the -codegen-data-generate flag is used under -enable-global-merge-func=true.
3*d23c5c2dSKyungwoo Lee
4*d23c5c2dSKyungwoo Lee; RUN: rm -rf %t; split-file %s %t
5*d23c5c2dSKyungwoo Lee
6*d23c5c2dSKyungwoo Lee; RUN: opt -module-summary -module-hash %t/foo.ll -o %t-foo.bc
7*d23c5c2dSKyungwoo Lee; RUN: opt -module-summary -module-hash %t/goo.ll -o %t-goo.bc
8*d23c5c2dSKyungwoo Lee
9*d23c5c2dSKyungwoo Lee; RUN: llvm-lto2 run -enable-global-merge-func=true -codegen-data-generate=false %t-foo.bc %t-goo.bc -o %tout-nowrite \
10*d23c5c2dSKyungwoo Lee; RUN:    -r %t-foo.bc,_f1,px \
11*d23c5c2dSKyungwoo Lee; RUN:    -r %t-goo.bc,_f2,px \
12*d23c5c2dSKyungwoo Lee; RUN:    -r %t-foo.bc,_g,l -r %t-foo.bc,_g1,l -r %t-foo.bc,_g2,l \
13*d23c5c2dSKyungwoo Lee; RUN:    -r %t-goo.bc,_g,l -r %t-goo.bc,_g1,l -r %t-goo.bc,_g2,l
14*d23c5c2dSKyungwoo Lee; RUN: llvm-nm %tout-nowrite.1 | FileCheck %s --check-prefix=NOWRITE
15*d23c5c2dSKyungwoo Lee; RUN: llvm-nm %tout-nowrite.2 | FileCheck %s --check-prefix=NOWRITE
16*d23c5c2dSKyungwoo Lee
17*d23c5c2dSKyungwoo Lee; No merge instance is locally created as each module has a singltone function.
18*d23c5c2dSKyungwoo Lee; NOWRITE-NOT: _f1.Tgm
19*d23c5c2dSKyungwoo Lee; NOWRITE-NOT: _f2.Tgm
20*d23c5c2dSKyungwoo Lee
21*d23c5c2dSKyungwoo Lee; RUN: llvm-lto2 run -enable-global-merge-func=true -codegen-data-generate=true %t-foo.bc %t-goo.bc -o %tout-nowrite \
22*d23c5c2dSKyungwoo Lee; RUN:    -r %t-foo.bc,_f1,px \
23*d23c5c2dSKyungwoo Lee; RUN:    -r %t-goo.bc,_f2,px \
24*d23c5c2dSKyungwoo Lee; RUN:    -r %t-foo.bc,_g,l -r %t-foo.bc,_g1,l -r %t-foo.bc,_g2,l \
25*d23c5c2dSKyungwoo Lee; RUN:    -r %t-goo.bc,_g,l -r %t-goo.bc,_g1,l -r %t-goo.bc,_g2,l
26*d23c5c2dSKyungwoo Lee; RUN: llvm-nm %tout-nowrite.1 | FileCheck %s --check-prefix=WRITE
27*d23c5c2dSKyungwoo Lee; RUN: llvm-nm %tout-nowrite.2 | FileCheck %s --check-prefix=WRITE
28*d23c5c2dSKyungwoo Lee; RUN: llvm-objdump -h %tout-nowrite.1 | FileCheck %s --check-prefix=SECTNAME
29*d23c5c2dSKyungwoo Lee; RUN: llvm-objdump -h %tout-nowrite.2 | FileCheck %s --check-prefix=SECTNAME
30*d23c5c2dSKyungwoo Lee
31*d23c5c2dSKyungwoo Lee; On a write mode, no merging happens yet for each module.
32*d23c5c2dSKyungwoo Lee; We only create stable functions and publish them into __llvm_merge section for each object.
33*d23c5c2dSKyungwoo Lee; WRITE-NOT: _f1.Tgm
34*d23c5c2dSKyungwoo Lee; WRITE-NOT: _f2.Tgm
35*d23c5c2dSKyungwoo Lee; SECTNAME: __llvm_merge
36*d23c5c2dSKyungwoo Lee
37*d23c5c2dSKyungwoo Lee; Merge the cgdata using llvm-cgdata.
38*d23c5c2dSKyungwoo Lee; We now validate the content of the merged cgdata.
39*d23c5c2dSKyungwoo Lee; Two functions have the same hash with only one different constnat at a same location.
40*d23c5c2dSKyungwoo Lee; RUN: llvm-cgdata --merge -o %tout.cgdata %tout-nowrite.1 %tout-nowrite.2
41*d23c5c2dSKyungwoo Lee; RUN: llvm-cgdata --convert %tout.cgdata   -o - | FileCheck %s
42*d23c5c2dSKyungwoo Lee
43*d23c5c2dSKyungwoo Lee; CHECK:      - Hash: [[#%d,HASH:]]
44*d23c5c2dSKyungwoo Lee; CHECK-NEXT:   FunctionName: f1
45*d23c5c2dSKyungwoo Lee; CHECK-NEXT:   ModuleName: {{.*}}
46*d23c5c2dSKyungwoo Lee; CHECK-NEXT:   InstCount: [[#%d,INSTCOUNT:]]
47*d23c5c2dSKyungwoo Lee; CHECK-NEXT:   IndexOperandHashes:
48*d23c5c2dSKyungwoo Lee; CHECK-NEXT:     - InstIndex: [[#%d,INSTINDEX:]]
49*d23c5c2dSKyungwoo Lee; CHECK-NEXT:       OpndIndex: [[#%d,OPNDINDEX:]]
50*d23c5c2dSKyungwoo Lee; CHECK-NEXT:       OpndHash: {{.*}}
51*d23c5c2dSKyungwoo Lee
52*d23c5c2dSKyungwoo Lee; CHECK:      - Hash: [[#%d,HASH]]
53*d23c5c2dSKyungwoo Lee; CHECK-NEXT:   FunctionName: f2
54*d23c5c2dSKyungwoo Lee; CHECK-NEXT:   ModuleName: {{.*}}
55*d23c5c2dSKyungwoo Lee; CHECK-NEXT:   InstCount: [[#%d,INSTCOUNT]]
56*d23c5c2dSKyungwoo Lee; CHECK-NEXT:   IndexOperandHashes:
57*d23c5c2dSKyungwoo Lee; CHECK-NEXT:     - InstIndex: [[#%d,INSTINDEX]]
58*d23c5c2dSKyungwoo Lee; CHECK-NEXT:       OpndIndex: [[#%d,OPNDINDEX]]
59*d23c5c2dSKyungwoo Lee; CHECK-NEXT:       OpndHash: {{.*}}
60*d23c5c2dSKyungwoo Lee
61*d23c5c2dSKyungwoo Lee;--- foo.ll
62*d23c5c2dSKyungwoo Leetarget datalayout = "e-m:o-i64:64-i128:128-n32:64-S128"
63*d23c5c2dSKyungwoo Leetarget triple = "arm64-unknown-ios12.0.0"
64*d23c5c2dSKyungwoo Lee
65*d23c5c2dSKyungwoo Lee@g = external local_unnamed_addr global [0 x i32], align 4
66*d23c5c2dSKyungwoo Lee@g1 = external global i32, align 4
67*d23c5c2dSKyungwoo Lee@g2 = external global i32, align 4
68*d23c5c2dSKyungwoo Lee
69*d23c5c2dSKyungwoo Leedefine i32 @f1(i32 %a) {
70*d23c5c2dSKyungwoo Leeentry:
71*d23c5c2dSKyungwoo Lee  %idxprom = sext i32 %a to i64
72*d23c5c2dSKyungwoo Lee  %arrayidx = getelementptr inbounds [0 x i32], [0 x i32]* @g, i64 0, i64 %idxprom
73*d23c5c2dSKyungwoo Lee  %0 = load i32, i32* %arrayidx, align 4
74*d23c5c2dSKyungwoo Lee  %1 = load volatile i32, i32* @g1, align 4
75*d23c5c2dSKyungwoo Lee  %mul = mul nsw i32 %1, %0
76*d23c5c2dSKyungwoo Lee  %add = add nsw i32 %mul, 1
77*d23c5c2dSKyungwoo Lee  ret i32 %add
78*d23c5c2dSKyungwoo Lee}
79*d23c5c2dSKyungwoo Lee
80*d23c5c2dSKyungwoo Lee;--- goo.ll
81*d23c5c2dSKyungwoo Leetarget datalayout = "e-m:o-i64:64-i128:128-n32:64-S128"
82*d23c5c2dSKyungwoo Leetarget triple = "arm64-unknown-ios12.0.0"
83*d23c5c2dSKyungwoo Lee
84*d23c5c2dSKyungwoo Lee@g = external local_unnamed_addr global [0 x i32], align 4
85*d23c5c2dSKyungwoo Lee@g1 = external global i32, align 4
86*d23c5c2dSKyungwoo Lee@g2 = external global i32, align 4
87*d23c5c2dSKyungwoo Lee
88*d23c5c2dSKyungwoo Leedefine i32 @f2(i32 %a) {
89*d23c5c2dSKyungwoo Leeentry:
90*d23c5c2dSKyungwoo Lee  %idxprom = sext i32 %a to i64
91*d23c5c2dSKyungwoo Lee  %arrayidx = getelementptr inbounds [0 x i32], [0 x i32]* @g, i64 0, i64 %idxprom
92*d23c5c2dSKyungwoo Lee  %0 = load i32, i32* %arrayidx, align 4
93*d23c5c2dSKyungwoo Lee  %1 = load volatile i32, i32* @g2, align 4
94*d23c5c2dSKyungwoo Lee  %mul = mul nsw i32 %1, %0
95*d23c5c2dSKyungwoo Lee  %add = add nsw i32 %mul, 1
96*d23c5c2dSKyungwoo Lee  ret i32 %add
97*d23c5c2dSKyungwoo Lee}
98