diff options
| author | Yong He <yonghe@outlook.com> | 2023-03-23 11:37:29 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-03-23 11:37:29 -0700 |
| commit | 85f005888cadeb4b1d957b57a86cbad6cc9ea313 (patch) | |
| tree | f227827398e1be0765df9478c6f78b4bb524e1b4 /source/slang/slang-ir-restructure-scoping.cpp | |
| parent | 34acec2258ef1586564fe51126b25910b3202541 (diff) | |
Fix scope fixing for address insts. (#2724)
Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'source/slang/slang-ir-restructure-scoping.cpp')
| -rw-r--r-- | source/slang/slang-ir-restructure-scoping.cpp | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/source/slang/slang-ir-restructure-scoping.cpp b/source/slang/slang-ir-restructure-scoping.cpp index 17ed44162..d7195a718 100644 --- a/source/slang/slang-ir-restructure-scoping.cpp +++ b/source/slang/slang-ir-restructure-scoping.cpp @@ -211,7 +211,8 @@ void defaultInitializeVar( static void fixValueScopingForInst( IRInst* def, SimpleRegion* defRegion, - RegionTree* regionTree) + RegionTree* regionTree, + bool isInstAlwaysFolded) { // This algorithm should not consider "phi nodes" for now, // because the emit logic will already create variables for them. @@ -305,8 +306,18 @@ static void fixValueScopingForInst( // If we've gotten this far, we know that `u` is a "bad" // use of `def`, and needs fixing. // - // We will use a temporary variable to resolve the bad scoping, - // creating it on-demand when we ecounter a first "bad" use, and + // For insts that are always fold into use sites, we try to hoist them + // to as early as possible, and then leave it there. + // + if (isInstAlwaysFolded) + { + def->removeFromParent(); + addHoistableInst(&builder, def); + continue; + } + + // For non-hoistable insts, we will use a temporary variable to resolve + // the bad scoping, creating it on-demand when we ecounter a first "bad" use, and // then re-using that temporary for any subsequent bad uses. // if( !tmp ) @@ -433,7 +444,7 @@ static void fixValueScopingForInst( } } -void fixValueScoping(RegionTree* regionTree) +void fixValueScoping(RegionTree* regionTree, const Func<bool, IRInst*>& shouldAlwaysFoldInst) { // We are going to have to walk through every instruction // in the code of the function to detect an bad cases. @@ -475,8 +486,8 @@ void fixValueScoping(RegionTree* regionTree) for (auto inst = block->getFirstOrdinaryInst(); inst; inst = nextInst) { nextInst = inst->getNextInst(); - - fixValueScopingForInst(inst, parentRegion, regionTree); + bool isInstAlwaysFolded = shouldAlwaysFoldInst(inst); + fixValueScopingForInst(inst, parentRegion, regionTree, isInstAlwaysFolded); } } } |
