[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)
commitf8cec99b2fa07a32e132a2e010fe005f36ed2c31
treee8e97c7347f02d308b12ccc05d01051984dc82d8
parent3d1f23717155ac7ada19889aec55155a538c03c2
[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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@275583 91177308-0d34-0410-b5e6-96231b3b80d8
15 files changed:
include/llvm/Analysis/OptimizationDiagnosticInfo.h [new file with mode: 0644]
include/llvm/IR/DiagnosticInfo.h
include/llvm/IR/LLVMContext.h
include/llvm/InitializePasses.h
lib/Analysis/Analysis.cpp
lib/Analysis/CMakeLists.txt
lib/Analysis/OptimizationDiagnosticInfo.cpp [new file with mode: 0644]
lib/IR/DiagnosticInfo.cpp
lib/IR/LLVMContext.cpp
lib/IR/LLVMContextImpl.cpp
lib/IR/LLVMContextImpl.h
lib/Transforms/Scalar/LoopDistribute.cpp
test/Transforms/LoopDistribute/diagnostics-with-hotness-lazy-BFI.ll [new file with mode: 0644]
test/Transforms/LoopDistribute/diagnostics-with-hotness.ll [new file with mode: 0644]
tools/opt/opt.cpp