* Add a nice utility method to DSNode
authorChris Lattner <sabre@nondot.org>
Wed, 27 Mar 2002 19:41:45 +0000 (19:41 +0000)
committerChris Lattner <sabre@nondot.org>
Wed, 27 Mar 2002 19:41:45 +0000 (19:41 +0000)
* Export interface to tell whether an alloc node represent a malloc or alloca
* Add the concept of a "critical" shadow node

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

include/llvm/Analysis/DataStructure.h
include/llvm/Analysis/DataStructure/DataStructure.h

index 55029b26945e9317d36a2c0aa49e2e8051a0f492..73cc19f3f0a5e3753c8a7db79d789858b1af0101 100644 (file)
@@ -128,6 +128,10 @@ public:
   void removeReferrer(PointerValSet *PVS);
   const std::vector<PointerValSet*> &getReferrers() const { return Referrers; }
 
+  // removeAllIncomingEdges - Erase all edges in the graph that point to
+  // this node
+  void removeAllIncomingEdges();
+
   void addPointer(Value *V) { Pointers.push_back(V); }
   const std::vector<Value*> &getPointers() const { return Pointers; }
 
@@ -170,6 +174,9 @@ public:
 
   virtual std::string getCaption() const;
 
+  bool isAllocaNode() const;
+  bool isMallocNode() const { return !isAllocaNode(); }
+
   // Support type inquiry through isa, cast, and dyn_cast...
   static bool classof(const NewDSNode *) { return true; }
   static bool classof(const DSNode *N) { return N->NodeType == NewNode; }
@@ -256,14 +263,22 @@ private:
 // to.  When functions are integrated into each other, shadow nodes are
 // resolved.
 //
+// Shadow nodes may be marked as "critical" nodes when they are created.  This
+// mark indicates that the node is the result of a function call, the value
+// pointed to by an incoming argument, or the value pointed to by a global
+// variable [fixme todo].  Since it is not possible to know what these nodes
+// point to, given just the current context, they are marked "Critical" to avoid
+// having the shadow node merger eliminate them.
+//
 class ShadowDSNode : public DSNode {
   friend class FunctionDSGraph;
   DSNode *Parent;
   Module *Mod;
   ShadowDSNode *ShadowParent;   // Nonnull if this is a synthesized node...
   std::vector<std::pair<const Type *, ShadowDSNode *> > SynthNodes;
+  bool CriticalNode;
 public:
-  ShadowDSNode(DSNode *Parent, Module *M);
+  ShadowDSNode(DSNode *Parent, Module *M, bool Critical = false);
   virtual std::string getCaption() const;
 
   // synthesizeNode - Create a new shadow node that is to be linked into this
@@ -271,6 +286,9 @@ public:
   //
   ShadowDSNode *synthesizeNode(const Type *Ty, FunctionRepBuilder *Rep);
 
+  bool isCriticalNode() const { return CriticalNode; }
+  void resetCriticalMark() { CriticalNode = false; }
+
   // Support type inquiry through isa, cast, and dyn_cast...
   static bool classof(const ShadowDSNode *) { return true; }
   static bool classof(const DSNode *N) { return N->NodeType == ShadowNode; }
@@ -284,7 +302,7 @@ protected:
     if (ShadowParent)
       return new ShadowDSNode(getType(), Mod, ShadowParent);
     else
-      return new ShadowDSNode(Parent, Mod);
+      return new ShadowDSNode(Parent, Mod, CriticalNode);
   }
 };
 
index 55029b26945e9317d36a2c0aa49e2e8051a0f492..73cc19f3f0a5e3753c8a7db79d789858b1af0101 100644 (file)
@@ -128,6 +128,10 @@ public:
   void removeReferrer(PointerValSet *PVS);
   const std::vector<PointerValSet*> &getReferrers() const { return Referrers; }
 
+  // removeAllIncomingEdges - Erase all edges in the graph that point to
+  // this node
+  void removeAllIncomingEdges();
+
   void addPointer(Value *V) { Pointers.push_back(V); }
   const std::vector<Value*> &getPointers() const { return Pointers; }
 
@@ -170,6 +174,9 @@ public:
 
   virtual std::string getCaption() const;
 
+  bool isAllocaNode() const;
+  bool isMallocNode() const { return !isAllocaNode(); }
+
   // Support type inquiry through isa, cast, and dyn_cast...
   static bool classof(const NewDSNode *) { return true; }
   static bool classof(const DSNode *N) { return N->NodeType == NewNode; }
@@ -256,14 +263,22 @@ private:
 // to.  When functions are integrated into each other, shadow nodes are
 // resolved.
 //
+// Shadow nodes may be marked as "critical" nodes when they are created.  This
+// mark indicates that the node is the result of a function call, the value
+// pointed to by an incoming argument, or the value pointed to by a global
+// variable [fixme todo].  Since it is not possible to know what these nodes
+// point to, given just the current context, they are marked "Critical" to avoid
+// having the shadow node merger eliminate them.
+//
 class ShadowDSNode : public DSNode {
   friend class FunctionDSGraph;
   DSNode *Parent;
   Module *Mod;
   ShadowDSNode *ShadowParent;   // Nonnull if this is a synthesized node...
   std::vector<std::pair<const Type *, ShadowDSNode *> > SynthNodes;
+  bool CriticalNode;
 public:
-  ShadowDSNode(DSNode *Parent, Module *M);
+  ShadowDSNode(DSNode *Parent, Module *M, bool Critical = false);
   virtual std::string getCaption() const;
 
   // synthesizeNode - Create a new shadow node that is to be linked into this
@@ -271,6 +286,9 @@ public:
   //
   ShadowDSNode *synthesizeNode(const Type *Ty, FunctionRepBuilder *Rep);
 
+  bool isCriticalNode() const { return CriticalNode; }
+  void resetCriticalMark() { CriticalNode = false; }
+
   // Support type inquiry through isa, cast, and dyn_cast...
   static bool classof(const ShadowDSNode *) { return true; }
   static bool classof(const DSNode *N) { return N->NodeType == ShadowNode; }
@@ -284,7 +302,7 @@ protected:
     if (ShadowParent)
       return new ShadowDSNode(getType(), Mod, ShadowParent);
     else
-      return new ShadowDSNode(Parent, Mod);
+      return new ShadowDSNode(Parent, Mod, CriticalNode);
   }
 };