summaryrefslogtreecommitdiff
path: root/source/slang/slang-ir-variable-scope-correction.h
diff options
context:
space:
mode:
Diffstat (limited to 'source/slang/slang-ir-variable-scope-correction.h')
-rw-r--r--source/slang/slang-ir-variable-scope-correction.h35
1 files changed, 35 insertions, 0 deletions
diff --git a/source/slang/slang-ir-variable-scope-correction.h b/source/slang/slang-ir-variable-scope-correction.h
new file mode 100644
index 000000000..5f958f9d0
--- /dev/null
+++ b/source/slang/slang-ir-variable-scope-correction.h
@@ -0,0 +1,35 @@
+// slang-ir-variable-scope-correction.h
+#ifndef SLANG_IR_VARIABLE_SCOPE_CORRECTION_H
+#define SLANG_IR_VARIABLE_SCOPE_CORRECTION_H
+
+namespace Slang
+{
+
+struct IRModule;
+
+/// This pass correct the scope of variables in loop regions
+///
+/// In the IR optimization pass, we turn all the loop to do-while loop form.
+/// But in the do-while loop form, the loop body block is dominating the
+/// blocks after the loop break block. E.g.
+///
+/// do {
+/// A
+/// } while (cond);
+/// B
+///
+/// In the above example, the block A is dominating block B. This assumption
+/// is fine for SPIRV and IR code, however, it's incorrect for all the other
+/// language targets (e.g. c/c++/cuda/glsl/hlsl) because the instructions defined
+/// in the block A are not visible from block B. Therefore, when translating to
+/// other textual language, there could be issue for the variables scope.
+///
+/// To fix this issue, we first detect the instructions that are defined
+/// inside the loop block (block A), then check if these instructions are used after
+/// the break block (block B). If so, we duplicate these instructions right before
+/// their users such that we can make those instructions available globally.
+void applyVariableScopeCorrection(IRModule* module, TargetRequest* targetReq);
+
+}
+
+#endif // SLANG_IR_VARIABLE_SCOPE_CORRECTION_H