Change MachineBasicBlock's to not be Annotations, instead they are kept as
authorChris Lattner <sabre@nondot.org>
Mon, 28 Oct 2002 05:30:46 +0000 (05:30 +0000)
committerChris Lattner <sabre@nondot.org>
Mon, 28 Oct 2002 05:30:46 +0000 (05:30 +0000)
part of a linked list tracked by MachineFunction.  MachineBasicBlock::get
is now linear time instead of constant time, and thus is deprecated!

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@4337 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/CodeGen/MachineBasicBlock.h
include/llvm/CodeGen/MachineFunction.h
lib/CodeGen/InstrSelection/InstrSelection.cpp
lib/CodeGen/MachineBasicBlock.cpp [deleted file]
lib/CodeGen/MachineFunction.cpp
lib/Target/SparcV9/InstrSelection/InstrSelection.cpp

index aa32a8110988819cccba23a48663f94f975fefec..dfa8e0d183ce3d8a400a274cbaf32c1a9ce3cc16 100644 (file)
@@ -7,31 +7,28 @@
 #ifndef LLVM_CODEGEN_MACHINEBASICBLOCK_H
 #define LLVM_CODEGEN_MACHINEBASICBLOCK_H
 
-#include "llvm/Annotation.h"
 #include <vector>
 class BasicBlock;
 class MachineInstr;
 template <typename T> struct ilist_traits;
 
