This aligns the printer with the parser contract: the operation isn't part of the user-controllable part of the syntax.
Differential Revision: https://reviews.llvm.org/D108804
}];
let printer = [{
- p << getOperationName() << ' ' << (*this)->getAttr(inType());
+ p << ' ' << (*this)->getAttr(inType());
if (hasLenParams()) {
// print the LEN parameters to a derived type in parens
p << '(' << getLenParams() << " : " << getLenParams().getTypes() << ')';
}];
let printer = [{
- p << getOperationName() << ' ';
+ p << ' ';
p.printOperand(memref());
p.printOptionalAttrDict((*this)->getAttrs(), {});
p << " : " << memref().getType();
}];
let printer = [{
- p << getOperationName() << ' ';
+ p << ' ';
p.printOperand(value());
p << " to ";
p.printOperand(memref());
}];
let printer = [{
- p << getOperationName() << ' ';
+ p << ' ';
p.printOperand(getSelector());
p << " : " << getSelector().getType() << " [";
auto cases = (*this)->getAttrOfType<mlir::ArrayAttr>(getCasesAttr()).getValue();
let parser = "return parseSelectCase(parser, result);";
let printer = [{
- p << getOperationName() << ' ';
+ p << ' ';
p.printOperand(getSelector());
p << " : " << getSelector().getType() << " [";
auto cases = (*this)->getAttrOfType<mlir::ArrayAttr>(getCasesAttr()).getValue();
let parser = "return parseSelectType(parser, result);";
let printer = [{
- p << getOperationName() << ' ';
+ p << ' ';
p.printOperand(getSelector());
p << " : " << getSelector().getType() << " [";
auto cases = (*this)->getAttrOfType<mlir::ArrayAttr>(getCasesAttr()).getValue();
let parser = "return mlir::success();";
- let printer = "p << getOperationName();";
+ let printer = "";
}
def fir_FirEndOp : fir_Op<"end", [Terminator]> {
}];
let printer = [{
- p << getOperationName() << ' ' << (*this)->getAttr("funcname");
+ p << ' ' << (*this)->getAttr("funcname");
auto h = host();
if (h) {
p << ", ";
}];
let printer = [{
- p << getOperationName() << ' '
+ p << ' '
<< (*this)->getAttrOfType<mlir::StringAttr>(fieldAttrName()).getValue()
<< ", " << (*this)->getAttr(typeAttrName());
if (getNumOperands()) {
}];
let printer = [{
- p << getOperationName() << ' '
+ p << ' '
<< (*this)->getAttrOfType<mlir::StringAttr>(fieldAttrName()).getValue()
<< ", " << (*this)->getAttr(typeAttrName());
}];
}];
let printer = [{
- p << getOperationName() << ' ' << methodAttr() << '(';
+ p << ' ' << methodAttr() << '(';
p.printOperand(object());
if (!args().empty()) {
p << ", ";
}];
let printer = [{
- p << getOperationName() << ' ' << getValue() << '(';
+ p << ' ' << getValue() << '(';
p << getSize().cast<mlir::IntegerAttr>().getValue() << ") : ";
p.printType(getType());
}];
}];
let printer = [{
- p << getOperationName() << " (0x";
+ p << " (0x";
auto f1 = (*this)->getAttr(realAttrName()).cast<mlir::FloatAttr>();
auto i1 = f1.getValue().bitcastToAPInt();
p.getStream().write_hex(i1.getZExtValue());
}];
let printer = [{
- p << getOperationName() << ' ' << (*this)->getAttr("in_type");
+ p << ' ' << (*this)->getAttr("in_type");
p.printOptionalAttrDict((*this)->getAttrs(), {"in_type"});
}];
let parser = "return parseGlobalOp(parser, result);";
let printer = [{
- p << getOperationName();
if (linkName().hasValue())
p << ' ' << linkName().getValue();
p << ' ';
}];
let printer = [{
- p << getOperationName() << ' ' << (*this)->getAttr(lenParamAttrName())
+ p << ' ' << (*this)->getAttr(lenParamAttrName())
<< ", " << (*this)->getAttr(intAttrName());
}];
let printer = [{
auto tableName = (*this)->getAttrOfType<StringAttr>(
mlir::SymbolTable::getSymbolAttrName()).getValue();
- p << getOperationName() << " @" << tableName;
+ p << " @" << tableName;
Region &body = (*this)->getRegion(0);
if (!body.empty())
}];
let printer = [{
- p << getOperationName() << ' ' << methodAttr() << ", "
+ p << ' ' << methodAttr() << ", "
<< procAttr();
}];
}
static void printCallOp(mlir::OpAsmPrinter &p, fir::CallOp &op) {
auto callee = op.callee();
bool isDirect = callee.hasValue();
- p << op.getOperationName() << ' ';
+ p << ' ';
if (isDirect)
p << callee.getValue();
else
template <typename OPTY>
static void printCmpOp(OpAsmPrinter &p, OPTY op) {
- p << op.getOperationName() << ' ';
+ p << ' ';
auto predSym = mlir::symbolizeCmpFPredicate(
op->template getAttrOfType<mlir::IntegerAttr>(
OPTY::getPredicateAttrName())
//===----------------------------------------------------------------------===//
static void print(mlir::OpAsmPrinter &p, fir::CoordinateOp op) {
- p << op.getOperationName() << ' ' << op.ref() << ", " << op.coor();
+ p << ' ' << op.ref() << ", " << op.coor();
p.printOptionalAttrDict(op->getAttrs(), /*elideAttrs=*/{"baseType"});
p << " : ";
p.printFunctionalType(op.getOperandTypes(), op->getResultTypes());
}
static void print(mlir::OpAsmPrinter &p, fir::IterWhileOp op) {
- p << fir::IterWhileOp::getOperationName() << " (" << op.getInductionVar()
- << " = " << op.lowerBound() << " to " << op.upperBound() << " step "
- << op.step() << ") and (";
+ p << " (" << op.getInductionVar() << " = " << op.lowerBound() << " to "
+ << op.upperBound() << " step " << op.step() << ") and (";
assert(op.hasIterOperands());
auto regionArgs = op.getRegionIterArgs();
auto operands = op.getIterOperands();
static void print(mlir::OpAsmPrinter &p, fir::DoLoopOp op) {
bool printBlockTerminators = false;
- p << fir::DoLoopOp::getOperationName() << ' ' << op.getInductionVar() << " = "
- << op.lowerBound() << " to " << op.upperBound() << " step " << op.step();
+ p << ' ' << op.getInductionVar() << " = " << op.lowerBound() << " to "
+ << op.upperBound() << " step " << op.step();
if (op.unordered())
p << " unordered";
if (op.hasIterOperands()) {
static void print(mlir::OpAsmPrinter &p, fir::IfOp op) {
bool printBlockTerminators = false;
- p << fir::IfOp::getOperationName() << ' ' << op.condition();
+ p << ' ' << op.condition();
if (!op.results().empty()) {
p << " -> (" << op.getResultTypes() << ')';
printBlockTerminators = true;
assert(op->getNumOperands() == 2 && "binary op must have two operands");
assert(op->getNumResults() == 1 && "binary op must have one result");
- p << op->getName() << ' ' << op->getOperand(0) << ", " << op->getOperand(1);
+ p << ' ' << op->getOperand(0) << ", " << op->getOperand(1);
p.printOptionalAttrDict(op->getAttrs());
p << " : " << op->getResult(0).getType();
}
assert(op->getNumOperands() == 1 && "unary op must have one operand");
assert(op->getNumResults() == 1 && "unary op must have one result");
- p << op->getName() << ' ' << op->getOperand(0);
+ p << ' ' << op->getOperand(0);
p.printOptionalAttrDict(op->getAttrs());
p << " : " << op->getResult(0).getType();
}
/// A generalized printer for binary operations. It prints in two different
/// forms depending on if all of the types match.
static void printBinaryOp(mlir::OpAsmPrinter &printer, mlir::Operation *op) {
- printer << op->getName() << " " << op->getOperands();
+ printer << " " << op->getOperands();
printer.printOptionalAttrDict(op->getAttrs());
printer << " : ";
/// The 'OpAsmPrinter' class is a stream that allows for formatting
/// strings, attributes, operands, types, etc.
static void print(mlir::OpAsmPrinter &printer, ConstantOp op) {
- printer << "toy.constant ";
+ printer << " ";
printer.printOptionalAttrDict(op->getAttrs(), /*elidedAttrs=*/{"value"});
printer << op.value();
}
/// A generalized printer for binary operations. It prints in two different
/// forms depending on if all of the types match.
static void printBinaryOp(mlir::OpAsmPrinter &printer, mlir::Operation *op) {
- printer << op->getName() << " " << op->getOperands();
+ printer << " " << op->getOperands();
printer.printOptionalAttrDict(op->getAttrs());
printer << " : ";
/// The 'OpAsmPrinter' class is a stream that allows for formatting
/// strings, attributes, operands, types, etc.
static void print(mlir::OpAsmPrinter &printer, ConstantOp op) {
- printer << "toy.constant ";
+ printer << " ";
printer.printOptionalAttrDict(op->getAttrs(), /*elidedAttrs=*/{"value"});
printer << op.value();
}
/// A generalized printer for binary operations. It prints in two different
/// forms depending on if all of the types match.
static void printBinaryOp(mlir::OpAsmPrinter &printer, mlir::Operation *op) {
- printer << op->getName() << " " << op->getOperands();
+ printer << " " << op->getOperands();
printer.printOptionalAttrDict(op->getAttrs());
printer << " : ";
/// The 'OpAsmPrinter' class is a stream that allows for formatting
/// strings, attributes, operands, types, etc.
static void print(mlir::OpAsmPrinter &printer, ConstantOp op) {
- printer << "toy.constant ";
+ printer << " ";
printer.printOptionalAttrDict(op->getAttrs(), /*elidedAttrs=*/{"value"});
printer << op.value();
}
/// A generalized printer for binary operations. It prints in two different
/// forms depending on if all of the types match.
static void printBinaryOp(mlir::OpAsmPrinter &printer, mlir::Operation *op) {
- printer << op->getName() << " " << op->getOperands();
+ printer << " " << op->getOperands();
printer.printOptionalAttrDict(op->getAttrs());
printer << " : ";
/// The 'OpAsmPrinter' class is a stream that allows for formatting
/// strings, attributes, operands, types, etc.
static void print(mlir::OpAsmPrinter &printer, ConstantOp op) {
- printer << "toy.constant ";
+ printer << " ";
printer.printOptionalAttrDict(op->getAttrs(), /*elidedAttrs=*/{"value"});
printer << op.value();
}
/// A generalized printer for binary operations. It prints in two different
/// forms depending on if all of the types match.
static void printBinaryOp(mlir::OpAsmPrinter &printer, mlir::Operation *op) {
- printer << op->getName() << " " << op->getOperands();
+ printer << " " << op->getOperands();
printer.printOptionalAttrDict(op->getAttrs());
printer << " : ";
/// The 'OpAsmPrinter' class is a stream that allows for formatting
/// strings, attributes, operands, types, etc.
static void print(mlir::OpAsmPrinter &printer, ConstantOp op) {
- printer << "toy.constant ";
+ printer << " ";
printer.printOptionalAttrDict(op->getAttrs(), /*elidedAttrs=*/{"value"});
printer << op.value();
}
/// A generalized printer for binary operations. It prints in two different
/// forms depending on if all of the types match.
static void printBinaryOp(mlir::OpAsmPrinter &printer, mlir::Operation *op) {
- printer << op->getName() << " " << op->getOperands();
+ printer << " " << op->getOperands();
printer.printOptionalAttrDict(op->getAttrs());
printer << " : ";
/// The 'OpAsmPrinter' class is a stream that allows for formatting
/// strings, attributes, operands, types, etc.
static void print(mlir::OpAsmPrinter &printer, ConstantOp op) {
- printer << "toy.constant ";
+ printer << " ";
printer.printOptionalAttrDict(op->getAttrs(), /*elidedAttrs=*/{"value"});
printer << op.value();
}
let builders = [OpBuilder<(ins), [{ // empty}]>];
- let parser = [{ return parseReturnOp(parser, result); }];
- let printer = [{ p << getOperationName(); }];
+ let assemblyFormat = "attr-dict ($operands^ `:` type($operands))?";
let verifier = [{ return ::verify(*this); }];
}
terminator takes no operands.
}];
- let parser = [{ return success(); }];
- let printer = [{ p << getOperationName(); }];
+ let assemblyFormat = "attr-dict";
}
def GPU_YieldOp : GPU_Op<"yield", [NoSideEffect, Terminator]>,
Either none or all work items of a workgroup need to execute this op
in convergence.
}];
- let parser = [{ return success(); }];
- let printer = [{ p << getOperationName(); }];
+ let assemblyFormat = "attr-dict";
}
def GPU_GPUModuleOp : GPU_Op<"module", [
This op terminates the only block inside the only region of a `gpu.module`.
}];
- let parser = [{ return success(); }];
- let printer = [{ p << getOperationName(); }];
+ let assemblyFormat = "attr-dict";
}
def GPU_HostRegisterOp : GPU_Op<"host_register">,
}
def LLVM_UnreachableOp : LLVM_TerminatorOp<"unreachable", []> {
string llvmBuilder = [{ builder.CreateUnreachable(); }];
- let parser = [{ return success(); }];
- let printer = [{ p << getOperationName(); }];
+ let assemblyFormat = "attr-dict";
}
def LLVM_SwitchOp : LLVM_TerminatorOp<"switch",
let parser = [{ return parseROCDLMubufLoadOp(parser, result); }];
let printer = [{
Operation *op = this->getOperation();
- p << op->getName() << " " << op->getOperands()
+ p << " " << op->getOperands()
<< " : " << op->getResultTypes();
}];
}
let parser = [{ return parseROCDLMubufStoreOp(parser, result); }];
let printer = [{
Operation *op = this->getOperation();
- p << op->getName() << " " << op->getOperands()
+ p << " " << op->getOperands()
<< " : " << vdata().getType();
}];
}
/// linalg::(Tensor)CollapseShapeOp.
template <typename ReshapeLikeOp>
void printReshapeOp(OpAsmPrinter &p, ReshapeLikeOp op) {
- p << op.getOperationName() << ' ' << op.src() << " [";
+ p << ' ' << op.src() << " [";
llvm::interleaveComma(op.reassociation(), p, [&](const Attribute &attr) {
p << '[';
ShapedType resultType = reshapeOp.getResultType();
Optional<SmallVector<ReassociationIndices>> reassociationIndices =
composeReassociationIndices(srcReshapeOp.getReassociationIndices(),
- reshapeOp.getReassociationIndices(),
- rewriter.getContext());
+ reshapeOp.getReassociationIndices(),
+ rewriter.getContext());
if (!reassociationIndices)
return failure();
rewriter.replaceOpWithNewOp<ReshapeOpTy>(
// The fallback for the printer is to print it the generic assembly form.
static void print(Operation *op, OpAsmPrinter &p);
+ static void printOpName(Operation *op, OpAsmPrinter &p);
/// Mutability management is handled by the OpWrapper/OpConstWrapper classes,
/// so we can cast it away here.
static std::enable_if_t<!detect_has_print<ConcreteOpT>::value,
AbstractOperation::PrintAssemblyFn>
getPrintAssemblyFnImpl() {
- return [](Operation *op, OpAsmPrinter &parser) {
- return OpState::print(op, parser);
+ return [](Operation *op, OpAsmPrinter &printer) {
+ return OpState::print(op, printer);
};
}
/// The internal implementation of `getPrintAssemblyFn` that is invoked when
return &printAssembly;
}
static void printAssembly(Operation *op, OpAsmPrinter &p) {
+ OpState::printOpName(op, p);
return cast<ConcreteType>(op).print(p);
}
/// Implementation of `VerifyInvariantsFn` AbstractOperation hook.
ArrayRef<StringRef> elidedAttrs = {}) = 0;
/// Print the entire operation with the default generic assembly form.
- virtual void printGenericOp(Operation *op) = 0;
+ /// If `printOpName` is true, then the operation name is printed (the default)
+ /// otherwise it is omitted and the print will start with the operand list.
+ virtual void printGenericOp(Operation *op, bool printOpName = true) = 0;
/// Prints a region.
/// If 'printEntryBlockArgs' is false, the arguments of the
}
static void print(OpAsmPrinter &p, AffineApplyOp op) {
- p << AffineApplyOp::getOperationName() << " " << op.mapAttr();
+ p << " " << op.mapAttr();
printDimAndSymbolList(op.operand_begin(), op.operand_end(),
op.getAffineMap().getNumDims(), p);
p.printOptionalAttrDict(op->getAttrs(), /*elidedAttrs=*/{"map"});
}
void AffineDmaStartOp::print(OpAsmPrinter &p) {
- p << "affine.dma_start " << getSrcMemRef() << '[';
+ p << " " << getSrcMemRef() << '[';
p.printAffineMapOfSSAIds(getSrcMapAttr(), getSrcIndices());
p << "], " << getDstMemRef() << '[';
p.printAffineMapOfSSAIds(getDstMapAttr(), getDstIndices());
}
void AffineDmaWaitOp::print(OpAsmPrinter &p) {
- p << "affine.dma_wait " << getTagMemRef() << '[';
+ p << " " << getTagMemRef() << '[';
SmallVector<Value, 2> operands(getTagIndices());
p.printAffineMapOfSSAIds(getTagMapAttr(), operands);
p << "], ";
}
static void print(OpAsmPrinter &p, AffineForOp op) {
- p << op.getOperationName() << ' ';
+ p << ' ';
p.printOperand(op.getBody()->getArgument(0));
p << " = ";
printBound(op.getLowerBoundMapAttr(), op.getLowerBoundOperands(), "max", p);
static void print(OpAsmPrinter &p, AffineIfOp op) {
auto conditionAttr =
op->getAttrOfType<IntegerSetAttr>(op.getConditionAttrName());
- p << "affine.if " << conditionAttr;
+ p << " " << conditionAttr;
printDimAndSymbolList(op.operand_begin(), op.operand_end(),
conditionAttr.getValue().getNumDims(), p);
p.printOptionalArrowTypeList(op.getResultTypes());
}
static void print(OpAsmPrinter &p, AffineLoadOp op) {
- p << "affine.load " << op.getMemRef() << '[';
+ p << " " << op.getMemRef() << '[';
if (AffineMapAttr mapAttr =
op->getAttrOfType<AffineMapAttr>(op.getMapAttrName()))
p.printAffineMapOfSSAIds(mapAttr, op.getMapOperands());
}
static void print(OpAsmPrinter &p, AffineStoreOp op) {
- p << "affine.store " << op.getValueToStore();
+ p << " " << op.getValueToStore();
p << ", " << op.getMemRef() << '[';
if (AffineMapAttr mapAttr =
op->getAttrOfType<AffineMapAttr>(op.getMapAttrName()))
template <typename T>
static void printAffineMinMaxOp(OpAsmPrinter &p, T op) {
- p << op.getOperationName() << ' ' << op->getAttr(T::getMapAttrName());
+ p << ' ' << op->getAttr(T::getMapAttrName());
auto operands = op.getOperands();
unsigned numDims = op.map().getNumDims();
p << '(' << operands.take_front(numDims) << ')';
}
static void print(OpAsmPrinter &p, AffinePrefetchOp op) {
- p << AffinePrefetchOp::getOperationName() << " " << op.memref() << '[';
+ p << " " << op.memref() << '[';
AffineMapAttr mapAttr = op->getAttrOfType<AffineMapAttr>(op.getMapAttrName());
if (mapAttr) {
SmallVector<Value, 2> operands(op.getMapOperands());
}
static void print(OpAsmPrinter &p, AffineParallelOp op) {
- p << op.getOperationName() << " (" << op.getBody()->getArguments() << ") = (";
+ p << " (" << op.getBody()->getArguments() << ") = (";
printMinMaxBound(p, op.lowerBoundsMapAttr(), op.lowerBoundsGroupsAttr(),
op.getLowerBoundsOperands(), "max");
p << ") to (";
}
static void print(OpAsmPrinter &p, AffineVectorLoadOp op) {
- p << "affine.vector_load " << op.getMemRef() << '[';
+ p << " " << op.getMemRef() << '[';
if (AffineMapAttr mapAttr =
op->getAttrOfType<AffineMapAttr>(op.getMapAttrName()))
p.printAffineMapOfSSAIds(mapAttr, op.getMapOperands());
}
static void print(OpAsmPrinter &p, AffineVectorStoreOp op) {
- p << "affine.vector_store " << op.getValueToStore();
+ p << " " << op.getValueToStore();
p << ", " << op.getMemRef() << '[';
if (AffineMapAttr mapAttr =
op->getAttrOfType<AffineMapAttr>(op.getMapAttrName()))
}
static void print(OpAsmPrinter &p, ExecuteOp op) {
- p << op.getOperationName();
-
// [%tokens,...]
if (!op.dependencies().empty())
p << " [" << op.dependencies() << "]";
static void print(OpAsmPrinter &p, IncludeOp &op) {
bool standardInclude = op.is_standard_include();
- p << IncludeOp::getOperationName() << " ";
+ p << " ";
if (standardInclude)
p << "<";
p << "\"" << op.include() << "\"";
}
static void printShuffleOp(OpAsmPrinter &p, ShuffleOp op) {
- p << ShuffleOp::getOperationName() << ' ' << op.getOperands() << ' '
- << op.mode() << " : " << op.value().getType();
+ p << ' ' << op.getOperands() << ' ' << op.mode() << " : "
+ << op.value().getType();
}
static ParseResult parseShuffleOp(OpAsmParser &parser, OperationState &state) {
static void printLaunchOp(OpAsmPrinter &p, LaunchOp op) {
// Print the launch configuration.
- p << LaunchOp::getOperationName() << ' ' << op.getBlocksKeyword();
+ p << ' ' << op.getBlocksKeyword();
printSizeAssignment(p, op.getGridSize(), op.getGridSizeOperandValues(),
op.getBlockIds());
p << ' ' << op.getThreadsKeyword();
/// Prints a GPU Func op.
static void printGPUFuncOp(OpAsmPrinter &p, GPUFuncOp op) {
- p << GPUFuncOp::getOperationName() << ' ';
+ p << ' ';
p.printSymbolName(op.getName());
FunctionType type = op.getType();
// ReturnOp
//===----------------------------------------------------------------------===//
-static ParseResult parseReturnOp(OpAsmParser &parser, OperationState &result) {
- llvm::SmallVector<OpAsmParser::OperandType, 4> operands;
- llvm::SmallVector<Type, 4> types;
- if (parser.parseOperandList(operands) ||
- parser.parseOptionalColonTypeList(types) ||
- parser.resolveOperands(operands, types, parser.getCurrentLocation(),
- result.operands))
- return failure();
-
- return success();
-}
-
static LogicalResult verify(gpu::ReturnOp returnOp) {
GPUFuncOp function = returnOp->getParentOfType<GPUFuncOp>();
}
static void print(OpAsmPrinter &p, GPUModuleOp op) {
- p << op.getOperationName() << ' ';
+ p << ' ';
p.printSymbolName(op.getName());
p.printOptionalAttrDictWithKeyword(op->getAttrs(),
{SymbolTable::getSymbolAttrName()});
// Printing/parsing for LLVM::CmpOp.
//===----------------------------------------------------------------------===//
static void printICmpOp(OpAsmPrinter &p, ICmpOp &op) {
- p << op.getOperationName() << " \"" << stringifyICmpPredicate(op.predicate())
- << "\" " << op.getOperand(0) << ", " << op.getOperand(1);
+ p << " \"" << stringifyICmpPredicate(op.predicate()) << "\" "
+ << op.getOperand(0) << ", " << op.getOperand(1);
p.printOptionalAttrDict(op->getAttrs(), {"predicate"});
p << " : " << op.lhs().getType();
}
static void printFCmpOp(OpAsmPrinter &p, FCmpOp &op) {
- p << op.getOperationName() << " \"" << stringifyFCmpPredicate(op.predicate())
- << "\" " << op.getOperand(0) << ", " << op.getOperand(1);
+ p << " \"" << stringifyFCmpPredicate(op.predicate()) << "\" "
+ << op.getOperand(0) << ", " << op.getOperand(1);
p.printOptionalAttrDict(processFMFAttr(op->getAttrs()), {"predicate"});
p << " : " << op.lhs().getType();
}
auto funcTy = FunctionType::get(op.getContext(), {op.arraySize().getType()},
{op.getType()});
- p << op.getOperationName() << ' ' << op.arraySize() << " x " << elemTy;
+ p << ' ' << op.arraySize() << " x " << elemTy;
if (op.alignment().hasValue() && *op.alignment() != 0)
p.printOptionalAttrDict(op->getAttrs());
else
}
static void printLoadOp(OpAsmPrinter &p, LoadOp &op) {
- p << op.getOperationName() << ' ';
+ p << ' ';
if (op.volatile_())
p << "volatile ";
p << op.addr();
}
static void printStoreOp(OpAsmPrinter &p, StoreOp &op) {
- p << op.getOperationName() << ' ';
+ p << ' ';
if (op.volatile_())
p << "volatile ";
p << op.value() << ", " << op.addr();
auto callee = op.callee();
bool isDirect = callee.hasValue();
- p << op.getOperationName() << ' ';
+ p << ' ';
// Either function name or pointer
if (isDirect)
}
static void printLandingpadOp(OpAsmPrinter &p, LandingpadOp &op) {
- p << op.getOperationName() << (op.cleanup() ? " cleanup " : " ");
+ p << (op.cleanup() ? " cleanup " : " ");
// Clauses
for (auto value : op.getOperands()) {
// Print the direct callee if present as a function attribute, or an indirect
// callee (first operand) otherwise.
- p << op.getOperationName() << ' ';
+ p << ' ';
if (isDirect)
p.printSymbolName(callee.getValue());
else
}
static void printExtractElementOp(OpAsmPrinter &p, ExtractElementOp &op) {
- p << op.getOperationName() << ' ' << op.vector() << "[" << op.position()
- << " : " << op.position().getType() << "]";
+ p << ' ' << op.vector() << "[" << op.position() << " : "
+ << op.position().getType() << "]";
p.printOptionalAttrDict(op->getAttrs());
p << " : " << op.vector().getType();
}
//===----------------------------------------------------------------------===//
static void printExtractValueOp(OpAsmPrinter &p, ExtractValueOp &op) {
- p << op.getOperationName() << ' ' << op.container() << op.position();
+ p << ' ' << op.container() << op.position();
p.printOptionalAttrDict(op->getAttrs(), {"position"});
p << " : " << op.container().getType();
}
//===----------------------------------------------------------------------===//
static void printInsertElementOp(OpAsmPrinter &p, InsertElementOp &op) {
- p << op.getOperationName() << ' ' << op.value() << ", " << op.vector() << "["
- << op.position() << " : " << op.position().getType() << "]";
+ p << ' ' << op.value() << ", " << op.vector() << "[" << op.position() << " : "
+ << op.position().getType() << "]";
p.printOptionalAttrDict(op->getAttrs());
p << " : " << op.vector().getType();
}
//===----------------------------------------------------------------------===//
static void printInsertValueOp(OpAsmPrinter &p, InsertValueOp &op) {
- p << op.getOperationName() << ' ' << op.value() << ", " << op.container()
- << op.position();
+ p << ' ' << op.value() << ", " << op.container() << op.position();
p.printOptionalAttrDict(op->getAttrs(), {"position"});
p << " : " << op.container().getType();
}
//===----------------------------------------------------------------------===//
static void printReturnOp(OpAsmPrinter &p, ReturnOp op) {
- p << op.getOperationName();
p.printOptionalAttrDict(op->getAttrs());
assert(op.getNumOperands() <= 1);
}
static void printGlobalOp(OpAsmPrinter &p, GlobalOp op) {
- p << op.getOperationName() << ' ' << stringifyLinkage(op.linkage()) << ' ';
+ p << ' ' << stringifyLinkage(op.linkage()) << ' ';
if (op.unnamed_addr())
p << stringifyUnnamedAddr(*op.unnamed_addr()) << ' ';
if (op.constant())
}
static void printShuffleVectorOp(OpAsmPrinter &p, ShuffleVectorOp &op) {
- p << op.getOperationName() << ' ' << op.v1() << ", " << op.v2() << " "
- << op.mask();
+ p << ' ' << op.v1() << ", " << op.v2() << " " << op.mask();
p.printOptionalAttrDict(op->getAttrs(), {"mask"});
p << " : " << op.v1().getType() << ", " << op.v2().getType();
}
// helper functions. Drops "void" result since it cannot be parsed back. Skips
// the external linkage since it is the default value.
static void printLLVMFuncOp(OpAsmPrinter &p, LLVMFuncOp op) {
- p << op.getOperationName() << ' ';
+ p << ' ';
if (op.linkage() != LLVM::Linkage::External)
p << stringifyLinkage(op.linkage()) << ' ';
p.printSymbolName(op.getName());
//===----------------------------------------------------------------------===//
static void printAtomicRMWOp(OpAsmPrinter &p, AtomicRMWOp &op) {
- p << op.getOperationName() << ' ' << stringifyAtomicBinOp(op.bin_op()) << ' '
- << op.ptr() << ", " << op.val() << ' '
- << stringifyAtomicOrdering(op.ordering()) << ' ';
+ p << ' ' << stringifyAtomicBinOp(op.bin_op()) << ' ' << op.ptr() << ", "
+ << op.val() << ' ' << stringifyAtomicOrdering(op.ordering()) << ' ';
p.printOptionalAttrDict(op->getAttrs(), {"bin_op", "ordering"});
p << " : " << op.res().getType();
}
//===----------------------------------------------------------------------===//
static void printAtomicCmpXchgOp(OpAsmPrinter &p, AtomicCmpXchgOp &op) {
- p << op.getOperationName() << ' ' << op.ptr() << ", " << op.cmp() << ", "
- << op.val() << ' ' << stringifyAtomicOrdering(op.success_ordering()) << ' '
+ p << ' ' << op.ptr() << ", " << op.cmp() << ", " << op.val() << ' '
+ << stringifyAtomicOrdering(op.success_ordering()) << ' '
<< stringifyAtomicOrdering(op.failure_ordering());
p.printOptionalAttrDict(op->getAttrs(),
{"success_ordering", "failure_ordering"});
static void printFenceOp(OpAsmPrinter &p, FenceOp &op) {
StringRef syncscopeKeyword = "syncscope";
- p << op.getOperationName() << ' ';
+ p << ' ';
if (!op->getAttr(syncscopeKeyword).cast<StringAttr>().getValue().empty())
p << "syncscope(" << op->getAttr(syncscopeKeyword) << ") ";
p << stringifyAtomicOrdering(op.ordering());
//===----------------------------------------------------------------------===//
static void printNVVMIntrinsicOp(OpAsmPrinter &p, Operation *op) {
- p << op->getName() << " " << op->getOperands();
+ p << " " << op->getOperands();
if (op->getNumResults() > 0)
p << " : " << op->getResultTypes();
}
static void printWMMAMmaF16F16M16N16K16Op(OpAsmPrinter &p,
WMMAMmaF16F16M16N16K16Op &op) {
- p << op.getOperationName();
p << ' ';
p << op.args();
p.printOptionalAttrDict(op->getAttrs(), {});
}
static void print(OpAsmPrinter &p, GenericOp op) {
- p << op.getOperationName() << " ";
+ p << " ";
// Print extra attributes.
auto genericAttrNames = op.linalgTraitAttrNames();
//===----------------------------------------------------------------------===//
static void print(OpAsmPrinter &p, linalg::YieldOp op) {
- p << op.getOperationName();
if (op.getNumOperands() > 0)
p << ' ' << op.getOperands();
p.printOptionalAttrDict(op->getAttrs());
}
static void print(OpAsmPrinter &p, TiledLoopOp op) {
- p << op.getOperationName() << " (" << op.getInductionVars() << ") = ("
- << op.lowerBound() << ") to (" << op.upperBound() << ") step (" << op.step()
- << ")";
+ p << " (" << op.getInductionVars() << ") = (" << op.lowerBound() << ") to ("
+ << op.upperBound() << ") step (" << op.step() << ")";
if (!op.inputs().empty()) {
p << " ins (";
auto src = dimOp.source().template dyn_cast<BlockArgument>();
if (!src)
return failure();
- auto loopOp = dyn_cast<TiledLoopOp>(
- src.getOwner()->getParent()->getParentOp());
+ auto loopOp =
+ dyn_cast<TiledLoopOp>(src.getOwner()->getParent()->getParentOp());
if (!loopOp)
return failure();
template <typename NamedStructuredOpType>
static void printNamedStructuredOp(OpAsmPrinter &p, NamedStructuredOpType op) {
- p << op.getOperationName();
p.printOptionalAttrDict(
op->getAttrs(),
/*elidedAttrs=*/{"operand_segment_sizes",
static void print(OpAsmPrinter &p, AllocaScopeOp &op) {
bool printBlockTerminators = false;
- p << AllocaScopeOp::getOperationName() << " ";
+ p << " ";
if (!op.results().empty()) {
p << " -> (" << op.getResultTypes() << ")";
printBlockTerminators = true;
}
void DmaStartOp::print(OpAsmPrinter &p) {
- p << getOperationName() << " " << getSrcMemRef() << '[' << getSrcIndices()
- << "], " << getDstMemRef() << '[' << getDstIndices() << "], "
- << getNumElements() << ", " << getTagMemRef() << '[' << getTagIndices()
- << ']';
+ p << " " << getSrcMemRef() << '[' << getSrcIndices() << "], "
+ << getDstMemRef() << '[' << getDstIndices() << "], " << getNumElements()
+ << ", " << getTagMemRef() << '[' << getTagIndices() << ']';
if (isStrided())
p << ", " << getStride() << ", " << getNumElementsPerStride();
}
void DmaWaitOp::print(OpAsmPrinter &p) {
- p << getOperationName() << " " << getTagMemRef() << '[' << getTagIndices()
- << "], " << getNumElements();
+ p << " " << getTagMemRef() << '[' << getTagIndices() << "], "
+ << getNumElements();
p.printOptionalAttrDict((*this)->getAttrs());
p << " : " << getTagMemRef().getType();
}
//===----------------------------------------------------------------------===//
static void print(OpAsmPrinter &p, PrefetchOp op) {
- p << PrefetchOp::getOperationName() << " " << op.memref() << '[';
+ p << " " << op.memref() << '[';
p.printOperands(op.indices());
p << ']' << ", " << (op.isWrite() ? "write" : "read");
p << ", locality<" << op.localityHint();
// transpose $in $permutation attr-dict : type($in) `to` type(results)
static void print(OpAsmPrinter &p, TransposeOp op) {
- p << "memref.transpose " << op.in() << " " << op.permutation();
+ p << " " << op.in() << " " << op.permutation();
p.printOptionalAttrDict(op->getAttrs(),
{TransposeOp::getPermutationAttrName()});
p << " : " << op.in().getType() << " to " << op.getType();
}
static void print(OpAsmPrinter &p, ViewOp op) {
- p << op.getOperationName() << ' ' << op.getOperand(0) << '[';
+ p << ' ' << op.getOperand(0) << '[';
p.printOperand(op.byte_shift());
p << "][" << op.sizes() << ']';
p.printOptionalAttrDict(op->getAttrs());
}
static void print(OpAsmPrinter &printer, ParallelOp &op) {
- printer << ParallelOp::getOperationName();
-
// async()?
if (Value async = op.async())
printer << " " << ParallelOp::getAsyncKeyword() << "(" << async << ": "
}
static void print(OpAsmPrinter &printer, LoopOp &op) {
- printer << LoopOp::getOperationName();
-
unsigned execMapping = op.exec_mapping();
if (execMapping & OpenACCExecMapping::GANG) {
printer << " " << LoopOp::getGangKeyword();
}
static void printParallelOp(OpAsmPrinter &p, ParallelOp op) {
- p << "omp.parallel";
-
if (auto ifCond = op.if_expr_var())
p << " if(" << ifCond << " : " << ifCond.getType() << ")";
static void printWsLoopOp(OpAsmPrinter &p, WsLoopOp op) {
auto args = op.getRegion().front().getArguments();
- p << op.getOperationName() << " (" << args << ") : " << args[0].getType()
- << " = (" << op.lowerBound() << ") to (" << op.upperBound() << ") step ("
- << op.step() << ")";
+ p << " (" << args << ") : " << args[0].getType() << " = (" << op.lowerBound()
+ << ") to (" << op.upperBound() << ") step (" << op.step() << ")";
// Print private, firstprivate, shared and copyin parameters
auto printDataVars = [&p](StringRef name, OperandRange vars) {
}
static void print(OpAsmPrinter &p, ExecuteRegionOp op) {
- p << ExecuteRegionOp::getOperationName();
p.printOptionalArrowTypeList(op.getResultTypes());
p.printRegion(op.region(),
}
static void print(OpAsmPrinter &p, ForOp op) {
- p << op.getOperationName() << " " << op.getInductionVar() << " = "
- << op.lowerBound() << " to " << op.upperBound() << " step " << op.step();
+ p << " " << op.getInductionVar() << " = " << op.lowerBound() << " to "
+ << op.upperBound() << " step " << op.step();
printInitializationList(p, op.getRegionIterArgs(), op.getIterOperands(),
" iter_args");
static void print(OpAsmPrinter &p, IfOp op) {
bool printBlockTerminators = false;
- p << IfOp::getOperationName() << " " << op.condition();
+ p << " " << op.condition();
if (!op.results().empty()) {
p << " -> (" << op.getResultTypes() << ")";
// Print yield explicitly if the op defines values.
}
static void print(OpAsmPrinter &p, ParallelOp op) {
- p << op.getOperationName() << " (" << op.getBody()->getArguments() << ") = ("
- << op.lowerBound() << ") to (" << op.upperBound() << ") step (" << op.step()
- << ")";
+ p << " (" << op.getBody()->getArguments() << ") = (" << op.lowerBound()
+ << ") to (" << op.upperBound() << ") step (" << op.step() << ")";
if (!op.initVals().empty())
p << " init (" << op.initVals() << ")";
p.printOptionalArrowTypeList(op.getResultTypes());
}
static void print(OpAsmPrinter &p, ReduceOp op) {
- p << op.getOperationName() << "(" << op.operand() << ") ";
+ p << "(" << op.operand() << ") ";
p << " : " << op.operand().getType();
p.printRegion(op.reductionOperator());
}
/// Prints a `while` op.
static void print(OpAsmPrinter &p, scf::WhileOp op) {
- p << op.getOperationName();
printInitializationList(p, op.before().front().getArguments(), op.inits(),
" ");
p << " : ";
// Prints an atomic update op.
static void printAtomicUpdateOp(Operation *op, OpAsmPrinter &printer) {
- printer << op->getName() << " \"";
+ printer << " \"";
auto scopeAttr = op->getAttrOfType<IntegerAttr>(kMemoryScopeAttrName);
printer << spirv::stringifyScope(
static_cast<spirv::Scope>(scopeAttr.getInt()))
static void printGroupNonUniformArithmeticOp(Operation *groupOp,
OpAsmPrinter &printer) {
- printer << groupOp->getName() << " \""
+ printer << " \""
<< stringifyScope(static_cast<spirv::Scope>(
groupOp->getAttrOfType<IntegerAttr>(kExecutionScopeAttrName)
.getInt()))
}
static void printUnaryOp(Operation *unaryOp, OpAsmPrinter &printer) {
- printer << unaryOp->getName() << ' ' << unaryOp->getOperand(0) << " : "
+ printer << ' ' << unaryOp->getOperand(0) << " : "
<< unaryOp->getOperand(0).getType();
}
}
static void printLogicalOp(Operation *logicalOp, OpAsmPrinter &printer) {
- printer << logicalOp->getName() << ' ' << logicalOp->getOperands() << " : "
+ printer << ' ' << logicalOp->getOperands() << " : "
<< logicalOp->getOperand(0).getType();
}
static void printShiftOp(Operation *op, OpAsmPrinter &printer) {
Value base = op->getOperand(0);
Value shift = op->getOperand(1);
- printer << op->getName() << ' ' << base << ", " << shift << " : "
- << base.getType() << ", " << shift.getType();
+ printer << ' ' << base << ", " << shift << " : " << base.getType() << ", "
+ << shift.getType();
}
static LogicalResult verifyShiftOp(Operation *op) {
template <typename Op>
static void printAccessChain(Op op, ValueRange indices, OpAsmPrinter &printer) {
- printer << Op::getOperationName() << ' ' << op.base_ptr() << '[' << indices
+ printer << ' ' << op.base_ptr() << '[' << indices
<< "] : " << op.base_ptr().getType() << ", " << indices.getTypes();
}
static void print(spirv::AtomicCompareExchangeWeakOp atomOp,
OpAsmPrinter &printer) {
- printer << spirv::AtomicCompareExchangeWeakOp::getOperationName() << " \""
- << stringifyScope(atomOp.memory_scope()) << "\" \""
+ printer << " \"" << stringifyScope(atomOp.memory_scope()) << "\" \""
<< stringifyMemorySemantics(atomOp.equal_semantics()) << "\" \""
<< stringifyMemorySemantics(atomOp.unequal_semantics()) << "\" "
<< atomOp.getOperands() << " : " << atomOp.pointer().getType();
}
static void print(spirv::BranchConditionalOp branchOp, OpAsmPrinter &printer) {
- printer << spirv::BranchConditionalOp::getOperationName() << ' '
- << branchOp.condition();
+ printer << ' ' << branchOp.condition();
if (auto weights = branchOp.branch_weights()) {
printer << " [";
static void print(spirv::CompositeConstructOp compositeConstructOp,
OpAsmPrinter &printer) {
- printer << spirv::CompositeConstructOp::getOperationName() << " "
- << compositeConstructOp.constituents() << " : "
+ printer << " " << compositeConstructOp.constituents() << " : "
<< compositeConstructOp.getResult().getType();
}
static void print(spirv::CompositeExtractOp compositeExtractOp,
OpAsmPrinter &printer) {
- printer << spirv::CompositeExtractOp::getOperationName() << ' '
- << compositeExtractOp.composite() << compositeExtractOp.indices()
- << " : " << compositeExtractOp.composite().getType();
+ printer << ' ' << compositeExtractOp.composite()
+ << compositeExtractOp.indices() << " : "
+ << compositeExtractOp.composite().getType();
}
static LogicalResult verify(spirv::CompositeExtractOp compExOp) {
static void print(spirv::CompositeInsertOp compositeInsertOp,
OpAsmPrinter &printer) {
- printer << spirv::CompositeInsertOp::getOperationName() << " "
- << compositeInsertOp.object() << ", " << compositeInsertOp.composite()
- << compositeInsertOp.indices() << " : "
- << compositeInsertOp.object().getType() << " into "
+ printer << " " << compositeInsertOp.object() << ", "
+ << compositeInsertOp.composite() << compositeInsertOp.indices()
+ << " : " << compositeInsertOp.object().getType() << " into "
<< compositeInsertOp.composite().getType();
}
}
static void print(spirv::ConstantOp constOp, OpAsmPrinter &printer) {
- printer << spirv::ConstantOp::getOperationName() << ' ' << constOp.value();
+ printer << ' ' << constOp.value();
if (constOp.getType().isa<spirv::ArrayType>())
printer << " : " << constOp.getType();
}
}
static void print(spirv::EntryPointOp entryPointOp, OpAsmPrinter &printer) {
- printer << spirv::EntryPointOp::getOperationName() << " \""
- << stringifyExecutionModel(entryPointOp.execution_model()) << "\" ";
+ printer << " \"" << stringifyExecutionModel(entryPointOp.execution_model())
+ << "\" ";
printer.printSymbolName(entryPointOp.fn());
auto interfaceVars = entryPointOp.interface().getValue();
if (!interfaceVars.empty()) {
}
static void print(spirv::ExecutionModeOp execModeOp, OpAsmPrinter &printer) {
- printer << spirv::ExecutionModeOp::getOperationName() << " ";
+ printer << " ";
printer.printSymbolName(execModeOp.fn());
printer << " \"" << stringifyExecutionMode(execModeOp.execution_mode())
<< "\"";
static void print(spirv::FuncOp fnOp, OpAsmPrinter &printer) {
// Print function name, signature, and control.
- printer << spirv::FuncOp::getOperationName() << " ";
+ printer << " ";
printer.printSymbolName(fnOp.sym_name());
auto fnType = fnOp.getType();
function_like_impl::printFunctionSignature(printer, fnOp, fnType.getInputs(),
auto *op = varOp.getOperation();
SmallVector<StringRef, 4> elidedAttrs{
spirv::attributeName<spirv::StorageClass>()};
- printer << spirv::GlobalVariableOp::getOperationName();
// Print variable name.
printer << ' ';
static void print(spirv::SubgroupBlockReadINTELOp blockReadOp,
OpAsmPrinter &printer) {
SmallVector<StringRef, 4> elidedAttrs;
- printer << spirv::SubgroupBlockReadINTELOp::getOperationName() << " "
- << blockReadOp.ptr();
+ printer << " " << blockReadOp.ptr();
printer << " : " << blockReadOp.getType();
}
static void print(spirv::SubgroupBlockWriteINTELOp blockWriteOp,
OpAsmPrinter &printer) {
SmallVector<StringRef, 4> elidedAttrs;
- printer << spirv::SubgroupBlockWriteINTELOp::getOperationName() << " "
- << blockWriteOp.ptr() << ", " << blockWriteOp.value();
+ printer << " " << blockWriteOp.ptr() << ", " << blockWriteOp.value();
printer << " : " << blockWriteOp.value().getType();
}
SmallVector<StringRef, 4> elidedAttrs;
StringRef sc = stringifyStorageClass(
loadOp.ptr().getType().cast<spirv::PointerType>().getStorageClass());
- printer << spirv::LoadOp::getOperationName() << " \"" << sc << "\" "
- << loadOp.ptr();
+ printer << " \"" << sc << "\" " << loadOp.ptr();
printMemoryAccessAttribute(loadOp, printer, elidedAttrs);
static void print(spirv::LoopOp loopOp, OpAsmPrinter &printer) {
auto *op = loopOp.getOperation();
- printer << spirv::LoopOp::getOperationName();
auto control = loopOp.loop_control();
if (control != spirv::LoopControl::None)
printer << " control(" << spirv::stringifyLoopControl(control) << ")";
}
static void print(spirv::ModuleOp moduleOp, OpAsmPrinter &printer) {
- printer << spirv::ModuleOp::getOperationName();
-
if (Optional<StringRef> name = moduleOp.getName()) {
printer << ' ';
printer.printSymbolName(*name);
static void print(spirv::SelectionOp selectionOp, OpAsmPrinter &printer) {
auto *op = selectionOp.getOperation();
-
- printer << spirv::SelectionOp::getOperationName();
auto control = selectionOp.selection_control();
if (control != spirv::SelectionControl::None)
printer << " control(" << spirv::stringifySelectionControl(control) << ")";
}
static void print(spirv::SpecConstantOp constOp, OpAsmPrinter &printer) {
- printer << spirv::SpecConstantOp::getOperationName() << ' ';
+ printer << ' ';
printer.printSymbolName(constOp.sym_name());
if (auto specID = constOp->getAttrOfType<IntegerAttr>(kSpecIdAttrName))
printer << ' ' << kSpecIdAttrName << '(' << specID.getInt() << ')';
SmallVector<StringRef, 4> elidedAttrs;
StringRef sc = stringifyStorageClass(
storeOp.ptr().getType().cast<spirv::PointerType>().getStorageClass());
- printer << spirv::StoreOp::getOperationName() << " \"" << sc << "\" "
- << storeOp.ptr() << ", " << storeOp.value();
+ printer << " \"" << sc << "\" " << storeOp.ptr() << ", " << storeOp.value();
printMemoryAccessAttribute(storeOp, printer, elidedAttrs);
static void print(spirv::VariableOp varOp, OpAsmPrinter &printer) {
SmallVector<StringRef, 4> elidedAttrs{
spirv::attributeName<spirv::StorageClass>()};
- printer << spirv::VariableOp::getOperationName();
-
// Print optional initializer
if (varOp.getNumOperands() != 0)
printer << " init(" << varOp.initializer() << ")";
}
static void print(spirv::CooperativeMatrixLoadNVOp M, OpAsmPrinter &printer) {
- printer << spirv::CooperativeMatrixLoadNVOp::getOperationName() << " "
- << M.pointer() << ", " << M.stride() << ", " << M.columnmajor();
+ printer << " " << M.pointer() << ", " << M.stride() << ", "
+ << M.columnmajor();
// Print optional memory access attribute.
if (auto memAccess = M.memory_access())
printer << " [\"" << stringifyMemoryAccess(*memAccess) << "\"]";
static void print(spirv::CooperativeMatrixStoreNVOp coopMatrix,
OpAsmPrinter &printer) {
- printer << spirv::CooperativeMatrixStoreNVOp::getOperationName() << " "
- << coopMatrix.pointer() << ", " << coopMatrix.object() << ", "
+ printer << " " << coopMatrix.pointer() << ", " << coopMatrix.object() << ", "
<< coopMatrix.stride() << ", " << coopMatrix.columnmajor();
// Print optional memory access attribute.
if (auto memAccess = coopMatrix.memory_access())
static void print(spirv::CopyMemoryOp copyMemory, OpAsmPrinter &printer) {
auto *op = copyMemory.getOperation();
- printer << spirv::CopyMemoryOp::getOperationName() << ' ';
+ printer << ' ';
StringRef targetStorageClass =
stringifyStorageClass(copyMemory.target()
}
static void print(spirv::SpecConstantCompositeOp op, OpAsmPrinter &printer) {
- printer << spirv::SpecConstantCompositeOp::getOperationName() << " ";
+ printer << " ";
printer.printSymbolName(op.sym_name());
printer << " (";
auto constituents = op.constituents().getValue();
}
static void print(spirv::SpecConstantOperationOp op, OpAsmPrinter &printer) {
- printer << op.getOperationName() << " wraps ";
+ printer << " wraps ";
printer.printGenericOp(&op.body().front().front());
}
static void print(OpAsmPrinter &p, AssumingOp op) {
bool yieldsResults = !op.results().empty();
- p << AssumingOp::getOperationName() << " " << op.witness();
+ p << " " << op.witness();
if (yieldsResults) {
p << " -> (" << op.getResultTypes() << ")";
}
//===----------------------------------------------------------------------===//
static void print(OpAsmPrinter &p, ConstShapeOp &op) {
- p << "shape.const_shape ";
+ p << " ";
p.printOptionalAttrDict(op->getAttrs(), /*elidedAttrs=*/{"shape"});
p << "[";
interleaveComma(op.shape().getValues<int64_t>(), p,
}
void print(OpAsmPrinter &p, FunctionLibraryOp op) {
- p << op.getOperationName() << ' ';
+ p << ' ';
p.printSymbolName(op.getName());
p.printOptionalAttrDictWithKeyword(
op->getAttrs(), {SymbolTable::getSymbolAttrName(), "mapping"});
}
static void print(OpAsmPrinter &p, ReduceOp op) {
- p << op.getOperationName() << '(' << op.shape() << ", " << op.initVals()
+ p << '(' << op.shape() << ", " << op.initVals()
<< ") : " << op.shape().getType();
p.printOptionalArrowTypeList(op.getResultTypes());
p.printRegion(op.region());
assert(op->getNumOperands() == 1 && "unary op should have one operand");
assert(op->getNumResults() == 1 && "unary op should have one result");
- int stdDotLen = StandardOpsDialect::getDialectNamespace().size() + 1;
- p << op->getName().getStringRef().drop_front(stdDotLen) << ' '
- << op->getOperand(0);
+ p << ' ' << op->getOperand(0);
p.printOptionalAttrDict(op->getAttrs());
p << " : " << op->getOperand(0).getType();
}
return;
}
- int stdDotLen = StandardOpsDialect::getDialectNamespace().size() + 1;
- p << op->getName().getStringRef().drop_front(stdDotLen) << ' '
- << op->getOperand(0) << ", " << op->getOperand(1);
+ p << ' ' << op->getOperand(0) << ", " << op->getOperand(1);
p.printOptionalAttrDict(op->getAttrs());
// Now we can output only one type for all operands and the result.
return;
}
- int stdDotLen = StandardOpsDialect::getDialectNamespace().size() + 1;
- p << op->getName().getStringRef().drop_front(stdDotLen) << ' '
- << op->getOperand(0) << ", " << op->getOperand(1) << ", "
+ p << ' ' << op->getOperand(0) << ", " << op->getOperand(1) << ", "
<< op->getOperand(2);
p.printOptionalAttrDict(op->getAttrs());
/// A custom cast operation printer that omits the "std." prefix from the
/// operation names.
static void printStandardCastOp(Operation *op, OpAsmPrinter &p) {
- int stdDotLen = StandardOpsDialect::getDialectNamespace().size() + 1;
- p << op->getName().getStringRef().drop_front(stdDotLen) << ' '
- << op->getOperand(0) << " : " << op->getOperand(0).getType() << " to "
- << op->getResult(0).getType();
+ p << ' ' << op->getOperand(0) << " : " << op->getOperand(0).getType()
+ << " to " << op->getResult(0).getType();
}
void StandardOpsDialect::initialize() {
}
static void print(OpAsmPrinter &p, GenericAtomicRMWOp op) {
- p << op.getOperationName() << ' ' << op.memref() << "[" << op.indices()
+ p << ' ' << op.memref() << "[" << op.indices()
<< "] : " << op.memref().getType();
p.printRegion(op.body());
p.printOptionalAttrDict(op->getAttrs());
//===----------------------------------------------------------------------===//
static void print(OpAsmPrinter &p, ConstantOp &op) {
- p << "constant ";
+ p << " ";
p.printOptionalAttrDict(op->getAttrs(), /*elidedAttrs=*/{"value"});
if (op->getAttrs().size() > 1)
}
static void print(OpAsmPrinter &p, SelectOp op) {
- p << "select " << op.getOperands();
+ p << " " << op.getOperands();
p.printOptionalAttrDict(op->getAttrs());
p << " : ";
if (ShapedType condType = op.getCondition().getType().dyn_cast<ShapedType>())
}
static void print(OpAsmPrinter &p, ReductionOp op) {
- p << op.getOperationName() << " \"" << op.kind() << "\", " << op.vector();
+ p << " \"" << op.kind() << "\", " << op.vector();
if (!op.acc().empty())
p << ", " << op.acc();
p << " : " << op.vector().getType() << " into " << op.dest().getType();
attrs.push_back(attr);
auto dictAttr = DictionaryAttr::get(op.getContext(), attrs);
- p << op.getOperationName() << " " << dictAttr << " " << op.lhs() << ", ";
+ p << " " << dictAttr << " " << op.lhs() << ", ";
p << op.rhs() << ", " << op.acc();
if (op.masks().size() == 2)
p << ", " << op.masks();
}
static void print(OpAsmPrinter &p, vector::ExtractOp op) {
- p << op.getOperationName() << " " << op.vector() << op.position();
+ p << " " << op.vector() << op.position();
p.printOptionalAttrDict(op->getAttrs(), {"position"});
p << " : " << op.vector().getType();
}
}
static void print(OpAsmPrinter &p, ShuffleOp op) {
- p << op.getOperationName() << " " << op.v1() << ", " << op.v2() << " "
- << op.mask();
+ p << " " << op.v1() << ", " << op.v2() << " " << op.mask();
p.printOptionalAttrDict(op->getAttrs(), {ShuffleOp::getMaskAttrName()});
p << " : " << op.v1().getType() << ", " << op.v2().getType();
}
}
static void print(OpAsmPrinter &p, OuterProductOp op) {
- p << op.getOperationName() << " " << op.lhs() << ", " << op.rhs();
+ p << " " << op.lhs() << ", " << op.rhs();
if (!op.acc().empty()) {
p << ", " << op.acc();
p.printOptionalAttrDict(op->getAttrs());
"as permutation_map results: ")
<< AffineMapAttr::get(permutationMap);
for (unsigned int i = 0; i < permutationMap.getNumResults(); ++i)
- if (permutationMap.getResult(i).isa<AffineConstantExpr>()
- && !inBounds.getValue()[i].cast<BoolAttr>().getValue())
+ if (permutationMap.getResult(i).isa<AffineConstantExpr>() &&
+ !inBounds.getValue()[i].cast<BoolAttr>().getValue())
return op->emitOpError("requires broadcast dimensions to be in-bounds");
}
}
static void print(OpAsmPrinter &p, TransferReadOp op) {
- p << op.getOperationName() << " " << op.source() << "[" << op.indices()
- << "], " << op.padding();
+ p << " " << op.source() << "[" << op.indices() << "], " << op.padding();
if (op.mask())
p << ", " << op.mask();
printTransferAttrs(p, cast<VectorTransferOpInterface>(op.getOperation()));
// inBounds.
auto dimExpr = permutationMap.getResult(i).dyn_cast<AffineDimExpr>();
assert(dimExpr && "Broadcast dims must be in-bounds");
- auto inBounds = isInBounds(
- op, /*resultIdx=*/i, /*indicesIdx=*/dimExpr.getPosition());
+ auto inBounds =
+ isInBounds(op, /*resultIdx=*/i, /*indicesIdx=*/dimExpr.getPosition());
newInBounds.push_back(inBounds);
// We commit the pattern if it is "more inbounds".
changed |= inBounds;
}
static void print(OpAsmPrinter &p, TransferWriteOp op) {
- p << op.getOperationName() << " " << op.vector() << ", " << op.source() << "["
- << op.indices() << "]";
+ p << " " << op.vector() << ", " << op.source() << "[" << op.indices() << "]";
if (op.mask())
p << ", " << op.mask();
printTransferAttrs(p, cast<VectorTransferOpInterface>(op.getOperation()));
private:
/// Print the given operation in the generic form.
- void printGenericOp(Operation *op) override {
+ void printGenericOp(Operation *op, bool printOpName = true) override {
// Consider nested operations for aliases.
if (op->getNumRegions() != 0) {
for (Region ®ion : op->getRegions())
/// Print the bare location, not including indentation/location/etc.
void printOperation(Operation *op);
/// Print the given operation in the generic form.
- void printGenericOp(Operation *op) override;
+ void printGenericOp(Operation *op, bool printOpName) override;
/// Print the name of the given block.
void printBlockName(Block *block);
// Otherwise try to dispatch to the dialect, if available.
if (Dialect *dialect = op->getDialect()) {
if (auto opPrinter = dialect->getOperationPrinter(op)) {
+ // Print the op name first.
+ StringRef name = op->getName().getStringRef();
+ printEscapedString(name, os);
+ // Print the rest of the op now.
opPrinter(op, *this);
return;
}
}
// Otherwise print with the generic assembly form.
- printGenericOp(op);
+ printGenericOp(op, /*printOpName=*/true);
}
-void OperationPrinter::printGenericOp(Operation *op) {
- os << '"';
- printEscapedString(op->getName().getStringRef(), os);
- os << "\"(";
+void OperationPrinter::printGenericOp(Operation *op, bool printOpName) {
+ if (printOpName) {
+ os << '"';
+ printEscapedString(op->getName().getStringRef(), os);
+ os << '"';
+ }
+ os << '(';
interleaveComma(op->getOperands(), [&](Value value) { printValueID(value); });
os << ')';
auto funcName =
op->getAttrOfType<StringAttr>(SymbolTable::getSymbolAttrName())
.getValue();
- p << op->getName() << ' ';
+ p << ' ';
StringRef visibilityAttrName = SymbolTable::getVisibilityAttrName();
if (auto visibility = op->getAttrOfType<StringAttr>(visibilityAttrName))
#include "mlir/IR/PatternMatch.h"
#include "mlir/IR/TypeUtilities.h"
#include "mlir/Interfaces/FoldInterfaces.h"
+#include "llvm/ADT/StringExtras.h"
#include <numeric>
using namespace mlir;
// The fallback for the printer is to print in the generic assembly form.
void OpState::print(Operation *op, OpAsmPrinter &p) { p.printGenericOp(op); }
+// The fallback for the printer is to print in the generic assembly form.
+void OpState::printOpName(Operation *op, OpAsmPrinter &p) {
+ StringRef name = op->getName().getStringRef();
+ if (name.startswith("std."))
+ name = name.drop_front(4);
+ p.getStream() << name;
+}
/// Emit an error about fatal conditions with this operation, reporting up to
/// any diagnostic handlers that may be listening.
OperationState &result) {
SmallVector<OpAsmParser::OperandType, 2> ops;
Type type;
+ // If the operand list is in-between parentheses, then we have a generic form.
+ // (see the fallback in `printOneResultOp`).
+ llvm::SMLoc loc = parser.getCurrentLocation();
+ if (!parser.parseOptionalLParen()) {
+ if (parser.parseOperandList(ops) || parser.parseRParen() ||
+ parser.parseOptionalAttrDict(result.attributes) ||
+ parser.parseColon() || parser.parseType(type))
+ return failure();
+ auto fnType = type.dyn_cast<FunctionType>();
+ if (!fnType) {
+ parser.emitError(loc, "expected function type");
+ return failure();
+ }
+ if (parser.resolveOperands(ops, fnType.getInputs(), loc, result.operands))
+ return failure();
+ result.addTypes(fnType.getResults());
+ return success();
+ }
return failure(parser.parseOperandList(ops) ||
parser.parseOptionalAttrDict(result.attributes) ||
parser.parseColonType(type) ||
auto resultType = op->getResult(0).getType();
if (llvm::any_of(op->getOperandTypes(),
[&](Type type) { return type != resultType; })) {
- p.printGenericOp(op);
+ p.printGenericOp(op, /*printOpName=*/false);
return;
}
- p << op->getName() << ' ';
+ p << ' ';
p.printOperands(op->getOperands());
p.printOptionalAttrDict(op->getAttrs());
// Now we can output only one type for all operands and the result.
}
void impl::printCastOp(Operation *op, OpAsmPrinter &p) {
- p << op->getName() << ' ' << op->getOperand(0);
+ p << ' ' << op->getOperand(0);
p.printOptionalAttrDict(op->getAttrs());
p << " : " << op->getOperand(0).getType() << " to "
<< op->getResult(0).getType();
%x = atomic_rmw maxf %f, %F[%i] : (f32, memref<10xf32>) -> f32
return %x : f32
}
-// CHECK: %0 = std.generic_atomic_rmw %arg0[%arg2] : memref<10xf32> {
+// CHECK: %0 = generic_atomic_rmw %arg0[%arg2] : memref<10xf32> {
// CHECK: ^bb0([[CUR_VAL:%.*]]: f32):
// CHECK: [[CMP:%.*]] = cmpf ogt, [[CUR_VAL]], [[f]] : f32
// CHECK: [[SELECT:%.*]] = select [[CMP]], [[CUR_VAL]], [[f]] : f32
func @func_with_ops(f32) {
^bb0(%a : f32):
- %sf = addf(%a, %a) : f32 // expected-error {{expected ':'}}
+ %sf = addf(%a, %a) : f32 // expected-error {{'std.addf' expected function type}}
}
// -----
StringRef opName = op->getName().getStringRef();
if (opName == "test.dialect_custom_printer") {
return [](Operation *op, OpAsmPrinter &printer) {
- printer.getStream() << op->getName().getStringRef() << " custom_format";
+ printer.getStream() << " custom_format";
};
}
return {};
}
static void print(OpAsmPrinter &p, ParseIntegerLiteralOp op) {
- p << ParseIntegerLiteralOp::getOperationName();
if (unsigned numResults = op->getNumResults())
p << " : " << numResults;
}
}
static void print(OpAsmPrinter &p, ParseWrappedKeywordOp op) {
- p << ParseWrappedKeywordOp::getOperationName() << " " << op.keyword();
+ p << " " << op.keyword();
}
//===----------------------------------------------------------------------===//
}
static void print(OpAsmPrinter &p, WrappingRegionOp op) {
- p << op.getOperationName() << " wraps ";
+ p << " wraps ";
p.printGenericOp(&op.region().front().front());
}
}
static void print(OpAsmPrinter &p, StringAttrPrettyNameOp op) {
- p << "test.string_attr_pretty_name";
-
// Note that we only need to print the "name" attribute if the asmprinter
// result name disagrees with it. This can happen in strange cases, e.g.
// when there are conflicts.
//===----------------------------------------------------------------------===//
static void print(OpAsmPrinter &p, RegionIfOp op) {
- p << RegionIfOp::getOperationName() << " ";
+ p << " ";
p.printOperands(op.getOperands());
p << ": " << op.getOperandTypes();
p.printArrowTypeList(op.getResultTypes());
}
static void print(SingleNoTerminatorCustomAsmOp op, OpAsmPrinter &printer) {
- printer << op.getOperationName();
printer.printRegion(
op.getRegion(), /*printEntryBlockArgs=*/false,
// This op has a single block without terminators. But explicitly mark
opClass.addMethodAndPrune("void", "print", "::mlir::OpAsmPrinter &p");
auto &body = method->body();
- // Emit the operation name, trimming the prefix if this is the standard
- // dialect.
- body << " p << \"";
- std::string opName = op.getOperationName();
- if (op.getDialectName() == "std")
- body << StringRef(opName).drop_front(4);
- else
- body << opName;
- body << "\";\n";
-
// Flags for if we should emit a space, and if the last element was
// punctuation.
bool shouldEmitSpace = true, lastWasPunctuation = false;