Hi gang, time for my weekly confusion… (I’m trying not to bombard the board with questions)
The thing that’s on my mind at the moment (there’s some backend-stuff that I’m just working my way though) is that I’m not getting very far when trying to get LLVM to profile code - I’m looking for nothing more special than list of how many times each basic block has been called - but when wading though the docs I get lots of command line fragments that don’t work and the distint impression that the method for profiling has changed three times in the last three release - I don’t suppose that you have any insight into what’s going on with profiling for llvm…? I’m starting to get the feeling that I’ve missed something obvious… My setup is:
LLVM version 3.2svn
DEBUG build with assertions.
Built Jul 27 2012 (18:29:09).
Default target: x86_64-apple-darwin11.4.0
Host CPU: corei7-avx
We recently got some profiling going with llvm 3.1. (Alastair has got some code in for metadata generation after reading the profiled data(post 3.1) which you can follow in some of the earlier mail chains). I will describe the (earlier) 3.1 method which has worked for us. Note this is just a way of doing it. Not the way.
Assume you are using clang/clang++ and have a set of C/C++ files:
a) Run individual C/C++ files with : clang/clang++ -mllvm -emit-llvm -S –o x.o x.c/x.cpp
b) Link all the .o s using llvm-link: llvm-link *.o –o X.o // new single X.o created
c) Insert edge profiling: opt -O3 -insert-edge-profiling X.o -o X_prof.o
d) llc X_prof.o // creates X_prof.o.s
e) as X_prof.o.s // creates a.out
f) clang/clang++ -o X_prof.exe a.out –lprofile_rt –L //creates the instrumented binary X_prof.exe
Now run the instrumented executable “X_prof.exe” using whatever input test data you have. This will create the llvmprof.out file.
Create the new optimized executable after reading llvmprof.out:
g) opt –O3 –profile-loader X.o –o X_opt.o // you can replace this with Alastair’s profile loading step –profile-metadata-loader
h) llc X_opt.o // creates X_opt.o.s
i) as X_opt.o.s // creates a.out
j) clang/clang++ -o X_opt.exe a.out –lprofile_rt –L //creates the final optimized binary X_opt.exe
Hope this helps.