<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Mar 10, 2016 at 10:01 AM, Toshio Suganuma <span dir="ltr"><<a href="mailto:SUGANUMA@jp.ibm.com" target="_blank">SUGANUMA@jp.ibm.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><p>Hi David,<br><br>Thank you for your reply. I tried both of the ways you suggested:<br><br>1) By specifying -instrprof for opt command, the IR level instrumentation seems to work ok.<span class=""><br>$ clang -c -o main.bc -O2 -m64 -emit-llvm main.c<br></span>$ clang -c -o lbm.bc -O2 -m64 -emit-llvm lbm.c<br>$ llvm-link -o _all_combined.bc lbm.bc main.bc<br>$ opt -pgo-instr-gen -instrprof _all_combined.bc -o _all_combined_inst.bc<br>$ clang -o lbm_inst _all_combined_inst.bc -O2 -m64 -lm -fprofile-instr-generate<br><br>I found that the option -fprofile-instr-generate is still necessary in the link step, without which no profile data is produced (I confirmed it by ltrace).<br></p></div></blockquote><div><br></div><div>yes -- it is needed as the driver needs to pass in the profile runtime library to the linker -- which is signaled by the option.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><p>When using the resulting profile in opt command and printing call graphs, is it easy to set call edge counts from the profile data?<br><br>$ opt -analyze -pgo-instr-use -print-callgraph _all_combined.bc<br><br>Call graph node for function: 'main'<<0xb7635d60>>  #uses=1<br>  CS<0xb764d420> calls function 'MAIN_parseCommandLine'<br>  CS<0xb764dd78> calls function 'printf'<br>  CS<0xb764de00> calls function 'MAIN_initialize'<br>  CS<0xb764e400> calls function 'LBM_handleInOutFlow'<br>  ... <br></p></div></blockquote><div><br></div><div>There is no explicit way of doing this now -- especially for cg post-inline. This is currently being worked on.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><p><br>2) clang doesn't seem to accept -fprofile-instrument=llvm<br>$ clang -fprofile-instr-generate -Xclang -fprofile-instrument=llvm main.c<br>error: invalid PGO instrumentor in argument '-fprofile-instrument=llvm'<br><br></p></div></blockquote><div>This was added recently. You can update your clang/llvm source and rebuild clang.</div><div><br></div><div>thanks,</div><div><br></div><div>David</div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><p>Thank you,<br>--Toshio<br><br><img width="16" height="16" src="cid:1__=C6BBF5E1DF88097E8f9e8a93df938690918cC6B@" border="0" alt="Inactive hide details for Xinliang David Li ---2016/03/10 03:12:14---On Wed, Mar 9, 2016 at 9:45 AM, Toshio Suganuma via llvm-d"><font color="#424282">Xinliang David Li ---2016/03/10 03:12:14---On Wed, Mar 9, 2016 at 9:45 AM, Toshio Suganuma via llvm-dev < <a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:</font><br><br><font size="2" color="#5F5F5F">From:        </font><font size="2">Xinliang David Li <<a href="mailto:xinliangli@gmail.com" target="_blank">xinliangli@gmail.com</a>></font><br><font size="2" color="#5F5F5F">To:        </font><font size="2">Toshio Suganuma/Japan/IBM@IBMJP</font><br><font size="2" color="#5F5F5F">Cc:        </font><font size="2">llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>>, Rong Xu <<a href="mailto:xur@google.com" target="_blank">xur@google.com</a>></font><br><font size="2" color="#5F5F5F">Date:        </font><font size="2">2016/03/10 03:12</font><br><font size="2" color="#5F5F5F">Subject:        </font><font size="2">Re: [llvm-dev] PGO question</font><br></p><hr width="100%" size="2" align="left" noshade style="color:#8091a5"><div><div class="h5"><br><br><br><br><br><font size="4">On Wed, Mar 9, 2016 at 9:45 AM, Toshio Suganuma via llvm-dev <</font><a href="mailto:llvm-dev@lists.llvm.org" target="_blank"><u><font size="4" color="#0000FF">llvm-dev@lists.llvm.org</font></u></a><font size="4">> wrote:</font><ul><font size="4">Hi,<br><br>I have a question regarding PGO.<br><br>I collected profile data with the instrumentation build (-fprofile-instr-generate) and provided for PGO optimization in the second build (with -fprofile-instr-use=xxx.profdata). This works fine.<br><br>Then I tried to provide the profile data to opt using the option -pgo-instr-use, but this causes an error with the message: "Not an IR level instrumentation profile".<br>I thought this error occurred because the profile data was produced by the instrumentation build from the source level, not IR level. </font></ul><br><br><font size="4">-fprofile-instr-generate by default still uses Clang frontend based instrumentation -- that is why you see the warning.</font><br><font size="4"> </font><ul><font size="4">However, if I try to make -pgo-instr-gen for the opt command, the resulting bitcode seems to cause a problem as follows (my environment is 3.9.0, mid Feb trunk).<br><br>$ clang -c -o main.bc -O2 -m64 -emit-llvm main.c<br>$ opt -pgo-instr-gen main.bc -o main_inst.bc</font></ul><br><br><font size="4">you also need to use -instrprof to add the lowering pass.</font><br><br><font size="4">The formal way to enable IR level instrumentation is to use the following command line:</font><br><br><font size="4">clang -fprofile-instr-generate -Xclang -fprofile-instrument=llvm main.c</font><br><br><font size="4">David</font><ul><font size="4">$ llc main_inst.bc -o main_inst.s<br>instrprof failed to lower an increment<br>UNREACHABLE executed at /home/suganuma/tools/llvm_new/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp:5245!<br>#0 0x00000000815ecc7a llvm::sys::PrintStackTrace(llvm::raw_ostream&) /home/suganuma/tools/llvm_new/llvm/lib/Support/Unix/Signals.inc:322:0<br>#1 0x00000000815ed02a PrintStackTraceSignalHandler(void*) /home/suganuma/tools/llvm_new/llvm/lib/Support/Unix/Signals.inc:380:0<br>#2 0x00000000815eb33e llvm::sys::RunSignalHandlers() /home/suganuma/tools/llvm_new/llvm/lib/Support/Signals.cpp:44:0<br>...<br>#7 0x0000000081577202 /home/suganuma/tools/llvm_new/llvm/lib/Support/ErrorHandling.cpp:117:0<br>#8 0x000000008139792a llvm::SelectionDAGBuilder::visitIntrinsicCall(llvm::CallInst const&, unsigned int) /home/suganuma/tools/llvm_new/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp:5247:0<br>#9 0x000000008139b11c llvm::SelectionDAGBuilder::visitCall(llvm::CallInst const&) /home/suganuma/tools/llvm_new/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp:5811:0<br>#10 0x00000000813737e4 llvm::SelectionDAGBuilder::visit(unsigned int, llvm::User const&) /home/suganuma/tools/llvm_new/llvm/include/llvm/IR/Instruction.def:186:0<br>...<br><br>Am I doing something wrong? How can we provide profile data to opt? <br>What actually I want to do is to dump call graph (cross module) and cfg that reflect counter values from profile data.<br><br>Thank you,<br>--Toshio</font><br><font size="4"><br>_______________________________________________<br>LLVM Developers mailing list</font><u><font size="4" color="#0000FF"><br></font></u><a href="mailto:llvm-dev@lists.llvm.org" target="_blank"><u><font size="4" color="#0000FF">llvm-dev@lists.llvm.org</font></u></a><u><font size="4" color="#0000FF"><br></font></u><a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" target="_blank"><u><font size="4" color="#0000FF">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</font></u></a><font size="4"><br></font></ul><br><br>
</div></div><p></p></div>
</blockquote></div><br></div></div>