From 90444f8366255f274993ce4699738d9ab7cf4ee1 Mon Sep 17 00:00:00 2001 From: Yong He Date: Mon, 15 Jun 2020 09:04:53 -0700 Subject: Generate IRType for interfaces, and reference them as `operand[0]` in IRWitnessTable values (#1387) * Generate IRType for interfaces, and use them as the type of IRWitnessTable values. This results the following IR for the included test case: ``` [export("_S3tu010IInterface7Computep1pii")] let %1 : _ = key [export("_ST3tu010IInterface")] [nameHint("IInterface")] interface %IInterface : _(%1); [export("_S3tu04Impl7Computep1pii")] [nameHint("Impl.Compute")] func %Implx5FCompute : Func(Int, Int) { block %2( [nameHint("inVal")] param %inVal : Int): let %3 : Int = mul(%inVal, %inVal) return_val(%3) } [export("_SW3tu04Impl3tu010IInterface")] witness_table %4 : %IInterface { witness_table_entry(%1,%Implx5FCompute) } ``` * Fixes per code review comments. Moved interface type reference in IRWitnessTable from their type to operand[0]. * Fix typo in comment. --- source/slang/slang-ir-link.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'source/slang/slang-ir-link.cpp') diff --git a/source/slang/slang-ir-link.cpp b/source/slang/slang-ir-link.cpp index 904a88d78..3f51aa876 100644 --- a/source/slang/slang-ir-link.cpp +++ b/source/slang/slang-ir-link.cpp @@ -567,7 +567,12 @@ IRWitnessTable* cloneWitnessTableImpl( IRWitnessTable* dstTable = nullptr, bool registerValue = true) { - auto clonedTable = dstTable ? dstTable : builder->createWitnessTable(); + IRWitnessTable* clonedTable = dstTable; + if (!clonedTable) + { + auto clonedBaseType = cloneType(context, as(originalTable->getOperand(0))); + clonedTable = builder->createWitnessTable(clonedBaseType); + } cloneSimpleGlobalValueImpl(context, originalTable, originalValues, clonedTable, registerValue); return clonedTable; } @@ -599,7 +604,13 @@ IRInterfaceType* cloneInterfaceTypeImpl( IRInterfaceType* originalInterface, IROriginalValuesForClone const& originalValues) { - auto clonedInterface = builder->createInterfaceType(); + auto clonedInterface = builder->createInterfaceType(originalInterface->getOperandCount(), nullptr); + for (UInt i = 0; i < originalInterface->getOperandCount(); i++) + { + auto clonedKey = findClonedValue(context, originalInterface->getOperand(i)); + SLANG_ASSERT(clonedKey); + clonedInterface->setOperand(i, clonedKey); + } cloneSimpleGlobalValueImpl(context, originalInterface, originalValues, clonedInterface); return clonedInterface; } -- cgit v1.2.3