• 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
5; See if the calls and other references are recorded properly using the
6; expected value id and other information as appropriate (callsite cout
7; for calls). Use different linkage types for the various test cases to
8; distinguish the test cases here (op1 contains the linkage type).
9; Note that op3 contains the # non-call references.
10; This also ensures that we didn't include a call or reference to intrinsic
11; llvm.ctpop.i8.
12; CHECK:       <GLOBALVAL_SUMMARY_BLOCK
13; Function main contains call to func, as well as address reference to func:
14; CHECK-DAG:    <PERMODULE {{.*}} op0=[[MAINID:[0-9]+]] op1=0 {{.*}} op3=1 op4=[[FUNCID:[0-9]+]] op5=[[FUNCID]] op6=1/>
15; Function W contains a call to func3 as well as a reference to globalvar:
16; CHECK-DAG:    <PERMODULE {{.*}} op0=[[WID:[0-9]+]] op1=5 {{.*}} op3=1 op4=[[GLOBALVARID:[0-9]+]] op5=[[FUNC3ID:[0-9]+]] op6=1/>
17; Function X contains call to foo, as well as address reference to foo
18; which is in the same instruction as the call:
19; CHECK-DAG:    <PERMODULE {{.*}} op0=[[XID:[0-9]+]] op1=1 {{.*}} op3=1 op4=[[FOOID:[0-9]+]] op5=[[FOOID]] op6=1/>
20; Function Y contains call to func2, and ensures we don't incorrectly add
21; a reference to it when reached while earlier analyzing the phi using its
22; return value:
23; CHECK-DAG:    <PERMODULE {{.*}} op0=[[YID:[0-9]+]] op1=8 {{.*}} op3=0 op4=[[FUNC2ID:[0-9]+]] op5=1/>
24; Function Z contains call to func2, and ensures we don't incorrectly add
25; a reference to it when reached while analyzing subsequent use of its return
26; value:
27; CHECK-DAG:    <PERMODULE {{.*}} op0=[[ZID:[0-9]+]] op1=3 {{.*}} op3=0 op4=[[FUNC2ID:[0-9]+]] op5=1/>
28; Variable bar initialization contains address reference to func:
29; CHECK-DAG:    <PERMODULE_GLOBALVAR_INIT_REFS {{.*}} op0=[[BARID:[0-9]+]] op1=0 op2=[[FUNCID]]/>
30; CHECK:  </GLOBALVAL_SUMMARY_BLOCK>
31
32; CHECK-NEXT:  <VALUE_SYMTAB
33; CHECK-DAG:    <ENTRY {{.*}} op0=[[BARID]] {{.*}} record string = 'bar'
34; CHECK-DAG:    <ENTRY {{.*}} op0=[[FUNCID]] {{.*}} record string = 'func'
35; CHECK-DAG:    <ENTRY {{.*}} op0=[[FOOID]] {{.*}} record string = 'foo'
36; CHECK-DAG:    <FNENTRY {{.*}} op0=[[MAINID]] {{.*}} record string = 'main'
37; CHECK-DAG:    <FNENTRY {{.*}} op0=[[WID]] {{.*}} record string = 'W'
38; CHECK-DAG:    <FNENTRY {{.*}} op0=[[XID]] {{.*}} record string = 'X'
39; CHECK-DAG:    <FNENTRY {{.*}} op0=[[YID]] {{.*}} record string = 'Y'
40; CHECK-DAG:    <FNENTRY {{.*}} op0=[[ZID]] {{.*}} record string = 'Z'
41; CHECK-DAG:    <ENTRY {{.*}} op0=[[FUNC2ID]] {{.*}} record string = 'func2'
42; CHECK-DAG:    <ENTRY {{.*}} op0=[[FUNC3ID]] {{.*}} record string = 'func3'
43; CHECK-DAG:    <ENTRY {{.*}} op0=[[GLOBALVARID]] {{.*}} record string = 'globalvar'
44; CHECK:  </VALUE_SYMTAB>
45
46; ModuleID = 'thinlto-function-summary-refgraph.ll'
47target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
48target triple = "x86_64-unknown-linux-gnu"
49
50@bar = global void (...)* bitcast (void ()* @func to void (...)*), align 8
51
52@globalvar = global i32 0, align 4
53
54declare void @func() #0
55declare i32 @func2(...) #1
56declare void @foo(i8* %F) #0
57declare i32 @func3(i32* dereferenceable(4)) #2
58
59; Function Attrs: nounwind uwtable
60define weak_odr void @W() #0 {
61entry:
62  %call = tail call i32 @func3(i32* nonnull dereferenceable(4) @globalvar)
63  ret void
64}
65
66; Function Attrs: nounwind uwtable
67define available_externally void @X() #0 {
68entry:
69  call void @foo(i8* bitcast (void (i8*)* @foo to i8*))
70  ret void
71}
72
73; Function Attrs: nounwind uwtable
74define private i32 @Y(i32 %i) #0 {
75entry:
76  %cmp3 = icmp slt i32 %i, 10
77  br i1 %cmp3, label %while.body.preheader, label %while.end
78
79while.body.preheader:                             ; preds = %entry
80  br label %while.body
81
82while.body:                                       ; preds = %while.body.preheader, %while.body
83  %j.05 = phi i32 [ %add, %while.body ], [ 0, %while.body.preheader ]
84  %i.addr.04 = phi i32 [ %inc, %while.body ], [ %i, %while.body.preheader ]
85  %inc = add nsw i32 %i.addr.04, 1
86  %call = tail call i32 (...) @func2() #2
87  %add = add nsw i32 %call, %j.05
88  %exitcond = icmp eq i32 %inc, 10
89  br i1 %exitcond, label %while.end.loopexit, label %while.body
90
91while.end.loopexit:                               ; preds = %while.body
92  %add.lcssa = phi i32 [ %add, %while.body ]
93  br label %while.end
94
95while.end:                                        ; preds = %while.end.loopexit, %entry
96  %j.0.lcssa = phi i32 [ 0, %entry ], [ %add.lcssa, %while.end.loopexit ]
97  ret i32 %j.0.lcssa
98}
99
100; Function Attrs: nounwind uwtable
101define linkonce_odr i32 @Z() #0 {
102entry:
103  %call = tail call i32 (...) @func2() #2
104  ret i32 %call
105}
106
107declare i8 @llvm.ctpop.i8(i8)
108
109; Function Attrs: nounwind uwtable
110define i32 @main() #0 {
111entry:
112  %retval = alloca i32, align 4
113  %foo = alloca void (...)*, align 8
114  store i32 0, i32* %retval, align 4
115  store void (...)* bitcast (void ()* @func to void (...)*), void (...)** %foo, align 8
116  %0 = load void (...)*, void (...)** %foo, align 8
117  call void (...) %0()
118  call void @func()
119  call i8  @llvm.ctpop.i8( i8 10 )
120  ret i32 0
121}
122