@@ -34,35 +34,45 @@ using namespace mlir;
34
34
using namespace affine ;
35
35
using namespace presburger ;
36
36
37
-
38
- void FlatAffineValueConstraints::addInductionVarOrTerminalSymbol (Value val) {
37
+ LogicalResult
38
+ FlatAffineValueConstraints::addInductionVarOrTerminalSymbol (Value val) {
39
39
if (containsVar (val))
40
- return ;
40
+ return success () ;
41
41
42
42
// 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
+ }
45
49
// Outer loop IVs could be used in forOp's bounds.
46
50
if (auto loop = getForInductionVarOwner (val)) {
47
51
appendDimVar (val);
48
- if (failed (this ->addAffineForOpDomain (loop)))
52
+ if (failed (this ->addAffineForOpDomain (loop))) {
49
53
LLVM_DEBUG (
50
54
loop.emitWarning (" failed to add domain info to constraint system" ));
51
- return ;
55
+ return failure ();
56
+ }
57
+ return success ();
52
58
}
59
+
53
60
if (auto parallel = getAffineParallelInductionVarOwner (val)) {
54
61
appendDimVar (parallel.getIVs ());
55
- if (failed (this ->addAffineParallelOpDomain (parallel)))
62
+ if (failed (this ->addAffineParallelOpDomain (parallel))) {
56
63
LLVM_DEBUG (parallel.emitWarning (
57
64
" failed to add domain info to constraint system" ));
58
- return ;
65
+ return failure ();
66
+ }
67
+ return success ();
59
68
}
60
69
61
70
// Add top level symbol.
62
71
appendSymbolVar (val);
63
72
// Check if the symbol is a constant.
64
73
if (std::optional<int64_t > constOp = getConstantIntValue (val))
65
74
addBound (BoundType::EQ, val, constOp.value ());
75
+ return success ();
66
76
}
67
77
68
78
LogicalResult
@@ -222,8 +232,10 @@ LogicalResult FlatAffineValueConstraints::addBound(BoundType type, unsigned pos,
222
232
fullyComposeAffineMapAndOperands (&map, &operands);
223
233
map = simplifyAffineMap (map);
224
234
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
+ }
227
239
return addBound (type, pos, computeAlignedMap (map, operands));
228
240
}
229
241
0 commit comments