summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Northover <tnorthover@apple.com>2014-05-22 13:03:43 +0000
committerTim Northover <tnorthover@apple.com>2014-05-22 13:03:43 +0000
commitde70176f5ff5465cb32828ffcd70797c6ccb1f81 (patch)
tree8e436a0c0ea4adcdfe767692d569529e4e8970cc
parent65ea1ad2086954740678842d1b877f817003f727 (diff)
downloadllvm-de70176f5ff5465cb32828ffcd70797c6ccb1f81.tar.gz
llvm-de70176f5ff5465cb32828ffcd70797c6ccb1f81.tar.bz2
llvm-de70176f5ff5465cb32828ffcd70797c6ccb1f81.tar.xz
Segmented stacks: omit __morestack call when there's no frame.
Patch by Florian Zeitz git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@209436 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Target/ARM/ARMFrameLowering.cpp8
-rw-r--r--lib/Target/X86/X86FrameLowering.cpp14
-rw-r--r--test/CodeGen/ARM/segmented-stacks.ll16
-rw-r--r--test/CodeGen/Thumb/segmented-stacks.ll16
-rw-r--r--test/CodeGen/X86/segmented-stacks.ll41
5 files changed, 77 insertions, 18 deletions
diff --git a/lib/Target/ARM/ARMFrameLowering.cpp b/lib/Target/ARM/ARMFrameLowering.cpp
index c0f8a8d902..0caf4bfd77 100644
--- a/lib/Target/ARM/ARMFrameLowering.cpp
+++ b/lib/Target/ARM/ARMFrameLowering.cpp
@@ -1746,6 +1746,12 @@ void ARMFrameLowering::adjustForSegmentedStacks(MachineFunction &MF) const {
ARMFunctionInfo *ARMFI = MF.getInfo<ARMFunctionInfo>();
DebugLoc DL;
+ uint64_t StackSize = MFI->getStackSize();
+
+ // Do not generate a prologue for functions with a stack of size zero
+ if (StackSize == 0)
+ return;
+
// Use R4 and R5 as scratch registers.
// We save R4 and R5 before use and restore them before leaving the function.
unsigned ScratchReg0 = ARM::R4;
@@ -1775,8 +1781,6 @@ void ARMFrameLowering::adjustForSegmentedStacks(MachineFunction &MF) const {
MF.push_front(PrevStackMBB);
// The required stack size that is aligned to ARM constant criterion.
- uint64_t StackSize = MFI->getStackSize();
-
AlignedStackSize = alignToARMConstant(StackSize);
// When the frame size is less than 256 we just compare the stack
diff --git a/lib/Target/X86/X86FrameLowering.cpp b/lib/Target/X86/X86FrameLowering.cpp
index 1c1b06623b..4c1374f70f 100644
--- a/lib/Target/X86/X86FrameLowering.cpp
+++ b/lib/Target/X86/X86FrameLowering.cpp
@@ -1176,6 +1176,15 @@ X86FrameLowering::adjustForSegmentedStacks(MachineFunction &MF) const {
!STI.isTargetWin32() && !STI.isTargetWin64() && !STI.isTargetFreeBSD())
report_fatal_error("Segmented stacks not supported on this platform.");
+ // Eventually StackSize will be calculated by a link-time pass; which will
+ // also decide whether checking code needs to be injected into this particular
+ // prologue.
+ StackSize = MFI->getStackSize();
+
+ // Do not generate a prologue for functions with a stack of size zero
+ if (StackSize == 0)
+ return;
+
MachineBasicBlock *allocMBB = MF.CreateMachineBasicBlock();
MachineBasicBlock *checkMBB = MF.CreateMachineBasicBlock();
X86MachineFunctionInfo *X86FI = MF.getInfo<X86MachineFunctionInfo>();
@@ -1200,11 +1209,6 @@ X86FrameLowering::adjustForSegmentedStacks(MachineFunction &MF) const {
MF.push_front(allocMBB);
MF.push_front(checkMBB);
- // Eventually StackSize will be calculated by a link-time pass; which will
- // also decide whether checking code needs to be injected into this particular
- // prologue.
- StackSize = MFI->getStackSize();
-
// When the frame size is less than 256 we just compare the stack
// boundary directly to the value of the stack pointer, per gcc.
bool CompareStackPointer = StackSize < kSplitStackAvailable;
diff --git a/test/CodeGen/ARM/segmented-stacks.ll b/test/CodeGen/ARM/segmented-stacks.ll
index a7804b900a..9873bf3329 100644
--- a/test/CodeGen/ARM/segmented-stacks.ll
+++ b/test/CodeGen/ARM/segmented-stacks.ll
@@ -57,6 +57,8 @@ define void @test_basic() #0 {
define i32 @test_nested(i32 * nest %closure, i32 %other) #0 {
%addend = load i32 * %closure
%result = add i32 %other, %addend
+ %mem = alloca i32, i32 10
+ call void @dummy_use (i32* %mem, i32 10)
ret i32 %result
; ARM-linux: test_nested:
@@ -68,7 +70,7 @@ define i32 @test_nested(i32 * nest %closure, i32 %other) #0 {
; ARM-linux-NEXT: cmp r4, r5
; ARM-linux-NEXT: blo .LBB1_2
-; ARM-linux: mov r4, #0
+; ARM-linux: mov r4, #56
; ARM-linux-NEXT: mov r5, #0
; ARM-linux-NEXT: stmdb sp!, {lr}
; ARM-linux-NEXT: bl __morestack
@@ -87,7 +89,7 @@ define i32 @test_nested(i32 * nest %closure, i32 %other) #0 {
; ARM-android-NEXT: cmp r4, r5
; ARM-android-NEXT: blo .LBB1_2
-; ARM-android: mov r4, #0
+; ARM-android: mov r4, #56
; ARM-android-NEXT: mov r5, #0
; ARM-android-NEXT: stmdb sp!, {lr}
; ARM-android-NEXT: bl __morestack
@@ -234,4 +236,14 @@ define fastcc void @test_fastcc_large() #0 {
}
+define void @test_nostack() #0 {
+ ret void
+
+; ARM-linux-LABEL: test_nostack:
+; ARM-linux-NOT: bl __morestack
+
+; ARM-android-LABEL: test_nostack:
+; ARM-android-NOT: bl __morestack
+}
+
attributes #0 = { "split-stack" }
diff --git a/test/CodeGen/Thumb/segmented-stacks.ll b/test/CodeGen/Thumb/segmented-stacks.ll
index 89043ec11d..d6e25c7792 100644
--- a/test/CodeGen/Thumb/segmented-stacks.ll
+++ b/test/CodeGen/Thumb/segmented-stacks.ll
@@ -57,6 +57,8 @@ define void @test_basic() #0 {
define i32 @test_nested(i32 * nest %closure, i32 %other) #0 {
%addend = load i32 * %closure
%result = add i32 %other, %addend
+ %mem = alloca i32, i32 10
+ call void @dummy_use (i32* %mem, i32 10)
ret i32 %result
; Thumb-android: test_nested:
@@ -68,7 +70,7 @@ define i32 @test_nested(i32 * nest %closure, i32 %other) #0 {
; Thumb-android-NEXT: cmp r4, r5
; Thumb-android-NEXT: blo .LBB1_2
-; Thumb-android: mov r4, #0
+; Thumb-android: mov r4, #56
; Thumb-android-NEXT: mov r5, #0
; Thumb-android-NEXT: push {lr}
; Thumb-android-NEXT: bl __morestack
@@ -88,7 +90,7 @@ define i32 @test_nested(i32 * nest %closure, i32 %other) #0 {
; Thumb-linux-NEXT: cmp r4, r5
; Thumb-linux-NEXT: blo .LBB1_2
-; Thumb-linux: mov r4, #0
+; Thumb-linux: mov r4, #56
; Thumb-linux-NEXT: mov r5, #0
; Thumb-linux-NEXT: push {lr}
; Thumb-linux-NEXT: bl __morestack
@@ -246,4 +248,14 @@ define fastcc void @test_fastcc_large() #0 {
}
+define void @test_nostack() #0 {
+ ret void
+
+; Thumb-android-LABEL: test_nostack:
+; Thumb-android-NOT: bl __morestack
+
+; Thumb-linux-LABEL: test_nostack:
+; Thumb-linux-NOT: bl __morestack
+}
+
attributes #0 = { "split-stack" }
diff --git a/test/CodeGen/X86/segmented-stacks.ll b/test/CodeGen/X86/segmented-stacks.ll
index 8089f20568..9dab3cd8d6 100644
--- a/test/CodeGen/X86/segmented-stacks.ll
+++ b/test/CodeGen/X86/segmented-stacks.ll
@@ -107,13 +107,15 @@ define void @test_basic() #0 {
define i32 @test_nested(i32 * nest %closure, i32 %other) #0 {
%addend = load i32 * %closure
%result = add i32 %other, %addend
+ %mem = alloca i32, i32 10
+ call void @dummy_use (i32* %mem, i32 10)
ret i32 %result
; X32-Linux: cmpl %gs:48, %esp
; X32-Linux-NEXT: ja .LBB1_2
; X32-Linux: pushl $4
-; X32-Linux-NEXT: pushl $0
+; X32-Linux-NEXT: pushl $60
; X32-Linux-NEXT: calll __morestack
; X32-Linux-NEXT: ret
@@ -121,7 +123,7 @@ define i32 @test_nested(i32 * nest %closure, i32 %other) #0 {
; X64-Linux-NEXT: ja .LBB1_2
; X64-Linux: movq %r10, %rax
-; X64-Linux-NEXT: movabsq $0, %r10
+; X64-Linux-NEXT: movabsq $56, %r10
; X64-Linux-NEXT: movabsq $0, %r11
; X64-Linux-NEXT: callq __morestack
; X64-Linux-NEXT: ret
@@ -132,7 +134,7 @@ define i32 @test_nested(i32 * nest %closure, i32 %other) #0 {
; X32-Darwin-NEXT: ja LBB1_2
; X32-Darwin: pushl $4
-; X32-Darwin-NEXT: pushl $0
+; X32-Darwin-NEXT: pushl $60
; X32-Darwin-NEXT: calll ___morestack
; X32-Darwin-NEXT: ret
@@ -140,7 +142,7 @@ define i32 @test_nested(i32 * nest %closure, i32 %other) #0 {
; X64-Darwin-NEXT: ja LBB1_2
; X64-Darwin: movq %r10, %rax
-; X64-Darwin-NEXT: movabsq $0, %r10
+; X64-Darwin-NEXT: movabsq $56, %r10
; X64-Darwin-NEXT: movabsq $0, %r11
; X64-Darwin-NEXT: callq ___morestack
; X64-Darwin-NEXT: ret
@@ -150,7 +152,7 @@ define i32 @test_nested(i32 * nest %closure, i32 %other) #0 {
; X32-MinGW-NEXT: ja LBB1_2
; X32-MinGW: pushl $4
-; X32-MinGW-NEXT: pushl $0
+; X32-MinGW-NEXT: pushl $52
; X32-MinGW-NEXT: calll ___morestack
; X32-MinGW-NEXT: ret
@@ -159,7 +161,7 @@ define i32 @test_nested(i32 * nest %closure, i32 %other) #0 {
; X64-MinGW-NEXT: ja .LBB1_2
; X64-MinGW: movq %r10, %rax
-; X64-MinGW-NEXT: movabsq $0, %r10
+; X64-MinGW-NEXT: movabsq $88, %r10
; X64-MinGW-NEXT: movabsq $32, %r11
; X64-MinGW-NEXT: callq __morestack
; X64-MinGW-NEXT: retq
@@ -169,7 +171,7 @@ define i32 @test_nested(i32 * nest %closure, i32 %other) #0 {
; X64-FreeBSD-NEXT: ja .LBB1_2
; X64-FreeBSD: movq %r10, %rax
-; X64-FreeBSD-NEXT: movabsq $0, %r10
+; X64-FreeBSD-NEXT: movabsq $56, %r10
; X64-FreeBSD-NEXT: movabsq $0, %r11
; X64-FreeBSD-NEXT: callq __morestack
; X64-FreeBSD-NEXT: ret
@@ -435,4 +437,29 @@ define fastcc void @test_fastcc_large_with_ecx_arg(i32 %a) #0 {
}
+define void @test_nostack() #0 {
+ ret void
+
+; X32-Linux-LABEL: test_nostack:
+; X32-Linux-NOT: calll __morestack
+
+; X64-Linux-LABEL: test_nostack:
+; X32-Linux-NOT: callq __morestack
+
+; X32-Darwin-LABEL: test_nostack:
+; X32-Darwin-NOT: calll __morestack
+
+; X64-Darwin-LABEL: test_nostack:
+; X64-Darwin-NOT: callq __morestack
+
+; X32-MinGW-LABEL: test_nostack:
+; X32-MinGW-NOT: calll __morestack
+
+; X64-MinGW-LABEL: test_nostack:
+; X64-MinGW-NOT: callq __morestack
+
+; X64-FreeBSD-LABEL: test_nostack:
+; X64-FreeBSD-NOT: callq __morestack
+}
+
attributes #0 = { "split-stack" }