From 726bafda652754096ee4d3c8ceb07aa8d105f8b9 Mon Sep 17 00:00:00 2001 From: "Vikram S. Adve" Date: Sun, 20 Oct 2002 18:04:43 +0000 Subject: [PATCH] Added a first-class representation for each call site that can be used in the DS graphs. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@4227 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Analysis/DSGraph.h | 38 +++++++++++++++++-- include/llvm/Analysis/DataStructure/DSGraph.h | 38 +++++++++++++++++-- 2 files changed, 70 insertions(+), 6 deletions(-) diff --git a/include/llvm/Analysis/DSGraph.h b/include/llvm/Analysis/DSGraph.h index efb82bc10f5..1148dd65a1e 100644 --- a/include/llvm/Analysis/DSGraph.h +++ b/include/llvm/Analysis/DSGraph.h @@ -10,8 +10,10 @@ #include #include +#include class Function; +class CallInst; class Value; class GlobalValue; class Type; @@ -20,6 +22,7 @@ class DSNode; // Each node in the graph class DSGraph; // A graph for a function class DSNodeIterator; // Data structure graph traversal iterator + //===----------------------------------------------------------------------===// /// DSNodeHandle - Implement a "handle" to a data structure node that takes care /// of all of the add/un'refing of the node to prevent the backpointers in the @@ -350,6 +353,35 @@ inline void DSNodeHandle::mergeWith(const DSNodeHandle &Node) { } +//===----------------------------------------------------------------------===// +/// DSCallSite - Representation of a call site via its call instruction, +/// the DSNode handle for the callee function (or function pointer), and +/// the DSNode handles for the function arguments. +/// +class DSCallSite: public std::vector { + Function* caller; + CallInst* callInst; + DSCallSite(); // do not implement + +public: + DSCallSite(Function& _caller, CallInst& _callInst) + : caller(&_caller), callInst(&_callInst) { } + + // Copy constructor with helper for cloning nodes. The helper should be a + // model of unary_function, i.e., it + // should take a pointer to DSNodeHandle and return a fresh DSNodeHandle. + // If no helper is specified, this defaults to a simple copy constructor. + template + DSCallSite::DSCallSite(const DSCallSite& FromCall, + _CopierFunction nodeCopier = *(_CopierFunction*) 0); + + Function& getCaller() const { return *caller; } + CallInst& getCallInst() const { return *callInst; } + DSNodeHandle getReturnValueNode() const { return (*this)[0]; } + DSNodeHandle getCalleeNode() const { return (*this)[1]; } +}; + + //===----------------------------------------------------------------------===// /// DSGraph - The graph that represents a function. /// @@ -373,7 +405,7 @@ class DSGraph { // call, the second is the function scalar being invoked, and the rest are // pointer arguments to the function. // - std::vector > FunctionCalls; + std::vector FunctionCalls; void operator=(const DSGraph &); // DO NOT IMPLEMENT public: @@ -400,10 +432,10 @@ public: std::map &getValueMap() { return ValueMap; } const std::map &getValueMap() const { return ValueMap;} - std::vector > &getFunctionCalls() { + std::vector &getFunctionCalls() { return FunctionCalls; } - const std::vector > &getFunctionCalls() const { + const std::vector &getFunctionCalls() const { return FunctionCalls; } diff --git a/include/llvm/Analysis/DataStructure/DSGraph.h b/include/llvm/Analysis/DataStructure/DSGraph.h index efb82bc10f5..1148dd65a1e 100644 --- a/include/llvm/Analysis/DataStructure/DSGraph.h +++ b/include/llvm/Analysis/DataStructure/DSGraph.h @@ -10,8 +10,10 @@ #include #include +#include class Function; +class CallInst; class Value; class GlobalValue; class Type; @@ -20,6 +22,7 @@ class DSNode; // Each node in the graph class DSGraph; // A graph for a function class DSNodeIterator; // Data structure graph traversal iterator + //===----------------------------------------------------------------------===// /// DSNodeHandle - Implement a "handle" to a data structure node that takes care /// of all of the add/un'refing of the node to prevent the backpointers in the @@ -350,6 +353,35 @@ inline void DSNodeHandle::mergeWith(const DSNodeHandle &Node) { } +//===----------------------------------------------------------------------===// +/// DSCallSite - Representation of a call site via its call instruction, +/// the DSNode handle for the callee function (or function pointer), and +/// the DSNode handles for the function arguments. +/// +class DSCallSite: public std::vector { + Function* caller; + CallInst* callInst; + DSCallSite(); // do not implement + +public: + DSCallSite(Function& _caller, CallInst& _callInst) + : caller(&_caller), callInst(&_callInst) { } + + // Copy constructor with helper for cloning nodes. The helper should be a + // model of unary_function, i.e., it + // should take a pointer to DSNodeHandle and return a fresh DSNodeHandle. + // If no helper is specified, this defaults to a simple copy constructor. + template + DSCallSite::DSCallSite(const DSCallSite& FromCall, + _CopierFunction nodeCopier = *(_CopierFunction*) 0); + + Function& getCaller() const { return *caller; } + CallInst& getCallInst() const { return *callInst; } + DSNodeHandle getReturnValueNode() const { return (*this)[0]; } + DSNodeHandle getCalleeNode() const { return (*this)[1]; } +}; + + //===----------------------------------------------------------------------===// /// DSGraph - The graph that represents a function. /// @@ -373,7 +405,7 @@ class DSGraph { // call, the second is the function scalar being invoked, and the rest are // pointer arguments to the function. // - std::vector > FunctionCalls; + std::vector FunctionCalls; void operator=(const DSGraph &); // DO NOT IMPLEMENT public: @@ -400,10 +432,10 @@ public: std::map &getValueMap() { return ValueMap; } const std::map &getValueMap() const { return ValueMap;} - std::vector > &getFunctionCalls() { + std::vector &getFunctionCalls() { return FunctionCalls; } - const std::vector > &getFunctionCalls() const { + const std::vector &getFunctionCalls() const { return FunctionCalls; }