1 ; Test to check both the callgraph and refgraph in summary
2 ; RUN: opt -module-summary %s -o %t.o
3 ; RUN: llvm-bcanalyzer -dump %t.o | FileCheck %s
4 ; RUN: llvm-dis -o - %t.o | FileCheck %s --check-prefix=DIS
5 ; Round trip it through llvm-as
6 ; RUN: llvm-dis -o - %t.o | llvm-as -o - | llvm-dis -o - | FileCheck %s --check-prefix=DIS
8 ; CHECK: <SOURCE_FILENAME
10 ; CHECK-NEXT: <GLOBALVAR {{.*}} op0=0 op1=3
12 ; CHECK-NEXT: <GLOBALVAR {{.*}} op0=3 op1=9
14 ; CHECK-NEXT: <FUNCTION op0=12 op1=4
16 ; CHECK-NEXT: <FUNCTION op0=16 op1=5
18 ; CHECK-NEXT: <FUNCTION op0=21 op1=3
20 ; CHECK-NEXT: <FUNCTION op0=24 op1=5
22 ; CHECK-NEXT: <FUNCTION op0=29 op1=1
24 ; CHECK-NEXT: <FUNCTION op0=30 op1=1
26 ; CHECK-NEXT: <FUNCTION op0=31 op1=1
28 ; CHECK-NEXT: <FUNCTION op0=32 op1=1
30 ; CHECK-NEXT: <FUNCTION op0=33 op1=13
32 ; CHECK-NEXT: <FUNCTION op0=46 op1=4
34 ; 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
41 ; CHECK: <GLOBALVAL_SUMMARY_BLOCK
42 ; Function main contains call to func, as well as address reference to func:
43 ; op0=main op4=func op5=func
44 ; CHECK-DAG: <PERMODULE_PROFILE {{.*}} op0=11 op1=0 {{.*}} op4=1 op5=0 op6=0 op7=2 op8=2 op9=0/>
45 ; Function W contains a tail call to func3 as well as a reference to globalvar:
46 ; op0=W op4=globalvar op5=func3
47 ; CHECK-DAG: <PERMODULE_PROFILE {{.*}} op0=6 op1=5 {{.*}} op4=1 op5=0 op6=0 op7=1 op8=5 op9=8/>
48 ; Function X contains call to foo, as well as address reference to foo
49 ; which is in the same instruction as the call:
50 ; op0=X op4=foo op5=foo
51 ; CHECK-DAG: <PERMODULE_PROFILE {{.*}} op0=7 op1=1 {{.*}} op4=1 op5=0 op6=0 op7=4 op8=4 op9=0/>
52 ; Function Y contains tail call to func2, and ensures we don't incorrectly add
53 ; a reference to it when reached while earlier analyzing the phi using its
56 ; CHECK-DAG: <PERMODULE_PROFILE {{.*}} op0=8 op1=72 {{.*}} op4=0 op5=0 op6=0 op7=3 op8=8/>
57 ; Function Z contains a tail call to func2, and ensures we don't incorrectly add
58 ; a reference to it when reached while analyzing subsequent use of its return
61 ; CHECK-DAG: <PERMODULE_PROFILE {{.*}} op0=9 op1=3 {{.*}} op4=0 op5=0 op6=0 op7=3 op8=8/>
62 ; Variable bar initialization contains address reference to func:
64 ; CHECK-DAG: <PERMODULE_GLOBALVAR_INIT_REFS {{.*}} op0=0 op1=0 op2=3 op3=2/>
65 ; CHECK: </GLOBALVAL_SUMMARY_BLOCK>
67 ; CHECK: <STRTAB_BLOCK
68 ; CHECK-NEXT: blob data = 'barglobalvarfuncfunc2foofunc3WXYZllvm.ctpop.i8main{{.*}}'
70 ; ModuleID = 'thinlto-function-summary-refgraph.ll'
71 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
72 target triple = "x86_64-unknown-linux-gnu"
74 @bar = global void (...)* bitcast (void ()* @func to void (...)*), align 8
76 @globalvar = constant i32 0, align 4
78 declare void @func() #0
79 declare i32 @func2(...) #1
80 declare void @foo(i8* %F) #0
81 declare i32 @func3(i32* dereferenceable(4)) #2
83 ; Function Attrs: nounwind uwtable
84 define weak_odr void @W() #0 {
86 %call = tail call i32 @func3(i32* nonnull dereferenceable(4) @globalvar)
90 ; Function Attrs: nounwind uwtable
91 define available_externally void @X() #0 {
93 call void @foo(i8* bitcast (void (i8*)* @foo to i8*))
97 ; Function Attrs: nounwind uwtable
98 define private i32 @Y(i32 %i) #0 {
100 %cmp3 = icmp slt i32 %i, 10
101 br i1 %cmp3, label %while.body.preheader, label %while.end
103 while.body.preheader: ; preds = %entry
106 while.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
115 while.end.loopexit: ; preds = %while.body
116 %add.lcssa = phi i32 [ %add, %while.body ]
119 while.end: ; preds = %while.end.loopexit, %entry
120 %j.0.lcssa = phi i32 [ 0, %entry ], [ %add.lcssa, %while.end.loopexit ]
124 ; Function Attrs: nounwind uwtable
125 define linkonce_odr i32 @Z() #0 {
127 %call = tail call i32 (...) @func2() #2
131 declare i8 @llvm.ctpop.i8(i8)
133 ; Function Attrs: nounwind uwtable
134 define i32 @main() #0 {
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
143 call i8 @llvm.ctpop.i8( i8 10 )
147 ; 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.
150 ; DIS: ^0 = module: (path: "{{.*}}", hash: (0, 0, 0, 0, 0))
151 ; DIS-DAG: = gv: (name: "Z", summaries: (function: (module: ^0, flags: (linkage: linkonce_odr, visibility: default, notEligibleToImport: 0, live: 0, dsoLocal: 0, canAutoHide: 0, importType: definition), insts: 2, calls: ((callee: ^{{.*}}, tail: 1))))) ; guid = 104084381700047393
152 ; DIS-DAG: = gv: (name: "X", summaries: (function: (module: ^0, flags: (linkage: available_externally, visibility: default, notEligibleToImport: 0, live: 0, dsoLocal: 0, canAutoHide: 0, importType: definition), insts: 2, calls: ((callee: ^{{.*}})), refs: (^{{.*}})))) ; guid = 1881667236089500162
153 ; DIS-DAG: = gv: (name: "W", summaries: (function: (module: ^0, flags: (linkage: weak_odr, visibility: default, notEligibleToImport: 0, live: 0, dsoLocal: 0, canAutoHide: 0, importType: definition), insts: 2, calls: ((callee: ^{{.*}}, tail: 1)), 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
157 ; Check that default value of writeonly attribute is zero for constant variables
158 ; DIS-DAG: = gv: (name: "globalvar", summaries: (variable: (module: ^0, flags: (linkage: external, visibility: default, notEligibleToImport: 0, live: 0, dsoLocal: 0, canAutoHide: 0, importType: definition), varFlags: (readonly: 1, writeonly: 0, constant: 1)))) ; guid = 12887606300320728018
159 ; DIS-DAG: = gv: (name: "func2") ; guid = 14069196320850861797
160 ; DIS-DAG: = gv: (name: "llvm.ctpop.i8") ; guid = 15254915475081819833
161 ; DIS-DAG: = gv: (name: "main", summaries: (function: (module: ^0, flags: (linkage: external, visibility: default, notEligibleToImport: 0, live: 0, dsoLocal: 0, canAutoHide: 0, importType: definition), insts: 9, funcFlags: (readNone: 0, readOnly: 0, noRecurse: 0, returnDoesNotAlias: 0, noInline: 0, alwaysInline: 0, noUnwind: 0, mayThrow: 0, hasUnknownCall: 1, mustBeUnreachable: 0), calls: ((callee: ^{{.*}})), refs: (^{{.*}})))) ; guid = 15822663052811949562
162 ; DIS-DAG: = gv: (name: "bar", summaries: (variable: (module: ^0, flags: (linkage: external, visibility: default, notEligibleToImport: 0, live: 0, dsoLocal: 0, canAutoHide: 0, importType: definition), varFlags: (readonly: 1, writeonly: 1, constant: 0), refs: (^{{.*}})))) ; guid = 16434608426314478903
163 ; Don't try to match the exact GUID. Since it is private, the file path
164 ; will get hashed, and that will be test dependent.
165 ; DIS-DAG: = gv: (name: "Y", summaries: (function: (module: ^0, flags: (linkage: private, visibility: default, notEligibleToImport: 0, live: 0, dsoLocal: 1, canAutoHide: 0, importType: definition), insts: 14, calls: ((callee: ^{{.*}}, tail: 1))))) ; guid =