Question about BlockFrequencyInfo

Hi everyone,

I have been studying llvm for the last two weeks and I got stuck in some topics. I’m a little lost about where to look for information, for this reason I’m asking here. Sorry if it’s not the right place to do that.

I managed to do a toy compiler with bison and llvm, but now I need to do some others things:

  1. I need discover the amount of times that each basic block is executed.
    I tried to use the BlockFrequencyInfo but I think I’m doing some thing wrong:

    BlockFrequencyInfo* BFI = new BlockFrequencyInfo();
    FunctionPassManager FPM(module);
    FPM.add(BFI);
    FPM.doInitialization();

for(auto& func : *module) {
FPM.run(func);
for(auto& bb : func)
std::cout << BFI->getEntryFreq() << std::endl;
}

This code just prints 0.

And for example, if I want to do it (get the BasicBlock frequency) dynamically how could I proceed?

  1. I saw that there is a MachineBasicBlock, what do I need to study to be able to get this blocks from BasicBlock?

Thank you,

Vanderson M. Rosario

I am using llvm-prof. It prints very nice BB freq summaries.
Ex: Top 20 most frequently executed basic blocks:

%% Frequency

  1. 32.3232% 32/99 _Z12func_sin_cosdd() - entry
  2. 32.3232% 32/99 main() - for.body
  3. 32.3232% 32/99 main() - for.body14
  4. 1.0101% 1/99 main() - entry
  5. 1.0101% 1/99 main() - for.cond12.preheader
  6. 1.0101% 1/99 main() - for.end20

http://llvm.org/releases/2.1/docs/CommandGuide/html/llvm-prof.html [I am using llvm 3.3].

Hi everyone,

I have been studying llvm for the last two weeks and I got stuck in some topics. I’m a little lost about where to look for information, for this reason I’m asking here. Sorry if it’s not the right place to do that.

I managed to do a toy compiler with bison and llvm, but now I need to do some others things:

  1. I need discover the amount of times that each basic block is executed.
    I tried to use the BlockFrequencyInfo but I think I’m doing some thing wrong:

    BlockFrequencyInfo* BFI = new BlockFrequencyInfo();
    FunctionPassManager FPM(module);
    FPM.add(BFI);
    FPM.doInitialization();

for(auto& func : *module) {
FPM.run(func);
for(auto& bb : func)
std::cout << BFI->getEntryFreq() << std::endl;
}

This code just prints 0.

Unless you are using profile-guided optimization (http://clang.llvm.org/docs/UsersManual.html#profile-guided-optimization), the block frequency info is derived from heuristics, e.g., loop back edges are usually taken. You won’t get entry frequency data from those heuristics.