1; RUN: opt < %s -passes=pseudo-probe,sample-profile -sample-profile-file=%S/Inputs/pseudo-probe-profile.prof -pass-remarks=sample-profile -pass-remarks-output=%t.opt.yaml -sample-profile-use-profi=0 -S -o %t 2; RUN: FileCheck %s --input-file %t 3; RUN: FileCheck %s -check-prefix=YAML --input-file %t.opt.yaml 4; RUN: opt < %t -passes=sample-profile -sample-profile-file=%S/Inputs/pseudo-probe-profile.prof -sample-profile-remove-probe -S | FileCheck %s -check-prefix=REMOVE-PROBE 5 6; REMOVE-PROBE-NOT: call void @llvm.pseudoprobe 7; REMOVE-PROBE-NOT: !llvm.pseudo_probe_desc 8; REMOVE-PROBE: !DILexicalBlockFile({{.*}}, discriminator: 0) 9 10define dso_local i32 @foo(i32 %x, ptr %f) #0 !dbg !4 { 11entry: 12 %retval = alloca i32, align 4 13 %x.addr = alloca i32, align 4 14 store i32 %x, ptr %x.addr, align 4 15 %0 = load i32, ptr %x.addr, align 4 16 %cmp = icmp eq i32 %0, 0 17 ; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 1, i32 0, i64 -1) 18 br i1 %cmp, label %if.then, label %if.else 19 ; CHECK: br i1 %cmp, label %if.then, label %if.else, !prof ![[PD1:[0-9]+]] 20 21if.then: 22 ; CHECK: call {{.*}}, !dbg ![[#PROBE1:]], !prof ![[PROF1:[0-9]+]] 23 call void %f(i32 1) 24 ; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 2, i32 0, i64 -1) 25 store i32 1, ptr %retval, align 4 26 br label %return 27 28if.else: 29 ; CHECK: call {{.*}}, !dbg ![[#PROBE2:]], !prof ![[PROF2:[0-9]+]] 30 call void %f(i32 2) 31 ; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 4, i32 0, i64 -1) 32 store i32 2, ptr %retval, align 4 33 br label %return 34 35return: 36 ; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 6, i32 0, i64 -1) 37 %1 = load i32, ptr %retval, align 4 38 ret i32 %1 39} 40 41attributes #0 = {"use-sample-profile"} 42 43; CHECK: ![[PD1]] = !{!"branch_weights", i32 8, i32 7} 44; CHECK: ![[#PROBE1]] = !DILocation(line: 0, scope: ![[#SCOPE1:]]) 45;; A discriminator of 387973151 which is 0x1720001f in hexdecimal, stands for an indirect call probe 46;; with an index of 3. 47; CHECK: ![[#SCOPE1]] = !DILexicalBlockFile(scope: ![[#]], file: ![[#]], discriminator: 387973151) 48; CHECK: ![[PROF1]] = !{!"VP", i32 0, i64 7, i64 9191153033785521275, i64 5, i64 -1069303473483922844, i64 2} 49;; A discriminator of 387973167 which is 0x1720002f in hexdecimal, stands for an indirect call probe 50;; with an index of 5. 51; CHECK: ![[#PROBE2]] = !DILocation(line: 0, scope: ![[#SCOPE2:]]) 52; CHECK: ![[#SCOPE2]] = !DILexicalBlockFile(scope: ![[#]], file: ![[#]], discriminator: 387973167) 53; CHECK: ![[PROF2]] = !{!"VP", i32 0, i64 6, i64 -1069303473483922844, i64 4, i64 9191153033785521275, i64 2} 54 55!llvm.module.flags = !{!9, !10} 56 57!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1) 58!1 = !DIFile(filename: "test.c", directory: "") 59!2 = !{} 60!4 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 1, type: !5, unit: !0, retainedNodes: !2) 61!5 = !DISubroutineType(types: !6) 62!6 = !{!7} 63!7 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed) 64!9 = !{i32 2, !"Dwarf Version", i32 4} 65!10 = !{i32 2, !"Debug Info Version", i32 3} 66 67; Checking to see if YAML file is generated and contains remarks 68;YAML: --- !Analysis 69;YAML-NEXT: Pass: sample-profile 70;YAML-NEXT: Name: AppliedSamples 71;YAML-NEXT: DebugLoc: { File: test.c, Line: 0, Column: 0 } 72;YAML-NEXT: Function: foo 73;YAML-NEXT: Args: 74;YAML-NEXT: - String: 'Applied ' 75;YAML-NEXT: - NumSamples: '13' 76;YAML-NEXT: - String: ' samples from profile (ProbeId=' 77;YAML-NEXT: - ProbeId: '1' 78;YAML-NEXT: - String: ', Factor=' 79;YAML-NEXT: - Factor: '1.000000e+00' 80;YAML-NEXT: - String: ', OriginalSamples=' 81;YAML-NEXT: - OriginalSamples: '13' 82;YAML-NEXT: - String: ')' 83;YAML: --- !Analysis 84;YAML-NEXT: Pass: sample-profile 85;YAML-NEXT: Name: AppliedSamples 86;YAML-NEXT: DebugLoc: { File: test.c, Line: 0, Column: 0 } 87;YAML-NEXT: Function: foo 88;YAML-NEXT: Args: 89;YAML-NEXT: - String: 'Applied ' 90;YAML-NEXT: - NumSamples: '7' 91;YAML-NEXT: - String: ' samples from profile (ProbeId=' 92;YAML-NEXT: - ProbeId: '3' 93;YAML-NEXT: - String: ', Factor=' 94;YAML-NEXT: - Factor: '1.000000e+00' 95;YAML-NEXT: - String: ', OriginalSamples=' 96;YAML-NEXT: - OriginalSamples: '7' 97;YAML-NEXT: - String: ')' 98;YAML: --- !Analysis 99;YAML-NEXT: Pass: sample-profile 100;YAML-NEXT: Name: AppliedSamples 101;YAML-NEXT: DebugLoc: { File: test.c, Line: 0, Column: 0 } 102;YAML-NEXT: Function: foo 103;YAML-NEXT: Args: 104;YAML-NEXT: - String: 'Applied ' 105;YAML-NEXT: - NumSamples: '7' 106;YAML-NEXT: - String: ' samples from profile (ProbeId=' 107;YAML-NEXT: - ProbeId: '2' 108;YAML-NEXT: - String: ', Factor=' 109;YAML-NEXT: - Factor: '1.000000e+00' 110;YAML-NEXT: - String: ', OriginalSamples=' 111;YAML-NEXT: - OriginalSamples: '7' 112;YAML-NEXT: - String: ')' 113;YAML: --- !Analysis 114;YAML-NEXT: Pass: sample-profile 115;YAML-NEXT: Name: AppliedSamples 116;YAML-NEXT: DebugLoc: { File: test.c, Line: 0, Column: 0 } 117;YAML-NEXT: Function: foo 118;YAML-NEXT: Args: 119;YAML-NEXT: - String: 'Applied ' 120;YAML-NEXT: - NumSamples: '6' 121;YAML-NEXT: - String: ' samples from profile (ProbeId=' 122;YAML-NEXT: - ProbeId: '5' 123;YAML-NEXT: - String: ', Factor=' 124;YAML-NEXT: - Factor: '1.000000e+00' 125;YAML-NEXT: - String: ', OriginalSamples=' 126;YAML-NEXT: - OriginalSamples: '6' 127;YAML-NEXT: - String: ')' 128;YAML: --- !Analysis 129;YAML-NEXT: Pass: sample-profile 130;YAML-NEXT: Name: AppliedSamples 131;YAML-NEXT: DebugLoc: { File: test.c, Line: 0, Column: 0 } 132;YAML-NEXT: Function: foo 133;YAML-NEXT: Args: 134;YAML-NEXT: - String: 'Applied ' 135;YAML-NEXT: - NumSamples: '6' 136;YAML-NEXT: - String: ' samples from profile (ProbeId=' 137;YAML-NEXT: - ProbeId: '4' 138;YAML-NEXT: - String: ', Factor=' 139;YAML-NEXT: - Factor: '1.000000e+00' 140;YAML-NEXT: - String: ', OriginalSamples=' 141;YAML-NEXT: - OriginalSamples: '6' 142;YAML-NEXT: - String: ')' 143;YAML: --- !Analysis 144;YAML-NEXT: Pass: sample-profile 145;YAML-NEXT: Name: AppliedSamples 146;YAML-NEXT: DebugLoc: { File: test.c, Line: 0, Column: 0 } 147;YAML-NEXT: Function: foo 148;YAML-NEXT: Args: 149;YAML-NEXT: - String: 'Applied ' 150;YAML-NEXT: - NumSamples: '13' 151;YAML-NEXT: - String: ' samples from profile (ProbeId=' 152;YAML-NEXT: - ProbeId: '6' 153;YAML-NEXT: - String: ', Factor=' 154;YAML-NEXT: - Factor: '1.000000e+00' 155;YAML-NEXT: - String: ', OriginalSamples=' 156;YAML-NEXT: - OriginalSamples: '13' 157;YAML-NEXT: - String: ')' 158