From 4644b64d648893718336d83fae0139ee19405e61 Mon Sep 17 00:00:00 2001 From: Tim Foley Date: Mon, 11 Sep 2017 15:25:31 -0700 Subject: Get another test working with IR codedgen - Add support for matrix types in IR/codegen - Add support for basic indexing operations in IR/codegen --- source/slang/ir.cpp | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) (limited to 'source/slang/ir.cpp') diff --git a/source/slang/ir.cpp b/source/slang/ir.cpp index 9e39579f6..3a6410125 100644 --- a/source/slang/ir.cpp +++ b/source/slang/ir.cpp @@ -534,6 +534,25 @@ namespace Slang &args[0]); } + template + static T* findOrEmitInst( + IRBuilder* builder, + IROp op, + IRType* type, + IRInst* arg1, + IRInst* arg2, + IRInst* arg3) + { + IRInst* args[] = { arg1, arg2, arg3 }; + return (T*) findOrEmitInstImpl( + builder, + sizeof(T), + op, + type, + 3, + &args[0]); + } + // bool operator==(IRConstantKey const& left, IRConstantKey const& right) @@ -644,6 +663,20 @@ namespace Slang elementCount); } + IRType* IRBuilder::getMatrixType( + IRType* elementType, + IRValue* rowCount, + IRValue* columnCount) + { + return findOrEmitInst( + this, + kIROp_MatrixType, + getTypeType(), + elementType, + rowCount, + columnCount); + } + IRType* IRBuilder::getTypeType() { return findOrEmitInst( @@ -931,6 +964,38 @@ namespace Slang return inst; } + IRInst* IRBuilder::emitElementExtract( + IRType* type, + IRValue* base, + IRValue* index) + { + auto inst = createInst( + this, + kIROp_getElement, + type, + base, + index); + + addInst(inst); + return inst; + } + + IRInst* IRBuilder::emitElementAddress( + IRType* type, + IRValue* basePtr, + IRValue* index) + { + auto inst = createInst( + this, + kIROp_getElementPtr, + type, + basePtr, + index); + + addInst(inst); + return inst; + } + IRInst* IRBuilder::emitReturn( IRValue* val) { -- cgit v1.2.3