-extern AnnotationID MCFBB_AID;
-
-class MachineBasicBlock : public Annotation {
+class MachineBasicBlock {
   std::vector<MachineInstr*> Insts;
   MachineBasicBlock *Prev, *Next;
+  BasicBlock *BB;
 public:
-  MachineBasicBlock() : Annotation(MCFBB_AID) {}
+  MachineBasicBlock(BasicBlock *bb = 0) : Prev(0), Next(0), BB(bb) {}
   ~MachineBasicBlock() {}
   
-  // Static methods to retrieve or destroy the MachineBasicBlock
-  // object for a given basic block.
-  static MachineBasicBlock& get(const BasicBlock *BB) {
-    return *(MachineBasicBlock*)
-      ((Annotable*)BB)->getOrCreateAnnotation(MCFBB_AID);
-  }
-  
-  static void destroy(const BasicBlock *BB) {
-    ((Annotable*)BB)->deleteAnnotation(MCFBB_AID);
-  }
+  // get - This deprecated static method returns the MachineBasicBlock object
+  // for the specified BasicBlock.
+  //
+  static MachineBasicBlock& get(const BasicBlock *BB);
+
+  /// getBasicBlock - Return the LLVM basic block that this instance
+  /// corresponded to originally.
+  ///
+  BasicBlock *getBasicBlock() const { return BB; }
   
   typedef std::vector<MachineInstr*>::iterator                iterator;
   typedef std::vector<MachineInstr*>::const_iterator    const_iterator;
index 131b0359f76e1b532af025e0c13a61d92b94ba4d..33f9efc281bce56b989f5adc38f0530aab63f5b5 100644 (file)
@@ -10,6 +10,7 @@
 #define LLVM_CODEGEN_MACHINEFUNCTION_H
 
 #include "llvm/CodeGen/MachineBasicBlock.h"
+#include "llvm/Annotation.h"
 #include "Support/NonCopyable.h"
 #include "Support/HashExtras.h"
 #include "Support/hash_set"
@@ -59,9 +60,38 @@ public:
   static MachineFunction& construct(const Function *method,
                                          const TargetMachine &target);
   static void destruct(const Function *F);
-  static MachineFunction& get(const Function* function);
-  
+  static MachineFunction& get(const Function *F);
+
+  // Provide accessors for the MachineBasicBlock list...
+  typedef iplist<MachineBasicBlock> BasicBlockListType;
+  typedef BasicBlockListType::iterator iterator;
+  typedef BasicBlockListType::const_iterator const_iterator;
+  typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
+  typedef std::reverse_iterator<iterator>             reverse_iterator;
+
+  // Provide accessors for basic blocks...
+  const BasicBlockListType &getBasicBlockList() const { return BasicBlocks; }
+        BasicBlockListType &getBasicBlockList()       { return BasicBlocks; }
+  //===--------------------------------------------------------------------===//
+  // BasicBlock iterator forwarding functions
+  //
+  iterator                 begin()       { return BasicBlocks.begin(); }
+  const_iterator           begin() const { return BasicBlocks.begin(); }
+  iterator                 end  ()       { return BasicBlocks.end();   }
+  const_iterator           end  () const { return BasicBlocks.end();   }
+
+  reverse_iterator        rbegin()       { return BasicBlocks.rbegin(); }
+  const_reverse_iterator  rbegin() const { return BasicBlocks.rbegin(); }
+  reverse_iterator        rend  ()       { return BasicBlocks.rend();   }
+  const_reverse_iterator  rend  () const { return BasicBlocks.rend();   }
 
+  unsigned                  size() const { return BasicBlocks.size(); }
+  bool                     empty() const { return BasicBlocks.empty(); }
+  const MachineBasicBlock &front() const { return BasicBlocks.front(); }
+        MachineBasicBlock &front()       { return BasicBlocks.front(); }
+  const MachineBasicBlock &back() const { return BasicBlocks.back(); }
+        MachineBasicBlock &back()       { return BasicBlocks.back(); }
 
   //===--------------------------------------------------------------------===//
   //
index 390b5da6796ec50a2a4fd0c3dcd637c2abad1aa9..677bef7d04ad14741819d5fcdae80f1a810379f1 100644 (file)
@@ -139,14 +139,20 @@ bool InstructionSelection::runOnFunction(Function &F)
     }
   
   //
-  // Record instructions in the vector for each basic block
+  // Create the MachineBasicBlock records and add all of the MachineInstrs
+  // defined in the MachineCodeForInstruction objects to also live in the
+  // MachineBasicBlock objects.
   // 
-  for (Function::iterator BI = F.begin(), BE = F.end(); BI != BE; ++BI)
+  MachineFunction &MF = MachineFunction::get(&F);
+  for (Function::iterator BI = F.begin(), BE = F.end(); BI != BE; ++BI) {
+    MachineBasicBlock *MCBB = new MachineBasicBlock(BI);
+    MF.getBasicBlockList().push_back(MCBB);
+
     for (BasicBlock::iterator II = BI->begin(); II != BI->end(); ++II) {
       MachineCodeForInstruction &mvec = MachineCodeForInstruction::get(II);
-      MachineBasicBlock &MCBB = MachineBasicBlock::get(BI);
-      MCBB.insert(MCBB.end(), mvec.begin(), mvec.end());
+      MCBB->insert(MCBB->end(), mvec.begin(), mvec.end());
     }
+  }
 
   // Insert phi elimination code
   InsertCodeForPhis(F);
diff --git a/lib/CodeGen/MachineBasicBlock.cpp b/lib/CodeGen/MachineBasicBlock.cpp
deleted file mode 100644 (file)
index 666d547..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-//===-- MachineBasicBlock.cpp ---------------------------------------------===//
-// 
-// Collect the sequence of machine instructions for a basic block.
-//
-//===----------------------------------------------------------------------===//
-
-#include "llvm/CodeGen/MachineBasicBlock.h"
-
-AnnotationID MCFBB_AID(
-             AnnotationManager::getID("CodeGen::MachineBasicBlock"));
-
-static Annotation *CreateMCFBB(AnnotationID AID, const Annotable *, void *) {
-  assert(AID == MCFBB_AID);
-  return new MachineBasicBlock();  // Invoke constructor!
-}
-
-// Register the annotation with the annotation factory
-static struct MCFBBInitializer {
-  MCFBBInitializer() {
-    AnnotationManager::registerAnnotationFactory(MCFBB_AID, &CreateMCFBB);
-  }
-} RegisterCreateMCFBB;
-
index b9c017a4591b267e2e8e06d2fbf3d917980b12d0..15036a4d077ed9531910bf69fb0fb237a26be9d4 100644 (file)
@@ -72,6 +72,21 @@ Pass *createMachineCodeDestructionPass() {
 }
 
 
+// get - This deprecated static method returns the MachineBasicBlock object
+// for the specified BasicBlock.
+//
+MachineBasicBlock& MachineBasicBlock::get(const BasicBlock *BB) {
+  const Function *F = BB->getParent();
+  MachineFunction &MF = MachineFunction::get(F);
+
+  for (MachineFunction::iterator I = MF.begin(), E = MF.end(); I != E; ++I)
+    if (I->getBasicBlock() == BB)
+      return *I;
+  assert(0 && "MachineBasicBlock object not found for specified block!");
+  return get(BB);
+}
+
+
 //===---------------------------------------------------------------------===//
 // MachineFunction implementation
 //===---------------------------------------------------------------------===//
index 390b5da6796ec50a2a4fd0c3dcd637c2abad1aa9..677bef7d04ad14741819d5fcdae80f1a810379f1 100644 (file)
@@ -139,14 +139,20 @@ bool InstructionSelection::runOnFunction(Function &F)
     }
   
   //
-  // Record instructions in the vector for each basic block
+  // Create the MachineBasicBlock records and add all of the MachineInstrs
+  // defined in the MachineCodeForInstruction objects to also live in the
+  // MachineBasicBlock objects.
   // 
-  for (Function::iterator BI = F.begin(), BE = F.end(); BI != BE; ++BI)
+  MachineFunction &MF = MachineFunction::get(&F);
+  for (Function::iterator BI = F.begin(), BE = F.end(); BI != BE; ++BI) {
+    MachineBasicBlock *MCBB = new MachineBasicBlock(BI);
+    MF.getBasicBlockList().push_back(MCBB);
+
     for (BasicBlock::iterator II = BI->begin(); II != BI->end(); ++II) {
       MachineCodeForInstruction &mvec = MachineCodeForInstruction::get(II);
-      MachineBasicBlock &MCBB = MachineBasicBlock::get(BI);
-      MCBB.insert(MCBB.end(), mvec.begin(), mvec.end());
+      MCBB->insert(MCBB->end(), mvec.begin(), mvec.end());
     }
+  }
 
   // Insert phi elimination code
   InsertCodeForPhis(F);