#include "llvm/CodeGen/Passes.h"
#include "llvm/CodeGen/LiveStackAnalysis.h"
#include "llvm/CodeGen/MachineFrameInfo.h"
+#include "llvm/CodeGen/PseudoSourceValue.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/Debug.h"
public:
static char ID; // Pass identification
- StackSlotColoring() : MachineFunctionPass((intptr_t)&ID), NextColor(-1) {}
+ StackSlotColoring() : MachineFunctionPass(&ID), NextColor(-1) {}
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
AU.addRequired<LiveStacks>();
+ AU.addPreservedID(MachineLoopInfoID);
+ AU.addPreservedID(MachineDominatorsID);
MachineFunctionPass::getAnalysisUsage(AU);
}
// Record the assignment.
Assignments[Color].push_back(li);
int FI = li->getStackSlotIndex();
- DOUT << "Assigning fi #" << FI << " to fi #" << Color << "\n";
+ DOUT << "Assigning fi#" << FI << " to fi#" << Color << "\n";
// Change size and alignment of the allocated slot. If there are multiple
// objects sharing the same slot, then make sure the size and alignment
MachineInstr &MI = *MII;
for (unsigned i = 0, e = MI.getNumOperands(); i != e; ++i) {
MachineOperand &MO = MI.getOperand(i);
- if (!MO.isFrameIndex())
+ if (!MO.isFI())
continue;
int FI = MO.getIndex();
if (FI < 0)
continue;
- FI = SlotMapping[FI];
- if (FI == -1)
+ int NewFI = SlotMapping[FI];
+ if (NewFI == -1)
continue;
- MO.setIndex(FI);
+ MO.setIndex(NewFI);
+
+ // Update the MachineMemOperand for the new memory location.
+ // FIXME: We need a better method of managing these too.
+ SmallVector<MachineMemOperand, 2> MMOs(MI.memoperands_begin(),
+ MI.memoperands_end());
+ MI.clearMemOperands(MF);
+ const Value *OldSV = PseudoSourceValue::getFixedStack(FI);
+ for (unsigned i = 0, e = MMOs.size(); i != e; ++i) {
+ if (MMOs[i].getValue() == OldSV) {
+ MachineMemOperand MMO(PseudoSourceValue::getFixedStack(NewFI),
+ MMOs[i].getFlags(), MMOs[i].getOffset(),
+ MMOs[i].getSize(), MMOs[i].getAlignment());
+ MI.addMemOperand(MF, MMO);
+ } else
+ MI.addMemOperand(MF, MMOs[i]);
+ }
}
}
}
// Delete unused stack slots.
while (NextColor != -1) {
- DOUT << "Removing unused stack object fi #" << NextColor << "\n";
+ DOUT << "Removing unused stack object fi#" << NextColor << "\n";
MFI->RemoveStackObject(NextColor);
NextColor = AllColors.find_next(NextColor);
}
}
bool StackSlotColoring::runOnMachineFunction(MachineFunction &MF) {
- DOUT << "******** Stack Slot Coloring ********\n";
+ DOUT << "********** Stack Slot Coloring **********\n";
MFI = MF.getFrameInfo();
LS = &getAnalysis<LiveStacks>();