From b2806e197eafafdbf3b3342409ebdad3e4e4726a Mon Sep 17 00:00:00 2001 From: River Riddle Date: Fri, 3 May 2019 15:59:42 -0700 Subject: [PATCH] Remove the ability to directly print affine structures from the OpAsmPrinter. These should go through attributes like most everything else. -- PiperOrigin-RevId: 246589682 --- mlir/include/mlir/AffineOps/AffineOps.h | 10 ++++++---- mlir/include/mlir/IR/OpImplementation.h | 13 +------------ mlir/lib/AffineOps/AffineOps.cpp | 22 ++++++++++++---------- mlir/lib/IR/AsmPrinter.cpp | 9 --------- 4 files changed, 19 insertions(+), 35 deletions(-) diff --git a/mlir/include/mlir/AffineOps/AffineOps.h b/mlir/include/mlir/AffineOps/AffineOps.h index 29009b6e3998..5b1446da7626 100644 --- a/mlir/include/mlir/AffineOps/AffineOps.h +++ b/mlir/include/mlir/AffineOps/AffineOps.h @@ -177,12 +177,14 @@ public: } /// Returns affine map for the lower bound. - AffineMap getLowerBoundMap() { - return getAttr(getLowerBoundAttrName()).cast().getValue(); + AffineMap getLowerBoundMap() { return getLowerBoundMapAttr().getValue(); } + AffineMapAttr getLowerBoundMapAttr() { + return getAttr(getLowerBoundAttrName()).cast(); } /// Returns affine map for the upper bound. The upper bound is exclusive. - AffineMap getUpperBoundMap() { - return getAttr(getUpperBoundAttrName()).cast().getValue(); + AffineMap getUpperBoundMap() { return getUpperBoundMapAttr().getValue(); } + AffineMapAttr getUpperBoundMapAttr() { + return getAttr(getUpperBoundAttrName()).cast(); } /// Set lower bound. The new bound must have the same number of operands as diff --git a/mlir/include/mlir/IR/OpImplementation.h b/mlir/include/mlir/IR/OpImplementation.h index f99e4d2d919b..f402f74aa353 100644 --- a/mlir/include/mlir/IR/OpImplementation.h +++ b/mlir/include/mlir/IR/OpImplementation.h @@ -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 ::value && !std::is_convertible::value && - !std::is_convertible::value && - !std::is_convertible::value, + !std::is_convertible::value, T>::type * = nullptr> inline OpAsmPrinter &operator<<(OpAsmPrinter &p, const T &other) { p.getStream() << other; diff --git a/mlir/lib/AffineOps/AffineOps.cpp b/mlir/lib/AffineOps/AffineOps.cpp index 1e26d0e90485..4135c612e18b 100644 --- a/mlir/lib/AffineOps/AffineOps.cpp +++ b/mlir/lib/AffineOps/AffineOps.cpp @@ -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()) { - 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(); diff --git a/mlir/lib/IR/AsmPrinter.cpp b/mlir/lib/IR/AsmPrinter.cpp index 504bf684236f..03fb5c6f85e5 100644 --- a/mlir/lib/IR/AsmPrinter.cpp +++ b/mlir/lib/IR/AsmPrinter.cpp @@ -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); }