7

I have been using LLVM and I was confused how to use a different already present pass from my own pass ? Precisely my program needs Dominance Frontier Calculation for any given instruction. LLVM already has the Dominance function Class that is implemented as a function pass. How can i invoke it/make use of it in my Module Pass ?

4
  • Have you checked the docs? Because the last time I checked, the answer was there: llvm.org/docs/WritingAnLLVMPass.html Commented Feb 17, 2012 at 18:58
  • Add AU.addRequired<DominanceFrontier>(); to your pass getAnalysisUsage(AnalysisUsage &AU) method. Commented Feb 17, 2012 at 18:59
  • The documentation is really obscure and I had real problems deciphering it. An example would have helped. Commented Feb 17, 2012 at 19:09
  • What is your version of LLVM? What kind of information do you want to get? Commented Feb 17, 2012 at 19:12

1 Answer 1

4

WARNING: I have no real experience and answer may be incorrect or outdated. (it is based largely on outdated LLVM sources: version 1.3.)

Add an include:

#include "llvm/Analysis/DominanceFrontier.h"

If your pass if Function Pass, add to your class the method (if it is not implemented):

virtual void getAnalysisUsage(AnalysisUsage &AU) const { }

And put this into it:

 AU.addRequired<DominanceFrontier>();

Then, in your class runOnFunction method:

 DominanceFrontier *DF = &getAnalysis<DominanceFrontier>();

After this you can use:

    BasicBlock *BB = /* some BB */;
    DominanceFrontier::iterator DFI = DF->find(BB);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.