diff options
| author | Yong He <yonghe@outlook.com> | 2023-01-27 16:41:31 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-01-27 16:41:31 -0800 |
| commit | 4a66e9729175a89833e5db784bb64e6a7f60cdf2 (patch) | |
| tree | 6a3cb0da3a6682ac0f8b06e66cb8e5fcd6dff279 /source/slang/slang-ir.cpp | |
| parent | 93a6b6119b6b65c4f6b00ca12d745e21b679c82f (diff) | |
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 <yhe@nvidia.com>
Diffstat (limited to 'source/slang/slang-ir.cpp')
| -rw-r--r-- | source/slang/slang-ir.cpp | 63 |
1 files changed, 62 insertions, 1 deletions
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<IRFieldAddress>( + auto inst = createInst<IRGetElement>( 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<IRPtrTypeBase>(basePtr->getDataType()); + if (auto arrayType = as<IRArrayType>(basePtrType->getValueType())) + { + type = arrayType->getElementType(); + } + else if (auto vectorType = as<IRVectorType>(basePtrType->getValueType())) + { + type = vectorType->getElementType(); + } + else if (auto matrixType = as<IRMatrixType>(basePtrType->getValueType())) + { + type = getVectorType(matrixType->getElementType(), matrixType->getColumnCount()); + } + SLANG_RELEASE_ASSERT(type); + auto inst = createInst<IRGetElementPtr>( + this, + kIROp_GetElementPtr, + getPtrType(type), + basePtr, + index); + + addInst(inst); + return inst; + } + + IRInst* IRBuilder::emitElementAddress( + IRInst* basePtr, + const ArrayView<IRInst*>& accessChain) + { + for (auto access : accessChain) + { + auto basePtrType = cast<IRPtrTypeBase>(basePtr->getDataType()); + IRType* resultType = nullptr; + if (auto structKey = as<IRStructKey>(access)) + { + auto structType = as<IRStructType>(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<IRUpdateElement>( |
