-
Notifications
You must be signed in to change notification settings - Fork 0
Home
- LLVM tutorials
- Scott's presentation on getting started with LLVM
- LLVM generates C++ code that emits bitcode instructions
- The sometime's accurate programmer's manual for LLVM - A good starting point
- LLVM Commands - many useful utilities here ;)
- LLVM Dev Meeting Youtube Channel, many interesting talks
- The Instruction Visitor class, lets you specify cleanly actions to be taken on different types of instructions
- Introduction to LLVM (Talk), FOSDEM 2018
- Introduction to LLVM (Youtube), FOSDEM 2018
- Introduction to LLVM (Slides & Code), FOSDEM 2018
- Mapping High Level Constructs to LLVM IR
- Hot Examples - Find LLVM examples of functions and classes
-
Please clone the LLVM git (https://github.com/S2-Lab/LLVM) below
git clone https://github.com/S2-Lab/LLVM
-
Before build LLVM, please run the following script to install all related packages.
-
Run ./LLVM/build.sh to build llvm.
-
After building LLVM, you can check new
clang
orclang++
from./build/bin
directory. -
If you give
-fsanitize=s2lab
option (e.g.,./build/bin/clang++ test.cpp -fsanitize=s2lab
), you can run the our default llvm path and runtime library.- default LLVM pass file: https://github.com/S2-Lab/LLVM/blob/main/LLVM/src/llvm-files/S2LabPass.cpp
- default runtime library pass file: https://github.com/S2-Lab/LLVM/blob/main/LLVM/src/compiler-rt-files/s2lab.cc
-
After modifying LLVM (e.g., LLVM pass or runtime library), please build LLVM again using ninja from the build directory (e.g.,
./build/ninja
).
You shall build up a test suite of several bitcode files by compiling test C programs with "-S -emit-llvm." You shall test your your pass by running opt on these bitcode files.
Use the lldb you built yourself to debug your pass, not gdb. Then you have get have this: http://homes.cs.washington.edu/~bholt/posts/llvm-debugging.html
You may use an lldbinit file to automate starting your process, setting breakpoints, etc.
If you disagree with me about whatever, make your own workflow but at least know you need "-fstandalone-debug" to get lldb to print LLVM stuff nicely.
You want to implement X in LLVM. You shall find a place in the LLVM source code that does something like X and use it as a guide to write your implementation of X.
CMake can generate projects for Eclipse, KDevelop, Visual Studio, etc. You could try these things. Scott has. Scott always goes back to Vim.
Scott recommends YouCompleteMe for vim and using grep to search the LLVM code base when YouCompleteMe is not enough.
You should look at these patches for guidelines on how to add new functionality:
You probably want a command line option so you can benchmark with and without your instrumentation.
You can do this: http://bholt.org/posts/llvm-commandline.html
The gotcha is if your pass is in LLVM (not clang) you need -mllvm before your option
For example:
clang
-mllvm
-dataconf
test.c
The LLVM build takes a really long time. You should use -DBUILD_SHARED_LIBS at least. For more information on speeding up your build see:
http://blogs.s-osg.org/a-conclusion-to-accelerating-your-build-with-clang
http://blogs.s-osg.org/an-introduction-to-accelerating-your-build-with-clang/
These are some notes on using LLDB to debug you custom LLVM
First you will need a version of LLDB that matches you LLVM (see scotts notes on building LLVM
Then run your build command with -v, this will printout the really long nasty command actually given to the linker
clang -v <your build options>
Get the long nasty command to the linker and run
lldb -- <long nasty command>
Use the up command until you get to a location you recognize
(lldb) up