diff --git a/lib/Analysis/LiveVar/BBLiveVar.cpp b/lib/Analysis/LiveVar/BBLiveVar.cpp index 525435d4f41..68eaebf7d27 100644 --- a/lib/Analysis/LiveVar/BBLiveVar.cpp +++ b/lib/Analysis/LiveVar/BBLiveVar.cpp @@ -21,27 +21,9 @@ /// BROKEN: Should not include sparc stuff directly into here #include "../../Target/Sparc/SparcInternals.h" // Only for PHI defn -static AnnotationID AID(AnnotationManager::getID("Analysis::BBLiveVar")); - -BBLiveVar *BBLiveVar::CreateOnBB(const BasicBlock &BB, MachineBasicBlock &MBB, - unsigned POID) { - BBLiveVar *Result = new BBLiveVar(BB, MBB, 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, MachineBasicBlock &mbb, unsigned id) - : Annotation(AID), BB(bb), MBB(mbb), POID(id) { + : BB(bb), MBB(mbb), POID(id) { InSetChanged = OutSetChanged = false; calcDefUseSets(); @@ -205,7 +187,8 @@ bool BBLiveVar::setPropagate(ValueSet *OutSet, const ValueSet *InSet, // propagates in set to OutSets of PREDECESSORs //----------------------------------------------------------------------------- -bool BBLiveVar::applyFlowFunc() { +bool BBLiveVar::applyFlowFunc(hash_map &BBLiveVarInfo) { // IMPORTANT: caller should check whether inset changed // (else no point in calling) @@ -216,7 +199,7 @@ bool BBLiveVar::applyFlowFunc() { for (pred_const_iterator PI = pred_begin(&BB), PE = pred_end(&BB); PI != PE ; ++PI) { - BBLiveVar *PredLVBB = BBLiveVar::GetFromBB(**PI); + BBLiveVar *PredLVBB = BBLiveVarInfo[*PI]; // do set union if (setPropagate(&PredLVBB->OutSet, &InSet, *PI)) { diff --git a/lib/Analysis/LiveVar/BBLiveVar.h b/lib/Analysis/LiveVar/BBLiveVar.h index 88e99a804eb..638b5aa8c61 100644 --- a/lib/Analysis/LiveVar/BBLiveVar.h +++ b/lib/Analysis/LiveVar/BBLiveVar.h @@ -9,8 +9,7 @@ #define LIVE_VAR_BB_H #include "llvm/CodeGen/ValueSet.h" -#include "Support/Annotation.h" -#include +#include "Support/hash_map" class BasicBlock; class Value; class MachineBasicBlock; @@ -24,7 +23,7 @@ enum LiveVarDebugLevel_t { extern LiveVarDebugLevel_t DEBUG_LV; -class BBLiveVar : public Annotation { +class BBLiveVar { const BasicBlock &BB; // pointer to BasicBlock MachineBasicBlock &MBB; // Pointer to MachineBasicBlock unsigned POID; // Post-Order ID @@ -36,7 +35,7 @@ class BBLiveVar : public Annotation { // map that contains PredBB -> Phi arguments // coming in on that edge. such uses have to be // treated differently from ordinary uses. - std::map PredToEdgeInSetMap; + hash_map PredToEdgeInSetMap; // method to propagate an InSet to OutSet of a predecessor bool setPropagate(ValueSet *OutSetOfPred, @@ -50,14 +49,9 @@ class BBLiveVar : public Annotation { void addUse(const Value *Op); void calcDefUseSets(); // calculates the Def & Use sets for this BB +public: BBLiveVar(const BasicBlock &BB, MachineBasicBlock &MBB, unsigned POID); - ~BBLiveVar() {} // make dtor private - public: - static BBLiveVar *CreateOnBB(const BasicBlock &BB, MachineBasicBlock &MBB, - unsigned POID); - static BBLiveVar *GetFromBB(const BasicBlock &BB); - static void RemoveFromBB(const BasicBlock &BB); inline bool isInSetChanged() const { return InSetChanged; } inline bool isOutSetChanged() const { return OutSetChanged; } @@ -69,7 +63,7 @@ class BBLiveVar : public Annotation { bool applyTransferFunc(); // calcultes the In in terms of Out // calculates Out set using In sets of the predecessors - bool applyFlowFunc(); + bool applyFlowFunc(hash_map &BBLiveVarInfo); inline const ValueSet &getOutSet() const { return OutSet; } inline ValueSet &getOutSet() { return OutSet; } diff --git a/lib/Analysis/LiveVar/FunctionLiveVarInfo.cpp b/lib/Analysis/LiveVar/FunctionLiveVarInfo.cpp index 26026d642a5..588ec646da7 100644 --- a/lib/Analysis/LiveVar/FunctionLiveVarInfo.cpp +++ b/lib/Analysis/LiveVar/FunctionLiveVarInfo.cpp @@ -47,18 +47,18 @@ clEnumValN(LV_DEBUG_Verbose, "v", "print def, use sets for every instrn also"), // gets OutSet of a BB const ValueSet &FunctionLiveVarInfo::getOutSetOfBB(const BasicBlock *BB) const { - return BBLiveVar::GetFromBB(*BB)->getOutSet(); + return BBLiveVarInfo.find(BB)->second->getOutSet(); } ValueSet &FunctionLiveVarInfo::getOutSetOfBB(const BasicBlock *BB) { - return BBLiveVar::GetFromBB(*BB)->getOutSet(); + return BBLiveVarInfo[BB]->getOutSet(); } // gets InSet of a BB const ValueSet &FunctionLiveVarInfo::getInSetOfBB(const BasicBlock *BB) const { - return BBLiveVar::GetFromBB(*BB)->getInSet(); + return BBLiveVarInfo.find(BB)->second->getInSet(); } - ValueSet &FunctionLiveVarInfo::getInSetOfBB(const BasicBlock *BB) { - return BBLiveVar::GetFromBB(*BB)->getInSet(); +ValueSet &FunctionLiveVarInfo::getInSetOfBB(const BasicBlock *BB) { + return BBLiveVarInfo[BB]->getInSet(); } @@ -103,15 +103,16 @@ void FunctionLiveVarInfo::constructBBs(const Function *F) { std::map::iterator POI = PONumbering.find(&BB); if (POI != PONumbering.end()) { // create a new BBLiveVar - LVBB = BBLiveVar::CreateOnBB(BB, *I, POId); + LVBB = new BBLiveVar(BB, *I, POId); } else { // The PO iterator does not discover unreachable blocks, but the random // iterator later may access these blocks. We must make sure to // initialize unreachable blocks as well. However, LV info is not correct // for those blocks (they are not analyzed) // - LVBB = BBLiveVar::CreateOnBB(BB, *I, ++POId); + LVBB = new BBLiveVar(BB, *I, ++POId); } + BBLiveVarInfo[&BB] = LVBB; if (DEBUG_LV) LVBB->printAllSets(); @@ -130,7 +131,7 @@ bool FunctionLiveVarInfo::doSingleBackwardPass(const Function *M, bool NeedAnotherIteration = false; for (po_iterator BBI = po_begin(M), BBE = po_end(M); BBI != BBE; ++BBI) { - BBLiveVar *LVBB = BBLiveVar::GetFromBB(**BBI); + BBLiveVar *LVBB = BBLiveVarInfo[*BBI]; assert(LVBB && "BasicBlock information not set for block!"); if (DEBUG_LV) std::cerr << " For BB " << (*BBI)->getName() << ":\n"; @@ -142,7 +143,7 @@ bool FunctionLiveVarInfo::doSingleBackwardPass(const Function *M, // OutSets are initialized to EMPTY. Recompute on first iter or if InSet // changed. if (iter == 0 || LVBB->isInSetChanged()) // to calc Outsets of preds - NeedAnotherIteration |= LVBB->applyFlowFunc(); + NeedAnotherIteration |= LVBB->applyFlowFunc(BBLiveVarInfo); if (DEBUG_LV) LVBB->printInOutSets(); } @@ -153,10 +154,12 @@ bool FunctionLiveVarInfo::doSingleBackwardPass(const Function *M, void FunctionLiveVarInfo::releaseMemory() { - // First remove all BBLiveVar annotations created in constructBBs(). - if (M) + // First remove all BBLiveVars created in constructBBs(). + if (M) { for (Function::const_iterator I = M->begin(), E = M->end(); I != E; ++I) - BBLiveVar::RemoveFromBB(*I); + delete BBLiveVarInfo[I]; + BBLiveVarInfo.clear(); + } M = 0; // Then delete all objects of type ValueSet created in calcLiveVarSetsForBB @@ -263,7 +266,7 @@ static void applyTranferFuncForMInst(ValueSet &LVS, const MachineInstr *MInst) { //----------------------------------------------------------------------------- void FunctionLiveVarInfo::calcLiveVarSetsForBB(const BasicBlock *BB) { - BBLiveVar *BBLV = BBLiveVar::GetFromBB(*BB); + BBLiveVar *BBLV = BBLiveVarInfo[BB]; assert(BBLV && "BBLiveVar annotation doesn't exist?"); const MachineBasicBlock &MIVec = BBLV->getMachineBasicBlock(); const MachineFunction &MF = MachineFunction::get(M); diff --git a/lib/Target/SparcV9/LiveVar/BBLiveVar.cpp b/lib/Target/SparcV9/LiveVar/BBLiveVar.cpp index 525435d4f41..68eaebf7d27 100644 --- a/lib/Target/SparcV9/LiveVar/BBLiveVar.cpp +++ b/lib/Target/SparcV9/LiveVar/BBLiveVar.cpp @@ -21,27 +21,9 @@ /// BROKEN: Should not include sparc stuff directly into here #include "../../Target/Sparc/SparcInternals.h" // Only for PHI defn -static AnnotationID AID(AnnotationManager::getID("Analysis::BBLiveVar")); - -BBLiveVar *BBLiveVar::CreateOnBB(const BasicBlock &BB, MachineBasicBlock &MBB, - unsigned POID) { - BBLiveVar *Result = new BBLiveVar(BB, MBB, 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, MachineBasicBlock &mbb, unsigned id) - : Annotation(AID), BB(bb), MBB(mbb), POID(id) { + : BB(bb), MBB(mbb), POID(id) { InSetChanged = OutSetChanged = false; calcDefUseSets(); @@ -205,7 +187,8 @@ bool BBLiveVar::setPropagate(ValueSet *OutSet, const ValueSet *InSet, // propagates in set to OutSets of PREDECESSORs //----------------------------------------------------------------------------- -bool BBLiveVar::applyFlowFunc() { +bool BBLiveVar::applyFlowFunc(hash_map &BBLiveVarInfo) { // IMPORTANT: caller should check whether inset changed // (else no point in calling) @@ -216,7 +199,7 @@ bool BBLiveVar::applyFlowFunc() { for (pred_const_iterator PI = pred_begin(&BB), PE = pred_end(&BB); PI != PE ; ++PI) { - BBLiveVar *PredLVBB = BBLiveVar::GetFromBB(**PI); + BBLiveVar *PredLVBB = BBLiveVarInfo[*PI]; // do set union if (setPropagate(&PredLVBB->OutSet, &InSet, *PI)) { diff --git a/lib/Target/SparcV9/LiveVar/BBLiveVar.h b/lib/Target/SparcV9/LiveVar/BBLiveVar.h index 88e99a804eb..638b5aa8c61 100644 --- a/lib/Target/SparcV9/LiveVar/BBLiveVar.h +++ b/lib/Target/SparcV9/LiveVar/BBLiveVar.h @@ -9,8 +9,7 @@ #define LIVE_VAR_BB_H #include "llvm/CodeGen/ValueSet.h" -#include "Support/Annotation.h" -#include +#include "Support/hash_map" class BasicBlock; class Value; class MachineBasicBlock; @@ -24,7 +23,7 @@ enum LiveVarDebugLevel_t { extern LiveVarDebugLevel_t DEBUG_LV; -class BBLiveVar : public Annotation { +class BBLiveVar { const BasicBlock &BB; // pointer to BasicBlock MachineBasicBlock &MBB; // Pointer to MachineBasicBlock unsigned POID; // Post-Order ID @@ -36,7 +35,7 @@ class BBLiveVar : public Annotation { // map that contains PredBB -> Phi arguments // coming in on that edge. such uses have to be // treated differently from ordinary uses. - std::map PredToEdgeInSetMap; + hash_map PredToEdgeInSetMap; // method to propagate an InSet to OutSet of a predecessor bool setPropagate(ValueSet *OutSetOfPred, @@ -50,14 +49,9 @@ class BBLiveVar : public Annotation { void addUse(const Value *Op); void calcDefUseSets(); // calculates the Def & Use sets for this BB +public: BBLiveVar(const BasicBlock &BB, MachineBasicBlock &MBB, unsigned POID); - ~BBLiveVar() {} // make dtor private - public: - static BBLiveVar *CreateOnBB(const BasicBlock &BB, MachineBasicBlock &MBB, - unsigned POID); - static BBLiveVar *GetFromBB(const BasicBlock &BB); - static void RemoveFromBB(const BasicBlock &BB); inline bool isInSetChanged() const { return InSetChanged; } inline bool isOutSetChanged() const { return OutSetChanged; } @@ -69,7 +63,7 @@ class BBLiveVar : public Annotation { bool applyTransferFunc(); // calcultes the In in terms of Out // calculates Out set using In sets of the predecessors - bool applyFlowFunc(); + bool applyFlowFunc(hash_map &BBLiveVarInfo); inline const ValueSet &getOutSet() const { return OutSet; } inline ValueSet &getOutSet() { return OutSet; } diff --git a/lib/Target/SparcV9/LiveVar/FunctionLiveVarInfo.cpp b/lib/Target/SparcV9/LiveVar/FunctionLiveVarInfo.cpp index 26026d642a5..588ec646da7 100644 --- a/lib/Target/SparcV9/LiveVar/FunctionLiveVarInfo.cpp +++ b/lib/Target/SparcV9/LiveVar/FunctionLiveVarInfo.cpp @@ -47,18 +47,18 @@ clEnumValN(LV_DEBUG_Verbose, "v", "print def, use sets for every instrn also"), // gets OutSet of a BB const ValueSet &FunctionLiveVarInfo::getOutSetOfBB(const BasicBlock *BB) const { - return BBLiveVar::GetFromBB(*BB)->getOutSet(); + return BBLiveVarInfo.find(BB)->second->getOutSet(); } ValueSet &FunctionLiveVarInfo::getOutSetOfBB(const BasicBlock *BB) { - return BBLiveVar::GetFromBB(*BB)->getOutSet(); + return BBLiveVarInfo[BB]->getOutSet(); } // gets InSet of a BB const ValueSet &FunctionLiveVarInfo::getInSetOfBB(const BasicBlock *BB) const { - return BBLiveVar::GetFromBB(*BB)->getInSet(); + return BBLiveVarInfo.find(BB)->second->getInSet(); } - ValueSet &FunctionLiveVarInfo::getInSetOfBB(const BasicBlock *BB) { - return BBLiveVar::GetFromBB(*BB)->getInSet(); +ValueSet &FunctionLiveVarInfo::getInSetOfBB(const BasicBlock *BB) { + return BBLiveVarInfo[BB]->getInSet(); } @@ -103,15 +103,16 @@ void FunctionLiveVarInfo::constructBBs(const Function *F) { std::map::iterator POI = PONumbering.find(&BB); if (POI != PONumbering.end()) { // create a new BBLiveVar - LVBB = BBLiveVar::CreateOnBB(BB, *I, POId); + LVBB = new BBLiveVar(BB, *I, POId); } else { // The PO iterator does not discover unreachable blocks, but the random // iterator later may access these blocks. We must make sure to // initialize unreachable blocks as well. However, LV info is not correct // for those blocks (they are not analyzed) // - LVBB = BBLiveVar::CreateOnBB(BB, *I, ++POId); + LVBB = new BBLiveVar(BB, *I, ++POId); } + BBLiveVarInfo[&BB] = LVBB; if (DEBUG_LV) LVBB->printAllSets(); @@ -130,7 +131,7 @@ bool FunctionLiveVarInfo::doSingleBackwardPass(const Function *M, bool NeedAnotherIteration = false; for (po_iterator BBI = po_begin(M), BBE = po_end(M); BBI != BBE; ++BBI) { - BBLiveVar *LVBB = BBLiveVar::GetFromBB(**BBI); + BBLiveVar *LVBB = BBLiveVarInfo[*BBI]; assert(LVBB && "BasicBlock information not set for block!"); if (DEBUG_LV) std::cerr << " For BB " << (*BBI)->getName() << ":\n"; @@ -142,7 +143,7 @@ bool FunctionLiveVarInfo::doSingleBackwardPass(const Function *M, // OutSets are initialized to EMPTY. Recompute on first iter or if InSet // changed. if (iter == 0 || LVBB->isInSetChanged()) // to calc Outsets of preds - NeedAnotherIteration |= LVBB->applyFlowFunc(); + NeedAnotherIteration |= LVBB->applyFlowFunc(BBLiveVarInfo); if (DEBUG_LV) LVBB->printInOutSets(); } @@ -153,10 +154,12 @@ bool FunctionLiveVarInfo::doSingleBackwardPass(const Function *M, void FunctionLiveVarInfo::releaseMemory() { - // First remove all BBLiveVar annotations created in constructBBs(). - if (M) + // First remove all BBLiveVars created in constructBBs(). + if (M) { for (Function::const_iterator I = M->begin(), E = M->end(); I != E; ++I) - BBLiveVar::RemoveFromBB(*I); + delete BBLiveVarInfo[I]; + BBLiveVarInfo.clear(); + } M = 0; // Then delete all objects of type ValueSet created in calcLiveVarSetsForBB @@ -263,7 +266,7 @@ static void applyTranferFuncForMInst(ValueSet &LVS, const MachineInstr *MInst) { //----------------------------------------------------------------------------- void FunctionLiveVarInfo::calcLiveVarSetsForBB(const BasicBlock *BB) { - BBLiveVar *BBLV = BBLiveVar::GetFromBB(*BB); + BBLiveVar *BBLV = BBLiveVarInfo[BB]; assert(BBLV && "BBLiveVar annotation doesn't exist?"); const MachineBasicBlock &MIVec = BBLV->getMachineBasicBlock(); const MachineFunction &MF = MachineFunction::get(M);