#include "llvm/Support/Debug.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/ADT/STLExtras.h"
+#include <algorithm>
using namespace llvm;
namespace {
};
}
-bool SimpleSpiller::runOnMachineFunction(MachineFunction& MF,
- const VirtRegMap& VRM) {
+bool SimpleSpiller::runOnMachineFunction(MachineFunction &MF,
+ const VirtRegMap &VRM) {
DEBUG(std::cerr << "********** REWRITE MACHINE CODE **********\n");
DEBUG(std::cerr << "********** Function: "
<< MF.getFunction()->getName() << '\n');
- const TargetMachine& TM = MF.getTarget();
- const MRegisterInfo& MRI = *TM.getRegisterInfo();
+ const TargetMachine &TM = MF.getTarget();
+ const MRegisterInfo &MRI = *TM.getRegisterInfo();
+ bool *PhysRegsUsed = MF.getUsedPhysregs();
// LoadedRegs - Keep track of which vregs are loaded, so that we only load
// each vreg once (in the case where a spilled vreg is used by multiple
++NumStores;
}
}
+ PhysRegsUsed[PhysReg] = true;
MI.SetMachineOperandReg(i, PhysReg);
}
}
// same stack slot, the original store is deleted.
std::map<int, MachineInstr*> MaybeDeadStores;
+ bool *PhysRegsUsed = MBB.getParent()->getUsedPhysregs();
+
for (MachineBasicBlock::iterator MII = MBB.begin(), E = MBB.end();
MII != E; ) {
MachineInstr &MI = *MII;
if (!VRM.hasStackSlot(VirtReg)) {
// This virtual register was assigned a physreg!
- MI.SetMachineOperandReg(i, VRM.getPhys(VirtReg));
+ unsigned Phys = VRM.getPhys(VirtReg);
+ PhysRegsUsed[Phys] = true;
+ MI.SetMachineOperandReg(i, Phys);
} else {
// Is this virtual register a spilled value?
if (MO.isUse()) {
// Otherwise, reload it and remember that we have it.
PhysReg = VRM.getPhys(VirtReg);
+ RecheckRegister:
// Note that, if we reused a register for a previous operand, the
// register we want to reload into might not actually be
// available. If this occurs, use the register indicated by the
if (ReusedOperands[ro].PhysRegReused == PhysReg) {
// Yup, use the reload register that we didn't use before.
PhysReg = ReusedOperands[ro].AssignedPhysReg;
- break;
+ goto RecheckRegister;
} else {
ReusedOp &Op = ReusedOperands[ro];
unsigned PRRU = Op.PhysRegReused;
}
}
ContinueReload:
-
+ PhysRegsUsed[PhysReg] = true;
MRI->loadRegFromStackSlot(MBB, &MI, PhysReg, StackSlot);
// This invalidates PhysReg.
ClobberPhysReg(PhysReg, SpillSlotsAvailable, PhysRegsAvailable);
// Loop over all of the implicit defs, clearing them from our available
// sets.
- const TargetInstrDescriptor &InstrDesc = TII->get(MI.getOpcode());
- for (const unsigned* ImpDef = InstrDesc.ImplicitDefs; *ImpDef; ++ImpDef)
+ for (const unsigned *ImpDef = TII->getImplicitDefs(MI.getOpcode());
+ *ImpDef; ++ImpDef) {
+ PhysRegsUsed[*ImpDef] = true;
ClobberPhysReg(*ImpDef, SpillSlotsAvailable, PhysRegsAvailable);
+ }
DEBUG(std::cerr << '\t' << MI);
// If we have folded references to memory operands, make sure we clear all
// physical registers that may contain the value of the spilled virtual
// register
- VirtRegMap::MI2VirtMapTy::const_iterator I, E;
- for (tie(I, E) = VRM.getFoldedVirts(&MI); I != E; ++I) {
+ VirtRegMap::MI2VirtMapTy::const_iterator I, End;
+ for (tie(I, End) = VRM.getFoldedVirts(&MI); I != End; ++I) {
DEBUG(std::cerr << "Folded vreg: " << I->second.first << " MR: "
<< I->second.second);
unsigned VirtReg = I->second.first;
else
PhysReg = MO.getReg();
+ PhysRegsUsed[PhysReg] = true;
MRI->storeRegToStackSlot(MBB, next(MII), PhysReg, StackSlot);
DEBUG(std::cerr << "Store:\t" << *next(MII));
MI.SetMachineOperandReg(i, PhysReg);