mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-03-13 08:35:46 +00:00
Added phi elimination code - not final
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@1264 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
d9beb975f2
commit
b2490fc4fb
@ -21,6 +21,8 @@
|
|||||||
#include "llvm/Instruction.h"
|
#include "llvm/Instruction.h"
|
||||||
#include "llvm/BasicBlock.h"
|
#include "llvm/BasicBlock.h"
|
||||||
#include "llvm/Method.h"
|
#include "llvm/Method.h"
|
||||||
|
#include "llvm/iOther.h"
|
||||||
|
#include "llvm/Target/MachineRegInfo.h"
|
||||||
|
|
||||||
|
|
||||||
//******************** Internal Data Declarations ************************/
|
//******************** Internal Data Declarations ************************/
|
||||||
@ -57,6 +59,9 @@ static void PostprocessMachineCodeForTree(InstructionNode* instrNode,
|
|||||||
short* nts,
|
short* nts,
|
||||||
TargetMachine &target);
|
TargetMachine &target);
|
||||||
|
|
||||||
|
static void InsertCode4AllPhisInMeth(Method *method, TargetMachine &target);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//******************* Externally Visible Functions *************************/
|
//******************* Externally Visible Functions *************************/
|
||||||
|
|
||||||
@ -125,6 +130,10 @@ SelectInstructionsForMethod(Method* method, TargetMachine &target)
|
|||||||
bbMvec.push_back(mvec[i]);
|
bbMvec.push_back(mvec[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Insert phi elimination code -- added by Ruchira
|
||||||
|
InsertCode4AllPhisInMeth(method, target);
|
||||||
|
|
||||||
|
|
||||||
if (SelectDebugLevel >= Select_PrintMachineCode)
|
if (SelectDebugLevel >= Select_PrintMachineCode)
|
||||||
{
|
{
|
||||||
@ -140,6 +149,97 @@ SelectInstructionsForMethod(Method* method, TargetMachine &target)
|
|||||||
//*********************** Private Functions *****************************/
|
//*********************** 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
|
// Function AppendMachineCodeForVMInstr
|
||||||
//
|
//
|
||||||
|
@ -21,6 +21,8 @@
|
|||||||
#include "llvm/Instruction.h"
|
#include "llvm/Instruction.h"
|
||||||
#include "llvm/BasicBlock.h"
|
#include "llvm/BasicBlock.h"
|
||||||
#include "llvm/Method.h"
|
#include "llvm/Method.h"
|
||||||
|
#include "llvm/iOther.h"
|
||||||
|
#include "llvm/Target/MachineRegInfo.h"
|
||||||
|
|
||||||
|
|
||||||
//******************** Internal Data Declarations ************************/
|
//******************** Internal Data Declarations ************************/
|
||||||
@ -57,6 +59,9 @@ static void PostprocessMachineCodeForTree(InstructionNode* instrNode,
|
|||||||
short* nts,
|
short* nts,
|
||||||
TargetMachine &target);
|
TargetMachine &target);
|
||||||
|
|
||||||
|
static void InsertCode4AllPhisInMeth(Method *method, TargetMachine &target);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//******************* Externally Visible Functions *************************/
|
//******************* Externally Visible Functions *************************/
|
||||||
|
|
||||||
@ -125,6 +130,10 @@ SelectInstructionsForMethod(Method* method, TargetMachine &target)
|
|||||||
bbMvec.push_back(mvec[i]);
|
bbMvec.push_back(mvec[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Insert phi elimination code -- added by Ruchira
|
||||||
|
InsertCode4AllPhisInMeth(method, target);
|
||||||
|
|
||||||
|
|
||||||
if (SelectDebugLevel >= Select_PrintMachineCode)
|
if (SelectDebugLevel >= Select_PrintMachineCode)
|
||||||
{
|
{
|
||||||
@ -140,6 +149,97 @@ SelectInstructionsForMethod(Method* method, TargetMachine &target)
|
|||||||
//*********************** Private Functions *****************************/
|
//*********************** 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
|
// Function AppendMachineCodeForVMInstr
|
||||||
//
|
//
|
||||||
|
Loading…
x
Reference in New Issue
Block a user