define i32 @add1(i32 %a, i32 %b) {
entry:
%tmp1 = add i32 %a, %b
ret i32 %tmp1
}
define i32 @add2(i32 %a, i32 %b) {
entry:
%tmp1 = icmp eq i32 %a, 0
br i1 %tmp1, label %done, label %recurse
recurse:
%tmp2 = sub i32 %a, 1
%tmp3 = add i32 %b, 1
%tmp4 = call i32 @add2(i32 %tmp2, i32 %tmp3)
ret i32 %tmp4
done:
ret i32 %b
}
- LLVM IR (.ll) => [llvm-as] => BITCODE goop (.bc)
- LLVM BITCODE (.bc) => [llvm-dis] => LLVM IR (.ll)
-
clang -S -emit-llvm foo.c
: Produces foo.ll which is an LLVM IR file.- The
-emit-llvm
option can also be passed to the compiler front-end directly, and not the driver by means of -cc1:
-
clang -cc1 foo.c -emit-llvm
- Produces foo.ll with the IR. -cc1 adds some cool options like -ast-print. Check out -cc1 --help for more details.
-
llc foo.ll
- compiles LLVM IR further to assembly