2002-03-30 04:02:41 +00:00
|
|
|
//===- DataStructure.h - Build data structure graphs -------------*- C++ -*--=//
|
2002-03-26 22:38:45 +00:00
|
|
|
//
|
|
|
|
// Implement the LLVM data structure analysis library.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_ANALYSIS_DATA_STRUCTURE_H
|
|
|
|
#define LLVM_ANALYSIS_DATA_STRUCTURE_H
|
|
|
|
|
|
|
|
#include "llvm/Pass.h"
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
class Type;
|
|
|
|
class CallInst;
|
|
|
|
class AllocationInst;
|
2002-04-09 19:59:31 +00:00
|
|
|
class Argument;
|
2002-03-26 22:38:45 +00:00
|
|
|
class DSNode;
|
|
|
|
class FunctionRepBuilder;
|
|
|
|
class GlobalValue;
|
|
|
|
class FunctionDSGraph;
|
|
|
|
class DataStructure;
|
2002-03-31 07:11:20 +00:00
|
|
|
class DSNodeIterator;
|
2002-04-17 03:24:47 +00:00
|
|
|
class ShadowDSNode;
|
2002-03-26 22:38:45 +00:00
|
|
|
|
|
|
|
// FIXME: move this somewhere private
|
|
|
|
unsigned countPointerFields(const Type *Ty);
|
|
|
|
|
|
|
|
// PointerVal - Represent a pointer to a datastructure. The pointer points to
|
|
|
|
// a node, and can index into it. This is used for getelementptr instructions,
|
|
|
|
// which do not affect which node a pointer points to, but does change the field
|
|
|
|
// index
|
|
|
|
//
|
|
|
|
struct PointerVal {
|
|
|
|
DSNode *Node;
|
|
|
|
unsigned Index; // Index into Node->FieldLinks[]
|
|
|
|
public:
|
|
|
|
PointerVal(DSNode *N, unsigned Idx = 0) : Node(N), Index(Idx) {}
|
|
|
|
|
|
|
|
DSNode *getNode() const { return Node; }
|
|
|
|
unsigned getIndex() const { return Index; }
|
|
|
|
|
|
|
|
inline bool operator==(DSNode *N) const { return Node == N; }
|
|
|
|
inline bool operator!=(DSNode *N) const { return Node != N; }
|
|
|
|
|
2002-03-28 17:48:41 +00:00
|
|
|
// operator< - Allow insertion into a map...
|
|
|
|
bool operator<(const PointerVal &PV) const {
|
|
|
|
return Node < PV.Node || (Node == PV.Node && Index < PV.Index);
|
|
|
|
}
|
|
|
|
|
2002-03-26 22:38:45 +00:00
|
|
|
inline bool operator==(const PointerVal &PV) const {
|
|
|
|
return Node == PV.Node && Index == PV.Index;
|
|
|
|
}
|
|
|
|
inline bool operator!=(const PointerVal &PV) const { return !operator==(PV); }
|
|
|
|
|
|
|
|
void print(std::ostream &O) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// PointerValSet - This class represents a list of pointer values. The add
|
|
|
|
// method is used to add values to the set, and ensures that duplicates cannot
|
|
|
|
// happen.
|
|
|
|
//
|
|
|
|
class PointerValSet {
|
|
|
|
std::vector<PointerVal> Vals;
|
|
|
|
void dropRefs();
|
|
|
|
void addRefs();
|
|
|
|
public:
|
|
|
|
PointerValSet() {}
|
|
|
|
PointerValSet(const PointerValSet &PVS) : Vals(PVS.Vals) { addRefs(); }
|
|
|
|
~PointerValSet() { dropRefs(); }
|
|
|
|
const PointerValSet &operator=(const PointerValSet &PVS);
|
|
|
|
|
2002-03-28 17:48:41 +00:00
|
|
|
// operator< - Allow insertion into a map...
|
|
|
|
bool operator<(const PointerValSet &PVS) const;
|
|
|
|
bool operator==(const PointerValSet &PVS) const;
|
|
|
|
|
2002-03-26 22:38:45 +00:00
|
|
|
const PointerVal &operator[](unsigned i) const { return Vals[i]; }
|
|
|
|
|
|
|
|
unsigned size() const { return Vals.size(); }
|
|
|
|
bool empty() const { return Vals.empty(); }
|
|
|
|
void clear() { dropRefs(); Vals.clear(); }
|
|
|
|
|
|
|
|
// add - Add the specified pointer, or contents of the specified PVS to this
|
|
|
|
// pointer set. If a 'Pointer' value is provided, notify the underlying data
|
|
|
|
// structure node that the pointer is pointing to it, so that it can be
|
|
|
|
// invalidated if neccesary later. True is returned if the value is new to
|
|
|
|
// this pointer.
|
|
|
|
//
|
|
|
|
bool add(const PointerVal &PV, Value *Pointer = 0);
|
|
|
|
bool add(const PointerValSet &PVS, Value *Pointer = 0) {
|
|
|
|
bool Changed = false;
|
|
|
|
for (unsigned i = 0, e = PVS.size(); i != e; ++i)
|
|
|
|
Changed |= add(PVS[i], Pointer);
|
|
|
|
return Changed;
|
|
|
|
}
|
|
|
|
|
|
|
|
// removePointerTo - Remove a single pointer val that points to the specified
|
|
|
|
// node...
|
|
|
|
void removePointerTo(DSNode *Node);
|
|
|
|
|
|
|
|
void print(std::ostream &O) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// DSNode - Base class for all data structure nodes...
|
|
|
|
//
|
|
|
|
// This class keeps track of its type, the pointer fields in the data structure,
|
|
|
|
// and a list of LLVM values that are pointing to this node.
|
|
|
|
//
|
|
|
|
class DSNode {
|
|
|
|
friend class FunctionDSGraph;
|
|
|
|
const Type *Ty;
|
|
|
|
std::vector<PointerValSet> FieldLinks;
|
|
|
|
std::vector<Value*> Pointers; // Values pointing to me...
|
|
|
|
std::vector<PointerValSet*> Referrers;
|
2002-04-17 03:24:47 +00:00
|
|
|
|
|
|
|
std::vector<std::pair<const Type *, ShadowDSNode *> > SynthNodes;
|
2002-03-26 22:38:45 +00:00
|
|
|
|
|
|
|
DSNode(const DSNode &); // DO NOT IMPLEMENT
|
|
|
|
void operator=(const DSNode &); // DO NOT IMPLEMENT
|
|
|
|
public:
|
|
|
|
enum NodeTy {
|
2002-04-16 20:39:23 +00:00
|
|
|
NewNode, CallNode, ShadowNode, GlobalNode
|
2002-03-26 22:38:45 +00:00
|
|
|
} NodeType;
|
|
|
|
|
|
|
|
DSNode(enum NodeTy NT, const Type *T);
|
|
|
|
virtual ~DSNode() {
|
|
|
|
dropAllReferences();
|
|
|
|
assert(Referrers.empty() && "Referrers to dead node exist!");
|
|
|
|
}
|
|
|
|
|
2002-03-31 07:11:20 +00:00
|
|
|
typedef DSNodeIterator iterator;
|
|
|
|
inline iterator begin(); // Defined in DataStructureGraph.h
|
|
|
|
inline iterator end();
|
|
|
|
|
2002-03-26 22:38:45 +00:00
|
|
|
unsigned getNumLinks() const { return FieldLinks.size(); }
|
|
|
|
PointerValSet &getLink(unsigned i) {
|
|
|
|
assert(i < getNumLinks() && "Field links access out of range...");
|
|
|
|
return FieldLinks[i];
|
|
|
|
}
|
2002-03-30 09:07:51 +00:00
|
|
|
const PointerValSet &getLink(unsigned i) const {
|
|
|
|
assert(i < getNumLinks() && "Field links access out of range...");
|
|
|
|
return FieldLinks[i];
|
|
|
|
}
|
2002-03-26 22:38:45 +00:00
|
|
|
|
|
|
|
// addReferrer - Keep the referrer set up to date...
|
|
|
|
void addReferrer(PointerValSet *PVS) { Referrers.push_back(PVS); }
|
|
|
|
void removeReferrer(PointerValSet *PVS);
|
|
|
|
const std::vector<PointerValSet*> &getReferrers() const { return Referrers; }
|
|
|
|
|
2002-03-27 19:41:45 +00:00
|
|
|
// removeAllIncomingEdges - Erase all edges in the graph that point to
|
|
|
|
// this node
|
|
|
|
void removeAllIncomingEdges();
|
|
|
|
|
2002-03-26 22:38:45 +00:00
|
|
|
void addPointer(Value *V) { Pointers.push_back(V); }
|
|
|
|
const std::vector<Value*> &getPointers() const { return Pointers; }
|
|
|
|
|
|
|
|
const Type *getType() const { return Ty; }
|
|
|
|
|
2002-03-30 09:07:51 +00:00
|
|
|
// getNumOutgoingLinks - Return the number of outgoing links, which is usually
|
|
|
|
// the number of normal links, but for call nodes it also includes their
|
|
|
|
// arguments.
|
|
|
|
//
|
|
|
|
virtual unsigned getNumOutgoingLinks() const { return getNumLinks(); }
|
|
|
|
virtual PointerValSet &getOutgoingLink(unsigned Link) {
|
|
|
|
return getLink(Link);
|
|
|
|
}
|
|
|
|
virtual const PointerValSet &getOutgoingLink(unsigned Link) const {
|
|
|
|
return getLink(Link);
|
|
|
|
}
|
|
|
|
|
2002-03-26 22:38:45 +00:00
|
|
|
void print(std::ostream &O) const;
|
2002-03-31 07:11:20 +00:00
|
|
|
void dump() const;
|
2002-03-26 22:38:45 +00:00
|
|
|
|
|
|
|
virtual std::string getCaption() const = 0;
|
|
|
|
virtual const std::vector<PointerValSet> *getAuxLinks() const {
|
|
|
|
return 0; // Default to nothing...
|
|
|
|
}
|
|
|
|
|
2002-03-28 17:48:41 +00:00
|
|
|
// isEquivalentTo - Return true if the nodes should be merged...
|
|
|
|
virtual bool isEquivalentTo(DSNode *Node) const = 0;
|
2002-04-27 02:27:11 +00:00
|
|
|
virtual void mergeInto(DSNode *Node) const {}
|
2002-03-28 17:48:41 +00:00
|
|
|
|
2002-03-26 22:38:45 +00:00
|
|
|
DSNode *clone() const {
|
|
|
|
DSNode *New = cloneImpl();
|
|
|
|
// Add all of the pointers to the new node...
|
|
|
|
for (unsigned pn = 0, pe = Pointers.size(); pn != pe; ++pn)
|
|
|
|
New->addPointer(Pointers[pn]);
|
|
|
|
return New;
|
|
|
|
}
|
|
|
|
|
2002-04-17 03:24:47 +00:00
|
|
|
// synthesizeNode - Create a new shadow node that is to be linked into this
|
|
|
|
// chain..
|
|
|
|
//
|
|
|
|
ShadowDSNode *synthesizeNode(const Type *Ty, FunctionRepBuilder *Rep);
|
2002-03-26 22:38:45 +00:00
|
|
|
|
|
|
|
virtual void dropAllReferences() {
|
|
|
|
FieldLinks.clear();
|
|
|
|
}
|
|
|
|
|
2002-03-27 00:52:57 +00:00
|
|
|
static bool classof(const DSNode *N) { return true; }
|
2002-03-26 22:38:45 +00:00
|
|
|
protected:
|
|
|
|
virtual DSNode *cloneImpl() const = 0;
|
|
|
|
virtual void mapNode(std::map<const DSNode*, DSNode*> &NodeMap,
|
|
|
|
const DSNode *Old);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2002-03-28 17:48:41 +00:00
|
|
|
// AllocDSNode - Represent all allocation (malloc or alloca) in the program.
|
2002-03-26 22:38:45 +00:00
|
|
|
//
|
2002-03-28 17:48:41 +00:00
|
|
|
class AllocDSNode : public DSNode {
|
2002-03-26 22:38:45 +00:00
|
|
|
AllocationInst *Allocation;
|
2002-04-27 02:27:11 +00:00
|
|
|
bool isVarSize; // Allocating variable sized objects
|
2002-03-26 22:38:45 +00:00
|
|
|
public:
|
2002-04-27 02:27:11 +00:00
|
|
|
AllocDSNode(AllocationInst *V, bool isVarSize = false);
|
2002-03-26 22:38:45 +00:00
|
|
|
|
|
|
|
virtual std::string getCaption() const;
|
|
|
|
|
2002-03-27 19:41:45 +00:00
|
|
|
bool isAllocaNode() const;
|
|
|
|
bool isMallocNode() const { return !isAllocaNode(); }
|
|
|
|
|
2002-03-29 03:35:30 +00:00
|
|
|
AllocationInst *getAllocation() const { return Allocation; }
|
2002-04-27 02:27:11 +00:00
|
|
|
bool isVariableSize() const { return isVarSize; }
|
2002-03-29 03:35:30 +00:00
|
|
|
|
2002-03-28 17:48:41 +00:00
|
|
|
// isEquivalentTo - Return true if the nodes should be merged...
|
|
|
|
virtual bool isEquivalentTo(DSNode *Node) const;
|
2002-04-27 02:27:11 +00:00
|
|
|
virtual void mergeInto(DSNode *Node) const;
|
2002-03-28 17:48:41 +00:00
|
|
|
|
2002-03-26 22:38:45 +00:00
|
|
|
// Support type inquiry through isa, cast, and dyn_cast...
|
2002-03-28 17:48:41 +00:00
|
|
|
static bool classof(const AllocDSNode *) { return true; }
|
2002-03-26 22:38:45 +00:00
|
|
|
static bool classof(const DSNode *N) { return N->NodeType == NewNode; }
|
|
|
|
protected:
|
2002-04-27 02:27:11 +00:00
|
|
|
virtual AllocDSNode *cloneImpl() const { return new AllocDSNode(Allocation,
|
|
|
|
isVarSize); }
|
2002-03-26 22:38:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// GlobalDSNode - Represent the memory location that a global variable occupies
|
|
|
|
//
|
|
|
|
class GlobalDSNode : public DSNode {
|
|
|
|
GlobalValue *Val;
|
|
|
|
public:
|
|
|
|
GlobalDSNode(GlobalValue *V);
|
|
|
|
|
2002-03-28 17:48:41 +00:00
|
|
|
GlobalValue *getGlobal() const { return Val; }
|
|
|
|
|
2002-03-26 22:38:45 +00:00
|
|
|
virtual std::string getCaption() const;
|
|
|
|
|
2002-03-28 17:48:41 +00:00
|
|
|
// isEquivalentTo - Return true if the nodes should be merged...
|
|
|
|
virtual bool isEquivalentTo(DSNode *Node) const;
|
|
|
|
|
2002-03-26 22:38:45 +00:00
|
|
|
// 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; }
|
|
|
|
private:
|
|
|
|
virtual GlobalDSNode *cloneImpl() const { return new GlobalDSNode(Val); }
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// CallDSNode - Represent a call instruction in the program...
|
|
|
|
//
|
|
|
|
class CallDSNode : public DSNode {
|
2002-03-28 17:48:41 +00:00
|
|
|
friend class FunctionDSGraph;
|
2002-03-26 22:38:45 +00:00
|
|
|
CallInst *CI;
|
|
|
|
std::vector<PointerValSet> ArgLinks;
|
|
|
|
public:
|
|
|
|
CallDSNode(CallInst *CI);
|
2002-04-16 20:39:23 +00:00
|
|
|
~CallDSNode() {
|
|
|
|
ArgLinks.clear();
|
|
|
|
}
|
2002-03-26 22:38:45 +00:00
|
|
|
|
|
|
|
CallInst *getCall() const { return CI; }
|
|
|
|
|
|
|
|
const std::vector<PointerValSet> *getAuxLinks() const { return &ArgLinks; }
|
|
|
|
virtual std::string getCaption() const;
|
|
|
|
|
|
|
|
bool addArgValue(unsigned ArgNo, const PointerValSet &PVS) {
|
|
|
|
return ArgLinks[ArgNo].add(PVS);
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned getNumArgs() const { return ArgLinks.size(); }
|
|
|
|
const PointerValSet &getArgValues(unsigned ArgNo) const {
|
|
|
|
assert(ArgNo < ArgLinks.size() && "Arg # out of range!");
|
2002-03-30 04:02:41 +00:00
|
|
|
return ArgLinks[ArgNo];
|
|
|
|
}
|
|
|
|
PointerValSet &getArgValues(unsigned ArgNo) {
|
|
|
|
assert(ArgNo < ArgLinks.size() && "Arg # out of range!");
|
2002-03-26 22:38:45 +00:00
|
|
|
return ArgLinks[ArgNo];
|
|
|
|
}
|
2002-03-28 17:48:41 +00:00
|
|
|
const std::vector<PointerValSet> &getArgs() const { return ArgLinks; }
|
2002-03-26 22:38:45 +00:00
|
|
|
|
|
|
|
virtual void dropAllReferences() {
|
|
|
|
DSNode::dropAllReferences();
|
|
|
|
ArgLinks.clear();
|
|
|
|
}
|
|
|
|
|
2002-03-30 09:07:51 +00:00
|
|
|
// getNumOutgoingLinks - Return the number of outgoing links, which is usually
|
|
|
|
// the number of normal links, but for call nodes it also includes their
|
|
|
|
// arguments.
|
|
|
|
//
|
|
|
|
virtual unsigned getNumOutgoingLinks() const {
|
|
|
|
return getNumLinks() + getNumArgs();
|
|
|
|
}
|
|
|
|
virtual PointerValSet &getOutgoingLink(unsigned Link) {
|
|
|
|
if (Link < getNumLinks()) return getLink(Link);
|
|
|
|
return getArgValues(Link-getNumLinks());
|
|
|
|
}
|
|
|
|
virtual const PointerValSet &getOutgoingLink(unsigned Link) const {
|
|
|
|
if (Link < getNumLinks()) return getLink(Link);
|
|
|
|
return getArgValues(Link-getNumLinks());
|
|
|
|
}
|
|
|
|
|
2002-03-28 17:48:41 +00:00
|
|
|
// isEquivalentTo - Return true if the nodes should be merged...
|
|
|
|
virtual bool isEquivalentTo(DSNode *Node) const;
|
2002-03-26 22:38:45 +00:00
|
|
|
|
|
|
|
// Support type inquiry through isa, cast, and dyn_cast...
|
|
|
|
static bool classof(const CallDSNode *) { return true; }
|
|
|
|
static bool classof(const DSNode *N) { return N->NodeType == CallNode; }
|
|
|
|
private:
|
|
|
|
virtual CallDSNode *cloneImpl() const { return new CallDSNode(CI); }
|
|
|
|
virtual void mapNode(std::map<const DSNode*, DSNode*> &NodeMap,
|
|
|
|
const DSNode *Old);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// ShadowDSNode - Represent a chunk of memory that we need to be able to
|
|
|
|
// address. These are generated due to (for example) pointer type method
|
|
|
|
// arguments... if the pointer is dereferenced, we need to have a node to point
|
|
|
|
// to. When functions are integrated into each other, shadow nodes are
|
|
|
|
// resolved.
|
|
|
|
//
|
|
|
|
class ShadowDSNode : public DSNode {
|
|
|
|
friend class FunctionDSGraph;
|
2002-04-17 03:24:47 +00:00
|
|
|
friend class FunctionRepBuilder;
|
2002-03-26 22:38:45 +00:00
|
|
|
Module *Mod;
|
2002-04-17 03:24:47 +00:00
|
|
|
DSNode *ShadowParent; // Nonnull if this is a synthesized node...
|
2002-03-26 22:38:45 +00:00
|
|
|
public:
|
2002-04-16 20:39:23 +00:00
|
|
|
ShadowDSNode(const Type *Ty, Module *M);
|
2002-03-26 22:38:45 +00:00
|
|
|
virtual std::string getCaption() const;
|
|
|
|
|
2002-03-28 17:48:41 +00:00
|
|
|
// isEquivalentTo - Return true if the nodes should be merged...
|
|
|
|
virtual bool isEquivalentTo(DSNode *Node) const;
|
|
|
|
|
2002-04-17 03:24:47 +00:00
|
|
|
DSNode *getShadowParent() const { return ShadowParent; }
|
|
|
|
|
2002-03-26 22:38:45 +00:00
|
|
|
// 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; }
|
|
|
|
|
|
|
|
private:
|
2002-04-17 03:24:47 +00:00
|
|
|
ShadowDSNode(const Type *Ty, Module *M, DSNode *ShadParent);
|
2002-03-26 22:38:45 +00:00
|
|
|
protected:
|
|
|
|
virtual ShadowDSNode *cloneImpl() const {
|
|
|
|
if (ShadowParent)
|
|
|
|
return new ShadowDSNode(getType(), Mod, ShadowParent);
|
|
|
|
else
|
2002-04-16 20:39:23 +00:00
|
|
|
return new ShadowDSNode(getType(), Mod);
|
2002-03-26 22:38:45 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// FunctionDSGraph - The graph that represents a method.
|
|
|
|
//
|
|
|
|
class FunctionDSGraph {
|
|
|
|
Function *Func;
|
2002-03-28 17:48:41 +00:00
|
|
|
std::vector<AllocDSNode*> AllocNodes;
|
2002-03-26 22:38:45 +00:00
|
|
|
std::vector<ShadowDSNode*> ShadowNodes;
|
2002-03-28 17:48:41 +00:00
|
|
|
std::vector<GlobalDSNode*> GlobalNodes;
|
|
|
|
std::vector<CallDSNode*> CallNodes;
|
2002-03-26 22:38:45 +00:00
|
|
|
PointerValSet RetNode; // Node that gets returned...
|
|
|
|
std::map<Value*, PointerValSet> ValueMap;
|
|
|
|
|
|
|
|
// cloneFunctionIntoSelf - Clone the specified method graph into the current
|
|
|
|
// method graph, returning the Return's set of the graph. If ValueMap is set
|
|
|
|
// to true, the ValueMap of the function is cloned into this function as well
|
2002-04-16 03:41:22 +00:00
|
|
|
// as the data structure graph itself. Regardless, the arguments value sets
|
|
|
|
// of DSG are copied into Args.
|
2002-03-26 22:38:45 +00:00
|
|
|
//
|
2002-04-16 03:41:22 +00:00
|
|
|
PointerValSet cloneFunctionIntoSelf(const FunctionDSGraph &G, bool ValueMap,
|
|
|
|
std::vector<PointerValSet> &Args);
|
|
|
|
|
2002-03-28 19:15:38 +00:00
|
|
|
bool RemoveUnreachableNodes();
|
|
|
|
bool UnlinkUndistinguishableNodes();
|
2002-03-28 19:33:00 +00:00
|
|
|
void MarkEscapeableNodesReachable(std::vector<bool> &RSN,
|
|
|
|
std::vector<bool> &RAN);
|
2002-03-28 19:15:38 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
// Define the interface only accessable to DataStructure
|
|
|
|
friend class DataStructure;
|
2002-03-26 22:38:45 +00:00
|
|
|
FunctionDSGraph(Function *F);
|
|
|
|
FunctionDSGraph(const FunctionDSGraph &DSG);
|
|
|
|
~FunctionDSGraph();
|
|
|
|
|
|
|
|
void computeClosure(const DataStructure &DS);
|
2002-03-28 19:15:38 +00:00
|
|
|
public:
|
2002-03-26 22:38:45 +00:00
|
|
|
|
|
|
|
Function *getFunction() const { return Func; }
|
|
|
|
|
2002-03-28 19:15:38 +00:00
|
|
|
// getEscapingAllocations - Add all allocations that escape the current
|
|
|
|
// function to the specified vector.
|
|
|
|
//
|
|
|
|
void getEscapingAllocations(std::vector<AllocDSNode*> &Allocs);
|
|
|
|
|
2002-03-28 19:33:00 +00:00
|
|
|
// getNonEscapingAllocations - Add all allocations that do not escape the
|
|
|
|
// current function to the specified vector.
|
2002-03-28 19:15:38 +00:00
|
|
|
//
|
|
|
|
void getNonEscapingAllocations(std::vector<AllocDSNode*> &Allocs);
|
|
|
|
|
2002-03-29 03:35:30 +00:00
|
|
|
// getValueMap - Get a map that describes what the nodes the scalars in this
|
|
|
|
// function point to...
|
|
|
|
//
|
|
|
|
std::map<Value*, PointerValSet> &getValueMap() { return ValueMap; }
|
2002-04-16 03:41:22 +00:00
|
|
|
const std::map<Value*, PointerValSet> &getValueMap() const { return ValueMap;}
|
2002-03-29 03:35:30 +00:00
|
|
|
|
2002-03-30 09:07:51 +00:00
|
|
|
const PointerValSet &getRetNodes() const { return RetNode; }
|
2002-03-29 03:35:30 +00:00
|
|
|
|
2002-04-04 19:20:00 +00:00
|
|
|
unsigned getGraphSize() const {
|
2002-04-16 03:41:22 +00:00
|
|
|
return AllocNodes.size() + ShadowNodes.size() +
|
2002-04-04 19:20:00 +00:00
|
|
|
GlobalNodes.size() + CallNodes.size();
|
|
|
|
}
|
2002-03-29 03:35:30 +00:00
|
|
|
|
2002-03-26 22:38:45 +00:00
|
|
|
void printFunction(std::ostream &O, const char *Label) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// FIXME: This should be a FunctionPass. When the pass framework sees a 'Pass'
|
|
|
|
// that uses the output of a FunctionPass, it should automatically build a map
|
|
|
|
// of output from the method pass that the pass can use.
|
|
|
|
//
|
|
|
|
class DataStructure : public Pass {
|
|
|
|
// DSInfo, one intraprocedural and one closed graph for each method...
|
|
|
|
typedef std::map<Function*, std::pair<FunctionDSGraph*,
|
|
|
|
FunctionDSGraph*> > InfoMap;
|
|
|
|
mutable InfoMap DSInfo;
|
|
|
|
public:
|
|
|
|
static AnalysisID ID; // DataStructure Analysis ID
|
|
|
|
|
|
|
|
DataStructure(AnalysisID id) { assert(id == ID); }
|
|
|
|
~DataStructure() { releaseMemory(); }
|
|
|
|
|
2002-04-29 14:57:45 +00:00
|
|
|
virtual const char *getPassName() const { return "Data Structure Analysis"; }
|
|
|
|
|
2002-03-26 22:38:45 +00:00
|
|
|
// run - Do nothing, because methods are analyzed lazily
|
|
|
|
virtual bool run(Module *TheModule) { return false; }
|
|
|
|
|
|
|
|
// getDSGraph - Return the data structure graph for the specified method.
|
|
|
|
// Since method graphs are lazily computed, we may have to create one on the
|
|
|
|
// fly here.
|
|
|
|
//
|
|
|
|
FunctionDSGraph &getDSGraph(Function *F) const {
|
|
|
|
std::pair<FunctionDSGraph*, FunctionDSGraph*> &N = DSInfo[F];
|
|
|
|
if (N.first) return *N.first;
|
|
|
|
return *(N.first = new FunctionDSGraph(F));
|
|
|
|
}
|
|
|
|
|
|
|
|
// getClosedDSGraph - Return the data structure graph for the specified
|
|
|
|
// method. Since method graphs are lazily computed, we may have to create one
|
|
|
|
// on the fly here. This is different than the normal DSGraph for the method
|
|
|
|
// because any function calls that are resolvable will have the data structure
|
|
|
|
// graphs of the called function incorporated into this function as well.
|
|
|
|
//
|
|
|
|
FunctionDSGraph &getClosedDSGraph(Function *F) const {
|
|
|
|
std::pair<FunctionDSGraph*, FunctionDSGraph*> &N = DSInfo[F];
|
|
|
|
if (N.second) return *N.second;
|
|
|
|
N.second = new FunctionDSGraph(getDSGraph(F));
|
|
|
|
N.second->computeClosure(*this);
|
|
|
|
return *N.second;
|
|
|
|
}
|
|
|
|
|
2002-03-29 21:23:29 +00:00
|
|
|
// invalidateFunction - Inform this analysis that you changed the specified
|
|
|
|
// function, so the graphs that depend on it are out of date.
|
|
|
|
//
|
|
|
|
void invalidateFunction(Function *F) const {
|
|
|
|
// FIXME: THis should invalidate all functions who have inlined the
|
|
|
|
// specified graph!
|
|
|
|
//
|
|
|
|
std::pair<FunctionDSGraph*, FunctionDSGraph*> &N = DSInfo[F];
|
|
|
|
delete N.first;
|
|
|
|
delete N.second;
|
|
|
|
N.first = N.second = 0;
|
|
|
|
}
|
|
|
|
|
2002-03-26 22:38:45 +00:00
|
|
|
// print - Print out the analysis results...
|
|
|
|
void print(std::ostream &O, Module *M) const;
|
|
|
|
|
|
|
|
// If the pass pipeline is done with this pass, we can release our memory...
|
|
|
|
virtual void releaseMemory();
|
|
|
|
|
2002-04-27 06:56:12 +00:00
|
|
|
// getAnalysisUsage - This obviously provides a call graph
|
|
|
|
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
|
|
|
|
AU.setPreservesAll();
|
|
|
|
AU.addProvided(ID);
|
2002-03-26 22:38:45 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|