diff --git a/flang/include/flang/Optimizer/Dialect/FIROps.td b/flang/include/flang/Optimizer/Dialect/FIROps.td --- a/flang/include/flang/Optimizer/Dialect/FIROps.td +++ b/flang/include/flang/Optimizer/Dialect/FIROps.td @@ -135,9 +135,8 @@ let results = (outs fir_ReferenceType); - let parser = - "return parseAllocatableOp(wrapAllocaResultType, parser, result);"; - let printer = "printAllocatableOp(p, (*this));"; + let hasCustomAssemblyFormat = 1; + let hasVerifier = 1; let builders = [ OpBuilder<(ins "mlir::Type":$inType, "llvm::StringRef":$uniqName, @@ -166,8 +165,6 @@ CArg<"mlir::ValueRange", "{}">:$shape, CArg<"llvm::ArrayRef", "{}">:$attributes)>]; - let verifier = "return ::verify(*this);"; - let extraClassDeclaration = [{ mlir::Type getAllocatedType(); bool hasLenParams() { return !typeparams().empty(); } @@ -205,9 +202,11 @@ ); let results = (outs fir_HeapType); - let parser = - "return parseAllocatableOp(wrapAllocMemResultType, parser, result);"; - let printer = "printAllocatableOp(p, (*this));"; + let hasCustomAssemblyFormat = 1; + let hasVerifier = 1; + // let parser = + // "return parseAllocatableOp(wrapAllocMemResultType, parser, result);"; + // let printer = "printAllocatableOp(p, (*this));"; let builders = [ OpBuilder<(ins "mlir::Type":$in_type, "llvm::StringRef":$uniq_name, @@ -223,8 +222,6 @@ CArg<"mlir::ValueRange", "{}">:$shape, CArg<"llvm::ArrayRef", "{}">:$attributes)>]; - let verifier = "return ::verify(*this);"; - let extraClassDeclaration = [{ mlir::Type getAllocatedType(); bool hasLenParams() { return !typeparams().empty(); } @@ -279,9 +276,7 @@ let builders = [OpBuilder<(ins "mlir::Value":$refVal)>]; - let parser = "return parseLoadOp(parser, result);"; - - let printer = "::print(p, *this);"; + let hasCustomAssemblyFormat = 1; let extraClassDeclaration = [{ static mlir::ParseResult getElementOf(mlir::Type &ele, mlir::Type ref); @@ -350,11 +345,8 @@ let arguments = (ins AnyType:$value, Arg:$memref); - let parser = "return parseStoreOp(parser, result);"; - - let printer = "::print(p, *this);"; - - let verifier = "return ::verify(*this);"; + let hasCustomAssemblyFormat = 1; + let hasVerifier = 1; let extraClassDeclaration = [{ static mlir::Type elementType(mlir::Type refType); @@ -731,11 +723,8 @@ CArg<"llvm::ArrayRef", "{}">:$destOperands, CArg<"llvm::ArrayRef", "{}">:$attributes)>]; - let parser = "return parseSelectCase(parser, result);"; - - let printer = "::print(p, *this);"; - - let verifier = "return ::verify(*this);"; + let hasCustomAssemblyFormat = 1; + let hasVerifier = 1; let extraClassDeclaration = extraSwitchClassDeclaration#[{ unsigned compareOffsetSize(); @@ -769,11 +758,8 @@ CArg<"llvm::ArrayRef", "{}">:$destOperands, CArg<"llvm::ArrayRef", "{}">:$attributes)>]; - let parser = "return parseSelectType(parser, result);"; - - let printer = "::print(p, *this);"; - - let verifier = "return ::verify(*this);"; + let hasCustomAssemblyFormat = 1; + let hasVerifier = 1; let extraClassDeclaration = extraSwitchClassDeclaration; } @@ -793,9 +779,8 @@ ``` }]; - let parser = "return mlir::success();"; + let assemblyFormat = [{ attr-dict }]; - let printer = ""; } def fir_FirEndOp : fir_Op<"end", [Terminator]> { @@ -1009,11 +994,8 @@ let results = (outs fir_BoxProcType); - let parser = "return parseEmboxProcOp(parser, result);"; - - let printer = "::print(p, *this);"; - - let verifier = "return ::verify(*this);"; + let hasCustomAssemblyFormat = 1; + let hasVerifier = 1; } def fir_UnboxCharOp : fir_SimpleOp<"unboxchar", [NoSideEffect]> { @@ -1754,9 +1736,8 @@ let results = (outs RefOrLLVMPtr); - let parser = "return parseCoordinateCustom(parser, result);"; - let printer = "::print(p, *this);"; - let verifier = "return ::verify(*this);"; + let hasCustomAssemblyFormat = 1; + let hasVerifier = 1; let builders = [ OpBuilder<(ins "mlir::Type":$resultType, @@ -1818,9 +1799,7 @@ Variadic:$typeparams ); - let parser = "return parseFieldIndexOp(parser, result);"; - - let printer = "::print(p, *this);"; + let hasCustomAssemblyFormat = 1; let builders = [OpBuilder<(ins "llvm::StringRef":$fieldName, "mlir::Type":$recTy, CArg<"mlir::ValueRange","{}">:$operands)>]; @@ -2081,9 +2060,7 @@ let arguments = (ins StrAttr:$field_id, TypeAttr:$on_type); - let parser = "return parseLenParamIndexOp(parser, result);"; - - let printer = "::print(p, *this);"; + let hasCustomAssemblyFormat = 1; let builders = [OpBuilder<(ins "llvm::StringRef":$fieldName, "mlir::Type":$recTy), @@ -2388,8 +2365,7 @@ ); let results = (outs Variadic); - let parser = "return parseCallOp(parser, result);"; - let printer = "printCallOp(p, *this);"; + let hasCustomAssemblyFormat = 1; let builders = [ OpBuilder<(ins "mlir::FuncOp":$callee, @@ -2452,9 +2428,7 @@ let results = (outs Variadic); - let parser = "return parseDispatchOp(parser, result);"; - - let printer = "::print(p, *this);"; + let hasCustomAssemblyFormat = 1; let extraClassDeclaration = [{ mlir::FunctionType getFunctionType(); @@ -2490,9 +2464,8 @@ let results = (outs fir_CharacterType); - let parser = "return parseStringLitOp(parser, result);"; - - let printer = "::print(p, *this);"; + let hasCustomAssemblyFormat = 1; + let hasVerifier = 1; let builders = [ OpBuilder<(ins "fir::CharacterType":$inType, @@ -2556,11 +2529,8 @@ let results = (outs fir_ComplexType); - let parser = "return parseConstcOp(parser, result);"; - - let printer = "::print(p, *this);"; - - let verifier = "return ::verify(*this);"; + let hasCustomAssemblyFormat = 1; + let hasVerifier = 1; let extraClassDeclaration = [{ static constexpr llvm::StringRef realAttrName() { return "real"; } @@ -2599,9 +2569,7 @@ let results = (outs AnyLogicalLike); - let parser = "return parseCmpcOp(parser, result);"; - - let printer = "printCmpcOp(p, *this);"; + let hasCustomAssemblyFormat = 1; let builders = [OpBuilder<(ins "mlir::arith::CmpFPredicate":$predicate, "mlir::Value":$lhs, "mlir::Value":$rhs), [{ @@ -2706,13 +2674,10 @@ let arguments = (ins FortranTypeAttr:$in_type); - let parser = "return parseGenTypeDescOp(parser, result);"; - - let printer = "::print(p, *this);"; + let hasCustomAssemblyFormat = 1; + let hasVerifier = 1; let builders = [OpBuilder<(ins "mlir::TypeAttr":$inty)>]; - - let verifier = "return ::verify(*this);"; } def fir_NoReassocOp : fir_OneResultOp<"no_reassoc", @@ -2777,9 +2742,7 @@ let regions = (region AtMostRegion<1>:$region); - let parser = "return parseGlobalOp(parser, result);"; - - let printer = "::print(p, *this);"; + let hasCustomAssemblyFormat = 1; let skipDefaultBuilders = 1; let builders = [ @@ -2862,9 +2825,7 @@ let arguments = (ins StrAttr:$lenparam, APIntAttr:$intval); - let parser = "return parseGlobalLenOp(parser, result);"; - - let printer = "::print(p, *this);"; + let hasCustomAssemblyFormat = 1; let extraClassDeclaration = [{ static constexpr llvm::StringRef lenParamAttrName() { return "lenparam"; } @@ -2894,11 +2855,8 @@ ``` }]; - let parser = "return parseDispatchTableOp(parser, result);"; - - let printer = "::print(p, *this);"; - - let verifier = "return ::verify(*this);"; + let hasCustomAssemblyFormat = 1; + let hasVerifier = 1; let regions = (region SizedRegion<1>:$region); @@ -2940,9 +2898,7 @@ let arguments = (ins StrAttr:$method, SymbolRefAttr:$proc); - let parser = "return parseDTEntryOp(parser, result);"; - - let printer = "::print(p, *this);"; + let hasCustomAssemblyFormat = 1; let extraClassDeclaration = [{ static constexpr llvm::StringRef getMethodAttrNameStr() { return "method"; } diff --git a/flang/lib/Optimizer/Dialect/FIROps.cpp b/flang/lib/Optimizer/Dialect/FIROps.cpp --- a/flang/lib/Optimizer/Dialect/FIROps.cpp +++ b/flang/lib/Optimizer/Dialect/FIROps.cpp @@ -237,17 +237,24 @@ result.addAttributes(attributes); } -static mlir::LogicalResult verify(fir::AllocaOp &op) { +mlir::ParseResult fir::AllocaOp::parse(OpAsmParser &parser, + OperationState &result) { + return parseAllocatableOp(wrapAllocaResultType, parser, result); +} + +void fir::AllocaOp::print(OpAsmPrinter &p) { printAllocatableOp(p, (*this)); } + +mlir::LogicalResult fir::AllocaOp::verify() { llvm::SmallVector visited; - if (verifyInType(op.getInType(), visited, op.numShapeOperands())) - return op.emitOpError("invalid type for allocation"); - if (verifyTypeParamCount(op.getInType(), op.numLenParams())) - return op.emitOpError("LEN params do not correspond to type"); - mlir::Type outType = op.getType(); + if (verifyInType(getInType(), visited, numShapeOperands())) + return emitOpError("invalid type for allocation"); + if (verifyTypeParamCount(getInType(), numLenParams())) + return emitOpError("LEN params do not correspond to type"); + mlir::Type outType = getType(); if (!outType.isa()) - return op.emitOpError("must be a !fir.ref type"); + return emitOpError("must be a !fir.ref type"); if (fir::isa_unknown_size_box(fir::dyn_cast_ptrEleTy(outType))) - return op.emitOpError("cannot allocate !fir.box of unknown rank or type"); + return emitOpError("cannot allocate !fir.box of unknown rank or type"); return mlir::success(); } @@ -306,17 +313,24 @@ result.addAttributes(attributes); } -static mlir::LogicalResult verify(fir::AllocMemOp op) { +mlir::ParseResult AllocMemOp::parse(OpAsmParser &parser, + OperationState &result) { + return parseAllocatableOp(wrapAllocMemResultType, parser, result); +} + +void AllocMemOp::print(OpAsmPrinter &p) { printAllocatableOp(p, (*this)); } + +mlir::LogicalResult AllocMemOp::verify() { llvm::SmallVector visited; - if (verifyInType(op.getInType(), visited, op.numShapeOperands())) - return op.emitOpError("invalid type for allocation"); - if (verifyTypeParamCount(op.getInType(), op.numLenParams())) - return op.emitOpError("LEN params do not correspond to type"); - mlir::Type outType = op.getType(); + if (verifyInType(getInType(), visited, numShapeOperands())) + return emitOpError("invalid type for allocation"); + if (verifyTypeParamCount(getInType(), numLenParams())) + return emitOpError("LEN params do not correspond to type"); + mlir::Type outType = getType(); if (!outType.dyn_cast()) - return op.emitOpError("must be a !fir.heap type"); + return emitOpError("must be a !fir.heap type"); if (fir::isa_unknown_size_box(fir::dyn_cast_ptrEleTy(outType))) - return op.emitOpError("cannot allocate !fir.box of unknown rank or type"); + return emitOpError("cannot allocate !fir.box of unknown rank or type"); return mlir::success(); } @@ -594,24 +608,23 @@ getResultTypes()); } -static void printCallOp(mlir::OpAsmPrinter &p, fir::CallOp &op) { - auto callee = op.callee(); - bool isDirect = callee.hasValue(); +void fir::CallOp::print(mlir::OpAsmPrinter &p) { + bool isDirect = callee().hasValue(); p << ' '; if (isDirect) - p << callee.getValue(); + p << callee().getValue(); else - p << op.getOperand(0); - p << '(' << op->getOperands().drop_front(isDirect ? 0 : 1) << ')'; - p.printOptionalAttrDict(op->getAttrs(), + p << getOperand(0); + p << '(' << (*this)->getOperands().drop_front(isDirect ? 0 : 1) << ')'; + p.printOptionalAttrDict((*this)->getAttrs(), {fir::CallOp::getCalleeAttrNameStr()}); - auto resultTypes{op.getResultTypes()}; + auto resultTypes{getResultTypes()}; llvm::SmallVector argTypes( - llvm::drop_begin(op.getOperandTypes(), isDirect ? 0 : 1)); - p << " : " << FunctionType::get(op.getContext(), argTypes, resultTypes); + llvm::drop_begin(getOperandTypes(), isDirect ? 0 : 1)); + p << " : " << FunctionType::get(getContext(), argTypes, resultTypes); } -static mlir::ParseResult parseCallOp(mlir::OpAsmParser &parser, +mlir::ParseResult fir::CallOp::parse(mlir::OpAsmParser &parser, mlir::OperationState &result) { llvm::SmallVector operands; if (parser.parseOperandList(operands)) @@ -759,10 +772,10 @@ return pred.getValue(); } -static void printCmpcOp(OpAsmPrinter &p, fir::CmpcOp op) { printCmpOp(p, op); } +void CmpcOp::print(OpAsmPrinter &p) { printCmpOp(p, *this); } -mlir::ParseResult fir::parseCmpcOp(mlir::OpAsmParser &parser, - mlir::OperationState &result) { +mlir::ParseResult CmpcOp::parse(mlir::OpAsmParser &parser, + mlir::OperationState &result) { return parseCmpOp(parser, result); } @@ -770,8 +783,8 @@ // ConstcOp //===----------------------------------------------------------------------===// -static mlir::ParseResult parseConstcOp(mlir::OpAsmParser &parser, - mlir::OperationState &result) { +mlir::ParseResult ConstcOp::parse(mlir::OpAsmParser &parser, + mlir::OperationState &result) { fir::RealAttr realp; fir::RealAttr imagp; mlir::Type type; @@ -787,16 +800,16 @@ return mlir::success(); } -static void print(mlir::OpAsmPrinter &p, fir::ConstcOp &op) { +void ConstcOp::print(mlir::OpAsmPrinter &p) { p << '('; - p << op.getOperation()->getAttr(fir::ConstcOp::realAttrName()) << ", "; - p << op.getOperation()->getAttr(fir::ConstcOp::imagAttrName()) << ") : "; - p.printType(op.getType()); + p << getOperation()->getAttr(fir::ConstcOp::realAttrName()) << ", "; + p << getOperation()->getAttr(fir::ConstcOp::imagAttrName()) << ") : "; + p.printType(getType()); } -static mlir::LogicalResult verify(fir::ConstcOp &op) { - if (!op.getType().isa()) - return op.emitOpError("must be a !fir.complex type"); +mlir::LogicalResult ConstcOp::verify() { + if (!getType().isa()) + return emitOpError("must be a !fir.complex type"); return mlir::success(); } @@ -869,15 +882,15 @@ // CoordinateOp //===----------------------------------------------------------------------===// -static void print(mlir::OpAsmPrinter &p, fir::CoordinateOp op) { - p << ' ' << op.ref() << ", " << op.coor(); - p.printOptionalAttrDict(op->getAttrs(), /*elideAttrs=*/{"baseType"}); +void CoordinateOp::print(mlir::OpAsmPrinter &p) { + p << ' ' << ref() << ", " << coor(); + p.printOptionalAttrDict((*this)->getAttrs(), /*elideAttrs=*/{"baseType"}); p << " : "; - p.printFunctionalType(op.getOperandTypes(), op->getResultTypes()); + p.printFunctionalType(getOperandTypes(), (*this)->getResultTypes()); } -static mlir::ParseResult parseCoordinateCustom(mlir::OpAsmParser &parser, - mlir::OperationState &result) { +mlir::ParseResult CoordinateOp::parse(mlir::OpAsmParser &parser, + mlir::OperationState &result) { mlir::OpAsmParser::OperandType memref; if (parser.parseOperand(memref) || parser.parseComma()) return mlir::failure(); @@ -899,29 +912,29 @@ return mlir::success(); } -static mlir::LogicalResult verify(fir::CoordinateOp op) { - auto refTy = op.ref().getType(); +mlir::LogicalResult CoordinateOp::verify() { + auto refTy = ref().getType(); if (fir::isa_ref_type(refTy)) { auto eleTy = fir::dyn_cast_ptrEleTy(refTy); if (auto arrTy = eleTy.dyn_cast()) { if (arrTy.hasUnknownShape()) - return op.emitOpError("cannot find coordinate in unknown shape"); + return emitOpError("cannot find coordinate in unknown shape"); if (arrTy.getConstantRows() < arrTy.getDimension() - 1) - return op.emitOpError("cannot find coordinate with unknown extents"); + return emitOpError("cannot find coordinate with unknown extents"); } if (!(fir::isa_aggregate(eleTy) || fir::isa_complex(eleTy) || fir::isa_char_string(eleTy))) - return op.emitOpError("cannot apply coordinate_of to this type"); + return emitOpError("cannot apply coordinate_of to this type"); } // Recovering a LEN type parameter only makes sense from a boxed value. For a // bare reference, the LEN type parameters must be passed as additional // arguments to `op`. - for (auto co : op.coor()) + for (auto co : coor()) if (dyn_cast_or_null(co.getDefiningOp())) { - if (op.getNumOperands() != 2) - return op.emitOpError("len_param_index must be last argument"); - if (!op.ref().getType().isa()) - return op.emitOpError("len_param_index must be used on box type"); + if (getNumOperands() != 2) + return emitOpError("len_param_index must be last argument"); + if (!ref().getType().isa()) + return emitOpError("len_param_index must be used on box type"); } return mlir::success(); } @@ -935,8 +948,8 @@ getResultTypes()); } -static mlir::ParseResult parseDispatchOp(mlir::OpAsmParser &parser, - mlir::OperationState &result) { +mlir::ParseResult DispatchOp::parse(mlir::OpAsmParser &parser, + mlir::OperationState &result) { mlir::FunctionType calleeType; llvm::SmallVector operands; auto calleeLoc = parser.getNameLoc(); @@ -961,16 +974,16 @@ return mlir::success(); } -static void print(mlir::OpAsmPrinter &p, fir::DispatchOp &op) { - p << ' ' << op.getMethodAttr() << '('; - p.printOperand(op.object()); - if (!op.args().empty()) { +void DispatchOp::print(mlir::OpAsmPrinter &p) { + p << ' ' << getMethodAttr() << '('; + p.printOperand(object()); + if (!args().empty()) { p << ", "; - p.printOperands(op.args()); + p.printOperands(args()); } p << ") : "; - p.printFunctionalType(op.getOperation()->getOperandTypes(), - op.getOperation()->getResultTypes()); + p.printFunctionalType(getOperation()->getOperandTypes(), + getOperation()->getResultTypes()); } //===----------------------------------------------------------------------===// @@ -983,8 +996,8 @@ block.getOperations().insert(block.end(), op); } -static mlir::ParseResult parseDispatchTableOp(mlir::OpAsmParser &parser, - mlir::OperationState &result) { +mlir::ParseResult DispatchTableOp::parse(mlir::OpAsmParser &parser, + mlir::OperationState &result) { // Parse the name as a symbol reference attribute. SymbolRefAttr nameAttr; if (parser.parseAttribute(nameAttr, mlir::SymbolTable::getSymbolAttrName(), @@ -1006,14 +1019,14 @@ return mlir::success(); } -static void print(mlir::OpAsmPrinter &p, fir::DispatchTableOp &op) { +void DispatchTableOp::print(mlir::OpAsmPrinter &p) { auto tableName = - op.getOperation() + getOperation() ->getAttrOfType(mlir::SymbolTable::getSymbolAttrName()) .getValue(); p << " @" << tableName; - Region &body = op.getOperation()->getRegion(0); + Region &body = getOperation()->getRegion(0); if (!body.empty()) { p << ' '; p.printRegion(body, /*printEntryBlockArgs=*/false, @@ -1021,8 +1034,8 @@ } } -static mlir::LogicalResult verify(fir::DispatchTableOp &op) { - for (auto &op : op.getBlock()) +mlir::LogicalResult DispatchTableOp::verify() { + for (auto &op : getBlock()) if (!(isa(op) || isa(op))) return op.emitOpError("dispatch table must contain dt_entry"); return mlir::success(); @@ -1077,8 +1090,8 @@ // EmboxProcOp //===----------------------------------------------------------------------===// -static mlir::ParseResult parseEmboxProcOp(mlir::OpAsmParser &parser, - mlir::OperationState &result) { +mlir::ParseResult EmboxProcOp::parse(mlir::OpAsmParser &parser, + mlir::OperationState &result) { mlir::SymbolRefAttr procRef; if (parser.parseAttribute(procRef, "funcname", result.attributes)) return mlir::failure(); @@ -1106,22 +1119,22 @@ return mlir::success(); } -static void print(mlir::OpAsmPrinter &p, fir::EmboxProcOp &op) { - p << ' ' << op.getOperation()->getAttr("funcname"); - auto h = op.host(); +void EmboxProcOp::print(mlir::OpAsmPrinter &p) { + p << ' ' << getOperation()->getAttr("funcname"); + auto h = host(); if (h) { p << ", "; p.printOperand(h); } - p << " : (" << op.getOperation()->getAttr("functype"); + p << " : (" << getOperation()->getAttr("functype"); if (h) p << ", " << h.getType(); - p << ") -> " << op.getType(); + p << ") -> " << getType(); } -static mlir::LogicalResult verify(fir::EmboxProcOp &op) { +mlir::LogicalResult EmboxProcOp::verify() { // host bindings (optional) must be a reference to a tuple - if (auto h = op.host()) { + if (auto h = host()) { if (auto r = h.getType().dyn_cast()) { if (!r.getEleTy().dyn_cast()) return mlir::failure(); @@ -1142,8 +1155,8 @@ result.addTypes(TypeDescType::get(inty.getValue())); } -static mlir::ParseResult parseGenTypeDescOp(mlir::OpAsmParser &parser, - mlir::OperationState &result) { +mlir::ParseResult GenTypeDescOp::parse(mlir::OpAsmParser &parser, + mlir::OperationState &result) { mlir::Type intype; if (parser.parseType(intype)) return mlir::failure(); @@ -1154,18 +1167,18 @@ return mlir::success(); } -static void print(mlir::OpAsmPrinter &p, fir::GenTypeDescOp &op) { - p << ' ' << op.getOperation()->getAttr("in_type"); - p.printOptionalAttrDict(op.getOperation()->getAttrs(), {"in_type"}); +void GenTypeDescOp::print(mlir::OpAsmPrinter &p) { + p << ' ' << getOperation()->getAttr("in_type"); + p.printOptionalAttrDict(getOperation()->getAttrs(), {"in_type"}); } -static mlir::LogicalResult verify(fir::GenTypeDescOp &op) { - mlir::Type resultTy = op.getType(); +mlir::LogicalResult GenTypeDescOp::verify() { + mlir::Type resultTy = getType(); if (auto tdesc = resultTy.dyn_cast()) { - if (tdesc.getOfTy() != op.getInType()) - return op.emitOpError("wrapped type mismatched"); + if (tdesc.getOfTy() != getInType()) + return emitOpError("wrapped type mismatched"); } else { - return op.emitOpError("must be !fir.tdesc type"); + return emitOpError("must be !fir.tdesc type"); } return mlir::success(); } @@ -1178,7 +1191,7 @@ return wrapAllocaResultType(getType()); } -static ParseResult parseGlobalOp(OpAsmParser &parser, OperationState &result) { +ParseResult GlobalOp::parse(OpAsmParser &parser, OperationState &result) { // Parse the optional linkage llvm::StringRef linkage; auto &builder = parser.getBuilder(); @@ -1231,20 +1244,20 @@ return mlir::success(); } -static void print(mlir::OpAsmPrinter &p, fir::GlobalOp &op) { - if (op.linkName().hasValue()) - p << ' ' << op.linkName().getValue(); +void GlobalOp::print(mlir::OpAsmPrinter &p) { + if (linkName().hasValue()) + p << ' ' << linkName().getValue(); p << ' '; - p.printAttributeWithoutType(op.getSymrefAttr()); - if (auto val = op.getValueOrNull()) + p.printAttributeWithoutType(getSymrefAttr()); + if (auto val = getValueOrNull()) p << '(' << val << ')'; - if (op.getOperation()->getAttr(fir::GlobalOp::getConstantAttrNameStr())) + if (getOperation()->getAttr(fir::GlobalOp::getConstantAttrNameStr())) p << " constant"; p << " : "; - p.printType(op.getType()); - if (op.hasInitializationBody()) { + p.printType(getType()); + if (hasInitializationBody()) { p << ' '; - p.printRegion(op.getOperation()->getRegion(0), + p.printRegion(getOperation()->getRegion(0), /*printEntryBlockArgs=*/false, /*printBlockTerminators=*/true); } @@ -1313,8 +1326,8 @@ // GlobalLenOp //===----------------------------------------------------------------------===// -static mlir::ParseResult parseGlobalLenOp(mlir::OpAsmParser &parser, - mlir::OperationState &result) { +mlir::ParseResult GlobalLenOp::parse(mlir::OpAsmParser &parser, + mlir::OperationState &result) { llvm::StringRef fieldName; if (failed(parser.parseOptionalKeyword(&fieldName))) { mlir::StringAttr fieldAttr; @@ -1333,17 +1346,17 @@ return mlir::success(); } -static void print(mlir::OpAsmPrinter &p, fir::GlobalLenOp &op) { - p << ' ' << op.getOperation()->getAttr(fir::GlobalLenOp::lenParamAttrName()) - << ", " << op.getOperation()->getAttr(fir::GlobalLenOp::intAttrName()); +void GlobalLenOp::print(mlir::OpAsmPrinter &p) { + p << ' ' << getOperation()->getAttr(fir::GlobalLenOp::lenParamAttrName()) + << ", " << getOperation()->getAttr(fir::GlobalLenOp::intAttrName()); } //===----------------------------------------------------------------------===// // FieldIndexOp //===----------------------------------------------------------------------===// -static mlir::ParseResult parseFieldIndexOp(mlir::OpAsmParser &parser, - mlir::OperationState &result) { +mlir::ParseResult FieldIndexOp::parse(mlir::OpAsmParser &parser, + mlir::OperationState &result) { llvm::StringRef fieldName; auto &builder = parser.getBuilder(); mlir::Type recty; @@ -1371,17 +1384,17 @@ return mlir::success(); } -static void print(mlir::OpAsmPrinter &p, fir::FieldIndexOp &op) { +void FieldIndexOp::print(mlir::OpAsmPrinter &p) { p << ' ' - << op.getOperation() + << getOperation() ->getAttrOfType(fir::FieldIndexOp::fieldAttrName()) .getValue() - << ", " << op.getOperation()->getAttr(fir::FieldIndexOp::typeAttrName()); - if (op.getNumOperands()) { + << ", " << getOperation()->getAttr(fir::FieldIndexOp::typeAttrName()); + if (getNumOperands()) { p << '('; - p.printOperands(op.typeparams()); + p.printOperands(typeparams()); const auto *sep = ") : "; - for (auto op : op.typeparams()) { + for (auto op : typeparams()) { p << sep; if (op) p.printType(op.getType()); @@ -1778,8 +1791,8 @@ // LenParamIndexOp //===----------------------------------------------------------------------===// -static mlir::ParseResult parseLenParamIndexOp(mlir::OpAsmParser &parser, - mlir::OperationState &result) { +mlir::ParseResult LenParamIndexOp::parse(mlir::OpAsmParser &parser, + mlir::OperationState &result) { llvm::StringRef fieldName; auto &builder = parser.getBuilder(); mlir::Type recty; @@ -1798,13 +1811,13 @@ return mlir::success(); } -static void print(mlir::OpAsmPrinter &p, fir::LenParamIndexOp &op) { +void LenParamIndexOp::print(mlir::OpAsmPrinter &p) { p << ' ' - << op.getOperation() + << getOperation() ->getAttrOfType( fir::LenParamIndexOp::fieldAttrName()) .getValue() - << ", " << op.getOperation()->getAttr(fir::LenParamIndexOp::typeAttrName()); + << ", " << getOperation()->getAttr(fir::LenParamIndexOp::typeAttrName()); } //===----------------------------------------------------------------------===// @@ -1832,8 +1845,8 @@ return mlir::failure(); } -static mlir::ParseResult parseLoadOp(mlir::OpAsmParser &parser, - mlir::OperationState &result) { +mlir::ParseResult LoadOp::parse(mlir::OpAsmParser &parser, + mlir::OperationState &result) { mlir::Type type; mlir::OpAsmParser::OperandType oper; if (parser.parseOperand(oper) || @@ -1848,11 +1861,11 @@ return mlir::success(); } -static void print(mlir::OpAsmPrinter &p, fir::LoadOp &op) { +void LoadOp::print(mlir::OpAsmPrinter &p) { p << ' '; - p.printOperand(op.memref()); - p.printOptionalAttrDict(op.getOperation()->getAttrs(), {}); - p << " : " << op.memref().getType(); + p.printOperand(memref()); + p.printOptionalAttrDict(getOperation()->getAttrs(), {}); + p << " : " << memref().getType(); } //===----------------------------------------------------------------------===// @@ -2081,8 +2094,8 @@ // DTEntryOp //===----------------------------------------------------------------------===// -static mlir::ParseResult parseDTEntryOp(mlir::OpAsmParser &parser, - mlir::OperationState &result) { +mlir::ParseResult DTEntryOp::parse(mlir::OpAsmParser &parser, + mlir::OperationState &result) { llvm::StringRef methodName; // allow `methodName` or `"methodName"` if (failed(parser.parseOptionalKeyword(&methodName))) { @@ -2103,8 +2116,8 @@ return mlir::success(); } -static void print(mlir::OpAsmPrinter &p, fir::DTEntryOp &op) { - p << ' ' << op.getMethodAttr() << ", " << op.getProcAttr(); +void DTEntryOp::print(mlir::OpAsmPrinter &p) { + p << ' ' << getMethodAttr() << ", " << getProcAttr(); } //===----------------------------------------------------------------------===// @@ -2400,8 +2413,8 @@ } // parser for fir.select_case Op -static mlir::ParseResult parseSelectCase(mlir::OpAsmParser &parser, - mlir::OperationState &result) { +mlir::ParseResult SelectCaseOp::parse(mlir::OpAsmParser &parser, + mlir::OperationState &result) { mlir::OpAsmParser::OperandType selector; mlir::Type type; if (parseSelector(parser, result, selector, type)) @@ -2473,20 +2486,19 @@ return mlir::success(); } -static void print(mlir::OpAsmPrinter &p, fir::SelectCaseOp &op) { +void SelectCaseOp::print(mlir::OpAsmPrinter &p) { p << ' '; - p.printOperand(op.getSelector()); - p << " : " << op.getSelector().getType() << " ["; - auto cases = op.getOperation() - ->getAttrOfType(op.getCasesAttr()) - .getValue(); - auto count = op.getNumConditions(); + p.printOperand(getSelector()); + p << " : " << getSelector().getType() << " ["; + auto cases = + getOperation()->getAttrOfType(getCasesAttr()).getValue(); + auto count = getNumConditions(); for (decltype(count) i = 0; i != count; ++i) { if (i) p << ", "; p << cases[i] << ", "; if (!cases[i].isa()) { - auto caseArgs = *op.getCompareOperands(i); + auto caseArgs = *getCompareOperands(i); p.printOperand(*caseArgs.begin()); p << ", "; if (cases[i].isa()) { @@ -2494,13 +2506,12 @@ p << ", "; } } - op.printSuccessorAtIndex(p, i); + printSuccessorAtIndex(p, i); } p << ']'; - p.printOptionalAttrDict(op.getOperation()->getAttrs(), - {op.getCasesAttr(), getCompareOffsetAttr(), - getTargetOffsetAttr(), - op.getOperandSegmentSizeAttr()}); + p.printOptionalAttrDict(getOperation()->getAttrs(), + {getCasesAttr(), getCompareOffsetAttr(), + getTargetOffsetAttr(), getOperandSegmentSizeAttr()}); } unsigned fir::SelectCaseOp::compareOffsetSize() { @@ -2591,31 +2602,30 @@ destOperands, attributes); } -static mlir::LogicalResult verify(fir::SelectCaseOp &op) { - if (!(op.getSelector().getType().isa() || - op.getSelector().getType().isa() || - op.getSelector().getType().isa() || - op.getSelector().getType().isa() || - op.getSelector().getType().isa())) - return op.emitOpError("must be an integer, character, or logical"); - auto cases = op.getOperation() - ->getAttrOfType(op.getCasesAttr()) - .getValue(); - auto count = op.getNumDest(); +mlir::LogicalResult SelectCaseOp::verify() { + if (!(getSelector().getType().isa() || + getSelector().getType().isa() || + getSelector().getType().isa() || + getSelector().getType().isa() || + getSelector().getType().isa())) + return emitOpError("must be an integer, character, or logical"); + auto cases = + getOperation()->getAttrOfType(getCasesAttr()).getValue(); + auto count = getNumDest(); if (count == 0) - return op.emitOpError("must have at least one successor"); - if (op.getNumConditions() != count) - return op.emitOpError("number of conditions and successors don't match"); - if (op.compareOffsetSize() != count) - return op.emitOpError("incorrect number of compare operand groups"); - if (op.targetOffsetSize() != count) - return op.emitOpError("incorrect number of successor operand groups"); + return emitOpError("must have at least one successor"); + if (getNumConditions() != count) + return emitOpError("number of conditions and successors don't match"); + if (compareOffsetSize() != count) + return emitOpError("incorrect number of compare operand groups"); + if (targetOffsetSize() != count) + return emitOpError("incorrect number of successor operand groups"); for (decltype(count) i = 0; i != count; ++i) { auto &attr = cases[i]; if (!(attr.isa() || attr.isa() || attr.isa() || attr.isa() || attr.isa())) - return op.emitOpError("incorrect select case attribute type"); + return emitOpError("incorrect select case attribute type"); } return mlir::success(); } @@ -2695,8 +2705,7 @@ return {getSubOperands(oper, getSubOperands(2, operands, segments), a)}; } -static ParseResult parseSelectType(OpAsmParser &parser, - OperationState &result) { +ParseResult SelectTypeOp::parse(OpAsmParser &parser, OperationState &result) { mlir::OpAsmParser::OperandType selector; mlir::Type type; if (parseSelector(parser, result, selector, type)) @@ -2745,45 +2754,43 @@ getTargetOffsetAttr())); } -static void print(mlir::OpAsmPrinter &p, fir::SelectTypeOp &op) { +void SelectTypeOp::print(mlir::OpAsmPrinter &p) { p << ' '; - p.printOperand(op.getSelector()); - p << " : " << op.getSelector().getType() << " ["; - auto cases = op.getOperation() - ->getAttrOfType(op.getCasesAttr()) - .getValue(); - auto count = op.getNumConditions(); + p.printOperand(getSelector()); + p << " : " << getSelector().getType() << " ["; + auto cases = + getOperation()->getAttrOfType(getCasesAttr()).getValue(); + auto count = getNumConditions(); for (decltype(count) i = 0; i != count; ++i) { if (i) p << ", "; p << cases[i] << ", "; - op.printSuccessorAtIndex(p, i); + printSuccessorAtIndex(p, i); } p << ']'; - p.printOptionalAttrDict(op.getOperation()->getAttrs(), - {op.getCasesAttr(), getCompareOffsetAttr(), + p.printOptionalAttrDict(getOperation()->getAttrs(), + {getCasesAttr(), getCompareOffsetAttr(), getTargetOffsetAttr(), fir::SelectTypeOp::getOperandSegmentSizeAttr()}); } -static mlir::LogicalResult verify(fir::SelectTypeOp &op) { - if (!(op.getSelector().getType().isa())) - return op.emitOpError("must be a boxed type"); - auto cases = op.getOperation() - ->getAttrOfType(op.getCasesAttr()) - .getValue(); - auto count = op.getNumDest(); +mlir::LogicalResult SelectTypeOp::verify() { + if (!(getSelector().getType().isa())) + return emitOpError("must be a boxed type"); + auto cases = + getOperation()->getAttrOfType(getCasesAttr()).getValue(); + auto count = getNumDest(); if (count == 0) - return op.emitOpError("must have at least one successor"); - if (op.getNumConditions() != count) - return op.emitOpError("number of conditions and successors don't match"); - if (op.targetOffsetSize() != count) - return op.emitOpError("incorrect number of successor operand groups"); + return emitOpError("must have at least one successor"); + if (getNumConditions() != count) + return emitOpError("number of conditions and successors don't match"); + if (targetOffsetSize() != count) + return emitOpError("incorrect number of successor operand groups"); for (decltype(count) i = 0; i != count; ++i) { auto &attr = cases[i]; if (!(attr.isa() || attr.isa() || attr.isa())) - return op.emitOpError("invalid type-case alternative"); + return emitOpError("invalid type-case alternative"); } return mlir::success(); } @@ -2910,8 +2917,8 @@ return fir::dyn_cast_ptrEleTy(refType); } -static mlir::ParseResult parseStoreOp(mlir::OpAsmParser &parser, - mlir::OperationState &result) { +mlir::ParseResult StoreOp::parse(mlir::OpAsmParser &parser, + mlir::OperationState &result) { mlir::Type type; mlir::OpAsmParser::OperandType oper; mlir::OpAsmParser::OperandType store; @@ -2926,20 +2933,20 @@ return mlir::success(); } -static void print(mlir::OpAsmPrinter &p, fir::StoreOp &op) { +void StoreOp::print(mlir::OpAsmPrinter &p) { p << ' '; - p.printOperand(op.value()); + p.printOperand(value()); p << " to "; - p.printOperand(op.memref()); - p.printOptionalAttrDict(op.getOperation()->getAttrs(), {}); - p << " : " << op.memref().getType(); + p.printOperand(memref()); + p.printOptionalAttrDict(getOperation()->getAttrs(), {}); + p << " : " << memref().getType(); } -static mlir::LogicalResult verify(fir::StoreOp &op) { - if (op.value().getType() != fir::dyn_cast_ptrEleTy(op.memref().getType())) - return op.emitOpError("store value type must match memory reference type"); - if (fir::isa_unknown_size_box(op.value().getType())) - return op.emitOpError("cannot store !fir.box of unknown rank or type"); +mlir::LogicalResult StoreOp::verify() { + if (value().getType() != fir::dyn_cast_ptrEleTy(memref().getType())) + return emitOpError("store value type must match memory reference type"); + if (fir::isa_unknown_size_box(value().getType())) + return emitOpError("cannot store !fir.box of unknown rank or type"); return mlir::success(); } @@ -3015,8 +3022,8 @@ result.addTypes(inType); } -static mlir::ParseResult parseStringLitOp(mlir::OpAsmParser &parser, - mlir::OperationState &result) { +mlir::ParseResult StringLitOp::parse(mlir::OpAsmParser &parser, + mlir::OperationState &result) { auto &builder = parser.getBuilder(); mlir::Attribute val; mlir::NamedAttrList attrs; @@ -3049,20 +3056,20 @@ return mlir::success(); } -static void print(mlir::OpAsmPrinter &p, fir::StringLitOp &op) { - p << ' ' << op.getValue() << '('; - p << op.getSize().cast().getValue() << ") : "; - p.printType(op.getType()); +void StringLitOp::print(mlir::OpAsmPrinter &p) { + p << ' ' << getValue() << '('; + p << getSize().cast().getValue() << ") : "; + p.printType(getType()); } -static mlir::LogicalResult verify(fir::StringLitOp &op) { - if (op.getSize().cast().getValue().isNegative()) - return op.emitOpError("size must be non-negative"); - if (auto xl = op.getOperation()->getAttr(fir::StringLitOp::xlist())) { +mlir::LogicalResult StringLitOp::verify() { + if (getSize().cast().getValue().isNegative()) + return emitOpError("size must be non-negative"); + if (auto xl = getOperation()->getAttr(fir::StringLitOp::xlist())) { auto xList = xl.cast(); for (auto a : xList) if (!a.isa()) - return op.emitOpError("values in list must be integers"); + return emitOpError("values in list must be integers"); } return mlir::success(); }