mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-08-23 17:29:19 +00:00
Refactoring patch.
1. VarArgStyleRegisters: functionality that emits "store" instructions for byval regs moved out into separated method "StoreByValRegs". Before this patch VarArgStyleRegisters had confused use-cases. It was used for both variadic functions and for regular functions with byval parameters. In last case it created new stack-frame and registered it as VarArg frame, that is wrong. This patch replaces VarArgsStyleRegisters usage for byval parameters with StoreByValRegs method. 2. In ARMMachineFunctionInfo, "get/setVarArgsRegSaveSize" was renamed to "get/setArgRegsSaveSize". By the same reason. Sometimes it was used for variadic functions, and sometimes for byval parameters in regular functions. Actually, this property means the size of registers, that keeps arguments, and thats why it was renamed. 3. In ARMISelLowering.cpp, ARMTargetLowering class, in methods computeRegArea and StoreByValRegs, VARegXXXXXX was renamed to ArgRegsXXXXXX still by the same reasons. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@180774 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
2a83943855
commit
f65e4932f8
@ -141,7 +141,7 @@ void ARMFrameLowering::emitPrologue(MachineFunction &MF) const {
|
||||
assert(!AFI->isThumb1OnlyFunction() &&
|
||||
"This emitPrologue does not support Thumb1!");
|
||||
bool isARM = !AFI->isThumbFunction();
|
||||
unsigned VARegSaveSize = AFI->getVarArgsRegSaveSize();
|
||||
unsigned ArgRegsSaveSize = AFI->getArgRegsSaveSize();
|
||||
unsigned NumBytes = MFI->getStackSize();
|
||||
const std::vector<CalleeSavedInfo> &CSI = MFI->getCalleeSavedInfo();
|
||||
DebugLoc dl = MBBI != MBB.end() ? MBBI->getDebugLoc() : DebugLoc();
|
||||
@ -159,8 +159,8 @@ void ARMFrameLowering::emitPrologue(MachineFunction &MF) const {
|
||||
return;
|
||||
|
||||
// Allocate the vararg register save area. This is not counted in NumBytes.
|
||||
if (VARegSaveSize)
|
||||
emitSPUpdate(isARM, MBB, MBBI, dl, TII, -VARegSaveSize,
|
||||
if (ArgRegsSaveSize)
|
||||
emitSPUpdate(isARM, MBB, MBBI, dl, TII, -ArgRegsSaveSize,
|
||||
MachineInstr::FrameSetup);
|
||||
|
||||
if (!AFI->hasStackFrame()) {
|
||||
@ -357,7 +357,7 @@ void ARMFrameLowering::emitEpilogue(MachineFunction &MF,
|
||||
"This emitEpilogue does not support Thumb1!");
|
||||
bool isARM = !AFI->isThumbFunction();
|
||||
|
||||
unsigned VARegSaveSize = AFI->getVarArgsRegSaveSize();
|
||||
unsigned ArgRegsSaveSize = AFI->getArgRegsSaveSize();
|
||||
int NumBytes = (int)MFI->getStackSize();
|
||||
unsigned FramePtr = RegInfo->getFrameRegister(MF);
|
||||
|
||||
@ -471,8 +471,8 @@ void ARMFrameLowering::emitEpilogue(MachineFunction &MF,
|
||||
MBBI = NewMI;
|
||||
}
|
||||
|
||||
if (VARegSaveSize)
|
||||
emitSPUpdate(isARM, MBB, MBBI, dl, TII, VARegSaveSize);
|
||||
if (ArgRegsSaveSize)
|
||||
emitSPUpdate(isARM, MBB, MBBI, dl, TII, ArgRegsSaveSize);
|
||||
}
|
||||
|
||||
/// getFrameIndexReference - Provide a base+offset reference to an FI slot for
|
||||
@ -1003,7 +1003,7 @@ bool ARMFrameLowering::restoreCalleeSavedRegisters(MachineBasicBlock &MBB,
|
||||
|
||||
MachineFunction &MF = *MBB.getParent();
|
||||
ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>();
|
||||
bool isVarArg = AFI->getVarArgsRegSaveSize() > 0;
|
||||
bool isVarArg = AFI->getArgRegsSaveSize() > 0;
|
||||
unsigned NumAlignedDPRCS2Regs = AFI->getNumAlignedDPRCS2Regs();
|
||||
|
||||
// The emitPopInst calls below do not insert reloads for the aligned DPRCS2
|
||||
@ -1174,7 +1174,7 @@ ARMFrameLowering::processFunctionBeforeCalleeSavedScan(MachineFunction &MF,
|
||||
|
||||
if (AFI->isThumb1OnlyFunction()) {
|
||||
// Spill LR if Thumb1 function uses variable length argument lists.
|
||||
if (AFI->getVarArgsRegSaveSize() > 0)
|
||||
if (AFI->getArgRegsSaveSize() > 0)
|
||||
MRI.setPhysRegUsed(ARM::LR);
|
||||
|
||||
// Spill R4 if Thumb1 epilogue has to restore SP from FP. We don't know
|
||||
|
@ -1897,7 +1897,7 @@ ARMTargetLowering::IsEligibleForTailCallOptimization(SDValue Callee,
|
||||
// local frame.
|
||||
const ARMFunctionInfo *AFI_Caller = DAG.getMachineFunction().
|
||||
getInfo<ARMFunctionInfo>();
|
||||
if (AFI_Caller->getVarArgsRegSaveSize())
|
||||
if (AFI_Caller->getArgRegsSaveSize())
|
||||
return false;
|
||||
|
||||
// If the callee takes no arguments then go on to check the results of the
|
||||
@ -2580,7 +2580,8 @@ ARMTargetLowering::GetF64FormalArgument(CCValAssign &VA, CCValAssign &NextVA,
|
||||
|
||||
void
|
||||
ARMTargetLowering::computeRegArea(CCState &CCInfo, MachineFunction &MF,
|
||||
unsigned &VARegSize, unsigned &VARegSaveSize)
|
||||
unsigned &ArgRegsSize,
|
||||
unsigned &ArgRegsSaveSize)
|
||||
const {
|
||||
unsigned NumGPRs;
|
||||
if (CCInfo.isFirstByValRegValid())
|
||||
@ -2594,8 +2595,8 @@ ARMTargetLowering::computeRegArea(CCState &CCInfo, MachineFunction &MF,
|
||||
}
|
||||
|
||||
unsigned Align = MF.getTarget().getFrameLowering()->getStackAlignment();
|
||||
VARegSize = NumGPRs * 4;
|
||||
VARegSaveSize = (VARegSize + Align - 1) & ~(Align - 1);
|
||||
ArgRegsSize = NumGPRs * 4;
|
||||
ArgRegsSaveSize = (ArgRegsSize + Align - 1) & ~(Align - 1);
|
||||
}
|
||||
|
||||
// The remaining GPRs hold either the beginning of variable-argument
|
||||
@ -2605,13 +2606,26 @@ ARMTargetLowering::computeRegArea(CCState &CCInfo, MachineFunction &MF,
|
||||
// If this is a variadic function, the va_list pointer will begin with
|
||||
// these values; otherwise, this reassembles a (byval) structure that
|
||||
// was split between registers and memory.
|
||||
void
|
||||
ARMTargetLowering::VarArgStyleRegisters(CCState &CCInfo, SelectionDAG &DAG,
|
||||
DebugLoc dl, SDValue &Chain,
|
||||
const Value *OrigArg,
|
||||
unsigned OffsetFromOrigArg,
|
||||
unsigned ArgOffset,
|
||||
bool ForceMutable) const {
|
||||
// Return: The frame index registers were stored into.
|
||||
int
|
||||
ARMTargetLowering::StoreByValRegs(CCState &CCInfo, SelectionDAG &DAG,
|
||||
DebugLoc dl, SDValue &Chain,
|
||||
const Value *OrigArg,
|
||||
unsigned OffsetFromOrigArg,
|
||||
unsigned ArgOffset,
|
||||
bool ForceMutable) const {
|
||||
|
||||
// Currently, two use-cases possible:
|
||||
// Case #1. Non var-args function, and we meet first byval parameter.
|
||||
// Setup first unallocated register as first byval register;
|
||||
// eat all remained registers
|
||||
// (these two actions are performed by HandleByVal method).
|
||||
// Then, here, we initialize stack frame with
|
||||
// "store-reg" instructions.
|
||||
// Case #2. Var-args function, that doesn't contain byval parameters.
|
||||
// The same: eat all remained unallocated registers,
|
||||
// initialize stack frame.
|
||||
|
||||
MachineFunction &MF = DAG.getMachineFunction();
|
||||
MachineFrameInfo *MFI = MF.getFrameInfo();
|
||||
ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>();
|
||||
@ -2623,19 +2637,22 @@ ARMTargetLowering::VarArgStyleRegisters(CCState &CCInfo, SelectionDAG &DAG,
|
||||
(GPRArgRegs, sizeof(GPRArgRegs) / sizeof(GPRArgRegs[0]));
|
||||
}
|
||||
|
||||
unsigned VARegSize, VARegSaveSize;
|
||||
computeRegArea(CCInfo, MF, VARegSize, VARegSaveSize);
|
||||
if (VARegSaveSize) {
|
||||
// If this function is vararg, store any remaining integer argument regs
|
||||
// to their spots on the stack so that they may be loaded by deferencing
|
||||
// the result of va_next.
|
||||
AFI->setVarArgsRegSaveSize(VARegSaveSize);
|
||||
AFI->setVarArgsFrameIndex(MFI->CreateFixedObject(VARegSaveSize,
|
||||
ArgOffset + VARegSaveSize
|
||||
- VARegSize,
|
||||
false));
|
||||
SDValue FIN = DAG.getFrameIndex(AFI->getVarArgsFrameIndex(),
|
||||
getPointerTy());
|
||||
unsigned ArgRegsSize, ArgRegsSaveSize;
|
||||
computeRegArea(CCInfo, MF, ArgRegsSize, ArgRegsSaveSize);
|
||||
|
||||
// Store any by-val regs to their spots on the stack so that they may be
|
||||
// loaded by deferencing the result of formal parameter pointer or va_next.
|
||||
// Note: once stack area for byval/varargs registers
|
||||
// was initialized, it can't be initialized again.
|
||||
if (!AFI->getArgRegsSaveSize() && ArgRegsSaveSize) {
|
||||
|
||||
AFI->setArgRegsSaveSize(ArgRegsSaveSize);
|
||||
|
||||
int FrameIndex = MFI->CreateFixedObject(
|
||||
ArgRegsSaveSize,
|
||||
ArgOffset + ArgRegsSaveSize - ArgRegsSize,
|
||||
false);
|
||||
SDValue FIN = DAG.getFrameIndex(FrameIndex, getPointerTy());
|
||||
|
||||
SmallVector<SDValue, 4> MemOps;
|
||||
for (unsigned i = 0; firstRegToSaveIndex < 4; ++firstRegToSaveIndex, ++i) {
|
||||
@ -2658,10 +2675,30 @@ ARMTargetLowering::VarArgStyleRegisters(CCState &CCInfo, SelectionDAG &DAG,
|
||||
if (!MemOps.empty())
|
||||
Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other,
|
||||
&MemOps[0], MemOps.size());
|
||||
return FrameIndex;
|
||||
} else
|
||||
// This will point to the next argument passed via stack.
|
||||
AFI->setVarArgsFrameIndex(
|
||||
MFI->CreateFixedObject(4, ArgOffset, !ForceMutable));
|
||||
return MFI->CreateFixedObject(4, ArgOffset, !ForceMutable);
|
||||
}
|
||||
|
||||
// Setup stack frame, the va_list pointer will start from.
|
||||
void
|
||||
ARMTargetLowering::VarArgStyleRegisters(CCState &CCInfo, SelectionDAG &DAG,
|
||||
DebugLoc dl, SDValue &Chain,
|
||||
unsigned ArgOffset,
|
||||
bool ForceMutable) const {
|
||||
MachineFunction &MF = DAG.getMachineFunction();
|
||||
ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>();
|
||||
|
||||
// Try to store any remaining integer argument regs
|
||||
// to their spots on the stack so that they may be loaded by deferencing
|
||||
// the result of va_next.
|
||||
// If there is no regs to be stored, just point address after last
|
||||
// argument passed via stack.
|
||||
int FrameIndex =
|
||||
StoreByValRegs(CCInfo, DAG, dl, Chain, 0, 0, ArgOffset, ForceMutable);
|
||||
|
||||
AFI->setVarArgsFrameIndex(FrameIndex);
|
||||
}
|
||||
|
||||
SDValue
|
||||
@ -2787,20 +2824,12 @@ ARMTargetLowering::LowerFormalArguments(SDValue Chain,
|
||||
// Since they could be overwritten by lowering of arguments in case of
|
||||
// a tail call.
|
||||
if (Flags.isByVal()) {
|
||||
ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>();
|
||||
if (!AFI->getVarArgsFrameIndex()) {
|
||||
VarArgStyleRegisters(CCInfo, DAG,
|
||||
dl, Chain, CurOrigArg,
|
||||
Ins[VA.getValNo()].PartOffset,
|
||||
VA.getLocMemOffset(),
|
||||
true /*force mutable frames*/);
|
||||
int VAFrameIndex = AFI->getVarArgsFrameIndex();
|
||||
InVals.push_back(DAG.getFrameIndex(VAFrameIndex, getPointerTy()));
|
||||
} else {
|
||||
int FI = MFI->CreateFixedObject(Flags.getByValSize(),
|
||||
VA.getLocMemOffset(), false);
|
||||
InVals.push_back(DAG.getFrameIndex(FI, getPointerTy()));
|
||||
}
|
||||
int FrameIndex = StoreByValRegs(
|
||||
CCInfo, DAG, dl, Chain, CurOrigArg,
|
||||
Ins[VA.getValNo()].PartOffset,
|
||||
VA.getLocMemOffset(),
|
||||
true /*force mutable frames*/);
|
||||
InVals.push_back(DAG.getFrameIndex(FrameIndex, getPointerTy()));
|
||||
} else {
|
||||
int FI = MFI->CreateFixedObject(VA.getLocVT().getSizeInBits()/8,
|
||||
VA.getLocMemOffset(), true);
|
||||
@ -2818,7 +2847,7 @@ ARMTargetLowering::LowerFormalArguments(SDValue Chain,
|
||||
|
||||
// varargs
|
||||
if (isVarArg)
|
||||
VarArgStyleRegisters(CCInfo, DAG, dl, Chain, 0, 0,
|
||||
VarArgStyleRegisters(CCInfo, DAG, dl, Chain,
|
||||
CCInfo.getNextStackOffset());
|
||||
|
||||
return Chain;
|
||||
|
@ -474,16 +474,21 @@ namespace llvm {
|
||||
DebugLoc dl, SelectionDAG &DAG,
|
||||
SmallVectorImpl<SDValue> &InVals) const;
|
||||
|
||||
int StoreByValRegs(CCState &CCInfo, SelectionDAG &DAG,
|
||||
DebugLoc dl, SDValue &Chain,
|
||||
const Value *OrigArg,
|
||||
unsigned OffsetFromOrigArg,
|
||||
unsigned ArgOffset,
|
||||
bool ForceMutable) const;
|
||||
|
||||
void VarArgStyleRegisters(CCState &CCInfo, SelectionDAG &DAG,
|
||||
DebugLoc dl, SDValue &Chain,
|
||||
const Value *OrigArg,
|
||||
unsigned OffsetFromOrigArg,
|
||||
unsigned ArgOffset,
|
||||
bool ForceMutable = false)
|
||||
const;
|
||||
bool ForceMutable = false) const;
|
||||
|
||||
void computeRegArea(CCState &CCInfo, MachineFunction &MF,
|
||||
unsigned &VARegSize, unsigned &VARegSaveSize) const;
|
||||
unsigned &ArgRegsSize,
|
||||
unsigned &ArgRegsSaveSize) const;
|
||||
|
||||
virtual SDValue
|
||||
LowerCall(TargetLowering::CallLoweringInfo &CLI,
|
||||
|
@ -38,7 +38,7 @@ class ARMFunctionInfo : public MachineFunctionInfo {
|
||||
|
||||
/// VarArgsRegSaveSize - Size of the register save area for vararg functions.
|
||||
///
|
||||
unsigned VarArgsRegSaveSize;
|
||||
unsigned ArgRegsSaveSize;
|
||||
|
||||
/// HasStackFrame - True if this function has a stack frame. Set by
|
||||
/// processFunctionBeforeCalleeSavedScan().
|
||||
@ -117,7 +117,7 @@ public:
|
||||
ARMFunctionInfo() :
|
||||
isThumb(false),
|
||||
hasThumb2(false),
|
||||
VarArgsRegSaveSize(0), HasStackFrame(false), RestoreSPFromFP(false),
|
||||
ArgRegsSaveSize(0), HasStackFrame(false), RestoreSPFromFP(false),
|
||||
LRSpilledForFarJump(false),
|
||||
FramePtrSpillOffset(0), GPRCS1Offset(0), GPRCS2Offset(0), DPRCSOffset(0),
|
||||
GPRCS1Size(0), GPRCS2Size(0), DPRCSSize(0),
|
||||
@ -129,7 +129,7 @@ public:
|
||||
explicit ARMFunctionInfo(MachineFunction &MF) :
|
||||
isThumb(MF.getTarget().getSubtarget<ARMSubtarget>().isThumb()),
|
||||
hasThumb2(MF.getTarget().getSubtarget<ARMSubtarget>().hasThumb2()),
|
||||
VarArgsRegSaveSize(0), HasStackFrame(false), RestoreSPFromFP(false),
|
||||
ArgRegsSaveSize(0), HasStackFrame(false), RestoreSPFromFP(false),
|
||||
LRSpilledForFarJump(false),
|
||||
FramePtrSpillOffset(0), GPRCS1Offset(0), GPRCS2Offset(0), DPRCSOffset(0),
|
||||
GPRCS1Size(0), GPRCS2Size(0), DPRCSSize(0),
|
||||
@ -141,8 +141,8 @@ public:
|
||||
bool isThumb1OnlyFunction() const { return isThumb && !hasThumb2; }
|
||||
bool isThumb2Function() const { return isThumb && hasThumb2; }
|
||||
|
||||
unsigned getVarArgsRegSaveSize() const { return VarArgsRegSaveSize; }
|
||||
void setVarArgsRegSaveSize(unsigned s) { VarArgsRegSaveSize = s; }
|
||||
unsigned getArgRegsSaveSize() const { return ArgRegsSaveSize; }
|
||||
void setArgRegsSaveSize(unsigned s) { ArgRegsSaveSize = s; }
|
||||
|
||||
bool hasStackFrame() const { return HasStackFrame; }
|
||||
void setHasStackFrame(bool s) { HasStackFrame = s; }
|
||||
|
@ -88,7 +88,7 @@ void Thumb1FrameLowering::emitPrologue(MachineFunction &MF) const {
|
||||
const Thumb1InstrInfo &TII =
|
||||
*static_cast<const Thumb1InstrInfo*>(MF.getTarget().getInstrInfo());
|
||||
|
||||
unsigned VARegSaveSize = AFI->getVarArgsRegSaveSize();
|
||||
unsigned ArgRegsSaveSize = AFI->getArgRegsSaveSize();
|
||||
unsigned NumBytes = MFI->getStackSize();
|
||||
const std::vector<CalleeSavedInfo> &CSI = MFI->getCalleeSavedInfo();
|
||||
DebugLoc dl = MBBI != MBB.end() ? MBBI->getDebugLoc() : DebugLoc();
|
||||
@ -104,8 +104,8 @@ void Thumb1FrameLowering::emitPrologue(MachineFunction &MF) const {
|
||||
unsigned GPRCS1Size = 0, GPRCS2Size = 0, DPRCSSize = 0;
|
||||
int FramePtrSpillFI = 0;
|
||||
|
||||
if (VARegSaveSize)
|
||||
emitSPUpdate(MBB, MBBI, TII, dl, *RegInfo, -VARegSaveSize,
|
||||
if (ArgRegsSaveSize)
|
||||
emitSPUpdate(MBB, MBBI, TII, dl, *RegInfo, -ArgRegsSaveSize,
|
||||
MachineInstr::FrameSetup);
|
||||
|
||||
if (!AFI->hasStackFrame()) {
|
||||
@ -249,7 +249,7 @@ void Thumb1FrameLowering::emitEpilogue(MachineFunction &MF,
|
||||
const Thumb1InstrInfo &TII =
|
||||
*static_cast<const Thumb1InstrInfo*>(MF.getTarget().getInstrInfo());
|
||||
|
||||
unsigned VARegSaveSize = AFI->getVarArgsRegSaveSize();
|
||||
unsigned ArgRegsSaveSize = AFI->getArgRegsSaveSize();
|
||||
int NumBytes = (int)MFI->getStackSize();
|
||||
const uint16_t *CSRegs = RegInfo->getCalleeSavedRegs();
|
||||
unsigned FramePtr = RegInfo->getFrameRegister(MF);
|
||||
@ -300,7 +300,7 @@ void Thumb1FrameLowering::emitEpilogue(MachineFunction &MF,
|
||||
}
|
||||
}
|
||||
|
||||
if (VARegSaveSize) {
|
||||
if (ArgRegsSaveSize) {
|
||||
// Unlike T2 and ARM mode, the T1 pop instruction cannot restore
|
||||
// to LR, and we can't pop the value directly to the PC since
|
||||
// we need to update the SP after popping the value. Therefore, we
|
||||
@ -313,7 +313,7 @@ void Thumb1FrameLowering::emitEpilogue(MachineFunction &MF,
|
||||
AddDefaultPred(BuildMI(MBB, MBBI, dl, TII.get(ARM::tPOP)))
|
||||
.addReg(ARM::R3, RegState::Define);
|
||||
|
||||
emitSPUpdate(MBB, MBBI, TII, dl, *RegInfo, VARegSaveSize);
|
||||
emitSPUpdate(MBB, MBBI, TII, dl, *RegInfo, ArgRegsSaveSize);
|
||||
|
||||
MachineInstrBuilder MIB =
|
||||
BuildMI(MBB, MBBI, dl, TII.get(ARM::tBX_RET_vararg))
|
||||
@ -376,7 +376,7 @@ restoreCalleeSavedRegisters(MachineBasicBlock &MBB,
|
||||
ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>();
|
||||
const TargetInstrInfo &TII = *MF.getTarget().getInstrInfo();
|
||||
|
||||
bool isVarArg = AFI->getVarArgsRegSaveSize() > 0;
|
||||
bool isVarArg = AFI->getArgRegsSaveSize() > 0;
|
||||
DebugLoc DL = MI->getDebugLoc();
|
||||
MachineInstrBuilder MIB = BuildMI(MF, DL, TII.get(ARM::tPOP));
|
||||
AddDefaultPred(MIB);
|
||||
|
Loading…
Reference in New Issue
Block a user