Add parent pointer to MachineInstr that points to owning
authorAlkis Evlogimenos <alkis@evlogimenos.com>
Thu, 12 Feb 2004 18:49:07 +0000 (18:49 +0000)
committerAlkis Evlogimenos <alkis@evlogimenos.com>
Thu, 12 Feb 2004 18:49:07 +0000 (18:49 +0000)
MachineBasicBlock. Also change opcode to a short and numImplicitRefs
to an unsigned char so that overall MachineInstr's size stays the
same.

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

include/llvm/CodeGen/MachineBasicBlock.h
include/llvm/CodeGen/MachineInstr.h
include/llvm/Target/TargetInstrInfo.h
lib/CodeGen/MachineInstr.cpp

index 7285057210919d0141f917c534b3c6b588376ca4..94409c5ef4c6cb41a08e87bf9f399c32d59ffd2a 100644 (file)
@@ -15,7 +15,6 @@
 #define LLVM_CODEGEN_MACHINEBASICBLOCK_H
 
 #include "llvm/CodeGen/MachineInstr.h"
-#include "Support/ilist"
 
 namespace llvm {
 
@@ -28,7 +27,9 @@ public:
   MachineBasicBlock *Prev, *Next;
   const BasicBlock *BB;
 public:
-  MachineBasicBlock(const BasicBlock *bb = 0) : Prev(0), Next(0), BB(bb) {}
+  MachineBasicBlock(const BasicBlock *bb = 0) : Prev(0), Next(0), BB(bb) {
+    Insts.parent = this;
+  }
   ~MachineBasicBlock() {}
   
   /// getBasicBlock - Return the LLVM basic block that this instance
index 52c6085a8493fb6879ac9735727e4ffc39702eb4..8f010917c6caf2ac5319b4b5781d57e0c22576b6 100644 (file)
@@ -17,7 +17,7 @@
 #define LLVM_CODEGEN_MACHINEINSTR_H
 
 #include "Support/Annotation.h"
-#include "Support/iterator"
+#include "Support/ilist"
 #include <vector>
 
 namespace llvm {
@@ -29,8 +29,9 @@ class TargetMachine;
 class GlobalValue;
 
 template <typename T> class ilist_traits;
+template <typename T> class ilist;
 
-typedef int MachineOpCode;
+typedef short MachineOpCode;
 
 //===----------------------------------------------------------------------===//
 /// MOTy - MachineOperandType - This namespace contains an enum that describes
@@ -332,10 +333,11 @@ private:
 //===----------------------------------------------------------------------===//
 
 class MachineInstr {
-  int              Opcode;              // the opcode
+  short            Opcode;              // the opcode
+  unsigned char numImplicitRefs;        // number of implicit operands
   std::vector<MachineOperand> operands; // the operands
-  unsigned numImplicitRefs;             // number of implicit operands
   MachineInstr* prev, *next;            // links for our intrusive list
+  MachineBasicBlock* parent;            // pointer to the owning basic block
   // OperandComplete - Return true if it's illegal to add a new operand
   bool OperandsComplete() const;
 
@@ -346,29 +348,26 @@ private:
   // Intrusive list support
   //
   friend class ilist_traits<MachineInstr>;
-  MachineInstr() { /* this is for ilist use only to create the sentinel */ }
-  MachineInstr* getPrev() const { return prev; }
-  MachineInstr* getNext() const { return next; }
-
-  void setPrev(MachineInstr* mi) { prev = mi; }
-  void setNext(MachineInstr* mi) { next = mi; }
 
 public:
-  MachineInstr(int Opcode, unsigned numOperands);
+  MachineInstr(short Opcode, unsigned numOperands);
 
   /// MachineInstr ctor - This constructor only does a _reserve_ of the
   /// operands, not a resize for them.  It is expected that if you use this that
   /// you call add* methods below to fill up the operands, instead of the Set
   /// methods.  Eventually, the "resizing" ctors will be phased out.
   ///
-  MachineInstr(int Opcode, unsigned numOperands, bool XX, bool YY);
+  MachineInstr(short Opcode, unsigned numOperands, bool XX, bool YY);
 
   /// MachineInstr ctor - Work exactly the same as the ctor above, except that
   /// the MachineInstr is created and added to the end of the specified basic
   /// block.
   ///
-  MachineInstr(MachineBasicBlock *MBB, int Opcode, unsigned numOps);
+  MachineInstr(MachineBasicBlock *MBB, short Opcode, unsigned numOps);
   
+  const MachineBasicBlock* getParent() const { return parent; }
+  MachineBasicBlock* getParent() { return parent; }
+
   /// Accessors for opcode.
   ///
   const int getOpcode() const { return Opcode; }
@@ -587,7 +586,7 @@ public:
   /// simply replace() and then set new operands with Set.*Operand methods
   /// below.
   /// 
-  void replace(int Opcode, unsigned numOperands);
+  void replace(short Opcode, unsigned numOperands);
 
   /// setOpcode - Replace the opcode of the current instruction with a new one.
   ///
@@ -695,6 +694,51 @@ public:
   }
 };
 
+// ilist_traits
+template <>
+class ilist_traits<MachineInstr>
+{
+  typedef ilist_traits<MachineInstr> self;
+
+  // this is only set by the MachineBasicBlock owning the ilist
+  friend class MachineBasicBlock;
+  MachineBasicBlock* parent;
+
+public:
+  ilist_traits<MachineInstr>() : parent(0) { }
+
+  static MachineInstr* getPrev(MachineInstr* N) { return N->prev; }
+  static MachineInstr* getNext(MachineInstr* N) { return N->next; }
+
+  static const MachineInstr*
+  getPrev(const MachineInstr* N) { return N->prev; }
+
+  static const MachineInstr*
+  getNext(const MachineInstr* N) { return N->next; }
+
+  static void setPrev(MachineInstr* N, MachineInstr* prev) { N->prev = prev; }
+  static void setNext(MachineInstr* N, MachineInstr* next) { N->next = next; }
+
+  static MachineInstr* createNode() { return new MachineInstr(0, 0); }
+
+  void addNodeToList(MachineInstr* N) {
+    assert(N->parent == 0 && "machine instruction already in a basic block");
+    N->parent = parent;
+  }
+
+  void removeNodeFromList(MachineInstr* N) {
+    assert(N->parent != 0 && "machine instruction not in a basic block");
+    N->parent = 0;
+  }
+
+  void transferNodesFromList(iplist<MachineInstr, self>& toList,
+                             ilist_iterator<MachineInstr> first,
+                             ilist_iterator<MachineInstr> last) {
+    if (parent != toList.parent)
+      for (; first != last; ++first)
+          first->parent = toList.parent;
+  }
+};
 
 //===----------------------------------------------------------------------===//
 // Debugging Support
index 963c2d36bb318d443b7d6747e98b47ce0f621ed6..4db5416b46567375c03f5882e470d18c868c8ac3 100644 (file)
@@ -33,7 +33,7 @@ class MachineCodeForInstruction;
 // Data types used to define information about a single machine instruction
 //---------------------------------------------------------------------------
 
-typedef int MachineOpCode;
+typedef short MachineOpCode;
 typedef unsigned InstrSchedClass;
 
 const MachineOpCode INVALID_MACHINE_OPCODE = -1;
index f9902659b0797c9eb2b0f525af34bed619eccf30..cbc0af91cea7b1f52f9ee238490a2cb3bdd5b1a5 100644 (file)
@@ -28,8 +28,11 @@ namespace llvm {
 extern const TargetInstrDescriptor *TargetInstrDescriptors;
 
 // Constructor for instructions with variable #operands
-MachineInstr::MachineInstr(MachineOpCode opcode, unsigned  numOperands)
-  : Opcode(opcode), operands(numOperands, MachineOperand()), numImplicitRefs(0){
+MachineInstr::MachineInstr(short opcode, unsigned numOperands)
+  : Opcode(opcode),
+    numImplicitRefs(0),
+    operands(numOperands, MachineOperand()),
+    parent(0) {
 }
 
 /// MachineInstr ctor - This constructor only does a _reserve_ of the operands,
@@ -37,18 +40,22 @@ MachineInstr::MachineInstr(MachineOpCode opcode, unsigned  numOperands)
 /// add* methods below to fill up the operands, instead of the Set methods.
 /// Eventually, the "resizing" ctors will be phased out.
 ///
-MachineInstr::MachineInstr(MachineOpCode opcode, unsigned numOperands,
+MachineInstr::MachineInstr(short opcode, unsigned numOperands,
                            bool XX, bool YY)
-  : Opcode(opcode), numImplicitRefs(0) {
+  : Opcode(opcode),
+    numImplicitRefs(0),
+    parent(0) {
   operands.reserve(numOperands);
 }
 
 /// MachineInstr ctor - Work exactly the same as the ctor above, except that the
 /// MachineInstr is created and added to the end of the specified basic block.
 ///
-MachineInstr::MachineInstr(MachineBasicBlock *MBB, MachineOpCode opcode,
+MachineInstr::MachineInstr(MachineBasicBlock *MBB, short opcode,
                            unsigned numOperands)
-  : Opcode(opcode), numImplicitRefs(0) {
+  : Opcode(opcode),
+    numImplicitRefs(0),
+    parent(0) {
   assert(MBB && "Cannot use inserting ctor with null basic block!");
   operands.reserve(numOperands);
   MBB->push_back(this);  // Add instruction to end of basic block!
@@ -69,7 +76,7 @@ bool MachineInstr::OperandsComplete() const {
 // This only resets the size of the operand vector and initializes it.
 // The new operands must be set explicitly later.
 // 
-void MachineInstr::replace(MachineOpCode opcode, unsigned numOperands) {
+void MachineInstr::replace(short opcode, unsigned numOperands) {
   assert(getNumImplicitRefs() == 0 &&
          "This is probably broken because implicit refs are going to be lost.");
   Opcode = opcode;