This project is mainly used to save some practices of writing llvm pass, which is helpful for people who are unfamiliar with LLVM.
Introduce some information about several directories.
pass_example: there are some llvm pass example, like iterate BasicBlocks
./info.txt: 对pass的功能进行说明
test_program: there are some C program, which is used to
write_ir: 用llvm架构,直接编写IR
notice: 这些文件要放到 example 目录下
Notice: More information you can see in dir's doc file
-
You should compile the LLVM for your platform
-
Select a LLVM Pass example, and copy it in LLVM
cp -R pass_example/${LLVM_PASS} ${LLVM_HOME}/lib/Transforms
add the pass_dir's description into CMakeLists.txt, just like "add_subdirectory(MyHello)"
cd ${LLVM_BUILD}
make
-
Test the LLVM Pass
clang -emit-llvm -S -o ${TEST_FILE}.ll test_program/${TEST_FILE}.c
opt -load ${LLVM_BUILD}/lib/LLVM${LLVM_PASS}.so -${LLVM_PASS_RegisterName} ${TEST_FILE}.ll
例子:
clang -emit-llvm -o main.ll -S main.c
opt -load ~/develop/llvm_risc_ise/llvm_4_build/lib/LLVMcountOpcode.so -opcodeCounter main_itrBB.ll
Notice:
LLVM_HOME: llvm's home dir
LLVM_BUILD: the dir which is uesd to build llvm
LLVM_PASS: the llvm pass which you want to test
LLVM_PASS_RegisterName: the name used to register pass
TEST_FILE: test C file