From 49e45b454fc0e2610b0a1a228d8fc1ff8db51dbd Mon Sep 17 00:00:00 2001 From: Adam Nemet Date: Thu, 2 Feb 2017 05:41:51 +0000 Subject: [PATCH] [LV] Also port failure remarks to new OptimizationRemarkEmitter API git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293866 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/IR/DiagnosticInfo.h | 21 +++---- lib/Analysis/OptimizationDiagnosticInfo.cpp | 4 +- lib/IR/DiagnosticInfo.cpp | 19 +++---- lib/Transforms/Vectorize/LoopVectorize.cpp | 16 ++++-- .../X86/vectorization-remarks-missed.ll | 57 +++++++++++++++++++ 5 files changed, 85 insertions(+), 32 deletions(-) diff --git a/include/llvm/IR/DiagnosticInfo.h b/include/llvm/IR/DiagnosticInfo.h index 8361c577f9e..1a5770c8632 100644 --- a/include/llvm/IR/DiagnosticInfo.h +++ b/include/llvm/IR/DiagnosticInfo.h @@ -891,6 +891,14 @@ public: : DiagnosticInfoIROptimization(DK_OptimizationFailure, DS_Warning, nullptr, Fn, DLoc, Msg) {} + /// \p PassName is the name of the pass emitting this diagnostic. \p + /// RemarkName is a textual identifier for the remark (single-word, + /// camel-case). \p DLoc is the debug location and \p CodeRegion is the + /// region that the optimization operates on (currently basic block is + /// supported). + DiagnosticInfoOptimizationFailure(const char *PassName, StringRef RemarkName, + const DebugLoc &DLoc, Value *CodeRegion); + static bool classof(const DiagnosticInfo *DI) { return DI->getKind() == DK_OptimizationFailure; } @@ -926,19 +934,6 @@ public: void print(DiagnosticPrinter &DP) const override; }; - -/// Emit a warning when loop vectorization is specified but fails. \p Fn is the -/// function triggering the warning, \p DLoc is the debug location where the -/// diagnostic is generated. \p Msg is the message string to use. -void emitLoopVectorizeWarning(LLVMContext &Ctx, const Function &Fn, - const DebugLoc &DLoc, const Twine &Msg); - -/// Emit a warning when loop interleaving is specified but fails. \p Fn is the -/// function triggering the warning, \p DLoc is the debug location where the -/// diagnostic is generated. \p Msg is the message string to use. -void emitLoopInterleaveWarning(LLVMContext &Ctx, const Function &Fn, - const DebugLoc &DLoc, const Twine &Msg); - } // end namespace llvm #endif // LLVM_IR_DIAGNOSTICINFO_H diff --git a/lib/Analysis/OptimizationDiagnosticInfo.cpp b/lib/Analysis/OptimizationDiagnosticInfo.cpp index a104a786afd..d3f7493a787 100644 --- a/lib/Analysis/OptimizationDiagnosticInfo.cpp +++ b/lib/Analysis/OptimizationDiagnosticInfo.cpp @@ -93,8 +93,10 @@ void MappingTraits::mapping( OptDiag->getKind() == DK_OptimizationRemarkAnalysisAliasing)) ; + else if (io.mapTag("!Failure", OptDiag->getKind() == DK_OptimizationFailure)) + ; else - llvm_unreachable("todo"); + llvm_unreachable("Unknown remark type"); // These are read-only for now. DebugLoc DL = OptDiag->getDebugLoc(); diff --git a/lib/IR/DiagnosticInfo.cpp b/lib/IR/DiagnosticInfo.cpp index f9815eb45d4..d27eb7672d8 100644 --- a/lib/IR/DiagnosticInfo.cpp +++ b/lib/IR/DiagnosticInfo.cpp @@ -319,6 +319,13 @@ void llvm::emitOptimizationRemarkAnalysisAliasing(LLVMContext &Ctx, Ctx.diagnose(OptimizationRemarkAnalysisAliasing(PassName, Fn, DLoc, Msg)); } +DiagnosticInfoOptimizationFailure::DiagnosticInfoOptimizationFailure( + const char *PassName, StringRef RemarkName, const DebugLoc &DLoc, + Value *CodeRegion) + : DiagnosticInfoIROptimization( + DK_OptimizationFailure, DS_Warning, PassName, RemarkName, + *cast(CodeRegion)->getParent(), DLoc, CodeRegion) {} + bool DiagnosticInfoOptimizationFailure::isEnabled() const { // Only print warnings. return getSeverity() == DS_Warning; @@ -334,18 +341,6 @@ void DiagnosticInfoUnsupported::print(DiagnosticPrinter &DP) const { DP << Str; } -void llvm::emitLoopVectorizeWarning(LLVMContext &Ctx, const Function &Fn, - const DebugLoc &DLoc, const Twine &Msg) { - Ctx.diagnose(DiagnosticInfoOptimizationFailure( - Fn, DLoc, Twine("loop not vectorized: " + Msg))); -} - -void llvm::emitLoopInterleaveWarning(LLVMContext &Ctx, const Function &Fn, - const DebugLoc &DLoc, const Twine &Msg) { - Ctx.diagnose(DiagnosticInfoOptimizationFailure( - Fn, DLoc, Twine("loop not interleaved: " + Msg))); -} - void DiagnosticInfoISelFallback::print(DiagnosticPrinter &DP) const { DP << "Instruction selection used fallback path for " << getFunction(); } diff --git a/lib/Transforms/Vectorize/LoopVectorize.cpp b/lib/Transforms/Vectorize/LoopVectorize.cpp index e75a47d51d1..e2edcd788e5 100644 --- a/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -1513,13 +1513,17 @@ static void emitMissedWarning(Function *F, Loop *L, if (LH.getForce() == LoopVectorizeHints::FK_Enabled) { if (LH.getWidth() != 1) - emitLoopVectorizeWarning( - F->getContext(), *F, L->getStartLoc(), - "failed explicitly specified loop vectorization"); + ORE->emit(DiagnosticInfoOptimizationFailure( + DEBUG_TYPE, "FailedRequestedVectorization", + L->getStartLoc(), L->getHeader()) + << "loop not vectorized: " + << "failed explicitly specified loop vectorization"); else if (LH.getInterleave() != 1) - emitLoopInterleaveWarning( - F->getContext(), *F, L->getStartLoc(), - "failed explicitly specified loop interleaving"); + ORE->emit(DiagnosticInfoOptimizationFailure( + DEBUG_TYPE, "FailedRequestedInterleaving", L->getStartLoc(), + L->getHeader()) + << "loop not interleaved: " + << "failed explicitly specified loop interleaving"); } } diff --git a/test/Transforms/LoopVectorize/X86/vectorization-remarks-missed.ll b/test/Transforms/LoopVectorize/X86/vectorization-remarks-missed.ll index f28e6be2352..b2933c4b56f 100644 --- a/test/Transforms/LoopVectorize/X86/vectorization-remarks-missed.ll +++ b/test/Transforms/LoopVectorize/X86/vectorization-remarks-missed.ll @@ -1,4 +1,6 @@ ; RUN: opt < %s -loop-vectorize -S -pass-remarks-missed='loop-vectorize' -pass-remarks-analysis='loop-vectorize' 2>&1 | FileCheck %s +; RUN: opt < %s -loop-vectorize -o /dev/null -pass-remarks-output=%t.yaml +; RUN: cat %t.yaml | FileCheck -check-prefix=YAML %s ; C/C++ code for tests ; void test(int *A, int Length) { @@ -42,6 +44,61 @@ ; CHECK-NOT: x i32> ; CHECK: ret +; YAML: --- !Analysis +; YAML-NEXT: Pass: loop-vectorize +; YAML-NEXT: Name: CantComputeNumberOfIterations +; YAML-NEXT: DebugLoc: { File: source.cpp, Line: 4, Column: 5 } +; YAML-NEXT: Function: _Z4testPii +; YAML-NEXT: Args: +; YAML-NEXT: - String: 'loop not vectorized: ' +; YAML-NEXT: - String: could not determine number of loop iterations +; YAML-NEXT: ... +; YAML-NEXT: --- !Missed +; YAML-NEXT: Pass: loop-vectorize +; YAML-NEXT: Name: MissedDetails +; YAML-NEXT: DebugLoc: { File: source.cpp, Line: 4, Column: 5 } +; YAML-NEXT: Function: _Z4testPii +; YAML-NEXT: Args: +; YAML-NEXT: - String: loop not vectorized +; YAML-NEXT: ... +; YAML-NEXT: --- !Analysis +; YAML-NEXT: Pass: loop-vectorize +; YAML-NEXT: Name: AllDisabled +; YAML-NEXT: DebugLoc: { File: source.cpp, Line: 13, Column: 5 } +; YAML-NEXT: Function: _Z13test_disabledPii +; YAML-NEXT: Args: +; YAML-NEXT: - String: 'loop not vectorized: vectorization and interleaving are explicitly disabled, or vectorize width and interleave count are both set to 1' +; YAML-NEXT: ... +; YAML-NEXT: --- !Analysis +; YAML-NEXT: Pass: '' +; YAML-NEXT: Name: CantIdentifyArrayBounds +; YAML-NEXT: DebugLoc: { File: source.cpp, Line: 19, Column: 5 } +; YAML-NEXT: Function: _Z17test_array_boundsPiS_i +; YAML-NEXT: Args: +; YAML-NEXT: - String: 'loop not vectorized: ' +; YAML-NEXT: - String: cannot identify array bounds +; YAML-NEXT: ... +; YAML-NEXT: --- !Missed +; YAML-NEXT: Pass: loop-vectorize +; YAML-NEXT: Name: MissedDetails +; YAML-NEXT: DebugLoc: { File: source.cpp, Line: 19, Column: 5 } +; YAML-NEXT: Function: _Z17test_array_boundsPiS_i +; YAML-NEXT: Args: +; YAML-NEXT: - String: loop not vectorized +; YAML-NEXT: - String: ' (Force=' +; YAML-NEXT: - Force: 'true' +; YAML-NEXT: - String: ')' +; YAML-NEXT: ... +; YAML-NEXT: --- !Failure +; YAML-NEXT: Pass: loop-vectorize +; YAML-NEXT: Name: FailedRequestedVectorization +; YAML-NEXT: DebugLoc: { File: source.cpp, Line: 19, Column: 5 } +; YAML-NEXT: Function: _Z17test_array_boundsPiS_i +; YAML-NEXT: Args: +; YAML-NEXT: - String: 'loop not vectorized: ' +; YAML-NEXT: - String: failed explicitly specified loop vectorization +; YAML-NEXT: ... + target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128" ; Function Attrs: nounwind optsize ssp uwtable