From 1d8ec6194a3c8d6e676f373af04171e5ad2ed4eb Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Thu, 28 Mar 2002 17:48:41 +0000 Subject: [PATCH] * Define some operators on PointerVal and PVS's * 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 | 45 ++++++++++++++++--- .../Analysis/DataStructure/DataStructure.h | 45 ++++++++++++++++--- 2 files changed, 78 insertions(+), 12 deletions(-) diff --git a/include/llvm/Analysis/DataStructure.h b/include/llvm/Analysis/DataStructure.h index 73cc19f3f0a..5132208277e 100644 --- a/include/llvm/Analysis/DataStructure.h +++ b/include/llvm/Analysis/DataStructure.h @@ -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 ArgLinks; public: @@ -224,12 +245,15 @@ public: assert(ArgNo < ArgLinks.size() && "Arg # out of range!"); return ArgLinks[ArgNo]; } + const std::vector &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 Nodes; + std::vector ArgNodes; + std::vector AllocNodes; std::vector ShadowNodes; + std::vector GlobalNodes; + std::vector CallNodes; PointerValSet RetNode; // Node that gets returned... std::map ValueMap; diff --git a/include/llvm/Analysis/DataStructure/DataStructure.h b/include/llvm/Analysis/DataStructure/DataStructure.h index 73cc19f3f0a..5132208277e 100644 --- a/include/llvm/Analysis/DataStructure/DataStructure.h +++ b/include/llvm/Analysis/DataStructure/DataStructure.h @@ -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 ArgLinks; public: @@ -224,12 +245,15 @@ public: assert(ArgNo < ArgLinks.size() && "Arg # out of range!"); return ArgLinks[ArgNo]; } + const std::vector &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 Nodes; + std::vector ArgNodes; + std::vector AllocNodes; std::vector ShadowNodes; + std::vector GlobalNodes; + std::vector CallNodes; PointerValSet RetNode; // Node that gets returned... std::map ValueMap; -- 2.34.1