summaryrefslogtreecommitdiff
path: root/lib/Analysis
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2002-02-04 20:49:04 +0000
committerChris Lattner <sabre@nondot.org>2002-02-04 20:49:04 +0000
commitbdfd3285153540b03cf5516bab9b4aa955dc7b1b (patch)
tree3a54069f762390eb90af1f7e369b19f20c85418a /lib/Analysis
parent5ff562e2c08a719c4f4f5280bff2da88fc9d5e8c (diff)
downloadllvm-bdfd3285153540b03cf5516bab9b4aa955dc7b1b.tar.gz
llvm-bdfd3285153540b03cf5516bab9b4aa955dc7b1b.tar.bz2
llvm-bdfd3285153540b03cf5516bab9b4aa955dc7b1b.tar.xz
Clean up MethodLiveVarInfo
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@1703 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis')
-rw-r--r--lib/Analysis/LiveVar/FunctionLiveVarInfo.cpp187
1 files changed, 77 insertions, 110 deletions
diff --git a/lib/Analysis/LiveVar/FunctionLiveVarInfo.cpp b/lib/Analysis/LiveVar/FunctionLiveVarInfo.cpp
index 54980d7960..b43f7aaedd 100644
--- a/lib/Analysis/LiveVar/FunctionLiveVarInfo.cpp
+++ b/lib/Analysis/LiveVar/FunctionLiveVarInfo.cpp
@@ -14,39 +14,26 @@
#include "llvm/BasicBlock.h"
#include "Support/PostOrderIterator.h"
#include <iostream>
-using std::cout;
-using std::endl;
+using std::cerr;
AnalysisID MethodLiveVarInfo::ID(AnalysisID::create<MethodLiveVarInfo>());
-void MethodLiveVarInfo::releaseMemory() {
- // 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)
- delete HMI->second; // delete all BBLiveVar in BB2BBLVMap
-
- BB2BBLVMap.clear();
-
- // 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
+//-----------------------------------------------------------------------------
+// Performs live var analysis for a method
+//-----------------------------------------------------------------------------
- // hash map iterator for MInst2LVSetBI
- //
- MInstToLiveVarSetMapType::iterator MI = MInst2LVSetBI.begin();
+bool MethodLiveVarInfo::runOnMethod(Method *M) {
+ if (DEBUG_LV) cerr << "Analysing live variables ...\n";
- for( ; MI != MInst2LVSetBI.end(); ++MI)
- delete MI->second; // delete all LiveVarSets in MInst2LVSetBI
+ // create and initialize all the BBLiveVars of the CFG
+ constructBBs(M);
- MInst2LVSetBI.clear();
- MInst2LVSetAI.clear();
+ while (doSingleBackwardPass(M))
+ ; // Iterate until we are done.
+
+ if (DEBUG_LV) cerr << "Live Variable Analysis complete!\n";
+ return false;
}
@@ -54,27 +41,22 @@ void MethodLiveVarInfo::releaseMemory() {
// constructs BBLiveVars and init Def and In sets
//-----------------------------------------------------------------------------
-void MethodLiveVarInfo::constructBBs()
-{
+void MethodLiveVarInfo::constructBBs(const Method *M) {
unsigned int POId = 0; // Reverse Depth-first Order ID
-
- po_iterator<const Method*> BBI = po_begin(Meth);
-
- for( ; BBI != po_end(Meth) ; ++BBI, ++POId)
- {
-
+
+ for(po_iterator<const Method*> BBI = po_begin(M), BBE = po_end(M);
+ BBI != BBE; ++BBI, ++POId) {
const BasicBlock *BB = *BBI; // get the current BB
- if(DEBUG_LV) { cout << " For BB "; printValue(BB); cout << ":" << endl; }
+ if (DEBUG_LV) { cerr << " For BB "; printValue(BB); cerr << ":\n"; }
- // create a new BBLiveVar
- BBLiveVar * LVBB = new BBLiveVar( BB, POId );
-
- BB2BBLVMap[ BB ] = LVBB; // insert the pair to Map
+ // create a new BBLiveVar
+ BBLiveVar *LVBB = new BBLiveVar(BB, POId);
+ BB2BBLVMap[BB] = LVBB; // insert the pair to Map
LVBB->calcDefUseSets(); // calculates the def and in set
- if(DEBUG_LV)
+ if (DEBUG_LV)
LVBB->printAllSets();
}
@@ -82,54 +64,38 @@ void MethodLiveVarInfo::constructBBs()
// go over the random iterator and init those blocks as well.
// However, LV info is not correct for those blocks (they are not
// analyzed)
-
- Method::const_iterator BBRI = Meth->begin(); // random iterator for BBs
-
- for( ; BBRI != Meth->end(); ++BBRI, ++POId) {
-
- if( ! BB2BBLVMap[ *BBRI ] )
- BB2BBLVMap[ *BBRI ] = new BBLiveVar( *BBRI, POId );
-
- }
-
-
+ //
+ for (Method::const_iterator BBRI = M->begin(), BBRE = M->end();
+ BBRI != BBRE; ++BBRI, ++POId)
+ if (!BB2BBLVMap[*BBRI]) // Not yet processed?
+ BB2BBLVMap[*BBRI] = new BBLiveVar(*BBRI, POId);
}
//-----------------------------------------------------------------------------
// do one backward pass over the CFG (for iterative analysis)
//-----------------------------------------------------------------------------
-bool MethodLiveVarInfo::doSingleBackwardPass()
-{
+bool MethodLiveVarInfo::doSingleBackwardPass(const Method *M) {
bool ResultFlow, NeedAnotherIteration = false;
- if(DEBUG_LV)
- cout << endl << " After Backward Pass ..." << endl;
+ if (DEBUG_LV)
+ cerr << "\n After Backward Pass ...\n";
- po_iterator<const Method*> BBI = po_begin(Meth);
+ po_iterator<const Method*> BBI = po_begin(M);
- for( ; BBI != po_end(Meth) ; ++BBI)
- {
+ for( ; BBI != po_end(M) ; ++BBI) {
+ BBLiveVar *LVBB = BB2BBLVMap[*BBI];
+ assert(LVBB);
- BBLiveVar* LVBB = BB2BBLVMap[*BBI];
- assert( LVBB );
+ if (DEBUG_LV) cerr << " For BB " << (*BBI)->getName() << ":\n";
- if(DEBUG_LV) cout << " For BB " << (*BBI)->getName() << ":" << endl;
- // cout << " (POId=" << LVBB->getPOId() << ")" << endl ;
-
- ResultFlow = false;
-
- if( LVBB->isOutSetChanged() )
+ if(LVBB->isOutSetChanged())
LVBB->applyTransferFunc(); // apply the Tran Func to calc InSet
- if( LVBB->isInSetChanged() ) // to calc Outsets of preds
- ResultFlow = LVBB->applyFlowFunc(BB2BBLVMap);
+ if (LVBB->isInSetChanged()) // to calc Outsets of preds
+ NeedAnotherIteration |= LVBB->applyFlowFunc(BB2BBLVMap);
if(DEBUG_LV) LVBB->printInOutSets();
-
-
- if( ResultFlow ) NeedAnotherIteration = true;
-
}
// true if we need to reiterate over the CFG
@@ -137,32 +103,39 @@ bool MethodLiveVarInfo::doSingleBackwardPass()
}
+void MethodLiveVarInfo::releaseMemory() {
+ // 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();
-//-----------------------------------------------------------------------------
-// performs live var anal for a method
-//-----------------------------------------------------------------------------
+ for( ; HMI != BB2BBLVMap.end(); ++HMI)
+ delete HMI->second; // delete all BBLiveVar in BB2BBLVMap
-bool MethodLiveVarInfo::runOnMethod(Method *M) {
- Meth = M;
+ BB2BBLVMap.clear();
- if( DEBUG_LV) cout << "Analysing live variables ...\n";
+ // 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
- // create and initialize all the BBLiveVars of the CFG
- constructBBs();
+ // hash map iterator for MInst2LVSetBI
+ //
+ MInstToLiveVarSetMapType::iterator MI = MInst2LVSetBI.begin();
- bool NeedAnotherIteration = false;
- do { // do one pass over CFG
- NeedAnotherIteration = doSingleBackwardPass( );
- } while (NeedAnotherIteration ); // repeat until we need more iterations
+ for( ; MI != MInst2LVSetBI.end(); ++MI)
+ delete MI->second; // delete all LiveVarSets in MInst2LVSetBI
-
- if( DEBUG_LV) cout << "Live Variable Analysis complete!\n";
- return false;
+ MInst2LVSetBI.clear();
+ MInst2LVSetAI.clear();
}
+
//-----------------------------------------------------------------------------
/* Following functions will give the LiveVar info for any machine instr in
a method. It should be called after a call to analyze().
@@ -178,23 +151,17 @@ bool MethodLiveVarInfo::runOnMethod(Method *M) {
//-----------------------------------------------------------------------------
// Gives live variable information before a machine instruction
//-----------------------------------------------------------------------------
-const LiveVarSet *
-MethodLiveVarInfo::getLiveVarSetBeforeMInst(const MachineInstr *const MInst,
- const BasicBlock *const CurBB)
-{
+const LiveVarSet *
+MethodLiveVarInfo::getLiveVarSetBeforeMInst(const MachineInstr *MInst,
+ const BasicBlock *CurBB) {
const LiveVarSet *LVSet = MInst2LVSetBI[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 ];
+ if (LVSet) {
+ return LVSet; // if found, just return the set
+ } else {
+ calcLiveVarSetsForBB(CurBB); // else, calc for all instrs in BB
+ assert(MInst2LVSetBI[MInst]);
+ return MInst2LVSetBI[MInst];
}
}
@@ -203,16 +170,16 @@ MethodLiveVarInfo::getLiveVarSetBeforeMInst(const MachineInstr *const MInst,
// Gives live variable information after a machine instruction
//-----------------------------------------------------------------------------
const LiveVarSet *
-MethodLiveVarInfo::getLiveVarSetAfterMInst(const MachineInstr *const MInst,
- const BasicBlock *const CurBB)
-{
+MethodLiveVarInfo::getLiveVarSetAfterMInst(const MachineInstr *MInst,
+ const BasicBlock *CurBB) {
const LiveVarSet *LVSet = MInst2LVSetAI[MInst];
- if( LVSet ) return LVSet; // if found, just return the set
- else {
- calcLiveVarSetsForBB( CurBB ); // else, calc for all instrs in BB
- assert( MInst2LVSetAI[ MInst ] );
- return MInst2LVSetAI[ MInst ];
+ if(LVSet) {
+ return LVSet; // if found, just return the set
+ } else {
+ calcLiveVarSetsForBB(CurBB); // else, calc for all instrs in BB
+ assert(MInst2LVSetAI[MInst]);
+ return MInst2LVSetAI[MInst];
}
}