LLVM code examples
Each of the below C functions examples was compiled with:
clang -S -emit-llvm [options]Note that using -O, especially, may inline functions and eliminate code so that the generated LLVM code does not perform the same operations as the original C code.
Topic | Source | clang source.c | clang -O1 source.c | clang -O source.c |
---|---|---|---|---|
Arithmetic | arith.c | arith.ll | arith.O1.ll | arith.O.ll |
Bitwise | bitwise.c | bitwise.ll | bitwise.O1.ll | bitwise.O.ll |
Shifts | shift.c | shift.ll | shift.O1.ll | shift.O.ll |
Comparisons | compare.c | compare.ll | compare.O1.ll | compare.O.ll |
Local variable | var.c | var.ll | var.O1.ll | var.O.ll |
If | if.c | if.ll | if.O1.ll | if.O.ll |
While | while.c | while.ll | while.O1.ll | while.O.ll |
Calls | call.c | call.ll | call.O1.ll | call.O.ll |
Arrays | array.c | array.ll | array.O1.ll | array.O.ll |
Structs | struct.c | struct.ll | struct.O1.ll | struct.O.ll |