summaryrefslogtreecommitdiffstats
path: root/source/slang
diff options
context:
space:
mode:
authorAnders Leino <aleino@nvidia.com>2025-01-31 19:27:20 +0200
committerGitHub <noreply@github.com>2025-01-31 09:27:20 -0800
commita026df756096ca580ca9d19019abd08fa5d2c015 (patch)
treec11335fc0834aac4ccfc783b76a539956683b97e /source/slang
parenteebe849075c21d163739cbc5e976e7b5b6837e7f (diff)
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.
Diffstat (limited to 'source/slang')
-rw-r--r--source/slang/slang-emit.cpp17
-rw-r--r--source/slang/slang-ir-strip-debug-info.cpp33
-rw-r--r--source/slang/slang-ir-strip-debug-info.h9
-rw-r--r--source/slang/slang.cpp15
4 files changed, 73 insertions, 1 deletions
diff --git a/source/slang/slang-emit.cpp b/source/slang/slang-emit.cpp
index d8594ffdd..70521c7ee 100644
--- a/source/slang/slang-emit.cpp
+++ b/source/slang/slang-emit.cpp
@@ -94,6 +94,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"
@@ -301,6 +302,7 @@ struct LinkingAndOptimizationOptions
//
struct RequiredLoweringPassSet
{
+ bool debugInfo;
bool resultType;
bool optionalType;
bool combinedTextureSamplers;
@@ -332,6 +334,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;
@@ -584,6 +593,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));
@@ -615,6 +625,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);
diff --git a/source/slang/slang-ir-strip-debug-info.cpp b/source/slang/slang-ir-strip-debug-info.cpp
new file mode 100644
index 000000000..8b2a07663
--- /dev/null
+++ b/source/slang/slang-ir-strip-debug-info.cpp
@@ -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
diff --git a/source/slang/slang-ir-strip-debug-info.h b/source/slang/slang-ir-strip-debug-info.h
new file mode 100644
index 000000000..67aac1abb
--- /dev/null
+++ b/source/slang/slang-ir-strip-debug-info.h
@@ -0,0 +1,9 @@
+#pragma once
+
+namespace Slang
+{
+struct IRModule;
+
+/// Strip all debug info instructions from `irModule`
+void stripDebugInfo(IRModule* irModule);
+} // namespace Slang
diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp
index 21944e4f3..ee0aa4c14 100644
--- a/source/slang/slang.cpp
+++ b/source/slang/slang.cpp
@@ -842,6 +842,16 @@ Session::createSession(slang::SessionDesc const& inDesc, slang::ISession** outSe
}
}
+ // If any target requires debug info, then we will need to enable debug info when lowering to
+ // target-agnostic IR. The target-agnostic IR will only include debug info if the linkage IR
+ // options specify that it should, so make sure the linkage debug info level is greater than or
+ // equal to that of any target.
+ DebugInfoLevel linkageDebugInfoLevel = linkage->m_optionSet.getDebugInfoLevel();
+ for (auto target : linkage->targets)
+ linkageDebugInfoLevel =
+ Math::Max(linkageDebugInfoLevel, target->getOptionSet().getDebugInfoLevel());
+ linkage->m_optionSet.set(CompilerOptionName::DebugInformation, linkageDebugInfoLevel);
+
*outSession = asExternal(linkage.detach());
return SLANG_OK;
}
@@ -1337,7 +1347,10 @@ void Linkage::addTarget(slang::TargetDesc const& desc)
optionSet.setProfile(Profile(desc.profile));
optionSet.set(CompilerOptionName::LineDirectiveMode, LineDirectiveMode(desc.lineDirectiveMode));
optionSet.set(CompilerOptionName::GLSLForceScalarLayout, desc.forceGLSLScalarBufferLayout);
- optionSet.load(desc.compilerOptionEntryCount, desc.compilerOptionEntries);
+
+ CompilerOptionSet targetOptions;
+ targetOptions.load(desc.compilerOptionEntryCount, desc.compilerOptionEntries);
+ optionSet.overrideWith(targetOptions);
}
#if 0