<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr">On Sun, Jan 13, 2019 at 9:24 AM Dennis Fischer via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hey,<br>
<br>
I am trying to use the BlockFrequencyInfoWrapperPass to obtain hotness <br>
information in my LLVM pass. Attached is a minimal example of code which <br>
creates a SIGSEGV. The pass calls <br>
AU.addRequired<BlockFrequencyInfoWrapperPass>(); in <br>
getAnalysisUsage(..). The problem exists with changed and unchanged IR.<br>
<br>
The binary is instrumented like this: clang input.bc -fprofile-generate <br>
-o output<br>
<br>
The binary runs with selected inputs and the profiles are merged: <br>
llvm-profdata merge input.profraw -output=output.prof<br>
<br>
Then opt runs with arguments: opt input.bc -o output.bc -load mypass.so <br>
-block-freq -pgo-instr-use -pgo-test-profile-file=output.prof <br>
-profile-sample-accurate -mypass<br>
<br>
Is this a bug or am can someone provide an example on how to use <br>
BlockFrequencyInfo correctly?<br>
<br>
<br>
Example code:<br>
<br>
<br>
for (auto& F : M) {<br>
     if (F.isDeclaration()) {<br>
         continue;<br>
     }<br>
     auto& bfiPass = getAnalysis<BlockFrequencyInfoWrapperPass>(F);<br>
     llvm::BlockFrequencyInfo* BFI = &bfiPass.getBFI();<br>
<br>
     //Works - shows all info I want<br>
     BFI->print(llvm::dbgs());<br></blockquote><div><br></div><div>I don't know offhand why your code below is segfaulting, but note that BFI->print() will dereference the F pointer just as *getFunction below will. I would look in the debugger to see what the value of F is during print() since it seems to be ok there, and then see if you can figure out where it is changing if it is returning a bad value below.</div><div>Teresa</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
     for (const llvm::BasicBlock& B : F) {<br>
         //Fails with SIGSEGV -> *getFunction() returns 0xa<br>
         dbgs() << BFI->getBlockProfileCount(&B).getValueOr(0) << "\n";<br>
     }<br>
}<br>
<br>
<br>
lib/Analysis/BlockFrequencyInfo.cpp#L211<br>
<br>
return BFI->getBlockProfileCount(*getFunction(), BB);<br>
<br>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><span style="font-family:Times;font-size:medium"><table cellspacing="0" cellpadding="0"><tbody><tr style="color:rgb(85,85,85);font-family:sans-serif;font-size:small"><td nowrap style="border-top:2px solid rgb(213,15,37)">Teresa Johnson |</td><td nowrap style="border-top:2px solid rgb(51,105,232)"> Software Engineer |</td><td nowrap style="border-top:2px solid rgb(0,153,57)"> <a href="mailto:tejohnson@google.com" target="_blank">tejohnson@google.com</a> |</td><td nowrap style="border-top:2px solid rgb(238,178,17)"><br></td></tr></tbody></table></span></div></div></div></div>