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

Chris Lattner lattner at cs.uiuc.edu
Mon Oct 28 12:02:00 PST 2002


Changes in directory llvm/lib/Analysis/LiveVar:

BBLiveVar.cpp updated: 1.29 -> 1.30
BBLiveVar.h updated: 1.16 -> 1.17
FunctionLiveVarInfo.cpp updated: 1.40 -> 1.41

---
Log message:

Eliminate uses of MachineBasicBlock::get


---
Diffs of the changes:

Index: llvm/lib/Analysis/LiveVar/BBLiveVar.cpp
diff -u llvm/lib/Analysis/LiveVar/BBLiveVar.cpp:1.29 llvm/lib/Analysis/LiveVar/BBLiveVar.cpp:1.30
--- llvm/lib/Analysis/LiveVar/BBLiveVar.cpp:1.29	Sun Oct 27 19:40:34 2002
+++ llvm/lib/Analysis/LiveVar/BBLiveVar.cpp	Mon Oct 28 12:01:21 2002
@@ -18,8 +18,9 @@
 
 static AnnotationID AID(AnnotationManager::getID("Analysis::BBLiveVar"));
 
-BBLiveVar *BBLiveVar::CreateOnBB(const BasicBlock &BB, unsigned POID) {
-  BBLiveVar *Result = new BBLiveVar(BB, POID);
+BBLiveVar *BBLiveVar::CreateOnBB(const BasicBlock &BB, MachineBasicBlock &MBB,
+                                 unsigned POID) {
+  BBLiveVar *Result = new BBLiveVar(BB, MBB, POID);
   BB.addAnnotation(Result);
   return Result;
 }
@@ -34,8 +35,8 @@
 }
 
 
