mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-08-21 03:29:40 +00:00
When store nodes or memcpy nodes are created to copy the function call
arguments to the stack in MipsISelLowering::LowerCall, use stack pointer and integer offset operands rather than frame object operands. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@161068 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
d97f3a5ab0
commit
e2d529ac11
@ -97,7 +97,6 @@ bool MipsFrameLowering::targetHandlesStackFrameRounding() const {
|
||||
void MipsFrameLowering::emitPrologue(MachineFunction &MF) const {
|
||||
MachineBasicBlock &MBB = MF.front();
|
||||
MachineFrameInfo *MFI = MF.getFrameInfo();
|
||||
MipsFunctionInfo *MipsFI = MF.getInfo<MipsFunctionInfo>();
|
||||
const MipsRegisterInfo *RegInfo =
|
||||
static_cast<const MipsRegisterInfo*>(MF.getTarget().getRegisterInfo());
|
||||
const MipsInstrInfo &TII =
|
||||
@ -113,7 +112,7 @@ void MipsFrameLowering::emitPrologue(MachineFunction &MF) const {
|
||||
// First, compute final stack size.
|
||||
unsigned StackAlign = getStackAlignment();
|
||||
uint64_t StackSize = RoundUpToAlignment(MFI->getStackSize(), StackAlign);
|
||||
StackSize += RoundUpToAlignment(MipsFI->getMaxCallFrameSize(), StackAlign);
|
||||
StackSize += RoundUpToAlignment(MFI->getMaxCallFrameSize(), StackAlign);
|
||||
|
||||
// Update stack size
|
||||
MFI->setStackSize(StackSize);
|
||||
|
@ -2453,9 +2453,9 @@ static unsigned getNextIntArgReg(unsigned Reg) {
|
||||
|
||||
// Write ByVal Arg to arg registers and stack.
|
||||
static void
|
||||
WriteByValArg(SDValue& ByValChain, SDValue Chain, DebugLoc dl,
|
||||
WriteByValArg(SDValue Chain, DebugLoc dl,
|
||||
SmallVector<std::pair<unsigned, SDValue>, 16> &RegsToPass,
|
||||
SmallVector<SDValue, 8> &MemOpChains, int &LastFI,
|
||||
SmallVector<SDValue, 8> &MemOpChains, SDValue StackPtr,
|
||||
MachineFrameInfo *MFI, SelectionDAG &DAG, SDValue Arg,
|
||||
const CCValAssign &VA, const ISD::ArgFlagsTy &Flags,
|
||||
MVT PtrType, bool isLittle) {
|
||||
@ -2529,24 +2529,24 @@ WriteByValArg(SDValue& ByValChain, SDValue Chain, DebugLoc dl,
|
||||
return;
|
||||
}
|
||||
|
||||
// Create a fixed object on stack at offset LocMemOffset and copy
|
||||
// remaining part of byval arg to it using memcpy.
|
||||
// Copy remaining part of byval arg using memcpy.
|
||||
SDValue Src = DAG.getNode(ISD::ADD, dl, MVT::i32, Arg,
|
||||
DAG.getConstant(Offset, MVT::i32));
|
||||
LastFI = MFI->CreateFixedObject(RemainingSize, LocMemOffset, true);
|
||||
SDValue Dst = DAG.getFrameIndex(LastFI, PtrType);
|
||||
ByValChain = DAG.getMemcpy(ByValChain, dl, Dst, Src,
|
||||
DAG.getConstant(RemainingSize, MVT::i32),
|
||||
std::min(ByValAlign, (unsigned)4),
|
||||
/*isVolatile=*/false, /*AlwaysInline=*/false,
|
||||
MachinePointerInfo(0), MachinePointerInfo(0));
|
||||
SDValue Dst = DAG.getNode(ISD::ADD, dl, MVT::i32, StackPtr,
|
||||
DAG.getIntPtrConstant(LocMemOffset));
|
||||
Chain = DAG.getMemcpy(Chain, dl, Dst, Src,
|
||||
DAG.getConstant(RemainingSize, MVT::i32),
|
||||
std::min(ByValAlign, (unsigned)4),
|
||||
/*isVolatile=*/false, /*AlwaysInline=*/false,
|
||||
MachinePointerInfo(0), MachinePointerInfo(0));
|
||||
MemOpChains.push_back(Chain);
|
||||
}
|
||||
|
||||
// Copy Mips64 byVal arg to registers and stack.
|
||||
void static
|
||||
PassByValArg64(SDValue& ByValChain, SDValue Chain, DebugLoc dl,
|
||||
PassByValArg64(SDValue Chain, DebugLoc dl,
|
||||
SmallVector<std::pair<unsigned, SDValue>, 16> &RegsToPass,
|
||||
SmallVector<SDValue, 8> &MemOpChains, int &LastFI,
|
||||
SmallVector<SDValue, 8> &MemOpChains, SDValue StackPtr,
|
||||
MachineFrameInfo *MFI, SelectionDAG &DAG, SDValue Arg,
|
||||
const CCValAssign &VA, const ISD::ArgFlagsTy &Flags,
|
||||
EVT PtrTy, bool isLittle) {
|
||||
@ -2618,16 +2618,16 @@ PassByValArg64(SDValue& ByValChain, SDValue Chain, DebugLoc dl,
|
||||
|
||||
assert(MemCpySize && "MemCpySize must not be zero.");
|
||||
|
||||
// Create a fixed object on stack at offset LocMemOffset and copy
|
||||
// remainder of byval arg to it with memcpy.
|
||||
// Copy remainder of byval arg to it with memcpy.
|
||||
SDValue Src = DAG.getNode(ISD::ADD, dl, PtrTy, Arg,
|
||||
DAG.getConstant(Offset, PtrTy));
|
||||
LastFI = MFI->CreateFixedObject(MemCpySize, LocMemOffset, true);
|
||||
SDValue Dst = DAG.getFrameIndex(LastFI, PtrTy);
|
||||
ByValChain = DAG.getMemcpy(ByValChain, dl, Dst, Src,
|
||||
DAG.getConstant(MemCpySize, PtrTy), Alignment,
|
||||
/*isVolatile=*/false, /*AlwaysInline=*/false,
|
||||
MachinePointerInfo(0), MachinePointerInfo(0));
|
||||
SDValue Dst = DAG.getNode(ISD::ADD, dl, MVT::i64, StackPtr,
|
||||
DAG.getIntPtrConstant(LocMemOffset));
|
||||
Chain = DAG.getMemcpy(Chain, dl, Dst, Src,
|
||||
DAG.getConstant(MemCpySize, PtrTy), Alignment,
|
||||
/*isVolatile=*/false, /*AlwaysInline=*/false,
|
||||
MachinePointerInfo(0), MachinePointerInfo(0));
|
||||
MemOpChains.push_back(Chain);
|
||||
}
|
||||
|
||||
/// LowerCall - functions arguments are copied from virtual regs to
|
||||
@ -2641,7 +2641,7 @@ MipsTargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI,
|
||||
SmallVector<ISD::OutputArg, 32> &Outs = CLI.Outs;
|
||||
SmallVector<SDValue, 32> &OutVals = CLI.OutVals;
|
||||
SmallVector<ISD::InputArg, 32> &Ins = CLI.Ins;
|
||||
SDValue InChain = CLI.Chain;
|
||||
SDValue Chain = CLI.Chain;
|
||||
SDValue Callee = CLI.Callee;
|
||||
bool &isTailCall = CLI.IsTailCall;
|
||||
CallingConv::ID CallConv = CLI.CallConv;
|
||||
@ -2684,10 +2684,12 @@ MipsTargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI,
|
||||
// Chain is the output chain of the last Load/Store or CopyToReg node.
|
||||
// ByValChain is the output chain of the last Memcpy node created for copying
|
||||
// byval arguments to the stack.
|
||||
SDValue Chain, CallSeqStart, ByValChain;
|
||||
SDValue NextStackOffsetVal = DAG.getIntPtrConstant(NextStackOffset, true);
|
||||
Chain = CallSeqStart = DAG.getCALLSEQ_START(InChain, NextStackOffsetVal);
|
||||
ByValChain = InChain;
|
||||
Chain = DAG.getCALLSEQ_START(Chain, NextStackOffsetVal);
|
||||
|
||||
SDValue StackPtr = DAG.getCopyFromReg(Chain, dl,
|
||||
IsN64 ? Mips::SP_64 : Mips::SP,
|
||||
getPointerTy());
|
||||
|
||||
// Get the frame index of the stack frame object that points to the location
|
||||
// of dynamically allocated area on the stack.
|
||||
@ -2706,8 +2708,6 @@ MipsTargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI,
|
||||
SmallVector<std::pair<unsigned, SDValue>, 16> RegsToPass;
|
||||
SmallVector<SDValue, 8> MemOpChains;
|
||||
|
||||
int FirstFI = -MFI->getNumFixedObjects() - 1, LastFI = 0;
|
||||
|
||||
// Walk the register/memloc assignments, inserting copies/loads.
|
||||
for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i) {
|
||||
SDValue Arg = OutVals[i];
|
||||
@ -2720,11 +2720,11 @@ MipsTargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI,
|
||||
assert(Flags.getByValSize() &&
|
||||
"ByVal args of size 0 should have been ignored by front-end.");
|
||||
if (IsO32)
|
||||
WriteByValArg(ByValChain, Chain, dl, RegsToPass, MemOpChains, LastFI,
|
||||
WriteByValArg(Chain, dl, RegsToPass, MemOpChains, StackPtr,
|
||||
MFI, DAG, Arg, VA, Flags, getPointerTy(),
|
||||
Subtarget->isLittle());
|
||||
else
|
||||
PassByValArg64(ByValChain, Chain, dl, RegsToPass, MemOpChains, LastFI,
|
||||
PassByValArg64(Chain, dl, RegsToPass, MemOpChains, StackPtr,
|
||||
MFI, DAG, Arg, VA, Flags, getPointerTy(),
|
||||
Subtarget->isLittle());
|
||||
continue;
|
||||
@ -2774,29 +2774,14 @@ MipsTargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI,
|
||||
// Register can't get to this point...
|
||||
assert(VA.isMemLoc());
|
||||
|
||||
// Create the frame index object for this incoming parameter
|
||||
LastFI = MFI->CreateFixedObject(ValVT.getSizeInBits()/8,
|
||||
VA.getLocMemOffset(), true);
|
||||
SDValue PtrOff = DAG.getFrameIndex(LastFI, getPointerTy());
|
||||
|
||||
// emit ISD::STORE whichs stores the
|
||||
// parameter value to a stack Location
|
||||
SDValue PtrOff = DAG.getNode(ISD::ADD, dl, getPointerTy(), StackPtr,
|
||||
DAG.getIntPtrConstant(VA.getLocMemOffset()));
|
||||
MemOpChains.push_back(DAG.getStore(Chain, dl, Arg, PtrOff,
|
||||
MachinePointerInfo(), false, false, 0));
|
||||
}
|
||||
|
||||
// Extend range of indices of frame objects for outgoing arguments that were
|
||||
// created during this function call. Skip this step if no such objects were
|
||||
// created.
|
||||
if (LastFI)
|
||||
MipsFI->extendOutArgFIRange(FirstFI, LastFI);
|
||||
|
||||
// If a memcpy has been created to copy a byval arg to a stack, replace the
|
||||
// chain input of CallSeqStart with ByValChain.
|
||||
if (InChain != ByValChain)
|
||||
DAG.UpdateNodeOperands(CallSeqStart.getNode(), ByValChain,
|
||||
NextStackOffsetVal);
|
||||
|
||||
// Transform all store nodes into one single node because all store
|
||||
// nodes are independent of each other.
|
||||
if (!MemOpChains.empty())
|
||||
|
@ -1,7 +1,9 @@
|
||||
; RUN: llc -march=mipsel -mcpu=mips16 -relocation-model=pic -O3 < %s | FileCheck %s -check-prefix=C1
|
||||
; RUN: llc -march=mipsel -mcpu=mips16 -relocation-model=pic -O3 < %s | FileCheck %s -check-prefix=C2
|
||||
; RUN: llc -march=mipsel -mcpu=mips16 -relocation-model=pic -O3 < %s | FileCheck %s -check-prefix=PE
|
||||
; RUN: llc -march=mipsel -mcpu=mips16 -relocation-model=pic -O3 < %s | FileCheck %s -check-prefix=SR
|
||||
;
|
||||
; re-enable this when mips16's jalr is fixed.
|
||||
; DISABLED: llc -march=mipsel -mcpu=mips16 -relocation-model=pic -O3 < %s | FileCheck %s -check-prefix=SR
|
||||
|
||||
|
||||
@.str = private unnamed_addr constant [13 x i8] c"hello world\0A\00", align 1
|
||||
|
Loading…
Reference in New Issue
Block a user