aboutsummaryrefslogtreecommitdiffstats
path: root/lib/CodeGen
diff options
context:
space:
mode:
authorRuchira Sasanka <sasanka@students.uiuc.edu>2001-11-12 14:44:50 +0000
committerRuchira Sasanka <sasanka@students.uiuc.edu>2001-11-12 14:44:50 +0000
commitb2490fc4fbab28624aeef9cae6fcde31248ce797 (patch)
treee55e91aba4cdbfff2d17015401d4110053f8a80e /lib/CodeGen
parentd9beb975f20cea2d3e9c3f528068cd25b80a1b72 (diff)
downloadexternal_llvm-b2490fc4fbab28624aeef9cae6fcde31248ce797.zip
external_llvm-b2490fc4fbab28624aeef9cae6fcde31248ce797.tar.gz
external_llvm-b2490fc4fbab28624aeef9cae6fcde31248ce797.tar.bz2
Added phi elimination code - not final
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@1264 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen')
-rw-r--r--lib/CodeGen/InstrSelection/InstrSelection.cpp100
1 files changed, 100 insertions, 0 deletions
diff --git a/lib/CodeGen/InstrSelection/InstrSelection.cpp b/lib/CodeGen/InstrSelection/InstrSelection.cpp
index fafe023..b749873 100644
--- a/lib/CodeGen/InstrSelection/InstrSelection.cpp
+++ b/lib/CodeGen/InstrSelection/InstrSelection.cpp
@@ -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
//