summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authorSai Praveen Bangaru <31557731+saipraveenb25@users.noreply.github.com>2024-11-14 12:06:17 -0500
committerGitHub <noreply@github.com>2024-11-14 12:06:17 -0500
commit147ceb1991454b7a5ba6f3ec0c149dd40360a31d (patch)
treef290109f71a4cca9337537ddb42a58ba1fcd6d94 /source
parente58ba6b23cb3ee04d69452bfe7e1f8274956ce7d (diff)
Fix issue with raw default constructors in SPIRV emit (#5556)
Diffstat (limited to 'source')
-rw-r--r--source/slang/slang-emit.cpp14
-rw-r--r--source/slang/slang-ir-insts.h7
-rw-r--r--source/slang/slang-ir-strip-default-construct.cpp45
-rw-r--r--source/slang/slang-ir-strip-default-construct.h11
4 files changed, 77 insertions, 0 deletions
diff --git a/source/slang/slang-emit.cpp b/source/slang/slang-emit.cpp
index 05bb12ecc..010b4bc92 100644
--- a/source/slang/slang-emit.cpp
+++ b/source/slang/slang-emit.cpp
@@ -89,6 +89,7 @@
#include "slang-ir-ssa.h"
#include "slang-ir-string-hash.h"
#include "slang-ir-strip-cached-dict.h"
+#include "slang-ir-strip-default-construct.h"
#include "slang-ir-strip-witness-tables.h"
#include "slang-ir-strip.h"
#include "slang-ir-synthesize-active-mask.h"
@@ -1419,6 +1420,19 @@ Result linkAndOptimizeIR(
// we will need to disable this pass.
stripWitnessTables(irModule);
+ switch (target)
+ {
+ // On targets that don't support default initialization, remove 'raw' default construct
+ // insts because our code-gen will not have any way to emit them.
+ //
+ case CodeGenTarget::SPIRV:
+ if (targetProgram->shouldEmitSPIRVDirectly())
+ removeRawDefaultConstructors(irModule);
+ break;
+ default:
+ break;
+ }
+
#if 0
dumpIRIfEnabled(codeGenContext, irModule, "AFTER STRIP WITNESS TABLES");
#endif
diff --git a/source/slang/slang-ir-insts.h b/source/slang/slang-ir-insts.h
index 4baa786e3..9ccfce51c 100644
--- a/source/slang/slang-ir-insts.h
+++ b/source/slang/slang-ir-insts.h
@@ -2894,6 +2894,13 @@ struct IRUndefined : IRInst
{
};
+// Special inst for targets that support default initialization,
+// like the braces '= {}' in C/HLSL
+struct IRDefaultConstruct : IRInst
+{
+ IR_LEAF_ISA(DefaultConstruct)
+};
+
// A global-scope generic parameter (a type parameter, a
// constraint parameter, etc.)
struct IRGlobalGenericParam : IRInst
diff --git a/source/slang/slang-ir-strip-default-construct.cpp b/source/slang/slang-ir-strip-default-construct.cpp
new file mode 100644
index 000000000..ea141d2fd
--- /dev/null
+++ b/source/slang/slang-ir-strip-default-construct.cpp
@@ -0,0 +1,45 @@
+// slang-ir-strip-default-construct.cpp
+#include "slang-ir-strip-default-construct.h"
+
+#include "slang-ir-inst-pass-base.h"
+#include "slang-ir-insts.h"
+#include "slang-ir.h"
+
+namespace Slang
+{
+
+struct RemoveDefaultConstructInsts : InstPassBase
+{
+ RemoveDefaultConstructInsts(IRModule* module)
+ : InstPassBase(module)
+ {
+ }
+ void processModule()
+ {
+ processInstsOfType<IRDefaultConstruct>(
+ kIROp_DefaultConstruct,
+ [&](IRDefaultConstruct* defaultConstruct)
+ {
+ List<IRInst*> instsToRemove;
+ for (auto use = defaultConstruct->firstUse; use; use = use->nextUse)
+ {
+ if (as<IRStore>(use->getUser()))
+ instsToRemove.add(use->getUser());
+ else
+ return; // Ignore this inst if there are non-store uses.
+ }
+
+ for (auto inst : instsToRemove)
+ inst->removeAndDeallocate();
+
+ defaultConstruct->removeAndDeallocate();
+ });
+ }
+};
+
+void removeRawDefaultConstructors(IRModule* module)
+{
+ RemoveDefaultConstructInsts(module).processModule();
+}
+
+} // namespace Slang
diff --git a/source/slang/slang-ir-strip-default-construct.h b/source/slang/slang-ir-strip-default-construct.h
new file mode 100644
index 000000000..ea3984d8b
--- /dev/null
+++ b/source/slang/slang-ir-strip-default-construct.h
@@ -0,0 +1,11 @@
+// slang-ir-strip-default-construct.h
+#pragma once
+
+namespace Slang
+{
+struct IRModule;
+
+/// Strip the contents of all witness table instructions from the given IR `module`
+void removeRawDefaultConstructors(IRModule* module);
+
+} // namespace Slang