summaryrefslogtreecommitdiffstats
path: root/source/slang/slang-ir-inline.cpp
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2023-04-10 13:43:18 -0700
committerGitHub <noreply@github.com>2023-04-10 13:43:18 -0700
commitd82992e30d5985001870e00afdf27091f59464f2 (patch)
tree6ee2c4ce4c98686e5721bda89f274343e366ab4e /source/slang/slang-ir-inline.cpp
parentea15647ba6bccb5ac48de5f4b80b8c2769d69b8f (diff)
Cleaner impl of unary stdlib derivative functions. (#2785)
* Cleaner impl of unary stdlib derivative functions. * fixup * Fix. --------- Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'source/slang/slang-ir-inline.cpp')
-rw-r--r--source/slang/slang-ir-inline.cpp23
1 files changed, 18 insertions, 5 deletions
diff --git a/source/slang/slang-ir-inline.cpp b/source/slang/slang-ir-inline.cpp
index d8486d7aa..5223e35cf 100644
--- a/source/slang/slang-ir-inline.cpp
+++ b/source/slang/slang-ir-inline.cpp
@@ -49,13 +49,26 @@ struct InliningPassBase
changed = considerCallSite(call);
}
- // Note: we defensively iterate through the child instructions
- // so that even if `child` gets removed (because of inlining)
- // we automatically start at the next instruction after it.
+ // Note: we iterate until no more changes can be applied.
+ // This is defensive against changes made by inlining one callsite
+ // and make sure we get to process all callsites.
//
- for (auto child : inst->getModifiableChildren())
+ for (;;)
{
- changed |= considerAllCallSitesRec(child);
+ bool changedInThisIteration = false;
+ // Note: getModifiableChildren will skip any insts that are no
+ // longer the chhild of `inst`. If we process one callsite, the
+ // remaining insts of the block will be moved into a different
+ // block and therefore we won't process them during this iteration.
+ // However, those callsites will eventually be processed
+ // by the outer loop.
+ for (auto child : inst->getModifiableChildren())
+ {
+ changedInThisIteration = considerAllCallSitesRec(child);
+ changed |= changedInThisIteration;
+ }
+ if (!changedInThisIteration)
+ break;
}
return changed;
}