diff --git a/flang/include/flang/Lower/Mangler.h b/flang/include/flang/Lower/Mangler.h index 99da96b0d6ba5..41939abe29e5e 100644 --- a/flang/include/flang/Lower/Mangler.h +++ b/flang/include/flang/Lower/Mangler.h @@ -90,7 +90,7 @@ inline std::string mangleArrayLiteral( return mangleArrayLiteral(x.values().size() * sizeof(x.values()[0]), x.shape(), Fortran::common::TypeCategory::Derived, /*kind=*/0, /*charLen=*/-1, - mlir::cast(eleTy).getName()); + eleTy.cast().getName()); } /// Return the compiler-generated name of a static namelist variable descriptor. diff --git a/flang/include/flang/Optimizer/Analysis/TBAAForest.h b/flang/include/flang/Optimizer/Analysis/TBAAForest.h index 619ed4939c51c..b69e50bbe05c7 100644 --- a/flang/include/flang/Optimizer/Analysis/TBAAForest.h +++ b/flang/include/flang/Optimizer/Analysis/TBAAForest.h @@ -88,7 +88,7 @@ class TBAAForrest { // name must be used so that we add to the tbaa tree added in the FIR pass mlir::Attribute attr = func->getAttr(getInternalFuncNameAttrName()); if (attr) { - return getFuncTree(mlir::cast(attr)); + return getFuncTree(attr.cast()); } return getFuncTree(func.getSymNameAttr()); } diff --git a/flang/include/flang/Optimizer/Builder/BoxValue.h b/flang/include/flang/Optimizer/Builder/BoxValue.h index 5c7e89dbc08f1..2fed2d48a7a08 100644 --- a/flang/include/flang/Optimizer/Builder/BoxValue.h +++ b/flang/include/flang/Optimizer/Builder/BoxValue.h @@ -78,7 +78,7 @@ class CharBoxValue : public AbstractBox { public: CharBoxValue(mlir::Value addr, mlir::Value len) : AbstractBox{addr}, len{len} { - if (addr && mlir::isa(addr.getType())) + if (addr && addr.getType().template isa()) fir::emitFatalError(addr.getLoc(), "BoxChar should not be in CharBoxValue"); } @@ -221,7 +221,7 @@ class AbstractIrBox : public AbstractBox, public AbstractArrayBox { auto type = getAddr().getType(); if (auto pointedTy = fir::dyn_cast_ptrEleTy(type)) type = pointedTy; - return mlir::cast(type); + return type.cast(); } /// Return the part of the address type after memory and box types. That is /// the element type, maybe wrapped in a fir.array type. @@ -243,22 +243,22 @@ class AbstractIrBox : public AbstractBox, public AbstractArrayBox { /// Get the scalar type related to the described entity mlir::Type getEleTy() const { auto type = getBaseTy(); - if (auto seqTy = mlir::dyn_cast(type)) + if (auto seqTy = type.dyn_cast()) return seqTy.getEleTy(); return type; } /// Is the entity an array or an assumed rank ? - bool hasRank() const { return mlir::isa(getBaseTy()); } + bool hasRank() const { return getBaseTy().isa(); } /// Is this an assumed rank ? bool hasAssumedRank() const { - auto seqTy = mlir::dyn_cast(getBaseTy()); + auto seqTy = getBaseTy().dyn_cast(); return seqTy && seqTy.hasUnknownShape(); } /// Returns the rank of the entity. Beware that zero will be returned for /// both scalars and assumed rank. unsigned rank() const { - if (auto seqTy = mlir::dyn_cast(getBaseTy())) + if (auto seqTy = getBaseTy().dyn_cast()) return seqTy.getDimension(); return 0; } @@ -267,7 +267,7 @@ class AbstractIrBox : public AbstractBox, public AbstractArrayBox { bool isCharacter() const { return fir::isa_char(getEleTy()); } /// Is this a derived type entity ? - bool isDerived() const { return mlir::isa(getEleTy()); } + bool isDerived() const { return getEleTy().isa(); } bool isDerivedWithLenParameters() const { return fir::isRecordWithTypeParameters(getEleTy()); @@ -377,11 +377,11 @@ class MutableBoxValue : public AbstractIrBox { } /// Is this a Fortran pointer ? bool isPointer() const { - return mlir::isa(getBoxTy().getEleTy()); + return getBoxTy().getEleTy().isa(); } /// Is this an allocatable ? bool isAllocatable() const { - return mlir::isa(getBoxTy().getEleTy()); + return getBoxTy().getEleTy().isa(); } // Replace the fir.ref, keeping any non-deferred parameters. MutableBoxValue clone(mlir::Value newBox) const { @@ -488,7 +488,7 @@ class ExtendedValue : public details::matcher { if (const auto *b = getUnboxed()) { if (*b) { auto type = b->getType(); - if (mlir::isa(type)) + if (type.template isa()) fir::emitFatalError(b->getLoc(), "BoxChar should be unboxed"); type = fir::unwrapSequenceType(fir::unwrapRefType(type)); if (fir::isa_char(type)) diff --git a/flang/include/flang/Optimizer/Builder/Factory.h b/flang/include/flang/Optimizer/Builder/Factory.h index 4e5c52ac44e07..ec294d26ac961 100644 --- a/flang/include/flang/Optimizer/Builder/Factory.h +++ b/flang/include/flang/Optimizer/Builder/Factory.h @@ -43,9 +43,9 @@ template void genCharacterCopy(mlir::Value src, mlir::Value srcLen, mlir::Value dst, mlir::Value dstLen, B &builder, mlir::Location loc) { auto srcTy = - mlir::cast(fir::dyn_cast_ptrEleTy(src.getType())); + fir::dyn_cast_ptrEleTy(src.getType()).template cast(); auto dstTy = - mlir::cast(fir::dyn_cast_ptrEleTy(dst.getType())); + fir::dyn_cast_ptrEleTy(dst.getType()).template cast(); if (!srcLen && !dstLen && srcTy.getFKind() == dstTy.getFKind() && srcTy.getLen() == dstTy.getLen()) { // same size, so just use load and store @@ -61,8 +61,8 @@ void genCharacterCopy(mlir::Value src, mlir::Value srcLen, mlir::Value dst, fir::CharacterType::getSingleton(ty.getContext(), ty.getFKind()))); }; auto toEleTy = [&](fir::ReferenceType ty) { - auto seqTy = mlir::cast(ty.getEleTy()); - return mlir::cast(seqTy.getEleTy()); + auto seqTy = ty.getEleTy().cast(); + return seqTy.getEleTy().cast(); }; auto toCoorTy = [&](fir::ReferenceType ty) { return fir::ReferenceType::get(toEleTy(ty)); @@ -190,8 +190,8 @@ originateIndices(mlir::Location loc, B &builder, mlir::Type memTy, if (origins.empty()) { assert(!shapeVal || mlir::isa(shapeVal.getDefiningOp())); auto ty = fir::dyn_cast_ptrOrBoxEleTy(memTy); - assert(ty && mlir::isa(ty)); - auto seqTy = mlir::cast(ty); + assert(ty && ty.isa()); + auto seqTy = ty.cast(); auto one = builder.template create(loc, 1); const auto dimension = seqTy.getDimension(); if (shapeVal) { diff --git a/flang/include/flang/Optimizer/Builder/HLFIRTools.h b/flang/include/flang/Optimizer/Builder/HLFIRTools.h index 6c36f7e84db68..035035601e2f2 100644 --- a/flang/include/flang/Optimizer/Builder/HLFIRTools.h +++ b/flang/include/flang/Optimizer/Builder/HLFIRTools.h @@ -77,12 +77,12 @@ class Entity : public mlir::Value { /// Return the rank of this entity or -1 if it is an assumed rank. int getRank() const { mlir::Type type = fir::unwrapPassByRefType(fir::unwrapRefType(getType())); - if (auto seqTy = mlir::dyn_cast(type)) { + if (auto seqTy = type.dyn_cast()) { if (seqTy.hasUnknownShape()) return -1; return seqTy.getDimension(); } - if (auto exprType = mlir::dyn_cast(type)) + if (auto exprType = type.dyn_cast()) return exprType.getRank(); return 0; } @@ -99,17 +99,17 @@ class Entity : public mlir::Value { bool hasLengthParameters() const { mlir::Type eleTy = getFortranElementType(); - return mlir::isa(eleTy) || + return eleTy.isa() || fir::isRecordWithTypeParameters(eleTy); } bool isCharacter() const { - return mlir::isa(getFortranElementType()); + return getFortranElementType().isa(); } bool hasIntrinsicType() const { mlir::Type eleTy = getFortranElementType(); - return fir::isa_trivial(eleTy) || mlir::isa(eleTy); + return fir::isa_trivial(eleTy) || eleTy.isa(); } bool isDerivedWithLengthParameters() const { @@ -124,8 +124,8 @@ class Entity : public mlir::Value { if (auto varIface = getIfVariableInterface()) { if (auto shape = varIface.getShape()) { auto shapeTy = shape.getType(); - return mlir::isa(shapeTy) || - mlir::isa(shapeTy); + return shapeTy.isa() || + shapeTy.isa(); } return false; } diff --git a/flang/include/flang/Optimizer/Builder/IntrinsicCall.h b/flang/include/flang/Optimizer/Builder/IntrinsicCall.h index b7d0609267613..604f2bd969eed 100644 --- a/flang/include/flang/Optimizer/Builder/IntrinsicCall.h +++ b/flang/include/flang/Optimizer/Builder/IntrinsicCall.h @@ -663,8 +663,8 @@ static inline mlir::FunctionType genFuncType(mlir::MLIRContext *context, //===----------------------------------------------------------------------===// static inline mlir::Type getConvertedElementType(mlir::MLIRContext *context, mlir::Type eleTy) { - if (mlir::isa(eleTy) && !eleTy.isSignlessInteger()) { - const auto intTy{mlir::dyn_cast(eleTy)}; + if (eleTy.isa() && !eleTy.isSignlessInteger()) { + const auto intTy{eleTy.dyn_cast()}; auto newEleTy{mlir::IntegerType::get(context, intTy.getWidth())}; return newEleTy; } diff --git a/flang/include/flang/Optimizer/Builder/PPCIntrinsicCall.h b/flang/include/flang/Optimizer/Builder/PPCIntrinsicCall.h index a7c4c075d818e..1e87bf0f6ad15 100644 --- a/flang/include/flang/Optimizer/Builder/PPCIntrinsicCall.h +++ b/flang/include/flang/Optimizer/Builder/PPCIntrinsicCall.h @@ -180,10 +180,10 @@ struct VecTypeInfo { // Returns a VecTypeInfo with element type and length of given fir vector type. // Preserves signness of fir vector type if element type of integer. static inline VecTypeInfo getVecTypeFromFirType(mlir::Type firTy) { - assert(mlir::isa(firTy)); + assert(firTy.isa()); VecTypeInfo vecTyInfo; - vecTyInfo.eleTy = mlir::dyn_cast(firTy).getEleTy(); - vecTyInfo.len = mlir::dyn_cast(firTy).getLen(); + vecTyInfo.eleTy = firTy.dyn_cast().getEleTy(); + vecTyInfo.len = firTy.dyn_cast().getLen(); return vecTyInfo; } diff --git a/flang/include/flang/Optimizer/Dialect/CanonicalizationPatterns.td b/flang/include/flang/Optimizer/Dialect/CanonicalizationPatterns.td index 0ef37a37ce94f..544fc3cdf75ea 100644 --- a/flang/include/flang/Optimizer/Dialect/CanonicalizationPatterns.td +++ b/flang/include/flang/Optimizer/Dialect/CanonicalizationPatterns.td @@ -21,18 +21,17 @@ include "flang/Optimizer/Dialect/FIROps.td" def IdenticalTypePred : Constraint>; def IntegerTypePred : Constraint>; -def IndexTypePred : Constraint($0.getType())">>; +def IndexTypePred : Constraint()">>; // Widths are monotonic. // $0.bits >= $1.bits >= $2.bits or $0.bits <= $1.bits <= $2.bits def MonotonicTypePred - : Constraint($0.getType()) && " - " mlir::isa($1.getType()) && " - " mlir::isa($2.getType())) || " - " (mlir::isa($0.getType()) && " - " mlir::isa($1.getType()) && " - " mlir::isa($2.getType()))) && " + : Constraint() && " + " $1.getType().isa() && " + " $2.getType().isa()) || " + " ($0.getType().isa() && " + " $1.getType().isa() && " + " $2.getType().isa())) && " "(($0.getType().getIntOrFloatBitWidth() <= " " $1.getType().getIntOrFloatBitWidth() && " " $1.getType().getIntOrFloatBitWidth() <= " @@ -43,8 +42,8 @@ def MonotonicTypePred " $2.getType().getIntOrFloatBitWidth()))">>; def IntPred : Constraint($0.getType()) && " - "mlir::isa($1.getType())">>; + "$0.getType().isa() && " + "$1.getType().isa()">>; // If both are int type and the first is smaller than the second. // $0.bits <= $1.bits @@ -102,8 +101,8 @@ def CombineConvertTruncOptPattern def createConstantOp : NativeCodeCall<"$_builder.create" "($_loc, $_builder.getIndexType(), " - "rewriter.getIndexAttr(" - "mlir::dyn_cast($1).getInt()))">; + "rewriter.getIndexAttr($1.dyn_cast()" + ".getInt()))">; def ForwardConstantConvertPattern : Pat<(fir_ConvertOp:$res (Arith_ConstantOp:$cnt $attr)), diff --git a/flang/include/flang/Optimizer/Dialect/FIROps.td b/flang/include/flang/Optimizer/Dialect/FIROps.td index 496193e25cab6..92790a691e473 100644 --- a/flang/include/flang/Optimizer/Dialect/FIROps.td +++ b/flang/include/flang/Optimizer/Dialect/FIROps.td @@ -2708,14 +2708,14 @@ def fir_ConvertOp : fir_OneResultOp<"convert", [NoMemoryEffect]> { let hasCanonicalizer = 1; } -def FortranTypeAttr : Attr($_self)">, - Or<[CPred<"mlir::isa(mlir::cast($_self).getValue())" - >]>]>, "Fortran surface type"> { +def FortranTypeAttr : Attr()">, + Or<[CPred<"$_self.cast().getValue().isa()">]>]>, + "Fortran surface type"> { let storageType = [{ ::mlir::TypeAttr }]; let returnType = "mlir::Type"; - let convertFromStorage = "mlir::cast($_self.getValue())"; + let convertFromStorage = "$_self.getValue().cast()"; } def fir_TypeDescOp : fir_OneResultOp<"type_desc", [NoMemoryEffect]> { diff --git a/flang/include/flang/Optimizer/Dialect/FIRType.h b/flang/include/flang/Optimizer/Dialect/FIRType.h index b4344435db9f5..7fcd9c1babf24 100644 --- a/flang/include/flang/Optimizer/Dialect/FIRType.h +++ b/flang/include/flang/Optimizer/Dialect/FIRType.h @@ -97,36 +97,35 @@ bool isa_fir_or_std_type(mlir::Type t); /// Is `t` a FIR dialect type that implies a memory (de)reference? inline bool isa_ref_type(mlir::Type t) { - return mlir::isa(t); + return t.isa(); } /// Is `t` a boxed type? inline bool isa_box_type(mlir::Type t) { - return mlir::isa(t); + return t.isa(); } /// Is `t` a type that is always trivially pass-by-reference? Specifically, this /// is testing if `t` is a ReferenceType or any box type. Compare this to /// conformsWithPassByRef(), which includes pointers and allocatables. inline bool isa_passbyref_type(mlir::Type t) { - return mlir::isa(t) || - isa_box_type(t); + return t.isa() || isa_box_type(t); } /// Is `t` a type that can conform to be pass-by-reference? Depending on the /// context, these types may simply demote to pass-by-reference or a reference /// to them may have to be passed instead. Functions are always referent. inline bool conformsWithPassByRef(mlir::Type t) { - return isa_ref_type(t) || isa_box_type(t) || mlir::isa(t); + return isa_ref_type(t) || isa_box_type(t) || t.isa(); } /// Is `t` a derived (record) type? -inline bool isa_derived(mlir::Type t) { return mlir::isa(t); } +inline bool isa_derived(mlir::Type t) { return t.isa(); } /// Is `t` type(c_ptr) or type(c_funptr)? inline bool isa_builtin_cptr_type(mlir::Type t) { - if (auto recTy = mlir::dyn_cast_or_null(t)) + if (auto recTy = t.dyn_cast_or_null()) return recTy.getName().ends_with("T__builtin_c_ptr") || recTy.getName().ends_with("T__builtin_c_funptr"); return false; @@ -134,7 +133,7 @@ inline bool isa_builtin_cptr_type(mlir::Type t) { /// Is `t` a FIR dialect aggregate type? inline bool isa_aggregate(mlir::Type t) { - return mlir::isa(t) || fir::isa_derived(t); + return t.isa() || fir::isa_derived(t); } /// Extract the `Type` pointed to from a FIR memory reference type. If `t` is @@ -147,17 +146,17 @@ mlir::Type dyn_cast_ptrOrBoxEleTy(mlir::Type t); /// Is `t` a FIR Real or MLIR Float type? inline bool isa_real(mlir::Type t) { - return mlir::isa(t); + return t.isa(); } /// Is `t` an integral type? inline bool isa_integer(mlir::Type t) { - return mlir::isa(t); + return t.isa(); } /// Is `t` a vector type? inline bool isa_vector(mlir::Type t) { - return mlir::isa(t); + return t.isa(); } mlir::Type parseFirType(FIROpsDialect *, mlir::DialectAsmParser &parser); @@ -170,22 +169,22 @@ void verifyIntegralType(mlir::Type type); /// Is `t` a FIR or MLIR Complex type? inline bool isa_complex(mlir::Type t) { - return mlir::isa(t); + return t.isa(); } /// Is `t` a CHARACTER type? Does not check the length. -inline bool isa_char(mlir::Type t) { return mlir::isa(t); } +inline bool isa_char(mlir::Type t) { return t.isa(); } /// Is `t` a trivial intrinsic type? CHARACTER is excluded because it /// is a dependent type. inline bool isa_trivial(mlir::Type t) { return isa_integer(t) || isa_real(t) || isa_complex(t) || isa_vector(t) || - mlir::isa(t); + t.isa(); } /// Is `t` a CHARACTER type with a LEN other than 1? inline bool isa_char_string(mlir::Type t) { - if (auto ct = mlir::dyn_cast_or_null(t)) + if (auto ct = t.dyn_cast_or_null()) return ct.getLen() != fir::CharacterType::singleton(); return false; } @@ -199,7 +198,7 @@ bool isa_unknown_size_box(mlir::Type t); /// Returns true iff `t` is a fir.char type and has an unknown length. inline bool characterWithDynamicLen(mlir::Type t) { - if (auto charTy = mlir::dyn_cast(t)) + if (auto charTy = t.dyn_cast()) return charTy.hasDynamicLen(); return false; } @@ -214,11 +213,11 @@ inline bool sequenceWithNonConstantShape(fir::SequenceType seqTy) { bool hasDynamicSize(mlir::Type t); inline unsigned getRankOfShapeType(mlir::Type t) { - if (auto shTy = mlir::dyn_cast(t)) + if (auto shTy = t.dyn_cast()) return shTy.getRank(); - if (auto shTy = mlir::dyn_cast(t)) + if (auto shTy = t.dyn_cast()) return shTy.getRank(); - if (auto shTy = mlir::dyn_cast(t)) + if (auto shTy = t.dyn_cast()) return shTy.getRank(); return 0; } @@ -226,14 +225,14 @@ inline unsigned getRankOfShapeType(mlir::Type t) { /// Get the memory reference type of the data pointer from the box type, inline mlir::Type boxMemRefType(fir::BaseBoxType t) { auto eleTy = t.getEleTy(); - if (!mlir::isa(eleTy)) + if (!eleTy.isa()) eleTy = fir::ReferenceType::get(t); return eleTy; } /// If `t` is a SequenceType return its element type, otherwise return `t`. inline mlir::Type unwrapSequenceType(mlir::Type t) { - if (auto seqTy = mlir::dyn_cast(t)) + if (auto seqTy = t.dyn_cast()) return seqTy.getEleTy(); return t; } @@ -279,7 +278,7 @@ inline fir::SequenceType unwrapUntilSeqType(mlir::Type t) { t = ty; continue; } - if (auto seqTy = mlir::dyn_cast(t)) + if (auto seqTy = t.dyn_cast()) return seqTy; return {}; } @@ -288,8 +287,8 @@ inline fir::SequenceType unwrapUntilSeqType(mlir::Type t) { /// Unwrap the referential and sequential outer types (if any). Returns the /// the element if type is fir::RecordType inline fir::RecordType unwrapIfDerived(fir::BaseBoxType boxTy) { - return mlir::dyn_cast( - fir::unwrapSequenceType(fir::unwrapRefType(boxTy.getEleTy()))); + return fir::unwrapSequenceType(fir::unwrapRefType(boxTy.getEleTy())) + .template dyn_cast(); } /// Return true iff `boxTy` wraps a fir::RecordType with length parameters @@ -378,7 +377,7 @@ bool isRecordWithDescriptorMember(mlir::Type ty); /// Return true iff `ty` is a RecordType with type parameters. inline bool isRecordWithTypeParameters(mlir::Type ty) { - if (auto recTy = mlir::dyn_cast_or_null(ty)) + if (auto recTy = ty.dyn_cast_or_null()) return recTy.isDependentType(); return false; } @@ -402,14 +401,14 @@ mlir::Type fromRealTypeID(mlir::MLIRContext *context, llvm::Type::TypeID typeID, int getTypeCode(mlir::Type ty, const KindMapping &kindMap); inline bool BaseBoxType::classof(mlir::Type type) { - return mlir::isa(type); + return type.isa(); } /// Return true iff `ty` is none or fir.array. inline bool isNoneOrSeqNone(mlir::Type type) { - if (auto seqTy = mlir::dyn_cast(type)) - return mlir::isa(seqTy.getEleTy()); - return mlir::isa(type); + if (auto seqTy = type.dyn_cast()) + return seqTy.getEleTy().isa(); + return type.isa(); } /// Return a fir.box or fir.class if the type is polymorphic. If the type @@ -429,16 +428,16 @@ inline mlir::Type wrapInClassOrBoxType(mlir::Type eleTy, /// !fir.array<2xf32> -> !fir.array<2xnone> /// !fir.heap> -> !fir.heap> inline mlir::Type updateTypeForUnlimitedPolymorphic(mlir::Type ty) { - if (auto seqTy = mlir::dyn_cast(ty)) + if (auto seqTy = ty.dyn_cast()) return fir::SequenceType::get( seqTy.getShape(), updateTypeForUnlimitedPolymorphic(seqTy.getEleTy())); - if (auto heapTy = mlir::dyn_cast(ty)) + if (auto heapTy = ty.dyn_cast()) return fir::HeapType::get( updateTypeForUnlimitedPolymorphic(heapTy.getEleTy())); - if (auto pointerTy = mlir::dyn_cast(ty)) + if (auto pointerTy = ty.dyn_cast()) return fir::PointerType::get( updateTypeForUnlimitedPolymorphic(pointerTy.getEleTy())); - if (!mlir::isa(ty)) + if (!ty.isa()) return mlir::NoneType::get(ty.getContext()); return ty; } @@ -452,19 +451,18 @@ mlir::Type changeElementType(mlir::Type type, mlir::Type newElementType, /// Is `t` an address to fir.box or class type? inline bool isBoxAddress(mlir::Type t) { - return fir::isa_ref_type(t) && - mlir::isa(fir::unwrapRefType(t)); + return fir::isa_ref_type(t) && fir::unwrapRefType(t).isa(); } /// Is `t` a fir.box or class address or value type? inline bool isBoxAddressOrValue(mlir::Type t) { - return mlir::isa(fir::unwrapRefType(t)); + return fir::unwrapRefType(t).isa(); } /// Is this a fir.boxproc address type? inline bool isBoxProcAddressType(mlir::Type t) { t = fir::dyn_cast_ptrEleTy(t); - return t && mlir::isa(t); + return t && t.isa(); } /// Return a string representation of `ty`. diff --git a/flang/include/flang/Optimizer/Dialect/FIRTypes.td b/flang/include/flang/Optimizer/Dialect/FIRTypes.td index 7378ed93944c9..3b876e4642da9 100644 --- a/flang/include/flang/Optimizer/Dialect/FIRTypes.td +++ b/flang/include/flang/Optimizer/Dialect/FIRTypes.td @@ -578,7 +578,7 @@ def fir_VoidType : FIR_Type<"Void", "void"> { // Whether a type is a BaseBoxType def IsBaseBoxTypePred - : CPred<"mlir::isa<::fir::BaseBoxType>($_self)">; + : CPred<"$_self.isa<::fir::BaseBoxType>()">; def fir_BaseBoxType : Type; // Generalized FIR and standard dialect types representing intrinsic types diff --git a/flang/include/flang/Optimizer/Dialect/FortranVariableInterface.td b/flang/include/flang/Optimizer/Dialect/FortranVariableInterface.td index 3f78a93a2515e..6405afbf1bfbc 100644 --- a/flang/include/flang/Optimizer/Dialect/FortranVariableInterface.td +++ b/flang/include/flang/Optimizer/Dialect/FortranVariableInterface.td @@ -75,7 +75,7 @@ def fir_FortranVariableOpInterface : OpInterface<"FortranVariableOpInterface"> { /// variable. mlir::Type getElementOrSequenceType() { mlir::Type type = fir::unwrapPassByRefType(fir::unwrapRefType(getBase().getType())); - if (auto boxCharType = mlir::dyn_cast(type)) + if (auto boxCharType = type.dyn_cast()) return boxCharType.getEleTy(); return type; } @@ -87,13 +87,13 @@ def fir_FortranVariableOpInterface : OpInterface<"FortranVariableOpInterface"> { /// Is the variable an array? bool isArray() { - return mlir::isa(getElementOrSequenceType()); + return getElementOrSequenceType().isa(); } /// Return the rank of the entity if it is known at compile time. std::optional getRank() { if (auto sequenceType = - mlir::dyn_cast(getElementOrSequenceType())) { + getElementOrSequenceType().dyn_cast()) { if (sequenceType.hasUnknownShape()) return {}; return sequenceType.getDimension(); @@ -133,7 +133,7 @@ def fir_FortranVariableOpInterface : OpInterface<"FortranVariableOpInterface"> { /// Is this a Fortran character variable? bool isCharacter() { - return mlir::isa(getElementType()); + return getElementType().isa(); } /// Is this a Fortran character variable with an explicit length? @@ -149,7 +149,7 @@ def fir_FortranVariableOpInterface : OpInterface<"FortranVariableOpInterface"> { /// Is this variable represented as a fir.box or fir.class value? bool isBoxValue() { - return mlir::isa(getBase().getType()); + return getBase().getType().isa(); } /// Is this variable represented as a fir.box or fir.class address? diff --git a/flang/include/flang/Optimizer/HLFIR/HLFIRDialect.h b/flang/include/flang/Optimizer/HLFIR/HLFIRDialect.h index 3830237f96f3c..aa68d0811c486 100644 --- a/flang/include/flang/Optimizer/HLFIR/HLFIRDialect.h +++ b/flang/include/flang/Optimizer/HLFIR/HLFIRDialect.h @@ -40,9 +40,9 @@ namespace hlfir { inline mlir::Type getFortranElementType(mlir::Type type) { type = fir::unwrapSequenceType( fir::unwrapPassByRefType(fir::unwrapRefType(type))); - if (auto exprType = mlir::dyn_cast(type)) + if (auto exprType = type.dyn_cast()) return exprType.getEleTy(); - if (auto boxCharType = mlir::dyn_cast(type)) + if (auto boxCharType = type.dyn_cast()) return boxCharType.getEleTy(); return type; } @@ -51,12 +51,12 @@ inline mlir::Type getFortranElementType(mlir::Type type) { /// fir.array type. Otherwise, returns the Fortran element typeof the entity. inline mlir::Type getFortranElementOrSequenceType(mlir::Type type) { type = fir::unwrapPassByRefType(fir::unwrapRefType(type)); - if (auto exprType = mlir::dyn_cast(type)) { + if (auto exprType = type.dyn_cast()) { if (exprType.isArray()) return fir::SequenceType::get(exprType.getShape(), exprType.getEleTy()); return exprType.getEleTy(); } - if (auto boxCharType = mlir::dyn_cast(type)) + if (auto boxCharType = type.dyn_cast()) return boxCharType.getEleTy(); return type; } @@ -64,16 +64,16 @@ inline mlir::Type getFortranElementOrSequenceType(mlir::Type type) { /// Is this a fir.box or fir.class address type? inline bool isBoxAddressType(mlir::Type type) { type = fir::dyn_cast_ptrEleTy(type); - return type && mlir::isa(type); + return type && type.isa(); } /// Is this a fir.box or fir.class address or value type? inline bool isBoxAddressOrValueType(mlir::Type type) { - return mlir::isa(fir::unwrapRefType(type)); + return fir::unwrapRefType(type).isa(); } inline bool isPolymorphicType(mlir::Type type) { - if (auto exprType = mlir::dyn_cast(type)) + if (auto exprType = type.dyn_cast()) return exprType.isPolymorphic(); return fir::isPolymorphicType(type); } @@ -81,14 +81,14 @@ inline bool isPolymorphicType(mlir::Type type) { /// Is this an SSA value type for the value of a Fortran procedure /// designator ? inline bool isFortranProcedureValue(mlir::Type type) { - return mlir::isa(type) || - (mlir::isa(type) && + return type.isa() || + (type.isa() && fir::isCharacterProcedureTuple(type, /*acceptRawFunc=*/false)); } /// Is this an SSA value type for the value of a Fortran expression? inline bool isFortranValueType(mlir::Type type) { - return mlir::isa(type) || fir::isa_trivial(type) || + return type.isa() || fir::isa_trivial(type) || isFortranProcedureValue(type); } diff --git a/flang/include/flang/Optimizer/Support/Utils.h b/flang/include/flang/Optimizer/Support/Utils.h index 2da6f24da40e9..2b4fa50e0e421 100644 --- a/flang/include/flang/Optimizer/Support/Utils.h +++ b/flang/include/flang/Optimizer/Support/Utils.h @@ -29,9 +29,7 @@ namespace fir { /// Return the integer value of a arith::ConstantOp. inline std::int64_t toInt(mlir::arith::ConstantOp cop) { - return mlir::cast(cop.getValue()) - .getValue() - .getSExtValue(); + return cop.getValue().cast().getValue().getSExtValue(); } // Reconstruct binding tables for dynamic dispatch. diff --git a/flang/include/flang/Tools/PointerModels.h b/flang/include/flang/Tools/PointerModels.h index c3c0977d6e54a..7acaf2f9fda5b 100644 --- a/flang/include/flang/Tools/PointerModels.h +++ b/flang/include/flang/Tools/PointerModels.h @@ -20,7 +20,7 @@ struct OpenMPPointerLikeModel : public mlir::omp::PointerLikeType::ExternalModel< OpenMPPointerLikeModel, T> { mlir::Type getElementType(mlir::Type pointer) const { - return mlir::cast(pointer).getElementType(); + return pointer.cast().getElementType(); } }; @@ -29,7 +29,7 @@ struct OpenACCPointerLikeModel : public mlir::acc::PointerLikeType::ExternalModel< OpenACCPointerLikeModel, T> { mlir::Type getElementType(mlir::Type pointer) const { - return mlir::cast(pointer).getElementType(); + return pointer.cast().getElementType(); } }; diff --git a/flang/lib/Lower/Allocatable.cpp b/flang/lib/Lower/Allocatable.cpp index a1957c0eb1bb7..8e84ea2fc5d52 100644 --- a/flang/lib/Lower/Allocatable.cpp +++ b/flang/lib/Lower/Allocatable.cpp @@ -162,7 +162,7 @@ static void genRuntimeInitCharacter(fir::FirOpBuilder &builder, args.push_back(builder.createConvert(loc, inputTypes[0], box.getAddr())); args.push_back(builder.createConvert(loc, inputTypes[1], len)); if (kind == 0) - kind = mlir::cast(box.getEleTy()).getFKind(); + kind = box.getEleTy().cast().getFKind(); args.push_back(builder.createIntegerConstant(loc, inputTypes[2], kind)); int rank = box.rank(); args.push_back(builder.createIntegerConstant(loc, inputTypes[3], rank)); @@ -879,7 +879,7 @@ void Fortran::lower::genDeallocateIfAllocated( builder.genIfThen(loc, isAllocated) .genThen([&]() { if (mlir::Type eleType = box.getEleTy(); - mlir::isa(eleType) && box.isPolymorphic()) { + eleType.isa() && box.isPolymorphic()) { mlir::Value declaredTypeDesc = builder.create( loc, mlir::TypeAttr::get(eleType)); genDeallocateBox(converter, box, loc, sym, declaredTypeDesc); @@ -918,7 +918,7 @@ void Fortran::lower::genDeallocateStmt( mlir::Value declaredTypeDesc = {}; if (box.isPolymorphic()) { mlir::Type eleType = box.getEleTy(); - if (mlir::isa(eleType)) + if (eleType.isa()) if (const Fortran::semantics::DerivedTypeSpec *derivedTypeSpec = symbol.GetType()->AsDerived()) { declaredTypeDesc = @@ -1007,7 +1007,7 @@ createMutableProperties(Fortran::lower::AbstractConverter &converter, fir::MutableProperties mutableProperties; std::string name = converter.mangleName(sym); mlir::Type baseAddrTy = converter.genType(sym); - if (auto boxType = mlir::dyn_cast(baseAddrTy)) + if (auto boxType = baseAddrTy.dyn_cast()) baseAddrTy = boxType.getEleTy(); // Allocate and set a variable to hold the address. // It will be set to null in setUnallocatedStatus. @@ -1032,9 +1032,9 @@ createMutableProperties(Fortran::lower::AbstractConverter &converter, mlir::Type eleTy = baseAddrTy; if (auto newTy = fir::dyn_cast_ptrEleTy(eleTy)) eleTy = newTy; - if (auto seqTy = mlir::dyn_cast(eleTy)) + if (auto seqTy = eleTy.dyn_cast()) eleTy = seqTy.getEleTy(); - if (auto record = mlir::dyn_cast(eleTy)) + if (auto record = eleTy.dyn_cast()) if (record.getNumLenParams() != 0) TODO(loc, "deferred length type parameters."); if (fir::isa_char(eleTy) && nonDeferredParams.empty()) { diff --git a/flang/lib/Lower/Bridge.cpp b/flang/lib/Lower/Bridge.cpp index 19c00884bd1b7..f66607dfa22f1 100644 --- a/flang/lib/Lower/Bridge.cpp +++ b/flang/lib/Lower/Bridge.cpp @@ -683,7 +683,7 @@ class FirConverter : public Fortran::lower::AbstractConverter { auto if_builder = builder->genIfThenElse(loc, isAllocated); if_builder.genThen([&]() { std::string name = mangleName(sym) + ".alloc"; - if (auto seqTy = mlir::dyn_cast(symType)) { + if (auto seqTy = symType.dyn_cast()) { fir::ExtendedValue read = fir::factory::genMutableBoxRead( *builder, loc, box, /*mayBePolymorphic=*/false); if (auto read_arr_box = read.getBoxOf()) { @@ -1132,7 +1132,7 @@ class FirConverter : public Fortran::lower::AbstractConverter { fir::ExtendedValue lhs = symBoxToExtendedValue(lhs_sb); fir::ExtendedValue rhs = symBoxToExtendedValue(rhs_sb); mlir::Type symType = genType(sym); - if (auto seqTy = mlir::dyn_cast(symType)) { + if (auto seqTy = symType.dyn_cast()) { Fortran::lower::StatementContext stmtCtx; Fortran::lower::createSomeArrayAssignment(*this, lhs, rhs, localSymbols, stmtCtx); @@ -1355,7 +1355,7 @@ class FirConverter : public Fortran::lower::AbstractConverter { return; } mlir::Type selectorType = selector.getType(); - bool realSelector = mlir::isa(selectorType); + bool realSelector = selectorType.isa(); assert((inArithmeticIfContext || !realSelector) && "invalid selector type"); mlir::Value zero; if (inArithmeticIfContext) @@ -1630,7 +1630,7 @@ class FirConverter : public Fortran::lower::AbstractConverter { stmtCtx); stmtCtx.finalizeAndReset(); // Raise an exception if REAL expr is a NaN. - if (mlir::isa(expr.getType())) + if (expr.getType().isa()) expr = builder->create(toLocation(), expr, expr); // An empty valueList indicates to genMultiwayBranch that the branch is // an ArithmeticIfStmt that has two branches on value 0 or 0.0. @@ -2807,7 +2807,7 @@ class FirConverter : public Fortran::lower::AbstractConverter { auto caseValue = valueList.begin(); auto caseBlock = blockList.begin(); for (mlir::Attribute attr : attrList) { - if (mlir::isa(attr)) { + if (attr.isa()) { genBranch(*caseBlock++); break; } @@ -2825,7 +2825,7 @@ class FirConverter : public Fortran::lower::AbstractConverter { rhsVal.second); }; mlir::Block *newBlock = insertBlock(*caseBlock); - if (mlir::isa(attr)) { + if (attr.isa()) { mlir::Block *newBlock2 = insertBlock(*caseBlock); mlir::Value cond = genCond(*caseValue++, mlir::arith::CmpIPredicate::sge); @@ -2838,12 +2838,12 @@ class FirConverter : public Fortran::lower::AbstractConverter { continue; } mlir::arith::CmpIPredicate pred; - if (mlir::isa(attr)) { + if (attr.isa()) { pred = mlir::arith::CmpIPredicate::eq; - } else if (mlir::isa(attr)) { + } else if (attr.isa()) { pred = mlir::arith::CmpIPredicate::sge; } else { - assert(mlir::isa(attr) && "unexpected predicate"); + assert(attr.isa() && "unexpected predicate"); pred = mlir::arith::CmpIPredicate::sle; } mlir::Value cond = genCond(*caseValue++, pred); @@ -3105,7 +3105,7 @@ class FirConverter : public Fortran::lower::AbstractConverter { bool isPointer = fir::isPointerType(baseTy); bool isAllocatable = fir::isAllocatableType(baseTy); bool isArray = - mlir::isa(fir::dyn_cast_ptrOrBoxEleTy(baseTy)); + fir::dyn_cast_ptrOrBoxEleTy(baseTy).isa(); const fir::BoxValue *selectorBox = selector.getBoxOf(); if (std::holds_alternative(guard.u)) { // CLASS DEFAULT @@ -3114,12 +3114,12 @@ class FirConverter : public Fortran::lower::AbstractConverter { std::get_if(&guard.u)) { // TYPE IS fir::ExactTypeAttr attr = - mlir::dyn_cast(typeGuardAttr); + typeGuardAttr.dyn_cast(); mlir::Value exactValue; mlir::Type addrTy = attr.getType(); if (isArray) { - auto seqTy = mlir::dyn_cast( - fir::dyn_cast_ptrOrBoxEleTy(baseTy)); + auto seqTy = fir::dyn_cast_ptrOrBoxEleTy(baseTy) + .dyn_cast(); addrTy = fir::SequenceType::get(seqTy.getShape(), attr.getType()); } if (isPointer) @@ -3141,7 +3141,7 @@ class FirConverter : public Fortran::lower::AbstractConverter { addAssocEntitySymbol(selectorBox->clone(exact)); } else if (intrinsic->category() == Fortran::common::TypeCategory::Character) { - auto charTy = mlir::dyn_cast(attr.getType()); + auto charTy = attr.getType().dyn_cast(); mlir::Value charLen = fir::factory::CharacterExprHelper(*builder, loc) .readLengthFromBox(fir::getBase(selector), charTy); @@ -3158,12 +3158,11 @@ class FirConverter : public Fortran::lower::AbstractConverter { } else if (std::holds_alternative( guard.u)) { // CLASS IS - fir::SubclassAttr attr = - mlir::dyn_cast(typeGuardAttr); + fir::SubclassAttr attr = typeGuardAttr.dyn_cast(); mlir::Type addrTy = attr.getType(); if (isArray) { - auto seqTy = mlir::dyn_cast( - fir::dyn_cast_ptrOrBoxEleTy(baseTy)); + auto seqTy = fir::dyn_cast_ptrOrBoxEleTy(baseTy) + .dyn_cast(); addrTy = fir::SequenceType::get(seqTy.getShape(), attr.getType()); } if (isPointer) @@ -4140,7 +4139,7 @@ class FirConverter : public Fortran::lower::AbstractConverter { } else if (isDerivedCategory(lhsType->category())) { // Handle parent component. if (Fortran::lower::isParentComponent(assign.lhs)) { - if (!mlir::isa(fir::getBase(lhs).getType())) + if (!fir::getBase(lhs).getType().isa()) lhs = fir::getBase(builder->createBox(loc, lhs)); lhs = Fortran::lower::updateBoxForParentComponent(*this, lhs, assign.lhs); @@ -5491,7 +5490,7 @@ Fortran::lower::LoweringBridge::LoweringBridge( default: break; } - if (!mlir::isa(diag.getLocation())) + if (!diag.getLocation().isa()) os << diag.getLocation() << ": "; os << diag << '\n'; os.flush(); diff --git a/flang/lib/Lower/CallInterface.cpp b/flang/lib/Lower/CallInterface.cpp index c1f54ad392879..5ad244600328c 100644 --- a/flang/lib/Lower/CallInterface.cpp +++ b/flang/lib/Lower/CallInterface.cpp @@ -1182,7 +1182,7 @@ class Fortran::lower::CallInterfaceImpl { Property prop = Property::BaseAddress; if (isValueAttr) { bool isBuiltinCptrType = fir::isa_builtin_cptr_type(type); - if (isBindC || (!mlir::isa(type) && + if (isBindC || (!type.isa() && !obj.attrs.test(Attrs::Optional) && (dynamicType.category() != Fortran::common::TypeCategory::Derived || @@ -1190,7 +1190,7 @@ class Fortran::lower::CallInterfaceImpl { passBy = PassEntityBy::Value; prop = Property::Value; if (isBuiltinCptrType) { - auto recTy = mlir::dyn_cast(type); + auto recTy = type.dyn_cast(); mlir::Type fieldTy = recTy.getTypeList()[0].second; passType = fir::ReferenceType::get(fieldTy); } else { @@ -1714,7 +1714,7 @@ mlir::Type Fortran::lower::getDummyProcedureType( } bool Fortran::lower::isCPtrArgByValueType(mlir::Type ty) { - return mlir::isa(ty) && + return ty.isa() && fir::isa_integer(fir::unwrapRefType(ty)); } diff --git a/flang/lib/Lower/ConvertArrayConstructor.cpp b/flang/lib/Lower/ConvertArrayConstructor.cpp index a5b5838fe6b62..24aa9beba6bf4 100644 --- a/flang/lib/Lower/ConvertArrayConstructor.cpp +++ b/flang/lib/Lower/ConvertArrayConstructor.cpp @@ -336,7 +336,7 @@ class RuntimeTempStrategy : public StrategyBase { if (!extent) extent = builder.createIntegerConstant(loc, builder.getIndexType(), 0); if (missingLengthParameters) { - if (mlir::isa(declaredType.getEleTy())) + if (declaredType.getEleTy().isa()) emboxLengths.push_back(builder.createIntegerConstant( loc, builder.getCharacterLengthType(), 0)); else @@ -357,7 +357,7 @@ class RuntimeTempStrategy : public StrategyBase { bool useSimplePushRuntime(hlfir::Entity value) { return value.isScalar() && - !mlir::isa(arrayConstructorElementType) && + !arrayConstructorElementType.isa() && !fir::isRecordWithAllocatableMember(arrayConstructorElementType) && !fir::isRecordWithTypeParameters(arrayConstructorElementType); } @@ -370,7 +370,7 @@ class RuntimeTempStrategy : public StrategyBase { auto [addrExv, cleanUp] = hlfir::convertToAddress( loc, builder, value, arrayConstructorElementType); mlir::Value addr = fir::getBase(addrExv); - if (mlir::isa(addr.getType())) + if (addr.getType().isa()) addr = builder.create(loc, addr); fir::runtime::genPushArrayConstructorSimpleScalar( loc, builder, arrayConstructorVector, addr); @@ -564,7 +564,7 @@ struct LengthAndTypeCollector> { /// lowering an ac-value and must be delayed? static bool missingLengthParameters(mlir::Type elementType, llvm::ArrayRef lengths) { - return (mlir::isa(elementType) || + return (elementType.isa() || fir::isRecordWithTypeParameters(elementType)) && lengths.empty(); } @@ -702,8 +702,7 @@ static ArrayCtorLoweringStrategy selectArrayCtorLoweringStrategy( // Based on what was gathered and the result of the analysis, select and // instantiate the right lowering strategy for the array constructor. if (!extent || needToEvaluateOneExprToGetLengthParameters || - analysis.anyArrayExpr || - mlir::isa(declaredType.getEleTy())) + analysis.anyArrayExpr || declaredType.getEleTy().isa()) return RuntimeTempStrategy( loc, builder, stmtCtx, symMap, declaredType, extent ? std::optional(extent) : std::nullopt, lengths, diff --git a/flang/lib/Lower/ConvertCall.cpp b/flang/lib/Lower/ConvertCall.cpp index e4a0cc8d47303..c6f7d3410ad5c 100644 --- a/flang/lib/Lower/ConvertCall.cpp +++ b/flang/lib/Lower/ConvertCall.cpp @@ -49,15 +49,15 @@ static fir::ExtendedValue toExtendedValue(mlir::Location loc, mlir::Value base, llvm::ArrayRef extents, llvm::ArrayRef lengths) { mlir::Type type = base.getType(); - if (mlir::isa(type)) + if (type.isa()) return fir::BoxValue(base, /*lbounds=*/{}, lengths, extents); type = fir::unwrapRefType(type); - if (mlir::isa(type)) + if (type.isa()) return fir::MutableBoxValue(base, lengths, /*mutableProperties*/ {}); - if (auto seqTy = mlir::dyn_cast(type)) { + if (auto seqTy = type.dyn_cast()) { if (seqTy.getDimension() != extents.size()) fir::emitFatalError(loc, "incorrect number of extents for array"); - if (mlir::isa(seqTy.getEleTy())) { + if (seqTy.getEleTy().isa()) { if (lengths.empty()) fir::emitFatalError(loc, "missing length for character"); assert(lengths.size() == 1); @@ -65,7 +65,7 @@ static fir::ExtendedValue toExtendedValue(mlir::Location loc, mlir::Value base, } return fir::ArrayBoxValue(base, extents); } - if (mlir::isa(type)) { + if (type.isa()) { if (lengths.empty()) fir::emitFatalError(loc, "missing length for character"); assert(lengths.size() == 1); @@ -193,7 +193,7 @@ static mlir::Value remapActualToDummyDescriptor( llvm::SmallVector lengths; mlir::Type dummyBoxType = caller.getDummyArgumentType(arg); mlir::Type dummyBaseType = fir::unwrapPassByRefType(dummyBoxType); - if (mlir::isa(dummyBaseType)) + if (dummyBaseType.isa()) caller.walkDummyArgumentExtents( arg, [&](const Fortran::lower::SomeExpr &e, bool isAssumedSizeExtent) { extents.emplace_back(lowerSpecExpr(e, isAssumedSizeExtent)); @@ -338,7 +338,7 @@ std::pair Fortran::lower::genCallOpAndResult( if (!caller.callerAllocateResult()) return {}; mlir::Type type = caller.getResultStorageType(); - if (mlir::isa(type)) + if (type.isa()) caller.walkResultExtents( [&](const Fortran::lower::SomeExpr &e, bool isAssumedSizeExtent) { assert(!isAssumedSizeExtent && "result cannot be assumed-size"); @@ -353,7 +353,7 @@ std::pair Fortran::lower::genCallOpAndResult( // Result length parameters should not be provided to box storage // allocation and save_results, but they are still useful information to // keep in the ExtendedValue if non-deferred. - if (!mlir::isa(type)) { + if (!type.isa()) { if (fir::isa_char(fir::unwrapSequenceType(type)) && lengths.empty()) { // Calling an assumed length function. This is only possible if this // is a call to a character dummy procedure. @@ -478,7 +478,7 @@ std::pair Fortran::lower::genCallOpAndResult( // FIR. if (funcPointer) { operands.push_back( - mlir::isa(funcPointer.getType()) + funcPointer.getType().isa() ? builder.create(loc, funcType, funcPointer) : builder.createConvert(loc, funcType, funcPointer)); } @@ -492,8 +492,8 @@ std::pair Fortran::lower::genCallOpAndResult( // arguments of any type and vice versa. mlir::Value cast; auto *context = builder.getContext(); - if (mlir::isa(snd) && - mlir::isa(fst.getType())) { + if (snd.isa() && + fst.getType().isa()) { auto funcTy = mlir::FunctionType::get(context, std::nullopt, std::nullopt); auto boxProcTy = builder.getBoxProcType(funcTy); @@ -734,9 +734,9 @@ std::pair Fortran::lower::genCallOpAndResult( // Call a BIND(C) function that return a char. if (caller.characterize().IsBindC() && - mlir::isa(funcType.getResults()[0])) { + funcType.getResults()[0].isa()) { fir::CharacterType charTy = - mlir::dyn_cast(funcType.getResults()[0]); + funcType.getResults()[0].dyn_cast(); mlir::Value len = builder.createIntegerConstant( loc, builder.getCharacterLengthType(), charTy.getLen()); return {fir::CharBoxValue{callResult, len}, /*resultIsFinalized=*/false}; @@ -890,7 +890,7 @@ extendedValueToHlfirEntity(mlir::Location loc, fir::FirOpBuilder &builder, mlir::Type firBaseTy = firBase.getType(); if (fir::isa_trivial(firBaseTy)) return hlfir::EntityWithAttributes{firBase}; - if (auto charTy = mlir::dyn_cast(firBase.getType())) { + if (auto charTy = firBase.getType().dyn_cast()) { // CHAR() intrinsic and BIND(C) procedures returning CHARACTER(1) // are lowered to a fir.char that is not in memory. // This tends to cause a lot of bugs because the rest of the @@ -1061,7 +1061,7 @@ static hlfir::Entity fixProcedureDummyMismatch(mlir::Location loc, fir::FirOpBuilder &builder, hlfir::Entity actual, mlir::Type dummyType) { - if (mlir::isa(actual.getType()) && + if (actual.getType().isa() && fir::isCharacterProcedureTuple(dummyType)) { mlir::Value length = builder.create(loc, builder.getCharacterLengthType()); @@ -1070,7 +1070,7 @@ static hlfir::Entity fixProcedureDummyMismatch(mlir::Location loc, return hlfir::Entity{tuple}; } assert(fir::isCharacterProcedureTuple(actual.getType()) && - mlir::isa(dummyType) && + dummyType.isa() && "unsupported dummy procedure mismatch with the actual argument"); mlir::Value boxProc = fir::factory::extractCharacterProcedureTuple( builder, loc, actual, /*openBoxProc=*/false) @@ -1143,7 +1143,7 @@ static PreparedDummyArgument preparePresentUserCallActualArgument( assert(actual.isProcedure()); // Do nothing if this is a procedure argument. It is already a // fir.boxproc/fir.tuple as it should. - if (!mlir::isa(actual.getType()) && + if (!actual.getType().isa() && actual.getType() != dummyType) // The actual argument may be a procedure that returns character (a // fir.tuple) while the dummy is not. Extract the tuple @@ -1164,7 +1164,7 @@ static PreparedDummyArgument preparePresentUserCallActualArgument( // dynamic type matters to determine the contiguity. const bool mustSetDynamicTypeToDummyType = passingPolymorphicToNonPolymorphic && - (actual.isArray() || mlir::isa(dummyType)); + (actual.isArray() || dummyType.isa()); // The simple contiguity of the actual is "lost" when passing a polymorphic // to a non polymorphic entity because the dummy dynamic type matters for @@ -1236,7 +1236,7 @@ static PreparedDummyArgument preparePresentUserCallActualArgument( preparedDummy.pushExprAssociateCleanUp(associate); } else if (mustDoCopyInOut) { // Copy-in non contiguous variables. - assert(mlir::isa(entity.getType()) && + assert(entity.getType().isa() && "expect non simply contiguous variables to be boxes"); if (actualIsAssumedRank) TODO(loc, "copy-in and copy-out of assumed-rank arguments"); @@ -1294,14 +1294,13 @@ static PreparedDummyArgument preparePresentUserCallActualArgument( // Step 3: now that the dummy argument storage has been prepared, package // it according to the interface. mlir::Value addr; - if (mlir::isa(dummyTypeWithActualRank)) { + if (dummyTypeWithActualRank.isa()) { addr = hlfir::genVariableBoxChar(loc, builder, entity); - } else if (mlir::isa(dummyTypeWithActualRank)) { + } else if (dummyTypeWithActualRank.isa()) { entity = hlfir::genVariableBox(loc, builder, entity); // Ensures the box has the right attributes and that it holds an // addendum if needed. - fir::BaseBoxType actualBoxType = - mlir::cast(entity.getType()); + fir::BaseBoxType actualBoxType = entity.getType().cast(); mlir::Type boxEleType = actualBoxType.getEleTy(); // For now, assume it is not OK to pass the allocatable/pointer // descriptor to a non pointer/allocatable dummy. That is a strict @@ -1568,7 +1567,7 @@ genUserCall(Fortran::lower::PreparedActualArguments &loweredActuals, // callee side, and it is illegal to use NULL without a MOLD if any // dummy length parameters are assumed. mlir::Type boxTy = fir::dyn_cast_ptrEleTy(argTy); - assert(boxTy && mlir::isa(boxTy) && + assert(boxTy && boxTy.isa() && "must be a fir.box type"); mlir::Value boxStorage = fir::factory::genNullBoxStorage(builder, loc, boxTy); @@ -1636,8 +1635,7 @@ genUserCall(Fortran::lower::PreparedActualArguments &loweredActuals, caller, callSiteType, callContext.resultType, callContext.isElementalProcWithArrayArgs()); // For procedure pointer function result, just return the call. - if (callContext.resultType && - mlir::isa(*callContext.resultType)) + if (callContext.resultType && callContext.resultType->isa()) return hlfir::EntityWithAttributes(fir::getBase(result)); /// Clean-up associations and copy-in. @@ -2117,9 +2115,9 @@ class ElementalCallBuilder { hlfir::getFortranElementType(*callContext.resultType); // Get result length parameters. llvm::SmallVector typeParams; - if (mlir::isa(elementType) || + if (elementType.isa() || fir::isRecordWithTypeParameters(elementType)) { - auto charType = mlir::dyn_cast(elementType); + auto charType = elementType.dyn_cast(); if (charType && charType.hasConstantLen()) typeParams.push_back(builder.createIntegerConstant( loc, builder.getIndexType(), charType.getLen())); @@ -2525,7 +2523,7 @@ genIntrinsicRef(const Fortran::evaluate::SpecificIntrinsic *intrinsic, } std::optional result = genHLFIRIntrinsicRefCore( loweredActuals, intrinsic, argLowering, callContext); - if (result && mlir::isa(result->getType())) { + if (result && result->getType().isa()) { fir::FirOpBuilder *bldr = &callContext.getBuilder(); callContext.stmtCtx.attachCleanup( [=]() { bldr->create(loc, *result); }); diff --git a/flang/lib/Lower/ConvertConstant.cpp b/flang/lib/Lower/ConvertConstant.cpp index 653e874a969c5..ed389bbe4ae5e 100644 --- a/flang/lib/Lower/ConvertConstant.cpp +++ b/flang/lib/Lower/ConvertConstant.cpp @@ -184,8 +184,8 @@ class DenseGlobalBuilder { if (!attributeElementType || attributes.empty()) return {}; - assert(mlir::isa(symTy) && "expecting an array global"); - auto arrTy = mlir::cast(symTy); + assert(symTy.isa() && "expecting an array global"); + auto arrTy = symTy.cast(); llvm::SmallVector tensorShape(arrTy.getShape()); std::reverse(tensorShape.begin(), tensorShape.end()); auto tensorTy = @@ -423,14 +423,14 @@ static mlir::Value genStructureComponentInit( // address field, which ought to be an intptr_t on the target. mlir::Value addr = fir::getBase( Fortran::lower::genExtAddrInInitializer(converter, loc, expr)); - if (mlir::isa(addr.getType())) + if (addr.getType().isa()) addr = builder.create(loc, addr); assert((fir::isa_ref_type(addr.getType()) || - mlir::isa(addr.getType())) && + addr.getType().isa()) && "expect reference type for address field"); assert(fir::isa_derived(componentTy) && "expect C_PTR, C_FUNPTR to be a record"); - auto cPtrRecTy = mlir::cast(componentTy); + auto cPtrRecTy = componentTy.cast(); llvm::StringRef addrFieldName = Fortran::lower::builtin::cptrFieldName; mlir::Type addrFieldTy = cPtrRecTy.getType(addrFieldName); auto addrField = builder.create( @@ -460,7 +460,7 @@ static mlir::Value genInlinedStructureCtorLitImpl( Fortran::lower::AbstractConverter &converter, mlir::Location loc, const Fortran::evaluate::StructureConstructor &ctor, mlir::Type type) { fir::FirOpBuilder &builder = converter.getFirOpBuilder(); - auto recTy = mlir::cast(type); + auto recTy = type.cast(); if (!converter.getLoweringOptions().getLowerToHighLevelFIR()) { mlir::Value res = builder.create(loc, recTy); @@ -587,7 +587,7 @@ genInlinedArrayLit(Fortran::lower::AbstractConverter &converter, } while (con.IncrementSubscripts(subscripts)); } else if constexpr (T::category == Fortran::common::TypeCategory::Derived) { do { - mlir::Type eleTy = mlir::cast(arrayTy).getEleTy(); + mlir::Type eleTy = arrayTy.cast().getEleTy(); mlir::Value elementVal = genScalarLit(converter, loc, con.At(subscripts), eleTy, /*outlineInReadOnlyMemory=*/false); @@ -597,7 +597,7 @@ genInlinedArrayLit(Fortran::lower::AbstractConverter &converter, } else { llvm::SmallVector rangeStartIdx; uint64_t rangeSize = 0; - mlir::Type eleTy = mlir::cast(arrayTy).getEleTy(); + mlir::Type eleTy = arrayTy.cast().getEleTy(); do { auto getElementVal = [&]() { return builder.createConvert(loc, eleTy, @@ -620,11 +620,12 @@ genInlinedArrayLit(Fortran::lower::AbstractConverter &converter, llvm::SmallVector rangeBounds; llvm::SmallVector idx = createIdx(); for (size_t i = 0; i < idx.size(); ++i) { - rangeBounds.push_back(mlir::cast(rangeStartIdx[i]) + rangeBounds.push_back(rangeStartIdx[i] + .cast() .getValue() .getSExtValue()); rangeBounds.push_back( - mlir::cast(idx[i]).getValue().getSExtValue()); + idx[i].cast().getValue().getSExtValue()); } array = builder.create( loc, arrayTy, array, getElementVal(), @@ -646,7 +647,7 @@ genOutlineArrayLit(Fortran::lower::AbstractConverter &converter, mlir::Location loc, mlir::Type arrayTy, const Fortran::evaluate::Constant &constant) { fir::FirOpBuilder &builder = converter.getFirOpBuilder(); - mlir::Type eleTy = mlir::cast(arrayTy).getEleTy(); + mlir::Type eleTy = arrayTy.cast().getEleTy(); llvm::StringRef globalName = converter.getUniqueLitName( loc, std::make_unique(toEvExpr(constant)), eleTy); diff --git a/flang/lib/Lower/ConvertExpr.cpp b/flang/lib/Lower/ConvertExpr.cpp index 9567685aa3d2e..fb7807718ff88 100644 --- a/flang/lib/Lower/ConvertExpr.cpp +++ b/flang/lib/Lower/ConvertExpr.cpp @@ -267,7 +267,7 @@ arrayLoadExtValue(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Type ty = fir::applyPathToType(arrTy, path); if (!ty) fir::emitFatalError(loc, "path does not apply to type"); - if (!mlir::isa(ty)) { + if (!ty.isa()) { if (fir::isa_char(ty)) { mlir::Value len = newLen; if (!len) @@ -282,7 +282,7 @@ arrayLoadExtValue(fir::FirOpBuilder &builder, mlir::Location loc, } return newBase; } - arrTy = mlir::cast(ty); + arrTy = ty.cast(); } auto arrayToExtendedValue = @@ -412,15 +412,15 @@ static fir::ExtendedValue genLoad(fir::FirOpBuilder &builder, return addr.match( [](const fir::CharBoxValue &box) -> fir::ExtendedValue { return box; }, [&](const fir::PolymorphicValue &p) -> fir::ExtendedValue { - if (mlir::isa( - fir::unwrapRefType(fir::getBase(p).getType()))) + if (fir::unwrapRefType(fir::getBase(p).getType()) + .isa()) return p; mlir::Value load = builder.create(loc, fir::getBase(p)); return fir::PolymorphicValue(load, p.getSourceBox()); }, [&](const fir::UnboxedValue &v) -> fir::ExtendedValue { - if (mlir::isa( - fir::unwrapRefType(fir::getBase(v).getType()))) + if (fir::unwrapRefType(fir::getBase(v).getType()) + .isa()) return v; return builder.create(loc, fir::getBase(v)); }, @@ -536,8 +536,8 @@ static mlir::Value createBoxProcCharTuple(Fortran::lower::AbstractConverter &converter, mlir::Type argTy, mlir::Value funcAddr, mlir::Value charLen) { - auto boxTy = mlir::cast( - mlir::cast(argTy).getType(0)); + auto boxTy = + argTy.cast().getType(0).cast(); mlir::Location loc = converter.getCurrentLocation(); auto &builder = converter.getFirOpBuilder(); @@ -549,7 +549,7 @@ createBoxProcCharTuple(Fortran::lower::AbstractConverter &converter, mlir::Type toTy = boxTy.getEleTy(); if (fir::isa_ref_type(fromTy)) funcAddr = builder.createConvert(loc, toTy, funcAddr); - else if (mlir::isa(fromTy)) + else if (fromTy.isa()) funcAddr = builder.create(loc, toTy, funcAddr); auto boxProc = [&]() -> mlir::Value { @@ -575,7 +575,7 @@ absentBoxToUnallocatedBox(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Value isPresent) { mlir::Value box = fir::getBase(exv); mlir::Type boxType = box.getType(); - assert(mlir::isa(boxType) && "argument must be a fir.box"); + assert(boxType.isa() && "argument must be a fir.box"); mlir::Value emptyBox = fir::factory::createUnallocatedBox(builder, loc, boxType, std::nullopt); auto safeToReadBox = @@ -915,7 +915,7 @@ class ScalarExprLowering { if (inInitializer) return Fortran::lower::genInlinedStructureCtorLit(converter, loc, ctor); mlir::Type ty = translateSomeExprToFIRType(converter, toEvExpr(ctor)); - auto recTy = mlir::cast(ty); + auto recTy = ty.cast(); auto fieldTy = fir::FieldType::get(ty.getContext()); mlir::Value res = builder.createTemporary(loc, recTy); mlir::Value box = builder.createBox(loc, fir::ExtendedValue{res}); @@ -1172,8 +1172,8 @@ class ScalarExprLowering { if (!charBox) fir::emitFatalError(loc, "expected scalar character"); mlir::Value charAddr = charBox->getAddr(); - auto charType = mlir::cast( - fir::unwrapPassByRefType(charAddr.getType())); + auto charType = + fir::unwrapPassByRefType(charAddr.getType()).cast(); if (charType.hasConstantLen()) { // Erase previous constant length from the base type. fir::CharacterType::LenType newLen = fir::CharacterType::unknownLen(); @@ -1441,7 +1441,7 @@ class ScalarExprLowering { auto fldTy = fir::FieldType::get(&converter.getMLIRContext()); // FIXME: need to thread the LEN type parameters here. for (const Fortran::evaluate::Component *field : list) { - auto recTy = mlir::cast(ty); + auto recTy = ty.cast(); const Fortran::semantics::Symbol &sym = getLastSym(*field); std::string name = converter.getRecordTypeFieldName(sym); coorArgs.push_back(builder.create( @@ -1478,7 +1478,7 @@ class ScalarExprLowering { mlir::Type genSubType(mlir::Type arrTy, unsigned dims) { mlir::Type unwrapTy = fir::dyn_cast_ptrOrBoxEleTy(arrTy); assert(unwrapTy && "must be a pointer or box type"); - auto seqTy = mlir::cast(unwrapTy); + auto seqTy = unwrapTy.cast(); llvm::ArrayRef shape = seqTy.getShape(); assert(shape.size() > 0 && "removing columns for sequence sans shape"); assert(dims <= shape.size() && "removing more columns than exist"); @@ -1550,9 +1550,9 @@ class ScalarExprLowering { } mlir::Type eleTy = fir::dyn_cast_ptrOrBoxEleTy(base.getType()); - if (auto classTy = mlir::dyn_cast(eleTy)) + if (auto classTy = eleTy.dyn_cast()) eleTy = classTy.getEleTy(); - auto seqTy = mlir::cast(eleTy); + auto seqTy = eleTy.cast(); assert(args.size() == seqTy.getDimension()); mlir::Type ty = builder.getRefType(seqTy.getEleTy()); auto addr = builder.create(loc, ty, base, args); @@ -1571,7 +1571,7 @@ class ScalarExprLowering { mlir::Location loc = getLoc(); mlir::Value addr = fir::getBase(array); mlir::Type arrTy = fir::dyn_cast_ptrEleTy(addr.getType()); - auto eleTy = mlir::cast(arrTy).getEleTy(); + auto eleTy = arrTy.cast().getEleTy(); mlir::Type seqTy = builder.getRefType(builder.getVarLenSeqTy(eleTy)); mlir::Type refTy = builder.getRefType(eleTy); mlir::Value base = builder.createConvert(loc, seqTy, addr); @@ -1656,7 +1656,7 @@ class ScalarExprLowering { mlir::Location loc = getLoc(); mlir::Value addr = fir::getBase(exv); mlir::Type arrTy = fir::dyn_cast_ptrOrBoxEleTy(addr.getType()); - mlir::Type eleTy = mlir::cast(arrTy).getEleTy(); + mlir::Type eleTy = arrTy.cast().getEleTy(); mlir::Type refTy = builder.getRefType(eleTy); mlir::IndexType idxTy = builder.getIndexType(); llvm::SmallVector arrayCoorArgs; @@ -1766,9 +1766,8 @@ class ScalarExprLowering { mlir::Location loc = getLoc(); ExtValue exv = genBoxArg(expr); auto exvTy = fir::getBase(exv).getType(); - if (mlir::isa(exvTy)) { - auto boxProcTy = - builder.getBoxProcType(mlir::cast(exvTy)); + if (exvTy.isa()) { + auto boxProcTy = builder.getBoxProcType(exvTy.cast()); return builder.create(loc, boxProcTy, fir::getBase(exv)); } @@ -1862,7 +1861,7 @@ class ScalarExprLowering { // IS_CONTIGUOUS may require an assumed size TYPE(*) to be passed to // the intrinsic library utility as a fir.box. if (argRules.lowerAs == fir::LowerIntrinsicArgAs::Box && - !mlir::isa(fir::getBase(exv).getType())) { + !fir::getBase(exv).getType().isa()) { operands.emplace_back( fir::factory::createBoxValue(builder, loc, exv)); continue; @@ -2006,7 +2005,7 @@ class ScalarExprLowering { fir::getTypeParams(mold); mlir::Value charLen; mlir::Type elementType = fir::unwrapSequenceType(type); - if (auto charType = mlir::dyn_cast(elementType)) { + if (auto charType = elementType.dyn_cast()) { charLen = allocMemTypeParams.empty() ? fir::factory::readCharLen(builder, loc, mold) : allocMemTypeParams[0]; @@ -2018,7 +2017,7 @@ class ScalarExprLowering { mlir::Value temp = builder.create( loc, type, tempName, allocMemTypeParams, extents); - if (mlir::isa(fir::unwrapSequenceType(type))) + if (fir::unwrapSequenceType(type).isa()) return fir::CharArrayBoxValue{temp, charLen, extents}; return fir::ArrayBoxValue{temp, extents}; } @@ -2167,7 +2166,7 @@ class ScalarExprLowering { // We have to initialize the temp if it may have components // that need initialization. If there are no components // requiring initialization, then the call is a no-op. - if (mlir::isa(getElementTypeOf(temp))) { + if (getElementTypeOf(temp).isa()) { mlir::Value tempBox = fir::getBase(builder.createBox(loc, temp)); fir::runtime::genDerivedTypeInitialize(builder, loc, tempBox); } @@ -2313,7 +2312,7 @@ class ScalarExprLowering { if (!copyOutPair.restrictCopyAndFreeAtRuntime) { doCopyOut(); - if (mlir::isa(fir::getElementTypeOf(copyOutPair.temp))) { + if (fir::getElementTypeOf(copyOutPair.temp).isa()) { // Destroy components of the temporary (if any). // If there are no components requiring destruction, then the call // is a no-op. @@ -2331,8 +2330,7 @@ class ScalarExprLowering { builder.genIfThen(loc, *copyOutPair.restrictCopyAndFreeAtRuntime) .genThen([&]() { doCopyOut(); - if (mlir::isa( - fir::getElementTypeOf(copyOutPair.temp))) { + if (fir::getElementTypeOf(copyOutPair.temp).isa()) { // Destroy components of the temporary (if any). // If there are no components requiring destruction, then the call // is a no-op. @@ -2383,7 +2381,7 @@ class ScalarExprLowering { mlir::Value actualArgBase = fir::getBase(actualArg); mlir::Value isPresent = builder.create( loc, builder.getI1Type(), actualArgBase); - if (!mlir::isa(actualArgBase.getType())) + if (!actualArgBase.getType().isa()) return {actualArg, isPresent}; ExtValue safeToReadBox = absentBoxToUnallocatedBox(builder, loc, actualArg, isPresent); @@ -2410,7 +2408,7 @@ class ScalarExprLowering { fir::getAdaptToByRefAttr(builder)}); return fir::CharBoxValue{temp, len}; } - assert((fir::isa_trivial(type) || mlir::isa(type)) && + assert((fir::isa_trivial(type) || type.isa()) && "must be simple scalar"); return builder.createTemporary(loc, type, llvm::ArrayRef{ @@ -2587,7 +2585,7 @@ class ScalarExprLowering { // callee side, and it is illegal to use NULL without a MOLD if any // dummy length parameters are assumed. mlir::Type boxTy = fir::dyn_cast_ptrEleTy(argTy); - assert(boxTy && mlir::isa(boxTy) && + assert(boxTy && boxTy.isa() && "must be a fir.box type"); mlir::Value boxStorage = builder.createTemporary(loc, boxTy); mlir::Value nullBox = fir::factory::createUnallocatedBox( @@ -2645,11 +2643,10 @@ class ScalarExprLowering { // If a character procedure was passed instead, handle the // mismatch. auto funcTy = - mlir::dyn_cast(x.getAddr().getType()); + x.getAddr().getType().dyn_cast(); if (funcTy && funcTy.getNumResults() == 1 && - mlir::isa(funcTy.getResult(0))) { - auto boxTy = - mlir::cast(funcTy.getResult(0)); + funcTy.getResult(0).isa()) { + auto boxTy = funcTy.getResult(0).cast(); mlir::Value ref = builder.createConvert( loc, builder.getRefType(boxTy.getEleTy()), x.getAddr()); auto len = builder.create( @@ -2670,7 +2667,7 @@ class ScalarExprLowering { // free-casting the base address to be a !fir.char reference and // setting the LEN argument to undefined. What could go wrong? auto dataPtr = fir::getBase(x); - assert(!mlir::isa(dataPtr.getType())); + assert(!dataPtr.getType().template isa()); return builder.convertWithSemantics( loc, argTy, dataPtr, /*allowCharacterConversion=*/true); @@ -2745,7 +2742,7 @@ class ScalarExprLowering { loc, fir::ClassType::get(mlir::NoneType::get(builder.getContext())), box); - } else if (mlir::isa(box.getType()) && + } else if (box.getType().isa() && fir::isPolymorphicType(argTy)) { box = builder.create(loc, argTy, box, mlir::Value{}, /*slice=*/mlir::Value{}); @@ -2794,7 +2791,7 @@ class ScalarExprLowering { : builder.createBox(getLoc(), genTempExtAddr(*expr), fir::isPolymorphicType(argTy), fir::isAssumedType(argTy)); - if (mlir::isa(box.getType()) && + if (box.getType().isa() && fir::isPolymorphicType(argTy) && !fir::isAssumedType(argTy)) { mlir::Type actualTy = argTy; if (Fortran::lower::isParentComponent(*expr)) @@ -3033,11 +3030,10 @@ class ScalarExprLowering { Fortran::common::ScopedSet(semant, PushVal); static bool isAdjustedArrayElementType(mlir::Type t) { - return fir::isa_char(t) || fir::isa_derived(t) || - mlir::isa(t); + return fir::isa_char(t) || fir::isa_derived(t) || t.isa(); } static bool elementTypeWasAdjusted(mlir::Type t) { - if (auto ty = mlir::dyn_cast(t)) + if (auto ty = t.dyn_cast()) return isAdjustedArrayElementType(ty.getEleTy()); return false; } @@ -3054,15 +3050,15 @@ static void genScalarUserDefinedAssignmentCall(fir::FirOpBuilder &builder, auto prepareUserDefinedArg = [](fir::FirOpBuilder &builder, mlir::Location loc, const fir::ExtendedValue &value, mlir::Type argType) -> mlir::Value { - if (mlir::isa(argType)) { + if (argType.isa()) { const fir::CharBoxValue *charBox = value.getCharBox(); assert(charBox && "argument type mismatch in elemental user assignment"); return fir::factory::CharacterExprHelper{builder, loc}.createEmbox( *charBox); } - if (mlir::isa(argType)) { + if (argType.isa()) { mlir::Value box = - builder.createBox(loc, value, mlir::isa(argType)); + builder.createBox(loc, value, argType.isa()); return builder.createConvert(loc, argType, box); } // Simple pass by address. @@ -3174,7 +3170,7 @@ convertToArrayBoxValue(mlir::Location loc, fir::FirOpBuilder &builder, mlir::Value val, mlir::Value len) { mlir::Type ty = fir::unwrapRefType(val.getType()); mlir::IndexType idxTy = builder.getIndexType(); - auto seqTy = mlir::cast(ty); + auto seqTy = ty.cast(); auto undef = builder.create(loc, idxTy); llvm::SmallVector extents(seqTy.getDimension(), undef); if (fir::isa_char(seqTy.getEleTy())) @@ -3466,7 +3462,7 @@ class ArrayExprLowering { [&](const auto &e) { auto f = genarr(e); ExtValue exv = f(IterationSpace{}); - if (mlir::isa(fir::getBase(exv).getType())) + if (fir::getBase(exv).getType().template isa()) return exv; fir::emitFatalError(getLoc(), "array must be emboxed"); }, @@ -3491,9 +3487,10 @@ class ArrayExprLowering { tempRes, dest.getSlice(), dest.getTypeparams()); - auto arrTy = mlir::cast( - fir::dyn_cast_ptrEleTy(tempRes.getType())); - if (auto charTy = mlir::dyn_cast(arrTy.getEleTy())) { + auto arrTy = + fir::dyn_cast_ptrEleTy(tempRes.getType()).cast(); + if (auto charTy = + arrTy.getEleTy().template dyn_cast()) { if (fir::characterWithDynamicLen(charTy)) TODO(loc, "CHARACTER does not have constant LEN"); mlir::Value len = builder.createIntegerConstant( @@ -3915,18 +3912,17 @@ class ArrayExprLowering { mlir::Value convertElementForUpdate(mlir::Location loc, mlir::Type eleTy, mlir::Value origVal) { if (auto origEleTy = fir::dyn_cast_ptrEleTy(origVal.getType())) - if (mlir::isa(origEleTy)) { + if (origEleTy.isa()) { // If origVal is a box variable, load it so it is in the value domain. origVal = builder.create(loc, origVal); } - if (mlir::isa(origVal.getType()) && - !mlir::isa(eleTy)) { + if (origVal.getType().isa() && !eleTy.isa()) { if (isPointerAssignment()) TODO(loc, "lhs of pointer assignment returned unexpected value"); TODO(loc, "invalid box conversion in elemental computation"); } - if (isPointerAssignment() && mlir::isa(eleTy) && - !mlir::isa(origVal.getType())) { + if (isPointerAssignment() && eleTy.isa() && + !origVal.getType().isa()) { // This is a pointer assignment and the rhs is a raw reference to a TARGET // in memory. Embox the reference so it can be stored to the boxed // POINTER variable. @@ -3934,7 +3930,7 @@ class ArrayExprLowering { if (auto eleTy = fir::dyn_cast_ptrEleTy(origVal.getType()); fir::hasDynamicSize(eleTy)) TODO(loc, "TARGET of pointer assignment with runtime size/shape"); - auto memrefTy = fir::boxMemRefType(mlir::cast(eleTy)); + auto memrefTy = fir::boxMemRefType(eleTy.cast()); auto castTo = builder.createConvert(loc, memrefTy, origVal); origVal = builder.create(loc, eleTy, castTo); } @@ -3986,7 +3982,7 @@ class ArrayExprLowering { auto arrayOp = builder.create( loc, resRefTy, innerArg, iterSpace.iterVec(), fir::factory::getTypeParams(loc, builder, destination)); - if (auto charTy = mlir::dyn_cast(eleTy)) { + if (auto charTy = eleTy.dyn_cast()) { llvm::SmallVector substringBounds; populateBounds(substringBounds, substring); mlir::Value dstLen = fir::factory::genLenOfCharacter( @@ -4000,7 +3996,7 @@ class ArrayExprLowering { loc, destination, builder, arrayOp, exv, eleTy, innerArg); return abstractArrayExtValue(amend /*FIXME: typeparams?*/); } - assert(mlir::isa(eleTy) && "must be an array"); + assert(eleTy.isa() && "must be an array"); TODO(loc, "array (as element) assignment"); } // By value semantics. The element is being assigned by value. @@ -4064,7 +4060,7 @@ class ArrayExprLowering { llvm::SmallVector getShape(ArrayOperand array) { if (array.slice) return computeSliceShape(array.slice); - if (mlir::isa(array.memref.getType())) + if (array.memref.getType().isa()) return fir::factory::readExtents(builder, getLoc(), fir::BoxValue{array.memref}); return fir::factory::getExtents(array.shape); @@ -4137,7 +4133,7 @@ class ArrayExprLowering { mlir::Location loc = getLoc(); return [=, builder = &converter.getFirOpBuilder()](IterSpace iters) { mlir::Type arrTy = fir::dyn_cast_ptrOrBoxEleTy(tmp.getType()); - auto eleTy = mlir::cast(arrTy).getEleTy(); + auto eleTy = arrTy.cast().getEleTy(); mlir::Type eleRefTy = builder->getRefType(eleTy); mlir::IntegerType i1Ty = builder->getI1Type(); // Adjust indices for any shift of the origin of the array. @@ -4446,15 +4442,15 @@ class ArrayExprLowering { TODO(loc, "polymorphic array temporary"); if (ccLoadDest) return (*ccLoadDest)(shape); - auto seqTy = mlir::dyn_cast(type); + auto seqTy = type.dyn_cast(); assert(seqTy && "must be an array"); // TODO: Need to thread the LEN parameters here. For character, they may // differ from the operands length (e.g concatenation). So the array loads // type parameters are not enough. - if (auto charTy = mlir::dyn_cast(seqTy.getEleTy())) + if (auto charTy = seqTy.getEleTy().dyn_cast()) if (charTy.hasDynamicLen()) TODO(loc, "character array expression temp with dynamic length"); - if (auto recTy = mlir::dyn_cast(seqTy.getEleTy())) + if (auto recTy = seqTy.getEleTy().dyn_cast()) if (recTy.getNumLenParams() > 0) TODO(loc, "derived type array expression temp with LEN parameters"); if (mlir::Type eleTy = fir::unwrapSequenceType(type); @@ -4831,7 +4827,7 @@ class ArrayExprLowering { }); } else { ExtValue exv = asScalarRef(*expr); - if (mlir::isa(fir::getBase(exv).getType())) { + if (fir::getBase(exv).getType().isa()) { operands.emplace_back( [=](IterSpace iters) -> ExtValue { return exv; }); } else { @@ -5569,7 +5565,7 @@ class ArrayExprLowering { } static mlir::Type unwrapBoxEleTy(mlir::Type ty) { - if (auto boxTy = mlir::dyn_cast(ty)) + if (auto boxTy = ty.dyn_cast()) return fir::unwrapRefType(boxTy.getEleTy()); return ty; } @@ -5579,7 +5575,7 @@ class ArrayExprLowering { ty = unwrapBoxEleTy(ty); mlir::Location loc = getLoc(); mlir::IndexType idxTy = builder.getIndexType(); - for (auto extent : mlir::cast(ty).getShape()) { + for (auto extent : ty.cast().getShape()) { auto v = extent == fir::SequenceType::getUnknownExtent() ? builder.create(loc, idxTy).getResult() : builder.createIntegerConstant(loc, idxTy, extent); @@ -5642,8 +5638,7 @@ class ArrayExprLowering { mlir::Location loc = getLoc(); mlir::Value memref = fir::getBase(extMemref); mlir::Type arrTy = fir::dyn_cast_ptrOrBoxEleTy(memref.getType()); - assert(mlir::isa(arrTy) && - "memory ref must be an array"); + assert(arrTy.isa() && "memory ref must be an array"); mlir::Value shape = builder.createShape(loc, extMemref); mlir::Value slice; if (components.isSlice()) { @@ -5693,12 +5688,12 @@ class ArrayExprLowering { components.suffixComponents); } if (components.hasComponents()) { - auto seqTy = mlir::cast(arrTy); + auto seqTy = arrTy.cast(); mlir::Type eleTy = fir::applyPathToType(seqTy.getEleTy(), components.suffixComponents); if (!eleTy) fir::emitFatalError(loc, "slicing path is ill-formed"); - if (auto realTy = mlir::dyn_cast(eleTy)) + if (auto realTy = eleTy.dyn_cast()) eleTy = Fortran::lower::convertReal(realTy.getContext(), realTy.getFKind()); @@ -5718,14 +5713,13 @@ class ArrayExprLowering { // value. The value of the box is forwarded in the continuation. mlir::Type reduceTy = reduceRank(arrTy, slice); mlir::Type boxTy = fir::BoxType::get(reduceTy); - if (mlir::isa(memref.getType()) && - !components.hasComponents()) + if (memref.getType().isa() && !components.hasComponents()) boxTy = fir::ClassType::get(reduceTy); if (components.substring) { // Adjust char length to substring size. fir::CharacterType charTy = fir::factory::CharacterExprHelper::getCharType(reduceTy); - auto seqTy = mlir::cast(reduceTy); + auto seqTy = reduceTy.cast(); // TODO: Use a constant for fir.char LEN if we can compute it. boxTy = fir::BoxType::get( fir::SequenceType::get(fir::CharacterType::getUnknownLen( @@ -5740,7 +5734,7 @@ class ArrayExprLowering { nonDeferredLenParams = fir::factory::getNonDeferredLenParams(extMemref); } mlir::Value embox = - mlir::isa(memref.getType()) + memref.getType().isa() ? builder.create(loc, boxTy, memref, shape, slice) .getResult() : builder @@ -5751,7 +5745,7 @@ class ArrayExprLowering { return fir::BoxValue(embox, lbounds, nonDeferredLenParams); }; } - auto eleTy = mlir::cast(arrTy).getEleTy(); + auto eleTy = arrTy.cast().getEleTy(); if (isReferentiallyOpaque()) { // Semantics are an opaque reference to an array. // This case forwards a continuation that will generate the address @@ -5766,12 +5760,12 @@ class ArrayExprLowering { mlir::Value coor = builder.create( loc, refEleTy, memref, shape, slice, indices, fir::getTypeParams(extMemref)); - if (auto charTy = mlir::dyn_cast(eleTy)) { + if (auto charTy = eleTy.dyn_cast()) { llvm::SmallVector substringBounds; populateBounds(substringBounds, components.substring); if (!substringBounds.empty()) { mlir::Value dstLen = fir::factory::genLenOfCharacter( - builder, loc, mlir::cast(arrTy), memref, + builder, loc, arrTy.cast(), memref, fir::getTypeParams(extMemref), iters.iterVec(), substringBounds); fir::CharBoxValue dstChar(coor, dstLen); @@ -5869,7 +5863,7 @@ class ArrayExprLowering { mlir::Type eleRefTy = builder.getRefType(eleTy); mlir::Value arrayOp = builder.create( loc, eleRefTy, arrLd, iters.iterVec(), arrLdTypeParams); - if (auto charTy = mlir::dyn_cast(eleTy)) { + if (auto charTy = eleTy.dyn_cast()) { llvm::SmallVector substringBounds; populateBounds(substringBounds, components.substring); if (!substringBounds.empty()) { @@ -5902,7 +5896,7 @@ class ArrayExprLowering { const bool hasOptionalAttr = fir::valueHasFirAttribute(base, fir::getOptionalAttrName()); mlir::Type baseType = fir::unwrapRefType(base.getType()); - const bool isBox = mlir::isa(baseType); + const bool isBox = baseType.isa(); const bool isAllocOrPtr = Fortran::evaluate::IsAllocatableOrPointerObject(expr); mlir::Type arrType = fir::unwrapPassByRefType(baseType); @@ -5995,7 +5989,7 @@ class ArrayExprLowering { if (slice) { auto slOp = mlir::dyn_cast(slice.getDefiningOp()); assert(slOp && "expected slice op"); - auto seqTy = mlir::dyn_cast(arrTy); + auto seqTy = arrTy.dyn_cast(); assert(seqTy && "expected array type"); mlir::Operation::operand_range triples = slOp.getTriples(); fir::SequenceType::Shape shape; @@ -6059,7 +6053,7 @@ class ArrayExprLowering { mlir::IndexType idxTy = builder.getIndexType(); mlir::Value multiplier = builder.createIntegerConstant(loc, idxTy, 1); if (fir::hasDynamicSize(eleTy)) { - if (auto charTy = mlir::dyn_cast(eleTy)) { + if (auto charTy = eleTy.dyn_cast()) { // Array of char with dynamic LEN parameter. Downcast to an array // of singleton char, and scale by the len type parameter from // `exv`. @@ -6080,7 +6074,7 @@ class ArrayExprLowering { }); fir::CharacterType newEleTy = fir::CharacterType::getSingleton( eleTy.getContext(), charTy.getFKind()); - if (auto seqTy = mlir::dyn_cast(resTy)) { + if (auto seqTy = resTy.dyn_cast()) { assert(eleTy == seqTy.getEleTy()); resTy = fir::SequenceType::get(seqTy.getShape(), newEleTy); } @@ -6167,7 +6161,7 @@ class ArrayExprLowering { if (!eleSz) { // Compute the element size at runtime. assert(fir::hasDynamicSize(eleTy)); - if (auto charTy = mlir::dyn_cast(eleTy)) { + if (auto charTy = eleTy.dyn_cast()) { auto charBytes = builder.getKindMap().getCharacterBitsize(charTy.getFKind()) / 8; mlir::Value bytes = @@ -6187,7 +6181,7 @@ class ArrayExprLowering { auto computeCoordinate = [&](mlir::Value buff, mlir::Value off) { mlir::Type refTy = eleRefTy; if (fir::hasDynamicSize(eleTy)) { - if (auto charTy = mlir::dyn_cast(eleTy)) { + if (auto charTy = eleTy.dyn_cast()) { // Scale a simple pointer using dynamic length and offset values. auto chTy = fir::CharacterType::getSingleton(charTy.getContext(), charTy.getFKind()); @@ -6314,7 +6308,7 @@ class ArrayExprLowering { builder.createConvert(loc, idxTy, fir::getBase(asScalar(x.upper()))); mlir::Value step = builder.createConvert(loc, idxTy, fir::getBase(asScalar(x.stride()))); - auto seqTy = mlir::cast(resTy); + auto seqTy = resTy.template cast(); mlir::Type eleTy = fir::unwrapSequenceType(seqTy); auto loop = builder.create(loc, lo, up, step, /*unordered=*/false, @@ -6381,7 +6375,7 @@ class ArrayExprLowering { auto evExpr = toEvExpr(x); mlir::Type resTy = translateSomeExprToFIRType(converter, evExpr); mlir::IndexType idxTy = builder.getIndexType(); - auto seqTy = mlir::cast(resTy); + auto seqTy = resTy.template cast(); mlir::Type eleTy = fir::unwrapSequenceType(resTy); mlir::Value buffSize = builder.createTemporary(loc, idxTy, ".buff.size"); mlir::Value zero = builder.createIntegerConstant(loc, idxTy, 0); @@ -6725,7 +6719,7 @@ class ArrayExprLowering { auto fieldTy = fir::FieldType::get(builder.getContext()); std::string name = converter.getRecordTypeFieldName(getLastSym(*x)); - if (auto recTy = mlir::dyn_cast(ty)) { + if (auto recTy = ty.dyn_cast()) { ty = recTy.getType(name); auto fld = builder.create( loc, fieldTy, name, recTy, fir::getTypeParams(arrayExv)); @@ -6734,7 +6728,7 @@ class ArrayExprLowering { // Need an intermediate dereference if the boxed value // appears in the middle of the component path or if it is // on the right and this is not a pointer assignment. - if (auto boxTy = mlir::dyn_cast(ty)) { + if (auto boxTy = ty.dyn_cast()) { auto currentFunc = components.getExtendCoorRef(); auto loc = getLoc(); auto *bldr = &converter.getFirOpBuilder(); @@ -6745,9 +6739,9 @@ class ArrayExprLowering { deref = true; } } - } else if (auto boxTy = mlir::dyn_cast(ty)) { + } else if (auto boxTy = ty.dyn_cast()) { ty = fir::unwrapRefType(boxTy.getEleTy()); - auto recTy = mlir::cast(ty); + auto recTy = ty.cast(); ty = recTy.getType(name); auto fld = builder.create( loc, fieldTy, name, recTy, fir::getTypeParams(arrayExv)); @@ -6796,7 +6790,7 @@ class ArrayExprLowering { auto arrayOp = builder.create( loc, eleRefTy, innerArg, iters.iterVec(), fir::factory::getTypeParams(loc, builder, load)); - if (auto charTy = mlir::dyn_cast(eleTy)) { + if (auto charTy = eleTy.dyn_cast()) { mlir::Value dstLen = fir::factory::genLenOfCharacter( builder, loc, load, iters.iterVec(), substringBounds); fir::ArrayAmendOp amend = createCharArrayAmend( @@ -6812,13 +6806,13 @@ class ArrayExprLowering { return arrayLoadExtValue(builder, loc, load, iters.iterVec(), amend); } - assert(mlir::isa(eleTy)); + assert(eleTy.isa()); TODO(loc, "array (as element) assignment"); } if (components.hasExtendCoorRef()) { auto eleBoxTy = fir::applyPathToType(innerArg.getType(), iters.iterVec()); - if (!eleBoxTy || !mlir::isa(eleBoxTy)) + if (!eleBoxTy || !eleBoxTy.isa()) TODO(loc, "assignment in a FORALL involving a designator with a " "POINTER or ALLOCATABLE component part-ref"); auto arrayOp = builder.create( @@ -6830,7 +6824,7 @@ class ArrayExprLowering { // assignment, then insert the dereference of the box before any // conversion and store. if (!isPointerAssignment()) { - if (auto boxTy = mlir::dyn_cast(eleTy)) { + if (auto boxTy = eleTy.dyn_cast()) { eleTy = fir::boxMemRefType(boxTy); addr = builder.create(loc, eleTy, addr); eleTy = fir::unwrapRefType(eleTy); @@ -6891,7 +6885,7 @@ class ArrayExprLowering { } if (components.hasExtendCoorRef()) { auto eleBoxTy = fir::applyPathToType(load.getType(), iters.iterVec()); - if (!eleBoxTy || !mlir::isa(eleBoxTy)) + if (!eleBoxTy || !eleBoxTy.isa()) TODO(loc, "assignment in a FORALL involving a designator with a " "POINTER or ALLOCATABLE component part-ref"); auto access = builder.create( @@ -6903,7 +6897,7 @@ class ArrayExprLowering { } if (isPointerAssignment()) { auto eleTy = fir::applyPathToType(load.getType(), iters.iterVec()); - if (!mlir::isa(eleTy)) { + if (!eleTy.isa()) { // Rhs is a regular expression that will need to be boxed before // assigning to the boxed variable. auto typeParams = fir::factory::getTypeParams(loc, builder, load); @@ -7621,7 +7615,7 @@ mlir::Value Fortran::lower::addCrayPointerInst(mlir::Location loc, auto box = builder.create(loc, boxTy, ptrVal, empty, empty, emptyRange); mlir::Value addrof = - (mlir::isa(ptrTy)) + (ptrTy.isa()) ? builder.create(loc, ptrTy, box) : builder.create(loc, builder.getRefType(ptrTy), box); diff --git a/flang/lib/Lower/ConvertExprToHLFIR.cpp b/flang/lib/Lower/ConvertExprToHLFIR.cpp index 93bdf650f9ffb..6e57b31d022b0 100644 --- a/flang/lib/Lower/ConvertExprToHLFIR.cpp +++ b/flang/lib/Lower/ConvertExprToHLFIR.cpp @@ -138,8 +138,8 @@ class HlfirDesignatorBuilder { mlir::Location loc = getLoc(); mlir::Type idxTy = builder.getIndexType(); llvm::SmallVector extents; - auto seqTy = mlir::cast( - hlfir::getFortranElementOrSequenceType(fieldType)); + auto seqTy = hlfir::getFortranElementOrSequenceType(fieldType) + .cast(); for (auto extent : seqTy.getShape()) { if (extent == fir::SequenceType::getUnknownExtent()) { // We have already generated invalid hlfir.declare @@ -199,7 +199,7 @@ class HlfirDesignatorBuilder { const T &designatorNode) { // Get base's shape if its a sequence type with no previously computed // result shape - if (partInfo.base && mlir::isa(resultValueType) && + if (partInfo.base && resultValueType.isa() && !partInfo.resultShape) partInfo.resultShape = hlfir::genShape(getLoc(), getBuilder(), *partInfo.base); @@ -209,7 +209,7 @@ class HlfirDesignatorBuilder { return fir::ClassType::get(resultValueType); // Character scalar with dynamic length needs a fir.boxchar to hold the // designator length. - auto charType = mlir::dyn_cast(resultValueType); + auto charType = resultValueType.dyn_cast(); if (charType && charType.hasDynamicLen()) return fir::BoxCharType::get(charType.getContext(), charType.getFKind()); // Arrays with non default lower bounds or dynamic length or dynamic extent @@ -218,7 +218,7 @@ class HlfirDesignatorBuilder { hasNonDefaultLowerBounds(partInfo)) return fir::BoxType::get(resultValueType); // Non simply contiguous ref require a fir.box to carry the byte stride. - if (mlir::isa(resultValueType) && + if (resultValueType.isa() && !Fortran::evaluate::IsSimplyContiguous( designatorNode, getConverter().getFoldingContext())) return fir::BoxType::get(resultValueType); @@ -398,8 +398,8 @@ class HlfirDesignatorBuilder { partInfo.typeParams[0] = fir::factory::genMaxWithZero(builder, loc, rawLen); } - auto kind = mlir::cast( - hlfir::getFortranElementType(baseStringType)) + auto kind = hlfir::getFortranElementType(baseStringType) + .cast() .getFKind(); auto newCharTy = fir::CharacterType::get( baseStringType.getContext(), kind, @@ -579,7 +579,7 @@ class HlfirDesignatorBuilder { return createVectorSubscriptElementAddrOp(partInfo, baseType, resultExtents); - mlir::Type resultType = mlir::cast(baseType).getEleTy(); + mlir::Type resultType = baseType.cast().getEleTy(); if (!resultTypeShape.empty()) { // Ranked array section. The result shape comes from the array section // subscripts. @@ -612,8 +612,8 @@ class HlfirDesignatorBuilder { } static bool hasNonDefaultLowerBounds(const PartInfo &partInfo) { return partInfo.resultShape && - mlir::isa( - partInfo.resultShape.getType()); + (partInfo.resultShape.getType().isa() || + partInfo.resultShape.getType().isa()); } mlir::Type visit(const Fortran::evaluate::Component &component, @@ -705,7 +705,7 @@ class HlfirDesignatorBuilder { const Fortran::semantics::Symbol &componentSym = component.GetLastSymbol(); partInfo.componentName = converter.getRecordTypeFieldName(componentSym); auto recordType = - mlir::cast(hlfir::getFortranElementType(baseType)); + hlfir::getFortranElementType(baseType).cast(); if (recordType.isDependentType()) TODO(getLoc(), "Designate derived type with length parameters in HLFIR"); mlir::Type fieldType = recordType.getType(partInfo.componentName); @@ -718,7 +718,7 @@ class HlfirDesignatorBuilder { if (fir::isRecordWithTypeParameters(fieldEleType)) TODO(loc, "lower a component that is a parameterized derived type to HLFIR"); - if (auto charTy = mlir::dyn_cast(fieldEleType)) { + if (auto charTy = fieldEleType.dyn_cast()) { mlir::Location loc = getLoc(); mlir::Type idxTy = builder.getIndexType(); if (charTy.hasConstantLen()) @@ -811,7 +811,7 @@ class HlfirDesignatorBuilder { } } builder.setInsertionPoint(elementalAddrOp); - return mlir::cast(baseType).getEleTy(); + return baseType.cast().getEleTy(); } /// Yield the designator for the final part-ref inside the @@ -1665,7 +1665,7 @@ class HlfirBuilder { mlir::Location loc = getLoc(); fir::FirOpBuilder &builder = getBuilder(); mlir::Type ty = translateSomeExprToFIRType(converter, toEvExpr(ctor)); - auto recTy = mlir::cast(ty); + auto recTy = ty.cast(); if (recTy.isDependentType()) TODO(loc, "structure constructor for derived type with length parameters " diff --git a/flang/lib/Lower/ConvertProcedureDesignator.cpp b/flang/lib/Lower/ConvertProcedureDesignator.cpp index aa0d7ce54788b..2446be3a1908b 100644 --- a/flang/lib/Lower/ConvertProcedureDesignator.cpp +++ b/flang/lib/Lower/ConvertProcedureDesignator.cpp @@ -107,11 +107,11 @@ static hlfir::EntityWithAttributes designateProcedurePointerComponent( procComponentSym); /// Passed argument may be a descriptor. This is a scalar reference, so the /// base address can be directly addressed. - if (mlir::isa(base.getType())) + if (base.getType().isa()) base = builder.create(loc, base); std::string fieldName = converter.getRecordTypeFieldName(procComponentSym); auto recordType = - mlir::cast(hlfir::getFortranElementType(base.getType())); + hlfir::getFortranElementType(base.getType()).cast(); mlir::Type fieldType = recordType.getType(fieldName); // Note: semantics turns x%p() into x%t%p() when the procedure pointer // component is part of parent component t. @@ -164,7 +164,7 @@ hlfir::EntityWithAttributes Fortran::lower::convertProcedureDesignatorToHLFIR( fir::FirOpBuilder &builder = converter.getFirOpBuilder(); mlir::Value funcAddr = fir::getBase(procExv); - if (!mlir::isa(funcAddr.getType())) { + if (!funcAddr.getType().isa()) { mlir::Type boxTy = Fortran::lower::getUntypedBoxProcType(&converter.getMLIRContext()); if (auto host = Fortran::lower::argumentHostAssocs(converter, funcAddr)) diff --git a/flang/lib/Lower/ConvertVariable.cpp b/flang/lib/Lower/ConvertVariable.cpp index edf1f24a08e5c..21db0cac11bf6 100644 --- a/flang/lib/Lower/ConvertVariable.cpp +++ b/flang/lib/Lower/ConvertVariable.cpp @@ -389,13 +389,13 @@ static mlir::Value genDefaultInitializerValue( fir::FirOpBuilder &builder = converter.getFirOpBuilder(); mlir::Type scalarType = symTy; fir::SequenceType sequenceType; - if (auto ty = mlir::dyn_cast(symTy)) { + if (auto ty = symTy.dyn_cast()) { sequenceType = ty; scalarType = ty.getEleTy(); } // Build a scalar default value of the symbol type, looping through the // components to build each component initial value. - auto recTy = mlir::cast(scalarType); + auto recTy = scalarType.cast(); mlir::Value initialValue = builder.create(loc, scalarType); const Fortran::semantics::DeclTypeSpec *declTy = sym.GetType(); assert(declTy && "var with default initialization must have a type"); @@ -493,9 +493,9 @@ static fir::GlobalOp defineGlobal(Fortran::lower::AbstractConverter &converter, // with a tensor mlir type. This optimization currently only supports // Fortran arrays of integer, real, complex, or logical. The tensor // type does not support nested structures. - if (mlir::isa(symTy) && + if (symTy.isa() && !Fortran::semantics::IsAllocatableOrPointer(sym)) { - mlir::Type eleTy = mlir::cast(symTy).getEleTy(); + mlir::Type eleTy = symTy.cast().getEleTy(); if (eleTy.isa()) { const auto *details = @@ -1292,7 +1292,7 @@ static void finalizeCommonBlockDefinition( fir::GlobalOp global, const Fortran::semantics::MutableSymbolVector &cmnBlkMems) { fir::FirOpBuilder &builder = converter.getFirOpBuilder(); - mlir::TupleType commonTy = mlir::cast(global.getType()); + mlir::TupleType commonTy = global.getType().cast(); auto initFunc = [&](fir::FirOpBuilder &builder) { mlir::IndexType idxTy = builder.getIndexType(); mlir::Value cb = builder.create(loc, commonTy); @@ -1407,7 +1407,7 @@ static bool lowerToBoxValue(const Fortran::semantics::Symbol &sym, mlir::Value dummyArg, Fortran::lower::AbstractConverter &converter) { // Only dummy arguments coming as fir.box can be tracked in an BoxValue. - if (!dummyArg || !mlir::isa(dummyArg.getType())) + if (!dummyArg || !dummyArg.getType().isa()) return false; // Non contiguous arrays must be tracked in an BoxValue. if (sym.Rank() > 0 && !Fortran::evaluate::IsSimplyContiguous( @@ -1905,7 +1905,7 @@ void Fortran::lower::mapSymbolAttributes( // Do not keep scalar characters as fir.box (even when optional). // Lowering and FIR is not meant to deal with scalar characters as // fir.box outside of calls. - auto boxTy = mlir::dyn_cast(dummyArg.getType()); + auto boxTy = dummyArg.getType().dyn_cast(); mlir::Type refTy = builder.getRefType(boxTy.getEleTy()); mlir::Type lenType = builder.getCharacterLengthType(); mlir::Value addr, len; @@ -1984,8 +1984,8 @@ void Fortran::lower::mapSymbolAttributes( // a non pointer/allocatable symbol to be mapped to a MutableBox. mlir::Type ty = converter.genType(var); bool isPolymorphic = false; - if (auto boxTy = mlir::dyn_cast(ty)) { - isPolymorphic = mlir::isa(ty); + if (auto boxTy = ty.dyn_cast()) { + isPolymorphic = ty.isa(); ty = boxTy.getEleTy(); } Fortran::lower::genDeclareSymbol( @@ -2092,7 +2092,7 @@ void Fortran::lower::mapSymbolAttributes( mlir::Value addr = preAlloc; if (arg) - if (auto boxTy = mlir::dyn_cast(arg.getType())) { + if (auto boxTy = arg.getType().dyn_cast()) { // Contiguous assumed shape that can be tracked without a fir.box. mlir::Type refTy = builder.getRefType(boxTy.getEleTy()); addr = builder.create(loc, refTy, arg); @@ -2134,7 +2134,7 @@ void Fortran::lower::mapSymbolAttributes( } else if (!len) { // Assumed length fir.box (possible for contiguous assumed shapes). // Read length from box. - assert(arg && mlir::isa(arg.getType()) && + assert(arg && arg.getType().isa() && "must be character dummy fir.box"); len = charHelp.readLengthFromBox(arg); } diff --git a/flang/lib/Lower/CustomIntrinsicCall.cpp b/flang/lib/Lower/CustomIntrinsicCall.cpp index 30c6ce7f53b3f..439fc3d915b4e 100644 --- a/flang/lib/Lower/CustomIntrinsicCall.cpp +++ b/flang/lib/Lower/CustomIntrinsicCall.cpp @@ -227,23 +227,22 @@ lowerIshftc(fir::FirOpBuilder &builder, mlir::Location loc, args.push_back(getOperand(1, loadOperand)); auto iPC = isPresentCheck(2); assert(iPC.has_value()); - args.push_back( - builder - .genIfOp(loc, {resultType}, *iPC, - /*withElseRegion=*/true) - .genThen([&]() { - fir::ExtendedValue sizeExv = getOperand(2, loadOperand); - mlir::Value size = - builder.createConvert(loc, resultType, fir::getBase(sizeExv)); - builder.create(loc, size); - }) - .genElse([&]() { - mlir::Value bitSize = builder.createIntegerConstant( - loc, resultType, - mlir::cast(resultType).getWidth()); - builder.create(loc, bitSize); - }) - .getResults()[0]); + args.push_back(builder + .genIfOp(loc, {resultType}, *iPC, + /*withElseRegion=*/true) + .genThen([&]() { + fir::ExtendedValue sizeExv = getOperand(2, loadOperand); + mlir::Value size = builder.createConvert( + loc, resultType, fir::getBase(sizeExv)); + builder.create(loc, size); + }) + .genElse([&]() { + mlir::Value bitSize = builder.createIntegerConstant( + loc, resultType, + resultType.cast().getWidth()); + builder.create(loc, bitSize); + }) + .getResults()[0]); return genIntrinsicCall(builder, loc, name, resultType, args, stmtCtx); } @@ -283,7 +282,7 @@ lowerAssociated(fir::FirOpBuilder &builder, mlir::Location loc, builder.create(loc, builder.getI1Type(), targetBase); mlir::Type targetType = fir::unwrapRefType(targetBase.getType()); mlir::Type targetValueType = fir::unwrapPassByRefType(targetType); - mlir::Type boxType = mlir::isa(targetType) + mlir::Type boxType = targetType.isa() ? targetType : fir::BoxType::get(targetValueType); fir::BoxValue targetBox = diff --git a/flang/lib/Lower/DirectivesCommon.h b/flang/lib/Lower/DirectivesCommon.h index 42bd3868196b2..3ebf3fd965da1 100644 --- a/flang/lib/Lower/DirectivesCommon.h +++ b/flang/lib/Lower/DirectivesCommon.h @@ -642,14 +642,14 @@ getDataOperandBaseAddr(Fortran::lower::AbstractConverter &converter, isPresent = builder.create(loc, builder.getI1Type(), rawInput); - if (auto boxTy = mlir::dyn_cast( - fir::unwrapRefType(symAddr.getType()))) { - if (mlir::isa(boxTy.getEleTy())) + if (auto boxTy = + fir::unwrapRefType(symAddr.getType()).dyn_cast()) { + if (boxTy.getEleTy().isa()) TODO(loc, "derived type"); // Load the box when baseAddr is a `fir.ref>` or a // `fir.ref>` type. - if (mlir::isa(symAddr.getType())) { + if (symAddr.getType().isa()) { if (Fortran::semantics::IsOptional(sym)) { mlir::Value addr = builder.genIfOp(loc, {boxTy}, isPresent, /*withElseRegion=*/true) @@ -722,7 +722,7 @@ genBoundsOpsFromBox(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Type idxTy = builder.getIndexType(); mlir::Type boundTy = builder.getType(); - assert(mlir::isa(info.addr.getType()) && + assert(info.addr.getType().isa() && "expect fir.box or fir.class"); if (info.isPresent) { @@ -909,8 +909,7 @@ genBoundsOps(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Value stride = one; bool strideInBytes = false; - if (mlir::isa( - fir::unwrapRefType(info.addr.getType()))) { + if (fir::unwrapRefType(info.addr.getType()).isa()) { if (info.isPresent) { stride = builder @@ -1021,8 +1020,8 @@ genBoundsOps(fir::FirOpBuilder &builder, mlir::Location loc, } } - if (info.isPresent && mlir::isa( - fir::unwrapRefType(info.addr.getType()))) { + if (info.isPresent && + fir::unwrapRefType(info.addr.getType()).isa()) { extent = builder .genIfOp(loc, idxTy, info.isPresent, /*withElseRegion=*/true) @@ -1158,7 +1157,7 @@ AddrAndBoundsInfo gatherDataOperandAddrAndBounds( converter.genExprAddr(operandLocation, designator, stmtCtx); info.addr = fir::getBase(compExv); info.rawInput = info.addr; - if (mlir::isa(fir::unwrapRefType(info.addr.getType()))) + if (fir::unwrapRefType(info.addr.getType()).isa()) bounds = genBaseBoundsOps(builder, operandLocation, converter, compExv, /*isAssumedSize=*/false); @@ -1200,14 +1199,13 @@ AddrAndBoundsInfo gatherDataOperandAddrAndBounds( fir::ExtendedValue dataExv = converter.getSymbolExtendedValue(*symRef); info = getDataOperandBaseAddr(converter, builder, *symRef, operandLocation); - if (mlir::isa( - fir::unwrapRefType(info.addr.getType()))) { + if (fir::unwrapRefType(info.addr.getType()).isa()) { bounds = genBoundsOpsFromBox( builder, operandLocation, converter, dataExv, info); } bool dataExvIsAssumedSize = Fortran::semantics::IsAssumedSizeArray(symRef->get().GetUltimate()); - if (mlir::isa(fir::unwrapRefType(info.addr.getType()))) + if (fir::unwrapRefType(info.addr.getType()).isa()) bounds = genBaseBoundsOps( builder, operandLocation, converter, dataExv, dataExvIsAssumedSize); asFortran << symRef->get().name().ToString(); diff --git a/flang/lib/Lower/HlfirIntrinsics.cpp b/flang/lib/Lower/HlfirIntrinsics.cpp index 310b62697f710..bda04fa9689be 100644 --- a/flang/lib/Lower/HlfirIntrinsics.cpp +++ b/flang/lib/Lower/HlfirIntrinsics.cpp @@ -265,7 +265,7 @@ HlfirTransformationalIntrinsic::computeResultType(mlir::Value argArray, mlir::Type stmtResultType) { mlir::Type normalisedResult = hlfir::getFortranElementOrSequenceType(stmtResultType); - if (auto array = mlir::dyn_cast(normalisedResult)) { + if (auto array = normalisedResult.dyn_cast()) { hlfir::ExprType::Shape resultShape = hlfir::ExprType::Shape{array.getShape()}; mlir::Type elementType = array.getEleTy(); @@ -341,7 +341,7 @@ mlir::Value HlfirTransposeLowering::lowerImpl( hlfir::ExprType::Shape resultShape; mlir::Type normalisedResult = hlfir::getFortranElementOrSequenceType(stmtResultType); - auto array = mlir::cast(normalisedResult); + auto array = normalisedResult.cast(); llvm::ArrayRef arrayShape = array.getShape(); assert(arrayShape.size() == 2 && "arguments to transpose have a rank of 2"); mlir::Type elementType = array.getEleTy(); diff --git a/flang/lib/Lower/HostAssociations.cpp b/flang/lib/Lower/HostAssociations.cpp index 75a5bed566557..2e2656356719f 100644 --- a/flang/lib/Lower/HostAssociations.cpp +++ b/flang/lib/Lower/HostAssociations.cpp @@ -219,7 +219,7 @@ class CapturedCharacterScalars static mlir::Type getType(Fortran::lower::AbstractConverter &converter, const Fortran::semantics::Symbol &sym) { fir::KindTy kind = - mlir::cast(converter.genType(sym)).getFKind(); + converter.genType(sym).cast().getFKind(); return fir::BoxCharType::get(&converter.getMLIRContext(), kind); } @@ -293,7 +293,7 @@ class CapturedPolymorphicScalar mlir::Location loc = args.loc; mlir::Value box = args.valueInTuple; if (Fortran::semantics::IsOptional(sym)) { - auto boxTy = mlir::cast(box.getType()); + auto boxTy = box.getType().cast(); auto eleTy = boxTy.getEleTy(); if (!fir::isa_ref_type(eleTy)) eleTy = builder.getRefType(eleTy); @@ -381,8 +381,8 @@ class CapturedArrays : public CapturedSymbols { const Fortran::semantics::Symbol &sym) { mlir::Type type = converter.genType(sym); bool isPolymorphic = Fortran::semantics::IsPolymorphic(sym); - assert((mlir::isa(type) || - (isPolymorphic && mlir::isa(type))) && + assert((type.isa() || + (isPolymorphic && type.isa())) && "must be a sequence type"); if (isPolymorphic) return type; @@ -459,7 +459,7 @@ class CapturedArrays : public CapturedSymbols { // (absent boxes are null descriptor addresses, not descriptors containing // a null base address). if (Fortran::semantics::IsOptional(sym)) { - auto boxTy = mlir::cast(box.getType()); + auto boxTy = box.getType().cast(); auto eleTy = boxTy.getEleTy(); if (!fir::isa_ref_type(eleTy)) eleTy = builder.getRefType(eleTy); @@ -527,7 +527,7 @@ walkCaptureCategories(T visitor, Fortran::lower::AbstractConverter &converter, // `t` should be the result of getArgumentType, which has a type of // `!fir.ref>`. static mlir::TupleType unwrapTupleTy(mlir::Type t) { - return mlir::cast(fir::dyn_cast_ptrEleTy(t)); + return fir::dyn_cast_ptrEleTy(t).cast(); } static mlir::Value genTupleCoor(fir::FirOpBuilder &builder, mlir::Location loc, @@ -535,7 +535,7 @@ static mlir::Value genTupleCoor(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Value offset) { // fir.ref and fir.ptr are forbidden. Use // fir.llvm_ptr if needed. - auto ty = mlir::isa(varTy) + auto ty = varTy.isa() ? mlir::Type(fir::LLVMPointerType::get(varTy)) : mlir::Type(builder.getRefType(varTy)); return builder.create(loc, ty, tupleArg, offset); diff --git a/flang/lib/Lower/IO.cpp b/flang/lib/Lower/IO.cpp index ed0afad9197df..ac82276bcddbd 100644 --- a/flang/lib/Lower/IO.cpp +++ b/flang/lib/Lower/IO.cpp @@ -168,7 +168,7 @@ static constexpr fir::runtime::FuncTypeBuilderFunc getTypeModel() { } inline int64_t getLength(mlir::Type argTy) { - return mlir::cast(argTy).getShape()[0]; + return argTy.cast().getShape()[0]; } /// Get (or generate) the MLIR FuncOp for a given IO runtime function. @@ -656,11 +656,11 @@ static void genNamelistIO(Fortran::lower::AbstractConverter &converter, static mlir::func::FuncOp getOutputFunc(mlir::Location loc, fir::FirOpBuilder &builder, mlir::Type type, bool isFormatted) { - if (mlir::isa(fir::unwrapPassByRefType(type))) + if (fir::unwrapPassByRefType(type).isa()) return getIORuntimeFunc(loc, builder); if (!isFormatted) return getIORuntimeFunc(loc, builder); - if (auto ty = mlir::dyn_cast(type)) { + if (auto ty = type.dyn_cast()) { switch (ty.getWidth()) { case 1: return getIORuntimeFunc(loc, builder); @@ -677,14 +677,14 @@ static mlir::func::FuncOp getOutputFunc(mlir::Location loc, } llvm_unreachable("unknown OutputInteger kind"); } - if (auto ty = mlir::dyn_cast(type)) { + if (auto ty = type.dyn_cast()) { if (auto width = ty.getWidth(); width == 32) return getIORuntimeFunc(loc, builder); else if (width == 64) return getIORuntimeFunc(loc, builder); } auto kindMap = fir::getKindMapping(builder.getModule()); - if (auto ty = mlir::dyn_cast(type)) { + if (auto ty = type.dyn_cast()) { // COMPLEX(KIND=k) corresponds to a pair of REAL(KIND=k). auto width = kindMap.getRealBitsize(ty.getFKind()); if (width == 32) @@ -692,7 +692,7 @@ static mlir::func::FuncOp getOutputFunc(mlir::Location loc, else if (width == 64) return getIORuntimeFunc(loc, builder); } - if (mlir::isa(type)) + if (type.isa()) return getIORuntimeFunc(loc, builder); if (fir::factory::CharacterExprHelper::isCharacterScalar(type)) { // TODO: What would it mean if the default CHARACTER KIND is set to a wide @@ -731,14 +731,14 @@ static void genOutputItemList( mlir::func::FuncOp outputFunc = getOutputFunc(loc, builder, itemTy, isFormatted); mlir::Type argType = outputFunc.getFunctionType().getInput(1); - assert((isFormatted || mlir::isa(argType)) && + assert((isFormatted || argType.isa()) && "expect descriptor for unformatted IO runtime"); llvm::SmallVector outputFuncArgs = {cookie}; fir::factory::CharacterExprHelper helper{builder, loc}; - if (mlir::isa(argType)) { + if (argType.isa()) { mlir::Value box = fir::getBase(converter.genExprBox(loc, *expr, stmtCtx)); outputFuncArgs.push_back(builder.createConvert(loc, argType, box)); - if (mlir::isa(fir::unwrapPassByRefType(itemTy))) + if (fir::unwrapPassByRefType(itemTy).isa()) outputFuncArgs.push_back(getNonTbpDefinedIoTableAddr(converter)); } else if (helper.isCharacterScalar(itemTy)) { fir::ExtendedValue exv = converter.genExprAddr(loc, expr, stmtCtx); @@ -773,29 +773,29 @@ static void genOutputItemList( static mlir::func::FuncOp getInputFunc(mlir::Location loc, fir::FirOpBuilder &builder, mlir::Type type, bool isFormatted) { - if (mlir::isa(fir::unwrapPassByRefType(type))) + if (fir::unwrapPassByRefType(type).isa()) return getIORuntimeFunc(loc, builder); if (!isFormatted) return getIORuntimeFunc(loc, builder); - if (auto ty = mlir::dyn_cast(type)) + if (auto ty = type.dyn_cast()) return ty.getWidth() == 1 ? getIORuntimeFunc(loc, builder) : getIORuntimeFunc(loc, builder); - if (auto ty = mlir::dyn_cast(type)) { + if (auto ty = type.dyn_cast()) { if (auto width = ty.getWidth(); width == 32) return getIORuntimeFunc(loc, builder); else if (width == 64) return getIORuntimeFunc(loc, builder); } auto kindMap = fir::getKindMapping(builder.getModule()); - if (auto ty = mlir::dyn_cast(type)) { + if (auto ty = type.dyn_cast()) { auto width = kindMap.getRealBitsize(ty.getFKind()); if (width == 32) return getIORuntimeFunc(loc, builder); else if (width == 64) return getIORuntimeFunc(loc, builder); } - if (mlir::isa(type)) + if (type.isa()) return getIORuntimeFunc(loc, builder); if (fir::factory::CharacterExprHelper::isCharacterScalar(type)) { auto asciiKind = kindMap.defaultCharacterKind(); @@ -830,12 +830,12 @@ createIoRuntimeCallForItem(Fortran::lower::AbstractConverter &converter, fir::FirOpBuilder &builder = converter.getFirOpBuilder(); mlir::Type argType = inputFunc.getFunctionType().getInput(1); llvm::SmallVector inputFuncArgs = {cookie}; - if (mlir::isa(argType)) { + if (argType.isa()) { mlir::Value box = fir::getBase(item); - auto boxTy = mlir::dyn_cast(box.getType()); + auto boxTy = box.getType().dyn_cast(); assert(boxTy && "must be previously emboxed"); inputFuncArgs.push_back(builder.createConvert(loc, argType, box)); - if (mlir::isa(fir::unwrapPassByRefType(boxTy))) + if (fir::unwrapPassByRefType(boxTy).isa()) inputFuncArgs.push_back(getNonTbpDefinedIoTableAddr(converter)); } else { mlir::Value itemAddr = fir::getBase(item); @@ -846,16 +846,16 @@ createIoRuntimeCallForItem(Fortran::lower::AbstractConverter &converter, mlir::Value len = fir::getLen(item); inputFuncArgs.push_back(builder.createConvert( loc, inputFunc.getFunctionType().getInput(2), len)); - } else if (mlir::isa(itemTy)) { + } else if (itemTy.isa()) { inputFuncArgs.push_back(builder.create( loc, builder.getI32IntegerAttr( - mlir::cast(itemTy).getWidth() / 8))); + itemTy.cast().getWidth() / 8))); } } auto call = builder.create(loc, inputFunc, inputFuncArgs); auto itemAddr = fir::getBase(item); auto itemTy = fir::unwrapRefType(itemAddr.getType()); - if (mlir::isa(itemTy)) + if (itemTy.isa()) boolRefToLogical(loc, builder, itemAddr); return call.getResult(0); } @@ -886,7 +886,7 @@ static void genInputItemList(Fortran::lower::AbstractConverter &converter, mlir::func::FuncOp inputFunc = getInputFunc( loc, builder, vectorSubscriptBox.getElementType(), isFormatted); const bool mustBox = - mlir::isa(inputFunc.getFunctionType().getInput(1)); + inputFunc.getFunctionType().getInput(1).isa(); if (!checkResult) { auto elementalGenerator = [&](const fir::ExtendedValue &element) { createIoRuntimeCallForItem(converter, loc, inputFunc, cookie, @@ -911,10 +911,9 @@ static void genInputItemList(Fortran::lower::AbstractConverter &converter, mlir::Type itemTy = converter.genType(*expr); mlir::func::FuncOp inputFunc = getInputFunc(loc, builder, itemTy, isFormatted); - auto itemExv = - mlir::isa(inputFunc.getFunctionType().getInput(1)) - ? converter.genExprBox(loc, *expr, stmtCtx) - : converter.genExprAddr(loc, expr, stmtCtx); + auto itemExv = inputFunc.getFunctionType().getInput(1).isa() + ? converter.genExprBox(loc, *expr, stmtCtx) + : converter.genExprAddr(loc, expr, stmtCtx); ok = createIoRuntimeCallForItem(converter, loc, inputFunc, cookie, itemExv); } } @@ -1773,8 +1772,8 @@ static mlir::Value genIOUnitNumber(Fortran::lower::AbstractConverter &converter, auto &builder = converter.getFirOpBuilder(); auto rawUnit = fir::getBase(converter.genExprValue(loc, iounit, stmtCtx)); unsigned rawUnitWidth = - mlir::cast(rawUnit.getType()).getWidth(); - unsigned runtimeArgWidth = mlir::cast(ty).getWidth(); + rawUnit.getType().cast().getWidth(); + unsigned runtimeArgWidth = ty.cast().getWidth(); // The IO runtime supports `int` unit numbers, if the unit number may // overflow when passed to the IO runtime, check that the unit number is // in range before calling the BeginXXX. @@ -2332,7 +2331,7 @@ mlir::Value genInquireSpec( if (!eleTy) fir::emitFatalError(loc, "internal error: expected a memory reference type"); - auto width = mlir::cast(eleTy).getWidth(); + auto width = eleTy.cast().getWidth(); mlir::IndexType idxTy = builder.getIndexType(); mlir::Value kind = builder.createIntegerConstant(loc, idxTy, width / 8); llvm::SmallVector args = { diff --git a/flang/lib/Lower/OpenACC.cpp b/flang/lib/Lower/OpenACC.cpp index eae2afc760e64..b56bdedc07bf5 100644 --- a/flang/lib/Lower/OpenACC.cpp +++ b/flang/lib/Lower/OpenACC.cpp @@ -65,7 +65,7 @@ static Op createDataEntryOp(fir::FirOpBuilder &builder, mlir::Location loc, mlir::acc::DataClause dataClause, mlir::Type retTy, mlir::Value isPresent = {}) { mlir::Value varPtrPtr; - if (auto boxTy = mlir::dyn_cast(baseAddr.getType())) { + if (auto boxTy = baseAddr.getType().dyn_cast()) { if (isPresent) { mlir::Type ifRetTy = boxTy.getEleTy(); if (!fir::isa_ref_type(ifRetTy)) @@ -2658,7 +2658,7 @@ genACCHostDataOp(Fortran::lower::AbstractConverter &converter, if (ifCond) { if (auto cst = mlir::dyn_cast(ifCond.getDefiningOp())) - if (auto boolAttr = mlir::dyn_cast(cst.getValue())) { + if (auto boolAttr = cst.getValue().dyn_cast()) { if (boolAttr.getValue()) { // get rid of the if condition if it is always true. ifCond = mlir::Value(); diff --git a/flang/lib/Lower/OpenMP/ClauseProcessor.cpp b/flang/lib/Lower/OpenMP/ClauseProcessor.cpp index 79525d6dfe7a2..4c51b61f6bf02 100644 --- a/flang/lib/Lower/OpenMP/ClauseProcessor.cpp +++ b/flang/lib/Lower/OpenMP/ClauseProcessor.cpp @@ -23,10 +23,10 @@ namespace omp { /// Check for unsupported map operand types. static void checkMapType(mlir::Location location, mlir::Type type) { - if (auto refType = mlir::dyn_cast(type)) + if (auto refType = type.dyn_cast()) type = refType.getElementType(); - if (auto boxType = mlir::dyn_cast_or_null(type)) - if (!mlir::isa(boxType.getElementType())) + if (auto boxType = type.dyn_cast_or_null()) + if (!boxType.getElementType().isa()) TODO(location, "OMPD_target_data MapOperand BoxType"); } @@ -814,7 +814,7 @@ createMapInfoOp(fir::FirOpBuilder &builder, mlir::Location loc, llvm::ArrayRef members, uint64_t mapType, mlir::omp::VariableCaptureKind mapCaptureType, mlir::Type retTy, bool isVal) { - if (auto boxTy = mlir::dyn_cast(baseAddr.getType())) { + if (auto boxTy = baseAddr.getType().dyn_cast()) { baseAddr = builder.create(loc, baseAddr); retTy = baseAddr.getType(); } diff --git a/flang/lib/Lower/OpenMP/OpenMP.cpp b/flang/lib/Lower/OpenMP/OpenMP.cpp index 64ec5ae65c823..f454f5a45a515 100644 --- a/flang/lib/Lower/OpenMP/OpenMP.cpp +++ b/flang/lib/Lower/OpenMP/OpenMP.cpp @@ -84,7 +84,7 @@ static fir::GlobalOp globalInitialization( // Create default initialization for non-character scalar. if (Fortran::semantics::IsAllocatableOrObjectPointer(&sym)) { - mlir::Type baseAddrType = mlir::dyn_cast(ty).getEleTy(); + mlir::Type baseAddrType = ty.dyn_cast().getEleTy(); Fortran::lower::createGlobalInitialization( firOpBuilder, global, [&](fir::FirOpBuilder &b) { mlir::Value nullAddr = @@ -778,7 +778,7 @@ static void genBodyOfTargetDataOp( for (auto [argIndex, argSymbol] : llvm::enumerate(useDeviceSymbols)) { const mlir::BlockArgument &arg = region.front().getArgument(argIndex); fir::ExtendedValue extVal = converter.getSymbolExtendedValue(*argSymbol); - if (auto refType = mlir::dyn_cast(arg.getType())) { + if (auto refType = arg.getType().dyn_cast()) { if (fir::isa_builtin_cptr_type(refType.getElementType())) { converter.bindSymbol(*argSymbol, arg); } else { @@ -1570,15 +1570,13 @@ genTargetOp(Fortran::lower::AbstractConverter &converter, Fortran::lower::AddrAndBoundsInfo info = getDataOperandBaseAddr( converter, firOpBuilder, sym, converter.getCurrentLocation()); - if (mlir::isa( - fir::unwrapRefType(info.addr.getType()))) + if (fir::unwrapRefType(info.addr.getType()).isa()) bounds = Fortran::lower::genBoundsOpsFromBox( firOpBuilder, converter.getCurrentLocation(), converter, dataExv, info); - if (mlir::isa( - fir::unwrapRefType(info.addr.getType()))) { + if (fir::unwrapRefType(info.addr.getType()).isa()) { bool dataExvIsAssumedSize = Fortran::semantics::IsAssumedSizeArray(sym.GetUltimate()); bounds = Fortran::lower::genBaseBoundsOps(baseOp.getType())) + if (auto refType = baseOp.getType().dyn_cast()) eleType = refType.getElementType(); // If a variable is specified in declare target link and if device diff --git a/flang/lib/Lower/OpenMP/ReductionProcessor.cpp b/flang/lib/Lower/OpenMP/ReductionProcessor.cpp index 38edd1b468215..895340549f7c6 100644 --- a/flang/lib/Lower/OpenMP/ReductionProcessor.cpp +++ b/flang/lib/Lower/OpenMP/ReductionProcessor.cpp @@ -138,7 +138,7 @@ ReductionProcessor::getReductionInitValue(mlir::Location loc, mlir::Type type, TODO(loc, "Reduction of some types is not supported"); switch (redId) { case ReductionIdentifier::MAX: { - if (auto ty = mlir::dyn_cast(type)) { + if (auto ty = type.dyn_cast()) { const llvm::fltSemantics &sem = ty.getFloatSemantics(); return builder.createRealConstant( loc, type, llvm::APFloat::getLargest(sem, /*Negative=*/true)); @@ -148,7 +148,7 @@ ReductionProcessor::getReductionInitValue(mlir::Location loc, mlir::Type type, return builder.createIntegerConstant(loc, type, minInt); } case ReductionIdentifier::MIN: { - if (auto ty = mlir::dyn_cast(type)) { + if (auto ty = type.dyn_cast()) { const llvm::fltSemantics &sem = ty.getFloatSemantics(); return builder.createRealConstant( loc, type, llvm::APFloat::getLargest(sem, /*Negative=*/false)); @@ -188,12 +188,12 @@ ReductionProcessor::getReductionInitValue(mlir::Location loc, mlir::Type type, return fir::factory::Complex{builder, loc}.createComplex(type, initRe, initIm); } - if (mlir::isa(type)) + if (type.isa()) return builder.create( loc, type, builder.getFloatAttr(type, (double)getOperationIdentity(redId, loc))); - if (mlir::isa(type)) { + if (type.isa()) { mlir::Value intConst = builder.create( loc, builder.getI1Type(), builder.getIntegerAttr(builder.getI1Type(), @@ -474,11 +474,11 @@ createReductionCleanupRegion(fir::FirOpBuilder &builder, mlir::Location loc, // like fir::unwrapSeqOrBoxedSeqType except it also works for non-sequence boxes static mlir::Type unwrapSeqOrBoxedType(mlir::Type ty) { - if (auto seqTy = mlir::dyn_cast(ty)) + if (auto seqTy = ty.dyn_cast()) return seqTy.getEleTy(); - if (auto boxTy = mlir::dyn_cast(ty)) { + if (auto boxTy = ty.dyn_cast()) { auto eleTy = fir::unwrapRefType(boxTy.getEleTy()); - if (auto seqTy = mlir::dyn_cast(eleTy)) + if (auto seqTy = eleTy.dyn_cast()) return seqTy.getEleTy(); return eleTy; } @@ -790,7 +790,7 @@ void ReductionProcessor::addDeclareReduction( for (mlir::Value symVal : reductionVars) { auto redType = mlir::cast(symVal.getType()); const auto &kindMap = firOpBuilder.getKindMap(); - if (mlir::isa(redType.getEleTy())) + if (redType.getEleTy().isa()) decl = createDeclareReduction(firOpBuilder, getReductionName(intrinsicOp, kindMap, firOpBuilder.getI1Type(), @@ -816,7 +816,7 @@ void ReductionProcessor::addDeclareReduction( mlir::Value symVal = converter.getSymbolAddress(*symbol); if (auto declOp = symVal.getDefiningOp()) symVal = declOp.getBase(); - auto redType = mlir::cast(symVal.getType()); + auto redType = symVal.getType().cast(); if (!redType.getEleTy().isIntOrIndexOrFloat()) TODO(currentLocation, "User Defined Reduction on non-trivial type"); decl = createDeclareReduction( diff --git a/flang/lib/Lower/VectorSubscripts.cpp b/flang/lib/Lower/VectorSubscripts.cpp index d7a311d32d59d..7439b9f7df8fd 100644 --- a/flang/lib/Lower/VectorSubscripts.cpp +++ b/flang/lib/Lower/VectorSubscripts.cpp @@ -105,7 +105,7 @@ class VectorSubscriptBoxBuilder { } mlir::Type gen(const Fortran::evaluate::Component &component) { - auto recTy = mlir::cast(gen(component.base())); + auto recTy = gen(component.base()).cast(); const Fortran::semantics::Symbol &componentSymbol = component.GetLastSymbol(); // Parent components will not be found here, they are not part diff --git a/flang/lib/Optimizer/Analysis/AliasAnalysis.cpp b/flang/lib/Optimizer/Analysis/AliasAnalysis.cpp index f723e8f66e3e4..c403b9effbfac 100644 --- a/flang/lib/Optimizer/Analysis/AliasAnalysis.cpp +++ b/flang/lib/Optimizer/Analysis/AliasAnalysis.cpp @@ -68,7 +68,7 @@ bool AliasAnalysis::Source::isPointerReference(mlir::Type ty) { if (!eleTy) return false; - return fir::isPointerType(eleTy) || mlir::isa(eleTy); + return fir::isPointerType(eleTy) || eleTy.isa(); } bool AliasAnalysis::Source::isTargetOrPointer() const { @@ -81,7 +81,7 @@ bool AliasAnalysis::Source::isRecordWithPointerComponent() const { if (!eleTy) return false; // TO DO: Look for pointer components - return mlir::isa(eleTy); + return eleTy.isa(); } AliasResult AliasAnalysis::alias(Value lhs, Value rhs) { diff --git a/flang/lib/Optimizer/Builder/BoxValue.cpp b/flang/lib/Optimizer/Builder/BoxValue.cpp index a90ce5570de7d..361fa59e20403 100644 --- a/flang/lib/Optimizer/Builder/BoxValue.cpp +++ b/flang/lib/Optimizer/Builder/BoxValue.cpp @@ -191,7 +191,7 @@ bool fir::MutableBoxValue::verify() const { mlir::Type type = fir::dyn_cast_ptrEleTy(getAddr().getType()); if (!type) return false; - auto box = mlir::dyn_cast(type); + auto box = type.dyn_cast(); if (!box) return false; // A boxed value always takes a memory reference, @@ -210,7 +210,7 @@ bool fir::MutableBoxValue::verify() const { /// Debug verifier for BoxValue ctor. There is no guarantee this will /// always be called. bool fir::BoxValue::verify() const { - if (!mlir::isa(addr.getType())) + if (!addr.getType().isa()) return false; if (!lbounds.empty() && lbounds.size() != rank()) return false; diff --git a/flang/lib/Optimizer/Builder/Character.cpp b/flang/lib/Optimizer/Builder/Character.cpp index b7a7453efdb39..af0786809cc26 100644 --- a/flang/lib/Optimizer/Builder/Character.cpp +++ b/flang/lib/Optimizer/Builder/Character.cpp @@ -26,11 +26,11 @@ /// Unwrap all the ref and box types and return the inner element type. static mlir::Type unwrapBoxAndRef(mlir::Type type) { - if (auto boxType = mlir::dyn_cast(type)) + if (auto boxType = type.dyn_cast()) return boxType.getEleTy(); while (true) { type = fir::unwrapRefType(type); - if (auto boxTy = mlir::dyn_cast(type)) + if (auto boxTy = type.dyn_cast()) type = boxTy.getEleTy(); else break; @@ -41,19 +41,19 @@ static mlir::Type unwrapBoxAndRef(mlir::Type type) { /// Unwrap base fir.char type. static fir::CharacterType recoverCharacterType(mlir::Type type) { type = fir::unwrapSequenceType(unwrapBoxAndRef(type)); - if (auto charTy = mlir::dyn_cast(type)) + if (auto charTy = type.dyn_cast()) return charTy; llvm::report_fatal_error("expected a character type"); } bool fir::factory::CharacterExprHelper::isCharacterScalar(mlir::Type type) { type = unwrapBoxAndRef(type); - return !mlir::isa(type) && fir::isa_char(type); + return !type.isa() && fir::isa_char(type); } bool fir::factory::CharacterExprHelper::isArray(mlir::Type type) { type = unwrapBoxAndRef(type); - if (auto seqTy = mlir::dyn_cast(type)) + if (auto seqTy = type.dyn_cast()) return fir::isa_char(seqTy.getEleTy()); return false; } @@ -92,8 +92,7 @@ getCompileTimeLength(const fir::CharBoxValue &box) { /// Detect the precondition that the value `str` does not reside in memory. Such /// values will have a type `!fir.array<...x!fir.char>` or `!fir.char`. LLVM_ATTRIBUTE_UNUSED static bool needToMaterialize(mlir::Value str) { - return mlir::isa(str.getType()) || - fir::isa_char(str.getType()); + return str.getType().isa() || fir::isa_char(str.getType()); } /// This is called only if `str` does not reside in memory. Such a bare string @@ -104,7 +103,7 @@ fir::factory::CharacterExprHelper::materializeValue(mlir::Value str) { assert(needToMaterialize(str)); auto ty = str.getType(); assert(isCharacterScalar(ty) && "expected scalar character"); - auto charTy = mlir::dyn_cast(ty); + auto charTy = ty.dyn_cast(); if (!charTy || charTy.getLen() == fir::CharacterType::unknownLen()) { LLVM_DEBUG(llvm::dbgs() << "cannot materialize: " << str << '\n'); llvm_unreachable("must be a !fir.char type"); @@ -130,7 +129,7 @@ fir::factory::CharacterExprHelper::toExtendedValue(mlir::Value character, if (auto eleType = fir::dyn_cast_ptrEleTy(type)) type = eleType; - if (auto arrayType = mlir::dyn_cast(type)) { + if (auto arrayType = type.dyn_cast()) { type = arrayType.getEleTy(); auto indexType = builder.getIndexType(); for (auto extent : arrayType.getShape()) { @@ -146,10 +145,10 @@ fir::factory::CharacterExprHelper::toExtendedValue(mlir::Value character, mlir::emitError(loc, "cannot retrieve array extents from type"); } - if (auto charTy = mlir::dyn_cast(type)) { + if (auto charTy = type.dyn_cast()) { if (!resultLen && charTy.getLen() != fir::CharacterType::unknownLen()) resultLen = builder.createIntegerConstant(loc, lenType, charTy.getLen()); - } else if (auto boxCharType = mlir::dyn_cast(type)) { + } else if (auto boxCharType = type.dyn_cast()) { auto refType = builder.getRefType(boxCharType.getEleTy()); // If the embox is accessible, use its operand to avoid filling // the generated fir with embox/unbox. @@ -169,7 +168,7 @@ fir::factory::CharacterExprHelper::toExtendedValue(mlir::Value character, if (!resultLen) { resultLen = boxCharLen; } - } else if (mlir::isa(type)) { + } else if (type.isa()) { mlir::emitError(loc, "descriptor or derived type not yet handled"); } else { llvm_unreachable("Cannot translate mlir::Value to character ExtendedValue"); @@ -222,7 +221,7 @@ fir::factory::CharacterExprHelper::createEmbox(const fir::CharBoxValue &box) { fir::CharBoxValue fir::factory::CharacterExprHelper::toScalarCharacter( const fir::CharArrayBoxValue &box) { - if (mlir::isa(box.getBuffer().getType())) + if (box.getBuffer().getType().isa()) TODO(loc, "concatenating non contiguous character array into a scalar"); // TODO: add a fast path multiplying new length at compile time if the info is @@ -656,7 +655,7 @@ fir::factory::CharacterExprHelper::createUnboxChar(mlir::Value boxChar) { } bool fir::factory::CharacterExprHelper::isCharacterLiteral(mlir::Type type) { - if (auto seqType = mlir::dyn_cast(type)) + if (auto seqType = type.dyn_cast()) return (seqType.getShape().size() == 1) && fir::isa_char(seqType.getEleTy()); return false; @@ -729,9 +728,9 @@ mlir::Value fir::factory::CharacterExprHelper::getLength(mlir::Value memref) { if (charType.hasConstantLen()) return builder.createIntegerConstant(loc, builder.getCharacterLengthType(), charType.getLen()); - if (mlir::isa(memrefType)) + if (memrefType.isa()) return readLengthFromBox(memref); - if (mlir::isa(memrefType)) + if (memrefType.isa()) return createUnboxChar(memref).second; // Length cannot be deduced from memref. @@ -743,14 +742,14 @@ fir::factory::extractCharacterProcedureTuple(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Value tuple, bool openBoxProc) { - mlir::TupleType tupleType = mlir::cast(tuple.getType()); + mlir::TupleType tupleType = tuple.getType().cast(); mlir::Value addr = builder.create( loc, tupleType.getType(0), tuple, builder.getArrayAttr( {builder.getIntegerAttr(builder.getIndexType(), 0)})); mlir::Value proc = [&]() -> mlir::Value { if (openBoxProc) - if (auto addrTy = mlir::dyn_cast(addr.getType())) + if (auto addrTy = addr.getType().dyn_cast()) return builder.create(loc, addrTy.getEleTy(), addr); return addr; }(); @@ -764,7 +763,7 @@ fir::factory::extractCharacterProcedureTuple(fir::FirOpBuilder &builder, mlir::Value fir::factory::createCharacterProcedureTuple( fir::FirOpBuilder &builder, mlir::Location loc, mlir::Type argTy, mlir::Value addr, mlir::Value len) { - mlir::TupleType tupleType = mlir::cast(argTy); + mlir::TupleType tupleType = argTy.cast(); addr = builder.createConvert(loc, tupleType.getType(0), addr); if (len) len = builder.createConvert(loc, tupleType.getType(1), len); @@ -867,7 +866,7 @@ fir::factory::convertCharacterKind(fir::FirOpBuilder &builder, auto kindMap = builder.getKindMap(); mlir::Value boxCharAddr = srcBoxChar.getAddr(); auto fromTy = boxCharAddr.getType(); - if (auto charTy = mlir::dyn_cast(fromTy)) { + if (auto charTy = fromTy.dyn_cast()) { // boxchar is a value, not a variable. Turn it into a temporary. // As a value, it ought to have a constant LEN value. assert(charTy.hasConstantLen() && "must have constant length"); @@ -876,7 +875,7 @@ fir::factory::convertCharacterKind(fir::FirOpBuilder &builder, boxCharAddr = tmp; } auto fromBits = kindMap.getCharacterBitsize( - mlir::cast(fir::unwrapRefType(fromTy)).getFKind()); + fir::unwrapRefType(fromTy).cast().getFKind()); auto toBits = kindMap.getCharacterBitsize(toKind); if (toBits < fromBits) { // Scale by relative ratio to give a buffer of the same length. diff --git a/flang/lib/Optimizer/Builder/Complex.cpp b/flang/lib/Optimizer/Builder/Complex.cpp index cbcd4f850014e..e97cb30678089 100644 --- a/flang/lib/Optimizer/Builder/Complex.cpp +++ b/flang/lib/Optimizer/Builder/Complex.cpp @@ -14,8 +14,7 @@ mlir::Type fir::factory::Complex::getComplexPartType(mlir::Type complexType) const { - return builder.getRealType( - mlir::cast(complexType).getFKind()); + return builder.getRealType(complexType.cast().getFKind()); } mlir::Type fir::factory::Complex::getComplexPartType(mlir::Value cplx) const { diff --git a/flang/lib/Optimizer/Builder/FIRBuilder.cpp b/flang/lib/Optimizer/Builder/FIRBuilder.cpp index a6da387637264..a0fbae5b614cc 100644 --- a/flang/lib/Optimizer/Builder/FIRBuilder.cpp +++ b/flang/lib/Optimizer/Builder/FIRBuilder.cpp @@ -90,7 +90,7 @@ fir::FirOpBuilder::getNamedGlobal(mlir::ModuleOp modOp, } mlir::Type fir::FirOpBuilder::getRefType(mlir::Type eleTy) { - assert(!mlir::isa(eleTy) && "cannot be a reference type"); + assert(!eleTy.isa() && "cannot be a reference type"); return fir::ReferenceType::get(eleTy); } @@ -147,7 +147,7 @@ mlir::Value fir::FirOpBuilder::createRealConstant(mlir::Location loc, mlir::Type fltTy, llvm::APFloat::integerPart val) { auto apf = [&]() -> llvm::APFloat { - if (auto ty = mlir::dyn_cast(fltTy)) + if (auto ty = fltTy.dyn_cast()) return llvm::APFloat(kindMap.getFloatSemantics(ty.getFKind()), val); if (fltTy.isF16()) return llvm::APFloat(llvm::APFloat::IEEEhalf(), val); @@ -169,7 +169,7 @@ fir::FirOpBuilder::createRealConstant(mlir::Location loc, mlir::Type fltTy, mlir::Value fir::FirOpBuilder::createRealConstant(mlir::Location loc, mlir::Type fltTy, const llvm::APFloat &value) { - if (mlir::isa(fltTy)) { + if (fltTy.isa()) { auto attr = getFloatAttr(fltTy, value); return create(loc, fltTy, attr); } @@ -178,7 +178,7 @@ mlir::Value fir::FirOpBuilder::createRealConstant(mlir::Location loc, static llvm::SmallVector elideExtentsAlreadyInType(mlir::Type type, mlir::ValueRange shape) { - auto arrTy = mlir::dyn_cast(type); + auto arrTy = type.dyn_cast(); if (shape.empty() || !arrTy) return {}; // elide the constant dimensions before construction @@ -195,7 +195,7 @@ static llvm::SmallVector elideLengthsAlreadyInType(mlir::Type type, mlir::ValueRange lenParams) { if (lenParams.empty()) return {}; - if (auto arrTy = mlir::dyn_cast(type)) + if (auto arrTy = type.dyn_cast()) type = arrTy.getEleTy(); if (fir::hasDynamicSize(type)) return lenParams; @@ -264,7 +264,7 @@ mlir::Value fir::FirOpBuilder::createTemporaryAlloc( mlir::Location loc, mlir::Type type, llvm::StringRef name, mlir::ValueRange lenParams, mlir::ValueRange shape, llvm::ArrayRef attrs) { - assert(!mlir::isa(type) && "cannot be a reference"); + assert(!type.isa() && "cannot be a reference"); // If the alloca is inside an OpenMP Op which will be outlined then pin // the alloca here. const bool pinned = @@ -310,7 +310,7 @@ mlir::Value fir::FirOpBuilder::createHeapTemporary( llvm::SmallVector dynamicLength = elideLengthsAlreadyInType(type, lenParams); - assert(!mlir::isa(type) && "cannot be a reference"); + assert(!type.isa() && "cannot be a reference"); return create(loc, type, /*unique_name=*/llvm::StringRef{}, name, dynamicLength, dynamicShape, attrs); } @@ -376,9 +376,8 @@ mlir::Value fir::FirOpBuilder::convertWithSemantics( // imaginary part is zero auto eleTy = helper.getComplexPartType(toTy); auto cast = createConvert(loc, eleTy, val); - llvm::APFloat zero{kindMap.getFloatSemantics( - mlir::cast(toTy).getFKind()), - 0}; + llvm::APFloat zero{ + kindMap.getFloatSemantics(toTy.cast().getFKind()), 0}; auto imag = createRealConstant(loc, eleTy, zero); return helper.createComplex(toTy, cast, imag); } @@ -389,14 +388,14 @@ mlir::Value fir::FirOpBuilder::convertWithSemantics( return createConvert(loc, toTy, rp); } if (allowCharacterConversion) { - if (mlir::isa(fromTy)) { + if (fromTy.isa()) { // Extract the address of the character string and pass it fir::factory::CharacterExprHelper charHelper{*this, loc}; std::pair unboxchar = charHelper.createUnboxChar(val); return createConvert(loc, toTy, unboxchar.first); } - if (auto boxType = mlir::dyn_cast(toTy)) { + if (auto boxType = toTy.dyn_cast()) { // Extract the address of the actual argument and create a boxed // character value with an undefined length // TODO: We should really calculate the total size of the actual @@ -416,10 +415,10 @@ mlir::Value fir::FirOpBuilder::convertWithSemantics( "element types expected to match")); return create(loc, toTy, val); } - if (fir::isa_ref_type(fromTy) && mlir::isa(toTy)) { + if (fir::isa_ref_type(fromTy) && toTy.isa()) { // Call is expecting a boxed procedure, not a reference to other data type. // Convert the reference to a procedure and embox it. - mlir::Type procTy = mlir::cast(toTy).getEleTy(); + mlir::Type procTy = toTy.cast().getEleTy(); mlir::Value proc = createConvert(loc, procTy, val); return create(loc, toTy, proc); } @@ -429,7 +428,7 @@ mlir::Value fir::FirOpBuilder::convertWithSemantics( if (((fir::isPolymorphicType(fromTy) && (fir::isAllocatableType(fromTy) || fir::isPointerType(fromTy)) && fir::isPolymorphicType(toTy)) || - (fir::isPolymorphicType(fromTy) && mlir::isa(toTy))) && + (fir::isPolymorphicType(fromTy) && toTy.isa())) && !(fir::isUnlimitedPolymorphicType(fromTy) && fir::isAssumedType(toTy))) return create(loc, toTy, val, mlir::Value{}, /*slice=*/mlir::Value{}); @@ -582,7 +581,7 @@ mlir::Value fir::FirOpBuilder::createBox(mlir::Location loc, bool isPolymorphic, bool isAssumedType) { mlir::Value itemAddr = fir::getBase(exv); - if (mlir::isa(itemAddr.getType())) + if (itemAddr.getType().isa()) return itemAddr; auto elementType = fir::dyn_cast_ptrEleTy(itemAddr.getType()); if (!elementType) { @@ -593,7 +592,7 @@ mlir::Value fir::FirOpBuilder::createBox(mlir::Location loc, mlir::Type boxTy; mlir::Value tdesc; // Avoid to wrap a box/class with box/class. - if (mlir::isa(elementType)) { + if (elementType.isa()) { boxTy = elementType; } else { boxTy = fir::BoxType::get(elementType); @@ -710,7 +709,7 @@ mlir::Value fir::FirOpBuilder::genAbsentOp(mlir::Location loc, return create(loc, argTy); auto boxProc = - create(loc, mlir::cast(argTy).getType(0)); + create(loc, argTy.cast().getType(0)); mlir::Value charLen = create(loc, getCharacterLengthType()); return fir::factory::createCharacterProcedureTuple(*this, loc, argTy, boxProc, charLen); @@ -959,14 +958,14 @@ static llvm::SmallVector getFromBox(mlir::Location loc, fir::FirOpBuilder &builder, mlir::Type valTy, mlir::Value boxVal) { - if (auto boxTy = mlir::dyn_cast(valTy)) { + if (auto boxTy = valTy.dyn_cast()) { auto eleTy = fir::unwrapAllRefAndSeqType(boxTy.getEleTy()); - if (auto recTy = mlir::dyn_cast(eleTy)) { + if (auto recTy = eleTy.dyn_cast()) { if (recTy.getNumLenParams() > 0) { // Walk each type parameter in the record and get the value. TODO(loc, "generate code to get LEN type parameters"); } - } else if (auto charTy = mlir::dyn_cast(eleTy)) { + } else if (auto charTy = eleTy.dyn_cast()) { if (charTy.hasDynamicLen()) { auto idxTy = builder.getIndexType(); auto eleSz = builder.create(loc, idxTy, boxVal); @@ -1013,7 +1012,7 @@ llvm::SmallVector fir::factory::getTypeParams(mlir::Location loc, fir::FirOpBuilder &builder, fir::ArrayLoadOp load) { mlir::Type memTy = load.getMemref().getType(); - if (auto boxTy = mlir::dyn_cast(memTy)) + if (auto boxTy = memTy.dyn_cast()) return getFromBox(loc, builder, boxTy, load.getMemref()); return load.getTypeparams(); } @@ -1040,7 +1039,7 @@ std::string fir::factory::uniqueCGIdent(llvm::StringRef prefix, mlir::Value fir::factory::locationToFilename(fir::FirOpBuilder &builder, mlir::Location loc) { - if (auto flc = mlir::dyn_cast(loc)) { + if (auto flc = loc.dyn_cast()) { // must be encoded as asciiz, C string auto fn = flc.getFilename().str() + '\0'; return fir::getBase(createStringLiteral(builder, loc, fn)); @@ -1051,7 +1050,7 @@ mlir::Value fir::factory::locationToFilename(fir::FirOpBuilder &builder, mlir::Value fir::factory::locationToLineNo(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Type type) { - if (auto flc = mlir::dyn_cast(loc)) + if (auto flc = loc.dyn_cast()) return builder.createIntegerConstant(loc, type, flc.getLine()); return builder.createIntegerConstant(loc, type, 0); } @@ -1109,10 +1108,10 @@ fir::ExtendedValue fir::factory::componentToExtendedValue( auto fieldTy = component.getType(); if (auto ty = fir::dyn_cast_ptrEleTy(fieldTy)) fieldTy = ty; - if (mlir::isa(fieldTy)) { + if (fieldTy.isa()) { llvm::SmallVector nonDeferredTypeParams; auto eleTy = fir::unwrapSequenceType(fir::dyn_cast_ptrOrBoxEleTy(fieldTy)); - if (auto charTy = mlir::dyn_cast(eleTy)) { + if (auto charTy = eleTy.dyn_cast()) { auto lenTy = builder.getCharacterLengthType(); if (charTy.hasConstantLen()) nonDeferredTypeParams.emplace_back( @@ -1121,7 +1120,7 @@ fir::ExtendedValue fir::factory::componentToExtendedValue( // on a PDT length parameter. There is no way to make a difference with // deferred length here yet. } - if (auto recTy = mlir::dyn_cast(eleTy)) + if (auto recTy = eleTy.dyn_cast()) if (recTy.getNumLenParams() > 0) TODO(loc, "allocatable and pointer components non deferred length " "parameters"); @@ -1130,7 +1129,7 @@ fir::ExtendedValue fir::factory::componentToExtendedValue( /*mutableProperties=*/{}); } llvm::SmallVector extents; - if (auto seqTy = mlir::dyn_cast(fieldTy)) { + if (auto seqTy = fieldTy.dyn_cast()) { fieldTy = seqTy.getEleTy(); auto idxTy = builder.getIndexType(); for (auto extent : seqTy.getShape()) { @@ -1139,7 +1138,7 @@ fir::ExtendedValue fir::factory::componentToExtendedValue( extents.emplace_back(builder.createIntegerConstant(loc, idxTy, extent)); } } - if (auto charTy = mlir::dyn_cast(fieldTy)) { + if (auto charTy = fieldTy.dyn_cast()) { auto cstLen = charTy.getLen(); if (cstLen == fir::CharacterType::unknownLen()) TODO(loc, "get character component length from length type parameters"); @@ -1149,7 +1148,7 @@ fir::ExtendedValue fir::factory::componentToExtendedValue( return fir::CharArrayBoxValue{component, len, extents}; return fir::CharBoxValue{component, len}; } - if (auto recordTy = mlir::dyn_cast(fieldTy)) + if (auto recordTy = fieldTy.dyn_cast()) if (recordTy.getNumLenParams() != 0) TODO(loc, "lower component ref that is a derived type with length parameter"); @@ -1212,14 +1211,14 @@ void fir::factory::genScalarAssignment(fir::FirOpBuilder &builder, assert(lhs.rank() == 0 && rhs.rank() == 0 && "must be scalars"); auto type = fir::unwrapSequenceType( fir::unwrapPassByRefType(fir::getBase(lhs).getType())); - if (mlir::isa(type)) { + if (type.isa()) { const fir::CharBoxValue *toChar = lhs.getCharBox(); const fir::CharBoxValue *fromChar = rhs.getCharBox(); assert(toChar && fromChar); fir::factory::CharacterExprHelper helper{builder, loc}; helper.createAssign(fir::ExtendedValue{*toChar}, fir::ExtendedValue{*fromChar}); - } else if (mlir::isa(type)) { + } else if (type.isa()) { fir::factory::genRecordAssignment(builder, loc, lhs, rhs, needFinalization, isTemporaryLHS); } else { @@ -1240,10 +1239,10 @@ static void genComponentByComponentAssignment(fir::FirOpBuilder &builder, const fir::ExtendedValue &rhs, bool isTemporaryLHS) { auto lbaseType = fir::unwrapPassByRefType(fir::getBase(lhs).getType()); - auto lhsType = mlir::dyn_cast(lbaseType); + auto lhsType = lbaseType.dyn_cast(); assert(lhsType && "lhs must be a scalar record type"); auto rbaseType = fir::unwrapPassByRefType(fir::getBase(rhs).getType()); - auto rhsType = mlir::dyn_cast(rbaseType); + auto rhsType = rbaseType.dyn_cast(); assert(rhsType && "rhs must be a scalar record type"); auto fieldIndexType = fir::FieldType::get(lhsType.getContext()); for (auto [lhsPair, rhsPair] : @@ -1262,7 +1261,7 @@ static void genComponentByComponentAssignment(fir::FirOpBuilder &builder, mlir::Value toCoor = builder.create( loc, fieldRefType, fir::getBase(lhs), field); std::optional outerLoop; - if (auto sequenceType = mlir::dyn_cast(lFieldTy)) { + if (auto sequenceType = lFieldTy.dyn_cast()) { // Create loops to assign array components elements by elements. // Note that, since these are components, they either do not overlap, // or are the same and exactly overlap. They also have compile time @@ -1289,9 +1288,10 @@ static void genComponentByComponentAssignment(fir::FirOpBuilder &builder, fromCoor, indices); } if (auto fieldEleTy = fir::unwrapSequenceType(lFieldTy); - mlir::isa(fieldEleTy)) { - assert(mlir::isa( - mlir::cast(fieldEleTy).getEleTy()) && + fieldEleTy.isa()) { + assert(fieldEleTy.cast() + .getEleTy() + .isa() && "allocatable members require deep copy"); auto fromPointerValue = builder.create(loc, fromCoor); auto castTo = builder.createConvert(loc, fieldEleTy, fromPointerValue); @@ -1320,11 +1320,11 @@ static bool recordTypeCanBeMemCopied(fir::RecordType recordType) { for (auto [_, fieldType] : recordType.getTypeList()) { // Derived type component may have user assignment (so far, we cannot tell // in FIR, so assume it is always the case, TODO: get the actual info). - if (mlir::isa(fir::unwrapSequenceType(fieldType))) + if (fir::unwrapSequenceType(fieldType).isa()) return false; // Allocatable components need deep copy. - if (auto boxType = mlir::dyn_cast(fieldType)) - if (mlir::isa(boxType.getEleTy())) + if (auto boxType = fieldType.dyn_cast()) + if (boxType.getEleTy().isa()) return false; } // Constant size components without user defined assignment and pointers can @@ -1353,10 +1353,9 @@ void fir::factory::genRecordAssignment(fir::FirOpBuilder &builder, // Box operands may be polymorphic, it is not entirely clear from 10.2.1.3 // if the assignment is performed on the dynamic of declared type. Use the // runtime assuming it is performed on the dynamic type. - bool hasBoxOperands = - mlir::isa(fir::getBase(lhs).getType()) || - mlir::isa(fir::getBase(rhs).getType()); - auto recTy = mlir::dyn_cast(baseTy); + bool hasBoxOperands = fir::getBase(lhs).getType().isa() || + fir::getBase(rhs).getType().isa(); + auto recTy = baseTy.dyn_cast(); assert(recTy && "must be a record type"); if ((needFinalization && mayHaveFinalizer(recTy, builder)) || hasBoxOperands || !recordTypeCanBeMemCopied(recTy)) { @@ -1402,7 +1401,7 @@ mlir::Value fir::factory::genLenOfCharacter( llvm::ArrayRef path, llvm::ArrayRef substring) { llvm::SmallVector typeParams(arrLoad.getTypeparams()); return genLenOfCharacter(builder, loc, - mlir::cast(arrLoad.getType()), + arrLoad.getType().cast(), arrLoad.getMemref(), typeParams, path, substring); } @@ -1430,7 +1429,7 @@ mlir::Value fir::factory::genLenOfCharacter( lower = builder.createConvert(loc, idxTy, substring.front()); auto eleTy = fir::applyPathToType(seqTy, path); if (!fir::hasDynamicSize(eleTy)) { - if (auto charTy = mlir::dyn_cast(eleTy)) { + if (auto charTy = eleTy.dyn_cast()) { // Use LEN from the type. return builder.createIntegerConstant(loc, idxTy, charTy.getLen()); } @@ -1439,9 +1438,9 @@ mlir::Value fir::factory::genLenOfCharacter( "application of path did not result in a !fir.char"); } if (fir::isa_box_type(memref.getType())) { - if (mlir::isa(memref.getType())) + if (memref.getType().isa()) return builder.create(loc, idxTy, memref); - if (mlir::isa(memref.getType())) + if (memref.getType().isa()) return CharacterExprHelper(builder, loc).readLengthFromBox(memref); fir::emitFatalError(loc, "memref has wrong type"); } @@ -1458,7 +1457,7 @@ mlir::Value fir::factory::genLenOfCharacter( mlir::Value fir::factory::createZeroValue(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Type type) { mlir::Type i1 = builder.getIntegerType(1); - if (mlir::isa(type) || type == i1) + if (type.isa() || type == i1) return builder.createConvert(loc, type, builder.createBool(loc, false)); if (fir::isa_integer(type)) return builder.createIntegerConstant(loc, type, 0); @@ -1508,7 +1507,7 @@ mlir::Value fir::factory::genMaxWithZero(fir::FirOpBuilder &builder, mlir::Value zero = builder.createIntegerConstant(loc, value.getType(), 0); if (mlir::Operation *definingOp = value.getDefiningOp()) if (auto cst = mlir::dyn_cast(definingOp)) - if (auto intAttr = mlir::dyn_cast(cst.getValue())) + if (auto intAttr = cst.getValue().dyn_cast()) return intAttr.getInt() > 0 ? value : zero; mlir::Value valueIsGreater = builder.create( loc, mlir::arith::CmpIPredicate::sgt, value, zero); @@ -1520,8 +1519,8 @@ mlir::Value fir::factory::genCPtrOrCFunptrAddr(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Value cPtr, mlir::Type ty) { - assert(mlir::isa(ty)); - auto recTy = mlir::dyn_cast(ty); + assert(ty.isa()); + auto recTy = ty.dyn_cast(); assert(recTy.getTypeList().size() == 1); auto fieldName = recTy.getTypeList()[0].first; mlir::Type fieldTy = recTy.getTypeList()[0].second; @@ -1583,7 +1582,7 @@ mlir::Value fir::factory::genCPtrOrCFunptrValue(fir::FirOpBuilder &builder, mlir::Value fir::factory::createNullBoxProc(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Type boxType) { - auto boxTy{mlir::dyn_cast(boxType)}; + auto boxTy{boxType.dyn_cast()}; if (!boxTy) fir::emitFatalError(loc, "Procedure pointer must be of BoxProcType"); auto boxEleTy{fir::unwrapRefType(boxTy.getEleTy())}; diff --git a/flang/lib/Optimizer/Builder/HLFIRTools.cpp b/flang/lib/Optimizer/Builder/HLFIRTools.cpp index 44779427ab557..db638ceb40700 100644 --- a/flang/lib/Optimizer/Builder/HLFIRTools.cpp +++ b/flang/lib/Optimizer/Builder/HLFIRTools.cpp @@ -38,10 +38,10 @@ hlfir::getExplicitExtentsFromShape(mlir::Value shape, } else if (mlir::dyn_cast_or_null(shapeOp)) { return {}; } else if (auto s = mlir::dyn_cast_or_null(shapeOp)) { - hlfir::ExprType expr = mlir::cast(s.getExpr().getType()); + hlfir::ExprType expr = s.getExpr().getType().cast(); llvm::ArrayRef exprShape = expr.getShape(); mlir::Type indexTy = builder.getIndexType(); - fir::ShapeType shapeTy = mlir::cast(shape.getType()); + fir::ShapeType shapeTy = shape.getType().cast(); result.reserve(shapeTy.getRank()); for (unsigned i = 0; i < shapeTy.getRank(); ++i) { int64_t extent = exprShape[i]; @@ -99,7 +99,7 @@ genLboundsAndExtentsFromBox(mlir::Location loc, fir::FirOpBuilder &builder, hlfir::Entity boxEntity, llvm::SmallVectorImpl &lbounds, llvm::SmallVectorImpl *extents) { - assert(mlir::isa(boxEntity.getType()) && "must be a box"); + assert(boxEntity.getType().isa() && "must be a box"); mlir::Type idxTy = builder.getIndexType(); const int rank = boxEntity.getRank(); for (int i = 0; i < rank; ++i) { @@ -154,7 +154,7 @@ static mlir::Value genCharacterVariableLength(mlir::Location loc, hlfir::Entity var) { if (mlir::Value len = tryGettingNonDeferredCharLen(var)) return len; - auto charType = mlir::cast(var.getFortranElementType()); + auto charType = var.getFortranElementType().cast(); if (charType.hasConstantLen()) return builder.createIntegerConstant(loc, builder.getIndexType(), charType.getLen()); @@ -172,7 +172,7 @@ static fir::CharBoxValue genUnboxChar(mlir::Location loc, if (auto emboxChar = boxChar.getDefiningOp()) return {emboxChar.getMemref(), emboxChar.getLen()}; mlir::Type refType = fir::ReferenceType::get( - mlir::cast(boxChar.getType()).getEleTy()); + boxChar.getType().cast().getEleTy()); auto unboxed = builder.create( loc, refType, builder.getIndexType(), boxChar); mlir::Value addr = unboxed.getResult(0); @@ -252,8 +252,8 @@ hlfir::genAssociateExpr(mlir::Location loc, fir::FirOpBuilder &builder, // and the other static). mlir::Type varEleTy = getFortranElementType(variableType); mlir::Type valueEleTy = getFortranElementType(value.getType()); - if (varEleTy != valueEleTy && !(mlir::isa(valueEleTy) && - mlir::isa(varEleTy))) { + if (varEleTy != valueEleTy && !(valueEleTy.isa() && + varEleTy.isa())) { assert(value.isScalar() && fir::isa_trivial(value.getType())); source = builder.createConvert(loc, fir::unwrapPassByRefType(variableType), value); @@ -278,9 +278,9 @@ mlir::Value hlfir::genVariableRawAddress(mlir::Location loc, if (var.isMutableBox()) baseAddr = builder.create(loc, baseAddr); // Get raw address. - if (mlir::isa(var.getType())) + if (var.getType().isa()) baseAddr = genUnboxChar(loc, builder, var.getBase()).getAddr(); - if (mlir::isa(baseAddr.getType())) + if (baseAddr.getType().isa()) baseAddr = builder.create(loc, baseAddr); return baseAddr; } @@ -289,13 +289,13 @@ mlir::Value hlfir::genVariableBoxChar(mlir::Location loc, fir::FirOpBuilder &builder, hlfir::Entity var) { assert(var.isVariable() && "only address of variables can be taken"); - if (mlir::isa(var.getType())) + if (var.getType().isa()) return var; mlir::Value addr = genVariableRawAddress(loc, builder, var); llvm::SmallVector lengths; genLengthParameters(loc, builder, var, lengths); assert(lengths.size() == 1); - auto charType = mlir::cast(var.getFortranElementType()); + auto charType = var.getFortranElementType().cast(); auto boxCharType = fir::BoxCharType::get(builder.getContext(), charType.getFKind()); auto scalarAddr = @@ -309,7 +309,7 @@ hlfir::Entity hlfir::genVariableBox(mlir::Location loc, hlfir::Entity var) { assert(var.isVariable() && "must be a variable"); var = hlfir::derefPointersAndAllocatables(loc, builder, var); - if (mlir::isa(var.getType())) + if (var.getType().isa()) return var; // Note: if the var is not a fir.box/fir.class at that point, it has default // lower bounds and is not polymorphic. @@ -317,11 +317,11 @@ hlfir::Entity hlfir::genVariableBox(mlir::Location loc, var.isArray() ? hlfir::genShape(loc, builder, var) : mlir::Value{}; llvm::SmallVector typeParams; auto maybeCharType = - mlir::dyn_cast(var.getFortranElementType()); + var.getFortranElementType().dyn_cast(); if (!maybeCharType || maybeCharType.hasDynamicLen()) hlfir::genLengthParameters(loc, builder, var, typeParams); mlir::Value addr = var.getBase(); - if (mlir::isa(var.getType())) + if (var.getType().isa()) addr = genVariableRawAddress(loc, builder, var); mlir::Type boxType = fir::BoxType::get(var.getElementOrSequenceType()); auto embox = @@ -348,7 +348,7 @@ hlfir::Entity hlfir::getElementAt(mlir::Location loc, return entity; llvm::SmallVector lenParams; genLengthParameters(loc, builder, entity, lenParams); - if (mlir::isa(entity.getType())) + if (entity.getType().isa()) return hlfir::Entity{builder.create( loc, entity, oneBasedIndices, lenParams)}; // Build hlfir.designate. The lower bounds may need to be added to @@ -394,7 +394,7 @@ static mlir::Value genUBound(mlir::Location loc, fir::FirOpBuilder &builder, llvm::SmallVector> hlfir::genBounds(mlir::Location loc, fir::FirOpBuilder &builder, Entity entity) { - if (mlir::isa(entity.getType())) + if (entity.getType().isa()) TODO(loc, "bounds of expressions in hlfir"); auto [exv, cleanup] = translateToExtendedValue(loc, builder, entity); assert(!cleanup && "translation of entity should not yield cleanup"); @@ -415,8 +415,8 @@ hlfir::genBounds(mlir::Location loc, fir::FirOpBuilder &builder, llvm::SmallVector> hlfir::genBounds(mlir::Location loc, fir::FirOpBuilder &builder, mlir::Value shape) { - assert((mlir::isa(shape.getType()) || - mlir::isa(shape.getType())) && + assert((shape.getType().isa() || + shape.getType().isa()) && "shape must contain extents"); auto extents = hlfir::getExplicitExtentsFromShape(shape, builder); auto lowers = getExplicitLboundsFromShape(shape); @@ -474,7 +474,7 @@ static mlir::Value computeVariableExtent(mlir::Location loc, if (typeExtent != fir::SequenceType::getUnknownExtent()) return builder.createIntegerConstant(loc, idxTy, typeExtent); } - assert(mlir::isa(variable.getType()) && + assert(variable.getType().isa() && "array variable with dynamic extent must be boxed"); mlir::Value dimVal = builder.createIntegerConstant(loc, idxTy, dim); auto dimInfo = builder.create(loc, idxTy, idxTy, idxTy, @@ -496,8 +496,9 @@ llvm::SmallVector getVariableExtents(mlir::Location loc, variable = hlfir::derefPointersAndAllocatables(loc, builder, variable); // Use the type shape information, and/or the fir.box/fir.class shape // information if any extents are not static. - fir::SequenceType seqTy = mlir::cast( - hlfir::getFortranElementOrSequenceType(variable.getType())); + fir::SequenceType seqTy = + hlfir::getFortranElementOrSequenceType(variable.getType()) + .cast(); unsigned rank = seqTy.getShape().size(); for (unsigned dim = 0; dim < rank; ++dim) extents.push_back( @@ -506,7 +507,7 @@ llvm::SmallVector getVariableExtents(mlir::Location loc, } static mlir::Value tryRetrievingShapeOrShift(hlfir::Entity entity) { - if (mlir::isa(entity.getType())) { + if (entity.getType().isa()) { if (auto elemental = entity.getDefiningOp()) return elemental.getShape(); return mlir::Value{}; @@ -522,13 +523,13 @@ mlir::Value hlfir::genShape(mlir::Location loc, fir::FirOpBuilder &builder, entity = followShapeInducingSource(entity); assert(entity && "what?"); if (auto shape = tryRetrievingShapeOrShift(entity)) { - if (mlir::isa(shape.getType())) + if (shape.getType().isa()) return shape; - if (mlir::isa(shape.getType())) + if (shape.getType().isa()) if (auto s = shape.getDefiningOp()) return builder.create(loc, s.getExtents()); } - if (mlir::isa(entity.getType())) + if (entity.getType().isa()) return builder.create(loc, entity.getBase()); // There is no shape lying around for this entity. Retrieve the extents and // build a new fir.shape. @@ -562,8 +563,9 @@ mlir::Value hlfir::genExtent(mlir::Location loc, fir::FirOpBuilder &builder, entity = hlfir::derefPointersAndAllocatables(loc, builder, entity); // Use the type shape information, and/or the fir.box/fir.class shape // information if any extents are not static. - fir::SequenceType seqTy = mlir::cast( - hlfir::getFortranElementOrSequenceType(entity.getType())); + fir::SequenceType seqTy = + hlfir::getFortranElementOrSequenceType(entity.getType()) + .cast(); return computeVariableExtent(loc, builder, entity, seqTy, dim); } TODO(loc, "get extent from HLFIR expr without producer holding the shape"); @@ -582,7 +584,7 @@ mlir::Value hlfir::genLBound(mlir::Location loc, fir::FirOpBuilder &builder, } if (entity.isMutableBox()) entity = hlfir::derefPointersAndAllocatables(loc, builder, entity); - assert(mlir::isa(entity.getType()) && "must be a box"); + assert(entity.getType().isa() && "must be a box"); mlir::Type idxTy = builder.getIndexType(); mlir::Value dimVal = builder.createIntegerConstant(loc, idxTy, dim); auto dimInfo = @@ -595,7 +597,7 @@ void hlfir::genLengthParameters(mlir::Location loc, fir::FirOpBuilder &builder, llvm::SmallVectorImpl &result) { if (!entity.hasLengthParameters()) return; - if (mlir::isa(entity.getType())) { + if (entity.getType().isa()) { mlir::Value expr = entity; if (auto reassoc = expr.getDefiningOp()) expr = reassoc.getVal(); @@ -652,8 +654,8 @@ static mlir::Value asEmboxShape(mlir::Location loc, fir::FirOpBuilder &builder, // fir.shape_shift) since this information is already in the input fir.box, // it only accepts fir.shift because local lower bounds may not be reflected // in the fir.box. - if (mlir::isa(fir::getBase(exv).getType()) && - !mlir::isa(shape.getType())) + if (fir::getBase(exv).getType().isa() && + !shape.getType().isa()) return builder.createShape(loc, exv); return shape; } @@ -684,7 +686,7 @@ hlfir::Entity hlfir::derefPointersAndAllocatables(mlir::Location loc, if (!entity.isPolymorphic() && !entity.hasLengthParameters()) return hlfir::Entity{builder.create(loc, boxLoad)}; mlir::Type elementType = boxLoad.getFortranElementType(); - if (auto charType = mlir::dyn_cast(elementType)) { + if (auto charType = elementType.dyn_cast()) { mlir::Value base = builder.create(loc, boxLoad); if (charType.hasConstantLen()) return hlfir::Entity{base}; @@ -714,7 +716,7 @@ mlir::Type hlfir::getVariableElementType(hlfir::Entity variable) { mlir::Type eleTy = variable.getFortranElementType(); if (variable.isPolymorphic()) return fir::ClassType::get(eleTy); - if (auto charType = mlir::dyn_cast(eleTy)) { + if (auto charType = eleTy.dyn_cast()) { if (charType.hasDynamicLen()) return fir::BoxCharType::get(charType.getContext(), charType.getFKind()); } else if (fir::isRecordWithTypeParameters(eleTy)) { @@ -735,7 +737,7 @@ mlir::Type hlfir::getEntityElementType(hlfir::Entity entity) { static hlfir::ExprType getArrayExprType(mlir::Type elementType, mlir::Value shape, bool isPolymorphic) { - unsigned rank = mlir::cast(shape.getType()).getRank(); + unsigned rank = shape.getType().cast().getRank(); hlfir::ExprType::Shape typeShape(rank, hlfir::ExprType::getUnknownExtent()); if (auto shapeOp = shape.getDefiningOp()) for (auto extent : llvm::enumerate(shapeOp.getExtents())) @@ -857,7 +859,7 @@ translateVariableToExtendedValue(mlir::Location loc, fir::FirOpBuilder &builder, return fir::MutableBoxValue(base, getExplicitTypeParams(variable), fir::MutableProperties{}); - if (mlir::isa(base.getType())) { + if (base.getType().isa()) { if (!variable.isSimplyContiguous() || variable.isPolymorphic() || variable.isDerivedWithLengthParameters() || variable.isOptional()) { llvm::SmallVector nonDefaultLbounds = @@ -872,7 +874,7 @@ translateVariableToExtendedValue(mlir::Location loc, fir::FirOpBuilder &builder, if (variable.isScalar()) { if (variable.isCharacter()) { - if (mlir::isa(base.getType())) + if (base.getType().isa()) return genUnboxChar(loc, builder, base); mlir::Value len = genCharacterVariableLength(loc, builder, variable); return fir::CharBoxValue{base, len}; @@ -881,7 +883,7 @@ translateVariableToExtendedValue(mlir::Location loc, fir::FirOpBuilder &builder, } llvm::SmallVector extents; llvm::SmallVector nonDefaultLbounds; - if (mlir::isa(variable.getType()) && + if (variable.getType().isa() && !variable.getIfVariableInterface()) { // This special case avoids generating two sets of identical // fir.box_dim to get both the lower bounds and extents. @@ -921,7 +923,7 @@ hlfir::translateToExtendedValue(mlir::Location loc, fir::FirOpBuilder &builder, return {static_cast(entity), std::nullopt}; } - if (mlir::isa(entity.getType())) { + if (entity.getType().isa()) { mlir::NamedAttribute byRefAttr = fir::getAdaptToByRefAttr(builder); hlfir::AssociateOp associate = hlfir::genAssociateExpr( loc, builder, entity, entity.getType(), "", byRefAttr); diff --git a/flang/lib/Optimizer/Builder/IntrinsicCall.cpp b/flang/lib/Optimizer/Builder/IntrinsicCall.cpp index 9d72e76e2369d..e28d14cd318d3 100644 --- a/flang/lib/Optimizer/Builder/IntrinsicCall.cpp +++ b/flang/lib/Optimizer/Builder/IntrinsicCall.cpp @@ -786,7 +786,7 @@ mlir::Value genLibSplitComplexArgsCall(fir::FirOpBuilder &builder, auto getSplitComplexArgsType = [&builder, &args]() -> mlir::FunctionType { mlir::Type ctype = args[0].getType(); - auto fKind = mlir::cast(ctype).getFKind(); + auto fKind = ctype.cast().getFKind(); mlir::Type ftype; if (fKind == 2) @@ -894,8 +894,8 @@ mlir::Value genComplexMathOp(fir::FirOpBuilder &builder, mlir::Location loc, LLVM_DEBUG(llvm::dbgs() << "Generating '" << mathLibFuncName << "' operation with type "; mathLibFuncType.dump(); llvm::dbgs() << "\n"); - auto type = mlir::cast(mathLibFuncType.getInput(0)); - auto kind = mlir::cast(type.getElementType()).getFKind(); + auto type = mathLibFuncType.getInput(0).cast(); + auto kind = type.getElementType().cast().getFKind(); auto realTy = builder.getRealType(kind); auto mComplexTy = mlir::ComplexType::get(realTy); @@ -1394,14 +1394,14 @@ class FunctionDistance { // Floating point can be mlir::FloatType or fir::real static unsigned getFloatingPointWidth(mlir::Type t) { - if (auto f{mlir::dyn_cast(t)}) + if (auto f{t.dyn_cast()}) return f.getWidth(); // FIXME: Get width another way for fir.real/complex // - use fir/KindMapping.h and llvm::Type // - or use evaluate/type.h - if (auto r{mlir::dyn_cast(t)}) + if (auto r{t.dyn_cast()}) return r.getFKind() * 4; - if (auto cplx{mlir::dyn_cast(t)}) + if (auto cplx{t.dyn_cast()}) return cplx.getFKind() * 4; llvm_unreachable("not a floating-point type"); } @@ -1410,8 +1410,8 @@ class FunctionDistance { if (from == to) return Conversion::None; - if (auto fromIntTy{mlir::dyn_cast(from)}) { - if (auto toIntTy{mlir::dyn_cast(to)}) { + if (auto fromIntTy{from.dyn_cast()}) { + if (auto toIntTy{to.dyn_cast()}) { return fromIntTy.getWidth() > toIntTy.getWidth() ? Conversion::Narrow : Conversion::Extend; } @@ -1423,8 +1423,8 @@ class FunctionDistance { : Conversion::Extend; } - if (auto fromCplxTy{mlir::dyn_cast(from)}) { - if (auto toCplxTy{mlir::dyn_cast(to)}) { + if (auto fromCplxTy{from.dyn_cast()}) { + if (auto toCplxTy{to.dyn_cast()}) { return getFloatingPointWidth(fromCplxTy) > getFloatingPointWidth(toCplxTy) ? Conversion::Narrow @@ -1550,10 +1550,10 @@ fir::ExtendedValue toExtendedValue(mlir::Value val, fir::FirOpBuilder &builder, if (charHelper.isCharacterScalar(type)) return charHelper.toExtendedValue(val); - if (auto refType = mlir::dyn_cast(type)) + if (auto refType = type.dyn_cast()) type = refType.getEleTy(); - if (auto arrayType = mlir::dyn_cast(type)) { + if (auto arrayType = type.dyn_cast()) { type = arrayType.getEleTy(); for (fir::SequenceType::Extent extent : arrayType.getShape()) { if (extent == fir::SequenceType::getUnknownExtent()) @@ -1566,8 +1566,7 @@ fir::ExtendedValue toExtendedValue(mlir::Value val, fir::FirOpBuilder &builder, // have been used in the interface). if (extents.size() + 1 < arrayType.getShape().size()) mlir::emitError(loc, "cannot retrieve array extents from type"); - } else if (mlir::isa(type) || - mlir::isa(type)) { + } else if (type.isa() || type.isa()) { fir::emitFatalError(loc, "not yet implemented: descriptor or derived type"); } @@ -1581,10 +1580,10 @@ mlir::Value toValue(const fir::ExtendedValue &val, fir::FirOpBuilder &builder, if (const fir::CharBoxValue *charBox = val.getCharBox()) { mlir::Value buffer = charBox->getBuffer(); auto buffTy = buffer.getType(); - if (mlir::isa(buffTy)) + if (buffTy.isa()) fir::emitFatalError( loc, "A character's buffer type cannot be a function type."); - if (mlir::isa(buffTy)) + if (buffTy.isa()) return buffer; return fir::factory::CharacterExprHelper{builder, loc}.createEmboxChar( buffer, charBox->getLen()); @@ -1828,27 +1827,27 @@ IntrinsicLibrary::invokeGenerator(SubroutineGenerator generator, /// Note: mlir has Type::dump(ostream) methods but it may add "!" that is not /// suitable for function names. static std::string typeToString(mlir::Type t) { - if (auto refT{mlir::dyn_cast(t)}) + if (auto refT{t.dyn_cast()}) return "ref_" + typeToString(refT.getEleTy()); - if (auto i{mlir::dyn_cast(t)}) { + if (auto i{t.dyn_cast()}) { return "i" + std::to_string(i.getWidth()); } - if (auto cplx{mlir::dyn_cast(t)}) { + if (auto cplx{t.dyn_cast()}) { return "z" + std::to_string(cplx.getFKind()); } - if (auto real{mlir::dyn_cast(t)}) { + if (auto real{t.dyn_cast()}) { return "r" + std::to_string(real.getFKind()); } - if (auto f{mlir::dyn_cast(t)}) { + if (auto f{t.dyn_cast()}) { return "f" + std::to_string(f.getWidth()); } - if (auto logical{mlir::dyn_cast(t)}) { + if (auto logical{t.dyn_cast()}) { return "l" + std::to_string(logical.getFKind()); } - if (auto character{mlir::dyn_cast(t)}) { + if (auto character{t.dyn_cast()}) { return "c" + std::to_string(character.getFKind()); } - if (auto boxCharacter{mlir::dyn_cast(t)}) { + if (auto boxCharacter{t.dyn_cast()}) { return "bc" + std::to_string(boxCharacter.getEleTy().getFKind()); } llvm_unreachable("no mangling for type"); @@ -1908,7 +1907,7 @@ mlir::func::FuncOp IntrinsicLibrary::getWrapper(GeneratorType generator, mlir::Location localLoc = localBuilder->getUnknownLoc(); llvm::SmallVector localArguments; for (mlir::BlockArgument bArg : function.front().getArguments()) { - auto refType = mlir::dyn_cast(bArg.getType()); + auto refType = bArg.getType().dyn_cast(); if (loadRefArguments && refType) { auto loaded = localBuilder->create(localLoc, bArg); localArguments.push_back(loaded); @@ -2061,7 +2060,7 @@ mlir::SymbolRefAttr IntrinsicLibrary::getUnrestrictedIntrinsicSymbolRefAttr( if (!funcOp) { llvm::SmallVector argTypes; for (mlir::Type type : signature.getInputs()) { - if (auto refType = mlir::dyn_cast(type)) + if (auto refType = type.dyn_cast()) argTypes.push_back(refType.getEleTy()); else argTypes.push_back(type); @@ -2146,7 +2145,7 @@ mlir::Value IntrinsicLibrary::genAbs(mlir::Type resultType, // math::AbsFOp but it does not support all fir floating point types. return genRuntimeCall("abs", resultType, args); } - if (auto intType = mlir::dyn_cast(type)) { + if (auto intType = type.dyn_cast()) { // At the time of this implementation there is no abs op in mlir. // So, implement abs here without branching. mlir::Value shift = @@ -2380,8 +2379,8 @@ IntrinsicLibrary::genAssociated(mlir::Type resultType, llvm::ArrayRef args) { assert(args.size() == 2); mlir::Type ptrTy = fir::getBase(args[0]).getType(); - if (ptrTy && (fir::isBoxProcAddressType(ptrTy) || - mlir::isa(ptrTy))) { + if (ptrTy && + (fir::isBoxProcAddressType(ptrTy) || ptrTy.isa())) { mlir::Value pointerBoxProc = fir::isBoxProcAddressType(ptrTy) ? builder.create(loc, fir::getBase(args[0])) @@ -2393,7 +2392,7 @@ IntrinsicLibrary::genAssociated(mlir::Type resultType, mlir::Value target = fir::getBase(args[1]); if (fir::isBoxProcAddressType(target.getType())) target = builder.create(loc, target); - if (mlir::isa(target.getType())) + if (target.getType().isa()) target = builder.create(loc, target); mlir::Type intPtrTy = builder.getIntPtrType(); mlir::Value pointerInt = @@ -2650,7 +2649,7 @@ static mlir::Value getAddrFromBox(fir::FirOpBuilder &builder, mlir::Value argValue = fir::getBase(arg); mlir::Value addr{nullptr}; if (isFunc) { - auto funcTy = mlir::cast(argValue.getType()).getEleTy(); + auto funcTy = argValue.getType().cast().getEleTy(); addr = builder.create(loc, funcTy, argValue); } else { const auto *box = arg.getBoxOf(); @@ -3030,7 +3029,7 @@ void IntrinsicLibrary::genDateAndTime(llvm::ArrayRef args) { mlir::Value IntrinsicLibrary::genDim(mlir::Type resultType, llvm::ArrayRef args) { assert(args.size() == 2); - if (mlir::isa(resultType)) { + if (resultType.isa()) { mlir::Value zero = builder.createIntegerConstant(loc, resultType, 0); auto diff = builder.create(loc, args[0], args[1]); auto cmp = builder.create( @@ -3575,7 +3574,7 @@ IntrinsicLibrary::genReduction(FN func, FD funcDim, llvm::StringRef errMsg, if (absentDim || rank == 1) { mlir::Type ty = array.getType(); mlir::Type arrTy = fir::dyn_cast_ptrOrBoxEleTy(ty); - auto eleTy = mlir::cast(arrTy).getEleTy(); + auto eleTy = arrTy.cast().getEleTy(); if (fir::isa_complex(eleTy)) { mlir::Value result = builder.createTemporary(loc, eleTy); func(builder, loc, array, mask, result); @@ -3647,7 +3646,7 @@ mlir::Value IntrinsicLibrary::genIbits(mlir::Type resultType, mlir::Value pos = builder.createConvert(loc, resultType, args[1]); mlir::Value len = builder.createConvert(loc, resultType, args[2]); mlir::Value bitSize = builder.createIntegerConstant( - loc, resultType, mlir::cast(resultType).getWidth()); + loc, resultType, resultType.cast().getWidth()); auto shiftCount = builder.create(loc, bitSize, len); mlir::Value zero = builder.createIntegerConstant(loc, resultType, 0); mlir::Value ones = builder.createAllOnesInteger(loc, resultType); @@ -3687,7 +3686,7 @@ IntrinsicLibrary::genIchar(mlir::Type resultType, mlir::Value buffer = charBox->getBuffer(); mlir::Type bufferTy = buffer.getType(); mlir::Value charVal; - if (auto charTy = mlir::dyn_cast(bufferTy)) { + if (auto charTy = bufferTy.dyn_cast()) { assert(charTy.singleton()); charVal = buffer; } else { @@ -3760,7 +3759,7 @@ void IntrinsicLibrary::genRaiseExcept(int except, mlir::Value cond) { static std::pair getFieldRef(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Value rec) { auto recType = - mlir::dyn_cast(fir::unwrapPassByRefType(rec.getType())); + fir::unwrapPassByRefType(rec.getType()).dyn_cast(); assert(recType.getTypeList().size() == 1 && "expected exactly one component"); auto [fieldName, fieldTy] = recType.getTypeList().front(); mlir::Value field = builder.create( @@ -3809,7 +3808,7 @@ mlir::Value IntrinsicLibrary::genIeeeClass(mlir::Type resultType, assert(args.size() == 1); mlir::Value realVal = args[0]; - mlir::FloatType realType = mlir::dyn_cast(realVal.getType()); + mlir::FloatType realType = realVal.getType().dyn_cast(); const unsigned intWidth = realType.getWidth(); mlir::Type intType = builder.getIntegerType(intWidth); mlir::Value intVal = @@ -4057,10 +4056,8 @@ IntrinsicLibrary::genIeeeCopySign(mlir::Type resultType, assert(args.size() == 2); mlir::Value xRealVal = args[0]; mlir::Value yRealVal = args[1]; - mlir::FloatType xRealType = - mlir::dyn_cast(xRealVal.getType()); - mlir::FloatType yRealType = - mlir::dyn_cast(yRealVal.getType()); + mlir::FloatType xRealType = xRealVal.getType().dyn_cast(); + mlir::FloatType yRealType = yRealVal.getType().dyn_cast(); if (yRealType == mlir::FloatType::getBF16(builder.getContext())) { // Workaround: CopySignOp and BitcastOp don't work for kind 3 arg Y. @@ -4109,7 +4106,7 @@ void IntrinsicLibrary::genIeeeGetFlag(llvm::ArrayRef args) { mlir::Value flag = fir::getBase(args[0]); mlir::Value flagValue = fir::getBase(args[1]); mlir::Type resultTy = - mlir::dyn_cast(flagValue.getType()).getEleTy(); + flagValue.getType().dyn_cast().getEleTy(); mlir::Type i32Ty = builder.getIntegerType(32); mlir::Value zero = builder.createIntegerConstant(loc, i32Ty, 0); auto [fieldRef, ignore] = getFieldRef(builder, loc, flag); @@ -4133,7 +4130,7 @@ void IntrinsicLibrary::genIeeeGetHaltingMode( mlir::Value flag = fir::getBase(args[0]); mlir::Value halting = fir::getBase(args[1]); mlir::Type resultTy = - mlir::dyn_cast(halting.getType()).getEleTy(); + halting.getType().dyn_cast().getEleTy(); mlir::Type i32Ty = builder.getIntegerType(32); mlir::Value zero = builder.createIntegerConstant(loc, i32Ty, 0); auto [fieldRef, ignore] = getFieldRef(builder, loc, flag); @@ -4251,7 +4248,7 @@ mlir::Value IntrinsicLibrary::genIeeeLogb(mlir::Type resultType, // : ieee_copy_sign(X, 1.0) // +infinity or NaN assert(args.size() == 1); mlir::Value realVal = args[0]; - mlir::FloatType realType = mlir::dyn_cast(realVal.getType()); + mlir::FloatType realType = realVal.getType().dyn_cast(); int bitWidth = realType.getWidth(); mlir::Type intType = builder.getIntegerType(realType.getWidth()); mlir::Value intVal = @@ -4548,7 +4545,7 @@ mlir::Value IntrinsicLibrary::genIeeeSignbit(mlir::Type resultType, // Check if the sign bit of arg X is set. assert(args.size() == 1); mlir::Value realVal = args[0]; - mlir::FloatType realType = mlir::dyn_cast(realVal.getType()); + mlir::FloatType realType = realVal.getType().dyn_cast(); int bitWidth = realType.getWidth(); if (realType == mlir::FloatType::getBF16(builder.getContext())) { // Workaround: can't bitcast or convert real(3) to integer(2) or real(2). @@ -4645,7 +4642,7 @@ mlir::Value IntrinsicLibrary::genIeeeValue(mlir::Type resultType, // A compiler generated call has one argument: // - arg[0] is an index constant assert(args.size() == 1 || args.size() == 2); - mlir::FloatType realType = mlir::dyn_cast(resultType); + mlir::FloatType realType = resultType.dyn_cast(); int bitWidth = realType.getWidth(); mlir::Type intType = builder.getIntegerType(bitWidth); mlir::Type valueTy = bitWidth <= 64 ? intType : builder.getIntegerType(64); @@ -4887,7 +4884,7 @@ mlir::Value IntrinsicLibrary::genIshft(mlir::Type resultType, // : I << abs(SHIFT) assert(args.size() == 2); mlir::Value bitSize = builder.createIntegerConstant( - loc, resultType, mlir::cast(resultType).getWidth()); + loc, resultType, resultType.cast().getWidth()); mlir::Value zero = builder.createIntegerConstant(loc, resultType, 0); mlir::Value shift = builder.createConvert(loc, resultType, args[1]); mlir::Value absShift = genAbs(resultType, {shift}); @@ -4923,7 +4920,7 @@ mlir::Value IntrinsicLibrary::genIshftc(mlir::Type resultType, // Return: SHIFT == 0 || SIZE == abs(SHIFT) ? I : (unchanged | left | right) assert(args.size() == 3); mlir::Value bitSize = builder.createIntegerConstant( - loc, resultType, mlir::cast(resultType).getWidth()); + loc, resultType, resultType.cast().getWidth()); mlir::Value I = args[0]; mlir::Value shift = builder.createConvert(loc, resultType, args[1]); mlir::Value size = @@ -5030,7 +5027,7 @@ IntrinsicLibrary::genLoc(mlir::Type resultType, mlir::Value box = fir::getBase(args[0]); assert(fir::isa_box_type(box.getType()) && "argument must have been lowered to box type"); - bool isFunc = mlir::isa(box.getType()); + bool isFunc = box.getType().isa(); if (!isOptional(box)) { mlir::Value argAddr = getAddrFromBox(builder, loc, args[0], isFunc); return builder.createConvert(loc, resultType, argAddr); @@ -5159,7 +5156,7 @@ IntrinsicLibrary::genMerge(mlir::Type, auto convertToStaticType = [&](mlir::Value polymorphic, mlir::Value other) -> mlir::Value { mlir::Type otherType = other.getType(); - if (mlir::isa(otherType)) + if (otherType.isa()) return builder.create(loc, otherType, polymorphic, /*shape*/ mlir::Value{}, /*slice=*/mlir::Value{}); @@ -5212,7 +5209,7 @@ mlir::Value IntrinsicLibrary::genMergeBits(mlir::Type resultType, mlir::Value IntrinsicLibrary::genMod(mlir::Type resultType, llvm::ArrayRef args) { assert(args.size() == 2); - if (mlir::isa(resultType)) + if (resultType.isa()) return builder.create(loc, args[0], args[1]); // Use runtime. @@ -5234,7 +5231,7 @@ mlir::Value IntrinsicLibrary::genModulo(mlir::Type resultType, // - Otherwise, when A/P < 0 and MOD(A,P) !=0, then MODULO(A, P) = // A-FLOOR(A/P)*P = A-(INT(A/P)-1)*P = A-INT(A/P)*P+P = MOD(A,P)+P // Note that A/P < 0 if and only if A and P signs are different. - if (mlir::isa(resultType)) { + if (resultType.isa()) { auto remainder = builder.create(loc, args[0], args[1]); auto argXor = builder.create(loc, args[0], args[1]); @@ -5347,7 +5344,7 @@ void IntrinsicLibrary::genMvbits(llvm::ArrayRef args) { mlir::Value zero = builder.createIntegerConstant(loc, resultType, 0); mlir::Value ones = builder.createAllOnesInteger(loc, resultType); mlir::Value bitSize = builder.createIntegerConstant( - loc, resultType, mlir::cast(resultType).getWidth()); + loc, resultType, resultType.cast().getWidth()); auto shiftCount = builder.create(loc, bitSize, len); auto mask = builder.create(loc, ones, shiftCount); auto unchangedTmp1 = builder.create(loc, mask, topos); @@ -5631,7 +5628,7 @@ IntrinsicLibrary::genReshape(mlir::Type resultType, assert(fir::BoxValue(shape).rank() == 1); mlir::Type shapeTy = shape.getType(); mlir::Type shapeArrTy = fir::dyn_cast_ptrOrBoxEleTy(shapeTy); - auto resultRank = mlir::cast(shapeArrTy).getShape()[0]; + auto resultRank = shapeArrTy.cast().getShape()[0]; if (resultRank == fir::SequenceType::getUnknownExtent()) TODO(loc, "intrinsic: reshape requires computing rank of result"); @@ -5924,7 +5921,7 @@ void IntrinsicLibrary::genSignalSubroutine( mlir::Value IntrinsicLibrary::genSign(mlir::Type resultType, llvm::ArrayRef args) { assert(args.size() == 2); - if (mlir::isa(resultType)) { + if (resultType.isa()) { mlir::Value abs = genAbs(resultType, {args[0]}); mlir::Value zero = builder.createIntegerConstant(loc, resultType, 0); auto neg = builder.create(loc, zero, abs); diff --git a/flang/lib/Optimizer/Builder/MutableBox.cpp b/flang/lib/Optimizer/Builder/MutableBox.cpp index 76b920dba8697..d4012e9c3d9d9 100644 --- a/flang/lib/Optimizer/Builder/MutableBox.cpp +++ b/flang/lib/Optimizer/Builder/MutableBox.cpp @@ -28,7 +28,7 @@ createNewFirBox(fir::FirOpBuilder &builder, mlir::Location loc, const fir::MutableBoxValue &box, mlir::Value addr, mlir::ValueRange lbounds, mlir::ValueRange extents, mlir::ValueRange lengths, mlir::Value tdesc = {}) { - if (mlir::isa(addr.getType())) + if (addr.getType().isa()) // The entity is already boxed. return builder.createConvert(loc, box.getBoxTy(), addr); @@ -53,21 +53,20 @@ createNewFirBox(fir::FirOpBuilder &builder, mlir::Location loc, // error in the embox). llvm::SmallVector cleanedLengths; auto cleanedAddr = addr; - if (auto charTy = mlir::dyn_cast(box.getEleTy())) { + if (auto charTy = box.getEleTy().dyn_cast()) { // Cast address to box type so that both input and output type have // unknown or constant lengths. auto bt = box.getBaseTy(); auto addrTy = addr.getType(); - auto type = mlir::isa(addrTy) ? fir::HeapType::get(bt) - : mlir::isa(addrTy) - ? fir::PointerType::get(bt) - : builder.getRefType(bt); + auto type = addrTy.isa() ? fir::HeapType::get(bt) + : addrTy.isa() ? fir::PointerType::get(bt) + : builder.getRefType(bt); cleanedAddr = builder.createConvert(loc, type, addr); if (charTy.getLen() == fir::CharacterType::unknownLen()) cleanedLengths.append(lengths.begin(), lengths.end()); } else if (fir::isUnlimitedPolymorphicType(box.getBoxTy())) { - if (auto charTy = mlir::dyn_cast( - fir::dyn_cast_ptrEleTy(addr.getType()))) { + if (auto charTy = fir::dyn_cast_ptrEleTy(addr.getType()) + .dyn_cast()) { if (charTy.getLen() == fir::CharacterType::unknownLen()) cleanedLengths.append(lengths.begin(), lengths.end()); } @@ -329,18 +328,18 @@ class MutablePropertyWriter { mlir::Value fir::factory::createUnallocatedBox( fir::FirOpBuilder &builder, mlir::Location loc, mlir::Type boxType, mlir::ValueRange nonDeferredParams, mlir::Value typeSourceBox) { - auto baseAddrType = mlir::dyn_cast(boxType).getEleTy(); + auto baseAddrType = boxType.dyn_cast().getEleTy(); if (!fir::isa_ref_type(baseAddrType)) baseAddrType = builder.getRefType(baseAddrType); auto type = fir::unwrapRefType(baseAddrType); auto eleTy = fir::unwrapSequenceType(type); - if (auto recTy = mlir::dyn_cast(eleTy)) + if (auto recTy = eleTy.dyn_cast()) if (recTy.getNumLenParams() > 0) TODO(loc, "creating unallocated fir.box of derived type with length " "parameters"); auto nullAddr = builder.createNullConstant(loc, baseAddrType); mlir::Value shape; - if (auto seqTy = mlir::dyn_cast(type)) { + if (auto seqTy = type.dyn_cast()) { auto zero = builder.createIntegerConstant(loc, builder.getIndexType(), 0); llvm::SmallVector extents(seqTy.getDimension(), zero); shape = builder.createShape( @@ -349,7 +348,7 @@ mlir::Value fir::factory::createUnallocatedBox( // Provide dummy length parameters if they are dynamic. If a length parameter // is deferred. It is set to zero here and will be set on allocation. llvm::SmallVector lenParams; - if (auto charTy = mlir::dyn_cast(eleTy)) { + if (auto charTy = eleTy.dyn_cast()) { if (charTy.getLen() == fir::CharacterType::unknownLen()) { if (!nonDeferredParams.empty()) { lenParams.push_back(nonDeferredParams[0]); @@ -593,7 +592,7 @@ void fir::factory::associateMutableBoxWithRemap( auto cast = [&](mlir::Value addr) -> mlir::Value { // Cast base addr to new sequence type. auto ty = fir::dyn_cast_ptrEleTy(addr.getType()); - if (auto seqTy = mlir::dyn_cast(ty)) { + if (auto seqTy = ty.dyn_cast()) { fir::SequenceType::Shape shape(newRank, fir::SequenceType::getUnknownExtent()); ty = fir::SequenceType::get(shape, seqTy.getEleTy()); @@ -674,10 +673,10 @@ void fir::factory::disassociateMutableBox(fir::FirOpBuilder &builder, if (box.isPolymorphic() && polymorphicSetType) { // 7.3.2.3 point 7. The dynamic type of a disassociated pointer is the // same as its declared type. - auto boxTy = mlir::dyn_cast(box.getBoxTy()); + auto boxTy = box.getBoxTy().dyn_cast(); auto eleTy = fir::unwrapPassByRefType(boxTy.getEleTy()); mlir::Type derivedType = fir::getDerivedType(eleTy); - if (auto recTy = mlir::dyn_cast(derivedType)) { + if (auto recTy = derivedType.dyn_cast()) { fir::runtime::genNullifyDerivedType(builder, loc, box.getAddr(), recTy, box.rank()); return; @@ -691,7 +690,7 @@ getNewLengths(fir::FirOpBuilder &builder, mlir::Location loc, const fir::MutableBoxValue &box, mlir::ValueRange lenParams) { llvm::SmallVector lengths; auto idxTy = builder.getIndexType(); - if (auto charTy = mlir::dyn_cast(box.getEleTy())) { + if (auto charTy = box.getEleTy().dyn_cast()) { if (charTy.getLen() == fir::CharacterType::unknownLen()) { if (box.hasNonDeferredLenParams()) { lengths.emplace_back( @@ -718,7 +717,7 @@ static mlir::Value allocateAndInitNewStorage(fir::FirOpBuilder &builder, auto lengths = getNewLengths(builder, loc, box, lenParams); auto newStorage = builder.create( loc, box.getBaseTy(), allocName, lengths, extents); - if (mlir::isa(box.getEleTy())) { + if (box.getEleTy().isa()) { // TODO: skip runtime initialization if this is not required. Currently, // there is no way to know here if a derived type needs it or not. But the // information is available at compile time and could be reflected here @@ -743,7 +742,7 @@ void fir::factory::genInlinedAllocation( lengths, safeExtents); MutablePropertyWriter{builder, loc, box}.updateMutableBox( heap, lbounds, safeExtents, lengths); - if (mlir::isa(box.getEleTy())) { + if (box.getEleTy().isa()) { // TODO: skip runtime initialization if this is not required. Currently, // there is no way to know here if a derived type needs it or not. But the // information is available at compile time and could be reflected here diff --git a/flang/lib/Optimizer/Builder/PPCIntrinsicCall.cpp b/flang/lib/Optimizer/Builder/PPCIntrinsicCall.cpp index 7f09e88228446..160118e2c050a 100644 --- a/flang/lib/Optimizer/Builder/PPCIntrinsicCall.cpp +++ b/flang/lib/Optimizer/Builder/PPCIntrinsicCall.cpp @@ -1119,7 +1119,7 @@ PPCIntrinsicLibrary::genVecAbs(mlir::Type resultType, funcOp = builder.createFunction(loc, fname, ftype); auto callOp{builder.create(loc, funcOp, argBases[0])}; return callOp.getResult(0); - } else if (auto eleTy = mlir::dyn_cast(vTypeInfo.eleTy)) { + } else if (auto eleTy = vTypeInfo.eleTy.dyn_cast()) { // vec_abs(arg1) = max(0 - arg1, arg1) auto newVecTy{mlir::VectorType::get(vTypeInfo.len, eleTy)}; @@ -1173,13 +1173,12 @@ fir::ExtendedValue PPCIntrinsicLibrary::genVecAddAndMulSubXor( assert(args.size() == 2); auto argBases{getBasesForArgs(args)}; auto argsTy{getTypesForArgs(argBases)}; - assert(mlir::isa(argsTy[0]) && - mlir::isa(argsTy[1])); + assert(argsTy[0].isa() && argsTy[1].isa()); auto vecTyInfo{getVecTypeFromFir(argBases[0])}; - const auto isInteger{mlir::isa(vecTyInfo.eleTy)}; - const auto isFloat{mlir::isa(vecTyInfo.eleTy)}; + const auto isInteger{vecTyInfo.eleTy.isa()}; + const auto isFloat{vecTyInfo.eleTy.isa()}; assert((isInteger || isFloat) && "unknown vector type"); auto vargs{convertVecArgs(builder, loc, vecTyInfo, argBases)}; @@ -1213,7 +1212,7 @@ fir::ExtendedValue PPCIntrinsicLibrary::genVecAddAndMulSubXor( arg2 = vargs[1]; } else if (isFloat) { // bitcast the arguments to integer - auto wd{mlir::dyn_cast(vecTyInfo.eleTy).getWidth()}; + auto wd{vecTyInfo.eleTy.dyn_cast().getWidth()}; auto ftype{builder.getIntegerType(wd)}; auto bcVecTy{mlir::VectorType::get(vecTyInfo.len, ftype)}; arg1 = builder.create(loc, bcVecTy, vargs[0]); @@ -1451,7 +1450,7 @@ PPCIntrinsicLibrary::genVecCmp(mlir::Type resultType, mlir::Value res{nullptr}; - if (auto eTy = mlir::dyn_cast(vecTyInfo.eleTy)) { + if (auto eTy = vecTyInfo.eleTy.dyn_cast()) { constexpr int firstArg{0}; constexpr int secondArg{1}; std::map> argOrder{ @@ -1560,7 +1559,7 @@ PPCIntrinsicLibrary::genVecConvert(mlir::Type resultType, case VecOp::Ctf: { assert(args.size() == 2); auto convArg{builder.createConvert(loc, i32Ty, argBases[1])}; - auto eTy{mlir::dyn_cast(vecTyInfo.eleTy)}; + auto eTy{vecTyInfo.eleTy.dyn_cast()}; assert(eTy && "Unsupported vector type"); const auto isUnsigned{eTy.isUnsignedInteger()}; const auto width{eTy.getWidth()}; @@ -1588,9 +1587,10 @@ PPCIntrinsicLibrary::genVecConvert(mlir::Type resultType, : builder.create(loc, ty, vArg1)}; // construct vector<1./(1< - auto constInt{mlir::dyn_cast_or_null( + auto constInt{ mlir::dyn_cast(argBases[1].getDefiningOp()) - .getValue())}; + .getValue() + .dyn_cast_or_null()}; assert(constInt && "expected integer constant argument"); double f{1.0 / (1 << constInt.getInt())}; llvm::SmallVector vals{f, f}; @@ -1815,7 +1815,7 @@ static mlir::Value addOffsetToAddress(fir::FirOpBuilder &builder, static mlir::Value reverseVectorElements(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Value v, int64_t len) { - assert(mlir::isa(v.getType())); + assert(v.getType().isa()); assert(len > 0); llvm::SmallVector mask; for (int64_t i = 0; i < len; ++i) { @@ -2144,9 +2144,10 @@ PPCIntrinsicLibrary::genVecPerm(mlir::Type resultType, } case VecOp::Permi: { // arg3 is a constant - auto constIntOp{mlir::dyn_cast_or_null( + auto constIntOp{ mlir::dyn_cast(argBases[2].getDefiningOp()) - .getValue())}; + .getValue() + .dyn_cast_or_null()}; assert(constIntOp && "expected integer constant argument"); auto constInt{constIntOp.getInt()}; // arg1, arg2, and result type share same VecTypeInfo @@ -2320,9 +2321,10 @@ PPCIntrinsicLibrary::genVecShift(mlir::Type resultType, } } else if (vop == VecOp::Sld || vop == VecOp::Sldw) { assert(args.size() == 3); - auto constIntOp = mlir::dyn_cast_or_null( + auto constIntOp = mlir::dyn_cast(argBases[2].getDefiningOp()) - .getValue()); + .getValue() + .dyn_cast_or_null(); assert(constIntOp && "expected integer constant argument"); // Bitcast to vector<16xi8> @@ -2795,16 +2797,16 @@ void PPCIntrinsicLibrary::genMmaIntr(llvm::ArrayRef args) { auto vType{v.getType()}; mlir::Type targetType{intrFuncType.getInput(j)}; if (vType != targetType) { - if (mlir::isa(targetType)) { + if (targetType.isa()) { // Perform vector type conversion for arguments passed by value. - auto eleTy{mlir::dyn_cast(vType).getEleTy()}; - auto len{mlir::dyn_cast(vType).getLen()}; + auto eleTy{vType.dyn_cast().getEleTy()}; + auto len{vType.dyn_cast().getLen()}; mlir::VectorType mlirType = mlir::VectorType::get(len, eleTy); auto v0{builder.createConvert(loc, mlirType, v)}; auto v1{builder.create(loc, targetType, v0)}; intrArgs.push_back(v1); - } else if (mlir::isa(targetType) && - mlir::isa(vType)) { + } else if (targetType.isa() && + vType.isa()) { auto v0{builder.createConvert(loc, targetType, v)}; intrArgs.push_back(v0); } else { @@ -2859,7 +2861,7 @@ void PPCIntrinsicLibrary::genVecStore(llvm::ArrayRef args) { if (arg1TyInfo.isFloat32()) { stTy = mlir::VectorType::get(len, i32ty); fname = "llvm.ppc.altivec.stvewx"; - } else if (mlir::isa(arg1TyInfo.eleTy)) { + } else if (arg1TyInfo.eleTy.isa()) { stTy = mlir::VectorType::get(len, mlir::IntegerType::get(context, width)); switch (width) { diff --git a/flang/lib/Optimizer/Builder/Runtime/Allocatable.cpp b/flang/lib/Optimizer/Builder/Runtime/Allocatable.cpp index 70a88ff18cb1d..abff0e150ab4a 100644 --- a/flang/lib/Optimizer/Builder/Runtime/Allocatable.cpp +++ b/flang/lib/Optimizer/Builder/Runtime/Allocatable.cpp @@ -27,7 +27,7 @@ mlir::Value fir::runtime::genMoveAlloc(fir::FirOpBuilder &builder, if (fir::isPolymorphicType(from.getType()) && !fir::isUnlimitedPolymorphicType(from.getType())) { fir::ClassType clTy = - mlir::dyn_cast(fir::dyn_cast_ptrEleTy(from.getType())); + fir::dyn_cast_ptrEleTy(from.getType()).dyn_cast(); mlir::Type derivedType = fir::unwrapInnerType(clTy.getEleTy()); declaredTypeDesc = builder.create(loc, mlir::TypeAttr::get(derivedType)); diff --git a/flang/lib/Optimizer/Builder/Runtime/Character.cpp b/flang/lib/Optimizer/Builder/Runtime/Character.cpp index b16819915d5ab..f3663439fdd59 100644 --- a/flang/lib/Optimizer/Builder/Runtime/Character.cpp +++ b/flang/lib/Optimizer/Builder/Runtime/Character.cpp @@ -39,15 +39,15 @@ static void genCharacterSearch(FN func, fir::FirOpBuilder &builder, /// Helper function to recover the KIND from the FIR type. static int discoverKind(mlir::Type ty) { - if (auto charTy = mlir::dyn_cast(ty)) + if (auto charTy = ty.dyn_cast()) return charTy.getFKind(); if (auto eleTy = fir::dyn_cast_ptrEleTy(ty)) return discoverKind(eleTy); - if (auto arrTy = mlir::dyn_cast(ty)) + if (auto arrTy = ty.dyn_cast()) return discoverKind(arrTy.getEleTy()); - if (auto boxTy = mlir::dyn_cast(ty)) + if (auto boxTy = ty.dyn_cast()) return discoverKind(boxTy.getEleTy()); - if (auto boxTy = mlir::dyn_cast(ty)) + if (auto boxTy = ty.dyn_cast()) return discoverKind(boxTy.getEleTy()); llvm_unreachable("unexpected character type"); } diff --git a/flang/lib/Optimizer/Builder/Runtime/Intrinsics.cpp b/flang/lib/Optimizer/Builder/Runtime/Intrinsics.cpp index 8b78a1688c731..57c47da0f3f85 100644 --- a/flang/lib/Optimizer/Builder/Runtime/Intrinsics.cpp +++ b/flang/lib/Optimizer/Builder/Runtime/Intrinsics.cpp @@ -228,8 +228,7 @@ void fir::runtime::genSystemClock(fir::FirOpBuilder &builder, fir::IfOp ifOp{}; const bool isOptionalArg = fir::valueHasFirAttribute(arg, fir::getOptionalAttrName()); - if (mlir::dyn_cast(type) || - mlir::dyn_cast(type)) { + if (type.dyn_cast() || type.dyn_cast()) { // Check for a disassociated pointer or an unallocated allocatable. assert(!isOptionalArg && "invalid optional argument"); ifOp = builder.create(loc, builder.genIsNotNullAddr(loc, arg), @@ -243,8 +242,7 @@ void fir::runtime::genSystemClock(fir::FirOpBuilder &builder, builder.setInsertionPointToStart(&ifOp.getThenRegion().front()); mlir::Type kindTy = func.getFunctionType().getInput(0); int integerKind = 8; - if (auto intType = - mlir::dyn_cast(fir::unwrapRefType(type))) + if (auto intType = fir::unwrapRefType(type).dyn_cast()) integerKind = intType.getWidth() / 8; mlir::Value kind = builder.createIntegerConstant(loc, kindTy, integerKind); mlir::Value res = diff --git a/flang/lib/Optimizer/Builder/Runtime/Ragged.cpp b/flang/lib/Optimizer/Builder/Runtime/Ragged.cpp index e5d0fb0fb27a9..4d33282a35d9d 100644 --- a/flang/lib/Optimizer/Builder/Runtime/Ragged.cpp +++ b/flang/lib/Optimizer/Builder/Runtime/Ragged.cpp @@ -32,8 +32,7 @@ void fir::runtime::genRaggedArrayAllocate(mlir::Location loc, // Position of the bufferPointer in the header struct. auto one = builder.createIntegerConstant(loc, i32Ty, 1); auto eleTy = fir::unwrapSequenceType(fir::unwrapRefType(header.getType())); - auto ptrTy = - builder.getRefType(mlir::cast(eleTy).getType(1)); + auto ptrTy = builder.getRefType(eleTy.cast().getType(1)); auto ptr = builder.create(loc, ptrTy, header, one); auto heap = builder.create(loc, ptr); auto cmp = builder.genIsNullAddr(loc, heap); diff --git a/flang/lib/Optimizer/Builder/Runtime/Reduction.cpp b/flang/lib/Optimizer/Builder/Runtime/Reduction.cpp index d4076067bf103..66fbaddcbda1a 100644 --- a/flang/lib/Optimizer/Builder/Runtime/Reduction.cpp +++ b/flang/lib/Optimizer/Builder/Runtime/Reduction.cpp @@ -666,7 +666,7 @@ void fir::runtime::genMaxloc(fir::FirOpBuilder &builder, mlir::Location loc, mlir::func::FuncOp func; auto ty = arrayBox.getType(); auto arrTy = fir::dyn_cast_ptrOrBoxEleTy(ty); - auto eleTy = mlir::cast(arrTy).getEleTy(); + auto eleTy = arrTy.cast().getEleTy(); fir::factory::CharacterExprHelper charHelper{builder, loc}; if (eleTy.isF32()) func = fir::runtime::getRuntimeFunc(loc, builder); @@ -713,7 +713,7 @@ mlir::Value fir::runtime::genMaxval(fir::FirOpBuilder &builder, mlir::func::FuncOp func; auto ty = arrayBox.getType(); auto arrTy = fir::dyn_cast_ptrOrBoxEleTy(ty); - auto eleTy = mlir::cast(arrTy).getEleTy(); + auto eleTy = arrTy.cast().getEleTy(); auto dim = builder.createIntegerConstant(loc, builder.getIndexType(), 0); if (eleTy.isF32()) @@ -781,7 +781,7 @@ void fir::runtime::genMinloc(fir::FirOpBuilder &builder, mlir::Location loc, mlir::func::FuncOp func; auto ty = arrayBox.getType(); auto arrTy = fir::dyn_cast_ptrOrBoxEleTy(ty); - auto eleTy = mlir::cast(arrTy).getEleTy(); + auto eleTy = arrTy.cast().getEleTy(); fir::factory::CharacterExprHelper charHelper{builder, loc}; if (eleTy.isF32()) func = fir::runtime::getRuntimeFunc(loc, builder); @@ -853,7 +853,7 @@ mlir::Value fir::runtime::genMinval(fir::FirOpBuilder &builder, mlir::func::FuncOp func; auto ty = arrayBox.getType(); auto arrTy = fir::dyn_cast_ptrOrBoxEleTy(ty); - auto eleTy = mlir::cast(arrTy).getEleTy(); + auto eleTy = arrTy.cast().getEleTy(); auto dim = builder.createIntegerConstant(loc, builder.getIndexType(), 0); if (eleTy.isF32()) @@ -895,7 +895,7 @@ void fir::runtime::genNorm2Dim(fir::FirOpBuilder &builder, mlir::Location loc, mlir::func::FuncOp func; auto ty = arrayBox.getType(); auto arrTy = fir::dyn_cast_ptrOrBoxEleTy(ty); - auto eleTy = mlir::cast(arrTy).getEleTy(); + auto eleTy = arrTy.cast().getEleTy(); if (eleTy.isF128()) func = fir::runtime::getRuntimeFunc(loc, builder); else @@ -917,7 +917,7 @@ mlir::Value fir::runtime::genNorm2(fir::FirOpBuilder &builder, mlir::func::FuncOp func; auto ty = arrayBox.getType(); auto arrTy = fir::dyn_cast_ptrOrBoxEleTy(ty); - auto eleTy = mlir::cast(arrTy).getEleTy(); + auto eleTy = arrTy.cast().getEleTy(); auto dim = builder.createIntegerConstant(loc, builder.getIndexType(), 0); if (eleTy.isF32()) @@ -968,7 +968,7 @@ mlir::Value fir::runtime::genProduct(fir::FirOpBuilder &builder, mlir::func::FuncOp func; auto ty = arrayBox.getType(); auto arrTy = fir::dyn_cast_ptrOrBoxEleTy(ty); - auto eleTy = mlir::cast(arrTy).getEleTy(); + auto eleTy = arrTy.cast().getEleTy(); auto dim = builder.createIntegerConstant(loc, builder.getIndexType(), 0); if (eleTy.isF32()) @@ -1069,7 +1069,7 @@ mlir::Value fir::runtime::genDotProduct(fir::FirOpBuilder &builder, else if (eleTy.isInteger(builder.getKindMap().getIntegerBitsize(16))) func = fir::runtime::getRuntimeFunc(loc, builder); - else if (mlir::isa(eleTy)) + else if (eleTy.isa()) func = fir::runtime::getRuntimeFunc(loc, builder); else @@ -1111,7 +1111,7 @@ mlir::Value fir::runtime::genSum(fir::FirOpBuilder &builder, mlir::Location loc, mlir::func::FuncOp func; auto ty = arrayBox.getType(); auto arrTy = fir::dyn_cast_ptrOrBoxEleTy(ty); - auto eleTy = mlir::cast(arrTy).getEleTy(); + auto eleTy = arrTy.cast().getEleTy(); auto dim = builder.createIntegerConstant(loc, builder.getIndexType(), 0); if (eleTy.isF32()) @@ -1173,7 +1173,7 @@ mlir::Value fir::runtime::genSum(fir::FirOpBuilder &builder, mlir::Location loc, mlir::func::FuncOp func; \ auto ty = arrayBox.getType(); \ auto arrTy = fir::dyn_cast_ptrOrBoxEleTy(ty); \ - auto eleTy = mlir::cast(arrTy).getEleTy(); \ + auto eleTy = arrTy.cast().getEleTy(); \ auto dim = builder.createIntegerConstant(loc, builder.getIndexType(), 0); \ \ if (eleTy.isInteger(builder.getKindMap().getIntegerBitsize(1))) \ diff --git a/flang/lib/Optimizer/CodeGen/BoxedProcedure.cpp b/flang/lib/Optimizer/CodeGen/BoxedProcedure.cpp index 5229d40f2250d..48173033ecbe2 100644 --- a/flang/lib/Optimizer/CodeGen/BoxedProcedure.cpp +++ b/flang/lib/Optimizer/CodeGen/BoxedProcedure.cpp @@ -51,9 +51,9 @@ class BoxprocTypeRewriter : public mlir::TypeConverter { /// not at all depending on the implementation target's characteristics and /// preference. bool needsConversion(mlir::Type ty) { - if (mlir::isa(ty)) + if (ty.isa()) return true; - if (auto funcTy = mlir::dyn_cast(ty)) { + if (auto funcTy = ty.dyn_cast()) { for (auto t : funcTy.getInputs()) if (needsConversion(t)) return true; @@ -62,13 +62,13 @@ class BoxprocTypeRewriter : public mlir::TypeConverter { return true; return false; } - if (auto tupleTy = mlir::dyn_cast(ty)) { + if (auto tupleTy = ty.dyn_cast()) { for (auto t : tupleTy.getTypes()) if (needsConversion(t)) return true; return false; } - if (auto recTy = mlir::dyn_cast(ty)) { + if (auto recTy = ty.dyn_cast()) { auto visited = visitedTypes.find(ty); if (visited != visitedTypes.end()) return visited->second; @@ -97,11 +97,11 @@ class BoxprocTypeRewriter : public mlir::TypeConverter { visitedTypes.find(ty)->second = result; return result; } - if (auto boxTy = mlir::dyn_cast(ty)) + if (auto boxTy = ty.dyn_cast()) return needsConversion(boxTy.getEleTy()); if (isa_ref_type(ty)) return needsConversion(unwrapRefType(ty)); - if (auto t = mlir::dyn_cast(ty)) + if (auto t = ty.dyn_cast()) return needsConversion(unwrapSequenceType(ty)); return false; } @@ -246,7 +246,7 @@ class BoxedProcedurePass if (typeConverter.needsConversion(ty)) { rewriter.startOpModification(func); auto toTy = - mlir::cast(typeConverter.convertType(ty)); + typeConverter.convertType(ty).cast(); if (!func.empty()) for (auto e : llvm::enumerate(toTy.getInputs())) { unsigned i = e.index(); @@ -263,7 +263,7 @@ class BoxedProcedurePass // Rewrite all `fir.emboxproc` ops to either `fir.convert` or a thunk // as required. mlir::Type toTy = typeConverter.convertType( - mlir::cast(embox.getType()).getEleTy()); + embox.getType().cast().getEleTy()); rewriter.setInsertionPoint(embox); if (embox.getHost()) { // Create the thunk. diff --git a/flang/lib/Optimizer/CodeGen/CGOps.cpp b/flang/lib/Optimizer/CodeGen/CGOps.cpp index 44d07d26dd2b6..c3bcdeaf86db5 100644 --- a/flang/lib/Optimizer/CodeGen/CGOps.cpp +++ b/flang/lib/Optimizer/CodeGen/CGOps.cpp @@ -41,24 +41,24 @@ unsigned fir::cg::XEmboxOp::getOutRank() { } unsigned fir::cg::XReboxOp::getOutRank() { - if (auto seqTy = mlir::dyn_cast( - fir::dyn_cast_ptrOrBoxEleTy(getType()))) + if (auto seqTy = + fir::dyn_cast_ptrOrBoxEleTy(getType()).dyn_cast()) return seqTy.getDimension(); return 0; } unsigned fir::cg::XReboxOp::getRank() { - if (auto seqTy = mlir::dyn_cast( - fir::dyn_cast_ptrOrBoxEleTy(getBox().getType()))) + if (auto seqTy = fir::dyn_cast_ptrOrBoxEleTy(getBox().getType()) + .dyn_cast()) return seqTy.getDimension(); return 0; } unsigned fir::cg::XArrayCoorOp::getRank() { auto memrefTy = getMemref().getType(); - if (mlir::isa(memrefTy)) - if (auto seqty = mlir::dyn_cast( - fir::dyn_cast_ptrOrBoxEleTy(memrefTy))) + if (memrefTy.isa()) + if (auto seqty = + fir::dyn_cast_ptrOrBoxEleTy(memrefTy).dyn_cast()) return seqty.getDimension(); return getShape().size(); } diff --git a/flang/lib/Optimizer/CodeGen/CodeGen.cpp b/flang/lib/Optimizer/CodeGen/CodeGen.cpp index 19628ac71b0b2..921eac2f8f4b6 100644 --- a/flang/lib/Optimizer/CodeGen/CodeGen.cpp +++ b/flang/lib/Optimizer/CodeGen/CodeGen.cpp @@ -101,7 +101,7 @@ static int64_t getConstantIntValue(mlir::Value val) { } static unsigned getTypeDescFieldId(mlir::Type ty) { - auto isArray = mlir::isa(fir::dyn_cast_ptrOrBoxEleTy(ty)); + auto isArray = fir::dyn_cast_ptrOrBoxEleTy(ty).isa(); return isArray ? kOptTypePtrPosInBox : kDimsPosInBox; } static unsigned getLenParamFieldId(mlir::Type ty) { @@ -147,7 +147,7 @@ genAllocationScaleSize(OP op, mlir::Type ity, mlir::ConversionPatternRewriter &rewriter) { mlir::Location loc = op.getLoc(); mlir::Type dataTy = op.getInType(); - auto seqTy = mlir::dyn_cast(dataTy); + auto seqTy = dataTy.dyn_cast(); fir::SequenceType::Extent constSize = 1; if (seqTy) { int constRows = seqTy.getConstantRows(); @@ -191,13 +191,13 @@ struct AllocaOpConversion : public fir::FIROpConversion { for (; i < end; ++i) lenParams.push_back(operands[i]); mlir::Type scalarType = fir::unwrapSequenceType(alloc.getInType()); - if (auto chrTy = mlir::dyn_cast(scalarType)) { + if (auto chrTy = scalarType.dyn_cast()) { fir::CharacterType rawCharTy = fir::CharacterType::getUnknownLen( chrTy.getContext(), chrTy.getFKind()); llvmObjectType = convertType(rawCharTy); assert(end == 1); size = integerCast(loc, rewriter, ity, lenParams[0]); - } else if (auto recTy = mlir::dyn_cast(scalarType)) { + } else if (auto recTy = scalarType.dyn_cast()) { mlir::LLVM::LLVMFuncOp memSizeFn = getDependentTypeMemSizeFn(recTy, alloc, rewriter); if (!memSizeFn) @@ -265,8 +265,7 @@ struct BoxAddrOpConversion : public fir::FIROpConversion { mlir::ConversionPatternRewriter &rewriter) const override { mlir::Value a = adaptor.getOperands()[0]; auto loc = boxaddr.getLoc(); - if (auto argty = - mlir::dyn_cast(boxaddr.getVal().getType())) { + if (auto argty = boxaddr.getVal().getType().dyn_cast()) { TypePair boxTyPair = getBoxTypePair(argty); rewriter.replaceOp(boxaddr, getBaseAddrFromBox(loc, boxTyPair, a, rewriter)); @@ -477,25 +476,24 @@ struct StringLitOpConversion : public fir::FIROpConversion { mlir::ConversionPatternRewriter &rewriter) const override { auto ty = convertType(constop.getType()); auto attr = constop.getValue(); - if (mlir::isa(attr)) { + if (attr.isa()) { rewriter.replaceOpWithNewOp(constop, ty, attr); return mlir::success(); } - auto charTy = mlir::cast(constop.getType()); + auto charTy = constop.getType().cast(); unsigned bits = lowerTy().characterBitsize(charTy); mlir::Type intTy = rewriter.getIntegerType(bits); mlir::Location loc = constop.getLoc(); mlir::Value cst = rewriter.create(loc, ty); - if (auto arr = mlir::dyn_cast(attr)) { + if (auto arr = attr.dyn_cast()) { cst = rewriter.create(loc, ty, arr); - } else if (auto arr = mlir::dyn_cast(attr)) { + } else if (auto arr = attr.dyn_cast()) { for (auto a : llvm::enumerate(arr.getValue())) { // convert each character to a precise bitsize auto elemAttr = mlir::IntegerAttr::get( intTy, - mlir::cast(a.value()).getValue().zextOrTrunc( - bits)); + a.value().cast().getValue().zextOrTrunc(bits)); auto elemCst = rewriter.create(loc, intTy, elemAttr); cst = rewriter.create(loc, cst, elemCst, @@ -530,9 +528,9 @@ struct CallOpConversion : public fir::FIROpConversion { } // namespace static mlir::Type getComplexEleTy(mlir::Type complex) { - if (auto cc = mlir::dyn_cast(complex)) + if (auto cc = complex.dyn_cast()) return cc.getElementType(); - return mlir::cast(complex).getElementType(); + return complex.cast().getElementType(); } namespace { @@ -601,7 +599,7 @@ struct ConstcOpConversion : public fir::FIROpConversion { } inline llvm::APFloat getValue(mlir::Attribute attr) const { - return mlir::cast(attr).getValue(); + return attr.cast().getValue(); } }; @@ -610,7 +608,7 @@ struct ConvertOpConversion : public fir::FIROpConversion { using FIROpConversion::FIROpConversion; static bool isFloatingPointTy(mlir::Type ty) { - return mlir::isa(ty); + return ty.isa(); } mlir::LogicalResult @@ -630,8 +628,7 @@ struct ConvertOpConversion : public fir::FIROpConversion { auto loc = convert.getLoc(); auto i1Type = mlir::IntegerType::get(convert.getContext(), 1); - if (mlir::isa(fromFirTy) || - mlir::isa(toFirTy)) { + if (fromFirTy.isa() || toFirTy.isa()) { // By specification fir::LogicalType value may be any number, // where non-zero value represents .true. and zero value represents // .false. @@ -644,8 +641,7 @@ struct ConvertOpConversion : public fir::FIROpConversion { // Conversion from narrow logical to wide logical may be implemented // as a zero or sign extension of the input, but it may use value // normalization as well. - if (!mlir::isa(fromTy) || - !mlir::isa(toTy)) + if (!fromTy.isa() || !toTy.isa()) return mlir::emitError(loc) << "unsupported types for logical conversion: " << fromTy << " -> " << toTy; @@ -726,13 +722,13 @@ struct ConvertOpConversion : public fir::FIROpConversion { rewriter.replaceOp(convert, v); return mlir::success(); } - if (mlir::isa(toTy)) { + if (toTy.isa()) { rewriter.replaceOpWithNewOp(convert, toTy, op0); return mlir::success(); } - } else if (mlir::isa(fromTy)) { + } else if (fromTy.isa()) { // Integer to integer conversion. - if (mlir::isa(toTy)) { + if (toTy.isa()) { auto fromBits = mlir::LLVM::getPrimitiveTypeSizeInBits(fromTy); auto toBits = mlir::LLVM::getPrimitiveTypeSizeInBits(toTy); assert(fromBits != toBits); @@ -753,18 +749,18 @@ struct ConvertOpConversion : public fir::FIROpConversion { return mlir::success(); } // Integer to pointer conversion. - if (mlir::isa(toTy)) { + if (toTy.isa()) { rewriter.replaceOpWithNewOp(convert, toTy, op0); return mlir::success(); } - } else if (mlir::isa(fromTy)) { + } else if (fromTy.isa()) { // Pointer to integer conversion. - if (mlir::isa(toTy)) { + if (toTy.isa()) { rewriter.replaceOpWithNewOp(convert, toTy, op0); return mlir::success(); } // Pointer to pointer conversion. - if (mlir::isa(toTy)) { + if (toTy.isa()) { rewriter.replaceOpWithNewOp(convert, toTy, op0); return mlir::success(); } @@ -846,11 +842,11 @@ struct EmboxCharOpConversion : public fir::FIROpConversion { auto llvmStruct = rewriter.create(loc, llvmStructTy); mlir::Type lenTy = - mlir::cast(llvmStructTy).getBody()[1]; + llvmStructTy.cast().getBody()[1]; mlir::Value lenAfterCast = integerCast(loc, rewriter, lenTy, charBufferLen); mlir::Type addrTy = - mlir::cast(llvmStructTy).getBody()[0]; + llvmStructTy.cast().getBody()[0]; if (addrTy != charBuffer.getType()) charBuffer = rewriter.create(loc, addrTy, charBuffer); @@ -983,10 +979,9 @@ static mlir::SymbolRefAttr getFree(fir::FreeMemOp op, static unsigned getDimension(mlir::LLVM::LLVMArrayType ty) { unsigned result = 1; - for (auto eleTy = - mlir::dyn_cast(ty.getElementType()); - eleTy; eleTy = mlir::dyn_cast( - eleTy.getElementType())) + for (auto eleTy = ty.getElementType().dyn_cast(); + eleTy; + eleTy = eleTy.getElementType().dyn_cast()) ++result; return result; } @@ -1057,9 +1052,9 @@ struct EmboxCommonConversion : public fir::FIROpConversion { static int getCFIAttr(fir::BaseBoxType boxTy) { auto eleTy = boxTy.getEleTy(); - if (mlir::isa(eleTy)) + if (eleTy.isa()) return CFI_attribute_pointer; - if (mlir::isa(eleTy)) + if (eleTy.isa()) return CFI_attribute_allocatable; return CFI_attribute_other; } @@ -1087,29 +1082,27 @@ struct EmboxCommonConversion : public fir::FIROpConversion { auto i64Ty = mlir::IntegerType::get(rewriter.getContext(), 64); if (auto eleTy = fir::dyn_cast_ptrEleTy(boxEleTy)) boxEleTy = eleTy; - if (auto seqTy = mlir::dyn_cast(boxEleTy)) + if (auto seqTy = boxEleTy.dyn_cast()) return getSizeAndTypeCode(loc, rewriter, seqTy.getEleTy(), lenParams); - if (mlir::isa( - boxEleTy)) // unlimited polymorphic or assumed type + if (boxEleTy.isa()) // unlimited polymorphic or assumed type return {rewriter.create(loc, i64Ty, 0), this->genConstantOffset(loc, rewriter, CFI_type_other)}; mlir::Value typeCodeVal = this->genConstantOffset( loc, rewriter, fir::getTypeCode(boxEleTy, this->lowerTy().getKindMap())); - if (fir::isa_integer(boxEleTy) || - mlir::dyn_cast(boxEleTy) || fir::isa_real(boxEleTy) || - fir::isa_complex(boxEleTy)) + if (fir::isa_integer(boxEleTy) || boxEleTy.dyn_cast() || + fir::isa_real(boxEleTy) || fir::isa_complex(boxEleTy)) return {genTypeStrideInBytes(loc, i64Ty, rewriter, this->convertType(boxEleTy)), typeCodeVal}; - if (auto charTy = mlir::dyn_cast(boxEleTy)) + if (auto charTy = boxEleTy.dyn_cast()) return {getCharacterByteSize(loc, rewriter, charTy, lenParams), typeCodeVal}; if (fir::isa_ref_type(boxEleTy)) { auto ptrTy = ::getLlvmPtrType(rewriter.getContext()); return {genTypeStrideInBytes(loc, i64Ty, rewriter, ptrTy), typeCodeVal}; } - if (mlir::isa(boxEleTy)) + if (boxEleTy.isa()) return {genTypeStrideInBytes(loc, i64Ty, rewriter, this->convertType(boxEleTy)), typeCodeVal}; @@ -1218,8 +1211,8 @@ struct EmboxCommonConversion : public fir::FIROpConversion { if (!typeDesc) { if (useInputType) { mlir::Type innerType = fir::unwrapInnerType(inputType); - if (innerType && mlir::isa(innerType)) { - auto recTy = mlir::dyn_cast(innerType); + if (innerType && innerType.template isa()) { + auto recTy = innerType.template dyn_cast(); typeDesc = getTypeDescriptor(mod, rewriter, loc, recTy); } else { // Unlimited polymorphic type descriptor with no record type. Set @@ -1257,7 +1250,7 @@ struct EmboxCommonConversion : public fir::FIROpConversion { mlir::ValueRange lenParams, mlir::Value sourceBox = {}, mlir::Type sourceBoxType = {}) const { auto loc = box.getLoc(); - auto boxTy = mlir::dyn_cast(box.getType()); + auto boxTy = box.getType().template dyn_cast(); bool useInputType = fir::isPolymorphicType(boxTy) && !fir::isUnlimitedPolymorphicType(inputType); llvm::SmallVector typeparams = lenParams; @@ -1300,8 +1293,8 @@ struct EmboxCommonConversion : public fir::FIROpConversion { mlir::ValueRange lenParams, mlir::Value typeDesc = {}) const { auto loc = box.getLoc(); - auto boxTy = mlir::dyn_cast(box.getType()); - auto inputBoxTy = mlir::dyn_cast(box.getBox().getType()); + auto boxTy = box.getType().dyn_cast(); + auto inputBoxTy = box.getBox().getType().dyn_cast(); auto inputBoxTyPair = this->getBoxTypePair(inputBoxTy); llvm::SmallVector typeparams = lenParams; if (!box.getSubstr().empty() && fir::hasDynamicSize(boxTy.getEleTy())) @@ -1350,7 +1343,7 @@ struct EmboxCommonConversion : public fir::FIROpConversion { mlir::Type resultTy = llvmBaseObjectType; // Fortran is column major, llvm GEP is row major: reverse the indices here. for (mlir::Value interiorIndex : llvm::reverse(cstInteriorIndices)) { - auto arrayTy = mlir::dyn_cast(resultTy); + auto arrayTy = resultTy.dyn_cast(); if (!arrayTy) fir::emitFatalError( loc, @@ -1362,7 +1355,7 @@ struct EmboxCommonConversion : public fir::FIROpConversion { convertSubcomponentIndices(loc, resultTy, componentIndices, &resultTy); gepArgs.append(gepIndices.begin(), gepIndices.end()); if (substringOffset) { - if (auto arrayTy = mlir::dyn_cast(resultTy)) { + if (auto arrayTy = resultTy.dyn_cast()) { gepArgs.push_back(*substringOffset); resultTy = arrayTy.getElementType(); } else { @@ -1511,18 +1504,18 @@ struct XEmboxOpConversion : public EmboxCommonConversion { unsigned constRows = 0; mlir::Value ptrOffset = zero; mlir::Type memEleTy = fir::dyn_cast_ptrEleTy(xbox.getMemref().getType()); - assert(mlir::isa(memEleTy)); - auto seqTy = mlir::cast(memEleTy); + assert(memEleTy.isa()); + auto seqTy = memEleTy.cast(); mlir::Type seqEleTy = seqTy.getEleTy(); // Adjust the element scaling factor if the element is a dependent type. if (fir::hasDynamicSize(seqEleTy)) { - if (auto charTy = mlir::dyn_cast(seqEleTy)) { + if (auto charTy = seqEleTy.dyn_cast()) { // The GEP pointer type decays to llvm.ptr. // The scaling factor is the runtime value of the length. assert(!adaptor.getLenParams().empty()); prevPtrOff = FIROpConversion::integerCast( loc, rewriter, i64Ty, adaptor.getLenParams().back()); - } else if (mlir::isa(seqEleTy)) { + } else if (seqEleTy.isa()) { // prevPtrOff = ; TODO(loc, "generate call to calculate size of PDT"); } else { @@ -1547,7 +1540,7 @@ struct XEmboxOpConversion : public EmboxCommonConversion { } else if (hasSubstr) { // We have a substring. The step value needs to be the number of bytes // per CHARACTER element. - auto charTy = mlir::cast(seqEleTy); + auto charTy = seqEleTy.cast(); if (fir::hasDynamicSize(charTy)) { prevDimByteStride = getCharacterByteSize(loc, rewriter, charTy, adaptor.getLenParams()); @@ -1596,7 +1589,7 @@ struct XEmboxOpConversion : public EmboxCommonConversion { // Lower bound is normalized to 0 for BIND(C) interoperability. mlir::Value lb = zero; const bool isaPointerOrAllocatable = - mlir::isa(eleTy); + eleTy.isa() || eleTy.isa(); // Lower bound is defaults to 1 for POINTER, ALLOCATABLE, and // denormalized descriptors. if (isaPointerOrAllocatable || !normalizedLowerBound(xbox)) @@ -1702,7 +1695,7 @@ struct XReboxOpConversion : public EmboxCommonConversion { // Create new descriptor and fill its non-shape related data. llvm::SmallVector lenParams; mlir::Type inputEleTy = getInputEleTy(rebox); - if (auto charTy = mlir::dyn_cast(inputEleTy)) { + if (auto charTy = inputEleTy.dyn_cast()) { if (charTy.hasConstantLen()) { mlir::Value len = genConstantIndex(loc, idxTy, rewriter, charTy.getLen()); @@ -1719,15 +1712,15 @@ struct XReboxOpConversion : public EmboxCommonConversion { } lenParams.emplace_back(len); } - } else if (auto recTy = mlir::dyn_cast(inputEleTy)) { + } else if (auto recTy = inputEleTy.dyn_cast()) { if (recTy.getNumLenParams() != 0) TODO(loc, "reboxing descriptor of derived type with length parameters"); } // Rebox on polymorphic entities needs to carry over the dynamic type. mlir::Value typeDescAddr; - if (mlir::isa(inputBoxTyPair.fir) && - mlir::isa(rebox.getType())) + if (inputBoxTyPair.fir.isa() && + rebox.getType().isa()) typeDescAddr = loadTypeDescAddress(loc, inputBoxTyPair, loweredBox, rewriter); @@ -1915,7 +1908,7 @@ struct XReboxOpConversion : public EmboxCommonConversion { /// Return scalar element type of the input box. static mlir::Type getInputEleTy(fir::cg::XReboxOp rebox) { auto ty = fir::dyn_cast_ptrOrBoxEleTy(rebox.getBox().getType()); - if (auto seqTy = mlir::dyn_cast(ty)) + if (auto seqTy = ty.dyn_cast()) return seqTy.getEleTy(); return ty; } @@ -1943,7 +1936,7 @@ struct ValueOpCommon { assert(ty && "type is null"); const auto end = indices.size(); for (std::remove_const_t i = 0; i < end; ++i) { - if (auto seq = mlir::dyn_cast(ty)) { + if (auto seq = ty.dyn_cast()) { const auto dim = getDimension(seq); if (dim > 1) { auto ub = std::min(i + dim, end); @@ -1951,7 +1944,7 @@ struct ValueOpCommon { i += dim - 1; } ty = getArrayElementType(seq); - } else if (auto st = mlir::dyn_cast(ty)) { + } else if (auto st = ty.dyn_cast()) { ty = st.getBody()[indices[i]]; } else { llvm_unreachable("index into invalid type"); @@ -1970,7 +1963,7 @@ struct ValueOpCommon { auto fieldName = i->cast().getValue(); ++i; auto ty = i->cast().getValue(); - auto index = mlir::cast(ty).getFieldIndex(fieldName); + auto index = ty.cast().getFieldIndex(fieldName); indices.push_back(index); } } @@ -1980,7 +1973,7 @@ struct ValueOpCommon { private: static mlir::Type getArrayElementType(mlir::LLVM::LLVMArrayType ty) { auto eleTy = ty.getElementType(); - while (auto arrTy = mlir::dyn_cast(eleTy)) + while (auto arrTy = eleTy.dyn_cast()) eleTy = arrTy.getElementType(); return eleTy; } @@ -2048,7 +2041,7 @@ struct InsertOnRangeOpConversion auto type = adaptor.getOperands()[0].getType(); // Iteratively extract the array dimensions from the type. - while (auto t = mlir::dyn_cast(type)) { + while (auto t = type.dyn_cast()) { dims.push_back(t.getNumElements()); type = t.getElementType(); } @@ -2114,8 +2107,7 @@ struct XArrayCoorOpConversion mlir::Value offset = genConstantIndex(loc, idxTy, rewriter, 0); const bool isShifted = !coor.getShift().empty(); const bool isSliced = !coor.getSlice().empty(); - const bool baseIsBoxed = - mlir::isa(coor.getMemref().getType()); + const bool baseIsBoxed = coor.getMemref().getType().isa(); TypePair baseBoxTyPair = baseIsBoxed ? getBoxTypePair(coor.getMemref().getType()) : TypePair{}; mlir::LLVM::IntegerOverflowFlags nsw = @@ -2193,8 +2185,7 @@ struct XArrayCoorOpConversion // components. mlir::Type elementType = getLlvmObjectTypeFromBoxType(coor.getMemref().getType()); - while (auto arrayTy = - mlir::dyn_cast(elementType)) + while (auto arrayTy = elementType.dyn_cast()) elementType = arrayTy.getElementType(); args.clear(); args.push_back(0); @@ -2284,12 +2275,11 @@ struct CoordinateOpConversion } // Boxed type - get the base pointer from the box - if (mlir::dyn_cast(baseObjectTy)) + if (baseObjectTy.dyn_cast()) return doRewriteBox(coor, operands, loc, rewriter); // Reference, pointer or a heap type - if (mlir::isa( - baseObjectTy)) + if (baseObjectTy.isa()) return doRewriteRefOrPtr(coor, llvmObjectTy, operands, loc, rewriter); return rewriter.notifyMatchFailure( @@ -2305,7 +2295,7 @@ struct CoordinateOpConversion } static bool hasSubDimensions(mlir::Type type) { - return mlir::isa(type); + return type.isa(); } /// Check whether this form of `!fir.coordinate_of` is supported. These @@ -2320,14 +2310,14 @@ struct CoordinateOpConversion bool ptrEle = false; for (; i < numOfCoors; ++i) { mlir::Value nxtOpnd = coors[i]; - if (auto arrTy = mlir::dyn_cast(type)) { + if (auto arrTy = type.dyn_cast()) { subEle = true; i += arrTy.getDimension() - 1; type = arrTy.getEleTy(); - } else if (auto recTy = mlir::dyn_cast(type)) { + } else if (auto recTy = type.dyn_cast()) { subEle = true; type = recTy.getType(getFieldNumber(recTy, nxtOpnd)); - } else if (auto tupTy = mlir::dyn_cast(type)) { + } else if (auto tupTy = type.dyn_cast()) { subEle = true; type = tupTy.getType(getConstantIntValue(nxtOpnd)); } else { @@ -2345,14 +2335,14 @@ struct CoordinateOpConversion static bool arraysHaveKnownShape(mlir::Type type, mlir::ValueRange coors) { for (std::size_t i = 0, sz = coors.size(); i < sz; ++i) { mlir::Value nxtOpnd = coors[i]; - if (auto arrTy = mlir::dyn_cast(type)) { + if (auto arrTy = type.dyn_cast()) { if (fir::sequenceWithNonConstantShape(arrTy)) return false; i += arrTy.getDimension() - 1; type = arrTy.getEleTy(); - } else if (auto strTy = mlir::dyn_cast(type)) { + } else if (auto strTy = type.dyn_cast()) { type = strTy.getType(getFieldNumber(strTy, nxtOpnd)); - } else if (auto strTy = mlir::dyn_cast(type)) { + } else if (auto strTy = type.dyn_cast()) { type = strTy.getType(getConstantIntValue(nxtOpnd)); } else { return true; @@ -2367,8 +2357,7 @@ struct CoordinateOpConversion mlir::Location loc, mlir::ConversionPatternRewriter &rewriter) const { mlir::Type boxObjTy = coor.getBaseType(); - assert(mlir::dyn_cast(boxObjTy) && - "This is not a `fir.box`"); + assert(boxObjTy.dyn_cast() && "This is not a `fir.box`"); TypePair boxTyPair = getBoxTypePair(boxObjTy); mlir::Value boxBaseAddr = operands[0]; @@ -2410,7 +2399,7 @@ struct CoordinateOpConversion mlir::LLVM::IntegerOverflowFlags::nsw; for (unsigned i = 1, last = operands.size(); i < last; ++i) { - if (auto arrTy = mlir::dyn_cast(cpnTy)) { + if (auto arrTy = cpnTy.dyn_cast()) { if (i != 1) TODO(loc, "fir.array nested inside other array and/or derived type"); // Applies byte strides from the box. Ignore lower bound from box @@ -2432,7 +2421,7 @@ struct CoordinateOpConversion llvm::ArrayRef{off}); i += arrTy.getDimension() - 1; cpnTy = arrTy.getEleTy(); - } else if (auto recTy = mlir::dyn_cast(cpnTy)) { + } else if (auto recTy = cpnTy.dyn_cast()) { mlir::Value nxtOpnd = operands[i]; cpnTy = recTy.getType(getFieldNumber(recTy, nxtOpnd)); auto llvmRecTy = lowerTy().convertType(recTy); @@ -2467,7 +2456,7 @@ struct CoordinateOpConversion // If only the column is `?`, then we can simply place the column value in // the 0-th GEP position. - if (auto arrTy = mlir::dyn_cast(cpnTy)) { + if (auto arrTy = cpnTy.dyn_cast()) { if (!hasKnownShape) { const unsigned sz = arrTy.getDimension(); if (arraysHaveKnownShape(arrTy.getEleTy(), @@ -2511,29 +2500,29 @@ struct CoordinateOpConversion dims = dimsLeft - 1; continue; } - cpnTy = mlir::cast(cpnTy).getEleTy(); + cpnTy = cpnTy.cast().getEleTy(); // append array range in reverse (FIR arrays are column-major) offs.append(arrIdx.rbegin(), arrIdx.rend()); arrIdx.clear(); dims.reset(); continue; } - if (auto arrTy = mlir::dyn_cast(cpnTy)) { + if (auto arrTy = cpnTy.dyn_cast()) { int d = arrTy.getDimension() - 1; if (d > 0) { dims = d; arrIdx.push_back(nxtOpnd); continue; } - cpnTy = mlir::cast(cpnTy).getEleTy(); + cpnTy = cpnTy.cast().getEleTy(); offs.push_back(nxtOpnd); continue; } // check if the i-th coordinate relates to a field - if (auto recTy = mlir::dyn_cast(cpnTy)) + if (auto recTy = cpnTy.dyn_cast()) cpnTy = recTy.getType(getFieldNumber(recTy, nxtOpnd)); - else if (auto tupTy = mlir::dyn_cast(cpnTy)) + else if (auto tupTy = cpnTy.dyn_cast()) cpnTy = tupTy.getType(getConstantIntValue(nxtOpnd)); else cpnTy = nullptr; @@ -2562,7 +2551,7 @@ struct FieldIndexOpConversion : public fir::FIROpConversion { mlir::LogicalResult matchAndRewrite(fir::FieldIndexOp field, OpAdaptor adaptor, mlir::ConversionPatternRewriter &rewriter) const override { - auto recTy = mlir::cast(field.getOnType()); + auto recTy = field.getOnType().cast(); unsigned index = recTy.getFieldIndex(field.getFieldId()); if (!fir::hasDynamicSize(recTy)) { @@ -2615,8 +2604,8 @@ struct TypeDescOpConversion : public fir::FIROpConversion { matchAndRewrite(fir::TypeDescOp typeDescOp, OpAdaptor adaptor, mlir::ConversionPatternRewriter &rewriter) const override { mlir::Type inTy = typeDescOp.getInType(); - assert(mlir::isa(inTy) && "expecting fir.type"); - auto recordType = mlir::dyn_cast(inTy); + assert(inTy.isa() && "expecting fir.type"); + auto recordType = inTy.dyn_cast(); auto module = typeDescOp.getOperation()->getParentOfType(); std::string typeDescName = fir::NameUniquer::getTypeDescriptorName(recordType.getName()); @@ -2743,7 +2732,7 @@ struct GlobalOpConversion : public fir::FIROpConversion { mlir::Type vecType = mlir::VectorType::get( insertOp.getType().getShape(), constant.getType()); auto denseAttr = mlir::DenseElementsAttr::get( - mlir::cast(vecType), constant.getValue()); + vecType.cast(), constant.getValue()); rewriter.setInsertionPointAfter(insertOp); rewriter.replaceOpWithNewOp( insertOp, seqTyAttr, denseAttr); @@ -2819,7 +2808,7 @@ struct LoadOpConversion : public fir::FIROpConversion { matchAndRewrite(fir::LoadOp load, OpAdaptor adaptor, mlir::ConversionPatternRewriter &rewriter) const override { mlir::Type llvmLoadTy = convertObjectType(load.getType()); - if (auto boxTy = mlir::dyn_cast(load.getType())) { + if (auto boxTy = load.getType().dyn_cast()) { // fir.box is a special case because it is considered as an ssa values in // fir, but it is lowered as a pointer to a descriptor. So // fir.ref and fir.box end up being the same llvm types and @@ -2932,7 +2921,7 @@ struct SelectCaseOpConversion : public fir::FIROpConversion { llvm::ArrayRef cases = caseOp.getCases().getValue(); // Type can be CHARACTER, INTEGER, or LOGICAL (C1145) auto ty = caseOp.getSelector().getType(); - if (mlir::isa(ty)) { + if (ty.isa()) { TODO(caseOp.getLoc(), "fir.select_case codegen with character type"); return mlir::failure(); } @@ -2946,25 +2935,25 @@ struct SelectCaseOpConversion : public fir::FIROpConversion { *caseOp.getCompareOperands(adaptor.getOperands(), t); mlir::Value caseArg = *(cmpOps.value().begin()); mlir::Attribute attr = cases[t]; - if (mlir::isa(attr)) { + if (attr.isa()) { auto cmp = rewriter.create( loc, mlir::LLVM::ICmpPredicate::eq, selector, caseArg); genCaseLadderStep(loc, cmp, dest, destOps, rewriter); continue; } - if (mlir::isa(attr)) { + if (attr.isa()) { auto cmp = rewriter.create( loc, mlir::LLVM::ICmpPredicate::sle, caseArg, selector); genCaseLadderStep(loc, cmp, dest, destOps, rewriter); continue; } - if (mlir::isa(attr)) { + if (attr.isa()) { auto cmp = rewriter.create( loc, mlir::LLVM::ICmpPredicate::sle, selector, caseArg); genCaseLadderStep(loc, cmp, dest, destOps, rewriter); continue; } - if (mlir::isa(attr)) { + if (attr.isa()) { auto cmp = rewriter.create( loc, mlir::LLVM::ICmpPredicate::sle, caseArg, selector); auto *thisBlock = rewriter.getInsertionBlock(); @@ -2980,7 +2969,7 @@ struct SelectCaseOpConversion : public fir::FIROpConversion { rewriter.setInsertionPointToEnd(newBlock2); continue; } - assert(mlir::isa(attr)); + assert(attr.isa()); assert((t + 1 == conds) && "unit must be last"); genBrOp(caseOp, dest, destOps, rewriter); } @@ -3008,7 +2997,7 @@ static void selectMatchAndRewrite(const fir::LLVMTypeConverter &lowering, mlir::Block *dest = select.getSuccessor(t); auto destOps = select.getSuccessorOperands(adaptor.getOperands(), t); const mlir::Attribute &attr = cases[t]; - if (auto intAttr = mlir::dyn_cast(attr)) { + if (auto intAttr = attr.template dyn_cast()) { destinations.push_back(dest); destinationsOperands.push_back(destOps ? *destOps : mlir::ValueRange{}); caseValues.push_back(intAttr.getInt()); @@ -3082,7 +3071,7 @@ struct StoreOpConversion : public fir::FIROpConversion { mlir::Location loc = store.getLoc(); mlir::Type storeTy = store.getValue().getType(); mlir::LLVM::StoreOp newStoreOp; - if (auto boxTy = mlir::dyn_cast(storeTy)) { + if (auto boxTy = storeTy.dyn_cast()) { // fir.box value is actually in memory, load it first before storing it. mlir::Type llvmBoxTy = lowerTy().convertBoxTypeAsStruct(boxTy); auto val = rewriter.create(loc, llvmBoxTy, @@ -3197,9 +3186,9 @@ struct IsPresentOpConversion : public fir::FIROpConversion { mlir::Location loc = isPresent.getLoc(); auto ptr = adaptor.getOperands()[0]; - if (mlir::isa(isPresent.getVal().getType())) { + if (isPresent.getVal().getType().isa()) { [[maybe_unused]] auto structTy = - mlir::cast(ptr.getType()); + ptr.getType().cast(); assert(!structTy.isOpaque() && !structTy.getBody().empty()); ptr = rewriter.create(loc, ptr, 0); @@ -3225,8 +3214,8 @@ struct AbsentOpConversion : public fir::FIROpConversion { mlir::Type ty = convertType(absent.getType()); mlir::Location loc = absent.getLoc(); - if (mlir::isa(absent.getType())) { - auto structTy = mlir::cast(ty); + if (absent.getType().isa()) { + auto structTy = ty.cast(); assert(!structTy.isOpaque() && !structTy.getBody().empty()); auto undefStruct = rewriter.create(loc, ty); auto nullField = diff --git a/flang/lib/Optimizer/CodeGen/FIROpPatterns.cpp b/flang/lib/Optimizer/CodeGen/FIROpPatterns.cpp index 00c5f77cde7ce..26871d8888155 100644 --- a/flang/lib/Optimizer/CodeGen/FIROpPatterns.cpp +++ b/flang/lib/Optimizer/CodeGen/FIROpPatterns.cpp @@ -20,7 +20,7 @@ static inline mlir::Type getLlvmPtrType(mlir::MLIRContext *context, } static unsigned getTypeDescFieldId(mlir::Type ty) { - auto isArray = mlir::isa(fir::dyn_cast_ptrOrBoxEleTy(ty)); + auto isArray = fir::dyn_cast_ptrOrBoxEleTy(ty).isa(); return isArray ? kOptTypePtrPosInBox : kDimsPosInBox; } @@ -37,7 +37,7 @@ ConvertFIRToLLVMPattern::ConvertFIRToLLVMPattern( // reference. mlir::Type ConvertFIRToLLVMPattern::convertObjectType(mlir::Type firType) const { - if (auto boxTy = mlir::dyn_cast(firType)) + if (auto boxTy = firType.dyn_cast()) return lowerTy().convertBoxTypeAsStruct(boxTy); return lowerTy().convertType(firType); } @@ -69,7 +69,7 @@ ConvertFIRToLLVMPattern::integerCast(mlir::Location loc, auto valTy = val.getType(); // If the value was not yet lowered, lower its type so that it can // be used in getPrimitiveTypeSizeInBits. - if (!mlir::isa(valTy)) + if (!valTy.isa()) valTy = convertType(valTy); auto toSize = mlir::LLVM::getPrimitiveTypeSizeInBits(ty); auto fromSize = mlir::LLVM::getPrimitiveTypeSizeInBits(valTy); @@ -91,7 +91,7 @@ ConvertFIRToLLVMPattern::getBoxTypePair(mlir::Type firBoxTy) const { mlir::Value ConvertFIRToLLVMPattern::getValueFromBox( mlir::Location loc, TypePair boxTy, mlir::Value box, mlir::Type resultTy, mlir::ConversionPatternRewriter &rewriter, int boxValue) const { - if (mlir::isa(box.getType())) { + if (box.getType().isa()) { auto pty = getLlvmPtrType(resultTy.getContext()); auto p = rewriter.create( loc, pty, boxTy.llvm, box, @@ -133,7 +133,7 @@ llvm::SmallVector ConvertFIRToLLVMPattern::getDimsFromBox( mlir::Value ConvertFIRToLLVMPattern::loadDimFieldFromBox( mlir::Location loc, TypePair boxTy, mlir::Value box, mlir::Value dim, int off, mlir::Type ty, mlir::ConversionPatternRewriter &rewriter) const { - assert(mlir::isa(box.getType()) && + assert(box.getType().isa() && "descriptor inquiry with runtime dim can only be done on descriptor " "in memory"); mlir::LLVM::GEPOp p = genGEP(loc, boxTy.llvm, rewriter, box, 0, @@ -146,7 +146,7 @@ mlir::Value ConvertFIRToLLVMPattern::loadDimFieldFromBox( mlir::Value ConvertFIRToLLVMPattern::getDimFieldFromBox( mlir::Location loc, TypePair boxTy, mlir::Value box, int dim, int off, mlir::Type ty, mlir::ConversionPatternRewriter &rewriter) const { - if (mlir::isa(box.getType())) { + if (box.getType().isa()) { mlir::LLVM::GEPOp p = genGEP(loc, boxTy.llvm, rewriter, box, 0, static_cast(kDimsPosInBox), dim, off); auto loadOp = rewriter.create(loc, ty, p); @@ -184,12 +184,12 @@ mlir::Value ConvertFIRToLLVMPattern::getElementSizeFromBox( mlir::Type ConvertFIRToLLVMPattern::getBoxEleTy( mlir::Type type, llvm::ArrayRef indexes) const { for (unsigned i : indexes) { - if (auto t = mlir::dyn_cast(type)) { + if (auto t = type.dyn_cast()) { assert(!t.isOpaque() && i < t.getBody().size()); type = t.getBody()[i]; - } else if (auto t = mlir::dyn_cast(type)) { + } else if (auto t = type.dyn_cast()) { type = t.getElementType(); - } else if (auto t = mlir::dyn_cast(type)) { + } else if (auto t = type.dyn_cast()) { type = t.getElementType(); } else { fir::emitFatalError(mlir::UnknownLoc::get(type.getContext()), diff --git a/flang/lib/Optimizer/CodeGen/PreCGRewrite.cpp b/flang/lib/Optimizer/CodeGen/PreCGRewrite.cpp index ce7ee22d5d774..665bf09b8fc33 100644 --- a/flang/lib/Optimizer/CodeGen/PreCGRewrite.cpp +++ b/flang/lib/Optimizer/CodeGen/PreCGRewrite.cpp @@ -86,10 +86,10 @@ class EmboxConversion : public mlir::OpRewritePattern { // If the embox does not include a shape, then do not convert it if (auto shapeVal = embox.getShape()) return rewriteDynamicShape(embox, rewriter, shapeVal); - if (mlir::isa(embox.getType())) + if (embox.getType().isa()) TODO(embox.getLoc(), "embox conversion for fir.class type"); - if (auto boxTy = mlir::dyn_cast(embox.getType())) - if (auto seqTy = mlir::dyn_cast(boxTy.getEleTy())) + if (auto boxTy = embox.getType().dyn_cast()) + if (auto seqTy = boxTy.getEleTy().dyn_cast()) if (!seqTy.hasDynamicExtents()) return rewriteStaticShape(embox, rewriter, seqTy); return mlir::failure(); @@ -294,9 +294,10 @@ class CodeGenRewrite : public fir::impl::CodeGenRewriteBase { target.addIllegalOp(); target.addIllegalOp(); target.addDynamicallyLegalOp([](fir::EmboxOp embox) { - return !(embox.getShape() || - mlir::isa( - mlir::cast(embox.getType()).getEleTy())); + return !(embox.getShape() || embox.getType() + .cast() + .getEleTy() + .isa()); }); mlir::RewritePatternSet patterns(&context); fir::populatePreCGRewritePatterns(patterns); diff --git a/flang/lib/Optimizer/CodeGen/TBAABuilder.cpp b/flang/lib/Optimizer/CodeGen/TBAABuilder.cpp index a21384e8d5946..b1b0e9b766a62 100644 --- a/flang/lib/Optimizer/CodeGen/TBAABuilder.cpp +++ b/flang/lib/Optimizer/CodeGen/TBAABuilder.cpp @@ -120,7 +120,7 @@ void TBAABuilder::attachTBAATag(AliasAnalysisOpInterface op, Type baseFIRType, // with both data and descriptor accesses. // Conservatively set any-access tag if there is any descriptor member. tbaaTagSym = getAnyAccessTag(func); - } else if (mlir::isa(baseFIRType)) { + } else if (baseFIRType.isa()) { tbaaTagSym = getBoxAccessTag(baseFIRType, accessFIRType, gep, func); } else { tbaaTagSym = getDataAccessTag(baseFIRType, accessFIRType, gep, func); diff --git a/flang/lib/Optimizer/CodeGen/Target.cpp b/flang/lib/Optimizer/CodeGen/Target.cpp index 652e2bddc1b89..cea7a1f97f419 100644 --- a/flang/lib/Optimizer/CodeGen/Target.cpp +++ b/flang/lib/Optimizer/CodeGen/Target.cpp @@ -41,9 +41,9 @@ llvm::StringRef Attributes::getIntExtensionAttrName() const { static const llvm::fltSemantics &floatToSemantics(const KindMapping &kindMap, mlir::Type type) { assert(isa_real(type)); - if (auto ty = mlir::dyn_cast(type)) + if (auto ty = type.dyn_cast()) return kindMap.getFloatSemantics(ty.getFKind()); - return mlir::cast(type).getFloatSemantics(); + return type.cast().getFloatSemantics(); } static void typeTodo(const llvm::fltSemantics *sem, mlir::Location loc, diff --git a/flang/lib/Optimizer/CodeGen/TargetRewrite.cpp b/flang/lib/Optimizer/CodeGen/TargetRewrite.cpp index 616de78d00260..7bf31ec386959 100644 --- a/flang/lib/Optimizer/CodeGen/TargetRewrite.cpp +++ b/flang/lib/Optimizer/CodeGen/TargetRewrite.cpp @@ -137,7 +137,7 @@ class TargetRewrite : public fir::impl::TargetRewritePassBase { if (!hasPortableSignature(dispatch.getFunctionType(), op)) convertCallOp(dispatch); } else if (auto addr = mlir::dyn_cast(op)) { - if (mlir::isa(addr.getType()) && + if (addr.getType().isa() && !hasPortableSignature(addr.getType(), op)) convertAddrOp(addr); } @@ -601,7 +601,7 @@ class TargetRewrite : public fir::impl::TargetRewritePassBase { /// Taking the address of a function. Modify the signature as needed. void convertAddrOp(fir::AddrOfOp addrOp) { rewriter->setInsertionPoint(addrOp); - auto addrTy = mlir::cast(addrOp.getType()); + auto addrTy = addrOp.getType().cast(); fir::CodeGenSpecifics::Marshalling newInTyAndAttrs; llvm::SmallVector newResTys; auto loc = addrOp.getLoc(); @@ -705,23 +705,22 @@ class TargetRewrite : public fir::impl::TargetRewritePassBase { /// return `true`. Otherwise, the signature is not portable and `false` is /// returned. bool hasPortableSignature(mlir::Type signature, mlir::Operation *op) { - assert(mlir::isa(signature)); - auto func = mlir::dyn_cast(signature); + assert(signature.isa()); + auto func = signature.dyn_cast(); bool hasCCallingConv = isFuncWithCCallingConvention(op); for (auto ty : func.getResults()) - if ((mlir::isa(ty) && !noCharacterConversion) || + if ((ty.isa() && !noCharacterConversion) || (fir::isa_complex(ty) && !noComplexConversion) || - (mlir::isa(ty) && hasCCallingConv)) { + (ty.isa() && hasCCallingConv)) { LLVM_DEBUG(llvm::dbgs() << "rewrite " << signature << " for target\n"); return false; } for (auto ty : func.getInputs()) - if (((mlir::isa(ty) || - fir::isCharacterProcedureTuple(ty)) && + if (((ty.isa() || fir::isCharacterProcedureTuple(ty)) && !noCharacterConversion) || (fir::isa_complex(ty) && !noComplexConversion) || - (mlir::isa(ty) && hasCCallingConv) || - (mlir::isa(ty) && !noStructConversion)) { + (ty.isa() && hasCCallingConv) || + (ty.isa() && !noStructConversion)) { LLVM_DEBUG(llvm::dbgs() << "rewrite " << signature << " for target\n"); return false; } @@ -741,7 +740,7 @@ class TargetRewrite : public fir::impl::TargetRewritePassBase { /// Rewrite the signatures and body of the `FuncOp`s in the module for /// the immediately subsequent target code gen. void convertSignature(mlir::func::FuncOp func) { - auto funcTy = mlir::cast(func.getFunctionType()); + auto funcTy = func.getFunctionType().cast(); if (hasPortableSignature(funcTy, func) && !hasHostAssociations(func)) return; llvm::SmallVector newResTys; diff --git a/flang/lib/Optimizer/CodeGen/TypeConverter.cpp b/flang/lib/Optimizer/CodeGen/TypeConverter.cpp index fb2ec3f0b2f5e..8fa423f35806e 100644 --- a/flang/lib/Optimizer/CodeGen/TypeConverter.cpp +++ b/flang/lib/Optimizer/CodeGen/TypeConverter.cpp @@ -103,10 +103,10 @@ LLVMTypeConverter::LLVMTypeConverter(mlir::ModuleOp module, bool applyTBAA, for (auto mem : tuple.getTypes()) { // Prevent fir.box from degenerating to a pointer to a descriptor in the // context of a tuple type. - if (auto box = mlir::dyn_cast(mem)) + if (auto box = mem.dyn_cast()) members.push_back(convertBoxTypeAsStruct(box)); else - members.push_back(mlir::cast(convertType(mem))); + members.push_back(convertType(mem).cast()); } return mlir::LLVM::LLVMStructType::getLiteral(&getContext(), members, /*isPacked=*/false); @@ -181,10 +181,10 @@ std::optional LLVMTypeConverter::convertRecordType( for (auto mem : derived.getTypeList()) { // Prevent fir.box from degenerating to a pointer to a descriptor in the // context of a record type. - if (auto box = mlir::dyn_cast(mem.second)) + if (auto box = mem.second.dyn_cast()) members.push_back(convertBoxTypeAsStruct(box)); else - members.push_back(mlir::cast(convertType(mem.second))); + members.push_back(convertType(mem.second).cast()); } if (mlir::failed(st.setBody(members, /*isPacked=*/false))) return mlir::failure(); @@ -196,7 +196,7 @@ std::optional LLVMTypeConverter::convertRecordType( // Extended descriptors are required for derived types. bool LLVMTypeConverter::requiresExtendedDesc(mlir::Type boxElementType) const { auto eleTy = fir::unwrapSequenceType(boxElementType); - return mlir::isa(eleTy); + return eleTy.isa(); } // This corresponds to the descriptor as defined in ISO_Fortran_binding.h and @@ -211,8 +211,7 @@ mlir::Type LLVMTypeConverter::convertBoxTypeAsStruct(BaseBoxType box, ele = removeIndirection; auto eleTy = convertType(ele); // base_addr* - if (mlir::isa(ele) && - mlir::isa(eleTy)) + if (ele.isa() && eleTy.isa()) dataDescFields.push_back(eleTy); else dataDescFields.push_back( @@ -237,7 +236,7 @@ mlir::Type LLVMTypeConverter::convertBoxTypeAsStruct(BaseBoxType box, getDescFieldTypeModel()(&getContext())); // [dims] if (rank == unknownRank()) { - if (auto seqTy = mlir::dyn_cast(ele)) + if (auto seqTy = ele.dyn_cast()) rank = seqTy.getDimension(); else rank = 0; @@ -253,8 +252,7 @@ mlir::Type LLVMTypeConverter::convertBoxTypeAsStruct(BaseBoxType box, auto rowTy = getExtendedDescFieldTypeModel()(&getContext()); dataDescFields.push_back(mlir::LLVM::LLVMArrayType::get(rowTy, 1)); - if (auto recTy = - mlir::dyn_cast(fir::unwrapSequenceType(ele))) + if (auto recTy = fir::unwrapSequenceType(ele).dyn_cast()) if (recTy.getNumLenParams() > 0) { // The descriptor design needs to be clarified regarding the number of // length parameters in the addendum. Since it can change for diff --git a/flang/lib/Optimizer/Dialect/FIRAttr.cpp b/flang/lib/Optimizer/Dialect/FIRAttr.cpp index 9ea3a0568f691..e43710f5627ee 100644 --- a/flang/lib/Optimizer/Dialect/FIRAttr.cpp +++ b/flang/lib/Optimizer/Dialect/FIRAttr.cpp @@ -264,23 +264,23 @@ void fir::FortranVariableFlagsAttr::print(mlir::AsmPrinter &printer) const { void fir::printFirAttribute(FIROpsDialect *dialect, mlir::Attribute attr, mlir::DialectAsmPrinter &p) { auto &os = p.getStream(); - if (auto exact = mlir::dyn_cast(attr)) { + if (auto exact = attr.dyn_cast()) { os << fir::ExactTypeAttr::getAttrName() << '<'; p.printType(exact.getType()); os << '>'; - } else if (auto sub = mlir::dyn_cast(attr)) { + } else if (auto sub = attr.dyn_cast()) { os << fir::SubclassAttr::getAttrName() << '<'; p.printType(sub.getType()); os << '>'; - } else if (mlir::dyn_cast_or_null(attr)) { + } else if (attr.dyn_cast_or_null()) { os << fir::PointIntervalAttr::getAttrName(); - } else if (mlir::dyn_cast_or_null(attr)) { + } else if (attr.dyn_cast_or_null()) { os << fir::ClosedIntervalAttr::getAttrName(); - } else if (mlir::dyn_cast_or_null(attr)) { + } else if (attr.dyn_cast_or_null()) { os << fir::LowerBoundAttr::getAttrName(); - } else if (mlir::dyn_cast_or_null(attr)) { + } else if (attr.dyn_cast_or_null()) { os << fir::UpperBoundAttr::getAttrName(); - } else if (auto a = mlir::dyn_cast_or_null(attr)) { + } else if (auto a = attr.dyn_cast_or_null()) { os << fir::RealAttr::getAttrName() << '<' << a.getFKind() << ", i x"; llvm::SmallString<40> ss; a.getValue().bitcastToAPInt().toStringUnsigned(ss, 16); diff --git a/flang/lib/Optimizer/Dialect/FIROps.cpp b/flang/lib/Optimizer/Dialect/FIROps.cpp index a39087aeb358b..24af94f9b90a1 100644 --- a/flang/lib/Optimizer/Dialect/FIROps.cpp +++ b/flang/lib/Optimizer/Dialect/FIROps.cpp @@ -57,7 +57,7 @@ static void propagateAttributes(mlir::Operation *fromOp, static bool verifyInType(mlir::Type inType, llvm::SmallVectorImpl &visited, unsigned dynamicExtents = 0) { - if (auto st = mlir::dyn_cast(inType)) { + if (auto st = inType.dyn_cast()) { auto shape = st.getShape(); if (shape.size() == 0) return true; @@ -67,7 +67,7 @@ static bool verifyInType(mlir::Type inType, if (dynamicExtents-- == 0) return true; } - } else if (auto rt = mlir::dyn_cast(inType)) { + } else if (auto rt = inType.dyn_cast()) { // don't recurse if we're already visiting this one if (llvm::is_contained(visited, rt.getName())) return false; @@ -84,13 +84,13 @@ static bool verifyInType(mlir::Type inType, static bool verifyTypeParamCount(mlir::Type inType, unsigned numParams) { auto ty = fir::unwrapSequenceType(inType); if (numParams > 0) { - if (auto recTy = mlir::dyn_cast(ty)) + if (auto recTy = ty.dyn_cast()) return numParams != recTy.getNumLenParams(); - if (auto chrTy = mlir::dyn_cast(ty)) + if (auto chrTy = ty.dyn_cast()) return !(numParams == 1 && chrTy.hasDynamicLen()); return true; } - if (auto chrTy = mlir::dyn_cast(ty)) + if (auto chrTy = ty.dyn_cast()) return !chrTy.hasConstantLen(); return false; } @@ -171,13 +171,13 @@ static void printAllocatableOp(mlir::OpAsmPrinter &p, OP &op) { /// Create a legal memory reference as return type static mlir::Type wrapAllocaResultType(mlir::Type intype) { // FIR semantics: memory references to memory references are disallowed - if (mlir::isa(intype)) + if (intype.isa()) return {}; return fir::ReferenceType::get(intype); } mlir::Type fir::AllocaOp::getAllocatedType() { - return mlir::cast(getType()).getEleTy(); + return getType().cast().getEleTy(); } mlir::Type fir::AllocaOp::getRefTy(mlir::Type ty) { @@ -270,7 +270,7 @@ mlir::LogicalResult fir::AllocaOp::verify() { if (verifyTypeParamCount(getInType(), numLenParams())) return emitOpError("LEN params do not correspond to type"); mlir::Type outType = getType(); - if (!mlir::isa(outType)) + if (!outType.isa()) return emitOpError("must be a !fir.ref type"); if (fir::isa_unknown_size_box(fir::dyn_cast_ptrEleTy(outType))) return emitOpError("cannot allocate !fir.box of unknown rank or type"); @@ -286,14 +286,14 @@ static mlir::Type wrapAllocMemResultType(mlir::Type intype) { // Fortran semantics: C852 an entity cannot be both ALLOCATABLE and POINTER // 8.5.3 note 1 prohibits ALLOCATABLE procedures as well // FIR semantics: one may not allocate a memory reference value - if (mlir::isa(intype)) + if (intype.isa()) return {}; return fir::HeapType::get(intype); } mlir::Type fir::AllocMemOp::getAllocatedType() { - return mlir::cast(getType()).getEleTy(); + return getType().cast().getEleTy(); } mlir::Type fir::AllocMemOp::getRefTy(mlir::Type ty) { @@ -348,7 +348,7 @@ mlir::LogicalResult fir::AllocMemOp::verify() { if (verifyTypeParamCount(getInType(), numLenParams())) return emitOpError("LEN params do not correspond to type"); mlir::Type outType = getType(); - if (!mlir::dyn_cast(outType)) + if (!outType.dyn_cast()) return emitOpError("must be a !fir.heap type"); if (fir::isa_unknown_size_box(fir::dyn_cast_ptrEleTy(outType))) return emitOpError("cannot allocate !fir.box of unknown rank or type"); @@ -364,13 +364,13 @@ mlir::LogicalResult fir::AllocMemOp::verify() { static bool validTypeParams(mlir::Type dynTy, mlir::ValueRange typeParams) { dynTy = fir::unwrapAllRefAndSeqType(dynTy); // A box value will contain type parameter values itself. - if (mlir::isa(dynTy)) + if (dynTy.isa()) return typeParams.size() == 0; // Derived type must have all type parameters satisfied. - if (auto recTy = mlir::dyn_cast(dynTy)) + if (auto recTy = dynTy.dyn_cast()) return typeParams.size() == recTy.getNumLenParams(); // Characters with non-constant LEN must have a type parameter value. - if (auto charTy = mlir::dyn_cast(dynTy)) + if (auto charTy = dynTy.dyn_cast()) if (charTy.hasDynamicLen()) return typeParams.size() == 1; // Otherwise, any type parameters are invalid. @@ -379,7 +379,7 @@ static bool validTypeParams(mlir::Type dynTy, mlir::ValueRange typeParams) { mlir::LogicalResult fir::ArrayCoorOp::verify() { auto eleTy = fir::dyn_cast_ptrOrBoxEleTy(getMemref().getType()); - auto arrTy = mlir::dyn_cast(eleTy); + auto arrTy = eleTy.dyn_cast(); if (!arrTy) return emitOpError("must be a reference to an array"); auto arrDim = arrTy.getDimension(); @@ -387,14 +387,14 @@ mlir::LogicalResult fir::ArrayCoorOp::verify() { if (auto shapeOp = getShape()) { auto shapeTy = shapeOp.getType(); unsigned shapeTyRank = 0; - if (auto s = mlir::dyn_cast(shapeTy)) { + if (auto s = shapeTy.dyn_cast()) { shapeTyRank = s.getRank(); - } else if (auto ss = mlir::dyn_cast(shapeTy)) { + } else if (auto ss = shapeTy.dyn_cast()) { shapeTyRank = ss.getRank(); } else { - auto s = mlir::cast(shapeTy); + auto s = shapeTy.cast(); shapeTyRank = s.getRank(); - if (!mlir::isa(getMemref().getType())) + if (!getMemref().getType().isa()) return emitOpError("shift can only be provided with fir.box memref"); } if (arrDim && arrDim != shapeTyRank) @@ -407,7 +407,7 @@ mlir::LogicalResult fir::ArrayCoorOp::verify() { if (auto sl = mlir::dyn_cast_or_null(sliceOp.getDefiningOp())) if (!sl.getSubstr().empty()) return emitOpError("array_coor cannot take a slice with substring"); - if (auto sliceTy = mlir::dyn_cast(sliceOp.getType())) + if (auto sliceTy = sliceOp.getType().dyn_cast()) if (sliceTy.getRank() != arrDim) return emitOpError("rank of dimension in slice mismatched"); } @@ -422,13 +422,13 @@ mlir::LogicalResult fir::ArrayCoorOp::verify() { //===----------------------------------------------------------------------===// static mlir::Type adjustedElementType(mlir::Type t) { - if (auto ty = mlir::dyn_cast(t)) { + if (auto ty = t.dyn_cast()) { auto eleTy = ty.getEleTy(); if (fir::isa_char(eleTy)) return eleTy; if (fir::isa_derived(eleTy)) return eleTy; - if (mlir::isa(eleTy)) + if (eleTy.isa()) return eleTy; } return t; @@ -448,7 +448,7 @@ std::vector fir::ArrayLoadOp::getExtents() { mlir::LogicalResult fir::ArrayLoadOp::verify() { auto eleTy = fir::dyn_cast_ptrOrBoxEleTy(getMemref().getType()); - auto arrTy = mlir::dyn_cast(eleTy); + auto arrTy = eleTy.dyn_cast(); if (!arrTy) return emitOpError("must be a reference to an array"); auto arrDim = arrTy.getDimension(); @@ -456,14 +456,14 @@ mlir::LogicalResult fir::ArrayLoadOp::verify() { if (auto shapeOp = getShape()) { auto shapeTy = shapeOp.getType(); unsigned shapeTyRank = 0u; - if (auto s = mlir::dyn_cast(shapeTy)) { + if (auto s = shapeTy.dyn_cast()) { shapeTyRank = s.getRank(); - } else if (auto ss = mlir::dyn_cast(shapeTy)) { + } else if (auto ss = shapeTy.dyn_cast()) { shapeTyRank = ss.getRank(); } else { - auto s = mlir::cast(shapeTy); + auto s = shapeTy.cast(); shapeTyRank = s.getRank(); - if (!mlir::isa(getMemref().getType())) + if (!getMemref().getType().isa()) return emitOpError("shift can only be provided with fir.box memref"); } if (arrDim && arrDim != shapeTyRank) @@ -474,7 +474,7 @@ mlir::LogicalResult fir::ArrayLoadOp::verify() { if (auto sl = mlir::dyn_cast_or_null(sliceOp.getDefiningOp())) if (!sl.getSubstr().empty()) return emitOpError("array_load cannot take a slice with substring"); - if (auto sliceTy = mlir::dyn_cast(sliceOp.getType())) + if (auto sliceTy = sliceOp.getType().dyn_cast()) if (sliceTy.getRank() != arrDim) return emitOpError("rank of dimension in slice mismatched"); } @@ -502,7 +502,7 @@ mlir::LogicalResult fir::ArrayMergeStoreOp::verify() { // 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(getMemref().getType()); - if (auto seqTy = mlir::dyn_cast(eleTy)) { + if (auto seqTy = eleTy.dyn_cast()) { auto projTy = fir::applyPathToType(seqTy.getEleTy(), sliceOp.getFields()); if (fir::unwrapSequenceType(getOriginal().getType()) != projTy) @@ -540,7 +540,7 @@ mlir::Type validArraySubobject(A op) { } mlir::LogicalResult fir::ArrayFetchOp::verify() { - auto arrTy = mlir::cast(getSequence().getType()); + auto arrTy = getSequence().getType().cast(); auto indSize = getIndices().size(); if (indSize < arrTy.getDimension()) return emitOpError("number of indices != dimension of array"); @@ -562,7 +562,7 @@ mlir::LogicalResult fir::ArrayFetchOp::verify() { //===----------------------------------------------------------------------===// mlir::LogicalResult fir::ArrayAccessOp::verify() { - auto arrTy = mlir::cast(getSequence().getType()); + auto arrTy = getSequence().getType().cast(); std::size_t indSize = getIndices().size(); if (indSize < arrTy.getDimension()) return emitOpError("number of indices != dimension of array"); @@ -584,7 +584,7 @@ mlir::LogicalResult fir::ArrayAccessOp::verify() { mlir::LogicalResult fir::ArrayUpdateOp::verify() { if (fir::isa_ref_type(getMerge().getType())) return emitOpError("does not support reference type for merge"); - auto arrTy = mlir::cast(getSequence().getType()); + auto arrTy = getSequence().getType().cast(); auto indSize = getIndices().size(); if (indSize < arrTy.getDimension()) return emitOpError("number of indices != dimension of array"); @@ -604,7 +604,7 @@ mlir::LogicalResult fir::ArrayUpdateOp::verify() { //===----------------------------------------------------------------------===// mlir::LogicalResult fir::ArrayModifyOp::verify() { - auto arrTy = mlir::cast(getSequence().getType()); + auto arrTy = getSequence().getType().cast(); auto indSize = getIndices().size(); if (indSize < arrTy.getDimension()) return emitOpError("number of indices must match array dimension"); @@ -740,7 +740,7 @@ mlir::ParseResult fir::CallOp::parse(mlir::OpAsmParser &parser, parser.parseType(type)) return mlir::failure(); - auto funcType = mlir::dyn_cast(type); + auto funcType = type.dyn_cast(); if (!funcType) return parser.emitError(parser.getNameLoc(), "expected function type"); if (isDirect) { @@ -785,7 +785,7 @@ void fir::CallOp::build(mlir::OpBuilder &builder, mlir::OperationState &result, mlir::LogicalResult fir::CharConvertOp::verify() { auto unwrap = [&](mlir::Type t) { t = fir::unwrapSequenceType(fir::dyn_cast_ptrEleTy(t)); - return mlir::dyn_cast(t); + return t.dyn_cast(); }; auto inTy = unwrap(getFrom().getType()); auto outTy = unwrap(getTo().getType()); @@ -832,13 +832,13 @@ static mlir::ParseResult parseCmpOp(mlir::OpAsmParser &parser, parser.resolveOperands(ops, type, result.operands)) return mlir::failure(); - if (!mlir::isa(predicateNameAttr)) + if (!predicateNameAttr.isa()) return parser.emitError(parser.getNameLoc(), "expected string comparison predicate attribute"); // Rewrite string attribute to an enum value. llvm::StringRef predicateName = - mlir::cast(predicateNameAttr).getValue(); + predicateNameAttr.cast().getValue(); auto predicate = fir::CmpcOp::getPredicateByName(predicateName); auto builder = parser.getBuilder(); mlir::Type i1Type = builder.getI1Type(); @@ -906,7 +906,7 @@ void fir::ConstcOp::print(mlir::OpAsmPrinter &p) { } mlir::LogicalResult fir::ConstcOp::verify() { - if (!mlir::isa(getType())) + if (!getType().isa()) return emitOpError("must be a !fir.complex type"); return mlir::success(); } @@ -929,16 +929,15 @@ mlir::OpFoldResult fir::ConvertOp::fold(FoldAdaptor adaptor) { if (matchPattern(getValue(), mlir::m_Op())) { auto inner = mlir::cast(getValue().getDefiningOp()); // (convert (convert 'a : logical -> i1) : i1 -> logical) ==> forward 'a - if (auto toTy = mlir::dyn_cast(getType())) - if (auto fromTy = - mlir::dyn_cast(inner.getValue().getType())) - if (mlir::isa(inner.getType()) && (toTy == fromTy)) + if (auto toTy = getType().dyn_cast()) + if (auto fromTy = inner.getValue().getType().dyn_cast()) + if (inner.getType().isa() && (toTy == fromTy)) return inner.getValue(); // (convert (convert 'a : i1 -> logical) : logical -> i1) ==> forward 'a - if (auto toTy = mlir::dyn_cast(getType())) + if (auto toTy = getType().dyn_cast()) if (auto fromTy = - mlir::dyn_cast(inner.getValue().getType())) - if (mlir::isa(inner.getType()) && (toTy == fromTy) && + inner.getValue().getType().dyn_cast()) + if (inner.getType().isa() && (toTy == fromTy) && (fromTy.getWidth() == 1)) return inner.getValue(); } @@ -946,7 +945,7 @@ mlir::OpFoldResult fir::ConvertOp::fold(FoldAdaptor adaptor) { } bool fir::ConvertOp::isInteger(mlir::Type ty) { - return mlir::isa(ty); + return ty.isa(); } bool fir::ConvertOp::isIntegerCompatible(mlir::Type ty) { @@ -954,13 +953,13 @@ bool fir::ConvertOp::isIntegerCompatible(mlir::Type ty) { } bool fir::ConvertOp::isFloatCompatible(mlir::Type ty) { - return mlir::isa(ty); + return ty.isa(); } bool fir::ConvertOp::isPointerCompatible(mlir::Type ty) { - return mlir::isa(ty); + return ty.isa(); } static std::optional getVectorElementType(mlir::Type ty) { @@ -1027,14 +1026,12 @@ bool fir::ConvertOp::canBeConverted(mlir::Type inType, mlir::Type outType) { (isFloatCompatible(inType) && isFloatCompatible(outType)) || (isIntegerCompatible(inType) && isPointerCompatible(outType)) || (isPointerCompatible(inType) && isIntegerCompatible(outType)) || - (mlir::isa(inType) && - mlir::isa(outType)) || - (mlir::isa(inType) && - mlir::isa(outType)) || + (inType.isa() && outType.isa()) || + (inType.isa() && outType.isa()) || (fir::isa_complex(inType) && fir::isa_complex(outType)) || (fir::isBoxedRecordType(inType) && fir::isPolymorphicType(outType)) || (fir::isPolymorphicType(inType) && fir::isPolymorphicType(outType)) || - (fir::isPolymorphicType(inType) && mlir::isa(outType)) || + (fir::isPolymorphicType(inType) && outType.isa()) || areVectorsCompatible(inType, outType); } @@ -1082,7 +1079,7 @@ mlir::LogicalResult fir::CoordinateOp::verify() { const mlir::Type refTy = getRef().getType(); if (fir::isa_ref_type(refTy)) { auto eleTy = fir::dyn_cast_ptrEleTy(refTy); - if (auto arrTy = mlir::dyn_cast(eleTy)) { + if (auto arrTy = eleTy.dyn_cast()) { if (arrTy.hasUnknownShape()) return emitOpError("cannot find coordinate in unknown shape"); if (arrTy.getConstantRows() < arrTy.getDimension() - 1) @@ -1097,8 +1094,8 @@ mlir::LogicalResult fir::CoordinateOp::verify() { const unsigned numCoors = getCoor().size(); for (auto coorOperand : llvm::enumerate(getCoor())) { auto co = coorOperand.value(); - if (dimension == 0 && mlir::isa(eleTy)) { - dimension = mlir::cast(eleTy).getDimension(); + if (dimension == 0 && eleTy.isa()) { + dimension = eleTy.cast().getDimension(); if (dimension == 0) return emitOpError("cannot apply to array of unknown rank"); } @@ -1107,7 +1104,7 @@ mlir::LogicalResult fir::CoordinateOp::verify() { // 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 `index`. - if (mlir::isa(refTy)) { + if (refTy.isa()) { if (coorOperand.index() != numCoors - 1) return emitOpError("len_param_index must be last argument"); if (getNumOperands() != 2) @@ -1120,7 +1117,7 @@ mlir::LogicalResult fir::CoordinateOp::verify() { } else if (auto index = mlir::dyn_cast(defOp)) { if (eleTy != index.getOnType()) emitOpError("field_index type not compatible with reference type"); - if (auto recTy = mlir::dyn_cast(eleTy)) { + if (auto recTy = eleTy.dyn_cast()) { eleTy = recTy.getType(index.getFieldName()); continue; } @@ -1129,21 +1126,21 @@ mlir::LogicalResult fir::CoordinateOp::verify() { } if (dimension) { if (--dimension == 0) - eleTy = mlir::cast(eleTy).getEleTy(); + eleTy = eleTy.cast().getEleTy(); } else { - if (auto t = mlir::dyn_cast(eleTy)) { + if (auto t = eleTy.dyn_cast()) { // FIXME: Generally, we don't know which field of the tuple is being // referred to unless the operand is a constant. Just assume everything // is good in the tuple case for now. return mlir::success(); - } else if (auto t = mlir::dyn_cast(eleTy)) { + } else if (auto t = eleTy.dyn_cast()) { // FIXME: This is the same as the tuple case. return mlir::success(); - } else if (auto t = mlir::dyn_cast(eleTy)) { + } else if (auto t = eleTy.dyn_cast()) { eleTy = t.getElementType(); - } else if (auto t = mlir::dyn_cast(eleTy)) { + } else if (auto t = eleTy.dyn_cast()) { eleTy = t.getElementType(); - } else if (auto t = mlir::dyn_cast(eleTy)) { + } else if (auto t = eleTy.dyn_cast()) { if (t.getLen() == fir::CharacterType::singleton()) return emitOpError("cannot apply to character singleton"); eleTy = fir::CharacterType::getSingleton(t.getContext(), t.getFKind()); @@ -1219,17 +1216,17 @@ mlir::LogicalResult fir::TypeInfoOp::verify() { mlir::LogicalResult fir::EmboxOp::verify() { auto eleTy = fir::dyn_cast_ptrEleTy(getMemref().getType()); bool isArray = false; - if (auto seqTy = mlir::dyn_cast(eleTy)) { + if (auto seqTy = eleTy.dyn_cast()) { eleTy = seqTy.getEleTy(); isArray = true; } if (hasLenParams()) { auto lenPs = numLenParams(); - if (auto rt = mlir::dyn_cast(eleTy)) { + if (auto rt = eleTy.dyn_cast()) { if (lenPs != rt.getNumLenParams()) return emitOpError("number of LEN params does not correspond" " to the !fir.type type"); - } else if (auto strTy = mlir::dyn_cast(eleTy)) { + } else if (auto strTy = eleTy.dyn_cast()) { if (strTy.getLen() != fir::CharacterType::unknownLen()) return emitOpError("CHARACTER already has static LEN"); } else { @@ -1243,7 +1240,7 @@ mlir::LogicalResult fir::EmboxOp::verify() { return emitOpError("shape must not be provided for a scalar"); if (getSlice() && !isArray) return emitOpError("slice must not be provided for a scalar"); - if (getSourceBox() && !mlir::isa(getResult().getType())) + if (getSourceBox() && !getResult().getType().isa()) return emitOpError("source_box must be used with fir.class result type"); return mlir::success(); } @@ -1254,7 +1251,7 @@ mlir::LogicalResult fir::EmboxOp::verify() { mlir::LogicalResult fir::EmboxCharOp::verify() { auto eleTy = fir::dyn_cast_ptrEleTy(getMemref().getType()); - if (!mlir::dyn_cast_or_null(eleTy)) + if (!eleTy.dyn_cast_or_null()) return mlir::failure(); return mlir::success(); } @@ -1266,8 +1263,8 @@ mlir::LogicalResult fir::EmboxCharOp::verify() { mlir::LogicalResult fir::EmboxProcOp::verify() { // host bindings (optional) must be a reference to a tuple if (auto h = getHost()) { - if (auto r = mlir::dyn_cast(h.getType())) - if (mlir::isa(r.getEleTy())) + if (auto r = h.getType().dyn_cast()) + if (r.getEleTy().isa()) return mlir::success(); return mlir::failure(); } @@ -1303,7 +1300,7 @@ void fir::TypeDescOp::print(mlir::OpAsmPrinter &p) { mlir::LogicalResult fir::TypeDescOp::verify() { mlir::Type resultTy = getType(); - if (auto tdesc = mlir::dyn_cast(resultTy)) { + if (auto tdesc = resultTy.dyn_cast()) { if (tdesc.getOfTy() != getInType()) return emitOpError("wrapped type mismatched"); return mlir::success(); @@ -1530,7 +1527,7 @@ mlir::ParseResult parseFieldLikeOp(mlir::OpAsmParser &parser, return mlir::failure(); result.addAttribute(fir::FieldIndexOp::getFieldAttrName(), builder.getStringAttr(fieldName)); - if (!mlir::dyn_cast(recty)) + if (!recty.dyn_cast()) return mlir::failure(); result.addAttribute(fir::FieldIndexOp::getTypeAttrName(), mlir::TypeAttr::get(recty)); @@ -1674,7 +1671,7 @@ mlir::LogicalResult fir::InsertOnRangeOp::verify() { //===----------------------------------------------------------------------===// static bool checkIsIntegerConstant(mlir::Attribute attr, std::int64_t conVal) { - if (auto iattr = mlir::dyn_cast(attr)) + if (auto iattr = attr.dyn_cast()) return iattr.getInt() == conVal; return false; } @@ -1693,7 +1690,7 @@ struct UndoComplexPattern : public mlir::RewritePattern { matchAndRewrite(mlir::Operation *op, mlir::PatternRewriter &rewriter) const override { auto insval = mlir::dyn_cast_or_null(op); - if (!insval || !mlir::isa(insval.getType())) + if (!insval || !insval.getType().isa()) return mlir::failure(); auto insval2 = mlir::dyn_cast_or_null( insval.getAdt().getDefiningOp()); @@ -1822,7 +1819,7 @@ mlir::ParseResult fir::IterWhileOp::parse(mlir::OpAsmParser &parser, parser.parseRParen()) return mlir::failure(); // Type list must be "(index, i1)". - if (typeList.size() != 2 || !mlir::isa(typeList[0]) || + if (typeList.size() != 2 || !typeList[0].isa() || !typeList[1].isSignlessInteger(1)) return mlir::failure(); result.addTypes(typeList); @@ -1876,7 +1873,7 @@ mlir::LogicalResult fir::IterWhileOp::verify() { auto opNumResults = getNumResults(); if (getFinalValue()) { // Result type must be "(index, i1, ...)". - if (!mlir::isa(getResult(0).getType())) + if (!getResult(0).getType().isa()) return emitOpError("result #0 expected to be index"); if (!getResult(1).getType().isSignlessInteger(1)) return emitOpError("result #1 expected to be i1"); @@ -2319,7 +2316,7 @@ void fir::DTEntryOp::print(mlir::OpAsmPrinter &p) { /// Example: return f32 for !fir.box>. static mlir::Type getBoxScalarEleTy(mlir::Type boxTy) { auto eleTy = fir::dyn_cast_ptrOrBoxEleTy(boxTy); - if (auto seqTy = mlir::dyn_cast(eleTy)) + if (auto seqTy = eleTy.dyn_cast()) return seqTy.getEleTy(); return eleTy; } @@ -2327,8 +2324,8 @@ static mlir::Type getBoxScalarEleTy(mlir::Type boxTy) { /// Test if \p t1 and \p t2 are compatible character types (if they can /// represent the same type at runtime). static bool areCompatibleCharacterTypes(mlir::Type t1, mlir::Type t2) { - auto c1 = mlir::dyn_cast(t1); - auto c2 = mlir::dyn_cast(t2); + auto c1 = t1.dyn_cast(); + auto c2 = t2.dyn_cast(); if (!c1 || !c2) return false; if (c1.hasDynamicLen() || c2.hasDynamicLen()) @@ -2350,10 +2347,10 @@ mlir::LogicalResult fir::ReboxOp::verify() { if (auto sliceVal = getSlice()) { // Slicing case - if (mlir::cast(sliceVal.getType()).getRank() != inputRank) + if (sliceVal.getType().cast().getRank() != inputRank) return emitOpError("slice operand rank must match box operand rank"); if (auto shapeVal = getShape()) { - if (auto shiftTy = mlir::dyn_cast(shapeVal.getType())) { + if (auto shiftTy = shapeVal.getType().dyn_cast()) { if (shiftTy.getRank() != inputRank) return emitOpError("shape operand and input box ranks must match " "when there is a slice"); @@ -2373,12 +2370,12 @@ mlir::LogicalResult fir::ReboxOp::verify() { unsigned shapeRank = inputRank; if (auto shapeVal = getShape()) { auto ty = shapeVal.getType(); - if (auto shapeTy = mlir::dyn_cast(ty)) { + if (auto shapeTy = ty.dyn_cast()) { shapeRank = shapeTy.getRank(); - } else if (auto shapeShiftTy = mlir::dyn_cast(ty)) { + } else if (auto shapeShiftTy = ty.dyn_cast()) { shapeRank = shapeShiftTy.getRank(); } else { - auto shiftTy = mlir::cast(ty); + auto shiftTy = ty.cast(); shapeRank = shiftTy.getRank(); if (shapeRank != inputRank) return emitOpError("shape operand and input box ranks must match " @@ -2397,13 +2394,11 @@ mlir::LogicalResult fir::ReboxOp::verify() { // the types is a character with dynamic length, the other type can be any // character type. const bool typeCanMismatch = - mlir::isa(inputEleTy) || - mlir::isa(outEleTy) || - (mlir::isa(inputEleTy) && - mlir::isa(outEleTy)) || - (getSlice() && mlir::isa(inputEleTy)) || + inputEleTy.isa() || outEleTy.isa() || + (inputEleTy.isa() && outEleTy.isa()) || + (getSlice() && inputEleTy.isa()) || (getSlice() && fir::isa_complex(inputEleTy) && - mlir::isa(outEleTy)) || + outEleTy.isa()) || areCompatibleCharacterTypes(inputEleTy, outEleTy); if (!typeCanMismatch) return emitOpError( @@ -2440,7 +2435,7 @@ mlir::LogicalResult fir::SaveResultOp::verify() { if (fir::isa_unknown_size_box(resultType)) return emitOpError("cannot save !fir.box of unknown rank or type"); - if (mlir::isa(resultType)) { + if (resultType.isa()) { if (getShape() || !getTypeparams().empty()) return emitOpError( "must not have shape or length operands if the value is a fir.box"); @@ -2451,14 +2446,14 @@ mlir::LogicalResult fir::SaveResultOp::verify() { unsigned shapeTyRank = 0; if (auto shapeVal = getShape()) { auto shapeTy = shapeVal.getType(); - if (auto s = mlir::dyn_cast(shapeTy)) + if (auto s = shapeTy.dyn_cast()) shapeTyRank = s.getRank(); else - shapeTyRank = mlir::cast(shapeTy).getRank(); + shapeTyRank = shapeTy.cast().getRank(); } auto eleTy = resultType; - if (auto seqTy = mlir::dyn_cast(resultType)) { + if (auto seqTy = resultType.dyn_cast()) { if (seqTy.getDimension() != shapeTyRank) emitOpError("shape operand must be provided and have the value rank " "when the value is a fir.array"); @@ -2469,11 +2464,11 @@ mlir::LogicalResult fir::SaveResultOp::verify() { "shape operand should only be provided if the value is a fir.array"); } - if (auto recTy = mlir::dyn_cast(eleTy)) { + if (auto recTy = eleTy.dyn_cast()) { if (recTy.getNumLenParams() != getTypeparams().size()) emitOpError("length parameters number must match with the value type " "length parameters"); - } else if (auto charTy = mlir::dyn_cast(eleTy)) { + } else if (auto charTy = eleTy.dyn_cast()) { if (getTypeparams().size() > 1) emitOpError("no more than one length parameter must be provided for " "character value"); @@ -2513,7 +2508,7 @@ static mlir::LogicalResult verifyIntegralSwitchTerminator(OpT op) { if (op.targetOffsetSize() != count) return op.emitOpError("incorrect number of successor operand groups"); for (decltype(count) i = 0; i != count; ++i) { - if (!mlir::isa(cases[i])) + if (!cases[i].template isa()) return op.emitOpError("invalid case alternative"); } return mlir::success(); @@ -2625,7 +2620,7 @@ getMutableSuccessorOperands(unsigned pos, mlir::MutableOperandRange operands, *owner->getAttrDictionary().getNamed(offsetAttr); return getSubOperands( pos, operands, - mlir::cast(targetOffsetAttr.getValue()), + targetOffsetAttr.getValue().cast(), mlir::MutableOperandRange::OperandSegment(pos, targetOffsetAttr)); } @@ -2747,9 +2742,9 @@ mlir::ParseResult fir::SelectCaseOp::parse(mlir::OpAsmParser &parser, parser.parseComma()) return mlir::failure(); attrs.push_back(attr); - if (mlir::dyn_cast_or_null(attr)) { + if (attr.dyn_cast_or_null()) { argOffs.push_back(0); - } else if (mlir::dyn_cast_or_null(attr)) { + } else if (attr.dyn_cast_or_null()) { mlir::OpAsmParser::UnresolvedOperand oper1; mlir::OpAsmParser::UnresolvedOperand oper2; if (parser.parseOperand(oper1) || parser.parseComma() || @@ -2811,11 +2806,11 @@ void fir::SelectCaseOp::print(mlir::OpAsmPrinter &p) { if (i) p << ", "; p << cases[i] << ", "; - if (!mlir::isa(cases[i])) { + if (!cases[i].isa()) { auto caseArgs = *getCompareOperands(i); p.printOperand(*caseArgs.begin()); p << ", "; - if (mlir::isa(cases[i])) { + if (cases[i].isa()) { p.printOperand(*(++caseArgs.begin())); p << ", "; } @@ -2853,10 +2848,10 @@ void fir::SelectCaseOp::build(mlir::OpBuilder &builder, llvm::SmallVector operOffs; int32_t operSize = 0; for (auto attr : compareAttrs) { - if (mlir::isa(attr)) { + if (attr.isa()) { operOffs.push_back(2); operSize += 2; - } else if (mlir::isa(attr)) { + } else if (attr.isa()) { operOffs.push_back(0); } else { operOffs.push_back(1); @@ -2905,10 +2900,10 @@ void fir::SelectCaseOp::build(mlir::OpBuilder &builder, llvm::SmallVector cmpOpers; auto iter = cmpOpList.begin(); for (auto &attr : compareAttrs) { - if (mlir::isa(attr)) { + if (attr.isa()) { cmpOpers.push_back(mlir::ValueRange({iter, iter + 2})); iter += 2; - } else if (mlir::isa(attr)) { + } else if (attr.isa()) { cmpOpers.push_back(mlir::ValueRange{}); } else { cmpOpers.push_back(mlir::ValueRange({iter, iter + 1})); @@ -2920,8 +2915,10 @@ void fir::SelectCaseOp::build(mlir::OpBuilder &builder, } mlir::LogicalResult fir::SelectCaseOp::verify() { - if (!mlir::isa(getSelector().getType())) + if (!getSelector() + .getType() + .isa()) return emitOpError("must be an integer, character, or logical"); auto cases = getOperation()->getAttrOfType(getCasesAttr()).getValue(); @@ -2936,11 +2933,9 @@ mlir::LogicalResult fir::SelectCaseOp::verify() { return emitOpError("incorrect number of successor operand groups"); for (decltype(count) i = 0; i != count; ++i) { auto &attr = cases[i]; - if (!(mlir::isa(attr) || - mlir::isa(attr) || - mlir::isa(attr) || - mlir::isa(attr) || - mlir::isa(attr))) + if (!(attr.isa() || + attr.isa() || attr.isa() || + attr.isa() || attr.isa())) return emitOpError("incorrect select case attribute type"); } return mlir::success(); @@ -3116,14 +3111,14 @@ void fir::SelectTypeOp::print(mlir::OpAsmPrinter &p) { } mlir::LogicalResult fir::SelectTypeOp::verify() { - if (!mlir::isa(getSelector().getType())) + if (!(getSelector().getType().isa())) return emitOpError("must be a fir.class or fir.box type"); - if (auto boxType = mlir::dyn_cast(getSelector().getType())) - if (!mlir::isa(boxType.getEleTy())) + if (auto boxType = getSelector().getType().dyn_cast()) + if (!boxType.getEleTy().isa()) return emitOpError("selector must be polymorphic"); auto typeGuardAttr = getCases(); for (unsigned idx = 0; idx < typeGuardAttr.size(); ++idx) - if (mlir::isa(typeGuardAttr[idx]) && + if (typeGuardAttr[idx].isa() && idx != typeGuardAttr.size() - 1) return emitOpError("default must be the last attribute"); auto count = getNumDest(); @@ -3134,8 +3129,9 @@ mlir::LogicalResult fir::SelectTypeOp::verify() { if (targetOffsetSize() != count) return emitOpError("incorrect number of successor operand groups"); for (unsigned i = 0; i != count; ++i) { - if (!mlir::isa( - typeGuardAttr[i])) + if (!(typeGuardAttr[i].isa() || + typeGuardAttr[i].isa() || + typeGuardAttr[i].isa())) return emitOpError("invalid type-case alternative"); } return mlir::success(); @@ -3179,7 +3175,7 @@ void fir::SelectTypeOp::build(mlir::OpBuilder &builder, mlir::LogicalResult fir::ShapeOp::verify() { auto size = getExtents().size(); - auto shapeTy = mlir::dyn_cast(getType()); + auto shapeTy = getType().dyn_cast(); assert(shapeTy && "must be a shape type"); if (shapeTy.getRank() != size) return emitOpError("shape type rank mismatch"); @@ -3202,7 +3198,7 @@ mlir::LogicalResult fir::ShapeShiftOp::verify() { return emitOpError("incorrect number of args"); if (size % 2 != 0) return emitOpError("requires a multiple of 2 args"); - auto shapeTy = mlir::dyn_cast(getType()); + auto shapeTy = getType().dyn_cast(); assert(shapeTy && "must be a shape shift type"); if (shapeTy.getRank() * 2 != size) return emitOpError("shape type rank mismatch"); @@ -3215,7 +3211,7 @@ mlir::LogicalResult fir::ShapeShiftOp::verify() { mlir::LogicalResult fir::ShiftOp::verify() { auto size = getOrigins().size(); - auto shiftTy = mlir::dyn_cast(getType()); + auto shiftTy = getType().dyn_cast(); assert(shiftTy && "must be a shift type"); if (shiftTy.getRank() != size) return emitOpError("shift type rank mismatch"); @@ -3255,7 +3251,7 @@ mlir::LogicalResult fir::SliceOp::verify() { return emitOpError("incorrect number of args for triple"); if (size % 3 != 0) return emitOpError("requires a multiple of 3 args"); - auto sliceTy = mlir::dyn_cast(getType()); + auto sliceTy = getType().dyn_cast(); assert(sliceTy && "must be a slice type"); if (sliceTy.getRank() * 3 != size) return emitOpError("slice type rank mismatch"); @@ -3313,8 +3309,8 @@ void fir::StoreOp::build(mlir::OpBuilder &builder, mlir::OperationState &result, //===----------------------------------------------------------------------===// inline fir::CharacterType::KindTy stringLitOpGetKind(fir::StringLitOp op) { - auto eleTy = mlir::cast(op.getType()).getEleTy(); - return mlir::cast(eleTy).getFKind(); + auto eleTy = op.getType().cast().getEleTy(); + return eleTy.cast().getFKind(); } bool fir::StringLitOp::isWideValue() { return stringLitOpGetKind(*this) != 1; } @@ -3394,13 +3390,13 @@ mlir::ParseResult fir::StringLitOp::parse(mlir::OpAsmParser &parser, llvm::SMLoc trailingTypeLoc; if (parser.parseAttribute(val, "fake", attrs)) return mlir::failure(); - if (auto v = mlir::dyn_cast(val)) + if (auto v = val.dyn_cast()) result.attributes.push_back( builder.getNamedAttr(fir::StringLitOp::value(), v)); - else if (auto v = mlir::dyn_cast(val)) + else if (auto v = val.dyn_cast()) result.attributes.push_back( builder.getNamedAttr(fir::StringLitOp::xlist(), v)); - else if (auto v = mlir::dyn_cast(val)) + else if (auto v = val.dyn_cast()) result.attributes.push_back( builder.getNamedAttr(fir::StringLitOp::xlist(), v)); else @@ -3413,7 +3409,7 @@ mlir::ParseResult fir::StringLitOp::parse(mlir::OpAsmParser &parser, parser.parseRParen() || parser.getCurrentLocation(&trailingTypeLoc) || parser.parseColonType(type)) return mlir::failure(); - auto charTy = mlir::dyn_cast(type); + auto charTy = type.dyn_cast(); if (!charTy) return parser.emitError(trailingTypeLoc, "must have character type"); type = fir::CharacterType::get(builder.getContext(), charTy.getFKind(), @@ -3425,19 +3421,19 @@ mlir::ParseResult fir::StringLitOp::parse(mlir::OpAsmParser &parser, void fir::StringLitOp::print(mlir::OpAsmPrinter &p) { p << ' ' << getValue() << '('; - p << mlir::cast(getSize()).getValue() << ") : "; + p << getSize().cast().getValue() << ") : "; p.printType(getType()); } mlir::LogicalResult fir::StringLitOp::verify() { - if (mlir::cast(getSize()).getValue().isNegative()) + if (getSize().cast().getValue().isNegative()) return emitOpError("size must be non-negative"); if (auto xl = getOperation()->getAttr(fir::StringLitOp::xlist())) { - if (auto xList = mlir::dyn_cast(xl)) { + if (auto xList = xl.dyn_cast()) { for (auto a : xList) - if (!mlir::isa(a)) + if (!a.isa()) return emitOpError("values in initializer must be integers"); - } else if (mlir::isa(xl)) { + } else if (xl.isa()) { // do nothing } else { return emitOpError("has unexpected attribute"); @@ -3452,7 +3448,7 @@ mlir::LogicalResult fir::StringLitOp::verify() { mlir::LogicalResult fir::UnboxProcOp::verify() { if (auto eleTy = fir::dyn_cast_ptrEleTy(getRefTuple().getType())) - if (mlir::isa(eleTy)) + if (eleTy.isa()) return mlir::success(); return emitOpError("second output argument has bad type"); } @@ -3531,7 +3527,7 @@ void fir::IfOp::getEntrySuccessorRegions( void fir::IfOp::getRegionInvocationBounds( llvm::ArrayRef operands, llvm::SmallVectorImpl &invocationBounds) { - if (auto cond = mlir::dyn_cast_or_null(operands[0])) { + if (auto cond = operands[0].dyn_cast_or_null()) { // If the condition is known, then one region is known to be executed once // and the other zero times. invocationBounds.emplace_back(0, cond.getValue() ? 1 : 0); @@ -3650,8 +3646,8 @@ void fir::BoxOffsetOp::build(mlir::OpBuilder &builder, //===----------------------------------------------------------------------===// mlir::ParseResult fir::isValidCaseAttr(mlir::Attribute attr) { - if (mlir::isa(attr)) + if (attr.isa()) return mlir::success(); return mlir::failure(); } @@ -3661,9 +3657,9 @@ unsigned fir::getCaseArgumentOffset(llvm::ArrayRef cases, unsigned o = 0; for (unsigned i = 0; i < dest; ++i) { auto &attr = cases[i]; - if (!mlir::dyn_cast_or_null(attr)) { + if (!attr.dyn_cast_or_null()) { ++o; - if (mlir::dyn_cast_or_null(attr)) + if (attr.dyn_cast_or_null()) ++o; } } @@ -3726,7 +3722,7 @@ fir::GlobalOp fir::createGlobalOp(mlir::Location loc, mlir::ModuleOp module, bool fir::hasHostAssociationArgument(mlir::func::FuncOp func) { if (auto allArgAttrs = func.getAllArgAttrs()) for (auto attr : allArgAttrs) - if (auto dict = mlir::dyn_cast_or_null(attr)) + if (auto dict = attr.template dyn_cast_or_null()) if (dict.get(fir::getHostAssocAttrName())) return true; return false; @@ -3776,7 +3772,7 @@ valueCheckFirAttributes(mlir::Value value, }; // If this is a fir.box that was loaded, the fir attributes will be on the // related fir.ref creation. - if (mlir::isa(value.getType())) + if (value.getType().isa()) if (auto definingOp = value.getDefiningOp()) if (auto loadOp = mlir::dyn_cast(definingOp)) value = loadOp.getMemref(); @@ -3841,10 +3837,10 @@ bool fir::anyFuncArgsHaveAttr(mlir::func::FuncOp func, llvm::StringRef attr) { std::optional fir::getIntIfConstant(mlir::Value value) { if (auto *definingOp = value.getDefiningOp()) { if (auto cst = mlir::dyn_cast(definingOp)) - if (auto intAttr = mlir::dyn_cast(cst.getValue())) + if (auto intAttr = cst.getValue().dyn_cast()) return intAttr.getInt(); if (auto llConstOp = mlir::dyn_cast(definingOp)) - if (auto attr = mlir::dyn_cast(llConstOp.getValue())) + if (auto attr = llConstOp.getValue().dyn_cast()) return attr.getValue().getSExtValue(); } return {}; @@ -4006,15 +4002,15 @@ mlir::LogicalResult fir::CUDAKernelOp::verify() { mlir::LogicalResult fir::CUDAAllocateOp::verify() { if (getPinned() && getStream()) return emitOpError("pinned and stream cannot appears at the same time"); - if (!mlir::isa(fir::unwrapRefType(getBox().getType()))) + if (!fir::unwrapRefType(getBox().getType()).isa()) return emitOpError( "expect box to be a reference to a class or box type value"); if (getSource() && - !mlir::isa(fir::unwrapRefType(getSource().getType()))) + !fir::unwrapRefType(getSource().getType()).isa()) return emitOpError( "expect source to be a reference to/or a class or box type value"); if (getErrmsg() && - !mlir::isa(fir::unwrapRefType(getErrmsg().getType()))) + !fir::unwrapRefType(getErrmsg().getType()).isa()) return emitOpError( "expect errmsg to be a reference to/or a box type value"); if (getErrmsg() && !getHasStat()) @@ -4023,11 +4019,11 @@ mlir::LogicalResult fir::CUDAAllocateOp::verify() { } mlir::LogicalResult fir::CUDADeallocateOp::verify() { - if (!mlir::isa(fir::unwrapRefType(getBox().getType()))) + if (!fir::unwrapRefType(getBox().getType()).isa()) return emitOpError( "expect box to be a reference to class or box type value"); if (getErrmsg() && - !mlir::isa(fir::unwrapRefType(getErrmsg().getType()))) + !fir::unwrapRefType(getErrmsg().getType()).isa()) return emitOpError( "expect errmsg to be a reference to/or a box type value"); if (getErrmsg() && !getHasStat()) diff --git a/flang/lib/Optimizer/Dialect/FIRType.cpp b/flang/lib/Optimizer/Dialect/FIRType.cpp index 38a6a09d1808a..5c4cad6d20834 100644 --- a/flang/lib/Optimizer/Dialect/FIRType.cpp +++ b/flang/lib/Optimizer/Dialect/FIRType.cpp @@ -61,13 +61,14 @@ TYPE parseTypeSingleton(mlir::AsmParser &parser) { /// Is `ty` a standard or FIR integer type? static bool isaIntegerType(mlir::Type ty) { // TODO: why aren't we using isa_integer? investigatation required. - return mlir::isa(ty); + return ty.isa() || ty.isa(); } bool verifyRecordMemberType(mlir::Type ty) { - return !mlir::isa( - ty); + return !(ty.isa() || ty.isa() || + ty.isa() || ty.isa() || + ty.isa() || ty.isa() || ty.isa() || + ty.isa() || ty.isa()); } bool verifySameLists(llvm::ArrayRef a1, @@ -193,7 +194,7 @@ bool isa_std_type(mlir::Type t) { } bool isa_fir_or_std_type(mlir::Type t) { - if (auto funcType = mlir::dyn_cast(t)) + if (auto funcType = t.dyn_cast()) return llvm::all_of(funcType.getInputs(), isa_fir_or_std_type) && llvm::all_of(funcType.getResults(), isa_fir_or_std_type); return isa_fir_type(t) || isa_std_type(t); @@ -202,7 +203,7 @@ bool isa_fir_or_std_type(mlir::Type t) { mlir::Type getDerivedType(mlir::Type ty) { return llvm::TypeSwitch(ty) .Case([](auto p) { - if (auto seq = mlir::dyn_cast(p.getEleTy())) + if (auto seq = p.getEleTy().template dyn_cast()) return seq.getEleTy(); return p.getEleTy(); }) @@ -227,12 +228,12 @@ mlir::Type dyn_cast_ptrOrBoxEleTy(mlir::Type t) { static bool hasDynamicSize(fir::RecordType recTy) { for (auto field : recTy.getTypeList()) { - if (auto arr = mlir::dyn_cast(field.second)) { + if (auto arr = field.second.dyn_cast()) { if (sequenceWithNonConstantShape(arr)) return true; } else if (characterWithDynamicLen(field.second)) { return true; - } else if (auto rec = mlir::dyn_cast(field.second)) { + } else if (auto rec = field.second.dyn_cast()) { if (hasDynamicSize(rec)) return true; } @@ -241,14 +242,14 @@ static bool hasDynamicSize(fir::RecordType recTy) { } bool hasDynamicSize(mlir::Type t) { - if (auto arr = mlir::dyn_cast(t)) { + if (auto arr = t.dyn_cast()) { if (sequenceWithNonConstantShape(arr)) return true; t = arr.getEleTy(); } if (characterWithDynamicLen(t)) return true; - if (auto rec = mlir::dyn_cast(t)) + if (auto rec = t.dyn_cast()) return hasDynamicSize(rec); return false; } @@ -268,33 +269,33 @@ mlir::Type extractSequenceType(mlir::Type ty) { bool isPointerType(mlir::Type ty) { if (auto refTy = fir::dyn_cast_ptrEleTy(ty)) ty = refTy; - if (auto boxTy = mlir::dyn_cast(ty)) - return mlir::isa(boxTy.getEleTy()); + if (auto boxTy = ty.dyn_cast()) + return boxTy.getEleTy().isa(); return false; } bool isAllocatableType(mlir::Type ty) { if (auto refTy = fir::dyn_cast_ptrEleTy(ty)) ty = refTy; - if (auto boxTy = mlir::dyn_cast(ty)) - return mlir::isa(boxTy.getEleTy()); + if (auto boxTy = ty.dyn_cast()) + return boxTy.getEleTy().isa(); return false; } bool isBoxNone(mlir::Type ty) { - if (auto box = mlir::dyn_cast(ty)) - return mlir::isa(box.getEleTy()); + if (auto box = ty.dyn_cast()) + return box.getEleTy().isa(); return false; } bool isBoxedRecordType(mlir::Type ty) { if (auto refTy = fir::dyn_cast_ptrEleTy(ty)) ty = refTy; - if (auto boxTy = mlir::dyn_cast(ty)) { - if (mlir::isa(boxTy.getEleTy())) + if (auto boxTy = ty.dyn_cast()) { + if (boxTy.getEleTy().isa()) return true; mlir::Type innerType = boxTy.unwrapInnerType(); - return innerType && mlir::isa(innerType); + return innerType && innerType.isa(); } return false; } @@ -302,13 +303,13 @@ bool isBoxedRecordType(mlir::Type ty) { bool isScalarBoxedRecordType(mlir::Type ty) { if (auto refTy = fir::dyn_cast_ptrEleTy(ty)) ty = refTy; - if (auto boxTy = mlir::dyn_cast(ty)) { - if (mlir::isa(boxTy.getEleTy())) + if (auto boxTy = ty.dyn_cast()) { + if (boxTy.getEleTy().isa()) return true; - if (auto heapTy = mlir::dyn_cast(boxTy.getEleTy())) - return mlir::isa(heapTy.getEleTy()); - if (auto ptrTy = mlir::dyn_cast(boxTy.getEleTy())) - return mlir::isa(ptrTy.getEleTy()); + if (auto heapTy = boxTy.getEleTy().dyn_cast()) + return heapTy.getEleTy().isa(); + if (auto ptrTy = boxTy.getEleTy().dyn_cast()) + return ptrTy.getEleTy().isa(); } return false; } @@ -362,10 +363,10 @@ bool isPolymorphicType(mlir::Type ty) { bool isUnlimitedPolymorphicType(mlir::Type ty) { // CLASS(*) if (auto clTy = mlir::dyn_cast(fir::unwrapRefType(ty))) { - if (mlir::isa(clTy.getEleTy())) + if (clTy.getEleTy().isa()) return true; mlir::Type innerType = clTy.unwrapInnerType(); - return innerType && mlir::isa(innerType); + return innerType && innerType.isa(); } // TYPE(*) return isAssumedType(ty); @@ -375,7 +376,7 @@ mlir::Type unwrapInnerType(mlir::Type ty) { return llvm::TypeSwitch(ty) .Case([](auto t) { mlir::Type eleTy = t.getEleTy(); - if (auto seqTy = mlir::dyn_cast(eleTy)) + if (auto seqTy = eleTy.dyn_cast()) return seqTy.getEleTy(); return eleTy; }) @@ -384,14 +385,13 @@ mlir::Type unwrapInnerType(mlir::Type ty) { } bool isRecordWithAllocatableMember(mlir::Type ty) { - if (auto recTy = mlir::dyn_cast(ty)) + if (auto recTy = ty.dyn_cast()) for (auto [field, memTy] : recTy.getTypeList()) { if (fir::isAllocatableType(memTy)) return true; // A record type cannot recursively include itself as a direct member. // There must be an intervening `ptr` type, so recursion is safe here. - if (mlir::isa(memTy) && - isRecordWithAllocatableMember(memTy)) + if (memTy.isa() && isRecordWithAllocatableMember(memTy)) return true; } return false; @@ -399,12 +399,11 @@ bool isRecordWithAllocatableMember(mlir::Type ty) { bool isRecordWithDescriptorMember(mlir::Type ty) { ty = unwrapSequenceType(ty); - if (auto recTy = mlir::dyn_cast(ty)) + if (auto recTy = ty.dyn_cast()) for (auto [field, memTy] : recTy.getTypeList()) { if (mlir::isa(memTy)) return true; - if (mlir::isa(memTy) && - isRecordWithDescriptorMember(memTy)) + if (memTy.isa() && isRecordWithDescriptorMember(memTy)) return true; } return false; @@ -413,7 +412,7 @@ bool isRecordWithDescriptorMember(mlir::Type ty) { mlir::Type unwrapAllRefAndSeqType(mlir::Type ty) { while (true) { mlir::Type nt = unwrapSequenceType(unwrapRefType(ty)); - if (auto vecTy = mlir::dyn_cast(nt)) + if (auto vecTy = nt.dyn_cast()) nt = vecTy.getEleTy(); if (nt == ty) return ty; @@ -422,11 +421,11 @@ mlir::Type unwrapAllRefAndSeqType(mlir::Type ty) { } mlir::Type unwrapSeqOrBoxedSeqType(mlir::Type ty) { - if (auto seqTy = mlir::dyn_cast(ty)) + if (auto seqTy = ty.dyn_cast()) return seqTy.getEleTy(); - if (auto boxTy = mlir::dyn_cast(ty)) { + if (auto boxTy = ty.dyn_cast()) { auto eleTy = unwrapRefType(boxTy.getEleTy()); - if (auto seqTy = mlir::dyn_cast(eleTy)) + if (auto seqTy = eleTy.dyn_cast()) return seqTy.getEleTy(); } return ty; @@ -434,7 +433,7 @@ mlir::Type unwrapSeqOrBoxedSeqType(mlir::Type ty) { unsigned getBoxRank(mlir::Type boxTy) { auto eleTy = fir::dyn_cast_ptrOrBoxEleTy(boxTy); - if (auto seqTy = mlir::dyn_cast(eleTy)) + if (auto seqTy = eleTy.dyn_cast()) return seqTy.getDimension(); return 0; } @@ -442,7 +441,7 @@ unsigned getBoxRank(mlir::Type boxTy) { /// Return the ISO_C_BINDING intrinsic module value of type \p ty. int getTypeCode(mlir::Type ty, const fir::KindMapping &kindMap) { unsigned width = 0; - if (mlir::IntegerType intTy = mlir::dyn_cast(ty)) { + if (mlir::IntegerType intTy = ty.dyn_cast()) { switch (intTy.getWidth()) { case 8: return CFI_type_int8_t; @@ -457,7 +456,7 @@ int getTypeCode(mlir::Type ty, const fir::KindMapping &kindMap) { } llvm_unreachable("unsupported integer type"); } - if (fir::LogicalType logicalTy = mlir::dyn_cast(ty)) { + if (fir::LogicalType logicalTy = ty.dyn_cast()) { switch (kindMap.getLogicalBitsize(logicalTy.getFKind())) { case 8: return CFI_type_Bool; @@ -470,7 +469,7 @@ int getTypeCode(mlir::Type ty, const fir::KindMapping &kindMap) { } llvm_unreachable("unsupported logical type"); } - if (mlir::FloatType floatTy = mlir::dyn_cast(ty)) { + if (mlir::FloatType floatTy = ty.dyn_cast()) { switch (floatTy.getWidth()) { case 16: return floatTy.isBF16() ? CFI_type_bfloat : CFI_type_half_float; @@ -486,14 +485,13 @@ int getTypeCode(mlir::Type ty, const fir::KindMapping &kindMap) { llvm_unreachable("unsupported real type"); } if (fir::isa_complex(ty)) { - if (mlir::ComplexType complexTy = mlir::dyn_cast(ty)) { + if (mlir::ComplexType complexTy = ty.dyn_cast()) { mlir::FloatType floatTy = - mlir::cast(complexTy.getElementType()); + complexTy.getElementType().cast(); if (floatTy.isBF16()) return CFI_type_bfloat_Complex; width = floatTy.getWidth(); - } else if (fir::ComplexType complexTy = - mlir::dyn_cast(ty)) { + } else if (fir::ComplexType complexTy = ty.dyn_cast()) { auto FKind = complexTy.getFKind(); if (FKind == 3) return CFI_type_bfloat_Complex; @@ -513,7 +511,7 @@ int getTypeCode(mlir::Type ty, const fir::KindMapping &kindMap) { } llvm_unreachable("unsupported complex size"); } - if (fir::CharacterType charTy = mlir::dyn_cast(ty)) { + if (fir::CharacterType charTy = ty.dyn_cast()) { switch (kindMap.getCharacterBitsize(charTy.getFKind())) { case 8: return CFI_type_char; @@ -526,7 +524,7 @@ int getTypeCode(mlir::Type ty, const fir::KindMapping &kindMap) { } if (fir::isa_ref_type(ty)) return CFI_type_cptr; - if (mlir::isa(ty)) + if (ty.isa()) return CFI_type_struct; llvm_unreachable("unsupported type"); } @@ -544,12 +542,12 @@ std::string getTypeAsString(mlir::Type ty, const fir::KindMapping &kindMap, name << "idx"; } else if (ty.isIntOrIndex()) { name << 'i' << ty.getIntOrFloatBitWidth(); - } else if (mlir::isa(ty)) { + } else if (ty.isa()) { name << 'f' << ty.getIntOrFloatBitWidth(); } else if (fir::isa_complex(ty)) { name << 'z'; if (auto cplxTy = mlir::dyn_cast_or_null(ty)) { - auto floatTy = mlir::cast(cplxTy.getElementType()); + auto floatTy = cplxTy.getElementType().cast(); name << floatTy.getWidth(); } else if (auto cplxTy = mlir::dyn_cast_or_null(ty)) { name << kindMap.getRealBitsize(cplxTy.getFKind()); @@ -646,7 +644,7 @@ static llvm::SmallPtrSet } // namespace void fir::verifyIntegralType(mlir::Type type) { - if (isaIntegerType(type) || mlir::isa(type)) + if (isaIntegerType(type) || type.isa()) return; llvm::report_fatal_error("expected integral type"); } @@ -658,9 +656,9 @@ void fir::printFirType(FIROpsDialect *, mlir::Type ty, } bool fir::isa_unknown_size_box(mlir::Type t) { - if (auto boxTy = mlir::dyn_cast(t)) { + if (auto boxTy = t.dyn_cast()) { auto valueType = fir::unwrapPassByRefType(boxTy); - if (auto seqTy = mlir::dyn_cast(valueType)) + if (auto seqTy = valueType.dyn_cast()) if (seqTy.hasUnknownShape()) return true; } @@ -686,10 +684,10 @@ void fir::BoxProcType::print(mlir::AsmPrinter &printer) const { mlir::LogicalResult BoxProcType::verify(llvm::function_ref emitError, mlir::Type eleTy) { - if (mlir::isa(eleTy)) + if (eleTy.isa()) return mlir::success(); - if (auto refTy = mlir::dyn_cast(eleTy)) - if (mlir::isa(refTy)) + if (auto refTy = eleTy.dyn_cast()) + if (refTy.isa()) return mlir::success(); return emitError() << "invalid type for boxproc" << eleTy << '\n'; } @@ -707,7 +705,7 @@ static bool cannotBePointerOrHeapElementType(mlir::Type eleTy) { mlir::LogicalResult fir::BoxType::verify(llvm::function_ref emitError, mlir::Type eleTy) { - if (mlir::isa(eleTy)) + if (eleTy.isa()) return emitError() << "invalid element type\n"; // TODO return mlir::success(); @@ -1238,10 +1236,10 @@ bool fir::VectorType::isValidElementType(mlir::Type t) { } bool fir::isCharacterProcedureTuple(mlir::Type ty, bool acceptRawFunc) { - mlir::TupleType tuple = mlir::dyn_cast(ty); + mlir::TupleType tuple = ty.dyn_cast(); return tuple && tuple.size() == 2 && - (mlir::isa(tuple.getType(0)) || - (acceptRawFunc && mlir::isa(tuple.getType(0)))) && + (tuple.getType(0).isa() || + (acceptRawFunc && tuple.getType(0).isa())) && fir::isa_integer(tuple.getType(1)); } @@ -1249,8 +1247,7 @@ bool fir::hasAbstractResult(mlir::FunctionType ty) { if (ty.getNumResults() == 0) return false; auto resultType = ty.getResult(0); - return mlir::isa( - resultType); + return resultType.isa(); } /// Convert llvm::Type::TypeID to mlir::Type. \p kind is provided for error diff --git a/flang/lib/Optimizer/Dialect/FortranVariableInterface.cpp b/flang/lib/Optimizer/Dialect/FortranVariableInterface.cpp index 70b1a2f3d8446..94f1689dfb058 100644 --- a/flang/lib/Optimizer/Dialect/FortranVariableInterface.cpp +++ b/flang/lib/Optimizer/Dialect/FortranVariableInterface.cpp @@ -18,7 +18,7 @@ mlir::LogicalResult fir::FortranVariableOpInterface::verifyDeclareLikeOpImpl(mlir::Value memref) { const unsigned numExplicitTypeParams = getExplicitTypeParams().size(); mlir::Type memType = memref.getType(); - const bool sourceIsBoxValue = mlir::isa(memType); + const bool sourceIsBoxValue = memType.isa(); const bool sourceIsBoxAddress = fir::isBoxAddress(memType); const bool sourceIsBox = sourceIsBoxValue || sourceIsBoxAddress; if (isCharacter()) { @@ -29,8 +29,7 @@ fir::FortranVariableOpInterface::verifyDeclareLikeOpImpl(mlir::Value memref) { return emitOpError("must be provided exactly one type parameter when its " "base is a character that is not a box"); - } else if (auto recordType = - mlir::dyn_cast(getElementType())) { + } else if (auto recordType = getElementType().dyn_cast()) { if (numExplicitTypeParams < recordType.getNumLenParams() && !sourceIsBox) return emitOpError("must be provided all the derived type length " "parameters when the base is not a box"); @@ -46,16 +45,16 @@ fir::FortranVariableOpInterface::verifyDeclareLikeOpImpl(mlir::Value memref) { if (sourceIsBoxAddress) return emitOpError("for box address must not have a shape operand"); unsigned shapeRank = 0; - if (auto shapeType = mlir::dyn_cast(shape.getType())) { + if (auto shapeType = shape.getType().dyn_cast()) { shapeRank = shapeType.getRank(); } else if (auto shapeShiftType = - mlir::dyn_cast(shape.getType())) { + shape.getType().dyn_cast()) { shapeRank = shapeShiftType.getRank(); } else { if (!sourceIsBoxValue) emitOpError("of array entity with a raw address base must have a " "shape operand that is a shape or shapeshift"); - shapeRank = mlir::cast(shape.getType()).getRank(); + shapeRank = shape.getType().cast().getRank(); } std::optional rank = getRank(); diff --git a/flang/lib/Optimizer/HLFIR/IR/HLFIRDialect.cpp b/flang/lib/Optimizer/HLFIR/IR/HLFIRDialect.cpp index 0b61c0edce622..08b2b0538c732 100644 --- a/flang/lib/Optimizer/HLFIR/IR/HLFIRDialect.cpp +++ b/flang/lib/Optimizer/HLFIR/IR/HLFIRDialect.cpp @@ -84,8 +84,7 @@ bool hlfir::isFortranVariableType(mlir::Type type) { return llvm::TypeSwitch(type) .Case([](auto p) { mlir::Type eleType = p.getEleTy(); - return mlir::isa(eleType) || - !fir::hasDynamicSize(eleType); + return eleType.isa() || !fir::hasDynamicSize(eleType); }) .Case([](auto) { return true; }) .Case([](auto) { return true; }) @@ -94,15 +93,15 @@ bool hlfir::isFortranVariableType(mlir::Type type) { bool hlfir::isFortranScalarCharacterType(mlir::Type type) { return isFortranScalarCharacterExprType(type) || - mlir::isa(type) || - mlir::isa( - fir::unwrapPassByRefType(fir::unwrapRefType(type))); + type.isa() || + fir::unwrapPassByRefType(fir::unwrapRefType(type)) + .isa(); } bool hlfir::isFortranScalarCharacterExprType(mlir::Type type) { - if (auto exprType = mlir::dyn_cast(type)) + if (auto exprType = type.dyn_cast()) return exprType.isScalar() && - mlir::isa(exprType.getElementType()); + exprType.getElementType().isa(); return false; } @@ -122,8 +121,8 @@ bool hlfir::isFortranScalarNumericalType(mlir::Type type) { bool hlfir::isFortranNumericalArrayObject(mlir::Type type) { if (isBoxAddressType(type)) return false; - if (auto arrayTy = mlir::dyn_cast( - getFortranElementOrSequenceType(type))) + if (auto arrayTy = + getFortranElementOrSequenceType(type).dyn_cast()) return isFortranScalarNumericalType(arrayTy.getEleTy()); return false; } @@ -131,8 +130,8 @@ bool hlfir::isFortranNumericalArrayObject(mlir::Type type) { bool hlfir::isFortranNumericalOrLogicalArrayObject(mlir::Type type) { if (isBoxAddressType(type)) return false; - if (auto arrayTy = mlir::dyn_cast( - getFortranElementOrSequenceType(type))) { + if (auto arrayTy = + getFortranElementOrSequenceType(type).dyn_cast()) { mlir::Type eleTy = arrayTy.getEleTy(); return isFortranScalarNumericalType(eleTy) || mlir::isa(eleTy); @@ -143,8 +142,7 @@ bool hlfir::isFortranNumericalOrLogicalArrayObject(mlir::Type type) { bool hlfir::isFortranArrayObject(mlir::Type type) { if (isBoxAddressType(type)) return false; - return !!mlir::dyn_cast( - getFortranElementOrSequenceType(type)); + return !!getFortranElementOrSequenceType(type).dyn_cast(); } bool hlfir::isPassByRefOrIntegerType(mlir::Type type) { @@ -153,7 +151,7 @@ bool hlfir::isPassByRefOrIntegerType(mlir::Type type) { } bool hlfir::isI1Type(mlir::Type type) { - if (mlir::IntegerType integer = mlir::dyn_cast(type)) + if (mlir::IntegerType integer = type.dyn_cast()) if (integer.getWidth() == 1) return true; return false; @@ -162,8 +160,8 @@ bool hlfir::isI1Type(mlir::Type type) { bool hlfir::isFortranLogicalArrayObject(mlir::Type type) { if (isBoxAddressType(type)) return false; - if (auto arrayTy = mlir::dyn_cast( - getFortranElementOrSequenceType(type))) { + if (auto arrayTy = + getFortranElementOrSequenceType(type).dyn_cast()) { mlir::Type eleTy = arrayTy.getEleTy(); return mlir::isa(eleTy); } diff --git a/flang/lib/Optimizer/HLFIR/IR/HLFIROps.cpp b/flang/lib/Optimizer/HLFIR/IR/HLFIROps.cpp index 0d62ca4954e6b..8bad4e445082d 100644 --- a/flang/lib/Optimizer/HLFIR/IR/HLFIROps.cpp +++ b/flang/lib/Optimizer/HLFIR/IR/HLFIROps.cpp @@ -74,8 +74,8 @@ getIntrinsicEffects(mlir::Operation *self, /// Is this a fir.[ref/ptr/heap]>> type? static bool isAllocatableBoxRef(mlir::Type type) { fir::BaseBoxType boxType = - mlir::dyn_cast_or_null(fir::dyn_cast_ptrEleTy(type)); - return boxType && mlir::isa(boxType.getEleTy()); + fir::dyn_cast_ptrEleTy(type).dyn_cast_or_null(); + return boxType && boxType.getEleTy().isa(); } mlir::LogicalResult hlfir::AssignOp::verify() { @@ -84,7 +84,7 @@ mlir::LogicalResult hlfir::AssignOp::verify() { return emitOpError("lhs must be an allocatable when `realloc` is set"); if (mustKeepLhsLengthInAllocatableAssignment() && !(isAllocatableAssignment() && - mlir::isa(hlfir::getFortranElementType(lhsType)))) + hlfir::getFortranElementType(lhsType).isa())) return emitOpError("`realloc` must be set and lhs must be a character " "allocatable when `keep_lhs_length_if_realloc` is set"); return mlir::success(); @@ -99,13 +99,13 @@ mlir::LogicalResult hlfir::AssignOp::verify() { mlir::Type hlfir::DeclareOp::getHLFIRVariableType(mlir::Type inputType, bool hasExplicitLowerBounds) { mlir::Type type = fir::unwrapRefType(inputType); - if (mlir::isa(type)) + if (type.isa()) return inputType; - if (auto charType = mlir::dyn_cast(type)) + if (auto charType = type.dyn_cast()) if (charType.hasDynamicLen()) return fir::BoxCharType::get(charType.getContext(), charType.getFKind()); - auto seqType = mlir::dyn_cast(type); + auto seqType = type.dyn_cast(); bool hasDynamicExtents = seqType && fir::sequenceWithNonConstantShape(seqType); mlir::Type eleType = seqType ? seqType.getEleTy() : type; @@ -117,8 +117,7 @@ mlir::Type hlfir::DeclareOp::getHLFIRVariableType(mlir::Type inputType, } static bool hasExplicitLowerBounds(mlir::Value shape) { - return shape && - mlir::isa(shape.getType()); + return shape && shape.getType().isa(); } void hlfir::DeclareOp::build(mlir::OpBuilder &builder, @@ -289,7 +288,7 @@ mlir::LogicalResult hlfir::DesignateOp::verify() { bool hasBoxComponent; if (getComponent()) { auto component = getComponent().value(); - auto recType = mlir::dyn_cast(baseElementType); + auto recType = baseElementType.dyn_cast(); if (!recType) return emitOpError( "component must be provided only when the memref is a derived type"); @@ -301,14 +300,14 @@ mlir::LogicalResult hlfir::DesignateOp::verify() { } mlir::Type fieldType = recType.getType(fieldIdx); mlir::Type componentBaseType = getFortranElementOrSequenceType(fieldType); - hasBoxComponent = mlir::isa(fieldType); - if (mlir::isa(componentBaseType) && - mlir::isa(baseType) && + hasBoxComponent = fieldType.isa(); + if (componentBaseType.isa() && + baseType.isa() && (numSubscripts == 0 || subscriptsRank > 0)) return emitOpError("indices must be provided and must not contain " "triplets when both memref and component are arrays"); if (numSubscripts != 0) { - if (!mlir::isa(componentBaseType)) + if (!componentBaseType.isa()) return emitOpError("indices must not be provided if component appears " "and is not an array component"); if (!getComponentShape()) @@ -316,9 +315,9 @@ mlir::LogicalResult hlfir::DesignateOp::verify() { "component_shape must be provided when indexing a component"); mlir::Type compShapeType = getComponentShape().getType(); unsigned componentRank = - mlir::cast(componentBaseType).getDimension(); - auto shapeType = mlir::dyn_cast(compShapeType); - auto shapeShiftType = mlir::dyn_cast(compShapeType); + componentBaseType.cast().getDimension(); + auto shapeType = compShapeType.dyn_cast(); + auto shapeShiftType = compShapeType.dyn_cast(); if (!((shapeType && shapeType.getRank() == componentRank) || (shapeShiftType && shapeShiftType.getRank() == componentRank))) return emitOpError("component_shape must be a fir.shape or " @@ -326,33 +325,33 @@ mlir::LogicalResult hlfir::DesignateOp::verify() { if (numSubscripts > componentRank) return emitOpError("indices number must match array component rank"); } - if (auto baseSeqType = mlir::dyn_cast(baseType)) + if (auto baseSeqType = baseType.dyn_cast()) // This case must come first to cover "array%array_comp(i, j)" that has // subscripts for the component but whose rank come from the base. outputRank = baseSeqType.getDimension(); else if (numSubscripts != 0) outputRank = subscriptsRank; else if (auto componentSeqType = - mlir::dyn_cast(componentBaseType)) + componentBaseType.dyn_cast()) outputRank = componentSeqType.getDimension(); outputElementType = fir::unwrapSequenceType(componentBaseType); } else { outputElementType = baseElementType; unsigned baseTypeRank = - mlir::isa(baseType) - ? mlir::cast(baseType).getDimension() + baseType.isa() + ? baseType.cast().getDimension() : 0; if (numSubscripts != 0) { if (baseTypeRank != numSubscripts) return emitOpError("indices number must match memref rank"); outputRank = subscriptsRank; - } else if (auto baseSeqType = mlir::dyn_cast(baseType)) { + } else if (auto baseSeqType = baseType.dyn_cast()) { outputRank = baseSeqType.getDimension(); } } if (!getSubstring().empty()) { - if (!mlir::isa(outputElementType)) + if (!outputElementType.isa()) return emitOpError("memref or component must have character type if " "substring indices are provided"); if (getSubstring().size() != 2) @@ -362,16 +361,16 @@ mlir::LogicalResult hlfir::DesignateOp::verify() { if (!fir::isa_complex(outputElementType)) return emitOpError("memref or component must have complex type if " "complex_part is provided"); - if (auto firCplx = mlir::dyn_cast(outputElementType)) + if (auto firCplx = outputElementType.dyn_cast()) outputElementType = firCplx.getElementType(); else outputElementType = - mlir::cast(outputElementType).getElementType(); + outputElementType.cast().getElementType(); } mlir::Type resultBaseType = getFortranElementOrSequenceType(getResult().getType()); unsigned resultRank = 0; - if (auto resultSeqType = mlir::dyn_cast(resultBaseType)) + if (auto resultSeqType = resultBaseType.dyn_cast()) resultRank = resultSeqType.getDimension(); if (resultRank != outputRank) return emitOpError("result type rank is not consistent with operands, " @@ -381,10 +380,10 @@ mlir::LogicalResult hlfir::DesignateOp::verify() { // result type must match the one that was inferred here, except the character // length may differ because of substrings. if (resultElementType != outputElementType && - !(mlir::isa(resultElementType) && - mlir::isa(outputElementType)) && - !(mlir::isa(resultElementType) && - mlir::isa(outputElementType))) + !(resultElementType.isa() && + outputElementType.isa()) && + !(resultElementType.isa() && + outputElementType.isa())) return emitOpError( "result element type is not consistent with operands, expected ") << outputElementType; @@ -402,22 +401,22 @@ mlir::LogicalResult hlfir::DesignateOp::verify() { return emitOpError("shape must be provided if and only if the result is " "an array that is not a box address"); if (resultRank != 0) { - auto shapeType = mlir::dyn_cast(getShape().getType()); + auto shapeType = getShape().getType().dyn_cast(); auto shapeShiftType = - mlir::dyn_cast(getShape().getType()); + getShape().getType().dyn_cast(); if (!((shapeType && shapeType.getRank() == resultRank) || (shapeShiftType && shapeShiftType.getRank() == resultRank))) return emitOpError("shape must be a fir.shape or fir.shapeshift with " "the rank of the result"); } auto numLenParam = getTypeparams().size(); - if (mlir::isa(outputElementType)) { + if (outputElementType.isa()) { if (numLenParam != 1) return emitOpError("must be provided one length parameter when the " "result is a character"); } else if (fir::isRecordWithTypeParameters(outputElementType)) { if (numLenParam != - mlir::cast(outputElementType).getNumLenParams()) + outputElementType.cast().getNumLenParams()) return emitOpError("must be provided the same number of length " "parameters as in the result derived type"); } else if (numLenParam != 0) { @@ -435,18 +434,18 @@ mlir::LogicalResult hlfir::DesignateOp::verify() { mlir::LogicalResult hlfir::ParentComponentOp::verify() { mlir::Type baseType = hlfir::getFortranElementOrSequenceType(getMemref().getType()); - auto maybeInputSeqType = mlir::dyn_cast(baseType); + auto maybeInputSeqType = baseType.dyn_cast(); unsigned inputTypeRank = maybeInputSeqType ? maybeInputSeqType.getDimension() : 0; unsigned shapeRank = 0; if (mlir::Value shape = getShape()) - if (auto shapeType = mlir::dyn_cast(shape.getType())) + if (auto shapeType = shape.getType().dyn_cast()) shapeRank = shapeType.getRank(); if (inputTypeRank != shapeRank) return emitOpError( "must be provided a shape if and only if the base is an array"); mlir::Type outputBaseType = hlfir::getFortranElementOrSequenceType(getType()); - auto maybeOutputSeqType = mlir::dyn_cast(outputBaseType); + auto maybeOutputSeqType = outputBaseType.dyn_cast(); unsigned outputTypeRank = maybeOutputSeqType ? maybeOutputSeqType.getDimension() : 0; if (inputTypeRank != outputTypeRank) @@ -460,23 +459,23 @@ mlir::LogicalResult hlfir::ParentComponentOp::verify() { return emitOpError( "result type extents are inconsistent with memref type"); fir::RecordType baseRecType = - mlir::dyn_cast(hlfir::getFortranElementType(baseType)); - fir::RecordType outRecType = mlir::dyn_cast( - hlfir::getFortranElementType(outputBaseType)); + hlfir::getFortranElementType(baseType).dyn_cast(); + fir::RecordType outRecType = + hlfir::getFortranElementType(outputBaseType).dyn_cast(); if (!baseRecType || !outRecType) return emitOpError("result type and input type must be derived types"); // Note: result should not be a fir.class: its dynamic type is being set to // the parent type and allowing fir.class would break the operation codegen: // it would keep the input dynamic type. - if (mlir::isa(getType())) + if (getType().isa()) return emitOpError("result type must not be polymorphic"); // The array results are known to not be dis-contiguous in most cases (the // exception being if the parent type was extended by a type without any // components): require a fir.box to be used for the result to carry the // strides. - if (!mlir::isa(getType()) && + if (!getType().isa() && (outputTypeRank != 0 || fir::isRecordWithTypeParameters(outRecType))) return emitOpError("result type must be a fir.box if the result is an " "array or has length parameters"); @@ -497,8 +496,9 @@ verifyLogicalReductionOp(LogicalReductionOp reductionOp) { mlir::Value mask = reductionOp->getMask(); mlir::Value dim = reductionOp->getDim(); - fir::SequenceType maskTy = mlir::cast( - hlfir::getFortranElementOrSequenceType(mask.getType())); + fir::SequenceType maskTy = + hlfir::getFortranElementOrSequenceType(mask.getType()) + .cast(); mlir::Type logicalTy = maskTy.getEleTy(); llvm::ArrayRef maskShape = maskTy.getShape(); @@ -576,8 +576,9 @@ mlir::LogicalResult hlfir::CountOp::verify() { mlir::Value mask = getMask(); mlir::Value dim = getDim(); - fir::SequenceType maskTy = mlir::cast( - hlfir::getFortranElementOrSequenceType(mask.getType())); + fir::SequenceType maskTy = + hlfir::getFortranElementOrSequenceType(mask.getType()) + .cast(); llvm::ArrayRef maskShape = maskTy.getShape(); mlir::Type resultType = results[0]; @@ -612,14 +613,13 @@ void hlfir::CountOp::getEffects( //===----------------------------------------------------------------------===// static unsigned getCharacterKind(mlir::Type t) { - return mlir::cast(hlfir::getFortranElementType(t)) - .getFKind(); + return hlfir::getFortranElementType(t).cast().getFKind(); } static std::optional getCharacterLengthIfStatic(mlir::Type t) { if (auto charType = - mlir::dyn_cast(hlfir::getFortranElementType(t))) + hlfir::getFortranElementType(t).dyn_cast()) if (charType.hasConstantLen()) return charType.getLen(); return std::nullopt; @@ -672,13 +672,15 @@ verifyArrayAndMaskForReductionOp(NumericalReductionOp reductionOp) { mlir::Value array = reductionOp->getArray(); mlir::Value mask = reductionOp->getMask(); - fir::SequenceType arrayTy = mlir::cast( - hlfir::getFortranElementOrSequenceType(array.getType())); + fir::SequenceType arrayTy = + hlfir::getFortranElementOrSequenceType(array.getType()) + .cast(); llvm::ArrayRef arrayShape = arrayTy.getShape(); if (mask) { - fir::SequenceType maskSeq = mlir::dyn_cast( - hlfir::getFortranElementOrSequenceType(mask.getType())); + fir::SequenceType maskSeq = + hlfir::getFortranElementOrSequenceType(mask.getType()) + .dyn_cast(); llvm::ArrayRef maskShape; if (maskSeq) @@ -718,8 +720,9 @@ verifyNumericalReductionOp(NumericalReductionOp reductionOp) { mlir::Value array = reductionOp->getArray(); mlir::Value dim = reductionOp->getDim(); - fir::SequenceType arrayTy = mlir::cast( - hlfir::getFortranElementOrSequenceType(array.getType())); + fir::SequenceType arrayTy = + hlfir::getFortranElementOrSequenceType(array.getType()) + .cast(); mlir::Type numTy = arrayTy.getEleTy(); llvm::ArrayRef arrayShape = arrayTy.getShape(); @@ -787,12 +790,13 @@ verifyCharacterReductionOp(CharacterReductionOp reductionOp) { mlir::Value array = reductionOp->getArray(); mlir::Value dim = reductionOp->getDim(); - fir::SequenceType arrayTy = mlir::cast( - hlfir::getFortranElementOrSequenceType(array.getType())); + fir::SequenceType arrayTy = + hlfir::getFortranElementOrSequenceType(array.getType()) + .cast(); mlir::Type numTy = arrayTy.getEleTy(); llvm::ArrayRef arrayShape = arrayTy.getShape(); - auto resultExpr = mlir::cast(results[0]); + auto resultExpr = results[0].cast(); mlir::Type resultType = resultExpr.getEleTy(); assert(mlir::isa(resultType) && "result must be character"); @@ -877,8 +881,9 @@ verifyResultForMinMaxLoc(NumericalReductionOp reductionOp) { mlir::Value array = reductionOp->getArray(); mlir::Value dim = reductionOp->getDim(); - fir::SequenceType arrayTy = mlir::cast( - hlfir::getFortranElementOrSequenceType(array.getType())); + fir::SequenceType arrayTy = + hlfir::getFortranElementOrSequenceType(array.getType()) + .cast(); llvm::ArrayRef arrayShape = arrayTy.getShape(); mlir::Type resultType = results[0]; @@ -988,10 +993,12 @@ void hlfir::SumOp::getEffects( mlir::LogicalResult hlfir::DotProductOp::verify() { mlir::Value lhs = getLhs(); mlir::Value rhs = getRhs(); - fir::SequenceType lhsTy = mlir::cast( - hlfir::getFortranElementOrSequenceType(lhs.getType())); - fir::SequenceType rhsTy = mlir::cast( - hlfir::getFortranElementOrSequenceType(rhs.getType())); + fir::SequenceType lhsTy = + hlfir::getFortranElementOrSequenceType(lhs.getType()) + .cast(); + fir::SequenceType rhsTy = + hlfir::getFortranElementOrSequenceType(rhs.getType()) + .cast(); llvm::ArrayRef lhsShape = lhsTy.getShape(); llvm::ArrayRef rhsShape = rhsTy.getShape(); std::size_t lhsRank = lhsShape.size(); @@ -1044,17 +1051,19 @@ void hlfir::DotProductOp::getEffects( mlir::LogicalResult hlfir::MatmulOp::verify() { mlir::Value lhs = getLhs(); mlir::Value rhs = getRhs(); - fir::SequenceType lhsTy = mlir::cast( - hlfir::getFortranElementOrSequenceType(lhs.getType())); - fir::SequenceType rhsTy = mlir::cast( - hlfir::getFortranElementOrSequenceType(rhs.getType())); + fir::SequenceType lhsTy = + hlfir::getFortranElementOrSequenceType(lhs.getType()) + .cast(); + fir::SequenceType rhsTy = + hlfir::getFortranElementOrSequenceType(rhs.getType()) + .cast(); llvm::ArrayRef lhsShape = lhsTy.getShape(); llvm::ArrayRef rhsShape = rhsTy.getShape(); std::size_t lhsRank = lhsShape.size(); std::size_t rhsRank = rhsShape.size(); mlir::Type lhsEleTy = lhsTy.getEleTy(); mlir::Type rhsEleTy = rhsTy.getEleTy(); - hlfir::ExprType resultTy = mlir::cast(getResult().getType()); + hlfir::ExprType resultTy = getResult().getType().cast(); llvm::ArrayRef resultShape = resultTy.getShape(); mlir::Type resultEleTy = resultTy.getEleTy(); @@ -1171,12 +1180,13 @@ void hlfir::MatmulOp::getEffects( mlir::LogicalResult hlfir::TransposeOp::verify() { mlir::Value array = getArray(); - fir::SequenceType arrayTy = mlir::cast( - hlfir::getFortranElementOrSequenceType(array.getType())); + fir::SequenceType arrayTy = + hlfir::getFortranElementOrSequenceType(array.getType()) + .cast(); llvm::ArrayRef inShape = arrayTy.getShape(); std::size_t rank = inShape.size(); mlir::Type eleTy = arrayTy.getEleTy(); - hlfir::ExprType resultTy = mlir::cast(getResult().getType()); + hlfir::ExprType resultTy = getResult().getType().cast(); llvm::ArrayRef resultShape = resultTy.getShape(); std::size_t resultRank = resultShape.size(); mlir::Type resultEleTy = resultTy.getEleTy(); @@ -1214,17 +1224,19 @@ void hlfir::TransposeOp::getEffects( mlir::LogicalResult hlfir::MatmulTransposeOp::verify() { mlir::Value lhs = getLhs(); mlir::Value rhs = getRhs(); - fir::SequenceType lhsTy = mlir::cast( - hlfir::getFortranElementOrSequenceType(lhs.getType())); - fir::SequenceType rhsTy = mlir::cast( - hlfir::getFortranElementOrSequenceType(rhs.getType())); + fir::SequenceType lhsTy = + hlfir::getFortranElementOrSequenceType(lhs.getType()) + .cast(); + fir::SequenceType rhsTy = + hlfir::getFortranElementOrSequenceType(rhs.getType()) + .cast(); llvm::ArrayRef lhsShape = lhsTy.getShape(); llvm::ArrayRef rhsShape = rhsTy.getShape(); std::size_t lhsRank = lhsShape.size(); std::size_t rhsRank = rhsShape.size(); mlir::Type lhsEleTy = lhsTy.getEleTy(); mlir::Type rhsEleTy = rhsTy.getEleTy(); - hlfir::ExprType resultTy = mlir::cast(getResult().getType()); + hlfir::ExprType resultTy = getResult().getType().cast(); llvm::ArrayRef resultShape = resultTy.getShape(); mlir::Type resultEleTy = resultTy.getEleTy(); @@ -1369,7 +1381,7 @@ void hlfir::AsExprOp::build(mlir::OpBuilder &builder, hlfir::ExprType::Shape typeShape; bool isPolymorphic = fir::isPolymorphicType(var.getType()); mlir::Type type = getFortranElementOrSequenceType(var.getType()); - if (auto seqType = mlir::dyn_cast(type)) { + if (auto seqType = type.dyn_cast()) { typeShape.append(seqType.getShape().begin(), seqType.getShape().end()); type = seqType.getEleTy(); } @@ -1415,7 +1427,7 @@ static void buildElemental(mlir::OpBuilder &builder, isUnordered ? builder.getUnitAttr() : nullptr); mlir::Region *bodyRegion = odsState.addRegion(); bodyRegion->push_back(new mlir::Block{}); - if (auto shapeType = mlir::dyn_cast(shape.getType())) { + if (auto shapeType = shape.getType().dyn_cast()) { unsigned dim = shapeType.getRank(); mlir::Type indexType = builder.getIndexType(); for (unsigned d = 0; d < dim; ++d) @@ -1456,7 +1468,7 @@ void hlfir::ApplyOp::build(mlir::OpBuilder &builder, mlir::ValueRange indices, mlir::ValueRange typeparams) { mlir::Type resultType = expr.getType(); - if (auto exprType = mlir::dyn_cast(resultType)) + if (auto exprType = resultType.dyn_cast()) resultType = exprType.getElementExprType(); build(builder, odsState, resultType, expr, indices, typeparams); } @@ -1505,20 +1517,20 @@ void hlfir::CopyInOp::build(mlir::OpBuilder &builder, void hlfir::ShapeOfOp::build(mlir::OpBuilder &builder, mlir::OperationState &result, mlir::Value expr) { - hlfir::ExprType exprTy = mlir::cast(expr.getType()); + hlfir::ExprType exprTy = expr.getType().cast(); mlir::Type type = fir::ShapeType::get(builder.getContext(), exprTy.getRank()); build(builder, result, type, expr); } std::size_t hlfir::ShapeOfOp::getRank() { mlir::Type resTy = getResult().getType(); - fir::ShapeType shape = mlir::cast(resTy); + fir::ShapeType shape = resTy.cast(); return shape.getRank(); } mlir::LogicalResult hlfir::ShapeOfOp::verify() { mlir::Value expr = getExpr(); - hlfir::ExprType exprTy = mlir::cast(expr.getType()); + hlfir::ExprType exprTy = expr.getType().cast(); std::size_t exprRank = exprTy.getShape().size(); if (exprRank == 0) @@ -1537,8 +1549,7 @@ hlfir::ShapeOfOp::canonicalize(ShapeOfOp shapeOf, // if extent information is available at compile time, immediately fold the // hlfir.shape_of into a fir.shape mlir::Location loc = shapeOf.getLoc(); - hlfir::ExprType expr = - mlir::cast(shapeOf.getExpr().getType()); + hlfir::ExprType expr = shapeOf.getExpr().getType().cast(); mlir::Value shape = hlfir::genExprShape(rewriter, loc, expr); if (!shape) @@ -1563,7 +1574,7 @@ void hlfir::GetExtentOp::build(mlir::OpBuilder &builder, } mlir::LogicalResult hlfir::GetExtentOp::verify() { - fir::ShapeType shapeTy = mlir::cast(getShape().getType()); + fir::ShapeType shapeTy = getShape().getType().cast(); std::uint64_t rank = shapeTy.getRank(); llvm::APInt dim = getDim(); if (dim.sge(rank)) @@ -1698,11 +1709,10 @@ mlir::LogicalResult hlfir::ElementalAddrOp::verify() { return emitOpError("body region must be terminated by an hlfir.yield"); mlir::Type elementAddrType = yieldOp.getEntity().getType(); if (!hlfir::isFortranVariableType(elementAddrType) || - mlir::isa( - hlfir::getFortranElementOrSequenceType(elementAddrType))) + hlfir::getFortranElementOrSequenceType(elementAddrType) + .isa()) return emitOpError("body must compute the address of a scalar entity"); - unsigned shapeRank = - mlir::cast(getShape().getType()).getRank(); + unsigned shapeRank = getShape().getType().cast().getRank(); if (shapeRank != getIndices().size()) return emitOpError("body number of indices must match shape rank"); return mlir::success(); @@ -1807,8 +1817,8 @@ static bool yieldsLogical(mlir::Region ®ion, bool mustBeScalarI1) { if (mustBeScalarI1) return hlfir::isI1Type(yieldType); return hlfir::isMaskArgument(yieldType) && - mlir::isa( - hlfir::getFortranElementOrSequenceType(yieldType)); + hlfir::getFortranElementOrSequenceType(yieldType) + .isa(); } mlir::LogicalResult hlfir::ForallMaskOp::verify() { diff --git a/flang/lib/Optimizer/HLFIR/Transforms/BufferizeHLFIR.cpp b/flang/lib/Optimizer/HLFIR/Transforms/BufferizeHLFIR.cpp index d4e4835ee7265..1c4f82e2de818 100644 --- a/flang/lib/Optimizer/HLFIR/Transforms/BufferizeHLFIR.cpp +++ b/flang/lib/Optimizer/HLFIR/Transforms/BufferizeHLFIR.cpp @@ -77,7 +77,7 @@ static mlir::Value packageBufferizedExpr(mlir::Location loc, /// currently enforced by the verifiers that only accept HLFIR value or /// variable types which do not include tuples. static hlfir::Entity getBufferizedExprStorage(mlir::Value bufferizedExpr) { - auto tupleType = mlir::dyn_cast(bufferizedExpr.getType()); + auto tupleType = bufferizedExpr.getType().dyn_cast(); if (!tupleType) return hlfir::Entity{bufferizedExpr}; assert(tupleType.size() == 2 && "unexpected tuple type"); @@ -90,7 +90,7 @@ static hlfir::Entity getBufferizedExprStorage(mlir::Value bufferizedExpr) { /// Helper to extract the clean-up flag from a tuple created by /// packageBufferizedExpr. static mlir::Value getBufferizedExprMustFreeFlag(mlir::Value bufferizedExpr) { - auto tupleType = mlir::dyn_cast(bufferizedExpr.getType()); + auto tupleType = bufferizedExpr.getType().dyn_cast(); if (!tupleType) return bufferizedExpr; assert(tupleType.size() == 2 && "unexpected tuple type"); @@ -218,7 +218,7 @@ struct ShapeOfOpConversion } else { // everything else failed so try to create a shape from static type info hlfir::ExprType exprTy = - mlir::dyn_cast_or_null(adaptor.getExpr().getType()); + adaptor.getExpr().getType().dyn_cast_or_null(); if (exprTy) shape = hlfir::genExprShape(builder, loc, exprTy); } @@ -480,10 +480,10 @@ struct AssociateOpConversion assert(mlir::isa(sourceVar.getType()) && fir::isAllocatableType(sourceVar.getType())); assert(sourceVar.getType() == assocType); - } else if ((mlir::isa(sourceVar.getType()) && - !mlir::isa(assocType)) || - ((mlir::isa(sourceVar.getType()) && - !mlir::isa(assocType)))) { + } else if ((sourceVar.getType().isa() && + !assocType.isa()) || + ((sourceVar.getType().isa() && + !assocType.isa()))) { sourceVar = builder.create(loc, assocType, sourceVar); } else { sourceVar = builder.createConvert(loc, assocType, sourceVar); @@ -590,13 +590,13 @@ static void genBufferDestruction(mlir::Location loc, fir::FirOpBuilder &builder, // for MERGE with polymorphic results. if (mustFinalize) TODO(loc, "finalizing polymorphic temporary in HLFIR"); - } else if (mlir::isa(var.getType())) { + } else if (var.getType().isa()) { if (mustFinalize && !mlir::isa(var.getType())) fir::emitFatalError(loc, "non-finalizable variable"); addr = builder.create(loc, heapType, var); } else { - if (!mlir::isa(var.getType())) + if (!var.getType().isa()) addr = builder.create(loc, heapType, var); if (mustFinalize || deallocComponents) { @@ -831,7 +831,7 @@ struct ElementalOpConversion // the assign, insert an hlfir.destroy to mark the expression end-of-life. // If the expression creation allocated a buffer on the heap inside the // loop, this will ensure the buffer properly deallocated. - if (mlir::isa(elementValue.getType()) && + if (elementValue.getType().isa() && wasCreatedInCurrentBlock(elementValue, builder)) builder.create(loc, elementValue); } @@ -926,12 +926,11 @@ class BufferizeHLFIR : public hlfir::impl::BufferizeHLFIRBase { hlfir::EndAssociateOp, hlfir::SetLengthOp>(); target.markUnknownOpDynamicallyLegal([](mlir::Operation *op) { - return llvm::all_of(op->getResultTypes(), - [](mlir::Type ty) { - return !mlir::isa(ty); - }) && + return llvm::all_of( + op->getResultTypes(), + [](mlir::Type ty) { return !ty.isa(); }) && llvm::all_of(op->getOperandTypes(), [](mlir::Type ty) { - return !mlir::isa(ty); + return !ty.isa(); }); }); if (mlir::failed( diff --git a/flang/lib/Optimizer/HLFIR/Transforms/ConvertToFIR.cpp b/flang/lib/Optimizer/HLFIR/Transforms/ConvertToFIR.cpp index 517285dce133d..cd534bae4ad2a 100644 --- a/flang/lib/Optimizer/HLFIR/Transforms/ConvertToFIR.cpp +++ b/flang/lib/Optimizer/HLFIR/Transforms/ConvertToFIR.cpp @@ -34,7 +34,7 @@ using namespace mlir; static mlir::Value genAllocatableTempFromSourceBox(mlir::Location loc, fir::FirOpBuilder &builder, mlir::Value sourceBox) { - assert(mlir::isa(sourceBox.getType()) && + assert(sourceBox.getType().isa() && "must be a base box type"); // Use the runtime to make a quick and dirty temp with the rhs value. // Overkill for scalar rhs that could be done in much more clever ways. @@ -44,7 +44,7 @@ static mlir::Value genAllocatableTempFromSourceBox(mlir::Location loc, // This has the huge benefit of dealing with all cases, including // polymorphic entities. mlir::Type fromHeapType = fir::HeapType::get(fir::unwrapRefType( - mlir::cast(sourceBox.getType()).getEleTy())); + sourceBox.getType().cast().getEleTy())); mlir::Type fromBoxHeapType = fir::BoxType::get(fromHeapType); mlir::Value fromMutableBox = fir::factory::genNullBoxStorage(builder, loc, fromBoxHeapType); @@ -69,7 +69,7 @@ class AssignOpConversion : public mlir::OpRewritePattern { auto module = assignOp->getParentOfType(); fir::FirOpBuilder builder(rewriter, module); - if (mlir::isa(rhs.getType())) { + if (rhs.getType().isa()) { mlir::emitError(loc, "hlfir must be bufferized with --bufferize-hlfir " "pass before being converted to FIR"); return mlir::failure(); @@ -343,15 +343,16 @@ class DeclareOpConversion : public mlir::OpRewritePattern { auto firBase = firDeclareOp.getResult(); mlir::Value hlfirBase; mlir::Type hlfirBaseType = declareOp.getBase().getType(); - if (mlir::isa(hlfirBaseType)) { + if (hlfirBaseType.isa()) { fir::FirOpBuilder builder(rewriter, declareOp.getOperation()); // Helper to generate the hlfir fir.box with the local lower bounds and // type parameters. auto genHlfirBox = [&]() -> mlir::Value { - if (!mlir::isa(firBase.getType())) { + if (!firBase.getType().isa()) { llvm::SmallVector typeParams; - auto maybeCharType = mlir::dyn_cast( - fir::unwrapSequenceType(fir::unwrapPassByRefType(hlfirBaseType))); + auto maybeCharType = + fir::unwrapSequenceType(fir::unwrapPassByRefType(hlfirBaseType)) + .dyn_cast(); if (!maybeCharType || maybeCharType.hasDynamicLen()) typeParams.append(declareOp.getTypeparams().begin(), declareOp.getTypeparams().end()); @@ -398,7 +399,7 @@ class DeclareOpConversion : public mlir::OpRewritePattern { }) .getResults()[0]; } - } else if (mlir::isa(hlfirBaseType)) { + } else if (hlfirBaseType.isa()) { assert(declareOp.getTypeparams().size() == 1 && "must contain character length"); hlfirBase = rewriter.create( @@ -479,12 +480,11 @@ class DesignateOpConversion // - scalar%scalar_component [substring|complex_part] or // - scalar%static_size_array_comp // - scalar%array(indices) [substring| complex part] - mlir::Type componentType = - mlir::cast(baseEleTy).getType( - designate.getComponent().value()); + mlir::Type componentType = baseEleTy.cast().getType( + designate.getComponent().value()); mlir::Type coorTy = fir::ReferenceType::get(componentType); base = builder.create(loc, coorTy, base, fieldIndex); - if (mlir::isa(componentType)) { + if (componentType.isa()) { auto variableInterface = mlir::cast( designate.getOperation()); if (variableInterface.isAllocatable() || @@ -500,14 +500,14 @@ class DesignateOpConversion } else { // array%component[(indices) substring|complex part] cases. // Component ref of array bases are dealt with below in embox/rebox. - assert(mlir::isa(designateResultType)); + assert(designateResultType.isa()); } } - if (mlir::isa(designateResultType)) { + if (designateResultType.isa()) { // Generate embox or rebox. mlir::Type eleTy = fir::unwrapPassByRefType(designateResultType); - bool isScalarDesignator = !mlir::isa(eleTy); + bool isScalarDesignator = !eleTy.isa(); mlir::Value sourceBox; if (isScalarDesignator) { // The base box will be used for emboxing the scalar element. @@ -583,7 +583,7 @@ class DesignateOpConversion assert(sliceFields.empty() && substring.empty()); llvm::SmallVector resultType{designateResultType}; mlir::Value resultBox; - if (mlir::isa(base.getType())) + if (base.getType().isa()) resultBox = builder.create(loc, resultType, base, shape, slice); else @@ -598,8 +598,7 @@ class DesignateOpConversion // first element of a contiguous array section with compile time constant // shape. The base may be an array, or a scalar. mlir::Type resultAddressType = designateResultType; - if (auto boxCharType = - mlir::dyn_cast(designateResultType)) + if (auto boxCharType = designateResultType.dyn_cast()) resultAddressType = fir::ReferenceType::get(boxCharType.getEleTy()); // Array element indexing. @@ -621,7 +620,7 @@ class DesignateOpConversion // Scalar complex part ref if (designate.getComplexPart()) { // Sequence types should have already been handled by this point - assert(!mlir::isa(designateResultType)); + assert(!designateResultType.isa()); auto index = builder.createIntegerConstant(loc, builder.getIndexType(), *designate.getComplexPart()); auto coorTy = fir::ReferenceType::get(resultEleTy); @@ -629,7 +628,7 @@ class DesignateOpConversion } // Cast/embox the computed scalar address if needed. - if (mlir::isa(designateResultType)) { + if (designateResultType.isa()) { assert(designate.getTypeparams().size() == 1 && "must have character length"); auto emboxChar = builder.create( @@ -672,13 +671,13 @@ class ParentComponentOpConversion mlir::PatternRewriter &rewriter) const override { mlir::Location loc = parentComponent.getLoc(); mlir::Type resultType = parentComponent.getType(); - if (!mlir::isa(parentComponent.getType())) { + if (!parentComponent.getType().isa()) { mlir::Value baseAddr = parentComponent.getMemref(); // Scalar parent component ref without any length type parameters. The // input may be a fir.class if it is polymorphic, since this is a scalar // and the output will be monomorphic, the base address can be extracted // from the fir.class. - if (mlir::isa(baseAddr.getType())) + if (baseAddr.getType().isa()) baseAddr = rewriter.create(loc, baseAddr); rewriter.replaceOpWithNewOp(parentComponent, resultType, baseAddr); @@ -687,7 +686,7 @@ class ParentComponentOpConversion // Array parent component ref or PDTs. hlfir::Entity base{parentComponent.getMemref()}; mlir::Value baseAddr = base.getBase(); - if (!mlir::isa(baseAddr.getType())) { + if (!baseAddr.getType().isa()) { // Embox cannot directly be used to address parent components: it expects // the output type to match the input type when there are no slices. When // the types have at least one component, a slice to the first element can @@ -749,7 +748,7 @@ class GetExtentOpConversion // the hlfir.shape_of operation which led to the creation of this get_extent // operation should now have been lowered to a fir.shape operation if (auto s = mlir::dyn_cast_or_null(shapeOp)) { - fir::ShapeType shapeTy = mlir::cast(shape.getType()); + fir::ShapeType shapeTy = shape.getType().cast(); llvm::APInt dim = getExtentOp.getDim(); uint64_t dimVal = dim.getLimitedValue(shapeTy.getRank()); mlir::Value extent = s.getExtents()[dimVal]; diff --git a/flang/lib/Optimizer/HLFIR/Transforms/LowerHLFIRIntrinsics.cpp b/flang/lib/Optimizer/HLFIR/Transforms/LowerHLFIRIntrinsics.cpp index e9dbb7095d0eb..0142fb0cfb0bb 100644 --- a/flang/lib/Optimizer/HLFIR/Transforms/LowerHLFIRIntrinsics.cpp +++ b/flang/lib/Optimizer/HLFIR/Transforms/LowerHLFIRIntrinsics.cpp @@ -185,7 +185,7 @@ class HlfirIntrinsicConversion : public mlir::OpRewritePattern { // the width for use in runtime intrinsic calls. static unsigned getKindForType(mlir::Type ty) { mlir::Type eltty = hlfir::getFortranElementType(ty); - unsigned width = mlir::cast(eltty).getWidth(); + unsigned width = eltty.cast().getWidth(); return width / 8; } diff --git a/flang/lib/Optimizer/HLFIR/Transforms/LowerHLFIROrderedAssignments.cpp b/flang/lib/Optimizer/HLFIR/Transforms/LowerHLFIROrderedAssignments.cpp index 63b52c0cd0bc4..84101353a740a 100644 --- a/flang/lib/Optimizer/HLFIR/Transforms/LowerHLFIROrderedAssignments.cpp +++ b/flang/lib/Optimizer/HLFIR/Transforms/LowerHLFIROrderedAssignments.cpp @@ -1090,7 +1090,7 @@ void OrderedAssignmentRewriter::generateSaveEntity( mlir::Value loopExtent = computeLoopNestIterationNumber(loc, builder, loopNest); auto sequenceType = - mlir::cast(builder.getVarLenSeqTy(entityType)); + builder.getVarLenSeqTy(entityType).cast(); temp = insertSavedEntity(region, fir::factory::HomogeneousScalarStack{ loc, builder, sequenceType, loopExtent, diff --git a/flang/lib/Optimizer/HLFIR/Transforms/OptimizedBufferization.cpp b/flang/lib/Optimizer/HLFIR/Transforms/OptimizedBufferization.cpp index 8d68c70216082..685c73d676257 100644 --- a/flang/lib/Optimizer/HLFIR/Transforms/OptimizedBufferization.cpp +++ b/flang/lib/Optimizer/HLFIR/Transforms/OptimizedBufferization.cpp @@ -249,7 +249,7 @@ static bool areIdenticalOrDisjointSlices(mlir::Value ref1, mlir::Value ref2) { auto isPositiveConstant = [](mlir::Value v) -> bool { if (auto conOp = mlir::dyn_cast(v.getDefiningOp())) - if (auto iattr = mlir::dyn_cast(conOp.getValue())) + if (auto iattr = conOp.getValue().dyn_cast()) return iattr.getInt() > 0; return false; }; @@ -601,7 +601,7 @@ mlir::LogicalResult VariableAssignBufferization::matchAndRewrite( // TODO: ExprType check is here to avoid conflicts with // ElementalAssignBufferization pattern. We need to combine // these matchers into a single one that applies to AssignOp. - if (mlir::isa(rhs.getType())) + if (rhs.getType().isa()) return rewriter.notifyMatchFailure(assign, "RHS is not in memory"); if (!rhs.isArray()) @@ -834,7 +834,7 @@ class MinMaxlocElementalConversion : public mlir::OpRewritePattern { unsigned rank = mlir::cast(mloc.getType()).getShape()[0]; mlir::Type arrayType = array.getType(); - if (!mlir::isa(arrayType)) + if (!arrayType.isa()) return rewriter.notifyMatchFailure( mloc, "Currently requires a boxed type input"); mlir::Type elementType = hlfir::getFortranElementType(arrayType); @@ -850,7 +850,7 @@ class MinMaxlocElementalConversion : public mlir::OpRewritePattern { auto init = [isMax](fir::FirOpBuilder builder, mlir::Location loc, mlir::Type elementType) { - if (auto ty = mlir::dyn_cast(elementType)) { + if (auto ty = elementType.dyn_cast()) { const llvm::fltSemantics &sem = ty.getFloatSemantics(); llvm::APFloat limit = llvm::APFloat::getInf(sem, /*Negative=*/isMax); return builder.createRealConstant(loc, elementType, limit); @@ -901,7 +901,7 @@ class MinMaxlocElementalConversion : public mlir::OpRewritePattern { // Compare with the max reduction value mlir::Value cmp; - if (mlir::isa(elementType)) { + if (elementType.isa()) { // For FP reductions we want the first smallest value to be used, that // is not NaN. A OGL/OLT condition will usually work for this unless all // the values are Nan or Inf. This follows the same logic as @@ -918,7 +918,7 @@ class MinMaxlocElementalConversion : public mlir::OpRewritePattern { loc, mlir::arith::CmpFPredicate::OEQ, elem, elem); cmpNan = builder.create(loc, cmpNan, cmpNan2); cmp = builder.create(loc, cmp, cmpNan); - } else if (mlir::isa(elementType)) { + } else if (elementType.isa()) { cmp = builder.create( loc, isMax ? mlir::arith::CmpIPredicate::sgt diff --git a/flang/lib/Optimizer/HLFIR/Transforms/SimplifyHLFIRIntrinsics.cpp b/flang/lib/Optimizer/HLFIR/Transforms/SimplifyHLFIRIntrinsics.cpp index b761563eba0f8..2751575ce9821 100644 --- a/flang/lib/Optimizer/HLFIR/Transforms/SimplifyHLFIRIntrinsics.cpp +++ b/flang/lib/Optimizer/HLFIR/Transforms/SimplifyHLFIRIntrinsics.cpp @@ -103,8 +103,7 @@ class SimplifyHLFIRIntrinsics // by hlfir.elemental) target.addDynamicallyLegalOp( [](hlfir::TransposeOp transpose) { - return mlir::cast(transpose.getType()) - .isPolymorphic(); + return transpose.getType().cast().isPolymorphic(); }); target.markUnknownOpDynamicallyLegal( [](mlir::Operation *) { return true; }); diff --git a/flang/lib/Optimizer/Transforms/AbstractResult.cpp b/flang/lib/Optimizer/Transforms/AbstractResult.cpp index 85472cdc5103a..eb4dd637bb167 100644 --- a/flang/lib/Optimizer/Transforms/AbstractResult.cpp +++ b/flang/lib/Optimizer/Transforms/AbstractResult.cpp @@ -65,14 +65,14 @@ static mlir::FunctionType getCPtrFunctionType(mlir::FunctionType funcTy) { auto resultType = funcTy.getResult(0); assert(fir::isa_builtin_cptr_type(resultType)); llvm::SmallVector outputTypes; - auto recTy = mlir::dyn_cast(resultType); + auto recTy = resultType.dyn_cast(); outputTypes.emplace_back(recTy.getTypeList()[0].second); return mlir::FunctionType::get(funcTy.getContext(), funcTy.getInputs(), outputTypes); } static bool mustEmboxResult(mlir::Type resultType, bool shouldBoxResult) { - return mlir::isa(resultType) && + return resultType.isa() && shouldBoxResult; } @@ -114,7 +114,7 @@ class CallConversion : public mlir::OpRewritePattern { bool isResultBuiltinCPtr = fir::isa_builtin_cptr_type(result.getType()); Op newOp; if (isResultBuiltinCPtr) { - auto recTy = mlir::dyn_cast(result.getType()); + auto recTy = result.getType().template dyn_cast(); newResultTypes.emplace_back(recTy.getTypeList()[0].second); } @@ -261,7 +261,7 @@ class AddrOfOpConversion : public mlir::OpRewritePattern { mlir::LogicalResult matchAndRewrite(fir::AddrOfOp addrOf, mlir::PatternRewriter &rewriter) const override { - auto oldFuncTy = mlir::cast(addrOf.getType()); + auto oldFuncTy = addrOf.getType().cast(); mlir::FunctionType newFuncTy; // TODO: This should be generalized for derived types, and it is // architecture and OS dependent. @@ -296,7 +296,7 @@ class AbstractResultOpt auto loc = func.getLoc(); auto *context = &getContext(); // Convert function type itself if it has an abstract result. - auto funcTy = mlir::cast(func.getFunctionType()); + auto funcTy = func.getFunctionType().cast(); if (hasAbstractResult(funcTy)) { // TODO: This should be generalized for derived types, and it is // architecture and OS dependent. @@ -343,11 +343,11 @@ class AbstractResultOpt return mlir::TypeSwitch(type) .Case([](fir::BoxProcType boxProc) { return fir::hasAbstractResult( - mlir::cast(boxProc.getEleTy())); + boxProc.getEleTy().cast()); }) .Case([](fir::PointerType pointer) { return fir::hasAbstractResult( - mlir::cast(pointer.getEleTy())); + pointer.getEleTy().cast()); }) .Default([](auto &&) { return false; }); } @@ -411,7 +411,7 @@ class AbstractResultOpt return !hasAbstractResult(call.getFunctionType()); }); target.addDynamicallyLegalOp([](fir::AddrOfOp addrOf) { - if (auto funTy = mlir::dyn_cast(addrOf.getType())) + if (auto funTy = addrOf.getType().dyn_cast()) return !hasAbstractResult(funTy); return true; }); diff --git a/flang/lib/Optimizer/Transforms/AddDebugInfo.cpp b/flang/lib/Optimizer/Transforms/AddDebugInfo.cpp index 18d98a11ef3c4..68584bef055b6 100644 --- a/flang/lib/Optimizer/Transforms/AddDebugInfo.cpp +++ b/flang/lib/Optimizer/Transforms/AddDebugInfo.cpp @@ -69,7 +69,7 @@ void AddDebugInfoPass::runOnOperation() { // In that case, 'inputFilename' may be empty. Location embedded in the // module will be used to get file name and its directory. if (inputFilename.empty()) { - if (auto fileLoc = mlir::dyn_cast(module.getLoc())) { + if (auto fileLoc = module.getLoc().dyn_cast()) { fileName = llvm::sys::path::filename(fileLoc.getFilename().getValue()); filePath = llvm::sys::path::parent_path(fileLoc.getFilename().getValue()); } else @@ -94,14 +94,14 @@ void AddDebugInfoPass::runOnOperation() { mlir::Location l = funcOp->getLoc(); // If fused location has already been created then nothing to do // Otherwise, create a fused location. - if (mlir::dyn_cast(l)) + if (l.dyn_cast()) return; unsigned int CC = (funcOp.getName() == fir::NameUniquer::doProgramEntry()) ? llvm::dwarf::getCallingConvention("DW_CC_program") : llvm::dwarf::getCallingConvention("DW_CC_normal"); - if (auto funcLoc = mlir::dyn_cast(l)) { + if (auto funcLoc = l.dyn_cast()) { fileName = llvm::sys::path::filename(funcLoc.getFilename().getValue()); filePath = llvm::sys::path::parent_path(funcLoc.getFilename().getValue()); } diff --git a/flang/lib/Optimizer/Transforms/AffineDemotion.cpp b/flang/lib/Optimizer/Transforms/AffineDemotion.cpp index b4523a060f5a5..da29ae880700e 100644 --- a/flang/lib/Optimizer/Transforms/AffineDemotion.cpp +++ b/flang/lib/Optimizer/Transforms/AffineDemotion.cpp @@ -98,15 +98,14 @@ class ConvertConversion : public mlir::OpRewritePattern { mlir::LogicalResult matchAndRewrite(fir::ConvertOp op, mlir::PatternRewriter &rewriter) const override { - if (mlir::isa(op.getRes().getType())) { + if (op.getRes().getType().isa()) { // due to index calculation moving to affine maps we still need to // add converts for sequence types this has a side effect of losing // some information about arrays with known dimensions by creating: // fir.convert %arg0 : (!fir.ref>) -> // !fir.ref> - if (auto refTy = - mlir::dyn_cast(op.getValue().getType())) - if (auto arrTy = mlir::dyn_cast(refTy.getEleTy())) { + if (auto refTy = op.getValue().getType().dyn_cast()) + if (auto arrTy = refTy.getEleTy().dyn_cast()) { fir::SequenceType::Shape flatShape = { fir::SequenceType::getUnknownExtent()}; auto flatArrTy = fir::SequenceType::get(flatShape, arrTy.getEleTy()); @@ -159,7 +158,7 @@ class AffineDialectDemotion mlir::ConversionTarget target(*context); target.addIllegalOp(); target.addDynamicallyLegalOp([](fir::ConvertOp op) { - if (mlir::isa(op.getRes().getType())) + if (op.getRes().getType().isa()) return false; return true; }); diff --git a/flang/lib/Optimizer/Transforms/AffinePromotion.cpp b/flang/lib/Optimizer/Transforms/AffinePromotion.cpp index 7d0131ac6fa4e..64531cb1868ef 100644 --- a/flang/lib/Optimizer/Transforms/AffinePromotion.cpp +++ b/flang/lib/Optimizer/Transforms/AffinePromotion.cpp @@ -111,7 +111,7 @@ struct AffineLoopAnalysis { bool analyzeReference(mlir::Value memref, mlir::Operation *op) { if (auto acoOp = memref.getDefiningOp()) { - if (mlir::isa(acoOp.getMemref().getType())) { + if (acoOp.getMemref().getType().isa()) { // TODO: Look if and how fir.box can be promoted to affine. LLVM_DEBUG(llvm::dbgs() << "AffineLoopAnalysis: cannot promote loop, " "array memory operation uses fir.box\n"; @@ -222,7 +222,7 @@ struct AffineIfCondition { return affineBinaryOp(mlir::AffineExprKind::Mod, op.getLhs(), op.getRhs()); if (auto op = value.getDefiningOp()) - if (auto intConstant = mlir::dyn_cast(op.getValue())) + if (auto intConstant = op.getValue().dyn_cast()) return toAffineExpr(intConstant.getInt()); if (auto blockArg = mlir::dyn_cast(value)) { affineArgs.push_back(value); @@ -331,16 +331,15 @@ static mlir::AffineMap createArrayIndexAffineMap(unsigned dimensions, static std::optional constantIntegerLike(const mlir::Value value) { if (auto definition = value.getDefiningOp()) - if (auto stepAttr = mlir::dyn_cast(definition.getValue())) + if (auto stepAttr = definition.getValue().dyn_cast()) return stepAttr.getInt(); return {}; } static mlir::Type coordinateArrayElement(fir::ArrayCoorOp op) { if (auto refType = - mlir::dyn_cast_or_null(op.getMemref().getType())) { - if (auto seqType = - mlir::dyn_cast_or_null(refType.getEleTy())) { + op.getMemref().getType().dyn_cast_or_null()) { + if (auto seqType = refType.getEleTy().dyn_cast_or_null()) { return seqType.getEleTy(); } } diff --git a/flang/lib/Optimizer/Transforms/ArrayValueCopy.cpp b/flang/lib/Optimizer/Transforms/ArrayValueCopy.cpp index ebc1862225256..a08d58383d3a9 100644 --- a/flang/lib/Optimizer/Transforms/ArrayValueCopy.cpp +++ b/flang/lib/Optimizer/Transforms/ArrayValueCopy.cpp @@ -461,9 +461,9 @@ void ArrayCopyAnalysisBase::arrayMentions( } static bool hasPointerType(mlir::Type type) { - if (auto boxTy = mlir::dyn_cast(type)) + if (auto boxTy = type.dyn_cast()) type = boxTy.getEleTy(); - return mlir::isa(type); + return type.isa(); } // This is a NF performance hack. It makes a simple test that the slices of the @@ -512,7 +512,7 @@ static bool mutuallyExclusiveSliceRange(ArrayLoadOp ld, ArrayMergeStoreOp st) { auto isPositiveConstant = [](mlir::Value v) -> bool { if (auto conOp = mlir::dyn_cast(v.getDefiningOp())) - if (auto iattr = mlir::dyn_cast(conOp.getValue())) + if (auto iattr = conOp.getValue().dyn_cast()) return iattr.getInt() > 0; return false; }; @@ -725,8 +725,8 @@ static bool conservativeCallConflict(llvm::ArrayRef reaches) { return llvm::any_of(reaches, [](mlir::Operation *op) { if (auto call = mlir::dyn_cast(op)) - if (auto callee = mlir::dyn_cast( - call.getCallableForCallee())) { + if (auto callee = + call.getCallableForCallee().dyn_cast()) { auto module = op->getParentOfType(); return isInternalProcedure( module.lookupSymbol(callee)); @@ -891,9 +891,9 @@ static mlir::Value getOrReadExtentsAndShapeOp( if (arrLoad->hasAttr(fir::getOptionalAttrName())) fir::emitFatalError( loc, "shapes from array load of OPTIONAL arrays must not be used"); - if (auto boxTy = mlir::dyn_cast(arrLoad.getMemref().getType())) { + if (auto boxTy = arrLoad.getMemref().getType().dyn_cast()) { auto rank = - mlir::cast(dyn_cast_ptrOrBoxEleTy(boxTy)).getDimension(); + dyn_cast_ptrOrBoxEleTy(boxTy).cast().getDimension(); auto idxTy = rewriter.getIndexType(); for (decltype(rank) dim = 0; dim < rank; ++dim) { auto dimVal = rewriter.create(loc, dim); @@ -929,7 +929,7 @@ static mlir::Type toRefType(mlir::Type ty) { static llvm::SmallVector getTypeParamsIfRawData(mlir::Location loc, FirOpBuilder &builder, ArrayLoadOp arrLoad, mlir::Type ty) { - if (mlir::isa(ty)) + if (ty.isa()) return {}; return fir::factory::getTypeParams(loc, builder, arrLoad); } @@ -947,8 +947,8 @@ static mlir::Value genCoorOp(mlir::PatternRewriter &rewriter, originated = factory::originateIndices(loc, rewriter, alloc.getType(), shape, indices); auto seqTy = dyn_cast_ptrOrBoxEleTy(alloc.getType()); - assert(seqTy && mlir::isa(seqTy)); - const auto dimension = mlir::cast(seqTy).getDimension(); + assert(seqTy && seqTy.isa()); + const auto dimension = seqTy.cast().getDimension(); auto module = load->getParentOfType(); FirOpBuilder builder(rewriter, module); auto typeparams = getTypeParamsIfRawData(loc, builder, load, alloc.getType()); @@ -967,7 +967,7 @@ static mlir::Value getCharacterLen(mlir::Location loc, FirOpBuilder &builder, ArrayLoadOp load, CharacterType charTy) { auto charLenTy = builder.getCharacterLengthType(); if (charTy.hasDynamicLen()) { - if (mlir::isa(load.getMemref().getType())) { + if (load.getMemref().getType().isa()) { // The loaded array is an emboxed value. Get the CHARACTER length from // the box value. auto eleSzInBytes = @@ -1027,7 +1027,7 @@ void genArrayCopy(mlir::Location loc, mlir::PatternRewriter &rewriter, getTypeParamsIfRawData(loc, builder, arrLoad, dst.getType())); auto eleTy = unwrapSequenceType(unwrapPassByRefType(dst.getType())); // Copy from (to) object to (from) temp copy of same object. - if (auto charTy = mlir::dyn_cast(eleTy)) { + if (auto charTy = eleTy.dyn_cast()) { auto len = getCharacterLen(loc, builder, arrLoad, charTy); CharBoxValue toChar(toAddr, len); CharBoxValue fromChar(fromAddr, len); @@ -1049,8 +1049,8 @@ genArrayLoadTypeParameters(mlir::Location loc, mlir::PatternRewriter &rewriter, auto eleTy = unwrapSequenceType(unwrapPassByRefType(load.getMemref().getType())); if (hasDynamicSize(eleTy)) { - if (auto charTy = mlir::dyn_cast(eleTy)) { - assert(mlir::isa(load.getMemref().getType())); + if (auto charTy = eleTy.dyn_cast()) { + assert(load.getMemref().getType().isa()); auto module = load->getParentOfType(); FirOpBuilder builder(rewriter, module); return {getCharacterLen(loc, builder, load, charTy)}; @@ -1067,7 +1067,7 @@ findNonconstantExtents(mlir::Type memrefTy, llvm::ArrayRef extents) { llvm::SmallVector nce; auto arrTy = unwrapPassByRefType(memrefTy); - auto seqTy = mlir::cast(arrTy); + auto seqTy = arrTy.cast(); for (auto [s, x] : llvm::zip(seqTy.getShape(), extents)) if (s == SequenceType::getUnknownExtent()) nce.emplace_back(x); diff --git a/flang/lib/Optimizer/Transforms/CharacterConversion.cpp b/flang/lib/Optimizer/Transforms/CharacterConversion.cpp index 44baad73aa258..87ea72dbca9bb 100644 --- a/flang/lib/Optimizer/Transforms/CharacterConversion.cpp +++ b/flang/lib/Optimizer/Transforms/CharacterConversion.cpp @@ -60,8 +60,8 @@ class CharacterConvertConversion // For each code point in the `from` string, convert naively to the `to` // string code point. Conversion is done blindly on size only, not value. auto getCharBits = [&](mlir::Type t) { - auto chrTy = mlir::cast( - fir::unwrapSequenceType(fir::dyn_cast_ptrEleTy(t))); + auto chrTy = fir::unwrapSequenceType(fir::dyn_cast_ptrEleTy(t)) + .cast(); return kindMap.getCharacterBitsize(chrTy.getFKind()); }; auto fromBits = getCharBits(conv.getFrom().getType()); diff --git a/flang/lib/Optimizer/Transforms/LoopVersioning.cpp b/flang/lib/Optimizer/Transforms/LoopVersioning.cpp index 38cdc2b1388d4..0afc9c24b45b0 100644 --- a/flang/lib/Optimizer/Transforms/LoopVersioning.cpp +++ b/flang/lib/Optimizer/Transforms/LoopVersioning.cpp @@ -147,7 +147,7 @@ struct ArgsUsageInLoop { static fir::SequenceType getAsSequenceType(mlir::Value *v) { mlir::Type argTy = fir::unwrapPassByRefType(fir::unwrapRefType(v->getType())); - return mlir::dyn_cast(argTy); + return argTy.dyn_cast(); } /// if a value comes from a fir.declare, follow it to the original source, diff --git a/flang/lib/Optimizer/Transforms/MemoryAllocation.cpp b/flang/lib/Optimizer/Transforms/MemoryAllocation.cpp index ada67b4201e15..40b452a6202b0 100644 --- a/flang/lib/Optimizer/Transforms/MemoryAllocation.cpp +++ b/flang/lib/Optimizer/Transforms/MemoryAllocation.cpp @@ -65,7 +65,7 @@ keepStackAllocation(fir::AllocaOp alloca, mlir::Block *entry, // TODO: Generalize the algorithm and placement of the freemem nodes. if (alloca->getBlock() != entry) return true; - if (auto seqTy = mlir::dyn_cast(alloca.getInType())) { + if (auto seqTy = alloca.getInType().dyn_cast()) { if (fir::hasDynamicSize(seqTy)) { // Move all arrays with runtime determined size to the heap. if (options.dynamicArrayOnHeap) diff --git a/flang/lib/Optimizer/Transforms/PolymorphicOpConversion.cpp b/flang/lib/Optimizer/Transforms/PolymorphicOpConversion.cpp index d933dc58f3757..93efea434cb12 100644 --- a/flang/lib/Optimizer/Transforms/PolymorphicOpConversion.cpp +++ b/flang/lib/Optimizer/Transforms/PolymorphicOpConversion.cpp @@ -97,8 +97,8 @@ struct DispatchOpConv : public OpConversionPattern { // Get derived type information. mlir::Type declaredType = fir::getDerivedType(dispatch.getObject().getType().getEleTy()); - assert(mlir::isa(declaredType) && "expecting fir.type"); - auto recordType = mlir::dyn_cast(declaredType); + assert(declaredType.isa() && "expecting fir.type"); + auto recordType = declaredType.dyn_cast(); // Lookup for the binding table. auto bindingsIter = bindingTables.find(recordType.getName()); @@ -157,7 +157,7 @@ struct DispatchOpConv : public OpConversionPattern { // Load the bindings descriptor. auto bindingsCompName = Fortran::semantics::bindingDescCompName; - fir::RecordType typeDescRecTy = mlir::cast(typeDescTy); + fir::RecordType typeDescRecTy = typeDescTy.cast(); mlir::Value field = rewriter.create( loc, fieldTy, bindingsCompName, typeDescRecTy, mlir::ValueRange{}); mlir::Type coorTy = @@ -168,8 +168,8 @@ struct DispatchOpConv : public OpConversionPattern { // Load the correct binding. mlir::Value bindings = rewriter.create(loc, bindingBox); - fir::RecordType bindingTy = fir::unwrapIfDerived( - mlir::cast(bindingBox.getType())); + fir::RecordType bindingTy = + fir::unwrapIfDerived(bindingBox.getType().cast()); mlir::Type bindingAddrTy = fir::ReferenceType::get(bindingTy); mlir::Value bindingIdxVal = rewriter.create( loc, rewriter.getIndexType(), rewriter.getIndexAttr(bindingIdx)); @@ -181,7 +181,7 @@ struct DispatchOpConv : public OpConversionPattern { mlir::Value procField = rewriter.create( loc, fieldTy, procCompName, bindingTy, mlir::ValueRange{}); fir::RecordType procTy = - mlir::cast(bindingTy.getType(procCompName)); + bindingTy.getType(procCompName).cast(); mlir::Type procRefTy = fir::ReferenceType::get(procTy); mlir::Value procRef = rewriter.create( loc, procRefTy, bindingAddr, procField); @@ -298,13 +298,13 @@ mlir::LogicalResult SelectTypeConv::matchAndRewrite( // before in the list to respect point 3. above. Otherwise it is just // added in order at the end. for (unsigned t = 0; t < typeGuardNum; ++t) { - if (auto a = mlir::dyn_cast(typeGuards[t])) { + if (auto a = typeGuards[t].dyn_cast()) { orderedTypeGuards.push_back(t); continue; } - if (auto a = mlir::dyn_cast(typeGuards[t])) { - if (auto recTy = mlir::dyn_cast(a.getType())) { + if (auto a = typeGuards[t].dyn_cast()) { + if (auto recTy = a.getType().dyn_cast()) { auto dt = mod.lookupSymbol(recTy.getName()); assert(dt && "dispatch table not found"); llvm::SmallSet ancestors = @@ -313,8 +313,8 @@ mlir::LogicalResult SelectTypeConv::matchAndRewrite( auto it = orderedClassIsGuards.begin(); while (it != orderedClassIsGuards.end()) { fir::SubclassAttr sAttr = - mlir::dyn_cast(typeGuards[*it]); - if (auto ty = mlir::dyn_cast(sAttr.getType())) { + typeGuards[*it].dyn_cast(); + if (auto ty = sAttr.getType().dyn_cast()) { if (ancestors.contains(ty.getName())) break; } @@ -339,7 +339,7 @@ mlir::LogicalResult SelectTypeConv::matchAndRewrite( auto *dest = selectType.getSuccessor(idx); std::optional destOps = selectType.getSuccessorOperands(operands, idx); - if (mlir::dyn_cast(typeGuards[idx])) + if (typeGuards[idx].dyn_cast()) rewriter.replaceOpWithNewOp( selectType, dest, destOps.value_or(mlir::ValueRange{})); else if (mlir::failed(genTypeLadderStep(loc, selector, typeGuards[idx], @@ -357,9 +357,9 @@ mlir::LogicalResult SelectTypeConv::genTypeLadderStep( fir::KindMapping &kindMap) const { mlir::Value cmp; // TYPE IS type guard comparison are all done inlined. - if (auto a = mlir::dyn_cast(attr)) { + if (auto a = attr.dyn_cast()) { if (fir::isa_trivial(a.getType()) || - mlir::isa(a.getType())) { + a.getType().isa()) { // For type guard statement with Intrinsic type spec the type code of // the descriptor is compared. int code = fir::getTypeCode(a.getType(), kindMap); @@ -383,10 +383,10 @@ mlir::LogicalResult SelectTypeConv::genTypeLadderStep( cmp = res; } // CLASS IS type guard statement is done with a runtime call. - } else if (auto a = mlir::dyn_cast(attr)) { + } else if (auto a = attr.dyn_cast()) { // Retrieve the type descriptor from the type guard statement record type. - assert(mlir::isa(a.getType()) && "expect fir.record type"); - fir::RecordType recTy = mlir::dyn_cast(a.getType()); + assert(a.getType().isa() && "expect fir.record type"); + fir::RecordType recTy = a.getType().dyn_cast(); std::string typeDescName = fir::NameUniquer::getTypeDescriptorName(recTy.getName()); auto typeDescGlobal = mod.lookupSymbol(typeDescName); @@ -438,8 +438,8 @@ mlir::Value SelectTypeConv::genTypeDescCompare(mlir::Location loc, mlir::Value selector, mlir::Type ty, mlir::ModuleOp mod, mlir::PatternRewriter &rewriter) const { - assert(mlir::isa(ty) && "expect fir.record type"); - fir::RecordType recTy = mlir::dyn_cast(ty); + assert(ty.isa() && "expect fir.record type"); + fir::RecordType recTy = ty.dyn_cast(); std::string typeDescName = fir::NameUniquer::getTypeDescriptorName(recTy.getName()); auto typeDescGlobal = mod.lookupSymbol(typeDescName); diff --git a/flang/lib/Optimizer/Transforms/SimplifyIntrinsics.cpp b/flang/lib/Optimizer/Transforms/SimplifyIntrinsics.cpp index 601bf04ce5e9b..a4f2f5238e403 100644 --- a/flang/lib/Optimizer/Transforms/SimplifyIntrinsics.cpp +++ b/flang/lib/Optimizer/Transforms/SimplifyIntrinsics.cpp @@ -215,8 +215,8 @@ static unsigned getDimCount(mlir::Value val) { // the first ConvertOp that has non-opaque box type that we meet // going through the ConvertOp chain. if (mlir::Value emboxVal = findBoxDef(val)) - if (auto boxTy = mlir::dyn_cast(emboxVal.getType())) - if (auto seqTy = mlir::dyn_cast(boxTy.getEleTy())) + if (auto boxTy = emboxVal.getType().dyn_cast()) + if (auto seqTy = boxTy.getEleTy().dyn_cast()) return seqTy.getDimension(); return 0; } @@ -237,9 +237,9 @@ static std::optional getArgElementType(mlir::Value val) { val = defOp->getOperand(0); // The convert operation is expected to convert from one // box type to another box type. - auto boxType = mlir::cast(val.getType()); + auto boxType = val.getType().cast(); auto elementType = fir::unwrapSeqOrBoxedSeqType(boxType); - if (!mlir::isa(elementType)) + if (!elementType.isa()) return elementType; } while (true); } @@ -381,7 +381,7 @@ static void genRuntimeSumBody(fir::FirOpBuilder &builder, // end function RTNAME(Sum)x_simplified auto zero = [](fir::FirOpBuilder builder, mlir::Location loc, mlir::Type elementType) { - if (auto ty = mlir::dyn_cast(elementType)) { + if (auto ty = elementType.dyn_cast()) { const llvm::fltSemantics &sem = ty.getFloatSemantics(); return builder.createRealConstant(loc, elementType, llvm::APFloat::getZero(sem)); @@ -392,9 +392,9 @@ static void genRuntimeSumBody(fir::FirOpBuilder &builder, auto genBodyOp = [](fir::FirOpBuilder builder, mlir::Location loc, mlir::Type elementType, mlir::Value elem1, mlir::Value elem2) -> mlir::Value { - if (mlir::isa(elementType)) + if (elementType.isa()) return builder.create(loc, elem1, elem2); - if (mlir::isa(elementType)) + if (elementType.isa()) return builder.create(loc, elem1, elem2); llvm_unreachable("unsupported type"); @@ -414,7 +414,7 @@ static void genRuntimeMaxvalBody(fir::FirOpBuilder &builder, mlir::Type elementType) { auto init = [](fir::FirOpBuilder builder, mlir::Location loc, mlir::Type elementType) { - if (auto ty = mlir::dyn_cast(elementType)) { + if (auto ty = elementType.dyn_cast()) { const llvm::fltSemantics &sem = ty.getFloatSemantics(); return builder.createRealConstant( loc, elementType, llvm::APFloat::getLargest(sem, /*Negative=*/true)); @@ -427,7 +427,7 @@ static void genRuntimeMaxvalBody(fir::FirOpBuilder &builder, auto genBodyOp = [](fir::FirOpBuilder builder, mlir::Location loc, mlir::Type elementType, mlir::Value elem1, mlir::Value elem2) -> mlir::Value { - if (mlir::isa(elementType)) { + if (elementType.isa()) { // arith.maxf later converted to llvm.intr.maxnum does not work // correctly for NaNs and -0.0 (see maxnum/minnum pattern matching // in LLVM's InstCombine pass). Moreover, llvm.intr.maxnum @@ -439,7 +439,7 @@ static void genRuntimeMaxvalBody(fir::FirOpBuilder &builder, loc, mlir::arith::CmpFPredicate::OGT, elem1, elem2); return builder.create(loc, compare, elem1, elem2); } - if (mlir::isa(elementType)) + if (elementType.isa()) return builder.create(loc, elem1, elem2); llvm_unreachable("unsupported type"); @@ -662,7 +662,7 @@ static void genRuntimeMinMaxlocBody(fir::FirOpBuilder &builder, mlir::Type resultElemTy, bool isDim) { auto init = [isMax](fir::FirOpBuilder builder, mlir::Location loc, mlir::Type elementType) { - if (auto ty = mlir::dyn_cast(elementType)) { + if (auto ty = elementType.dyn_cast()) { const llvm::fltSemantics &sem = ty.getFloatSemantics(); llvm::APFloat limit = llvm::APFloat::getInf(sem, /*Negative=*/isMax); return builder.createRealConstant(loc, elementType, limit); @@ -744,7 +744,7 @@ static void genRuntimeMinMaxlocBody(fir::FirOpBuilder &builder, mlir::Value elem = builder.create(loc, addr); mlir::Value cmp; - if (mlir::isa(elementType)) { + if (elementType.isa()) { // For FP reductions we want the first smallest value to be used, that // is not NaN. A OGL/OLT condition will usually work for this unless all // the values are Nan or Inf. This follows the same logic as @@ -761,7 +761,7 @@ static void genRuntimeMinMaxlocBody(fir::FirOpBuilder &builder, loc, mlir::arith::CmpFPredicate::OEQ, elem, elem); cmpNan = builder.create(loc, cmpNan, cmpNan2); cmp = builder.create(loc, cmp, cmpNan); - } else if (mlir::isa(elementType)) { + } else if (elementType.isa()) { cmp = builder.create( loc, isMax ? mlir::arith::CmpIPredicate::sgt @@ -839,7 +839,7 @@ static void genRuntimeMinMaxlocBody(fir::FirOpBuilder &builder, builder.setInsertionPointToStart(&ifOp.getElseRegion().front()); mlir::Value basicValue; - if (mlir::isa(elementType)) { + if (elementType.isa()) { basicValue = builder.createIntegerConstant(loc, elementType, 0); } else { basicValue = builder.createRealConstant(loc, elementType, 0); @@ -921,7 +921,7 @@ static void genRuntimeDotBody(fir::FirOpBuilder &builder, mlir::IndexType idxTy = builder.getIndexType(); mlir::Value zero = - mlir::isa(resultElementType) + resultElementType.isa() ? builder.createRealConstant(loc, resultElementType, 0.0) : builder.createIntegerConstant(loc, resultElementType, 0); @@ -978,10 +978,10 @@ static void genRuntimeDotBody(fir::FirOpBuilder &builder, // Convert to the result type. elem2 = builder.create(loc, resultElementType, elem2); - if (mlir::isa(resultElementType)) + if (resultElementType.isa()) sumVal = builder.create( loc, builder.create(loc, elem1, elem2), sumVal); - else if (mlir::isa(resultElementType)) + else if (resultElementType.isa()) sumVal = builder.create( loc, builder.create(loc, elem1, elem2), sumVal); else @@ -1056,8 +1056,8 @@ void SimplifyIntrinsicsPass::simplifyIntOrFloatReduction( mlir::Type resultType = call.getResult(0).getType(); - if (!mlir::isa(resultType) && - !mlir::isa(resultType)) + if (!resultType.isa() && + !resultType.isa()) return; auto argType = getArgElementType(args[0]); @@ -1103,8 +1103,7 @@ void SimplifyIntrinsicsPass::simplifyLogicalDim0Reduction( fir::FirOpBuilder builder{getSimplificationBuilder(call, kindMap)}; // Treating logicals as integers makes things a lot easier - fir::LogicalType logicalType = { - mlir::dyn_cast(elementType)}; + fir::LogicalType logicalType = {elementType.dyn_cast()}; fir::KindTy kind = logicalType.getFKind(); mlir::Type intElementType = builder.getIntegerType(kind * 8); @@ -1139,8 +1138,7 @@ void SimplifyIntrinsicsPass::simplifyLogicalDim1Reduction( fir::FirOpBuilder builder{getSimplificationBuilder(call, kindMap)}; // Treating logicals as integers makes things a lot easier - fir::LogicalType logicalType = { - mlir::dyn_cast(elementType)}; + fir::LogicalType logicalType = {elementType.dyn_cast()}; fir::KindTy kind = logicalType.getFKind(); mlir::Type intElementType = builder.getIntegerType(kind * 8); @@ -1184,7 +1182,7 @@ void SimplifyIntrinsicsPass::simplifyMinMaxlocReduction( auto inputBox = findBoxDef(args[1]); mlir::Type inputType = hlfir::getFortranElementType(inputBox.getType()); - if (mlir::isa(inputType)) + if (inputType.isa()) return; int maskRank; @@ -1195,8 +1193,7 @@ void SimplifyIntrinsicsPass::simplifyMinMaxlocReduction( } else { maskRank = getDimCount(mask); mlir::Type maskElemTy = hlfir::getFortranElementType(maskDef.getType()); - fir::LogicalType logicalFirType = { - mlir::dyn_cast(maskElemTy)}; + fir::LogicalType logicalFirType = {maskElemTy.dyn_cast()}; kind = logicalFirType.getFKind(); // Convert fir::LogicalType to mlir::Type logicalElemType = logicalFirType; @@ -1305,8 +1302,7 @@ void SimplifyIntrinsicsPass::runOnOperation() { std::string fmfString{builder.getFastMathFlagsString()}; mlir::Type type = call.getResult(0).getType(); - if (!mlir::isa(type) && - !mlir::isa(type)) + if (!type.isa() && !type.isa()) return; // Try to find the element types of the boxed arguments. diff --git a/flang/lib/Optimizer/Transforms/StackArrays.cpp b/flang/lib/Optimizer/Transforms/StackArrays.cpp index 16bbb1c356460..c81524dd16a77 100644 --- a/flang/lib/Optimizer/Transforms/StackArrays.cpp +++ b/flang/lib/Optimizer/Transforms/StackArrays.cpp @@ -351,7 +351,7 @@ void AllocationAnalysis::visitOperation(mlir::Operation *op, } auto retTy = allocmem.getAllocatedType(); - if (!mlir::isa(retTy)) { + if (!retTy.isa()) { LLVM_DEBUG(llvm::dbgs() << "--Allocation is not for an array: skipping\n"); return; diff --git a/flang/unittests/Optimizer/Builder/ComplexTest.cpp b/flang/unittests/Optimizer/Builder/ComplexTest.cpp index 17171512470ac..5364eec904ff4 100644 --- a/flang/unittests/Optimizer/Builder/ComplexTest.cpp +++ b/flang/unittests/Optimizer/Builder/ComplexTest.cpp @@ -96,6 +96,6 @@ TEST_F(ComplexTest, verifyConvertWithSemantics) { // Convert complex to integer mlir::Value v2 = firBuilder->convertWithSemantics(loc, integerTy1, v1); - EXPECT_TRUE(mlir::isa(v2.getType())); + EXPECT_TRUE(v2.getType().isa()); EXPECT_TRUE(mlir::dyn_cast(v2.getDefiningOp())); } diff --git a/flang/unittests/Optimizer/Builder/DoLoopHelperTest.cpp b/flang/unittests/Optimizer/Builder/DoLoopHelperTest.cpp index d0a9342914a39..7e7206dbf934d 100644 --- a/flang/unittests/Optimizer/Builder/DoLoopHelperTest.cpp +++ b/flang/unittests/Optimizer/Builder/DoLoopHelperTest.cpp @@ -34,7 +34,7 @@ struct DoLoopHelperTest : public testing::Test { void checkConstantValue(const mlir::Value &value, int64_t v) { EXPECT_TRUE(mlir::isa(value.getDefiningOp())); auto cstOp = dyn_cast(value.getDefiningOp()); - auto valueAttr = dyn_cast_or_null(cstOp.getValue()); + auto valueAttr = cstOp.getValue().dyn_cast_or_null(); EXPECT_EQ(v, valueAttr.getInt()); } diff --git a/flang/unittests/Optimizer/Builder/FIRBuilderTest.cpp b/flang/unittests/Optimizer/Builder/FIRBuilderTest.cpp index e5e5454ee88ad..b6a1f9c9db8f0 100644 --- a/flang/unittests/Optimizer/Builder/FIRBuilderTest.cpp +++ b/flang/unittests/Optimizer/Builder/FIRBuilderTest.cpp @@ -54,7 +54,7 @@ static void checkIntegerConstant(mlir::Value value, mlir::Type ty, int64_t v) { EXPECT_TRUE(mlir::isa(value.getDefiningOp())); auto cstOp = dyn_cast(value.getDefiningOp()); EXPECT_EQ(ty, cstOp.getType()); - auto valueAttr = mlir::dyn_cast_or_null(cstOp.getValue()); + auto valueAttr = cstOp.getValue().dyn_cast_or_null(); EXPECT_EQ(v, valueAttr.getInt()); } @@ -151,7 +151,7 @@ TEST_F(FIRBuilderTest, createRealZeroConstant) { auto cstOp = dyn_cast(cst.getDefiningOp()); EXPECT_EQ(realTy, cstOp.getType()); EXPECT_EQ( - 0u, mlir::cast(cstOp.getValue()).getValue().convertToDouble()); + 0u, cstOp.getValue().cast().getValue().convertToDouble()); } TEST_F(FIRBuilderTest, createBool) { @@ -164,8 +164,8 @@ TEST_F(FIRBuilderTest, createBool) { TEST_F(FIRBuilderTest, getVarLenSeqTy) { auto builder = getBuilder(); auto ty = builder.getVarLenSeqTy(builder.getI64Type()); - EXPECT_TRUE(mlir::isa(ty)); - fir::SequenceType seqTy = mlir::dyn_cast(ty); + EXPECT_TRUE(ty.isa()); + fir::SequenceType seqTy = ty.dyn_cast(); EXPECT_EQ(1u, seqTy.getDimension()); EXPECT_TRUE(fir::unwrapSequenceType(ty).isInteger(64)); } @@ -216,9 +216,9 @@ TEST_F(FIRBuilderTest, createGlobal2) { EXPECT_FALSE(global.getConstant().has_value()); EXPECT_EQ(i32Type, global.getType()); EXPECT_TRUE(global.getInitVal().has_value()); - EXPECT_TRUE(mlir::isa(global.getInitVal().value())); - EXPECT_EQ(16, - mlir::cast(global.getInitVal().value()).getValue()); + EXPECT_TRUE(global.getInitVal().value().isa()); + EXPECT_EQ( + 16, global.getInitVal().value().cast().getValue()); EXPECT_TRUE(global.getLinkName().has_value()); EXPECT_EQ( builder.createLinkOnceLinkage().getValue(), global.getLinkName().value()); @@ -271,12 +271,12 @@ TEST_F(FIRBuilderTest, locationToFilename) { auto stringLitOps = global.getRegion().front().getOps(); EXPECT_TRUE(llvm::hasSingleElement(stringLitOps)); for (auto stringLit : stringLitOps) { - EXPECT_EQ( - 10, mlir::cast(stringLit.getSize()).getValue()); - EXPECT_TRUE(mlir::isa(stringLit.getValue())); + EXPECT_EQ(10, stringLit.getSize().cast().getValue()); + EXPECT_TRUE(stringLit.getValue().isa()); EXPECT_EQ(0, strcmp("file1.f90\0", - mlir::dyn_cast(stringLit.getValue()) + stringLit.getValue() + .dyn_cast() .getValue() .str() .c_str())); @@ -288,9 +288,9 @@ TEST_F(FIRBuilderTest, createStringLitOp) { llvm::StringRef data("mystringlitdata"); auto loc = builder.getUnknownLoc(); auto op = builder.createStringLitOp(loc, data); - EXPECT_EQ(15, mlir::cast(op.getSize()).getValue()); - EXPECT_TRUE(mlir::isa(op.getValue())); - EXPECT_EQ(data, mlir::dyn_cast(op.getValue()).getValue()); + EXPECT_EQ(15, op.getSize().cast().getValue()); + EXPECT_TRUE(op.getValue().isa()); + EXPECT_EQ(data, op.getValue().dyn_cast().getValue()); } TEST_F(FIRBuilderTest, createStringLiteral) { @@ -318,11 +318,9 @@ TEST_F(FIRBuilderTest, createStringLiteral) { auto stringLitOps = global.getRegion().front().getOps(); EXPECT_TRUE(llvm::hasSingleElement(stringLitOps)); for (auto stringLit : stringLitOps) { - EXPECT_EQ( - 16, mlir::cast(stringLit.getSize()).getValue()); - EXPECT_TRUE(mlir::isa(stringLit.getValue())); - EXPECT_EQ( - strValue, mlir::dyn_cast(stringLit.getValue()).getValue()); + EXPECT_EQ(16, stringLit.getSize().cast().getValue()); + EXPECT_TRUE(stringLit.getValue().isa()); + EXPECT_EQ(strValue, stringLit.getValue().dyn_cast().getValue()); } } @@ -346,7 +344,7 @@ TEST_F(FIRBuilderTest, allocateLocal) { static void checkShapeOp(mlir::Value shape, mlir::Value c10, mlir::Value c100) { EXPECT_TRUE(mlir::isa(shape.getDefiningOp())); fir::ShapeOp op = dyn_cast(shape.getDefiningOp()); - auto shapeTy = mlir::dyn_cast(op.getType()); + auto shapeTy = op.getType().dyn_cast(); EXPECT_EQ(2u, shapeTy.getRank()); EXPECT_EQ(2u, op.getExtents().size()); EXPECT_EQ(c10, op.getExtents()[0]); @@ -374,7 +372,7 @@ TEST_F(FIRBuilderTest, genShapeWithExtentsAndShapeShift) { auto shape = builder.genShape(loc, shifts, extents); EXPECT_TRUE(mlir::isa(shape.getDefiningOp())); fir::ShapeShiftOp op = dyn_cast(shape.getDefiningOp()); - auto shapeTy = mlir::dyn_cast(op.getType()); + auto shapeTy = op.getType().dyn_cast(); EXPECT_EQ(2u, shapeTy.getRank()); EXPECT_EQ(2u, op.getExtents().size()); EXPECT_EQ(2u, op.getOrigins().size()); @@ -430,7 +428,7 @@ TEST_F(FIRBuilderTest, createZeroValue) { auto cst = mlir::dyn_cast_or_null(zeroInt.getDefiningOp()); EXPECT_TRUE(cst); - auto intAttr = mlir::dyn_cast(cst.getValue()); + auto intAttr = cst.getValue().dyn_cast(); EXPECT_TRUE(intAttr && intAttr.getInt() == 0); mlir::Type f32Ty = mlir::FloatType::getF32(builder.getContext()); @@ -439,7 +437,7 @@ TEST_F(FIRBuilderTest, createZeroValue) { auto cst2 = mlir::dyn_cast_or_null( zeroFloat.getDefiningOp()); EXPECT_TRUE(cst2); - auto floatAttr = mlir::dyn_cast(cst2.getValue()); + auto floatAttr = cst2.getValue().dyn_cast(); EXPECT_TRUE(floatAttr && floatAttr.getValueAsDouble() == 0.); mlir::Type boolTy = mlir::IntegerType::get(builder.getContext(), 1); @@ -448,7 +446,7 @@ TEST_F(FIRBuilderTest, createZeroValue) { auto cst3 = mlir::dyn_cast_or_null( flaseBool.getDefiningOp()); EXPECT_TRUE(cst3); - auto intAttr2 = mlir::dyn_cast(cst.getValue()); + auto intAttr2 = cst.getValue().dyn_cast(); EXPECT_TRUE(intAttr2 && intAttr2.getInt() == 0); } @@ -484,7 +482,7 @@ TEST_F(FIRBuilderTest, getBaseTypeOf) { llvm::SmallVector arrays; auto extent = builder.create(loc, builder.getIndexType()); llvm::SmallVector extents( - mlir::dyn_cast(arrayType).getDimension(), + arrayType.dyn_cast().getDimension(), extent.getResult()); arrays.emplace_back(fir::ArrayBoxValue(ptrValArray, extents)); arrays.emplace_back(fir::BoxValue(boxValArray)); diff --git a/flang/unittests/Optimizer/RTBuilder.cpp b/flang/unittests/Optimizer/RTBuilder.cpp index d6cf96c4351c2..7fff7f71fc3b6 100644 --- a/flang/unittests/Optimizer/RTBuilder.cpp +++ b/flang/unittests/Optimizer/RTBuilder.cpp @@ -27,7 +27,7 @@ TEST(RTBuilderTest, ComplexRuntimeInterface) { mlir::Type c99_cacosf_signature{ fir::runtime::RuntimeTableKey::getTypeModel()( &ctx)}; - auto c99_cacosf_funcTy = mlir::cast(c99_cacosf_signature); + auto c99_cacosf_funcTy = c99_cacosf_signature.cast(); EXPECT_EQ(c99_cacosf_funcTy.getNumInputs(), 1u); EXPECT_EQ(c99_cacosf_funcTy.getNumResults(), 1u); auto cplx_ty = fir::ComplexType::get(&ctx, 4); diff --git a/llvm/include/llvm/ADT/TypeSwitch.h b/llvm/include/llvm/ADT/TypeSwitch.h index 14ad56ad575ff..10a2d48e918db 100644 --- a/llvm/include/llvm/ADT/TypeSwitch.h +++ b/llvm/include/llvm/ADT/TypeSwitch.h @@ -74,10 +74,7 @@ template class TypeSwitchBase { ValueT &&value, std::enable_if_t::value> * = nullptr) { - // Silence warnings about MLIR's deprecated dyn_cast member functions. - LLVM_SUPPRESS_DEPRECATED_DECLARATIONS_PUSH return value.template dyn_cast(); - LLVM_SUPPRESS_DEPRECATED_DECLARATIONS_POP } /// Attempt to dyn_cast the given `value` to `CastT`. This overload is diff --git a/mlir/include/mlir/Dialect/Linalg/IR/LinalgOps.td b/mlir/include/mlir/Dialect/Linalg/IR/LinalgOps.td index 64c538367267d..da12e7c83b22b 100644 --- a/mlir/include/mlir/Dialect/Linalg/IR/LinalgOps.td +++ b/mlir/include/mlir/Dialect/Linalg/IR/LinalgOps.td @@ -138,10 +138,10 @@ def Linalg_SoftmaxOp : Linalg_Op<"softmax", let extraClassDeclaration = [{ ShapedType getInputOperandType() { - return cast(getInput().getType()); + return getInput().getType().cast(); } ShapedType getOutputOperandType() { - return cast(getOutput().getType()); + return getOutput().getType().cast(); } int64_t getInputOperandRank() { return getInputOperandType().getRank(); diff --git a/mlir/include/mlir/Dialect/OpenMP/OpenMPOpsInterfaces.td b/mlir/include/mlir/Dialect/OpenMP/OpenMPOpsInterfaces.td index d9569d9d294d8..ab9b78e755d9d 100644 --- a/mlir/include/mlir/Dialect/OpenMP/OpenMPOpsInterfaces.td +++ b/mlir/include/mlir/Dialect/OpenMP/OpenMPOpsInterfaces.td @@ -234,8 +234,8 @@ def OffloadModuleInterface : OpInterface<"OffloadModuleInterface"> { /*methodName=*/"getIsTargetDevice", (ins), [{}], [{ if (Attribute isTargetDevice = $_op->getAttr("omp.is_target_device")) - if (::llvm::isa(isTargetDevice)) - return ::llvm::dyn_cast(isTargetDevice).getValue(); + if (isTargetDevice.isa()) + return isTargetDevice.dyn_cast().getValue(); return false; }]>, InterfaceMethod< @@ -259,7 +259,7 @@ def OffloadModuleInterface : OpInterface<"OffloadModuleInterface"> { /*methodName=*/"getIsGPU", (ins), [{}], [{ if (Attribute isTargetCGAttr = $_op->getAttr("omp.is_gpu")) - if (auto isTargetCGVal = ::llvm::dyn_cast(isTargetCGAttr)) + if (auto isTargetCGVal = isTargetCGAttr.dyn_cast()) return isTargetCGVal.getValue(); return false; }]>, @@ -332,7 +332,7 @@ def OffloadModuleInterface : OpInterface<"OffloadModuleInterface"> { /*methodName=*/"getRequires", (ins), [{}], [{ if (Attribute requiresAttr = $_op->getAttr("omp.requires")) - if (auto requiresVal = ::llvm::dyn_cast(requiresAttr)) + if (auto requiresVal = requiresAttr.dyn_cast()) return requiresVal.getValue(); return mlir::omp::ClauseRequires::none; }]>, diff --git a/mlir/include/mlir/Dialect/XeGPU/IR/XeGPUOps.td b/mlir/include/mlir/Dialect/XeGPU/IR/XeGPUOps.td index e477d9a0ca3f1..88f2e1acfeeb5 100644 --- a/mlir/include/mlir/Dialect/XeGPU/IR/XeGPUOps.td +++ b/mlir/include/mlir/Dialect/XeGPU/IR/XeGPUOps.td @@ -164,10 +164,10 @@ def XeGPU_CreateNdDescOp: XeGPU_Op<"create_nd_tdesc", [Pure, ViewLikeOpInterface /// source operand. They overide static shape from source memref type. ArrayRef getStaticSizes() { auto attr = getConstShapeAttr(); - if (llvm::isa(getSourceType()) || attr) + if (getSourceType().isa() || attr) return attr; - auto memrefType = llvm::dyn_cast(getSourceType()); + auto memrefType = getSourceType().dyn_cast(); assert(memrefType && "Incorrect use of getStaticSizes"); return memrefType.getShape(); } @@ -179,10 +179,10 @@ def XeGPU_CreateNdDescOp: XeGPU_Op<"create_nd_tdesc", [Pure, ViewLikeOpInterface /// source operand. They overide static strides from source memref type. ArrayRef getStaticStrides() { auto attr = getConstStridesAttr(); - if (llvm::isa(getSourceType()) || attr) + if (getSourceType().isa() || attr) return attr; - auto memrefType = llvm::dyn_cast(getSourceType()); + auto memrefType = getSourceType().dyn_cast(); assert(memrefType && "Incorrect use of getStaticStrides"); auto [strides, offset] = getStridesAndOffset(memrefType); // reuse the storage of ConstStridesAttr since strides from @@ -196,7 +196,7 @@ def XeGPU_CreateNdDescOp: XeGPU_Op<"create_nd_tdesc", [Pure, ViewLikeOpInterface /// `static_shape` and `static_strides` attributes. std::array getArrayAttrMaxRanks() { unsigned rank; - if (auto ty = llvm::dyn_cast(getSourceType())) { + if (auto ty = getSourceType().dyn_cast()) { rank = ty.getRank(); } else { rank = (unsigned)getMixedOffsets().size(); diff --git a/mlir/include/mlir/IR/Attributes.h b/mlir/include/mlir/IR/Attributes.h index 8a077865b51b5..cc0cee6a31183 100644 --- a/mlir/include/mlir/IR/Attributes.h +++ b/mlir/include/mlir/IR/Attributes.h @@ -50,19 +50,14 @@ class Attribute { /// Casting utility functions. These are deprecated and will be removed, /// please prefer using the `llvm` namespace variants instead. template - [[deprecated("Use mlir::isa() instead")]] bool isa() const; template - [[deprecated("Use mlir::isa_and_nonnull() instead")]] bool isa_and_nonnull() const; template - [[deprecated("Use mlir::dyn_cast() instead")]] U dyn_cast() const; template - [[deprecated("Use mlir::dyn_cast_or_null() instead")]] U dyn_cast_or_null() const; template - [[deprecated("Use mlir::cast() instead")]] U cast() const; /// Return a unique identifier for the concrete attribute type. This is used diff --git a/mlir/include/mlir/IR/BuiltinLocationAttributes.td b/mlir/include/mlir/IR/BuiltinLocationAttributes.td index 5a72404dea15b..dfcc180071f72 100644 --- a/mlir/include/mlir/IR/BuiltinLocationAttributes.td +++ b/mlir/include/mlir/IR/BuiltinLocationAttributes.td @@ -228,8 +228,7 @@ def OpaqueLoc : Builtin_LocationAttr<"OpaqueLoc"> { template static T getUnderlyingLocation(Location location) { assert(isa(location)); return reinterpret_cast( - mlir::cast(static_cast(location)) - .getUnderlyingLocation()); + location.cast().getUnderlyingLocation()); } /// Returns a pointer to some data structure that opaque location stores. @@ -238,17 +237,15 @@ def OpaqueLoc : Builtin_LocationAttr<"OpaqueLoc"> { template static T getUnderlyingLocationOrNull(Location location) { return isa(location) - ? reinterpret_cast(mlir::cast( - static_cast(location)) - .getUnderlyingLocation()) - : T(nullptr); + ? reinterpret_cast( + location.cast().getUnderlyingLocation()) + : T(nullptr); } /// Checks whether provided location is opaque location and contains a /// pointer to an object of particular type. template static bool isa(Location location) { - auto opaque_loc = - mlir::dyn_cast(static_cast(location)); + auto opaque_loc = location.dyn_cast(); return opaque_loc && opaque_loc.getUnderlyingTypeID() == TypeID::get(); } }]; diff --git a/mlir/include/mlir/IR/Location.h b/mlir/include/mlir/IR/Location.h index 423b4d19b5b94..aa8314f38cdfa 100644 --- a/mlir/include/mlir/IR/Location.h +++ b/mlir/include/mlir/IR/Location.h @@ -78,17 +78,14 @@ class Location { /// Type casting utilities on the underlying location. template - [[deprecated("Use mlir::isa() instead")]] bool isa() const { return llvm::isa(*this); } template - [[deprecated("Use mlir::dyn_cast() instead")]] U dyn_cast() const { return llvm::dyn_cast(*this); } template - [[deprecated("Use mlir::cast() instead")]] U cast() const { return llvm::cast(*this); } diff --git a/mlir/include/mlir/IR/Types.h b/mlir/include/mlir/IR/Types.h index 65824531fdc90..a89e13b625bf4 100644 --- a/mlir/include/mlir/IR/Types.h +++ b/mlir/include/mlir/IR/Types.h @@ -97,19 +97,14 @@ class Type { bool operator!() const { return impl == nullptr; } template - [[deprecated("Use mlir::isa() instead")]] bool isa() const; template - [[deprecated("Use mlir::isa_and_nonnull() instead")]] bool isa_and_nonnull() const; template - [[deprecated("Use mlir::dyn_cast() instead")]] U dyn_cast() const; template - [[deprecated("Use mlir::dyn_cast_or_null() instead")]] U dyn_cast_or_null() const; template - [[deprecated("Use mlir::cast() instead")]] U cast() const; /// Return a unique identifier for the concrete type. This is used to support diff --git a/mlir/include/mlir/IR/Value.h b/mlir/include/mlir/IR/Value.h index a7344c64e6730..cdbc6cc374368 100644 --- a/mlir/include/mlir/IR/Value.h +++ b/mlir/include/mlir/IR/Value.h @@ -98,25 +98,25 @@ class Value { constexpr Value(detail::ValueImpl *impl = nullptr) : impl(impl) {} template - [[deprecated("Use mlir::isa() instead")]] + [[deprecated("Use isa() instead")]] bool isa() const { return llvm::isa(*this); } template - [[deprecated("Use mlir::dyn_cast() instead")]] + [[deprecated("Use dyn_cast() instead")]] U dyn_cast() const { return llvm::dyn_cast(*this); } template - [[deprecated("Use mlir::dyn_cast_or_null() instead")]] + [[deprecated("Use dyn_cast_or_null() instead")]] U dyn_cast_or_null() const { return llvm::dyn_cast_or_null(*this); } template - [[deprecated("Use mlir::cast() instead")]] + [[deprecated("Use cast() instead")]] U cast() const { return llvm::cast(*this); } diff --git a/mlir/lib/Conversion/ComplexToStandard/ComplexToStandard.cpp b/mlir/lib/Conversion/ComplexToStandard/ComplexToStandard.cpp index c2a83f90bcbe9..4a15976d40c76 100644 --- a/mlir/lib/Conversion/ComplexToStandard/ComplexToStandard.cpp +++ b/mlir/lib/Conversion/ComplexToStandard/ComplexToStandard.cpp @@ -857,7 +857,7 @@ struct SqrtOpConversion : public OpConversionPattern { ImplicitLocOpBuilder b(op.getLoc(), rewriter); auto type = cast(op.getType()); - auto elementType = cast(type.getElementType()); + auto elementType = type.getElementType().cast(); arith::FastMathFlags fmf = op.getFastMathFlagsAttr().getValue(); auto cst = [&](APFloat v) { diff --git a/mlir/lib/Dialect/Polynomial/IR/PolynomialAttributes.cpp b/mlir/lib/Dialect/Polynomial/IR/PolynomialAttributes.cpp index f1ec2be72a33a..ee09c73bb3c4a 100644 --- a/mlir/lib/Dialect/Polynomial/IR/PolynomialAttributes.cpp +++ b/mlir/lib/Dialect/Polynomial/IR/PolynomialAttributes.cpp @@ -172,7 +172,7 @@ Attribute RingAttr::parse(AsmParser &parser, Type type) { if (failed(parser.parseEqual())) return {}; - IntegerType iType = mlir::dyn_cast(ty); + IntegerType iType = ty.dyn_cast(); if (!iType) { parser.emitError(parser.getCurrentLocation(), "coefficientType must specify an integer type"); diff --git a/mlir/lib/Dialect/Vector/Transforms/VectorLinearize.cpp b/mlir/lib/Dialect/Vector/Transforms/VectorLinearize.cpp index 802a64b0805ee..69999f0918c10 100644 --- a/mlir/lib/Dialect/Vector/Transforms/VectorLinearize.cpp +++ b/mlir/lib/Dialect/Vector/Transforms/VectorLinearize.cpp @@ -140,7 +140,7 @@ struct LinearizeVectorExtractStridedSlice final ConversionPatternRewriter &rewriter) const override { Type dstType = getTypeConverter()->convertType(extractOp.getType()); assert(!(extractOp.getVector().getType().isScalable() || - cast(dstType).isScalable()) && + dstType.cast().isScalable()) && "scalable vectors are not supported."); if (!isLessThanTargetBitWidth(extractOp, targetVectorBitWidth)) return rewriter.notifyMatchFailure( @@ -172,7 +172,7 @@ struct LinearizeVectorExtractStridedSlice final // Get total number of extracted slices. int64_t nExtractedSlices = 1; for (Attribute size : sizes) { - nExtractedSlices *= cast(size).getInt(); + nExtractedSlices *= size.cast().getInt(); } // Compute the strides of the source vector considering first k dimensions. llvm::SmallVector sourceStrides(kD, extractGranularitySize); @@ -189,7 +189,7 @@ struct LinearizeVectorExtractStridedSlice final // Compute extractedStrides. for (int i = kD - 2; i >= 0; --i) { extractedStrides[i] = - extractedStrides[i + 1] * cast(sizes[i + 1]).getInt(); + extractedStrides[i + 1] * sizes[i + 1].cast().getInt(); } // Iterate over all extracted slices from 0 to nExtractedSlices - 1 // and compute the multi-dimensional index and the corresponding linearized @@ -207,7 +207,7 @@ struct LinearizeVectorExtractStridedSlice final int64_t linearizedIndex = 0; for (int64_t j = 0; j < kD; ++j) { linearizedIndex += - (cast(offsets[j]).getInt() + multiDimIndex[j]) * + (offsets[j].cast().getInt() + multiDimIndex[j]) * sourceStrides[j]; } // Fill the indices array form linearizedIndex to linearizedIndex + @@ -254,7 +254,7 @@ struct LinearizeVectorShuffle final Type dstType = getTypeConverter()->convertType(shuffleOp.getType()); assert(!(shuffleOp.getV1VectorType().isScalable() || shuffleOp.getV2VectorType().isScalable() || - cast(dstType).isScalable()) && + dstType.cast().isScalable()) && "scalable vectors are not supported."); if (!isLessThanTargetBitWidth(shuffleOp, targetVectorBitWidth)) return rewriter.notifyMatchFailure( @@ -324,7 +324,7 @@ struct LinearizeVectorExtract final ConversionPatternRewriter &rewriter) const override { Type dstTy = getTypeConverter()->convertType(extractOp.getType()); assert(!(extractOp.getVector().getType().isScalable() || - cast(dstTy).isScalable()) && + dstTy.cast().isScalable()) && "scalable vectors are not supported."); if (!isLessThanTargetBitWidth(extractOp, targetVectorBitWidth)) return rewriter.notifyMatchFailure( @@ -405,7 +405,9 @@ void mlir::vector::populateVectorLinearizeShuffleLikeOpsPatterns( [=](vector::ShuffleOp shuffleOp) -> bool { return isLessThanTargetBitWidth(shuffleOp, targetBitWidth) ? (typeConverter.isLegal(shuffleOp) && - cast(shuffleOp.getResult().getType()) + shuffleOp.getResult() + .getType() + .cast() .getRank() == 1) : true; });