2013-07-30 04:18:19 +08:00
; RUN: opt -S -loop-rotate < %s | FileCheck %s
2011-02-15 07:03:23 +08:00
Move the complex address expression out of DIVariable and into an extra
argument of the llvm.dbg.declare/llvm.dbg.value intrinsics.
Previously, DIVariable was a variable-length field that has an optional
reference to a Metadata array consisting of a variable number of
complex address expressions. In the case of OpPiece expressions this is
wasting a lot of storage in IR, because when an aggregate type is, e.g.,
SROA'd into all of its n individual members, the IR will contain n copies
of the DIVariable, all alike, only differing in the complex address
reference at the end.
By making the complex address into an extra argument of the
dbg.value/dbg.declare intrinsics, all of the pieces can reference the
same variable and the complex address expressions can be uniqued across
the CU, too.
Down the road, this will allow us to move other flags, such as
"indirection" out of the DIVariable, too.
The new intrinsics look like this:
declare void @llvm.dbg.declare(metadata %storage, metadata %var, metadata %expr)
declare void @llvm.dbg.value(metadata %storage, i64 %offset, metadata %var, metadata %expr)
This patch adds a new LLVM-local tag to DIExpressions, so we can detect
and pretty-print DIExpression metadata nodes.
What this patch doesn't do:
This patch does not touch the "Indirect" field in DIVariable; but moving
that into the expression would be a natural next step.
http://reviews.llvm.org/D4919
rdar://problem/17994491
Thanks to dblaikie and dexonsmith for reviewing this patch!
Note: I accidentally committed a bogus older version of this patch previously.
llvm-svn: 218787
2014-10-02 02:55:02 +08:00
declare void @llvm.dbg.declare ( metadata , metadata , metadata ) nounwind readnone
declare void @llvm.dbg.value ( metadata , i64 , metadata , metadata ) nounwind readnone
2011-02-15 07:03:23 +08:00
2015-11-06 06:03:56 +08:00
define i32 @tak ( i32 %x , i32 %y , i32 %z ) nounwind ssp !dbg !0 {
2013-07-14 09:50:49 +08:00
; CHECK-LABEL: define i32 @tak(
2012-04-08 03:22:18 +08:00
; CHECK: entry
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.
llvm-svn: 224257
2014-12-16 03:07:53 +08:00
; CHECK-NEXT: call void @llvm.dbg.value(metadata i32 %x
2012-04-08 03:22:18 +08:00
2011-02-15 07:03:23 +08:00
entry:
br label %tailrecurse
tailrecurse: ; preds = %if.then, %entry
%x.tr = phi i32 [ %x , %entry ] , [ %call , %if.then ]
%y.tr = phi i32 [ %y , %entry ] , [ %call9 , %if.then ]
%z.tr = phi i32 [ %z , %entry ] , [ %call14 , %if.then ]
2015-04-30 00:38:44 +08:00
tail call void @llvm.dbg.value ( metadata i32 %x.tr , i64 0 , metadata !6 , metadata !DIExpression ( ) ) , !dbg !7
tail call void @llvm.dbg.value ( metadata i32 %y.tr , i64 0 , metadata !8 , metadata !DIExpression ( ) ) , !dbg !9
tail call void @llvm.dbg.value ( metadata i32 %z.tr , i64 0 , metadata !10 , metadata !DIExpression ( ) ) , !dbg !11
2011-02-15 07:03:23 +08:00
%cmp = icmp slt i32 %y.tr , %x.tr , !dbg !12
br i1 %cmp , label %if.then , label %if.end , !dbg !12
if.then: ; preds = %tailrecurse
%sub = sub nsw i32 %x.tr , 1 , !dbg !14
%call = tail call i32 @tak ( i32 %sub , i32 %y.tr , i32 %z.tr ) , !dbg !14
%sub6 = sub nsw i32 %y.tr , 1 , !dbg !14
%call9 = tail call i32 @tak ( i32 %sub6 , i32 %z.tr , i32 %x.tr ) , !dbg !14
%sub11 = sub nsw i32 %z.tr , 1 , !dbg !14
%call14 = tail call i32 @tak ( i32 %sub11 , i32 %x.tr , i32 %y.tr ) , !dbg !14
br label %tailrecurse
if.end: ; preds = %tailrecurse
br label %return , !dbg !16
return: ; preds = %if.end
ret i32 %z.tr , !dbg !17
}
2012-04-08 03:22:18 +08:00
@channelColumns = external global i64
@horzPlane = external global i8 * , align 8
define void @FindFreeHorzSeg ( i64 %startCol , i64 %row , i64 * %rowStart ) {
; Ensure that the loop increment basic block is rotated into the tail of the
; body, even though it contains a debug intrinsic call.
2013-07-14 09:50:49 +08:00
; CHECK-LABEL: define void @FindFreeHorzSeg(
2012-04-08 03:22:18 +08:00
; CHECK: %dec = add
; CHECK-NEXT: tail call void @llvm.dbg.value
2014-10-30 04:19:47 +08:00
; CHECK: %cmp = icmp
; CHECK: br i1 %cmp
; CHECK: phi i64 [ %{{[^,]*}}, %{{[^,]*}} ]
[LPM] Fix PR18643, another scary place where loop transforms failed to
preserve loop simplify of enclosing loops.
The problem here starts with LoopRotation which ends up cloning code out
of the latch into the new preheader it is buidling. This can create
a new edge from the preheader into the exit block of the loop which
breaks LoopSimplify form. The code tries to fix this by splitting the
critical edge between the latch and the exit block to get a new exit
block that only the latch dominates. This sadly isn't sufficient.
The exit block may be an exit block for multiple nested loops. When we
clone an edge from the latch of the inner loop to the new preheader
being built in the outer loop, we create an exiting edge from the outer
loop to this exit block. Despite breaking the LoopSimplify form for the
inner loop, this is fine for the outer loop. However, when we split the
edge from the inner loop to the exit block, we create a new block which
is in neither the inner nor outer loop as the new exit block. This is
a predecessor to the old exit block, and so the split itself takes the
outer loop out of LoopSimplify form. We need to split every edge
entering the exit block from inside a loop nested more deeply than the
exit block in order to preserve all of the loop simplify constraints.
Once we try to do that, a problem with splitting critical edges
surfaces. Previously, we tried a very brute force to update LoopSimplify
form by re-computing it for all exit blocks. We don't need to do this,
and doing this much will sometimes but not always overlap with the
LoopRotate bug fix. Instead, the code needs to specifically handle the
cases which can start to violate LoopSimplify -- they aren't that
common. We need to see if the destination of the split edge was a loop
exit block in simplified form for the loop of the source of the edge.
For this to be true, all the predecessors need to be in the exact same
loop as the source of the edge being split. If the dest block was
originally in this form, we have to split all of the deges back into
this loop to recover it. The old mechanism of doing this was
conservatively correct because at least *one* of the exiting blocks it
rewrote was the DestBB and so the DestBB's predecessors were fixed. But
this is a much more targeted way of doing it. Making it targeted is
important, because ballooning the set of edges touched prevents
LoopRotate from being able to split edges *it* needs to split to
preserve loop simplify in a coherent way -- the critical edge splitting
would sometimes find the other edges in need of splitting but not
others.
Many, *many* thanks for help from Nick reducing these test cases
mightily. And helping lots with the analysis here as this one was quite
tricky to track down.
llvm-svn: 200393
2014-01-29 21:16:53 +08:00
; CHECK-NEXT: br label %for.end
2012-04-08 03:22:18 +08:00
entry:
br label %for.cond
for.cond:
%i.0 = phi i64 [ %startCol , %entry ] , [ %dec , %for.inc ]
%cmp = icmp eq i64 %i.0 , 0
br i1 %cmp , label %for.end , label %for.body
for.body:
2015-02-28 05:17:42 +08:00
%0 = load i64 , i64 * @channelColumns , align 8
2012-04-08 03:22:18 +08:00
%mul = mul i64 %0 , %row
%add = add i64 %mul , %i.0
2015-02-28 05:17:42 +08:00
%1 = load i8 * , i8 * * @horzPlane , align 8
[opaque pointer type] Add textual IR support for explicit type parameter to getelementptr instruction
One of several parallel first steps to remove the target type of pointers,
replacing them with a single opaque pointer type.
This adds an explicit type parameter to the gep instruction so that when the
first parameter becomes an opaque pointer type, the type to gep through is
still available to the instructions.
* This doesn't modify gep operators, only instructions (operators will be
handled separately)
* Textual IR changes only. Bitcode (including upgrade) and changing the
in-memory representation will be in separate changes.
* geps of vectors are transformed as:
getelementptr <4 x float*> %x, ...
->getelementptr float, <4 x float*> %x, ...
Then, once the opaque pointer type is introduced, this will ultimately look
like:
getelementptr float, <4 x ptr> %x
with the unambiguous interpretation that it is a vector of pointers to float.
* address spaces remain on the pointer, not the type:
getelementptr float addrspace(1)* %x
->getelementptr float, float addrspace(1)* %x
Then, eventually:
getelementptr float, ptr addrspace(1) %x
Importantly, the massive amount of test case churn has been automated by
same crappy python code. I had to manually update a few test cases that
wouldn't fit the script's model (r228970,r229196,r229197,r229198). The
python script just massages stdin and writes the result to stdout, I
then wrapped that in a shell script to handle replacing files, then
using the usual find+xargs to migrate all the files.
update.py:
import fileinput
import sys
import re
ibrep = re.compile(r"(^.*?[^%\w]getelementptr inbounds )(((?:<\d* x )?)(.*?)(| addrspace\(\d\)) *\*(|>)(?:$| *(?:%|@|null|undef|blockaddress|getelementptr|addrspacecast|bitcast|inttoptr|\[\[[a-zA-Z]|\{\{).*$))")
normrep = re.compile( r"(^.*?[^%\w]getelementptr )(((?:<\d* x )?)(.*?)(| addrspace\(\d\)) *\*(|>)(?:$| *(?:%|@|null|undef|blockaddress|getelementptr|addrspacecast|bitcast|inttoptr|\[\[[a-zA-Z]|\{\{).*$))")
def conv(match, line):
if not match:
return line
line = match.groups()[0]
if len(match.groups()[5]) == 0:
line += match.groups()[2]
line += match.groups()[3]
line += ", "
line += match.groups()[1]
line += "\n"
return line
for line in sys.stdin:
if line.find("getelementptr ") == line.find("getelementptr inbounds"):
if line.find("getelementptr inbounds") != line.find("getelementptr inbounds ("):
line = conv(re.match(ibrep, line), line)
elif line.find("getelementptr ") != line.find("getelementptr ("):
line = conv(re.match(normrep, line), line)
sys.stdout.write(line)
apply.sh:
for name in "$@"
do
python3 `dirname "$0"`/update.py < "$name" > "$name.tmp" && mv "$name.tmp" "$name"
rm -f "$name.tmp"
done
The actual commands:
From llvm/src:
find test/ -name *.ll | xargs ./apply.sh
From llvm/src/tools/clang:
find test/ -name *.mm -o -name *.m -o -name *.cpp -o -name *.c | xargs -I '{}' ../../apply.sh "{}"
From llvm/src/tools/polly:
find test/ -name *.ll | xargs ./apply.sh
After that, check-all (with llvm, clang, clang-tools-extra, lld,
compiler-rt, and polly all checked out).
The extra 'rm' in the apply.sh script is due to a few files in clang's test
suite using interesting unicode stuff that my python script was throwing
exceptions on. None of those files needed to be migrated, so it seemed
sufficient to ignore those cases.
Reviewers: rafael, dexonsmith, grosser
Differential Revision: http://reviews.llvm.org/D7636
llvm-svn: 230786
2015-02-28 03:29:02 +08:00
%arrayidx = getelementptr inbounds i8 , i8 * %1 , i64 %add
2015-02-28 05:17:42 +08:00
%2 = load i8 , i8 * %arrayidx , align 1
2012-04-08 03:22:18 +08:00
%tobool = icmp eq i8 %2 , 0
br i1 %tobool , label %for.inc , label %for.end
for.inc:
%dec = add i64 %i.0 , -1
2015-08-01 02:58:39 +08:00
tail call void @llvm.dbg.value ( metadata i64 %dec , i64 0 , metadata !DILocalVariable ( scope: !0 ) , metadata !DIExpression ( ) ) , !dbg !DILocation ( scope: !0 )
2012-04-08 03:22:18 +08:00
br label %for.cond
for.end:
%add1 = add i64 %i.0 , 1
store i64 %add1 , i64 * %rowStart , align 8
ret void
}
2011-02-15 07:03:23 +08:00
2013-11-23 09:16:29 +08:00
!llvm.module.flags = ! { !20 }
2011-02-15 07:03:23 +08:00
!llvm.dbg.sp = ! { !0 }
2015-11-06 06:03:56 +08:00
!0 = distinct !DISubprogram ( name: "tak" , line: 32 , isLocal: false , isDefinition: true , virtualIndex: 6 , flags: D I F l a g P r o t o t y p e d , isOptimized: false , file: !18 , scope: !1 , type: !3 )
2015-04-30 00:38:44 +08:00
!1 = !DIFile ( filename: "/Volumes/Lalgate/cj/llvm/projects/llvm-test/SingleSource/Benchmarks/BenchmarkGame/recursive.c" , directory: "/Volumes/Lalgate/cj/D/projects/llvm-test/SingleSource/Benchmarks/BenchmarkGame" )
2015-08-04 01:26:41 +08:00
!2 = distinct !DICompileUnit ( language: D W _ L A N G _ C 99 , producer: "clang version 2.9 (trunk 125492)" , isOptimized: true , emissionKind: 0 , file: !18 , enums: !19 , retainedTypes: !19 )
2015-04-30 00:38:44 +08:00
!3 = !DISubroutineType ( types: !4 )
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.
llvm-svn: 224257
2014-12-16 03:07:53 +08:00
!4 = ! { !5 }
2015-04-30 00:38:44 +08:00
!5 = !DIBasicType ( tag: D W _ T A G _ b a s e _ type , name: "int" , size: 32 , align: 32 , encoding: D W _ A T E _ s i g n e d )
2015-08-01 02:58:39 +08:00
!6 = !DILocalVariable ( name: "x" , line: 32 , arg: 1 , scope: !0 , file: !1 , type: !5 )
2015-04-30 00:38:44 +08:00
!7 = !DILocation ( line: 32 , column: 13 , scope: !0 )
2015-08-01 02:58:39 +08:00
!8 = !DILocalVariable ( name: "y" , line: 32 , arg: 2 , scope: !0 , file: !1 , type: !5 )
2015-04-30 00:38:44 +08:00
!9 = !DILocation ( line: 32 , column: 20 , scope: !0 )
2015-08-01 02:58:39 +08:00
!10 = !DILocalVariable ( name: "z" , line: 32 , arg: 3 , scope: !0 , file: !1 , type: !5 )
2015-04-30 00:38:44 +08:00
!11 = !DILocation ( line: 32 , column: 27 , scope: !0 )
!12 = !DILocation ( line: 33 , column: 3 , scope: !13 )
!13 = distinct !DILexicalBlock ( line: 32 , column: 30 , file: !18 , scope: !0 )
!14 = !DILocation ( line: 34 , column: 5 , scope: !15 )
!15 = distinct !DILexicalBlock ( line: 33 , column: 14 , file: !18 , scope: !13 )
!16 = !DILocation ( line: 36 , column: 3 , scope: !13 )
!17 = !DILocation ( line: 37 , column: 1 , scope: !13 )
!18 = !DIFile ( filename: "/Volumes/Lalgate/cj/llvm/projects/llvm-test/SingleSource/Benchmarks/BenchmarkGame/recursive.c" , directory: "/Volumes/Lalgate/cj/D/projects/llvm-test/SingleSource/Benchmarks/BenchmarkGame" )
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.
llvm-svn: 224257
2014-12-16 03:07:53 +08:00
!19 = ! { i32 0 }
2015-03-04 01:24:31 +08:00
!20 = ! { i32 1 , !"Debug Info Version" , i32 3 }