xref: /llvm-project/llvm/test/ThinLTO/X86/ctxprof.ll (revision 6329355860e9b66bc7ed68b46c166763e408d4cc)
1; Test workload based importing via -thinlto-pgo-ctx-prof
2; Use external linkage symbols so we don't depend on module paths which are
3; used when computing the GUIDs of internal linkage symbols.
4; The functionality is shared with what workload.ll tests, so here we only care
5; about testing the ctx profile is loaded and handled correctly.
6;
7; Set up
8; RUN: rm -rf %t
9; RUN: mkdir -p %t
10; RUN: split-file %s %t
11;
12; RUN: opt -module-summary -passes=assign-guid %t/m1.ll -o %t/m1.bc
13; RUN: opt -module-summary -passes=assign-guid %t/m2.ll -o %t/m2.bc
14; RUN: llvm-dis %t/m1.bc -o - | FileCheck %s --check-prefix=GUIDS-1
15; RUN: llvm-dis %t/m2.bc -o - | FileCheck %s --check-prefix=GUIDS-2
16;
17; GUIDS-1-LABEL: @m1_f1
18; GUIDS-1-SAME: !guid ![[GUID1:[0-9]+]]
19; GUIDS-1:  ![[GUID1]] = !{i64 6019442868614718803}
20; GUIDS-1: ^0 = module:
21; GUIDS-1: name: "m1_f1"
22; GUIDS-1-SAME: guid = 6019442868614718803
23
24; note: -2853647799038631862 is 15593096274670919754
25; GUIDS-2-LABEL: @m2_f1
26; GUIDS-2-SAME: !guid ![[GUID2:[0-9]+]]
27; GUIDS-2: ![[GUID2]] = !{i64 -2853647799038631862}
28; GUIDS-2: ^0 = module:
29; GUIDS-2: name: "m2_f1"
30; GUIDS-2-SAME: guid = 15593096274670919754
31;
32; RUN: rm -rf %t_baseline
33; RUN: rm -rf %t_exp
34; RUN: mkdir -p %t_baseline
35; RUN: mkdir -p %t_exp
36;
37; Normal run. m1 shouldn't get m2_f1 because it's not referenced from there, and
38; m1_f1 shouldn't go to m2.
39;
40; RUN: llvm-lto2 run %t/m1.bc %t/m2.bc \
41; RUN:  -o %t_baseline/result.o -save-temps \
42; RUN:  -r %t/m1.bc,m1_f1,plx \
43; RUN:  -r %t/m2.bc,m2_f1,plx
44; RUN: llvm-dis %t_baseline/result.o.1.3.import.bc -o - | FileCheck %s --check-prefix=NOPROF-1
45; RUN: llvm-dis %t_baseline/result.o.2.3.import.bc -o - | FileCheck %s --check-prefix=NOPROF-2
46;
47; NOPROF-1-NOT: m2_f1()
48; NOPROF-2-NOT: m1_f1()
49;
50; The run with workload definitions - same other options. We do need to re-generate the .bc
51; files, to include instrumentation.
52; RUN: opt -module-summary -passes=assign-guid,ctx-instr-gen %t/m1.ll -o %t/m1-instr.bc
53; RUN: opt -module-summary -passes=assign-guid,ctx-instr-gen %t/m2.ll -o %t/m2-instr.bc
54;
55; RUN: echo '[ \
56; RUN:        {"Guid": 6019442868614718803, "Counters": [1], "Callsites": [[{"Guid": 15593096274670919754, "Counters": [1]}]]}, \
57; RUN:        {"Guid": 15593096274670919754, "Counters": [1], "Callsites": [[{"Guid": 6019442868614718803, "Counters": [1]}]]} \
58; RUN:  ]' > %t_exp/ctxprof.yaml
59; RUN: llvm-ctxprof-util fromYAML --input %t_exp/ctxprof.yaml --output %t_exp/ctxprof.bitstream
60; RUN: llvm-lto2 run %t/m1-instr.bc %t/m2-instr.bc \
61; RUN:  -o %t_exp/result.o -save-temps \
62; RUN:  -use-ctx-profile=%t_exp/ctxprof.bitstream \
63; RUN:  -r %t/m1-instr.bc,m1_f1,plx \
64; RUN:  -r %t/m2-instr.bc,m2_f1,plx
65; RUN: llvm-dis %t_exp/result.o.1.3.import.bc -o - | FileCheck %s --check-prefix=FIRST
66; RUN: llvm-dis %t_exp/result.o.2.3.import.bc -o - | FileCheck %s --check-prefix=SECOND
67;
68;
69; FIRST: m2_f1()
70; SECOND: m1_f1()
71;
72;--- m1.ll
73target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
74target triple = "x86_64-pc-linux-gnu"
75
76define dso_local void @m1_f1() {
77  ret void
78}
79
80;--- m2.ll
81target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
82target triple = "x86_64-pc-linux-gnu"
83
84define dso_local void @m2_f1() {
85  ret void
86}
87