@@ -49,9 +49,9 @@ struct Region {
49
49
50
50
operator signed () const { return num; }
51
51
52
- bool isConsumed () const { return num < 0 ; }
52
+ bool isTransferred () const { return num < 0 ; }
53
53
54
- static Region consumed () { return Region (-1 ); }
54
+ static Region transferred () { return Region (-1 ); }
55
55
};
56
56
}
57
57
@@ -61,20 +61,20 @@ using namespace PartitionPrimitives;
61
61
// / SILInstructions can be translated to
62
62
enum class PartitionOpKind : uint8_t {
63
63
// / Assign one value to the region of another, takes two args, second arg
64
- // / must already be tracked with a non-consumed region
64
+ // / must already be tracked with a non-transferred region
65
65
Assign,
66
66
67
67
// / Assign one value to a fresh region, takes one arg.
68
68
AssignFresh,
69
69
70
70
// / Merge the regions of two values, takes two args, both must be from
71
- // / non-consumed regions.
71
+ // / non-transferred regions.
72
72
Merge,
73
73
74
- // / Consume the region of a value if not already consumed , takes one arg.
74
+ // / Consume the region of a value if not already transferred , takes one arg.
75
75
Transfer,
76
76
77
- // / Require the region of a value to be non-consumed , takes one arg.
77
+ // / Require the region of a value to be non-transferred , takes one arg.
78
78
Require,
79
79
};
80
80
@@ -92,7 +92,8 @@ class PartitionOp {
92
92
SILInstruction *sourceInst;
93
93
94
94
// Record an AST expression corresponding to this PartitionOp, currently
95
- // populated only for Consume expressions to indicate the value being consumed
95
+ // populated only for Consume expressions to indicate the value being
96
+ // transferred
96
97
Expr *sourceExpr;
97
98
98
99
// TODO: can the following declarations be merged?
@@ -176,7 +177,7 @@ class PartitionOp {
176
177
os << " assign_fresh %%" << OpArgs[0 ] << " \n " ;
177
178
break ;
178
179
case PartitionOpKind::Transfer:
179
- os << " consume %%" << OpArgs[0 ] << " \n " ;
180
+ os << " transfer %%" << OpArgs[0 ] << " \n " ;
180
181
break ;
181
182
case PartitionOpKind::Merge:
182
183
os << " merge %%" << OpArgs[0 ] << " with %%" << OpArgs[1 ] << " \n " ;
@@ -213,8 +214,8 @@ static void horizontalUpdate(std::map<Element, Region> &map, Element key,
213
214
class Partition {
214
215
private:
215
216
// Label each index with a non-negative (unsigned) label if it is associated
216
- // with a valid region, and with -1 if it is associated with a consumed region
217
- // in-order traversal relied upon.
217
+ // with a valid region, and with -1 if it is associated with a transferred
218
+ // region in-order traversal relied upon.
218
219
std::map<Element, Region> labels;
219
220
220
221
// Track a label that is guaranteed to be strictly larger than all in use,
@@ -240,8 +241,8 @@ class Partition {
240
241
};
241
242
242
243
for (auto &[i, label] : labels) {
243
- // correctness vacuous at consumed indices
244
- if (label.isConsumed ())
244
+ // correctness vacuous at transferred indices
245
+ if (label.isTransferred ())
245
246
continue ;
246
247
247
248
// this label should not exceed fresh_label
@@ -266,7 +267,7 @@ class Partition {
266
267
267
268
// linear time - For each region label that occurs, find the first index
268
269
// at which it occurs and relabel all instances of it to that index.
269
- // This excludes the -1 label for consumed regions.
270
+ // This excludes the -1 label for transferred regions.
270
271
void canonicalize () {
271
272
if (canonical)
272
273
return ;
@@ -276,8 +277,8 @@ class Partition {
276
277
277
278
// relies on in-order traversal of labels
278
279
for (auto &[i, label] : labels) {
279
- // leave -1 (consumed region) as is
280
- if (label.isConsumed ())
280
+ // leave -1 (transferred region) as is
281
+ if (label.isTransferred ())
281
282
continue ;
282
283
283
284
if (!relabel.count (label)) {
@@ -348,8 +349,8 @@ class Partition {
348
349
349
350
bool isTracked (Element val) const { return labels.count (val); }
350
351
351
- bool isConsumed (Element val) const {
352
- return isTracked (val) && labels.at (val).isConsumed ();
352
+ bool isTransferred (Element val) const {
353
+ return isTracked (val) && labels.at (val).isTransferred ();
353
354
}
354
355
355
356
// quadratic time - Construct the partition corresponding to the join of the
@@ -374,9 +375,10 @@ class Partition {
374
375
// of indices that are in the same region in snd are also in the same region
375
376
// in fst - the desired property
376
377
for (const auto [i, snd_label] : snd_reduced.labels ) {
377
- if (snd_label.isConsumed ())
378
- // if snd says that the region has been consumed, mark it consumed in fst
379
- horizontalUpdate (fst_reduced.labels , i, Region::consumed ());
378
+ if (snd_label.isTransferred ())
379
+ // if snd says that the region has been transferred, mark it transferred
380
+ // in fst
381
+ horizontalUpdate (fst_reduced.labels , i, Region::transferred ());
380
382
else
381
383
fst_reduced.merge (i, Element (snd_label));
382
384
}
@@ -394,12 +396,12 @@ class Partition {
394
396
395
397
// Apply the passed PartitionOp to this partition, performing its action.
396
398
// A `handleFailure` closure can optionally be passed in that will be called
397
- // if a consumed region is required. The closure is given the PartitionOp that
398
- // failed, and the index of the SIL value that was required but consumed.
399
- // Additionally, a list of "nonconsumable" indices can be passed in along with
400
- // a handleConsumeNonConsumable closure. In the event that a region containing
401
- // one of the nonconsumable indices is consumed , the closure will be called
402
- // with the offending Consume.
399
+ // if a transferred region is required. The closure is given the PartitionOp
400
+ // that failed, and the index of the SIL value that was required but
401
+ // transferred. Additionally, a list of "nonconsumable" indices can be passed
402
+ // in along with a handleConsumeNonConsumable closure. In the event that a
403
+ // region containing one of the nonconsumable indices is transferred , the
404
+ // closure will be called with the offending Consume.
403
405
void apply (
404
406
PartitionOp op,
405
407
llvm::function_ref<void (const PartitionOp &, Element)> handleFailure =
@@ -422,7 +424,7 @@ class Partition {
422
424
assert (labels.count (op.OpArgs [1 ]) &&
423
425
" Assign PartitionOp's source argument should be already tracked" );
424
426
// if assigning to a missing region, handle the failure
425
- if (isConsumed (op.OpArgs [1 ]))
427
+ if (isTransferred (op.OpArgs [1 ]))
426
428
handleFailure (op, op.OpArgs [1 ]);
427
429
428
430
labels.insert_or_assign (op.OpArgs [0 ], labels.at (op.OpArgs [1 ]));
@@ -448,25 +450,24 @@ class Partition {
448
450
assert (labels.count (op.OpArgs [0 ]) &&
449
451
" Consume PartitionOp's argument should already be tracked" );
450
452
451
- // check if any nonconsumables are consumed here, and handle the failure if so
453
+ // check if any nonconsumables are transferred here, and handle the
454
+ // failure if so
452
455
for (Element nonconsumable : nonconsumables) {
453
456
assert (labels.count (nonconsumable) &&
454
457
" nonconsumables should be function args and self, and therefore"
455
458
" always present in the label map because of initialization at "
456
459
" entry" );
457
- if (!isConsumed (nonconsumable) &&
460
+ if (!isTransferred (nonconsumable) &&
458
461
labels.at (nonconsumable) == labels.at (op.OpArgs [0 ])) {
459
462
handleConsumeNonConsumable (op, nonconsumable);
460
463
break ;
461
464
}
462
465
}
463
466
464
- // ensure region is consumed
465
- if (!isConsumed (op.OpArgs [0 ]))
466
- // mark region as consumed
467
- horizontalUpdate (labels, op.OpArgs [0 ], Region::consumed ());
468
-
469
-
467
+ // ensure region is transferred
468
+ if (!isTransferred (op.OpArgs [0 ]))
469
+ // mark region as transferred
470
+ horizontalUpdate (labels, op.OpArgs [0 ], Region::transferred ());
470
471
471
472
break ;
472
473
case PartitionOpKind::Merge:
@@ -475,10 +476,10 @@ class Partition {
475
476
assert (labels.count (op.OpArgs [0 ]) && labels.count (op.OpArgs [1 ]) &&
476
477
" Merge PartitionOp's arguments should already be tracked" );
477
478
478
- // if attempting to merge a consumed region, handle the failure
479
- if (isConsumed (op.OpArgs [0 ]))
479
+ // if attempting to merge a transferred region, handle the failure
480
+ if (isTransferred (op.OpArgs [0 ]))
480
481
handleFailure (op, op.OpArgs [0 ]);
481
- if (isConsumed (op.OpArgs [1 ]))
482
+ if (isTransferred (op.OpArgs [1 ]))
482
483
handleFailure (op, op.OpArgs [1 ]);
483
484
484
485
merge (op.OpArgs [0 ], op.OpArgs [1 ]);
@@ -488,26 +489,26 @@ class Partition {
488
489
" Require PartitionOp should be passed 1 argument" );
489
490
assert (labels.count (op.OpArgs [0 ]) &&
490
491
" Require PartitionOp's argument should already be tracked" );
491
- if (isConsumed (op.OpArgs [0 ]))
492
+ if (isTransferred (op.OpArgs [0 ]))
492
493
handleFailure (op, op.OpArgs [0 ]);
493
494
}
494
495
495
496
assert (is_canonical_correct ());
496
497
}
497
498
498
- // return a vector of the consumed values in this partition
499
- std::vector<Element> getConsumedVals () const {
499
+ // return a vector of the transferred values in this partition
500
+ std::vector<Element> getTransferredVals () const {
500
501
// for effeciency, this could return an iterator not a vector
501
- std::vector<Element> consumedVals ;
502
+ std::vector<Element> transferredVals ;
502
503
for (auto [i, _] : labels)
503
- if (isConsumed (i))
504
- consumedVals .push_back (i);
505
- return consumedVals ;
504
+ if (isTransferred (i))
505
+ transferredVals .push_back (i);
506
+ return transferredVals ;
506
507
}
507
508
508
- // return a vector of the non-consumed regions in this partition, each
509
+ // return a vector of the non-transferred regions in this partition, each
509
510
// represented as a vector of values
510
- std::vector<std::vector<Element>> getNonConsumedRegions () const {
511
+ std::vector<std::vector<Element>> getNonTransferredRegions () const {
511
512
// for effeciency, this could return an iterator not a vector
512
513
std::map<Region, std::vector<Element>> buckets;
513
514
@@ -542,12 +543,12 @@ class Partition {
542
543
543
544
os << " [" ;
544
545
for (auto [label, indices] : buckets) {
545
- os << (label.isConsumed () ? " {" : " (" );
546
+ os << (label.isTransferred () ? " {" : " (" );
546
547
int j = 0 ;
547
548
for (Element i : indices) {
548
549
os << (j++ ? " " : " " ) << i;
549
550
}
550
- os << (label.isConsumed () ? " }" : " )" );
551
+ os << (label.isTransferred () ? " }" : " )" );
551
552
}
552
553
os << " ]\n " ;
553
554
}
0 commit comments