[llvm] r276223 - [OptDiag, LV] Add hotness attribute to applied-optimization remarks

Adam Nemet via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 20 18:07:13 PDT 2016


Author: anemet
Date: Wed Jul 20 20:07:13 2016
New Revision: 276223

URL: http://llvm.org/viewvc/llvm-project?rev=276223&view=rev
Log:
[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.

Modified:
    llvm/trunk/include/llvm/Analysis/OptimizationDiagnosticInfo.h
    llvm/trunk/include/llvm/IR/DiagnosticInfo.h
    llvm/trunk/lib/Analysis/OptimizationDiagnosticInfo.cpp
    llvm/trunk/lib/Transforms/Vectorize/LoopVectorize.cpp
    llvm/trunk/test/Transforms/LoopVectorize/X86/no_fpmath_with_hotness.ll

Modified: llvm/trunk/include/llvm/Analysis/OptimizationDiagnosticInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/OptimizationDiagnosticInfo.h?rev=276223&r1=276222&r2=276223&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Analysis/OptimizationDiagnosticInfo.h (original)
+++ llvm/trunk/include/llvm/Analysis/OptimizationDiagnosticInfo.h Wed Jul 20 20:07:13 2016
@@ -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

Modified: llvm/trunk/include/llvm/IR/DiagnosticInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/DiagnosticInfo.h?rev=276223&r1=276222&r2=276223&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/DiagnosticInfo.h (original)
+++ llvm/trunk/include/llvm/IR/DiagnosticInfo.h Wed Jul 20 20:07:13 2016
@@ -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<uint64_t> 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;

Modified: llvm/trunk/lib/Analysis/OptimizationDiagnosticInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/OptimizationDiagnosticInfo.cpp?rev=276223&r1=276222&r2=276223&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/OptimizationDiagnosticInfo.cpp (original)
+++ llvm/trunk/lib/Analysis/OptimizationDiagnosticInfo.cpp Wed Jul 20 20:07:13 2016
@@ -27,6 +27,21 @@ Optional<uint64_t> OptimizationRemarkEmi
   return BFI->getBlockProfileCount(cast<BasicBlock>(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) {

Modified: llvm/trunk/lib/Transforms/Vectorize/LoopVectorize.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Vectorize/LoopVectorize.cpp?rev=276223&r1=276222&r2=276223&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Vectorize/LoopVectorize.cpp (original)
+++ llvm/trunk/lib/Transforms/Vectorize/LoopVectorize.cpp Wed Jul 20 20:07:13 2016
@@ -6575,9 +6575,9 @@ bool LoopVectorizePass::processLoop(Loop
     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
       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.

Modified: llvm/trunk/test/Transforms/LoopVectorize/X86/no_fpmath_with_hotness.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/LoopVectorize/X86/no_fpmath_with_hotness.ll?rev=276223&r1=276222&r2=276223&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/LoopVectorize/X86/no_fpmath_with_hotness.ll (original)
+++ llvm/trunk/test/Transforms/LoopVectorize/X86/no_fpmath_with_hotness.ll Wed Jul 20 20:07:13 2016
@@ -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:
 }
 
 ; 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:
   %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 }




More information about the llvm-commits mailing list