This procedure works in the LegUp 3.0 Virtual Box. It runs the LLVM profiler to determine the total number of times each basic block is executed during a program's execution. It does so by directly executing the LLVM IR using the LLVM interpreter.
We'll use the CHStone/mips benchmark as an example. Just follow these simple steps.
The “opt” command instruments the original IR and produces a new IR called mips_profile.ll. The new IR keeps track of run-time data as it executes.
The “lli” command executes the instrumented IR using the LLVM interpreter. The “-load” on the command-line is needed because the instrumentation code inserted by the “opt” command needs access to special functions in the “libprofile_rt.so” library. The profiling results are printed to a special file called “llvmprof.out”.
The “llvm-prof” command reads the instrumented IR and the profiling results and it prints out the IR with the profiling data.
So, you will see some output like this, which indicates the number of times each basic block is executed. It also indicates the number of times each edge in the control-flow graph is traversed.
; <label>:1 ; preds = %4, %0
;;; Basic block executed 2 times. %s.i.0 = phi i32* [ %tmp, %0 ], [ %6, %4 ] %2 = phi i32 [ 64, %0 ], [ %5, %4 ] %3 = icmp eq i32 %2, 0 br i1 %3, label %.legup_memset_4.exit_crit_edge, label %4 ;;; Out-edge counts: [1.000000e+00 -> .legup_memset_4.exit_crit_edge] [6.400000e+01 -> ]