* Define some operators on PointerVal and PVS's
authorChris Lattner <sabre@nondot.org>
Thu, 28 Mar 2002 17:48:41 +0000 (17:48 +0000)
committerChris Lattner <sabre@nondot.org>
Thu, 28 Mar 2002 17:48:41 +0000 (17:48 +0000)
* Nodes can determine whether they are foldable with another node
* Rename NewDSNode to AllocDSNode
* The Function graph breaks up all of the node types into individual
  vectors to alloc fast access when you are looking for a particular type
  of node.  Simplifies much code.

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

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

index 73cc19f3f0a5e3753c8a7db79d789858b1af0101..5132208277e2ebf2c4962c01722186a4e18bff05 100644 (file)
@@ -40,6 +40,11 @@ public:
   inline bool operator==(DSNode *N) const { return Node == N; }
   inline bool operator!=(DSNode *N) const { return Node != N; }
 
+  // operator< - Allow insertion into a map...
+  bool operator<(const PointerVal &PV) const {
+    return Node < PV.Node || (Node == PV.Node && Index < PV.Index);
+  }
+
   inline bool operator==(const PointerVal &PV) const {
     return Node == PV.Node && Index == PV.Index;
   }
@@ -63,6 +68,10 @@ public:
   ~PointerValSet() { dropRefs(); }
   const PointerValSet &operator=(const PointerValSet &PVS);
 
+  // operator< - Allow insertion into a map...
+  bool operator<(const PointerValSet &PVS) const;
+  bool operator==(const PointerValSet &PVS) const;
+
   const PointerVal &operator[](unsigned i) const { return Vals[i]; }
 
   unsigned size() const { return Vals.size(); }
@@ -144,6 +153,9 @@ public:
     return 0;  // Default to nothing...
   }
 
+  // isEquivalentTo - Return true if the nodes should be merged...
+  virtual bool isEquivalentTo(DSNode *Node) const = 0;
+
   DSNode *clone() const {
     DSNode *New = cloneImpl();
     // Add all of the pointers to the new node...
@@ -165,23 +177,26 @@ protected:
 };
 
 
-// NewDSNode - Represent all allocation (malloc or alloca) in the program.
+// AllocDSNode - Represent all allocation (malloc or alloca) in the program.
 //
