From 7cfd5971ab09bde7ec4f14e1f995414380ea4179 Mon Sep 17 00:00:00 2001 From: Adam Nemet Date: Thu, 21 Jul 2016 01:07:13 +0000 Subject: [PATCH] [OptDiag,LV] Add hotness attribute to applied-optimization remarks Test coverage is provided by modifying the function in the FP-math testcase that we are allowed to vectorize. llvm-svn: 276223 --- llvm/include/llvm/Analysis/OptimizationDiagnosticInfo.h | 15 +++++++++++++++ llvm/include/llvm/IR/DiagnosticInfo.h | 5 +++-- llvm/lib/Analysis/OptimizationDiagnosticInfo.cpp | 15 +++++++++++++++ llvm/lib/Transforms/Vectorize/LoopVectorize.cpp | 14 +++++++------- .../LoopVectorize/X86/no_fpmath_with_hotness.ll | 8 ++++---- 5 files changed, 44 insertions(+), 13 deletions(-) diff --git a/llvm/include/llvm/Analysis/OptimizationDiagnosticInfo.h b/llvm/include/llvm/Analysis/OptimizationDiagnosticInfo.h index dfa6177..65ca2921 100644 --- a/llvm/include/llvm/Analysis/OptimizationDiagnosticInfo.h +++ b/llvm/include/llvm/Analysis/OptimizationDiagnosticInfo.h @@ -43,6 +43,21 @@ public: return *this; } + /// Emit an optimization-applied message. + /// + /// \p PassName is the name of the pass emitting the message. If -Rpass= is + /// given and \p PassName matches the regular expression in -Rpass, then the + /// remark will be emitted. \p Fn is the function triggering the remark, \p + /// DLoc is the debug location where the diagnostic is generated. \p V is the + /// IR Value that identifies the code region. \p Msg is the message string to + /// use. + void emitOptimizationRemark(const char *PassName, const DebugLoc &DLoc, + const Value *V, const Twine &Msg); + + /// \brief Same as above but derives the IR Value for the code region and the + /// debug location from the Loop parameter \p L. + void emitOptimizationRemark(const char *PassName, Loop *L, const Twine &Msg); + /// Emit an optimization-missed message. /// /// \p PassName is the name of the pass emitting the message. If diff --git a/llvm/include/llvm/IR/DiagnosticInfo.h b/llvm/include/llvm/IR/DiagnosticInfo.h index b8667fc..cbd328c 100644 --- a/llvm/include/llvm/IR/DiagnosticInfo.h +++ b/llvm/include/llvm/IR/DiagnosticInfo.h @@ -433,9 +433,10 @@ public: /// Note that this class does not copy this message, so this reference /// must be valid for the whole life time of the diagnostic. DiagnosticInfoOptimizationRemark(const char *PassName, const Function &Fn, - const DebugLoc &DLoc, const Twine &Msg) + const DebugLoc &DLoc, const Twine &Msg, + Optional Hotness = None) : DiagnosticInfoOptimizationBase(DK_OptimizationRemark, DS_Remark, - PassName, Fn, DLoc, Msg) {} + PassName, Fn, DLoc, Msg, Hotness) {} static bool classof(const DiagnosticInfo *DI) { return DI->getKind() == DK_OptimizationRemark; diff --git a/llvm/lib/Analysis/OptimizationDiagnosticInfo.cpp b/llvm/lib/Analysis/OptimizationDiagnosticInfo.cpp index cae2253..e658755 100644 --- a/llvm/lib/Analysis/OptimizationDiagnosticInfo.cpp +++ b/llvm/lib/Analysis/OptimizationDiagnosticInfo.cpp @@ -27,6 +27,21 @@ Optional OptimizationRemarkEmitter::computeHotness(const Value *V) { return BFI->getBlockProfileCount(cast(V)); } +void OptimizationRemarkEmitter::emitOptimizationRemark(const char *PassName, + const DebugLoc &DLoc, + const Value *V, + const Twine &Msg) { + LLVMContext &Ctx = F->getContext(); + Ctx.diagnose(DiagnosticInfoOptimizationRemark(PassName, *F, DLoc, Msg, + computeHotness(V))); +} + +void OptimizationRemarkEmitter::emitOptimizationRemark(const char *PassName, + Loop *L, + const Twine &Msg) { + emitOptimizationRemark(PassName, L->getStartLoc(), L->getHeader(), Msg); +} + void OptimizationRemarkEmitter::emitOptimizationRemarkMissed( const char *PassName, const DebugLoc &DLoc, const Value *V, const Twine &Msg) { diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp index 5befef9..b6ba079 100644 --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -6575,9 +6575,9 @@ bool LoopVectorizePass::processLoop(Loop *L) { InnerLoopUnroller Unroller(L, PSE, LI, DT, TLI, TTI, AC, ORE, IC); Unroller.vectorize(&LVL, CM.MinBWs, CM.VecValuesToIgnore); - emitOptimizationRemark(F->getContext(), LV_NAME, *F, L->getStartLoc(), - Twine("interleaved loop (interleaved count: ") + - Twine(IC) + ")"); + ORE->emitOptimizationRemark(LV_NAME, L, + Twine("interleaved loop (interleaved count: ") + + Twine(IC) + ")"); } else { // If we decided that it is *legal* to vectorize the loop, then do it. InnerLoopVectorizer LB(L, PSE, LI, DT, TLI, TTI, AC, ORE, VF.Width, IC); @@ -6591,10 +6591,10 @@ bool LoopVectorizePass::processLoop(Loop *L) { AddRuntimeUnrollDisableMetaData(L); // Report the vectorization decision. - emitOptimizationRemark(F->getContext(), LV_NAME, *F, L->getStartLoc(), - Twine("vectorized loop (vectorization width: ") + - Twine(VF.Width) + ", interleaved count: " + - Twine(IC) + ")"); + ORE->emitOptimizationRemark( + LV_NAME, L, Twine("vectorized loop (vectorization width: ") + + Twine(VF.Width) + ", interleaved count: " + Twine(IC) + + ")"); } // Mark the loop as already vectorized to avoid vectorizing again. diff --git a/llvm/test/Transforms/LoopVectorize/X86/no_fpmath_with_hotness.ll b/llvm/test/Transforms/LoopVectorize/X86/no_fpmath_with_hotness.ll index 7cb38f6..f86ea52 100644 --- a/llvm/test/Transforms/LoopVectorize/X86/no_fpmath_with_hotness.ll +++ b/llvm/test/Transforms/LoopVectorize/X86/no_fpmath_with_hotness.ll @@ -3,7 +3,7 @@ ; CHECK: remark: no_fpmath.c:6:11: loop not vectorized: cannot prove it is safe to reorder floating-point operations (hotness: 300) ; CHECK: remark: no_fpmath.c:6:14: loop not vectorized: -; CHECK: remark: no_fpmath.c:17:14: vectorized loop (vectorization width: 2, interleaved count: 2) +; CHECK: remark: no_fpmath.c:17:14: vectorized loop (vectorization width: 2, interleaved count: 2) (hotness: 300) target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128" target triple = "x86_64-apple-macosx10.10.0" @@ -40,10 +40,10 @@ for.body: ; preds = %for.body.preheader, } ; Function Attrs: nounwind readonly ssp uwtable -define double @cond_sum_loop_hint(i32* nocapture readonly %v, i32 %n) #0 !dbg !20 { +define double @cond_sum_loop_hint(i32* nocapture readonly %v, i32 %n) #0 !dbg !20 !prof !29{ entry: %cmp.7 = icmp sgt i32 %n, 0, !dbg !19 - br i1 %cmp.7, label %for.body.preheader, label %for.cond.cleanup, !dbg !21 + br i1 %cmp.7, label %for.body.preheader, label %for.cond.cleanup, !dbg !21, !prof !30 for.body.preheader: ; preds = %entry br label %for.body, !dbg !22 @@ -67,7 +67,7 @@ for.body: ; preds = %for.body.preheader, %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1, !dbg !21 %lftr.wideiv = trunc i64 %indvars.iv.next to i32, !dbg !21 %exitcond = icmp eq i32 %lftr.wideiv, %n, !dbg !21 - br i1 %exitcond, label %for.cond.cleanup.loopexit, label %for.body, !dbg !21, !llvm.loop !26 + br i1 %exitcond, label %for.cond.cleanup.loopexit, label %for.body, !dbg !21, !llvm.loop !26, !prof !31 } attributes #0 = { nounwind } -- 2.7.4