Chris Lattner | 10c91cc | 2003-10-28 22:11:31 +0000 | [diff] [blame] | 1 | #!/usr/bin/perl -w |
| 2 | # |
| 3 | # Program: profile.pl |
| 4 | # |
| 5 | # Synopsis: Insert instrumentation code into a program, run it with the JIT, |
| 6 | # then print out a profile report. |
| 7 | # |
| 8 | # Syntax: profile.pl [OPTIONS] bytecodefile <arguments> |
| 9 | # |
| 10 | # OPTIONS may include one or more of the following: |
Chris Lattner | 2c14d253 | 2003-10-28 22:52:05 +0000 | [diff] [blame] | 11 | # -block - Enable basic block level profiling |
Chris Lattner | 10c91cc | 2003-10-28 22:11:31 +0000 | [diff] [blame] | 12 | # |
Chris Lattner | 3538c9d | 2003-10-29 21:51:00 +0000 | [diff] [blame^] | 13 | # Any unrecognized options are passed into the invocation of llvm-prof |
| 14 | # |
Chris Lattner | 10c91cc | 2003-10-28 22:11:31 +0000 | [diff] [blame] | 15 | |
| 16 | my $ProfilePass = "-insert-function-profiling"; |
| 17 | |
Chris Lattner | 3538c9d | 2003-10-29 21:51:00 +0000 | [diff] [blame^] | 18 | my $LLVMProfOpts = ""; |
| 19 | |
Chris Lattner | 10c91cc | 2003-10-28 22:11:31 +0000 | [diff] [blame] | 20 | # Parse arguments... |
| 21 | while (scalar(@ARGV) and ($_ = $ARGV[0], /^[-+]/)) { |
| 22 | shift; |
| 23 | last if /^--$/; # Stop processing arguments on -- |
| 24 | |
| 25 | # List command line options here... |
Chris Lattner | 2c14d253 | 2003-10-28 22:52:05 +0000 | [diff] [blame] | 26 | if (/^-block$/) { $ProfilePass = "-insert-block-profiling"; next; } |
Chris Lattner | 10c91cc | 2003-10-28 22:11:31 +0000 | [diff] [blame] | 27 | |
Chris Lattner | 3538c9d | 2003-10-29 21:51:00 +0000 | [diff] [blame^] | 28 | # Otherwise, pass the option on to llvm-prof |
| 29 | $LLVMProfOpts .= " " . $_; |
Chris Lattner | 10c91cc | 2003-10-28 22:11:31 +0000 | [diff] [blame] | 30 | } |
| 31 | |
| 32 | die "Must specify LLVM bytecode file as first argument!" if (@ARGV == 0); |
| 33 | |
| 34 | my $BytecodeFile = $ARGV[0]; |
| 35 | |
| 36 | shift @ARGV; |
| 37 | |
| 38 | my $LLIPath = `which lli`; |
| 39 | $LLIPath = `dirname $LLIPath`; |
| 40 | chomp $LLIPath; |
| 41 | |
| 42 | my $LibProfPath = $LLIPath . "/../../lib/Debug/libprofile_rt.so"; |
| 43 | |
Chris Lattner | 2c14d253 | 2003-10-28 22:52:05 +0000 | [diff] [blame] | 44 | system "opt $ProfilePass < $BytecodeFile | lli -fake-argv0 '$BytecodeFile'" . |
| 45 | " -load $LibProfPath - " . (join ' ', @ARGV); |
Chris Lattner | 10c91cc | 2003-10-28 22:11:31 +0000 | [diff] [blame] | 46 | |
Chris Lattner | 3538c9d | 2003-10-29 21:51:00 +0000 | [diff] [blame^] | 47 | system "llvm-prof $LLVMProfOpts $BytecodeFile"; |