@@ -152,6 +152,7 @@ static void _cloneInstDecorationsAndChildren(
152
152
// require the second phase.
153
153
//
154
154
List<IRCloningOldNewPair> pairs;
155
+ ShortList<IRCloningOldNewPair> paramPairs;
155
156
156
157
for ( auto oldChild : oldInst->getDecorationsAndChildren () )
157
158
{
@@ -172,7 +173,19 @@ static void _cloneInstDecorationsAndChildren(
172
173
// on the child, and register it in our map from
173
174
// old to new values.
174
175
//
175
- auto newChild = cloneInstAndOperands (env, builder, oldChild);
176
+ IRInst* newChild = nullptr ;
177
+ if (oldChild->getOp () == kIROp_Param )
178
+ {
179
+ // For parameters, don't clone its type just yet, since
180
+ // the type might be a forward reference to things defined
181
+ // later in the block that we haven't cloned and registered yet.
182
+ newChild = builder->emitParam (nullptr );
183
+ paramPairs.add ({ oldChild, newChild });
184
+ }
185
+ else
186
+ {
187
+ newChild = cloneInstAndOperands (env, builder, oldChild);
188
+ }
176
189
env->mapOldValToNew .add (oldChild, newChild);
177
190
178
191
// If and only if the old child had decorations
@@ -181,10 +194,7 @@ static void _cloneInstDecorationsAndChildren(
181
194
//
182
195
if ( oldChild->getFirstDecorationOrChild () )
183
196
{
184
- IRCloningOldNewPair pair;
185
- pair.oldInst = oldChild;
186
- pair.newInst = newChild;
187
- pairs.add (pair);
197
+ pairs.add ({ oldChild, newChild });
188
198
}
189
199
}
190
200
@@ -200,6 +210,17 @@ static void _cloneInstDecorationsAndChildren(
200
210
201
211
_cloneInstDecorationsAndChildren (env, module, oldChild, newChild);
202
212
}
213
+
214
+ // For params, we can now clone their types since we have done cloning the entire block.
215
+ for (auto pair : paramPairs)
216
+ {
217
+ auto oldParam = pair.oldInst ;
218
+ auto newParam = pair.newInst ;
219
+
220
+ auto oldType = oldParam->getFullType ();
221
+ auto newType = (IRType*)findCloneForOperand (env, oldType);
222
+ newParam->setFullType (newType);
223
+ }
203
224
}
204
225
205
226
// The public version of `cloneInstDecorationsAndChildren` is then
0 commit comments