diff options
Diffstat (limited to 'source/slang/slang-ir.cpp')
| -rw-r--r-- | source/slang/slang-ir.cpp | 71 |
1 files changed, 60 insertions, 11 deletions
diff --git a/source/slang/slang-ir.cpp b/source/slang/slang-ir.cpp index bfd6c20cf..c97c04f88 100644 --- a/source/slang/slang-ir.cpp +++ b/source/slang/slang-ir.cpp @@ -808,12 +808,7 @@ namespace Slang IRType* IRFunc::getResultType() { return getDataType()->getResultType(); } UInt IRFunc::getParamCount() { return getDataType()->getParamCount(); } IRType* IRFunc::getParamType(UInt index) { return getDataType()->getParamType(index); } - - void IRGlobalValueWithCode::addBlock(IRBlock* block) - { - block->insertAtEnd(this); - } - + void fixUpFuncType(IRFunc* func, IRType* resultType) { SLANG_ASSERT(func); @@ -1279,14 +1274,16 @@ namespace Slang // Get the current function (or other value with code) // that we are inserting into (if any). - IRGlobalValueWithCode* IRInsertLoc::getFunc() const + IRInst* IRInsertLoc::getFunc() const { auto pp = getParent(); if (const auto block = as<IRBlock>(pp)) { pp = pp->getParent(); } - return as<IRGlobalValueWithCode>(pp); + if (as<IRGlobalValueWithCode>(pp) || as<IRExpand>(pp)) + return pp; + return nullptr; } void addHoistableInst( @@ -2805,6 +2802,14 @@ namespace Slang return getTupleType(SLANG_COUNT_OF(operands), operands); } + IRExpandType* IRBuilder::getExpandTypeOrVal(IRType* type, IRInst* pattern, ArrayView<IRInst*> capture) + { + ShortList<IRInst*> args; + args.add(pattern); + args.addRange(capture); + return (IRExpandType*)emitIntrinsicInst(type, kIROp_ExpandTypeOrVal, args.getCount(), args.getArrayView().getBuffer()); + } + IRResultType* IRBuilder::getResultType(IRType* valueType, IRType* errorType) { IRInst* operands[] = {valueType, errorType}; @@ -3548,6 +3553,26 @@ namespace Slang return inst; } + IRInst* IRBuilder::emitExpandInst(IRType* type, UInt capturedArgCount, IRInst* const* capturedArgs) + { + auto inst = createInstWithTrailingArgs<IRSpecialize>( + this, + kIROp_Expand, + type, + capturedArgCount, + capturedArgs, + 0, + nullptr); + addInst(inst); + return inst; + } + + IRInst* IRBuilder::emitEachInst(IRType* type, IRInst* base, IRInst* indexArg) + { + IRInst* args[] = { base, indexArg }; + return emitIntrinsicInst(type, kIROp_Each, indexArg ? 2 : 1, args); + } + IRInst* IRBuilder::emitLookupInterfaceMethodInst( IRType* type, IRInst* witnessTableVal, @@ -4057,6 +4082,12 @@ namespace Slang return emitIntrinsicInst(getNativeStringType(), kIROp_getNativeStr, 1, &str); } + IRInst* IRBuilder::emitGetTupleElement(IRType* type, IRInst* tuple, IRInst* element) + { + IRInst* args[] = { tuple, element }; + return emitIntrinsicInst(type, kIROp_GetTupleElement, 2, args); + } + IRInst* IRBuilder::emitGetTupleElement(IRType* type, IRInst* tuple, UInt element) { // As a quick simplification/optimization, if the user requests @@ -4070,9 +4101,7 @@ namespace Slang return makeTuple->getOperand(element); } } - - IRInst* args[] = { tuple, getIntValue(getIntType(), element) }; - return emitIntrinsicInst(type, kIROp_GetTupleElement, 2, args); + return emitGetTupleElement(type, tuple, getIntValue(getIntType(), element)); } IRInst* IRBuilder::emitMakeResultError(IRType* resultType, IRInst* errorVal) @@ -5409,6 +5438,18 @@ namespace Slang return inst; } + IRInst* IRBuilder::emitYield( + IRInst* val) + { + auto inst = createInst<IRYield>( + this, + kIROp_Yield, + nullptr, + val); + addInst(inst); + return inst; + } + IRInst* IRBuilder::emitReturn() { auto voidVal = getVoidValue(); @@ -7238,6 +7279,7 @@ namespace Slang case kIROp_Func: case kIROp_GlobalVar: case kIROp_Generic: + case kIROp_Expand: dumpIRGlobalValueWithCode(context, (IRGlobalValueWithCode*)inst); return; @@ -8230,6 +8272,7 @@ namespace Slang case kIROp_WitnessTableEntry: case kIROp_InterfaceRequirementEntry: case kIROp_Block: + case kIROp_Each: return false; /// Liveness markers have no side effects @@ -8250,6 +8293,7 @@ namespace Slang case kIROp_MakeMatrixFromScalar: case kIROp_MatrixReshape: case kIROp_VectorReshape: + case kIROp_MakeWitnessPack: case kIROp_MakeArray: case kIROp_MakeArrayFromElement: case kIROp_MakeStruct: @@ -8806,6 +8850,11 @@ namespace Slang } } + void IRInst::addBlock(IRBlock* block) + { + block->insertAtEnd(this); + } + void IRInst::dump() { if (auto intLit = as<IRIntLit>(this)) |
