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

Target Triples

These are used frequently as an example: https://clang.llvm.org/docs/CrossCompilation.html#target-triple

undef and poison

Bitcode Format

Abreviations and Records

Records may have one of five types of values (doc):

  1. Fixed-width integers
  2. Variable-width integers
  3. Arrays
  4. Characters (specified in char6 format)
  5. 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.