5 # Synopsis: Insert instrumentation code into a program, run it with the JIT,
6 # then print out a profile report.
8 # Syntax: profile.pl [OPTIONS] bytecodefile <arguments>
10 # OPTIONS may include one or more of the following:
11 # -block - Enable basic block level profiling
13 # Any unrecognized options are passed into the invocation of llvm-prof
16 my $ProfilePass = "-insert-function-profiling";
18 my $LLVMProfOpts = "";
21 while (scalar(@ARGV) and ($_ = $ARGV[0], /^[-+]/)) {
23 last if /^--$/; # Stop processing arguments on --
25 # List command line options here...
26 if (/^-block$/) { $ProfilePass = "-insert-block-profiling"; next; }
28 # Otherwise, pass the option on to llvm-prof
29 $LLVMProfOpts .= " " . $_;
32 die "Must specify LLVM bytecode file as first argument!" if (@ARGV == 0);
34 my $BytecodeFile = $ARGV[0];
38 my $LLIPath = `which lli`;
39 $LLIPath = `dirname $LLIPath`;
42 my $LibProfPath = $LLIPath . "/../../lib/Debug/libprofile_rt.so";
44 system "opt $ProfilePass < $BytecodeFile | lli -fake-argv0 '$BytecodeFile'" .
45 " -load $LibProfPath - " . (join ' ', @ARGV);
47 system "llvm-prof $LLVMProfOpts $BytecodeFile";