[llvm] r325900 - Support for the mno-stack-arg-probe flag
Hans Wennborg via llvm-commits
llvm-commits at lists.llvm.org
Fri Feb 23 05:46:25 PST 2018
Author: hans
Date: Fri Feb 23 05:46:25 2018
New Revision: 325900
URL: http://llvm.org/viewvc/llvm-project?rev=325900&view=rev
Log:
Support for the mno-stack-arg-probe flag
Adds support for this flag. There is also another piece for clang
(separate review). More info:
https://bugs.llvm.org/show_bug.cgi?id=36221
By Ruslan Nikolaev!
Differential Revision: https://reviews.llvm.org/D43107
Added:
llvm/trunk/test/CodeGen/X86/no-stack-arg-probe.ll
Modified:
llvm/trunk/docs/LangRef.rst
llvm/trunk/lib/Target/AArch64/AArch64FrameLowering.cpp
llvm/trunk/lib/Target/ARM/ARMFrameLowering.cpp
llvm/trunk/lib/Target/X86/X86ISelLowering.cpp
llvm/trunk/lib/Target/X86/X86WinAllocaExpander.cpp
Modified: llvm/trunk/docs/LangRef.rst
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/docs/LangRef.rst?rev=325900&r1=325899&r2=325900&view=diff
==============================================================================
--- llvm/trunk/docs/LangRef.rst (original)
+++ llvm/trunk/docs/LangRef.rst Fri Feb 23 05:46:25 2018
@@ -1561,6 +1561,8 @@ example:
inlined into a function that has no ``"stack-probe-size"`` attribute
at all, the resulting function has the ``"stack-probe-size"`` attribute
of the callee.
+``"no-stack-arg-probe"``
+ This attribute disables ABI-required stack probes, if any.
``writeonly``
On a function, this attribute indicates that the function may write to but
does not read from memory.
Modified: llvm/trunk/lib/Target/AArch64/AArch64FrameLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/AArch64/AArch64FrameLowering.cpp?rev=325900&r1=325899&r2=325900&view=diff
==============================================================================
--- llvm/trunk/lib/Target/AArch64/AArch64FrameLowering.cpp (original)
+++ llvm/trunk/lib/Target/AArch64/AArch64FrameLowering.cpp Fri Feb 23 05:46:25 2018
@@ -369,7 +369,8 @@ static bool windowsRequiresStackProbe(Ma
F.getFnAttribute("stack-probe-size")
.getValueAsString()
.getAsInteger(0, StackProbeSize);
- return StackSizeInBytes >= StackProbeSize;
+ return (StackSizeInBytes >= StackProbeSize) &&
+ !F.hasFnAttribute("no-stack-arg-probe");
}
bool AArch64FrameLowering::shouldCombineCSRLocalStackBump(
Modified: llvm/trunk/lib/Target/ARM/ARMFrameLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/ARMFrameLowering.cpp?rev=325900&r1=325899&r2=325900&view=diff
==============================================================================
--- llvm/trunk/lib/Target/ARM/ARMFrameLowering.cpp (original)
+++ llvm/trunk/lib/Target/ARM/ARMFrameLowering.cpp Fri Feb 23 05:46:25 2018
@@ -209,7 +209,8 @@ static bool WindowsRequiresStackProbe(co
F.getFnAttribute("stack-probe-size")
.getValueAsString()
.getAsInteger(0, StackProbeSize);
- return StackSizeInBytes >= StackProbeSize;
+ return (StackSizeInBytes >= StackProbeSize) &&
+ !F.hasFnAttribute("no-stack-arg-probe");
}
namespace {
Modified: llvm/trunk/lib/Target/X86/X86ISelLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86ISelLowering.cpp?rev=325900&r1=325899&r2=325900&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86ISelLowering.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86ISelLowering.cpp Fri Feb 23 05:46:25 2018
@@ -39186,7 +39186,8 @@ StringRef X86TargetLowering::getStackPro
// Generally, if we aren't on Windows, the platform ABI does not include
// support for stack probes, so don't emit them.
- if (!Subtarget.isOSWindows() || Subtarget.isTargetMachO())
+ if (!Subtarget.isOSWindows() || Subtarget.isTargetMachO() ||
+ MF.getFunction().hasFnAttribute("no-stack-arg-probe"))
return "";
// We need a stack probe to conform to the Windows ABI. Choose the right
Modified: llvm/trunk/lib/Target/X86/X86WinAllocaExpander.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86WinAllocaExpander.cpp?rev=325900&r1=325899&r2=325900&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86WinAllocaExpander.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86WinAllocaExpander.cpp Fri Feb 23 05:46:25 2018
@@ -62,6 +62,7 @@ private:
unsigned StackPtr;
unsigned SlotSize;
int64_t StackProbeSize;
+ bool NoStackArgProbe;
StringRef getPassName() const override { return "X86 WinAlloca Expander"; }
static char ID;
@@ -240,13 +241,21 @@ void X86WinAllocaExpander::lower(Machine
}
break;
case Probe:
- // The probe lowering expects the amount in RAX/EAX.
- BuildMI(*MBB, MI, DL, TII->get(TargetOpcode::COPY), RegA)
- .addReg(MI->getOperand(0).getReg());
-
- // Do the probe.
- STI->getFrameLowering()->emitStackProbe(*MBB->getParent(), *MBB, MI, DL,
- /*InPrologue=*/false);
+ if (!NoStackArgProbe) {
+ // The probe lowering expects the amount in RAX/EAX.
+ BuildMI(*MBB, MI, DL, TII->get(TargetOpcode::COPY), RegA)
+ .addReg(MI->getOperand(0).getReg());
+
+ // Do the probe.
+ STI->getFrameLowering()->emitStackProbe(*MBB->getParent(), *MBB, MI, DL,
+ /*InPrologue=*/false);
+ } else {
+ // Sub
+ BuildMI(*MBB, I, DL, TII->get(Is64Bit ? X86::SUB64rr : X86::SUB32rr),
+ StackPtr)
+ .addReg(StackPtr)
+ .addReg(MI->getOperand(0).getReg());
+ }
break;
}
@@ -285,6 +294,9 @@ bool X86WinAllocaExpander::runOnMachineF
.getValueAsString()
.getAsInteger(0, StackProbeSize);
}
+ NoStackArgProbe = MF.getFunction().hasFnAttribute("no-stack-arg-probe");
+ if (NoStackArgProbe)
+ StackProbeSize = INT64_MAX;
LoweringMap Lowerings;
computeLowerings(MF, Lowerings);
Added: llvm/trunk/test/CodeGen/X86/no-stack-arg-probe.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/no-stack-arg-probe.ll?rev=325900&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/X86/no-stack-arg-probe.ll (added)
+++ llvm/trunk/test/CodeGen/X86/no-stack-arg-probe.ll Fri Feb 23 05:46:25 2018
@@ -0,0 +1,38 @@
+; This test is attempting to detect that the compiler disables stack
+; probe calls when the corresponding option is specified.
+;
+; RUN: llc -mtriple=i686-windows-msvc < %s | FileCheck %s
+
+target datalayout = "e-m:w-p:32:32-i64:64-f80:32-n8:16:32-S32"
+
+define i32 @test1() "no-stack-arg-probe" {
+ %buffer = alloca [4095 x i8]
+
+ ret i32 0
+
+; CHECK-LABEL: _test1:
+; CHECK-NOT: movl $4095, %eax
+; CHECK: subl $4095, %esp
+; CHECK-NOT: calll __chkstk
+}
+
+define i32 @test2() "no-stack-arg-probe" {
+ %buffer = alloca [4096 x i8]
+
+ ret i32 0
+
+; CHECK-LABEL: _test2:
+; CHECK-NOT: movl $4096, %eax
+; CHECK: subl $4096, %esp
+; CHECK-NOT: calll __chkstk
+}
+
+define i32 @test3(i32 %size) "no-stack-arg-probe" {
+ %buffer = alloca i8, i32 %size
+
+ ret i32 0
+
+; CHECK-LABEL: _test3:
+; CHECK: subl {{.*}}, %esp
+; CHECK-NOT: calll __chkstk
+}
More information about the llvm-commits
mailing list