[llvm-commits] [llvm] r62539 - in /llvm/trunk: include/llvm/CodeGen/SelectionDAG.h include/llvm/CodeGen/SelectionDAGNodes.h lib/CodeGen/SelectionDAG/SelectionDAG.cpp

Dan Gohman gohman at apple.com
Mon Jan 19 14:39:37 PST 2009


Author: djg
Date: Mon Jan 19 16:39:36 2009
New Revision: 62539

URL: http://llvm.org/viewvc/llvm-project?rev=62539&view=rev
Log:
Remove SDNode's virtual destructor. This makes it impossible for
SDNode subclasses to keep state that requires non-trivial
destructors, however it was already effectively impossible,
since the destructor isn't actually ever called. There currently
aren't any SDNode subclasses affected by this, and in general
it's desireable to keep SDNode objects light-weight.

This eliminates the last virtual member function in the SDNode
class, so it eliminates the need for a vtable pointer, making
SDNode smaller.

Modified:
    llvm/trunk/include/llvm/CodeGen/SelectionDAG.h
    llvm/trunk/include/llvm/CodeGen/SelectionDAGNodes.h
    llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp

Modified: llvm/trunk/include/llvm/CodeGen/SelectionDAG.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/SelectionDAG.h?rev=62539&r1=62538&r2=62539&view=diff

==============================================================================
--- llvm/trunk/include/llvm/CodeGen/SelectionDAG.h (original)
+++ llvm/trunk/include/llvm/CodeGen/SelectionDAG.h Mon Jan 19 16:39:36 2009
@@ -800,6 +800,7 @@
                                void *&InsertPos);
 
   void DeleteNodeNotInCSEMaps(SDNode *N);
+  void DeallocateNode(SDNode *N);
 
   unsigned getMVTAlignment(MVT MemoryVT) const;
 

Modified: llvm/trunk/include/llvm/CodeGen/SelectionDAGNodes.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/SelectionDAGNodes.h?rev=62539&r1=62538&r2=62539&view=diff

==============================================================================
--- llvm/trunk/include/llvm/CodeGen/SelectionDAGNodes.h (original)
+++ llvm/trunk/include/llvm/CodeGen/SelectionDAGNodes.h Mon Jan 19 16:39:36 2009
@@ -1119,14 +1119,7 @@
   /// addUse - add SDUse to the list of uses.
   void addUse(SDUse &U) { U.addToList(&Uses); }
 
-  // Out-of-line virtual method to give class a home.
-  virtual void ANCHOR();
 public:
-  virtual ~SDNode() {
-    assert(NumOperands == 0 && "Operand list not cleared before deletion");
-    NodeType = ISD::DELETED_NODE;
-  }
-  
   //===--------------------------------------------------------------------===//
   //  Accessors
   //
