Implement operands for the lower and upper bounds of the for statement.
This revamps implementation of the loop bounds in the ForStmt, using general representation that supports operands. The frequent case of constant bounds is supported
via special access methods.
This also includes:
- Operand iterators for the Statement class.
- OpPointer::is() method to query the class of the Operation.
- Support for the bound shorthand notation parsing and printing.
- Validity checks for the bound operands used as dim ids and symbols
I didn't mean this CL to be so large. It just happened this way, as one thing led to another.
PiperOrigin-RevId: 210204858
diff --git a/lib/IR/AffineMap.cpp b/lib/IR/AffineMap.cpp
index 95cd8ff..2b6d680 100644
--- a/lib/IR/AffineMap.cpp
+++ b/lib/IR/AffineMap.cpp
@@ -39,6 +39,15 @@
return true;
}
+bool AffineMap::isSingleConstant() const {
+ return getNumResults() == 1 && isa<AffineConstantExpr>(getResult(0));
+}
+
+int64_t AffineMap::getSingleConstantValue() const {
+ assert(isSingleConstant() && "map must have a single constant result");
+ return dyn_cast<AffineConstantExpr>(getResult(0))->getValue();
+}
+
/// Simplify add expression. Return nullptr if it can't be simplified.
AffineExpr *AffineBinaryOpExpr::simplifyAdd(AffineExpr *lhs, AffineExpr *rhs,
MLIRContext *context) {