Constness changes
[oota-llvm.git] / include / llvm / Analysis / DataStructure / DSNode.h
index c7edc5547e9b2ad286a697915c46de3e7508cc4b..7d91918dba11d392c83b8b095308f7eb99645720 100644 (file)
@@ -8,6 +8,7 @@
 #define LLVM_ANALYSIS_DSNODE_H
 
 #include "llvm/Analysis/DSSupport.h"
+
 template<typename BaseType>
 class DSNodeIterator;          // Data structure graph traversal iterator
 
@@ -67,24 +68,27 @@ public:
     GlobalNode  = 1 << 2,   // This node was allocated by a global var decl
     UnknownNode = 1 << 3,   // This node points to unknown allocated memory 
     Incomplete  = 1 << 4,   // This node may not be complete
+
     Modified    = 1 << 5,   // This node is modified in this context
     Read        = 1 << 6,   // This node is read in this context
+
     Array       = 1 << 7,   // This node is treated like an array
-#if 1
+    //#ifndef NDEBUG
     DEAD        = 1 << 8,   // This node is dead and should not be pointed to
-#endif
+    //#endif
 
     Composition = AllocaNode | HeapNode | GlobalNode | UnknownNode,
   };
   
   /// NodeType - A union of the above bits.  "Shadow" nodes do not add any flags
   /// to the nodes in the data structure graph, so it is possible to have nodes
-  /// with a value of 0 for their NodeType.  Scalar and Alloca markers go away
-  /// when function graphs are inlined.
+  /// with a value of 0 for their NodeType.
   ///
+private:
   unsigned short NodeType;
+public:
 
-  DSNode(unsigned NodeTy, const Type *T, DSGraph *G);
+  DSNode(const Type *T, DSGraph *G);
   DSNode(const DSNode &, DSGraph *G);
 
   ~DSNode() {
@@ -120,14 +124,6 @@ public:
   /// return the number of nodes forwarding over the node!
   unsigned getNumReferrers() const { return NumReferrers; }
 
-  /// isModified - Return true if this node may be modified in this context
-  ///
-  bool isModified() const { return (NodeType & Modified) != 0; }
-
-  /// isRead - Return true if this node may be read in this context
-  ///
-  bool isRead() const { return (NodeType & Read) != 0; }
-
   DSGraph *getParentGraph() const { return ParentGraph; }
   void setParentGraph(DSGraph *G) { ParentGraph = G; }
 
@@ -181,7 +177,8 @@ public:
   /// This method returns true if the node is completely folded, otherwise
   /// false.
   ///
-  bool mergeTypeInfo(const Type *Ty, unsigned Offset);
+  bool mergeTypeInfo(const Type *Ty, unsigned Offset,
+                     bool FoldIfIncompatible = true);
 
   /// foldNodeCompletely - If we determine that this node has some funny
   /// behavior happening to it that we cannot represent, we fold it down to a
@@ -231,7 +228,43 @@ public:
   ///
   void addGlobal(GlobalValue *GV);
   const std::vector<GlobalValue*> &getGlobals() const { return Globals; }
-  std::vector<GlobalValue*> &getGlobals() { return Globals; }
+
+  /// maskNodeTypes - Apply a mask to the node types bitfield.
+  ///
+  void maskNodeTypes(unsigned Mask) {
+    NodeType &= Mask;
+  }
+
+  /// getNodeFlags - Return all of the flags set on the node.  If the DEAD flag
+  /// is set, hide it from the caller.
+  unsigned getNodeFlags() const { return NodeType & ~DEAD; }
+
+  bool isAllocaNode()  const { return NodeType & AllocaNode; }
+  bool isHeapNode()    const { return NodeType & HeapNode; }
+  bool isGlobalNode()  const { return NodeType & GlobalNode; }
+  bool isUnknownNode() const { return NodeType & UnknownNode; }
+
+  bool isModified() const   { return NodeType & Modified; }
+  bool isRead() const       { return NodeType & Read; }
+
+  bool isIncomplete() const { return NodeType & Incomplete; }
+  bool isComplete() const   { return !isIncomplete(); }
+  bool isDeadNode() const   { return NodeType & DEAD; }
+
+  DSNode *setAllocaNodeMarker()  { NodeType |= AllocaNode;  return this; }
+  DSNode *setHeapNodeMarker()    { NodeType |= HeapNode;    return this; }
+  DSNode *setGlobalNodeMarker()  { NodeType |= GlobalNode;  return this; }
+  DSNode *setUnknownNodeMarker() { NodeType |= UnknownNode; return this; }
+
+  DSNode *setIncompleteMarker() { NodeType |= Incomplete; return this; }
+  DSNode *setModifiedMarker()   { NodeType |= Modified;   return this; }
+  DSNode *setReadMarker()       { NodeType |= Read;       return this; }
+
+  void makeNodeDead() {
+    Globals.clear();
+    assert(hasNoReferrers() && "Dead node shouldn't have refs!");
+    NodeType = DEAD;
+  }
 
   /// forwardNode - Mark this node as being obsolete, and all references to it
   /// should be forwarded to the specified node and offset.
@@ -276,22 +309,7 @@ inline DSNode *DSNodeHandle::getNode() const {
   if (!N || N->ForwardNH.isNull())
     return N;
 
-  // Handle node forwarding here!
-  DSNode *Next = N->ForwardNH.getNode();  // Cause recursive shrinkage
-  Offset += N->ForwardNH.getOffset();
-
-  if (--N->NumReferrers == 0) {
-    // Removing the last referrer to the node, sever the forwarding link
-    N->stopForwarding();
-  }
-
-  N = Next;
-  N->NumReferrers++;
-  if (N->Size <= Offset) {
-    assert(N->Size <= 1 && "Forwarded to shrunk but not collapsed node?");
-    Offset = 0;
-  }
-  return N;
+  return HandleForwarding();
 }
 
 inline void DSNodeHandle::setNode(DSNode *n) {
@@ -307,7 +325,6 @@ inline void DSNodeHandle::setNode(DSNode *n) {
     }
   }
   assert(!N || ((N->NodeType & DSNode::DEAD) == 0));
-
   assert((!N || Offset < N->Size || (N->Size == 0 && Offset == 0) ||
           !N->ForwardNH.isNull()) && "Node handle offset out of range!");
 }