diff options
Diffstat (limited to 'source/slang/slang-ir-link.cpp')
| -rw-r--r-- | source/slang/slang-ir-link.cpp | 48 |
1 files changed, 32 insertions, 16 deletions
diff --git a/source/slang/slang-ir-link.cpp b/source/slang/slang-ir-link.cpp index 80f974536..55048484f 100644 --- a/source/slang/slang-ir-link.cpp +++ b/source/slang/slang-ir-link.cpp @@ -229,11 +229,14 @@ IRInst* IRSpecContext::maybeCloneValue(IRInst* originalValue) switch (originalValue->getOp()) { case kIROp_StructType: + case kIROp_ClassType: case kIROp_Func: case kIROp_Generic: case kIROp_GlobalVar: case kIROp_GlobalParam: + case kIROp_GlobalConstant: case kIROp_StructKey: + case kIROp_InterfaceRequirementEntry: case kIROp_GlobalGenericParam: case kIROp_WitnessTable: case kIROp_InterfaceType: @@ -277,26 +280,34 @@ IRInst* IRSpecContext::maybeCloneValue(IRInst* originalValue) } break; + case kIROp_VoidLit: + { + return builder->getVoidValue(); + } + break; + default: { // In the default case, assume that we have some sort of "hoistable" // instruction that requires us to create a clone of it. UInt argCount = originalValue->getOperandCount(); - IRInst* clonedValue = builder->createIntrinsicInst( - cloneType(this, originalValue->getFullType()), - originalValue->getOp(), - argCount, nullptr); - registerClonedValue(this, clonedValue, originalValue); + ShortList<IRInst*> newArgs; + newArgs.setCount(argCount); for (UInt aa = 0; aa < argCount; ++aa) { IRInst* originalArg = originalValue->getOperand(aa); IRInst* clonedArg = cloneValue(this, originalArg); - clonedValue->getOperands()[aa].init(clonedValue, clonedArg); + newArgs[aa] = clonedArg; } + IRInst* clonedValue = builder->createIntrinsicInst( + cloneType(this, originalValue->getFullType()), + originalValue->getOp(), + argCount, newArgs.getArrayView().getBuffer()); + registerClonedValue(this, clonedValue, originalValue); + cloneDecorationsAndChildren(this, clonedValue, originalValue); - - addHoistableInst(builder, clonedValue); + builder->addInst(clonedValue); return clonedValue; } @@ -524,6 +535,8 @@ IRGlobalConstant* cloneGlobalConstantImpl( IRGlobalConstant* originalVal, IROriginalValuesForClone const& originalValues) { + auto oldBuilder = context->builder; + context->builder = builder; auto clonedType = cloneType(context, originalVal->getFullType()); IRGlobalConstant* clonedVal = nullptr; if(auto originalInitVal = originalVal->getValue()) @@ -537,7 +550,7 @@ IRGlobalConstant* cloneGlobalConstantImpl( } cloneSimpleGlobalValueImpl(context, originalVal, originalValues, clonedVal); - + context->builder = oldBuilder; return clonedVal; } @@ -1174,21 +1187,24 @@ IRInst* cloneInst( // instruction with the right number of operands, intialize // it, and then add it to the sequence. UInt argCount = originalInst->getOperandCount(); - IRInst* clonedInst = builder->createIntrinsicInst( - cloneType(context, originalInst->getFullType()), - originalInst->getOp(), - argCount, nullptr); - registerClonedValue(context, clonedInst, originalValues); + ShortList<IRInst*> newArgs; + newArgs.setCount(argCount); auto oldBuilder = context->builder; context->builder = builder; for (UInt aa = 0; aa < argCount; ++aa) { IRInst* originalArg = originalInst->getOperand(aa); IRInst* clonedArg = cloneValue(context, originalArg); - clonedInst->getOperands()[aa].init(clonedInst, clonedArg); + newArgs[aa] = clonedArg; } - builder->addInst(clonedInst); context->builder = oldBuilder; + + IRInst* clonedInst = builder->createIntrinsicInst( + cloneType(context, originalInst->getFullType()), + originalInst->getOp(), + argCount, newArgs.getArrayView().getBuffer()); + builder->addInst(clonedInst); + registerClonedValue(context, clonedInst, originalValues); cloneDecorationsAndChildren(context, clonedInst, originalInst); cloneExtraDecorations(context, clonedInst, originalValues); return clonedInst; |
