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