How do I use an exisiting function pass from my LLVM - pass?

前提是你 提交于 2019-11-30 04:53:14

问题


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 ?


回答1:


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);


来源:https://stackoverflow.com/questions/9333726/how-do-i-use-an-exisiting-function-pass-from-my-llvm-pass

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!