166 lines · plain
1; Test to check both the callgraph and refgraph in summary2; RUN: opt -module-summary %s -o %t.o3; RUN: llvm-bcanalyzer -dump %t.o | FileCheck %s4; RUN: llvm-dis -o - %t.o | FileCheck %s --check-prefix=DIS5; Round trip it through llvm-as6; RUN: llvm-dis -o - %t.o | llvm-as -o - | llvm-dis -o - | FileCheck %s --check-prefix=DIS7 8; CHECK: <SOURCE_FILENAME9; "bar"10; CHECK-NEXT: <GLOBALVAR {{.*}} op0=0 op1=311; "globalvar"12; CHECK-NEXT: <GLOBALVAR {{.*}} op0=3 op1=913; "func"14; CHECK-NEXT: <FUNCTION op0=12 op1=415; "func2"16; CHECK-NEXT: <FUNCTION op0=16 op1=517; "foo"18; CHECK-NEXT: <FUNCTION op0=21 op1=319; "func3"20; CHECK-NEXT: <FUNCTION op0=24 op1=521; "W"22; CHECK-NEXT: <FUNCTION op0=29 op1=123; "X"24; CHECK-NEXT: <FUNCTION op0=30 op1=125; "Y"26; CHECK-NEXT: <FUNCTION op0=31 op1=127; "Z"28; CHECK-NEXT: <FUNCTION op0=32 op1=129; "llvm.ctpop.i8"30; CHECK-NEXT: <FUNCTION op0=33 op1=1331; "main"32; CHECK-NEXT: <FUNCTION op0=46 op1=433 34; See if the calls and other references are recorded properly using the35; expected value id and other information as appropriate (callsite cout36; for calls). Use different linkage types for the various test cases to37; 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 intrinsic40; llvm.ctpop.i8.41; CHECK: <GLOBALVAL_SUMMARY_BLOCK42; Function main contains call to func, as well as address reference to func:43; op0=main op4=func op5=func44; 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=func347; 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 foo49; which is in the same instruction as the call:50; op0=X op4=foo op5=foo51; 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 add53; a reference to it when reached while earlier analyzing the phi using its54; return value:55; op0=Y op4=func256; 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 add58; a reference to it when reached while analyzing subsequent use of its return59; value:60; op0=Z op4=func261; 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:63; op0=bar op2=func64; CHECK-DAG: <PERMODULE_GLOBALVAR_INIT_REFS {{.*}} op0=0 op1=0 op2=3 op3=2/>65; CHECK: </GLOBALVAL_SUMMARY_BLOCK>66 67; CHECK: <STRTAB_BLOCK68; 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 875 76@globalvar = constant i32 0, align 477 78declare void @func() #079declare i32 @func2(...) #180declare void @foo(i8* %F) #081declare i32 @func3(i32* dereferenceable(4)) #282 83; Function Attrs: nounwind uwtable84define weak_odr void @W() #0 {85entry:86 %call = tail call i32 @func3(i32* nonnull dereferenceable(4) @globalvar)87 ret void88}89 90; Function Attrs: nounwind uwtable91define available_externally void @X() #0 {92entry:93 call void @foo(i8* bitcast (void (i8*)* @foo to i8*))94 ret void95}96 97; Function Attrs: nounwind uwtable98define private i32 @Y(i32 %i) #0 {99entry:100 %cmp3 = icmp slt i32 %i, 10101 br i1 %cmp3, label %while.body.preheader, label %while.end102 103while.body.preheader: ; preds = %entry104 br label %while.body105 106while.body: ; preds = %while.body.preheader, %while.body107 %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, 1110 %call = tail call i32 (...) @func2() #2111 %add = add nsw i32 %call, %j.05112 %exitcond = icmp eq i32 %inc, 10113 br i1 %exitcond, label %while.end.loopexit, label %while.body114 115while.end.loopexit: ; preds = %while.body116 %add.lcssa = phi i32 [ %add, %while.body ]117 br label %while.end118 119while.end: ; preds = %while.end.loopexit, %entry120 %j.0.lcssa = phi i32 [ 0, %entry ], [ %add.lcssa, %while.end.loopexit ]121 ret i32 %j.0.lcssa122}123 124; Function Attrs: nounwind uwtable125define linkonce_odr i32 @Z() #0 {126entry:127 %call = tail call i32 (...) @func2() #2128 ret i32 %call129}130 131declare i8 @llvm.ctpop.i8(i8)132 133; Function Attrs: nounwind uwtable134define i32 @main() #0 {135entry:136 %retval = alloca i32, align 4137 %foo = alloca void (...)*, align 8138 store i32 0, i32* %retval, align 4139 store void (...)* bitcast (void ()* @func to void (...)*), void (...)** %foo, align 8140 %0 = load void (...)*, void (...)** %foo, align 8141 call void (...) %0()142 call void @func()143 call i8 @llvm.ctpop.i8( i8 10 )144 ret i32 0145}146 147; Don't try to match summary IDs. The numbering depends on the map iteration148; order, which depends on GUID, and the private function Y GUID will depend149; 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 = 104084381700047393152; 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 = 1881667236089500162153; 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 = 5790125716599269729154; DIS-DAG: = gv: (name: "foo") ; guid = 6699318081062747564155; DIS-DAG: = gv: (name: "func") ; guid = 7289175272376759421156; DIS-DAG: = gv: (name: "func3") ; guid = 11517462787082255043157; 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 = 12887606300320728018159; DIS-DAG: = gv: (name: "func2") ; guid = 14069196320850861797160; DIS-DAG: = gv: (name: "llvm.ctpop.i8") ; guid = 15254915475081819833161; 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 = 15822663052811949562162; 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 = 16434608426314478903163; Don't try to match the exact GUID. Since it is private, the file path164; 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 =166