@@ -34,35 +34,45 @@ using namespace mlir;
3434using namespace affine ;
3535using namespace presburger ;
3636
37-
38- void FlatAffineValueConstraints::addInductionVarOrTerminalSymbol (Value val) {
37+ LogicalResult
38+ FlatAffineValueConstraints::addInductionVarOrTerminalSymbol (Value val) {
3939 if (containsVar (val))
40- return ;
40+ return success () ;
4141
4242 // Caller is expected to fully compose map/operands if necessary.
43- assert ((isTopLevelValue (val) || isAffineInductionVar (val)) &&
44- " non-terminal symbol / loop IV expected" );
43+ if (val.getDefiningOp <affine::AffineApplyOp>() ||
44+ (!isValidSymbol (val) && !isAffineInductionVar (val))) {
45+ LLVM_DEBUG (llvm::dbgs ()
46+ << " only valid terminal symbols and affine IVs supported\n " );
47+ return failure ();
48+ }
4549 // Outer loop IVs could be used in forOp's bounds.
4650 if (auto loop = getForInductionVarOwner (val)) {
4751 appendDimVar (val);
48- if (failed (this ->addAffineForOpDomain (loop)))
52+ if (failed (this ->addAffineForOpDomain (loop))) {
4953 LLVM_DEBUG (
5054 loop.emitWarning (" failed to add domain info to constraint system" ));
51- return ;
55+ return failure ();
56+ }
57+ return success ();
5258 }
59+
5360 if (auto parallel = getAffineParallelInductionVarOwner (val)) {
5461 appendDimVar (parallel.getIVs ());
55- if (failed (this ->addAffineParallelOpDomain (parallel)))
62+ if (failed (this ->addAffineParallelOpDomain (parallel))) {
5663 LLVM_DEBUG (parallel.emitWarning (
5764 " failed to add domain info to constraint system" ));
58- return ;
65+ return failure ();
66+ }
67+ return success ();
5968 }
6069
6170 // Add top level symbol.
6271 appendSymbolVar (val);
6372 // Check if the symbol is a constant.
6473 if (std::optional<int64_t > constOp = getConstantIntValue (val))
6574 addBound (BoundType::EQ, val, constOp.value ());
75+ return success ();
6676}
6777
6878LogicalResult
@@ -222,8 +232,10 @@ LogicalResult FlatAffineValueConstraints::addBound(BoundType type, unsigned pos,
222232 fullyComposeAffineMapAndOperands (&map, &operands);
223233 map = simplifyAffineMap (map);
224234 canonicalizeMapAndOperands (&map, &operands);
225- for (auto operand : operands)
226- addInductionVarOrTerminalSymbol (operand);
235+ for (Value operand : operands) {
236+ if (failed (addInductionVarOrTerminalSymbol (operand)))
237+ return failure ();
238+ }
227239 return addBound (type, pos, computeAlignedMap (map, operands));
228240}
229241
0 commit comments