-class NewDSNode : public DSNode {
+class AllocDSNode : public DSNode {
   AllocationInst *Allocation;
 public:
-  NewDSNode(AllocationInst *V);
+  AllocDSNode(AllocationInst *V);
 
   virtual std::string getCaption() const;
 
   bool isAllocaNode() const;
   bool isMallocNode() const { return !isAllocaNode(); }
 
+  // isEquivalentTo - Return true if the nodes should be merged...
+  virtual bool isEquivalentTo(DSNode *Node) const;
+
   // Support type inquiry through isa, cast, and dyn_cast...
-  static bool classof(const NewDSNode *) { return true; }
+  static bool classof(const AllocDSNode *) { return true; }
   static bool classof(const DSNode *N) { return N->NodeType == NewNode; }
 protected:
-  virtual NewDSNode *cloneImpl() const { return new NewDSNode(Allocation); }
+  virtual AllocDSNode *cloneImpl() const { return new AllocDSNode(Allocation); }
 };
 
 
@@ -192,8 +207,13 @@ class GlobalDSNode : public DSNode {
 public:
   GlobalDSNode(GlobalValue *V);
 
+  GlobalValue *getGlobal() const { return Val; }
+  
   virtual std::string getCaption() const;
 
+  // isEquivalentTo - Return true if the nodes should be merged...
+  virtual bool isEquivalentTo(DSNode *Node) const;
+
   // Support type inquiry through isa, cast, and dyn_cast...
   static bool classof(const GlobalDSNode *) { return true; }
   static bool classof(const DSNode *N) { return N->NodeType == GlobalNode; }
@@ -205,6 +225,7 @@ private:
 // CallDSNode - Represent a call instruction in the program...
 //
 class CallDSNode : public DSNode {
+  friend class FunctionDSGraph;
   CallInst *CI;
   std::vector<PointerValSet> ArgLinks;
 public:
@@ -224,12 +245,15 @@ public:
     assert(ArgNo < ArgLinks.size() && "Arg # out of range!");
     return ArgLinks[ArgNo];
   }
+  const std::vector<PointerValSet> &getArgs() const { return ArgLinks; }
 
   virtual void dropAllReferences() {
     DSNode::dropAllReferences();
     ArgLinks.clear();
   }
 
+  // isEquivalentTo - Return true if the nodes should be merged...
+  virtual bool isEquivalentTo(DSNode *Node) const;
 
   // Support type inquiry through isa, cast, and dyn_cast...
   static bool classof(const CallDSNode *) { return true; }
@@ -249,6 +273,9 @@ public:
   ArgDSNode(FunctionArgument *MA);
   virtual std::string getCaption() const;
 
+  // isEquivalentTo - Return true if the nodes should be merged...
+  virtual bool isEquivalentTo(DSNode *Node) const;
+
   // Support type inquiry through isa, cast, and dyn_cast...
   static bool classof(const ArgDSNode *) { return true; }
   static bool classof(const DSNode *N) { return N->NodeType == ArgNode; }
@@ -289,6 +316,9 @@ public:
   bool isCriticalNode() const { return CriticalNode; }
   void resetCriticalMark() { CriticalNode = false; }
 
+  // isEquivalentTo - Return true if the nodes should be merged...
+  virtual bool isEquivalentTo(DSNode *Node) const;
+
   // 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; }
@@ -311,8 +341,11 @@ protected:
 //
 class FunctionDSGraph {
   Function *Func;
-  std::vector<DSNode*> Nodes;
+  std::vector<ArgDSNode*>    ArgNodes;
+  std::vector<AllocDSNode*>  AllocNodes;
   std::vector<ShadowDSNode*> ShadowNodes;
+  std::vector<GlobalDSNode*> GlobalNodes;
+  std::vector<CallDSNode*>   CallNodes;
   PointerValSet RetNode;             // Node that gets returned...
   std::map<Value*, PointerValSet> ValueMap;
 
index 73cc19f3f0a5e3753c8a7db79d789858b1af0101..5132208277e2ebf2c4962c01722186a4e18bff05 100644 (file)
@@ -40,6 +40,11 @@ public:
   inline bool operator==(DSNode *N) const { return Node == N; }
   inline bool operator!=(DSNode *N) const { return Node != N; }
 
+  // operator< - Allow insertion into a map...
+  bool operator<(const PointerVal &PV) const {
+    return Node < PV.Node || (Node == PV.Node && Index < PV.Index);
+  }
+
   inline bool operator==(const PointerVal &PV) const {
     return Node == PV.Node && Index == PV.Index;
   }
@@ -63,6 +68,10 @@ public:
   ~PointerValSet() { dropRefs(); }
   const PointerValSet &operator=(const PointerValSet &PVS);
 
+  // operator< - Allow insertion into a map...
+  bool operator<(const PointerValSet &PVS) const;
+  bool operator==(const PointerValSet &PVS) const;
+
   const PointerVal &operator[](unsigned i) const { return Vals[i]; }
 
   unsigned size() const { return Vals.size(); }
@@ -144,6 +153,9 @@ public:
     return 0;  // Default to nothing...
   }
 
+  // isEquivalentTo - Return true if the nodes should be merged...
+  virtual bool isEquivalentTo(DSNode *Node) const = 0;
+
   DSNode *clone() const {
     DSNode *New = cloneImpl();
     // Add all of the pointers to the new node...
@@ -165,23 +177,26 @@ protected:
 };
 
 
-// NewDSNode - Represent all allocation (malloc or alloca) in the program.
+// AllocDSNode - Represent all allocation (malloc or alloca) in the program.
 //
-class NewDSNode : public DSNode {
+class AllocDSNode : public DSNode {
   AllocationInst *Allocation;
 public:
-  NewDSNode(AllocationInst *V);
+  AllocDSNode(AllocationInst *V);
 
   virtual std::string getCaption() const;
 
   bool isAllocaNode() const;
   bool isMallocNode() const { return !isAllocaNode(); }
 
+  // isEquivalentTo - Return true if the nodes should be merged...
+  virtual bool isEquivalentTo(DSNode *Node) const;
+
   // Support type inquiry through isa, cast, and dyn_cast...
-  static bool classof(const NewDSNode *) { return true; }
+  static bool classof(const AllocDSNode *) { return true; }
   static bool classof(const DSNode *N) { return N->NodeType == NewNode; }
 protected:
-  virtual NewDSNode *cloneImpl() const { return new NewDSNode(Allocation); }
+  virtual AllocDSNode *cloneImpl() const { return new AllocDSNode(Allocation); }
 };
 
 
@@ -192,8 +207,13 @@ class GlobalDSNode : public DSNode {
 public:
   GlobalDSNode(GlobalValue *V);
 
+  GlobalValue *getGlobal() const { return Val; }
+  
   virtual std::string getCaption() const;
 
+  // isEquivalentTo - Return true if the nodes should be merged...
+  virtual bool isEquivalentTo(DSNode *Node) const;
+
   // Support type inquiry through isa, cast, and dyn_cast...
   static bool classof(const GlobalDSNode *) { return true; }
   static bool classof(const DSNode *N) { return N->NodeType == GlobalNode; }
@@ -205,6 +225,7 @@ private:
 // CallDSNode - Represent a call instruction in the program...
 //
 class CallDSNode : public DSNode {
+  friend class FunctionDSGraph;
   CallInst *CI;
   std::vector<PointerValSet> ArgLinks;
 public:
@@ -224,12 +245,15 @@ public:
     assert(ArgNo < ArgLinks.size() && "Arg # out of range!");
     return ArgLinks[ArgNo];
   }
+  const std::vector<PointerValSet> &getArgs() const { return ArgLinks; }
 
   virtual void dropAllReferences() {
     DSNode::dropAllReferences();
     ArgLinks.clear();
   }
 
+  // isEquivalentTo - Return true if the nodes should be merged...
+  virtual bool isEquivalentTo(DSNode *Node) const;
 
   // Support type inquiry through isa, cast, and dyn_cast...
   static bool classof(const CallDSNode *) { return true; }
@@ -249,6 +273,9 @@ public:
   ArgDSNode(FunctionArgument *MA);
   virtual std::string getCaption() const;
 
+  // isEquivalentTo - Return true if the nodes should be merged...
+  virtual bool isEquivalentTo(DSNode *Node) const;
+
   // Support type inquiry through isa, cast, and dyn_cast...
   static bool classof(const ArgDSNode *) { return true; }
   static bool classof(const DSNode *N) { return N->NodeType == ArgNode; }
@@ -289,6 +316,9 @@ public:
   bool isCriticalNode() const { return CriticalNode; }
   void resetCriticalMark() { CriticalNode = false; }
 
+  // isEquivalentTo - Return true if the nodes should be merged...
+  virtual bool isEquivalentTo(DSNode *Node) const;
+
   // 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; }
@@ -311,8 +341,11 @@ protected:
 //
 class FunctionDSGraph {
   Function *Func;
-  std::vector<DSNode*> Nodes;
+  std::vector<ArgDSNode*>    ArgNodes;
+  std::vector<AllocDSNode*>  AllocNodes;
   std::vector<ShadowDSNode*> ShadowNodes;
+  std::vector<GlobalDSNode*> GlobalNodes;
+  std::vector<CallDSNode*>   CallNodes;
   PointerValSet RetNode;             // Node that gets returned...
   std::map<Value*, PointerValSet> ValueMap;