Convert BBLiveVar to be a BasicBlock annotation, this removes the BB2BBLVMap from MethodLiveVarInfo.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@1721 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner
2002-02-05 06:52:25 +00:00
parent 2f898d2074
commit 6357a3f42d
8 changed files with 118 additions and 76 deletions

View File

@@ -73,15 +73,14 @@ class BBLiveVar;
class MachineInstr; class MachineInstr;
class MethodLiveVarInfo : public MethodPass { class MethodLiveVarInfo : public MethodPass {
// A map between the BasicBlock and BBLiveVar
std::map<const BasicBlock *, BBLiveVar *> BB2BBLVMap;
// Machine Instr to LiveVarSet Map for providing LVset BEFORE each inst // Machine Instr to LiveVarSet Map for providing LVset BEFORE each inst
std::map<const MachineInstr *, const ValueSet *> MInst2LVSetBI; std::map<const MachineInstr *, const ValueSet *> MInst2LVSetBI;
// Machine Instr to LiveVarSet Map for providing LVset AFTER each inst // Machine Instr to LiveVarSet Map for providing LVset AFTER each inst
std::map<const MachineInstr *, const ValueSet *> MInst2LVSetAI; std::map<const MachineInstr *, const ValueSet *> MInst2LVSetAI;
// Stored Method that the data is computed with respect to
const Method *M;
// --------- private methods ----------------------------------------- // --------- private methods -----------------------------------------
@@ -94,12 +93,10 @@ class MethodLiveVarInfo : public MethodPass {
// calculates live var sets for instructions in a BB // calculates live var sets for instructions in a BB
void calcLiveVarSetsForBB(const BasicBlock *BB); void calcLiveVarSetsForBB(const BasicBlock *BB);
public: public:
static AnalysisID ID; // We are an analysis, we must have an ID static AnalysisID ID; // We are an analysis, we must have an ID
MethodLiveVarInfo(AnalysisID id = ID) { assert(id == ID); } MethodLiveVarInfo(AnalysisID id = ID) { assert(id == ID); }
~MethodLiveVarInfo() { releaseMemory(); }
// --------- Implement the MethodPass interface ---------------------- // --------- Implement the MethodPass interface ----------------------

View File

@@ -73,15 +73,14 @@ class BBLiveVar;
class MachineInstr; class MachineInstr;
class MethodLiveVarInfo : public MethodPass { class MethodLiveVarInfo : public MethodPass {
// A map between the BasicBlock and BBLiveVar
std::map<const BasicBlock *, BBLiveVar *> BB2BBLVMap;
// Machine Instr to LiveVarSet Map for providing LVset BEFORE each inst // Machine Instr to LiveVarSet Map for providing LVset BEFORE each inst
std::map<const MachineInstr *, const ValueSet *> MInst2LVSetBI; std::map<const MachineInstr *, const ValueSet *> MInst2LVSetBI;
// Machine Instr to LiveVarSet Map for providing LVset AFTER each inst // Machine Instr to LiveVarSet Map for providing LVset AFTER each inst
std::map<const MachineInstr *, const ValueSet *> MInst2LVSetAI; std::map<const MachineInstr *, const ValueSet *> MInst2LVSetAI;
// Stored Method that the data is computed with respect to
const Method *M;
// --------- private methods ----------------------------------------- // --------- private methods -----------------------------------------
@@ -94,12 +93,10 @@ class MethodLiveVarInfo : public MethodPass {
// calculates live var sets for instructions in a BB // calculates live var sets for instructions in a BB
void calcLiveVarSetsForBB(const BasicBlock *BB); void calcLiveVarSetsForBB(const BasicBlock *BB);
public: public:
static AnalysisID ID; // We are an analysis, we must have an ID static AnalysisID ID; // We are an analysis, we must have an ID
MethodLiveVarInfo(AnalysisID id = ID) { assert(id == ID); } MethodLiveVarInfo(AnalysisID id = ID) { assert(id == ID); }
~MethodLiveVarInfo() { releaseMemory(); }
// --------- Implement the MethodPass interface ---------------------- // --------- Implement the MethodPass interface ----------------------

View File

@@ -15,8 +15,26 @@
using std::cerr; using std::cerr;
static AnnotationID AID(AnnotationManager::getID("Analysis::BBLiveVar"));
BBLiveVar *BBLiveVar::CreateOnBB(const BasicBlock *BB, unsigned POID) {
BBLiveVar *Result = new BBLiveVar(BB, POID);
BB->addAnnotation(Result);
return Result;
}
BBLiveVar *BBLiveVar::GetFromBB(const BasicBlock *BB) {
return (BBLiveVar*)BB->getAnnotation(AID);
}
void BBLiveVar::RemoveFromBB(const BasicBlock *BB) {
bool Deleted = BB->deleteAnnotation(AID);
assert(Deleted && "BBLiveVar annotation did not exist!");
}
BBLiveVar::BBLiveVar(const BasicBlock *bb, unsigned id) BBLiveVar::BBLiveVar(const BasicBlock *bb, unsigned id)
: BB(bb), POID(id) { : Annotation(AID), BB(bb), POID(id) {
InSetChanged = OutSetChanged = false; InSetChanged = OutSetChanged = false;
calcDefUseSets(); calcDefUseSets();
@@ -152,9 +170,12 @@ bool BBLiveVar::setPropagate(ValueSet *OutSet, const ValueSet *InSet,
InIt != InE; ++InIt) { InIt != InE; ++InIt) {
const BasicBlock *PredBBOfPhiArg = PhiArgMap[*InIt]; const BasicBlock *PredBBOfPhiArg = PhiArgMap[*InIt];
// if this var is not a phi arg OR // Only propogate liveness of the value if it is either not an argument of
// it's a phi arg and the var went down from this BB // a PHI node, or if it IS an argument, AND 'PredBB' is the basic block
if (!PredBBOfPhiArg || PredBBOfPhiArg == PredBB) // that it is coming in from. THIS IS BROKEN because the same value can
// come in from multiple predecessors (and it's not a multimap)!
//
if (PredBBOfPhiArg == 0 || PredBBOfPhiArg == PredBB)
if (OutSet->insert(*InIt).second) if (OutSet->insert(*InIt).second)
Changed = true; Changed = true;
} }
@@ -167,7 +188,7 @@ bool BBLiveVar::setPropagate(ValueSet *OutSet, const ValueSet *InSet,
// propogates in set to OutSets of PREDECESSORs // propogates in set to OutSets of PREDECESSORs
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
bool BBLiveVar::applyFlowFunc(std::map<const BasicBlock *, BBLiveVar *> &LVMap){ bool BBLiveVar::applyFlowFunc() {
// IMPORTANT: caller should check whether inset changed // IMPORTANT: caller should check whether inset changed
// (else no point in calling) // (else no point in calling)
@@ -178,7 +199,7 @@ bool BBLiveVar::applyFlowFunc(std::map<const BasicBlock *, BBLiveVar *> &LVMap){
for (BasicBlock::pred_const_iterator PI = BB->pred_begin(), for (BasicBlock::pred_const_iterator PI = BB->pred_begin(),
PE = BB->pred_begin(); PI != PE ; ++PI) { PE = BB->pred_begin(); PI != PE ; ++PI) {
BBLiveVar *PredLVBB = LVMap[*PI]; BBLiveVar *PredLVBB = BBLiveVar::GetFromBB(*PI);
// do set union // do set union
if (setPropagate(&PredLVBB->OutSet, &InSet, *PI)) { if (setPropagate(&PredLVBB->OutSet, &InSet, *PI)) {

View File

@@ -1,6 +1,7 @@
//===-- BBLiveVar.h - Live Variable Analysis for a BasicBlock ----*- C++ -*--=// //===-- BBLiveVar.h - Live Variable Analysis for a BasicBlock ----*- C++ -*--=//
// //
// This is a wrapper class for BasicBlock which is used by live var analysis. // This is a BasicBlock annotation class that is used by live var analysis to
// hold data flow information for a basic block.
// //
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
@@ -8,12 +9,13 @@
#define LIVE_VAR_BB_H #define LIVE_VAR_BB_H
#include "llvm/Analysis/LiveVar/ValueSet.h" #include "llvm/Analysis/LiveVar/ValueSet.h"
#include "llvm/Annotation.h"
#include <map> #include <map>
class Method; class Method;
class BasicBlock; class BasicBlock;
class Value; class Value;
class BBLiveVar { class BBLiveVar : public Annotation {
const BasicBlock *BB; // pointer to BasicBlock const BasicBlock *BB; // pointer to BasicBlock
unsigned POID; // Post-Order ID unsigned POID; // Post-Order ID
@@ -37,8 +39,13 @@ class BBLiveVar {
void addUse(const Value *Op); void addUse(const Value *Op);
void calcDefUseSets(); // calculates the Def & Use sets for this BB void calcDefUseSets(); // calculates the Def & Use sets for this BB
public:
BBLiveVar(const BasicBlock *BB, unsigned POID); BBLiveVar(const BasicBlock *BB, unsigned POID);
~BBLiveVar() {} // make dtor private
public:
static BBLiveVar *CreateOnBB(const BasicBlock *BB, unsigned POID);
static BBLiveVar *GetFromBB(const BasicBlock *BB);
static void RemoveFromBB(const BasicBlock *BB);
inline bool isInSetChanged() const { return InSetChanged; } inline bool isInSetChanged() const { return InSetChanged; }
inline bool isOutSetChanged() const { return OutSetChanged; } inline bool isOutSetChanged() const { return OutSetChanged; }
@@ -48,7 +55,7 @@ class BBLiveVar {
bool applyTransferFunc(); // calcultes the In in terms of Out bool applyTransferFunc(); // calcultes the In in terms of Out
// calculates Out set using In sets of the predecessors // calculates Out set using In sets of the predecessors
bool applyFlowFunc(std::map<const BasicBlock *, BBLiveVar *> &LVMap); bool applyFlowFunc();
inline const ValueSet &getOutSet() const { return OutSet; } inline const ValueSet &getOutSet() const { return OutSet; }
inline const ValueSet &getInSet() const { return InSet; } inline const ValueSet &getInSet() const { return InSet; }

View File

@@ -21,12 +21,12 @@ AnalysisID MethodLiveVarInfo::ID(AnalysisID::create<MethodLiveVarInfo>());
// gets OutSet of a BB // gets OutSet of a BB
const ValueSet &MethodLiveVarInfo::getOutSetOfBB(const BasicBlock *BB) const { const ValueSet &MethodLiveVarInfo::getOutSetOfBB(const BasicBlock *BB) const {
return BB2BBLVMap.find(BB)->second->getOutSet(); return BBLiveVar::GetFromBB(BB)->getOutSet();
} }
// gets InSet of a BB // gets InSet of a BB
const ValueSet &MethodLiveVarInfo::getInSetOfBB(const BasicBlock *BB) const { const ValueSet &MethodLiveVarInfo::getInSetOfBB(const BasicBlock *BB) const {
return BB2BBLVMap.find(BB)->second->getInSet(); return BBLiveVar::GetFromBB(BB)->getInSet();
} }
@@ -34,13 +34,14 @@ const ValueSet &MethodLiveVarInfo::getInSetOfBB(const BasicBlock *BB) const {
// Performs live var analysis for a method // Performs live var analysis for a method
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
bool MethodLiveVarInfo::runOnMethod(Method *M) { bool MethodLiveVarInfo::runOnMethod(Method *Meth) {
M = Meth;
if (DEBUG_LV) std::cerr << "Analysing live variables ...\n"; if (DEBUG_LV) std::cerr << "Analysing live variables ...\n";
// create and initialize all the BBLiveVars of the CFG // create and initialize all the BBLiveVars of the CFG
constructBBs(M); constructBBs(Meth);
while (doSingleBackwardPass(M)) while (doSingleBackwardPass(Meth))
; // Iterate until we are done. ; // Iterate until we are done.
if (DEBUG_LV) std::cerr << "Live Variable Analysis complete!\n"; if (DEBUG_LV) std::cerr << "Live Variable Analysis complete!\n";
@@ -62,8 +63,7 @@ void MethodLiveVarInfo::constructBBs(const Method *M) {
if (DEBUG_LV) std::cerr << " For BB " << RAV(BB) << ":\n"; if (DEBUG_LV) std::cerr << " For BB " << RAV(BB) << ":\n";
// create a new BBLiveVar // create a new BBLiveVar
BBLiveVar *LVBB = new BBLiveVar(BB, POId); BBLiveVar *LVBB = BBLiveVar::CreateOnBB(BB, POId);
BB2BBLVMap[BB] = LVBB; // insert the pair to Map
if (DEBUG_LV) if (DEBUG_LV)
LVBB->printAllSets(); LVBB->printAllSets();
@@ -76,8 +76,8 @@ void MethodLiveVarInfo::constructBBs(const Method *M) {
// //
for (Method::const_iterator BBRI = M->begin(), BBRE = M->end(); for (Method::const_iterator BBRI = M->begin(), BBRE = M->end();
BBRI != BBRE; ++BBRI, ++POId) BBRI != BBRE; ++BBRI, ++POId)
if (!BB2BBLVMap[*BBRI]) // Not yet processed? if (!BBLiveVar::GetFromBB(*BBRI)) // Not yet processed?
BB2BBLVMap[*BBRI] = new BBLiveVar(*BBRI, POId); BBLiveVar::CreateOnBB(*BBRI, POId);
} }
@@ -90,7 +90,7 @@ bool MethodLiveVarInfo::doSingleBackwardPass(const Method *M) {
bool NeedAnotherIteration = false; bool NeedAnotherIteration = false;
for (po_iterator<const Method*> BBI = po_begin(M); BBI != po_end(M) ; ++BBI) { for (po_iterator<const Method*> BBI = po_begin(M); BBI != po_end(M) ; ++BBI) {
BBLiveVar *LVBB = BB2BBLVMap[*BBI]; BBLiveVar *LVBB = BBLiveVar::GetFromBB(*BBI);
assert(LVBB && "BasicBlock information not set for block!"); assert(LVBB && "BasicBlock information not set for block!");
if (DEBUG_LV) std::cerr << " For BB " << (*BBI)->getName() << ":\n"; if (DEBUG_LV) std::cerr << " For BB " << (*BBI)->getName() << ":\n";
@@ -99,7 +99,7 @@ bool MethodLiveVarInfo::doSingleBackwardPass(const Method *M) {
LVBB->applyTransferFunc(); // apply the Tran Func to calc InSet LVBB->applyTransferFunc(); // apply the Tran Func to calc InSet
if (LVBB->isInSetChanged()) // to calc Outsets of preds if (LVBB->isInSetChanged()) // to calc Outsets of preds
NeedAnotherIteration |= LVBB->applyFlowFunc(BB2BBLVMap); NeedAnotherIteration |= LVBB->applyFlowFunc();
if (DEBUG_LV) LVBB->printInOutSets(); if (DEBUG_LV) LVBB->printInOutSets();
} }
@@ -110,15 +110,11 @@ bool MethodLiveVarInfo::doSingleBackwardPass(const Method *M) {
void MethodLiveVarInfo::releaseMemory() { void MethodLiveVarInfo::releaseMemory() {
// First delete all BBLiveVar objects created in constructBBs(). A new object // First remove all BBLiveVar annotations created in constructBBs().
// of type BBLiveVar is created for every BasicBlock in the method if (M)
// for (Method::const_iterator I = M->begin(), E = M->end(); I != E; ++I)
for (std::map<const BasicBlock *, BBLiveVar *>::iterator BBLiveVar::RemoveFromBB(*I);
HMI = BB2BBLVMap.begin(), M = 0;
HME = BB2BBLVMap.end(); HMI != HME; ++HMI)
delete HMI->second; // delete all BBLiveVar in BB2BBLVMap
BB2BBLVMap.clear();
// Then delete all objects of type ValueSet created in calcLiveVarSetsForBB // Then delete all objects of type ValueSet created in calcLiveVarSetsForBB
// and entered into MInst2LVSetBI and MInst2LVSetAI (these are caches // and entered into MInst2LVSetBI and MInst2LVSetAI (these are caches

View File

@@ -15,8 +15,26 @@
using std::cerr; using std::cerr;
static AnnotationID AID(AnnotationManager::getID("Analysis::BBLiveVar"));
BBLiveVar *BBLiveVar::CreateOnBB(const BasicBlock *BB, unsigned POID) {
BBLiveVar *Result = new BBLiveVar(BB, POID);
BB->addAnnotation(Result);
return Result;
}
BBLiveVar *BBLiveVar::GetFromBB(const BasicBlock *BB) {
return (BBLiveVar*)BB->getAnnotation(AID);
}
void BBLiveVar::RemoveFromBB(const BasicBlock *BB) {
bool Deleted = BB->deleteAnnotation(AID);
assert(Deleted && "BBLiveVar annotation did not exist!");
}
BBLiveVar::BBLiveVar(const BasicBlock *bb, unsigned id) BBLiveVar::BBLiveVar(const BasicBlock *bb, unsigned id)
: BB(bb), POID(id) { : Annotation(AID), BB(bb), POID(id) {
InSetChanged = OutSetChanged = false; InSetChanged = OutSetChanged = false;
calcDefUseSets(); calcDefUseSets();
@@ -152,9 +170,12 @@ bool BBLiveVar::setPropagate(ValueSet *OutSet, const ValueSet *InSet,
InIt != InE; ++InIt) { InIt != InE; ++InIt) {
const BasicBlock *PredBBOfPhiArg = PhiArgMap[*InIt]; const BasicBlock *PredBBOfPhiArg = PhiArgMap[*InIt];
// if this var is not a phi arg OR // Only propogate liveness of the value if it is either not an argument of
// it's a phi arg and the var went down from this BB // a PHI node, or if it IS an argument, AND 'PredBB' is the basic block
if (!PredBBOfPhiArg || PredBBOfPhiArg == PredBB) // that it is coming in from. THIS IS BROKEN because the same value can
// come in from multiple predecessors (and it's not a multimap)!
//
if (PredBBOfPhiArg == 0 || PredBBOfPhiArg == PredBB)
if (OutSet->insert(*InIt).second) if (OutSet->insert(*InIt).second)
Changed = true; Changed = true;
} }
@@ -167,7 +188,7 @@ bool BBLiveVar::setPropagate(ValueSet *OutSet, const ValueSet *InSet,
// propogates in set to OutSets of PREDECESSORs // propogates in set to OutSets of PREDECESSORs
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
bool BBLiveVar::applyFlowFunc(std::map<const BasicBlock *, BBLiveVar *> &LVMap){ bool BBLiveVar::applyFlowFunc() {
// IMPORTANT: caller should check whether inset changed // IMPORTANT: caller should check whether inset changed
// (else no point in calling) // (else no point in calling)
@@ -178,7 +199,7 @@ bool BBLiveVar::applyFlowFunc(std::map<const BasicBlock *, BBLiveVar *> &LVMap){
for (BasicBlock::pred_const_iterator PI = BB->pred_begin(), for (BasicBlock::pred_const_iterator PI = BB->pred_begin(),
PE = BB->pred_begin(); PI != PE ; ++PI) { PE = BB->pred_begin(); PI != PE ; ++PI) {
BBLiveVar *PredLVBB = LVMap[*PI]; BBLiveVar *PredLVBB = BBLiveVar::GetFromBB(*PI);
// do set union // do set union
if (setPropagate(&PredLVBB->OutSet, &InSet, *PI)) { if (setPropagate(&PredLVBB->OutSet, &InSet, *PI)) {

View File

@@ -1,6 +1,7 @@
//===-- BBLiveVar.h - Live Variable Analysis for a BasicBlock ----*- C++ -*--=// //===-- BBLiveVar.h - Live Variable Analysis for a BasicBlock ----*- C++ -*--=//
// //
// This is a wrapper class for BasicBlock which is used by live var analysis. // This is a BasicBlock annotation class that is used by live var analysis to
// hold data flow information for a basic block.
// //
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
@@ -8,12 +9,13 @@
#define LIVE_VAR_BB_H #define LIVE_VAR_BB_H
#include "llvm/Analysis/LiveVar/ValueSet.h" #include "llvm/Analysis/LiveVar/ValueSet.h"
#include "llvm/Annotation.h"
#include <map> #include <map>
class Method; class Method;
class BasicBlock; class BasicBlock;
class Value; class Value;
class BBLiveVar { class BBLiveVar : public Annotation {
const BasicBlock *BB; // pointer to BasicBlock const BasicBlock *BB; // pointer to BasicBlock
unsigned POID; // Post-Order ID unsigned POID; // Post-Order ID
@@ -37,8 +39,13 @@ class BBLiveVar {
void addUse(const Value *Op); void addUse(const Value *Op);
void calcDefUseSets(); // calculates the Def & Use sets for this BB void calcDefUseSets(); // calculates the Def & Use sets for this BB
public:
BBLiveVar(const BasicBlock *BB, unsigned POID); BBLiveVar(const BasicBlock *BB, unsigned POID);
~BBLiveVar() {} // make dtor private
public:
static BBLiveVar *CreateOnBB(const BasicBlock *BB, unsigned POID);
static BBLiveVar *GetFromBB(const BasicBlock *BB);
static void RemoveFromBB(const BasicBlock *BB);
inline bool isInSetChanged() const { return InSetChanged; } inline bool isInSetChanged() const { return InSetChanged; }
inline bool isOutSetChanged() const { return OutSetChanged; } inline bool isOutSetChanged() const { return OutSetChanged; }
@@ -48,7 +55,7 @@ class BBLiveVar {
bool applyTransferFunc(); // calcultes the In in terms of Out bool applyTransferFunc(); // calcultes the In in terms of Out
// calculates Out set using In sets of the predecessors // calculates Out set using In sets of the predecessors
bool applyFlowFunc(std::map<const BasicBlock *, BBLiveVar *> &LVMap); bool applyFlowFunc();
inline const ValueSet &getOutSet() const { return OutSet; } inline const ValueSet &getOutSet() const { return OutSet; }
inline const ValueSet &getInSet() const { return InSet; } inline const ValueSet &getInSet() const { return InSet; }

View File

@@ -21,12 +21,12 @@ AnalysisID MethodLiveVarInfo::ID(AnalysisID::create<MethodLiveVarInfo>());
// gets OutSet of a BB // gets OutSet of a BB
const ValueSet &MethodLiveVarInfo::getOutSetOfBB(const BasicBlock *BB) const { const ValueSet &MethodLiveVarInfo::getOutSetOfBB(const BasicBlock *BB) const {
return BB2BBLVMap.find(BB)->second->getOutSet(); return BBLiveVar::GetFromBB(BB)->getOutSet();
} }
// gets InSet of a BB // gets InSet of a BB
const ValueSet &MethodLiveVarInfo::getInSetOfBB(const BasicBlock *BB) const { const ValueSet &MethodLiveVarInfo::getInSetOfBB(const BasicBlock *BB) const {
return BB2BBLVMap.find(BB)->second->getInSet(); return BBLiveVar::GetFromBB(BB)->getInSet();
} }
@@ -34,13 +34,14 @@ const ValueSet &MethodLiveVarInfo::getInSetOfBB(const BasicBlock *BB) const {
// Performs live var analysis for a method // Performs live var analysis for a method
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
bool MethodLiveVarInfo::runOnMethod(Method *M) { bool MethodLiveVarInfo::runOnMethod(Method *Meth) {
M = Meth;
if (DEBUG_LV) std::cerr << "Analysing live variables ...\n"; if (DEBUG_LV) std::cerr << "Analysing live variables ...\n";
// create and initialize all the BBLiveVars of the CFG // create and initialize all the BBLiveVars of the CFG
constructBBs(M); constructBBs(Meth);
while (doSingleBackwardPass(M)) while (doSingleBackwardPass(Meth))
; // Iterate until we are done. ; // Iterate until we are done.
if (DEBUG_LV) std::cerr << "Live Variable Analysis complete!\n"; if (DEBUG_LV) std::cerr << "Live Variable Analysis complete!\n";
@@ -62,8 +63,7 @@ void MethodLiveVarInfo::constructBBs(const Method *M) {
if (DEBUG_LV) std::cerr << " For BB " << RAV(BB) << ":\n"; if (DEBUG_LV) std::cerr << " For BB " << RAV(BB) << ":\n";
// create a new BBLiveVar // create a new BBLiveVar
BBLiveVar *LVBB = new BBLiveVar(BB, POId); BBLiveVar *LVBB = BBLiveVar::CreateOnBB(BB, POId);
BB2BBLVMap[BB] = LVBB; // insert the pair to Map
if (DEBUG_LV) if (DEBUG_LV)
LVBB->printAllSets(); LVBB->printAllSets();
@@ -76,8 +76,8 @@ void MethodLiveVarInfo::constructBBs(const Method *M) {
// //
for (Method::const_iterator BBRI = M->begin(), BBRE = M->end(); for (Method::const_iterator BBRI = M->begin(), BBRE = M->end();
BBRI != BBRE; ++BBRI, ++POId) BBRI != BBRE; ++BBRI, ++POId)
if (!BB2BBLVMap[*BBRI]) // Not yet processed? if (!BBLiveVar::GetFromBB(*BBRI)) // Not yet processed?
BB2BBLVMap[*BBRI] = new BBLiveVar(*BBRI, POId); BBLiveVar::CreateOnBB(*BBRI, POId);
} }
@@ -90,7 +90,7 @@ bool MethodLiveVarInfo::doSingleBackwardPass(const Method *M) {
bool NeedAnotherIteration = false; bool NeedAnotherIteration = false;
for (po_iterator<const Method*> BBI = po_begin(M); BBI != po_end(M) ; ++BBI) { for (po_iterator<const Method*> BBI = po_begin(M); BBI != po_end(M) ; ++BBI) {
BBLiveVar *LVBB = BB2BBLVMap[*BBI]; BBLiveVar *LVBB = BBLiveVar::GetFromBB(*BBI);
assert(LVBB && "BasicBlock information not set for block!"); assert(LVBB && "BasicBlock information not set for block!");
if (DEBUG_LV) std::cerr << " For BB " << (*BBI)->getName() << ":\n"; if (DEBUG_LV) std::cerr << " For BB " << (*BBI)->getName() << ":\n";
@@ -99,7 +99,7 @@ bool MethodLiveVarInfo::doSingleBackwardPass(const Method *M) {
LVBB->applyTransferFunc(); // apply the Tran Func to calc InSet LVBB->applyTransferFunc(); // apply the Tran Func to calc InSet
if (LVBB->isInSetChanged()) // to calc Outsets of preds if (LVBB->isInSetChanged()) // to calc Outsets of preds
NeedAnotherIteration |= LVBB->applyFlowFunc(BB2BBLVMap); NeedAnotherIteration |= LVBB->applyFlowFunc();
if (DEBUG_LV) LVBB->printInOutSets(); if (DEBUG_LV) LVBB->printInOutSets();
} }
@@ -110,15 +110,11 @@ bool MethodLiveVarInfo::doSingleBackwardPass(const Method *M) {
void MethodLiveVarInfo::releaseMemory() { void MethodLiveVarInfo::releaseMemory() {
// First delete all BBLiveVar objects created in constructBBs(). A new object // First remove all BBLiveVar annotations created in constructBBs().
// of type BBLiveVar is created for every BasicBlock in the method if (M)
// for (Method::const_iterator I = M->begin(), E = M->end(); I != E; ++I)
for (std::map<const BasicBlock *, BBLiveVar *>::iterator BBLiveVar::RemoveFromBB(*I);
HMI = BB2BBLVMap.begin(), M = 0;
HME = BB2BBLVMap.end(); HMI != HME; ++HMI)
delete HMI->second; // delete all BBLiveVar in BB2BBLVMap
BB2BBLVMap.clear();
// Then delete all objects of type ValueSet created in calcLiveVarSetsForBB // Then delete all objects of type ValueSet created in calcLiveVarSetsForBB
// and entered into MInst2LVSetBI and MInst2LVSetAI (these are caches // and entered into MInst2LVSetBI and MInst2LVSetAI (these are caches