[PATCH] Add optimization remarks to the loop unroller and vectorizer.

Nadav Rotem nrotem at apple.com
Tue Apr 22 12:59:35 PDT 2014


Hi Diego, 

You may also want to record the vectorization factor and interleave factor.



+    // Report the vectorization decision.
+    F->getContext().emitOptimizationRemark(DEBUG_TYPE, *F, L->getStartLoc(),
+                                           "vectorized loop");
+
     DEBUG(verifyFunction(*L->getHeader()->getParent()));
     return true;


Thanks,
Nadav

On Apr 22, 2014, at 11:48 AM, Diego Novillo <dnovillo at google.com> wrote:

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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140422/109f81d1/attachment.html>


More information about the llvm-commits mailing list