summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkaizhangNV <149626564+kaizhangNV@users.noreply.github.com>2025-06-17 11:12:41 -0500
committerGitHub <noreply@github.com>2025-06-17 09:12:41 -0700
commit14d002ac5463f0fd20ca5c3d4288fd7be2aa1b80 (patch)
tree75c54f6ec333c179a844fd3c5cd3b2f53d81231d
parent60a8f1fc3eee37977ee891661f65916f66aef364 (diff)
AD cleanup for 'break' replacement (#7456)
close #4187. This PR makes some cleanup on the variable name. During CFG normalization, we introduce a variable to replace the break, but the variable indicates that we should continue running the loop if it's true, and break the loop if it's false. Previously we named this variable as 'breakVar', which is opposite to its purpose. So rename it to keepRunning.
-rw-r--r--source/slang/slang-ir-autodiff-cfg-norm.cpp26
1 files changed, 15 insertions, 11 deletions
diff --git a/source/slang/slang-ir-autodiff-cfg-norm.cpp b/source/slang/slang-ir-autodiff-cfg-norm.cpp
index 720fdece2..20a823bb5 100644
--- a/source/slang/slang-ir-autodiff-cfg-norm.cpp
+++ b/source/slang/slang-ir-autodiff-cfg-norm.cpp
@@ -40,7 +40,7 @@ struct RegionEndpoint
struct BreakableRegionInfo
{
- IRVar* breakVar;
+ IRVar* keepRunningVar;
IRBlock* breakBlock;
IRBlock* headerBlock;
};
@@ -119,7 +119,7 @@ struct CFGNormalizationPass
builder->setInsertInto(currBlock);
- builder->emitStore(info->breakVar, builder->getBoolValue(false));
+ builder->emitStore(info->keepRunningVar, builder->getBoolValue(false));
builder->emitBranch(afterBlock);
// Is after-block unreachable?
@@ -240,9 +240,13 @@ struct CFGNormalizationPass
auto afterSplitAfterBlock = builder.emitBlock();
builder.setInsertInto(afterSplitBlock);
- auto breakFlagValue = builder.emitLoad(parentRegion->breakVar);
+ auto keepRunningFlagValue = builder.emitLoad(parentRegion->keepRunningVar);
- builder.emitIfElse(breakFlagValue, block, afterSplitAfterBlock, afterSplitAfterBlock);
+ builder.emitIfElse(
+ keepRunningFlagValue,
+ block,
+ afterSplitAfterBlock,
+ afterSplitAfterBlock);
// At this point, we need to place afterSplitAfterBlock between
// at the _end_ of this region, but we aren't there yet (and
@@ -514,13 +518,13 @@ struct CFGNormalizationPass
// Emit var into parent block.
builder.setInsertBefore(as<IRBlock>(branchInst->getParent())->getTerminator());
- // Create and initialize break var to true
+ // Create and initialize keepRunning var to true
// true -> no break yet.
// false -> atleast one break statement hit.
//
- info.breakVar = builder.emitVar(builder.getBoolType());
- builder.addNameHintDecoration(info.breakVar, UnownedStringSlice("_bflag"));
- builder.emitStore(info.breakVar, builder.getBoolValue(true));
+ info.keepRunningVar = builder.emitVar(builder.getBoolType());
+ builder.addNameHintDecoration(info.keepRunningVar, UnownedStringSlice("_runFlag"));
+ builder.emitStore(info.keepRunningVar, builder.getBoolValue(true));
// If the loop is trivial (i.e. single iteration, with no
// edges actually in a loop), we're just going to remove
@@ -624,7 +628,7 @@ struct CFGNormalizationPass
auto cond = ifElse->getCondition();
builder.setInsertBefore(ifElse);
- auto breakFlagVal = builder.emitLoad(info.breakVar);
+ auto breakFlagVal = builder.emitLoad(info.keepRunningVar);
// Need to invert the break flag if the loop is
// on the false side.
@@ -665,8 +669,8 @@ struct CFGNormalizationPass
// true -> no break yet.
// false -> atleast one break statement hit.
//
- info.breakVar = builder.emitVar(builder.getBoolType());
- builder.emitStore(info.breakVar, builder.getBoolValue(true));
+ info.keepRunningVar = builder.emitVar(builder.getBoolType());
+ builder.emitStore(info.keepRunningVar, builder.getBoolValue(true));
// Go over case labels and normalize all sub-regions.
for (UIndex ii = 0; ii < switchInst->getCaseCount(); ii++)