<html><head><meta http-equiv="Content-Type" content="text/html charset=iso-8859-1"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div><div>Hi Diego, </div><div><br></div><div>You may also want to record the vectorization factor and interleave factor.</div><div><br></div><div><br></div><div><br></div><div>+    // Report the vectorization decision.</div><div>+    F->getContext().emitOptimizationRemark(DEBUG_TYPE, *F, L->getStartLoc(),</div><div>+                                           "vectorized loop");</div><div>+</div><div>     DEBUG(verifyFunction(*L->getHeader()->getParent()));</div><div>     return true;</div></div><div><br></div><div><br></div><div><div>Thanks,</div><div>Nadav</div></div><br><div><div>On Apr 22, 2014, at 11:48 AM, Diego Novillo <<a href="mailto:dnovillo@google.com">dnovillo@google.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div dir="ltr">Hal, could you take a look at this patch?<div><br></div><div>Thanks.  Diego.</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Apr 22, 2014 at 2:47 PM, Diego Novillo <span dir="ltr"><<a href="mailto:dnovillo@google.com" target="_blank">dnovillo@google.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">This calls emitOptimizationRemark from the loop unroller and vectorizer<br>
at the point where they make a positive transformation.<br>
<br>
BRANCH<br>
  add-optimization-remarks<br>
<br>
<a href="http://reviews.llvm.org/D3456" target="_blank">http://reviews.llvm.org/D3456</a><br>
<br>
Files:<br>
  include/llvm/Analysis/LoopInfo.h<br>
  lib/Transforms/Utils/LoopUnroll.cpp<br>
  lib/Transforms/Vectorize/LoopVectorize.cpp<br>
<br>
Index: include/llvm/Analysis/LoopInfo.h<br>
===================================================================<br>
--- include/llvm/Analysis/LoopInfo.h<br>
+++ include/llvm/Analysis/LoopInfo.h<br>
@@ -453,6 +453,31 @@<br>
<br>
   void dump() const;<br>
<br>
+  /// \brief Return the debug location of the start of this loop.<br>
+  /// This looks for the first instruction with a known debug location<br>
+  /// by looking at the preheader and header blocks. If it cannot<br>
+  /// find an instruction with location information, it returns an<br>
+  /// unknown location.<br>
+  DebugLoc getStartLoc() const {<br>
+    DebugLoc StartLoc;<br>
+    BasicBlock *HeadBB;<br>
+<br>
+    // Try the pre-header first.<br>
+    if ((HeadBB = getLoopPreheader()) != nullptr) {<br>
+      StartLoc = HeadBB->getFirstNonPHIOrDbgOrLifetime()->getDebugLoc();<br>
+      if (!StartLoc.isUnknown())<br>
+        return StartLoc;<br>
+    }<br>
+<br>
+    // If we have no pre-header or there are no instructions with debug<br>
+    // info in it, try the header.<br>
+    HeadBB = getHeader();<br>
+    if (HeadBB)<br>
+      StartLoc = HeadBB->getFirstNonPHIOrDbgOrLifetime()->getDebugLoc();<br>
+<br>
+    return StartLoc;<br>
+  }<br>
+<br>
 private:<br>
   friend class LoopInfoBase<BasicBlock, Loop>;<br>
   explicit Loop(BasicBlock *BB) : LoopBase<BasicBlock, Loop>(BB) {}<br>
Index: lib/Transforms/Utils/LoopUnroll.cpp<br>
===================================================================<br>
--- lib/Transforms/Utils/LoopUnroll.cpp<br>
+++ lib/Transforms/Utils/LoopUnroll.cpp<br>
@@ -24,6 +24,7 @@<br>
 #include "llvm/Analysis/ScalarEvolution.h"<br>
 #include "llvm/IR/BasicBlock.h"<br>
 #include "llvm/IR/Dominators.h"<br>
+#include "llvm/IR/LLVMContext.h"<br>
 #include "llvm/Support/Debug.h"<br>
 #include "llvm/Support/raw_ostream.h"<br>
 #include "llvm/Transforms/Utils/BasicBlockUtils.h"<br>
@@ -228,20 +229,33 @@<br>
       (unsigned)GreatestCommonDivisor64(Count, TripMultiple);<br>
   }<br>
<br>
+  // Report the unrolling decision.<br>
+  DebugLoc LoopLoc = L->getStartLoc();<br>
+  Function *F = Header->getParent();<br>
+  LLVMContext &Ctx = F->getContext();<br>
+<br>
   if (CompletelyUnroll) {<br>
     DEBUG(dbgs() << "COMPLETELY UNROLLING loop %" << Header->getName()<br>
           << " with trip count " << TripCount << "!\n");<br>
+    Ctx.emitOptimizationRemark(DEBUG_TYPE, *F, LoopLoc,<br>
+                               Twine("completely unrolled loop ") +<br>
+                                   Twine(TripCount) + " times");<br>
   } else {<br>
     DEBUG(dbgs() << "UNROLLING loop %" << Header->getName()<br>
           << " by " << Count);<br>
+    Twine DiagMsg("unrolled loop " + Twine(Count) + " times ");<br>
     if (TripMultiple == 0 || BreakoutTrip != TripMultiple) {<br>
       DEBUG(dbgs() << " with a breakout at trip " << BreakoutTrip);<br>
+      DiagMsg.concat(" with a breakout at trip " + Twine(BreakoutTrip));<br>
     } else if (TripMultiple != 1) {<br>
       DEBUG(dbgs() << " with " << TripMultiple << " trips per branch");<br>
+      DiagMsg.concat(" with " + Twine(TripMultiple) + " trips per branch");<br>
     } else if (RuntimeTripCount) {<br>
       DEBUG(dbgs() << " with run-time trip count");<br>
+      DiagMsg.concat(" with run-time trip count");<br>
     }<br>
     DEBUG(dbgs() << "!\n");<br>
+    Ctx.emitOptimizationRemark(DEBUG_TYPE, *F, LoopLoc, DiagMsg);<br>
   }<br>
<br>
   bool ContinueOnTrue = L->contains(BI->getSuccessor(0));<br>
Index: lib/Transforms/Vectorize/LoopVectorize.cpp<br>
===================================================================<br>
--- lib/Transforms/Vectorize/LoopVectorize.cpp<br>
+++ lib/Transforms/Vectorize/LoopVectorize.cpp<br>
@@ -1187,6 +1187,10 @@<br>
     // Mark the loop as already vectorized to avoid vectorizing again.<br>
     Hints.setAlreadyVectorized(L);<br>
<br>
+    // Report the vectorization decision.<br>
+    F->getContext().emitOptimizationRemark(DEBUG_TYPE, *F, L->getStartLoc(),<br>
+                                           "vectorized loop");<br>
+<br>
     DEBUG(verifyFunction(*L->getHeader()->getParent()));<br>
     return true;<br>
   }<br>
<br>
REPLY HANDLER ACTIONS<br>
  Reply to comment, or !reject, !abandon, !reclaim, !resign, !rethink, !unsubscribe.<br>
</blockquote></div><br></div>
_______________________________________________<br>llvm-commits mailing list<br><a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits<br></blockquote></div><br></body></html>