@@ -384,22 +384,31 @@ static GraphOperationInst *simplifyOperands(GraphOperationInst *origInst,
384
384
};
385
385
386
386
// Predicate that returns true if an argument of the specified type should be
387
- // rewritten - either to load an address argument or expand a struct
388
- // parameter.
389
- auto canSimplifyOperand =
390
- [&](SILType type, GraphOperationInfo::ArgumentLowering lowering) -> bool {
387
+ // rewritten to load an address argument or expand a struct parameter.
388
+ auto canSimplifyArgumentType = [&](SILType type) -> bool {
391
389
return isLoadableAddressType (type) ||
392
- getPrimitiveStructField (type.getASTType ()) != nullptr ||
393
- lowering == GraphOperationInfo::ArgumentLowering::Out;
390
+ getPrimitiveStructField (type.getASTType ()) != nullptr ;
391
+ };
392
+
393
+ // Predicate that returns true if an argument should be rewritten.
394
+ auto canSimplifyArgument =
395
+ [&](const GraphOperationInfo::StructuredArgument &argument) -> bool {
396
+ switch (argument.getKind ()) {
397
+ case GraphOperationInfo::SAK_Single:
398
+ return canSimplifyArgumentType (argument.getSingleArgument ()->getType ()) ||
399
+ std::get<1 >(argument.getArgumentNameAndLowering ()) ==
400
+ GraphOperationInfo::ArgumentLowering::Out;
401
+ case GraphOperationInfo::SAK_List:
402
+ // We can get SAK_List arguments from inlining functions that have already
403
+ // been deabstracted. These arguments do not need further simplification.
404
+ return false ;
405
+ }
394
406
};
395
407
396
408
// If we don't have to change any arguments, don't rewrite the graph_op.
397
409
bool mustChangeGraphOp = false ;
398
410
for (auto &argument : opInfo.getStructuredArguments ()) {
399
- assert (argument.getKind () == GraphOperationInfo::SAK_Single &&
400
- " SILGen should not have generated a list argument" );
401
- if (canSimplifyOperand (argument.getSingleArgument ()->getType (),
402
- std::get<1 >(argument.getArgumentNameAndLowering ()))) {
411
+ if (canSimplifyArgument (argument)) {
403
412
mustChangeGraphOp = true ;
404
413
break ;
405
414
}
@@ -413,10 +422,21 @@ static GraphOperationInst *simplifyOperands(GraphOperationInst *origInst,
413
422
// Okay, we do have to simplify something. Scan through and rewrite arguments.
414
423
SILBuilder B (origInst);
415
424
GraphOperationBuilder opBuilder (opInfo.getOperationName ());
425
+ // Pass attributes through.
426
+ for (auto &attr : origInst->getAttributes ())
427
+ opBuilder.addAttribute (attr);
416
428
SILValue outParameterAddress;
417
429
for (auto &argument : opInfo.getStructuredArguments ()) {
430
+ if (argument.getKind () == GraphOperationInfo::SAK_List) {
431
+ // We can get SAK_List arguments from inlining functions that have already
432
+ // been deabstracted. Pass these arguments through.
433
+ opBuilder.addListArgument (argument.getArgumentList (),
434
+ argument.getArgumentNameWithSuffix ());
435
+ continue ;
436
+ }
437
+
418
438
assert (argument.getKind () == GraphOperationInfo::SAK_Single &&
419
- " SILGen should not have generated a list argument" );
439
+ " should have already handled all other argument kinds " );
420
440
auto argumentValue = argument.getSingleArgument ();
421
441
auto argumentLowering = std::get<1 >(argument.getArgumentNameAndLowering ());
422
442
@@ -2126,6 +2146,14 @@ void TFDeabstraction::evaluateAttributesAndDoPacking(
2126
2146
// Find the device attribute specified for the instruction if present.
2127
2147
StringRef opDevice;
2128
2148
2149
+ // Pass attributes through.
2150
+ for (auto &attr : origInst->getAttributes ()) {
2151
+ if (attr.name .str () == DEVICE_ATTR) {
2152
+ opDevice = attr.value .getStringValue ();
2153
+ }
2154
+ opBuilder.addAttribute (attr);
2155
+ }
2156
+
2129
2157
// It is common to have input lists with repeated elements. These will
2130
2158
// generally be uniqued on entry to this routine. We cache the projections in
2131
2159
// these maps so that we can reuse them and avoid code bloat.
@@ -2137,8 +2165,17 @@ void TFDeabstraction::evaluateAttributesAndDoPacking(
2137
2165
2138
2166
for (auto i : range (opInfo.getStructuredArguments ().size ())) {
2139
2167
auto argument = opInfo.getStructuredArguments ()[i];
2168
+
2169
+ if (argument.getKind () == GraphOperationInfo::SAK_List) {
2170
+ // We can get SAK_List arguments from inlining functions that have already
2171
+ // been deabstracted. Pass these arguments through.
2172
+ opBuilder.addListArgument (argument.getArgumentList (),
2173
+ argument.getArgumentNameWithSuffix ());
2174
+ continue ;
2175
+ }
2176
+
2140
2177
assert (argument.getKind () == GraphOperationInfo::SAK_Single &&
2141
- " SILGen should not have generated a list argument" );
2178
+ " should have already handled all other argument kinds " );
2142
2179
auto argumentValue = argument.getSingleArgument ();
2143
2180
auto argumentTy = argumentValue->getType ();
2144
2181
auto argumentNameAndLowering = argument.getArgumentNameAndLowering ();
0 commit comments