diff options
| author | Ruchira Sasanka <sasanka@students.uiuc.edu> | 2001-11-15 00:27:14 +0000 | 
|---|---|---|
| committer | Ruchira Sasanka <sasanka@students.uiuc.edu> | 2001-11-15 00:27:14 +0000 | 
| commit | c5989f645bcec6a4c85b2f342e1e88d579507eaf (patch) | |
| tree | e58606f2162cbeb8862ce1fd5c56fc0e23eb6d30 /llvm | |
| parent | 3fb79e61c2282a18f7cc936a4877c796aeb9e28d (diff) | |
| download | bcm5719-llvm-c5989f645bcec6a4c85b2f342e1e88d579507eaf.tar.gz bcm5719-llvm-c5989f645bcec6a4c85b2f342e1e88d579507eaf.zip  | |
Changed phi elimination code
llvm-svn: 1311
Diffstat (limited to 'llvm')
| -rw-r--r-- | llvm/lib/CodeGen/InstrSelection/InstrSelection.cpp | 65 | 
1 files changed, 64 insertions, 1 deletions
diff --git a/llvm/lib/CodeGen/InstrSelection/InstrSelection.cpp b/llvm/lib/CodeGen/InstrSelection/InstrSelection.cpp index 909f2410ef8..f32165eda1b 100644 --- a/llvm/lib/CodeGen/InstrSelection/InstrSelection.cpp +++ b/llvm/lib/CodeGen/InstrSelection/InstrSelection.cpp @@ -180,7 +180,7 @@ void InsertPhiElimInst(BasicBlock *BB, MachineInstr *CpMI) {  } - +#if 0  //-------------------------------------------------------------------------  // This method inserts phi elimination code for all BBs in a method  //------------------------------------------------------------------------- @@ -224,6 +224,69 @@ void InsertCode4AllPhisInMeth(Method *method, TargetMachine &target) {    } // for all BBs in method  } +#endif + + +//------------------------------------------------------------------------- +// 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); + +	Value *PhiCpRes =  +	  new Value(PN->getType(), PN->getValueType() ); + +	// 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 + +	  MachineInstr *CpMI = +	    target.getRegInfo().cpValue2Value(PN->getIncomingValue(i), +					      PhiCpRes); + +	  InsertPhiElimInst(PN->getIncomingBlock(i), CpMI); + +	} + +	 +	MachineInstr *CpMI2 = +	  target.getRegInfo().cpValue2Value(PhiCpRes, PN); + +	// get an iterator to machine instructions in the BB +	MachineCodeForBasicBlock& bbMvec = BB->getMachineInstrVec(); + +	bbMvec.insert( bbMvec.begin(),  CpMI2); +	 + +      } +      else break;   // since PHI nodes can only be at the top +       +    }  // for each Phi Instr in BB + +  } // for all BBs in method + +} + + +  | 

