From f57cc62abf4d2d5fec91716372d060662d678fc8 Mon Sep 17 00:00:00 2001 From: Adam Nemet Date: Fri, 30 Sep 2016 03:44:16 +0000 Subject: [PATCH] [LoopUnroll] Port to the new streaming interface for opt remarks. llvm-svn: 282834 --- llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp | 49 +++++++++++++++------------ llvm/lib/Transforms/Utils/LoopUnroll.cpp | 23 +++++++------ 2 files changed, 41 insertions(+), 31 deletions(-) diff --git a/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp b/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp index a8442e6..ab8c7b6 100644 --- a/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp +++ b/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp @@ -809,10 +809,11 @@ static bool computeUnrollCount(Loop *L, const TargetTransformInfo &TTI, } if (UP.Count < 2) { if (PragmaEnableUnroll) - ORE->emitOptimizationRemarkMissed( - DEBUG_TYPE, L, - "Unable to unroll loop as directed by unroll(enable) pragma " - "because unrolled size is too large."); + ORE->emit( + OptimizationRemarkMissed(DEBUG_TYPE, "UnrollAsDirectedTooLarge", + L->getStartLoc(), L->getHeader()) + << "Unable to unroll loop as directed by unroll(enable) pragma " + "because unrolled size is too large."); UP.Count = 0; } } else { @@ -820,19 +821,22 @@ static bool computeUnrollCount(Loop *L, const TargetTransformInfo &TTI, } if ((PragmaFullUnroll || PragmaEnableUnroll) && TripCount && UP.Count != TripCount) - ORE->emitOptimizationRemarkMissed( - DEBUG_TYPE, L, - "Unable to fully unroll loop as directed by unroll pragma because " - "unrolled size is too large."); + ORE->emit( + OptimizationRemarkMissed(DEBUG_TYPE, "FullUnrollAsDirectedTooLarge", + L->getStartLoc(), L->getHeader()) + << "Unable to fully unroll loop as directed by unroll pragma because " + "unrolled size is too large."); return ExplicitUnroll; } assert(TripCount == 0 && "All cases when TripCount is constant should be covered here."); if (PragmaFullUnroll) - ORE->emitOptimizationRemarkMissed( - DEBUG_TYPE, L, - "Unable to fully unroll loop as directed by unroll(full) pragma " - "because loop has a runtime trip count."); + ORE->emit( + OptimizationRemarkMissed(DEBUG_TYPE, + "CantFullUnrollAsDirectedRuntimeTripCount", + L->getStartLoc(), L->getHeader()) + << "Unable to fully unroll loop as directed by unroll(full) pragma " + "because loop has a runtime trip count."); // 5th priority is runtime unrolling. // Don't unroll a runtime trip count loop when it is disabled. @@ -872,16 +876,19 @@ static bool computeUnrollCount(Loop *L, const TargetTransformInfo &TTI, "multiple, " << TripMultiple << ". Reducing unroll count from " << OrigCount << " to " << UP.Count << ".\n"); + using namespace ore; if (PragmaCount > 0 && !UP.AllowRemainder) - ORE->emitOptimizationRemarkMissed( - DEBUG_TYPE, L, - Twine("Unable to unroll loop the number of times directed by " - "unroll_count pragma because remainder loop is restricted " - "(that could architecture specific or because the loop " - "contains a convergent instruction) and so must have an unroll " - "count that divides the loop trip multiple of ") + - Twine(TripMultiple) + ". Unrolling instead " + Twine(UP.Count) + - " time(s)."); + ORE->emit( + OptimizationRemarkMissed(DEBUG_TYPE, + "DifferentUnrollCountFromDirected", + L->getStartLoc(), L->getHeader()) + << "Unable to unroll loop the number of times directed by " + "unroll_count pragma because remainder loop is restricted " + "(that could architecture specific or because the loop " + "contains a convergent instruction) and so must have an unroll " + "count that divides the loop trip multiple of " + << NV("TripMultiple", TripMultiple) << ". Unrolling instead " + << NV("UnrollCount", UP.Count) << " time(s)."); } if (UP.Count > UP.MaxCount) diff --git a/llvm/lib/Transforms/Utils/LoopUnroll.cpp b/llvm/lib/Transforms/Utils/LoopUnroll.cpp index 4913c78..77b744e 100644 --- a/llvm/lib/Transforms/Utils/LoopUnroll.cpp +++ b/llvm/lib/Transforms/Utils/LoopUnroll.cpp @@ -324,30 +324,33 @@ bool llvm::UnrollLoop(Loop *L, unsigned Count, unsigned TripCount, bool Force, (unsigned)GreatestCommonDivisor64(Count, TripMultiple); } + using namespace ore; // Report the unrolling decision. if (CompletelyUnroll) { DEBUG(dbgs() << "COMPLETELY UNROLLING loop %" << Header->getName() << " with trip count " << TripCount << "!\n"); - ORE->emitOptimizationRemark(DEBUG_TYPE, L, - Twine("completely unrolled loop with ") + - Twine(TripCount) + " iterations"); + ORE->emit(OptimizationRemark(DEBUG_TYPE, "FullyUnrolled", L->getStartLoc(), + L->getHeader()) + << "completely unrolled loop with " + << NV("UnrollCount", TripCount) << " iterations"); } else { - auto EmitDiag = [&](const Twine &T) { - ORE->emitOptimizationRemark( - DEBUG_TYPE, L, "unrolled loop by a factor of " + Twine(Count) + T); - }; + OptimizationRemark Diag(DEBUG_TYPE, "PartialUnrolled", L->getStartLoc(), + L->getHeader()); + Diag << "unrolled loop by a factor of " << NV("UnrollCount", Count); DEBUG(dbgs() << "UNROLLING loop %" << Header->getName() << " by " << Count); if (TripMultiple == 0 || BreakoutTrip != TripMultiple) { DEBUG(dbgs() << " with a breakout at trip " << BreakoutTrip); - EmitDiag(" with a breakout at trip " + Twine(BreakoutTrip)); + ORE->emit(Diag << " with a breakout at trip " + << NV("BreakoutTrip", BreakoutTrip)); } else if (TripMultiple != 1) { DEBUG(dbgs() << " with " << TripMultiple << " trips per branch"); - EmitDiag(" with " + Twine(TripMultiple) + " trips per branch"); + ORE->emit(Diag << " with " << NV("TripMultiple", TripMultiple) + << " trips per branch"); } else if (RuntimeTripCount) { DEBUG(dbgs() << " with run-time trip count"); - EmitDiag(" with run-time trip count"); + ORE->emit(Diag << " with run-time trip count"); } DEBUG(dbgs() << "!\n"); } -- 2.7.4