-BBLiveVar::BBLiveVar(const BasicBlock &bb, unsigned id)
-  : Annotation(AID), BB(bb), POID(id) {
+BBLiveVar::BBLiveVar(const BasicBlock &bb, MachineBasicBlock &mbb, unsigned id)
+  : Annotation(AID), BB(bb), MBB(mbb), POID(id) {
   InSetChanged = OutSetChanged = false;
 
   calcDefUseSets();
@@ -49,15 +50,12 @@
 //-----------------------------------------------------------------------------
 
 void BBLiveVar::calcDefUseSets() {
-  // get the iterator for machine instructions
-  const MachineBasicBlock &MIVec = MachineBasicBlock::get(&BB);
-
   // iterate over all the machine instructions in BB
-  for (MachineBasicBlock::const_reverse_iterator MII = MIVec.rbegin(),
-         MIE = MIVec.rend(); MII != MIE; ++MII) {
+  for (MachineBasicBlock::const_reverse_iterator MII = MBB.rbegin(),
+         MIE = MBB.rend(); MII != MIE; ++MII) {
     const MachineInstr *MI = *MII;
     
-    if (DEBUG_LV >= LV_DEBUG_Verbose) {                            // debug msg
+    if (DEBUG_LV >= LV_DEBUG_Verbose) {
       cerr << " *Iterating over machine instr ";
       MI->dump();
       cerr << "\n";


Index: llvm/lib/Analysis/LiveVar/BBLiveVar.h
diff -u llvm/lib/Analysis/LiveVar/BBLiveVar.h:1.16 llvm/lib/Analysis/LiveVar/BBLiveVar.h:1.17
--- llvm/lib/Analysis/LiveVar/BBLiveVar.h:1.16	Tue Jun 25 11:11:43 2002
+++ llvm/lib/Analysis/LiveVar/BBLiveVar.h	Mon Oct 28 12:01:21 2002
@@ -13,6 +13,7 @@
 #include <map>
 class BasicBlock;
 class Value;
+class MachineBasicBlock;
 
 enum LiveVarDebugLevel_t {
   LV_DEBUG_None,
@@ -25,9 +26,10 @@
 
 class BBLiveVar : public Annotation {
   const BasicBlock &BB;         // pointer to BasicBlock
+  MachineBasicBlock &MBB;       // Pointer to MachineBasicBlock
   unsigned POID;                // Post-Order ID
 
-  ValueSet DefSet;              // Def set (with no preceding uses) for LV analysis
+  ValueSet DefSet;           // Def set (with no preceding uses) for LV analysis
   ValueSet InSet, OutSet;       // In & Out for LV analysis
   bool InSetChanged, OutSetChanged;   // set if the InSet/OutSet is modified
 
@@ -49,15 +51,18 @@
 
   void calcDefUseSets();         // calculates the Def & Use sets for this BB
 
-  BBLiveVar(const BasicBlock &BB, unsigned POID);
+  BBLiveVar(const BasicBlock &BB, MachineBasicBlock &MBB, unsigned POID);
   ~BBLiveVar() {}                // make dtor private
  public:
-  static BBLiveVar *CreateOnBB(const BasicBlock &BB, unsigned POID);
+  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; }
+
+  MachineBasicBlock &getMachineBasicBlock() const { return MBB; }
 
   inline unsigned getPOId() const { return POID; }
 


Index: llvm/lib/Analysis/LiveVar/FunctionLiveVarInfo.cpp
diff -u llvm/lib/Analysis/LiveVar/FunctionLiveVarInfo.cpp:1.40 llvm/lib/Analysis/LiveVar/FunctionLiveVarInfo.cpp:1.41
--- llvm/lib/Analysis/LiveVar/FunctionLiveVarInfo.cpp:1.40	Sun Oct 27 19:40:34 2002
+++ llvm/lib/Analysis/LiveVar/FunctionLiveVarInfo.cpp	Mon Oct 28 12:01:21 2002
@@ -8,7 +8,7 @@
 #include "llvm/Analysis/LiveVar/FunctionLiveVarInfo.h"
 #include "BBLiveVar.h"
 #include "llvm/CodeGen/MachineInstr.h"
-#include "llvm/CodeGen/MachineBasicBlock.h"
+#include "llvm/CodeGen/MachineFunction.h"
 #include "llvm/Support/CFG.h"
 #include "Support/PostOrderIterator.h"
 #include "Support/SetOperations.h"
@@ -71,31 +71,36 @@
 // constructs BBLiveVars and init Def and In sets
 //-----------------------------------------------------------------------------
 
-void FunctionLiveVarInfo::constructBBs(const Function *M) {
-  unsigned int POId = 0;                // Reverse Depth-first Order ID
-  
-  for(po_iterator<const Function*> BBI = po_begin(M), BBE = po_end(M);
-      BBI != BBE; ++BBI, ++POId) { 
-    const BasicBlock &BB = **BBI;        // get the current BB 
+void FunctionLiveVarInfo::constructBBs(const Function *F) {
+  unsigned POId = 0;                // Reverse Depth-first Order ID
+  std::map<const BasicBlock*, unsigned> PONumbering;
+
+  for (po_iterator<const Function*> BBI = po_begin(M), BBE = po_end(M);
+      BBI != BBE; ++BBI)
+    PONumbering[*BBI] = POId++;
 
+  MachineFunction &MF = MachineFunction::get(F);
+  for (MachineFunction::iterator I = MF.begin(), E = MF.end(); I != E; ++I) {
+    const BasicBlock &BB = *I->getBasicBlock();        // get the current BB 
     if (DEBUG_LV) std::cerr << " For BB " << RAV(BB) << ":\n";
 
-    // create a new BBLiveVar
-    BBLiveVar *LVBB = BBLiveVar::CreateOnBB(BB, POId);  
+    BBLiveVar *LVBB;
+    std::map<const BasicBlock*, unsigned>::iterator POI = PONumbering.find(&BB);
+    if (POI != PONumbering.end()) {
+      // create a new BBLiveVar
+      LVBB = BBLiveVar::CreateOnBB(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);
+    }
     
     if (DEBUG_LV)
       LVBB->printAllSets();
   }
-
-  // Since the PO iterator does not discover unreachable blocks,
-  // go over the random iterator and init those blocks as well.
-  // However, LV info is not correct for those blocks (they are not
-  // analyzed)
-  //
-  for (Function::const_iterator BBRI = M->begin(), BBRE = M->end();
-       BBRI != BBRE; ++BBRI, ++POId)
-    if (!BBLiveVar::GetFromBB(*BBRI))                 // Not yet processed?
-      BBLiveVar::CreateOnBB(*BBRI, POId);
 }
 
 
@@ -240,7 +245,9 @@
 //-----------------------------------------------------------------------------
 
 void FunctionLiveVarInfo::calcLiveVarSetsForBB(const BasicBlock *BB) {
-  const MachineBasicBlock &MIVec = MachineBasicBlock::get(BB);
+  BBLiveVar *BBLV = BBLiveVar::GetFromBB(*BB);
+  assert(BBLV && "BBLiveVar annotation doesn't exist?");
+  const MachineBasicBlock &MIVec = BBLV->getMachineBasicBlock();
 
   if (DEBUG_LV >= LV_DEBUG_Instr)
     std::cerr << "\n======For BB " << BB->getName()





More information about the llvm-commits mailing list