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 basicblock-level profiling
12 # -function - Enable function-level profiling
13 # -o <filename> - Emit profiling information to the specified file, instead
16 # Any unrecognized options are passed into the invocation of llvm-prof
19 my $ProfilePass = "-insert-block-profiling";
21 my $LLVMProfOpts = "";
26 while (scalar(@ARGV) and ($_ = $ARGV[0], /^[-+]/)) {
28 last if /^--$/; # Stop processing arguments on --
30 # List command line options here...
31 if (/^-?-block$/) { $ProfilePass = "-insert-block-profiling"; next; }
32 if (/^-?-function$/) { $ProfilePass = "-insert-function-profiling"; next; }
33 if (/^-?-o$/) { # Read -o filename...
34 die "-o option requires a filename argument!" if (!scalar(@ARGV));
35 $ProgramOpts .= " -llvmprof-output $ARGV[0]";
36 $ProfileFile = $ARGV[0];
41 print "OVERVIEW: profile.pl - Instrumentation and profile printer.\n\n";
42 print "USAGE: profile.pl [options] program.bc <program args>\n\n";
44 print " -block - Enable basicblock-level profiling\n";
45 print " -function - Enable function-level profiling\n";
46 print " -o <file> - Specify an output file other than llvm-prof.out.\n";
47 print " -help - Print this usage information\n";
48 print "\nAll other options are passed into llvm-prof.\n";
52 # Otherwise, pass the option on to llvm-prof
53 $LLVMProfOpts .= " " . $_;
56 die "Must specify LLVM bytecode file as first argument!" if (@ARGV == 0);
58 my $BytecodeFile = $ARGV[0];
62 my $LLIPath = `which lli`;
63 $LLIPath = `dirname $LLIPath`;
66 my $LibProfPath = $LLIPath . "/../../lib/Debug/libprofile_rt.so";
68 system "opt -q $ProfilePass < $BytecodeFile | lli -fake-argv0 '$BytecodeFile'" .
69 " -load $LibProfPath -$ProgramOpts " . (join ' ', @ARGV);
71 system "llvm-prof $LLVMProfOpts $BytecodeFile $ProfileFile";