Moved iterators to common file.
[llvm-complete.git] / utils / profile.pl
blob857fbfc16458b8c10234bd7535fa7306fd8a341a
1 #!/usr/bin/perl -w
3 # Program: profile.pl
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 basic block level profiling
13 # Any unrecognized options are passed into the invocation of llvm-prof
16 my $ProfilePass = "-insert-function-profiling";
18 my $LLVMProfOpts = "";
20 # Parse arguments...
21 while (scalar(@ARGV) and ($_ = $ARGV[0], /^[-+]/)) {
22 shift;
23 last if /^--$/; # Stop processing arguments on --
25 # List command line options here...
26 if (/^-?-block$/) { $ProfilePass = "-insert-block-profiling"; next; }
27 if (/^-?-help$/) {
28 print "OVERVIEW: profile.pl - Instrumentation and profile printer.\n\n";
29 print "USAGE: profile.pl [options] program.bc <program args>\n\n";
30 print "OPTIONS:\n";
31 print " -block - Enable basic block level profiling\n";
32 print " -help - Print this usage information\n";
33 print "\nAll other options are passed into llvm-prof.\n";
34 exit 1;
37 # Otherwise, pass the option on to llvm-prof
38 $LLVMProfOpts .= " " . $_;
41 die "Must specify LLVM bytecode file as first argument!" if (@ARGV == 0);
43 my $BytecodeFile = $ARGV[0];
45 shift @ARGV;
47 my $LLIPath = `which lli`;
48 $LLIPath = `dirname $LLIPath`;
49 chomp $LLIPath;
51 my $LibProfPath = $LLIPath . "/../../lib/Debug/libprofile_rt.so";
53 system "opt -q $ProfilePass < $BytecodeFile | lli -fake-argv0 '$BytecodeFile'" .
54 " -load $LibProfPath - " . (join ' ', @ARGV);
56 system "llvm-prof $LLVMProfOpts $BytecodeFile";