mongearray
mongearray

Reputation: 26

Calling a llvm pass outside of a pass

I am new to LLVM and C++ and was trying to write some code to perform static analysis. My static analysis needs access to memory dependence info, which in LLVM can be obtained using MemoryDependenceAnalysis. This analysis generates an object of type MemoryDependenceResults, which is precisely what I need. The only ways I've seen this object being obtained, though, is through an LLVM pass and that's not something I want. My impression is you have to write a pass to be able to use an existing pass. I was wondering is that true? Can I call a pass outside of a pass, i.e. regular code? Or alternatively can a llvm pass be invoked programmatically without needing to run the opt command?

What I need is a way to obtain this MemoryDependenceResults object in my program (which is not a pass) and then perform some more manipulations to it.

Upvotes: 1

Views: 605

Answers (1)

西风逍遥游
西风逍遥游

Reputation: 94

First, you can create a PassManager instance anywhere, add the pass into the manager and run it. Here are two PassManagers can be used - legacy or the new one. To make it simple, I recommend you try the legacy one first:

legacy::PassManager passManager;
passManager.add(new MemoryDependenceWrapperPass());
passManager.run(*module);

Second, if you wish to run a transform pass, you call it. But if you wish to run an analysis pass, you need at least a wrapper pass to get the analysis result since the API getAnalysis() is only available in a pass. (You can copy and rename MemoryDependenceWrapperPass to your version.)

Upvotes: 1

Related Questions