Remove the ability to directly print affine structures from the OpAsmPrinter...
authorRiver Riddle <riverriddle@google.com>
Fri, 3 May 2019 22:59:42 +0000 (15:59 -0700)
committerMehdi Amini <joker.eph@gmail.com>
Mon, 6 May 2019 15:27:32 +0000 (08:27 -0700)
--

PiperOrigin-RevId: 246589682

mlir/include/mlir/AffineOps/AffineOps.h
mlir/include/mlir/IR/OpImplementation.h
mlir/lib/AffineOps/AffineOps.cpp
mlir/lib/IR/AsmPrinter.cpp

index 29009b6..5b1446d 100644 (file)
@@ -177,12 +177,14 @@ public:
   }
 
   /// Returns affine map for the lower bound.
-  AffineMap getLowerBoundMap() {
-    return getAttr(getLowerBoundAttrName()).cast<AffineMapAttr>().getValue();
+  AffineMap getLowerBoundMap() { return getLowerBoundMapAttr().getValue(); }
+  AffineMapAttr getLowerBoundMapAttr() {
+    return getAttr(getLowerBoundAttrName()).cast<AffineMapAttr>();
   }
   /// Returns affine map for the upper bound. The upper bound is exclusive.
-  AffineMap getUpperBoundMap() {
-    return getAttr(getUpperBoundAttrName()).cast<AffineMapAttr>().getValue();
+  AffineMap getUpperBoundMap() { return getUpperBoundMapAttr().getValue(); }
+  AffineMapAttr getUpperBoundMapAttr() {
+    return getAttr(getUpperBoundAttrName()).cast<AffineMapAttr>();
   }
 
   /// Set lower bound. The new bound must have the same number of operands as
index f99e4d2..f402f74 100644 (file)
@@ -22,7 +22,6 @@
 #ifndef MLIR_IR_OPIMPLEMENTATION_H
 #define MLIR_IR_OPIMPLEMENTATION_H
 
-#include "mlir/IR/AffineMap.h"
 #include "mlir/IR/OpDefinition.h"
 #include "llvm/ADT/Twine.h"
 #include "llvm/Support/SMLoc.h"
@@ -30,8 +29,6 @@
 
 namespace mlir {
 
-class AffineExpr;
-class AffineMap;
 class Builder;
 class Function;
 
@@ -71,8 +68,6 @@ public:
   virtual void printFunctionReference(Function *func) = 0;
   virtual void printAttribute(Attribute attr) = 0;
   virtual void printAttributeAndType(Attribute attr) = 0;
-  virtual void printAffineMap(AffineMap map) = 0;
-  virtual void printAffineExpr(AffineExpr expr) = 0;
 
   /// Print a successor, and use list, of a terminator operation given the
   /// terminator and the successor index.
@@ -113,19 +108,13 @@ inline OpAsmPrinter &operator<<(OpAsmPrinter &p, Attribute attr) {
   return p;
 }
 
-inline OpAsmPrinter &operator<<(OpAsmPrinter &p, AffineMap map) {
-  p.printAffineMap(map);
-  return p;
-}
-
 // Support printing anything that isn't convertible to one of the above types,
 // even if it isn't exactly one of them.  For example, we want to print
 // FunctionType with the Type& version above, not have it match this.
 template <typename T, typename std::enable_if<
                           !std::is_convertible<T &, Value &>::value &&
                               !std::is_convertible<T &, Type &>::value &&
-                              !std::is_convertible<T &, Attribute &>::value &&
-                              !std::is_convertible<T &, AffineMap &>::value,
+                              !std::is_convertible<T &, Attribute &>::value,
                           T>::type * = nullptr>
 inline OpAsmPrinter &operator<<(OpAsmPrinter &p, const T &other) {
   p.getStream() << other;
index 1e26d0e..4135c61 100644 (file)
@@ -154,9 +154,9 @@ bool AffineApplyOp::parse(OpAsmParser *parser, OperationState *result) {
 }
 
 void AffineApplyOp::print(OpAsmPrinter *p) {
-  auto map = getAffineMap();
-  *p << "affine.apply " << map;
-  printDimAndSymbolList(operand_begin(), operand_end(), map.getNumDims(), p);
+  *p << "affine.apply " << getAttr("map");
+  printDimAndSymbolList(operand_begin(), operand_end(),
+                        getAffineMap().getNumDims(), p);
   p->printOptionalAttrDict(getAttrs(), /*elidedAttrs=*/{"map"});
 }
 
@@ -939,8 +939,10 @@ bool AffineForOp::parse(OpAsmParser *parser, OperationState *result) {
   return false;
 }
 
-static void printBound(AffineBound bound, const char *prefix, OpAsmPrinter *p) {
-  AffineMap map = bound.getMap();
+static void printBound(AffineMapAttr boundMap,
+                       Operation::operand_range boundOperands,
+                       const char *prefix, OpAsmPrinter *p) {
+  AffineMap map = boundMap.getValue();
 
   // Check if this bound should be printed using custom assembly form.
   // The decision to restrict printing custom assembly form to trivial cases
@@ -963,7 +965,7 @@ static void printBound(AffineBound bound, const char *prefix, OpAsmPrinter *p) {
     // single symbol.
     if (map.getNumDims() == 0 && map.getNumSymbols() == 1) {
       if (auto symExpr = expr.dyn_cast<AffineSymbolExpr>()) {
-        p->printOperand(bound.getOperand(0));
+        p->printOperand(*boundOperands.begin());
         return;
       }
     }
@@ -973,8 +975,8 @@ static void printBound(AffineBound bound, const char *prefix, OpAsmPrinter *p) {
   }
 
   // Print the map and its operands.
-  p->printAffineMap(map);
-  printDimAndSymbolList(bound.operand_begin(), bound.operand_end(),
+  *p << boundMap;
+  printDimAndSymbolList(boundOperands.begin(), boundOperands.end(),
                         map.getNumDims(), p);
 }
 
@@ -982,9 +984,9 @@ void AffineForOp::print(OpAsmPrinter *p) {
   *p << "affine.for ";
   p->printOperand(getBody()->getArgument(0));
   *p << " = ";
-  printBound(getLowerBound(), "max", p);
+  printBound(getLowerBoundMapAttr(), getLowerBoundOperands(), "max", p);
   *p << " to ";
-  printBound(getUpperBound(), "min", p);
+  printBound(getUpperBoundMapAttr(), getUpperBoundOperands(), "min", p);
 
   if (getStep() != 1)
     *p << " step " << getStep();
index 504bf68..03fb5c6 100644 (file)
@@ -1180,15 +1180,6 @@ public:
   void printAttributeAndType(Attribute attr) {
     ModulePrinter::printAttributeAndType(attr);
   }
-  void printAffineMap(AffineMap map) {
-    return ModulePrinter::printAffineMapReference(map);
-  }
-  void printIntegerSet(IntegerSet set) {
-    return ModulePrinter::printIntegerSetReference(set);
-  }
-  void printAffineExpr(AffineExpr expr) {
-    return ModulePrinter::printAffineExpr(expr);
-  }
   void printFunctionReference(Function *func) {
     return ModulePrinter::printFunctionReference(func);
   }