forked from OSchip/llvm-project
parent
6e004c0818
commit
9f246e65d3
|
@ -21,6 +21,8 @@
|
|||
#include "llvm/Instruction.h"
|
||||
#include "llvm/BasicBlock.h"
|
||||
#include "llvm/Method.h"
|
||||
#include "llvm/iOther.h"
|
||||
#include "llvm/Target/MachineRegInfo.h"
|
||||
|
||||
|
||||
//******************** Internal Data Declarations ************************/
|
||||
|
@ -57,6 +59,9 @@ static void PostprocessMachineCodeForTree(InstructionNode* instrNode,
|
|||
short* nts,
|
||||
TargetMachine &target);
|
||||
|
||||
static void InsertCode4AllPhisInMeth(Method *method, TargetMachine &target);
|
||||
|
||||
|
||||
|
||||
//******************* Externally Visible Functions *************************/
|
||||
|
||||
|
@ -125,6 +130,10 @@ SelectInstructionsForMethod(Method* method, TargetMachine &target)
|
|||
bbMvec.push_back(mvec[i]);
|
||||
}
|
||||
}
|
||||
|
||||
// Insert phi elimination code -- added by Ruchira
|
||||
InsertCode4AllPhisInMeth(method, target);
|
||||
|
||||
|
||||
if (SelectDebugLevel >= Select_PrintMachineCode)
|
||||
{
|
||||
|
@ -140,6 +149,97 @@ SelectInstructionsForMethod(Method* method, TargetMachine &target)
|
|||
//*********************** Private Functions *****************************/
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
// Thid method inserts a copy instruction to a predecessor BB as a result
|
||||
// of phi elimination.
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
void InsertPhiElimInst(BasicBlock *BB, vector<MachineInstr*>& CopyInstVec) { // bak
|
||||
|
||||
TerminatorInst *TermInst = BB->getTerminator();
|
||||
MachineCodeForVMInstr &MC4Term = TermInst->getMachineInstrVec();
|
||||
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 ) ;
|
||||
|
||||
assert( MCIt != bbMvec.end() && "Start inst of terminator not found");
|
||||
assert( (CopyInstVec.size()==1) && "Must be only one copy instr");
|
||||
|
||||
// insert the copy instruction just before the first machine instruction
|
||||
// generated for the terminator
|
||||
bbMvec.insert( MCIt , CopyInstVec[0] );
|
||||
|
||||
cerr << "\nPhiElimination copy inst: " << *CopyInstVec[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
|
||||
|
||||
vector<MachineInstr*> CopyInstVec;
|
||||
|
||||
// target.getInstrInfo().CreateCopyInstructionsByType(
|
||||
// target, PN->getIncomingValue(i), PN, CopyInstVec );
|
||||
|
||||
MachineInstr *MI =
|
||||
target.getRegInfo().cpValue2Value(PN->getIncomingValue(i), PN);
|
||||
|
||||
CopyInstVec.push_back( MI );
|
||||
|
||||
InsertPhiElimInst( PN->getIncomingBlock(i), CopyInstVec);
|
||||
|
||||
// Map the generated copy instruction in pred BB to this phi
|
||||
// (PN->getMachineInstrVec()).push_back( CopyInstVec[0] );
|
||||
|
||||
}
|
||||
}
|
||||
else break; // since PHI nodes can only be at the top
|
||||
|
||||
} // for each Phi Instr in BB
|
||||
|
||||
} // for all BBs in method
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// Function AppendMachineCodeForVMInstr
|
||||
//
|
||||
|
|
Loading…
Reference in New Issue