Skip to content

Commit a026df7

Browse files
authored
Respect per-target debug options (#6193)
* Base compiler options for targets on target-specific compiler options Before this change, the target compiler options were based on the linkage-wide compiler options, which where later again inherited from (basically a no-op). With this change, the target-specific compiler options are added first, and then the linkage-wide comnpiler options are inherited from. * Remove debug instructions if target-specific setting is NONE This helps to address #6092. * Make sure the linkage debug info level is sufficient for each target This closes #6092.
1 parent eebe849 commit a026df7

File tree

4 files changed

+73
-1
lines changed

4 files changed

+73
-1
lines changed

source/slang/slang-emit.cpp

+17
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@
9494
#include "slang-ir-ssa-simplification.h"
9595
#include "slang-ir-ssa.h"
9696
#include "slang-ir-string-hash.h"
97+
#include "slang-ir-strip-debug-info.h"
9798
#include "slang-ir-strip-default-construct.h"
9899
#include "slang-ir-strip-legalization-insts.h"
99100
#include "slang-ir-synthesize-active-mask.h"
@@ -301,6 +302,7 @@ struct LinkingAndOptimizationOptions
301302
//
302303
struct RequiredLoweringPassSet
303304
{
305+
bool debugInfo;
304306
bool resultType;
305307
bool optionalType;
306308
bool combinedTextureSamplers;
@@ -332,6 +334,13 @@ void calcRequiredLoweringPassSet(
332334
{
333335
switch (inst->getOp())
334336
{
337+
case kIROp_DebugValue:
338+
case kIROp_DebugVar:
339+
case kIROp_DebugLine:
340+
case kIROp_DebugLocationDecoration:
341+
case kIROp_DebugSource:
342+
result.debugInfo = true;
343+
break;
335344
case kIROp_ResultType:
336345
result.resultType = true;
337346
break;
@@ -584,6 +593,7 @@ Result linkAndOptimizeIR(
584593
auto target = codeGenContext->getTargetFormat();
585594
auto targetRequest = codeGenContext->getTargetReq();
586595
auto targetProgram = codeGenContext->getTargetProgram();
596+
auto targetCompilerOptions = targetRequest->getOptionSet();
587597

588598
// Get the artifact desc for the target
589599
const auto artifactDesc = ArtifactDescUtil::makeDescForCompileTarget(asExternal(target));
@@ -615,6 +625,13 @@ Result linkAndOptimizeIR(
615625
RequiredLoweringPassSet requiredLoweringPassSet = {};
616626
calcRequiredLoweringPassSet(requiredLoweringPassSet, codeGenContext, irModule->getModuleInst());
617627

628+
// Debug info is added by the front-end, and therefore needs to be stripped out by targets that
629+
// opt out of debug info.
630+
if (requiredLoweringPassSet.debugInfo &&
631+
(targetCompilerOptions.getIntOption(CompilerOptionName::DebugInformation) ==
632+
SLANG_DEBUG_INFO_LEVEL_NONE))
633+
stripDebugInfo(irModule);
634+
618635
if (!isKhronosTarget(targetRequest) && requiredLoweringPassSet.glslSSBO)
619636
lowerGLSLShaderStorageBufferObjectsToStructuredBuffers(irModule, sink);
620637

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#include "slang-ir-strip-debug-info.h"
2+
3+
#include "slang-ir-insts.h"
4+
5+
namespace Slang
6+
{
7+
static void findDebugInfo(IRInst* inst, List<IRInst*>& debugInstructions)
8+
{
9+
switch (inst->getOp())
10+
{
11+
case kIROp_DebugValue:
12+
case kIROp_DebugVar:
13+
case kIROp_DebugLine:
14+
case kIROp_DebugLocationDecoration:
15+
case kIROp_DebugSource:
16+
debugInstructions.add(inst);
17+
break;
18+
default:
19+
break;
20+
}
21+
22+
for (auto child : inst->getChildren())
23+
findDebugInfo(child, debugInstructions);
24+
}
25+
26+
void stripDebugInfo(IRModule* irModule)
27+
{
28+
List<IRInst*> debugInstructions;
29+
findDebugInfo(irModule->getModuleInst(), debugInstructions);
30+
for (auto debugInst : debugInstructions)
31+
debugInst->removeAndDeallocate();
32+
}
33+
} // namespace Slang
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#pragma once
2+
3+
namespace Slang
4+
{
5+
struct IRModule;
6+
7+
/// Strip all debug info instructions from `irModule`
8+
void stripDebugInfo(IRModule* irModule);
9+
} // namespace Slang

source/slang/slang.cpp

+14-1
Original file line numberDiff line numberDiff line change
@@ -842,6 +842,16 @@ Session::createSession(slang::SessionDesc const& inDesc, slang::ISession** outSe
842842
}
843843
}
844844

845+
// If any target requires debug info, then we will need to enable debug info when lowering to
846+
// target-agnostic IR. The target-agnostic IR will only include debug info if the linkage IR
847+
// options specify that it should, so make sure the linkage debug info level is greater than or
848+
// equal to that of any target.
849+
DebugInfoLevel linkageDebugInfoLevel = linkage->m_optionSet.getDebugInfoLevel();
850+
for (auto target : linkage->targets)
851+
linkageDebugInfoLevel =
852+
Math::Max(linkageDebugInfoLevel, target->getOptionSet().getDebugInfoLevel());
853+
linkage->m_optionSet.set(CompilerOptionName::DebugInformation, linkageDebugInfoLevel);
854+
845855
*outSession = asExternal(linkage.detach());
846856
return SLANG_OK;
847857
}
@@ -1337,7 +1347,10 @@ void Linkage::addTarget(slang::TargetDesc const& desc)
13371347
optionSet.setProfile(Profile(desc.profile));
13381348
optionSet.set(CompilerOptionName::LineDirectiveMode, LineDirectiveMode(desc.lineDirectiveMode));
13391349
optionSet.set(CompilerOptionName::GLSLForceScalarLayout, desc.forceGLSLScalarBufferLayout);
1340-
optionSet.load(desc.compilerOptionEntryCount, desc.compilerOptionEntries);
1350+
1351+
CompilerOptionSet targetOptions;
1352+
targetOptions.load(desc.compilerOptionEntryCount, desc.compilerOptionEntries);
1353+
optionSet.overrideWith(targetOptions);
13411354
}
13421355

13431356
#if 0

0 commit comments

Comments
 (0)