2014-10-30 18:00:06 +00:00
|
|
|
; The two profiles used in this test are the same but encoded in different
|
|
|
|
; formats. This checks that we produce the same profile annotations regardless
|
|
|
|
; of the profile format.
|
|
|
|
;
|
|
|
|
; RUN: opt < %s -sample-profile -sample-profile-file=%S/Inputs/fnptr.prof | opt -analyze -branch-prob | FileCheck %s
|
|
|
|
; RUN: opt < %s -sample-profile -sample-profile-file=%S/Inputs/fnptr.binprof | opt -analyze -branch-prob | FileCheck %s
|
|
|
|
|
|
|
|
; CHECK: edge for.body3 -> if.then probability is 534 / 2598 = 20.5543%
|
|
|
|
; CHECK: edge for.body3 -> if.else probability is 2064 / 2598 = 79.4457%
|
|
|
|
; CHECK: edge for.inc -> for.inc12 probability is 1052 / 2598 = 40.4927%
|
|
|
|
; CHECK: edge for.inc -> for.body3 probability is 1546 / 2598 = 59.5073%
|
|
|
|
; CHECK: edge for.inc12 -> for.end14 probability is 518 / 1052 = 49.2395%
|
|
|
|
; CHECK: edge for.inc12 -> for.cond1.preheader probability is 534 / 1052 = 50.7605%
|
|
|
|
|
|
|
|
; Original C++ test case.
|
|
|
|
;
|
|
|
|
; #include <stdlib.h>
|
|
|
|
; #include <math.h>
|
|
|
|
; #include <stdio.h>
|
|
|
|
;
|
|
|
|
; #define N 10000
|
|
|
|
; #define M 6000
|
|
|
|
;
|
|
|
|
; double foo(int x) {
|
|
|
|
; return x * sin((double)x);
|
|
|
|
; }
|
|
|
|
;
|
|
|
|
; double bar(int x) {
|
|
|
|
; return x - cos((double)x);
|
|
|
|
; }
|
|
|
|
;
|
|
|
|
; int main() {
|
|
|
|
; double (*fptr)(int);
|
|
|
|
; double S = 0;
|
|
|
|
; for (int i = 0; i < N; i++)
|
|
|
|
; for (int j = 0; j < M; j++) {
|
|
|
|
; fptr = (rand() % 100 < 30) ? foo : bar;
|
|
|
|
; if (rand() % 100 < 10)
|
|
|
|
; S += (*fptr)(i + j * 300);
|
|
|
|
; else
|
|
|
|
; S += (*fptr)(i - j / 840);
|
|
|
|
; }
|
|
|
|
; printf("S = %lf\n", S);
|
|
|
|
; return 0;
|
|
|
|
; }
|
|
|
|
|
|
|
|
@.str = private unnamed_addr constant [9 x i8] c"S = %lf\0A\00", align 1
|
|
|
|
|
|
|
|
define double @_Z3fooi(i32 %x) #0 {
|
|
|
|
entry:
|
|
|
|
%conv = sitofp i32 %x to double, !dbg !2
|
|
|
|
%call = tail call double @sin(double %conv) #3, !dbg !8
|
|
|
|
%mul = fmul double %conv, %call, !dbg !8
|
|
|
|
ret double %mul, !dbg !8
|
|
|
|
}
|
|
|
|
|
|
|
|
declare double @sin(double) #1
|
|
|
|
|
|
|
|
define double @_Z3bari(i32 %x) #0 {
|
|
|
|
entry:
|
|
|
|
%conv = sitofp i32 %x to double, !dbg !9
|
|
|
|
%call = tail call double @cos(double %conv) #3, !dbg !11
|
|
|
|
%sub = fsub double %conv, %call, !dbg !11
|
|
|
|
ret double %sub, !dbg !11
|
|
|
|
}
|
|
|
|
|
|
|
|
declare double @cos(double) #1
|
|
|
|
|
|
|
|
define i32 @main() #2 {
|
|
|
|
entry:
|
|
|
|
br label %for.cond1.preheader, !dbg !12
|
|
|
|
|
|
|
|
for.cond1.preheader: ; preds = %for.inc12, %entry
|
|
|
|
%i.025 = phi i32 [ 0, %entry ], [ %inc13, %for.inc12 ]
|
|
|
|
%S.024 = phi double [ 0.000000e+00, %entry ], [ %S.2.lcssa, %for.inc12 ]
|
|
|
|
br label %for.body3, !dbg !14
|
|
|
|
|
|
|
|
for.body3: ; preds = %for.inc, %for.cond1.preheader
|
|
|
|
%j.023 = phi i32 [ 0, %for.cond1.preheader ], [ %inc, %for.inc ]
|
|
|
|
%S.122 = phi double [ %S.024, %for.cond1.preheader ], [ %S.2, %for.inc ]
|
|
|
|
%call = tail call i32 @rand() #3, !dbg !15
|
|
|
|
%rem = srem i32 %call, 100, !dbg !15
|
|
|
|
%cmp4 = icmp slt i32 %rem, 30, !dbg !15
|
|
|
|
%_Z3fooi._Z3bari = select i1 %cmp4, double (i32)* @_Z3fooi, double (i32)* @_Z3bari, !dbg !15
|
|
|
|
%call5 = tail call i32 @rand() #3, !dbg !16
|
|
|
|
%rem6 = srem i32 %call5, 100, !dbg !16
|
|
|
|
%cmp7 = icmp slt i32 %rem6, 10, !dbg !16
|
|
|
|
br i1 %cmp7, label %if.then, label %if.else, !dbg !16, !prof !17
|
|
|
|
|
|
|
|
if.then: ; preds = %for.body3
|
|
|
|
%mul = mul nsw i32 %j.023, 300, !dbg !18
|
|
|
|
%add = add nsw i32 %mul, %i.025, !dbg !18
|
|
|
|
%call8 = tail call double %_Z3fooi._Z3bari(i32 %add), !dbg !18
|
|
|
|
br label %for.inc, !dbg !18
|
|
|
|
|
|
|
|
if.else: ; preds = %for.body3
|
|
|
|
%div = sdiv i32 %j.023, 840, !dbg !19
|
|
|
|
%sub = sub nsw i32 %i.025, %div, !dbg !19
|
|
|
|
%call10 = tail call double %_Z3fooi._Z3bari(i32 %sub), !dbg !19
|
|
|
|
br label %for.inc
|
|
|
|
|
|
|
|
for.inc: ; preds = %if.then, %if.else
|
|
|
|
%call8.pn = phi double [ %call8, %if.then ], [ %call10, %if.else ]
|
|
|
|
%S.2 = fadd double %S.122, %call8.pn, !dbg !18
|
|
|
|
%inc = add nsw i32 %j.023, 1, !dbg !20
|
|
|
|
%exitcond = icmp eq i32 %j.023, 5999, !dbg !14
|
|
|
|
br i1 %exitcond, label %for.inc12, label %for.body3, !dbg !14, !prof !21
|
|
|
|
|
|
|
|
for.inc12: ; preds = %for.inc
|
|
|
|
%S.2.lcssa = phi double [ %S.2, %for.inc ]
|
|
|
|
%inc13 = add nsw i32 %i.025, 1, !dbg !22
|
|
|
|
%exitcond26 = icmp eq i32 %i.025, 9999, !dbg !12
|
|
|
|
br i1 %exitcond26, label %for.end14, label %for.cond1.preheader, !dbg !12, !prof !23
|
|
|
|
|
|
|
|
for.end14: ; preds = %for.inc12
|
|
|
|
%S.2.lcssa.lcssa = phi double [ %S.2.lcssa, %for.inc12 ]
|
[opaque pointer type] Add textual IR support for explicit type parameter to the call instruction
See r230786 and r230794 for similar changes to gep and load
respectively.
Call is a bit different because it often doesn't have a single explicit
type - usually the type is deduced from the arguments, and just the
return type is explicit. In those cases there's no need to change the
IR.
When that's not the case, the IR usually contains the pointer type of
the first operand - but since typed pointers are going away, that
representation is insufficient so I'm just stripping the "pointerness"
of the explicit type away.
This does make the IR a bit weird - it /sort of/ reads like the type of
the first operand: "call void () %x(" but %x is actually of type "void
()*" and will eventually be just of type "ptr". But this seems not too
bad and I don't think it would benefit from repeating the type
("void (), void () * %x(" and then eventually "void (), ptr %x(") as has
been done with gep and load.
This also has a side benefit: since the explicit type is no longer a
pointer, there's no ambiguity between an explicit type and a function
that returns a function pointer. Previously this case needed an explicit
type (eg: a function returning a void() function was written as
"call void () () * @x(" rather than "call void () * @x(" because of the
ambiguity between a function returning a pointer to a void() function
and a function returning void).
No ambiguity means even function pointer return types can just be
written alone, without writing the whole function's type.
This leaves /only/ the varargs case where the explicit type is required.
Given the special type syntax in call instructions, the regex-fu used
for migration was a bit more involved in its own unique way (as every
one of these is) so here it is. Use it in conjunction with the apply.sh
script and associated find/xargs commands I've provided in rr230786 to
migrate your out of tree tests. Do let me know if any of this doesn't
cover your cases & we can iterate on a more general script/regexes to
help others with out of tree tests.
About 9 test cases couldn't be automatically migrated - half of those
were functions returning function pointers, where I just had to manually
delete the function argument types now that we didn't need an explicit
function type there. The other half were typedefs of function types used
in calls - just had to manually drop the * from those.
import fileinput
import sys
import re
pat = re.compile(r'((?:=|:|^|\s)call\s(?:[^@]*?))(\s*$|\s*(?:(?:\[\[[a-zA-Z0-9_]+\]\]|[@%](?:(")?[\\\?@a-zA-Z0-9_.]*?(?(3)"|)|{{.*}}))(?:\(|$)|undef|inttoptr|bitcast|null|asm).*$)')
addrspace_end = re.compile(r"addrspace\(\d+\)\s*\*$")
func_end = re.compile("(?:void.*|\)\s*)\*$")
def conv(match, line):
if not match or re.search(addrspace_end, match.group(1)) or not re.search(func_end, match.group(1)):
return line
return line[:match.start()] + match.group(1)[:match.group(1).rfind('*')].rstrip() + match.group(2) + line[match.end():]
for line in sys.stdin:
sys.stdout.write(conv(re.search(pat, line), line))
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@235145 91177308-0d34-0410-b5e6-96231b3b80d8
2015-04-16 23:24:18 +00:00
|
|
|
%call15 = tail call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), double %S.2.lcssa.lcssa), !dbg !24
|
2014-10-30 18:00:06 +00:00
|
|
|
ret i32 0, !dbg !25
|
|
|
|
}
|
|
|
|
|
|
|
|
; Function Attrs: nounwind
|
|
|
|
declare i32 @rand() #1
|
|
|
|
|
|
|
|
; Function Attrs: nounwind
|
|
|
|
declare i32 @printf(i8* nocapture readonly, ...) #1
|
|
|
|
|
|
|
|
!llvm.module.flags = !{!0}
|
|
|
|
!llvm.ident = !{!1}
|
|
|
|
|
2015-03-03 17:24:31 +00:00
|
|
|
!0 = !{i32 2, !"Debug Info Version", i32 3}
|
IR: Make metadata typeless in assembly
Now that `Metadata` is typeless, reflect that in the assembly. These
are the matching assembly changes for the metadata/value split in
r223802.
- Only use the `metadata` type when referencing metadata from a call
intrinsic -- i.e., only when it's used as a `Value`.
- Stop pretending that `ValueAsMetadata` is wrapped in an `MDNode`
when referencing it from call intrinsics.
So, assembly like this:
define @foo(i32 %v) {
call void @llvm.foo(metadata !{i32 %v}, metadata !0)
call void @llvm.foo(metadata !{i32 7}, metadata !0)
call void @llvm.foo(metadata !1, metadata !0)
call void @llvm.foo(metadata !3, metadata !0)
call void @llvm.foo(metadata !{metadata !3}, metadata !0)
ret void, !bar !2
}
!0 = metadata !{metadata !2}
!1 = metadata !{i32* @global}
!2 = metadata !{metadata !3}
!3 = metadata !{}
turns into this:
define @foo(i32 %v) {
call void @llvm.foo(metadata i32 %v, metadata !0)
call void @llvm.foo(metadata i32 7, metadata !0)
call void @llvm.foo(metadata i32* @global, metadata !0)
call void @llvm.foo(metadata !3, metadata !0)
call void @llvm.foo(metadata !{!3}, metadata !0)
ret void, !bar !2
}
!0 = !{!2}
!1 = !{i32* @global}
!2 = !{!3}
!3 = !{}
I wrote an upgrade script that handled almost all of the tests in llvm
and many of the tests in cfe (even handling many `CHECK` lines). I've
attached it (or will attach it in a moment if you're speedy) to PR21532
to help everyone update their out-of-tree testcases.
This is part of PR21532.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@224257 91177308-0d34-0410-b5e6-96231b3b80d8
2014-12-15 19:07:53 +00:00
|
|
|
!1 = !{!"clang version 3.6.0 "}
|
2015-04-29 16:38:44 +00:00
|
|
|
!2 = !DILocation(line: 9, column: 3, scope: !3)
|
|
|
|
!3 = !DISubprogram(name: "foo", line: 8, isLocal: false, isDefinition: true, flags: DIFlagPrototyped, isOptimized: true, scopeLine: 8, file: !4, scope: !5, type: !6, function: double (i32)* @_Z3fooi, variables: !7)
|
|
|
|
!4 = !DIFile(filename: "fnptr.cc", directory: ".")
|
|
|
|
!5 = !DIFile(filename: "fnptr.cc", directory: ".")
|
|
|
|
!6 = !DISubroutineType(types: !7)
|
IR: Make metadata typeless in assembly
Now that `Metadata` is typeless, reflect that in the assembly. These
are the matching assembly changes for the metadata/value split in
r223802.
- Only use the `metadata` type when referencing metadata from a call
intrinsic -- i.e., only when it's used as a `Value`.
- Stop pretending that `ValueAsMetadata` is wrapped in an `MDNode`
when referencing it from call intrinsics.
So, assembly like this:
define @foo(i32 %v) {
call void @llvm.foo(metadata !{i32 %v}, metadata !0)
call void @llvm.foo(metadata !{i32 7}, metadata !0)
call void @llvm.foo(metadata !1, metadata !0)
call void @llvm.foo(metadata !3, metadata !0)
call void @llvm.foo(metadata !{metadata !3}, metadata !0)
ret void, !bar !2
}
!0 = metadata !{metadata !2}
!1 = metadata !{i32* @global}
!2 = metadata !{metadata !3}
!3 = metadata !{}
turns into this:
define @foo(i32 %v) {
call void @llvm.foo(metadata i32 %v, metadata !0)
call void @llvm.foo(metadata i32 7, metadata !0)
call void @llvm.foo(metadata i32* @global, metadata !0)
call void @llvm.foo(metadata !3, metadata !0)
call void @llvm.foo(metadata !{!3}, metadata !0)
ret void, !bar !2
}
!0 = !{!2}
!1 = !{i32* @global}
!2 = !{!3}
!3 = !{}
I wrote an upgrade script that handled almost all of the tests in llvm
and many of the tests in cfe (even handling many `CHECK` lines). I've
attached it (or will attach it in a moment if you're speedy) to PR21532
to help everyone update their out-of-tree testcases.
This is part of PR21532.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@224257 91177308-0d34-0410-b5e6-96231b3b80d8
2014-12-15 19:07:53 +00:00
|
|
|
!7 = !{}
|
2015-04-29 16:38:44 +00:00
|
|
|
!8 = !DILocation(line: 9, column: 14, scope: !3)
|
|
|
|
!9 = !DILocation(line: 13, column: 3, scope: !10)
|
|
|
|
!10 = !DISubprogram(name: "bar", line: 12, isLocal: false, isDefinition: true, flags: DIFlagPrototyped, isOptimized: true, scopeLine: 12, file: !4, scope: !5, type: !6, function: double (i32)* @_Z3bari, variables: !7)
|
|
|
|
!11 = !DILocation(line: 13, column: 14, scope: !10)
|
|
|
|
!12 = !DILocation(line: 19, column: 3, scope: !13)
|
|
|
|
!13 = !DISubprogram(name: "main", line: 16, isLocal: false, isDefinition: true, flags: DIFlagPrototyped, isOptimized: true, scopeLine: 16, file: !4, scope: !5, type: !6, function: i32 ()* @main, variables: !7)
|
|
|
|
!14 = !DILocation(line: 20, column: 5, scope: !13)
|
|
|
|
!15 = !DILocation(line: 21, column: 15, scope: !13)
|
|
|
|
!16 = !DILocation(line: 22, column: 11, scope: !13)
|
IR: Make metadata typeless in assembly
Now that `Metadata` is typeless, reflect that in the assembly. These
are the matching assembly changes for the metadata/value split in
r223802.
- Only use the `metadata` type when referencing metadata from a call
intrinsic -- i.e., only when it's used as a `Value`.
- Stop pretending that `ValueAsMetadata` is wrapped in an `MDNode`
when referencing it from call intrinsics.
So, assembly like this:
define @foo(i32 %v) {
call void @llvm.foo(metadata !{i32 %v}, metadata !0)
call void @llvm.foo(metadata !{i32 7}, metadata !0)
call void @llvm.foo(metadata !1, metadata !0)
call void @llvm.foo(metadata !3, metadata !0)
call void @llvm.foo(metadata !{metadata !3}, metadata !0)
ret void, !bar !2
}
!0 = metadata !{metadata !2}
!1 = metadata !{i32* @global}
!2 = metadata !{metadata !3}
!3 = metadata !{}
turns into this:
define @foo(i32 %v) {
call void @llvm.foo(metadata i32 %v, metadata !0)
call void @llvm.foo(metadata i32 7, metadata !0)
call void @llvm.foo(metadata i32* @global, metadata !0)
call void @llvm.foo(metadata !3, metadata !0)
call void @llvm.foo(metadata !{!3}, metadata !0)
ret void, !bar !2
}
!0 = !{!2}
!1 = !{i32* @global}
!2 = !{!3}
!3 = !{}
I wrote an upgrade script that handled almost all of the tests in llvm
and many of the tests in cfe (even handling many `CHECK` lines). I've
attached it (or will attach it in a moment if you're speedy) to PR21532
to help everyone update their out-of-tree testcases.
This is part of PR21532.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@224257 91177308-0d34-0410-b5e6-96231b3b80d8
2014-12-15 19:07:53 +00:00
|
|
|
!17 = !{!"branch_weights", i32 534, i32 2064}
|
2015-04-29 16:38:44 +00:00
|
|
|
!18 = !DILocation(line: 23, column: 14, scope: !13)
|
|
|
|
!19 = !DILocation(line: 25, column: 14, scope: !13)
|
|
|
|
!20 = !DILocation(line: 20, column: 28, scope: !13)
|
IR: Make metadata typeless in assembly
Now that `Metadata` is typeless, reflect that in the assembly. These
are the matching assembly changes for the metadata/value split in
r223802.
- Only use the `metadata` type when referencing metadata from a call
intrinsic -- i.e., only when it's used as a `Value`.
- Stop pretending that `ValueAsMetadata` is wrapped in an `MDNode`
when referencing it from call intrinsics.
So, assembly like this:
define @foo(i32 %v) {
call void @llvm.foo(metadata !{i32 %v}, metadata !0)
call void @llvm.foo(metadata !{i32 7}, metadata !0)
call void @llvm.foo(metadata !1, metadata !0)
call void @llvm.foo(metadata !3, metadata !0)
call void @llvm.foo(metadata !{metadata !3}, metadata !0)
ret void, !bar !2
}
!0 = metadata !{metadata !2}
!1 = metadata !{i32* @global}
!2 = metadata !{metadata !3}
!3 = metadata !{}
turns into this:
define @foo(i32 %v) {
call void @llvm.foo(metadata i32 %v, metadata !0)
call void @llvm.foo(metadata i32 7, metadata !0)
call void @llvm.foo(metadata i32* @global, metadata !0)
call void @llvm.foo(metadata !3, metadata !0)
call void @llvm.foo(metadata !{!3}, metadata !0)
ret void, !bar !2
}
!0 = !{!2}
!1 = !{i32* @global}
!2 = !{!3}
!3 = !{}
I wrote an upgrade script that handled almost all of the tests in llvm
and many of the tests in cfe (even handling many `CHECK` lines). I've
attached it (or will attach it in a moment if you're speedy) to PR21532
to help everyone update their out-of-tree testcases.
This is part of PR21532.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@224257 91177308-0d34-0410-b5e6-96231b3b80d8
2014-12-15 19:07:53 +00:00
|
|
|
!21 = !{!"branch_weights", i32 0, i32 1075}
|
2015-04-29 16:38:44 +00:00
|
|
|
!22 = !DILocation(line: 19, column: 26, scope: !13)
|
IR: Make metadata typeless in assembly
Now that `Metadata` is typeless, reflect that in the assembly. These
are the matching assembly changes for the metadata/value split in
r223802.
- Only use the `metadata` type when referencing metadata from a call
intrinsic -- i.e., only when it's used as a `Value`.
- Stop pretending that `ValueAsMetadata` is wrapped in an `MDNode`
when referencing it from call intrinsics.
So, assembly like this:
define @foo(i32 %v) {
call void @llvm.foo(metadata !{i32 %v}, metadata !0)
call void @llvm.foo(metadata !{i32 7}, metadata !0)
call void @llvm.foo(metadata !1, metadata !0)
call void @llvm.foo(metadata !3, metadata !0)
call void @llvm.foo(metadata !{metadata !3}, metadata !0)
ret void, !bar !2
}
!0 = metadata !{metadata !2}
!1 = metadata !{i32* @global}
!2 = metadata !{metadata !3}
!3 = metadata !{}
turns into this:
define @foo(i32 %v) {
call void @llvm.foo(metadata i32 %v, metadata !0)
call void @llvm.foo(metadata i32 7, metadata !0)
call void @llvm.foo(metadata i32* @global, metadata !0)
call void @llvm.foo(metadata !3, metadata !0)
call void @llvm.foo(metadata !{!3}, metadata !0)
ret void, !bar !2
}
!0 = !{!2}
!1 = !{i32* @global}
!2 = !{!3}
!3 = !{}
I wrote an upgrade script that handled almost all of the tests in llvm
and many of the tests in cfe (even handling many `CHECK` lines). I've
attached it (or will attach it in a moment if you're speedy) to PR21532
to help everyone update their out-of-tree testcases.
This is part of PR21532.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@224257 91177308-0d34-0410-b5e6-96231b3b80d8
2014-12-15 19:07:53 +00:00
|
|
|
!23 = !{!"branch_weights", i32 0, i32 534}
|
2015-04-29 16:38:44 +00:00
|
|
|
!24 = !DILocation(line: 27, column: 3, scope: !13)
|
|
|
|
!25 = !DILocation(line: 28, column: 3, scope: !13)
|