Skip to content

Commit

Permalink
Refactor backend diagnostics for unsupported features
Browse files Browse the repository at this point in the history
Re-commit of r258951 after fixing layering violation.

The BPF and WebAssembly backends had identical code for emitting errors
for unsupported features, and AMDGPU had very similar code. This merges
them all into one DiagnosticInfo subclass, that can be used by any
backend.

There should be minimal functional changes here, but some AMDGPU tests
have been updated for the new format of errors (it used a slightly
different format to BPF and WebAssembly). The AMDGPU error messages will
now benefit from having precise source locations when debug info is
available.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@259498 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
ostannard committed Feb 2, 2016
1 parent b5a9885 commit 9ed9eb7
Show file tree
Hide file tree
Showing 19 changed files with 124 additions and 248 deletions.
88 changes: 65 additions & 23 deletions include/llvm/IR/DiagnosticInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ enum DiagnosticKind {
DK_OptimizationFailure,
DK_MIRParser,
DK_PGOProfile,
DK_Unsupported,
DK_FirstPluginKind
};

Expand Down Expand Up @@ -275,8 +276,42 @@ class DiagnosticInfoPGOProfile : public DiagnosticInfo {
const Twine &Msg;
};

/// Common features for diagnostics with an associated DebugLoc
class DiagnosticInfoWithDebugLocBase : public DiagnosticInfo {
public:
/// \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,
enum DiagnosticSeverity Severity,
const Function &Fn,
const DebugLoc &DLoc)
: DiagnosticInfo(Kind, Severity), Fn(Fn), DLoc(DLoc) {}

/// Return true if location information is available for this diagnostic.
bool isLocationAvailable() const;

/// Return a string with the location information for this diagnostic
/// in the format "file:line:col". If location information is not available,
/// it returns "<unknown>:0:0".
const std::string getLocationStr() const;

