Walking through an example
In this section, we will walk you through a complete example of a textual representation of LLVM IR.
For this example, we will use the following snippet:
define i32 @foo(i32, i32, i32 %arg) {
entry:
%myid = add i32 %0, %1
%31 = mul i32 %myid, 2
%45 = shl i32 %31, 5
%"00~random~00" = udiv i32 %45, %arg
br label %46
br label %47
47:
ret i32 %"00~random~00"
}
In this example, you can see a function, foo
, that produces a 32-bit integer value (i32
) and takes three input arguments, all 32-bit integers (i32, i32, i32 %arg
). The first two arguments use implicit naming and are automatically bound to the identifiers %0
and %1
, respectively.
Note
The function’s arguments and basic block names are the only identifiers that do not need to be explicitly set. For all other values, even if you use the naming scheme of unnamed values, you must write their (non-)name down.
After the list of arguments...