@@ -817,13 +817,12 @@ FlatLinearValueConstraints::FlatLinearValueConstraints(IntegerSet set,
817
817
set.getNumDims() + set.getNumSymbols() + 1,
818
818
set.getNumDims(), set.getNumSymbols(),
819
819
/* numLocals=*/ 0) {
820
- // Populate values.
821
- if (operands.empty ()) {
822
- values.resize (getNumDimAndSymbolVars (), std::nullopt);
823
- } else {
824
- assert (set.getNumInputs () == operands.size () && " operand count mismatch" );
825
- values.assign (operands.begin (), operands.end ());
826
- }
820
+ // Use values in space for FlatLinearValueConstraints.
821
+ space.resetIds ();
822
+ // Set the values for the non-local variables.
823
+ for (unsigned i = 0 , e = operands.size (); i < e; ++i)
824
+ setValue (i, operands[i]);
825
+
827
826
828
827
// Flatten expressions and add them to the constraint system.
829
828
std::vector<SmallVector<int64_t , 8 >> flatExprs;
@@ -873,11 +872,6 @@ unsigned FlatLinearValueConstraints::insertVar(VarKind kind, unsigned pos,
873
872
unsigned num) {
874
873
unsigned absolutePos = IntegerPolyhedron::insertVar (kind, pos, num);
875
874
876
- if (kind != VarKind::Local) {
877
- values.insert (values.begin () + absolutePos, num, std::nullopt);
878
- assert (values.size () == getNumDimAndSymbolVars ());
879
- }
880
-
881
875
return absolutePos;
882
876
}
883
877
@@ -890,22 +884,23 @@ unsigned FlatLinearValueConstraints::insertVar(VarKind kind, unsigned pos,
890
884
unsigned absolutePos = IntegerPolyhedron::insertVar (kind, pos, num);
891
885
892
886
// If a Value is provided, insert it; otherwise use std::nullopt.
893
- for (unsigned i = 0 ; i < num; ++i)
894
- values.insert (values.begin () + absolutePos + i,
895
- vals[i] ? std::optional<Value>(vals[i]) : std::nullopt);
887
+ for (unsigned i = 0 , e = vals.size (); i < e; ++i)
888
+ setValue (absolutePos + i, vals[i]);
896
889
897
- assert (values.size () == getNumDimAndSymbolVars ());
898
890
return absolutePos;
899
891
}
900
892
901
893
// / Checks if two constraint systems are in the same space, i.e., if they are
902
894
// / associated with the same set of variables, appearing in the same order.
903
895
static bool areVarsAligned (const FlatLinearValueConstraints &a,
904
896
const FlatLinearValueConstraints &b) {
905
- return a.getNumDimVars () == b.getNumDimVars () &&
906
- a.getNumSymbolVars () == b.getNumSymbolVars () &&
907
- a.getNumVars () == b.getNumVars () &&
908
- a.getMaybeValues ().equals (b.getMaybeValues ());
897
+ if (a.getNumDomainVars () != b.getNumDomainVars () ||
898
+ a.getNumRangeVars () != b.getNumRangeVars () ||
899
+ a.getNumSymbolVars () != b.getNumSymbolVars ())
900
+ return false ;
901
+ SmallVector<std::optional<Value>> aMaybeValues = a.getMaybeValues (), bMaybeValues = b.getMaybeValues ();
902
+ return std::equal (aMaybeValues.begin (), aMaybeValues.end (),
903
+ bMaybeValues.begin (), bMaybeValues.end ());
909
904
}
910
905
911
906
// / Calls areVarsAligned to check if two constraint systems have the same set
@@ -928,12 +923,14 @@ static bool LLVM_ATTRIBUTE_UNUSED areVarsUnique(
928
923
return true ;
929
924
930
925
SmallPtrSet<Value, 8 > uniqueVars;
931
- ArrayRef<std::optional<Value>> maybeValues =
932
- cst.getMaybeValues ().slice (start, end - start);
933
- for (std::optional<Value> val : maybeValues) {
926
+ SmallVector<std::optional<Value>, 8 > maybeValuesAll = cst.getMaybeValues ();
927
+ ArrayRef<std::optional<Value>> maybeValues = {maybeValuesAll.data () + start,
928
+ maybeValuesAll.data () + end};
929
+
930
+ for (std::optional<Value> val : maybeValues)
934
931
if (val && !uniqueVars.insert (*val).second )
935
932
return false ;
936
- }
933
+
937
934
return true ;
938
935
}
939
936
@@ -1058,20 +1055,9 @@ void FlatLinearValueConstraints::mergeSymbolVars(
1058
1055
" expected same number of symbols" );
1059
1056
}
1060
1057
1061
- bool FlatLinearValueConstraints::hasConsistentState () const {
1062
- return IntegerPolyhedron::hasConsistentState () &&
1063
- values.size () == getNumDimAndSymbolVars ();
1064
- }
1065
-
1066
1058
void FlatLinearValueConstraints::removeVarRange (VarKind kind, unsigned varStart,
1067
1059
unsigned varLimit) {
1068
1060
IntegerPolyhedron::removeVarRange (kind, varStart, varLimit);
1069
- unsigned offset = getVarKindOffset (kind);
1070
-
1071
- if (kind != VarKind::Local) {
1072
- values.erase (values.begin () + varStart + offset,
1073
- values.begin () + varLimit + offset);
1074
- }
1075
1061
}
1076
1062
1077
1063
AffineMap
@@ -1089,14 +1075,15 @@ FlatLinearValueConstraints::computeAlignedMap(AffineMap map,
1089
1075
1090
1076
dims.reserve (getNumDimVars ());
1091
1077
syms.reserve (getNumSymbolVars ());
1092
- for (unsigned i = getVarKindOffset (VarKind::SetDim),
1093
- e = getVarKindEnd (VarKind::SetDim);
1094
- i < e; ++i)
1095
- dims.push_back (values[i] ? *values[i] : Value ());
1096
- for (unsigned i = getVarKindOffset (VarKind::Symbol),
1097
- e = getVarKindEnd (VarKind::Symbol);
1098
- i < e; ++i)
1099
- syms.push_back (values[i] ? *values[i] : Value ());
1078
+ for (unsigned i = 0 , e = getNumVarKind (VarKind::SetDim); i < e; ++i) {
1079
+ Identifier id = space.getId (VarKind::SetDim, i);
1080
+ dims.push_back (id.hasValue () ? Value (id.getValue <Value>()) : Value ());
1081
+ }
1082
+ for (unsigned i = 0 , e = getNumVarKind (VarKind::Symbol); i < e; ++i) {
1083
+ Identifier id = space.getId (VarKind::Symbol, i);
1084
+ syms.push_back (id.hasValue () ? Value (id.getValue <Value>()) : Value ());
1085
+ }
1086
+
1100
1087
1101
1088
AffineMap alignedMap =
1102
1089
alignAffineMapWithValues (map, operands, dims, syms, newSymsPtr);
@@ -1110,8 +1097,7 @@ FlatLinearValueConstraints::computeAlignedMap(AffineMap map,
1110
1097
bool FlatLinearValueConstraints::findVar (Value val, unsigned *pos,
1111
1098
unsigned offset) const {
1112
1099
unsigned i = offset;
1113
- for (const auto &mayBeVar :
1114
- ArrayRef<std::optional<Value>>(values).drop_front (offset)) {
1100
+ for (const auto &mayBeVar : getMaybeValues ()) {
1115
1101
if (mayBeVar && *mayBeVar == val) {
1116
1102
*pos = i;
1117
1103
return true ;
@@ -1122,25 +1108,12 @@ bool FlatLinearValueConstraints::findVar(Value val, unsigned *pos,
1122
1108
}
1123
1109
1124
1110
bool FlatLinearValueConstraints::containsVar (Value val) const {
1125
- return llvm::any_of (values, [&](const std::optional<Value> &mayBeVar) {
1126
- return mayBeVar && *mayBeVar == val;
1127
- });
1111
+ unsigned pos;
1112
+ return findVar (val, &pos, 0 );
1128
1113
}
1129
1114
1130
1115
void FlatLinearValueConstraints::swapVar (unsigned posA, unsigned posB) {
1131
1116
IntegerPolyhedron::swapVar (posA, posB);
1132
-
1133
- if (getVarKindAt (posA) == VarKind::Local &&
1134
- getVarKindAt (posB) == VarKind::Local)
1135
- return ;
1136
-
1137
- // Treat value of a local variable as std::nullopt.
1138
- if (getVarKindAt (posA) == VarKind::Local)
1139
- values[posB] = std::nullopt;
1140
- else if (getVarKindAt (posB) == VarKind::Local)
1141
- values[posA] = std::nullopt;
1142
- else
1143
- std::swap (values[posA], values[posB]);
1144
1117
}
1145
1118
1146
1119
void FlatLinearValueConstraints::addBound (BoundType type, Value val,
@@ -1182,27 +1155,13 @@ void FlatLinearValueConstraints::printSpace(raw_ostream &os) const {
1182
1155
1183
1156
void FlatLinearValueConstraints::clearAndCopyFrom (
1184
1157
const IntegerRelation &other) {
1185
-
1186
- if (auto *otherValueSet =
1187
- dyn_cast<const FlatLinearValueConstraints>(&other)) {
1188
- *this = *otherValueSet;
1189
- } else {
1190
- *static_cast <IntegerRelation *>(this ) = other;
1191
- values.clear ();
1192
- values.resize (getNumDimAndSymbolVars (), std::nullopt);
1193
- }
1158
+ IntegerPolyhedron::clearAndCopyFrom (other);
1194
1159
}
1195
1160
1196
1161
void FlatLinearValueConstraints::fourierMotzkinEliminate (
1197
1162
unsigned pos, bool darkShadow, bool *isResultIntegerExact) {
1198
- SmallVector<std::optional<Value>, 8 > newVals = values;
1199
- if (getVarKindAt (pos) != VarKind::Local)
1200
- newVals.erase (newVals.begin () + pos);
1201
- // Note: Base implementation discards all associated Values.
1202
1163
IntegerPolyhedron::fourierMotzkinEliminate (pos, darkShadow,
1203
1164
isResultIntegerExact);
1204
- values = newVals;
1205
- assert (values.size () == getNumDimAndSymbolVars ());
1206
1165
}
1207
1166
1208
1167
void FlatLinearValueConstraints::projectOut (Value val) {
@@ -1216,10 +1175,10 @@ void FlatLinearValueConstraints::projectOut(Value val) {
1216
1175
LogicalResult FlatLinearValueConstraints::unionBoundingBox (
1217
1176
const FlatLinearValueConstraints &otherCst) {
1218
1177
assert (otherCst.getNumDimVars () == getNumDimVars () && " dims mismatch" );
1219
- assert ( otherCst.getMaybeValues ()
1220
- . slice ( 0 , getNumDimVars ())
1221
- . equals ( getMaybeValues (). slice ( 0 , getNumDimVars () )) &&
1222
- " dim values mismatch" );
1178
+ SmallVector<std::optional<Value>> maybeValues = getMaybeValues (), otherMaybeValues = otherCst.getMaybeValues ();
1179
+ assert ( std::equal (maybeValues. begin (), maybeValues. begin () + getNumDimVars (),
1180
+ otherMaybeValues. begin (), otherMaybeValues. begin () + getNumDimVars ()) &&
1181
+ " dim values mismatch" );
1223
1182
assert (otherCst.getNumLocalVars () == 0 && " local vars not supported here" );
1224
1183
assert (getNumLocalVars () == 0 && " local vars not supported yet here" );
1225
1184
0 commit comments