/// Return location information for this diagnostic in three parts:
/// the source file name, line number and column.
void getLocation(StringRef *Filename, unsigned *Line, unsigned *Column) const;

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 DiagnosticInfo {
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
Expand All @@ -289,8 +324,8 @@ class DiagnosticInfoOptimizationBase : public DiagnosticInfo {
enum DiagnosticSeverity Severity,
const char *PassName, const Function &Fn,
const DebugLoc &DLoc, const Twine &Msg)
: DiagnosticInfo(Kind, Severity), PassName(PassName), Fn(Fn), DLoc(DLoc),
Msg(Msg) {}
: DiagnosticInfoWithDebugLocBase(Kind, Severity, Fn, DLoc),
PassName(PassName), Msg(Msg) {}

/// \see DiagnosticInfo::print.
void print(DiagnosticPrinter &DP) const override;
Expand All @@ -302,21 +337,7 @@ class DiagnosticInfoOptimizationBase : public DiagnosticInfo {
/// in BackendConsumer::OptimizationRemarkHandler).
virtual bool isEnabled() const = 0;

/// Return true if location information is available for this diagnostic.
bool isLocationAvailable() const;

/// Return a string with the location information for this diagnostic
/// in the format "file:line:col". If location information is not available,
/// it returns "<unknown>:0:0".
const std::string getLocationStr() const;

/// Return location information for this diagnostic in three parts:
/// 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; }
const Twine &getMsg() const { return Msg; }

private:
Expand All @@ -325,12 +346,6 @@ class DiagnosticInfoOptimizationBase : public DiagnosticInfo {
/// 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;
};
Expand Down Expand Up @@ -572,6 +587,33 @@ class DiagnosticInfoOptimizationFailure
bool isEnabled() const override;
};

/// Diagnostic information for unsupported feature in backend.
class DiagnosticInfoUnsupported
: public DiagnosticInfoWithDebugLocBase {
private:
const Twine &Msg;

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,
DebugLoc DLoc = DebugLoc())
: DiagnosticInfoWithDebugLocBase(DK_Unsupported, DS_Error, Fn, DLoc),
Msg(Msg) {}

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.
Expand Down
16 changes: 13 additions & 3 deletions lib/IR/DiagnosticInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,11 @@ void DiagnosticInfoPGOProfile::print(DiagnosticPrinter &DP) const {
DP << getMsg();
}

bool DiagnosticInfoOptimizationBase::isLocationAvailable() const {
bool DiagnosticInfoWithDebugLocBase::isLocationAvailable() const {
return getDebugLoc();
}

void DiagnosticInfoOptimizationBase::getLocation(StringRef *Filename,
void DiagnosticInfoWithDebugLocBase::getLocation(StringRef *Filename,
unsigned *Line,
unsigned *Column) const {
DILocation *L = getDebugLoc();
Expand All @@ -152,7 +152,7 @@ void DiagnosticInfoOptimizationBase::getLocation(StringRef *Filename,
*Column = L->getColumn();
}

const std::string DiagnosticInfoOptimizationBase::getLocationStr() const {
const std::string DiagnosticInfoWithDebugLocBase::getLocationStr() const {
StringRef Filename("<unknown>");
unsigned Line = 0;
unsigned Column = 0;
Expand Down Expand Up @@ -230,6 +230,16 @@ bool DiagnosticInfoOptimizationFailure::isEnabled() const {
return getSeverity() == DS_Warning;
}

void DiagnosticInfoUnsupported::print(DiagnosticPrinter &DP) const {
std::string Str;
raw_string_ostream OS(Str);

OS << getLocationStr() << ": in function " << getFunction().getName() << ' '
<< *getFunction().getFunctionType() << ": " << Msg << '\n';
OS.flush();
DP << Str;
}

void llvm::emitLoopVectorizeWarning(LLVMContext &Ctx, const Function &Fn,
const DebugLoc &DLoc, const Twine &Msg) {
Ctx.diagnose(DiagnosticInfoOptimizationFailure(
Expand Down
26 changes: 0 additions & 26 deletions lib/Target/AMDGPU/AMDGPUDiagnosticInfoUnsupported.cpp

This file was deleted.

48 changes: 0 additions & 48 deletions lib/Target/AMDGPU/AMDGPUDiagnosticInfoUnsupported.h

This file was deleted.

6 changes: 3 additions & 3 deletions lib/Target/AMDGPU/AMDGPUISelDAGToDAG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
//
//===----------------------------------------------------------------------===//

#include "AMDGPUDiagnosticInfoUnsupported.h"
#include "AMDGPUInstrInfo.h"
#include "AMDGPUISelLowering.h" // For AMDGPUISD
#include "AMDGPURegisterInfo.h"
Expand All @@ -27,6 +26,7 @@
#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;
Expand Down Expand Up @@ -1219,8 +1219,8 @@ SDNode *AMDGPUDAGToDAGISel::SelectAddrSpaceCast(SDNode *N) {
SDLoc DL(N);

const MachineFunction &MF = CurDAG->getMachineFunction();
DiagnosticInfoUnsupported NotImplemented(*MF.getFunction(),
"addrspacecast not implemented");
DiagnosticInfoUnsupported NotImplemented(
*MF.getFunction(), "addrspacecast not implemented", DL.getDebugLoc());
CurDAG->getContext()->diagnose(NotImplemented);

assert(Subtarget->hasFlatAddressSpace() &&
Expand Down
12 changes: 7 additions & 5 deletions lib/Target/AMDGPU/AMDGPUISelLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

#include "AMDGPUISelLowering.h"
#include "AMDGPU.h"
#include "AMDGPUDiagnosticInfoUnsupported.h"
#include "AMDGPUFrameLowering.h"
#include "AMDGPUIntrinsicInfo.h"
#include "AMDGPURegisterInfo.h"
Expand All @@ -28,6 +27,7 @@
#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;

Expand Down Expand Up @@ -609,7 +609,8 @@ SDValue AMDGPUTargetLowering::LowerCall(CallLoweringInfo &CLI,
else if (const GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee))
FuncName = G->getGlobal()->getName();

DiagnosticInfoUnsupported NoCalls(Fn, "call to function " + FuncName);
DiagnosticInfoUnsupported NoCalls(
Fn, "unsupported call to function " + FuncName, CLI.DL.getDebugLoc());
DAG.getContext()->diagnose(NoCalls);
return SDValue();
}
Expand All @@ -618,7 +619,8 @@ SDValue AMDGPUTargetLowering::LowerDYNAMIC_STACKALLOC(SDValue Op,
SelectionDAG &DAG) const {
const Function &Fn = *DAG.getMachineFunction().getFunction();

DiagnosticInfoUnsupported NoDynamicAlloca(Fn, "dynamic alloca");
DiagnosticInfoUnsupported NoDynamicAlloca(Fn, "unsupported dynamic alloca",
SDLoc(Op).getDebugLoc());
DAG.getContext()->diagnose(NoDynamicAlloca);
return SDValue();
}
Expand Down Expand Up @@ -865,8 +867,8 @@ SDValue AMDGPUTargetLowering::LowerGlobalAddress(AMDGPUMachineFunction* MFI,
}

const Function &Fn = *DAG.getMachineFunction().getFunction();
DiagnosticInfoUnsupported BadInit(Fn,
"initializer for address space");
DiagnosticInfoUnsupported BadInit(
Fn, "unsupported initializer for address space", SDLoc(Op).getDebugLoc());
DAG.getContext()->diagnose(BadInit);
return SDValue();
}
Expand Down
1 change: 0 additions & 1 deletion lib/Target/AMDGPU/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ add_llvm_target(AMDGPUCodeGen
AMDGPUAnnotateKernelFeatures.cpp
AMDGPUAnnotateUniformValues.cpp
AMDGPUAsmPrinter.cpp
AMDGPUDiagnosticInfoUnsupported.cpp
AMDGPUFrameLowering.cpp
AMDGPUTargetObjectFile.cpp
AMDGPUIntrinsicInfo.cpp
Expand Down
10 changes: 6 additions & 4 deletions lib/Target/AMDGPU/SIISelLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

#include "SIISelLowering.h"
#include "AMDGPU.h"
#include "AMDGPUDiagnosticInfoUnsupported.h"
#include "AMDGPUIntrinsicInfo.h"
#include "AMDGPUSubtarget.h"
#include "SIInstrInfo.h"
Expand All @@ -32,6 +31,7 @@
#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"

Expand Down Expand Up @@ -591,7 +591,8 @@ SDValue SITargetLowering::LowerFormalArguments(

if (Subtarget->isAmdHsaOS() && Info->getShaderType() != ShaderType::COMPUTE) {
const Function *Fn = MF.getFunction();
DiagnosticInfoUnsupported NoGraphicsHSA(*Fn, "non-compute shaders with HSA");
DiagnosticInfoUnsupported NoGraphicsHSA(
*Fn, "unsupported non-compute shaders with HSA", DL.getDebugLoc());
DAG.getContext()->diagnose(NoGraphicsHSA);
return SDValue();
}
Expand Down Expand Up @@ -1327,8 +1328,9 @@ SDValue SITargetLowering::LowerINTRINSIC_WO_CHAIN(SDValue Op,
switch (IntrinsicID) {
case Intrinsic::amdgcn_dispatch_ptr:
if (!Subtarget->isAmdHsaOS()) {
DiagnosticInfoUnsupported BadIntrin(*MF.getFunction(),
"hsa intrinsic without hsa target");
DiagnosticInfoUnsupported BadIntrin(
*MF.getFunction(), "unsupported hsa intrinsic without hsa target",
DL.getDebugLoc());
DAG.getContext()->diagnose(BadIntrin);
return DAG.getUNDEF(VT);
}
Expand Down
Loading

0 comments on commit 9ed9eb7

Please sign in to comment.