blob: d7c7ef3ddf3d9eae83bccca8e1eda9ac29d215af [file] [log] [blame]
Chris Lattner10c91cc2003-10-28 22:11:31 +00001#!/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 Lattner2c14d2532003-10-28 22:52:05 +000011# -block - Enable basic block level profiling
Chris Lattner10c91cc2003-10-28 22:11:31 +000012#
Chris Lattner3538c9d2003-10-29 21:51:00 +000013# Any unrecognized options are passed into the invocation of llvm-prof
14#
Chris Lattner10c91cc2003-10-28 22:11:31 +000015
16my $ProfilePass = "-insert-function-profiling";
17
Chris Lattner3538c9d2003-10-29 21:51:00 +000018my $LLVMProfOpts = "";
19
Chris Lattner10c91cc2003-10-28 22:11:31 +000020# Parse arguments...
21while (scalar(@ARGV) and ($_ = $ARGV[0], /^[-+]/)) {
22 shift;
23 last if /^--$/; # Stop processing arguments on --
24
25 # List command line options here...
Chris Lattner2c14d2532003-10-28 22:52:05 +000026 if (/^-block$/) { $ProfilePass = "-insert-block-profiling"; next; }
Chris Lattner10c91cc2003-10-28 22:11:31 +000027
Chris Lattner3538c9d2003-10-29 21:51:00 +000028 # Otherwise, pass the option on to llvm-prof
29 $LLVMProfOpts .= " " . $_;
Chris Lattner10c91cc2003-10-28 22:11:31 +000030}
31
32die "Must specify LLVM bytecode file as first argument!" if (@ARGV == 0);
33
34my $BytecodeFile = $ARGV[0];
35
36shift @ARGV;
37
38my $LLIPath = `which lli`;
39$LLIPath = `dirname $LLIPath`;
40chomp $LLIPath;
41
42my $LibProfPath = $LLIPath . "/../../lib/Debug/libprofile_rt.so";
43
Chris Lattner2c14d2532003-10-28 22:52:05 +000044system "opt $ProfilePass < $BytecodeFile | lli -fake-argv0 '$BytecodeFile'" .
45 " -load $LibProfPath - " . (join ' ', @ARGV);
Chris Lattner10c91cc2003-10-28 22:11:31 +000046
Chris Lattner3538c9d2003-10-29 21:51:00 +000047system "llvm-prof $LLVMProfOpts $BytecodeFile";