mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-08-21 18:29:46 +00:00
Refactor code. No functionality change.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@62893 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
3b64c6bc29
commit
8191371f87
@ -69,6 +69,11 @@ namespace {
|
||||
MachineInstr *MI, MachineInstr *DefMI,
|
||||
MachineBasicBlock *MBB, unsigned Loc,
|
||||
DenseMap<MachineInstr*, unsigned> &DistanceMap);
|
||||
|
||||
bool CommuteInstruction(MachineBasicBlock::iterator &mi,
|
||||
MachineFunction::iterator &mbbi,
|
||||
unsigned RegC, unsigned Dist,
|
||||
DenseMap<MachineInstr*, unsigned> &DistanceMap);
|
||||
public:
|
||||
static char ID; // Pass identification, replacement for typeid
|
||||
TwoAddressInstructionPass() : MachineFunctionPass(&ID) {}
|
||||
@ -250,6 +255,38 @@ TwoAddressInstructionPass::isProfitableToReMat(unsigned Reg,
|
||||
return MBB == DefMI->getParent();
|
||||
}
|
||||
|
||||
/// CommuteInstruction - Commute a two-address instruction and update the basic
|
||||
/// block, distance map, and live variables if needed. Return true if it is
|
||||
/// successful.
|
||||
bool
|
||||
TwoAddressInstructionPass::CommuteInstruction(MachineBasicBlock::iterator &mi,
|
||||
MachineFunction::iterator &mbbi,
|
||||
unsigned RegC, unsigned Dist,
|
||||
DenseMap<MachineInstr*, unsigned> &DistanceMap) {
|
||||
MachineInstr *MI = mi;
|
||||
DOUT << "2addr: COMMUTING : " << *MI;
|
||||
MachineInstr *NewMI = TII->commuteInstruction(MI);
|
||||
|
||||
if (NewMI == 0) {
|
||||
DOUT << "2addr: COMMUTING FAILED!\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
DOUT << "2addr: COMMUTED TO: " << *NewMI;
|
||||
// If the instruction changed to commute it, update livevar.
|
||||
if (NewMI != MI) {
|
||||
if (LV)
|
||||
// Update live variables
|
||||
LV->replaceKillInstruction(RegC, MI, NewMI);
|
||||
|
||||
mbbi->insert(mi, NewMI); // Insert the new inst
|
||||
mbbi->erase(mi); // Nuke the old inst.
|
||||
mi = NewMI;
|
||||
DistanceMap.insert(std::make_pair(NewMI, Dist));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// runOnMachineFunction - Reduce two-address instructions to two operands.
|
||||
///
|
||||
bool TwoAddressInstructionPass::runOnMachineFunction(MachineFunction &MF) {
|
||||
@ -337,27 +374,8 @@ bool TwoAddressInstructionPass::runOnMachineFunction(MachineFunction &MF) {
|
||||
assert(mi->getOperand(3-si).isReg() &&
|
||||
"Not a proper commutative instruction!");
|
||||
unsigned regC = mi->getOperand(3-si).getReg();
|
||||
|
||||
if (mi->killsRegister(regC)) {
|
||||
DOUT << "2addr: COMMUTING : " << *mi;
|
||||
MachineInstr *NewMI = TII->commuteInstruction(mi);
|
||||
|
||||
if (NewMI == 0) {
|
||||
DOUT << "2addr: COMMUTING FAILED!\n";
|
||||
} else {
|
||||
DOUT << "2addr: COMMUTED TO: " << *NewMI;
|
||||
// If the instruction changed to commute it, update livevar.
|
||||
if (NewMI != mi) {
|
||||
if (LV)
|
||||
// Update live variables
|
||||
LV->replaceKillInstruction(regC, mi, NewMI);
|
||||
|
||||
mbbi->insert(mi, NewMI); // Insert the new inst
|
||||
mbbi->erase(mi); // Nuke the old inst.
|
||||
mi = NewMI;
|
||||
DistanceMap.insert(std::make_pair(NewMI, Dist));
|
||||
}
|
||||
|
||||
if (CommuteInstruction(mi, mbbi, regC, Dist, DistanceMap)) {
|
||||
++NumCommuted;
|
||||
regB = regC;
|
||||
goto InstructionRearranged;
|
||||
|
Loading…
Reference in New Issue
Block a user