2012-10-20 05:47:33 +08:00
|
|
|
; RUN: llc -march=mipsel -relocation-model=pic -enable-mips-tail-calls < %s | \
|
2016-05-04 17:08:35 +08:00
|
|
|
; RUN: FileCheck %s -check-prefix=PIC32
|
2012-10-20 05:47:33 +08:00
|
|
|
; RUN: llc -march=mipsel -relocation-model=static \
|
2016-05-04 17:08:35 +08:00
|
|
|
; RUN: -enable-mips-tail-calls < %s | FileCheck %s -check-prefix=STATIC32
|
|
|
|
; RUN: llc -march=mips64el -mcpu=mips64r2 -enable-mips-tail-calls \
|
|
|
|
; RUN: < %s | FileCheck %s -check-prefix=N64
|
2015-10-15 22:34:23 +08:00
|
|
|
; RUN: llc -march=mipsel -mattr=mips16 -relocation-model=pic \
|
2016-05-04 17:08:35 +08:00
|
|
|
; RUN: -enable-mips-tail-calls < %s | FileCheck %s -check-prefix=PIC16
|
2012-10-20 05:47:33 +08:00
|
|
|
|
|
|
|
@g0 = common global i32 0, align 4
|
|
|
|
@g1 = common global i32 0, align 4
|
|
|
|
@g2 = common global i32 0, align 4
|
|
|
|
@g3 = common global i32 0, align 4
|
|
|
|
@g4 = common global i32 0, align 4
|
|
|
|
@g5 = common global i32 0, align 4
|
|
|
|
@g6 = common global i32 0, align 4
|
|
|
|
@g7 = common global i32 0, align 4
|
|
|
|
@g8 = common global i32 0, align 4
|
|
|
|
@g9 = common global i32 0, align 4
|
|
|
|
|
|
|
|
define i32 @caller1(i32 %a0) nounwind {
|
|
|
|
entry:
|
|
|
|
; PIC32-NOT: jalr
|
|
|
|
; STATIC32-NOT: jal
|
|
|
|
; N64-NOT: jalr
|
2012-11-01 01:25:23 +08:00
|
|
|
; PIC16: jalrc
|
2012-10-20 05:47:33 +08:00
|
|
|
|
|
|
|
%call = tail call i32 @callee1(i32 1, i32 1, i32 1, i32 %a0) nounwind
|
|
|
|
ret i32 %call
|
|
|
|
}
|
|
|
|
|
|
|
|
declare i32 @callee1(i32, i32, i32, i32)
|
|
|
|
|
|
|
|
define i32 @caller2(i32 %a0, i32 %a1, i32 %a2, i32 %a3) nounwind {
|
|
|
|
entry:
|
|
|
|
; PIC32: jalr
|
|
|
|
; STATIC32: jal
|
|
|
|
; N64-NOT: jalr
|
2012-11-01 01:25:23 +08:00
|
|
|
; PIC16: jalrc
|
2012-10-20 05:47:33 +08:00
|
|
|
|
|
|
|
%call = tail call i32 @callee2(i32 1, i32 %a0, i32 %a1, i32 %a2, i32 %a3) nounwind
|
|
|
|
ret i32 %call
|
|
|
|
}
|
|
|
|
|
|
|
|
declare i32 @callee2(i32, i32, i32, i32, i32)
|
|
|
|
|
|
|
|
define i32 @caller3(i32 %a0, i32 %a1, i32 %a2, i32 %a3, i32 %a4) nounwind {
|
|
|
|
entry:
|
|
|
|
; PIC32: jalr
|
|
|
|
; STATIC32: jal
|
|
|
|
; N64-NOT: jalr
|
2012-11-01 01:25:23 +08:00
|
|
|
; PIC16: jalrc
|
2012-10-20 05:47:33 +08:00
|
|
|
|
|
|
|
%call = tail call i32 @callee3(i32 1, i32 1, i32 1, i32 %a0, i32 %a1, i32 %a2, i32 %a3, i32 %a4) nounwind
|
|
|
|
ret i32 %call
|
|
|
|
}
|
|
|
|
|
|
|
|
declare i32 @callee3(i32, i32, i32, i32, i32, i32, i32, i32)
|
|
|
|
|
|
|
|
define i32 @caller4(i32 %a0, i32 %a1, i32 %a2, i32 %a3, i32 %a4, i32 %a5, i32 %a6, i32 %a7) nounwind {
|
|
|
|
entry:
|
|
|
|
; PIC32: jalr
|
|
|
|
; STATIC32: jal
|
|
|
|
; N64: jalr
|
2012-11-01 01:25:23 +08:00
|
|
|
; PIC16: jalrc
|
2012-10-20 05:47:33 +08:00
|
|
|
|
|
|
|
%call = tail call i32 @callee4(i32 1, i32 %a0, i32 %a1, i32 %a2, i32 %a3, i32 %a4, i32 %a5, i32 %a6, i32 %a7) nounwind
|
|
|
|
ret i32 %call
|
|
|
|
}
|
|
|
|
|
|
|
|
declare i32 @callee4(i32, i32, i32, i32, i32, i32, i32, i32, i32)
|
|
|
|
|
|
|
|
define i32 @caller5() nounwind readonly {
|
|
|
|
entry:
|
2012-10-27 08:56:56 +08:00
|
|
|
; PIC32: .ent caller5
|
2012-10-20 05:47:33 +08:00
|
|
|
; PIC32-NOT: jalr
|
2012-10-27 08:56:56 +08:00
|
|
|
; PIC32: .end caller5
|
|
|
|
; STATIC32: .ent caller5
|
2012-10-20 05:47:33 +08:00
|
|
|
; STATIC32-NOT: jal
|
2012-10-27 08:56:56 +08:00
|
|
|
; STATIC32: .end caller5
|
|
|
|
; N64: .ent caller5
|
2012-10-20 05:47:33 +08:00
|
|
|
; N64-NOT: jalr
|
2012-10-27 08:56:56 +08:00
|
|
|
; N64: .end caller5
|
2012-11-01 01:25:23 +08:00
|
|
|
; PIC16: .ent caller5
|
|
|
|
; PIC16: jalrc
|
|
|
|
; PIC16: .end caller5
|
2012-10-20 05:47:33 +08:00
|
|
|
|
2015-02-28 05:17:42 +08:00
|
|
|
%0 = load i32, i32* @g0, align 4
|
|
|
|
%1 = load i32, i32* @g1, align 4
|
|
|
|
%2 = load i32, i32* @g2, align 4
|
|
|
|
%3 = load i32, i32* @g3, align 4
|
|
|
|
%4 = load i32, i32* @g4, align 4
|
|
|
|
%5 = load i32, i32* @g5, align 4
|
|
|
|
%6 = load i32, i32* @g6, align 4
|
|
|
|
%7 = load i32, i32* @g7, align 4
|
|
|
|
%8 = load i32, i32* @g8, align 4
|
|
|
|
%9 = load i32, i32* @g9, align 4
|
2012-10-20 05:47:33 +08:00
|
|
|
%call = tail call fastcc i32 @callee5(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4, i32 %5, i32 %6, i32 %7, i32 %8, i32 %9)
|
|
|
|
ret i32 %call
|
|
|
|
}
|
|
|
|
|
|
|
|
define internal fastcc i32 @callee5(i32 %a0, i32 %a1, i32 %a2, i32 %a3, i32 %a4, i32 %a5, i32 %a6, i32 %a7, i32 %a8, i32 %a9) nounwind readnone noinline {
|
|
|
|
entry:
|
|
|
|
%add = add nsw i32 %a1, %a0
|
|
|
|
%add1 = add nsw i32 %add, %a2
|
|
|
|
%add2 = add nsw i32 %add1, %a3
|
|
|
|
%add3 = add nsw i32 %add2, %a4
|
|
|
|
%add4 = add nsw i32 %add3, %a5
|
|
|
|
%add5 = add nsw i32 %add4, %a6
|
|
|
|
%add6 = add nsw i32 %add5, %a7
|
|
|
|
%add7 = add nsw i32 %add6, %a8
|
|
|
|
%add8 = add nsw i32 %add7, %a9
|
|
|
|
ret i32 %add8
|
|
|
|
}
|
|
|
|
|
2012-10-27 08:56:56 +08:00
|
|
|
declare i32 @callee8(i32, ...)
|
|
|
|
|
|
|
|
define i32 @caller8_0() nounwind {
|
|
|
|
entry:
|
|
|
|
%call = tail call fastcc i32 @caller8_1()
|
|
|
|
ret i32 %call
|
|
|
|
}
|
|
|
|
|
|
|
|
define internal fastcc i32 @caller8_1() nounwind noinline {
|
|
|
|
entry:
|
|
|
|
; PIC32: .ent caller8_1
|
|
|
|
; PIC32: jalr
|
|
|
|
; PIC32: .end caller8_1
|
|
|
|
; STATIC32: .ent caller8_1
|
|
|
|
; STATIC32: jal
|
|
|
|
; STATIC32: .end caller8_1
|
|
|
|
; N64: .ent caller8_1
|
2012-10-31 04:16:31 +08:00
|
|
|
; N64-NOT: jalr
|
2012-10-27 08:56:56 +08:00
|
|
|
; N64: .end caller8_1
|
2012-11-01 01:25:23 +08:00
|
|
|
; PIC16: .ent caller8_1
|
|
|
|
; PIC16: jalrc
|
|
|
|
; PIC16: .end caller8_1
|
2012-10-27 08:56:56 +08:00
|
|
|
|
[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))
llvm-svn: 235145
2015-04-17 07:24:18 +08:00
|
|
|
%call = tail call i32 (i32, ...) @callee8(i32 2, i32 1) nounwind
|
2012-10-27 08:56:56 +08:00
|
|
|
ret i32 %call
|
|
|
|
}
|
|
|
|
|
|
|
|
%struct.S = type { [2 x i32] }
|
|
|
|
|
|
|
|
@gs1 = external global %struct.S
|
|
|
|
|
|
|
|
declare i32 @callee9(%struct.S* byval)
|
|
|
|
|
|
|
|
define i32 @caller9_0() nounwind {
|
|
|
|
entry:
|
|
|
|
%call = tail call fastcc i32 @caller9_1()
|
|
|
|
ret i32 %call
|
|
|
|
}
|
|
|
|
|
|
|
|
define internal fastcc i32 @caller9_1() nounwind noinline {
|
|
|
|
entry:
|
|
|
|
; PIC32: .ent caller9_1
|
|
|
|
; PIC32: jalr
|
|
|
|
; PIC32: .end caller9_1
|
|
|
|
; STATIC32: .ent caller9_1
|
|
|
|
; STATIC32: jal
|
|
|
|
; STATIC32: .end caller9_1
|
|
|
|
; N64: .ent caller9_1
|
|
|
|
; N64: jalr
|
|
|
|
; N64: .end caller9_1
|
2012-11-01 01:25:23 +08:00
|
|
|
; PIC16: .ent caller9_1
|
|
|
|
; PIC16: jalrc
|
|
|
|
; PIC16: .end caller9_1
|
2012-10-27 08:56:56 +08:00
|
|
|
|
|
|
|
%call = tail call i32 @callee9(%struct.S* byval @gs1) nounwind
|
|
|
|
ret i32 %call
|
|
|
|
}
|
|
|
|
|
2012-10-31 04:16:31 +08:00
|
|
|
declare i32 @callee10(i32, i32, i32, i32, i32, i32, i32, i32, i32)
|
|
|
|
|
|
|
|
define i32 @caller10(i32 %a0, i32 %a1, i32 %a2, i32 %a3, i32 %a4, i32 %a5, i32 %a6, i32 %a7, i32 %a8) nounwind {
|
|
|
|
entry:
|
|
|
|
; PIC32: .ent caller10
|
|
|
|
; PIC32-NOT: jalr
|
|
|
|
; STATIC32: .ent caller10
|
|
|
|
; STATIC32-NOT: jal
|
|
|
|
; N64: .ent caller10
|
|
|
|
; N64-NOT: jalr
|
2012-11-01 01:25:23 +08:00
|
|
|
; PIC16: .ent caller10
|
|
|
|
; PIC16: jalrc
|
2012-10-31 04:16:31 +08:00
|
|
|
|
|
|
|
%call = tail call i32 @callee10(i32 %a8, i32 %a0, i32 %a1, i32 %a2, i32 %a3, i32 %a4, i32 %a5, i32 %a6, i32 %a7) nounwind
|
|
|
|
ret i32 %call
|
|
|
|
}
|
|
|
|
|
|
|
|
declare i32 @callee11(%struct.S* byval)
|
|
|
|
|
|
|
|
define i32 @caller11() nounwind noinline {
|
|
|
|
entry:
|
|
|
|
; PIC32: .ent caller11
|
|
|
|
; PIC32: jalr
|
|
|
|
; STATIC32: .ent caller11
|
|
|
|
; STATIC32: jal
|
|
|
|
; N64: .ent caller11
|
|
|
|
; N64: jalr
|
2012-11-01 01:25:23 +08:00
|
|
|
; PIC16: .ent caller11
|
|
|
|
; PIC16: jalrc
|
2012-10-31 04:16:31 +08:00
|
|
|
|
|
|
|
%call = tail call i32 @callee11(%struct.S* byval @gs1) nounwind
|
|
|
|
ret i32 %call
|
|
|
|
}
|
|
|
|
|
|
|
|
declare i32 @callee12()
|
|
|
|
|
2015-11-19 13:56:52 +08:00
|
|
|
declare void @llvm.memcpy.p0i8.p0i8.i32(i8* nocapture, i8* nocapture, i32, i32, i1) nounwind
|
2012-10-31 04:16:31 +08:00
|
|
|
|
|
|
|
define i32 @caller12(%struct.S* nocapture byval %a0) nounwind {
|
|
|
|
entry:
|
|
|
|
; PIC32: .ent caller12
|
|
|
|
; PIC32: jalr
|
|
|
|
; STATIC32: .ent caller12
|
|
|
|
; STATIC32: jal
|
|
|
|
; N64: .ent caller12
|
|
|
|
; N64: jalr
|
2012-11-01 01:25:23 +08:00
|
|
|
; PIC16: .ent caller12
|
|
|
|
; PIC16: jalrc
|
2012-10-31 04:16:31 +08:00
|
|
|
|
|
|
|
%0 = bitcast %struct.S* %a0 to i8*
|
2015-11-19 13:56:52 +08:00
|
|
|
tail call void @llvm.memcpy.p0i8.p0i8.i32(i8* bitcast (%struct.S* @gs1 to i8*), i8* %0, i32 8, i32 4, i1 false)
|
2012-10-31 04:16:31 +08:00
|
|
|
%call = tail call i32 @callee12() nounwind
|
|
|
|
ret i32 %call
|
|
|
|
}
|
|
|
|
|
|
|
|
declare i32 @callee13(i32, ...)
|
|
|
|
|
|
|
|
define i32 @caller13() nounwind {
|
|
|
|
entry:
|
|
|
|
; PIC32: .ent caller13
|
|
|
|
; PIC32-NOT: jalr
|
|
|
|
; STATIC32: .ent caller13
|
|
|
|
; STATIC32-NOT: jal
|
|
|
|
; N64: .ent caller13
|
|
|
|
; N64-NOT: jalr
|
2012-11-01 01:25:23 +08:00
|
|
|
; PIC16: .ent caller13
|
|
|
|
; PIC16: jalrc
|
2012-10-31 04:16:31 +08:00
|
|
|
|
[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))
llvm-svn: 235145
2015-04-17 07:24:18 +08:00
|
|
|
%call = tail call i32 (i32, ...) @callee13(i32 1, i32 2) nounwind
|
2012-10-31 04:16:31 +08:00
|
|
|
ret i32 %call
|
|
|
|
}
|
|
|
|
|
2013-11-09 10:38:51 +08:00
|
|
|
; Check that there is a chain edge between the load and store nodes.
|
|
|
|
;
|
|
|
|
; PIC32-LABEL: caller14:
|
|
|
|
; PIC32: lw ${{[0-9]+}}, 16($sp)
|
|
|
|
; PIC32: sw $4, 16($sp)
|
|
|
|
|
|
|
|
define void @caller14(i32 %a, i32 %b, i32 %c, i32 %d, i32 %e) {
|
|
|
|
entry:
|
|
|
|
tail call void @callee14(i32 %e, i32 %b, i32 %c, i32 %d, i32 %a)
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
declare void @callee14(i32, i32, i32, i32, i32)
|