Queries Regarding Usage of PGOInstrumentation Passes instead of Deprecated ProfileInfo

Hey all,

I have a piece of code (written in LLVM 2.8) which uses profiling results produced by ProfileInfo. It essentially computes the number of iterations performed by a loop from the profiling information available. The code snippet in my pass looks something like this.

Hey all,

I have a piece of code (written in LLVM 2.8) which uses profiling results produced by ProfileInfo. It essentially computes the number of iterations performed by a loop from the profiling information available. The code snippet in my pass looks something like this.

  BasicBlock *header = loop->getHeader();
  ProfileInfo &pi = getAnalysis< ProfileInfo >();
  for(pred_iterator i=pred_begin(header), e=pred_end(header); i!=e; ++i)
  {
    BasicBlock *pred = *i;

    const double edgeCount = **pi.getEdgeWeight**( ProfileInfo::Edge(pred,header) );
    __/* Some code */__
  }

Now, since ProfileInfo has been deprecated and we have PGOInstrumentation passes along with BranchProbability and BlockFrequency, I wish to update the above snippet, in particular, obtaining the edge weights (highlighted in the code above) using the new tools.

In order to do that, I’m first generating edge count profile by the PGOInstrumentationGen pass and then interpreting the edge count profile with PGOInstrumentationUse.

In the original code, where I had
au.addRequired< ProfileInfo >(), I now have

au.addRequired< BlockFrequencyInfoWrapperPass >(); au.addRequired< BranchProbabilityInfoWrapperPass >(); Now, I have the following queries.
  • How do I use the edge count and branch weights data obtained using PGOInstrumentationUse in my pass and replace the getEdgeWeight() from ProfileInfo?

You can do
BPI.getEdgeProbability(Src, Dest).scale(BFI.getBlockProfileCount(Src));

  • If I call getBlockProfileCount() from the BlockFrequency pass, will that give me the data read during PGOInstrumentationUse or data based on static analysis? In other words, does the data obtained during PGOInstrumentationUse “propagate” to BlockFrequency and BranchProbability?

Correct.

David

Thank you so much for your response.

Thank you so much for your response.

What is function entry’s profile count? Note it is different from entry frequency (which is synthetic). You can find the function entry’s count from entry’s prof meta data. There is also an API to get it.

Branch probability info analysis pass will use the profile meta data (read in from profile data and annotated in the IR) and use that to compute branch probability. The block frequency propagation pass uses BPI info to compute relative block frequencies. The actual profile count of the function entry is kept, and a block’s actual profile count can then be recomputed using Entry Frequency, block frequency, and the entry count data.

David

Somehow, I didn’t receive your email regarding you asking for the function’s entry count but I’m able to see it on Google Groups.

The function’s entry count is 1. My apologies for not having mentioned it before.

Thank you so much for your response.

Easwaran, I think this is a bug that needs to be fixed.

David

I forgot to mention that I’m using LLVM 5.0.

Is the problem something that was fixed post LLVM 5.0?

Thank you.

Regards,
Malhar

I have fixed the rounding issue recently at r339835.

  • Easwaran

Thank you so much!