[PATCH] D22141: [BFI] Add option to lazily calculate BFI

Adam Nemet via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 8 09:04:33 PDT 2016


anemet created this revision.
anemet added reviewers: hfinkel, dexonsmith, davidxl.
anemet added a subscriber: llvm-commits.

This is necessary for D21771.  In order to add the hotness attribute to
optimization remarks we need BFI to be available in all passes that emit
optimization remarks.

This is achieved by making BFI lazy at the very high-level -- BFI is not
calculated unless requested.

Rather than adding:

  if (!Calculated)
    calculate()

to all the BFI query routines.  I wrapped BFI in a LazyBFI class and the
calculation of frequencies happen as BFI is accessed in a LazyBFI.  I
think this is less error-prone.

This requires no client change for the old PM because the
Lazy->Calculated state change occurs in the getBFI call in:
getAnalysis<BlockFrequencyInfoWrapperPass>().getBFI()

For the new PM there is an additional getCalculated() call that needs to
be invoked on the analysis result.  (As an example, refer to the change
in PGOInstrumentation.cpp.  I plan to look into the new PM to see if
there is a way to make the getCalculated call implicit as the result is
queried.)

http://reviews.llvm.org/D22141

Files:
  include/llvm/Analysis/BlockFrequencyInfo.h
  lib/Analysis/BlockFrequencyInfo.cpp
  lib/Transforms/Instrumentation/PGOInstrumentation.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D22141.63239.patch
Type: text/x-patch
Size: 6922 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160708/76b2f242/attachment.bin>


More information about the llvm-commits mailing list