From 4a66e9729175a89833e5db784bb64e6a7f60cdf2 Mon Sep 17 00:00:00 2001 From: Yong He Date: Fri, 27 Jan 2023 16:41:31 -0800 Subject: Register allocation during phi elimination. (#2613) * Register allocation during phi elimination. * Enhance the test case. * Cleanup line breaks in test case. * remove unncessary line break changes. * More cleanups. --------- Co-authored-by: Yong He --- source/slang/slang-ir.cpp | 63 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 62 insertions(+), 1 deletion(-) (limited to 'source/slang/slang-ir.cpp') diff --git a/source/slang/slang-ir.cpp b/source/slang/slang-ir.cpp index 0434ff682..845232ae6 100644 --- a/source/slang/slang-ir.cpp +++ b/source/slang/slang-ir.cpp @@ -4378,7 +4378,7 @@ namespace Slang type = getVectorType(matrixType->getElementType(), matrixType->getColumnCount()); } SLANG_RELEASE_ASSERT(type); - auto inst = createInst( + auto inst = createInst( this, kIROp_GetElement, type, @@ -4435,6 +4435,67 @@ namespace Slang return inst; } + IRInst* IRBuilder::emitElementAddress( + IRInst* basePtr, + IRInst* index) + { + IRType* type = nullptr; + auto basePtrType = as(basePtr->getDataType()); + if (auto arrayType = as(basePtrType->getValueType())) + { + type = arrayType->getElementType(); + } + else if (auto vectorType = as(basePtrType->getValueType())) + { + type = vectorType->getElementType(); + } + else if (auto matrixType = as(basePtrType->getValueType())) + { + type = getVectorType(matrixType->getElementType(), matrixType->getColumnCount()); + } + SLANG_RELEASE_ASSERT(type); + auto inst = createInst( + this, + kIROp_GetElementPtr, + getPtrType(type), + basePtr, + index); + + addInst(inst); + return inst; + } + + IRInst* IRBuilder::emitElementAddress( + IRInst* basePtr, + const ArrayView& accessChain) + { + for (auto access : accessChain) + { + auto basePtrType = cast(basePtr->getDataType()); + IRType* resultType = nullptr; + if (auto structKey = as(access)) + { + auto structType = as(basePtrType->getValueType()); + SLANG_RELEASE_ASSERT(structType); + for (auto field : structType->getFields()) + { + if (field->getKey() == structKey) + { + resultType = field->getFieldType(); + break; + } + } + SLANG_RELEASE_ASSERT(resultType); + basePtr = emitFieldAddress(getPtrType(resultType), basePtr, structKey); + } + else + { + basePtr = emitElementAddress(basePtr, access); + } + } + return basePtr; + } + IRInst* IRBuilder::emitUpdateElement(IRInst* base, IRInst* index, IRInst* newElement) { auto inst = createInst( -- cgit v1.2.3