Add the select optimization recently added to instcombine to constant folding.
[llvm.git] / utils / profile.pl
blob318011560bc8ee94961548e599ce54030c6d05c5
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] bitcodefile <arguments>
10 # OPTIONS may include one or more of the following:
11 # -block - Enable basicblock profiling
12 # -edge - Enable edge profiling
13 # -function - Enable function profiling
14 # -o <filename> - Emit profiling information to the specified file, instead
15 # of llvmprof.out
17 # Any unrecognized options are passed into the invocation of llvm-prof
20 my $ProfilePass = "-insert-edge-profiling";
22 my $LLVMProfOpts = "";
23 my $ProgramOpts = "";
24 my $ProfileFile = "";
26 # Parse arguments...
27 while (scalar(@ARGV) and ($_ = $ARGV[0], /^[-+]/)) {
28 shift;
29 last if /^--$/; # Stop processing arguments on --
31 # List command line options here...
32 if (/^-?-block$/) { $ProfilePass = "-insert-block-profiling"; next; }
33 if (/^-?-edge$/) { $ProfilePass = "-insert-edge-profiling"; next; }
34 if (/^-?-function$/) { $ProfilePass = "-insert-function-profiling"; next; }
35 if (/^-?-o$/) { # Read -o filename...
36 die "-o option requires a filename argument!" if (!scalar(@ARGV));
37 $ProgramOpts .= " -llvmprof-output $ARGV[0]";
38 $ProfileFile = $ARGV[0];
39 shift;
40 next;
42 if (/^-?-help$/) {
43 print "OVERVIEW: profile.pl - Instrumentation and profile printer.\n\n";
44 print "USAGE: profile.pl [options] program.bc <program args>\n\n";
45 print "OPTIONS:\n";
46 print " -block - Enable basicblock profiling\n";
47 print " -edge - Enable edge profiling\n";
48 print " -function - Enable function profiling\n";
49 print " -o <file> - Specify an output file other than llvm-prof.out.\n";
50 print " -help - Print this usage information\n";
51 print "\nAll other options are passed into llvm-prof.\n";
52 exit 1;
55 # Otherwise, pass the option on to llvm-prof
56 $LLVMProfOpts .= " " . $_;
59 die "Must specify LLVM bitcode file as first argument!" if (@ARGV == 0);
61 my $BytecodeFile = $ARGV[0];
63 shift @ARGV;
65 my $libdir = `llvm-config --libdir`;
66 chomp $libdir;
68 my $LibProfPath = $libdir . "/profile_rt.so";
70 system "opt -q -f $ProfilePass $BytecodeFile -o $BytecodeFile.inst";
71 system "lli -fake-argv0 '$BytecodeFile' -load $LibProfPath " .
72 "$BytecodeFile.inst $ProgramOpts " . (join ' ', @ARGV);
73 system "rm $BytecodeFile.inst";
74 system "llvm-prof $LLVMProfOpts $BytecodeFile $ProfileFile";