0

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?

2
  • if you're just looking for convenience, perhaps a shell script would be adequate? Commented Aug 7, 2018 at 19:03
  • 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. Commented Aug 10, 2018 at 6:42

1 Answer 1

1

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.

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.