diff --git a/clang/include/clang/Basic/DiagnosticFrontendKinds.td b/clang/include/clang/Basic/DiagnosticFrontendKinds.td index 1c759024abb0..033834bc505d 100644 --- a/clang/include/clang/Basic/DiagnosticFrontendKinds.td +++ b/clang/include/clang/Basic/DiagnosticFrontendKinds.td @@ -58,10 +58,8 @@ def remark_fe_backend_optimization_remark_analysis_aliasing : Remark<"%0; " BackendInfo, InGroup; def warn_fe_backend_optimization_failure : Warning<"%0">, BackendInfo, InGroup, DefaultWarn; -def note_fe_backend_invalid_loc : Note<"could " - "not determine the original source location for %0:%1:%2">, BackendInfo; - -def err_fe_backend_unsupported : Error<"%0">, BackendInfo; +def note_fe_backend_optimization_remark_invalid_loc : Note<"could " + "not determine the original source location for %0:%1:%2">; def remark_sanitize_address_insert_extra_padding_accepted : Remark< "-fsanitize-address-field-padding applied to %0">, ShowInSystemHeader, diff --git a/clang/lib/CodeGen/CodeGenAction.cpp b/clang/lib/CodeGen/CodeGenAction.cpp index 645663ff7b7c..f8ae031f0f3b 100644 --- a/clang/lib/CodeGen/CodeGenAction.cpp +++ b/clang/lib/CodeGen/CodeGenAction.cpp @@ -242,13 +242,6 @@ namespace clang { ((BackendConsumer *)Context)->DiagnosticHandlerImpl(DI); } - /// Get the best possible source location to represent a diagnostic that - /// may have associated debug info. - const FullSourceLoc - getBestLocationFromDebugLoc(const llvm::DiagnosticInfoWithDebugLocBase &D, - bool &BadDebugInfo, StringRef &Filename, - unsigned &Line, unsigned &Column) const; - void InlineAsmDiagHandler2(const llvm::SMDiagnostic &, SourceLocation LocCookie); @@ -261,8 +254,6 @@ namespace clang { /// \return True if the diagnostic has been successfully reported, false /// otherwise. bool StackSizeDiagHandler(const llvm::DiagnosticInfoStackSize &D); - /// \brief Specialized handler for unsupported backend feature diagnostic. - void UnsupportedDiagHandler(const llvm::DiagnosticInfoUnsupported &D); /// \brief Specialized handlers for optimization remarks. /// Note that these handlers only accept remarks and they always handle /// them. @@ -448,11 +439,16 @@ BackendConsumer::StackSizeDiagHandler(const llvm::DiagnosticInfoStackSize &D) { return false; } -const FullSourceLoc BackendConsumer::getBestLocationFromDebugLoc( - const llvm::DiagnosticInfoWithDebugLocBase &D, bool &BadDebugInfo, StringRef &Filename, - unsigned &Line, unsigned &Column) const { +void BackendConsumer::EmitOptimizationMessage( + const llvm::DiagnosticInfoOptimizationBase &D, unsigned DiagID) { + // We only support warnings and remarks. + assert(D.getSeverity() == llvm::DS_Remark || + D.getSeverity() == llvm::DS_Warning); + SourceManager &SourceMgr = Context->getSourceManager(); FileManager &FileMgr = SourceMgr.getFileManager(); + StringRef Filename; + unsigned Line, Column; SourceLocation DILoc; if (D.isLocationAvailable()) { @@ -463,7 +459,6 @@ const FullSourceLoc BackendConsumer::getBestLocationFromDebugLoc( // source manager, so pass 1 if Column is not set. DILoc = SourceMgr.translateFileLineCol(FE, Line, Column ? Column : 1); } - BadDebugInfo = DILoc.isInvalid(); } // If a location isn't available, try to approximate it using the associated @@ -472,63 +467,18 @@ const FullSourceLoc BackendConsumer::getBestLocationFromDebugLoc( FullSourceLoc Loc(DILoc, SourceMgr); if (Loc.isInvalid()) if (const Decl *FD = Gen->GetDeclForMangledName(D.getFunction().getName())) - Loc = FD->getASTContext().getFullLoc(FD->getLocation()); + Loc = FD->getASTContext().getFullLoc(FD->getBodyRBrace()); + + Diags.Report(Loc, DiagID) + << AddFlagValue(D.getPassName() ? D.getPassName() : "") + << D.getMsg().str(); if (DILoc.isInvalid() && D.isLocationAvailable()) // If we were not able to translate the file:line:col information // back to a SourceLocation, at least emit a note stating that // we could not translate this location. This can happen in the // case of #line directives. - Diags.Report(Loc, diag::note_fe_backend_invalid_loc) - << Filename << Line; - - return Loc; -} - -void BackendConsumer::UnsupportedDiagHandler( - const llvm::DiagnosticInfoUnsupported &D) { - // We only support errors. - assert(D.getSeverity() == llvm::DS_Error); - - StringRef Filename; - unsigned Line, Column; - bool BadDebugInfo; - FullSourceLoc Loc = getBestLocationFromDebugLoc(D, BadDebugInfo, Filename, - Line, Column); - - Diags.Report(Loc, diag::err_fe_backend_unsupported) << D.getMessage().str(); - - if (BadDebugInfo) - // If we were not able to translate the file:line:col information - // back to a SourceLocation, at least emit a note stating that - // we could not translate this location. This can happen in the - // case of #line directives. - Diags.Report(Loc, diag::note_fe_backend_invalid_loc) - << Filename << Line << Column; -} - -void BackendConsumer::EmitOptimizationMessage( - const llvm::DiagnosticInfoOptimizationBase &D, unsigned DiagID) { - // We only support warnings and remarks. - assert(D.getSeverity() == llvm::DS_Remark || - D.getSeverity() == llvm::DS_Warning); - - StringRef Filename; - unsigned Line, Column; - bool BadDebugInfo = false; - FullSourceLoc Loc = getBestLocationFromDebugLoc(D, BadDebugInfo, Filename, - Line, Column); - - Diags.Report(Loc, DiagID) - << AddFlagValue(D.getPassName() ? D.getPassName() : "") - << D.getMsg().str(); - - if (BadDebugInfo) - // If we were not able to translate the file:line:col information - // back to a SourceLocation, at least emit a note stating that - // we could not translate this location. This can happen in the - // case of #line directives. - Diags.Report(Loc, diag::note_fe_backend_invalid_loc) + Diags.Report(Loc, diag::note_fe_backend_optimization_remark_invalid_loc) << Filename << Line << Column; } @@ -653,9 +603,6 @@ void BackendConsumer::DiagnosticHandlerImpl(const DiagnosticInfo &DI) { // handler. OptimizationFailureHandler(cast(DI)); return; - case llvm::DK_Unsupported: - UnsupportedDiagHandler(cast(DI)); - return; default: // Plugin IDs are not bound to any value as they are set dynamically. ComputeDiagRemarkID(Severity, backend_plugin, DiagID); diff --git a/clang/test/CodeGen/backend-unsupported-error.ll b/clang/test/CodeGen/backend-unsupported-error.ll deleted file mode 100644 index 467897b5c93a..000000000000 --- a/clang/test/CodeGen/backend-unsupported-error.ll +++ /dev/null @@ -1,45 +0,0 @@ -; RUN: not %clang_cc1 -triple r600-unknown-unknown -S -o - %s 2>&1 | FileCheck %s -; REQUIRES: amdgpu-registered-target - -; This is to check that backend errors for unsupported features are formatted correctly - -; CHECK: error: test.c:2:20: in function bar i32 (): unsupported call to function foo.2 - -target triple = "r600-unknown-unknown" - -; Function Attrs: nounwind uwtable -define i32 @bar() #0 !dbg !4 { -entry: - %call = call i32 @foo(), !dbg !12 - ret i32 %call, !dbg !13 -} - -; Function Attrs: nounwind uwtable -define i32 @foo() #0 !dbg !8 { -entry: - %call = call i32 @bar(), !dbg !14 - ret i32 %call, !dbg !15 -} - -attributes #0 = { nounwind uwtable "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" } - -!llvm.dbg.cu = !{!0} -!llvm.module.flags = !{!9, !10} -!llvm.ident = !{!11} - -!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 3.9.0", isOptimized: false, runtimeVersion: 0, emissionKind: 1, enums: !2, subprograms: !3) -!1 = !DIFile(filename: "test.c", directory: "") -!2 = !{} -!3 = !{!4, !8} -!4 = distinct !DISubprogram(name: "bar", scope: !1, file: !1, line: 2, type: !5, isLocal: false, isDefinition: true, scopeLine: 2, isOptimized: false, variables: !2) -!5 = !DISubroutineType(types: !6) -!6 = !{!7} -!7 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed) -!8 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 3, type: !5, isLocal: false, isDefinition: true, scopeLine: 3, flags: DIFlagPrototyped, isOptimized: false, variables: !2) -!9 = !{i32 2, !"Dwarf Version", i32 4} -!10 = !{i32 2, !"Debug Info Version", i32 3} -!11 = !{!"clang version 3.9.0"} -!12 = !DILocation(line: 2, column: 20, scope: !4) -!13 = !DILocation(line: 2, column: 13, scope: !4) -!14 = !DILocation(line: 3, column: 20, scope: !8) -!15 = !DILocation(line: 3, column: 13, scope: !8) diff --git a/clang/test/Frontend/optimization-remark-analysis.c b/clang/test/Frontend/optimization-remark-analysis.c index b39632797618..5b4d9aec41ae 100644 --- a/clang/test/Frontend/optimization-remark-analysis.c +++ b/clang/test/Frontend/optimization-remark-analysis.c @@ -1,8 +1,8 @@ // RUN: %clang -O1 -fvectorize -target x86_64-unknown-unknown -emit-llvm -Rpass-analysis -S %s -o - 2>&1 | FileCheck %s --check-prefix=RPASS // RUN: %clang -O1 -fvectorize -target x86_64-unknown-unknown -emit-llvm -S %s -o - 2>&1 | FileCheck %s -// RPASS: {{.*}}:7:8: remark: loop not vectorized: loop contains a switch statement -// CHECK-NOT: {{.*}}:7:8: remark: loop not vectorized: loop contains a switch statement +// RPASS: {{.*}}:21:1: remark: loop not vectorized: loop contains a switch statement +// CHECK-NOT: {{.*}}:21:1: remark: loop not vectorized: loop contains a switch statement double foo(int N, int *Array) { double v = 0.0; diff --git a/clang/test/Misc/backend-optimization-failure-nodbg.cpp b/clang/test/Misc/backend-optimization-failure-nodbg.cpp index 1e847185e81c..3c3264601424 100644 --- a/clang/test/Misc/backend-optimization-failure-nodbg.cpp +++ b/clang/test/Misc/backend-optimization-failure-nodbg.cpp @@ -4,7 +4,7 @@ // Test verifies optimization failures generated by the backend are handled // correctly by clang. LLVM tests verify all of the failure conditions. -void test_switch(int *A, int *B, int Length) { /* expected-warning {{loop not vectorized: failed explicitly specified loop vectorization}} */ +void test_switch(int *A, int *B, int Length) { #pragma clang loop vectorize(enable) unroll(disable) for (int i = 0; i < Length; i++) { switch (A[i]) { @@ -18,4 +18,4 @@ void test_switch(int *A, int *B, int Length) { /* expected-warning {{loop not ve B[i] = 3; } } -} +/* expected-warning {{loop not vectorized: failed explicitly specified loop vectorization}} */ } diff --git a/llvm/include/llvm/IR/DiagnosticInfo.h b/llvm/include/llvm/IR/DiagnosticInfo.h index 892dab651b32..f69955e5ed48 100644 --- a/llvm/include/llvm/IR/DiagnosticInfo.h +++ b/llvm/include/llvm/IR/DiagnosticInfo.h @@ -16,7 +16,6 @@ #define LLVM_IR_DIAGNOSTICINFO_H #include "llvm/ADT/ArrayRef.h" -#include "llvm/CodeGen/SelectionDAG.h" #include "llvm/IR/DebugLoc.h" #include "llvm/IR/Module.h" #include "llvm/Support/Casting.h" @@ -61,7 +60,6 @@ enum DiagnosticKind { DK_OptimizationFailure, DK_MIRParser, DK_PGOProfile, - DK_Unsupported, DK_FirstPluginKind }; @@ -277,16 +275,32 @@ private: const Twine &Msg; }; -/// Common features for diagnostics with an associated DebugLoc -class DiagnosticInfoWithDebugLocBase : public DiagnosticInfo { +/// Common features for diagnostics dealing with optimization remarks. +class DiagnosticInfoOptimizationBase : public DiagnosticInfo { public: + /// \p PassName is the name of the pass emitting this diagnostic. /// \p Fn is the function where the diagnostic is being emitted. \p DLoc is - /// the location information to use in the diagnostic. - DiagnosticInfoWithDebugLocBase(enum DiagnosticKind Kind, + /// the location information to use in the diagnostic. If line table + /// information is available, the diagnostic will include the source code + /// location. \p Msg is the message to show. Note that this class does not + /// copy this message, so this reference must be valid for the whole life time + /// of the diagnostic. + DiagnosticInfoOptimizationBase(enum DiagnosticKind Kind, enum DiagnosticSeverity Severity, - const Function &Fn, - const DebugLoc &DLoc) - : DiagnosticInfo(Kind, Severity), Fn(Fn), DLoc(DLoc) {} + const char *PassName, const Function &Fn, + const DebugLoc &DLoc, const Twine &Msg) + : DiagnosticInfo(Kind, Severity), PassName(PassName), Fn(Fn), DLoc(DLoc), + Msg(Msg) {} + + /// \see DiagnosticInfo::print. + void print(DiagnosticPrinter &DP) const override; + + /// Return true if this optimization remark is enabled by one of + /// of the LLVM command line flags (-pass-remarks, -pass-remarks-missed, + /// or -pass-remarks-analysis). Note that this only handles the LLVM + /// flags. We cannot access Clang flags from here (they are handled + /// in BackendConsumer::OptimizationRemarkHandler). + virtual bool isEnabled() const = 0; /// Return true if location information is available for this diagnostic. bool isLocationAvailable() const; @@ -300,45 +314,9 @@ public: /// the source file name, line number and column. void getLocation(StringRef *Filename, unsigned *Line, unsigned *Column) const; + const char *getPassName() const { return PassName; } const Function &getFunction() const { return Fn; } const DebugLoc &getDebugLoc() const { return DLoc; } - -private: - /// Function where this diagnostic is triggered. - const Function &Fn; - - /// Debug location where this diagnostic is triggered. - DebugLoc DLoc; -}; - -/// Common features for diagnostics dealing with optimization remarks. -class DiagnosticInfoOptimizationBase : public DiagnosticInfoWithDebugLocBase { -public: - /// \p PassName is the name of the pass emitting this diagnostic. - /// \p Fn is the function where the diagnostic is being emitted. \p DLoc is - /// the location information to use in the diagnostic. If line table - /// information is available, the diagnostic will include the source code - /// location. \p Msg is the message to show. Note that this class does not - /// copy this message, so this reference must be valid for the whole life time - /// of the diagnostic. - DiagnosticInfoOptimizationBase(enum DiagnosticKind Kind, - enum DiagnosticSeverity Severity, - const char *PassName, const Function &Fn, - const DebugLoc &DLoc, const Twine &Msg) - : DiagnosticInfoWithDebugLocBase(Kind, Severity, Fn, DLoc), - PassName(PassName), Msg(Msg) {} - - /// \see DiagnosticInfo::print. - void print(DiagnosticPrinter &DP) const override; - - /// Return true if this optimization remark is enabled by one of - /// of the LLVM command line flags (-pass-remarks, -pass-remarks-missed, - /// or -pass-remarks-analysis). Note that this only handles the LLVM - /// flags. We cannot access Clang flags from here (they are handled - /// in BackendConsumer::OptimizationRemarkHandler). - virtual bool isEnabled() const = 0; - - const char *getPassName() const { return PassName; } const Twine &getMsg() const { return Msg; } private: @@ -347,6 +325,12 @@ private: /// be emitted. const char *PassName; + /// Function where this diagnostic is triggered. + const Function &Fn; + + /// Debug location where this diagnostic is triggered. + DebugLoc DLoc; + /// Message to report. const Twine &Msg; }; @@ -588,35 +572,6 @@ public: bool isEnabled() const override; }; -/// Diagnostic information for unsupported feature in backend. -class DiagnosticInfoUnsupported - : public DiagnosticInfoWithDebugLocBase { -private: - const Twine &Msg; - const SDValue Value; - -public: - /// \p Fn is the function where the diagnostic is being emitted. \p DLoc is - /// the location information to use in the diagnostic. If line table - /// information is available, the diagnostic will include the source code - /// location. \p Msg is the message to show. Note that this class does not - /// copy this message, so this reference must be valid for the whole life time - /// of the diagnostic. - DiagnosticInfoUnsupported(const Function &Fn, const Twine &Msg, - SDLoc DLoc = SDLoc(), SDValue Value = SDValue()) - : DiagnosticInfoWithDebugLocBase(DK_Unsupported, DS_Error, Fn, - DLoc.getDebugLoc()), - Msg(Msg), Value(Value) {} - - static bool classof(const DiagnosticInfo *DI) { - return DI->getKind() == DK_Unsupported; - } - - const Twine &getMessage() const { return Msg; } - - void print(DiagnosticPrinter &DP) const; -}; - /// 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. diff --git a/llvm/lib/CodeGen/CMakeLists.txt b/llvm/lib/CodeGen/CMakeLists.txt index b55a475445ab..8e326fae4e3b 100644 --- a/llvm/lib/CodeGen/CMakeLists.txt +++ b/llvm/lib/CodeGen/CMakeLists.txt @@ -18,7 +18,6 @@ add_llvm_library(LLVMCodeGen CriticalAntiDepBreaker.cpp DeadMachineInstructionElim.cpp DFAPacketizer.cpp - DiagnosticInfoCodeGen.cpp DwarfEHPrepare.cpp EarlyIfConversion.cpp EdgeBundles.cpp diff --git a/llvm/lib/CodeGen/DiagnosticInfoCodeGen.cpp b/llvm/lib/CodeGen/DiagnosticInfoCodeGen.cpp deleted file mode 100644 index 23d3a5b23ed8..000000000000 --- a/llvm/lib/CodeGen/DiagnosticInfoCodeGen.cpp +++ /dev/null @@ -1,33 +0,0 @@ -//===- llvm/Support/DiagnosticInfo.cpp - Diagnostic Definitions -*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -// -// This file defines the different classes involved in codegen diagnostics. -// -// Diagnostics reporting is still done as part of the LLVMContext. -//===----------------------------------------------------------------------===// - -#include "llvm/IR/DiagnosticInfo.h" -#include "llvm/IR/DiagnosticPrinter.h" - -namespace llvm { - -void DiagnosticInfoUnsupported::print(DiagnosticPrinter &DP) const { - std::string Str; - raw_string_ostream OS(Str); - - OS << getLocationStr() << ": in function " << getFunction().getName() << ' ' - << *getFunction().getFunctionType() << ": " << Msg; - if (Value) - Value->print(OS); - OS << '\n'; - OS.flush(); - DP << Str; -} - -} diff --git a/llvm/lib/IR/DiagnosticInfo.cpp b/llvm/lib/IR/DiagnosticInfo.cpp index b16c5f33377a..6426f76bbaa6 100644 --- a/llvm/lib/IR/DiagnosticInfo.cpp +++ b/llvm/lib/IR/DiagnosticInfo.cpp @@ -138,11 +138,11 @@ void DiagnosticInfoPGOProfile::print(DiagnosticPrinter &DP) const { DP << getMsg(); } -bool DiagnosticInfoWithDebugLocBase::isLocationAvailable() const { +bool DiagnosticInfoOptimizationBase::isLocationAvailable() const { return getDebugLoc(); } -void DiagnosticInfoWithDebugLocBase::getLocation(StringRef *Filename, +void DiagnosticInfoOptimizationBase::getLocation(StringRef *Filename, unsigned *Line, unsigned *Column) const { DILocation *L = getDebugLoc(); @@ -152,7 +152,7 @@ void DiagnosticInfoWithDebugLocBase::getLocation(StringRef *Filename, *Column = L->getColumn(); } -const std::string DiagnosticInfoWithDebugLocBase::getLocationStr() const { +const std::string DiagnosticInfoOptimizationBase::getLocationStr() const { StringRef Filename(""); unsigned Line = 0; unsigned Column = 0; diff --git a/llvm/lib/Target/AMDGPU/AMDGPUDiagnosticInfoUnsupported.cpp b/llvm/lib/Target/AMDGPU/AMDGPUDiagnosticInfoUnsupported.cpp new file mode 100644 index 000000000000..2f6b3022dd6e --- /dev/null +++ b/llvm/lib/Target/AMDGPU/AMDGPUDiagnosticInfoUnsupported.cpp @@ -0,0 +1,26 @@ +//===-- AMDGPUDiagnosticInfoUnsupported.cpp -------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "AMDGPUDiagnosticInfoUnsupported.h" + +using namespace llvm; + +DiagnosticInfoUnsupported::DiagnosticInfoUnsupported( + const Function &Fn, + const Twine &Desc, + DiagnosticSeverity Severity) + : DiagnosticInfo(getKindID(), Severity), + Description(Desc), + Fn(Fn) { } + +int DiagnosticInfoUnsupported::KindID = 0; + +void DiagnosticInfoUnsupported::print(DiagnosticPrinter &DP) const { + DP << "unsupported " << getDescription() << " in " << Fn.getName(); +} diff --git a/llvm/lib/Target/AMDGPU/AMDGPUDiagnosticInfoUnsupported.h b/llvm/lib/Target/AMDGPU/AMDGPUDiagnosticInfoUnsupported.h new file mode 100644 index 000000000000..0fd37e1ede6b --- /dev/null +++ b/llvm/lib/Target/AMDGPU/AMDGPUDiagnosticInfoUnsupported.h @@ -0,0 +1,48 @@ +//===-- AMDGPUDiagnosticInfoUnsupported.h - Error reporting -----*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIB_TARGET_AMDGPU_AMDGPUDIAGNOSTICINFOUNSUPPORTED_H +#define LLVM_LIB_TARGET_AMDGPU_AMDGPUDIAGNOSTICINFOUNSUPPORTED_H + +#include "llvm/IR/DiagnosticInfo.h" +#include "llvm/IR/DiagnosticPrinter.h" + +namespace llvm { + +/// Diagnostic information for unimplemented or unsupported feature reporting. +class DiagnosticInfoUnsupported : public DiagnosticInfo { +private: + const Twine &Description; + const Function &Fn; + + static int KindID; + + static int getKindID() { + if (KindID == 0) + KindID = llvm::getNextAvailablePluginDiagnosticKind(); + return KindID; + } + +public: + DiagnosticInfoUnsupported(const Function &Fn, const Twine &Desc, + DiagnosticSeverity Severity = DS_Error); + + const Function &getFunction() const { return Fn; } + const Twine &getDescription() const { return Description; } + + void print(DiagnosticPrinter &DP) const override; + + static bool classof(const DiagnosticInfo *DI) { + return DI->getKind() == getKindID(); + } +}; + +} + +#endif diff --git a/llvm/lib/Target/AMDGPU/AMDGPUISelDAGToDAG.cpp b/llvm/lib/Target/AMDGPU/AMDGPUISelDAGToDAG.cpp index 99a10c5b59b8..059f6afec75c 100644 --- a/llvm/lib/Target/AMDGPU/AMDGPUISelDAGToDAG.cpp +++ b/llvm/lib/Target/AMDGPU/AMDGPUISelDAGToDAG.cpp @@ -12,6 +12,7 @@ // //===----------------------------------------------------------------------===// +#include "AMDGPUDiagnosticInfoUnsupported.h" #include "AMDGPUInstrInfo.h" #include "AMDGPUISelLowering.h" // For AMDGPUISD #include "AMDGPURegisterInfo.h" @@ -26,7 +27,6 @@ #include "llvm/CodeGen/PseudoSourceValue.h" #include "llvm/CodeGen/SelectionDAG.h" #include "llvm/CodeGen/SelectionDAGISel.h" -#include "llvm/IR/DiagnosticInfo.h" #include "llvm/IR/Function.h" using namespace llvm; @@ -1220,7 +1220,7 @@ SDNode *AMDGPUDAGToDAGISel::SelectAddrSpaceCast(SDNode *N) { const MachineFunction &MF = CurDAG->getMachineFunction(); DiagnosticInfoUnsupported NotImplemented(*MF.getFunction(), - "addrspacecast not implemented", DL); + "addrspacecast not implemented"); CurDAG->getContext()->diagnose(NotImplemented); assert(Subtarget->hasFlatAddressSpace() && diff --git a/llvm/lib/Target/AMDGPU/AMDGPUISelLowering.cpp b/llvm/lib/Target/AMDGPU/AMDGPUISelLowering.cpp index 2d5337679511..48f61fb250b6 100644 --- a/llvm/lib/Target/AMDGPU/AMDGPUISelLowering.cpp +++ b/llvm/lib/Target/AMDGPU/AMDGPUISelLowering.cpp @@ -15,7 +15,7 @@ #include "AMDGPUISelLowering.h" #include "AMDGPU.h" -//#include "AMDGPUDiagnosticInfoUnsupported.h" +#include "AMDGPUDiagnosticInfoUnsupported.h" #include "AMDGPUFrameLowering.h" #include "AMDGPUIntrinsicInfo.h" #include "AMDGPURegisterInfo.h" @@ -28,7 +28,6 @@ #include "llvm/CodeGen/SelectionDAG.h" #include "llvm/CodeGen/TargetLoweringObjectFileImpl.h" #include "llvm/IR/DataLayout.h" -#include "llvm/IR/DiagnosticInfo.h" #include "SIInstrInfo.h" using namespace llvm; @@ -610,7 +609,7 @@ SDValue AMDGPUTargetLowering::LowerCall(CallLoweringInfo &CLI, else if (const GlobalAddressSDNode *G = dyn_cast(Callee)) FuncName = G->getGlobal()->getName(); - DiagnosticInfoUnsupported NoCalls(Fn, "unsupported call to function " + FuncName, CLI.DL); + DiagnosticInfoUnsupported NoCalls(Fn, "call to function " + FuncName); DAG.getContext()->diagnose(NoCalls); return SDValue(); } @@ -619,7 +618,7 @@ SDValue AMDGPUTargetLowering::LowerDYNAMIC_STACKALLOC(SDValue Op, SelectionDAG &DAG) const { const Function &Fn = *DAG.getMachineFunction().getFunction(); - DiagnosticInfoUnsupported NoDynamicAlloca(Fn, "unsupported dynamic alloca", SDLoc(Op)); + DiagnosticInfoUnsupported NoDynamicAlloca(Fn, "dynamic alloca"); DAG.getContext()->diagnose(NoDynamicAlloca); return SDValue(); } @@ -866,8 +865,8 @@ SDValue AMDGPUTargetLowering::LowerGlobalAddress(AMDGPUMachineFunction* MFI, } const Function &Fn = *DAG.getMachineFunction().getFunction(); - DiagnosticInfoUnsupported BadInit( - Fn, "unsupported initializer for address space", SDLoc(Op)); + DiagnosticInfoUnsupported BadInit(Fn, + "initializer for address space"); DAG.getContext()->diagnose(BadInit); return SDValue(); } diff --git a/llvm/lib/Target/AMDGPU/CMakeLists.txt b/llvm/lib/Target/AMDGPU/CMakeLists.txt index 8e99f2ba5ab7..b9ef0e821763 100644 --- a/llvm/lib/Target/AMDGPU/CMakeLists.txt +++ b/llvm/lib/Target/AMDGPU/CMakeLists.txt @@ -18,6 +18,7 @@ add_llvm_target(AMDGPUCodeGen AMDGPUAnnotateKernelFeatures.cpp AMDGPUAnnotateUniformValues.cpp AMDGPUAsmPrinter.cpp + AMDGPUDiagnosticInfoUnsupported.cpp AMDGPUFrameLowering.cpp AMDGPUTargetObjectFile.cpp AMDGPUIntrinsicInfo.cpp diff --git a/llvm/lib/Target/AMDGPU/SIISelLowering.cpp b/llvm/lib/Target/AMDGPU/SIISelLowering.cpp index 9a030e887037..faecf3c1da99 100644 --- a/llvm/lib/Target/AMDGPU/SIISelLowering.cpp +++ b/llvm/lib/Target/AMDGPU/SIISelLowering.cpp @@ -20,6 +20,7 @@ #include "SIISelLowering.h" #include "AMDGPU.h" +#include "AMDGPUDiagnosticInfoUnsupported.h" #include "AMDGPUIntrinsicInfo.h" #include "AMDGPUSubtarget.h" #include "SIInstrInfo.h" @@ -31,7 +32,6 @@ #include "llvm/CodeGen/MachineInstrBuilder.h" #include "llvm/CodeGen/MachineRegisterInfo.h" #include "llvm/CodeGen/SelectionDAG.h" -#include "llvm/IR/DiagnosticInfo.h" #include "llvm/IR/Function.h" #include "llvm/ADT/SmallString.h" @@ -591,8 +591,7 @@ SDValue SITargetLowering::LowerFormalArguments( if (Subtarget->isAmdHsaOS() && Info->getShaderType() != ShaderType::COMPUTE) { const Function *Fn = MF.getFunction(); - DiagnosticInfoUnsupported NoGraphicsHSA( - *Fn, "unsupported non-compute shaders with HSA", DL); + DiagnosticInfoUnsupported NoGraphicsHSA(*Fn, "non-compute shaders with HSA"); DAG.getContext()->diagnose(NoGraphicsHSA); return SDValue(); } @@ -1321,9 +1320,8 @@ SDValue SITargetLowering::LowerINTRINSIC_WO_CHAIN(SDValue Op, switch (IntrinsicID) { case Intrinsic::amdgcn_dispatch_ptr: if (!Subtarget->isAmdHsaOS()) { - DiagnosticInfoUnsupported BadIntrin( - *MF.getFunction(), "unsupported hsa intrinsic without hsa target", - DL); + DiagnosticInfoUnsupported BadIntrin(*MF.getFunction(), + "hsa intrinsic without hsa target"); DAG.getContext()->diagnose(BadIntrin); return DAG.getUNDEF(VT); } diff --git a/llvm/lib/Target/BPF/BPFISelLowering.cpp b/llvm/lib/Target/BPF/BPFISelLowering.cpp index d26e584eaaa9..6a5b37e153d8 100644 --- a/llvm/lib/Target/BPF/BPFISelLowering.cpp +++ b/llvm/lib/Target/BPF/BPFISelLowering.cpp @@ -34,6 +34,60 @@ using namespace llvm; #define DEBUG_TYPE "bpf-lower" +namespace { + +// Diagnostic information for unimplemented or unsupported feature reporting. +class DiagnosticInfoUnsupported : public DiagnosticInfo { +private: + // Debug location where this diagnostic is triggered. + DebugLoc DLoc; + const Twine &Description; + const Function &Fn; + SDValue Value; + + static int KindID; + + static int getKindID() { + if (KindID == 0) + KindID = llvm::getNextAvailablePluginDiagnosticKind(); + return KindID; + } + +public: + DiagnosticInfoUnsupported(SDLoc DLoc, const Function &Fn, const Twine &Desc, + SDValue Value) + : DiagnosticInfo(getKindID(), DS_Error), DLoc(DLoc.getDebugLoc()), + Description(Desc), Fn(Fn), Value(Value) {} + + void print(DiagnosticPrinter &DP) const override { + std::string Str; + raw_string_ostream OS(Str); + + if (DLoc) { + auto DIL = DLoc.get(); + StringRef Filename = DIL->getFilename(); + unsigned Line = DIL->getLine(); + unsigned Column = DIL->getColumn(); + OS << Filename << ':' << Line << ':' << Column << ' '; + } + + OS << "in function " << Fn.getName() << ' ' << *Fn.getFunctionType() << '\n' + << Description; + if (Value) + Value->print(OS); + OS << '\n'; + OS.flush(); + DP << Str; + } + + static bool classof(const DiagnosticInfo *DI) { + return DI->getKind() == getKindID(); + } +}; + +int DiagnosticInfoUnsupported::KindID = 0; +} + BPFTargetLowering::BPFTargetLowering(const TargetMachine &TM, const BPFSubtarget &STI) : TargetLowering(TM) { @@ -182,16 +236,16 @@ SDValue BPFTargetLowering::LowerFormalArguments( InVals.push_back(ArgValue); } } else { - DiagnosticInfoUnsupported Err( - *MF.getFunction(), "defined with too many args", DL); + DiagnosticInfoUnsupported Err(DL, *MF.getFunction(), + "defined with too many args", SDValue()); DAG.getContext()->diagnose(Err); } } if (IsVarArg || MF.getFunction()->hasStructRetAttr()) { DiagnosticInfoUnsupported Err( - *MF.getFunction(), - "functions with VarArgs or StructRet are not supported", DL); + DL, *MF.getFunction(), + "functions with VarArgs or StructRet are not supported", SDValue()); DAG.getContext()->diagnose(Err); } @@ -231,8 +285,8 @@ SDValue BPFTargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI, unsigned NumBytes = CCInfo.getNextStackOffset(); if (Outs.size() >= 6) { - DiagnosticInfoUnsupported Err(*MF.getFunction(), "too many args to ", - CLI.DL, Callee); + DiagnosticInfoUnsupported Err(CLI.DL, *MF.getFunction(), + "too many args to ", Callee); DAG.getContext()->diagnose(Err); } @@ -241,8 +295,8 @@ SDValue BPFTargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI, if (!Flags.isByVal()) continue; - DiagnosticInfoUnsupported Err( - *MF.getFunction(), "pass by value not supported ", CLI.DL, Callee); + DiagnosticInfoUnsupported Err(CLI.DL, *MF.getFunction(), + "pass by value not supported ", Callee); DAG.getContext()->diagnose(Err); } @@ -344,8 +398,8 @@ BPFTargetLowering::LowerReturn(SDValue Chain, CallingConv::ID CallConv, CCState CCInfo(CallConv, IsVarArg, MF, RVLocs, *DAG.getContext()); if (MF.getFunction()->getReturnType()->isAggregateType()) { - DiagnosticInfoUnsupported Err( - *MF.getFunction(), "only integer returns supported", DL); + DiagnosticInfoUnsupported Err(DL, *MF.getFunction(), + "only integer returns supported", SDValue()); DAG.getContext()->diagnose(Err); } @@ -389,8 +443,8 @@ SDValue BPFTargetLowering::LowerCallResult( CCState CCInfo(CallConv, IsVarArg, MF, RVLocs, *DAG.getContext()); if (Ins.size() >= 2) { - DiagnosticInfoUnsupported Err(*MF.getFunction(), - "only small returns supported", DL); + DiagnosticInfoUnsupported Err(DL, *MF.getFunction(), + "only small returns supported", SDValue()); DAG.getContext()->diagnose(Err); } diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp index 3232216ce8c8..c12016b8d2a4 100644 --- a/llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp +++ b/llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp @@ -35,6 +35,61 @@ using namespace llvm; #define DEBUG_TYPE "wasm-lower" +namespace { +// Diagnostic information for unimplemented or unsupported feature reporting. +// TODO: This code is copied from BPF and AMDGPU; consider factoring it out +// and sharing code. +class DiagnosticInfoUnsupported final : public DiagnosticInfo { +private: + // Debug location where this diagnostic is triggered. + DebugLoc DLoc; + const Twine &Description; + const Function &Fn; + SDValue Value; + + static int KindID; + + static int getKindID() { + if (KindID == 0) + KindID = llvm::getNextAvailablePluginDiagnosticKind(); + return KindID; + } + +public: + DiagnosticInfoUnsupported(SDLoc DLoc, const Function &Fn, const Twine &Desc, + SDValue Value) + : DiagnosticInfo(getKindID(), DS_Error), DLoc(DLoc.getDebugLoc()), + Description(Desc), Fn(Fn), Value(Value) {} + + void print(DiagnosticPrinter &DP) const override { + std::string Str; + raw_string_ostream OS(Str); + + if (DLoc) { + auto DIL = DLoc.get(); + StringRef Filename = DIL->getFilename(); + unsigned Line = DIL->getLine(); + unsigned Column = DIL->getColumn(); + OS << Filename << ':' << Line << ':' << Column << ' '; + } + + OS << "in function " << Fn.getName() << ' ' << *Fn.getFunctionType() << '\n' + << Description; + if (Value) + Value->print(OS); + OS << '\n'; + OS.flush(); + DP << Str; + } + + static bool classof(const DiagnosticInfo *DI) { + return DI->getKind() == getKindID(); + } +}; + +int DiagnosticInfoUnsupported::KindID = 0; +} // end anonymous namespace + WebAssemblyTargetLowering::WebAssemblyTargetLowering( const TargetMachine &TM, const WebAssemblySubtarget &STI) : TargetLowering(TM), Subtarget(&STI) { diff --git a/llvm/test/CodeGen/AMDGPU/addrspacecast.ll b/llvm/test/CodeGen/AMDGPU/addrspacecast.ll index e029d917dba3..61bcd4b3c093 100644 --- a/llvm/test/CodeGen/AMDGPU/addrspacecast.ll +++ b/llvm/test/CodeGen/AMDGPU/addrspacecast.ll @@ -1,6 +1,6 @@ ; RUN: not llc -O0 -march=amdgcn -mcpu=bonaire -mattr=-promote-alloca < %s 2>&1 | FileCheck -check-prefix=ERROR %s -; ERROR: addrspacecast not implemented +; ERROR: unsupported addrspacecast not implemented ; XUN: llc -O0 -march=amdgcn -mcpu=bonaire -mattr=-promote-alloca < %s | FileCheck -check-prefix=CHECK -check-prefix=CHECK-NO-PROMOTE %s ; XUN: llc -O0 -march=amdgcn -mcpu=bonaire -mattr=+promote-alloca < %s | FileCheck -check-prefix=CHECK -check-prefix=CHECK-PROMOTE %s diff --git a/llvm/test/CodeGen/AMDGPU/call.ll b/llvm/test/CodeGen/AMDGPU/call.ll index 82e77350ab2d..e769fd11c282 100644 --- a/llvm/test/CodeGen/AMDGPU/call.ll +++ b/llvm/test/CodeGen/AMDGPU/call.ll @@ -2,7 +2,7 @@ ; RUN: not llc -march=amdgcn -mcpu=tonga -verify-machineinstrs< %s 2>&1 | FileCheck %s ; RUN: not llc -march=r600 -mcpu=cypress < %s 2>&1 | FileCheck %s -; CHECK: in function test_call_external{{.*}}: unsupported call to function external_function +; CHECK: error: unsupported call to function external_function in test_call_external declare i32 @external_function(i32) nounwind diff --git a/llvm/test/CodeGen/AMDGPU/dynamic_stackalloc.ll b/llvm/test/CodeGen/AMDGPU/dynamic_stackalloc.ll index 580dc00f935e..f4409a0984a9 100644 --- a/llvm/test/CodeGen/AMDGPU/dynamic_stackalloc.ll +++ b/llvm/test/CodeGen/AMDGPU/dynamic_stackalloc.ll @@ -2,7 +2,7 @@ ; RUN: not llc -march=amdgcn -mcpu=tahiti -mattr=-promote-alloca -verify-machineinstrs < %s 2>&1 | FileCheck %s ; RUN: not llc -march=r600 -mcpu=cypress < %s 2>&1 | FileCheck %s -; CHECK: in function test_dynamic_stackalloc{{.*}}: unsupported dynamic alloca +; CHECK: error: unsupported dynamic alloca in test_dynamic_stackalloc define void @test_dynamic_stackalloc(i32 addrspace(1)* %out, i32 %n) { %alloca = alloca i32, i32 %n diff --git a/llvm/test/CodeGen/AMDGPU/global-zero-initializer.ll b/llvm/test/CodeGen/AMDGPU/global-zero-initializer.ll index 522a4b29775e..45aa8bf4e1d7 100644 --- a/llvm/test/CodeGen/AMDGPU/global-zero-initializer.ll +++ b/llvm/test/CodeGen/AMDGPU/global-zero-initializer.ll @@ -1,7 +1,7 @@ ; RUN: not llc -march=amdgcn -mcpu=SI < %s 2>&1 | FileCheck %s ; RUN: not llc -march=amdgcn -mcpu=tonga < %s 2>&1 | FileCheck %s -; CHECK: in function load_init_global_global{{.*}}: unsupported initializer for address space +; CHECK: error: unsupported initializer for address space in load_init_global_global @lds = addrspace(1) global [256 x i32] zeroinitializer diff --git a/llvm/test/CodeGen/AMDGPU/lds-initializer.ll b/llvm/test/CodeGen/AMDGPU/lds-initializer.ll index 9875814b03d3..bf8df63be9fd 100644 --- a/llvm/test/CodeGen/AMDGPU/lds-initializer.ll +++ b/llvm/test/CodeGen/AMDGPU/lds-initializer.ll @@ -1,7 +1,7 @@ ; RUN: not llc -march=amdgcn -mcpu=SI < %s 2>&1 | FileCheck %s ; RUN: not llc -march=amdgcn -mcpu=tonga < %s 2>&1 | FileCheck %s -; CHECK: in function load_init_lds_global{{.*}}: unsupported initializer for address space +; CHECK: error: unsupported initializer for address space in load_init_lds_global @lds = addrspace(3) global [8 x i32] [i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8] diff --git a/llvm/test/CodeGen/AMDGPU/lds-zero-initializer.ll b/llvm/test/CodeGen/AMDGPU/lds-zero-initializer.ll index cb5d73fb0d8b..fb51bc0e50c2 100644 --- a/llvm/test/CodeGen/AMDGPU/lds-zero-initializer.ll +++ b/llvm/test/CodeGen/AMDGPU/lds-zero-initializer.ll @@ -1,7 +1,7 @@ ; RUN: not llc -march=amdgcn -mcpu=SI < %s 2>&1 | FileCheck %s ; RUN: not llc -march=amdgcn -mcpu=tonga < %s 2>&1 | FileCheck %s -; CHECK: in function load_zeroinit_lds_global{{.*}}: unsupported initializer for address space +; CHECK: error: unsupported initializer for address space in load_zeroinit_lds_global @lds = addrspace(3) global [256 x i32] zeroinitializer diff --git a/llvm/test/CodeGen/AMDGPU/llvm.amdgcn.dispatch.ptr.ll b/llvm/test/CodeGen/AMDGPU/llvm.amdgcn.dispatch.ptr.ll index 2e8625256f13..d96ea743f6ed 100644 --- a/llvm/test/CodeGen/AMDGPU/llvm.amdgcn.dispatch.ptr.ll +++ b/llvm/test/CodeGen/AMDGPU/llvm.amdgcn.dispatch.ptr.ll @@ -1,7 +1,7 @@ ; RUN: llc -mtriple=amdgcn--amdhsa -mcpu=kaveri -verify-machineinstrs < %s | FileCheck -check-prefix=GCN %s ; RUN: not llc -mtriple=amdgcn-unknown-unknown -mcpu=kaveri -verify-machineinstrs < %s 2>&1 | FileCheck -check-prefix=ERROR %s -; ERROR: in function test{{.*}}: unsupported hsa intrinsic without hsa target +; ERROR: error: unsupported hsa intrinsic without hsa target in test ; GCN-LABEL: {{^}}test: ; GCN: enable_sgpr_dispatch_ptr = 1 diff --git a/llvm/test/CodeGen/AMDGPU/no-hsa-graphics-shaders.ll b/llvm/test/CodeGen/AMDGPU/no-hsa-graphics-shaders.ll index 29ef858b85b6..73a146710a9f 100644 --- a/llvm/test/CodeGen/AMDGPU/no-hsa-graphics-shaders.ll +++ b/llvm/test/CodeGen/AMDGPU/no-hsa-graphics-shaders.ll @@ -1,6 +1,6 @@ ; RUN: not llc -march=amdgcn -mtriple=amdgcn-unknown-amdhsa < %s 2>&1 | FileCheck %s -; CHECK: in function pixel_s{{.*}}: unsupported non-compute shaders with HSA +; CHECK: error: unsupported non-compute shaders with HSA in pixel_shader define void @pixel_shader() #0 { ret void } diff --git a/llvm/test/CodeGen/AMDGPU/promote-alloca-bitcast-function.ll b/llvm/test/CodeGen/AMDGPU/promote-alloca-bitcast-function.ll index 609001733b79..10739df08379 100644 --- a/llvm/test/CodeGen/AMDGPU/promote-alloca-bitcast-function.ll +++ b/llvm/test/CodeGen/AMDGPU/promote-alloca-bitcast-function.ll @@ -6,7 +6,7 @@ declare void @foo(float*) #0 declare void @foo.varargs(...) #0 -; CHECK: in function crash_call_constexpr_cast{{.*}}: unsupported call to function foo +; CHECK: error: unsupported call to function foo in crash_call_constexpr_cast define void @crash_call_constexpr_cast() #0 { %alloca = alloca i32 call void bitcast (void (float*)* @foo to void (i32*)*)(i32* %alloca) #0