Integrating LLVM passes

你说的曾经没有我的故事 提交于 2019-12-09 06:46:17

问题


This maybe a rookie question but is there a way to integrate my LLVM modulepass to be called by default during the transformation phase?

Right now I am using this syntax to load my pass and register it

 ~/llvm/llvm/build/Debug+Asserts/bin/clang -Xclang -load -Xclang ~/llvm/llvm/build/Debug+Asserts/lib/SOMEPASSLIB.so

(The problem is when I want to build some package with this pass, the compiler accepts it when I say, pass the loading part as CFLAGS env variable, but some makefiles use CFLAGS for linking too, and the linker has no idea what it can do with this information and fails the build :\ )


回答1:


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.



来源:https://stackoverflow.com/questions/29910051/integrating-llvm-passes

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