Reputation: 31
I have created a pass that pathprofiles and then stores results in different data structures such as blocks corresponding to the paths, edges in paths etc. I have different variables and data structures for each of these.
Is there a way to use these variables directly in another pass that i write? If yes, how? (Im not sure if getAnalysisUsage works for this?) Urgent help required
Upvotes: 0
Views: 109
Reputation: 9120
This answer might be late, but I had the same question, ran across your post and thanks to Oak was pointed into the right direction. So I wanted to share some code here.
Suppose you have two passes, the first one is your PathProfilePass
and the second one is your DoSomethingPass
. The first pass contains the data that you collect and share with the second path; nothing special needs to be done here:
/// Path profiling to gather heaps of data.
class PathProfilePass: public llvm::ModulePass {
public:
virtual bool runOnModule(llvm::Module &M) {
// Create goodness for edges and paths.
...
}
std::set<Edges> edges; ///< All the edges this pass collects.
std::set<Paths> paths; ///< All the paths this pass collects.
};
The interesting stuff happens in the second pass. Two things you need to do here:
Code-wise it would look something like this for the second pass:
/// Doing something with edge and path informations.
class DoSomethingPass: public llvm::ModulePass {
public:
/// Specify the dependency of this pass on PathProfilePass.
virtual void getAnalysisUsage(llvm::AnalysisUsage &AU) const {
AU.addRequired<PathProfilePass>();
}
/// Use the data of the PathProfilePass.
virtual bool runOnModule(llvm::Module &M) {
PathProfilePass &PPP = getAnalysis<PathProfilePass>();
// Get the edges and paths from the first pass.
std::set<Edges> &edges = PPP.edges;
std::set<Paths> &paths = PPP.paths;
// Now you can noodle over that data.
...
}
};
Disclaimer: I haven't compiled this code, but this is an adaptation to your example of what works for me. Hope this is useful :-)
Upvotes: 1
Reputation: 26868
Set a dependency from the 2nd pass to the 1st pass (via overriding getAnalysisUsage
and invoking getAnalysis
- see the programmer's guide to writing a pass on how to do that). Once you get an instance of the 1st pass, you can use it just like any other C++ object.
Upvotes: 0