[llvm-commits] [Review request][Win64] Improve allocating shadow area
NAKAMURA Takumi
geek4civic at gmail.com
Wed Dec 15 18:26:42 PST 2010
Good morning!
An additional patch(0002). Shadow area would not be allocated
explicitly by prologue any more.
...Takumi
-------------- next part --------------
From d0f65d20714f484ead070aa98f0a4b3c7cc77b0a Mon Sep 17 00:00:00 2001
From: NAKAMURA Takumi <geek4civic at gmail.com>
Date: Mon, 13 Dec 2010 17:59:20 +0900
Subject: [PATCH 1/2] Target/X86: Allocate Win64's shadow allocation, on stack, when callee requires one.
In leaf functions, shadow area would not be allocated any more.
---
lib/Target/X86/X86FrameInfo.cpp | 5 -----
lib/Target/X86/X86ISelLowering.cpp | 8 ++++++--
test/CodeGen/X86/2009-06-03-Win64DisableRedZone.ll | 4 ++--
test/CodeGen/X86/2009-06-03-Win64SpillXMM.ll | 9 ++++-----
test/CodeGen/X86/win64_params.ll | 4 ++--
test/CodeGen/X86/win64_vararg.ll | 10 +++++-----
6 files changed, 19 insertions(+), 21 deletions(-)
diff --git a/lib/Target/X86/X86FrameInfo.cpp b/lib/Target/X86/X86FrameInfo.cpp
index c47b0fa..3733f6c 100644
--- a/lib/Target/X86/X86FrameInfo.cpp
+++ b/lib/Target/X86/X86FrameInfo.cpp
@@ -325,11 +325,6 @@ void X86FrameInfo::emitPrologue(MachineFunction &MF) const {
if (HasFP) MinSize += SlotSize;
StackSize = std::max(MinSize, StackSize > 128 ? StackSize - 128 : 0);
MFI->setStackSize(StackSize);
- } else if (IsWin64) {
- // We need to always allocate 32 bytes as register spill area.
- // FIXME: We might reuse these 32 bytes for leaf functions.
- StackSize += 32;
- MFI->setStackSize(StackSize);
}
// Insert stack pointer adjustment for later moving of return addr. Only
diff --git a/lib/Target/X86/X86ISelLowering.cpp b/lib/Target/X86/X86ISelLowering.cpp
index 045bb93..fd93462 100644
--- a/lib/Target/X86/X86ISelLowering.cpp
+++ b/lib/Target/X86/X86ISelLowering.cpp
@@ -1807,8 +1807,7 @@ X86TargetLowering::LowerMemOpCallTo(SDValue Chain,
DebugLoc dl, SelectionDAG &DAG,
const CCValAssign &VA,
ISD::ArgFlagsTy Flags) const {
- const unsigned FirstStackArgOffset = (Subtarget->isTargetWin64() ? 32 : 0);
- unsigned LocMemOffset = FirstStackArgOffset + VA.getLocMemOffset();
+ unsigned LocMemOffset = VA.getLocMemOffset();
SDValue PtrOff = DAG.getIntPtrConstant(LocMemOffset);
PtrOff = DAG.getNode(ISD::ADD, dl, getPointerTy(), StackPtr, PtrOff);
if (Flags.isByVal())
@@ -1892,6 +1891,11 @@ X86TargetLowering::LowerCall(SDValue Chain, SDValue Callee,
SmallVector<CCValAssign, 16> ArgLocs;
CCState CCInfo(CallConv, isVarArg, getTargetMachine(),
ArgLocs, *DAG.getContext());
+
+ // Win64 CC requires at least 4 x 64bit of shadow allocation.
+ if (Subtarget->isTargetWin64())
+ CCInfo.AllocateStack(32, 16);
+
CCInfo.AnalyzeCallOperands(Outs, CC_X86);
// Get a count of how many bytes are to be pushed on the stack.
diff --git a/test/CodeGen/X86/2009-06-03-Win64DisableRedZone.ll b/test/CodeGen/X86/2009-06-03-Win64DisableRedZone.ll
index c598228..0413044 100644
--- a/test/CodeGen/X86/2009-06-03-Win64DisableRedZone.ll
+++ b/test/CodeGen/X86/2009-06-03-Win64DisableRedZone.ll
@@ -1,5 +1,5 @@
-; RUN: llc < %s | grep "subq.*\\\$40, \\\%rsp"
-target triple = "x86_64-pc-mingw64"
+; RUN: llc -mtriple=x86_64-pc-mingw64 < %s | FileCheck %s
+; CHECK: subq $8, %rsp
define x86_fp80 @a(i64 %x) nounwind readnone {
entry:
diff --git a/test/CodeGen/X86/2009-06-03-Win64SpillXMM.ll b/test/CodeGen/X86/2009-06-03-Win64SpillXMM.ll
index 810a6f4..9833d96 100644
--- a/test/CodeGen/X86/2009-06-03-Win64SpillXMM.ll
+++ b/test/CodeGen/X86/2009-06-03-Win64SpillXMM.ll
@@ -1,8 +1,7 @@
-; RUN: llc < %s -o %t1
-; RUN: grep "subq.*\\\$72, \\\%rsp" %t1
-; RUN: grep "movaps \\\%xmm8, 32\\\(\\\%rsp\\\)" %t1
-; RUN: grep "movaps \\\%xmm7, 48\\\(\\\%rsp\\\)" %t1
-target triple = "x86_64-pc-mingw64"
+; RUN: llc -mtriple=x86_64-pc-mingw64 < %s | FileCheck %s
+; CHECK: subq $40, %rsp
+; CHECK: movaps %xmm8, (%rsp)
+; CHECK: movaps %xmm7, 16(%rsp)
define i32 @a() nounwind {
entry:
diff --git a/test/CodeGen/X86/win64_params.ll b/test/CodeGen/X86/win64_params.ll
index 0b67368..f9d4bf9 100644
--- a/test/CodeGen/X86/win64_params.ll
+++ b/test/CodeGen/X86/win64_params.ll
@@ -4,8 +4,8 @@
; on the stack.
define i32 @f6(i32 %p1, i32 %p2, i32 %p3, i32 %p4, i32 %p5, i32 %p6) nounwind readnone optsize {
entry:
-; CHECK: movl 80(%rsp), %eax
-; CHECK: addl 72(%rsp), %eax
+; CHECK: movl 48(%rsp), %eax
+; CHECK: addl 40(%rsp), %eax
%add = add nsw i32 %p6, %p5
ret i32 %add
}
diff --git a/test/CodeGen/X86/win64_vararg.ll b/test/CodeGen/X86/win64_vararg.ll
index 072f36a..aa7d786 100644
--- a/test/CodeGen/X86/win64_vararg.ll
+++ b/test/CodeGen/X86/win64_vararg.ll
@@ -5,11 +5,11 @@
; calculated.
define void @average_va(i32 %count, ...) nounwind {
entry:
-; CHECK: subq $40, %rsp
-; CHECK: movq %r9, 72(%rsp)
-; CHECK: movq %r8, 64(%rsp)
-; CHECK: movq %rdx, 56(%rsp)
-; CHECK: leaq 56(%rsp), %rax
+; CHECK: subq $8, %rsp
+; CHECK: movq %r9, 40(%rsp)
+; CHECK: movq %r8, 32(%rsp)
+; CHECK: movq %rdx, 24(%rsp)
+; CHECK: leaq 24(%rsp), %rax
%ap = alloca i8*, align 8 ; <i8**> [#uses=1]
%ap1 = bitcast i8** %ap to i8* ; <i8*> [#uses=1]
--
1.7.1.GIT
-------------- next part --------------
From 55c46a76c00afbe3c8a9cfcfb59060f5688314c9 Mon Sep 17 00:00:00 2001
From: NAKAMURA Takumi <geek4civic at gmail.com>
Date: Tue, 14 Dec 2010 14:59:04 +0900
Subject: [PATCH 2/2] Target/X86: Remove stack frame allocation "-40" for Win64. X86TargetLowering::LowerFormalArguments() does it.
---
lib/Target/X86/X86FrameInfo.h | 2 +-
lib/Target/X86/X86ISelLowering.cpp | 5 +++++
2 files changed, 6 insertions(+), 1 deletions(-)
diff --git a/lib/Target/X86/X86FrameInfo.h b/lib/Target/X86/X86FrameInfo.h
index fbbde92..6ac2a3a 100644
--- a/lib/Target/X86/X86FrameInfo.h
+++ b/lib/Target/X86/X86FrameInfo.h
@@ -28,7 +28,7 @@ public:
explicit X86FrameInfo(const X86TargetMachine &tm, const X86Subtarget &sti)
: TargetFrameInfo(StackGrowsDown,
sti.getStackAlignment(),
- (sti.isTargetWin64() ? -40 : (sti.is64Bit() ? -8 : -4))),
+ (sti.is64Bit() ? -8 : -4)),
TM(tm), STI(sti) {
}
diff --git a/lib/Target/X86/X86ISelLowering.cpp b/lib/Target/X86/X86ISelLowering.cpp
index fd93462..0e40ca1 100644
--- a/lib/Target/X86/X86ISelLowering.cpp
+++ b/lib/Target/X86/X86ISelLowering.cpp
@@ -1573,6 +1573,11 @@ X86TargetLowering::LowerFormalArguments(SDValue Chain,
SmallVector<CCValAssign, 16> ArgLocs;
CCState CCInfo(CallConv, isVarArg, getTargetMachine(),
ArgLocs, *DAG.getContext());
+
+ // Win64 CC requires at least 4 x i64 of shadow allocation.
+ if (IsWin64)
+ CCInfo.AllocateStack(32, 16);
+
CCInfo.AnalyzeFormalArguments(Ins, CC_X86);
unsigned LastVal = ~0U;
--
1.7.1.GIT
More information about the llvm-commits
mailing list