From 9ecbf48ff50ea6c617962e732996ed9ba5db9374 Mon Sep 17 00:00:00 2001 From: Adam Nemet Date: Thu, 29 Sep 2016 16:23:12 +0000 Subject: [PATCH] [LV] Convert emitRemark to new opt remark streaming interface Also renamed the function to emitRemarkWithHints to better reflect what the function actually does. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@282723 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/IR/DiagnosticInfo.h | 10 ++++++- lib/IR/DiagnosticInfo.cpp | 11 ++++++++ lib/Transforms/Vectorize/LoopVectorize.cpp | 31 ++++++++++++---------- 3 files changed, 37 insertions(+), 15 deletions(-) diff --git a/include/llvm/IR/DiagnosticInfo.h b/include/llvm/IR/DiagnosticInfo.h index c9d82a5ec2f..a91a813ade3 100644 --- a/include/llvm/IR/DiagnosticInfo.h +++ b/include/llvm/IR/DiagnosticInfo.h @@ -389,6 +389,8 @@ public: explicit Argument(StringRef Str = "") : Key("String"), Val(Str) {} Argument(StringRef Key, Value *V) : Key(Key), Val(V->getName()) {} Argument(StringRef Key, int N); + Argument(StringRef Key, unsigned N); + Argument(StringRef Key, bool B) : Key(Key), Val(B ? "true" : "false") {} }; /// \p PassName is the name of the pass emitting this diagnostic. \p @@ -571,7 +573,13 @@ public: /// \p PassName is the name of the pass emitting this diagnostic. If this name /// matches the regular expression given in -Rpass-analysis=, then the /// diagnostic will be emitted. \p RemarkName is a textual identifier for the - /// remark. \p Inst is the instruction that the optimization operates on. + /// remark. \p DLoc is the debug location and \p CodeRegion is the region + /// that the optimization operates on (currently on block is supported). + OptimizationRemarkAnalysis(const char *PassName, StringRef RemarkName, + const DebugLoc &DLoc, Value *CodeRegion); + + /// \brief Same as above but \p Inst is used to derive code region and debug + /// location. OptimizationRemarkAnalysis(const char *PassName, StringRef RemarkName, Instruction *Inst); diff --git a/lib/IR/DiagnosticInfo.cpp b/lib/IR/DiagnosticInfo.cpp index 301a1d53fad..3c2ed083bf1 100644 --- a/lib/IR/DiagnosticInfo.cpp +++ b/lib/IR/DiagnosticInfo.cpp @@ -174,6 +174,9 @@ const std::string DiagnosticInfoWithDebugLocBase::getLocationStr() const { DiagnosticInfoOptimizationBase::Argument::Argument(StringRef Key, int N) : Key(Key), Val(itostr(N)) {} +DiagnosticInfoOptimizationBase::Argument::Argument(StringRef Key, unsigned N) + : Key(Key), Val(utostr(N)) {} + void DiagnosticInfoOptimizationBase::print(DiagnosticPrinter &DP) const { DP << getLocationStr() << ": " << getMsg(); if (Hotness) @@ -213,6 +216,14 @@ bool OptimizationRemarkMissed::isEnabled() const { PassRemarksMissedOptLoc.Pattern->match(getPassName()); } +OptimizationRemarkAnalysis::OptimizationRemarkAnalysis(const char *PassName, + StringRef RemarkName, + const DebugLoc &DLoc, + Value *CodeRegion) + : DiagnosticInfoOptimizationBase( + DK_OptimizationRemarkAnalysis, DS_Remark, PassName, RemarkName, + *cast(CodeRegion)->getParent(), DLoc, CodeRegion) {} + OptimizationRemarkAnalysis::OptimizationRemarkAnalysis(const char *PassName, StringRef RemarkName, Instruction *Inst) diff --git a/lib/Transforms/Vectorize/LoopVectorize.cpp b/lib/Transforms/Vectorize/LoopVectorize.cpp index c4fc7b2616d..1d8a36f1073 100644 --- a/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -1235,15 +1235,13 @@ public: bool allowVectorization(Function *F, Loop *L, bool AlwaysVectorize) const { if (getForce() == LoopVectorizeHints::FK_Disabled) { DEBUG(dbgs() << "LV: Not vectorizing: #pragma vectorize disable.\n"); - ORE.emitOptimizationRemarkAnalysis(vectorizeAnalysisPassName(), L, - emitRemark()); + emitRemarkWithHints(); return false; } if (!AlwaysVectorize && getForce() != LoopVectorizeHints::FK_Enabled) { DEBUG(dbgs() << "LV: Not vectorizing: No #pragma vectorize enable.\n"); - ORE.emitOptimizationRemarkAnalysis(vectorizeAnalysisPassName(), L, - emitRemark()); + emitRemarkWithHints(); return false; } @@ -1266,23 +1264,28 @@ public: } /// Dumps all the hint information. - std::string emitRemark() const { - VectorizationReport R; + void emitRemarkWithHints() const { + using namespace ore; if (Force.Value == LoopVectorizeHints::FK_Disabled) - R << "vectorization is explicitly disabled"; + ORE.emit(OptimizationRemarkMissed(LV_NAME, "MissedExplicitlyDisabled", + TheLoop->getStartLoc(), + TheLoop->getHeader()) + << "loop not vectorized: vectorization is explicitly disabled"); else { - R << "use -Rpass-analysis=loop-vectorize for more info"; + OptimizationRemarkMissed R(LV_NAME, "MissedDetails", + TheLoop->getStartLoc(), TheLoop->getHeader()); + R << "loop not vectorized: use -Rpass-analysis=loop-vectorize for more " + "info"; if (Force.Value == LoopVectorizeHints::FK_Enabled) { - R << " (Force=true"; + R << " (Force=" << NV("Force", true); if (Width.Value != 0) - R << ", Vector Width=" << Width.Value; + R << ", Vector Width=" << NV("VectorWidth", Width.Value); if (Interleave.Value != 0) - R << ", Interleave Count=" << Interleave.Value; + R << ", Interleave Count=" << NV("InterleaveCount", Interleave.Value); R << ")"; } + ORE.emit(R); } - - return R.str(); } unsigned getWidth() const { return Width.Value; } @@ -1452,7 +1455,7 @@ static void emitAnalysisDiag(const Loop *TheLoop, static void emitMissedWarning(Function *F, Loop *L, const LoopVectorizeHints &LH, OptimizationRemarkEmitter *ORE) { - ORE->emitOptimizationRemarkMissed(LV_NAME, L, LH.emitRemark()); + LH.emitRemarkWithHints(); if (LH.getForce() == LoopVectorizeHints::FK_Enabled) { if (LH.getWidth() != 1) -- 2.50.1