summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Korobeynikov <asl@math.spbu.ru>2007-03-01 16:29:22 +0000
committerAnton Korobeynikov <asl@math.spbu.ru>2007-03-01 16:29:22 +0000
commit9dd9abd87f77da4e523db02a396721e34631ef32 (patch)
treee4235c0cd9006dcec8c56473e90b8e6e7bdbaf90
parent43c6e7cd9b0d9a3b0006650ddfac256848f10d51 (diff)
downloadllvm-9dd9abd87f77da4e523db02a396721e34631ef32.tar.gz
llvm-9dd9abd87f77da4e523db02a396721e34631ef32.tar.bz2
llvm-9dd9abd87f77da4e523db02a396721e34631ef32.tar.xz
Ensure that fastcall'ed function is correctly mangled & stack is
properly aligned git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34788 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Target/X86/X86AsmPrinter.cpp6
-rw-r--r--lib/Target/X86/X86ISelLowering.cpp27
-rw-r--r--test/CodeGen/X86/fast-cc-callee-pops.ll2
-rw-r--r--test/CodeGen/X86/fastcall-correct-mangling.ll7
4 files changed, 28 insertions, 14 deletions
diff --git a/lib/Target/X86/X86AsmPrinter.cpp b/lib/Target/X86/X86AsmPrinter.cpp
index 0e9171bb71..75003e6b74 100644
--- a/lib/Target/X86/X86AsmPrinter.cpp
+++ b/lib/Target/X86/X86AsmPrinter.cpp
@@ -49,10 +49,8 @@ static X86FunctionInfo calculateFunctionInfo(const Function *F,
for (Function::const_arg_iterator AI = F->arg_begin(), AE = F->arg_end();
AI != AE; ++AI)
- Size += TD->getTypeSize(AI->getType());
-
- // Size should be aligned to DWORD boundary
- Size = ((Size + 3)/4)*4;
+ // Size should be aligned to DWORD boundary
+ Size += ((TD->getTypeSize(AI->getType()) + 3)/4)*4;
// We're not supporting tooooo huge arguments :)
Info.setBytesToPopOnReturn((unsigned int)Size);
diff --git a/lib/Target/X86/X86ISelLowering.cpp b/lib/Target/X86/X86ISelLowering.cpp
index bbabc423ab..65593ebb9b 100644
--- a/lib/Target/X86/X86ISelLowering.cpp
+++ b/lib/Target/X86/X86ISelLowering.cpp
@@ -30,11 +30,16 @@
#include "llvm/CodeGen/MachineInstrBuilder.h"
#include "llvm/CodeGen/SelectionDAG.h"
#include "llvm/CodeGen/SSARegMap.h"
+#include "llvm/Support/CommandLine.h"
#include "llvm/Support/MathExtras.h"
#include "llvm/Target/TargetOptions.h"
#include "llvm/ADT/StringExtras.h"
using namespace llvm;
+static cl::opt<bool> FastCallAlignStack("x86-fastcc-align-stack", cl::Hidden,
+ cl::desc("Align stack to 8-byte boundary for fastcall function"),
+ cl::init(false));
+
X86TargetLowering::X86TargetLowering(TargetMachine &TM)
: TargetLowering(TM) {
Subtarget = &TM.getSubtarget<X86Subtarget>();
@@ -903,11 +908,13 @@ X86TargetLowering::LowerFastCCArguments(SDOperand Op, SelectionDAG &DAG) {
ArgValues.push_back(Root);
unsigned StackSize = CCInfo.getNextStackOffset();
-
- // Make sure the instruction takes 8n+4 bytes to make sure the start of the
- // arguments and the arguments after the retaddr has been pushed are aligned.
- if ((StackSize & 7) == 0)
- StackSize += 4;
+
+ if (FastCallAlignStack) {
+ // Make sure the instruction takes 8n+4 bytes to make sure the start of the
+ // arguments and the arguments after the retaddr has been pushed are aligned.
+ if ((StackSize & 7) == 0)
+ StackSize += 4;
+ }
VarArgsFrameIndex = 0xAAAAAAA; // fastcc functions can't have varargs.
RegSaveFrameIndex = 0xAAAAAAA; // X86-64 only.
@@ -936,10 +943,12 @@ SDOperand X86TargetLowering::LowerFastCCCallTo(SDOperand Op, SelectionDAG &DAG,
// Get a count of how many bytes are to be pushed on the stack.
unsigned NumBytes = CCInfo.getNextStackOffset();
- // Make sure the instruction takes 8n+4 bytes to make sure the start of the
- // arguments and the arguments after the retaddr has been pushed are aligned.
- if ((NumBytes & 7) == 0)
- NumBytes += 4;
+ if (FastCallAlignStack) {
+ // Make sure the instruction takes 8n+4 bytes to make sure the start of the
+ // arguments and the arguments after the retaddr has been pushed are aligned.
+ if ((NumBytes & 7) == 0)
+ NumBytes += 4;
+ }
Chain = DAG.getCALLSEQ_START(Chain,DAG.getConstant(NumBytes, getPointerTy()));
diff --git a/test/CodeGen/X86/fast-cc-callee-pops.ll b/test/CodeGen/X86/fast-cc-callee-pops.ll
index 73d4e7d0c8..75e36dce33 100644
--- a/test/CodeGen/X86/fast-cc-callee-pops.ll
+++ b/test/CodeGen/X86/fast-cc-callee-pops.ll
@@ -1,4 +1,4 @@
-; RUN: llvm-upgrade < %s | llvm-as | llc -march=x86 -x86-asm-syntax=intel -mcpu=yonah | grep 'ret 28'
+; RUN: llvm-upgrade < %s | llvm-as | llc -march=x86 -x86-asm-syntax=intel -mcpu=yonah | grep 'ret 20'
; Check that a fastcc function pops its stack variables before returning.
diff --git a/test/CodeGen/X86/fastcall-correct-mangling.ll b/test/CodeGen/X86/fastcall-correct-mangling.ll
new file mode 100644
index 0000000000..bf8833dd2c
--- /dev/null
+++ b/test/CodeGen/X86/fastcall-correct-mangling.ll
@@ -0,0 +1,7 @@
+; RUN: llvm-upgrade < %s | llvm-as | llc -march=x86 -mtriple=mingw32 | grep '@12'
+
+; Check that a fastcall function gets correct mangling
+
+x86_fastcallcc void %func(long %X, ubyte %Y, ubyte %G, ushort %Z) {
+ ret void
+}