Use vector for machine instructions returned by GetInstructionsByRule.

Fix constants in instructions generated for Phi elimination.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@1902 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Vikram S. Adve 2002-03-18 03:31:54 +00:00
parent 705f95e0b7
commit 1ed009f66e
2 changed files with 62 additions and 140 deletions

View File

@ -31,9 +31,6 @@ using std::cerr;
//******************** 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 {
Select_NoDebugInfo,
@ -87,6 +84,11 @@ SelectInstructionsForMethod(Method* method, TargetMachine &target)
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 "
<< (method->hasName()? method->getName() : "")
<< "\n\n";
@ -157,85 +159,40 @@ SelectInstructionsForMethod(Method* method, TargetMachine &target)
// of phi elimination.
//-------------------------------------------------------------------------
void InsertPhiElimInst(BasicBlock *BB, MachineInstr *CpMI) {
void
InsertPhiElimInstructions(BasicBlock *BB, const vector<MachineInstr*>& CpVec)
{
Instruction *TermInst = (Instruction*)BB->getTerminator();
MachineCodeForInstruction &MC4Term = MachineCodeForInstruction::get(TermInst);
MachineInstr *FirstMIOfTerm = *( MC4Term.begin() );
assert( FirstMIOfTerm && "No Machine Instrs for terminator" );
// get an iterator to machine instructions in the BB
MachineCodeForBasicBlock& bbMvec = BB->getMachineInstrVec();
MachineCodeForBasicBlock::iterator MCIt = bbMvec.begin();
// find the position of first machine instruction generated by the
// 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");
// insert the copy instruction just before the first machine instruction
// insert the copy instructions just before the first machine instruction
// generated for the terminator
bbMvec.insert( MCIt , CpMI );
bbMvec.insert(MCIt, CpVec.begin(), CpVec.end());
//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
//-------------------------------------------------------------------------
void InsertCode4AllPhisInMeth(Method *method, TargetMachine &target) {
void
InsertCode4AllPhisInMeth(Method *method, TargetMachine &target)
{
// for all basic blocks in method
//
for (Method::iterator BI = method->begin(); BI != method->end(); ++BI) {
@ -261,10 +218,13 @@ void InsertCode4AllPhisInMeth(Method *method, TargetMachine &target) {
MachineInstr *CpMI =
target.getRegInfo().cpValue2Value(PN->getIncomingValue(i),
PhiCpRes);
InsertPhiElimInst(PN->getIncomingBlock(i), CpMI);
vector<MachineInstr*> CpVec = FixConstantOperandsForInstr(PN, CpMI, target);
CpVec.push_back(CpMI);
InsertPhiElimInstructions(PN->getIncomingBlock(i), CpVec);
}
MachineInstr *CpMI2 =
target.getRegInfo().cpValue2Value(PhiCpRes, PN);
@ -352,15 +312,16 @@ SelectInstructionsForTree(InstrTreeNode* treeRoot, int goalnt,
//
if (treeRoot->opLabel != VRegListOp)
{
vector<MachineInstr*> minstrVec;
InstructionNode* instrNode = (InstructionNode*)treeRoot;
assert(instrNode->getNodeType() == InstrTreeNode::NTInstructionNode);
unsigned N = GetInstructionsByRule(instrNode, ruleForNode, nts, target,
minstrVec);
assert(N <= MAX_INSTR_PER_VMINSTR);
GetInstructionsByRule(instrNode, ruleForNode, nts, target, minstrVec);
MachineCodeForInstruction &mvec =
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.

View File

@ -31,9 +31,6 @@ using std::cerr;
//******************** 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 {
Select_NoDebugInfo,
@ -87,6 +84,11 @@ SelectInstructionsForMethod(Method* method, TargetMachine &target)
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 "
<< (method->hasName()? method->getName() : "")
<< "\n\n";
@ -157,85 +159,40 @@ SelectInstructionsForMethod(Method* method, TargetMachine &target)
// of phi elimination.
//-------------------------------------------------------------------------
void InsertPhiElimInst(BasicBlock *BB, MachineInstr *CpMI) {
void
InsertPhiElimInstructions(BasicBlock *BB, const vector<MachineInstr*>& CpVec)
{
Instruction *TermInst = (Instruction*)BB->getTerminator();
MachineCodeForInstruction &MC4Term = MachineCodeForInstruction::get(TermInst);
MachineInstr *FirstMIOfTerm = *( MC4Term.begin() );
assert( FirstMIOfTerm && "No Machine Instrs for terminator" );
// get an iterator to machine instructions in the BB
MachineCodeForBasicBlock& bbMvec = BB->getMachineInstrVec();
MachineCodeForBasicBlock::iterator MCIt = bbMvec.begin();
// find the position of first machine instruction generated by the
// 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");
// insert the copy instruction just before the first machine instruction
// insert the copy instructions just before the first machine instruction
// generated for the terminator
bbMvec.insert( MCIt , CpMI );
bbMvec.insert(MCIt, CpVec.begin(), CpVec.end());
//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
//-------------------------------------------------------------------------
void InsertCode4AllPhisInMeth(Method *method, TargetMachine &target) {
void
InsertCode4AllPhisInMeth(Method *method, TargetMachine &target)
{
// for all basic blocks in method
//
for (Method::iterator BI = method->begin(); BI != method->end(); ++BI) {
@ -261,10 +218,13 @@ void InsertCode4AllPhisInMeth(Method *method, TargetMachine &target) {
MachineInstr *CpMI =
target.getRegInfo().cpValue2Value(PN->getIncomingValue(i),
PhiCpRes);
InsertPhiElimInst(PN->getIncomingBlock(i), CpMI);
vector<MachineInstr*> CpVec = FixConstantOperandsForInstr(PN, CpMI, target);
CpVec.push_back(CpMI);
InsertPhiElimInstructions(PN->getIncomingBlock(i), CpVec);
}
MachineInstr *CpMI2 =
target.getRegInfo().cpValue2Value(PhiCpRes, PN);
@ -352,15 +312,16 @@ SelectInstructionsForTree(InstrTreeNode* treeRoot, int goalnt,
//
if (treeRoot->opLabel != VRegListOp)
{
vector<MachineInstr*> minstrVec;
InstructionNode* instrNode = (InstructionNode*)treeRoot;
assert(instrNode->getNodeType() == InstrTreeNode::NTInstructionNode);
unsigned N = GetInstructionsByRule(instrNode, ruleForNode, nts, target,
minstrVec);
assert(N <= MAX_INSTR_PER_VMINSTR);
GetInstructionsByRule(instrNode, ruleForNode, nts, target, minstrVec);
MachineCodeForInstruction &mvec =
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.