Skip to content

Commit 6a8b99d

Browse files
committedMar 6, 2025·
Update comments
1 parent 342d386 commit 6a8b99d

File tree

4 files changed

+22
-36
lines changed

4 files changed

+22
-36
lines changed
 

‎source/slang/slang-ir-autodiff.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -1861,6 +1861,7 @@ IRInst* DifferentiableTypeConformanceContext::buildDifferentiablePairWitness(
18611861
sharedContext->differentiableInterfaceType,
18621862
(IRType*)pairType);
18631863

1864+
// Add WitnessTableEntry only once
18641865
if (table->getFirstDecorationOrChild() == nullptr)
18651866
{
18661867
// And place it in the synthesized witness table.
@@ -1946,6 +1947,7 @@ IRInst* DifferentiableTypeConformanceContext::buildDifferentiablePairWitness(
19461947
sharedContext->differentiablePtrInterfaceType,
19471948
(IRType*)pairType);
19481949

1950+
// Add WitnessTableEntry only once
19491951
if (table->getFirstDecorationOrChild() == nullptr)
19501952
{
19511953
// And place it in the synthesized witness table.
@@ -1992,6 +1994,7 @@ IRInst* DifferentiableTypeConformanceContext::buildArrayWitness(
19921994
sharedContext->differentiableInterfaceType,
19931995
(IRType*)arrayType);
19941996

1997+
// Add WitnessTableEntry only once
19951998
if (table->getFirstDecorationOrChild() == nullptr)
19961999
{
19972000
// And place it in the synthesized witness table.
@@ -2074,6 +2077,7 @@ IRInst* DifferentiableTypeConformanceContext::buildArrayWitness(
20742077
sharedContext->differentiablePtrInterfaceType,
20752078
(IRType*)arrayType);
20762079

2080+
// Add WitnessTableEntry only once
20772081
if (table->getFirstDecorationOrChild() == nullptr)
20782082
{
20792083
// And place it in the synthesized witness table.
@@ -2118,6 +2122,7 @@ IRInst* DifferentiableTypeConformanceContext::buildTupleWitness(
21182122
sharedContext->differentiableInterfaceType,
21192123
(IRType*)inTupleType);
21202124

2125+
// Add WitnessTableEntry only once
21212126
if (table->getFirstDecorationOrChild() == nullptr)
21222127
{
21232128
// And place it in the synthesized witness table.
@@ -2234,6 +2239,7 @@ IRInst* DifferentiableTypeConformanceContext::buildTupleWitness(
22342239
sharedContext->differentiablePtrInterfaceType,
22352240
(IRType*)inTupleType);
22362241

2242+
// Add WitnessTableEntry only once
22372243
if (table->getFirstDecorationOrChild() == nullptr)
22382244
{
22392245
// And place it in the synthesized witness table.
@@ -3096,6 +3102,7 @@ struct AutoDiffPass : public InstPassBase
30963102
builder.createWitnessTable(autodiffContext->differentiableInterfaceType, originalType);
30973103
result.diffWitness = origTypeIsDiffWitness;
30983104

3105+
// Add WitnessTableEntry only once
30993106
if (origTypeIsDiffWitness->getFirstDecorationOrChild() == nullptr)
31003107
{
31013108
builder.createWitnessTableEntry(
@@ -3116,6 +3123,7 @@ struct AutoDiffPass : public InstPassBase
31163123
addMethod);
31173124
}
31183125

3126+
// Add WitnessTableEntry only once
31193127
if (diffTypeIsDiffWitness->getFirstDecorationOrChild() == nullptr)
31203128
{
31213129
builder.createWitnessTableEntry(
@@ -3212,6 +3220,7 @@ struct AutoDiffPass : public InstPassBase
32123220
auto witnessTableType = innerResult.diffWitness->getFullType();
32133221
auto newWitnessTable = builder.createWitnessTable(witnessTableType, concreteType);
32143222

3223+
// Add WitnessTableEntry only once
32153224
if (newWitnessTable->getFirstDecorationOrChild() == nullptr)
32163225
{
32173226
builder.setInsertInto(newWitnessTable);

‎source/slang/slang-ir-specialize.cpp

-25
Original file line numberDiff line numberDiff line change
@@ -3029,31 +3029,6 @@ void finalizeSpecialization(IRModule* module)
30293029
}
30303030
}
30313031

3032-
// Returns true when "a" depends on "b".
3033-
bool IsIRInstDependOn(IRInst* a, IRInst* b)
3034-
{
3035-
if (a->getFullType() == b)
3036-
return true;
3037-
3038-
for (UInt i = 0; i < a->getOperandCount(); i++)
3039-
{
3040-
auto operand = a->getOperand(i);
3041-
if (operand == b)
3042-
return true;
3043-
}
3044-
3045-
if (auto wt = as<IRWitnessTable>(a))
3046-
{
3047-
for (auto entry : wt->getEntries())
3048-
{
3049-
if (entry->getRequirementKey() == b || entry->getSatisfyingVal() == b)
3050-
return true;
3051-
}
3052-
}
3053-
3054-
return false;
3055-
}
3056-
30573032
IRInst* specializeGenericImpl(
30583033
IRGeneric* genericVal,
30593034
IRSpecialize* specializeInst,

‎source/slang/slang-ir.cpp

+6-5
Original file line numberDiff line numberDiff line change
@@ -1696,10 +1696,11 @@ void addHoistableInst(IRBuilder* builder, IRInst* inst)
16961696

16971697
if (inst->getOp() == kIROp_WitnessTable)
16981698
{
1699-
// WitnessTable can refer to IRSpecialize from its WitnessTableEntry
1700-
// children. In this case, specialize insts must be cloned before the
1701-
// WitnessTable. Similar an WitnessTables can have depdency to another
1702-
// WitnessTable.
1699+
SLANG_ASSERT(getIROpInfo(kIROp_WitnessTable).isHoistable());
1700+
1701+
// WitnessTable can refer to IRSpecialize from its WitnessTableEntry children. In this case,
1702+
// specialize insts must be cloned before the WitnessTable. Similar an WitnessTables can
1703+
// have depdency to another WitnessTable.
17031704
//
17041705
for (IRInst* iter = insertBeforeInst; iter;)
17051706
{
@@ -4633,7 +4634,7 @@ void addGlobalValue(IRBuilder* builder, IRInst* value)
46334634
parent = builder->getModule()->getModuleInst();
46344635
}
46354636

4636-
// If the value is already in the parent, keep it as it. Because WitnessTable is Hoistable, the
4637+
// If the value is already in the parent, keep it as-is. Because WitnessTable is Hoistable, the
46374638
// parent can have only one instance of this WitnessTable. The order among siblings should
46384639
// remain because the later siblings may have dependency to the earlier siblings.
46394640
//

‎source/slang/slang-lower-to-ir.cpp

+7-6
Original file line numberDiff line numberDiff line change
@@ -8016,9 +8016,10 @@ struct DeclLoweringVisitor : DeclVisitor<DeclLoweringVisitor, LoweredValInfo>
80168016
irWitnessTableBaseType,
80178017
irWitnessTable->getConcreteType());
80188018

8019-
// Since IRWitnessTable is Hoistable, `createWitnessTable()` may return an
8020-
// IRWitnessTable that already has decorations/children. We need to avoid
8021-
// adding them more than once.
8019+
// Since IRWitnessTable is Hoistable, `createWitnessTable()` may return
8020+
// an IRWitnessTable that already has decorations/children. We should
8021+
// add them only once.
8022+
//
80228023
if (irSatisfyingWitnessTable->getFirstDecorationOrChild() == nullptr)
80238024
{
80248025
auto mangledName = getMangledNameForConformanceWitness(
@@ -8168,9 +8169,9 @@ struct DeclLoweringVisitor : DeclVisitor<DeclLoweringVisitor, LoweredValInfo>
81688169
inheritanceDecl,
81698170
LoweredValInfo::simple(findOuterMostGeneric(irWitnessTable)));
81708171

8171-
// Since IRWitnessTable is Hoistable, `createWitnessTable()` may return an
8172-
// IRWitnessTable that already has decorations/children. We need to avoid adding them
8173-
// more than once.
8172+
// Since IRWitnessTable is Hoistable, `createWitnessTable()` may return
8173+
// an IRWitnessTable that already has decorations/children. We should
8174+
// add them only once.
81748175
//
81758176
if (irWitnessTable->getFirstDecorationOrChild() == nullptr)
81768177
{

0 commit comments

Comments
 (0)
Please sign in to comment.