blob: 4de5242188dcdf72fb8f5e115329baddcc0f60c7 [file] [log] [blame]
Teresa Johnson76a1c1d2016-03-11 18:52:24 +00001; Test to check both the callgraph and refgraph in summary
Mehdi Amini68da4262016-04-12 21:35:18 +00002; RUN: opt -module-summary %s -o %t.o
Teresa Johnson76a1c1d2016-03-11 18:52:24 +00003; RUN: llvm-bcanalyzer -dump %t.o | FileCheck %s
Teresa Johnson08d5b4e2018-05-26 02:34:13 +00004; RUN: llvm-dis -o - %t.o | FileCheck %s --check-prefix=DIS
Teresa Johnson76a1c1d2016-03-11 18:52:24 +00005
Peter Collingbournea0f371a2017-04-17 17:51:36 +00006; CHECK: <SOURCE_FILENAME
7; "bar"
8; CHECK-NEXT: <GLOBALVAR {{.*}} op0=0 op1=3
9; "globalvar"
10; CHECK-NEXT: <GLOBALVAR {{.*}} op0=3 op1=9
11; "func"
12; CHECK-NEXT: <FUNCTION op0=12 op1=4
13; "func2"
14; CHECK-NEXT: <FUNCTION op0=16 op1=5
15; "foo"
16; CHECK-NEXT: <FUNCTION op0=21 op1=3
17; "func3"
18; CHECK-NEXT: <FUNCTION op0=24 op1=5
19; "W"
20; CHECK-NEXT: <FUNCTION op0=29 op1=1
21; "X"
22; CHECK-NEXT: <FUNCTION op0=30 op1=1
23; "Y"
24; CHECK-NEXT: <FUNCTION op0=31 op1=1
25; "Z"
26; CHECK-NEXT: <FUNCTION op0=32 op1=1
27; "llvm.ctpop.i8"
28; CHECK-NEXT: <FUNCTION op0=33 op1=13
29; "main"
30; CHECK-NEXT: <FUNCTION op0=46 op1=4
31
Teresa Johnson76a1c1d2016-03-11 18:52:24 +000032; See if the calls and other references are recorded properly using the
33; expected value id and other information as appropriate (callsite cout
34; for calls). Use different linkage types for the various test cases to
35; distinguish the test cases here (op1 contains the linkage type).
36; Note that op3 contains the # non-call references.
37; This also ensures that we didn't include a call or reference to intrinsic
38; llvm.ctpop.i8.
39; CHECK: <GLOBALVAL_SUMMARY_BLOCK
40; Function main contains call to func, as well as address reference to func:
Peter Collingbournea0f371a2017-04-17 17:51:36 +000041; op0=main op4=func op5=func
Charles Saternos75da10d2017-08-04 16:00:58 +000042; CHECK-DAG: <PERMODULE {{.*}} op0=11 op1=0 {{.*}} op4=1 op5=2 op6=2/>
Teresa Johnson76a1c1d2016-03-11 18:52:24 +000043; Function W contains a call to func3 as well as a reference to globalvar:
Peter Collingbournea0f371a2017-04-17 17:51:36 +000044; op0=W op4=globalvar op5=func3
Charles Saternos75da10d2017-08-04 16:00:58 +000045; CHECK-DAG: <PERMODULE {{.*}} op0=6 op1=5 {{.*}} op4=1 op5=1 op6=5/>
Teresa Johnson76a1c1d2016-03-11 18:52:24 +000046; Function X contains call to foo, as well as address reference to foo
47; which is in the same instruction as the call:
Peter Collingbournea0f371a2017-04-17 17:51:36 +000048; op0=X op4=foo op5=foo
Charles Saternos75da10d2017-08-04 16:00:58 +000049; CHECK-DAG: <PERMODULE {{.*}} op0=7 op1=1 {{.*}} op4=1 op5=4 op6=4/>
Teresa Johnson76a1c1d2016-03-11 18:52:24 +000050; Function Y contains call to func2, and ensures we don't incorrectly add
51; a reference to it when reached while earlier analyzing the phi using its
52; return value:
Peter Collingbournea0f371a2017-04-17 17:51:36 +000053; op0=Y op4=func2
Rafael Espindolae4b02312018-01-11 22:15:05 +000054; CHECK-DAG: <PERMODULE {{.*}} op0=8 op1=72 {{.*}} op4=0 op5=3/>
Teresa Johnson76a1c1d2016-03-11 18:52:24 +000055; Function Z contains call to func2, and ensures we don't incorrectly add
56; a reference to it when reached while analyzing subsequent use of its return
57; value:
Peter Collingbournea0f371a2017-04-17 17:51:36 +000058; op0=Z op4=func2
Charles Saternos75da10d2017-08-04 16:00:58 +000059; CHECK-DAG: <PERMODULE {{.*}} op0=9 op1=3 {{.*}} op4=0 op5=3/>
Teresa Johnson76a1c1d2016-03-11 18:52:24 +000060; Variable bar initialization contains address reference to func:
Peter Collingbournea0f371a2017-04-17 17:51:36 +000061; op0=bar op2=func
62; CHECK-DAG: <PERMODULE_GLOBALVAR_INIT_REFS {{.*}} op0=0 op1=0 op2=2/>
Teresa Johnson76a1c1d2016-03-11 18:52:24 +000063; CHECK: </GLOBALVAL_SUMMARY_BLOCK>
64
Peter Collingbournea0f371a2017-04-17 17:51:36 +000065; CHECK: <STRTAB_BLOCK
Peter Collingbourne92648c22017-06-27 23:50:11 +000066; CHECK-NEXT: blob data = 'barglobalvarfuncfunc2foofunc3WXYZllvm.ctpop.i8main{{.*}}'
Teresa Johnson76a1c1d2016-03-11 18:52:24 +000067
68; ModuleID = 'thinlto-function-summary-refgraph.ll'
69target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
70target triple = "x86_64-unknown-linux-gnu"
71
72@bar = global void (...)* bitcast (void ()* @func to void (...)*), align 8
73
74@globalvar = global i32 0, align 4
75
76declare void @func() #0
77declare i32 @func2(...) #1
78declare void @foo(i8* %F) #0
79declare i32 @func3(i32* dereferenceable(4)) #2
80
81; Function Attrs: nounwind uwtable
82define weak_odr void @W() #0 {
83entry:
84 %call = tail call i32 @func3(i32* nonnull dereferenceable(4) @globalvar)
85 ret void
86}
87
88; Function Attrs: nounwind uwtable
89define available_externally void @X() #0 {
90entry:
91 call void @foo(i8* bitcast (void (i8*)* @foo to i8*))
92 ret void
93}
94
95; Function Attrs: nounwind uwtable
96define private i32 @Y(i32 %i) #0 {
97entry:
98 %cmp3 = icmp slt i32 %i, 10
99 br i1 %cmp3, label %while.body.preheader, label %while.end
100
101while.body.preheader: ; preds = %entry
102 br label %while.body
103
104while.body: ; preds = %while.body.preheader, %while.body
105 %j.05 = phi i32 [ %add, %while.body ], [ 0, %while.body.preheader ]
106 %i.addr.04 = phi i32 [ %inc, %while.body ], [ %i, %while.body.preheader ]
107 %inc = add nsw i32 %i.addr.04, 1
108 %call = tail call i32 (...) @func2() #2
109 %add = add nsw i32 %call, %j.05
110 %exitcond = icmp eq i32 %inc, 10
111 br i1 %exitcond, label %while.end.loopexit, label %while.body
112
113while.end.loopexit: ; preds = %while.body
114 %add.lcssa = phi i32 [ %add, %while.body ]
115 br label %while.end
116
117while.end: ; preds = %while.end.loopexit, %entry
118 %j.0.lcssa = phi i32 [ 0, %entry ], [ %add.lcssa, %while.end.loopexit ]
119 ret i32 %j.0.lcssa
120}
121
122; Function Attrs: nounwind uwtable
123define linkonce_odr i32 @Z() #0 {
124entry:
125 %call = tail call i32 (...) @func2() #2
126 ret i32 %call
127}
128
129declare i8 @llvm.ctpop.i8(i8)
130
131; Function Attrs: nounwind uwtable
132define i32 @main() #0 {
133entry:
134 %retval = alloca i32, align 4
135 %foo = alloca void (...)*, align 8
136 store i32 0, i32* %retval, align 4
137 store void (...)* bitcast (void ()* @func to void (...)*), void (...)** %foo, align 8
138 %0 = load void (...)*, void (...)** %foo, align 8
139 call void (...) %0()
140 call void @func()
141 call i8 @llvm.ctpop.i8( i8 10 )
142 ret i32 0
143}
Teresa Johnson08d5b4e2018-05-26 02:34:13 +0000144
Teresa Johnsonfb89e7a2018-05-26 03:50:29 +0000145; Don't try to match summary IDs. The numbering depends on the map iteration
146; order, which depends on GUID, and the private function Y GUID will depend
147; on the path to the test.
148; DIS: ^0 = module: (path: "{{.*}}thinlto-function-summary-refgraph.ll.tmp.o", hash: (0, 0, 0, 0, 0))
149; DIS-DAG: = gv: (name: "Z", summaries: (function: (module: ^0, flags: (linkage: linkonce_odr, notEligibleToImport: 0, live: 0, dsoLocal: 0), insts: 2, calls: ((callee: ^{{.*}}))))) ; guid = 104084381700047393
150; DIS-DAG: = gv: (name: "X", summaries: (function: (module: ^0, flags: (linkage: available_externally, notEligibleToImport: 0, live: 0, dsoLocal: 0), insts: 2, calls: ((callee: ^{{.*}})), refs: (^{{.*}})))) ; guid = 1881667236089500162
151; DIS-DAG: = gv: (name: "W", summaries: (function: (module: ^0, flags: (linkage: weak_odr, notEligibleToImport: 0, live: 0, dsoLocal: 0), insts: 2, calls: ((callee: ^{{.*}})), refs: (^{{.*}})))) ; guid = 5790125716599269729
152; DIS-DAG: = gv: (name: "foo") ; guid = 6699318081062747564
153; DIS-DAG: = gv: (name: "func") ; guid = 7289175272376759421
154; DIS-DAG: = gv: (name: "func3") ; guid = 11517462787082255043
155; DIS-DAG: = gv: (name: "globalvar", summaries: (variable: (module: ^0, flags: (linkage: external, notEligibleToImport: 0, live: 0, dsoLocal: 0)))) ; guid = 12887606300320728018
156; DIS-DAG: = gv: (name: "func2") ; guid = 14069196320850861797
157; DIS-DAG: = gv: (name: "llvm.ctpop.i8") ; guid = 15254915475081819833
158; DIS-DAG: = gv: (name: "main", summaries: (function: (module: ^0, flags: (linkage: external, notEligibleToImport: 0, live: 0, dsoLocal: 0), insts: 9, calls: ((callee: ^{{.*}})), refs: (^{{.*}})))) ; guid = 15822663052811949562
159; DIS-DAG: = gv: (name: "bar", summaries: (variable: (module: ^0, flags: (linkage: external, notEligibleToImport: 0, live: 0, dsoLocal: 0), refs: (^{{.*}})))) ; guid = 16434608426314478903
Teresa Johnson365ed592018-05-26 03:20:06 +0000160; Don't try to match the exact GUID. Since it is private, the file path
161; will get hashed, and that will be test dependent.
Teresa Johnsonfb89e7a2018-05-26 03:50:29 +0000162; DIS-DAG: = gv: (name: "Y", summaries: (function: (module: ^0, flags: (linkage: private, notEligibleToImport: 0, live: 0, dsoLocal: 1), insts: 14, calls: ((callee: ^{{.*}}))))) ; guid =