<div dir="ltr">







<p class="gmail-p1">Goal: Instrument program with timers within each function.<br>Problem: I am having trouble running my .ll (and .bc) files in the JIT. </p>
<p class="gmail-p3"><span class="gmail-s1">Sample Error Message: LLVM ERROR: Program used external function '__ZTextureLinearDimensionEv' which could not be resolved</span></p>
<p class="gmail-p4">The error message above is a sample that I have gotten, and I want to highlight my methodology to see if there are any holes in this process. Any help is certainly appreciated! (And perhaps this will be a useful guide for others later on)</p>
<p class="gmail-p1">(1) I have a large codebase, it contains hundreds of .cpp files.<br>(2) I want to instrument every .cpp file and add simple timers for profiling purposes.<br>(3) So I use cmake to build my project.<br>(4) So far so good, I can compile my project without errors.<br>(5) Now, for the source files I have, I compile again, but this time emit bitcode(Note: I do a .bc and .ll version).</p>
<p class="gmail-p1"><span class="gmail-Apple-tab-span"> </span>The original compile command:<br>clang++ -Isome_directory -c source1.cpp -o source1.o</p>
<p class="gmail-p1"><span class="gmail-Apple-tab-span"> </span>Becomes this:<br>clang++ -S -emit-LLVM -Isome_directory -c source1.cpp -o source1.cpp.ll</p>
<p class="gmail-p1">(6) Now I have a collection of hundreds of .ll files. I use llvm-link to make one large .ll file (combined.ll). There are no duplicated symbols, and only 1 main function found--great!<br>(7) Next I run my function pass using the opt tool on combined.ll, and then emit a new .ll file (lets call it optimized.ll) that has instrumented every function.<br>(8) No errors at this point and I have an instrumented version of my source code.<br>(9) Now I run “lli optimized.ll”, and eventually get the above sample error message.<br>(10) This seems somewhat reasonable. I have realized that the functions I have not instrumented may be in shared libraries and thus cannot be instrumented. However, there must be a way to link to dynamic/shared libraries them using LLI that I am missing.</p>
<p class="gmail-p1">So a few specific questions:<br>0.) When using lli, is it absolutely necessary that I have all of the source code (including the libraries)?<br>    a.) I am wondering, because I am not sure if LLVM’s JIT is supposed to be used as I am doing so.<br>1.) What command line option am I missing to load libraries with lli? (Is there a -Linsert_library flag I need to add?)<br>    a.) I am assuming if I can do this, this tells lli that there is an external function named <span class="gmail-s2">__ZTextureLinearDimensionEv </span>that it can use. (There is the -load argument, is this what I am missing)<br>2.) Do I ever have any hope of instrumenting the shared libraries with my function pass?<br>    a.) I was thinking if I can generate a .ll after link-time, when I have all of the code then I might be in luck and can even profile the shared libraries. I guess the real question here is what can I do with link-time optimization in its current state?<br>3.) Do I ever have any hope of instrumenting the static  libraries with my function pass?<br>    a.) Same question as above, but I am hoping this option may work (again, perhaps with the -load argument).<br>4.) Eventually, once I have optimized.ll working, I want to use llc to generate an object file then compile to an instrumented executable to maximize performance (as opposed to only running my application with lli). Are any problems foreseen at this stage if I indeed can run my program with lli<br></p>
<p class="gmail-p5">Apologies if this is a long question, but I think this will clear up questions I have about statically instrumenting a program and then profiling it.<br></p>
<p class="gmail-p5">-Mike</p>
<p class="gmail-p1">Tool sources:</p>
<p class="gmail-p1"><a href="http://llvm.org/docs/CommandGuide/lli.html">http://llvm.org/docs/CommandGuide/lli.html</a><br><a href="http://llvm.org/docs/CommandGuide/opt.html">http://llvm.org/docs/CommandGuide/opt.html</a></p>
</div>