[OptRemark,LDist] RFC: Add hotness attribute
authorAdam Nemet <anemet@apple.com>
Fri, 15 Jul 2016 17:23:20 +0000 (17:23 +0000)
committerAdam Nemet <anemet@apple.com>
Fri, 15 Jul 2016 17:23:20 +0000 (17:23 +0000)
commitaad816083e3e0b6a195e57a9eab0fa61afea2ab5
tree900f10703ddf216011bf6eba647993575ce19905
parent5d9a17742e5c97ef252a86cdd5dc7db5dfc04c79
[OptRemark,LDist] RFC: Add hotness attribute

Summary:
This is the first set of changes implementing the RFC from
http://thread.gmane.org/gmane.comp.compilers.llvm.devel/98334

This is a cross-sectional patch; rather than implementing the hotness
attribute for all optimization remarks and all passes in a patch set, it
implements it for the 'missed-optimization' remark for Loop
Distribution.  My goal is to shake out the design issues before scaling
it up to other types and passes.

Hotness is computed as an integer as the multiplication of the block
frequency with the function entry count.  It's only printed in opt
currently since clang prints the diagnostic fields directly.  E.g.:

  remark: /tmp/t.c:3:3: loop not distributed: use -Rpass-analysis=loop-distribute for more info (hotness: 300)

A new API added is similar to emitOptimizationRemarkMissed.  The
difference is that it additionally takes a code region that the
diagnostic corresponds to.  From this, hotness is computed using BFI.
The new API is exposed via an analysis pass so that it can be made
dependent on LazyBFI.  (Thanks to Hal for the analysis pass idea.)

This feature can all be enabled by setDiagnosticHotnessRequested in the
LLVM context.  If this is off, LazyBFI is not calculated (D22141) so
there should be no overhead.

A new command-line option is added to turn this on in opt.

My plan is to switch all user of emitOptimizationRemark* to use this
module instead.

Reviewers: hfinkel

Subscribers: rcox2, mzolotukhin, llvm-commits

Differential Revision: http://reviews.llvm.org/D21771

llvm-svn: 275583
15 files changed:
llvm/include/llvm/Analysis/OptimizationDiagnosticInfo.h [new file with mode: 0644]
llvm/include/llvm/IR/DiagnosticInfo.h
llvm/include/llvm/IR/LLVMContext.h
llvm/include/llvm/InitializePasses.h
llvm/lib/Analysis/Analysis.cpp
llvm/lib/Analysis/CMakeLists.txt
llvm/lib/Analysis/OptimizationDiagnosticInfo.cpp [new file with mode: 0644]
llvm/lib/IR/DiagnosticInfo.cpp
llvm/lib/IR/LLVMContext.cpp
llvm/lib/IR/LLVMContextImpl.cpp
llvm/lib/IR/LLVMContextImpl.h
llvm/lib/Transforms/Scalar/LoopDistribute.cpp
llvm/test/Transforms/LoopDistribute/diagnostics-with-hotness-lazy-BFI.ll [new file with mode: 0644]
llvm/test/Transforms/LoopDistribute/diagnostics-with-hotness.ll [new file with mode: 0644]
llvm/tools/opt/opt.cpp