Chapter 9 ( Appendix )

Command Line Tools

llvm-as

The assembler transforms the human readable LLVM assembly to LLVM bitcode.

Usage:

  1. $ clang -S -emit-llvm hello.c -c -o hello.ll
  2. $ llvm-as hello.ll -o hello.bc

llvm-dis

The disassembler transforms the LLVM bitcode to human readable LLVM assembly.

Usage:

  1. $ clang -emit-llvm hello.c -c -o hello.bc
  2. $ llvm-dis < hello.bc | less

lli

lli is the LLVM interpreter, which can directly execute LLVM bitcode.

Usage:

  1. $ clang -emit-llvm hello.c -c -o hello.bc
  2. $ lli hello.bc
  3. $ lli -use-mcjit hello.bc

llc

llc is the LLVM backend compiler, which translates LLVM bitcode to native code assembly.

Usage:

  1. $ clang -emit-llvm hello.c -c -o hello.bc
  2. $ llc hello.bc -o hello.s
  3. $ cc hello.s -o hello.native
  4. $ llc -march=x86-64 hello.bc -o hello.s
  5. $ llc -march=arm hello.bc -o hello.s

opt

opt reads LLVM bitcode, applies a series of LLVM to LLVM transformations and then outputs the resultant bitcode. opt can also be used to run a specific analysis on an input LLVM bitcode file and print out the resulting IR or bitcode.

Usage:

  1. $ clang -emit-llvm hello.c -c -o hello.bc
  2. $ opt -mem2reg hello.bc
  3. $ opt -simplifycfg hello.bc
  4. $ opt -inline hello.bc
  5. $ opt -dce hello.bc
  6. $ opt -analyze -view-cfg hello.bc
  7. $ opt -bb-vectorize hello.bc
  8. $ opt -loop-vectorize -force-vector-width=8

llvm-link

llvm-link links multiple LLVM modules into a single program. Together with opt this can be used to perform link-time optimizations.

Usage:

  1. $ llvm-link foo.ll bar.ll -o foobar.ll
  2. $ opt -std-compile-opts -std-link-opts -O3 foobar.bc -o optimized.bc