• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
7
8; 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
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
40; llvm.ctpop.i8.
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 {{.*}} op0=11 op1=0 {{.*}} op4=1 op5=2 op6=2/>
45; Function W contains a call to func3 as well as a reference to globalvar:
46; op0=W op4=globalvar op5=func3
47; CHECK-DAG:    <PERMODULE {{.*}} op0=6 op1=5 {{.*}} op4=1 op5=1 op6=5/>
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 {{.*}} op0=7 op1=1 {{.*}} op4=1 op5=4 op6=4/>
52; 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:
55; op0=Y op4=func2
56; CHECK-DAG:    <PERMODULE {{.*}} op0=8 op1=72 {{.*}} op4=0 op5=3/>
57; 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:
60; op0=Z op4=func2
61; CHECK-DAG:    <PERMODULE {{.*}} op0=9 op1=3 {{.*}} op4=0 op5=3/>
62; Variable bar initialization contains address reference to func:
63; op0=bar op2=func
64; CHECK-DAG:    <PERMODULE_GLOBALVAR_INIT_REFS {{.*}} op0=0 op1=0 op2=2/>
65; CHECK:  </GLOBALVAL_SUMMARY_BLOCK>
66
67; CHECK: <STRTAB_BLOCK
68; CHECK-NEXT: blob data = 'barglobalvarfuncfunc2foofunc3WXYZllvm.ctpop.i8main{{.*}}'
69
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}
146
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, 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
157; DIS-DAG: = gv: (name: "globalvar", summaries: (variable: (module: ^0, flags: (linkage: external, notEligibleToImport: 0, live: 0, dsoLocal: 0)))) ; guid = 12887606300320728018
158; 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
161; DIS-DAG: = gv: (name: "bar", summaries: (variable: (module: ^0, flags: (linkage: external, notEligibleToImport: 0, live: 0, dsoLocal: 0), refs: (^{{.*}})))) ; guid = 16434608426314478903
162; 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.
164; DIS-DAG: = gv: (name: "Y", summaries: (function: (module: ^0, flags: (linkage: private, notEligibleToImport: 0, live: 0, dsoLocal: 1), insts: 14, calls: ((callee: ^{{.*}}))))) ; guid =
165