Integrating LLVM passes

瘦欲@ 提交于 2019-12-03 09:23:27

There are couple of files you need to modify in order to define your pass inside LLVM core:

i) inside your pass: loadable pass is registered like this (assuming your pass name is FunctionInfo):

char FunctionInfo::ID = 0;
RegisterPass<FunctionInfo> X("function-info", "Functions Information"); 

you need to change it to be like this:

char FunctionInfo::ID = 0;
INITIALIZE_PASS_BEGIN(FunctionInfo, "function-info", "Gathering Function info",  false, false)
INITIALIZE_PASS_DEPENDENCY(DominatorTree)
INITIALIZE_PASS_DEPENDENCY(LoopInfo)
.... // initialize all passes which your pass needs
INITIALIZE_PASS_END(FunctionInfo, "function-info", "gathering function info", false, false)

ModulePass *llvm::createFunctionInfoPass() { return new FunctionInfo(); }

ii) you need to register your pass inside llvm as well, at least in InitializePasses.h and LinkAllPasses.h. in LinkAllPasses.h you should add :

(void)llvm::createFunctionInfoPass();

and in InitializePasses.h add :

void initializeFunctionInfoPass(PassRegistry &);

iii) beside this modifications you might need to change another file depend on where you are going to add your pass. for instance if you are going to add it in lib/Analysis/ you also need to add one line to Analysis.cpp as below :

 initializeFunctionInfoPass(Registry);

or if you are going to add it as new Scalar Transform you need to modify both Scalar.h and Scalar.cpp likewise.

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