This Pass is added using the old Pass Manager
- Copy the MyFirstPass folder inside "llvm-project/llvm/lib/Transforms/" also add "add_subdirectory(MyFirstPass)" inside "llvm-project/llvm/lib/ Transforms/CMakeLists.txt"
- make or build the LLVM again. It should create a "LLVMMyFirstPass.so" inside "build/lib/"
- How to load the shared object and execute: /home/amar/AMAR/LLVM/llvm-project/build/bin/opt -load /home/amar/AMAR/LLVM/llvm-project/build/lib/LLVMMyFirstPass.so -myfirstpass -enable-new-pm=0 < prog9.ll > /dev/null
This Pass is added using the new Pass Manager
- Copy the ".cpp" file inside MyFirstPass_new_PM folder to "llvm/lib/Transforms/Utils/MyFirstPass.cpp". Copy the ".h" file inside MyFirstPass_new_PM folder to "llvm/include/llvm/Transforms/Utils/MyFirstPass.h"
- Add "MyFirstPass.cpp" in "llvm/lib/Transforms/Utils/CMakeLists.txt"
- Add "FUNCTION_PASS("myfirstpass", MyFirstPass())" in "llvm/lib/Passes/PassRegistry.def"
- Add "#include "llvm/Transforms/Utils/MyFirstPass.h"" in "llvm/lib/Passes/PassBuilder.cpp"
- move to build folder and build the llvm again (make)
- How to use the added pass "build/bin/opt -disable-output ~/AMAR/c/risc_v_programs/prog9.ll -passes=helloworld"
This Pass is added using the old Pass Manager
- Copy the PrintBBname folder inside "llvm-project/llvm/lib/Transforms/" also add "add_subdirectory(PrintBBname)" inside "llvm-project/llvm/lib/ Transforms/CMakeLists.txt"
- make or build the LLVM again. It should create a "LLVMPrintBBname.so" inside "build/lib/"
- To load the shared object and execute: /home/amar/AMAR/LLVM/llvm-project/build/bin/opt -load /home/amar/AMAR/LLVM/llvm-project/build/lib/LLVMPrintBBname.so -print_bb_name -enable-new-pm=0 < LLVM_IR.ll > /dev/null
This plugin code also generate an executable apart from generating loadable ".so" file.
This plugin is out-of-tree implemetation of Constant Propogation. Out-of-tree means code does not need to been inside llvm-project and just needs the path to llvm build folder.
This is a copied and fixed version of "https://github.com/lac-dcc/llvm-course/tree/master/llvm-passes"
Below steps can be followed to create the executable and run the executable. Please also read README inside the folder.
- "mkdir build"
- "LLVM_INSTALL_DIR=/home/amar/AMAR/LLVM/llvm-project/build"
- "LLVM_OPT=$LLVM_INSTALL_DIR/bin/opt"
- "cmake -DLLVM_INSTALL_DIR=$LLVM_INSTALL_DIR -G "Unix Makefiles" -B build/ ."
- "cd build/"
- "make"
- "cd bin"
- "./addconst ../../examples/foo.ll"
- "cat out.ll"