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: |
| 11 | # NONE SO FAR |
| 12 | # |
| 13 | # |
| 14 | |
| 15 | |
| 16 | my $ProfilePass = "-insert-function-profiling"; |
| 17 | |
| 18 | # Parse arguments... |
| 19 | while (scalar(@ARGV) and ($_ = $ARGV[0], /^[-+]/)) { |
| 20 | shift; |
| 21 | last if /^--$/; # Stop processing arguments on -- |
| 22 | |
| 23 | # List command line options here... |
| 24 | #if (/^-enable-foo$/) { $FOO = 1; next; } |
| 25 | |
| 26 | print "Unknown option: $_ : ignoring!\n"; |
| 27 | } |
| 28 | |
| 29 | die "Must specify LLVM bytecode file as first argument!" if (@ARGV == 0); |
| 30 | |
| 31 | my $BytecodeFile = $ARGV[0]; |
| 32 | |
| 33 | shift @ARGV; |
| 34 | |
| 35 | my $LLIPath = `which lli`; |
| 36 | $LLIPath = `dirname $LLIPath`; |
| 37 | chomp $LLIPath; |
| 38 | |
| 39 | my $LibProfPath = $LLIPath . "/../../lib/Debug/libprofile_rt.so"; |
| 40 | |
| 41 | system "opt $ProfilePass < $BytecodeFile | lli -load $LibProfPath - " . |
| 42 | (join ' ', @ARGV); |
| 43 | |
| 44 | system "llvm-prof $BytecodeFile"; |