Use vector for machine instructions returned by GetInstructionsByRule.
Fix constants in instructions generated for Phi elimination. llvm-svn: 1902
This commit is contained in:
parent
cecde7122c
commit
d2c71c1d08
|
@ -31,9 +31,6 @@ using std::cerr;
|
||||||
|
|
||||||
//******************** Internal Data Declarations ************************/
|
//******************** Internal Data Declarations ************************/
|
||||||
|
|
||||||
// Use a static vector to avoid allocating a new one per VM instruction
|
|
||||||
static MachineInstr* minstrVec[MAX_INSTR_PER_VMINSTR];
|
|
||||||
|
|
||||||
|
|
||||||
enum SelectDebugLevel_t {
|
enum SelectDebugLevel_t {
|
||||||
Select_NoDebugInfo,
|
Select_NoDebugInfo,
|
||||||
|
@ -87,6 +84,11 @@ SelectInstructionsForMethod(Method* method, TargetMachine &target)
|
||||||
|
|
||||||
if (SelectDebugLevel >= Select_DebugInstTrees)
|
if (SelectDebugLevel >= Select_DebugInstTrees)
|
||||||
{
|
{
|
||||||
|
cerr << "\n\n*** Input to instruction selection for method "
|
||||||
|
<< (method->hasName()? method->getName() : "")
|
||||||
|
<< "\n\n";
|
||||||
|
method->dump();
|
||||||
|
|
||||||
cerr << "\n\n*** Instruction trees for method "
|
cerr << "\n\n*** Instruction trees for method "
|
||||||
<< (method->hasName()? method->getName() : "")
|
<< (method->hasName()? method->getName() : "")
|
||||||
<< "\n\n";
|
<< "\n\n";
|
||||||
|
@ -157,85 +159,40 @@ SelectInstructionsForMethod(Method* method, TargetMachine &target)
|
||||||
// of phi elimination.
|
// of phi elimination.
|
||||||
//-------------------------------------------------------------------------
|
//-------------------------------------------------------------------------
|
||||||
|
|
||||||
void InsertPhiElimInst(BasicBlock *BB, MachineInstr *CpMI) {
|
void
|
||||||
|
InsertPhiElimInstructions(BasicBlock *BB, const vector<MachineInstr*>& CpVec)
|
||||||
|
{
|
||||||
Instruction *TermInst = (Instruction*)BB->getTerminator();
|
Instruction *TermInst = (Instruction*)BB->getTerminator();
|
||||||
MachineCodeForInstruction &MC4Term = MachineCodeForInstruction::get(TermInst);
|
MachineCodeForInstruction &MC4Term = MachineCodeForInstruction::get(TermInst);
|
||||||
MachineInstr *FirstMIOfTerm = *( MC4Term.begin() );
|
MachineInstr *FirstMIOfTerm = *( MC4Term.begin() );
|
||||||
|
|
||||||
assert( FirstMIOfTerm && "No Machine Instrs for terminator" );
|
assert( FirstMIOfTerm && "No Machine Instrs for terminator" );
|
||||||
|
|
||||||
// get an iterator to machine instructions in the BB
|
// get an iterator to machine instructions in the BB
|
||||||
MachineCodeForBasicBlock& bbMvec = BB->getMachineInstrVec();
|
MachineCodeForBasicBlock& bbMvec = BB->getMachineInstrVec();
|
||||||
MachineCodeForBasicBlock::iterator MCIt = bbMvec.begin();
|
MachineCodeForBasicBlock::iterator MCIt = bbMvec.begin();
|
||||||
|
|
||||||
// find the position of first machine instruction generated by the
|
// find the position of first machine instruction generated by the
|
||||||
// terminator of this BB
|
// terminator of this BB
|
||||||
for( ; (MCIt != bbMvec.end()) && (*MCIt != FirstMIOfTerm) ; ++MCIt ) ;
|
for( ; (MCIt != bbMvec.end()) && (*MCIt != FirstMIOfTerm) ; ++MCIt )
|
||||||
|
;
|
||||||
assert( MCIt != bbMvec.end() && "Start inst of terminator not found");
|
assert( MCIt != bbMvec.end() && "Start inst of terminator not found");
|
||||||
|
|
||||||
// insert the copy instruction just before the first machine instruction
|
// insert the copy instructions just before the first machine instruction
|
||||||
// generated for the terminator
|
// generated for the terminator
|
||||||
bbMvec.insert( MCIt , CpMI );
|
bbMvec.insert(MCIt, CpVec.begin(), CpVec.end());
|
||||||
|
|
||||||
//cerr << "\nPhiElimination copy inst: " << *CopyInstVec[0];
|
//cerr << "\nPhiElimination copy inst: " << *CopyInstVec[0];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
|
||||||
//-------------------------------------------------------------------------
|
|
||||||
// This method inserts phi elimination code for all BBs in a method
|
|
||||||
//-------------------------------------------------------------------------
|
|
||||||
void InsertCode4AllPhisInMeth(Method *method, TargetMachine &target) {
|
|
||||||
|
|
||||||
|
|
||||||
// for all basic blocks in method
|
|
||||||
//
|
|
||||||
for (Method::iterator BI = method->begin(); BI != method->end(); ++BI) {
|
|
||||||
|
|
||||||
BasicBlock *BB = *BI;
|
|
||||||
const BasicBlock::InstListType &InstList = BB->getInstList();
|
|
||||||
BasicBlock::InstListType::const_iterator IIt = InstList.begin();
|
|
||||||
|
|
||||||
// for all instructions in the basic block
|
|
||||||
//
|
|
||||||
for( ; IIt != InstList.end(); ++IIt ) {
|
|
||||||
|
|
||||||
if( (*IIt)->getOpcode() == Instruction::PHINode ) {
|
|
||||||
|
|
||||||
PHINode *PN = (PHINode *) (*IIt);
|
|
||||||
|
|
||||||
// for each incoming value of the phi, insert phi elimination
|
|
||||||
//
|
|
||||||
for (unsigned i = 0; i < PN->getNumIncomingValues(); ++i) {
|
|
||||||
|
|
||||||
// insert the copy instruction to the predecessor BB
|
|
||||||
|
|
||||||
std::vector<MachineInstr*> CopyInstVec;
|
|
||||||
|
|
||||||
MachineInstr *CpMI =
|
|
||||||
target.getRegInfo().cpValue2Value(PN->getIncomingValue(i), PN);
|
|
||||||
|
|
||||||
InsertPhiElimInst( PN->getIncomingBlock(i), CpMI);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else break; // since PHI nodes can only be at the top
|
|
||||||
|
|
||||||
} // for each Phi Instr in BB
|
|
||||||
|
|
||||||
} // for all BBs in method
|
|
||||||
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
//-------------------------------------------------------------------------
|
//-------------------------------------------------------------------------
|
||||||
// This method inserts phi elimination code for all BBs in a method
|
// This method inserts phi elimination code for all BBs in a method
|
||||||
//-------------------------------------------------------------------------
|
//-------------------------------------------------------------------------
|
||||||
void InsertCode4AllPhisInMeth(Method *method, TargetMachine &target) {
|
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
InsertCode4AllPhisInMeth(Method *method, TargetMachine &target)
|
||||||
|
{
|
||||||
// for all basic blocks in method
|
// for all basic blocks in method
|
||||||
//
|
//
|
||||||
for (Method::iterator BI = method->begin(); BI != method->end(); ++BI) {
|
for (Method::iterator BI = method->begin(); BI != method->end(); ++BI) {
|
||||||
|
@ -261,10 +218,13 @@ void InsertCode4AllPhisInMeth(Method *method, TargetMachine &target) {
|
||||||
MachineInstr *CpMI =
|
MachineInstr *CpMI =
|
||||||
target.getRegInfo().cpValue2Value(PN->getIncomingValue(i),
|
target.getRegInfo().cpValue2Value(PN->getIncomingValue(i),
|
||||||
PhiCpRes);
|
PhiCpRes);
|
||||||
|
|
||||||
InsertPhiElimInst(PN->getIncomingBlock(i), CpMI);
|
vector<MachineInstr*> CpVec = FixConstantOperandsForInstr(PN, CpMI, target);
|
||||||
|
CpVec.push_back(CpMI);
|
||||||
|
|
||||||
|
InsertPhiElimInstructions(PN->getIncomingBlock(i), CpVec);
|
||||||
}
|
}
|
||||||
|
|
||||||
MachineInstr *CpMI2 =
|
MachineInstr *CpMI2 =
|
||||||
target.getRegInfo().cpValue2Value(PhiCpRes, PN);
|
target.getRegInfo().cpValue2Value(PhiCpRes, PN);
|
||||||
|
|
||||||
|
@ -352,15 +312,16 @@ SelectInstructionsForTree(InstrTreeNode* treeRoot, int goalnt,
|
||||||
//
|
//
|
||||||
if (treeRoot->opLabel != VRegListOp)
|
if (treeRoot->opLabel != VRegListOp)
|
||||||
{
|
{
|
||||||
|
vector<MachineInstr*> minstrVec;
|
||||||
|
|
||||||
InstructionNode* instrNode = (InstructionNode*)treeRoot;
|
InstructionNode* instrNode = (InstructionNode*)treeRoot;
|
||||||
assert(instrNode->getNodeType() == InstrTreeNode::NTInstructionNode);
|
assert(instrNode->getNodeType() == InstrTreeNode::NTInstructionNode);
|
||||||
|
|
||||||
unsigned N = GetInstructionsByRule(instrNode, ruleForNode, nts, target,
|
GetInstructionsByRule(instrNode, ruleForNode, nts, target, minstrVec);
|
||||||
minstrVec);
|
|
||||||
assert(N <= MAX_INSTR_PER_VMINSTR);
|
|
||||||
MachineCodeForInstruction &mvec =
|
MachineCodeForInstruction &mvec =
|
||||||
MachineCodeForInstruction::get(instrNode->getInstruction());
|
MachineCodeForInstruction::get(instrNode->getInstruction());
|
||||||
mvec.insert(mvec.end(), minstrVec, minstrVec+N);
|
mvec.insert(mvec.end(), minstrVec.begin(), minstrVec.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Then, recursively compile the child nodes, if any.
|
// Then, recursively compile the child nodes, if any.
|
||||||
|
|
Loading…
Reference in New Issue