Remove the ability to directly print affine structures from the OpAsmPrinter. These should go through attributes like most everything else.

--

PiperOrigin-RevId: 246589682
This commit is contained in:
River Riddle 2019-05-03 15:59:42 -07:00 committed by Mehdi Amini
parent 9233df9045
commit b2806e197e
4 changed files with 19 additions and 35 deletions

View File

@ -177,12 +177,14 @@ public:
} }
/// Returns affine map for the lower bound. /// Returns affine map for the lower bound.
AffineMap getLowerBoundMap() { AffineMap getLowerBoundMap() { return getLowerBoundMapAttr().getValue(); }
return getAttr(getLowerBoundAttrName()).cast<AffineMapAttr>().getValue(); AffineMapAttr getLowerBoundMapAttr() {
return getAttr(getLowerBoundAttrName()).cast<AffineMapAttr>();
} }
/// Returns affine map for the upper bound. The upper bound is exclusive. /// Returns affine map for the upper bound. The upper bound is exclusive.
AffineMap getUpperBoundMap() { AffineMap getUpperBoundMap() { return getUpperBoundMapAttr().getValue(); }
return getAttr(getUpperBoundAttrName()).cast<AffineMapAttr>().getValue(); AffineMapAttr getUpperBoundMapAttr() {
return getAttr(getUpperBoundAttrName()).cast<AffineMapAttr>();
} }
/// Set lower bound. The new bound must have the same number of operands as /// Set lower bound. The new bound must have the same number of operands as

View File

@ -22,7 +22,6 @@
#ifndef MLIR_IR_OPIMPLEMENTATION_H #ifndef MLIR_IR_OPIMPLEMENTATION_H
#define MLIR_IR_OPIMPLEMENTATION_H #define MLIR_IR_OPIMPLEMENTATION_H
#include "mlir/IR/AffineMap.h"
#include "mlir/IR/OpDefinition.h" #include "mlir/IR/OpDefinition.h"
#include "llvm/ADT/Twine.h" #include "llvm/ADT/Twine.h"
#include "llvm/Support/SMLoc.h" #include "llvm/Support/SMLoc.h"
@ -30,8 +29,6 @@
namespace mlir { namespace mlir {
class AffineExpr;
class AffineMap;
class Builder; class Builder;
class Function; class Function;
@ -71,8 +68,6 @@ public:
virtual void printFunctionReference(Function *func) = 0; virtual void printFunctionReference(Function *func) = 0;
virtual void printAttribute(Attribute attr) = 0; virtual void printAttribute(Attribute attr) = 0;
virtual void printAttributeAndType(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 /// Print a successor, and use list, of a terminator operation given the
/// terminator and the successor index. /// terminator and the successor index.
@ -113,19 +108,13 @@ inline OpAsmPrinter &operator<<(OpAsmPrinter &p, Attribute attr) {
return p; 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, // 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 // 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. // FunctionType with the Type& version above, not have it match this.
template <typename T, typename std::enable_if< template <typename T, typename std::enable_if<
!std::is_convertible<T &, Value &>::value && !std::is_convertible<T &, Value &>::value &&
!std::is_convertible<T &, Type &>::value && !std::is_convertible<T &, Type &>::value &&
!std::is_convertible<T &, Attribute &>::value && !std::is_convertible<T &, Attribute &>::value,
!std::is_convertible<T &, AffineMap &>::value,
T>::type * = nullptr> T>::type * = nullptr>
inline OpAsmPrinter &operator<<(OpAsmPrinter &p, const T &other) { inline OpAsmPrinter &operator<<(OpAsmPrinter &p, const T &other) {
p.getStream() << other; p.getStream() << other;

View File

@ -154,9 +154,9 @@ bool AffineApplyOp::parse(OpAsmParser *parser, OperationState *result) {
} }
void AffineApplyOp::print(OpAsmPrinter *p) { void AffineApplyOp::print(OpAsmPrinter *p) {
auto map = getAffineMap(); *p << "affine.apply " << getAttr("map");
*p << "affine.apply " << map; printDimAndSymbolList(operand_begin(), operand_end(),
printDimAndSymbolList(operand_begin(), operand_end(), map.getNumDims(), p); getAffineMap().getNumDims(), p);
p->printOptionalAttrDict(getAttrs(), /*elidedAttrs=*/{"map"}); p->printOptionalAttrDict(getAttrs(), /*elidedAttrs=*/{"map"});
} }
@ -939,8 +939,10 @@ bool AffineForOp::parse(OpAsmParser *parser, OperationState *result) {
return false; return false;
} }
static void printBound(AffineBound bound, const char *prefix, OpAsmPrinter *p) { static void printBound(AffineMapAttr boundMap,
AffineMap map = bound.getMap(); Operation::operand_range boundOperands,
const char *prefix, OpAsmPrinter *p) {
AffineMap map = boundMap.getValue();
// Check if this bound should be printed using custom assembly form. // Check if this bound should be printed using custom assembly form.
// The decision to restrict printing custom assembly form to trivial cases // 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. // single symbol.
if (map.getNumDims() == 0 && map.getNumSymbols() == 1) { if (map.getNumDims() == 0 && map.getNumSymbols() == 1) {
if (auto symExpr = expr.dyn_cast<AffineSymbolExpr>()) { if (auto symExpr = expr.dyn_cast<AffineSymbolExpr>()) {
p->printOperand(bound.getOperand(0)); p->printOperand(*boundOperands.begin());
return; return;
} }
} }
@ -973,8 +975,8 @@ static void printBound(AffineBound bound, const char *prefix, OpAsmPrinter *p) {
} }
// Print the map and its operands. // Print the map and its operands.
p->printAffineMap(map); *p << boundMap;
printDimAndSymbolList(bound.operand_begin(), bound.operand_end(), printDimAndSymbolList(boundOperands.begin(), boundOperands.end(),
map.getNumDims(), p); map.getNumDims(), p);
} }
@ -982,9 +984,9 @@ void AffineForOp::print(OpAsmPrinter *p) {
*p << "affine.for "; *p << "affine.for ";
p->printOperand(getBody()->getArgument(0)); p->printOperand(getBody()->getArgument(0));
*p << " = "; *p << " = ";
printBound(getLowerBound(), "max", p); printBound(getLowerBoundMapAttr(), getLowerBoundOperands(), "max", p);
*p << " to "; *p << " to ";
printBound(getUpperBound(), "min", p); printBound(getUpperBoundMapAttr(), getUpperBoundOperands(), "min", p);
if (getStep() != 1) if (getStep() != 1)
*p << " step " << getStep(); *p << " step " << getStep();

View File

@ -1180,15 +1180,6 @@ public:
void printAttributeAndType(Attribute attr) { void printAttributeAndType(Attribute attr) {
ModulePrinter::printAttributeAndType(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) { void printFunctionReference(Function *func) {
return ModulePrinter::printFunctionReference(func); return ModulePrinter::printFunctionReference(func);
} }