[llvm] r207528 - Add optimization remarks to the loop unroller and vectorizer.
David Blaikie
dblaikie at gmail.com
Tue Apr 29 08:23:53 PDT 2014
On Tue, Apr 29, 2014 at 7:27 AM, Diego Novillo <dnovillo at google.com> wrote:
> Author: dnovillo
> Date: Tue Apr 29 09:27:31 2014
> New Revision: 207528
>
> URL: http://llvm.org/viewvc/llvm-project?rev=207528&view=rev
> Log:
> Add optimization remarks to the loop unroller and vectorizer.
>
> Summary:
> This calls emitOptimizationRemark from the loop unroller and vectorizer
> at the point where they make a positive transformation. For the
> vectorizer, it reports vectorization and interleave factors. For the
> loop unroller, it reports all the different supported types of
> unrolling.
>
> Subscribers: llvm-commits
>
> Differential Revision: http://reviews.llvm.org/D3456
Test coverage? (I assume we've plumbed the remark stuff through llc so
this can be tested in LLVM directly?)
>
> Modified:
> llvm/trunk/include/llvm/Analysis/LoopInfo.h
> llvm/trunk/lib/Transforms/Utils/LoopUnroll.cpp
> llvm/trunk/lib/Transforms/Vectorize/LoopVectorize.cpp
>
> Modified: llvm/trunk/include/llvm/Analysis/LoopInfo.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/LoopInfo.h?rev=207528&r1=207527&r2=207528&view=diff
> ==============================================================================
> --- llvm/trunk/include/llvm/Analysis/LoopInfo.h (original)
> +++ llvm/trunk/include/llvm/Analysis/LoopInfo.h Tue Apr 29 09:27:31 2014
> @@ -453,6 +453,31 @@ public:
>
> void dump() const;
>
> + /// \brief Return the debug location of the start of this loop.
> + /// This looks for a BB terminating instruction with a known debug
> + /// location by looking at the preheader and header blocks. If it
> + /// cannot find a terminating 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->getTerminator()->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->getTerminator()->getDebugLoc();
> +
> + return StartLoc;
> + }
> +
> private:
> friend class LoopInfoBase<BasicBlock, Loop>;
> explicit Loop(BasicBlock *BB) : LoopBase<BasicBlock, Loop>(BB) {}
>
> Modified: llvm/trunk/lib/Transforms/Utils/LoopUnroll.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/LoopUnroll.cpp?rev=207528&r1=207527&r2=207528&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Transforms/Utils/LoopUnroll.cpp (original)
> +++ llvm/trunk/lib/Transforms/Utils/LoopUnroll.cpp Tue Apr 29 09:27:31 2014
> @@ -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 @@ bool llvm::UnrollLoop(Loop *L, unsigned
> (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 with ") +
> + Twine(TripCount) + " iterations");
> } else {
> DEBUG(dbgs() << "UNROLLING loop %" << Header->getName()
> << " by " << Count);
> + Twine DiagMsg("unrolled loop by a factor of " + Twine(Count));
> 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));
>
> Modified: llvm/trunk/lib/Transforms/Vectorize/LoopVectorize.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Vectorize/LoopVectorize.cpp?rev=207528&r1=207527&r2=207528&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Transforms/Vectorize/LoopVectorize.cpp (original)
> +++ llvm/trunk/lib/Transforms/Vectorize/LoopVectorize.cpp Tue Apr 29 09:27:31 2014
> @@ -1222,6 +1222,12 @@ struct LoopVectorize : public FunctionPa
> // 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(),
> + Twine("vectorized loop (vectorization factor: ") + Twine(VF.Width) +
> + ", unroll factor: " + Twine(UF) + ")");
> +
> DEBUG(verifyFunction(*L->getHeader()->getParent()));
> return true;
> }
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
More information about the llvm-commits
mailing list