MachineFunction: Return reference for getFrameInfo(); NFC
getFrameInfo() never returns nullptr so we should use a reference instead of a pointer. llvm-svn: 277017
This commit is contained in:
@@ -67,11 +67,11 @@ namespace {
|
||||
/// StackObjSet - A set of stack object indexes
|
||||
typedef SmallSetVector<int, 8> StackObjSet;
|
||||
|
||||
void AdjustStackOffset(MachineFrameInfo *MFI, int FrameIdx, int64_t &Offset,
|
||||
void AdjustStackOffset(MachineFrameInfo &MFI, int FrameIdx, int64_t &Offset,
|
||||
bool StackGrowsDown, unsigned &MaxAlign);
|
||||
void AssignProtectedObjSet(const StackObjSet &UnassignedObjs,
|
||||
SmallSet<int, 16> &ProtectedObjs,
|
||||
MachineFrameInfo *MFI, bool StackGrowsDown,
|
||||
MachineFrameInfo &MFI, bool StackGrowsDown,
|
||||
int64_t &Offset, unsigned &MaxAlign);
|
||||
void calculateFrameObjectOffsets(MachineFunction &Fn);
|
||||
bool insertFrameReferenceRegisters(MachineFunction &Fn);
|
||||
@@ -102,9 +102,9 @@ INITIALIZE_PASS_END(LocalStackSlotPass, "localstackalloc",
|
||||
|
||||
|
||||
bool LocalStackSlotPass::runOnMachineFunction(MachineFunction &MF) {
|
||||
MachineFrameInfo *MFI = MF.getFrameInfo();
|
||||
MachineFrameInfo &MFI = MF.getFrameInfo();
|
||||
const TargetRegisterInfo *TRI = MF.getSubtarget().getRegisterInfo();
|
||||
unsigned LocalObjectCount = MFI->getObjectIndexEnd();
|
||||
unsigned LocalObjectCount = MFI.getObjectIndexEnd();
|
||||
|
||||
// If the target doesn't want/need this pass, or if there are no locals
|
||||
// to consider, early exit.
|
||||
@@ -112,7 +112,7 @@ bool LocalStackSlotPass::runOnMachineFunction(MachineFunction &MF) {
|
||||
return true;
|
||||
|
||||
// Make sure we have enough space to store the local offsets.
|
||||
LocalOffsets.resize(MFI->getObjectIndexEnd());
|
||||
LocalOffsets.resize(MFI.getObjectIndexEnd());
|
||||
|
||||
// Lay out the local blob.
|
||||
calculateFrameObjectOffsets(MF);
|
||||
@@ -125,21 +125,21 @@ bool LocalStackSlotPass::runOnMachineFunction(MachineFunction &MF) {
|
||||
// Otherwise, PEI can do a bit better job of getting the alignment right
|
||||
// without a hole at the start since it knows the alignment of the stack
|
||||
// at the start of local allocation, and this pass doesn't.
|
||||
MFI->setUseLocalStackAllocationBlock(UsedBaseRegs);
|
||||
MFI.setUseLocalStackAllocationBlock(UsedBaseRegs);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// AdjustStackOffset - Helper function used to adjust the stack frame offset.
|
||||
void LocalStackSlotPass::AdjustStackOffset(MachineFrameInfo *MFI,
|
||||
void LocalStackSlotPass::AdjustStackOffset(MachineFrameInfo &MFI,
|
||||
int FrameIdx, int64_t &Offset,
|
||||
bool StackGrowsDown,
|
||||
unsigned &MaxAlign) {
|
||||
// If the stack grows down, add the object size to find the lowest address.
|
||||
if (StackGrowsDown)
|
||||
Offset += MFI->getObjectSize(FrameIdx);
|
||||
Offset += MFI.getObjectSize(FrameIdx);
|
||||
|
||||
unsigned Align = MFI->getObjectAlignment(FrameIdx);
|
||||
unsigned Align = MFI.getObjectAlignment(FrameIdx);
|
||||
|
||||
// If the alignment of this object is greater than that of the stack, then
|
||||
// increase the stack alignment to match.
|
||||
@@ -154,10 +154,10 @@ void LocalStackSlotPass::AdjustStackOffset(MachineFrameInfo *MFI,
|
||||
// Keep the offset available for base register allocation
|
||||
LocalOffsets[FrameIdx] = LocalOffset;
|
||||
// And tell MFI about it for PEI to use later
|
||||
MFI->mapLocalFrameObject(FrameIdx, LocalOffset);
|
||||
MFI.mapLocalFrameObject(FrameIdx, LocalOffset);
|
||||
|
||||
if (!StackGrowsDown)
|
||||
Offset += MFI->getObjectSize(FrameIdx);
|
||||
Offset += MFI.getObjectSize(FrameIdx);
|
||||
|
||||
++NumAllocations;
|
||||
}
|
||||
@@ -166,7 +166,7 @@ void LocalStackSlotPass::AdjustStackOffset(MachineFrameInfo *MFI,
|
||||
/// those required to be close to the Stack Protector) to stack offsets.
|
||||
void LocalStackSlotPass::AssignProtectedObjSet(const StackObjSet &UnassignedObjs,
|
||||
SmallSet<int, 16> &ProtectedObjs,
|
||||
MachineFrameInfo *MFI,
|
||||
MachineFrameInfo &MFI,
|
||||
bool StackGrowsDown, int64_t &Offset,
|
||||
unsigned &MaxAlign) {
|
||||
|
||||
@@ -183,7 +183,7 @@ void LocalStackSlotPass::AssignProtectedObjSet(const StackObjSet &UnassignedObjs
|
||||
///
|
||||
void LocalStackSlotPass::calculateFrameObjectOffsets(MachineFunction &Fn) {
|
||||
// Loop over all of the stack objects, assigning sequential addresses...
|
||||
MachineFrameInfo *MFI = Fn.getFrameInfo();
|
||||
MachineFrameInfo &MFI = Fn.getFrameInfo();
|
||||
const TargetFrameLowering &TFI = *Fn.getSubtarget().getFrameLowering();
|
||||
bool StackGrowsDown =
|
||||
TFI.getStackGrowthDirection() == TargetFrameLowering::StackGrowsDown;
|
||||
@@ -194,22 +194,22 @@ void LocalStackSlotPass::calculateFrameObjectOffsets(MachineFunction &Fn) {
|
||||
// Make sure that the stack protector comes before the local variables on the
|
||||
// stack.
|
||||
SmallSet<int, 16> ProtectedObjs;
|
||||
if (MFI->getStackProtectorIndex() >= 0) {
|
||||
if (MFI.getStackProtectorIndex() >= 0) {
|
||||
StackObjSet LargeArrayObjs;
|
||||
StackObjSet SmallArrayObjs;
|
||||
StackObjSet AddrOfObjs;
|
||||
|
||||
AdjustStackOffset(MFI, MFI->getStackProtectorIndex(), Offset,
|
||||
AdjustStackOffset(MFI, MFI.getStackProtectorIndex(), Offset,
|
||||
StackGrowsDown, MaxAlign);
|
||||
|
||||
// Assign large stack objects first.
|
||||
for (unsigned i = 0, e = MFI->getObjectIndexEnd(); i != e; ++i) {
|
||||
if (MFI->isDeadObjectIndex(i))
|
||||
for (unsigned i = 0, e = MFI.getObjectIndexEnd(); i != e; ++i) {
|
||||
if (MFI.isDeadObjectIndex(i))
|
||||
continue;
|
||||
if (MFI->getStackProtectorIndex() == (int)i)
|
||||
if (MFI.getStackProtectorIndex() == (int)i)
|
||||
continue;
|
||||
|
||||
switch (SP->getSSPLayout(MFI->getObjectAllocation(i))) {
|
||||
switch (SP->getSSPLayout(MFI.getObjectAllocation(i))) {
|
||||
case StackProtector::SSPLK_None:
|
||||
continue;
|
||||
case StackProtector::SSPLK_SmallArray:
|
||||
@@ -235,10 +235,10 @@ void LocalStackSlotPass::calculateFrameObjectOffsets(MachineFunction &Fn) {
|
||||
|
||||
// Then assign frame offsets to stack objects that are not used to spill
|
||||
// callee saved registers.
|
||||
for (unsigned i = 0, e = MFI->getObjectIndexEnd(); i != e; ++i) {
|
||||
if (MFI->isDeadObjectIndex(i))
|
||||
for (unsigned i = 0, e = MFI.getObjectIndexEnd(); i != e; ++i) {
|
||||
if (MFI.isDeadObjectIndex(i))
|
||||
continue;
|
||||
if (MFI->getStackProtectorIndex() == (int)i)
|
||||
if (MFI.getStackProtectorIndex() == (int)i)
|
||||
continue;
|
||||
if (ProtectedObjs.count(i))
|
||||
continue;
|
||||
@@ -247,8 +247,8 @@ void LocalStackSlotPass::calculateFrameObjectOffsets(MachineFunction &Fn) {
|
||||
}
|
||||
|
||||
// Remember how big this blob of stack space is
|
||||
MFI->setLocalFrameSize(Offset);
|
||||
MFI->setLocalFrameMaxAlign(MaxAlign);
|
||||
MFI.setLocalFrameSize(Offset);
|
||||
MFI.setLocalFrameMaxAlign(MaxAlign);
|
||||
}
|
||||
|
||||
static inline bool
|
||||
@@ -273,7 +273,7 @@ bool LocalStackSlotPass::insertFrameReferenceRegisters(MachineFunction &Fn) {
|
||||
// and ask the target to create a defining instruction for it.
|
||||
bool UsedBaseReg = false;
|
||||
|
||||
MachineFrameInfo *MFI = Fn.getFrameInfo();
|
||||
MachineFrameInfo &MFI = Fn.getFrameInfo();
|
||||
const TargetRegisterInfo *TRI = Fn.getSubtarget().getRegisterInfo();
|
||||
const TargetFrameLowering &TFI = *Fn.getSubtarget().getFrameLowering();
|
||||
bool StackGrowsDown =
|
||||
@@ -305,7 +305,7 @@ bool LocalStackSlotPass::insertFrameReferenceRegisters(MachineFunction &Fn) {
|
||||
// an object allocated in the local block.
|
||||
if (MI.getOperand(i).isFI()) {
|
||||
// Don't try this with values not in the local block.
|
||||
if (!MFI->isObjectPreAllocated(MI.getOperand(i).getIndex()))
|
||||
if (!MFI.isObjectPreAllocated(MI.getOperand(i).getIndex()))
|
||||
break;
|
||||
int Idx = MI.getOperand(i).getIndex();
|
||||
int64_t LocalOffset = LocalOffsets[Idx];
|
||||
@@ -332,7 +332,7 @@ bool LocalStackSlotPass::insertFrameReferenceRegisters(MachineFunction &Fn) {
|
||||
MachineInstr &MI = *FR.getMachineInstr();
|
||||
int64_t LocalOffset = FR.getLocalOffset();
|
||||
int FrameIdx = FR.getFrameIndex();
|
||||
assert(MFI->isObjectPreAllocated(FrameIdx) &&
|
||||
assert(MFI.isObjectPreAllocated(FrameIdx) &&
|
||||
"Only pre-allocated locals expected!");
|
||||
|
||||
DEBUG(dbgs() << "Considering: " << MI);
|
||||
@@ -349,7 +349,7 @@ bool LocalStackSlotPass::insertFrameReferenceRegisters(MachineFunction &Fn) {
|
||||
assert(idx < MI.getNumOperands() && "Cannot find FI operand");
|
||||
|
||||
int64_t Offset = 0;
|
||||
int64_t FrameSizeAdjust = StackGrowsDown ? MFI->getLocalFrameSize() : 0;
|
||||
int64_t FrameSizeAdjust = StackGrowsDown ? MFI.getLocalFrameSize() : 0;
|
||||
|
||||
DEBUG(dbgs() << " Replacing FI in: " << MI);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user