From 73a61edda8893901acad05bb4e7d3110db5041a8 Mon Sep 17 00:00:00 2001 From: Yong He Date: Wed, 28 Feb 2024 22:57:07 -0800 Subject: [SPIRV] Add NonSemanticDebugInfo for step-through debugging. (#3644) * [SPIRV] Add NonSemanticDebugInfo for step-through debugging. * Fix. * Fix. --- source/slang/slang-ir-util.cpp | 54 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 50 insertions(+), 4 deletions(-) (limited to 'source/slang/slang-ir-util.cpp') 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(); - 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& 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) { -- cgit v1.2.3