@@ -1470,7 +1463,6 @@
 /// UnarySDNode - This class is used for single-operand SDNodes.  This is solely
 /// to allow co-allocation of node operands with the node itself.
 class UnarySDNode : public SDNode {
-  virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
   SDUse Op;
 public:
   UnarySDNode(unsigned Opc, SDVTList VTs, SDValue X)
@@ -1483,7 +1475,6 @@
 /// BinarySDNode - This class is used for two-operand SDNodes.  This is solely
 /// to allow co-allocation of node operands with the node itself.
 class BinarySDNode : public SDNode {
-  virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
   SDUse Ops[2];
 public:
   BinarySDNode(unsigned Opc, SDVTList VTs, SDValue X, SDValue Y)
@@ -1497,7 +1488,6 @@
 /// TernarySDNode - This class is used for three-operand SDNodes. This is solely
 /// to allow co-allocation of node operands with the node itself.
 class TernarySDNode : public SDNode {
-  virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
   SDUse Ops[3];
 public:
   TernarySDNode(unsigned Opc, SDVTList VTs, SDValue X, SDValue Y,
@@ -1516,7 +1506,6 @@
 /// operand.  This node should be directly created by end-users and not added to
 /// the AllNodes list.
 class HandleSDNode : public SDNode {
-  virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
   SDUse Op;
 public:
   // FIXME: Remove the "noinline" attribute once <rdar://problem/5852746> is
@@ -1536,8 +1525,6 @@
 
 /// Abstact virtual class for operations for memory operations
 class MemSDNode : public SDNode {
-  virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
-
 private:
   // MemoryVT - VT of in-memory value.
   MVT MemoryVT;
@@ -1613,10 +1600,9 @@
 /// AtomicSDNode - A SDNode reprenting atomic operations.
 ///
 class AtomicSDNode : public MemSDNode {
-  virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
   SDUse Ops[4];
   
- public:
+public:
   // Opc:   opcode for atomic
   // VTL:    value type list
   // Chain:  memory chain for operaand
@@ -1678,7 +1664,6 @@
 /// memory and need an associated memory operand.
 ///
 class MemIntrinsicSDNode : public MemSDNode {
-  virtual void ANCHOR();  // Out-of-line virtual method to give class a home.  
   bool ReadMem;  // Intrinsic reads memory
   bool WriteMem; // Intrinsic writes memory
 public:
@@ -1706,7 +1691,6 @@
 
 class ConstantSDNode : public SDNode {
   const ConstantInt *Value;
-  virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
 protected:
   friend class SelectionDAG;
   ConstantSDNode(bool isTarget, const ConstantInt *val, MVT VT)
@@ -1732,7 +1716,6 @@
 
 class ConstantFPSDNode : public SDNode {
   const ConstantFP *Value;
-  virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
 protected:
   friend class SelectionDAG;
   ConstantFPSDNode(bool isTarget, const ConstantFP *val, MVT VT)
@@ -1776,7 +1759,6 @@
 class GlobalAddressSDNode : public SDNode {
   GlobalValue *TheGlobal;
   int64_t Offset;
-  virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
 protected:
   friend class SelectionDAG;
   GlobalAddressSDNode(bool isTarget, const GlobalValue *GA, MVT VT,
@@ -1797,7 +1779,6 @@
 
 class FrameIndexSDNode : public SDNode {
   int FI;
-  virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
 protected:
   friend class SelectionDAG;
   FrameIndexSDNode(int fi, MVT VT, bool isTarg)
@@ -1817,7 +1798,6 @@
 
 class JumpTableSDNode : public SDNode {
   int JTI;
-  virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
 protected:
   friend class SelectionDAG;
   JumpTableSDNode(int jti, MVT VT, bool isTarg)
@@ -1842,7 +1822,6 @@
   } Val;
   int Offset;  // It's a MachineConstantPoolValue if top bit is set.
   unsigned Alignment;
-  virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
 protected:
   friend class SelectionDAG;
   ConstantPoolSDNode(bool isTarget, Constant *c, MVT VT, int o=0)
@@ -1908,7 +1887,6 @@
 
 class BasicBlockSDNode : public SDNode {
   MachineBasicBlock *MBB;
-  virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
 protected:
   friend class SelectionDAG;
   explicit BasicBlockSDNode(MachineBasicBlock *mbb)
@@ -1934,7 +1912,6 @@
 ///
 class SrcValueSDNode : public SDNode {
   const Value *V;
-  virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
 protected:
   friend class SelectionDAG;
   /// Create a SrcValue for a general value.
@@ -1957,7 +1934,6 @@
 /// and ISD::STORE have been lowered.
 ///
 class MemOperandSDNode : public SDNode {
-  virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
 protected:
   friend class SelectionDAG;
   /// Create a MachineMemOperand node
@@ -1977,7 +1953,6 @@
 
 class RegisterSDNode : public SDNode {
   unsigned Reg;
-  virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
 protected:
   friend class SelectionDAG;
   RegisterSDNode(unsigned reg, MVT VT)
@@ -1998,7 +1973,6 @@
   unsigned Line;
   unsigned Column;
   Value *CU;
-  virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
 protected:
   friend class SelectionDAG;
   DbgStopPointSDNode(SDValue ch, unsigned l, unsigned c,
@@ -2022,7 +1996,6 @@
 class LabelSDNode : public SDNode {
   SDUse Chain;
   unsigned LabelID;
-  virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
 protected:
   friend class SelectionDAG;
   LabelSDNode(unsigned NodeTy, SDValue ch, unsigned id)
@@ -2042,7 +2015,6 @@
 
 class ExternalSymbolSDNode : public SDNode {
   const char *Symbol;
-  virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
 protected:
   friend class SelectionDAG;
   ExternalSymbolSDNode(bool isTarget, const char *Sym, MVT VT)
@@ -2062,7 +2034,6 @@
 
 class CondCodeSDNode : public SDNode {
   ISD::CondCode Condition;
-  virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
 protected:
   friend class SelectionDAG;
   explicit CondCodeSDNode(ISD::CondCode Cond)
@@ -2082,7 +2053,6 @@
 /// future and most targets don't support it.
 class CvtRndSatSDNode : public SDNode {
   ISD::CvtCode CvtCode;
-  virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
 protected:
   friend class SelectionDAG;
   explicit CvtRndSatSDNode(MVT VT, const SDValue *Ops, unsigned NumOps,
@@ -2187,7 +2157,6 @@
 /// ARG_FLAGSSDNode - Leaf node holding parameter flags.
 class ARG_FLAGSSDNode : public SDNode {
   ISD::ArgFlagsTy TheFlags;
-  virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
 protected:
   friend class SelectionDAG;
   explicit ARG_FLAGSSDNode(ISD::ArgFlagsTy Flags)
@@ -2211,7 +2180,6 @@
   // will expand the size of the representation.  At the moment we only
   // need Inreg.
   bool Inreg;
-  virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
 protected:
   friend class SelectionDAG;
   CallSDNode(unsigned cc, bool isvararg, bool istailcall, bool isinreg,
@@ -2256,7 +2224,6 @@
 /// to parameterize some operations.
 class VTSDNode : public SDNode {
   MVT ValueType;
-  virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
 protected:
   friend class SelectionDAG;
   explicit VTSDNode(MVT VT)
@@ -2323,7 +2290,6 @@
 /// LoadSDNode - This class is used to represent ISD::LOAD nodes.
 ///
 class LoadSDNode : public LSBaseSDNode {
-  virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
 protected:
   friend class SelectionDAG;
   LoadSDNode(SDValue *ChainPtrOff, SDVTList VTs,
@@ -2353,7 +2319,6 @@
 /// StoreSDNode - This class is used to represent ISD::STORE nodes.
 ///
 class StoreSDNode : public LSBaseSDNode {
-  virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
 protected:
   friend class SelectionDAG;
   StoreSDNode(SDValue *ChainValuePtrOff, SDVTList VTs,

Modified: llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp?rev=62539&r1=62538&r2=62539&view=diff

==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp Mon Jan 19 16:39:36 2009
@@ -557,14 +557,7 @@
         DeadNodes.push_back(Operand);
     }
 
-    if (N->OperandsNeedDelete)
-      delete[] N->OperandList;
-
-    N->OperandList = 0;
-    N->NumOperands = 0;
-    
-    // Finally, remove N itself.
-    NodeAllocator.Deallocate(AllNodes.remove(N));
+    DeallocateNode(N);
   }
 }
 
@@ -585,16 +578,23 @@
 }
 
 void SelectionDAG::DeleteNodeNotInCSEMaps(SDNode *N) {
+  assert(N != AllNodes.begin());
+
   // Drop all of the operands and decrement used node's use counts.
   for (SDNode::op_iterator I = N->op_begin(), E = N->op_end(); I != E; ++I)
     I->getVal()->removeUser(std::distance(N->op_begin(), I), N);
 
-  if (N->OperandsNeedDelete) {
+  DeallocateNode(N);
+}
+
+void SelectionDAG::DeallocateNode(SDNode *N) {
+  if (N->OperandsNeedDelete)
     delete[] N->OperandList;
-    N->OperandList = 0;
-  }
   
-  assert(N != AllNodes.begin());
+  // Set the opcode to DELETED_NODE to help catch bugs when node
+  // memory is reallocated.
+  N->NodeType = ISD::DELETED_NODE;
+
   NodeAllocator.Deallocate(AllNodes.remove(N));
 }
 
@@ -786,17 +786,8 @@
 void SelectionDAG::allnodes_clear() {
   assert(&*AllNodes.begin() == &EntryNode);
   AllNodes.remove(AllNodes.begin());
-  while (!AllNodes.empty()) {
-    SDNode *N = AllNodes.remove(AllNodes.begin());
-    N->SetNextInBucket(0);
-
-    if (N->OperandsNeedDelete) {
-      delete [] N->OperandList;
-      N->OperandList = 0;
-    }
-
-    NodeAllocator.Deallocate(N);
-  }
+  while (!AllNodes.empty())
+    DeallocateNode(AllNodes.begin());
 }
 
 void SelectionDAG::clear() {
@@ -4737,36 +4728,6 @@
 //                              SDNode Class
 //===----------------------------------------------------------------------===//
 
-// Out-of-line virtual method to give class a home.
-void SDNode::ANCHOR() {}
-void UnarySDNode::ANCHOR() {}
-void BinarySDNode::ANCHOR() {}
-void TernarySDNode::ANCHOR() {}
-void HandleSDNode::ANCHOR() {}
-void ConstantSDNode::ANCHOR() {}
-void ConstantFPSDNode::ANCHOR() {}
-void GlobalAddressSDNode::ANCHOR() {}
-void FrameIndexSDNode::ANCHOR() {}
-void JumpTableSDNode::ANCHOR() {}
-void ConstantPoolSDNode::ANCHOR() {}
-void BasicBlockSDNode::ANCHOR() {}
-void SrcValueSDNode::ANCHOR() {}
-void MemOperandSDNode::ANCHOR() {}
-void RegisterSDNode::ANCHOR() {}
-void DbgStopPointSDNode::ANCHOR() {}
-void LabelSDNode::ANCHOR() {}
-void ExternalSymbolSDNode::ANCHOR() {}
-void CondCodeSDNode::ANCHOR() {}
-void ARG_FLAGSSDNode::ANCHOR() {}
-void VTSDNode::ANCHOR() {}
-void MemSDNode::ANCHOR() {}
-void LoadSDNode::ANCHOR() {}
-void StoreSDNode::ANCHOR() {}
-void AtomicSDNode::ANCHOR() {}
-void MemIntrinsicSDNode::ANCHOR() {}
-void CallSDNode::ANCHOR() {}
-void CvtRndSatSDNode::ANCHOR() {}
-
 HandleSDNode::~HandleSDNode() {
   DropOperands();
 }





More information about the llvm-commits mailing list