brintos

brintos / llvm-project-archived public Read only

0
0
Text · 6.4 KiB · 55ee75e Raw
158 lines · plain
1; The two profiles used in this test are the same but encoded in different2; formats. This checks that we produce the same profile annotations regardless3; of the profile format.4;5; RUN: opt < %s -passes=sample-profile -sample-profile-file=%S/Inputs/fnptr.prof | opt -passes='print<branch-prob>' -disable-output 2>&1 | FileCheck %s6; RUN: opt < %s -passes=sample-profile -sample-profile-file=%S/Inputs/fnptr.binprof | opt -passes='print<branch-prob>' -disable-output 2>&1 | FileCheck %s7 8; CHECK:   edge %for.body3 -> %if.then probability is 0x1a56a56a / 0x80000000 = 20.58%9; CHECK:   edge %for.body3 -> %if.else probability is 0x65a95a96 / 0x80000000 = 79.42%10; CHECK:   edge %for.inc -> %for.inc12 probability is 0x000fbd1c / 0x80000000 = 0.05%11; CHECK:   edge %for.inc -> %for.body3 probability is 0x7ff042e4 / 0x80000000 = 99.95%12; CHECK:   edge %for.inc12 -> %for.end14 probability is 0x04000000 / 0x80000000 = 3.12%13; CHECK:   edge %for.inc12 -> %for.cond1.preheader probability is 0x7c000000 / 0x80000000 = 96.88%14 15; Original C++ test case.16;17; #include <stdlib.h>18; #include <math.h>19; #include <stdio.h>20;21; #define N 1000022; #define M 600023;24; double foo(int x) {25;   return x * sin((double)x);26; }27;28; double bar(int x) {29;   return x - cos((double)x);30; }31;32; int main() {33;   double (*fptr)(int);34;   double S = 0;35;   for (int i = 0; i < N; i++)36;     for (int j = 0; j < M; j++) {37;       fptr = (rand() % 100 < 30) ? foo : bar;38;       if (rand() % 100 < 10)39;         S += (*fptr)(i + j * 300);40;       else41;         S += (*fptr)(i - j / 840);42;     }43;   printf("S = %lf\n", S);44;   return 0;45; }46 47@.str = private unnamed_addr constant [9 x i8] c"S = %lf\0A\00", align 148 49define double @_Z3fooi(i32 %x) #0 !dbg !3 {50entry:51  %conv = sitofp i32 %x to double, !dbg !252  %call = tail call double @sin(double %conv) #3, !dbg !853  %mul = fmul double %conv, %call, !dbg !854  ret double %mul, !dbg !855}56 57declare double @sin(double) #158 59define double @_Z3bari(i32 %x) #0 !dbg !10 {60entry:61  %conv = sitofp i32 %x to double, !dbg !962  %call = tail call double @cos(double %conv) #3, !dbg !1163  %sub = fsub double %conv, %call, !dbg !1164  ret double %sub, !dbg !1165}66 67declare double @cos(double) #168 69define i32 @main() #2 !dbg !13 {70entry:71  br label %for.cond1.preheader, !dbg !1272 73for.cond1.preheader:                              ; preds = %for.inc12, %entry74  %i.025 = phi i32 [ 0, %entry ], [ %inc13, %for.inc12 ]75  %S.024 = phi double [ 0.000000e+00, %entry ], [ %S.2.lcssa, %for.inc12 ]76  br label %for.body3, !dbg !1477 78for.body3:                                        ; preds = %for.inc, %for.cond1.preheader79  %j.023 = phi i32 [ 0, %for.cond1.preheader ], [ %inc, %for.inc ]80  %S.122 = phi double [ %S.024, %for.cond1.preheader ], [ %S.2, %for.inc ]81  %call = tail call i32 @rand() #3, !dbg !1582  %rem = srem i32 %call, 100, !dbg !1583  %cmp4 = icmp slt i32 %rem, 30, !dbg !1584  %_Z3fooi._Z3bari = select i1 %cmp4, ptr @_Z3fooi, ptr @_Z3bari, !dbg !1585  %call5 = tail call i32 @rand() #3, !dbg !1686  %rem6 = srem i32 %call5, 100, !dbg !1687  %cmp7 = icmp slt i32 %rem6, 10, !dbg !1688  br i1 %cmp7, label %if.then, label %if.else, !dbg !1689 90if.then:                                          ; preds = %for.body391  %mul = mul nsw i32 %j.023, 300, !dbg !1892  %add = add nsw i32 %mul, %i.025, !dbg !1893  %call8 = tail call double %_Z3fooi._Z3bari(i32 %add), !dbg !1894  br label %for.inc, !dbg !1895 96if.else:                                          ; preds = %for.body397  %div = sdiv i32 %j.023, 840, !dbg !1998  %sub = sub nsw i32 %i.025, %div, !dbg !1999  %call10 = tail call double %_Z3fooi._Z3bari(i32 %sub), !dbg !19100  br label %for.inc101 102for.inc:                                          ; preds = %if.then, %if.else103  %call8.pn = phi double [ %call8, %if.then ], [ %call10, %if.else ]104  %S.2 = fadd double %S.122, %call8.pn, !dbg !18105  %inc = add nsw i32 %j.023, 1, !dbg !20106  %exitcond = icmp eq i32 %j.023, 5999, !dbg !14107  br i1 %exitcond, label %for.inc12, label %for.body3, !dbg !14108 109for.inc12:                                        ; preds = %for.inc110  %S.2.lcssa = phi double [ %S.2, %for.inc ]111  %inc13 = add nsw i32 %i.025, 1, !dbg !22112  %exitcond26 = icmp eq i32 %i.025, 9999, !dbg !12113  br i1 %exitcond26, label %for.end14, label %for.cond1.preheader, !dbg !12114 115for.end14:                                        ; preds = %for.inc12116  %S.2.lcssa.lcssa = phi double [ %S.2.lcssa, %for.inc12 ]117  %call15 = tail call i32 (ptr, ...) @printf(ptr @.str, double %S.2.lcssa.lcssa), !dbg !24118  ret i32 0, !dbg !25119}120 121; Function Attrs: nounwind122declare i32 @rand() #1123 124; Function Attrs: nounwind125declare i32 @printf(ptr nocapture readonly, ...) #1126 127attributes #0 = {"use-sample-profile"}128attributes #2 = {"use-sample-profile"}129 130!llvm.module.flags = !{!0}131!llvm.ident = !{!1}132!llvm.dbg.cu = !{!26}133 134!0 = !{i32 2, !"Debug Info Version", i32 3}135!1 = !{!"clang version 3.6.0 "}136!2 = !DILocation(line: 9, column: 3, scope: !3)137!3 = distinct !DISubprogram(name: "foo", line: 8, isLocal: false, isDefinition: true, flags: DIFlagPrototyped, isOptimized: true, unit: !26, scopeLine: 8, file: !4, scope: !5, type: !6, retainedNodes: !7)138!4 = !DIFile(filename: "fnptr.cc", directory: ".")139!5 = !DIFile(filename: "fnptr.cc", directory: ".")140!6 = !DISubroutineType(types: !7)141!7 = !{}142!8 = !DILocation(line: 9, column: 14, scope: !3)143!9 = !DILocation(line: 13, column: 3, scope: !10)144!10 = distinct !DISubprogram(name: "bar", line: 12, isLocal: false, isDefinition: true, flags: DIFlagPrototyped, isOptimized: true, unit: !26, scopeLine: 12, file: !4, scope: !5, type: !6, retainedNodes: !7)145!11 = !DILocation(line: 13, column: 14, scope: !10)146!12 = !DILocation(line: 19, column: 3, scope: !13)147!13 = distinct !DISubprogram(name: "main", line: 16, isLocal: false, isDefinition: true, flags: DIFlagPrototyped, isOptimized: true, unit: !26, scopeLine: 16, file: !4, scope: !5, type: !6, retainedNodes: !7)148!14 = !DILocation(line: 20, column: 5, scope: !13)149!15 = !DILocation(line: 21, column: 15, scope: !13)150!16 = !DILocation(line: 22, column: 11, scope: !13)151!18 = !DILocation(line: 23, column: 14, scope: !13)152!19 = !DILocation(line: 25, column: 14, scope: !13)153!20 = !DILocation(line: 20, column: 28, scope: !13)154!22 = !DILocation(line: 19, column: 26, scope: !13)155!24 = !DILocation(line: 27, column: 3, scope: !13)156!25 = !DILocation(line: 28, column: 3, scope: !13)157!26 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, producer: "clang version 3.5 ", isOptimized: false, emissionKind: FullDebug, file: !4)158