explicit FlatAffineValueConstraints(ArrayRef<const AffineValueMap *> avmRef);
/// Creates an affine constraint system from an IntegerSet.
- explicit FlatAffineValueConstraints(IntegerSet set);
-
- FlatAffineValueConstraints(ArrayRef<const AffineValueMap *> avmRef,
- IntegerSet set);
+ explicit FlatAffineValueConstraints(IntegerSet set, ValueRange operands = {});
// Construct a hyperrectangular constraint set from ValueRanges that represent
// induction variables, lower and upper bounds. `ivs`, `lbs` and `ubs` are
/// 'affine.for' operation are added as trailing variables (either
/// dimensional or symbolic depending on whether the operand is a valid
/// symbol).
- // TODO: add support for non-unit strides.
LogicalResult addAffineForOpDomain(AffineForOp forOp);
/// Add constraints (lower and upper bounds) for the specified
/// Returns true if an variable with the specified Value exists, false
/// otherwise.
- bool containsVar(Value mayBeVar) const;
+ bool containsVar(Value val) const;
/// Swap the posA^th variable with the posB^th variable.
void swapVar(unsigned posA, unsigned posB) override;
}
// Construct from an IntegerSet.
-FlatAffineValueConstraints::FlatAffineValueConstraints(IntegerSet set)
+FlatAffineValueConstraints::FlatAffineValueConstraints(IntegerSet set,
+ ValueRange operands)
: IntegerPolyhedron(set.getNumInequalities(), set.getNumEqualities(),
set.getNumDims() + set.getNumSymbols() + 1,
PresburgerSpace::getSetSpace(set.getNumDims(),
set.getNumSymbols(),
/*numLocals=*/0)) {
-
- // Resize values.
- values.resize(getNumDimAndSymbolVars(), std::nullopt);
+ // Populate values.
+ if (operands.empty()) {
+ values.resize(getNumDimAndSymbolVars(), std::nullopt);
+ } else {
+ assert(set.getNumInputs() == operands.size() && "operand count mismatch");
+ values.assign(operands.begin(), operands.end());
+ }
// Flatten expressions and add them to the constraint system.
std::vector<SmallVector<int64_t, 8>> flatExprs;
}
void FlatAffineValueConstraints::addAffineIfOpDomain(AffineIfOp ifOp) {
- // Create the base constraints from the integer set attached to ifOp.
- FlatAffineValueConstraints cst(ifOp.getIntegerSet());
+ IntegerSet set = ifOp.getIntegerSet();
+ // Canonicalize set and operands to ensure unique values for
+ // FlatAffineValueConstraints below and for early simplification.
+ SmallVector<Value> operands(ifOp.getOperands());
+ canonicalizeSetAndOperands(&set, &operands);
- // Bind vars in the constraints to ifOp operands.
- SmallVector<Value, 4> operands = ifOp.getOperands();
- cst.setValues(0, cst.getNumDimAndSymbolVars(), operands);
+ // Create the base constraints from the integer set attached to ifOp.
+ FlatAffineValueConstraints cst(set, operands);
// Merge the constraints from ifOp to the current domain. We need first merge
// and align the IDs from both constraints, and then append the constraints
}
return
}
+
+// -----
+
+func.func @affine_if_no_dependence() {
+ %c1 = arith.constant 1 : index
+ %alloc = memref.alloc() : memref<15xi1>
+ %true = arith.constant true
+ affine.store %true, %alloc[%c1] : memref<15xi1>
+ // expected-remark@above {{dependence from 0 to 0 at depth 1 = false}}
+ // expected-remark@above {{dependence from 0 to 1 at depth 1 = false}}
+ // This set is empty.
+ affine.if affine_set<(d0, d1, d2, d3) : ((d0 + 1) mod 8 >= 0, d0 * -8 >= 0)>(%c1, %c1, %c1, %c1){
+ %265 = affine.load %alloc[%c1] : memref<15xi1>
+ // expected-remark@above {{dependence from 1 to 0 at depth 1 = false}}
+ // expected-remark@above {{dependence from 1 to 1 at depth 1 = false}}
+ }
+ return
+}