diff options
author | Reid Kleckner <reid@kleckner.net> | 2014-01-31 17:41:22 +0000 |
---|---|---|
committer | Reid Kleckner <reid@kleckner.net> | 2014-01-31 17:41:22 +0000 |
commit | 1c843228f825e91ede7e15b0cd15e8d2c8e7a7ff (patch) | |
tree | 45755ddc21e19f0abc6ac23d82a3635c9cd74577 /llvm/lib/Target/X86/X86CallingConv.h | |
parent | 56908b34015e79f57283c8f162f61730b4cf2b26 (diff) | |
download | bcm5719-llvm-1c843228f825e91ede7e15b0cd15e8d2c8e7a7ff.tar.gz bcm5719-llvm-1c843228f825e91ede7e15b0cd15e8d2c8e7a7ff.zip |
[ms-cxxabi] Add a new calling convention that swaps 'this' and 'sret'
MSVC always places the 'this' parameter for a method first. The
implicit 'sret' pointer for methods always comes second. We already
implement this for __thiscall by putting sret parameters on the stack,
but __cdecl methods require putting both parameters on the stack in
opposite order.
Using a special calling convention allows frontends to keep the sret
parameter first, which avoids breaking lots of assumptions in LLVM and
Clang.
Fixes PR15768 with the corresponding change in Clang.
Reviewers: ributzka, majnemer
Differential Revision: http://llvm-reviews.chandlerc.com/D2663
llvm-svn: 200561
Diffstat (limited to 'llvm/lib/Target/X86/X86CallingConv.h')
-rw-r--r-- | llvm/lib/Target/X86/X86CallingConv.h | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/llvm/lib/Target/X86/X86CallingConv.h b/llvm/lib/Target/X86/X86CallingConv.h index e76f9fda2db..040da3535e8 100644 --- a/llvm/lib/Target/X86/X86CallingConv.h +++ b/llvm/lib/Target/X86/X86CallingConv.h @@ -29,6 +29,33 @@ inline bool CC_X86_AnyReg_Error(unsigned &, MVT &, MVT &, return false; } +inline bool CC_X86_CDeclMethod_SRet(unsigned &ValNo, MVT &ValVT, MVT &LocVT, + CCValAssign::LocInfo &LocInfo, + ISD::ArgFlagsTy &ArgFlags, CCState &State) { + // Swap the order of the first two parameters if the first parameter is sret. + if (ArgFlags.isSRet()) { + assert(ValNo == 0); + assert(ValVT == MVT::i32); + State.AllocateStack(8, 4); + State.addLoc(CCValAssign::getCustomMem(ValNo, ValVT, 4, LocVT, LocInfo)); + + // Indicate that we need to swap the order of the first and second + // parameters by "allocating" register zero. There are no register + // parameters with cdecl methods, so we can use this to communicate to the + // next call. + State.AllocateReg(1); + return true; + } else if (ValNo == 1 && State.isAllocated(1)) { + assert(ValVT == MVT::i32 && "non-i32-sized this param unsupported"); + // Stack was already allocated while processing sret. + State.addLoc(CCValAssign::getCustomMem(ValNo, ValVT, 0, LocVT, LocInfo)); + return true; + } + + // All other args use the C calling convention. + return false; +} + } // End llvm namespace #endif |