[llvm-commits] CVS: llvm/lib/Analysis/LiveVar/BBLiveVar.cpp BBLiveVar.h FunctionLiveVarInfo.cpp

Chris Lattner lattner at cs.uiuc.edu
Mon Oct 20 15:53:01 PDT 2003


Changes in directory llvm/lib/Analysis/LiveVar:

BBLiveVar.cpp updated: 1.37 -> 1.38
BBLiveVar.h updated: 1.22 -> 1.23
FunctionLiveVarInfo.cpp updated: 1.48 -> 1.49

---
Log message:

Convert this code from using annotations to using a local map


---
Diffs of the changes:  (+25 -45)

Index: llvm/lib/Analysis/LiveVar/BBLiveVar.cpp
diff -u llvm/lib/Analysis/LiveVar/BBLiveVar.cpp:1.37 llvm/lib/Analysis/LiveVar/BBLiveVar.cpp:1.38
--- llvm/lib/Analysis/LiveVar/BBLiveVar.cpp:1.37	Mon Oct 20 15:38:17 2003
+++ llvm/lib/Analysis/LiveVar/BBLiveVar.cpp	Mon Oct 20 15:52:23 2003
@@ -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 @@
 // propagates in set to OutSets of PREDECESSORs
 //-----------------------------------------------------------------------------
 
-bool BBLiveVar::applyFlowFunc() {
+bool BBLiveVar::applyFlowFunc(hash_map<const BasicBlock*,
+                                       BBLiveVar*> &BBLiveVarInfo) {
   // IMPORTANT: caller should check whether inset changed 
   //            (else no point in calling)
   
@@ -216,7 +199,7 @@
 
   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)) {  


Index: llvm/lib/Analysis/LiveVar/BBLiveVar.h
diff -u llvm/lib/Analysis/LiveVar/BBLiveVar.h:1.22 llvm/lib/Analysis/LiveVar/BBLiveVar.h:1.23
--- llvm/lib/Analysis/LiveVar/BBLiveVar.h:1.22	Sun Oct 12 22:32:07 2003
+++ llvm/lib/Analysis/LiveVar/BBLiveVar.h	Mon Oct 20 15:52:23 2003
@@ -9,8 +9,7 @@
 #define LIVE_VAR_BB_H
 
 #include "llvm/CodeGen/ValueSet.h"
-#include "Support/Annotation.h"
-#include <map>
+#include "Support/hash_map"
 class BasicBlock;
 class Value;
 class MachineBasicBlock;
@@ -24,7 +23,7 @@
 
 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 @@
                                 // map that contains PredBB -> Phi arguments
                                 // coming in on that edge.  such uses have to be
                                 // treated differently from ordinary uses.
-  std::map<const BasicBlock *, ValueSet> PredToEdgeInSetMap;
+  hash_map<const BasicBlock *, ValueSet> PredToEdgeInSetMap;
   
   // method to propagate an InSet to OutSet of a predecessor
   bool setPropagate(ValueSet *OutSetOfPred, 
@@ -50,14 +49,9 @@
   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 @@
   bool applyTransferFunc();      // calcultes the In in terms of Out 
 
   // calculates Out set using In sets of the predecessors
-  bool applyFlowFunc();
+  bool applyFlowFunc(hash_map<const BasicBlock*, BBLiveVar*> &BBLiveVarInfo);
 
   inline const ValueSet &getOutSet() const { return OutSet; }
   inline       ValueSet &getOutSet()       { return OutSet; }


Index: llvm/lib/Analysis/LiveVar/FunctionLiveVarInfo.cpp
diff -u llvm/lib/Analysis/LiveVar/FunctionLiveVarInfo.cpp:1.48 llvm/lib/Analysis/LiveVar/FunctionLiveVarInfo.cpp:1.49
--- llvm/lib/Analysis/LiveVar/FunctionLiveVarInfo.cpp:1.48	Mon Oct 20 14:43:14 2003
+++ llvm/lib/Analysis/LiveVar/FunctionLiveVarInfo.cpp	Mon Oct 20 15:52:23 2003
@@ -47,18 +47,18 @@
 
 // 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 @@
     std::map<const BasicBlock*, unsigned>::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 NeedAnotherIteration = false;
   for (po_iterator<const Function*> 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 @@
     // 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 @@
 
 
 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 @@
 //-----------------------------------------------------------------------------
 
 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);





More information about the llvm-commits mailing list