diff options
| author | Yong He <yonghe@outlook.com> | 2023-07-12 16:00:05 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-07-12 16:00:05 -0700 |
| commit | 261b2f1f2bc13ccf7db5ec68c825ffc7b0781f7f (patch) | |
| tree | 4953e376e705a8110cb8164dda5b239c04f2768b /source/slang/slang-ir-util.cpp | |
| parent | bbd9c2e6d7b57f5acc3238083ab2f7c7b140df5e (diff) | |
Use scratchData on `IRInst` to replace HashSets. (#2978)
* Use scratchData on `IRInst` to replace HashSets.
* Update test results.
* Initialize scratchData.
* Update autodiff documentation.
* Use enum instead of bool.
---------
Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'source/slang/slang-ir-util.cpp')
| -rw-r--r-- | source/slang/slang-ir-util.cpp | 43 |
1 files changed, 37 insertions, 6 deletions
diff --git a/source/slang/slang-ir-util.cpp b/source/slang/slang-ir-util.cpp index 6b94711e0..07aaa127f 100644 --- a/source/slang/slang-ir-util.cpp +++ b/source/slang/slang-ir-util.cpp @@ -645,7 +645,7 @@ void setInsertAfterOrdinaryInst(IRBuilder* builder, IRInst* inst) } } -bool areCallArgumentsSideEffectFree(IRCall* call) +bool areCallArgumentsSideEffectFree(IRCall* call, SideEffectAnalysisOptions options) { // If the function has no side effect and is not writing to any outputs, // we can safely treat the call as a normal inst. @@ -668,10 +668,13 @@ bool areCallArgumentsSideEffectFree(IRCall* call) auto module = parentFunc->getModule(); if (!module) return false; - auto dom = module->findDominatorTree(parentFunc); if (arg->getOp() == kIROp_Var && getParentFunc(arg) == parentFunc) { + IRDominatorTree* dom = nullptr; + if (isBitSet(options, SideEffectAnalysisOptions::UseDominanceTree)) + dom = module->findOrCreateDominatorTree(parentFunc); + // If the pointer argument is a local variable (thus can't alias with other addresses) // and it is never read from in the function, we can safely treat the call as having // no side-effect. @@ -751,17 +754,17 @@ bool areCallArgumentsSideEffectFree(IRCall* call) return true; } -bool isPureFunctionalCall(IRCall* call) +bool isPureFunctionalCall(IRCall* call, SideEffectAnalysisOptions options) { auto callee = getResolvedInstForDecorations(call->getCallee()); if (callee->findDecoration<IRReadNoneDecoration>()) { - return areCallArgumentsSideEffectFree(call); + return areCallArgumentsSideEffectFree(call, options); } return false; } -bool isSideEffectFreeFunctionalCall(IRCall* call) +bool isSideEffectFreeFunctionalCall(IRCall* call, SideEffectAnalysisOptions options) { // If the call has been marked as no-side-effect, we // will treat it so, by-passing all other checks. @@ -770,7 +773,7 @@ bool isSideEffectFreeFunctionalCall(IRCall* call) if (!doesCalleeHaveSideEffect(call->getCallee())) { - return areCallArgumentsSideEffectFree(call); + return areCallArgumentsSideEffectFree(call, options); } return false; } @@ -964,6 +967,34 @@ bool isOne(IRInst* inst) } } +void initializeScratchData(IRInst* inst) +{ + List<IRInst*> workList; + workList.add(inst); + while (workList.getCount() != 0) + { + auto item = workList.getLast(); + workList.removeLast(); + item->scratchData = 0; + for (auto child = item->getLastDecorationOrChild(); child; child = child->getPrevInst()) + workList.add(child); + } +} + +void resetScratchDataBit(IRInst* inst, int bitIndex) +{ + List<IRInst*> workList; + workList.add(inst); + while (workList.getCount() != 0) + { + auto item = workList.getLast(); + workList.removeLast(); + item->scratchData &= ~(1ULL << bitIndex); + for (auto child = item->getLastDecorationOrChild(); child; child = child->getPrevInst()) + workList.add(child); + } +} + struct GenericChildrenMigrationContextImpl { IRCloneEnv cloneEnv; |
