Skip to content

Commit

Permalink
Support missing DWARF opcodes (#679)
Browse files Browse the repository at this point in the history
Experimental support of extra DWARF operations

As this functionality is not documented by any formal SPIR-V extension or SPIR-V
extended instruction set specification, it is disabled by default and in order
to enable generation of extra debug information, user needs to pass
`spirv-allow-extra-diexpressions` command line option to the
translator.

Signed-off-by: Andrew Savonichev <[email protected]>
  • Loading branch information
Andrew Savonichev authored and AlexeySotkin committed Oct 14, 2020
1 parent e1cee96 commit d6dc999
Show file tree
Hide file tree
Showing 7 changed files with 650 additions and 23 deletions.
12 changes: 12 additions & 0 deletions include/LLVMSPIRVOpts.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,14 @@ class TranslatorOpts {
SPIRVAllowUnknownIntrinsics = AllowUnknownIntrinsics;
}

bool allowExtraDIExpressions() const noexcept {
return AllowExtraDIExpressions;
}

void setAllowExtraDIExpressionsEnabled(bool Allow) noexcept {
AllowExtraDIExpressions = Allow;
}

DebugInfoEIS getDebugInfoEIS() const { return DebugInfoVersion; }

void setDebugInfoEIS(DebugInfoEIS EIS) { DebugInfoVersion = EIS; }
Expand Down Expand Up @@ -179,6 +187,10 @@ class TranslatorOpts {
// SPIR-V
bool SPIRVAllowUnknownIntrinsics = false;

// Enable support for extra DIExpression opcodes not listed in the SPIR-V
// DebugInfo specification.
bool AllowExtraDIExpressions = false;

DebugInfoEIS DebugInfoVersion = DebugInfoEIS::OpenCL_DebugInfo_100;
};

Expand Down
8 changes: 6 additions & 2 deletions lib/SPIRV/LLVMToSPIRVDbgTran.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -959,10 +959,14 @@ SPIRVEntry *LLVMToSPIRVDbgTran::transDbgExpression(const DIExpression *Expr) {
for (unsigned I = 0, N = Expr->getNumElements(); I < N; ++I) {
using namespace SPIRVDebug::Operand::Operation;
auto DWARFOpCode = static_cast<dwarf::LocationAtom>(Expr->getElement(I));

SPIRVDebug::ExpressionOpCode OC =
SPIRV::DbgExpressionOpCodeMap::map(DWARFOpCode);
assert(OpCountMap.find(OC) != OpCountMap.end() &&
"unhandled opcode found in DIExpression");
if (OpCountMap.find(OC) == OpCountMap.end())
report_fatal_error("unknown opcode found in DIExpression");
if (OC > SPIRVDebug::Fragment && !BM->allowExtraDIExpressions())
report_fatal_error("unsupported opcode found in DIExpression");

unsigned OpCount = OpCountMap[OC];
SPIRVWordVec Op(OpCount);
Op[OpCodeIdx] = OC;
Expand Down
Loading

0 comments on commit d6dc999

Please sign in to comment.