2002-10-01 22:34:45 +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"
|
|
|
|
|
|
|
|
class Type;
|
2002-10-02 22:14:17 +00:00
|
|
|
class DSGraph;
|
2002-10-17 04:23:05 +00:00
|
|
|
class DSNodeHandle;
|
2002-10-20 18:08:55 +00:00
|
|
|
class DSCallSite;
|
2002-07-10 22:42:17 +00:00
|
|
|
class LocalDataStructures; // A collection of local graphs for a program
|
2002-07-18 00:11:28 +00:00
|
|
|
class BUDataStructures; // A collection of bu graphs for a program
|
2002-07-18 16:12:08 +00:00
|
|
|
class TDDataStructures; // A collection of td graphs for a program
|
2002-07-10 22:42:17 +00:00
|
|
|
|
2002-10-01 22:34:45 +00:00
|
|
|
// FIXME: move this stuff to a private header
|
|
|
|
namespace DataStructureAnalysis {
|
|
|
|
// isPointerType - Return true if this first class type is big enough to hold
|
|
|
|
// a pointer.
|
2002-03-30 09:07:51 +00:00
|
|
|
//
|
2002-10-01 22:34:45 +00:00
|
|
|
bool isPointerType(const Type *Ty);
|
2002-07-10 22:42:17 +00:00
|
|
|
}
|
2002-03-26 22:38:45 +00:00
|
|
|
|
|
|
|
|
2002-07-10 22:42:17 +00:00
|
|
|
// LocalDataStructures - The analysis that computes the local data structure
|
|
|
|
// graphs for all of the functions in the program.
|
2002-03-26 22:38:45 +00:00
|
|
|
//
|
2002-07-18 00:11:28 +00:00
|
|
|
// FIXME: This should be a Function pass that can be USED by a Pass, and would
|
|
|
|
// be automatically preserved. Until we can do that, this is a Pass.
|
|
|
|
//
|
2002-07-10 22:42:17 +00:00
|
|
|
class LocalDataStructures : public Pass {
|
|
|
|
// DSInfo, one graph for each function
|
2002-07-30 22:02:04 +00:00
|
|
|
std::map<const Function*, DSGraph*> DSInfo;
|
2002-03-26 22:38:45 +00:00
|
|
|
public:
|
2002-07-10 22:42:17 +00:00
|
|
|
~LocalDataStructures() { releaseMemory(); }
|
2002-03-26 22:38:45 +00:00
|
|
|
|
2002-07-10 22:42:17 +00:00
|
|
|
virtual bool run(Module &M);
|
2002-03-26 22:38:45 +00:00
|
|
|
|
2002-07-10 22:42:17 +00:00
|
|
|
// getDSGraph - Return the data structure graph for the specified function.
|
2002-07-30 22:02:04 +00:00
|
|
|
DSGraph &getDSGraph(const Function &F) const {
|
|
|
|
std::map<const Function*, DSGraph*>::const_iterator I = DSInfo.find(&F);
|
2002-07-10 22:42:17 +00:00
|
|
|
assert(I != DSInfo.end() && "Function not in module!");
|
|
|
|
return *I->second;
|
2002-03-29 21:23:29 +00:00
|
|
|
}
|
|
|
|
|
2002-03-26 22:38:45 +00:00
|
|
|
// print - Print out the analysis results...
|
2002-07-27 01:12:15 +00:00
|
|
|
void print(std::ostream &O, const Module *M) const;
|
2002-03-26 22:38:45 +00:00
|
|
|
|
|
|
|
// If the pass pipeline is done with this pass, we can release our memory...
|
|
|
|
virtual void releaseMemory();
|
|
|
|
|
2002-07-10 22:42:17 +00:00
|
|
|
// getAnalysisUsage - This obviously provides a data structure graph.
|
2002-04-27 06:56:12 +00:00
|
|
|
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
|
|
|
|
AU.setPreservesAll();
|
2002-03-26 22:38:45 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2002-07-18 00:11:28 +00:00
|
|
|
// BUDataStructures - The analysis that computes the interprocedurally closed
|
|
|
|
// data structure graphs for all of the functions in the program. This pass
|
|
|
|
// only performs a "Bottom Up" propogation (hence the name).
|
|
|
|
//
|
|
|
|
class BUDataStructures : public Pass {
|
2002-10-17 04:23:05 +00:00
|
|
|
private:
|
2002-07-18 00:11:28 +00:00
|
|
|
// DSInfo, one graph for each function
|
2002-07-30 22:02:04 +00:00
|
|
|
std::map<const Function*, DSGraph*> DSInfo;
|
2002-10-20 18:08:55 +00:00
|
|
|
std::map<const Function*, std::vector<DSCallSite> > CallSites;
|
2002-07-18 00:11:28 +00:00
|
|
|
public:
|
|
|
|
~BUDataStructures() { releaseMemory(); }
|
|
|
|
|
|
|
|
virtual bool run(Module &M);
|
|
|
|
|
|
|
|
// getDSGraph - Return the data structure graph for the specified function.
|
2002-07-30 22:02:04 +00:00
|
|
|
DSGraph &getDSGraph(const Function &F) const {
|
|
|
|
std::map<const Function*, DSGraph*>::const_iterator I = DSInfo.find(&F);
|
2002-07-18 00:11:28 +00:00
|
|
|
assert(I != DSInfo.end() && "Function not in module!");
|
|
|
|
return *I->second;
|
|
|
|
}
|
2002-07-30 22:02:04 +00:00
|
|
|
|
2002-10-20 18:08:55 +00:00
|
|
|
const std::vector<DSCallSite> *getCallSites(const Function &F) const {
|
|
|
|
std::map<const Function*, std::vector<DSCallSite> >::const_iterator I
|
2002-10-17 04:23:05 +00:00
|
|
|
= CallSites.find(&F);
|
|
|
|
return I != CallSites.end() ? &I->second : 0;
|
|
|
|
}
|
|
|
|
|
2002-07-18 00:11:28 +00:00
|
|
|
// print - Print out the analysis results...
|
2002-07-27 01:12:15 +00:00
|
|
|
void print(std::ostream &O, const Module *M) const;
|
2002-07-18 00:11:28 +00:00
|
|
|
|
|
|
|
// If the pass pipeline is done with this pass, we can release our memory...
|
|
|
|
virtual void releaseMemory();
|
|
|
|
|
|
|
|
// getAnalysisUsage - This obviously provides a data structure graph.
|
|
|
|
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
|
|
|
|
AU.setPreservesAll();
|
2002-08-08 19:01:30 +00:00
|
|
|
AU.addRequired<LocalDataStructures>();
|
2002-07-18 00:11:28 +00:00
|
|
|
}
|
|
|
|
private:
|
|
|
|
DSGraph &calculateGraph(Function &F);
|
|
|
|
};
|
|
|
|
|
2002-07-18 16:12:08 +00:00
|
|
|
// TDDataStructures - Analysis that computes new data structure graphs
|
|
|
|
// for each function using the closed graphs for the callers computed
|
|
|
|
// by the bottom-up pass.
|
|
|
|
//
|
|
|
|
class TDDataStructures : public Pass {
|
|
|
|
// DSInfo, one graph for each function
|
2002-07-30 22:02:04 +00:00
|
|
|
std::map<const Function*, DSGraph*> DSInfo;
|
2002-07-18 16:12:08 +00:00
|
|
|
public:
|
|
|
|
~TDDataStructures() { releaseMemory(); }
|
|
|
|
|
|
|
|
virtual bool run(Module &M);
|
|
|
|
|
|
|
|
// getDSGraph - Return the data structure graph for the specified function.
|
2002-07-30 22:02:04 +00:00
|
|
|
DSGraph &getDSGraph(const Function &F) const {
|
|
|
|
std::map<const Function*, DSGraph*>::const_iterator I = DSInfo.find(&F);
|
2002-07-18 16:12:08 +00:00
|
|
|
assert(I != DSInfo.end() && "Function not in module!");
|
|
|
|
return *I->second;
|
|
|
|
}
|
|
|
|
|
|
|
|
// print - Print out the analysis results...
|
2002-07-27 01:12:15 +00:00
|
|
|
void print(std::ostream &O, const Module *M) const;
|
2002-07-18 16:12:08 +00:00
|
|
|
|
|
|
|
// If the pass pipeline is done with this pass, we can release our memory...
|
|
|
|
virtual void releaseMemory();
|
|
|
|
|
|
|
|
// getAnalysisUsage - This obviously provides a data structure graph.
|
|
|
|
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
|
|
|
|
AU.setPreservesAll();
|
2002-08-08 19:01:30 +00:00
|
|
|
AU.addRequired<BUDataStructures>();
|
2002-07-18 16:12:08 +00:00
|
|
|
}
|
|
|
|
private:
|
|
|
|
DSGraph &calculateGraph(Function &F);
|
2002-10-17 04:23:05 +00:00
|
|
|
|
|
|
|
void ResolveCallSite(DSGraph &Graph,
|
2002-10-20 18:08:55 +00:00
|
|
|
const DSCallSite &CallSite);
|
2002-07-18 16:12:08 +00:00
|
|
|
};
|
2002-10-01 22:34:45 +00:00
|
|
|
|
2002-10-02 21:55:52 +00:00
|
|
|
#if 0
|
|
|
|
// GlobalDSGraph - A common graph for all the globals and their outgoing links
|
|
|
|
// to externally visible nodes. This includes GlobalValues, New nodes,
|
|
|
|
// Cast nodes, and Calls. This graph can only be used by one of the
|
|
|
|
// individual function graphs, and it goes away when they all go away.
|
|
|
|
//
|
|
|
|
class GlobalDSGraph : public DSGraph {
|
|
|
|
hash_set<const DSGraph*> Referrers;
|
|
|
|
void addReference(const DSGraph* referrer);
|
|
|
|
void removeReference(const DSGraph* referrer);
|
|
|
|
friend class DSGraph; // give access to Referrers
|
|
|
|
|
|
|
|
GlobalDSGraph(const GlobalDSGraph &GlobalDSG); // Do not implement
|
|
|
|
|
|
|
|
// Helper function for cloneGlobals and cloneCalls
|
|
|
|
DSNode* cloneNodeInto(DSNode *OldNode,
|
|
|
|
std::map<const DSNode*, DSNode*> &NodeCache,
|
|
|
|
bool GlobalsAreFinal = false);
|
|
|
|
|
|
|
|
public:
|
|
|
|
GlobalDSGraph(); // Create an empty DSGraph
|
|
|
|
virtual ~GlobalDSGraph();
|
|
|
|
|
|
|
|
void cloneGlobals(DSGraph& Graph, bool CloneCalls = false);
|
|
|
|
void cloneCalls (DSGraph& Graph);
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2002-10-01 22:34:45 +00:00
|
|
|
#endif
|