0
votes

I am a beginner in writing LLVM Pass, and I was going through the documentation about writing my own LLVM pass and then run it with opt tool, i.e

/llvm/bin/opt -load /llvm/lib/LLVMHello.so  -hello input.ll

Here, my pass is Hello.cpp and a C function is in input.c which is converted to input.ll by Clang.

My question is can we run our pass without using opt tool i.e.

./hello input.ll

Is there any method to run a pass like above such method?

1
if you're just looking for convenience, perhaps a shell script would be adequate? - kmdreko
opt is dependent on many llvm libraries and in nerd language it is like a nintendo nes console which can use many games' nes cartridges(llvm passes). you can make a independent opt tool binary specific for your pass using api hooks in opt itself and link with llvm libraries, but it is NOT a good design and not worth spending time, but it is upto you, for the start point you can start looking into the tools/opt/CMakeLists.txt for dependencies and source files for api hooks. - Chirag Patel

1 Answers

1
votes

After attaining a valid Module, for example, via llvm::parseBitcodeFile, all actions you need are just creating llvm::legacy::Passmanager, invoking llvm::legacy::Passmanager::add to add passes and finally invoking llvm::legacy::Passmanager::run on your module.

opt use a class derived from llvm::legacy::Passmanager but actually call methods in the base class to cope with modules.