From da42b2846c82063bd1bce78d6a046f78f218eb72 Mon Sep 17 00:00:00 2001 From: Sergei Barannikov Date: Mon, 1 May 2023 11:56:39 +0300 Subject: [CodeGen] Support allocating of arguments by decreasing offsets Previously, `CCState::AllocateStack` always allocated stack space by increasing offsets. For targets with stack growing up (away from zero) it is more convenient to allocate arguments by decreasing offsets, so that the first argument is at the top of the stack. This is important when calling a function with variable number of arguments: the callee does not know the size of the stack, but must be able to access "fixed" arguments. For that to work, the "fixed" arguments should have fixed offsets relative to the stack top, i.e. the variadic arguments area should be at the stack bottom (at lowest addresses). The in-tree target with stack growing up is AMDGPU, but it allocates arguments by increasing addresses. It does not support variadic arguments. A drive-by change is to promote stack size/offset to 64-bit integer. This is what MachineFrameInfo expects. Reviewed By: arsenm Differential Revision: https://reviews.llvm.org/D149575 --- llvm/lib/CodeGen/CallingConvLower.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'llvm/lib/CodeGen/CallingConvLower.cpp') diff --git a/llvm/lib/CodeGen/CallingConvLower.cpp b/llvm/lib/CodeGen/CallingConvLower.cpp index 0cd9b005d074..b7152587a9fa 100644 --- a/llvm/lib/CodeGen/CallingConvLower.cpp +++ b/llvm/lib/CodeGen/CallingConvLower.cpp @@ -25,10 +25,13 @@ using namespace llvm; -CCState::CCState(CallingConv::ID CC, bool isVarArg, MachineFunction &mf, - SmallVectorImpl &locs, LLVMContext &C) - : CallingConv(CC), IsVarArg(isVarArg), MF(mf), - TRI(*MF.getSubtarget().getRegisterInfo()), Locs(locs), Context(C) { +CCState::CCState(CallingConv::ID CC, bool IsVarArg, MachineFunction &MF, + SmallVectorImpl &Locs, LLVMContext &Context, + bool NegativeOffsets) + : CallingConv(CC), IsVarArg(IsVarArg), MF(MF), + TRI(*MF.getSubtarget().getRegisterInfo()), Locs(Locs), Context(Context), + NegativeOffsets(NegativeOffsets) { + // No stack is used. StackSize = 0; @@ -51,7 +54,7 @@ void CCState::HandleByVal(unsigned ValNo, MVT ValVT, MVT LocVT, ensureMaxAlignment(Alignment); MF.getSubtarget().getTargetLowering()->HandleByVal(this, Size, Alignment); Size = unsigned(alignTo(Size, MinAlign)); - unsigned Offset = AllocateStack(Size, Alignment); + uint64_t Offset = AllocateStack(Size, Alignment); addLoc(CCValAssign::getMem(ValNo, ValVT, Offset, LocVT, LocInfo)); } @@ -197,7 +200,7 @@ static bool isValueTypeInRegForCC(CallingConv::ID CC, MVT VT) { void CCState::getRemainingRegParmsForType(SmallVectorImpl &Regs, MVT VT, CCAssignFn Fn) { - unsigned SavedStackSize = StackSize; + uint64_t SavedStackSize = StackSize; Align SavedMaxStackArgAlign = MaxStackArgAlign; unsigned NumLocs = Locs.size(); -- cgit v1.2.3