#define LLVM_ANALYSIS_DATA_STRUCTURE_H
#include "llvm/Pass.h"
-#include <set>
+#include "Support/hash_set"
class Type;
+class CallInst;
class DSGraph;
class DSNode;
class DSCallSite;
//
class LocalDataStructures : public Pass {
// DSInfo, one graph for each function
- std::map<const Function*, DSGraph*> DSInfo;
+ hash_map<Function*, DSGraph*> DSInfo;
+ DSGraph *GlobalsGraph;
public:
~LocalDataStructures() { releaseMemory(); }
virtual bool run(Module &M);
+ bool hasGraph(const Function &F) const {
+ return DSInfo.find(const_cast<Function*>(&F)) != DSInfo.end();
+ }
+
// getDSGraph - Return the data structure graph for the specified function.
DSGraph &getDSGraph(const Function &F) const {
- std::map<const Function*, DSGraph*>::const_iterator I = DSInfo.find(&F);
+ hash_map<Function*, DSGraph*>::const_iterator I =
+ DSInfo.find(const_cast<Function*>(&F));
assert(I != DSInfo.end() && "Function not in module!");
return *I->second;
}
+ DSGraph &getGlobalsGraph() const { return *GlobalsGraph; }
+
// print - Print out the analysis results...
void print(std::ostream &O, const Module *M) const;
//
class BUDataStructures : public Pass {
// DSInfo, one graph for each function
- std::map<const Function*, DSGraph*> DSInfo;
+ hash_map<Function*, DSGraph*> DSInfo;
+ DSGraph *GlobalsGraph;
+ hash_multimap<CallInst*, Function*> ActualCallees;
public:
~BUDataStructures() { releaseMemory(); }
virtual bool run(Module &M);
+ bool hasGraph(const Function &F) const {
+ return DSInfo.find(const_cast<Function*>(&F)) != DSInfo.end();
+ }
+
// getDSGraph - Return the data structure graph for the specified function.
DSGraph &getDSGraph(const Function &F) const {
- std::map<const Function*, DSGraph*>::const_iterator I = DSInfo.find(&F);
+ hash_map<Function*, DSGraph*>::const_iterator I =
+ DSInfo.find(const_cast<Function*>(&F));
assert(I != DSInfo.end() && "Function not in module!");
return *I->second;
}
- // print - Print out the analysis results...
+ DSGraph &getGlobalsGraph() const { return *GlobalsGraph; }
+
+ // print - Print out the analysis results...
void print(std::ostream &O, const Module *M) const;
// If the pass pipeline is done with this pass, we can release our memory...
AU.setPreservesAll();
AU.addRequired<LocalDataStructures>();
}
+
+ typedef hash_multimap<CallInst*, Function*> ActualCalleesTy;
+ const ActualCalleesTy &getActualCallees() const {
+ return ActualCallees;
+ }
+
private:
- DSGraph &calculateGraph(Function &F);
+ void calculateGraph(DSGraph &G);
+
+ void calculateReachableGraphs(Function *F);
+
+
+ DSGraph &getOrCreateGraph(Function *F);
+
+ unsigned calculateGraphs(Function *F, std::vector<Function*> &Stack,
+ unsigned &NextID,
+ hash_map<Function*, unsigned> &ValMap);
};
//
class TDDataStructures : public Pass {
// DSInfo, one graph for each function
- std::map<const Function*, DSGraph*> DSInfo;
- std::set<const Function*> GraphDone;
+ hash_map<Function*, DSGraph*> DSInfo;
+ hash_set<Function*> ArgsRemainIncomplete;
+ DSGraph *GlobalsGraph;
public:
- ~TDDataStructures() { releaseMemory(); }
+ ~TDDataStructures() { releaseMyMemory(); }
virtual bool run(Module &M);
+ bool hasGraph(const Function &F) const {
+ return DSInfo.find(const_cast<Function*>(&F)) != DSInfo.end();
+ }
+
// getDSGraph - Return the data structure graph for the specified function.
DSGraph &getDSGraph(const Function &F) const {
- std::map<const Function*, DSGraph*>::const_iterator I = DSInfo.find(&F);
+ hash_map<Function*, DSGraph*>::const_iterator I =
+ DSInfo.find(const_cast<Function*>(&F));
assert(I != DSInfo.end() && "Function not in module!");
return *I->second;
}
+ DSGraph &getGlobalsGraph() const { return *GlobalsGraph; }
+
// print - Print out the analysis results...
void print(std::ostream &O, const Module *M) const;
// If the pass pipeline is done with this pass, we can release our memory...
- virtual void releaseMemory();
+ virtual void releaseMyMemory();
// getAnalysisUsage - This obviously provides a data structure graph.
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
AU.setPreservesAll();
AU.addRequired<BUDataStructures>();
}
+
private:
- void calculateGraph(Function &F);
+ void inlineGraphIntoCallees(DSGraph &G);
DSGraph &getOrCreateDSGraph(Function &F);
-
- void ResolveCallSite(DSGraph &Graph, const DSCallSite &CallSite);
+ void ComputePostOrder(Function &F, hash_set<DSGraph*> &Visited,
+ std::vector<DSGraph*> &PostOrder,
+ const BUDataStructures::ActualCalleesTy &ActualCallees);
};
#endif