pointer so that they do not all get leaked!
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@2188
91177308-0d34-0410-b5e6-
96231b3b80d8
PhyRegAlloc::~PhyRegAlloc() {
for( unsigned int rc=0; rc < NumOfRegClasses; rc++)
delete RegClassList[rc];
PhyRegAlloc::~PhyRegAlloc() {
for( unsigned int rc=0; rc < NumOfRegClasses; rc++)
delete RegClassList[rc];
+
+ AddedInstrMap.clear();
}
//----------------------------------------------------------------------------
}
//----------------------------------------------------------------------------
if (TM.getInstrInfo().isCall(Opcode) ||
TM.getInstrInfo().isReturn(Opcode)) {
if (TM.getInstrInfo().isCall(Opcode) ||
TM.getInstrInfo().isReturn(Opcode)) {
- AddedInstrns *AI = AddedInstrMap[ MInst];
- if ( !AI ) {
- AI = new AddedInstrns();
- AddedInstrMap[ MInst ] = AI;
- }
+ AddedInstrns &AI = AddedInstrMap[MInst];
// Tmp stack poistions are needed by some calls that have spilled args
// So reset it before we call each such method
// Tmp stack poistions are needed by some calls that have spilled args
// So reset it before we call each such method
mcInfo.popAllTempValues(TM);
if (TM.getInstrInfo().isCall(Opcode))
mcInfo.popAllTempValues(TM);
if (TM.getInstrInfo().isCall(Opcode))
- MRI.colorCallArgs(MInst, LRI, AI, *this, *BBI);
+ MRI.colorCallArgs(MInst, LRI, &AI, *this, *BBI);
else if (TM.getInstrInfo().isReturn(Opcode))
else if (TM.getInstrInfo().isReturn(Opcode))
- MRI.colorRetValue(MInst, LRI, AI);
+ MRI.colorRetValue(MInst, LRI, &AI);
// If there are instructions to be added, *before* this machine
// instruction, add them now.
//
// If there are instructions to be added, *before* this machine
// instruction, add them now.
//
- if( AddedInstrMap[ MInst ] ) {
- std::deque<MachineInstr *> &IBef = AddedInstrMap[MInst]->InstrnsBefore;
+ if(AddedInstrMap.count(MInst)) {
+ std::deque<MachineInstr *> &IBef = AddedInstrMap[MInst].InstrnsBefore;
if( ! IBef.empty() ) {
std::deque<MachineInstr *>::iterator AdIt;
if( ! IBef.empty() ) {
std::deque<MachineInstr *>::iterator AdIt;
// If there are instructions to be added *after* this machine
// instruction, add them now
//
// If there are instructions to be added *after* this machine
// instruction, add them now
//
- if(AddedInstrMap[MInst] &&
- !AddedInstrMap[MInst]->InstrnsAfter.empty() ) {
+ if (!AddedInstrMap[MInst].InstrnsAfter.empty()) {
// if there are delay slots for this instruction, the instructions
// added after it must really go after the delayed instruction(s)
// if there are delay slots for this instruction, the instructions
// added after it must really go after the delayed instruction(s)
// Here we can add the "instructions after" to the current
// instruction since there are no delay slots for this instruction
// Here we can add the "instructions after" to the current
// instruction since there are no delay slots for this instruction
- std::deque<MachineInstr *> &IAft = AddedInstrMap[MInst]->InstrnsAfter;
+ std::deque<MachineInstr *> &IAft = AddedInstrMap[MInst].InstrnsAfter;
- if( ! IAft.empty() ) {
-
- std::deque<MachineInstr *>::iterator AdIt;
-
++MInstIterator; // advance to the next instruction
++MInstIterator; // advance to the next instruction
+ std::deque<MachineInstr *>::iterator AdIt;
for( AdIt = IAft.begin(); AdIt != IAft.end() ; ++AdIt ) {
if(DEBUG_RA) {
for( AdIt = IAft.begin(); AdIt != IAft.end() ; ++AdIt ) {
if(DEBUG_RA) {
int TmpRegU = getUsableUniRegAtMI(RC, RegType, MInst,&LVSetBef, MIBef, MIAft);
// get the added instructions for this instruciton
int TmpRegU = getUsableUniRegAtMI(RC, RegType, MInst,&LVSetBef, MIBef, MIAft);
// get the added instructions for this instruciton
- AddedInstrns *AI = AddedInstrMap[ MInst ];
- if ( !AI ) {
- AI = new AddedInstrns();
- AddedInstrMap[ MInst ] = AI;
- }
-
+ AddedInstrns &AI = AddedInstrMap[MInst];
// for a USE, we have to load the value of LR from stack to a TmpReg
// and use the TmpReg as one operand of instruction
// for a USE, we have to load the value of LR from stack to a TmpReg
// and use the TmpReg as one operand of instruction
AdIMid = MRI.cpMem2RegMI(MRI.getFramePointer(), SpillOff, TmpRegU,RegType);
if(MIBef)
AdIMid = MRI.cpMem2RegMI(MRI.getFramePointer(), SpillOff, TmpRegU,RegType);
if(MIBef)
- AI->InstrnsBefore.push_back(MIBef);
+ AI.InstrnsBefore.push_back(MIBef);
- AI->InstrnsBefore.push_back(AdIMid);
+ AI.InstrnsBefore.push_back(AdIMid);
- AI->InstrnsAfter.push_front(MIAft);
+ AI.InstrnsAfter.push_front(MIAft);
} else { // if this is a Def
// for a DEF, we have to store the value produced by this instruction
} else { // if this is a Def
// for a DEF, we have to store the value produced by this instruction
AdIMid = MRI.cpReg2MemMI(TmpRegU, MRI.getFramePointer(), SpillOff,RegType);
if (MIBef)
AdIMid = MRI.cpReg2MemMI(TmpRegU, MRI.getFramePointer(), SpillOff,RegType);
if (MIBef)
- AI->InstrnsBefore.push_back(MIBef);
+ AI.InstrnsBefore.push_back(MIBef);
- AI->InstrnsAfter.push_front(AdIMid);
+ AI.InstrnsAfter.push_front(AdIMid);
- AI->InstrnsAfter.push_front(MIAft);
+ AI.InstrnsAfter.push_front(MIAft);
// corresponding delayed instruction using the following method.
//----------------------------------------------------------------------------
// corresponding delayed instruction using the following method.
//----------------------------------------------------------------------------
-void PhyRegAlloc:: move2DelayedInstr(const MachineInstr *OrigMI,
- const MachineInstr *DelayedMI) {
+void PhyRegAlloc::move2DelayedInstr(const MachineInstr *OrigMI,
+ const MachineInstr *DelayedMI) {
// "added after" instructions of the original instr
// "added after" instructions of the original instr
- std::deque<MachineInstr *> &OrigAft = AddedInstrMap[OrigMI]->InstrnsAfter;
+ std::deque<MachineInstr *> &OrigAft = AddedInstrMap[OrigMI].InstrnsAfter;
// "added instructions" of the delayed instr
// "added instructions" of the delayed instr
- AddedInstrns *DelayAdI = AddedInstrMap[DelayedMI];
-
- if(! DelayAdI ) { // create a new "added after" if necessary
- DelayAdI = new AddedInstrns();
- AddedInstrMap[DelayedMI] = DelayAdI;
- }
+ AddedInstrns &DelayAdI = AddedInstrMap[DelayedMI];
// "added after" instructions of the delayed instr
// "added after" instructions of the delayed instr
- std::deque<MachineInstr *> &DelayedAft = DelayAdI->InstrnsAfter;
+ std::deque<MachineInstr *> &DelayedAft = DelayAdI.InstrnsAfter;
// go thru all the "added after instructions" of the original instruction
// and append them to the "addded after instructions" of the delayed
// go thru all the "added after instructions" of the original instruction
// and append them to the "addded after instructions" of the delayed
unsigned OpCode = CRMI->getOpCode();
// get the added instructions for this Call/Ret instruciton
unsigned OpCode = CRMI->getOpCode();
// get the added instructions for this Call/Ret instruciton
- AddedInstrns *AI = AddedInstrMap[ CRMI ];
- if ( !AI ) {
- AI = new AddedInstrns();
- AddedInstrMap[ CRMI ] = AI;
- }
+ AddedInstrns &AI = AddedInstrMap[CRMI];
- // Tmp stack poistions are needed by some calls that have spilled args
+ // Tmp stack positions are needed by some calls that have spilled args
// So reset it before we call each such method
//mcInfo.popAllTempValues(TM);
if (TM.getInstrInfo().isCall(OpCode))
// So reset it before we call each such method
//mcInfo.popAllTempValues(TM);
if (TM.getInstrInfo().isCall(OpCode))
- MRI.colorCallArgs(CRMI, LRI, AI, *this);
+ MRI.colorCallArgs(CRMI, LRI, &AI, *this);
else if (TM.getInstrInfo().isReturn(OpCode))
else if (TM.getInstrInfo().isReturn(OpCode))
- MRI.colorRetValue( CRMI, LRI, AI );
+ MRI.colorRetValue(CRMI, LRI, &AI);
else
assert(0 && "Non Call/Ret instrn in CallRetInstrList\n");
}
else
assert(0 && "Non Call/Ret instrn in CallRetInstrList\n");
}
const MachineInstr *FirstMI = FirstBB->getMachineInstrVec().front();
assert(FirstMI && "No machine instruction in entry BB");
const MachineInstr *FirstMI = FirstBB->getMachineInstrVec().front();
assert(FirstMI && "No machine instruction in entry BB");
- AddedInstrns *AI = AddedInstrMap[FirstMI];
- if (!AI)
- AddedInstrMap[FirstMI] = AI = new AddedInstrns();
-
- MRI.colorMethodArgs(Meth, LRI, AI);
+ MRI.colorMethodArgs(Meth, LRI, &AddedInstrMap[FirstMI]);
// to store such instructions added before and after an existing instruction.
//----------------------------------------------------------------------------
// to store such instructions added before and after an existing instruction.
//----------------------------------------------------------------------------
-class AddedInstrns
-{
- public:
std::deque<MachineInstr*> InstrnsBefore;// Added insts BEFORE an existing inst
std::deque<MachineInstr*> InstrnsAfter; // Added insts AFTER an existing inst
};
std::deque<MachineInstr*> InstrnsBefore;// Added insts BEFORE an existing inst
std::deque<MachineInstr*> InstrnsAfter; // Added insts AFTER an existing inst
};
-typedef std::hash_map<const MachineInstr *, AddedInstrns *> AddedInstrMapType;
+typedef std::map<const MachineInstr *, AddedInstrns> AddedInstrMapType;
PhyRegAlloc::~PhyRegAlloc() {
for( unsigned int rc=0; rc < NumOfRegClasses; rc++)
delete RegClassList[rc];
PhyRegAlloc::~PhyRegAlloc() {
for( unsigned int rc=0; rc < NumOfRegClasses; rc++)
delete RegClassList[rc];
+
+ AddedInstrMap.clear();
}
//----------------------------------------------------------------------------
}
//----------------------------------------------------------------------------
if (TM.getInstrInfo().isCall(Opcode) ||
TM.getInstrInfo().isReturn(Opcode)) {
if (TM.getInstrInfo().isCall(Opcode) ||
TM.getInstrInfo().isReturn(Opcode)) {
- AddedInstrns *AI = AddedInstrMap[ MInst];
- if ( !AI ) {
- AI = new AddedInstrns();
- AddedInstrMap[ MInst ] = AI;
- }
+ AddedInstrns &AI = AddedInstrMap[MInst];
// Tmp stack poistions are needed by some calls that have spilled args
// So reset it before we call each such method
// Tmp stack poistions are needed by some calls that have spilled args
// So reset it before we call each such method
mcInfo.popAllTempValues(TM);
if (TM.getInstrInfo().isCall(Opcode))
mcInfo.popAllTempValues(TM);
if (TM.getInstrInfo().isCall(Opcode))
- MRI.colorCallArgs(MInst, LRI, AI, *this, *BBI);
+ MRI.colorCallArgs(MInst, LRI, &AI, *this, *BBI);
else if (TM.getInstrInfo().isReturn(Opcode))
else if (TM.getInstrInfo().isReturn(Opcode))
- MRI.colorRetValue(MInst, LRI, AI);
+ MRI.colorRetValue(MInst, LRI, &AI);
// If there are instructions to be added, *before* this machine
// instruction, add them now.
//
// If there are instructions to be added, *before* this machine
// instruction, add them now.
//
- if( AddedInstrMap[ MInst ] ) {
- std::deque<MachineInstr *> &IBef = AddedInstrMap[MInst]->InstrnsBefore;
+ if(AddedInstrMap.count(MInst)) {
+ std::deque<MachineInstr *> &IBef = AddedInstrMap[MInst].InstrnsBefore;
if( ! IBef.empty() ) {
std::deque<MachineInstr *>::iterator AdIt;
if( ! IBef.empty() ) {
std::deque<MachineInstr *>::iterator AdIt;
// If there are instructions to be added *after* this machine
// instruction, add them now
//
// If there are instructions to be added *after* this machine
// instruction, add them now
//
- if(AddedInstrMap[MInst] &&
- !AddedInstrMap[MInst]->InstrnsAfter.empty() ) {
+ if (!AddedInstrMap[MInst].InstrnsAfter.empty()) {
// if there are delay slots for this instruction, the instructions
// added after it must really go after the delayed instruction(s)
// if there are delay slots for this instruction, the instructions
// added after it must really go after the delayed instruction(s)
// Here we can add the "instructions after" to the current
// instruction since there are no delay slots for this instruction
// Here we can add the "instructions after" to the current
// instruction since there are no delay slots for this instruction
- std::deque<MachineInstr *> &IAft = AddedInstrMap[MInst]->InstrnsAfter;
+ std::deque<MachineInstr *> &IAft = AddedInstrMap[MInst].InstrnsAfter;
- if( ! IAft.empty() ) {
-
- std::deque<MachineInstr *>::iterator AdIt;
-
++MInstIterator; // advance to the next instruction
++MInstIterator; // advance to the next instruction
+ std::deque<MachineInstr *>::iterator AdIt;
for( AdIt = IAft.begin(); AdIt != IAft.end() ; ++AdIt ) {
if(DEBUG_RA) {
for( AdIt = IAft.begin(); AdIt != IAft.end() ; ++AdIt ) {
if(DEBUG_RA) {
int TmpRegU = getUsableUniRegAtMI(RC, RegType, MInst,&LVSetBef, MIBef, MIAft);
// get the added instructions for this instruciton
int TmpRegU = getUsableUniRegAtMI(RC, RegType, MInst,&LVSetBef, MIBef, MIAft);
// get the added instructions for this instruciton
- AddedInstrns *AI = AddedInstrMap[ MInst ];
- if ( !AI ) {
- AI = new AddedInstrns();
- AddedInstrMap[ MInst ] = AI;
- }
-
+ AddedInstrns &AI = AddedInstrMap[MInst];
// for a USE, we have to load the value of LR from stack to a TmpReg
// and use the TmpReg as one operand of instruction
// for a USE, we have to load the value of LR from stack to a TmpReg
// and use the TmpReg as one operand of instruction
AdIMid = MRI.cpMem2RegMI(MRI.getFramePointer(), SpillOff, TmpRegU,RegType);
if(MIBef)
AdIMid = MRI.cpMem2RegMI(MRI.getFramePointer(), SpillOff, TmpRegU,RegType);
if(MIBef)
- AI->InstrnsBefore.push_back(MIBef);
+ AI.InstrnsBefore.push_back(MIBef);
- AI->InstrnsBefore.push_back(AdIMid);
+ AI.InstrnsBefore.push_back(AdIMid);
- AI->InstrnsAfter.push_front(MIAft);
+ AI.InstrnsAfter.push_front(MIAft);
} else { // if this is a Def
// for a DEF, we have to store the value produced by this instruction
} else { // if this is a Def
// for a DEF, we have to store the value produced by this instruction
AdIMid = MRI.cpReg2MemMI(TmpRegU, MRI.getFramePointer(), SpillOff,RegType);
if (MIBef)
AdIMid = MRI.cpReg2MemMI(TmpRegU, MRI.getFramePointer(), SpillOff,RegType);
if (MIBef)
- AI->InstrnsBefore.push_back(MIBef);
+ AI.InstrnsBefore.push_back(MIBef);
- AI->InstrnsAfter.push_front(AdIMid);
+ AI.InstrnsAfter.push_front(AdIMid);
- AI->InstrnsAfter.push_front(MIAft);
+ AI.InstrnsAfter.push_front(MIAft);
// corresponding delayed instruction using the following method.
//----------------------------------------------------------------------------
// corresponding delayed instruction using the following method.
//----------------------------------------------------------------------------
-void PhyRegAlloc:: move2DelayedInstr(const MachineInstr *OrigMI,
- const MachineInstr *DelayedMI) {
+void PhyRegAlloc::move2DelayedInstr(const MachineInstr *OrigMI,
+ const MachineInstr *DelayedMI) {
// "added after" instructions of the original instr
// "added after" instructions of the original instr
- std::deque<MachineInstr *> &OrigAft = AddedInstrMap[OrigMI]->InstrnsAfter;
+ std::deque<MachineInstr *> &OrigAft = AddedInstrMap[OrigMI].InstrnsAfter;
// "added instructions" of the delayed instr
// "added instructions" of the delayed instr
- AddedInstrns *DelayAdI = AddedInstrMap[DelayedMI];
-
- if(! DelayAdI ) { // create a new "added after" if necessary
- DelayAdI = new AddedInstrns();
- AddedInstrMap[DelayedMI] = DelayAdI;
- }
+ AddedInstrns &DelayAdI = AddedInstrMap[DelayedMI];
// "added after" instructions of the delayed instr
// "added after" instructions of the delayed instr
- std::deque<MachineInstr *> &DelayedAft = DelayAdI->InstrnsAfter;
+ std::deque<MachineInstr *> &DelayedAft = DelayAdI.InstrnsAfter;
// go thru all the "added after instructions" of the original instruction
// and append them to the "addded after instructions" of the delayed
// go thru all the "added after instructions" of the original instruction
// and append them to the "addded after instructions" of the delayed
unsigned OpCode = CRMI->getOpCode();
// get the added instructions for this Call/Ret instruciton
unsigned OpCode = CRMI->getOpCode();
// get the added instructions for this Call/Ret instruciton
- AddedInstrns *AI = AddedInstrMap[ CRMI ];
- if ( !AI ) {
- AI = new AddedInstrns();
- AddedInstrMap[ CRMI ] = AI;
- }
+ AddedInstrns &AI = AddedInstrMap[CRMI];
- // Tmp stack poistions are needed by some calls that have spilled args
+ // Tmp stack positions are needed by some calls that have spilled args
// So reset it before we call each such method
//mcInfo.popAllTempValues(TM);
if (TM.getInstrInfo().isCall(OpCode))
// So reset it before we call each such method
//mcInfo.popAllTempValues(TM);
if (TM.getInstrInfo().isCall(OpCode))
- MRI.colorCallArgs(CRMI, LRI, AI, *this);
+ MRI.colorCallArgs(CRMI, LRI, &AI, *this);
else if (TM.getInstrInfo().isReturn(OpCode))
else if (TM.getInstrInfo().isReturn(OpCode))
- MRI.colorRetValue( CRMI, LRI, AI );
+ MRI.colorRetValue(CRMI, LRI, &AI);
else
assert(0 && "Non Call/Ret instrn in CallRetInstrList\n");
}
else
assert(0 && "Non Call/Ret instrn in CallRetInstrList\n");
}
const MachineInstr *FirstMI = FirstBB->getMachineInstrVec().front();
assert(FirstMI && "No machine instruction in entry BB");
const MachineInstr *FirstMI = FirstBB->getMachineInstrVec().front();
assert(FirstMI && "No machine instruction in entry BB");
- AddedInstrns *AI = AddedInstrMap[FirstMI];
- if (!AI)
- AddedInstrMap[FirstMI] = AI = new AddedInstrns();
-
- MRI.colorMethodArgs(Meth, LRI, AI);
+ MRI.colorMethodArgs(Meth, LRI, &AddedInstrMap[FirstMI]);
// to store such instructions added before and after an existing instruction.
//----------------------------------------------------------------------------
// to store such instructions added before and after an existing instruction.
//----------------------------------------------------------------------------
-class AddedInstrns
-{
- public:
std::deque<MachineInstr*> InstrnsBefore;// Added insts BEFORE an existing inst
std::deque<MachineInstr*> InstrnsAfter; // Added insts AFTER an existing inst
};
std::deque<MachineInstr*> InstrnsBefore;// Added insts BEFORE an existing inst
std::deque<MachineInstr*> InstrnsAfter; // Added insts AFTER an existing inst
};
-typedef std::hash_map<const MachineInstr *, AddedInstrns *> AddedInstrMapType;
+typedef std::map<const MachineInstr *, AddedInstrns> AddedInstrMapType;
// adding them to the front of InstrnsBefore
if(AdIAftCC)
// adding them to the front of InstrnsBefore
if(AdIAftCC)
- PRA.AddedInstrMap[MInst]->InstrnsBefore.push_front(AdIAftCC);
+ PRA.AddedInstrMap[MInst].InstrnsBefore.push_front(AdIAftCC);
AdICpCC = cpCCR2IntMI(FreeIntReg);
AdICpCC = cpCCR2IntMI(FreeIntReg);
- PRA.AddedInstrMap[MInst]->InstrnsBefore.push_front(AdICpCC);
+ PRA.AddedInstrMap[MInst].InstrnsBefore.push_front(AdICpCC);
- PRA.AddedInstrMap[MInst]->InstrnsBefore.push_front(AdIBefCC);
+ PRA.AddedInstrMap[MInst].InstrnsBefore.push_front(AdIBefCC);
if(DEBUG_RA) {
cerr << "\n!! Inserted caller saving (push) inst for %ccr:";
if(DEBUG_RA) {
cerr << "\n!! Inserted caller saving (push) inst for %ccr:";
} else {
// for any other register type, just add the push inst
AdIBef = cpReg2MemMI(Reg, getFramePointer(), StackOff, RegType );
} else {
// for any other register type, just add the push inst
AdIBef = cpReg2MemMI(Reg, getFramePointer(), StackOff, RegType );
- PRA.AddedInstrMap[MInst]->InstrnsBefore.push_front(AdIBef);
+ PRA.AddedInstrMap[MInst].InstrnsBefore.push_front(AdIBef);
IntRegType, MInst, &LVSetAft, AdIBefCC, AdIAftCC);
if(AdIBefCC)
IntRegType, MInst, &LVSetAft, AdIBefCC, AdIAftCC);
if(AdIBefCC)
- PRA.AddedInstrMap[MInst]->InstrnsAfter.push_back(AdIBefCC);
+ PRA.AddedInstrMap[MInst].InstrnsAfter.push_back(AdIBefCC);
AdICpCC = cpInt2CCRMI(FreeIntReg);
AdICpCC = cpInt2CCRMI(FreeIntReg);
- PRA.AddedInstrMap[MInst]->InstrnsAfter.push_back(AdICpCC);
+ PRA.AddedInstrMap[MInst].InstrnsAfter.push_back(AdICpCC);
- PRA.AddedInstrMap[MInst]->InstrnsAfter.push_back(AdIAftCC);
+ PRA.AddedInstrMap[MInst].InstrnsAfter.push_back(AdIAftCC);
} else {
// for any other register type, just add the pop inst
AdIAft = cpMem2RegMI(getFramePointer(), StackOff, Reg, RegType );
} else {
// for any other register type, just add the pop inst
AdIAft = cpMem2RegMI(getFramePointer(), StackOff, Reg, RegType );
- PRA.AddedInstrMap[MInst]->InstrnsAfter.push_back(AdIAft);
+ PRA.AddedInstrMap[MInst].InstrnsAfter.push_back(AdIAft);
}
PushedRegSet.insert(Reg);
}
PushedRegSet.insert(Reg);