Meth(M), TM(tm), LVI(Lvi), LRI(M, tm, RegClassList),
MRI( tm.getRegInfo() ),
NumOfRegClasses(MRI.getNumOfRegClasses()),
- AddedInstrMap(), StackOffsets()
+ AddedInstrMap(), StackOffsets(), PhiInstList()
{
// **TODO: use an actual reserved color list
// iterate over all the machine instructions in BB
for( ; MInstIterator != MIVec.end(); ++MInstIterator) {
- const MachineInstr *const MInst = *MInstIterator;
+ const MachineInstr * MInst = *MInstIterator;
// get the LV set after the instruction
const LiveVarSet *const LVSetAI =
addInterference( MInst->getImplicitRef(z), LVSetAI, isCallInst );
}
+
+ // record phi instrns in PhiInstList
+ if( TM.getInstrInfo().isDummyPhiInstr(MInst->getOpCode()) )
+ PhiInstList.push_back( MInst );
+
+
} // for all machine instructions in BB
} // for all BBs in method
+void PhyRegAlloc::insertPhiEleminateInstrns() {
+
+ vector< const MachineInstr *>:: const_iterator It = PhiInstList.begin();
+
+ for( ; It != PhiInstList.end(); ++It ) {
+
+ const MachineInstr *PhiMI = *It;
+
+ Value *Def = (PhiMI->getOperand(0)).getVRegValue();
+ const LiveRange *LROfDef = LRI.getLiveRangeForValue( Def );
+
+ assert(LROfDef && "NO LR for a def of phi");
+
+ for(unsigned OpNum=1; OpNum < PhiMI->getNumOperands(); ++OpNum) {
+
+ if( OpNum % 2) { // i.e., the
+
+ Value *Use = (PhiMI->getOperand(OpNum)).getVRegValue();
+
+ const LiveRange *LROfUse = LRI.getLiveRangeForValue( Use );
+
+ if( LROfUse != LROfDef) {
+
+ // the result of the phi received a live range different to
+ // that of this use, so copy it
+
+ const BasicBlock *BB =
+ (BasicBlock *) (PhiMI->getOperand(OpNum+1)).getVRegValue();
+
+ MachineCodeForBasicBlock& MIVec = (BB)->getMachineInstrVec();
+
+ MachineInstr *AdI = MRI.cpValue2Value(Use, Def);
+
+ MIVec.push_back( AdI );
+
+ cerr << "\n%%% Added a phi elimination instr: " << *AdI;
+
+ } // if LRs are different
+
+ } // if operand is an incoming Value (i.e., not a BB)
+
+ } // for all phi operands
+
+ } // for all phi instrns in PhiInstMap
+
+}
+
//----------------------------------------------------------------------------
LRI.coalesceLRs(); // coalesce all live ranges
+ // coalscing could not get rid of all phi's, add phi elimination
+ // instructions
+ // insertPhiEleminateInstrns();
+
if( DEBUG_RA) {
// print all LRs in all reg classes
for( unsigned int rc=0; rc < NumOfRegClasses ; rc++)
Meth(M), TM(tm), LVI(Lvi), LRI(M, tm, RegClassList),
MRI( tm.getRegInfo() ),
NumOfRegClasses(MRI.getNumOfRegClasses()),
- AddedInstrMap(), StackOffsets()
+ AddedInstrMap(), StackOffsets(), PhiInstList()
{
// **TODO: use an actual reserved color list
// iterate over all the machine instructions in BB
for( ; MInstIterator != MIVec.end(); ++MInstIterator) {
- const MachineInstr *const MInst = *MInstIterator;
+ const MachineInstr * MInst = *MInstIterator;
// get the LV set after the instruction
const LiveVarSet *const LVSetAI =
addInterference( MInst->getImplicitRef(z), LVSetAI, isCallInst );
}
+
+ // record phi instrns in PhiInstList
+ if( TM.getInstrInfo().isDummyPhiInstr(MInst->getOpCode()) )
+ PhiInstList.push_back( MInst );
+
+
} // for all machine instructions in BB
} // for all BBs in method
+void PhyRegAlloc::insertPhiEleminateInstrns() {
+
+ vector< const MachineInstr *>:: const_iterator It = PhiInstList.begin();
+
+ for( ; It != PhiInstList.end(); ++It ) {
+
+ const MachineInstr *PhiMI = *It;
+
+ Value *Def = (PhiMI->getOperand(0)).getVRegValue();
+ const LiveRange *LROfDef = LRI.getLiveRangeForValue( Def );
+
+ assert(LROfDef && "NO LR for a def of phi");
+
+ for(unsigned OpNum=1; OpNum < PhiMI->getNumOperands(); ++OpNum) {
+
+ if( OpNum % 2) { // i.e., the
+
+ Value *Use = (PhiMI->getOperand(OpNum)).getVRegValue();
+
+ const LiveRange *LROfUse = LRI.getLiveRangeForValue( Use );
+
+ if( LROfUse != LROfDef) {
+
+ // the result of the phi received a live range different to
+ // that of this use, so copy it
+
+ const BasicBlock *BB =
+ (BasicBlock *) (PhiMI->getOperand(OpNum+1)).getVRegValue();
+
+ MachineCodeForBasicBlock& MIVec = (BB)->getMachineInstrVec();
+
+ MachineInstr *AdI = MRI.cpValue2Value(Use, Def);
+
+ MIVec.push_back( AdI );
+
+ cerr << "\n%%% Added a phi elimination instr: " << *AdI;
+
+ } // if LRs are different
+
+ } // if operand is an incoming Value (i.e., not a BB)
+
+ } // for all phi operands
+
+ } // for all phi instrns in PhiInstMap
+
+}
+
//----------------------------------------------------------------------------
LRI.coalesceLRs(); // coalesce all live ranges
+ // coalscing could not get rid of all phi's, add phi elimination
+ // instructions
+ // insertPhiEleminateInstrns();
+
if( DEBUG_RA) {
// print all LRs in all reg classes
for( unsigned int rc=0; rc < NumOfRegClasses ; rc++)
MachineInstr * cpMem2RegMI(const unsigned SrcPtrReg, const int Offset,
const unsigned DestReg, const int RegType) const;
+ MachineInstr* cpValue2Value(Value *Src, Value *Dest) const;
+
+
inline bool isRegVolatile(const int RegClassID, const int Reg) const {
return (MachineRegClassArr[RegClassID])->isRegVolatile(Reg);
}
}
+MachineInstr* UltraSparcRegInfo::cpValue2Value(Value *Src, Value *Dest) const {
+ MachineInstr * MI = NULL;
+
+ MI = new MachineInstr(ADD, 3);
+ MI->SetMachineOperand(0, MachineOperand:: MO_VirtualRegister, Src, false);
+ MI->SetMachineOperand(1, SparcIntRegOrder::g0, false);
+ MI->SetMachineOperand(2, MachineOperand:: MO_VirtualRegister, Dest, true);
+
+
+ return MI;
+
+}