@@ -1102,6 +1102,47 @@ struct SpecializationContext
1102
1102
return false ;
1103
1103
}
1104
1104
1105
+ // Test if a type is compile time constant.
1106
+ static bool isCompileTimeConstantType (IRInst* inst)
1107
+ {
1108
+ // TODO: We probably need/want a more robust test here.
1109
+ // For now we are just look into the dependency graph of the inst and
1110
+ // see if there are any opcodes that are causing problems.
1111
+ List<IRInst*> localWorkList;
1112
+ HashSet<IRInst*> processedInsts;
1113
+ localWorkList.add (inst);
1114
+ processedInsts.Add (inst);
1115
+
1116
+ while (localWorkList.getCount () != 0 )
1117
+ {
1118
+ IRInst* curInst = localWorkList.getLast ();
1119
+
1120
+ localWorkList.removeLast ();
1121
+ processedInsts.Remove (curInst);
1122
+
1123
+ switch (curInst->getOp ())
1124
+ {
1125
+ case kIROp_Load :
1126
+ case kIROp_Call :
1127
+ case kIROp_ExtractExistentialType :
1128
+ case kIROp_CreateExistentialObject :
1129
+ return false ;
1130
+ default :
1131
+ break ;
1132
+ }
1133
+
1134
+ for (UInt i = 0 ; i < curInst->getOperandCount (); ++i)
1135
+ {
1136
+ auto operand = curInst->getOperand (i);
1137
+ if (processedInsts.Add (operand))
1138
+ {
1139
+ localWorkList.add (operand);
1140
+ }
1141
+ }
1142
+ }
1143
+ return true ;
1144
+ }
1145
+
1105
1146
// Similarly, we want to be able to test whether an instruction
1106
1147
// used as an argument for an existential-type parameter is
1107
1148
// suitable for use in specialization.
@@ -1127,18 +1168,7 @@ struct SpecializationContext
1127
1168
auto concreteVal = makeExistential->getWrappedValue ();
1128
1169
auto concreteType = concreteVal->getDataType ();
1129
1170
1130
- // TODO: We probably need/want a more robust test here.
1131
- // For now we are just listing the single opcode that is
1132
- // causing problems.
1133
- //
1134
- // TODO: eventually this check would become unnecessary because
1135
- // we can simply check if the `concreteType` is a compile-time
1136
- // constant value.
1137
- //
1138
- if (concreteType->getOp () == kIROp_ExtractExistentialType )
1139
- return false ;
1140
-
1141
- return true ;
1171
+ return isCompileTimeConstantType (concreteType);
1142
1172
}
1143
1173
1144
1174
// A `wrapExistential(v, T0,w0, T1, w1, ...)` instruction
0 commit comments