blob: c91ac1a8a55f5e6e6383966481cb2d6324dfb000 [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 Lattner10c91cc2003-10-28 22:11:31 +000013
14my $ProfilePass = "-insert-function-profiling";
15
16# Parse arguments...
17while (scalar(@ARGV) and ($_ = $ARGV[0], /^[-+]/)) {
18 shift;
19 last if /^--$/; # Stop processing arguments on --
20
21 # List command line options here...
Chris Lattner2c14d2532003-10-28 22:52:05 +000022 if (/^-block$/) { $ProfilePass = "-insert-block-profiling"; next; }
Chris Lattner10c91cc2003-10-28 22:11:31 +000023
24 print "Unknown option: $_ : ignoring!\n";
25}
26
27die "Must specify LLVM bytecode file as first argument!" if (@ARGV == 0);
28
29my $BytecodeFile = $ARGV[0];
30
31shift @ARGV;
32
33my $LLIPath = `which lli`;
34$LLIPath = `dirname $LLIPath`;
35chomp $LLIPath;
36
37my $LibProfPath = $LLIPath . "/../../lib/Debug/libprofile_rt.so";
38
Chris Lattner2c14d2532003-10-28 22:52:05 +000039system "opt $ProfilePass < $BytecodeFile | lli -fake-argv0 '$BytecodeFile'" .
40 " -load $LibProfPath - " . (join ' ', @ARGV);
Chris Lattner10c91cc2003-10-28 22:11:31 +000041
42system "llvm-prof $BytecodeFile";