blob: 83039ad89b93474333d6db3a1552c1acb4a65b7f [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
4
Peter Collingbournea0f371a2017-04-17 17:51:36 +00005; CHECK: <SOURCE_FILENAME
6; "bar"
7; CHECK-NEXT: <GLOBALVAR {{.*}} op0=0 op1=3
8; "globalvar"
9; CHECK-NEXT: <GLOBALVAR {{.*}} op0=3 op1=9
10; "func"
11; CHECK-NEXT: <FUNCTION op0=12 op1=4
12; "func2"
13; CHECK-NEXT: <FUNCTION op0=16 op1=5
14; "foo"
15; CHECK-NEXT: <FUNCTION op0=21 op1=3
16; "func3"
17; CHECK-NEXT: <FUNCTION op0=24 op1=5
18; "W"
19; CHECK-NEXT: <FUNCTION op0=29 op1=1
20; "X"
21; CHECK-NEXT: <FUNCTION op0=30 op1=1
22; "Y"
23; CHECK-NEXT: <FUNCTION op0=31 op1=1
24; "Z"
25; CHECK-NEXT: <FUNCTION op0=32 op1=1
26; "llvm.ctpop.i8"
27; CHECK-NEXT: <FUNCTION op0=33 op1=13
28; "main"
29; CHECK-NEXT: <FUNCTION op0=46 op1=4
30
Teresa Johnson76a1c1d2016-03-11 18:52:24 +000031; See if the calls and other references are recorded properly using the
32; expected value id and other information as appropriate (callsite cout
33; for calls). Use different linkage types for the various test cases to
34; distinguish the test cases here (op1 contains the linkage type).
35; Note that op3 contains the # non-call references.
36; This also ensures that we didn't include a call or reference to intrinsic
37; llvm.ctpop.i8.
38; CHECK: <GLOBALVAL_SUMMARY_BLOCK
39; Function main contains call to func, as well as address reference to func:
Peter Collingbournea0f371a2017-04-17 17:51:36 +000040; op0=main op4=func op5=func
Charles Saternos75da10d2017-08-04 16:00:58 +000041; CHECK-DAG: <PERMODULE {{.*}} op0=11 op1=0 {{.*}} op4=1 op5=2 op6=2/>
Teresa Johnson76a1c1d2016-03-11 18:52:24 +000042; Function W contains a call to func3 as well as a reference to globalvar:
Peter Collingbournea0f371a2017-04-17 17:51:36 +000043; op0=W op4=globalvar op5=func3
Charles Saternos75da10d2017-08-04 16:00:58 +000044; CHECK-DAG: <PERMODULE {{.*}} op0=6 op1=5 {{.*}} op4=1 op5=1 op6=5/>
Teresa Johnson76a1c1d2016-03-11 18:52:24 +000045; Function X contains call to foo, as well as address reference to foo
46; which is in the same instruction as the call:
Peter Collingbournea0f371a2017-04-17 17:51:36 +000047; op0=X op4=foo op5=foo
Charles Saternos75da10d2017-08-04 16:00:58 +000048; CHECK-DAG: <PERMODULE {{.*}} op0=7 op1=1 {{.*}} op4=1 op5=4 op6=4/>
Teresa Johnson76a1c1d2016-03-11 18:52:24 +000049; Function Y contains call to func2, and ensures we don't incorrectly add
50; a reference to it when reached while earlier analyzing the phi using its
51; return value:
Peter Collingbournea0f371a2017-04-17 17:51:36 +000052; op0=Y op4=func2
Rafael Espindolae4b02312018-01-11 22:15:05 +000053; CHECK-DAG: <PERMODULE {{.*}} op0=8 op1=72 {{.*}} op4=0 op5=3/>
Teresa Johnson76a1c1d2016-03-11 18:52:24 +000054; Function Z contains call to func2, and ensures we don't incorrectly add
55; a reference to it when reached while analyzing subsequent use of its return
56; value:
Peter Collingbournea0f371a2017-04-17 17:51:36 +000057; op0=Z op4=func2
Charles Saternos75da10d2017-08-04 16:00:58 +000058; CHECK-DAG: <PERMODULE {{.*}} op0=9 op1=3 {{.*}} op4=0 op5=3/>
Teresa Johnson76a1c1d2016-03-11 18:52:24 +000059; Variable bar initialization contains address reference to func:
Peter Collingbournea0f371a2017-04-17 17:51:36 +000060; op0=bar op2=func
61; CHECK-DAG: <PERMODULE_GLOBALVAR_INIT_REFS {{.*}} op0=0 op1=0 op2=2/>
Teresa Johnson76a1c1d2016-03-11 18:52:24 +000062; CHECK: </GLOBALVAL_SUMMARY_BLOCK>
63
Peter Collingbournea0f371a2017-04-17 17:51:36 +000064; CHECK: <STRTAB_BLOCK
Peter Collingbourne92648c22017-06-27 23:50:11 +000065; CHECK-NEXT: blob data = 'barglobalvarfuncfunc2foofunc3WXYZllvm.ctpop.i8main{{.*}}'
Teresa Johnson76a1c1d2016-03-11 18:52:24 +000066
67; ModuleID = 'thinlto-function-summary-refgraph.ll'
68target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
69target triple = "x86_64-unknown-linux-gnu"
70
71@bar = global void (...)* bitcast (void ()* @func to void (...)*), align 8
72
73@globalvar = global i32 0, align 4
74
75declare void @func() #0
76declare i32 @func2(...) #1
77declare void @foo(i8* %F) #0
78declare i32 @func3(i32* dereferenceable(4)) #2
79
80; Function Attrs: nounwind uwtable
81define weak_odr void @W() #0 {
82entry:
83 %call = tail call i32 @func3(i32* nonnull dereferenceable(4) @globalvar)
84 ret void
85}
86
87; Function Attrs: nounwind uwtable
88define available_externally void @X() #0 {
89entry:
90 call void @foo(i8* bitcast (void (i8*)* @foo to i8*))
91 ret void
92}
93
94; Function Attrs: nounwind uwtable
95define private i32 @Y(i32 %i) #0 {
96entry:
97 %cmp3 = icmp slt i32 %i, 10
98 br i1 %cmp3, label %while.body.preheader, label %while.end
99
100while.body.preheader: ; preds = %entry
101 br label %while.body
102
103while.body: ; preds = %while.body.preheader, %while.body
104 %j.05 = phi i32 [ %add, %while.body ], [ 0, %while.body.preheader ]
105 %i.addr.04 = phi i32 [ %inc, %while.body ], [ %i, %while.body.preheader ]
106 %inc = add nsw i32 %i.addr.04, 1
107 %call = tail call i32 (...) @func2() #2
108 %add = add nsw i32 %call, %j.05
109 %exitcond = icmp eq i32 %inc, 10
110 br i1 %exitcond, label %while.end.loopexit, label %while.body
111
112while.end.loopexit: ; preds = %while.body
113 %add.lcssa = phi i32 [ %add, %while.body ]
114 br label %while.end
115
116while.end: ; preds = %while.end.loopexit, %entry
117 %j.0.lcssa = phi i32 [ 0, %entry ], [ %add.lcssa, %while.end.loopexit ]
118 ret i32 %j.0.lcssa
119}
120
121; Function Attrs: nounwind uwtable
122define linkonce_odr i32 @Z() #0 {
123entry:
124 %call = tail call i32 (...) @func2() #2
125 ret i32 %call
126}
127
128declare i8 @llvm.ctpop.i8(i8)
129
130; Function Attrs: nounwind uwtable
131define i32 @main() #0 {
132entry:
133 %retval = alloca i32, align 4
134 %foo = alloca void (...)*, align 8
135 store i32 0, i32* %retval, align 4
136 store void (...)* bitcast (void ()* @func to void (...)*), void (...)** %foo, align 8
137 %0 = load void (...)*, void (...)** %foo, align 8
138 call void (...) %0()
139 call void @func()
140 call i8 @llvm.ctpop.i8( i8 10 )
141 ret i32 0
142}