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