@@ -448,17 +448,46 @@ bool FlatAffineValueConstraints::areIdsAlignedWithOther(
448
448
return areIdsAligned (*this , other);
449
449
}
450
450
451
- // / Checks if the SSA values associated with `cst`'s identifiers are unique.
452
- static bool LLVM_ATTRIBUTE_UNUSED
453
- areIdsUnique (const FlatAffineValueConstraints &cst) {
451
+ // / Checks if the SSA values associated with `cst`'s identifiers in range
452
+ // / [start, end) are unique.
453
+ static bool LLVM_ATTRIBUTE_UNUSED areIdsUnique (
454
+ const FlatAffineValueConstraints &cst, unsigned start, unsigned end) {
455
+
456
+ assert (start <= cst.getNumIds () && " Start position out of bounds" );
457
+ assert (end <= cst.getNumIds () && " End position out of bounds" );
458
+
459
+ if (start >= end)
460
+ return true ;
461
+
454
462
SmallPtrSet<Value, 8 > uniqueIds;
455
- for (auto val : cst.getMaybeValues ()) {
463
+ ArrayRef<Optional<Value>> maybeValues = cst.getMaybeValues ();
464
+ for (Optional<Value> val : maybeValues) {
456
465
if (val.hasValue () && !uniqueIds.insert (val.getValue ()).second )
457
466
return false ;
458
467
}
459
468
return true ;
460
469
}
461
470
471
+ // / Checks if the SSA values associated with `cst`'s identifiers are unique.
472
+ static bool LLVM_ATTRIBUTE_UNUSED
473
+ areIdsUnique (const FlatAffineConstraints &cst) {
474
+ return areIdsUnique (cst, 0 , cst.getNumIds ());
475
+ }
476
+
477
+ // / Checks if the SSA values associated with `cst`'s identifiers of kind `kind`
478
+ // / are unique.
479
+ static bool LLVM_ATTRIBUTE_UNUSED areIdsUnique (
480
+ const FlatAffineValueConstraints &cst, FlatAffineConstraints::IdKind kind) {
481
+
482
+ if (kind == FlatAffineConstraints::IdKind::Dimension)
483
+ return areIdsUnique (cst, 0 , cst.getNumDimIds ());
484
+ if (kind == FlatAffineConstraints::IdKind::Symbol)
485
+ return areIdsUnique (cst, cst.getNumDimIds (), cst.getNumDimAndSymbolIds ());
486
+ if (kind == FlatAffineConstraints::IdKind::Local)
487
+ return areIdsUnique (cst, cst.getNumDimAndSymbolIds (), cst.getNumIds ());
488
+ llvm_unreachable (" Unexpected IdKind" );
489
+ }
490
+
462
491
// / Merge and align the identifiers of A and B starting at 'offset', so that
463
492
// / both constraint systems get the union of the contained identifiers that is
464
493
// / dimension-wise and symbol-wise unique; both constraint systems are updated
@@ -592,10 +621,15 @@ static void turnSymbolIntoDim(FlatAffineValueConstraints *cst, Value id) {
592
621
}
593
622
594
623
// / Merge and align symbols of `this` and `other` such that both get union of
595
- // / of symbols that are unique. Symbols with Value as `None` are considered
596
- // / to be inequal to all other symbols.
624
+ // / of symbols that are unique. Symbols in `this` and `other` should be
625
+ // / unique. Symbols with Value as `None` are considered to be inequal to all
626
+ // / other symbols.
597
627
void FlatAffineValueConstraints::mergeSymbolIds (
598
628
FlatAffineValueConstraints &other) {
629
+
630
+ assert (areIdsUnique (*this , IdKind::Symbol) && " Symbol ids are not unique" );
631
+ assert (areIdsUnique (other, IdKind::Symbol) && " Symbol ids are not unique" );
632
+
599
633
SmallVector<Value, 4 > aSymValues;
600
634
getValues (getNumDimIds (), getNumDimAndSymbolIds (), &aSymValues);
601
635
@@ -606,7 +640,7 @@ void FlatAffineValueConstraints::mergeSymbolIds(
606
640
// If the id is a symbol in `other`, then align it, otherwise assume that
607
641
// it is a new symbol
608
642
if (other.findId (aSymValue, &loc) && loc >= other.getNumDimIds () &&
609
- loc < getNumDimAndSymbolIds ())
643
+ loc < other. getNumDimAndSymbolIds ())
610
644
other.swapId (s, loc);
611
645
else
612
646
other.insertSymbolId (s - other.getNumDimIds (), aSymValue);
@@ -621,6 +655,8 @@ void FlatAffineValueConstraints::mergeSymbolIds(
621
655
622
656
assert (getNumSymbolIds () == other.getNumSymbolIds () &&
623
657
" expected same number of symbols" );
658
+ assert (areIdsUnique (*this , IdKind::Symbol) && " Symbol ids are not unique" );
659
+ assert (areIdsUnique (other, IdKind::Symbol) && " Symbol ids are not unique" );
624
660
}
625
661
626
662
// Changes all symbol identifiers which are loop IVs to dim identifiers.
0 commit comments