[llvm-dev] Problem using BlockFrequencyInfo's getBlockProfileCount

Dennis Fischer via llvm-dev llvm-dev at lists.llvm.org
Sun Jan 13 09:23:52 PST 2019


I am trying to use the BlockFrequencyInfoWrapperPass to obtain hotness 
information in my LLVM pass. Attached is a minimal example of code which 
creates a SIGSEGV. The pass calls 
AU.addRequired<BlockFrequencyInfoWrapperPass>(); in 
getAnalysisUsage(..). The problem exists with changed and unchanged IR.

The binary is instrumented like this: clang input.bc -fprofile-generate 
-o output

The binary runs with selected inputs and the profiles are merged: 
llvm-profdata merge input.profraw -output=output.prof

Then opt runs with arguments: opt input.bc -o output.bc -load mypass.so 
-block-freq -pgo-instr-use -pgo-test-profile-file=output.prof 
-profile-sample-accurate -mypass

Is this a bug or am can someone provide an example on how to use 
BlockFrequencyInfo correctly?

Example code:

for (auto& F : M) {
     if (F.isDeclaration()) {
     auto& bfiPass = getAnalysis<BlockFrequencyInfoWrapperPass>(F);
     llvm::BlockFrequencyInfo* BFI = &bfiPass.getBFI();

     //Works - shows all info I want

     for (const llvm::BasicBlock& B : F) {
         //Fails with SIGSEGV -> *getFunction() returns 0xa
         dbgs() << BFI->getBlockProfileCount(&B).getValueOr(0) << "\n";


return BFI->getBlockProfileCount(*getFunction(), BB);

More information about the llvm-dev mailing list