diff options
| author | Yong He <yonghe@outlook.com> | 2025-07-11 16:54:43 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-07-11 23:54:43 +0000 |
| commit | 1e1a49ccf595dcc99bd9792a47199ec89d5b4370 (patch) | |
| tree | 199dca9cc2c5f27466ebd8b6e9e6fcd8328db9fa /source/slang/slang-ir-specialize-address-space.cpp | |
| parent | d8d0b8969f731990820f25812f3d90ee4dd1ee75 (diff) | |
Fixup address spaces after inlining. (#7731)
* Fixup address spaces after inlining.
* add -O0
Diffstat (limited to 'source/slang/slang-ir-specialize-address-space.cpp')
| -rw-r--r-- | source/slang/slang-ir-specialize-address-space.cpp | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/source/slang/slang-ir-specialize-address-space.cpp b/source/slang/slang-ir-specialize-address-space.cpp index ae0542734..2bc1de775 100644 --- a/source/slang/slang-ir-specialize-address-space.cpp +++ b/source/slang/slang-ir-specialize-address-space.cpp @@ -412,4 +412,69 @@ void specializeAddressSpace(IRModule* module, InitialAddressSpaceAssigner* addrS AddressSpaceContext context(module, addrSpaceAssigner); context.processModule(); } + +void propagateAddressSpaceFromInsts(List<IRInst*>&& workList) +{ + HashSet<IRInst*> visited; + auto addUserToWorkList = [&](IRInst* inst) + { + for (auto use = inst->firstUse; use; use = use->nextUse) + { + auto user = use->getUser(); + if (visited.add(user)) + workList.add(user); + } + }; + for (auto item : workList) + { + visited.add(item); + } + for (Index i = 0; i < workList.getCount(); i++) + { + auto inst = workList[i]; + IRBuilder builder(inst); + auto instPtrType = as<IRPtrTypeBase>(inst->getDataType()); + if (!instPtrType) + continue; + for (auto use = inst->firstUse; use; use = use->nextUse) + { + auto user = use->getUser(); + builder.setInsertBefore(user); + switch (user->getOp()) + { + case kIROp_Loop: + case kIROp_UnconditionalBranch: + { + auto branch = as<IRUnconditionalBranch>(user); + UIndex phiIndex = (UIndex)(use - branch->getArgs()); + auto param = getParamAt(branch->getTargetBlock(), phiIndex); + if (!param) + continue; + user = param; + break; + } + } + switch (user->getOp()) + { + case kIROp_FieldAddress: + case kIROp_GetElementPtr: + case kIROp_GetOffsetPtr: + case kIROp_Param: + { + auto valueType = tryGetPointedToType(&builder, user->getDataType()); + if (!valueType) + continue; + auto newType = builder.getPtrTypeWithAddressSpace(valueType, instPtrType); + if (newType != user->getDataType()) + { + user->setFullType(newType); + addUserToWorkList(user); + } + break; + } + } + } + } +} + } // namespace Slang |
