langston-barrrett.github.io
LLVM IR
The intermediate representation used by the LLVM project, including Clang.
Generating Readable IR
clang -Xclang -disable-O0-optnone -S -O0 -emit-llvm -fno-discard-value-names -Wall -c example0.c
opt -mem2reg -S example.ll -o example-opt.ll
getelementptr
getelementptr
is for indexing into a struct or array. It looks like
this:
%tmp = getelementptr %struct.munger_struct, %struct.munger_struct* %P, i32 1, i32 0
- https://llvm.org/docs/GetElementPtr.html
- https://blog.yossarian.net/2020/09/19/LLVMs-getelementptr-by-example
Target Triples
These are used frequently as an example: https://clang.llvm.org/docs/CrossCompilation.html#target-triple
undef
and poison
- Pointers Are Complicated II, or: We need better language specs
- Taming Undefined Behavior in LLVM (PLDI 2017 - PLDI Research Papers) - PLDI 2017
Bitcode Format
Abreviations and Records
Records may have one of five types of values (doc):
- Fixed-width integers
- Variable-width integers
- Arrays
- Characters (specified in char6 format)
- Binary blobs
The types of arrays are specified weirdly.
Exceptions
See also C++#Exceptions.
Varargs/Variable Arity Functions
The Language Reference states:
The ‘va_arg’ instruction is used to access arguments passed through the “variable argument” area of a function call. It is used to implement the va_arg macro in C.
In practice, LLVM emits target/ABI-specific code rather than va_arg
, at least
for x86: https://godbolt.org/z/Wq4Gb7bKa.