From 0c87001d7fb9dabaa17f9784e99d7438592d2373 Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Mon, 6 Jan 2020 15:36:11 -0500 Subject: Fix scoping issue around use of IRTypeSet (#1160) * WIP use IRTypeSet in CPPSourceEmitter - doesn't work because of a cloning issue, causing a crash on exit. * Fix destruction of module issue for IRTypeSet usage in CPPEmitter. * Fix out definition emitting ordering that was removed. * Disable cuda output test. --- source/slang/slang-ir-type-set.cpp | 63 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) (limited to 'source/slang/slang-ir-type-set.cpp') diff --git a/source/slang/slang-ir-type-set.cpp b/source/slang/slang-ir-type-set.cpp index 7beeaced4..a4ebf8242 100644 --- a/source/slang/slang-ir-type-set.cpp +++ b/source/slang/slang-ir-type-set.cpp @@ -22,6 +22,22 @@ IRTypeSet::IRTypeSet(Session* session) } IRTypeSet::~IRTypeSet() +{ + _clearTypes(); +} + +void IRTypeSet::clear() +{ + _clearTypes(); + + m_cloneMap.Clear(); + + m_module = m_builder.createModule(); + m_sharedBuilder.module = m_module; + m_builder.setInsertInto(m_module->getModuleInst()); +} + +void IRTypeSet::_clearTypes() { List types; getTypes(types); @@ -226,4 +242,51 @@ void IRTypeSet::addVectorForMatrixTypes() } } +static bool _hasNominalOperand(IRInst* inst) +{ + const Index operandCount = Index(inst->getOperandCount()); + auto operands = inst->getOperands(); + + for (Index i = 0; i < operandCount; ++i) + { + IRInst* operand = operands[i].get(); + if (isNominalOp(operand->op)) + { + return true; + } + } + + return false; +} + +void IRTypeSet::_addAllBuiltinTypesRec(IRInst* inst) +{ + for (IRInst* child = inst->getFirstDecorationOrChild(); child; child = child->getNextInst()) + { + IRType* type = nullptr; + + if (auto vectorType = as(child)) + { + type = vectorType; + } + else if (auto matrixType = as(child)) + { + type = matrixType; + } + if (type && !_hasNominalOperand(type)) + { + add(type); + } + else + { + _addAllBuiltinTypesRec(child); + } + } +} + +void IRTypeSet::addAllBuiltinTypes(IRModule* module) +{ + _addAllBuiltinTypesRec(module->getModuleInst()); +} + } -- cgit v1.2.3