@@ -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,17 @@ 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
+ return a.getSpace ().isAligned (b.getSpace ());
909
898
}
910
899
911
900
// / Calls areVarsAligned to check if two constraint systems have the same set
@@ -928,12 +917,14 @@ static bool LLVM_ATTRIBUTE_UNUSED areVarsUnique(
928
917
return true ;
929
918
930
919
SmallPtrSet<Value, 8 > uniqueVars;
931
- ArrayRef<std::optional<Value>> maybeValues =
932
- cst.getMaybeValues ().slice (start, end - start);
933
- for (std::optional<Value> val : maybeValues) {
920
+ SmallVector<std::optional<Value>, 8 > maybeValuesAll = cst.getMaybeValues ();
921
+ ArrayRef<std::optional<Value>> maybeValues = {maybeValuesAll.data () + start,
922
+ maybeValuesAll.data () + end};
923
+
924
+ for (std::optional<Value> val : maybeValues)
934
925
if (val && !uniqueVars.insert (*val).second )
935
926
return false ;
936
- }
927
+
937
928
return true ;
938
929
}
939
930
@@ -1058,20 +1049,9 @@ void FlatLinearValueConstraints::mergeSymbolVars(
1058
1049
" expected same number of symbols" );
1059
1050
}
1060
1051
1061
- bool FlatLinearValueConstraints::hasConsistentState () const {
1062
- return IntegerPolyhedron::hasConsistentState () &&
1063
- values.size () == getNumDimAndSymbolVars ();
1064
- }
1065
-
1066
1052
void FlatLinearValueConstraints::removeVarRange (VarKind kind, unsigned varStart,
1067
1053
unsigned varLimit) {
1068
1054
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
1055
}
1076
1056
1077
1057
AffineMap
@@ -1089,14 +1069,15 @@ FlatLinearValueConstraints::computeAlignedMap(AffineMap map,
1089
1069
1090
1070
dims.reserve (getNumDimVars ());
1091
1071
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 ());
1072
+ for (unsigned i = 0 , e = getNumVarKind (VarKind::SetDim); i < e; ++i) {
1073
+ Identifier id = space.getId (VarKind::SetDim, i);
1074
+ dims.push_back (id.hasValue () ? Value (id.getValue <Value>()) : Value ());
1075
+ }
1076
+ for (unsigned i = 0 , e = getNumVarKind (VarKind::Symbol); i < e; ++i) {
1077
+ Identifier id = space.getId (VarKind::Symbol, i);
1078
+ syms.push_back (id.hasValue () ? Value (id.getValue <Value>()) : Value ());
1079
+ }
1080
+
1100
1081
1101
1082
AffineMap alignedMap =
1102
1083
alignAffineMapWithValues (map, operands, dims, syms, newSymsPtr);
@@ -1110,8 +1091,7 @@ FlatLinearValueConstraints::computeAlignedMap(AffineMap map,
1110
1091
bool FlatLinearValueConstraints::findVar (Value val, unsigned *pos,
1111
1092
unsigned offset) const {
1112
1093
unsigned i = offset;
1113
- for (const auto &mayBeVar :
1114
- ArrayRef<std::optional<Value>>(values).drop_front (offset)) {
1094
+ for (const auto &mayBeVar : getMaybeValues ()) {
1115
1095
if (mayBeVar && *mayBeVar == val) {
1116
1096
*pos = i;
1117
1097
return true ;
@@ -1122,25 +1102,12 @@ bool FlatLinearValueConstraints::findVar(Value val, unsigned *pos,
1122
1102
}
1123
1103
1124
1104
bool FlatLinearValueConstraints::containsVar (Value val) const {
1125
- return llvm::any_of (values, [&](const std::optional<Value> &mayBeVar) {
1126
- return mayBeVar && *mayBeVar == val;
1127
- });
1105
+ unsigned pos;
1106
+ return findVar (val, &pos, 0 );
1128
1107
}
1129
1108
1130
1109
void FlatLinearValueConstraints::swapVar (unsigned posA, unsigned posB) {
1131
1110
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
1111
}
1145
1112
1146
1113
void FlatLinearValueConstraints::addBound (BoundType type, Value val,
@@ -1182,27 +1149,13 @@ void FlatLinearValueConstraints::printSpace(raw_ostream &os) const {
1182
1149
1183
1150
void FlatLinearValueConstraints::clearAndCopyFrom (
1184
1151
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
- }
1152
+ IntegerPolyhedron::clearAndCopyFrom (other);
1194
1153
}
1195
1154
1196
1155
void FlatLinearValueConstraints::fourierMotzkinEliminate (
1197
1156
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
1157
IntegerPolyhedron::fourierMotzkinEliminate (pos, darkShadow,
1203
1158
isResultIntegerExact);
1204
- values = newVals;
1205
- assert (values.size () == getNumDimAndSymbolVars ());
1206
1159
}
1207
1160
1208
1161
void FlatLinearValueConstraints::projectOut (Value val) {
@@ -1215,11 +1168,7 @@ void FlatLinearValueConstraints::projectOut(Value val) {
1215
1168
1216
1169
LogicalResult FlatLinearValueConstraints::unionBoundingBox (
1217
1170
const FlatLinearValueConstraints &otherCst) {
1218
- assert (otherCst.getNumDimVars () == getNumDimVars () && " dims mismatch" );
1219
- assert (otherCst.getMaybeValues ()
1220
- .slice (0 , getNumDimVars ())
1221
- .equals (getMaybeValues ().slice (0 , getNumDimVars ())) &&
1222
- " dim values mismatch" );
1171
+ assert (otherCst.getSpace ().isAligned (getSpace (), VarKind::SetDim) && " dims mismatch" );
1223
1172
assert (otherCst.getNumLocalVars () == 0 && " local vars not supported here" );
1224
1173
assert (getNumLocalVars () == 0 && " local vars not supported yet here" );
1225
1174
0 commit comments