Skip to content

Commit 89c35fc

Browse files
committedFeb 23, 2018
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 llvm-svn: 325900
1 parent c30034e commit 89c35fc

File tree

6 files changed

+65
-10
lines changed

6 files changed

+65
-10
lines changed
 

‎llvm/docs/LangRef.rst

+2
Original file line numberDiff line numberDiff line change
@@ -1561,6 +1561,8 @@ example:
15611561
inlined into a function that has no ``"stack-probe-size"`` attribute
15621562
at all, the resulting function has the ``"stack-probe-size"`` attribute
15631563
of the callee.
1564+
``"no-stack-arg-probe"``
1565+
This attribute disables ABI-required stack probes, if any.
15641566
``writeonly``
15651567
On a function, this attribute indicates that the function may write to but
15661568
does not read from memory.

‎llvm/lib/Target/AArch64/AArch64FrameLowering.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,8 @@ static bool windowsRequiresStackProbe(MachineFunction &MF,
369369
F.getFnAttribute("stack-probe-size")
370370
.getValueAsString()
371371
.getAsInteger(0, StackProbeSize);
372-
return StackSizeInBytes >= StackProbeSize;
372+
return (StackSizeInBytes >= StackProbeSize) &&
373+
!F.hasFnAttribute("no-stack-arg-probe");
373374
}
374375

375376
bool AArch64FrameLowering::shouldCombineCSRLocalStackBump(

‎llvm/lib/Target/ARM/ARMFrameLowering.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,8 @@ static bool WindowsRequiresStackProbe(const MachineFunction &MF,
209209
F.getFnAttribute("stack-probe-size")
210210
.getValueAsString()
211211
.getAsInteger(0, StackProbeSize);
212-
return StackSizeInBytes >= StackProbeSize;
212+
return (StackSizeInBytes >= StackProbeSize) &&
213+
!F.hasFnAttribute("no-stack-arg-probe");
213214
}
214215

215216
namespace {

‎llvm/lib/Target/X86/X86ISelLowering.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -39186,7 +39186,8 @@ StringRef X86TargetLowering::getStackProbeSymbolName(MachineFunction &MF) const
3918639186

3918739187
// Generally, if we aren't on Windows, the platform ABI does not include
3918839188
// support for stack probes, so don't emit them.
39189-
if (!Subtarget.isOSWindows() || Subtarget.isTargetMachO())
39189+
if (!Subtarget.isOSWindows() || Subtarget.isTargetMachO() ||
39190+
MF.getFunction().hasFnAttribute("no-stack-arg-probe"))
3919039191
return "";
3919139192

3919239193
// We need a stack probe to conform to the Windows ABI. Choose the right

‎llvm/lib/Target/X86/X86WinAllocaExpander.cpp

+19-7
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ class X86WinAllocaExpander : public MachineFunctionPass {
6262
unsigned StackPtr;
6363
unsigned SlotSize;
6464
int64_t StackProbeSize;
65+
bool NoStackArgProbe;
6566

6667
StringRef getPassName() const override { return "X86 WinAlloca Expander"; }
6768
static char ID;
@@ -240,13 +241,21 @@ void X86WinAllocaExpander::lower(MachineInstr* MI, Lowering L) {
240241
}
241242
break;
242243
case Probe:
243-
// The probe lowering expects the amount in RAX/EAX.
244-
BuildMI(*MBB, MI, DL, TII->get(TargetOpcode::COPY), RegA)
245-
.addReg(MI->getOperand(0).getReg());
246-
247-
// Do the probe.
248-
STI->getFrameLowering()->emitStackProbe(*MBB->getParent(), *MBB, MI, DL,
249-
/*InPrologue=*/false);
244+
if (!NoStackArgProbe) {
245+
// The probe lowering expects the amount in RAX/EAX.
246+
BuildMI(*MBB, MI, DL, TII->get(TargetOpcode::COPY), RegA)
247+
.addReg(MI->getOperand(0).getReg());
248+
249+
// Do the probe.
250+
STI->getFrameLowering()->emitStackProbe(*MBB->getParent(), *MBB, MI, DL,
251+
/*InPrologue=*/false);
252+
} else {
253+
// Sub
254+
BuildMI(*MBB, I, DL, TII->get(Is64Bit ? X86::SUB64rr : X86::SUB32rr),
255+
StackPtr)
256+
.addReg(StackPtr)
257+
.addReg(MI->getOperand(0).getReg());
258+
}
250259
break;
251260
}
252261

@@ -285,6 +294,9 @@ bool X86WinAllocaExpander::runOnMachineFunction(MachineFunction &MF) {
285294
.getValueAsString()
286295
.getAsInteger(0, StackProbeSize);
287296
}
297+
NoStackArgProbe = MF.getFunction().hasFnAttribute("no-stack-arg-probe");
298+
if (NoStackArgProbe)
299+
StackProbeSize = INT64_MAX;
288300

289301
LoweringMap Lowerings;
290302
computeLowerings(MF, Lowerings);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
; This test is attempting to detect that the compiler disables stack
2+
; probe calls when the corresponding option is specified.
3+
;
4+
; RUN: llc -mtriple=i686-windows-msvc < %s | FileCheck %s
5+
6+
target datalayout = "e-m:w-p:32:32-i64:64-f80:32-n8:16:32-S32"
7+
8+
define i32 @test1() "no-stack-arg-probe" {
9+
%buffer = alloca [4095 x i8]
10+
11+
ret i32 0
12+
13+
; CHECK-LABEL: _test1:
14+
; CHECK-NOT: movl $4095, %eax
15+
; CHECK: subl $4095, %esp
16+
; CHECK-NOT: calll __chkstk
17+
}
18+
19+
define i32 @test2() "no-stack-arg-probe" {
20+
%buffer = alloca [4096 x i8]
21+
22+
ret i32 0
23+
24+
; CHECK-LABEL: _test2:
25+
; CHECK-NOT: movl $4096, %eax
26+
; CHECK: subl $4096, %esp
27+
; CHECK-NOT: calll __chkstk
28+
}
29+
30+
define i32 @test3(i32 %size) "no-stack-arg-probe" {
31+
%buffer = alloca i8, i32 %size
32+
33+
ret i32 0
34+
35+
; CHECK-LABEL: _test3:
36+
; CHECK: subl {{.*}}, %esp
37+
; CHECK-NOT: calll __chkstk
38+
}

0 commit comments

Comments
 (0)
Please sign in to comment.