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,8 @@ ); let results = (outs fir_HeapType); - let parser = - "return parseAllocatableOp(wrapAllocMemResultType, parser, result);"; - let printer = "printAllocatableOp(p, (*this));"; + let hasCustomAssemblyFormat = 1; + let hasVerifier = 1; let builders = [ OpBuilder<(ins "mlir::Type":$in_type, "llvm::StringRef":$uniq_name, @@ -223,8 +219,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 +273,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); @@ -325,7 +317,7 @@ $from `for` $count `to` $to attr-dict `:` type(operands) }]; - let verifier = "return ::verify(*this);"; + let hasVerifier = 1; } def fir_StoreOp : fir_Op<"store", []> { @@ -350,11 +342,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); @@ -407,7 +396,7 @@ attr-dict `:` type(operands) }]; - let verifier = "return ::verify(*this);"; + let hasVerifier = 1; } def fir_UndefOp : fir_OneResultOp<"undefined", [NoSideEffect]> { @@ -731,11 +720,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 +755,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 +776,8 @@ ``` }]; - let parser = "return mlir::success();"; + let assemblyFormat = [{ attr-dict }]; - let printer = ""; } def fir_FirEndOp : fir_Op<"end", [Terminator]> { @@ -887,7 +869,7 @@ (`map` $accessMap^)? attr-dict `:` functional-type(operands, results) }]; - let verifier = "return ::verify(*this);"; + let hasVerifier = 1; let extraClassDeclaration = [{ bool hasLenParams() { return !typeparams().empty(); } @@ -944,7 +926,7 @@ $box (`(` $shape^ `)`)? (`[` $slice^ `]`)? attr-dict `:` functional-type(operands, results) }]; - let verifier = "return ::verify(*this);"; + let hasVerifier = 1; } def fir_EmboxCharOp : fir_Op<"emboxchar", [NoSideEffect]> { @@ -977,7 +959,7 @@ $memref `,` $len attr-dict `:` functional-type(operands, results) }]; - let verifier = "return ::verify(*this);"; + let hasVerifier = 1; } def fir_EmboxProcOp : fir_Op<"emboxproc", [NoSideEffect]> { @@ -1009,11 +991,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]> { @@ -1047,7 +1026,7 @@ ``` }]; - let verifier = "return ::verify(*this);"; + let hasVerifier = 1; let arguments = (ins fir_BoxProcType:$boxproc); @@ -1367,7 +1346,7 @@ attr-dict `:` functional-type(operands, results) }]; - let verifier = "return ::verify(*this);"; + let hasVerifier = 1; let extraClassDeclaration = [{ std::vector getExtents(); @@ -1417,7 +1396,7 @@ functional-type(operands, results) }]; - let verifier = "return ::verify(*this);"; + let hasVerifier = 1; } def fir_ArrayUpdateOp : fir_Op<"array_update", [AttrSizedOperandSegments, @@ -1469,7 +1448,7 @@ `:` functional-type(operands, results) }]; - let verifier = "return ::verify(*this);"; + let hasVerifier = 1; } def fir_ArrayModifyOp : fir_Op<"array_modify", [AttrSizedOperandSegments, @@ -1530,7 +1509,7 @@ `:` functional-type(operands, results) }]; - let verifier = "return ::verify(*this);"; + let hasVerifier = 1; } def fir_ArrayAccessOp : fir_Op<"array_access", [AttrSizedOperandSegments, @@ -1592,7 +1571,7 @@ functional-type(operands, results) }]; - let verifier = "return ::verify(*this);"; + let hasVerifier = 1; } def fir_ArrayAmendOp : fir_Op<"array_amend", [NoSideEffect]> { @@ -1669,7 +1648,7 @@ $typeparams^)? attr-dict `:` type(operands) }]; - let verifier = "return ::verify(*this);"; + let hasVerifier = 1; } //===----------------------------------------------------------------------===// @@ -1718,7 +1697,7 @@ $typeparams^)? attr-dict `:` functional-type(operands, results) }]; - let verifier = "return ::verify(*this);"; + let hasVerifier = 1; } def fir_CoordinateOp : fir_Op<"coordinate_of", [NoSideEffect]> { @@ -1754,9 +1733,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 +1796,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)>]; @@ -1856,7 +1832,7 @@ operands attr-dict `:` functional-type(operands, results) }]; - let verifier = "return ::verify(*this);"; + let hasVerifier = 1; } def fir_ShapeShiftOp : fir_Op<"shape_shift", [NoSideEffect]> { @@ -1886,7 +1862,7 @@ operands attr-dict `:` functional-type(operands, results) }]; - let verifier = "return ::verify(*this);"; + let hasVerifier = 1; let extraClassDeclaration = [{ // Logically unzip the origins from the extent values. @@ -1933,7 +1909,7 @@ operands attr-dict `:` functional-type(operands, results) }]; - let verifier = "return ::verify(*this);"; + let hasVerifier = 1; } def fir_SliceOp : fir_Op<"slice", [NoSideEffect, AttrSizedOperandSegments]> { @@ -1991,7 +1967,7 @@ CArg<"mlir::ValueRange", "llvm::None">:$substr)> ]; - let verifier = "return ::verify(*this);"; + let hasVerifier = 1; let extraClassDeclaration = [{ unsigned getOutRank() { return getOutputRank(triples()); } @@ -2059,7 +2035,7 @@ $seq `,` $val custom($coor) attr-dict `:` functional-type(operands, results) }]; - let verifier = "return ::verify(*this);"; + let hasVerifier = 1; } def fir_LenParamIndexOp : fir_OneResultOp<"len_param_index", [NoSideEffect]> { @@ -2081,9 +2057,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), @@ -2120,7 +2094,7 @@ let assemblyFormat = "($results^ `:` type($results))? attr-dict"; - let verifier = "return ::verify(*this);"; + let hasVerifier = 1; } def FirRegionTerminator : SingleBlockImplicitTerminator<"ResultOp">; @@ -2388,8 +2362,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 +2425,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 +2461,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, @@ -2508,8 +2478,6 @@ "llvm::ArrayRef":$xlist, CArg<"llvm::Optional", "{}">:$len)>]; - let verifier = "return ::verify(*this);"; - let extraClassDeclaration = [{ static constexpr const char *size() { return "size"; } static constexpr const char *value() { return "value"; } @@ -2556,11 +2524,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 +2564,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), [{ @@ -2668,7 +2631,7 @@ let hasFolder = 1; - let verifier = "return ::verify(*this);"; + let hasVerifier = 1; let extraClassDeclaration = [{ static bool isIntegerCompatible(mlir::Type ty); @@ -2706,13 +2669,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 +2737,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 +2820,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 +2850,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 +2893,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(); } @@ -324,14 +338,14 @@ // ArrayCoorOp //===----------------------------------------------------------------------===// -static mlir::LogicalResult verify(fir::ArrayCoorOp op) { - auto eleTy = fir::dyn_cast_ptrOrBoxEleTy(op.memref().getType()); +mlir::LogicalResult ArrayCoorOp::verify() { + auto eleTy = fir::dyn_cast_ptrOrBoxEleTy(memref().getType()); auto arrTy = eleTy.dyn_cast(); if (!arrTy) - return op.emitOpError("must be a reference to an array"); + return emitOpError("must be a reference to an array"); auto arrDim = arrTy.getDimension(); - if (auto shapeOp = op.shape()) { + if (auto shapeOp = shape()) { auto shapeTy = shapeOp.getType(); unsigned shapeTyRank = 0; if (auto s = shapeTy.dyn_cast()) { @@ -341,22 +355,22 @@ } else { auto s = shapeTy.cast(); shapeTyRank = s.getRank(); - if (!op.memref().getType().isa()) - return op.emitOpError("shift can only be provided with fir.box memref"); + if (!memref().getType().isa()) + return emitOpError("shift can only be provided with fir.box memref"); } if (arrDim && arrDim != shapeTyRank) - return op.emitOpError("rank of dimension mismatched"); - if (shapeTyRank != op.indices().size()) - return op.emitOpError("number of indices do not match dim rank"); + return emitOpError("rank of dimension mismatched"); + if (shapeTyRank != indices().size()) + return emitOpError("number of indices do not match dim rank"); } - if (auto sliceOp = op.slice()) { + if (auto sliceOp = slice()) { if (auto sl = mlir::dyn_cast_or_null(sliceOp.getDefiningOp())) if (!sl.substr().empty()) - return op.emitOpError("array_coor cannot take a slice with substring"); + return emitOpError("array_coor cannot take a slice with substring"); if (auto sliceTy = sliceOp.getType().dyn_cast()) if (sliceTy.getRank() != arrDim) - return op.emitOpError("rank of dimension in slice mismatched"); + return emitOpError("rank of dimension in slice mismatched"); } return mlir::success(); @@ -391,14 +405,14 @@ return {}; } -static mlir::LogicalResult verify(fir::ArrayLoadOp op) { - auto eleTy = fir::dyn_cast_ptrOrBoxEleTy(op.memref().getType()); +mlir::LogicalResult ArrayLoadOp::verify() { + auto eleTy = fir::dyn_cast_ptrOrBoxEleTy(memref().getType()); auto arrTy = eleTy.dyn_cast(); if (!arrTy) - return op.emitOpError("must be a reference to an array"); + return emitOpError("must be a reference to an array"); auto arrDim = arrTy.getDimension(); - if (auto shapeOp = op.shape()) { + if (auto shapeOp = shape()) { auto shapeTy = shapeOp.getType(); unsigned shapeTyRank = 0; if (auto s = shapeTy.dyn_cast()) { @@ -408,20 +422,20 @@ } else { auto s = shapeTy.cast(); shapeTyRank = s.getRank(); - if (!op.memref().getType().isa()) - return op.emitOpError("shift can only be provided with fir.box memref"); + if (!memref().getType().isa()) + return emitOpError("shift can only be provided with fir.box memref"); } if (arrDim && arrDim != shapeTyRank) - return op.emitOpError("rank of dimension mismatched"); + return emitOpError("rank of dimension mismatched"); } - if (auto sliceOp = op.slice()) { + if (auto sliceOp = slice()) { if (auto sl = mlir::dyn_cast_or_null(sliceOp.getDefiningOp())) if (!sl.substr().empty()) - return op.emitOpError("array_load cannot take a slice with substring"); + return emitOpError("array_load cannot take a slice with substring"); if (auto sliceTy = sliceOp.getType().dyn_cast()) if (sliceTy.getRank() != arrDim) - return op.emitOpError("rank of dimension in slice mismatched"); + return emitOpError("rank of dimension in slice mismatched"); } return mlir::success(); @@ -431,41 +445,40 @@ // ArrayMergeStoreOp //===----------------------------------------------------------------------===// -static mlir::LogicalResult verify(fir::ArrayMergeStoreOp op) { - if (!isa(op.original().getDefiningOp())) - return op.emitOpError("operand #0 must be result of a fir.array_load op"); - if (auto sl = op.slice()) { +mlir::LogicalResult ArrayMergeStoreOp::verify() { + if (!isa(original().getDefiningOp())) + return emitOpError("operand #0 must be result of a fir.array_load op"); + if (auto sl = slice()) { if (auto sliceOp = mlir::dyn_cast_or_null(sl.getDefiningOp())) { if (!sliceOp.substr().empty()) - return op.emitOpError( + return emitOpError( "array_merge_store cannot take a slice with substring"); if (!sliceOp.fields().empty()) { // This is an intra-object merge, where the slice is projecting the // subfields that are to be overwritten by the merge operation. - auto eleTy = fir::dyn_cast_ptrOrBoxEleTy(op.memref().getType()); + auto eleTy = fir::dyn_cast_ptrOrBoxEleTy(memref().getType()); if (auto seqTy = eleTy.dyn_cast()) { auto projTy = fir::applyPathToType(seqTy.getEleTy(), sliceOp.fields()); - if (fir::unwrapSequenceType(op.original().getType()) != projTy) - return op.emitOpError( + if (fir::unwrapSequenceType(original().getType()) != projTy) + return emitOpError( "type of origin does not match sliced memref type"); - if (fir::unwrapSequenceType(op.sequence().getType()) != projTy) - return op.emitOpError( + if (fir::unwrapSequenceType(sequence().getType()) != projTy) + return emitOpError( "type of sequence does not match sliced memref type"); return mlir::success(); } - return op.emitOpError("referenced type is not an array"); + return emitOpError("referenced type is not an array"); } } return mlir::success(); } - auto eleTy = fir::dyn_cast_ptrOrBoxEleTy(op.memref().getType()); - if (op.original().getType() != eleTy) - return op.emitOpError("type of origin does not match memref element type"); - if (op.sequence().getType() != eleTy) - return op.emitOpError( - "type of sequence does not match memref element type"); + auto eleTy = fir::dyn_cast_ptrOrBoxEleTy(memref().getType()); + if (original().getType() != eleTy) + return emitOpError("type of origin does not match memref element type"); + if (sequence().getType() != eleTy) + return emitOpError("type of sequence does not match memref element type"); return mlir::success(); } @@ -480,19 +493,19 @@ return fir::applyPathToType(ty, op.indices()); } -static mlir::LogicalResult verify(fir::ArrayFetchOp op) { - auto arrTy = op.sequence().getType().cast(); - auto indSize = op.indices().size(); +mlir::LogicalResult ArrayFetchOp::verify() { + auto arrTy = sequence().getType().cast(); + auto indSize = indices().size(); if (indSize < arrTy.getDimension()) - return op.emitOpError("number of indices != dimension of array"); + return emitOpError("number of indices != dimension of array"); if (indSize == arrTy.getDimension() && - ::adjustedElementType(op.element().getType()) != arrTy.getEleTy()) - return op.emitOpError("return type does not match array"); - auto ty = validArraySubobject(op); - if (!ty || ty != ::adjustedElementType(op.getType())) - return op.emitOpError("return type and/or indices do not type check"); - if (!isa(op.sequence().getDefiningOp())) - return op.emitOpError("argument #0 must be result of fir.array_load"); + ::adjustedElementType(element().getType()) != arrTy.getEleTy()) + return emitOpError("return type does not match array"); + auto ty = validArraySubobject(*this); + if (!ty || ty != ::adjustedElementType(getType())) + return emitOpError("return type and/or indices do not type check"); + if (!isa(sequence().getDefiningOp())) + return emitOpError("argument #0 must be result of fir.array_load"); return mlir::success(); } @@ -500,17 +513,17 @@ // ArrayAccessOp //===----------------------------------------------------------------------===// -static mlir::LogicalResult verify(fir::ArrayAccessOp op) { - auto arrTy = op.sequence().getType().cast(); - std::size_t indSize = op.indices().size(); +mlir::LogicalResult ArrayAccessOp::verify() { + auto arrTy = sequence().getType().cast(); + std::size_t indSize = indices().size(); if (indSize < arrTy.getDimension()) - return op.emitOpError("number of indices != dimension of array"); + return emitOpError("number of indices != dimension of array"); if (indSize == arrTy.getDimension() && - op.element().getType() != fir::ReferenceType::get(arrTy.getEleTy())) - return op.emitOpError("return type does not match array"); - mlir::Type ty = validArraySubobject(op); - if (!ty || fir::ReferenceType::get(ty) != op.getType()) - return op.emitOpError("return type and/or indices do not type check"); + element().getType() != fir::ReferenceType::get(arrTy.getEleTy())) + return emitOpError("return type does not match array"); + mlir::Type ty = validArraySubobject(*this); + if (!ty || fir::ReferenceType::get(ty) != getType()) + return emitOpError("return type and/or indices do not type check"); return mlir::success(); } @@ -518,19 +531,19 @@ // ArrayUpdateOp //===----------------------------------------------------------------------===// -static mlir::LogicalResult verify(fir::ArrayUpdateOp op) { - if (fir::isa_ref_type(op.merge().getType())) - return op.emitOpError("does not support reference type for merge"); - auto arrTy = op.sequence().getType().cast(); - auto indSize = op.indices().size(); +mlir::LogicalResult ArrayUpdateOp::verify() { + if (fir::isa_ref_type(merge().getType())) + return emitOpError("does not support reference type for merge"); + auto arrTy = sequence().getType().cast(); + auto indSize = indices().size(); if (indSize < arrTy.getDimension()) - return op.emitOpError("number of indices != dimension of array"); + return emitOpError("number of indices != dimension of array"); if (indSize == arrTy.getDimension() && - ::adjustedElementType(op.merge().getType()) != arrTy.getEleTy()) - return op.emitOpError("merged value does not have element type"); - auto ty = validArraySubobject(op); - if (!ty || ty != ::adjustedElementType(op.merge().getType())) - return op.emitOpError("merged value and/or indices do not type check"); + ::adjustedElementType(merge().getType()) != arrTy.getEleTy()) + return emitOpError("merged value does not have element type"); + auto ty = validArraySubobject(*this); + if (!ty || ty != ::adjustedElementType(merge().getType())) + return emitOpError("merged value and/or indices do not type check"); return mlir::success(); } @@ -538,11 +551,11 @@ // ArrayModifyOp //===----------------------------------------------------------------------===// -static mlir::LogicalResult verify(fir::ArrayModifyOp op) { - auto arrTy = op.sequence().getType().cast(); - auto indSize = op.indices().size(); +mlir::LogicalResult ArrayModifyOp::verify() { + auto arrTy = sequence().getType().cast(); + auto indSize = indices().size(); if (indSize < arrTy.getDimension()) - return op.emitOpError("number of indices must match array dimension"); + return emitOpError("number of indices must match array dimension"); return mlir::success(); } @@ -594,24 +607,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)) @@ -725,17 +737,17 @@ // CharConvertOp //===----------------------------------------------------------------------===// -static mlir::LogicalResult verify(fir::CharConvertOp op) { +mlir::LogicalResult CharConvertOp::verify() { auto unwrap = [&](mlir::Type t) { t = fir::unwrapSequenceType(fir::dyn_cast_ptrEleTy(t)); return t.dyn_cast(); }; - auto inTy = unwrap(op.from().getType()); - auto outTy = unwrap(op.to().getType()); + auto inTy = unwrap(from().getType()); + auto outTy = unwrap(to().getType()); if (!(inTy && outTy)) - return op.emitOpError("not a reference to a character"); + return emitOpError("not a reference to a character"); if (inTy.getFKind() == outTy.getFKind()) - return op.emitOpError("buffers must have different KIND values"); + return emitOpError("buffers must have different KIND values"); return mlir::success(); } @@ -759,10 +771,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 +782,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 +799,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(); } @@ -847,37 +859,37 @@ ty.isa(); } -static mlir::LogicalResult verify(fir::ConvertOp &op) { - auto inType = op.value().getType(); - auto outType = op.getType(); +mlir::LogicalResult ConvertOp::verify() { + auto inType = value().getType(); + auto outType = getType(); if (inType == outType) return mlir::success(); - if ((op.isPointerCompatible(inType) && op.isPointerCompatible(outType)) || - (op.isIntegerCompatible(inType) && op.isIntegerCompatible(outType)) || - (op.isIntegerCompatible(inType) && op.isFloatCompatible(outType)) || - (op.isFloatCompatible(inType) && op.isIntegerCompatible(outType)) || - (op.isFloatCompatible(inType) && op.isFloatCompatible(outType)) || - (op.isIntegerCompatible(inType) && op.isPointerCompatible(outType)) || - (op.isPointerCompatible(inType) && op.isIntegerCompatible(outType)) || + if ((isPointerCompatible(inType) && isPointerCompatible(outType)) || + (isIntegerCompatible(inType) && isIntegerCompatible(outType)) || + (isIntegerCompatible(inType) && isFloatCompatible(outType)) || + (isFloatCompatible(inType) && isIntegerCompatible(outType)) || + (isFloatCompatible(inType) && isFloatCompatible(outType)) || + (isIntegerCompatible(inType) && isPointerCompatible(outType)) || + (isPointerCompatible(inType) && isIntegerCompatible(outType)) || (inType.isa() && outType.isa()) || (fir::isa_complex(inType) && fir::isa_complex(outType))) return mlir::success(); - return op.emitOpError("invalid type conversion"); + return emitOpError("invalid type conversion"); } //===----------------------------------------------------------------------===// // 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 +911,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 +947,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 +973,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 +995,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 +1018,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 +1033,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(); @@ -1032,33 +1044,33 @@ // EmboxOp //===----------------------------------------------------------------------===// -static mlir::LogicalResult verify(fir::EmboxOp op) { - auto eleTy = fir::dyn_cast_ptrEleTy(op.memref().getType()); +mlir::LogicalResult EmboxOp::verify() { + auto eleTy = fir::dyn_cast_ptrEleTy(memref().getType()); bool isArray = false; if (auto seqTy = eleTy.dyn_cast()) { eleTy = seqTy.getEleTy(); isArray = true; } - if (op.hasLenParams()) { - auto lenPs = op.numLenParams(); + if (hasLenParams()) { + auto lenPs = numLenParams(); if (auto rt = eleTy.dyn_cast()) { if (lenPs != rt.getNumLenParams()) - return op.emitOpError("number of LEN params does not correspond" - " to the !fir.type type"); + return emitOpError("number of LEN params does not correspond" + " to the !fir.type type"); } else if (auto strTy = eleTy.dyn_cast()) { if (strTy.getLen() != fir::CharacterType::unknownLen()) - return op.emitOpError("CHARACTER already has static LEN"); + return emitOpError("CHARACTER already has static LEN"); } else { - return op.emitOpError("LEN parameters require CHARACTER or derived type"); + return emitOpError("LEN parameters require CHARACTER or derived type"); } - for (auto lp : op.typeparams()) + for (auto lp : typeparams()) if (!fir::isa_integer(lp.getType())) - return op.emitOpError("LEN parameters must be integral type"); + return emitOpError("LEN parameters must be integral type"); } - if (op.getShape() && !isArray) - return op.emitOpError("shape must not be provided for a scalar"); - if (op.getSlice() && !isArray) - return op.emitOpError("slice must not be provided for a scalar"); + if (getShape() && !isArray) + return emitOpError("shape must not be provided for a scalar"); + if (getSlice() && !isArray) + return emitOpError("slice must not be provided for a scalar"); return mlir::success(); } @@ -1066,8 +1078,8 @@ // EmboxCharOp //===----------------------------------------------------------------------===// -static mlir::LogicalResult verify(fir::EmboxCharOp &op) { - auto eleTy = fir::dyn_cast_ptrEleTy(op.memref().getType()); +mlir::LogicalResult EmboxCharOp::verify() { + auto eleTy = fir::dyn_cast_ptrEleTy(memref().getType()); if (!eleTy.dyn_cast_or_null()) return mlir::failure(); return mlir::success(); @@ -1077,8 +1089,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 +1118,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 +1154,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 +1166,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 +1190,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 +1243,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 +1325,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 +1345,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 +1383,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()); @@ -1449,24 +1461,24 @@ } /// Range bounds must be nonnegative, and the range must not be empty. -static mlir::LogicalResult verify(fir::InsertOnRangeOp op) { - if (fir::hasDynamicSize(op.seq().getType())) - return op.emitOpError("must have constant shape and size"); - mlir::DenseIntElementsAttr coor = op.coor(); - if (coor.size() < 2 || coor.size() % 2 != 0) - return op.emitOpError("has uneven number of values in ranges"); +mlir::LogicalResult InsertOnRangeOp::verify() { + if (fir::hasDynamicSize(seq().getType())) + return emitOpError("must have constant shape and size"); + mlir::DenseIntElementsAttr coorAttr = coor(); + if (coorAttr.size() < 2 || coorAttr.size() % 2 != 0) + return emitOpError("has uneven number of values in ranges"); bool rangeIsKnownToBeNonempty = false; - for (auto i = coor.getValues().end(), - b = coor.getValues().begin(); + for (auto i = coorAttr.getValues().end(), + b = coorAttr.getValues().begin(); i != b;) { int64_t ub = (*--i); int64_t lb = (*--i); if (lb < 0 || ub < 0) - return op.emitOpError("negative range bound"); + return emitOpError("negative range bound"); if (rangeIsKnownToBeNonempty) continue; if (lb > ub) - return op.emitOpError("empty range"); + return emitOpError("empty range"); rangeIsKnownToBeNonempty = lb < ub; } return mlir::success(); @@ -1778,8 +1790,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 +1810,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 +1844,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 +1860,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 +2093,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 +2115,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(); } //===----------------------------------------------------------------------===// @@ -2128,43 +2140,43 @@ return 0; } -static mlir::LogicalResult verify(fir::ReboxOp op) { - auto inputBoxTy = op.box().getType(); +mlir::LogicalResult ReboxOp::verify() { + auto inputBoxTy = box().getType(); if (fir::isa_unknown_size_box(inputBoxTy)) - return op.emitOpError("box operand must not have unknown rank or type"); - auto outBoxTy = op.getType(); + return emitOpError("box operand must not have unknown rank or type"); + auto outBoxTy = getType(); if (fir::isa_unknown_size_box(outBoxTy)) - return op.emitOpError("result type must not have unknown rank or type"); + return emitOpError("result type must not have unknown rank or type"); auto inputRank = getBoxRank(inputBoxTy); auto inputEleTy = getBoxScalarEleTy(inputBoxTy); auto outRank = getBoxRank(outBoxTy); auto outEleTy = getBoxScalarEleTy(outBoxTy); - if (auto slice = op.slice()) { + if (auto sliceVal = slice()) { // Slicing case - if (slice.getType().cast().getRank() != inputRank) - return op.emitOpError("slice operand rank must match box operand rank"); - if (auto shape = op.shape()) { - if (auto shiftTy = shape.getType().dyn_cast()) { + if (sliceVal.getType().cast().getRank() != inputRank) + return emitOpError("slice operand rank must match box operand rank"); + if (auto shapeVal = shape()) { + if (auto shiftTy = shapeVal.getType().dyn_cast()) { if (shiftTy.getRank() != inputRank) - return op.emitOpError("shape operand and input box ranks must match " - "when there is a slice"); + return emitOpError("shape operand and input box ranks must match " + "when there is a slice"); } else { - return op.emitOpError("shape operand must absent or be a fir.shift " - "when there is a slice"); + return emitOpError("shape operand must absent or be a fir.shift " + "when there is a slice"); } } - if (auto sliceOp = slice.getDefiningOp()) { + if (auto sliceOp = sliceVal.getDefiningOp()) { auto slicedRank = mlir::cast(sliceOp).getOutRank(); if (slicedRank != outRank) - return op.emitOpError("result type rank and rank after applying slice " - "operand must match"); + return emitOpError("result type rank and rank after applying slice " + "operand must match"); } } else { // Reshaping case unsigned shapeRank = inputRank; - if (auto shape = op.shape()) { - auto ty = shape.getType(); + if (auto shapeVal = shape()) { + auto ty = shapeVal.getType(); if (auto shapeTy = ty.dyn_cast()) { shapeRank = shapeTy.getRank(); } else if (auto shapeShiftTy = ty.dyn_cast()) { @@ -2173,19 +2185,19 @@ auto shiftTy = ty.cast(); shapeRank = shiftTy.getRank(); if (shapeRank != inputRank) - return op.emitOpError("shape operand and input box ranks must match " - "when the shape is a fir.shift"); + return emitOpError("shape operand and input box ranks must match " + "when the shape is a fir.shift"); } } if (shapeRank != outRank) - return op.emitOpError("result type and shape operand ranks must match"); + return emitOpError("result type and shape operand ranks must match"); } if (inputEleTy != outEleTy) // TODO: check that outBoxTy is a parent type of inputBoxTy for derived // types. if (!inputEleTy.isa()) - return op.emitOpError( + return emitOpError( "op input and output element types must match for intrinsic types"); return mlir::success(); } @@ -2194,17 +2206,16 @@ // ResultOp //===----------------------------------------------------------------------===// -static mlir::LogicalResult verify(fir::ResultOp op) { - auto *parentOp = op->getParentOp(); +mlir::LogicalResult ResultOp::verify() { + auto *parentOp = (*this)->getParentOp(); auto results = parentOp->getResults(); - auto operands = op->getOperands(); + auto operands = (*this)->getOperands(); - if (parentOp->getNumResults() != op.getNumOperands()) - return op.emitOpError() << "parent of result must have same arity"; + if (parentOp->getNumResults() != getNumOperands()) + return emitOpError() << "parent of result must have same arity"; for (auto e : llvm::zip(results, operands)) if (std::get<0>(e).getType() != std::get<1>(e).getType()) - return op.emitOpError() - << "types mismatch between result op and its parent"; + return emitOpError() << "types mismatch between result op and its parent"; return success(); } @@ -2212,24 +2223,24 @@ // SaveResultOp //===----------------------------------------------------------------------===// -static mlir::LogicalResult verify(fir::SaveResultOp op) { - auto resultType = op.value().getType(); - if (resultType != fir::dyn_cast_ptrEleTy(op.memref().getType())) - return op.emitOpError("value type must match memory reference type"); +mlir::LogicalResult SaveResultOp::verify() { + auto resultType = value().getType(); + if (resultType != fir::dyn_cast_ptrEleTy(memref().getType())) + return emitOpError("value type must match memory reference type"); if (fir::isa_unknown_size_box(resultType)) - return op.emitOpError("cannot save !fir.box of unknown rank or type"); + return emitOpError("cannot save !fir.box of unknown rank or type"); if (resultType.isa()) { - if (op.shape() || !op.typeparams().empty()) - return op.emitOpError( + if (shape() || !typeparams().empty()) + return emitOpError( "must not have shape or length operands if the value is a fir.box"); return mlir::success(); } // fir.record or fir.array case. unsigned shapeTyRank = 0; - if (auto shapeOp = op.shape()) { - auto shapeTy = shapeOp.getType(); + if (auto shapeVal = shape()) { + auto shapeTy = shapeVal.getType(); if (auto s = shapeTy.dyn_cast()) shapeTyRank = s.getRank(); else @@ -2239,27 +2250,26 @@ auto eleTy = resultType; if (auto seqTy = resultType.dyn_cast()) { if (seqTy.getDimension() != shapeTyRank) - op.emitOpError("shape operand must be provided and have the value rank " - "when the value is a fir.array"); + emitOpError("shape operand must be provided and have the value rank " + "when the value is a fir.array"); eleTy = seqTy.getEleTy(); } else { if (shapeTyRank != 0) - op.emitOpError( + emitOpError( "shape operand should only be provided if the value is a fir.array"); } if (auto recTy = eleTy.dyn_cast()) { - if (recTy.getNumLenParams() != op.typeparams().size()) - op.emitOpError("length parameters number must match with the value type " - "length parameters"); + if (recTy.getNumLenParams() != typeparams().size()) + emitOpError("length parameters number must match with the value type " + "length parameters"); } else if (auto charTy = eleTy.dyn_cast()) { - if (op.typeparams().size() > 1) - op.emitOpError("no more than one length parameter must be provided for " - "character value"); + if (typeparams().size() > 1) + emitOpError("no more than one length parameter must be provided for " + "character value"); } else { - if (!op.typeparams().empty()) - op.emitOpError( - "length parameters must not be provided for this value type"); + if (!typeparams().empty()) + emitOpError("length parameters must not be provided for this value type"); } return mlir::success(); @@ -2400,8 +2410,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 +2483,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 +2503,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 +2599,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 +2702,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 +2751,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(); } @@ -2823,12 +2827,12 @@ // ShapeOp //===----------------------------------------------------------------------===// -static mlir::LogicalResult verify(fir::ShapeOp &op) { - auto size = op.extents().size(); - auto shapeTy = op.getType().dyn_cast(); +mlir::LogicalResult ShapeOp::verify() { + auto size = extents().size(); + auto shapeTy = getType().dyn_cast(); assert(shapeTy && "must be a shape type"); if (shapeTy.getRank() != size) - return op.emitOpError("shape type rank mismatch"); + return emitOpError("shape type rank mismatch"); return mlir::success(); } @@ -2836,16 +2840,16 @@ // ShapeShiftOp //===----------------------------------------------------------------------===// -static mlir::LogicalResult verify(fir::ShapeShiftOp &op) { - auto size = op.pairs().size(); +mlir::LogicalResult ShapeShiftOp::verify() { + auto size = pairs().size(); if (size < 2 || size > 16 * 2) - return op.emitOpError("incorrect number of args"); + return emitOpError("incorrect number of args"); if (size % 2 != 0) - return op.emitOpError("requires a multiple of 2 args"); - auto shapeTy = op.getType().dyn_cast(); + return emitOpError("requires a multiple of 2 args"); + auto shapeTy = getType().dyn_cast(); assert(shapeTy && "must be a shape shift type"); if (shapeTy.getRank() * 2 != size) - return op.emitOpError("shape type rank mismatch"); + return emitOpError("shape type rank mismatch"); return mlir::success(); } @@ -2853,12 +2857,12 @@ // ShiftOp //===----------------------------------------------------------------------===// -static mlir::LogicalResult verify(fir::ShiftOp &op) { - auto size = op.origins().size(); - auto shiftTy = op.getType().dyn_cast(); +mlir::LogicalResult ShiftOp::verify() { + auto size = origins().size(); + auto shiftTy = getType().dyn_cast(); assert(shiftTy && "must be a shift type"); if (shiftTy.getRank() != size) - return op.emitOpError("shift type rank mismatch"); + return emitOpError("shift type rank mismatch"); return mlir::success(); } @@ -2889,16 +2893,16 @@ return rank; } -static mlir::LogicalResult verify(fir::SliceOp &op) { - auto size = op.triples().size(); +mlir::LogicalResult SliceOp::verify() { + auto size = triples().size(); if (size < 3 || size > 16 * 3) - return op.emitOpError("incorrect number of args for triple"); + return emitOpError("incorrect number of args for triple"); if (size % 3 != 0) - return op.emitOpError("requires a multiple of 3 args"); - auto sliceTy = op.getType().dyn_cast(); + return emitOpError("requires a multiple of 3 args"); + auto sliceTy = getType().dyn_cast(); assert(sliceTy && "must be a slice type"); if (sliceTy.getRank() * 3 != size) - return op.emitOpError("slice type rank mismatch"); + return emitOpError("slice type rank mismatch"); return mlir::success(); } @@ -2910,8 +2914,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 +2930,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 +3019,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 +3053,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(); } @@ -3071,11 +3075,11 @@ // UnboxProcOp //===----------------------------------------------------------------------===// -static mlir::LogicalResult verify(fir::UnboxProcOp &op) { - if (auto eleTy = fir::dyn_cast_ptrEleTy(op.refTuple().getType())) +mlir::LogicalResult UnboxProcOp::verify() { + if (auto eleTy = fir::dyn_cast_ptrEleTy(refTuple().getType())) if (eleTy.isa()) return mlir::success(); - return op.emitOpError("second output argument has bad type"); + return emitOpError("second output argument has bad type"); } //===----------------------------------------------------------------------===//