summaryrefslogtreecommitdiff
path: root/source/slang/slang-ir-strip-default-construct.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'source/slang/slang-ir-strip-default-construct.cpp')
-rw-r--r--source/slang/slang-ir-strip-default-construct.cpp45
1 files changed, 45 insertions, 0 deletions
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