2010-05-12 04:51:07 +08:00
|
|
|
; RUN: llc < %s -O0 -regalloc=fast -relocation-model=pic -disable-fp-elim | FileCheck %s
|
2010-05-01 05:19:29 +08:00
|
|
|
target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128-n8:16:32"
|
|
|
|
target triple = "i386-apple-darwin10.0.0"
|
|
|
|
|
|
|
|
%struct.S = type { [2 x i8*] }
|
|
|
|
|
|
|
|
@_ZTIi = external constant i8* ; <i8**> [#uses=1]
|
|
|
|
@.str = internal constant [4 x i8] c"%p\0A\00" ; <[4 x i8]*> [#uses=1]
|
|
|
|
@llvm.used = appending global [1 x i8*] [i8* bitcast (i8* (%struct.S*, i32, %struct.S*)* @_Z4test1SiS_ to i8*)], section "llvm.metadata" ; <[1 x i8*]*> [#uses=0]
|
|
|
|
|
Elide argument copies during instruction selection
Summary:
Avoids tons of prologue boilerplate when arguments are passed in memory
and left in memory. This can happen in a debug build or in a release
build when an argument alloca is escaped. This will dramatically affect
the code size of x86 debug builds, because X86 fast isel doesn't handle
arguments passed in memory at all. It only handles the x86_64 case of up
to 6 basic register parameters.
This is implemented by analyzing the entry block before ISel to identify
copy elision candidates. A copy elision candidate is an argument that is
used to fully initialize an alloca before any other possibly escaping
uses of that alloca. If an argument is a copy elision candidate, we set
a flag on the InputArg. If the the target generates loads from a fixed
stack object that matches the size and alignment requirements of the
alloca, the SelectionDAG builder will delete the stack object created
for the alloca and replace it with the fixed stack object. The load is
left behind to satisfy any remaining uses of the argument value. The
store is now dead and is therefore elided. The fixed stack object is
also marked as mutable, as it may now be modified by the user, and it
would be invalid to rematerialize the initial load from it.
Supersedes D28388
Fixes PR26328
Reviewers: chandlerc, MatzeB, qcolombet, inglorion, hans
Subscribers: igorb, llvm-commits
Differential Revision: https://reviews.llvm.org/D29668
llvm-svn: 296683
2017-03-02 05:42:00 +08:00
|
|
|
; Verify that %s1 gets spilled before the call.
|
2010-05-01 05:19:29 +08:00
|
|
|
; CHECK: Z4test1SiS
|
Elide argument copies during instruction selection
Summary:
Avoids tons of prologue boilerplate when arguments are passed in memory
and left in memory. This can happen in a debug build or in a release
build when an argument alloca is escaped. This will dramatically affect
the code size of x86 debug builds, because X86 fast isel doesn't handle
arguments passed in memory at all. It only handles the x86_64 case of up
to 6 basic register parameters.
This is implemented by analyzing the entry block before ISel to identify
copy elision candidates. A copy elision candidate is an argument that is
used to fully initialize an alloca before any other possibly escaping
uses of that alloca. If an argument is a copy elision candidate, we set
a flag on the InputArg. If the the target generates loads from a fixed
stack object that matches the size and alignment requirements of the
alloca, the SelectionDAG builder will delete the stack object created
for the alloca and replace it with the fixed stack object. The load is
left behind to satisfy any remaining uses of the argument value. The
store is now dead and is therefore elided. The fixed stack object is
also marked as mutable, as it may now be modified by the user, and it
would be invalid to rematerialize the initial load from it.
Supersedes D28388
Fixes PR26328
Reviewers: chandlerc, MatzeB, qcolombet, inglorion, hans
Subscribers: igorb, llvm-commits
Differential Revision: https://reviews.llvm.org/D29668
llvm-svn: 296683
2017-03-02 05:42:00 +08:00
|
|
|
; CHECK: leal 8(%ebp), %[[reg:[^ ]*]]
|
|
|
|
; CHECK: movl %[[reg]],{{.*}}(%ebp) ## 4-byte Spill
|
2010-09-22 13:49:14 +08:00
|
|
|
; CHECK: calll __Z6throwsv
|
2010-05-01 05:19:29 +08:00
|
|
|
|
2015-06-18 04:52:32 +08:00
|
|
|
define i8* @_Z4test1SiS_(%struct.S* byval %s1, i32 %n, %struct.S* byval %s2) ssp personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) {
|
2010-05-01 05:19:29 +08:00
|
|
|
entry:
|
|
|
|
%retval = alloca i8*, align 4 ; <i8**> [#uses=2]
|
|
|
|
%n.addr = alloca i32, align 4 ; <i32*> [#uses=1]
|
|
|
|
%_rethrow = alloca i8* ; <i8**> [#uses=4]
|
|
|
|
%0 = alloca i32, align 4 ; <i32*> [#uses=1]
|
|
|
|
%cleanup.dst = alloca i32 ; <i32*> [#uses=3]
|
|
|
|
%cleanup.dst7 = alloca i32 ; <i32*> [#uses=6]
|
|
|
|
store i32 %n, i32* %n.addr
|
|
|
|
invoke void @_Z6throwsv()
|
|
|
|
to label %invoke.cont unwind label %try.handler
|
|
|
|
|
|
|
|
invoke.cont: ; preds = %entry
|
|
|
|
store i32 1, i32* %cleanup.dst7
|
|
|
|
br label %finally
|
|
|
|
|
|
|
|
terminate.handler: ; preds = %match.end
|
2015-06-18 04:52:32 +08:00
|
|
|
%1 = landingpad { i8*, i32 }
|
2011-11-08 08:17:28 +08:00
|
|
|
cleanup
|
2010-05-01 05:19:29 +08:00
|
|
|
call void @_ZSt9terminatev() noreturn nounwind
|
|
|
|
unreachable
|
|
|
|
|
|
|
|
try.handler: ; preds = %entry
|
2015-06-18 04:52:32 +08:00
|
|
|
%exc1.ptr = landingpad { i8*, i32 }
|
2011-11-08 08:17:28 +08:00
|
|
|
catch i8* null
|
|
|
|
%exc1 = extractvalue { i8*, i32 } %exc1.ptr, 0
|
|
|
|
%selector = extractvalue { i8*, i32 } %exc1.ptr, 1
|
2010-05-01 05:19:29 +08:00
|
|
|
%2 = call i32 @llvm.eh.typeid.for(i8* bitcast (i8** @_ZTIi to i8*)) ; <i32> [#uses=1]
|
|
|
|
%3 = icmp eq i32 %selector, %2 ; <i1> [#uses=1]
|
|
|
|
br i1 %3, label %match, label %catch.next
|
|
|
|
|
|
|
|
match: ; preds = %try.handler
|
|
|
|
%4 = call i8* @__cxa_begin_catch(i8* %exc1) ; <i8*> [#uses=1]
|
|
|
|
%5 = bitcast i8* %4 to i32* ; <i32*> [#uses=1]
|
2015-02-28 05:17:42 +08:00
|
|
|
%6 = load i32, i32* %5 ; <i32> [#uses=1]
|
2010-05-01 05:19:29 +08:00
|
|
|
store i32 %6, i32* %0
|
2015-04-25 03:32:54 +08:00
|
|
|
%call = invoke i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i32 0, i32 0), %struct.S* %s2)
|
2010-05-01 05:19:29 +08:00
|
|
|
to label %invoke.cont2 unwind label %match.handler ; <i32> [#uses=0]
|
|
|
|
|
|
|
|
invoke.cont2: ; preds = %match
|
|
|
|
store i32 1, i32* %cleanup.dst
|
|
|
|
br label %match.end
|
|
|
|
|
|
|
|
match.handler: ; preds = %match
|
2015-06-18 04:52:32 +08:00
|
|
|
%exc3 = landingpad { i8*, i32 }
|
2011-11-08 08:17:28 +08:00
|
|
|
cleanup
|
|
|
|
%7 = extractvalue { i8*, i32 } %exc3, 0
|
|
|
|
store i8* %7, i8** %_rethrow
|
2010-05-01 05:19:29 +08:00
|
|
|
store i32 2, i32* %cleanup.dst
|
|
|
|
br label %match.end
|
|
|
|
|
|
|
|
cleanup.pad: ; preds = %cleanup.switch
|
|
|
|
store i32 1, i32* %cleanup.dst7
|
|
|
|
br label %finally
|
|
|
|
|
|
|
|
cleanup.pad4: ; preds = %cleanup.switch
|
|
|
|
store i32 2, i32* %cleanup.dst7
|
|
|
|
br label %finally
|
|
|
|
|
|
|
|
match.end: ; preds = %match.handler, %invoke.cont2
|
|
|
|
invoke void @__cxa_end_catch()
|
|
|
|
to label %invoke.cont5 unwind label %terminate.handler
|
|
|
|
|
|
|
|
invoke.cont5: ; preds = %match.end
|
|
|
|
br label %cleanup.switch
|
|
|
|
|
|
|
|
cleanup.switch: ; preds = %invoke.cont5
|
2015-02-28 05:17:42 +08:00
|
|
|
%tmp = load i32, i32* %cleanup.dst ; <i32> [#uses=1]
|
2010-05-01 05:19:29 +08:00
|
|
|
switch i32 %tmp, label %cleanup.end [
|
|
|
|
i32 1, label %cleanup.pad
|
|
|
|
i32 2, label %cleanup.pad4
|
|
|
|
]
|
|
|
|
|
|
|
|
cleanup.end: ; preds = %cleanup.switch
|
|
|
|
store i32 2, i32* %cleanup.dst7
|
|
|
|
br label %finally
|
|
|
|
|
|
|
|
catch.next: ; preds = %try.handler
|
|
|
|
store i8* %exc1, i8** %_rethrow
|
|
|
|
store i32 2, i32* %cleanup.dst7
|
|
|
|
br label %finally
|
|
|
|
|
|
|
|
finally: ; preds = %catch.next, %cleanup.end, %cleanup.pad4, %cleanup.pad, %invoke.cont
|
|
|
|
br label %cleanup.switch9
|
|
|
|
|
|
|
|
cleanup.switch9: ; preds = %finally
|
2015-02-28 05:17:42 +08:00
|
|
|
%tmp8 = load i32, i32* %cleanup.dst7 ; <i32> [#uses=1]
|
2010-05-01 05:19:29 +08:00
|
|
|
switch i32 %tmp8, label %cleanup.end10 [
|
|
|
|
i32 1, label %finally.end
|
|
|
|
i32 2, label %finally.throw
|
|
|
|
]
|
|
|
|
|
|
|
|
cleanup.end10: ; preds = %cleanup.switch9
|
|
|
|
br label %finally.end
|
|
|
|
|
|
|
|
finally.throw: ; preds = %cleanup.switch9
|
2015-02-28 05:17:42 +08:00
|
|
|
%8 = load i8*, i8** %_rethrow ; <i8*> [#uses=1]
|
2010-05-01 05:19:29 +08:00
|
|
|
call void @_Unwind_Resume_or_Rethrow(i8* %8)
|
|
|
|
unreachable
|
|
|
|
|
|
|
|
finally.end: ; preds = %cleanup.end10, %cleanup.switch9
|
[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
|
|
|
%tmp11 = getelementptr inbounds %struct.S, %struct.S* %s1, i32 0, i32 0 ; <[2 x i8*]*> [#uses=1]
|
|
|
|
%arraydecay = getelementptr inbounds [2 x i8*], [2 x i8*]* %tmp11, i32 0, i32 0 ; <i8**> [#uses=1]
|
|
|
|
%arrayidx = getelementptr inbounds i8*, i8** %arraydecay, i32 1 ; <i8**> [#uses=1]
|
2015-02-28 05:17:42 +08:00
|
|
|
%tmp12 = load i8*, i8** %arrayidx ; <i8*> [#uses=1]
|
2010-05-01 05:19:29 +08:00
|
|
|
store i8* %tmp12, i8** %retval
|
2015-02-28 05:17:42 +08:00
|
|
|
%9 = load i8*, i8** %retval ; <i8*> [#uses=1]
|
2010-05-01 05:19:29 +08:00
|
|
|
ret i8* %9
|
|
|
|
}
|
|
|
|
|
|
|
|
declare void @_Z6throwsv() ssp
|
|
|
|
|
|
|
|
declare i32 @__gxx_personality_v0(...)
|
|
|
|
|
|
|
|
declare void @_ZSt9terminatev()
|
|
|
|
|
|
|
|
declare void @_Unwind_Resume_or_Rethrow(i8*)
|
|
|
|
|
|
|
|
declare i32 @llvm.eh.typeid.for(i8*) nounwind
|
|
|
|
|
|
|
|
declare i8* @__cxa_begin_catch(i8*)
|
|
|
|
|
|
|
|
declare i32 @printf(i8*, ...)
|
|
|
|
|
|
|
|
declare void @__cxa_end_catch()
|