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