diff options
Diffstat (limited to 'source/slang/slang-ir-util.cpp')
| -rw-r--r-- | source/slang/slang-ir-util.cpp | 54 |
1 files changed, 50 insertions, 4 deletions
diff --git a/source/slang/slang-ir-util.cpp b/source/slang/slang-ir-util.cpp index f514fea1d..8b39e8b45 100644 --- a/source/slang/slang-ir-util.cpp +++ b/source/slang/slang-ir-util.cpp @@ -266,12 +266,38 @@ String dumpIRToString(IRInst* root, IRDumpOptions options) return sb.toString(); } -void copyNameHintDecoration(IRInst* dest, IRInst* src) +void copyNameHintAndDebugDecorations(IRInst* dest, IRInst* src) { - auto decor = src->findDecoration<IRNameHintDecoration>(); - if (decor) + IRDecoration* nameHintDecoration = nullptr; + IRDecoration* linkageDecoration = nullptr; + IRDecoration* debugLocationDecoration = nullptr; + for (auto decor = src->getFirstDecoration(); decor; decor = decor->getNextDecoration()) { - cloneDecoration(decor, dest); + switch (decor->getOp()) + { + case kIROp_NameHintDecoration: + nameHintDecoration = decor; + break; + case kIROp_ImportDecoration: + case kIROp_ExportDecoration: + linkageDecoration = decor; + break; + case kIROp_DebugLocationDecoration: + debugLocationDecoration = decor; + break; + } + } + if (nameHintDecoration) + { + cloneDecoration(nameHintDecoration, dest); + } + if (linkageDecoration) + { + cloneDecoration(linkageDecoration, dest); + } + if (debugLocationDecoration) + { + cloneDecoration(debugLocationDecoration, dest); } } @@ -557,6 +583,26 @@ IRInst* getRootAddr(IRInst* addr) return addr; } +IRInst* getRootAddr(IRInst* addr, List<IRInst*>& outAccessChain) +{ + for (;;) + { + switch (addr->getOp()) + { + case kIROp_GetElementPtr: + case kIROp_FieldAddress: + outAccessChain.add(addr->getOperand(1)); + addr = addr->getOperand(0); + continue; + default: + break; + } + break; + } + outAccessChain.reverse(); + return addr; +} + // A simple and conservative address aliasing check. bool canAddressesPotentiallyAlias(IRGlobalValueWithCode* func, IRInst* addr1, IRInst* addr2) { |
