diff options
Diffstat (limited to 'source')
| -rw-r--r-- | source/slang/slang-ir-util.cpp | 15 | ||||
| -rw-r--r-- | source/slang/slang-ir-util.h | 2 | ||||
| -rw-r--r-- | source/slang/slang-lower-to-ir.cpp | 5 |
3 files changed, 15 insertions, 7 deletions
diff --git a/source/slang/slang-ir-util.cpp b/source/slang/slang-ir-util.cpp index c8d76569f..1b11f8165 100644 --- a/source/slang/slang-ir-util.cpp +++ b/source/slang/slang-ir-util.cpp @@ -997,12 +997,15 @@ void sortBlocksInFunc(IRGlobalValueWithCode* func) block->insertAtEnd(func); } -void removeLinkageDecorations(IRGlobalValueWithCode* func) +void removeLinkageDecorations(IRInst* inst) { + if (!inst) + return; + List<IRInst*> toRemove; - for (auto inst : func->getDecorations()) + for (auto decoration : inst->getDecorations()) { - switch (inst->getOp()) + switch (decoration->getOp()) { case kIROp_ImportDecoration: case kIROp_ExportDecoration: @@ -1013,14 +1016,14 @@ void removeLinkageDecorations(IRGlobalValueWithCode* func) case kIROp_CudaDeviceExportDecoration: case kIROp_DllExportDecoration: case kIROp_HLSLExportDecoration: - toRemove.add(inst); + toRemove.add(decoration); break; default: break; } } - for (auto inst : toRemove) - inst->removeAndDeallocate(); + for (auto decoration : toRemove) + decoration->removeAndDeallocate(); } void setInsertBeforeOrdinaryInst(IRBuilder* builder, IRInst* inst) diff --git a/source/slang/slang-ir-util.h b/source/slang/slang-ir-util.h index f47026185..77c464b1f 100644 --- a/source/slang/slang-ir-util.h +++ b/source/slang/slang-ir-util.h @@ -253,7 +253,7 @@ IRInst* emitLoopBlocks( void sortBlocksInFunc(IRGlobalValueWithCode* func); // Remove all linkage decorations from func. -void removeLinkageDecorations(IRGlobalValueWithCode* func); +void removeLinkageDecorations(IRInst* inst); IRInst* findInterfaceRequirement(IRInterfaceType* type, IRInst* key); diff --git a/source/slang/slang-lower-to-ir.cpp b/source/slang/slang-lower-to-ir.cpp index 4b232e829..1f5909e94 100644 --- a/source/slang/slang-lower-to-ir.cpp +++ b/source/slang/slang-lower-to-ir.cpp @@ -9344,6 +9344,11 @@ struct DeclLoweringVisitor : DeclVisitor<DeclLoweringVisitor, LoweredValInfo> switch (requirementVal->getOp()) { default: + // Remove linkage decorations from the requirement value to prevent + // duplicate mangled names and allow DCE to clean up unused functions. + // Interface requirements only need the type information, not the linkage. + removeLinkageDecorations(requirementVal); + // For the majority of requirements, we only care about its type in an // interface definition, so we store only the type from the lowered IR // in the interface entry. |
