mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-08-17 21:29:20 +00:00
Added more comments. Added code to destructor in MethodLiveVarInfo to delete
LiveVarSet caches. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@1435 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
b720a8bc1d
commit
789cebb908
@ -1,11 +1,12 @@
|
||||
#include "llvm/Analysis/LiveVar/BBLiveVar.h"
|
||||
#include "llvm/Analysis/LiveVar/MethodLiveVarInfo.h"
|
||||
#include "llvm/CodeGen/MachineInstr.h"
|
||||
#include "../../Target/Sparc/SparcInternals.h" // TODO: FIXME!! Only for PHI defn
|
||||
#include "../../Target/Sparc/SparcInternals.h" // Only for PHI defn
|
||||
|
||||
|
||||
/********************* Implementation **************************************/
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
BBLiveVar::BBLiveVar( const BasicBlock *const baseBB, unsigned int RdfoId)
|
||||
: BaseBB(baseBB), DefSet(), InSet(),
|
||||
OutSet(), PhiArgMap() {
|
||||
@ -14,10 +15,13 @@ BBLiveVar::BBLiveVar( const BasicBlock *const baseBB, unsigned int RdfoId)
|
||||
POId = RdfoId;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// caluculates def and use sets for each BB
|
||||
// There are two passes over operands of a machine instruction. This is
|
||||
// because, we can have instructions like V = V + 1, since we no longer
|
||||
// assume single definition.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void BBLiveVar::calcDefUseSets()
|
||||
{
|
||||
@ -56,7 +60,7 @@ void BBLiveVar::calcDefUseSets()
|
||||
|
||||
|
||||
// iterate over MI operands to find uses
|
||||
for (MachineInstr::val_const_op_iterator OpI(MInst); !OpI.done() ; ++OpI) {
|
||||
for (MachineInstr::val_const_op_iterator OpI(MInst); !OpI.done() ; ++OpI) {
|
||||
const Value *Op = *OpI;
|
||||
|
||||
if ( ((Op)->getType())->isLabelType() )
|
||||
@ -106,10 +110,12 @@ void BBLiveVar::calcDefUseSets()
|
||||
|
||||
} // for all machine instructions
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// To add an operand wichi is a def
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// To add an operand which is a def
|
||||
//-----------------------------------------------------------------------------
|
||||
void BBLiveVar::addDef(const Value *Op)
|
||||
{
|
||||
DefSet.add( Op ); // operand is a def - so add to def set
|
||||
@ -121,8 +127,10 @@ void BBLiveVar::addDef(const Value *Op)
|
||||
}
|
||||
}
|
||||
|
||||
// To add an operand which is a use
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// To add an operand which is a use
|
||||
//-----------------------------------------------------------------------------
|
||||
void BBLiveVar::addUse(const Value *Op)
|
||||
{
|
||||
InSet.add( Op ); // An operand is a use - so add to use set
|
||||
@ -136,6 +144,10 @@ void BBLiveVar::addUse(const Value *Op)
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Applies the transfer function to a basic block to produce the InSet using
|
||||
// the outset.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
bool BBLiveVar::applyTransferFunc() // calculates the InSet in terms of OutSet
|
||||
{
|
||||
@ -153,8 +165,9 @@ bool BBLiveVar::applyTransferFunc() // calculates the InSet in terms of OutSet
|
||||
}
|
||||
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// calculates Out set using In sets of the predecessors
|
||||
//-----------------------------------------------------------------------------
|
||||
bool BBLiveVar::setPropagate( LiveVarSet *const OutSet,
|
||||
const LiveVarSet *const InSet,
|
||||
const BasicBlock *const PredBB) {
|
||||
@ -180,9 +193,9 @@ bool BBLiveVar::setPropagate( LiveVarSet *const OutSet,
|
||||
}
|
||||
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// propogates in set to OutSets of PREDECESSORs
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
bool BBLiveVar::applyFlowFunc(BBToBBLiveVarMapType LVMap)
|
||||
{
|
||||
|
||||
|
@ -14,7 +14,7 @@
|
||||
#include "Support/PostOrderIterator.h"
|
||||
|
||||
|
||||
/************************** Constructor/Destructor ***************************/
|
||||
//************************** Constructor/Destructor ***************************
|
||||
|
||||
|
||||
MethodLiveVarInfo::MethodLiveVarInfo(const Method *const M) : Meth(M),
|
||||
@ -28,21 +28,45 @@ MethodLiveVarInfo::MethodLiveVarInfo(const Method *const M) : Meth(M),
|
||||
|
||||
MethodLiveVarInfo:: ~MethodLiveVarInfo()
|
||||
{
|
||||
// hash map iterator
|
||||
// First delete all BBLiveVar objects created in constructBBs(). A new object
|
||||
// of type BBLiveVa is created for every BasicBlock in the method
|
||||
|
||||
// hash map iterator for BB2BBLVMap
|
||||
//
|
||||
BBToBBLiveVarMapType::iterator HMI = BB2BBLVMap.begin();
|
||||
|
||||
for( ; HMI != BB2BBLVMap.end() ; HMI ++ ) {
|
||||
if( (*HMI).first ) // delete all LiveVarSets in BB2BBLVMap
|
||||
if( (*HMI).first ) // delete all BBLiveVar in BB2BBLVMap
|
||||
delete (*HMI).second;
|
||||
}
|
||||
|
||||
|
||||
// Then delete all objects of type LiveVarSet created in calcLiveVarSetsForBB
|
||||
// and entered into MInst2LVSetBI and MInst2LVSetAI (these are caches
|
||||
// to return LiveVarSet's before/after a machine instruction quickly). It
|
||||
// is sufficient to free up all LiveVarSet using only one cache since
|
||||
// both caches refer to the same sets
|
||||
|
||||
// hash map iterator for MInst2LVSetBI
|
||||
//
|
||||
MInstToLiveVarSetMapType::iterator MI = MInst2LVSetBI.begin();
|
||||
|
||||
for( ; MI != MInst2LVSetBI.end() ; MI ++ ) {
|
||||
if( (*MI).first ) // delete all LiveVarSets in MInst2LVSetBI
|
||||
delete (*MI).second;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
// -------------------------- support functions -------------------------------
|
||||
|
||||
// ************************* support functions ********************************
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// constructs BBLiveVars and init Def and In sets
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void MethodLiveVarInfo::constructBBs()
|
||||
{
|
||||
unsigned int POId = 0; // Reverse Depth-first Order ID
|
||||
@ -85,8 +109,9 @@ void MethodLiveVarInfo::constructBBs()
|
||||
}
|
||||
|
||||
|
||||
|
||||
// do one backward pass over the CFG
|
||||
//-----------------------------------------------------------------------------
|
||||
// do one backward pass over the CFG (for iterative analysis)
|
||||
//-----------------------------------------------------------------------------
|
||||
bool MethodLiveVarInfo::doSingleBackwardPass()
|
||||
{
|
||||
bool ResultFlow, NeedAnotherIteration = false;
|
||||
@ -127,8 +152,9 @@ bool MethodLiveVarInfo::doSingleBackwardPass()
|
||||
|
||||
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// performs live var anal for a method
|
||||
//-----------------------------------------------------------------------------
|
||||
void MethodLiveVarInfo::analyze()
|
||||
{
|
||||
// Don't analyze the same method twice!
|
||||
@ -157,8 +183,8 @@ void MethodLiveVarInfo::analyze()
|
||||
|
||||
|
||||
|
||||
|
||||
/* Thsese functions will give the LiveVar info for any machine instruction in
|
||||
//-----------------------------------------------------------------------------
|
||||
/* Following functions will give the LiveVar info for any machine instr in
|
||||
a method. It should be called after a call to analyze().
|
||||
|
||||
Thsese functions calucluates live var info for all the machine instrs in a
|
||||
@ -167,8 +193,11 @@ void MethodLiveVarInfo::analyze()
|
||||
block. Also, the arguments to this method does not require specific
|
||||
iterators.
|
||||
*/
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Gives live variable information before a machine instruction
|
||||
//-----------------------------------------------------------------------------
|
||||
const LiveVarSet *
|
||||
MethodLiveVarInfo::getLiveVarSetBeforeMInst(const MachineInstr *const MInst,
|
||||
const BasicBlock *const CurBB)
|
||||
@ -178,12 +207,21 @@ MethodLiveVarInfo::getLiveVarSetBeforeMInst(const MachineInstr *const MInst,
|
||||
if( LVSet ) return LVSet; // if found, just return the set
|
||||
else {
|
||||
calcLiveVarSetsForBB( CurBB ); // else, calc for all instrs in BB
|
||||
|
||||
/*if( ! MInst2LVSetBI[ MInst ] ) {
|
||||
cerr << "\nFor BB "; printValue( CurBB);
|
||||
cerr << "\nRequested LVSet for inst: " << *MInst;
|
||||
}*/
|
||||
|
||||
assert( MInst2LVSetBI[ MInst ] );
|
||||
return MInst2LVSetBI[ MInst ];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Gives live variable information after a machine instruction
|
||||
//-----------------------------------------------------------------------------
|
||||
const LiveVarSet *
|
||||
MethodLiveVarInfo::getLiveVarSetAfterMInst(const MachineInstr *const MInst,
|
||||
const BasicBlock *const CurBB)
|
||||
@ -199,6 +237,12 @@ MethodLiveVarInfo::getLiveVarSetAfterMInst(const MachineInstr *const MInst,
|
||||
}
|
||||
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// This method calculates the live variable information for all the
|
||||
// instructions in a basic block and enter the newly constructed live
|
||||
// variable sets into a the caches ( MInst2LVSetAI, MInst2LVSetBI)
|
||||
//-----------------------------------------------------------------------------
|
||||
void MethodLiveVarInfo::calcLiveVarSetsForBB(const BasicBlock *const BB)
|
||||
{
|
||||
const MachineCodeForBasicBlock& MIVec = BB->getMachineInstrVec();
|
||||
|
@ -1,11 +1,12 @@
|
||||
#include "llvm/Analysis/LiveVar/BBLiveVar.h"
|
||||
#include "llvm/Analysis/LiveVar/MethodLiveVarInfo.h"
|
||||
#include "llvm/CodeGen/MachineInstr.h"
|
||||
#include "../../Target/Sparc/SparcInternals.h" // TODO: FIXME!! Only for PHI defn
|
||||
#include "../../Target/Sparc/SparcInternals.h" // Only for PHI defn
|
||||
|
||||
|
||||
/********************* Implementation **************************************/
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
BBLiveVar::BBLiveVar( const BasicBlock *const baseBB, unsigned int RdfoId)
|
||||
: BaseBB(baseBB), DefSet(), InSet(),
|
||||
OutSet(), PhiArgMap() {
|
||||
@ -14,10 +15,13 @@ BBLiveVar::BBLiveVar( const BasicBlock *const baseBB, unsigned int RdfoId)
|
||||
POId = RdfoId;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// caluculates def and use sets for each BB
|
||||
// There are two passes over operands of a machine instruction. This is
|
||||
// because, we can have instructions like V = V + 1, since we no longer
|
||||
// assume single definition.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void BBLiveVar::calcDefUseSets()
|
||||
{
|
||||
@ -56,7 +60,7 @@ void BBLiveVar::calcDefUseSets()
|
||||
|
||||
|
||||
// iterate over MI operands to find uses
|
||||
for (MachineInstr::val_const_op_iterator OpI(MInst); !OpI.done() ; ++OpI) {
|
||||
for (MachineInstr::val_const_op_iterator OpI(MInst); !OpI.done() ; ++OpI) {
|
||||
const Value *Op = *OpI;
|
||||
|
||||
if ( ((Op)->getType())->isLabelType() )
|
||||
@ -106,10 +110,12 @@ void BBLiveVar::calcDefUseSets()
|
||||
|
||||
} // for all machine instructions
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// To add an operand wichi is a def
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// To add an operand which is a def
|
||||
//-----------------------------------------------------------------------------
|
||||
void BBLiveVar::addDef(const Value *Op)
|
||||
{
|
||||
DefSet.add( Op ); // operand is a def - so add to def set
|
||||
@ -121,8 +127,10 @@ void BBLiveVar::addDef(const Value *Op)
|
||||
}
|
||||
}
|
||||
|
||||
// To add an operand which is a use
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// To add an operand which is a use
|
||||
//-----------------------------------------------------------------------------
|
||||
void BBLiveVar::addUse(const Value *Op)
|
||||
{
|
||||
InSet.add( Op ); // An operand is a use - so add to use set
|
||||
@ -136,6 +144,10 @@ void BBLiveVar::addUse(const Value *Op)
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Applies the transfer function to a basic block to produce the InSet using
|
||||
// the outset.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
bool BBLiveVar::applyTransferFunc() // calculates the InSet in terms of OutSet
|
||||
{
|
||||
@ -153,8 +165,9 @@ bool BBLiveVar::applyTransferFunc() // calculates the InSet in terms of OutSet
|
||||
}
|
||||
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// calculates Out set using In sets of the predecessors
|
||||
//-----------------------------------------------------------------------------
|
||||
bool BBLiveVar::setPropagate( LiveVarSet *const OutSet,
|
||||
const LiveVarSet *const InSet,
|
||||
const BasicBlock *const PredBB) {
|
||||
@ -180,9 +193,9 @@ bool BBLiveVar::setPropagate( LiveVarSet *const OutSet,
|
||||
}
|
||||
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// propogates in set to OutSets of PREDECESSORs
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
bool BBLiveVar::applyFlowFunc(BBToBBLiveVarMapType LVMap)
|
||||
{
|
||||
|
||||
|
@ -14,7 +14,7 @@
|
||||
#include "Support/PostOrderIterator.h"
|
||||
|
||||
|
||||
/************************** Constructor/Destructor ***************************/
|
||||
//************************** Constructor/Destructor ***************************
|
||||
|
||||
|
||||
MethodLiveVarInfo::MethodLiveVarInfo(const Method *const M) : Meth(M),
|
||||
@ -28,21 +28,45 @@ MethodLiveVarInfo::MethodLiveVarInfo(const Method *const M) : Meth(M),
|
||||
|
||||
MethodLiveVarInfo:: ~MethodLiveVarInfo()
|
||||
{
|
||||
// hash map iterator
|
||||
// First delete all BBLiveVar objects created in constructBBs(). A new object
|
||||
// of type BBLiveVa is created for every BasicBlock in the method
|
||||
|
||||
// hash map iterator for BB2BBLVMap
|
||||
//
|
||||
BBToBBLiveVarMapType::iterator HMI = BB2BBLVMap.begin();
|
||||
|
||||
for( ; HMI != BB2BBLVMap.end() ; HMI ++ ) {
|
||||
if( (*HMI).first ) // delete all LiveVarSets in BB2BBLVMap
|
||||
if( (*HMI).first ) // delete all BBLiveVar in BB2BBLVMap
|
||||
delete (*HMI).second;
|
||||
}
|
||||
|
||||
|
||||
// Then delete all objects of type LiveVarSet created in calcLiveVarSetsForBB
|
||||
// and entered into MInst2LVSetBI and MInst2LVSetAI (these are caches
|
||||
// to return LiveVarSet's before/after a machine instruction quickly). It
|
||||
// is sufficient to free up all LiveVarSet using only one cache since
|
||||
// both caches refer to the same sets
|
||||
|
||||
// hash map iterator for MInst2LVSetBI
|
||||
//
|
||||
MInstToLiveVarSetMapType::iterator MI = MInst2LVSetBI.begin();
|
||||
|
||||
for( ; MI != MInst2LVSetBI.end() ; MI ++ ) {
|
||||
if( (*MI).first ) // delete all LiveVarSets in MInst2LVSetBI
|
||||
delete (*MI).second;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
// -------------------------- support functions -------------------------------
|
||||
|
||||
// ************************* support functions ********************************
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// constructs BBLiveVars and init Def and In sets
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void MethodLiveVarInfo::constructBBs()
|
||||
{
|
||||
unsigned int POId = 0; // Reverse Depth-first Order ID
|
||||
@ -85,8 +109,9 @@ void MethodLiveVarInfo::constructBBs()
|
||||
}
|
||||
|
||||
|
||||
|
||||
// do one backward pass over the CFG
|
||||
//-----------------------------------------------------------------------------
|
||||
// do one backward pass over the CFG (for iterative analysis)
|
||||
//-----------------------------------------------------------------------------
|
||||
bool MethodLiveVarInfo::doSingleBackwardPass()
|
||||
{
|
||||
bool ResultFlow, NeedAnotherIteration = false;
|
||||
@ -127,8 +152,9 @@ bool MethodLiveVarInfo::doSingleBackwardPass()
|
||||
|
||||
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// performs live var anal for a method
|
||||
//-----------------------------------------------------------------------------
|
||||
void MethodLiveVarInfo::analyze()
|
||||
{
|
||||
// Don't analyze the same method twice!
|
||||
@ -157,8 +183,8 @@ void MethodLiveVarInfo::analyze()
|
||||
|
||||
|
||||
|
||||
|
||||
/* Thsese functions will give the LiveVar info for any machine instruction in
|
||||
//-----------------------------------------------------------------------------
|
||||
/* Following functions will give the LiveVar info for any machine instr in
|
||||
a method. It should be called after a call to analyze().
|
||||
|
||||
Thsese functions calucluates live var info for all the machine instrs in a
|
||||
@ -167,8 +193,11 @@ void MethodLiveVarInfo::analyze()
|
||||
block. Also, the arguments to this method does not require specific
|
||||
iterators.
|
||||
*/
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Gives live variable information before a machine instruction
|
||||
//-----------------------------------------------------------------------------
|
||||
const LiveVarSet *
|
||||
MethodLiveVarInfo::getLiveVarSetBeforeMInst(const MachineInstr *const MInst,
|
||||
const BasicBlock *const CurBB)
|
||||
@ -178,12 +207,21 @@ MethodLiveVarInfo::getLiveVarSetBeforeMInst(const MachineInstr *const MInst,
|
||||
if( LVSet ) return LVSet; // if found, just return the set
|
||||
else {
|
||||
calcLiveVarSetsForBB( CurBB ); // else, calc for all instrs in BB
|
||||
|
||||
/*if( ! MInst2LVSetBI[ MInst ] ) {
|
||||
cerr << "\nFor BB "; printValue( CurBB);
|
||||
cerr << "\nRequested LVSet for inst: " << *MInst;
|
||||
}*/
|
||||
|
||||
assert( MInst2LVSetBI[ MInst ] );
|
||||
return MInst2LVSetBI[ MInst ];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Gives live variable information after a machine instruction
|
||||
//-----------------------------------------------------------------------------
|
||||
const LiveVarSet *
|
||||
MethodLiveVarInfo::getLiveVarSetAfterMInst(const MachineInstr *const MInst,
|
||||
const BasicBlock *const CurBB)
|
||||
@ -199,6 +237,12 @@ MethodLiveVarInfo::getLiveVarSetAfterMInst(const MachineInstr *const MInst,
|
||||
}
|
||||
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// This method calculates the live variable information for all the
|
||||
// instructions in a basic block and enter the newly constructed live
|
||||
// variable sets into a the caches ( MInst2LVSetAI, MInst2LVSetBI)
|
||||
//-----------------------------------------------------------------------------
|
||||
void MethodLiveVarInfo::calcLiveVarSetsForBB(const BasicBlock *const BB)
|
||||
{
|
||||
const MachineCodeForBasicBlock& MIVec = BB->getMachineInstrVec();
|
||||
|
Loading…
Reference in New Issue
Block a user