@@ -86,21 +86,37 @@ class PartitionOp {
86
86
}
87
87
88
88
void dump () const LLVM_ATTRIBUTE_USED {
89
+ raw_ostream &os = llvm::errs ();
89
90
switch (OpKind) {
90
91
case PartitionOpKind::Assign:
91
- llvm::dbgs () << " assign %" << OpArgs[0 ] << " = %" << OpArgs[1 ] << " \n " ;
92
+ os.changeColor (llvm::raw_ostream::CYAN, true );
93
+ os << " assign" ;
94
+ os.resetColor ();
95
+ os << " %%" << OpArgs[0 ] << " = %%" << OpArgs[1 ] << " \n " ;
92
96
break ;
93
97
case PartitionOpKind::AssignFresh:
94
- llvm::dbgs () << " assign_fresh %" << OpArgs[0 ] << " \n " ;
98
+ os.changeColor (llvm::raw_ostream::GREEN, true );
99
+ os << " assign_fresh" ;
100
+ os.resetColor ();
101
+ os << " %%" << OpArgs[0 ] << " \n " ;
95
102
break ;
96
103
case PartitionOpKind::Consume:
97
- llvm::dbgs () << " consume %" << OpArgs[0 ] << " \n " ;
104
+ os.changeColor (llvm::raw_ostream::RED, true );
105
+ os << " consume" ;
106
+ os.resetColor ();
107
+ os << " %%" << OpArgs[0 ] << " \n " ;
98
108
break ;
99
109
case PartitionOpKind::Merge:
100
- llvm::dbgs () << " merge %" << OpArgs[0 ] << " with %" << OpArgs[1 ] << " \n " ;
110
+ os.changeColor (llvm::raw_ostream::BLUE, true );
111
+ os << " merge" ;
112
+ os.resetColor ();
113
+ os << " %%" << OpArgs[0 ] << " with %%" << OpArgs[1 ] << " \n " ;
101
114
break ;
102
115
case PartitionOpKind::Require:
103
- llvm::dbgs () << " require %" << OpArgs[0 ] << " \n " ;
116
+ os.changeColor (llvm::raw_ostream::YELLOW, true );
117
+ os << " require" ;
118
+ os.resetColor ();
119
+ os << " %%" << OpArgs[0 ] << " \n " ;
104
120
break ;
105
121
}
106
122
}
@@ -160,10 +176,10 @@ class Partition {
160
176
if (label < 0 ) continue ;
161
177
162
178
// this label should not exceed fresh_label
163
- if (label >= fresh_label) return fail (i, 0 );
179
+ if (( unsigned ) label >= fresh_label) return fail (i, 0 );
164
180
165
181
// the label of a region should be at most as large as each index in it
166
- if (i < label) return fail (i, 1 );
182
+ if (( unsigned ) label > i ) return fail (i, 1 );
167
183
168
184
// each region label should refer to an index in that region
169
185
if (labels[label] != label) return fail (i, 2 );
@@ -299,10 +315,21 @@ class Partition {
299
315
PartitionOp op,
300
316
llvm::function_ref<void (const PartitionOp&, unsigned )>
301
317
handleFailure = [](const PartitionOp&, unsigned ) {},
302
- std::vector<unsigned > nonconsumables = {},
318
+
319
+ std::vector<unsigned >
320
+ nonconsumables = {},
321
+
303
322
llvm::function_ref<void (const PartitionOp&, unsigned )>
304
- handleConsumeNonConsumable = [](const PartitionOp&, unsigned ) {}
323
+ handleConsumeNonConsumable = [](const PartitionOp&, unsigned ) {},
324
+
325
+ bool reviveAfterFailure = false
305
326
) {
327
+ auto handleFailureAndRevive =
328
+ [&](const PartitionOp& partitionOp, unsigned consumedVal) {
329
+ if (reviveAfterFailure)
330
+ horizontalUpdate (labels, consumedVal, fresh_label++);
331
+ handleFailure (partitionOp, consumedVal);
332
+ };
306
333
switch (op.OpKind ) {
307
334
case PartitionOpKind::Assign:
308
335
assert (op.OpArgs .size () == 2 &&
@@ -311,7 +338,7 @@ class Partition {
311
338
" Assign PartitionOp's source argument should be already tracked" );
312
339
// if assigning to a missing region, handle the failure
313
340
if (labels[op.OpArgs [1 ]] < 0 )
314
- handleFailure (op, op.OpArgs [1 ]);
341
+ handleFailureAndRevive (op, op.OpArgs [1 ]);
315
342
316
343
labels[op.OpArgs [0 ]] = labels[op.OpArgs [1 ]];
317
344
@@ -322,8 +349,6 @@ class Partition {
322
349
case PartitionOpKind::AssignFresh:
323
350
assert (op.OpArgs .size () == 1 &&
324
351
" AssignFresh PartitionOp should be passed 1 argument" );
325
- assert (!labels.count (op.OpArgs [0 ]) &&
326
- " AssignFresh PartitionOp's argument should NOT already be tracked" );
327
352
328
353
// map index op.OpArgs[0] to a fresh label
329
354
labels[op.OpArgs [0 ]] = fresh_label++;
@@ -337,7 +362,7 @@ class Partition {
337
362
338
363
// if attempting to consume a consumed region, handle the failure
339
364
if (labels[op.OpArgs [0 ]] < 0 )
340
- handleFailure (op, op.OpArgs [0 ]);
365
+ handleFailureAndRevive (op, op.OpArgs [0 ]);
341
366
342
367
// mark region as consumed
343
368
horizontalUpdate (labels, op.OpArgs [0 ], -1 );
@@ -360,11 +385,12 @@ class Partition {
360
385
" Merge PartitionOp should be passed 2 arguments" );
361
386
assert (labels.count (op.OpArgs [0 ]) && labels.count (op.OpArgs [1 ]) &&
362
387
" Merge PartitionOp's arguments should already be tracked" );
388
+
363
389
// if attempting to merge a consumed region, handle the failure
364
390
if (labels[op.OpArgs [0 ]] < 0 )
365
- handleFailure (op, op.OpArgs [0 ]);
391
+ handleFailureAndRevive (op, op.OpArgs [0 ]);
366
392
if (labels[op.OpArgs [1 ]] < 0 )
367
- handleFailure (op, op.OpArgs [1 ]);
393
+ handleFailureAndRevive (op, op.OpArgs [1 ]);
368
394
369
395
merge (op.OpArgs [0 ], op.OpArgs [1 ]);
370
396
break ;
@@ -374,7 +400,7 @@ class Partition {
374
400
assert (labels.count (op.OpArgs [0 ]) &&
375
401
" Require PartitionOp's argument should already be tracked" );
376
402
if (labels[op.OpArgs [0 ]] < 0 )
377
- handleFailure (op, op.OpArgs [0 ]);
403
+ handleFailureAndRevive (op, op.OpArgs [0 ]);
378
404
}
379
405
380
406
assert (is_canonical_correct ());
@@ -406,9 +432,7 @@ class Partition {
406
432
}
407
433
llvm::dbgs () << (label < 0 ? " }" : " )" );
408
434
}
409
- llvm::dbgs () << " ] | " ;
410
-
411
- dump_labels ();
435
+ llvm::dbgs () << " ]" ;
412
436
}
413
437
};
414
438
}
0 commit comments