Skip to content

Commit

Permalink
Remove debug instructions if target-specific setting is NONE
Browse files Browse the repository at this point in the history
This helps to address shader-slang#6092.
  • Loading branch information
aleino-nv committed Jan 30, 2025
1 parent 2487ca3 commit 0ec7208
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
17 changes: 17 additions & 0 deletions source/slang/slang-emit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
#include "slang-ir-ssa-simplification.h"
#include "slang-ir-ssa.h"
#include "slang-ir-string-hash.h"
#include "slang-ir-strip-debug-info.h"
#include "slang-ir-strip-default-construct.h"
#include "slang-ir-strip-legalization-insts.h"
#include "slang-ir-synthesize-active-mask.h"
Expand Down Expand Up @@ -300,6 +301,7 @@ struct LinkingAndOptimizationOptions
//
struct RequiredLoweringPassSet
{
bool debugInfo;
bool resultType;
bool optionalType;
bool combinedTextureSamplers;
Expand Down Expand Up @@ -331,6 +333,13 @@ void calcRequiredLoweringPassSet(
{
switch (inst->getOp())
{
case kIROp_DebugValue:
case kIROp_DebugVar:
case kIROp_DebugLine:
case kIROp_DebugLocationDecoration:
case kIROp_DebugSource:
result.debugInfo = true;
break;
case kIROp_ResultType:
result.resultType = true;
break;
Expand Down Expand Up @@ -583,6 +592,7 @@ Result linkAndOptimizeIR(
auto target = codeGenContext->getTargetFormat();
auto targetRequest = codeGenContext->getTargetReq();
auto targetProgram = codeGenContext->getTargetProgram();
auto targetCompilerOptions = targetRequest->getOptionSet();

// Get the artifact desc for the target
const auto artifactDesc = ArtifactDescUtil::makeDescForCompileTarget(asExternal(target));
Expand Down Expand Up @@ -614,6 +624,13 @@ Result linkAndOptimizeIR(
RequiredLoweringPassSet requiredLoweringPassSet = {};
calcRequiredLoweringPassSet(requiredLoweringPassSet, codeGenContext, irModule->getModuleInst());

// Debug info is added by the front-end, and therefore needs to be stripped out by targets that
// opt out of debug info.
if (requiredLoweringPassSet.debugInfo &&
(targetCompilerOptions.getIntOption(CompilerOptionName::DebugInformation) ==
SLANG_DEBUG_INFO_LEVEL_NONE))
stripDebugInfo(irModule);

if (!isKhronosTarget(targetRequest) && requiredLoweringPassSet.glslSSBO)
lowerGLSLShaderStorageBufferObjectsToStructuredBuffers(irModule, sink);

Expand Down
33 changes: 33 additions & 0 deletions source/slang/slang-ir-strip-debug-info.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include "slang-ir-strip-debug-info.h"

#include "slang-ir-insts.h"

namespace Slang
{
static void findDebugInfo(IRInst* inst, List<IRInst*>& debugInstructions)
{
switch (inst->getOp())
{
case kIROp_DebugValue:
case kIROp_DebugVar:
case kIROp_DebugLine:
case kIROp_DebugLocationDecoration:
case kIROp_DebugSource:
debugInstructions.add(inst);
break;
default:
break;
}

for (auto child : inst->getChildren())
findDebugInfo(child, debugInstructions);
}

void stripDebugInfo(IRModule* irModule)
{
List<IRInst*> debugInstructions;
findDebugInfo(irModule->getModuleInst(), debugInstructions);
for (auto debugInst : debugInstructions)
debugInst->removeAndDeallocate();
}
} // namespace Slang
9 changes: 9 additions & 0 deletions source/slang/slang-ir-strip-debug-info.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#pragma once

namespace Slang
{
struct IRModule;

/// Strip all debug info instructions from `irModule`
void stripDebugInfo(IRModule* irModule);
} // namespace Slang

0 comments on commit 0ec7208

Please sign in to comment.