diff --git a/flang/include/flang/Lower/Mangler.h b/flang/include/flang/Lower/Mangler.h --- a/flang/include/flang/Lower/Mangler.h +++ b/flang/include/flang/Lower/Mangler.h @@ -88,7 +88,7 @@ return mangleArrayLiteral(x.values().size() * sizeof(x.values()[0]), x.shape(), Fortran::common::TypeCategory::Derived, /*kind=*/0, /*charLen=*/-1, - eleTy.cast().getName()); + mlir::cast(eleTy).getName()); } /// Return the compiler-generated name of a static namelist variable descriptor. diff --git a/flang/include/flang/Optimizer/Builder/BoxValue.h b/flang/include/flang/Optimizer/Builder/BoxValue.h --- a/flang/include/flang/Optimizer/Builder/BoxValue.h +++ b/flang/include/flang/Optimizer/Builder/BoxValue.h @@ -78,7 +78,7 @@ public: CharBoxValue(mlir::Value addr, mlir::Value len) : AbstractBox{addr}, len{len} { - if (addr && addr.getType().template isa()) + if (addr && mlir::isa(addr.getType())) fir::emitFatalError(addr.getLoc(), "BoxChar should not be in CharBoxValue"); } @@ -221,7 +221,7 @@ auto type = getAddr().getType(); if (auto pointedTy = fir::dyn_cast_ptrEleTy(type)) type = pointedTy; - return type.cast(); + return mlir::cast(type); } /// 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 @@ /// Get the scalar type related to the described entity mlir::Type getEleTy() const { auto type = getBaseTy(); - if (auto seqTy = type.dyn_cast()) + if (auto seqTy = mlir::dyn_cast(type)) return seqTy.getEleTy(); return type; } /// Is the entity an array or an assumed rank ? - bool hasRank() const { return getBaseTy().isa(); } + bool hasRank() const { return mlir::isa(getBaseTy()); } /// Is this an assumed rank ? bool hasAssumedRank() const { - auto seqTy = getBaseTy().dyn_cast(); + auto seqTy = mlir::dyn_cast(getBaseTy()); 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 = getBaseTy().dyn_cast()) + if (auto seqTy = mlir::dyn_cast(getBaseTy())) return seqTy.getDimension(); return 0; } @@ -267,7 +267,7 @@ bool isCharacter() const { return fir::isa_char(getEleTy()); } /// Is this a derived type entity ? - bool isDerived() const { return getEleTy().isa(); } + bool isDerived() const { return mlir::isa(getEleTy()); } bool isDerivedWithLenParameters() const { return fir::isRecordWithTypeParameters(getEleTy()); @@ -377,11 +377,11 @@ } /// Is this a Fortran pointer ? bool isPointer() const { - return getBoxTy().getEleTy().isa(); + return mlir::isa(getBoxTy().getEleTy()); } /// Is this an allocatable ? bool isAllocatable() const { - return getBoxTy().getEleTy().isa(); + return mlir::isa(getBoxTy().getEleTy()); } // Replace the fir.ref, keeping any non-deferred parameters. MutableBoxValue clone(mlir::Value newBox) const { @@ -488,7 +488,7 @@ if (const auto *b = getUnboxed()) { if (*b) { auto type = b->getType(); - if (type.template isa()) + if (mlir::isa(type)) 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 --- a/flang/include/flang/Optimizer/Builder/Factory.h +++ b/flang/include/flang/Optimizer/Builder/Factory.h @@ -43,9 +43,9 @@ void genCharacterCopy(mlir::Value src, mlir::Value srcLen, mlir::Value dst, mlir::Value dstLen, B &builder, mlir::Location loc) { auto srcTy = - fir::dyn_cast_ptrEleTy(src.getType()).template cast(); + mlir::cast(fir::dyn_cast_ptrEleTy(src.getType())); auto dstTy = - fir::dyn_cast_ptrEleTy(dst.getType()).template cast(); + mlir::cast(fir::dyn_cast_ptrEleTy(dst.getType())); if (!srcLen && !dstLen && srcTy.getFKind() == dstTy.getFKind() && srcTy.getLen() == dstTy.getLen()) { // same size, so just use load and store @@ -61,8 +61,8 @@ fir::CharacterType::getSingleton(ty.getContext(), ty.getFKind()))); }; auto toEleTy = [&](fir::ReferenceType ty) { - auto seqTy = ty.getEleTy().cast(); - return seqTy.getEleTy().cast(); + auto seqTy = mlir::cast(ty.getEleTy()); + return mlir::cast(seqTy.getEleTy()); }; auto toCoorTy = [&](fir::ReferenceType ty) { return fir::ReferenceType::get(toEleTy(ty)); @@ -190,8 +190,8 @@ if (origins.empty()) { assert(!shapeVal || mlir::isa(shapeVal.getDefiningOp())); auto ty = fir::dyn_cast_ptrOrBoxEleTy(memTy); - assert(ty && ty.isa()); - auto seqTy = ty.cast(); + assert(ty && mlir::isa(ty)); + auto seqTy = mlir::cast(ty); 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 --- a/flang/include/flang/Optimizer/Builder/HLFIRTools.h +++ b/flang/include/flang/Optimizer/Builder/HLFIRTools.h @@ -37,14 +37,14 @@ /// Is this an SSA value type for the value of a Fortran procedure /// designator ? inline bool isFortranProcedureValue(mlir::Type type) { - return type.isa() || - (type.isa() && + return mlir::isa(type) || + (mlir::isa(type) && 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 type.isa() || fir::isa_trivial(type) || + return mlir::isa(type) || fir::isa_trivial(type) || isFortranProcedureValue(type); } @@ -101,12 +101,12 @@ /// 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 = type.dyn_cast()) { + if (auto seqTy = mlir::dyn_cast(type)) { if (seqTy.hasUnknownShape()) return -1; return seqTy.getDimension(); } - if (auto exprType = type.dyn_cast()) + if (auto exprType = mlir::dyn_cast(type)) return exprType.getRank(); return 0; } @@ -123,17 +123,17 @@ bool hasLengthParameters() const { mlir::Type eleTy = getFortranElementType(); - return eleTy.isa() || + return mlir::isa(eleTy) || fir::isRecordWithTypeParameters(eleTy); } bool isCharacter() const { - return getFortranElementType().isa(); + return mlir::isa(getFortranElementType()); } bool hasIntrinsicType() const { mlir::Type eleTy = getFortranElementType(); - return fir::isa_trivial(eleTy) || eleTy.isa(); + return fir::isa_trivial(eleTy) || mlir::isa(eleTy); } bool isDerivedWithLengthParameters() const { @@ -148,8 +148,8 @@ if (auto varIface = getIfVariableInterface()) { if (auto shape = varIface.getShape()) { auto shapeTy = shape.getType(); - return shapeTy.isa() || - shapeTy.isa(); + return mlir::isa(shapeTy) || + mlir::isa(shapeTy); } return false; } diff --git a/flang/include/flang/Optimizer/CodeGen/TypeConverter.h b/flang/include/flang/Optimizer/CodeGen/TypeConverter.h --- a/flang/include/flang/Optimizer/CodeGen/TypeConverter.h +++ b/flang/include/flang/Optimizer/CodeGen/TypeConverter.h @@ -104,7 +104,7 @@ // interior dimensions lowers to a memory reference. In that case, we // degenerate the array and do not want a the type to become `T**` but // merely `T*`. - if (auto seqTy = eleTy.dyn_cast()) { + if (auto seqTy = mlir::dyn_cast(eleTy)) { if (seqTy.hasDynamicExtents() || characterWithDynamicLen(seqTy.getEleTy())) { if (seqTy.getConstantRows() > 0) @@ -118,7 +118,7 @@ // the same as a fir.box at the LLVM level. // The distinction is kept in fir to denote when a descriptor is expected // to be mutable (fir.ref) and when it is not (fir.box). - if (eleTy.isa()) + if (mlir::isa(eleTy)) return convertType(eleTy); return mlir::LLVM::LLVMPointerType::get(convertType(eleTy)); diff --git a/flang/include/flang/Optimizer/Dialect/CanonicalizationPatterns.td b/flang/include/flang/Optimizer/Dialect/CanonicalizationPatterns.td --- a/flang/include/flang/Optimizer/Dialect/CanonicalizationPatterns.td +++ b/flang/include/flang/Optimizer/Dialect/CanonicalizationPatterns.td @@ -21,17 +21,17 @@ def IdenticalTypePred : Constraint>; def IntegerTypePred : Constraint>; -def IndexTypePred : Constraint()">>; +def IndexTypePred : Constraint($0.getType())">>; // Widths are monotonic. // $0.bits >= $1.bits >= $2.bits or $0.bits <= $1.bits <= $2.bits def MonotonicTypePred - : Constraint() && " - " $1.getType().isa() && " - " $2.getType().isa()) || " - " ($0.getType().isa() && " - " $1.getType().isa() && " - " $2.getType().isa())) && " + : Constraint($0.getType()) && " + " mlir::isa($1.getType()) && " + " mlir::isa($2.getType())) || " + " (mlir::isa($0.getType()) && " + " mlir::isa($1.getType()) && " + " mlir::isa($2.getType()))) && " "(($0.getType().getIntOrFloatBitWidth() <= " " $1.getType().getIntOrFloatBitWidth() && " " $1.getType().getIntOrFloatBitWidth() <= " @@ -42,9 +42,9 @@ " $2.getType().getIntOrFloatBitWidth()))">>; def IntPred : Constraint() && " - "$1.getType().isa()">>; - + "mlir::isa($0.getType()) && " + "mlir::isa($1.getType())">>; + // If both are int type and the first is smaller than the second. // $0.bits <= $1.bits def SmallerWidthPred : Constraint" "($_loc, $_builder.getIndexType(), " - "rewriter.getIndexAttr($1.dyn_cast()" + "rewriter.getIndexAttr(mlir::dyn_cast($1)" ".getInt()))">; def ForwardConstantConvertPattern diff --git a/flang/include/flang/Optimizer/Dialect/FIROps.td b/flang/include/flang/Optimizer/Dialect/FIROps.td --- a/flang/include/flang/Optimizer/Dialect/FIROps.td +++ b/flang/include/flang/Optimizer/Dialect/FIROps.td @@ -2614,14 +2614,13 @@ let hasCanonicalizer = 1; } -def FortranTypeAttr : Attr()">, - Or<[CPred<"$_self.cast().getValue().isa()">]>]>, +def FortranTypeAttr : Attr($_self)">, + Or<[CPred<"mlir::isa(mlir::cast($_self).getValue())">]>]>, "Fortran surface type"> { let storageType = [{ ::mlir::TypeAttr }]; let returnType = "mlir::Type"; - let convertFromStorage = "$_self.getValue().cast()"; + let convertFromStorage = "mlir::cast($_self.getValue())"; } def fir_TypeDescOp : fir_OneResultOp<"type_desc", [NoMemoryEffect]> { diff --git a/flang/include/flang/Optimizer/Dialect/FIROpsSupport.h b/flang/include/flang/Optimizer/Dialect/FIROpsSupport.h --- a/flang/include/flang/Optimizer/Dialect/FIROpsSupport.h +++ b/flang/include/flang/Optimizer/Dialect/FIROpsSupport.h @@ -136,7 +136,7 @@ inline std::optional getIntIfConstant(mlir::Value value) { if (auto *definingOp = value.getDefiningOp()) if (auto cst = mlir::dyn_cast(definingOp)) - if (auto intAttr = cst.getValue().dyn_cast()) + if (auto intAttr = mlir::dyn_cast(cst.getValue())) return intAttr.getInt(); return {}; } diff --git a/flang/include/flang/Optimizer/Dialect/FIRType.h b/flang/include/flang/Optimizer/Dialect/FIRType.h --- a/flang/include/flang/Optimizer/Dialect/FIRType.h +++ b/flang/include/flang/Optimizer/Dialect/FIRType.h @@ -71,7 +71,7 @@ struct RecordTypeStorage; } // namespace detail -// These isa_ routines follow the precedent of llvm::isa_or_null<> +// These isa_ routines follow the precedent of mlir::isa_or_null<> /// Is `t` any of the FIR dialect types? bool isa_fir_type(mlir::Type t); @@ -84,35 +84,36 @@ /// Is `t` a FIR dialect type that implies a memory (de)reference? inline bool isa_ref_type(mlir::Type t) { - return t.isa(); + return mlir::isa(t); } /// Is `t` a boxed type? inline bool isa_box_type(mlir::Type t) { - return t.isa(); + return mlir::isa(t); } /// 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 t.isa() || isa_box_type(t); + return mlir::isa(t) || + 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) || t.isa(); + return isa_ref_type(t) || isa_box_type(t) || mlir::isa(t); } /// Is `t` a derived (record) type? -inline bool isa_derived(mlir::Type t) { return t.isa(); } +inline bool isa_derived(mlir::Type t) { return mlir::isa(t); } /// Is `t` type(c_ptr) or type(c_funptr)? inline bool isa_builtin_cptr_type(mlir::Type t) { - if (auto recTy = t.dyn_cast_or_null()) + if (auto recTy = mlir::dyn_cast_if_present(t)) return recTy.getName().endswith("T__builtin_c_ptr") || recTy.getName().endswith("T__builtin_c_funptr"); return false; @@ -120,7 +121,7 @@ /// Is `t` a FIR dialect aggregate type? inline bool isa_aggregate(mlir::Type t) { - return t.isa() || fir::isa_derived(t); + return mlir::isa(t) || fir::isa_derived(t); } /// Extract the `Type` pointed to from a FIR memory reference type. If `t` is @@ -133,12 +134,12 @@ /// Is `t` a FIR Real or MLIR Float type? inline bool isa_real(mlir::Type t) { - return t.isa(); + return mlir::isa(t); } /// Is `t` an integral type? inline bool isa_integer(mlir::Type t) { - return t.isa(); + return mlir::isa(t); } mlir::Type parseFirType(FIROpsDialect *, mlir::DialectAsmParser &parser); @@ -151,22 +152,22 @@ /// Is `t` a FIR or MLIR Complex type? inline bool isa_complex(mlir::Type t) { - return t.isa(); + return mlir::isa(t); } /// Is `t` a CHARACTER type? Does not check the length. -inline bool isa_char(mlir::Type t) { return t.isa(); } +inline bool isa_char(mlir::Type t) { return mlir::isa(t); } /// 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) || - t.isa(); + mlir::isa(t); } /// Is `t` a CHARACTER type with a LEN other than 1? inline bool isa_char_string(mlir::Type t) { - if (auto ct = t.dyn_cast_or_null()) + if (auto ct = mlir::dyn_cast_if_present(t)) return ct.getLen() != fir::CharacterType::singleton(); return false; } @@ -180,7 +181,7 @@ /// Returns true iff `t` is a fir.char type and has an unknown length. inline bool characterWithDynamicLen(mlir::Type t) { - if (auto charTy = t.dyn_cast()) + if (auto charTy = mlir::dyn_cast(t)) return charTy.hasDynamicLen(); return false; } @@ -195,11 +196,11 @@ bool hasDynamicSize(mlir::Type t); inline unsigned getRankOfShapeType(mlir::Type t) { - if (auto shTy = t.dyn_cast()) + if (auto shTy = mlir::dyn_cast(t)) return shTy.getRank(); - if (auto shTy = t.dyn_cast()) + if (auto shTy = mlir::dyn_cast(t)) return shTy.getRank(); - if (auto shTy = t.dyn_cast()) + if (auto shTy = mlir::dyn_cast(t)) return shTy.getRank(); return 0; } @@ -207,14 +208,14 @@ /// 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 (!eleTy.isa()) + if (!mlir::isa(eleTy)) 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 = t.dyn_cast()) + if (auto seqTy = mlir::dyn_cast(t)) return seqTy.getEleTy(); return t; } @@ -257,7 +258,7 @@ t = ty; continue; } - if (auto seqTy = t.dyn_cast()) + if (auto seqTy = mlir::dyn_cast(t)) return seqTy; return {}; } @@ -266,8 +267,8 @@ /// 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 fir::unwrapSequenceType(fir::unwrapRefType(boxTy.getEleTy())) - .template dyn_cast(); + return mlir::dyn_cast( + fir::unwrapSequenceType(fir::unwrapRefType(boxTy.getEleTy()))); } /// Return true iff `boxTy` wraps a fir::RecordType with length parameters @@ -341,7 +342,7 @@ /// Return true iff `ty` is a RecordType with type parameters. inline bool isRecordWithTypeParameters(mlir::Type ty) { - if (auto recTy = ty.dyn_cast_or_null()) + if (auto recTy = mlir::dyn_cast_if_present(ty)) return recTy.isDependentType(); return false; } @@ -365,14 +366,14 @@ int getTypeCode(mlir::Type ty, const KindMapping &kindMap); inline bool BaseBoxType::classof(mlir::Type type) { - return type.isa(); + return mlir::isa(type); } /// Return true iff `ty` is none or fir.array. inline bool isNoneOrSeqNone(mlir::Type type) { - if (auto seqTy = type.dyn_cast()) - return seqTy.getEleTy().isa(); - return type.isa(); + if (auto seqTy = mlir::dyn_cast(type)) + return mlir::isa(seqTy.getEleTy()); + return mlir::isa(type); } /// Return a fir.box or fir.class if the type is polymorphic. If the type @@ -392,28 +393,29 @@ /// !fir.array<2xf32> -> !fir.array<2xnone> /// !fir.heap> -> !fir.heap> inline mlir::Type updateTypeForUnlimitedPolymorphic(mlir::Type ty) { - if (auto seqTy = ty.dyn_cast()) + if (auto seqTy = mlir::dyn_cast(ty)) return fir::SequenceType::get( seqTy.getShape(), updateTypeForUnlimitedPolymorphic(seqTy.getEleTy())); - if (auto heapTy = ty.dyn_cast()) + if (auto heapTy = mlir::dyn_cast(ty)) return fir::HeapType::get( updateTypeForUnlimitedPolymorphic(heapTy.getEleTy())); - if (auto pointerTy = ty.dyn_cast()) + if (auto pointerTy = mlir::dyn_cast(ty)) return fir::PointerType::get( updateTypeForUnlimitedPolymorphic(pointerTy.getEleTy())); - if (!ty.isa()) + if (!mlir::isa(ty)) return mlir::NoneType::get(ty.getContext()); return ty; } /// Is `t` an address to fir.box or class type? inline bool isBoxAddress(mlir::Type t) { - return fir::isa_ref_type(t) && fir::unwrapRefType(t).isa(); + return fir::isa_ref_type(t) && + mlir::isa(fir::unwrapRefType(t)); } /// Is `t` a fir.box or class address or value type? inline bool isBoxAddressOrValue(mlir::Type t) { - return fir::unwrapRefType(t).isa(); + return mlir::isa(fir::unwrapRefType(t)); } /// Return a string representation of `ty`. diff --git a/flang/include/flang/Optimizer/Dialect/FIRTypes.td b/flang/include/flang/Optimizer/Dialect/FIRTypes.td --- a/flang/include/flang/Optimizer/Dialect/FIRTypes.td +++ b/flang/include/flang/Optimizer/Dialect/FIRTypes.td @@ -568,7 +568,7 @@ // Whether a type is a BaseBoxType def IsBaseBoxTypePred - : CPred<"$_self.isa<::fir::BaseBoxType>()">; + : CPred<"mlir::isa<::fir::BaseBoxType>($_self)">; 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 --- a/flang/include/flang/Optimizer/Dialect/FortranVariableInterface.td +++ b/flang/include/flang/Optimizer/Dialect/FortranVariableInterface.td @@ -75,7 +75,7 @@ /// variable. mlir::Type getElementOrSequenceType() { mlir::Type type = fir::unwrapPassByRefType(fir::unwrapRefType(getBase().getType())); - if (auto boxCharType = type.dyn_cast()) + if (auto boxCharType = mlir::dyn_cast(type)) return boxCharType.getEleTy(); return type; } @@ -87,13 +87,13 @@ /// Is the variable an array? bool isArray() { - return getElementOrSequenceType().isa(); + return mlir::isa(getElementOrSequenceType()); } /// Return the rank of the entity if it is known at compile time. std::optional getRank() { if (auto sequenceType = - getElementOrSequenceType().dyn_cast()) { + mlir::dyn_cast(getElementOrSequenceType())) { if (sequenceType.hasUnknownShape()) return {}; return sequenceType.getDimension(); @@ -133,7 +133,7 @@ /// Is this a Fortran character variable? bool isCharacter() { - return getElementType().isa(); + return mlir::isa(getElementType()); } /// Is this a Fortran character variable with an explicit length? @@ -149,7 +149,7 @@ /// Is this variable represented as a fir.box or fir.class value? bool isBoxValue() { - return getBase().getType().isa(); + return mlir::isa(getBase().getType()); } /// 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 --- a/flang/include/flang/Optimizer/HLFIR/HLFIRDialect.h +++ b/flang/include/flang/Optimizer/HLFIR/HLFIRDialect.h @@ -37,9 +37,9 @@ inline mlir::Type getFortranElementType(mlir::Type type) { type = fir::unwrapSequenceType( fir::unwrapPassByRefType(fir::unwrapRefType(type))); - if (auto exprType = type.dyn_cast()) + if (auto exprType = mlir::dyn_cast(type)) return exprType.getEleTy(); - if (auto boxCharType = type.dyn_cast()) + if (auto boxCharType = mlir::dyn_cast(type)) return boxCharType.getEleTy(); return type; } @@ -48,12 +48,12 @@ /// 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 = type.dyn_cast()) { + if (auto exprType = mlir::dyn_cast(type)) { if (exprType.isArray()) return fir::SequenceType::get(exprType.getShape(), exprType.getEleTy()); return exprType.getEleTy(); } - if (auto boxCharType = type.dyn_cast()) + if (auto boxCharType = mlir::dyn_cast(type)) return boxCharType.getEleTy(); return type; } @@ -61,16 +61,16 @@ /// Is this a fir.box or fir.class address type? inline bool isBoxAddressType(mlir::Type type) { type = fir::dyn_cast_ptrEleTy(type); - return type && type.isa(); + return type && mlir::isa(type); } /// Is this a fir.box or fir.class address or value type? inline bool isBoxAddressOrValueType(mlir::Type type) { - return fir::unwrapRefType(type).isa(); + return mlir::isa(fir::unwrapRefType(type)); } inline bool isPolymorphicType(mlir::Type type) { - if (auto exprType = type.dyn_cast()) + if (auto exprType = mlir::dyn_cast(type)) return exprType.isPolymorphic(); return fir::isPolymorphicType(type); } diff --git a/flang/include/flang/Optimizer/Support/Utils.h b/flang/include/flang/Optimizer/Support/Utils.h --- a/flang/include/flang/Optimizer/Support/Utils.h +++ b/flang/include/flang/Optimizer/Support/Utils.h @@ -26,7 +26,9 @@ namespace fir { /// Return the integer value of a arith::ConstantOp. inline std::int64_t toInt(mlir::arith::ConstantOp cop) { - return cop.getValue().cast().getValue().getSExtValue(); + return mlir::cast(cop.getValue()) + .getValue() + .getSExtValue(); } // Reconstruct binding tables for dynamic dispatch. diff --git a/flang/include/flang/Tools/CrossToolHelpers.h b/flang/include/flang/Tools/CrossToolHelpers.h --- a/flang/include/flang/Tools/CrossToolHelpers.h +++ b/flang/include/flang/Tools/CrossToolHelpers.h @@ -57,7 +57,7 @@ void setOffloadModuleInterfaceAttributes( mlir::ModuleOp &module, OffloadModuleOpts Opts) { // Should be registered by the OpenMPDialect - if (auto offloadMod = llvm::dyn_cast( + if (auto offloadMod = mlir::dyn_cast( module.getOperation())) { offloadMod.setIsDevice(Opts.OpenMPIsDevice); if (Opts.OpenMPIsDevice) { @@ -76,7 +76,7 @@ void setOffloadModuleInterfaceTargetAttribute(mlir::ModuleOp &module, llvm::StringRef targetCPU, llvm::StringRef targetFeatures) { // Should be registered by the OpenMPDialect - if (auto offloadMod = llvm::dyn_cast( + if (auto offloadMod = mlir::dyn_cast( module.getOperation())) { offloadMod.setTarget(targetCPU, targetFeatures); } diff --git a/flang/include/flang/Tools/PointerModels.h b/flang/include/flang/Tools/PointerModels.h --- a/flang/include/flang/Tools/PointerModels.h +++ b/flang/include/flang/Tools/PointerModels.h @@ -20,7 +20,7 @@ : public mlir::omp::PointerLikeType::ExternalModel< OpenMPPointerLikeModel, T> { mlir::Type getElementType(mlir::Type pointer) const { - return pointer.cast().getElementType(); + return mlir::cast(pointer).getElementType(); } }; @@ -29,7 +29,7 @@ : public mlir::acc::PointerLikeType::ExternalModel< OpenACCPointerLikeModel, T> { mlir::Type getElementType(mlir::Type pointer) const { - return pointer.cast().getElementType(); + return mlir::cast(pointer).getElementType(); } }; diff --git a/flang/lib/Lower/Allocatable.cpp b/flang/lib/Lower/Allocatable.cpp --- a/flang/lib/Lower/Allocatable.cpp +++ b/flang/lib/Lower/Allocatable.cpp @@ -160,7 +160,7 @@ args.push_back(builder.createConvert(loc, inputTypes[0], box.getAddr())); args.push_back(builder.createConvert(loc, inputTypes[1], len)); if (kind == 0) - kind = box.getEleTy().cast().getFKind(); + kind = mlir::cast(box.getEleTy()).getFKind(); args.push_back(builder.createIntegerConstant(loc, inputTypes[2], kind)); int rank = box.rank(); args.push_back(builder.createIntegerConstant(loc, inputTypes[3], rank)); @@ -871,7 +871,7 @@ fir::MutableProperties mutableProperties; std::string name = converter.mangleName(sym); mlir::Type baseAddrTy = converter.genType(sym); - if (auto boxType = baseAddrTy.dyn_cast()) + if (auto boxType = mlir::dyn_cast(baseAddrTy)) baseAddrTy = boxType.getEleTy(); // Allocate and set a variable to hold the address. // It will be set to null in setUnallocatedStatus. @@ -896,9 +896,9 @@ mlir::Type eleTy = baseAddrTy; if (auto newTy = fir::dyn_cast_ptrEleTy(eleTy)) eleTy = newTy; - if (auto seqTy = eleTy.dyn_cast()) + if (auto seqTy = mlir::dyn_cast(eleTy)) eleTy = seqTy.getEleTy(); - if (auto record = eleTy.dyn_cast()) + if (auto record = mlir::dyn_cast(eleTy)) 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 --- a/flang/lib/Lower/Bridge.cpp +++ b/flang/lib/Lower/Bridge.cpp @@ -670,7 +670,7 @@ mlir::Location loc = genLocation(sym.name()); mlir::Type symType = genType(sym); - if (auto seqTy = symType.dyn_cast()) { + if (auto seqTy = mlir::dyn_cast(symType)) { Fortran::lower::StatementContext stmtCtx; Fortran::lower::createSomeArrayAssignment(*this, lhs, rhs, localSymbols, stmtCtx); @@ -1139,7 +1139,7 @@ return; } mlir::Type selectorType = selector.getType(); - bool realSelector = selectorType.isa(); + bool realSelector = mlir::isa(selectorType); assert((inArithmeticIfContext || !realSelector) && "invalid selector type"); mlir::Value zero; if (inArithmeticIfContext) @@ -1387,7 +1387,7 @@ stmtCtx); stmtCtx.finalizeAndReset(); // Raise an exception if REAL expr is a NaN. - if (expr.getType().isa()) + if (mlir::isa(expr.getType())) 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. @@ -2342,7 +2342,7 @@ auto caseValue = valueList.begin(); auto caseBlock = blockList.begin(); for (mlir::Attribute attr : attrList) { - if (attr.isa()) { + if (mlir::isa(attr)) { genBranch(*caseBlock++); break; } @@ -2360,7 +2360,7 @@ rhsVal.second); }; mlir::Block *newBlock = insertBlock(*caseBlock); - if (attr.isa()) { + if (mlir::isa(attr)) { mlir::Block *newBlock2 = insertBlock(*caseBlock); mlir::Value cond = genCond(*caseValue++, mlir::arith::CmpIPredicate::sge); @@ -2373,12 +2373,12 @@ continue; } mlir::arith::CmpIPredicate pred; - if (attr.isa()) { + if (mlir::isa(attr)) { pred = mlir::arith::CmpIPredicate::eq; - } else if (attr.isa()) { + } else if (mlir::isa(attr)) { pred = mlir::arith::CmpIPredicate::sge; } else { - assert(attr.isa() && "unexpected predicate"); + assert(mlir::isa(attr) && "unexpected predicate"); pred = mlir::arith::CmpIPredicate::sle; } mlir::Value cond = genCond(*caseValue++, pred); @@ -2636,7 +2636,7 @@ bool isPointer = fir::isPointerType(baseTy); bool isAllocatable = fir::isAllocatableType(baseTy); bool isArray = - fir::dyn_cast_ptrOrBoxEleTy(baseTy).isa(); + mlir::isa(fir::dyn_cast_ptrOrBoxEleTy(baseTy)); const fir::BoxValue *selectorBox = selector.getBoxOf(); if (std::holds_alternative(guard.u)) { // CLASS DEFAULT @@ -2645,12 +2645,12 @@ std::get_if(&guard.u)) { // TYPE IS fir::ExactTypeAttr attr = - typeGuardAttr.dyn_cast(); + mlir::dyn_cast(typeGuardAttr); mlir::Value exactValue; mlir::Type addrTy = attr.getType(); if (isArray) { - auto seqTy = fir::dyn_cast_ptrOrBoxEleTy(baseTy) - .dyn_cast(); + auto seqTy = mlir::dyn_cast( + fir::dyn_cast_ptrOrBoxEleTy(baseTy)); addrTy = fir::SequenceType::get(seqTy.getShape(), attr.getType()); } if (isPointer) @@ -2672,7 +2672,7 @@ addAssocEntitySymbol(selectorBox->clone(exact)); } else if (intrinsic->category() == Fortran::common::TypeCategory::Character) { - auto charTy = attr.getType().dyn_cast(); + auto charTy = mlir::dyn_cast(attr.getType()); mlir::Value charLen = fir::factory::CharacterExprHelper(*builder, loc) .readLengthFromBox(fir::getBase(selector), charTy); @@ -2689,11 +2689,12 @@ } else if (std::holds_alternative( guard.u)) { // CLASS IS - fir::SubclassAttr attr = typeGuardAttr.dyn_cast(); + fir::SubclassAttr attr = + mlir::dyn_cast(typeGuardAttr); mlir::Type addrTy = attr.getType(); if (isArray) { - auto seqTy = fir::dyn_cast_ptrOrBoxEleTy(baseTy) - .dyn_cast(); + auto seqTy = mlir::dyn_cast( + fir::dyn_cast_ptrOrBoxEleTy(baseTy)); addrTy = fir::SequenceType::get(seqTy.getShape(), attr.getType()); } if (isPointer) @@ -3159,13 +3160,13 @@ hlfir::Entity rhs, Fortran::lower::StatementContext &stmtCtx) { mlir::Type fromTy = rhs.getFortranElementType(); - if (!fromTy.isa()) + if (!mlir::isa(fromTy)) return nullptr; mlir::Type toTy = hlfir::getFortranElementType(genType(assign.lhs)); if (fromTy == toTy) return nullptr; - if (!toTy.isa()) + if (!mlir::isa(toTy)) return nullptr; mlir::Location loc = toLocation(); @@ -3472,7 +3473,7 @@ } else if (isDerivedCategory(lhsType->category())) { // Handle parent component. if (Fortran::lower::isParentComponent(assign.lhs)) { - if (!fir::getBase(lhs).getType().isa()) + if (!mlir::isa(fir::getBase(lhs).getType())) lhs = fir::getBase(builder->createBox(loc, lhs)); lhs = Fortran::lower::updateBoxForParentComponent(*this, lhs, assign.lhs); @@ -4604,7 +4605,7 @@ default: break; } - if (!diag.getLocation().isa()) + if (!mlir::isa(diag.getLocation())) os << diag.getLocation() << ": "; os << diag << '\n'; os.flush(); diff --git a/flang/lib/Lower/CallInterface.cpp b/flang/lib/Lower/CallInterface.cpp --- a/flang/lib/Lower/CallInterface.cpp +++ b/flang/lib/Lower/CallInterface.cpp @@ -999,7 +999,7 @@ Property prop = Property::BaseAddress; if (isValueAttr) { bool isBuiltinCptrType = fir::isa_builtin_cptr_type(type); - if (isBindC || (!type.isa() && + if (isBindC || (!mlir::isa(type) && !obj.attrs.test(Attrs::Optional) && (dynamicType.category() != Fortran::common::TypeCategory::Derived || @@ -1007,7 +1007,7 @@ passBy = PassEntityBy::Value; prop = Property::Value; if (isBuiltinCptrType) { - auto recTy = type.dyn_cast(); + auto recTy = mlir::dyn_cast(type); mlir::Type fieldTy = recTy.getTypeList()[0].second; passType = fir::ReferenceType::get(fieldTy); } else { @@ -1480,6 +1480,6 @@ } bool Fortran::lower::isCPtrArgByValueType(mlir::Type ty) { - return ty.isa() && + return mlir::isa(ty) && fir::isa_integer(fir::unwrapRefType(ty)); } diff --git a/flang/lib/Lower/ConvertArrayConstructor.cpp b/flang/lib/Lower/ConvertArrayConstructor.cpp --- a/flang/lib/Lower/ConvertArrayConstructor.cpp +++ b/flang/lib/Lower/ConvertArrayConstructor.cpp @@ -315,7 +315,7 @@ if (!extent) extent = builder.createIntegerConstant(loc, builder.getIndexType(), 0); if (missingLengthParameters) { - if (declaredType.getEleTy().isa()) + if (mlir::isa(declaredType.getEleTy())) emboxLengths.push_back(builder.createIntegerConstant( loc, builder.getCharacterLengthType(), 0)); else @@ -336,7 +336,7 @@ bool useSimplePushRuntime(hlfir::Entity value) { return value.isScalar() && - !arrayConstructorElementType.isa() && + !mlir::isa(arrayConstructorElementType) && !fir::isRecordWithAllocatableMember(arrayConstructorElementType) && !fir::isRecordWithTypeParameters(arrayConstructorElementType); } @@ -349,7 +349,7 @@ auto [addrExv, cleanUp] = hlfir::convertToAddress( loc, builder, value, arrayConstructorElementType); mlir::Value addr = fir::getBase(addrExv); - if (addr.getType().isa()) + if (mlir::isa(addr.getType())) addr = builder.create(loc, addr); fir::runtime::genPushArrayConstructorSimpleScalar( loc, builder, arrayConstructorVector, addr); @@ -543,7 +543,7 @@ /// lowering an ac-value and must be delayed? static bool missingLengthParameters(mlir::Type elementType, llvm::ArrayRef lengths) { - return (elementType.isa() || + return (mlir::isa(elementType) || fir::isRecordWithTypeParameters(elementType)) && lengths.empty(); } @@ -681,7 +681,8 @@ // 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 || declaredType.getEleTy().isa()) + analysis.anyArrayExpr || + mlir::isa(declaredType.getEleTy())) 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 --- a/flang/lib/Lower/ConvertCall.cpp +++ b/flang/lib/Lower/ConvertCall.cpp @@ -43,15 +43,15 @@ llvm::ArrayRef extents, llvm::ArrayRef lengths) { mlir::Type type = base.getType(); - if (type.isa()) + if (mlir::isa(type)) return fir::BoxValue(base, /*lbounds=*/{}, lengths, extents); type = fir::unwrapRefType(type); - if (type.isa()) + if (mlir::isa(type)) return fir::MutableBoxValue(base, lengths, /*mutableProperties*/ {}); - if (auto seqTy = type.dyn_cast()) { + if (auto seqTy = mlir::dyn_cast(type)) { if (seqTy.getDimension() != extents.size()) fir::emitFatalError(loc, "incorrect number of extents for array"); - if (seqTy.getEleTy().isa()) { + if (mlir::isa(seqTy.getEleTy())) { if (lengths.empty()) fir::emitFatalError(loc, "missing length for character"); assert(lengths.size() == 1); @@ -59,7 +59,7 @@ } return fir::ArrayBoxValue(base, extents); } - if (type.isa()) { + if (mlir::isa(type)) { if (lengths.empty()) fir::emitFatalError(loc, "missing length for character"); assert(lengths.size() == 1); @@ -187,7 +187,7 @@ if (!caller.callerAllocateResult()) return {}; mlir::Type type = caller.getResultStorageType(); - if (type.isa()) + if (mlir::isa(type)) caller.walkResultExtents([&](const Fortran::lower::SomeExpr &e) { extents.emplace_back(lowerSpecExpr(e)); }); @@ -198,7 +198,7 @@ // 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 (!type.isa()) { + if (!mlir::isa(type)) { 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. @@ -323,7 +323,7 @@ // FIR. if (funcPointer) { operands.push_back( - funcPointer.getType().isa() + mlir::isa(funcPointer.getType()) ? builder.create(loc, funcType, funcPointer) : builder.createConvert(loc, funcType, funcPointer)); } @@ -337,8 +337,8 @@ // arguments of any type and vice versa. mlir::Value cast; auto *context = builder.getContext(); - if (snd.isa() && - fst.getType().isa()) { + if (mlir::isa(snd) && + mlir::isa(fst.getType())) { auto funcTy = mlir::FunctionType::get(context, std::nullopt, std::nullopt); auto boxProcTy = builder.getBoxProcType(funcTy); @@ -480,9 +480,9 @@ // Call a BIND(C) function that return a char. if (caller.characterize().IsBindC() && - funcType.getResults()[0].isa()) { + mlir::isa(funcType.getResults()[0])) { fir::CharacterType charTy = - funcType.getResults()[0].dyn_cast(); + mlir::dyn_cast(funcType.getResults()[0]); mlir::Value len = builder.createIntegerConstant( loc, builder.getCharacterLengthType(), charTy.getLen()); return fir::CharBoxValue{callResult, len}; @@ -664,7 +664,7 @@ mlir::Type firBaseTy = firBase.getType(); if (fir::isa_trivial(firBaseTy)) return hlfir::EntityWithAttributes{firBase}; - if (auto charTy = firBase.getType().dyn_cast()) { + if (auto charTy = mlir::dyn_cast(firBase.getType())) { // 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 @@ -827,7 +827,7 @@ fir::FirOpBuilder &builder, hlfir::Entity actual, mlir::Type dummyType) { - if (actual.getType().isa() && + if (mlir::isa(actual.getType()) && fir::isCharacterProcedureTuple(dummyType)) { mlir::Value length = builder.create(loc, builder.getCharacterLengthType()); @@ -836,7 +836,7 @@ return hlfir::Entity{tuple}; } assert(fir::isCharacterProcedureTuple(actual.getType()) && - dummyType.isa() && + mlir::isa(dummyType) && "unsupported dummy procedure mismatch with the actual argument"); mlir::Value boxProc = fir::factory::extractCharacterProcedureTuple( builder, loc, actual, /*openBoxProc=*/false) @@ -886,7 +886,7 @@ // dynamic type matters to determine the contiguity. const bool mustSetDynamicTypeToDummyType = passingPolymorphicToNonPolymorphic && - (actual.isArray() || dummyType.isa()); + (actual.isArray() || mlir::isa(dummyType)); // The simple contiguity of the actual is "lost" when passing a polymorphic // to a non polymorphic entity because the dummy dynamic type matters for @@ -930,7 +930,7 @@ associate.getFirBase(), associate.getMustFreeStrorageFlag()); } else if (mustDoCopyInOut) { // Copy-in non contiguous variables. - assert(entity.getType().isa() && + assert(mlir::isa(entity.getType()) && "expect non simply contiguous variables to be boxes"); // TODO: for non-finalizable monomorphic derived type actual // arguments associated with INTENT(OUT) dummy arguments @@ -964,13 +964,14 @@ // Step 3: now that the dummy argument storage has been prepared, package // it according to the interface. mlir::Value addr; - if (dummyType.isa()) { + if (mlir::isa(dummyType)) { addr = hlfir::genVariableBoxChar(loc, builder, entity); - } else if (dummyType.isa()) { + } else if (mlir::isa(dummyType)) { entity = hlfir::genVariableBox(loc, builder, entity); // Ensures the box has the right attributes and that it holds an // addendum if needed. - fir::BaseBoxType actualBoxType = entity.getType().cast(); + fir::BaseBoxType actualBoxType = + mlir::cast(entity.getType()); 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 @@ -1170,7 +1171,7 @@ // 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 && boxTy.isa() && + assert(boxTy && mlir::isa(boxTy) && "must be a fir.box type"); mlir::Value boxStorage = fir::factory::genNullBoxStorage(builder, loc, boxTy); @@ -1383,7 +1384,7 @@ mlir::Type normalisedResult = hlfir::getFortranElementOrSequenceType(stmtResultType); mlir::Type elementType; - if (auto array = normalisedResult.dyn_cast()) { + if (auto array = mlir::dyn_cast(normalisedResult)) { resultShape = hlfir::ExprType::Shape{array.getShape()}; elementType = array.getEleTy(); return hlfir::ExprType::get(builder.getContext(), resultShape, @@ -1451,7 +1452,7 @@ hlfir::ExprType::Shape resultShape; mlir::Type normalisedResult = hlfir::getFortranElementOrSequenceType(*callContext.resultType); - auto array = normalisedResult.cast(); + auto array = mlir::cast(normalisedResult); llvm::ArrayRef arrayShape = array.getShape(); assert(arrayShape.size() == 2 && "arguments to transpose have a rank of 2"); mlir::Type elementType = array.getEleTy(); @@ -1565,9 +1566,9 @@ hlfir::getFortranElementType(*callContext.resultType); // Get result length parameters. llvm::SmallVector typeParams; - if (elementType.isa() || + if (mlir::isa(elementType) || fir::isRecordWithTypeParameters(elementType)) { - auto charType = elementType.dyn_cast(); + auto charType = mlir::dyn_cast(elementType); if (charType && charType.hasConstantLen()) typeParams.push_back(builder.createIntegerConstant( loc, builder.getIndexType(), charType.getLen())); @@ -1793,7 +1794,7 @@ } std::optional result = genHLFIRIntrinsicRefCore( loweredActuals, intrinsic, argLowering, callContext); - if (result && result->getType().isa()) { + if (result && mlir::isa(result->getType())) { 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 --- a/flang/lib/Lower/ConvertConstant.cpp +++ b/flang/lib/Lower/ConvertConstant.cpp @@ -164,8 +164,8 @@ if (!attributeElementType || attributes.empty()) return {}; - assert(symTy.isa() && "expecting an array global"); - auto arrTy = symTy.cast(); + assert(mlir::isa(symTy) && "expecting an array global"); + auto arrTy = mlir::cast(symTy); llvm::SmallVector tensorShape(arrTy.getShape()); std::reverse(tensorShape.begin(), tensorShape.end()); auto tensorTy = @@ -336,7 +336,7 @@ Fortran::lower::AbstractConverter &converter, mlir::Location loc, const Fortran::evaluate::StructureConstructor &ctor, mlir::Type type) { fir::FirOpBuilder &builder = converter.getFirOpBuilder(); - auto recTy = type.cast(); + auto recTy = mlir::cast(type); auto fieldTy = fir::FieldType::get(type.getContext()); mlir::Value res = builder.create(loc, recTy); @@ -382,14 +382,14 @@ // The Ev::Expr returned is an initializer that is a pointer (e.g., // null) that must be inserted into an intermediate cptr record // value's address field, which ought to be an intptr_t on the target. - if (addr.getType().isa()) + if (mlir::isa(addr.getType())) addr = builder.create(loc, addr); assert((fir::isa_ref_type(addr.getType()) || - addr.getType().isa()) && + mlir::isa(addr.getType())) && "expect reference type for address field"); assert(fir::isa_derived(componentTy) && "expect C_PTR, C_FUNPTR to be a record"); - auto cPtrRecTy = componentTy.cast(); + auto cPtrRecTy = mlir::cast(componentTy); llvm::StringRef addrFieldName = Fortran::lower::builtin::cptrFieldName; mlir::Type addrFieldTy = cPtrRecTy.getType(addrFieldName); auto addrField = builder.create( @@ -473,7 +473,7 @@ } while (con.IncrementSubscripts(subscripts)); } else if constexpr (T::category == Fortran::common::TypeCategory::Derived) { do { - mlir::Type eleTy = arrayTy.cast().getEleTy(); + mlir::Type eleTy = mlir::cast(arrayTy).getEleTy(); mlir::Value elementVal = genScalarLit(converter, loc, con.At(subscripts), eleTy, /*outlineInReadOnlyMemory=*/false); @@ -483,7 +483,7 @@ } else { llvm::SmallVector rangeStartIdx; uint64_t rangeSize = 0; - mlir::Type eleTy = arrayTy.cast().getEleTy(); + mlir::Type eleTy = mlir::cast(arrayTy).getEleTy(); do { auto getElementVal = [&]() { return builder.createConvert(loc, eleTy, @@ -506,12 +506,11 @@ llvm::SmallVector rangeBounds; llvm::SmallVector idx = createIdx(); for (size_t i = 0; i < idx.size(); ++i) { - rangeBounds.push_back(rangeStartIdx[i] - .cast() + rangeBounds.push_back(mlir::cast(rangeStartIdx[i]) .getValue() .getSExtValue()); rangeBounds.push_back( - idx[i].cast().getValue().getSExtValue()); + mlir::cast(idx[i]).getValue().getSExtValue()); } array = builder.create( loc, arrayTy, array, getElementVal(), @@ -533,7 +532,7 @@ mlir::Location loc, mlir::Type arrayTy, const Fortran::evaluate::Constant &constant) { fir::FirOpBuilder &builder = converter.getFirOpBuilder(); - mlir::Type eleTy = arrayTy.cast().getEleTy(); + mlir::Type eleTy = mlir::cast(arrayTy).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 --- a/flang/lib/Lower/ConvertExpr.cpp +++ b/flang/lib/Lower/ConvertExpr.cpp @@ -267,7 +267,7 @@ mlir::Type ty = fir::applyPathToType(arrTy, path); if (!ty) fir::emitFatalError(loc, "path does not apply to type"); - if (!ty.isa()) { + if (!mlir::isa(ty)) { if (fir::isa_char(ty)) { mlir::Value len = newLen; if (!len) @@ -282,7 +282,7 @@ } return newBase; } - arrTy = ty.cast(); + arrTy = mlir::cast(ty); } auto arrayToExtendedValue = @@ -413,15 +413,15 @@ return addr.match( [](const fir::CharBoxValue &box) -> fir::ExtendedValue { return box; }, [&](const fir::PolymorphicValue &p) -> fir::ExtendedValue { - if (fir::unwrapRefType(fir::getBase(p).getType()) - .isa()) + if (mlir::isa( + fir::unwrapRefType(fir::getBase(p).getType()))) return p; mlir::Value load = builder.create(loc, fir::getBase(p)); return fir::PolymorphicValue(load, p.getSourceBox()); }, [&](const fir::UnboxedValue &v) -> fir::ExtendedValue { - if (fir::unwrapRefType(fir::getBase(v).getType()) - .isa()) + if (mlir::isa( + fir::unwrapRefType(fir::getBase(v).getType()))) return v; return builder.create(loc, fir::getBase(v)); }, @@ -537,8 +537,8 @@ createBoxProcCharTuple(Fortran::lower::AbstractConverter &converter, mlir::Type argTy, mlir::Value funcAddr, mlir::Value charLen) { - auto boxTy = - argTy.cast().getType(0).cast(); + auto boxTy = mlir::cast( + mlir::cast(argTy).getType(0)); mlir::Location loc = converter.getCurrentLocation(); auto &builder = converter.getFirOpBuilder(); @@ -550,7 +550,7 @@ mlir::Type toTy = boxTy.getEleTy(); if (fir::isa_ref_type(fromTy)) funcAddr = builder.createConvert(loc, toTy, funcAddr); - else if (fromTy.isa()) + else if (mlir::isa(fromTy)) funcAddr = builder.create(loc, toTy, funcAddr); auto boxProc = [&]() -> mlir::Value { @@ -576,7 +576,7 @@ mlir::Value isPresent) { mlir::Value box = fir::getBase(exv); mlir::Type boxType = box.getType(); - assert(boxType.isa() && "argument must be a fir.box"); + assert(mlir::isa(boxType) && "argument must be a fir.box"); mlir::Value emptyBox = fir::factory::createUnallocatedBox(builder, loc, boxType, std::nullopt); auto safeToReadBox = @@ -899,7 +899,7 @@ if (inInitializer) return Fortran::lower::genInlinedStructureCtorLit(converter, loc, ctor); mlir::Type ty = translateSomeExprToFIRType(converter, toEvExpr(ctor)); - auto recTy = ty.cast(); + auto recTy = mlir::cast(ty); auto fieldTy = fir::FieldType::get(ty.getContext()); mlir::Value res = builder.createTemporary(loc, recTy); mlir::Value box = builder.createBox(loc, fir::ExtendedValue{res}); @@ -1156,8 +1156,8 @@ if (!charBox) fir::emitFatalError(loc, "expected scalar character"); mlir::Value charAddr = charBox->getAddr(); - auto charType = - fir::unwrapPassByRefType(charAddr.getType()).cast(); + auto charType = mlir::cast( + fir::unwrapPassByRefType(charAddr.getType())); if (charType.hasConstantLen()) { // Erase previous constant length from the base type. fir::CharacterType::LenType newLen = fir::CharacterType::unknownLen(); @@ -1230,7 +1230,7 @@ auto kindMap = builder.getKindMap(); mlir::Value boxCharAddr = boxchar.getAddr(); auto fromTy = boxCharAddr.getType(); - if (auto charTy = fromTy.dyn_cast()) { + if (auto charTy = mlir::dyn_cast(fromTy)) { // 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"); @@ -1238,12 +1238,11 @@ builder.create(loc, boxCharAddr, tmp); boxCharAddr = tmp; } - auto fromBits = - kindMap.getCharacterBitsize(fir::unwrapRefType(fromTy) - .cast() - .getFKind()); + auto fromBits = kindMap.getCharacterBitsize( + mlir::cast(fir::unwrapRefType(fromTy)) + .getFKind()); auto toBits = kindMap.getCharacterBitsize( - ty.cast().getFKind()); + mlir::cast(ty).getFKind()); if (toBits < fromBits) { // Scale by relative ratio to give a buffer of the same length. auto ratio = builder.createIntegerConstant( @@ -1458,7 +1457,7 @@ 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 = ty.cast(); + auto recTy = mlir::cast(ty); const Fortran::semantics::Symbol &sym = getLastSym(*field); llvm::StringRef name = toStringRef(sym.name()); coorArgs.push_back(builder.create( @@ -1495,7 +1494,7 @@ 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 = unwrapTy.cast(); + auto seqTy = mlir::cast(unwrapTy); llvm::ArrayRef shape = seqTy.getShape(); assert(shape.size() > 0 && "removing columns for sequence sans shape"); assert(dims <= shape.size() && "removing more columns than exist"); @@ -1552,9 +1551,9 @@ } mlir::Value base = fir::getBase(array); mlir::Type eleTy = fir::dyn_cast_ptrOrBoxEleTy(base.getType()); - if (auto classTy = eleTy.dyn_cast()) + if (auto classTy = mlir::dyn_cast(eleTy)) eleTy = classTy.getEleTy(); - auto seqTy = eleTy.cast(); + auto seqTy = mlir::cast(eleTy); assert(args.size() == seqTy.getDimension()); mlir::Type ty = builder.getRefType(seqTy.getEleTy()); auto addr = builder.create(loc, ty, base, args); @@ -1573,7 +1572,7 @@ mlir::Location loc = getLoc(); mlir::Value addr = fir::getBase(array); mlir::Type arrTy = fir::dyn_cast_ptrEleTy(addr.getType()); - auto eleTy = arrTy.cast().getEleTy(); + auto eleTy = mlir::cast(arrTy).getEleTy(); mlir::Type seqTy = builder.getRefType(builder.getVarLenSeqTy(eleTy)); mlir::Type refTy = builder.getRefType(eleTy); mlir::Value base = builder.createConvert(loc, seqTy, addr); @@ -1658,7 +1657,7 @@ mlir::Location loc = getLoc(); mlir::Value addr = fir::getBase(exv); mlir::Type arrTy = fir::dyn_cast_ptrOrBoxEleTy(addr.getType()); - mlir::Type eleTy = arrTy.cast().getEleTy(); + mlir::Type eleTy = mlir::cast(arrTy).getEleTy(); mlir::Type refTy = builder.getRefType(eleTy); mlir::IndexType idxTy = builder.getIndexType(); llvm::SmallVector arrayCoorArgs; @@ -1769,8 +1768,9 @@ mlir::Location loc = getLoc(); ExtValue exv = genBoxArg(expr); auto exvTy = fir::getBase(exv).getType(); - if (exvTy.isa()) { - auto boxProcTy = builder.getBoxProcType(exvTy.cast()); + if (mlir::isa(exvTy)) { + auto boxProcTy = + builder.getBoxProcType(mlir::cast(exvTy)); return builder.create(loc, boxProcTy, fir::getBase(exv)); } @@ -1864,7 +1864,7 @@ // 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 && - !fir::getBase(exv).getType().isa()) { + !mlir::isa(fir::getBase(exv).getType())) { operands.emplace_back( fir::factory::createBoxValue(builder, loc, exv)); continue; @@ -2009,7 +2009,7 @@ fir::getTypeParams(mold); mlir::Value charLen; mlir::Type elementType = fir::unwrapSequenceType(type); - if (auto charType = elementType.dyn_cast()) { + if (auto charType = mlir::dyn_cast(elementType)) { charLen = allocMemTypeParams.empty() ? fir::factory::readCharLen(builder, loc, mold) : allocMemTypeParams[0]; @@ -2021,7 +2021,7 @@ mlir::Value temp = builder.create( loc, type, tempName, allocMemTypeParams, extents); - if (fir::unwrapSequenceType(type).isa()) + if (mlir::isa(fir::unwrapSequenceType(type))) return fir::CharArrayBoxValue{temp, charLen, extents}; return fir::ArrayBoxValue{temp, extents}; } @@ -2170,7 +2170,7 @@ // 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 (getElementTypeOf(temp).isa()) { + if (mlir::isa(getElementTypeOf(temp))) { mlir::Value tempBox = fir::getBase(builder.createBox(loc, temp)); fir::runtime::genDerivedTypeInitialize(builder, loc, tempBox); } @@ -2316,7 +2316,7 @@ if (!copyOutPair.restrictCopyAndFreeAtRuntime) { doCopyOut(); - if (fir::getElementTypeOf(copyOutPair.temp).isa()) { + if (mlir::isa(fir::getElementTypeOf(copyOutPair.temp))) { // Destroy components of the temporary (if any). // If there are no components requiring destruction, then the call // is a no-op. @@ -2334,7 +2334,8 @@ builder.genIfThen(loc, *copyOutPair.restrictCopyAndFreeAtRuntime) .genThen([&]() { doCopyOut(); - if (fir::getElementTypeOf(copyOutPair.temp).isa()) { + if (mlir::isa( + fir::getElementTypeOf(copyOutPair.temp))) { // Destroy components of the temporary (if any). // If there are no components requiring destruction, then the call // is a no-op. @@ -2386,7 +2387,7 @@ mlir::Value actualArgBase = fir::getBase(actualArg); mlir::Value isPresent = builder.create( loc, builder.getI1Type(), actualArgBase); - if (!actualArgBase.getType().isa()) + if (!mlir::isa(actualArgBase.getType())) return {actualArg, isPresent}; ExtValue safeToReadBox = absentBoxToUnallocatedBox(builder, loc, actualArg, isPresent); @@ -2413,7 +2414,7 @@ Fortran::lower::getAdaptToByRefAttr(builder)}); return fir::CharBoxValue{temp, len}; } - assert((fir::isa_trivial(type) || type.isa()) && + assert((fir::isa_trivial(type) || mlir::isa(type)) && "must be simple scalar"); return builder.createTemporary( loc, type, @@ -2590,7 +2591,7 @@ // 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 && boxTy.isa() && + assert(boxTy && mlir::isa(boxTy) && "must be a fir.box type"); mlir::Value boxStorage = builder.createTemporary(loc, boxTy); mlir::Value nullBox = fir::factory::createUnallocatedBox( @@ -2661,10 +2662,11 @@ // If a character procedure was passed instead, handle the // mismatch. auto funcTy = - x.getAddr().getType().dyn_cast(); + mlir::dyn_cast(x.getAddr().getType()); if (funcTy && funcTy.getNumResults() == 1 && - funcTy.getResult(0).isa()) { - auto boxTy = funcTy.getResult(0).cast(); + mlir::isa(funcTy.getResult(0))) { + auto boxTy = + mlir::cast(funcTy.getResult(0)); mlir::Value ref = builder.createConvert( loc, builder.getRefType(boxTy.getEleTy()), x.getAddr()); auto len = builder.create( @@ -2685,7 +2687,7 @@ // 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(!dataPtr.getType().template isa()); + assert(!mlir::isa(dataPtr.getType())); return builder.convertWithSemantics( loc, argTy, dataPtr, /*allowCharacterConversion=*/true); @@ -2761,7 +2763,7 @@ loc, fir::ClassType::get(mlir::NoneType::get(builder.getContext())), box); - } else if (box.getType().isa() && + } else if (mlir::isa(box.getType()) && fir::isPolymorphicType(argTy)) { box = builder.create(loc, argTy, box, mlir::Value{}, /*slice=*/mlir::Value{}); @@ -2810,7 +2812,7 @@ : builder.createBox(getLoc(), genTempExtAddr(*expr), fir::isPolymorphicType(argTy), fir::isAssumedType(argTy)); - if (box.getType().isa() && + if (mlir::isa(box.getType()) && fir::isPolymorphicType(argTy) && !fir::isAssumedType(argTy)) { mlir::Type actualTy = argTy; if (Fortran::lower::isParentComponent(*expr)) @@ -3027,10 +3029,11 @@ Fortran::common::ScopedSet(semant, PushVal); static bool isAdjustedArrayElementType(mlir::Type t) { - return fir::isa_char(t) || fir::isa_derived(t) || t.isa(); + return fir::isa_char(t) || fir::isa_derived(t) || + mlir::isa(t); } static bool elementTypeWasAdjusted(mlir::Type t) { - if (auto ty = t.dyn_cast()) + if (auto ty = mlir::dyn_cast(t)) return isAdjustedArrayElementType(ty.getEleTy()); return false; } @@ -3047,15 +3050,15 @@ auto prepareUserDefinedArg = [](fir::FirOpBuilder &builder, mlir::Location loc, const fir::ExtendedValue &value, mlir::Type argType) -> mlir::Value { - if (argType.isa()) { + if (mlir::isa(argType)) { const fir::CharBoxValue *charBox = value.getCharBox(); assert(charBox && "argument type mismatch in elemental user assignment"); return fir::factory::CharacterExprHelper{builder, loc}.createEmbox( *charBox); } - if (argType.isa()) { + if (mlir::isa(argType)) { mlir::Value box = - builder.createBox(loc, value, argType.isa()); + builder.createBox(loc, value, mlir::isa(argType)); return builder.createConvert(loc, argType, box); } // Simple pass by address. @@ -3167,7 +3170,7 @@ mlir::Value val, mlir::Value len) { mlir::Type ty = fir::unwrapRefType(val.getType()); mlir::IndexType idxTy = builder.getIndexType(); - auto seqTy = ty.cast(); + auto seqTy = mlir::cast(ty); auto undef = builder.create(loc, idxTy); llvm::SmallVector extents(seqTy.getDimension(), undef); if (fir::isa_char(seqTy.getEleTy())) @@ -3460,7 +3463,7 @@ [&](const auto &e) { auto f = genarr(e); ExtValue exv = f(IterationSpace{}); - if (fir::getBase(exv).getType().template isa()) + if (mlir::isa(fir::getBase(exv).getType())) return exv; fir::emitFatalError(getLoc(), "array must be emboxed"); }, @@ -3485,10 +3488,9 @@ tempRes, dest.getSlice(), dest.getTypeparams()); - auto arrTy = - fir::dyn_cast_ptrEleTy(tempRes.getType()).cast(); - if (auto charTy = - arrTy.getEleTy().template dyn_cast()) { + auto arrTy = mlir::cast( + fir::dyn_cast_ptrEleTy(tempRes.getType())); + if (auto charTy = mlir::dyn_cast(arrTy.getEleTy())) { if (fir::characterWithDynamicLen(charTy)) TODO(loc, "CHARACTER does not have constant LEN"); mlir::Value len = builder.createIntegerConstant( @@ -3910,17 +3912,18 @@ mlir::Value convertElementForUpdate(mlir::Location loc, mlir::Type eleTy, mlir::Value origVal) { if (auto origEleTy = fir::dyn_cast_ptrEleTy(origVal.getType())) - if (origEleTy.isa()) { + if (mlir::isa(origEleTy)) { // If origVal is a box variable, load it so it is in the value domain. origVal = builder.create(loc, origVal); } - if (origVal.getType().isa() && !eleTy.isa()) { + if (mlir::isa(origVal.getType()) && + !mlir::isa(eleTy)) { if (isPointerAssignment()) TODO(loc, "lhs of pointer assignment returned unexpected value"); TODO(loc, "invalid box conversion in elemental computation"); } - if (isPointerAssignment() && eleTy.isa() && - !origVal.getType().isa()) { + if (isPointerAssignment() && mlir::isa(eleTy) && + !mlir::isa(origVal.getType())) { // 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. @@ -3928,7 +3931,7 @@ 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(eleTy.cast()); + auto memrefTy = fir::boxMemRefType(mlir::cast(eleTy)); auto castTo = builder.createConvert(loc, memrefTy, origVal); origVal = builder.create(loc, eleTy, castTo); } @@ -3980,7 +3983,7 @@ auto arrayOp = builder.create( loc, resRefTy, innerArg, iterSpace.iterVec(), fir::factory::getTypeParams(loc, builder, destination)); - if (auto charTy = eleTy.dyn_cast()) { + if (auto charTy = mlir::dyn_cast(eleTy)) { llvm::SmallVector substringBounds; populateBounds(substringBounds, substring); mlir::Value dstLen = fir::factory::genLenOfCharacter( @@ -3994,7 +3997,7 @@ loc, destination, builder, arrayOp, exv, eleTy, innerArg); return abstractArrayExtValue(amend /*FIXME: typeparams?*/); } - assert(eleTy.isa() && "must be an array"); + assert(mlir::isa(eleTy) && "must be an array"); TODO(loc, "array (as element) assignment"); } // By value semantics. The element is being assigned by value. @@ -4058,7 +4061,7 @@ llvm::SmallVector getShape(ArrayOperand array) { if (array.slice) return computeSliceShape(array.slice); - if (array.memref.getType().isa()) + if (mlir::isa(array.memref.getType())) return fir::factory::readExtents(builder, getLoc(), fir::BoxValue{array.memref}); return fir::factory::getExtents(array.shape); @@ -4131,7 +4134,7 @@ mlir::Location loc = getLoc(); return [=, builder = &converter.getFirOpBuilder()](IterSpace iters) { mlir::Type arrTy = fir::dyn_cast_ptrOrBoxEleTy(tmp.getType()); - auto eleTy = arrTy.cast().getEleTy(); + auto eleTy = mlir::cast(arrTy).getEleTy(); mlir::Type eleRefTy = builder->getRefType(eleTy); mlir::IntegerType i1Ty = builder->getI1Type(); // Adjust indices for any shift of the origin of the array. @@ -4440,15 +4443,15 @@ TODO(loc, "polymorphic array temporary"); if (ccLoadDest) return (*ccLoadDest)(shape); - auto seqTy = type.dyn_cast(); + auto seqTy = mlir::dyn_cast(type); 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 = seqTy.getEleTy().dyn_cast()) + if (auto charTy = mlir::dyn_cast(seqTy.getEleTy())) if (charTy.hasDynamicLen()) TODO(loc, "character array expression temp with dynamic length"); - if (auto recTy = seqTy.getEleTy().dyn_cast()) + if (auto recTy = mlir::dyn_cast(seqTy.getEleTy())) if (recTy.getNumLenParams() > 0) TODO(loc, "derived type array expression temp with LEN parameters"); if (mlir::Type eleTy = fir::unwrapSequenceType(type); @@ -4818,7 +4821,7 @@ }); } else { ExtValue exv = asScalarRef(*expr); - if (fir::getBase(exv).getType().isa()) { + if (mlir::isa(fir::getBase(exv).getType())) { operands.emplace_back( [=](IterSpace iters) -> ExtValue { return exv; }); } else { @@ -5551,7 +5554,7 @@ } static mlir::Type unwrapBoxEleTy(mlir::Type ty) { - if (auto boxTy = ty.dyn_cast()) + if (auto boxTy = mlir::dyn_cast(ty)) return fir::unwrapRefType(boxTy.getEleTy()); return ty; } @@ -5561,7 +5564,7 @@ ty = unwrapBoxEleTy(ty); mlir::Location loc = getLoc(); mlir::IndexType idxTy = builder.getIndexType(); - for (auto extent : ty.cast().getShape()) { + for (auto extent : mlir::cast(ty).getShape()) { auto v = extent == fir::SequenceType::getUnknownExtent() ? builder.create(loc, idxTy).getResult() : builder.createIntegerConstant(loc, idxTy, extent); @@ -5623,7 +5626,8 @@ mlir::Location loc = getLoc(); mlir::Value memref = fir::getBase(extMemref); mlir::Type arrTy = fir::dyn_cast_ptrOrBoxEleTy(memref.getType()); - assert(arrTy.isa() && "memory ref must be an array"); + assert(mlir::isa(arrTy) && + "memory ref must be an array"); mlir::Value shape = builder.createShape(loc, extMemref); mlir::Value slice; if (components.isSlice()) { @@ -5673,12 +5677,12 @@ components.suffixComponents); } if (components.hasComponents()) { - auto seqTy = arrTy.cast(); + auto seqTy = mlir::cast(arrTy); mlir::Type eleTy = fir::applyPathToType(seqTy.getEleTy(), components.suffixComponents); if (!eleTy) fir::emitFatalError(loc, "slicing path is ill-formed"); - if (auto realTy = eleTy.dyn_cast()) + if (auto realTy = mlir::dyn_cast(eleTy)) eleTy = Fortran::lower::convertReal(realTy.getContext(), realTy.getFKind()); @@ -5698,13 +5702,14 @@ // 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 (memref.getType().isa() && !components.hasComponents()) + if (mlir::isa(memref.getType()) && + !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 = reduceTy.cast(); + auto seqTy = mlir::cast(reduceTy); // TODO: Use a constant for fir.char LEN if we can compute it. boxTy = fir::BoxType::get( fir::SequenceType::get(fir::CharacterType::getUnknownLen( @@ -5719,7 +5724,7 @@ nonDeferredLenParams = fir::factory::getNonDeferredLenParams(extMemref); } mlir::Value embox = - memref.getType().isa() + mlir::isa(memref.getType()) ? builder.create(loc, boxTy, memref, shape, slice) .getResult() : builder @@ -5730,7 +5735,7 @@ return fir::BoxValue(embox, lbounds, nonDeferredLenParams); }; } - auto eleTy = arrTy.cast().getEleTy(); + auto eleTy = mlir::cast(arrTy).getEleTy(); if (isReferentiallyOpaque()) { // Semantics are an opaque reference to an array. // This case forwards a continuation that will generate the address @@ -5745,12 +5750,12 @@ mlir::Value coor = builder.create( loc, refEleTy, memref, shape, slice, indices, fir::getTypeParams(extMemref)); - if (auto charTy = eleTy.dyn_cast()) { + if (auto charTy = mlir::dyn_cast(eleTy)) { llvm::SmallVector substringBounds; populateBounds(substringBounds, components.substring); if (!substringBounds.empty()) { mlir::Value dstLen = fir::factory::genLenOfCharacter( - builder, loc, arrTy.cast(), memref, + builder, loc, mlir::cast(arrTy), memref, fir::getTypeParams(extMemref), iters.iterVec(), substringBounds); fir::CharBoxValue dstChar(coor, dstLen); @@ -5838,7 +5843,7 @@ mlir::Type eleRefTy = builder.getRefType(eleTy); mlir::Value arrayOp = builder.create( loc, eleRefTy, arrLd, iters.iterVec(), arrLdTypeParams); - if (auto charTy = eleTy.dyn_cast()) { + if (auto charTy = mlir::dyn_cast(eleTy)) { llvm::SmallVector substringBounds; populateBounds(substringBounds, components.substring); if (!substringBounds.empty()) { @@ -5871,7 +5876,7 @@ const bool hasOptionalAttr = fir::valueHasFirAttribute(base, fir::getOptionalAttrName()); mlir::Type baseType = fir::unwrapRefType(base.getType()); - const bool isBox = baseType.isa(); + const bool isBox = mlir::isa(baseType); const bool isAllocOrPtr = Fortran::evaluate::IsAllocatableOrPointerObject( expr, converter.getFoldingContext()); mlir::Type arrType = fir::unwrapPassByRefType(baseType); @@ -5964,7 +5969,7 @@ if (slice) { auto slOp = mlir::dyn_cast(slice.getDefiningOp()); assert(slOp && "expected slice op"); - auto seqTy = arrTy.dyn_cast(); + auto seqTy = mlir::dyn_cast(arrTy); assert(seqTy && "expected array type"); mlir::Operation::operand_range triples = slOp.getTriples(); fir::SequenceType::Shape shape; @@ -6028,7 +6033,7 @@ mlir::IndexType idxTy = builder.getIndexType(); mlir::Value multiplier = builder.createIntegerConstant(loc, idxTy, 1); if (fir::hasDynamicSize(eleTy)) { - if (auto charTy = eleTy.dyn_cast()) { + if (auto charTy = mlir::dyn_cast(eleTy)) { // Array of char with dynamic LEN parameter. Downcast to an array // of singleton char, and scale by the len type parameter from // `exv`. @@ -6049,7 +6054,7 @@ }); fir::CharacterType newEleTy = fir::CharacterType::getSingleton( eleTy.getContext(), charTy.getFKind()); - if (auto seqTy = resTy.dyn_cast()) { + if (auto seqTy = mlir::dyn_cast(resTy)) { assert(eleTy == seqTy.getEleTy()); resTy = fir::SequenceType::get(seqTy.getShape(), newEleTy); } @@ -6136,7 +6141,7 @@ if (!eleSz) { // Compute the element size at runtime. assert(fir::hasDynamicSize(eleTy)); - if (auto charTy = eleTy.dyn_cast()) { + if (auto charTy = mlir::dyn_cast(eleTy)) { auto charBytes = builder.getKindMap().getCharacterBitsize(charTy.getFKind()) / 8; mlir::Value bytes = @@ -6156,7 +6161,7 @@ auto computeCoordinate = [&](mlir::Value buff, mlir::Value off) { mlir::Type refTy = eleRefTy; if (fir::hasDynamicSize(eleTy)) { - if (auto charTy = eleTy.dyn_cast()) { + if (auto charTy = mlir::dyn_cast(eleTy)) { // Scale a simple pointer using dynamic length and offset values. auto chTy = fir::CharacterType::getSingleton(charTy.getContext(), charTy.getFKind()); @@ -6283,7 +6288,7 @@ builder.createConvert(loc, idxTy, fir::getBase(asScalar(x.upper()))); mlir::Value step = builder.createConvert(loc, idxTy, fir::getBase(asScalar(x.stride()))); - auto seqTy = resTy.template cast(); + auto seqTy = mlir::cast(resTy); mlir::Type eleTy = fir::unwrapSequenceType(seqTy); auto loop = builder.create(loc, lo, up, step, /*unordered=*/false, @@ -6350,7 +6355,7 @@ auto evExpr = toEvExpr(x); mlir::Type resTy = translateSomeExprToFIRType(converter, evExpr); mlir::IndexType idxTy = builder.getIndexType(); - auto seqTy = resTy.template cast(); + auto seqTy = mlir::cast(resTy); mlir::Type eleTy = fir::unwrapSequenceType(resTy); mlir::Value buffSize = builder.createTemporary(loc, idxTy, ".buff.size"); mlir::Value zero = builder.createIntegerConstant(loc, idxTy, 0); @@ -6693,7 +6698,7 @@ [&](const Fortran::evaluate::Component *x) { auto fieldTy = fir::FieldType::get(builder.getContext()); llvm::StringRef name = toStringRef(getLastSym(*x).name()); - if (auto recTy = ty.dyn_cast()) { + if (auto recTy = mlir::dyn_cast(ty)) { ty = recTy.getType(name); auto fld = builder.create( loc, fieldTy, name, recTy, fir::getTypeParams(arrayExv)); @@ -6702,7 +6707,7 @@ // 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 = ty.dyn_cast()) { + if (auto boxTy = mlir::dyn_cast(ty)) { auto currentFunc = components.getExtendCoorRef(); auto loc = getLoc(); auto *bldr = &converter.getFirOpBuilder(); @@ -6713,9 +6718,9 @@ deref = true; } } - } else if (auto boxTy = ty.dyn_cast()) { + } else if (auto boxTy = mlir::dyn_cast(ty)) { ty = fir::unwrapRefType(boxTy.getEleTy()); - auto recTy = ty.cast(); + auto recTy = mlir::cast(ty); ty = recTy.getType(name); auto fld = builder.create( loc, fieldTy, name, recTy, fir::getTypeParams(arrayExv)); @@ -6765,7 +6770,7 @@ auto arrayOp = builder.create( loc, eleRefTy, innerArg, iters.iterVec(), fir::factory::getTypeParams(loc, builder, load)); - if (auto charTy = eleTy.dyn_cast()) { + if (auto charTy = mlir::dyn_cast(eleTy)) { mlir::Value dstLen = fir::factory::genLenOfCharacter( builder, loc, load, iters.iterVec(), substringBounds); fir::ArrayAmendOp amend = createCharArrayAmend( @@ -6781,13 +6786,13 @@ return arrayLoadExtValue(builder, loc, load, iters.iterVec(), amend); } - assert(eleTy.isa()); + assert(mlir::isa(eleTy)); TODO(loc, "array (as element) assignment"); } if (components.hasExtendCoorRef()) { auto eleBoxTy = fir::applyPathToType(innerArg.getType(), iters.iterVec()); - if (!eleBoxTy || !eleBoxTy.isa()) + if (!eleBoxTy || !mlir::isa(eleBoxTy)) TODO(loc, "assignment in a FORALL involving a designator with a " "POINTER or ALLOCATABLE component part-ref"); auto arrayOp = builder.create( @@ -6799,7 +6804,7 @@ // assignment, then insert the dereference of the box before any // conversion and store. if (!isPointerAssignment()) { - if (auto boxTy = eleTy.dyn_cast()) { + if (auto boxTy = mlir::dyn_cast(eleTy)) { eleTy = fir::boxMemRefType(boxTy); addr = builder.create(loc, eleTy, addr); eleTy = fir::unwrapRefType(eleTy); @@ -6860,7 +6865,7 @@ } if (components.hasExtendCoorRef()) { auto eleBoxTy = fir::applyPathToType(load.getType(), iters.iterVec()); - if (!eleBoxTy || !eleBoxTy.isa()) + if (!eleBoxTy || !mlir::isa(eleBoxTy)) TODO(loc, "assignment in a FORALL involving a designator with a " "POINTER or ALLOCATABLE component part-ref"); auto access = builder.create( @@ -6872,7 +6877,7 @@ } if (isPointerAssignment()) { auto eleTy = fir::applyPathToType(load.getType(), iters.iterVec()); - if (!eleTy.isa()) { + if (!mlir::isa(eleTy)) { // 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); diff --git a/flang/lib/Lower/ConvertExprToHLFIR.cpp b/flang/lib/Lower/ConvertExprToHLFIR.cpp --- a/flang/lib/Lower/ConvertExprToHLFIR.cpp +++ b/flang/lib/Lower/ConvertExprToHLFIR.cpp @@ -146,7 +146,7 @@ const T &designatorNode) { // Get base's shape if its a sequence type with no previously computed // result shape - if (partInfo.base && resultValueType.isa() && + if (partInfo.base && mlir::isa(resultValueType) && !partInfo.resultShape) partInfo.resultShape = hlfir::genShape(getLoc(), getBuilder(), *partInfo.base); @@ -156,7 +156,7 @@ return fir::ClassType::get(resultValueType); // Character scalar with dynamic length needs a fir.boxchar to hold the // designator length. - auto charType = resultValueType.dyn_cast(); + auto charType = mlir::dyn_cast(resultValueType); if (charType && charType.hasDynamicLen()) return fir::BoxCharType::get(charType.getContext(), charType.getFKind()); // Arrays with non default lower bounds or dynamic length or dynamic extent @@ -165,7 +165,7 @@ hasNonDefaultLowerBounds(partInfo)) return fir::BoxType::get(resultValueType); // Non simply contiguous ref require a fir.box to carry the byte stride. - if (resultValueType.isa() && + if (mlir::isa(resultValueType) && !Fortran::evaluate::IsSimplyContiguous( designatorNode, getConverter().getFoldingContext())) return fir::BoxType::get(resultValueType); @@ -361,8 +361,8 @@ partInfo.typeParams[0] = fir::factory::genMaxWithZero(builder, loc, rawLen); } - auto kind = hlfir::getFortranElementType(baseStringType) - .cast() + auto kind = mlir::cast( + hlfir::getFortranElementType(baseStringType)) .getFKind(); auto newCharTy = fir::CharacterType::get( baseStringType.getContext(), kind, @@ -542,7 +542,7 @@ return createVectorSubscriptElementAddrOp(partInfo, baseType, resultExtents); - mlir::Type resultType = baseType.cast().getEleTy(); + mlir::Type resultType = mlir::cast(baseType).getEleTy(); if (!resultTypeShape.empty()) { // Ranked array section. The result shape comes from the array section // subscripts. @@ -575,8 +575,8 @@ } static bool hasNonDefaultLowerBounds(const PartInfo &partInfo) { return partInfo.resultShape && - (partInfo.resultShape.getType().isa() || - partInfo.resultShape.getType().isa()); + (mlir::isa(partInfo.resultShape.getType()) || + mlir::isa(partInfo.resultShape.getType())); } mlir::Value genComponentShape(const Fortran::semantics::Symbol &componentSym, @@ -592,8 +592,8 @@ mlir::Location loc = getLoc(); mlir::Type idxTy = builder.getIndexType(); llvm::SmallVector extents; - auto seqTy = hlfir::getFortranElementOrSequenceType(fieldType) - .cast(); + auto seqTy = mlir::cast( + hlfir::getFortranElementOrSequenceType(fieldType)); for (auto extent : seqTy.getShape()) { if (extent == fir::SequenceType::getUnknownExtent()) { // We have already generated invalid hlfir.declare @@ -713,7 +713,7 @@ "parent components are skipped and must not reach visitComponentImpl"); partInfo.componentName = componentSym.name().ToString(); auto recordType = - hlfir::getFortranElementType(baseType).cast(); + mlir::cast(hlfir::getFortranElementType(baseType)); if (recordType.isDependentType()) TODO(getLoc(), "Designate derived type with length parameters in HLFIR"); mlir::Type fieldType = recordType.getType(partInfo.componentName); @@ -725,7 +725,7 @@ if (fir::isRecordWithTypeParameters(fieldEleType)) TODO(loc, "lower a component that is a parameterized derived type to HLFIR"); - if (auto charTy = fieldEleType.dyn_cast()) { + if (auto charTy = mlir::dyn_cast(fieldEleType)) { mlir::Location loc = getLoc(); mlir::Type idxTy = builder.getIndexType(); if (charTy.hasConstantLen()) @@ -813,7 +813,7 @@ } } builder.setInsertionPoint(elementalAddrOp); - return baseType.cast().getEleTy(); + return mlir::cast(baseType).getEleTy(); } /// Yield the designator for the final part-ref inside the diff --git a/flang/lib/Lower/ConvertProcedureDesignator.cpp b/flang/lib/Lower/ConvertProcedureDesignator.cpp --- a/flang/lib/Lower/ConvertProcedureDesignator.cpp +++ b/flang/lib/Lower/ConvertProcedureDesignator.cpp @@ -105,7 +105,7 @@ fir::FirOpBuilder &builder = converter.getFirOpBuilder(); mlir::Value funcAddr = fir::getBase(procExv); - if (!funcAddr.getType().isa()) { + if (!mlir::isa(funcAddr.getType())) { 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 --- a/flang/lib/Lower/ConvertVariable.cpp +++ b/flang/lib/Lower/ConvertVariable.cpp @@ -305,13 +305,13 @@ fir::FirOpBuilder &builder = converter.getFirOpBuilder(); mlir::Type scalarType = symTy; fir::SequenceType sequenceType; - if (auto ty = symTy.dyn_cast()) { + if (auto ty = mlir::dyn_cast(symTy)) { 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 = scalarType.cast(); + auto recTy = mlir::cast(scalarType); auto fieldTy = fir::FieldType::get(scalarType.getContext()); mlir::Value initialValue = builder.create(loc, scalarType); const Fortran::semantics::DeclTypeSpec *declTy = sym.GetType(); @@ -433,10 +433,11 @@ // with a tensor mlir type. This optimization currently only supports // Fortran arrays of integer, real, or logical. The tensor type does // not support nested structures which are needed for complex numbers. - if (symTy.isa() && + if (mlir::isa(symTy) && !Fortran::semantics::IsAllocatableOrPointer(sym)) { - mlir::Type eleTy = symTy.cast().getEleTy(); - if (eleTy.isa()) { + mlir::Type eleTy = mlir::cast(symTy).getEleTy(); + if (mlir::isa( + eleTy)) { const auto *details = sym.detailsIf(); if (details->init()) { @@ -518,7 +519,8 @@ Fortran::lower::createGlobalInitialization( builder, global, [&](fir::FirOpBuilder &builder) { mlir::Value initValue; - if (symTy.isa()) + if (mlir::isa( + symTy)) initValue = builder.create(loc, symTy); else initValue = builder.create(loc, symTy); @@ -1171,7 +1173,7 @@ fir::GlobalOp global, const Fortran::semantics::MutableSymbolVector &cmnBlkMems) { fir::FirOpBuilder &builder = converter.getFirOpBuilder(); - mlir::TupleType commonTy = global.getType().cast(); + mlir::TupleType commonTy = mlir::cast(global.getType()); auto initFunc = [&](fir::FirOpBuilder &builder) { mlir::IndexType idxTy = builder.getIndexType(); mlir::Value cb = builder.create(loc, commonTy); @@ -1276,7 +1278,7 @@ static bool lowerToBoxValue(const Fortran::semantics::Symbol &sym, mlir::Value dummyArg) { // Only dummy arguments coming as fir.box can be tracked in an BoxValue. - if (!dummyArg || !dummyArg.getType().isa()) + if (!dummyArg || !mlir::isa(dummyArg.getType())) return false; // Non contiguous arrays must be tracked in an BoxValue. if (sym.Rank() > 0 && !sym.attrs().test(Fortran::semantics::Attr::CONTIGUOUS)) @@ -1709,8 +1711,8 @@ // a non pointer/allocatable symbol to be mapped to a MutableBox. mlir::Type ty = converter.genType(var); bool isPolymorphic = false; - if (auto boxTy = ty.dyn_cast()) { - isPolymorphic = ty.isa(); + if (auto boxTy = mlir::dyn_cast(ty)) { + isPolymorphic = mlir::isa(ty); ty = boxTy.getEleTy(); } Fortran::lower::genDeclareSymbol( @@ -1817,7 +1819,7 @@ mlir::Value addr = preAlloc; if (arg) - if (auto boxTy = arg.getType().dyn_cast()) { + if (auto boxTy = mlir::dyn_cast(arg.getType())) { // Contiguous assumed shape that can be tracked without a fir.box. mlir::Type refTy = builder.getRefType(boxTy.getEleTy()); addr = builder.create(loc, refTy, arg); @@ -1827,7 +1829,7 @@ if (ba.isChar()) { if (arg) { assert(!preAlloc && "dummy cannot be pre-allocated"); - if (arg.getType().isa()) + if (mlir::isa(arg.getType())) std::tie(addr, len) = charHelp.createUnboxChar(arg); } if (std::optional cstLen = ba.getCharLenConst()) { @@ -1847,7 +1849,7 @@ } else if (!len) { // Assumed length fir.box (possible for contiguous assumed shapes). // Read length from box. - assert(arg && arg.getType().isa() && + assert(arg && mlir::isa(arg.getType()) && "must be character dummy fir.box"); len = charHelp.readLengthFromBox(arg); } @@ -1896,7 +1898,7 @@ if (isCptrByVal || !fir::conformsWithPassByRef(argType)) { // Dummy argument passed in register. Place the value in memory at that // point since lowering expect symbols to be mapped to memory addresses. - if (argType.isa()) + if (mlir::isa(argType)) TODO(loc, "derived type argument passed by value"); mlir::Type symType = converter.genType(sym); addr = builder.create(loc, symType); diff --git a/flang/lib/Lower/CustomIntrinsicCall.cpp b/flang/lib/Lower/CustomIntrinsicCall.cpp --- a/flang/lib/Lower/CustomIntrinsicCall.cpp +++ b/flang/lib/Lower/CustomIntrinsicCall.cpp @@ -232,22 +232,23 @@ 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, - resultType.cast().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, + mlir::cast(resultType).getWidth()); + builder.create(loc, bitSize); + }) + .getResults()[0]); return genIntrinsicCall(builder, loc, name, resultType, args, stmtCtx); } @@ -287,7 +288,7 @@ builder.create(loc, builder.getI1Type(), targetBase); mlir::Type targetType = fir::unwrapRefType(targetBase.getType()); mlir::Type targetValueType = fir::unwrapPassByRefType(targetType); - mlir::Type boxType = targetType.isa() + mlir::Type boxType = mlir::isa(targetType) ? targetType : fir::BoxType::get(targetValueType); fir::BoxValue targetBox = diff --git a/flang/lib/Lower/HostAssociations.cpp b/flang/lib/Lower/HostAssociations.cpp --- a/flang/lib/Lower/HostAssociations.cpp +++ b/flang/lib/Lower/HostAssociations.cpp @@ -220,7 +220,7 @@ static mlir::Type getType(Fortran::lower::AbstractConverter &converter, const Fortran::semantics::Symbol &sym) { fir::KindTy kind = - converter.genType(sym).cast().getFKind(); + mlir::cast(converter.genType(sym)).getFKind(); return fir::BoxCharType::get(&converter.getMLIRContext(), kind); } @@ -344,7 +344,7 @@ static mlir::Type getType(Fortran::lower::AbstractConverter &converter, const Fortran::semantics::Symbol &sym) { mlir::Type type = converter.genType(sym); - assert(type.isa() && "must be a sequence type"); + assert(mlir::isa(type) && "must be a sequence type"); return fir::BoxType::get(type); } @@ -418,7 +418,7 @@ // (absent boxes are null descriptor addresses, not descriptors containing // a null base address). if (Fortran::semantics::IsOptional(sym)) { - auto boxTy = box.getType().cast(); + auto boxTy = mlir::cast(box.getType()); auto eleTy = boxTy.getEleTy(); if (!fir::isa_ref_type(eleTy)) eleTy = builder.getRefType(eleTy); @@ -489,7 +489,7 @@ // `t` should be the result of getArgumentType, which has a type of // `!fir.ref>`. static mlir::TupleType unwrapTupleTy(mlir::Type t) { - return fir::dyn_cast_ptrEleTy(t).cast(); + return mlir::cast(fir::dyn_cast_ptrEleTy(t)); } static mlir::Value genTupleCoor(fir::FirOpBuilder &builder, mlir::Location loc, @@ -497,7 +497,7 @@ mlir::Value offset) { // fir.ref and fir.ptr are forbidden. Use // fir.llvm_ptr if needed. - auto ty = varTy.isa() + auto ty = mlir::isa(varTy) ? 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 --- a/flang/lib/Lower/IO.cpp +++ b/flang/lib/Lower/IO.cpp @@ -167,7 +167,7 @@ } inline int64_t getLength(mlir::Type argTy) { - return argTy.cast().getShape()[0]; + return mlir::cast(argTy).getShape()[0]; } /// Get (or generate) the MLIR FuncOp for a given IO runtime function. @@ -654,11 +654,11 @@ static mlir::func::FuncOp getOutputFunc(mlir::Location loc, fir::FirOpBuilder &builder, mlir::Type type, bool isFormatted) { - if (type.isa()) + if (mlir::isa(type)) return getIORuntimeFunc(loc, builder); if (!isFormatted) return getIORuntimeFunc(loc, builder); - if (auto ty = type.dyn_cast()) { + if (auto ty = mlir::dyn_cast(type)) { switch (ty.getWidth()) { case 1: return getIORuntimeFunc(loc, builder); @@ -675,14 +675,14 @@ } llvm_unreachable("unknown OutputInteger kind"); } - if (auto ty = type.dyn_cast()) { + if (auto ty = mlir::dyn_cast(type)) { 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 = type.dyn_cast()) { + if (auto ty = mlir::dyn_cast(type)) { // COMPLEX(KIND=k) corresponds to a pair of REAL(KIND=k). auto width = kindMap.getRealBitsize(ty.getFKind()); if (width == 32) @@ -690,7 +690,7 @@ else if (width == 64) return getIORuntimeFunc(loc, builder); } - if (type.isa()) + if (mlir::isa(type)) 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 @@ -729,14 +729,14 @@ mlir::func::FuncOp outputFunc = getOutputFunc(loc, builder, itemTy, isFormatted); mlir::Type argType = outputFunc.getFunctionType().getInput(1); - assert((isFormatted || argType.isa()) && + assert((isFormatted || mlir::isa(argType)) && "expect descriptor for unformatted IO runtime"); llvm::SmallVector outputFuncArgs = {cookie}; fir::factory::CharacterExprHelper helper{builder, loc}; - if (argType.isa()) { + if (mlir::isa(argType)) { mlir::Value box = fir::getBase(converter.genExprBox(loc, *expr, stmtCtx)); outputFuncArgs.push_back(builder.createConvert(loc, argType, box)); - if (itemTy.isa()) + if (mlir::isa(itemTy)) outputFuncArgs.push_back(getNonTbpDefinedIoTableAddr(converter)); } else if (helper.isCharacterScalar(itemTy)) { fir::ExtendedValue exv = converter.genExprAddr(loc, expr, stmtCtx); @@ -771,29 +771,29 @@ static mlir::func::FuncOp getInputFunc(mlir::Location loc, fir::FirOpBuilder &builder, mlir::Type type, bool isFormatted) { - if (type.isa()) + if (mlir::isa(type)) return getIORuntimeFunc(loc, builder); if (!isFormatted) return getIORuntimeFunc(loc, builder); - if (auto ty = type.dyn_cast()) + if (auto ty = mlir::dyn_cast(type)) return ty.getWidth() == 1 ? getIORuntimeFunc(loc, builder) : getIORuntimeFunc(loc, builder); - if (auto ty = type.dyn_cast()) { + if (auto ty = mlir::dyn_cast(type)) { 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 = type.dyn_cast()) { + if (auto ty = mlir::dyn_cast(type)) { auto width = kindMap.getRealBitsize(ty.getFKind()); if (width == 32) return getIORuntimeFunc(loc, builder); else if (width == 64) return getIORuntimeFunc(loc, builder); } - if (type.isa()) + if (mlir::isa(type)) return getIORuntimeFunc(loc, builder); if (fir::factory::CharacterExprHelper::isCharacterScalar(type)) { auto asciiKind = kindMap.defaultCharacterKind(); @@ -828,12 +828,12 @@ fir::FirOpBuilder &builder = converter.getFirOpBuilder(); mlir::Type argType = inputFunc.getFunctionType().getInput(1); llvm::SmallVector inputFuncArgs = {cookie}; - if (argType.isa()) { + if (mlir::isa(argType)) { mlir::Value box = fir::getBase(item); - auto boxTy = box.getType().dyn_cast(); + auto boxTy = mlir::dyn_cast(box.getType()); assert(boxTy && "must be previously emboxed"); inputFuncArgs.push_back(builder.createConvert(loc, argType, box)); - if (boxTy.getEleTy().isa()) + if (mlir::isa(boxTy.getEleTy())) inputFuncArgs.push_back(getNonTbpDefinedIoTableAddr(converter)); } else { mlir::Value itemAddr = fir::getBase(item); @@ -844,16 +844,16 @@ mlir::Value len = fir::getLen(item); inputFuncArgs.push_back(builder.createConvert( loc, inputFunc.getFunctionType().getInput(2), len)); - } else if (itemTy.isa()) { + } else if (mlir::isa(itemTy)) { inputFuncArgs.push_back(builder.create( loc, builder.getI32IntegerAttr( - itemTy.cast().getWidth() / 8))); + mlir::cast(itemTy).getWidth() / 8))); } } auto call = builder.create(loc, inputFunc, inputFuncArgs); auto itemAddr = fir::getBase(item); auto itemTy = fir::unwrapRefType(itemAddr.getType()); - if (itemTy.isa()) + if (mlir::isa(itemTy)) boolRefToLogical(loc, builder, itemAddr); return call.getResult(0); } @@ -884,7 +884,7 @@ mlir::func::FuncOp inputFunc = getInputFunc( loc, builder, vectorSubscriptBox.getElementType(), isFormatted); const bool mustBox = - inputFunc.getFunctionType().getInput(1).isa(); + mlir::isa(inputFunc.getFunctionType().getInput(1)); if (!checkResult) { auto elementalGenerator = [&](const fir::ExtendedValue &element) { createIoRuntimeCallForItem(converter, loc, inputFunc, cookie, @@ -909,9 +909,10 @@ mlir::Type itemTy = converter.genType(*expr); mlir::func::FuncOp inputFunc = getInputFunc(loc, builder, itemTy, isFormatted); - auto itemExv = inputFunc.getFunctionType().getInput(1).isa() - ? converter.genExprBox(loc, *expr, stmtCtx) - : converter.genExprAddr(loc, expr, stmtCtx); + auto itemExv = + mlir::isa(inputFunc.getFunctionType().getInput(1)) + ? converter.genExprBox(loc, *expr, stmtCtx) + : converter.genExprAddr(loc, expr, stmtCtx); ok = createIoRuntimeCallForItem(converter, loc, inputFunc, cookie, itemExv); } } @@ -1808,8 +1809,8 @@ auto &builder = converter.getFirOpBuilder(); auto rawUnit = fir::getBase(converter.genExprValue(loc, iounit, stmtCtx)); unsigned rawUnitWidth = - rawUnit.getType().cast().getWidth(); - unsigned runtimeArgWidth = ty.cast().getWidth(); + mlir::cast(rawUnit.getType()).getWidth(); + unsigned runtimeArgWidth = mlir::cast(ty).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. @@ -2353,7 +2354,7 @@ if (!eleTy) fir::emitFatalError(loc, "internal error: expected a memory reference type"); - auto width = eleTy.cast().getWidth(); + auto width = mlir::cast(eleTy).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 --- a/flang/lib/Lower/OpenACC.cpp +++ b/flang/lib/Lower/OpenACC.cpp @@ -110,7 +110,8 @@ mlir::Type idxTy = builder.getIndexType(); mlir::Type boundTy = builder.getType(); mlir::Value one = builder.createIntegerConstant(loc, idxTy, 1); - assert(box.getType().isa() && "expect firbox or fir.class"); + assert(mlir::isa(box.getType()) && + "expect firbox or fir.class"); for (unsigned dim = 0; dim < dataExv.rank(); ++dim) { mlir::Value d = builder.createIntegerConstant(loc, idxTy, dim); mlir::Value baseLb = @@ -186,7 +187,7 @@ mlir::Value stride = one; bool strideInBytes = false; - if (fir::unwrapRefType(baseAddr.getType()).isa()) { + if (mlir::isa(fir::unwrapRefType(baseAddr.getType()))) { mlir::Value d = builder.createIntegerConstant(loc, idxTy, dimension); auto dimInfo = builder.create(loc, idxTy, idxTy, idxTy, baseAddr, d); @@ -284,14 +285,14 @@ if (!symAddr) llvm::report_fatal_error("could not retrieve symbol address"); - if (auto boxTy = - fir::unwrapRefType(symAddr.getType()).dyn_cast()) { - if (boxTy.getEleTy().isa()) + if (auto boxTy = mlir::dyn_cast( + fir::unwrapRefType(symAddr.getType()))) { + if (mlir::isa(boxTy.getEleTy())) TODO(loc, "derived type"); // Load the box when baseAddr is a `fir.ref>` or a // `fir.ref>` type. - if (symAddr.getType().isa()) + if (mlir::isa(symAddr.getType())) return builder.create(loc, symAddr); } return symAddr; @@ -348,8 +349,8 @@ fir::ExtendedValue compExv = converter.genExprAddr(operandLocation, *expr, stmtCtx); baseAddr = fir::getBase(compExv); - if (fir::unwrapRefType(baseAddr.getType()) - .isa()) + if (mlir::isa( + fir::unwrapRefType(baseAddr.getType()))) bounds = genBaseBoundsOps(builder, operandLocation, converter, compExv, baseAddr); asFortran << (*expr).AsFortran(); @@ -373,12 +374,12 @@ converter.getSymbolExtendedValue(*name.symbol); baseAddr = getDataOperandBaseAddr( converter, builder, *name.symbol, operandLocation); - if (fir::unwrapRefType(baseAddr.getType()) - .isa()) + if (mlir::isa( + fir::unwrapRefType(baseAddr.getType()))) bounds = genBoundsOpsFromBox(builder, operandLocation, converter, dataExv, baseAddr); - if (fir::unwrapRefType(baseAddr.getType()) - .isa()) + if (mlir::isa( + fir::unwrapRefType(baseAddr.getType()))) bounds = genBaseBoundsOps(builder, operandLocation, converter, dataExv, baseAddr); asFortran << name.ToString(); @@ -419,7 +420,7 @@ mlir::SmallVector bounds, bool structured, mlir::acc::DataClause dataClause) { mlir::Value varPtrPtr; - if (auto boxTy = baseAddr.getType().dyn_cast()) + if (auto boxTy = mlir::dyn_cast(baseAddr.getType())) baseAddr = builder.create(loc, baseAddr); Op op = builder.create(loc, baseAddr.getType(), baseAddr); @@ -1221,7 +1222,7 @@ if (ifCond) { if (auto cst = mlir::dyn_cast(ifCond.getDefiningOp())) - if (auto boolAttr = cst.getValue().dyn_cast()) { + if (auto boolAttr = mlir::dyn_cast(cst.getValue())) { if (boolAttr.getValue()) { // get rid of the if condition if it is always true. ifCond = mlir::Value(); diff --git a/flang/lib/Lower/OpenMP.cpp b/flang/lib/Lower/OpenMP.cpp --- a/flang/lib/Lower/OpenMP.cpp +++ b/flang/lib/Lower/OpenMP.cpp @@ -754,9 +754,9 @@ for (mlir::Value mapOp : mapOperand) { /// Check for unsupported map operand types. mlir::Type checkType = mapOp.getType(); - if (auto refType = checkType.dyn_cast()) + if (auto refType = mlir::dyn_cast(checkType)) checkType = refType.getElementType(); - if (checkType.isa()) + if (mlir::isa(checkType)) TODO(currentLocation, "OMPD_target_data MapOperand BoxType"); mapOperands.push_back(mapOp); @@ -1191,10 +1191,10 @@ llvm::StringRef reductionOpName, fir::FirOpBuilder &builder) { assert((fir::isa_integer(type) || fir::isa_real(type) || - type.isa()) && + mlir::isa(type)) && "only integer, logical and real types are currently supported"); if (reductionOpName.contains("max")) { - if (auto ty = type.dyn_cast()) { + if (auto ty = mlir::dyn_cast(type)) { const llvm::fltSemantics &sem = ty.getFloatSemantics(); return builder.createRealConstant( loc, type, llvm::APFloat::getLargest(sem, /*Negative=*/true)); @@ -1203,7 +1203,7 @@ int64_t minInt = llvm::APInt::getSignedMinValue(bits).getSExtValue(); return builder.createIntegerConstant(loc, type, minInt); } else if (reductionOpName.contains("min")) { - if (auto ty = type.dyn_cast()) { + if (auto ty = mlir::dyn_cast(type)) { const llvm::fltSemantics &sem = ty.getFloatSemantics(); return builder.createRealConstant( loc, type, llvm::APFloat::getSmallest(sem, /*Negative=*/true)); @@ -1224,13 +1224,13 @@ int64_t allOnInt = llvm::APInt::getAllOnes(bits).getSExtValue(); return builder.createIntegerConstant(loc, type, allOnInt); } else { - if (type.isa()) + if (mlir::isa(type)) return builder.create( loc, type, builder.getFloatAttr( type, (double)getOperationIdentity(reductionOpName, loc))); - if (type.isa()) { + if (mlir::isa(type)) { Value intConst = builder.create( loc, builder.getI1Type(), builder.getIntegerAttr(builder.getI1Type(), @@ -1625,9 +1625,9 @@ if (const auto *symbol{name->symbol}) { mlir::Value symVal = converter.getSymbolAddress(*symbol); mlir::Type redType = - symVal.getType().cast().getEleTy(); + mlir::cast(symVal.getType()).getEleTy(); reductionVars.push_back(symVal); - if (redType.isa()) + if (mlir::isa(redType)) decl = createReductionDecl( firOpBuilder, getReductionName(intrinsicOp, firOpBuilder.getI1Type()), @@ -1663,7 +1663,7 @@ if (const auto *symbol{name->symbol}) { mlir::Value symVal = converter.getSymbolAddress(*symbol); mlir::Type redType = - symVal.getType().cast().getEleTy(); + mlir::cast(symVal.getType()).getEleTy(); reductionVars.push_back(symVal); assert(redType.isIntOrIndexOrFloat() && "Unsupported reduction type"); @@ -1713,7 +1713,7 @@ auto simdLoopOp = firOpBuilder.create( currentLocation, resultType, lowerBound, upperBound, step, alignedVars, nullptr, ifClauseOperand, nontemporalVars, - orderClauseOperand.dyn_cast_or_null(), + mlir::dyn_cast_if_present(orderClauseOperand), simdlenClauseOperand, safelenClauseOperand, /*inclusive=*/firOpBuilder.getUnitAttr()); createBodyOfOp(simdLoopOp, converter, currentLocation, @@ -1731,12 +1731,13 @@ ? nullptr : mlir::ArrayAttr::get(firOpBuilder.getContext(), reductionDeclSymbols), - scheduleClauseOperand.dyn_cast_or_null(), + mlir::dyn_cast_if_present( + scheduleClauseOperand), scheduleChunkClauseOperand, /*schedule_modifiers=*/nullptr, /*simd_modifier=*/nullptr, - noWaitClauseOperand.dyn_cast_or_null(), - orderedClauseOperand.dyn_cast_or_null(), - orderClauseOperand.dyn_cast_or_null(), + mlir::dyn_cast_if_present(noWaitClauseOperand), + mlir::dyn_cast_if_present(orderedClauseOperand), + mlir::dyn_cast_if_present(orderClauseOperand), /*inclusive=*/firOpBuilder.getUnitAttr()); // Handle attribute based clauses. @@ -2456,7 +2457,7 @@ // Create default initialization for non-character scalar. if (Fortran::semantics::IsAllocatableOrPointer(sym)) { - mlir::Type baseAddrType = ty.dyn_cast().getEleTy(); + mlir::Type baseAddrType = mlir::dyn_cast(ty).getEleTy(); Fortran::lower::createGlobalInitialization( firOpBuilder, global, [&](fir::FirOpBuilder &b) { mlir::Value nullAddr = @@ -2588,8 +2589,9 @@ if (const auto *symbol{name->symbol}) { mlir::Value reductionVal = converter.getSymbolAddress(*symbol); mlir::Type reductionType = - reductionVal.getType().cast().getEleTy(); - if (!reductionType.isa()) { + mlir::cast(reductionVal.getType()) + .getEleTy(); + if (!mlir::isa(reductionType)) { if (!reductionType.isIntOrIndexOrFloat()) continue; } @@ -2597,7 +2599,7 @@ if (auto loadOp = mlir::dyn_cast( reductionValUse.getOwner())) { mlir::Value loadVal = loadOp.getRes(); - if (reductionType.isa()) { + if (mlir::isa(reductionType)) { mlir::Operation *reductionOp = findReductionChain(loadVal); fir::ConvertOp convertOp = getConvertFromReductionOp(reductionOp, loadVal); diff --git a/flang/lib/Lower/VectorSubscripts.cpp b/flang/lib/Lower/VectorSubscripts.cpp --- a/flang/lib/Lower/VectorSubscripts.cpp +++ b/flang/lib/Lower/VectorSubscripts.cpp @@ -105,7 +105,7 @@ } mlir::Type gen(const Fortran::evaluate::Component &component) { - auto recTy = gen(component.base()).cast(); + auto recTy = mlir::cast(gen(component.base())); 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 --- a/flang/lib/Optimizer/Analysis/AliasAnalysis.cpp +++ b/flang/lib/Optimizer/Analysis/AliasAnalysis.cpp @@ -24,7 +24,7 @@ //===----------------------------------------------------------------------===// static bool isDummyArgument(mlir::Value v) { - auto blockArg{v.dyn_cast()}; + auto blockArg{mlir::dyn_cast(v)}; if (!blockArg) return false; @@ -34,9 +34,9 @@ namespace fir { void AliasAnalysis::Source::print(llvm::raw_ostream &os) const { - if (auto v = llvm::dyn_cast(u)) + if (auto v = mlir::dyn_cast(u)) os << v; - else if (auto gbl = llvm::dyn_cast(u)) + else if (auto gbl = mlir::dyn_cast(u)) os << gbl; os << " SourceKind: " << EnumToString(kind); os << " Type: " << valueType << " "; @@ -48,7 +48,7 @@ if (!eleTy) return false; - return fir::isPointerType(eleTy) || eleTy.isa(); + return fir::isPointerType(eleTy) || mlir::isa(eleTy); } bool AliasAnalysis::Source::isTargetOrPointer() const { @@ -61,7 +61,7 @@ if (!eleTy) return false; // TO DO: Look for pointer components - return eleTy.isa(); + return mlir::isa(eleTy); } AliasResult AliasAnalysis::alias(Value lhs, Value rhs) { @@ -216,7 +216,7 @@ if (Source::isPointerReference(ty)) attributes.set(Attribute::Pointer); - global = llvm::cast(op).getSymbol(); + global = mlir::cast(op).getSymbol(); breakFromLoop = true; }) .Default([&](auto op) { diff --git a/flang/lib/Optimizer/Builder/BoxValue.cpp b/flang/lib/Optimizer/Builder/BoxValue.cpp --- a/flang/lib/Optimizer/Builder/BoxValue.cpp +++ b/flang/lib/Optimizer/Builder/BoxValue.cpp @@ -191,7 +191,7 @@ mlir::Type type = fir::dyn_cast_ptrEleTy(getAddr().getType()); if (!type) return false; - auto box = type.dyn_cast(); + auto box = mlir::dyn_cast(type); if (!box) return false; // A boxed value always takes a memory reference, @@ -210,7 +210,7 @@ /// Debug verifier for BoxValue ctor. There is no guarantee this will /// always be called. bool fir::BoxValue::verify() const { - if (!addr.getType().isa()) + if (!mlir::isa(addr.getType())) 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 --- a/flang/lib/Optimizer/Builder/Character.cpp +++ b/flang/lib/Optimizer/Builder/Character.cpp @@ -25,11 +25,11 @@ /// Unwrap all the ref and box types and return the inner element type. static mlir::Type unwrapBoxAndRef(mlir::Type type) { - if (auto boxType = type.dyn_cast()) + if (auto boxType = mlir::dyn_cast(type)) return boxType.getEleTy(); while (true) { type = fir::unwrapRefType(type); - if (auto boxTy = type.dyn_cast()) + if (auto boxTy = mlir::dyn_cast(type)) type = boxTy.getEleTy(); else break; @@ -40,19 +40,19 @@ /// Unwrap base fir.char type. static fir::CharacterType recoverCharacterType(mlir::Type type) { type = fir::unwrapSequenceType(unwrapBoxAndRef(type)); - if (auto charTy = type.dyn_cast()) + if (auto charTy = mlir::dyn_cast(type)) return charTy; llvm::report_fatal_error("expected a character type"); } bool fir::factory::CharacterExprHelper::isCharacterScalar(mlir::Type type) { type = unwrapBoxAndRef(type); - return !type.isa() && fir::isa_char(type); + return !mlir::isa(type) && fir::isa_char(type); } bool fir::factory::CharacterExprHelper::isArray(mlir::Type type) { type = unwrapBoxAndRef(type); - if (auto seqTy = type.dyn_cast()) + if (auto seqTy = mlir::dyn_cast(type)) return fir::isa_char(seqTy.getEleTy()); return false; } @@ -91,7 +91,8 @@ /// 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 str.getType().isa() || fir::isa_char(str.getType()); + return mlir::isa(str.getType()) || + fir::isa_char(str.getType()); } /// This is called only if `str` does not reside in memory. Such a bare string @@ -102,7 +103,7 @@ assert(needToMaterialize(str)); auto ty = str.getType(); assert(isCharacterScalar(ty) && "expected scalar character"); - auto charTy = ty.dyn_cast(); + auto charTy = mlir::dyn_cast(ty); if (!charTy || charTy.getLen() == fir::CharacterType::unknownLen()) { LLVM_DEBUG(llvm::dbgs() << "cannot materialize: " << str << '\n'); llvm_unreachable("must be a !fir.char type"); @@ -128,7 +129,7 @@ if (auto eleType = fir::dyn_cast_ptrEleTy(type)) type = eleType; - if (auto arrayType = type.dyn_cast()) { + if (auto arrayType = mlir::dyn_cast(type)) { type = arrayType.getEleTy(); auto indexType = builder.getIndexType(); for (auto extent : arrayType.getShape()) { @@ -144,10 +145,10 @@ mlir::emitError(loc, "cannot retrieve array extents from type"); } - if (auto charTy = type.dyn_cast()) { + if (auto charTy = mlir::dyn_cast(type)) { if (!resultLen && charTy.getLen() != fir::CharacterType::unknownLen()) resultLen = builder.createIntegerConstant(loc, lenType, charTy.getLen()); - } else if (auto boxCharType = type.dyn_cast()) { + } else if (auto boxCharType = mlir::dyn_cast(type)) { auto refType = builder.getRefType(boxCharType.getEleTy()); // If the embox is accessible, use its operand to avoid filling // the generated fir with embox/unbox. @@ -167,7 +168,7 @@ if (!resultLen) { resultLen = boxCharLen; } - } else if (type.isa()) { + } else if (mlir::isa(type)) { mlir::emitError(loc, "descriptor or derived type not yet handled"); } else { llvm_unreachable("Cannot translate mlir::Value to character ExtendedValue"); @@ -218,7 +219,7 @@ fir::CharBoxValue fir::factory::CharacterExprHelper::toScalarCharacter( const fir::CharArrayBoxValue &box) { - if (box.getBuffer().getType().isa()) + if (mlir::isa(box.getBuffer().getType())) 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 @@ -652,7 +653,7 @@ } bool fir::factory::CharacterExprHelper::isCharacterLiteral(mlir::Type type) { - if (auto seqType = type.dyn_cast()) + if (auto seqType = mlir::dyn_cast(type)) return (seqType.getShape().size() == 1) && fir::isa_char(seqType.getEleTy()); return false; @@ -725,9 +726,9 @@ if (charType.hasConstantLen()) return builder.createIntegerConstant(loc, builder.getCharacterLengthType(), charType.getLen()); - if (memrefType.isa()) + if (mlir::isa(memrefType)) return readLengthFromBox(memref); - if (memrefType.isa()) + if (mlir::isa(memrefType)) return createUnboxChar(memref).second; // Length cannot be deduced from memref. @@ -739,14 +740,14 @@ mlir::Location loc, mlir::Value tuple, bool openBoxProc) { - mlir::TupleType tupleType = tuple.getType().cast(); + mlir::TupleType tupleType = mlir::cast(tuple.getType()); 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 = addr.getType().dyn_cast()) + if (auto addrTy = mlir::dyn_cast(addr.getType())) return builder.create(loc, addrTy.getEleTy(), addr); return addr; }(); @@ -760,7 +761,7 @@ mlir::Value fir::factory::createCharacterProcedureTuple( fir::FirOpBuilder &builder, mlir::Location loc, mlir::Type argTy, mlir::Value addr, mlir::Value len) { - mlir::TupleType tupleType = argTy.cast(); + mlir::TupleType tupleType = mlir::cast(argTy); addr = builder.createConvert(loc, tupleType.getType(0), addr); if (len) len = builder.createConvert(loc, tupleType.getType(1), len); diff --git a/flang/lib/Optimizer/Builder/Complex.cpp b/flang/lib/Optimizer/Builder/Complex.cpp --- a/flang/lib/Optimizer/Builder/Complex.cpp +++ b/flang/lib/Optimizer/Builder/Complex.cpp @@ -14,7 +14,8 @@ mlir::Type fir::factory::Complex::getComplexPartType(mlir::Type complexType) const { - return builder.getRealType(complexType.cast().getFKind()); + return builder.getRealType( + mlir::cast(complexType).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 --- a/flang/lib/Optimizer/Builder/FIRBuilder.cpp +++ b/flang/lib/Optimizer/Builder/FIRBuilder.cpp @@ -57,7 +57,7 @@ } mlir::Type fir::FirOpBuilder::getRefType(mlir::Type eleTy) { - assert(!eleTy.isa() && "cannot be a reference type"); + assert(!mlir::isa(eleTy) && "cannot be a reference type"); return fir::ReferenceType::get(eleTy); } @@ -102,7 +102,7 @@ fir::FirOpBuilder::createRealConstant(mlir::Location loc, mlir::Type fltTy, llvm::APFloat::integerPart val) { auto apf = [&]() -> llvm::APFloat { - if (auto ty = fltTy.dyn_cast()) + if (auto ty = mlir::dyn_cast(fltTy)) return llvm::APFloat(kindMap.getFloatSemantics(ty.getFKind()), val); if (fltTy.isF16()) return llvm::APFloat(llvm::APFloat::IEEEhalf(), val); @@ -124,7 +124,7 @@ mlir::Value fir::FirOpBuilder::createRealConstant(mlir::Location loc, mlir::Type fltTy, const llvm::APFloat &value) { - if (fltTy.isa()) { + if (mlir::isa(fltTy)) { auto attr = getFloatAttr(fltTy, value); return create(loc, fltTy, attr); } @@ -133,7 +133,7 @@ static llvm::SmallVector elideExtentsAlreadyInType(mlir::Type type, mlir::ValueRange shape) { - auto arrTy = type.dyn_cast(); + auto arrTy = mlir::dyn_cast(type); if (shape.empty() || !arrTy) return {}; // elide the constant dimensions before construction @@ -150,7 +150,7 @@ elideLengthsAlreadyInType(mlir::Type type, mlir::ValueRange lenParams) { if (lenParams.empty()) return {}; - if (auto arrTy = type.dyn_cast()) + if (auto arrTy = mlir::dyn_cast(type)) type = arrTy.getEleTy(); if (fir::hasDynamicSize(type)) return lenParams; @@ -227,7 +227,7 @@ // alloca here. const bool pinned = getRegion().getParentOfType(); - assert(!type.isa() && "cannot be a reference"); + assert(!mlir::isa(type) && "cannot be a reference"); auto ae = create(loc, type, /*unique_name=*/llvm::StringRef{}, name, pinned, dynamicLength, dynamicShape, attrs); @@ -245,7 +245,7 @@ llvm::SmallVector dynamicLength = elideLengthsAlreadyInType(type, lenParams); - assert(!type.isa() && "cannot be a reference"); + assert(!mlir::isa(type) && "cannot be a reference"); return create(loc, type, /*unique_name=*/llvm::StringRef{}, name, dynamicLength, dynamicShape, attrs); } @@ -315,8 +315,9 @@ // imaginary part is zero auto eleTy = helper.getComplexPartType(toTy); auto cast = createConvert(loc, eleTy, val); - llvm::APFloat zero{ - kindMap.getFloatSemantics(toTy.cast().getFKind()), 0}; + llvm::APFloat zero{kindMap.getFloatSemantics( + mlir::cast(toTy).getFKind()), + 0}; auto imag = createRealConstant(loc, eleTy, zero); return helper.createComplex(toTy, cast, imag); } @@ -327,14 +328,14 @@ return createConvert(loc, toTy, rp); } if (allowCharacterConversion) { - if (fromTy.isa()) { + if (mlir::isa(fromTy)) { // 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 = toTy.dyn_cast()) { + if (auto boxType = mlir::dyn_cast(toTy)) { // 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 @@ -354,10 +355,10 @@ "element types expected to match")); return create(loc, toTy, val); } - if (fir::isa_ref_type(fromTy) && toTy.isa()) { + if (fir::isa_ref_type(fromTy) && mlir::isa(toTy)) { // 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 = toTy.cast().getEleTy(); + mlir::Type procTy = mlir::cast(toTy).getEleTy(); mlir::Value proc = createConvert(loc, procTy, val); return create(loc, toTy, proc); } @@ -365,7 +366,7 @@ if (((fir::isPolymorphicType(fromTy) && (fir::isAllocatableType(fromTy) || fir::isPointerType(fromTy)) && fir::isPolymorphicType(toTy)) || - (fir::isPolymorphicType(fromTy) && toTy.isa())) && + (fir::isPolymorphicType(fromTy) && mlir::isa(toTy))) && !(fir::isUnlimitedPolymorphicType(fromTy) && fir::isAssumedType(toTy))) return create(loc, toTy, val, mlir::Value{}, /*slice=*/mlir::Value{}); @@ -512,7 +513,7 @@ bool isPolymorphic, bool isAssumedType) { mlir::Value itemAddr = fir::getBase(exv); - if (itemAddr.getType().isa()) + if (mlir::isa(itemAddr.getType())) return itemAddr; auto elementType = fir::dyn_cast_ptrEleTy(itemAddr.getType()); if (!elementType) { @@ -523,7 +524,7 @@ mlir::Type boxTy; mlir::Value tdesc; // Avoid to wrap a box/class with box/class. - if (elementType.isa()) { + if (mlir::isa(elementType)) { boxTy = elementType; } else { boxTy = fir::BoxType::get(elementType); @@ -640,7 +641,7 @@ return create(loc, argTy); auto boxProc = - create(loc, argTy.cast().getType(0)); + create(loc, mlir::cast(argTy).getType(0)); mlir::Value charLen = create(loc, getCharacterLengthType()); return fir::factory::createCharacterProcedureTuple(*this, loc, argTy, boxProc, charLen); @@ -889,14 +890,14 @@ fir::FirOpBuilder &builder, mlir::Type valTy, mlir::Value boxVal) { - if (auto boxTy = valTy.dyn_cast()) { + if (auto boxTy = mlir::dyn_cast(valTy)) { auto eleTy = fir::unwrapAllRefAndSeqType(boxTy.getEleTy()); - if (auto recTy = eleTy.dyn_cast()) { + if (auto recTy = mlir::dyn_cast(eleTy)) { 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 = eleTy.dyn_cast()) { + } else if (auto charTy = mlir::dyn_cast(eleTy)) { if (charTy.hasDynamicLen()) { auto idxTy = builder.getIndexType(); auto eleSz = builder.create(loc, idxTy, boxVal); @@ -943,7 +944,7 @@ fir::factory::getTypeParams(mlir::Location loc, fir::FirOpBuilder &builder, fir::ArrayLoadOp load) { mlir::Type memTy = load.getMemref().getType(); - if (auto boxTy = memTy.dyn_cast()) + if (auto boxTy = mlir::dyn_cast(memTy)) return getFromBox(loc, builder, boxTy, load.getMemref()); return load.getTypeparams(); } @@ -970,7 +971,7 @@ mlir::Value fir::factory::locationToFilename(fir::FirOpBuilder &builder, mlir::Location loc) { - if (auto flc = loc.dyn_cast()) { + if (auto flc = mlir::dyn_cast(loc)) { // must be encoded as asciiz, C string auto fn = flc.getFilename().str() + '\0'; return fir::getBase(createStringLiteral(builder, loc, fn)); @@ -981,7 +982,7 @@ mlir::Value fir::factory::locationToLineNo(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Type type) { - if (auto flc = loc.dyn_cast()) + if (auto flc = mlir::dyn_cast(loc)) return builder.createIntegerConstant(loc, type, flc.getLine()); return builder.createIntegerConstant(loc, type, 0); } @@ -1041,10 +1042,10 @@ auto fieldTy = component.getType(); if (auto ty = fir::dyn_cast_ptrEleTy(fieldTy)) fieldTy = ty; - if (fieldTy.isa()) { + if (mlir::isa(fieldTy)) { llvm::SmallVector nonDeferredTypeParams; auto eleTy = fir::unwrapSequenceType(fir::dyn_cast_ptrOrBoxEleTy(fieldTy)); - if (auto charTy = eleTy.dyn_cast()) { + if (auto charTy = mlir::dyn_cast(eleTy)) { auto lenTy = builder.getCharacterLengthType(); if (charTy.hasConstantLen()) nonDeferredTypeParams.emplace_back( @@ -1053,7 +1054,7 @@ // on a PDT length parameter. There is no way to make a difference with // deferred length here yet. } - if (auto recTy = eleTy.dyn_cast()) + if (auto recTy = mlir::dyn_cast(eleTy)) if (recTy.getNumLenParams() > 0) TODO(loc, "allocatable and pointer components non deferred length " "parameters"); @@ -1062,7 +1063,7 @@ /*mutableProperties=*/{}); } llvm::SmallVector extents; - if (auto seqTy = fieldTy.dyn_cast()) { + if (auto seqTy = mlir::dyn_cast(fieldTy)) { fieldTy = seqTy.getEleTy(); auto idxTy = builder.getIndexType(); for (auto extent : seqTy.getShape()) { @@ -1071,7 +1072,7 @@ extents.emplace_back(builder.createIntegerConstant(loc, idxTy, extent)); } } - if (auto charTy = fieldTy.dyn_cast()) { + if (auto charTy = mlir::dyn_cast(fieldTy)) { auto cstLen = charTy.getLen(); if (cstLen == fir::CharacterType::unknownLen()) TODO(loc, "get character component length from length type parameters"); @@ -1081,7 +1082,7 @@ return fir::CharArrayBoxValue{component, len, extents}; return fir::CharBoxValue{component, len}; } - if (auto recordTy = fieldTy.dyn_cast()) + if (auto recordTy = mlir::dyn_cast(fieldTy)) if (recordTy.getNumLenParams() != 0) TODO(loc, "lower component ref that is a derived type with length parameter"); @@ -1142,14 +1143,14 @@ assert(lhs.rank() == 0 && rhs.rank() == 0 && "must be scalars"); auto type = fir::unwrapSequenceType( fir::unwrapPassByRefType(fir::getBase(lhs).getType())); - if (type.isa()) { + if (mlir::isa(type)) { 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 (type.isa()) { + } else if (mlir::isa(type)) { fir::factory::genRecordAssignment(builder, loc, lhs, rhs); } else { assert(!fir::hasDynamicSize(type)); @@ -1168,10 +1169,10 @@ const fir::ExtendedValue &lhs, const fir::ExtendedValue &rhs) { auto lbaseType = fir::unwrapPassByRefType(fir::getBase(lhs).getType()); - auto lhsType = lbaseType.dyn_cast(); + auto lhsType = mlir::dyn_cast(lbaseType); assert(lhsType && "lhs must be a scalar record type"); auto rbaseType = fir::unwrapPassByRefType(fir::getBase(rhs).getType()); - auto rhsType = rbaseType.dyn_cast(); + auto rhsType = mlir::dyn_cast(rbaseType); assert(rhsType && "rhs must be a scalar record type"); auto fieldIndexType = fir::FieldType::get(lhsType.getContext()); for (auto [lhsPair, rhsPair] : @@ -1190,7 +1191,7 @@ mlir::Value toCoor = builder.create( loc, fieldRefType, fir::getBase(lhs), field); std::optional outerLoop; - if (auto sequenceType = lFieldTy.dyn_cast()) { + if (auto sequenceType = mlir::dyn_cast(lFieldTy)) { // 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 @@ -1217,10 +1218,9 @@ fromCoor, indices); } if (auto fieldEleTy = fir::unwrapSequenceType(lFieldTy); - fieldEleTy.isa()) { - assert(fieldEleTy.cast() - .getEleTy() - .isa() && + mlir::isa(fieldEleTy)) { + assert(mlir::isa( + mlir::cast(fieldEleTy).getEleTy()) && "allocatable members require deep copy"); auto fromPointerValue = builder.create(loc, fromCoor); auto castTo = builder.createConvert(loc, fieldEleTy, fromPointerValue); @@ -1244,11 +1244,11 @@ 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 (fir::unwrapSequenceType(fieldType).isa()) + if (mlir::isa(fir::unwrapSequenceType(fieldType))) return false; // Allocatable components need deep copy. - if (auto boxType = fieldType.dyn_cast()) - if (boxType.getEleTy().isa()) + if (auto boxType = mlir::dyn_cast(fieldType)) + if (mlir::isa(boxType.getEleTy())) return false; } // Constant size components without user defined assignment and pointers can @@ -1267,9 +1267,10 @@ // 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 = fir::getBase(lhs).getType().isa() || - fir::getBase(rhs).getType().isa(); - auto recTy = baseTy.dyn_cast(); + bool hasBoxOperands = + mlir::isa(fir::getBase(lhs).getType()) || + mlir::isa(fir::getBase(rhs).getType()); + auto recTy = mlir::dyn_cast(baseTy); assert(recTy && "must be a record type"); if (hasBoxOperands || !recordTypeCanBeMemCopied(recTy)) { auto to = fir::getBase(builder.createBox(loc, lhs)); @@ -1317,7 +1318,7 @@ llvm::ArrayRef path, llvm::ArrayRef substring) { llvm::SmallVector typeParams(arrLoad.getTypeparams()); return genLenOfCharacter(builder, loc, - arrLoad.getType().cast(), + mlir::cast(arrLoad.getType()), arrLoad.getMemref(), typeParams, path, substring); } @@ -1345,7 +1346,7 @@ lower = builder.createConvert(loc, idxTy, substring.front()); auto eleTy = fir::applyPathToType(seqTy, path); if (!fir::hasDynamicSize(eleTy)) { - if (auto charTy = eleTy.dyn_cast()) { + if (auto charTy = mlir::dyn_cast(eleTy)) { // Use LEN from the type. return builder.createIntegerConstant(loc, idxTy, charTy.getLen()); } @@ -1354,9 +1355,9 @@ "application of path did not result in a !fir.char"); } if (fir::isa_box_type(memref.getType())) { - if (memref.getType().isa()) + if (mlir::isa(memref.getType())) return builder.create(loc, idxTy, memref); - if (memref.getType().isa()) + if (mlir::isa(memref.getType())) return CharacterExprHelper(builder, loc).readLengthFromBox(memref); fir::emitFatalError(loc, "memref has wrong type"); } @@ -1373,7 +1374,7 @@ mlir::Value fir::factory::createZeroValue(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Type type) { mlir::Type i1 = builder.getIntegerType(1); - if (type.isa() || type == i1) + if (mlir::isa(type) || type == i1) return builder.createConvert(loc, type, builder.createBool(loc, false)); if (fir::isa_integer(type)) return builder.createIntegerConstant(loc, type, 0); @@ -1423,7 +1424,7 @@ 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 = cst.getValue().dyn_cast()) + if (auto intAttr = mlir::dyn_cast(cst.getValue())) return intAttr.getInt() > 0 ? value : zero; mlir::Value valueIsGreater = builder.create( loc, mlir::arith::CmpIPredicate::sgt, value, zero); @@ -1435,8 +1436,8 @@ mlir::Location loc, mlir::Value cPtr, mlir::Type ty) { - assert(ty.isa()); - auto recTy = ty.dyn_cast(); + assert(mlir::isa(ty)); + auto recTy = mlir::dyn_cast(ty); assert(recTy.getTypeList().size() == 1); auto fieldName = recTy.getTypeList()[0].first; mlir::Type fieldTy = recTy.getTypeList()[0].second; diff --git a/flang/lib/Optimizer/Builder/HLFIRTools.cpp b/flang/lib/Optimizer/Builder/HLFIRTools.cpp --- a/flang/lib/Optimizer/Builder/HLFIRTools.cpp +++ b/flang/lib/Optimizer/Builder/HLFIRTools.cpp @@ -37,10 +37,10 @@ } else if (mlir::dyn_cast_or_null(shapeOp)) { return {}; } else if (auto s = mlir::dyn_cast_or_null(shapeOp)) { - hlfir::ExprType expr = s.getExpr().getType().cast(); + hlfir::ExprType expr = mlir::cast(s.getExpr().getType()); llvm::ArrayRef exprShape = expr.getShape(); mlir::Type indexTy = builder.getIndexType(); - fir::ShapeType shapeTy = shape.getType().cast(); + fir::ShapeType shapeTy = mlir::cast(shape.getType()); result.reserve(shapeTy.getRank()); for (unsigned i = 0; i < shapeTy.getRank(); ++i) { int64_t extent = exprShape[i]; @@ -98,7 +98,7 @@ hlfir::Entity boxEntity, llvm::SmallVectorImpl &lbounds, llvm::SmallVectorImpl *extents) { - assert(boxEntity.getType().isa() && "must be a box"); + assert(mlir::isa(boxEntity.getType()) && "must be a box"); mlir::Type idxTy = builder.getIndexType(); const int rank = boxEntity.getRank(); for (int i = 0; i < rank; ++i) { @@ -153,7 +153,7 @@ hlfir::Entity var) { if (mlir::Value len = tryGettingNonDeferredCharLen(var)) return len; - auto charType = var.getFortranElementType().cast(); + auto charType = mlir::cast(var.getFortranElementType()); if (charType.hasConstantLen()) return builder.createIntegerConstant(loc, builder.getIndexType(), charType.getLen()); @@ -171,7 +171,7 @@ if (auto emboxChar = boxChar.getDefiningOp()) return {emboxChar.getMemref(), emboxChar.getLen()}; mlir::Type refType = fir::ReferenceType::get( - boxChar.getType().cast().getEleTy()); + mlir::cast(boxChar.getType()).getEleTy()); auto unboxed = builder.create( loc, refType, builder.getIndexType(), boxChar); mlir::Value addr = unboxed.getResult(0); @@ -250,8 +250,8 @@ // and the other static). mlir::Type varEleTy = getFortranElementType(variableType); mlir::Type valueEleTy = getFortranElementType(value.getType()); - if (varEleTy != valueEleTy && !(valueEleTy.isa() && - varEleTy.isa())) { + if (varEleTy != valueEleTy && !(mlir::isa(valueEleTy) && + mlir::isa(varEleTy))) { assert(value.isScalar() && fir::isa_trivial(value.getType())); source = builder.createConvert(loc, fir::unwrapPassByRefType(variableType), value); @@ -270,9 +270,9 @@ if (var.isMutableBox()) baseAddr = builder.create(loc, baseAddr); // Get raw address. - if (var.getType().isa()) + if (mlir::isa(var.getType())) baseAddr = genUnboxChar(loc, builder, var.getBase()).getAddr(); - if (baseAddr.getType().isa()) + if (mlir::isa(baseAddr.getType())) baseAddr = builder.create(loc, baseAddr); return baseAddr; } @@ -281,13 +281,13 @@ fir::FirOpBuilder &builder, hlfir::Entity var) { assert(var.isVariable() && "only address of variables can be taken"); - if (var.getType().isa()) + if (mlir::isa(var.getType())) return var; mlir::Value addr = genVariableRawAddress(loc, builder, var); llvm::SmallVector lengths; genLengthParameters(loc, builder, var, lengths); assert(lengths.size() == 1); - auto charType = var.getFortranElementType().cast(); + auto charType = mlir::cast(var.getFortranElementType()); auto boxCharType = fir::BoxCharType::get(builder.getContext(), charType.getFKind()); auto scalarAddr = @@ -301,7 +301,7 @@ hlfir::Entity var) { assert(var.isVariable() && "must be a variable"); var = hlfir::derefPointersAndAllocatables(loc, builder, var); - if (var.getType().isa()) + if (mlir::isa(var.getType())) 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. @@ -309,11 +309,11 @@ var.isArray() ? hlfir::genShape(loc, builder, var) : mlir::Value{}; llvm::SmallVector typeParams; auto maybeCharType = - var.getFortranElementType().dyn_cast(); + mlir::dyn_cast(var.getFortranElementType()); if (!maybeCharType || maybeCharType.hasDynamicLen()) hlfir::genLengthParameters(loc, builder, var, typeParams); mlir::Value addr = var.getBase(); - if (var.getType().isa()) + if (mlir::isa(var.getType())) addr = genVariableRawAddress(loc, builder, var); mlir::Type boxType = fir::BoxType::get(var.getElementOrSequenceType()); auto embox = @@ -340,7 +340,7 @@ return entity; llvm::SmallVector lenParams; genLengthParameters(loc, builder, entity, lenParams); - if (entity.getType().isa()) + if (mlir::isa(entity.getType())) return hlfir::Entity{builder.create( loc, entity, oneBasedIndices, lenParams)}; // Build hlfir.designate. The lower bounds may need to be added to @@ -386,7 +386,7 @@ llvm::SmallVector> hlfir::genBounds(mlir::Location loc, fir::FirOpBuilder &builder, Entity entity) { - if (entity.getType().isa()) + if (mlir::isa(entity.getType())) TODO(loc, "bounds of expressions in hlfir"); auto [exv, cleanup] = translateToExtendedValue(loc, builder, entity); assert(!cleanup && "translation of entity should not yield cleanup"); @@ -407,8 +407,8 @@ llvm::SmallVector> hlfir::genBounds(mlir::Location loc, fir::FirOpBuilder &builder, mlir::Value shape) { - assert((shape.getType().isa() || - shape.getType().isa()) && + assert((mlir::isa(shape.getType()) || + mlir::isa(shape.getType())) && "shape must contain extents"); auto extents = hlfir::getExplicitExtentsFromShape(shape, builder); auto lowers = getExplicitLboundsFromShape(shape); @@ -466,7 +466,7 @@ if (typeExtent != fir::SequenceType::getUnknownExtent()) return builder.createIntegerConstant(loc, idxTy, typeExtent); } - assert(variable.getType().isa() && + assert(mlir::isa(variable.getType()) && "array variable with dynamic extent must be boxed"); mlir::Value dimVal = builder.createIntegerConstant(loc, idxTy, dim); auto dimInfo = builder.create(loc, idxTy, idxTy, idxTy, @@ -488,9 +488,8 @@ 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 = - hlfir::getFortranElementOrSequenceType(variable.getType()) - .cast(); + fir::SequenceType seqTy = mlir::cast( + hlfir::getFortranElementOrSequenceType(variable.getType())); unsigned rank = seqTy.getShape().size(); for (unsigned dim = 0; dim < rank; ++dim) extents.push_back( @@ -499,7 +498,7 @@ } static mlir::Value tryRetrievingShapeOrShift(hlfir::Entity entity) { - if (entity.getType().isa()) { + if (mlir::isa(entity.getType())) { if (auto elemental = entity.getDefiningOp()) return elemental.getShape(); return mlir::Value{}; @@ -515,13 +514,13 @@ entity = followShapeInducingSource(entity); assert(entity && "what?"); if (auto shape = tryRetrievingShapeOrShift(entity)) { - if (shape.getType().isa()) + if (mlir::isa(shape.getType())) return shape; - if (shape.getType().isa()) + if (mlir::isa(shape.getType())) if (auto s = shape.getDefiningOp()) return builder.create(loc, s.getExtents()); } - if (entity.getType().isa()) + if (mlir::isa(entity.getType())) return builder.create(loc, entity.getBase()); // There is no shape lying around for this entity. Retrieve the extents and // build a new fir.shape. @@ -555,9 +554,8 @@ 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 = - hlfir::getFortranElementOrSequenceType(entity.getType()) - .cast(); + fir::SequenceType seqTy = mlir::cast( + hlfir::getFortranElementOrSequenceType(entity.getType())); return computeVariableExtent(loc, builder, entity, seqTy, dim); } TODO(loc, "get extent from HLFIR expr without producer holding the shape"); @@ -576,7 +574,7 @@ } if (entity.isMutableBox()) entity = hlfir::derefPointersAndAllocatables(loc, builder, entity); - assert(entity.getType().isa() && "must be a box"); + assert(mlir::isa(entity.getType()) && "must be a box"); mlir::Type idxTy = builder.getIndexType(); mlir::Value dimVal = builder.createIntegerConstant(loc, idxTy, dim); auto dimInfo = @@ -589,7 +587,7 @@ llvm::SmallVectorImpl &result) { if (!entity.hasLengthParameters()) return; - if (entity.getType().isa()) { + if (mlir::isa(entity.getType())) { mlir::Value expr = entity; if (auto reassoc = expr.getDefiningOp()) expr = reassoc.getVal(); @@ -641,8 +639,8 @@ // 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 (fir::getBase(exv).getType().isa() && - !shape.getType().isa()) + if (mlir::isa(fir::getBase(exv).getType()) && + !mlir::isa(shape.getType())) return builder.createShape(loc, exv); return shape; } @@ -673,7 +671,7 @@ if (!entity.isPolymorphic() && !entity.hasLengthParameters()) return hlfir::Entity{builder.create(loc, boxLoad)}; mlir::Type elementType = boxLoad.getFortranElementType(); - if (auto charType = elementType.dyn_cast()) { + if (auto charType = mlir::dyn_cast(elementType)) { mlir::Value base = builder.create(loc, boxLoad); if (charType.hasConstantLen()) return hlfir::Entity{base}; @@ -701,7 +699,7 @@ mlir::Type eleTy = variable.getFortranElementType(); if (variable.isPolymorphic()) return fir::ClassType::get(eleTy); - if (auto charType = eleTy.dyn_cast()) { + if (auto charType = mlir::dyn_cast(eleTy)) { if (charType.hasDynamicLen()) return fir::BoxCharType::get(charType.getContext(), charType.getFKind()); } else if (fir::isRecordWithTypeParameters(eleTy)) { @@ -712,7 +710,7 @@ static hlfir::ExprType getArrayExprType(mlir::Type elementType, mlir::Value shape, bool isPolymorphic) { - unsigned rank = shape.getType().cast().getRank(); + unsigned rank = mlir::cast(shape.getType()).getRank(); hlfir::ExprType::Shape typeShape(rank, hlfir::ExprType::getUnknownExtent()); if (auto shapeOp = shape.getDefiningOp()) for (auto extent : llvm::enumerate(shapeOp.getExtents())) @@ -833,7 +831,7 @@ return fir::MutableBoxValue(firBase, getExplicitTypeParams(variable), fir::MutableProperties{}); - if (firBase.getType().isa()) { + if (mlir::isa(firBase.getType())) { if (!variable.isSimplyContiguous() || variable.isPolymorphic() || variable.isDerivedWithLengthParameters() || variable.isOptional()) { llvm::SmallVector nonDefaultLbounds = @@ -848,7 +846,7 @@ if (variable.isScalar()) { if (variable.isCharacter()) { - if (firBase.getType().isa()) + if (mlir::isa(firBase.getType())) return genUnboxChar(loc, builder, firBase); mlir::Value len = genCharacterVariableLength(loc, builder, variable); return fir::CharBoxValue{firBase, len}; @@ -857,7 +855,7 @@ } llvm::SmallVector extents; llvm::SmallVector nonDefaultLbounds; - if (variable.getType().isa() && + if (mlir::isa(variable.getType()) && !variable.getIfVariableInterface()) { // This special case avoids generating two generating to sets of identical // fir.box_dim to get both the lower bounds and extents. @@ -896,7 +894,7 @@ return {static_cast(entity), std::nullopt}; } - if (entity.getType().isa()) { + if (mlir::isa(entity.getType())) { hlfir::AssociateOp associate = hlfir::genAssociateExpr( loc, builder, entity, entity.getType(), "adapt.valuebyref"); auto *bldr = &builder; diff --git a/flang/lib/Optimizer/Builder/IntrinsicCall.cpp b/flang/lib/Optimizer/Builder/IntrinsicCall.cpp --- a/flang/lib/Optimizer/Builder/IntrinsicCall.cpp +++ b/flang/lib/Optimizer/Builder/IntrinsicCall.cpp @@ -1191,7 +1191,7 @@ auto getSplitComplexArgsType = [&builder, &args]() -> mlir::FunctionType { mlir::Type ctype = args[0].getType(); - auto fKind = ctype.cast().getFKind(); + auto fKind = mlir::cast(ctype).getFKind(); mlir::Type ftype; if (fKind == 2) @@ -1291,8 +1291,8 @@ LLVM_DEBUG(llvm::dbgs() << "Generating '" << mathLibFuncName << "' operation with type "; mathLibFuncType.dump(); llvm::dbgs() << "\n"); - auto type = mathLibFuncType.getInput(0).cast(); - auto kind = type.getElementType().cast().getFKind(); + auto type = mlir::cast(mathLibFuncType.getInput(0)); + auto kind = mlir::cast(type.getElementType()).getFKind(); auto realTy = builder.getRealType(kind); auto mComplexTy = mlir::ComplexType::get(realTy); @@ -1616,14 +1616,14 @@ // Floating point can be mlir::FloatType or fir::real static unsigned getFloatingPointWidth(mlir::Type t) { - if (auto f{t.dyn_cast()}) + if (auto f{mlir::dyn_cast(t)}) 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{t.dyn_cast()}) + if (auto r{mlir::dyn_cast(t)}) return r.getFKind() * 4; - if (auto cplx{t.dyn_cast()}) + if (auto cplx{mlir::dyn_cast(t)}) return cplx.getFKind() * 4; llvm_unreachable("not a floating-point type"); } @@ -1632,8 +1632,8 @@ if (from == to) return Conversion::None; - if (auto fromIntTy{from.dyn_cast()}) { - if (auto toIntTy{to.dyn_cast()}) { + if (auto fromIntTy{mlir::dyn_cast(from)}) { + if (auto toIntTy{mlir::dyn_cast(to)}) { return fromIntTy.getWidth() > toIntTy.getWidth() ? Conversion::Narrow : Conversion::Extend; } @@ -1645,8 +1645,8 @@ : Conversion::Extend; } - if (auto fromCplxTy{from.dyn_cast()}) { - if (auto toCplxTy{to.dyn_cast()}) { + if (auto fromCplxTy{mlir::dyn_cast(from)}) { + if (auto toCplxTy{mlir::dyn_cast(to)}) { return getFloatingPointWidth(fromCplxTy) > getFloatingPointWidth(toCplxTy) ? Conversion::Narrow @@ -1786,10 +1786,10 @@ if (charHelper.isCharacterScalar(type)) return charHelper.toExtendedValue(val); - if (auto refType = type.dyn_cast()) + if (auto refType = mlir::dyn_cast(type)) type = refType.getEleTy(); - if (auto arrayType = type.dyn_cast()) { + if (auto arrayType = mlir::dyn_cast(type)) { type = arrayType.getEleTy(); for (fir::SequenceType::Extent extent : arrayType.getShape()) { if (extent == fir::SequenceType::getUnknownExtent()) @@ -1802,7 +1802,8 @@ // have been used in the interface). if (extents.size() + 1 < arrayType.getShape().size()) mlir::emitError(loc, "cannot retrieve array extents from type"); - } else if (type.isa() || type.isa()) { + } else if (mlir::isa(type) || + mlir::isa(type)) { fir::emitFatalError(loc, "not yet implemented: descriptor or derived type"); } @@ -1816,10 +1817,10 @@ if (const fir::CharBoxValue *charBox = val.getCharBox()) { mlir::Value buffer = charBox->getBuffer(); auto buffTy = buffer.getType(); - if (buffTy.isa()) + if (mlir::isa(buffTy)) fir::emitFatalError( loc, "A character's buffer type cannot be a function type."); - if (buffTy.isa()) + if (mlir::isa(buffTy)) return buffer; return fir::factory::CharacterExprHelper{builder, loc}.createEmboxChar( buffer, charBox->getLen()); @@ -2055,27 +2056,27 @@ /// 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{t.dyn_cast()}) + if (auto refT{mlir::dyn_cast(t)}) return "ref_" + typeToString(refT.getEleTy()); - if (auto i{t.dyn_cast()}) { + if (auto i{mlir::dyn_cast(t)}) { return "i" + std::to_string(i.getWidth()); } - if (auto cplx{t.dyn_cast()}) { + if (auto cplx{mlir::dyn_cast(t)}) { return "z" + std::to_string(cplx.getFKind()); } - if (auto real{t.dyn_cast()}) { + if (auto real{mlir::dyn_cast(t)}) { return "r" + std::to_string(real.getFKind()); } - if (auto f{t.dyn_cast()}) { + if (auto f{mlir::dyn_cast(t)}) { return "f" + std::to_string(f.getWidth()); } - if (auto logical{t.dyn_cast()}) { + if (auto logical{mlir::dyn_cast(t)}) { return "l" + std::to_string(logical.getFKind()); } - if (auto character{t.dyn_cast()}) { + if (auto character{mlir::dyn_cast(t)}) { return "c" + std::to_string(character.getFKind()); } - if (auto boxCharacter{t.dyn_cast()}) { + if (auto boxCharacter{mlir::dyn_cast(t)}) { return "bc" + std::to_string(boxCharacter.getEleTy().getFKind()); } llvm_unreachable("no mangling for type"); @@ -2137,7 +2138,7 @@ mlir::Location localLoc = localBuilder->getUnknownLoc(); llvm::SmallVector localArguments; for (mlir::BlockArgument bArg : function.front().getArguments()) { - auto refType = bArg.getType().dyn_cast(); + auto refType = mlir::dyn_cast(bArg.getType()); if (loadRefArguments && refType) { auto loaded = localBuilder->create(localLoc, bArg); localArguments.push_back(loaded); @@ -2284,7 +2285,7 @@ if (!funcOp) { llvm::SmallVector argTypes; for (mlir::Type type : signature.getInputs()) { - if (auto refType = type.dyn_cast()) + if (auto refType = mlir::dyn_cast(type)) argTypes.push_back(refType.getEleTy()); else argTypes.push_back(type); @@ -2369,7 +2370,7 @@ // math::AbsFOp but it does not support all fir floating point types. return genRuntimeCall("abs", resultType, args); } - if (auto intType = type.dyn_cast()) { + if (auto intType = mlir::dyn_cast(type)) { // At the time of this implementation there is no abs op in mlir. // So, implement abs here without branching. mlir::Value shift = @@ -2776,7 +2777,7 @@ mlir::Value argValue = fir::getBase(arg); mlir::Value addr{nullptr}; if (isFunc) { - auto funcTy = argValue.getType().cast().getEleTy(); + auto funcTy = mlir::cast(argValue.getType()).getEleTy(); addr = builder.create(loc, funcTy, argValue); } else { const auto *box = arg.getBoxOf(); @@ -3108,7 +3109,7 @@ mlir::Value IntrinsicLibrary::genDim(mlir::Type resultType, llvm::ArrayRef args) { assert(args.size() == 2); - if (resultType.isa()) { + if (mlir::isa(resultType)) { mlir::Value zero = builder.createIntegerConstant(loc, resultType, 0); auto diff = builder.create(loc, args[0], args[1]); auto cmp = builder.create( @@ -3588,7 +3589,7 @@ if (absentDim || rank == 1) { mlir::Type ty = array.getType(); mlir::Type arrTy = fir::dyn_cast_ptrOrBoxEleTy(ty); - auto eleTy = arrTy.cast().getEleTy(); + auto eleTy = mlir::cast(arrTy).getEleTy(); if (fir::isa_complex(eleTy)) { mlir::Value result = builder.createTemporary(loc, eleTy); func(builder, loc, array, mask, result); @@ -3660,7 +3661,7 @@ 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, resultType.cast().getWidth()); + loc, resultType, mlir::cast(resultType).getWidth()); auto shiftCount = builder.create(loc, bitSize, len); mlir::Value zero = builder.createIntegerConstant(loc, resultType, 0); mlir::Value ones = builder.createIntegerConstant(loc, resultType, -1); @@ -3700,7 +3701,7 @@ mlir::Value buffer = charBox->getBuffer(); mlir::Type bufferTy = buffer.getType(); mlir::Value charVal; - if (auto charTy = bufferTy.dyn_cast()) { + if (auto charTy = mlir::dyn_cast(bufferTy)) { assert(charTy.singleton()); charVal = buffer; } else { @@ -3734,7 +3735,7 @@ mlir::Value arg0 = fir::getBase(args[0]); mlir::Value arg1 = fir::getBase(args[1]); auto recType = - fir::unwrapPassByRefType(arg0.getType()).dyn_cast(); + mlir::dyn_cast(fir::unwrapPassByRefType(arg0.getType())); assert(recType.getTypeList().size() == 1 && "expected exactly one component"); auto [fieldName, fieldType] = recType.getTypeList().front(); mlir::Type fieldIndexType = fir::FieldType::get(recType.getContext()); @@ -3758,16 +3759,17 @@ // IEEE_IS_FINITE(X) is true iff exponent(X) is the max exponent of kind(X). assert(args.size() == 1); mlir::Value floatVal = fir::getBase(args[0]); - mlir::FloatType floatType = floatVal.getType().dyn_cast(); + mlir::FloatType floatType = + mlir::dyn_cast(floatVal.getType()); int floatBits = floatType.getWidth(); mlir::Type intType = builder.getIntegerType( - floatType.isa() ? 128 : floatBits); + mlir::isa(floatType) ? 128 : floatBits); mlir::Value intVal = builder.create(loc, intType, floatVal); int significandBits; - if (floatType.isa()) + if (mlir::isa(floatType)) significandBits = 23; - else if (floatType.isa()) + else if (mlir::isa(floatType)) significandBits = 52; else // problems elsewhere for other kinds TODO(loc, "intrinsic module procedure: ieee_is_finite"); @@ -3925,7 +3927,7 @@ // : I << abs(SHIFT) assert(args.size() == 2); mlir::Value bitSize = builder.createIntegerConstant( - loc, resultType, resultType.cast().getWidth()); + loc, resultType, mlir::cast(resultType).getWidth()); mlir::Value zero = builder.createIntegerConstant(loc, resultType, 0); mlir::Value shift = builder.createConvert(loc, resultType, args[1]); mlir::Value absShift = genAbs(resultType, {shift}); @@ -3961,7 +3963,7 @@ // Return: SHIFT == 0 || SIZE == abs(SHIFT) ? I : (unchanged | left | right) assert(args.size() == 3); mlir::Value bitSize = builder.createIntegerConstant( - loc, resultType, resultType.cast().getWidth()); + loc, resultType, mlir::cast(resultType).getWidth()); mlir::Value I = args[0]; mlir::Value shift = builder.createConvert(loc, resultType, args[1]); mlir::Value size = @@ -4062,7 +4064,7 @@ mlir::Value argValue = fir::getBase(args[0]); assert(fir::isa_box_type(argValue.getType()) && "argument must have been lowered to box type"); - bool isFunc = argValue.getType().isa(); + bool isFunc = mlir::isa(argValue.getType()); mlir::Value argAddr = getAddrFromBox(builder, loc, args[0], isFunc); return builder.createConvert(loc, fir::unwrapRefType(resultType), argAddr); } @@ -4220,7 +4222,7 @@ mlir::Value IntrinsicLibrary::genMod(mlir::Type resultType, llvm::ArrayRef args) { assert(args.size() == 2); - if (resultType.isa()) + if (mlir::isa(resultType)) return builder.create(loc, args[0], args[1]); // Use runtime. @@ -4240,7 +4242,7 @@ // - 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 (resultType.isa()) { + if (mlir::isa(resultType)) { auto remainder = builder.create(loc, args[0], args[1]); auto argXor = builder.create(loc, args[0], args[1]); @@ -4346,7 +4348,7 @@ mlir::Value zero = builder.createIntegerConstant(loc, resultType, 0); mlir::Value ones = builder.createIntegerConstant(loc, resultType, -1); mlir::Value bitSize = builder.createIntegerConstant( - loc, resultType, resultType.cast().getWidth()); + loc, resultType, mlir::cast(resultType).getWidth()); auto shiftCount = builder.create(loc, bitSize, len); auto mask = builder.create(loc, ones, shiftCount); auto unchangedTmp1 = builder.create(loc, mask, topos); @@ -4621,7 +4623,7 @@ assert(fir::BoxValue(shape).rank() == 1); mlir::Type shapeTy = shape.getType(); mlir::Type shapeArrTy = fir::dyn_cast_ptrOrBoxEleTy(shapeTy); - auto resultRank = shapeArrTy.cast().getShape()[0]; + auto resultRank = mlir::cast(shapeArrTy).getShape()[0]; if (resultRank == fir::SequenceType::getUnknownExtent()) TODO(loc, "intrinsic: reshape requires computing rank of result"); @@ -4873,7 +4875,7 @@ mlir::Value IntrinsicLibrary::genSign(mlir::Type resultType, llvm::ArrayRef args) { assert(args.size() == 2); - if (resultType.isa()) { + if (mlir::isa(resultType)) { mlir::Value abs = genAbs(resultType, {args[0]}); mlir::Value zero = builder.createIntegerConstant(loc, resultType, 0); auto neg = builder.create(loc, zero, abs); @@ -5204,7 +5206,7 @@ if (args[0].getBoxOf()) { box = builder.createBox(loc, args[0], /*isPolymorphic=*/true); - } else if (box.getType().isa()) { + } else if (mlir::isa(box.getType())) { box = builder.create(loc, box); } mlir::Value eleSize = builder.create(loc, kindTy, box); diff --git a/flang/lib/Optimizer/Builder/MutableBox.cpp b/flang/lib/Optimizer/Builder/MutableBox.cpp --- a/flang/lib/Optimizer/Builder/MutableBox.cpp +++ b/flang/lib/Optimizer/Builder/MutableBox.cpp @@ -28,7 +28,7 @@ const fir::MutableBoxValue &box, mlir::Value addr, mlir::ValueRange lbounds, mlir::ValueRange extents, mlir::ValueRange lengths, mlir::Value tdesc = {}) { - if (addr.getType().isa()) + if (mlir::isa(addr.getType())) // The entity is already boxed. return builder.createConvert(loc, box.getBoxTy(), addr); @@ -53,20 +53,21 @@ // error in the embox). llvm::SmallVector cleanedLengths; auto cleanedAddr = addr; - if (auto charTy = box.getEleTy().dyn_cast()) { + if (auto charTy = mlir::dyn_cast(box.getEleTy())) { // 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 = addrTy.isa() ? fir::HeapType::get(bt) - : addrTy.isa() ? fir::PointerType::get(bt) - : builder.getRefType(bt); + auto type = mlir::isa(addrTy) ? fir::HeapType::get(bt) + : mlir::isa(addrTy) + ? 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 = fir::dyn_cast_ptrEleTy(addr.getType()) - .dyn_cast()) { + if (auto charTy = mlir::dyn_cast( + fir::dyn_cast_ptrEleTy(addr.getType()))) { if (charTy.getLen() == fir::CharacterType::unknownLen()) cleanedLengths.append(lengths.begin(), lengths.end()); } @@ -328,18 +329,18 @@ mlir::Value fir::factory::createUnallocatedBox( fir::FirOpBuilder &builder, mlir::Location loc, mlir::Type boxType, mlir::ValueRange nonDeferredParams, mlir::Value typeSourceBox) { - auto baseAddrType = boxType.dyn_cast().getEleTy(); + auto baseAddrType = mlir::dyn_cast(boxType).getEleTy(); if (!fir::isa_ref_type(baseAddrType)) baseAddrType = builder.getRefType(baseAddrType); auto type = fir::unwrapRefType(baseAddrType); auto eleTy = fir::unwrapSequenceType(type); - if (auto recTy = eleTy.dyn_cast()) + if (auto recTy = mlir::dyn_cast(eleTy)) 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 = type.dyn_cast()) { + if (auto seqTy = mlir::dyn_cast(type)) { auto zero = builder.createIntegerConstant(loc, builder.getIndexType(), 0); llvm::SmallVector extents(seqTy.getDimension(), zero); shape = builder.createShape( @@ -348,7 +349,7 @@ // 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 = eleTy.dyn_cast()) { + if (auto charTy = mlir::dyn_cast(eleTy)) { if (charTy.getLen() == fir::CharacterType::unknownLen()) { if (!nonDeferredParams.empty()) { lenParams.push_back(nonDeferredParams[0]); @@ -590,7 +591,7 @@ 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 = ty.dyn_cast()) { + if (auto seqTy = mlir::dyn_cast(ty)) { fir::SequenceType::Shape shape(newRank, fir::SequenceType::getUnknownExtent()); ty = fir::SequenceType::get(shape, seqTy.getEleTy()); @@ -671,10 +672,10 @@ 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 = box.getBoxTy().dyn_cast(); + auto boxTy = mlir::dyn_cast(box.getBoxTy()); auto eleTy = fir::dyn_cast_ptrOrBoxEleTy(boxTy.getEleTy()); mlir::Type derivedType = fir::getDerivedType(eleTy); - if (auto recTy = derivedType.dyn_cast()) { + if (auto recTy = mlir::dyn_cast(derivedType)) { fir::runtime::genNullifyDerivedType(builder, loc, box.getAddr(), recTy, box.rank()); return; @@ -688,7 +689,7 @@ const fir::MutableBoxValue &box, mlir::ValueRange lenParams) { llvm::SmallVector lengths; auto idxTy = builder.getIndexType(); - if (auto charTy = box.getEleTy().dyn_cast()) { + if (auto charTy = mlir::dyn_cast(box.getEleTy())) { if (charTy.getLen() == fir::CharacterType::unknownLen()) { if (box.hasNonDeferredLenParams()) { lengths.emplace_back( @@ -715,7 +716,7 @@ auto lengths = getNewLengths(builder, loc, box, lenParams); auto newStorage = builder.create( loc, box.getBaseTy(), allocName, lengths, extents); - if (box.getEleTy().isa()) { + if (mlir::isa(box.getEleTy())) { // 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 @@ -740,7 +741,7 @@ lengths, safeExtents); MutablePropertyWriter{builder, loc, box}.updateMutableBox( heap, lbounds, safeExtents, lengths); - if (box.getEleTy().isa()) { + if (mlir::isa(box.getEleTy())) { // 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/Runtime/Allocatable.cpp b/flang/lib/Optimizer/Builder/Runtime/Allocatable.cpp --- a/flang/lib/Optimizer/Builder/Runtime/Allocatable.cpp +++ b/flang/lib/Optimizer/Builder/Runtime/Allocatable.cpp @@ -27,7 +27,7 @@ if (fir::isPolymorphicType(from.getType()) && !fir::isUnlimitedPolymorphicType(from.getType())) { fir::ClassType clTy = - fir::dyn_cast_ptrEleTy(from.getType()).dyn_cast(); + mlir::dyn_cast(fir::dyn_cast_ptrEleTy(from.getType())); 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 --- a/flang/lib/Optimizer/Builder/Runtime/Character.cpp +++ b/flang/lib/Optimizer/Builder/Runtime/Character.cpp @@ -39,15 +39,15 @@ /// Helper function to recover the KIND from the FIR type. static int discoverKind(mlir::Type ty) { - if (auto charTy = ty.dyn_cast()) + if (auto charTy = mlir::dyn_cast(ty)) return charTy.getFKind(); if (auto eleTy = fir::dyn_cast_ptrEleTy(ty)) return discoverKind(eleTy); - if (auto arrTy = ty.dyn_cast()) + if (auto arrTy = mlir::dyn_cast(ty)) return discoverKind(arrTy.getEleTy()); - if (auto boxTy = ty.dyn_cast()) + if (auto boxTy = mlir::dyn_cast(ty)) return discoverKind(boxTy.getEleTy()); - if (auto boxTy = ty.dyn_cast()) + if (auto boxTy = mlir::dyn_cast(ty)) 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 --- a/flang/lib/Optimizer/Builder/Runtime/Intrinsics.cpp +++ b/flang/lib/Optimizer/Builder/Runtime/Intrinsics.cpp @@ -202,7 +202,8 @@ fir::IfOp ifOp{}; const bool isOptionalArg = fir::valueHasFirAttribute(arg, fir::getOptionalAttrName()); - if (type.dyn_cast() || type.dyn_cast()) { + if (mlir::dyn_cast(type) || + mlir::dyn_cast(type)) { // Check for a disassociated pointer or an unallocated allocatable. assert(!isOptionalArg && "invalid optional argument"); ifOp = builder.create(loc, builder.genIsNotNullAddr(loc, arg), @@ -216,7 +217,8 @@ builder.setInsertionPointToStart(&ifOp.getThenRegion().front()); mlir::Type kindTy = func.getFunctionType().getInput(0); int integerKind = 8; - if (auto intType = fir::unwrapRefType(type).dyn_cast()) + if (auto intType = + mlir::dyn_cast(fir::unwrapRefType(type))) 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 --- a/flang/lib/Optimizer/Builder/Runtime/Ragged.cpp +++ b/flang/lib/Optimizer/Builder/Runtime/Ragged.cpp @@ -32,7 +32,8 @@ // 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(eleTy.cast().getType(1)); + auto ptrTy = + builder.getRefType(mlir::cast(eleTy).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 --- a/flang/lib/Optimizer/Builder/Runtime/Reduction.cpp +++ b/flang/lib/Optimizer/Builder/Runtime/Reduction.cpp @@ -650,7 +650,7 @@ mlir::func::FuncOp func; auto ty = arrayBox.getType(); auto arrTy = fir::dyn_cast_ptrOrBoxEleTy(ty); - auto eleTy = arrTy.cast().getEleTy(); + auto eleTy = mlir::cast(arrTy).getEleTy(); fir::factory::CharacterExprHelper charHelper{builder, loc}; if (eleTy.isF16() || eleTy.isBF16()) TODO(loc, "half-precision MAXLOC"); @@ -699,7 +699,7 @@ mlir::func::FuncOp func; auto ty = arrayBox.getType(); auto arrTy = fir::dyn_cast_ptrOrBoxEleTy(ty); - auto eleTy = arrTy.cast().getEleTy(); + auto eleTy = mlir::cast(arrTy).getEleTy(); auto dim = builder.createIntegerConstant(loc, builder.getIndexType(), 0); if (eleTy.isF16() || eleTy.isBF16()) @@ -769,7 +769,7 @@ mlir::func::FuncOp func; auto ty = arrayBox.getType(); auto arrTy = fir::dyn_cast_ptrOrBoxEleTy(ty); - auto eleTy = arrTy.cast().getEleTy(); + auto eleTy = mlir::cast(arrTy).getEleTy(); fir::factory::CharacterExprHelper charHelper{builder, loc}; if (eleTy.isF16() || eleTy.isBF16()) TODO(loc, "half-precision MINLOC"); @@ -843,7 +843,7 @@ mlir::func::FuncOp func; auto ty = arrayBox.getType(); auto arrTy = fir::dyn_cast_ptrOrBoxEleTy(ty); - auto eleTy = arrTy.cast().getEleTy(); + auto eleTy = mlir::cast(arrTy).getEleTy(); auto dim = builder.createIntegerConstant(loc, builder.getIndexType(), 0); if (eleTy.isF16() || eleTy.isBF16()) @@ -902,7 +902,7 @@ mlir::func::FuncOp func; auto ty = arrayBox.getType(); auto arrTy = fir::dyn_cast_ptrOrBoxEleTy(ty); - auto eleTy = arrTy.cast().getEleTy(); + auto eleTy = mlir::cast(arrTy).getEleTy(); auto dim = builder.createIntegerConstant(loc, builder.getIndexType(), 0); if (eleTy.isF16() || eleTy.isBF16()) @@ -955,7 +955,7 @@ mlir::func::FuncOp func; auto ty = arrayBox.getType(); auto arrTy = fir::dyn_cast_ptrOrBoxEleTy(ty); - auto eleTy = arrTy.cast().getEleTy(); + auto eleTy = mlir::cast(arrTy).getEleTy(); auto dim = builder.createIntegerConstant(loc, builder.getIndexType(), 0); if (eleTy.isF16() || eleTy.isBF16()) @@ -1066,7 +1066,7 @@ else if (eleTy.isInteger(builder.getKindMap().getIntegerBitsize(16))) func = fir::runtime::getRuntimeFunc(loc, builder); - else if (eleTy.isa()) + else if (mlir::isa(eleTy)) func = fir::runtime::getRuntimeFunc(loc, builder); else @@ -1108,7 +1108,7 @@ mlir::func::FuncOp func; auto ty = arrayBox.getType(); auto arrTy = fir::dyn_cast_ptrOrBoxEleTy(ty); - auto eleTy = arrTy.cast().getEleTy(); + auto eleTy = mlir::cast(arrTy).getEleTy(); auto dim = builder.createIntegerConstant(loc, builder.getIndexType(), 0); if (eleTy.isF16() || eleTy.isBF16()) @@ -1175,7 +1175,7 @@ mlir::func::FuncOp func; \ auto ty = arrayBox.getType(); \ auto arrTy = fir::dyn_cast_ptrOrBoxEleTy(ty); \ - auto eleTy = arrTy.cast().getEleTy(); \ + auto eleTy = mlir::cast(arrTy).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 --- a/flang/lib/Optimizer/CodeGen/BoxedProcedure.cpp +++ b/flang/lib/Optimizer/CodeGen/BoxedProcedure.cpp @@ -50,9 +50,9 @@ /// not at all depending on the implementation target's characteristics and /// preference. bool needsConversion(mlir::Type ty) { - if (ty.isa()) + if (mlir::isa(ty)) return true; - if (auto funcTy = ty.dyn_cast()) { + if (auto funcTy = mlir::dyn_cast(ty)) { for (auto t : funcTy.getInputs()) if (needsConversion(t)) return true; @@ -61,13 +61,13 @@ return true; return false; } - if (auto tupleTy = ty.dyn_cast()) { + if (auto tupleTy = mlir::dyn_cast(ty)) { for (auto t : tupleTy.getTypes()) if (needsConversion(t)) return true; return false; } - if (auto recTy = ty.dyn_cast()) { + if (auto recTy = mlir::dyn_cast(ty)) { if (llvm::is_contained(visitedTypes, recTy)) return false; bool result = false; @@ -81,11 +81,11 @@ visitedTypes.pop_back(); return result; } - if (auto boxTy = ty.dyn_cast()) + if (auto boxTy = mlir::dyn_cast(ty)) return needsConversion(boxTy.getEleTy()); if (isa_ref_type(ty)) return needsConversion(unwrapRefType(ty)); - if (auto t = ty.dyn_cast()) + if (auto t = mlir::dyn_cast(ty)) return needsConversion(unwrapSequenceType(ty)); return false; } @@ -195,7 +195,7 @@ if (auto addr = mlir::dyn_cast(op)) { auto ty = addr.getVal().getType(); if (typeConverter.needsConversion(ty) || - ty.isa()) { + mlir::isa(ty)) { // Rewrite all `fir.box_addr` ops on values of type `!fir.boxproc` // or function type to be `fir.convert` ops. rewriter.setInsertionPoint(addr); @@ -207,7 +207,7 @@ if (typeConverter.needsConversion(ty)) { rewriter.startRootUpdate(func); auto toTy = - typeConverter.convertType(ty).cast(); + mlir::cast(typeConverter.convertType(ty)); if (!func.empty()) for (auto e : llvm::enumerate(toTy.getInputs())) { unsigned i = e.index(); @@ -223,7 +223,7 @@ } else if (auto embox = mlir::dyn_cast(op)) { // Rewrite all `fir.emboxproc` ops to either `fir.convert` or a thunk // as required. - mlir::Type toTy = embox.getType().cast().getEleTy(); + mlir::Type toTy = mlir::cast(embox.getType()).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 --- a/flang/lib/Optimizer/CodeGen/CGOps.cpp +++ b/flang/lib/Optimizer/CodeGen/CGOps.cpp @@ -41,24 +41,24 @@ } unsigned fir::cg::XReboxOp::getOutRank() { - if (auto seqTy = - fir::dyn_cast_ptrOrBoxEleTy(getType()).dyn_cast()) + if (auto seqTy = mlir::dyn_cast( + fir::dyn_cast_ptrOrBoxEleTy(getType()))) return seqTy.getDimension(); return 0; } unsigned fir::cg::XReboxOp::getRank() { - if (auto seqTy = fir::dyn_cast_ptrOrBoxEleTy(getBox().getType()) - .dyn_cast()) + if (auto seqTy = mlir::dyn_cast( + fir::dyn_cast_ptrOrBoxEleTy(getBox().getType()))) return seqTy.getDimension(); return 0; } unsigned fir::cg::XArrayCoorOp::getRank() { auto memrefTy = getMemref().getType(); - if (memrefTy.isa()) - if (auto seqty = - fir::dyn_cast_ptrOrBoxEleTy(memrefTy).dyn_cast()) + if (mlir::isa(memrefTy)) + if (auto seqty = mlir::dyn_cast( + fir::dyn_cast_ptrOrBoxEleTy(memrefTy))) return seqty.getDimension(); return getShape().size(); } diff --git a/flang/lib/Optimizer/CodeGen/CodeGen.cpp b/flang/lib/Optimizer/CodeGen/CodeGen.cpp --- a/flang/lib/Optimizer/CodeGen/CodeGen.cpp +++ b/flang/lib/Optimizer/CodeGen/CodeGen.cpp @@ -84,7 +84,7 @@ /// Extract constant from a value if it is a result of one of the /// ConstantOp operations, otherwise, return std::nullopt. static std::optional getIfConstantIntValue(mlir::Value val) { - if (!val || !val.dyn_cast()) + if (!val || !mlir::dyn_cast(val)) return {}; mlir::Operation *defop = val.getDefiningOp(); @@ -92,7 +92,7 @@ if (auto constOp = mlir::dyn_cast(defop)) return constOp.value(); if (auto llConstOp = mlir::dyn_cast(defop)) - if (auto attr = llConstOp.getValue().dyn_cast()) + if (auto attr = mlir::dyn_cast(llConstOp.getValue())) return attr.getValue().getSExtValue(); return {}; @@ -107,7 +107,7 @@ } static unsigned getTypeDescFieldId(mlir::Type ty) { - auto isArray = fir::dyn_cast_ptrOrBoxEleTy(ty).isa(); + auto isArray = mlir::isa(fir::dyn_cast_ptrOrBoxEleTy(ty)); return isArray ? kOptTypePtrPosInBox : kDimsPosInBox; } @@ -158,7 +158,7 @@ auto valTy = val.getType(); // If the value was not yet lowered, lower its type so that it can // be used in getPrimitiveTypeSizeInBits. - if (!valTy.isa()) + if (!mlir::isa(valTy)) valTy = convertType(valTy); auto toSize = mlir::LLVM::getPrimitiveTypeSizeInBits(ty); auto fromSize = mlir::LLVM::getPrimitiveTypeSizeInBits(valTy); @@ -174,7 +174,7 @@ mlir::Value box, mlir::Type resultTy, mlir::ConversionPatternRewriter &rewriter, int boxValue) const { - if (box.getType().isa()) { + if (mlir::isa(box.getType())) { auto pty = mlir::LLVM::LLVMPointerType::get(resultTy); auto p = rewriter.create( loc, pty, box, llvm::ArrayRef{0, boxValue}); @@ -217,7 +217,7 @@ loadDimFieldFromBox(mlir::Location loc, mlir::Type boxTy, mlir::Value box, mlir::Value dim, int off, mlir::Type ty, mlir::ConversionPatternRewriter &rewriter) const { - assert(box.getType().isa() && + assert(mlir::isa(box.getType()) && "descriptor inquiry with runtime dim can only be done on descriptor " "in memory"); auto pty = mlir::LLVM::LLVMPointerType::get(ty); @@ -232,7 +232,7 @@ getDimFieldFromBox(mlir::Location loc, mlir::Type boxTy, mlir::Value box, int dim, int off, mlir::Type ty, mlir::ConversionPatternRewriter &rewriter) const { - if (box.getType().isa()) { + if (mlir::isa(box.getType())) { auto pty = mlir::LLVM::LLVMPointerType::get(ty); mlir::LLVM::GEPOp p = genGEP(loc, pty, rewriter, box, 0, static_cast(kDimsPosInBox), dim, off); @@ -273,15 +273,15 @@ // [llvm.ptr](array|struct|vector)+ and the provided indexes. static mlir::Type getBoxEleTy(mlir::Type type, llvm::ArrayRef indexes) { - if (auto t = type.dyn_cast()) + if (auto t = mlir::dyn_cast(type)) type = t.getElementType(); for (unsigned i : indexes) { - if (auto t = type.dyn_cast()) { + if (auto t = mlir::dyn_cast(type)) { assert(!t.isOpaque() && i < t.getBody().size()); type = t.getBody()[i]; - } else if (auto t = type.dyn_cast()) { + } else if (auto t = mlir::dyn_cast(type)) { type = t.getElementType(); - } else if (auto t = type.dyn_cast()) { + } else if (auto t = mlir::dyn_cast(type)) { type = t.getElementType(); } else { fir::emitFatalError(mlir::UnknownLoc::get(type.getContext()), @@ -430,7 +430,7 @@ mlir::ConversionPatternRewriter &rewriter) { mlir::Location loc = op.getLoc(); mlir::Type dataTy = op.getInType(); - auto seqTy = dataTy.dyn_cast(); + auto seqTy = mlir::dyn_cast(dataTy); fir::SequenceType::Extent constSize = 1; if (seqTy) { int constRows = seqTy.getConstantRows(); @@ -474,13 +474,13 @@ for (; i < end; ++i) lenParams.push_back(operands[i]); mlir::Type scalarType = fir::unwrapSequenceType(alloc.getInType()); - if (auto chrTy = scalarType.dyn_cast()) { + if (auto chrTy = mlir::dyn_cast(scalarType)) { fir::CharacterType rawCharTy = fir::CharacterType::getUnknownLen( chrTy.getContext(), chrTy.getFKind()); ty = mlir::LLVM::LLVMPointerType::get(convertType(rawCharTy)); assert(end == 1); size = integerCast(loc, rewriter, ity, lenParams[0]); - } else if (auto recTy = scalarType.dyn_cast()) { + } else if (auto recTy = mlir::dyn_cast(scalarType)) { mlir::LLVM::LLVMFuncOp memSizeFn = getDependentTypeMemSizeFn(recTy, alloc, rewriter); if (!memSizeFn) @@ -530,7 +530,8 @@ mlir::Value a = adaptor.getOperands()[0]; auto loc = boxaddr.getLoc(); mlir::Type ty = convertType(boxaddr.getType()); - if (auto argty = boxaddr.getVal().getType().dyn_cast()) { + if (auto argty = + mlir::dyn_cast(boxaddr.getVal().getType())) { rewriter.replaceOp(boxaddr, getBaseAddrFromBox(loc, ty, argty, a, rewriter)); } else { @@ -730,24 +731,25 @@ mlir::ConversionPatternRewriter &rewriter) const override { auto ty = convertType(constop.getType()); auto attr = constop.getValue(); - if (attr.isa()) { + if (mlir::isa(attr)) { rewriter.replaceOpWithNewOp(constop, ty, attr); return mlir::success(); } - auto charTy = constop.getType().cast(); + auto charTy = mlir::cast(constop.getType()); 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 = attr.dyn_cast()) { + if (auto arr = mlir::dyn_cast(attr)) { cst = rewriter.create(loc, ty, arr); - } else if (auto arr = attr.dyn_cast()) { + } else if (auto arr = mlir::dyn_cast(attr)) { for (auto a : llvm::enumerate(arr.getValue())) { // convert each character to a precise bitsize auto elemAttr = mlir::IntegerAttr::get( intTy, - a.value().cast().getValue().zextOrTrunc(bits)); + mlir::cast(a.value()).getValue().zextOrTrunc( + bits)); auto elemCst = rewriter.create(loc, intTy, elemAttr); cst = rewriter.create(loc, cst, elemCst, @@ -782,9 +784,9 @@ } // namespace static mlir::Type getComplexEleTy(mlir::Type complex) { - if (auto cc = complex.dyn_cast()) + if (auto cc = mlir::dyn_cast(complex)) return cc.getElementType(); - return complex.cast().getElementType(); + return mlir::cast(complex).getElementType(); } namespace { @@ -851,7 +853,7 @@ } inline llvm::APFloat getValue(mlir::Attribute attr) const { - return attr.cast().getValue(); + return mlir::cast(attr).getValue(); } }; @@ -860,7 +862,7 @@ using FIROpConversion::FIROpConversion; static bool isFloatingPointTy(mlir::Type ty) { - return ty.isa(); + return mlir::isa(ty); } mlir::LogicalResult @@ -880,7 +882,8 @@ auto loc = convert.getLoc(); auto i1Type = mlir::IntegerType::get(convert.getContext(), 1); - if (fromFirTy.isa() || toFirTy.isa()) { + if (mlir::isa(fromFirTy) || + mlir::isa(toFirTy)) { // By specification fir::LogicalType value may be any number, // where non-zero value represents .true. and zero value represents // .false. @@ -893,7 +896,8 @@ // 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 (!fromTy.isa() || !toTy.isa()) + if (!mlir::isa(fromTy) || + !mlir::isa(toTy)) return mlir::emitError(loc) << "unsupported types for logical conversion: " << fromTy << " -> " << toTy; @@ -974,13 +978,13 @@ rewriter.replaceOp(convert, v); return mlir::success(); } - if (toTy.isa()) { + if (mlir::isa(toTy)) { rewriter.replaceOpWithNewOp(convert, toTy, op0); return mlir::success(); } - } else if (fromTy.isa()) { + } else if (mlir::isa(fromTy)) { // Integer to integer conversion. - if (toTy.isa()) { + if (mlir::isa(toTy)) { auto fromBits = mlir::LLVM::getPrimitiveTypeSizeInBits(fromTy); auto toBits = mlir::LLVM::getPrimitiveTypeSizeInBits(toTy); assert(fromBits != toBits); @@ -1001,18 +1005,18 @@ return mlir::success(); } // Integer to pointer conversion. - if (toTy.isa()) { + if (mlir::isa(toTy)) { rewriter.replaceOpWithNewOp(convert, toTy, op0); return mlir::success(); } - } else if (fromTy.isa()) { + } else if (mlir::isa(fromTy)) { // Pointer to integer conversion. - if (toTy.isa()) { + if (mlir::isa(toTy)) { rewriter.replaceOpWithNewOp(convert, toTy, op0); return mlir::success(); } // Pointer to pointer conversion. - if (toTy.isa()) { + if (mlir::isa(toTy)) { rewriter.replaceOpWithNewOp(convert, toTy, op0); return mlir::success(); } @@ -1093,11 +1097,11 @@ auto llvmStruct = rewriter.create(loc, llvmStructTy); mlir::Type lenTy = - llvmStructTy.cast().getBody()[1]; + mlir::cast(llvmStructTy).getBody()[1]; mlir::Value lenAfterCast = integerCast(loc, rewriter, lenTy, charBufferLen); mlir::Type addrTy = - llvmStructTy.cast().getBody()[0]; + mlir::cast(llvmStructTy).getBody()[0]; if (addrTy != charBuffer.getType()) charBuffer = rewriter.create(loc, addrTy, charBuffer); @@ -1199,7 +1203,7 @@ mlir::Value genTypeSizeInBytes(mlir::Location loc, mlir::Type idxTy, mlir::ConversionPatternRewriter &rewriter, mlir::Type llTy) const { - auto ptrTy = llTy.dyn_cast(); + auto ptrTy = mlir::dyn_cast(llTy); return computeElementDistance(loc, ptrTy, idxTy, rewriter); } }; @@ -1223,9 +1227,10 @@ static unsigned getDimension(mlir::LLVM::LLVMArrayType ty) { unsigned result = 1; - for (auto eleTy = ty.getElementType().dyn_cast(); - eleTy; - eleTy = eleTy.getElementType().dyn_cast()) + for (auto eleTy = + mlir::dyn_cast(ty.getElementType()); + eleTy; eleTy = mlir::dyn_cast( + eleTy.getElementType())) ++result; return result; } @@ -1258,9 +1263,9 @@ static int getCFIAttr(fir::BaseBoxType boxTy) { auto eleTy = boxTy.getEleTy(); - if (eleTy.isa()) + if (mlir::isa(eleTy)) return CFI_attribute_pointer; - if (eleTy.isa()) + if (mlir::isa(eleTy)) return CFI_attribute_allocatable; return CFI_attribute_other; } @@ -1272,20 +1277,22 @@ auto i64Ty = mlir::IntegerType::get(rewriter.getContext(), 64); if (auto eleTy = fir::dyn_cast_ptrEleTy(boxEleTy)) boxEleTy = eleTy; - if (auto seqTy = boxEleTy.dyn_cast()) + if (auto seqTy = mlir::dyn_cast(boxEleTy)) return getSizeAndTypeCode(loc, rewriter, seqTy.getEleTy(), lenParams); - if (boxEleTy.isa()) // unlimited polymorphic or assumed type + if (mlir::isa( + boxEleTy)) // 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) || boxEleTy.dyn_cast() || - fir::isa_real(boxEleTy) || fir::isa_complex(boxEleTy)) + if (fir::isa_integer(boxEleTy) || + mlir::dyn_cast(boxEleTy) || fir::isa_real(boxEleTy) || + fir::isa_complex(boxEleTy)) return {genTypeStrideInBytes(loc, i64Ty, rewriter, this->convertType(boxEleTy)), typeCodeVal}; - if (auto charTy = boxEleTy.dyn_cast()) { + if (auto charTy = mlir::dyn_cast(boxEleTy)) { mlir::Value size = genTypeStrideInBytes(loc, i64Ty, rewriter, this->convertType(charTy)); if (charTy.getLen() == fir::CharacterType::unknownLen()) { @@ -1302,7 +1309,7 @@ mlir::LLVM::LLVMVoidType::get(rewriter.getContext())); return {genTypeStrideInBytes(loc, i64Ty, rewriter, ptrTy), typeCodeVal}; } - if (boxEleTy.isa()) + if (mlir::isa(boxEleTy)) return {genTypeStrideInBytes(loc, i64Ty, rewriter, this->convertType(boxEleTy)), typeCodeVal}; @@ -1391,7 +1398,7 @@ mlir::Value cfiTy, mlir::Value typeDesc) const { auto convTy = this->lowerTy().convertBoxType(boxTy, rank); - auto llvmBoxPtrTy = convTy.template cast(); + auto llvmBoxPtrTy = mlir::cast(convTy); auto llvmBoxTy = llvmBoxPtrTy.getElementType(); bool isUnlimitedPolymorphic = fir::isUnlimitedPolymorphicType(boxTy); bool useInputType = fir::isPolymorphicType(boxTy) || isUnlimitedPolymorphic; @@ -1417,8 +1424,8 @@ if (!typeDesc) { if (useInputType) { mlir::Type innerType = fir::unwrapInnerType(inputType); - if (innerType && innerType.template isa()) { - auto recTy = innerType.template dyn_cast(); + if (innerType && mlir::isa(innerType)) { + auto recTy = mlir::dyn_cast(innerType); typeDesc = getTypeDescriptor(mod, rewriter, loc, recTy); } else { // Unlimited polymorphic type descriptor with no record type. Set @@ -1448,7 +1455,7 @@ mlir::ValueRange lenParams, mlir::Value sourceBox = {}, mlir::Type sourceBoxType = {}) const { auto loc = box.getLoc(); - auto boxTy = box.getType().template dyn_cast(); + auto boxTy = mlir::dyn_cast(box.getType()); bool useInputType = fir::isPolymorphicType(boxTy) && !fir::isUnlimitedPolymorphicType(inputType); llvm::SmallVector typeparams = lenParams; @@ -1490,8 +1497,8 @@ mlir::ValueRange lenParams, mlir::Value typeDesc = {}) const { auto loc = box.getLoc(); - auto boxTy = box.getType().dyn_cast(); - auto inputBoxTy = box.getBox().getType().dyn_cast(); + auto boxTy = mlir::dyn_cast(box.getType()); + auto inputBoxTy = mlir::dyn_cast(box.getBox().getType()); llvm::SmallVector typeparams = lenParams; if (!box.getSubstr().empty() && fir::hasDynamicSize(boxTy.getEleTy())) typeparams.push_back(substrParams[1]); @@ -1537,10 +1544,11 @@ std::optional substringOffset) const { llvm::SmallVector gepArgs{outerOffset}; mlir::Type resultTy = - base.getType().cast().getElementType(); + mlir::cast(base.getType()) + .getElementType(); // Fortran is column major, llvm GEP is row major: reverse the indices here. for (mlir::Value interiorIndex : llvm::reverse(cstInteriorIndices)) { - auto arrayTy = resultTy.dyn_cast(); + auto arrayTy = mlir::dyn_cast(resultTy); if (!arrayTy) fir::emitFatalError( loc, @@ -1551,11 +1559,12 @@ for (mlir::Value componentIndex : componentIndices) { // Component indices can be field index to select a component, or array // index, to select an element in an array component. - if (auto structTy = resultTy.dyn_cast()) { + if (auto structTy = + mlir::dyn_cast(resultTy)) { std::int64_t cstIndex = getConstantIntValue(componentIndex); resultTy = structTy.getBody()[cstIndex]; } else if (auto arrayTy = - resultTy.dyn_cast()) { + mlir::dyn_cast(resultTy)) { resultTy = arrayTy.getElementType(); } else { fir::emitFatalError(loc, "corrupted component GEP generated being " @@ -1564,7 +1573,7 @@ gepArgs.push_back(componentIndex); } if (substringOffset) { - if (auto arrayTy = resultTy.dyn_cast()) { + if (auto arrayTy = mlir::dyn_cast(resultTy)) { gepArgs.push_back(*substringOffset); resultTy = arrayTy.getElementType(); } else { @@ -1713,14 +1722,14 @@ unsigned constRows = 0; mlir::Value ptrOffset = zero; mlir::Type memEleTy = fir::dyn_cast_ptrEleTy(xbox.getMemref().getType()); - assert(memEleTy.isa()); - auto seqTy = memEleTy.cast(); + assert(mlir::isa(memEleTy)); + auto seqTy = mlir::cast(memEleTy); mlir::Type seqEleTy = seqTy.getEleTy(); // Adjust the element scaling factor if the element is a dependent type. if (fir::hasDynamicSize(seqEleTy)) { - if (auto charTy = seqEleTy.dyn_cast()) { + if (auto charTy = mlir::dyn_cast(seqEleTy)) { prevPtrOff = eleSize; - } else if (seqEleTy.isa()) { + } else if (mlir::isa(seqEleTy)) { // prevPtrOff = ; TODO(loc, "generate call to calculate size of PDT"); } else { @@ -1743,7 +1752,7 @@ } else if (hasSubstr) { // We have a substring. The step value needs to be the number of bytes // per CHARACTER element. - auto charTy = seqEleTy.cast(); + auto charTy = mlir::cast(seqEleTy); if (fir::hasDynamicSize(charTy)) { prevDimByteStride = prevPtrOff; } else { @@ -1791,7 +1800,8 @@ // Lower bound is normalized to 0 for BIND(C) interoperability. mlir::Value lb = zero; const bool isaPointerOrAllocatable = - eleTy.isa() || eleTy.isa(); + mlir::isa(eleTy) || + mlir::isa(eleTy); // Lower bound is defaults to 1 for POINTER, ALLOCATABLE, and // denormalized descriptors. if (isaPointerOrAllocatable || !normalizedLowerBound(xbox)) @@ -1892,7 +1902,7 @@ // Create new descriptor and fill its non-shape related data. llvm::SmallVector lenParams; mlir::Type inputEleTy = getInputEleTy(rebox); - if (auto charTy = inputEleTy.dyn_cast()) { + if (auto charTy = mlir::dyn_cast(inputEleTy)) { mlir::Value len = getElementSizeFromBox( loc, idxTy, rebox.getBox().getType(), loweredBox, rewriter); if (charTy.getFKind() != 1) { @@ -1901,15 +1911,15 @@ len = rewriter.create(loc, idxTy, len, width); } lenParams.emplace_back(len); - } else if (auto recTy = inputEleTy.dyn_cast()) { + } else if (auto recTy = mlir::dyn_cast(inputEleTy)) { 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 (rebox.getBox().getType().isa() && - rebox.getType().isa()) + if (mlir::isa(rebox.getBox().getType()) && + mlir::isa(rebox.getType())) typeDescAddr = loadTypeDescAddress(loc, rebox.getBox().getType(), loweredBox, rewriter); @@ -2106,7 +2116,7 @@ /// 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 = ty.dyn_cast()) + if (auto seqTy = mlir::dyn_cast(ty)) return seqTy.getEleTy(); return ty; } @@ -2134,7 +2144,7 @@ assert(ty && "type is null"); const auto end = indices.size(); for (std::remove_const_t i = 0; i < end; ++i) { - if (auto seq = ty.dyn_cast()) { + if (auto seq = mlir::dyn_cast(ty)) { const auto dim = getDimension(seq); if (dim > 1) { auto ub = std::min(i + dim, end); @@ -2142,7 +2152,7 @@ i += dim - 1; } ty = getArrayElementType(seq); - } else if (auto st = ty.dyn_cast()) { + } else if (auto st = mlir::dyn_cast(ty)) { ty = st.getBody()[indices[i]]; } else { llvm_unreachable("index into invalid type"); @@ -2155,13 +2165,13 @@ mlir::ArrayAttr arrAttr) { llvm::SmallVector indices; for (auto i = arrAttr.begin(), e = arrAttr.end(); i != e; ++i) { - if (auto intAttr = i->dyn_cast()) { + if (auto intAttr = mlir::dyn_cast(*i)) { indices.push_back(intAttr.getInt()); } else { - auto fieldName = i->cast().getValue(); + auto fieldName = mlir::cast(*i).getValue(); ++i; - auto ty = i->cast().getValue(); - auto index = ty.cast().getFieldIndex(fieldName); + auto ty = mlir::cast(*i).getValue(); + auto index = mlir::cast(ty).getFieldIndex(fieldName); indices.push_back(index); } } @@ -2171,7 +2181,7 @@ private: static mlir::Type getArrayElementType(mlir::LLVM::LLVMArrayType ty) { auto eleTy = ty.getElementType(); - while (auto arrTy = eleTy.dyn_cast()) + while (auto arrTy = mlir::dyn_cast(eleTy)) eleTy = arrTy.getElementType(); return eleTy; } @@ -2239,7 +2249,7 @@ auto type = adaptor.getOperands()[0].getType(); // Iteratively extract the array dimensions from the type. - while (auto t = type.dyn_cast()) { + while (auto t = mlir::dyn_cast(type)) { dims.push_back(t.getNumElements()); type = t.getElementType(); } @@ -2305,7 +2315,8 @@ mlir::Value offset = genConstantIndex(loc, idxTy, rewriter, 0); const bool isShifted = !coor.getShift().empty(); const bool isSliced = !coor.getSlice().empty(); - const bool baseIsBoxed = coor.getMemref().getType().isa(); + const bool baseIsBoxed = + mlir::isa(coor.getMemref().getType()); // For each dimension of the array, generate the offset calculation. for (unsigned i = 0; i < rank; ++i, ++indexOffset, ++shapeOffset, @@ -2375,8 +2386,9 @@ // derived type members can be addresses via a GEP using the index of // components. mlir::Type elementType = - baseTy.cast().getElementType(); - while (auto arrayTy = elementType.dyn_cast()) + mlir::cast(baseTy).getElementType(); + while (auto arrayTy = + mlir::dyn_cast(elementType)) elementType = arrayTy.getElementType(); mlir::Type elementPtrType = mlir::LLVM::LLVMPointerType::get(elementType); auto casted = @@ -2422,10 +2434,10 @@ // Operand #0 must have a pointer type. For subcomponent slicing, we // want to cast away the array type and have a plain struct type. mlir::Type ty0 = operands[0].getType(); - auto ptrTy = ty0.dyn_cast(); + auto ptrTy = mlir::dyn_cast(ty0); assert(ptrTy && "expected pointer type"); mlir::Type eleTy = ptrTy.getElementType(); - while (auto arrTy = eleTy.dyn_cast()) + while (auto arrTy = mlir::dyn_cast(eleTy)) eleTy = arrTy.getElementType(); auto newTy = mlir::LLVM::LLVMPointerType::get(eleTy); base = rewriter.create(loc, newTy, operands[0]); @@ -2467,11 +2479,12 @@ } // Boxed type - get the base pointer from the box - if (baseObjectTy.dyn_cast()) + if (mlir::dyn_cast(baseObjectTy)) return doRewriteBox(coor, ty, operands, loc, rewriter); // Reference, pointer or a heap type - if (baseObjectTy.isa()) + if (mlir::isa( + baseObjectTy)) return doRewriteRefOrPtr(coor, ty, operands, loc, rewriter); return rewriter.notifyMatchFailure( @@ -2487,7 +2500,7 @@ } static bool hasSubDimensions(mlir::Type type) { - return type.isa(); + return mlir::isa(type); } /// Check whether this form of `!fir.coordinate_of` is supported. These @@ -2502,14 +2515,14 @@ bool ptrEle = false; for (; i < numOfCoors; ++i) { mlir::Value nxtOpnd = coors[i]; - if (auto arrTy = type.dyn_cast()) { + if (auto arrTy = mlir::dyn_cast(type)) { subEle = true; i += arrTy.getDimension() - 1; type = arrTy.getEleTy(); - } else if (auto recTy = type.dyn_cast()) { + } else if (auto recTy = mlir::dyn_cast(type)) { subEle = true; type = recTy.getType(getFieldNumber(recTy, nxtOpnd)); - } else if (auto tupTy = type.dyn_cast()) { + } else if (auto tupTy = mlir::dyn_cast(type)) { subEle = true; type = tupTy.getType(getConstantIntValue(nxtOpnd)); } else { @@ -2527,14 +2540,14 @@ 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 = type.dyn_cast()) { + if (auto arrTy = mlir::dyn_cast(type)) { if (fir::sequenceWithNonConstantShape(arrTy)) return false; i += arrTy.getDimension() - 1; type = arrTy.getEleTy(); - } else if (auto strTy = type.dyn_cast()) { + } else if (auto strTy = mlir::dyn_cast(type)) { type = strTy.getType(getFieldNumber(strTy, nxtOpnd)); - } else if (auto strTy = type.dyn_cast()) { + } else if (auto strTy = mlir::dyn_cast(type)) { type = strTy.getType(getConstantIntValue(nxtOpnd)); } else { return true; @@ -2549,7 +2562,8 @@ mlir::Location loc, mlir::ConversionPatternRewriter &rewriter) const { mlir::Type boxObjTy = coor.getBaseType(); - assert(boxObjTy.dyn_cast() && "This is not a `fir.box`"); + assert(mlir::dyn_cast(boxObjTy) && + "This is not a `fir.box`"); mlir::Value boxBaseAddr = operands[0]; @@ -2588,7 +2602,7 @@ mlir::Type voidPtrTy = ::getVoidPtrType(coor.getContext()); for (unsigned i = 1, last = operands.size(); i < last; ++i) { - if (auto arrTy = cpnTy.dyn_cast()) { + if (auto arrTy = mlir::dyn_cast(cpnTy)) { 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 @@ -2612,7 +2626,7 @@ llvm::ArrayRef{off}); i += arrTy.getDimension() - 1; cpnTy = arrTy.getEleTy(); - } else if (auto recTy = cpnTy.dyn_cast()) { + } else if (auto recTy = mlir::dyn_cast(cpnTy)) { auto recRefTy = mlir::LLVM::LLVMPointerType::get(lowerTy().convertType(recTy)); mlir::Value nxtOpnd = operands[i]; @@ -2653,7 +2667,7 @@ // If only the column is `?`, then we can simply place the column value in // the 0-th GEP position. - if (auto arrTy = cpnTy.dyn_cast()) { + if (auto arrTy = mlir::dyn_cast(cpnTy)) { if (!hasKnownShape) { const unsigned sz = arrTy.getDimension(); if (arraysHaveKnownShape(arrTy.getEleTy(), @@ -2697,29 +2711,29 @@ dims = dimsLeft - 1; continue; } - cpnTy = cpnTy.cast().getEleTy(); + cpnTy = mlir::cast(cpnTy).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 = cpnTy.dyn_cast()) { + if (auto arrTy = mlir::dyn_cast(cpnTy)) { int d = arrTy.getDimension() - 1; if (d > 0) { dims = d; arrIdx.push_back(nxtOpnd); continue; } - cpnTy = cpnTy.cast().getEleTy(); + cpnTy = mlir::cast(cpnTy).getEleTy(); offs.push_back(nxtOpnd); continue; } // check if the i-th coordinate relates to a field - if (auto recTy = cpnTy.dyn_cast()) + if (auto recTy = mlir::dyn_cast(cpnTy)) cpnTy = recTy.getType(getFieldNumber(recTy, nxtOpnd)); - else if (auto tupTy = cpnTy.dyn_cast()) + else if (auto tupTy = mlir::dyn_cast(cpnTy)) cpnTy = tupTy.getType(getConstantIntValue(nxtOpnd)); else cpnTy = nullptr; @@ -2748,7 +2762,7 @@ mlir::LogicalResult matchAndRewrite(fir::FieldIndexOp field, OpAdaptor adaptor, mlir::ConversionPatternRewriter &rewriter) const override { - auto recTy = field.getOnType().cast(); + auto recTy = mlir::cast(field.getOnType()); unsigned index = recTy.getFieldIndex(field.getFieldId()); if (!fir::hasDynamicSize(recTy)) { @@ -2801,8 +2815,8 @@ matchAndRewrite(fir::TypeDescOp typeDescOp, OpAdaptor adaptor, mlir::ConversionPatternRewriter &rewriter) const override { mlir::Type inTy = typeDescOp.getInType(); - assert(inTy.isa() && "expecting fir.type"); - auto recordType = inTy.dyn_cast(); + assert(mlir::isa(inTy) && "expecting fir.type"); + auto recordType = mlir::dyn_cast(inTy); auto module = typeDescOp.getOperation()->getParentOfType(); std::string typeDescName = fir::NameUniquer::getTypeDescriptorName(recordType.getName()); @@ -2846,8 +2860,8 @@ matchAndRewrite(fir::GlobalOp global, OpAdaptor adaptor, mlir::ConversionPatternRewriter &rewriter) const override { auto tyAttr = convertType(global.getType()); - if (global.getType().isa()) - tyAttr = tyAttr.cast().getElementType(); + if (mlir::isa(global.getType())) + tyAttr = mlir::cast(tyAttr).getElementType(); auto loc = global.getLoc(); mlir::Attribute initAttr = global.getInitVal().value_or(mlir::Attribute()); auto linkage = convertLinkage(global.getLinkName()); @@ -2885,7 +2899,7 @@ mlir::Type vecType = mlir::VectorType::get( insertOp.getType().getShape(), constant.getType()); auto denseAttr = mlir::DenseElementsAttr::get( - vecType.cast(), constant.getValue()); + mlir::cast(vecType), constant.getValue()); rewriter.setInsertionPointAfter(insertOp); rewriter.replaceOpWithNewOp( insertOp, seqTyAttr, denseAttr); @@ -2939,7 +2953,7 @@ mlir::LogicalResult matchAndRewrite(fir::LoadOp load, OpAdaptor adaptor, mlir::ConversionPatternRewriter &rewriter) const override { - if (auto boxTy = load.getType().dyn_cast()) { + if (auto boxTy = mlir::dyn_cast(load.getType())) { // 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 @@ -2955,7 +2969,8 @@ TODO(loc, "loading or assumed rank fir.box"); mlir::Type boxPtrTy = inputBoxStorage.getType(); auto boxValue = rewriter.create( - loc, boxPtrTy.cast().getElementType(), + loc, + mlir::cast(boxPtrTy).getElementType(), inputBoxStorage); attachTBAATag(boxValue, boxTy, boxTy, nullptr); auto newBoxStorage = @@ -3049,7 +3064,7 @@ llvm::ArrayRef cases = caseOp.getCases().getValue(); // Type can be CHARACTER, INTEGER, or LOGICAL (C1145) auto ty = caseOp.getSelector().getType(); - if (ty.isa()) { + if (mlir::isa(ty)) { TODO(caseOp.getLoc(), "fir.select_case codegen with character type"); return mlir::failure(); } @@ -3063,25 +3078,25 @@ *caseOp.getCompareOperands(adaptor.getOperands(), t); mlir::Value caseArg = *(cmpOps.value().begin()); mlir::Attribute attr = cases[t]; - if (attr.isa()) { + if (mlir::isa(attr)) { auto cmp = rewriter.create( loc, mlir::LLVM::ICmpPredicate::eq, selector, caseArg); genCaseLadderStep(loc, cmp, dest, destOps, rewriter); continue; } - if (attr.isa()) { + if (mlir::isa(attr)) { auto cmp = rewriter.create( loc, mlir::LLVM::ICmpPredicate::sle, caseArg, selector); genCaseLadderStep(loc, cmp, dest, destOps, rewriter); continue; } - if (attr.isa()) { + if (mlir::isa(attr)) { auto cmp = rewriter.create( loc, mlir::LLVM::ICmpPredicate::sle, selector, caseArg); genCaseLadderStep(loc, cmp, dest, destOps, rewriter); continue; } - if (attr.isa()) { + if (mlir::isa(attr)) { auto cmp = rewriter.create( loc, mlir::LLVM::ICmpPredicate::sle, caseArg, selector); auto *thisBlock = rewriter.getInsertionBlock(); @@ -3097,7 +3112,7 @@ rewriter.setInsertionPointToEnd(newBlock2); continue; } - assert(attr.isa()); + assert(mlir::isa(attr)); assert((t + 1 == conds) && "unit must be last"); genBrOp(caseOp, dest, destOps, rewriter); } @@ -3125,13 +3140,13 @@ mlir::Block *dest = select.getSuccessor(t); auto destOps = select.getSuccessorOperands(adaptor.getOperands(), t); const mlir::Attribute &attr = cases[t]; - if (auto intAttr = attr.template dyn_cast()) { + if (auto intAttr = mlir::dyn_cast(attr)) { destinations.push_back(dest); destinationsOperands.push_back(destOps ? *destOps : mlir::ValueRange{}); caseValues.push_back(intAttr.getInt()); continue; } - assert(attr.template dyn_cast_or_null()); + assert(mlir::dyn_cast_if_present(attr)); assert((t + 1 == conds) && "unit must be last"); defaultDestination = dest; defaultOperands = destOps ? *destOps : mlir::ValueRange{}; @@ -3199,11 +3214,12 @@ mlir::Location loc = store.getLoc(); mlir::Type storeTy = store.getValue().getType(); mlir::LLVM::StoreOp newStoreOp; - if (auto boxTy = storeTy.dyn_cast()) { + if (auto boxTy = mlir::dyn_cast(storeTy)) { // fir.box value is actually in memory, load it first before storing it. mlir::Type boxPtrTy = adaptor.getOperands()[0].getType(); auto val = rewriter.create( - loc, boxPtrTy.cast().getElementType(), + loc, + mlir::cast(boxPtrTy).getElementType(), adaptor.getOperands()[0]); attachTBAATag(val, boxTy, boxTy, nullptr); newStoreOp = rewriter.create( @@ -3278,9 +3294,9 @@ matchAndRewrite(fir::ZeroOp zero, OpAdaptor, mlir::ConversionPatternRewriter &rewriter) const override { mlir::Type ty = convertType(zero.getType()); - if (ty.isa()) { + if (mlir::isa(ty)) { rewriter.replaceOpWithNewOp(zero, ty); - } else if (ty.isa()) { + } else if (mlir::isa(ty)) { rewriter.replaceOpWithNewOp( zero, ty, mlir::IntegerAttr::get(ty, 0)); } else if (mlir::LLVM::isCompatibleFloatingPointType(ty)) { @@ -3324,9 +3340,9 @@ mlir::Location loc = isPresent.getLoc(); auto ptr = adaptor.getOperands()[0]; - if (isPresent.getVal().getType().isa()) { + if (mlir::isa(isPresent.getVal().getType())) { [[maybe_unused]] auto structTy = - ptr.getType().cast(); + mlir::cast(ptr.getType()); assert(!structTy.isOpaque() && !structTy.getBody().empty()); ptr = rewriter.create(loc, ptr, 0); @@ -3352,8 +3368,8 @@ mlir::Type ty = convertType(absent.getType()); mlir::Location loc = absent.getLoc(); - if (absent.getType().isa()) { - auto structTy = ty.cast(); + if (mlir::isa(absent.getType())) { + auto structTy = mlir::cast(ty); assert(!structTy.isOpaque() && !structTy.getBody().empty()); auto undefStruct = rewriter.create(loc, ty); auto nullField = diff --git a/flang/lib/Optimizer/CodeGen/PreCGRewrite.cpp b/flang/lib/Optimizer/CodeGen/PreCGRewrite.cpp --- a/flang/lib/Optimizer/CodeGen/PreCGRewrite.cpp +++ b/flang/lib/Optimizer/CodeGen/PreCGRewrite.cpp @@ -86,10 +86,10 @@ // If the embox does not include a shape, then do not convert it if (auto shapeVal = embox.getShape()) return rewriteDynamicShape(embox, rewriter, shapeVal); - if (embox.getType().isa()) + if (mlir::isa(embox.getType())) TODO(embox.getLoc(), "embox conversion for fir.class type"); - if (auto boxTy = embox.getType().dyn_cast()) - if (auto seqTy = boxTy.getEleTy().dyn_cast()) + if (auto boxTy = mlir::dyn_cast(embox.getType())) + if (auto seqTy = mlir::dyn_cast(boxTy.getEleTy())) if (!seqTy.hasDynamicExtents()) return rewriteStaticShape(embox, rewriter, seqTy); return mlir::failure(); @@ -292,10 +292,9 @@ target.addIllegalOp(); target.addIllegalOp(); target.addDynamicallyLegalOp([](fir::EmboxOp embox) { - return !(embox.getShape() || embox.getType() - .cast() - .getEleTy() - .isa()); + return !(embox.getShape() || + mlir::isa( + mlir::cast(embox.getType()).getEleTy())); }); mlir::RewritePatternSet patterns(&context); patterns.insert()) + if (mlir::isa(baseFIRType)) tbaaTagSym = getBoxAccessTag(baseFIRType, accessFIRType, gep); else tbaaTagSym = getDataAccessTag(baseFIRType, accessFIRType, gep); diff --git a/flang/lib/Optimizer/CodeGen/Target.cpp b/flang/lib/Optimizer/CodeGen/Target.cpp --- a/flang/lib/Optimizer/CodeGen/Target.cpp +++ b/flang/lib/Optimizer/CodeGen/Target.cpp @@ -39,9 +39,9 @@ static const llvm::fltSemantics &floatToSemantics(const KindMapping &kindMap, mlir::Type type) { assert(isa_real(type)); - if (auto ty = type.dyn_cast()) + if (auto ty = mlir::dyn_cast(type)) return kindMap.getFloatSemantics(ty.getFKind()); - return type.cast().getFloatSemantics(); + return mlir::cast(type).getFloatSemantics(); } namespace { diff --git a/flang/lib/Optimizer/CodeGen/TargetRewrite.cpp b/flang/lib/Optimizer/CodeGen/TargetRewrite.cpp --- a/flang/lib/Optimizer/CodeGen/TargetRewrite.cpp +++ b/flang/lib/Optimizer/CodeGen/TargetRewrite.cpp @@ -114,7 +114,7 @@ if (!hasPortableSignature(dispatch.getFunctionType(), op)) convertCallOp(dispatch); } else if (auto addr = mlir::dyn_cast(op)) { - if (addr.getType().isa() && + if (mlir::isa(addr.getType()) && !hasPortableSignature(addr.getType(), op)) convertAddrOp(addr); } @@ -450,7 +450,7 @@ /// Taking the address of a function. Modify the signature as needed. void convertAddrOp(fir::AddrOfOp addrOp) { rewriter->setInsertionPoint(addrOp); - auto addrTy = addrOp.getType().cast(); + auto addrTy = mlir::cast(addrOp.getType()); llvm::SmallVector newResTys; llvm::SmallVector newInTys; auto loc = addrOp.getLoc(); @@ -529,21 +529,22 @@ /// return `true`. Otherwise, the signature is not portable and `false` is /// returned. bool hasPortableSignature(mlir::Type signature, mlir::Operation *op) { - assert(signature.isa()); - auto func = signature.dyn_cast(); + assert(mlir::isa(signature)); + auto func = mlir::dyn_cast(signature); bool hasCCallingConv = isFuncWithCCallingConvention(op); for (auto ty : func.getResults()) - if ((ty.isa() && !noCharacterConversion) || + if ((mlir::isa(ty) && !noCharacterConversion) || (fir::isa_complex(ty) && !noComplexConversion) || - (ty.isa() && hasCCallingConv)) { + (mlir::isa(ty) && hasCCallingConv)) { LLVM_DEBUG(llvm::dbgs() << "rewrite " << signature << " for target\n"); return false; } for (auto ty : func.getInputs()) - if (((ty.isa() || fir::isCharacterProcedureTuple(ty)) && + if (((mlir::isa(ty) || + fir::isCharacterProcedureTuple(ty)) && !noCharacterConversion) || (fir::isa_complex(ty) && !noComplexConversion) || - (ty.isa() && hasCCallingConv)) { + (mlir::isa(ty) && hasCCallingConv)) { LLVM_DEBUG(llvm::dbgs() << "rewrite " << signature << " for target\n"); return false; } @@ -563,7 +564,7 @@ /// 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 = func.getFunctionType().cast(); + auto funcTy = mlir::cast(func.getFunctionType()); 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 --- a/flang/lib/Optimizer/CodeGen/TypeConverter.cpp +++ b/flang/lib/Optimizer/CodeGen/TypeConverter.cpp @@ -105,10 +105,10 @@ 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 = mem.dyn_cast()) + if (auto box = mlir::dyn_cast(mem)) members.push_back(convertBoxTypeAsStruct(box)); else - members.push_back(convertType(mem).cast()); + members.push_back(mlir::cast(convertType(mem))); } return mlir::LLVM::LLVMStructType::getLiteral(&getContext(), members, /*isPacked=*/false); @@ -179,10 +179,10 @@ 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 = mem.second.dyn_cast()) + if (auto box = mlir::dyn_cast(mem.second)) members.push_back(convertBoxTypeAsStruct(box)); else - members.push_back(convertType(mem.second).cast()); + members.push_back(mlir::cast(convertType(mem.second))); } if (mlir::failed(st.setBody(members, /*isPacked=*/false))) return mlir::failure(); @@ -194,7 +194,7 @@ // Extended descriptors are required for derived types. bool LLVMTypeConverter::requiresExtendedDesc(mlir::Type boxElementType) { auto eleTy = fir::unwrapSequenceType(boxElementType); - return eleTy.isa(); + return mlir::isa(eleTy); } // This corresponds to the descriptor as defined in ISO_Fortran_binding.h and @@ -208,7 +208,8 @@ ele = removeIndirection; auto eleTy = convertType(ele); // base_addr* - if (ele.isa() && eleTy.isa()) + if (mlir::isa(ele) && + mlir::isa(eleTy)) dataDescFields.push_back(eleTy); else dataDescFields.push_back(mlir::LLVM::LLVMPointerType::get(eleTy)); @@ -232,7 +233,7 @@ getDescFieldTypeModel()(&getContext())); // [dims] if (rank == unknownRank()) { - if (auto seqTy = ele.dyn_cast()) + if (auto seqTy = mlir::dyn_cast(ele)) rank = seqTy.getDimension(); else rank = 0; @@ -248,7 +249,8 @@ auto rowTy = getExtendedDescFieldTypeModel()(&getContext()); dataDescFields.push_back(mlir::LLVM::LLVMArrayType::get(rowTy, 1)); - if (auto recTy = fir::unwrapSequenceType(ele).dyn_cast()) + if (auto recTy = + mlir::dyn_cast(fir::unwrapSequenceType(ele))) 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 @@ -270,8 +272,7 @@ /// Convert fir.box type to the corresponding llvm struct type instead of a /// pointer to this struct type. mlir::Type LLVMTypeConverter::convertBoxTypeAsStruct(BaseBoxType box) { - return convertBoxType(box) - .cast() + return mlir::cast(convertBoxType(box)) .getElementType(); } diff --git a/flang/lib/Optimizer/Dialect/FIRAttr.cpp b/flang/lib/Optimizer/Dialect/FIRAttr.cpp --- a/flang/lib/Optimizer/Dialect/FIRAttr.cpp +++ b/flang/lib/Optimizer/Dialect/FIRAttr.cpp @@ -263,23 +263,23 @@ void fir::printFirAttribute(FIROpsDialect *dialect, mlir::Attribute attr, mlir::DialectAsmPrinter &p) { auto &os = p.getStream(); - if (auto exact = attr.dyn_cast()) { + if (auto exact = mlir::dyn_cast(attr)) { os << fir::ExactTypeAttr::getAttrName() << '<'; p.printType(exact.getType()); os << '>'; - } else if (auto sub = attr.dyn_cast()) { + } else if (auto sub = mlir::dyn_cast(attr)) { os << fir::SubclassAttr::getAttrName() << '<'; p.printType(sub.getType()); os << '>'; - } else if (attr.dyn_cast_or_null()) { + } else if (mlir::dyn_cast_if_present(attr)) { os << fir::PointIntervalAttr::getAttrName(); - } else if (attr.dyn_cast_or_null()) { + } else if (mlir::dyn_cast_if_present(attr)) { os << fir::ClosedIntervalAttr::getAttrName(); - } else if (attr.dyn_cast_or_null()) { + } else if (mlir::dyn_cast_if_present(attr)) { os << fir::LowerBoundAttr::getAttrName(); - } else if (attr.dyn_cast_or_null()) { + } else if (mlir::dyn_cast_if_present(attr)) { os << fir::UpperBoundAttr::getAttrName(); - } else if (auto a = attr.dyn_cast_or_null()) { + } else if (auto a = mlir::dyn_cast_if_present(attr)) { 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/FIRDialect.cpp b/flang/lib/Optimizer/Dialect/FIRDialect.cpp --- a/flang/lib/Optimizer/Dialect/FIRDialect.cpp +++ b/flang/lib/Optimizer/Dialect/FIRDialect.cpp @@ -41,7 +41,7 @@ /// return. void handleTerminator(mlir::Operation *op, llvm::ArrayRef valuesToRepl) const final { - auto returnOp = llvm::cast(op); + auto returnOp = mlir::cast(op); assert(returnOp.getNumOperands() == valuesToRepl.size()); for (const auto &it : llvm::enumerate(returnOp.getOperands())) valuesToRepl[it.index()].replaceAllUsesWith(it.value()); diff --git a/flang/lib/Optimizer/Dialect/FIROps.cpp b/flang/lib/Optimizer/Dialect/FIROps.cpp --- a/flang/lib/Optimizer/Dialect/FIROps.cpp +++ b/flang/lib/Optimizer/Dialect/FIROps.cpp @@ -44,7 +44,7 @@ static bool verifyInType(mlir::Type inType, llvm::SmallVectorImpl &visited, unsigned dynamicExtents = 0) { - if (auto st = inType.dyn_cast()) { + if (auto st = mlir::dyn_cast(inType)) { auto shape = st.getShape(); if (shape.size() == 0) return true; @@ -54,7 +54,7 @@ if (dynamicExtents-- == 0) return true; } - } else if (auto rt = inType.dyn_cast()) { + } else if (auto rt = mlir::dyn_cast(inType)) { // don't recurse if we're already visiting this one if (llvm::is_contained(visited, rt.getName())) return false; @@ -71,13 +71,13 @@ static bool verifyTypeParamCount(mlir::Type inType, unsigned numParams) { auto ty = fir::unwrapSequenceType(inType); if (numParams > 0) { - if (auto recTy = ty.dyn_cast()) + if (auto recTy = mlir::dyn_cast(ty)) return numParams != recTy.getNumLenParams(); - if (auto chrTy = ty.dyn_cast()) + if (auto chrTy = mlir::dyn_cast(ty)) return !(numParams == 1 && chrTy.hasDynamicLen()); return true; } - if (auto chrTy = ty.dyn_cast()) + if (auto chrTy = mlir::dyn_cast(ty)) return !chrTy.hasConstantLen(); return false; } @@ -159,13 +159,13 @@ /// 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 (intype.isa()) + if (mlir::isa(intype)) return {}; return fir::ReferenceType::get(intype); } mlir::Type fir::AllocaOp::getAllocatedType() { - return getType().cast().getEleTy(); + return mlir::cast(getType()).getEleTy(); } mlir::Type fir::AllocaOp::getRefTy(mlir::Type ty) { @@ -258,7 +258,7 @@ if (verifyTypeParamCount(getInType(), numLenParams())) return emitOpError("LEN params do not correspond to type"); mlir::Type outType = getType(); - if (!outType.isa()) + if (!mlir::isa(outType)) 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"); @@ -274,14 +274,14 @@ // 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 (intype.isa()) + if (mlir::isa(intype)) return {}; return fir::HeapType::get(intype); } mlir::Type fir::AllocMemOp::getAllocatedType() { - return getType().cast().getEleTy(); + return mlir::cast(getType()).getEleTy(); } mlir::Type fir::AllocMemOp::getRefTy(mlir::Type ty) { @@ -336,7 +336,7 @@ if (verifyTypeParamCount(getInType(), numLenParams())) return emitOpError("LEN params do not correspond to type"); mlir::Type outType = getType(); - if (!outType.dyn_cast()) + if (!mlir::dyn_cast(outType)) 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"); @@ -352,13 +352,13 @@ static bool validTypeParams(mlir::Type dynTy, mlir::ValueRange typeParams) { dynTy = fir::unwrapAllRefAndSeqType(dynTy); // A box value will contain type parameter values itself. - if (dynTy.isa()) + if (mlir::isa(dynTy)) return typeParams.size() == 0; // Derived type must have all type parameters satisfied. - if (auto recTy = dynTy.dyn_cast()) + if (auto recTy = mlir::dyn_cast(dynTy)) return typeParams.size() == recTy.getNumLenParams(); // Characters with non-constant LEN must have a type parameter value. - if (auto charTy = dynTy.dyn_cast()) + if (auto charTy = mlir::dyn_cast(dynTy)) if (charTy.hasDynamicLen()) return typeParams.size() == 1; // Otherwise, any type parameters are invalid. @@ -367,7 +367,7 @@ mlir::LogicalResult fir::ArrayCoorOp::verify() { auto eleTy = fir::dyn_cast_ptrOrBoxEleTy(getMemref().getType()); - auto arrTy = eleTy.dyn_cast(); + auto arrTy = mlir::dyn_cast(eleTy); if (!arrTy) return emitOpError("must be a reference to an array"); auto arrDim = arrTy.getDimension(); @@ -375,14 +375,14 @@ if (auto shapeOp = getShape()) { auto shapeTy = shapeOp.getType(); unsigned shapeTyRank = 0; - if (auto s = shapeTy.dyn_cast()) { + if (auto s = mlir::dyn_cast(shapeTy)) { shapeTyRank = s.getRank(); - } else if (auto ss = shapeTy.dyn_cast()) { + } else if (auto ss = mlir::dyn_cast(shapeTy)) { shapeTyRank = ss.getRank(); } else { - auto s = shapeTy.cast(); + auto s = mlir::cast(shapeTy); shapeTyRank = s.getRank(); - if (!getMemref().getType().isa()) + if (!mlir::isa(getMemref().getType())) return emitOpError("shift can only be provided with fir.box memref"); } if (arrDim && arrDim != shapeTyRank) @@ -395,7 +395,7 @@ 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 = sliceOp.getType().dyn_cast()) + if (auto sliceTy = mlir::dyn_cast(sliceOp.getType())) if (sliceTy.getRank() != arrDim) return emitOpError("rank of dimension in slice mismatched"); } @@ -410,13 +410,13 @@ //===----------------------------------------------------------------------===// static mlir::Type adjustedElementType(mlir::Type t) { - if (auto ty = t.dyn_cast()) { + if (auto ty = mlir::dyn_cast(t)) { auto eleTy = ty.getEleTy(); if (fir::isa_char(eleTy)) return eleTy; if (fir::isa_derived(eleTy)) return eleTy; - if (eleTy.isa()) + if (mlir::isa(eleTy)) return eleTy; } return t; @@ -436,7 +436,7 @@ mlir::LogicalResult fir::ArrayLoadOp::verify() { auto eleTy = fir::dyn_cast_ptrOrBoxEleTy(getMemref().getType()); - auto arrTy = eleTy.dyn_cast(); + auto arrTy = mlir::dyn_cast(eleTy); if (!arrTy) return emitOpError("must be a reference to an array"); auto arrDim = arrTy.getDimension(); @@ -444,14 +444,14 @@ if (auto shapeOp = getShape()) { auto shapeTy = shapeOp.getType(); unsigned shapeTyRank = 0u; - if (auto s = shapeTy.dyn_cast()) { + if (auto s = mlir::dyn_cast(shapeTy)) { shapeTyRank = s.getRank(); - } else if (auto ss = shapeTy.dyn_cast()) { + } else if (auto ss = mlir::dyn_cast(shapeTy)) { shapeTyRank = ss.getRank(); } else { - auto s = shapeTy.cast(); + auto s = mlir::cast(shapeTy); shapeTyRank = s.getRank(); - if (!getMemref().getType().isa()) + if (!mlir::isa(getMemref().getType())) return emitOpError("shift can only be provided with fir.box memref"); } if (arrDim && arrDim != shapeTyRank) @@ -462,7 +462,7 @@ 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 = sliceOp.getType().dyn_cast()) + if (auto sliceTy = mlir::dyn_cast(sliceOp.getType())) if (sliceTy.getRank() != arrDim) return emitOpError("rank of dimension in slice mismatched"); } @@ -490,7 +490,7 @@ // 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 = eleTy.dyn_cast()) { + if (auto seqTy = mlir::dyn_cast(eleTy)) { auto projTy = fir::applyPathToType(seqTy.getEleTy(), sliceOp.getFields()); if (fir::unwrapSequenceType(getOriginal().getType()) != projTy) @@ -528,7 +528,7 @@ } mlir::LogicalResult fir::ArrayFetchOp::verify() { - auto arrTy = getSequence().getType().cast(); + auto arrTy = mlir::cast(getSequence().getType()); auto indSize = getIndices().size(); if (indSize < arrTy.getDimension()) return emitOpError("number of indices != dimension of array"); @@ -550,7 +550,7 @@ //===----------------------------------------------------------------------===// mlir::LogicalResult fir::ArrayAccessOp::verify() { - auto arrTy = getSequence().getType().cast(); + auto arrTy = mlir::cast(getSequence().getType()); std::size_t indSize = getIndices().size(); if (indSize < arrTy.getDimension()) return emitOpError("number of indices != dimension of array"); @@ -572,7 +572,7 @@ mlir::LogicalResult fir::ArrayUpdateOp::verify() { if (fir::isa_ref_type(getMerge().getType())) return emitOpError("does not support reference type for merge"); - auto arrTy = getSequence().getType().cast(); + auto arrTy = mlir::cast(getSequence().getType()); auto indSize = getIndices().size(); if (indSize < arrTy.getDimension()) return emitOpError("number of indices != dimension of array"); @@ -592,7 +592,7 @@ //===----------------------------------------------------------------------===// mlir::LogicalResult fir::ArrayModifyOp::verify() { - auto arrTy = getSequence().getType().cast(); + auto arrTy = mlir::cast(getSequence().getType()); auto indSize = getIndices().size(); if (indSize < arrTy.getDimension()) return emitOpError("number of indices must match array dimension"); @@ -724,7 +724,7 @@ parser.parseType(type)) return mlir::failure(); - auto funcType = type.dyn_cast(); + auto funcType = mlir::dyn_cast(type); if (!funcType) return parser.emitError(parser.getNameLoc(), "expected function type"); if (isDirect) { @@ -769,7 +769,7 @@ mlir::LogicalResult fir::CharConvertOp::verify() { auto unwrap = [&](mlir::Type t) { t = fir::unwrapSequenceType(fir::dyn_cast_ptrEleTy(t)); - return t.dyn_cast(); + return mlir::dyn_cast(t); }; auto inTy = unwrap(getFrom().getType()); auto outTy = unwrap(getTo().getType()); @@ -816,13 +816,13 @@ parser.resolveOperands(ops, type, result.operands)) return mlir::failure(); - if (!predicateNameAttr.isa()) + if (!mlir::isa(predicateNameAttr)) return parser.emitError(parser.getNameLoc(), "expected string comparison predicate attribute"); // Rewrite string attribute to an enum value. llvm::StringRef predicateName = - predicateNameAttr.cast().getValue(); + mlir::cast(predicateNameAttr).getValue(); auto predicate = fir::CmpcOp::getPredicateByName(predicateName); auto builder = parser.getBuilder(); mlir::Type i1Type = builder.getI1Type(); @@ -890,7 +890,7 @@ } mlir::LogicalResult fir::ConstcOp::verify() { - if (!getType().isa()) + if (!mlir::isa(getType())) return emitOpError("must be a !fir.complex type"); return mlir::success(); } @@ -913,15 +913,16 @@ if (matchPattern(getValue(), mlir::m_Op())) { auto inner = mlir::cast(getValue().getDefiningOp()); // (convert (convert 'a : logical -> i1) : i1 -> logical) ==> forward 'a - if (auto toTy = getType().dyn_cast()) - if (auto fromTy = inner.getValue().getType().dyn_cast()) - if (inner.getType().isa() && (toTy == fromTy)) + if (auto toTy = mlir::dyn_cast(getType())) + if (auto fromTy = + mlir::dyn_cast(inner.getValue().getType())) + if (mlir::isa(inner.getType()) && (toTy == fromTy)) return inner.getValue(); // (convert (convert 'a : i1 -> logical) : logical -> i1) ==> forward 'a - if (auto toTy = getType().dyn_cast()) + if (auto toTy = mlir::dyn_cast(getType())) if (auto fromTy = - inner.getValue().getType().dyn_cast()) - if (inner.getType().isa() && (toTy == fromTy) && + mlir::dyn_cast(inner.getValue().getType())) + if (mlir::isa(inner.getType()) && (toTy == fromTy) && (fromTy.getWidth() == 1)) return inner.getValue(); } @@ -929,18 +930,18 @@ } bool fir::ConvertOp::isIntegerCompatible(mlir::Type ty) { - return ty.isa(); + return mlir::isa(ty); } bool fir::ConvertOp::isFloatCompatible(mlir::Type ty) { - return ty.isa(); + return mlir::isa(ty); } bool fir::ConvertOp::isPointerCompatible(mlir::Type ty) { - return ty.isa(); + return mlir::isa(ty); } bool fir::ConvertOp::canBeConverted(mlir::Type inType, mlir::Type outType) { @@ -953,12 +954,14 @@ (isFloatCompatible(inType) && isFloatCompatible(outType)) || (isIntegerCompatible(inType) && isPointerCompatible(outType)) || (isPointerCompatible(inType) && isIntegerCompatible(outType)) || - (inType.isa() && outType.isa()) || - (inType.isa() && outType.isa()) || + (mlir::isa(inType) && + mlir::isa(outType)) || + (mlir::isa(inType) && + mlir::isa(outType)) || (fir::isa_complex(inType) && fir::isa_complex(outType)) || (fir::isBoxedRecordType(inType) && fir::isPolymorphicType(outType)) || (fir::isPolymorphicType(inType) && fir::isPolymorphicType(outType)) || - (fir::isPolymorphicType(inType) && outType.isa()); + (fir::isPolymorphicType(inType) && mlir::isa(outType)); } mlir::LogicalResult fir::ConvertOp::verify() { @@ -1005,7 +1008,7 @@ const mlir::Type refTy = getRef().getType(); if (fir::isa_ref_type(refTy)) { auto eleTy = fir::dyn_cast_ptrEleTy(refTy); - if (auto arrTy = eleTy.dyn_cast()) { + if (auto arrTy = mlir::dyn_cast(eleTy)) { if (arrTy.hasUnknownShape()) return emitOpError("cannot find coordinate in unknown shape"); if (arrTy.getConstantRows() < arrTy.getDimension() - 1) @@ -1020,8 +1023,8 @@ const unsigned numCoors = getCoor().size(); for (auto coorOperand : llvm::enumerate(getCoor())) { auto co = coorOperand.value(); - if (dimension == 0 && eleTy.isa()) { - dimension = eleTy.cast().getDimension(); + if (dimension == 0 && mlir::isa(eleTy)) { + dimension = mlir::cast(eleTy).getDimension(); if (dimension == 0) return emitOpError("cannot apply to array of unknown rank"); } @@ -1030,7 +1033,7 @@ // 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 (refTy.isa()) { + if (mlir::isa(refTy)) { if (coorOperand.index() != numCoors - 1) return emitOpError("len_param_index must be last argument"); if (getNumOperands() != 2) @@ -1043,7 +1046,7 @@ } else if (auto index = mlir::dyn_cast(defOp)) { if (eleTy != index.getOnType()) emitOpError("field_index type not compatible with reference type"); - if (auto recTy = eleTy.dyn_cast()) { + if (auto recTy = mlir::dyn_cast(eleTy)) { eleTy = recTy.getType(index.getFieldName()); continue; } @@ -1052,21 +1055,21 @@ } if (dimension) { if (--dimension == 0) - eleTy = eleTy.cast().getEleTy(); + eleTy = mlir::cast(eleTy).getEleTy(); } else { - if (auto t = eleTy.dyn_cast()) { + if (auto t = mlir::dyn_cast(eleTy)) { // 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 = eleTy.dyn_cast()) { + } else if (auto t = mlir::dyn_cast(eleTy)) { // FIXME: This is the same as the tuple case. return mlir::success(); - } else if (auto t = eleTy.dyn_cast()) { + } else if (auto t = mlir::dyn_cast(eleTy)) { eleTy = t.getElementType(); - } else if (auto t = eleTy.dyn_cast()) { + } else if (auto t = mlir::dyn_cast(eleTy)) { eleTy = t.getElementType(); - } else if (auto t = eleTy.dyn_cast()) { + } else if (auto t = mlir::dyn_cast(eleTy)) { if (t.getLen() == fir::CharacterType::singleton()) return emitOpError("cannot apply to character singleton"); eleTy = fir::CharacterType::getSingleton(t.getContext(), t.getFKind()); @@ -1181,17 +1184,17 @@ mlir::LogicalResult fir::EmboxOp::verify() { auto eleTy = fir::dyn_cast_ptrEleTy(getMemref().getType()); bool isArray = false; - if (auto seqTy = eleTy.dyn_cast()) { + if (auto seqTy = mlir::dyn_cast(eleTy)) { eleTy = seqTy.getEleTy(); isArray = true; } if (hasLenParams()) { auto lenPs = numLenParams(); - if (auto rt = eleTy.dyn_cast()) { + if (auto rt = mlir::dyn_cast(eleTy)) { if (lenPs != rt.getNumLenParams()) return emitOpError("number of LEN params does not correspond" " to the !fir.type type"); - } else if (auto strTy = eleTy.dyn_cast()) { + } else if (auto strTy = mlir::dyn_cast(eleTy)) { if (strTy.getLen() != fir::CharacterType::unknownLen()) return emitOpError("CHARACTER already has static LEN"); } else { @@ -1205,7 +1208,7 @@ 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() && !getResult().getType().isa()) + if (getSourceBox() && !mlir::isa(getResult().getType())) return emitOpError("source_box must be used with fir.class result type"); return mlir::success(); } @@ -1216,7 +1219,7 @@ mlir::LogicalResult fir::EmboxCharOp::verify() { auto eleTy = fir::dyn_cast_ptrEleTy(getMemref().getType()); - if (!eleTy.dyn_cast_or_null()) + if (!mlir::dyn_cast_if_present(eleTy)) return mlir::failure(); return mlir::success(); } @@ -1228,8 +1231,8 @@ mlir::LogicalResult fir::EmboxProcOp::verify() { // host bindings (optional) must be a reference to a tuple if (auto h = getHost()) { - if (auto r = h.getType().dyn_cast()) - if (r.getEleTy().isa()) + if (auto r = mlir::dyn_cast(h.getType())) + if (mlir::isa(r.getEleTy())) return mlir::success(); return mlir::failure(); } @@ -1265,7 +1268,7 @@ mlir::LogicalResult fir::TypeDescOp::verify() { mlir::Type resultTy = getType(); - if (auto tdesc = resultTy.dyn_cast()) { + if (auto tdesc = mlir::dyn_cast(resultTy)) { if (tdesc.getOfTy() != getInType()) return emitOpError("wrapped type mismatched"); return mlir::success(); @@ -1482,7 +1485,7 @@ return mlir::failure(); result.addAttribute(fir::FieldIndexOp::getFieldAttrName(), builder.getStringAttr(fieldName)); - if (!recty.dyn_cast()) + if (!mlir::dyn_cast(recty)) return mlir::failure(); result.addAttribute(fir::FieldIndexOp::getTypeAttrName(), mlir::TypeAttr::get(recty)); @@ -1626,7 +1629,7 @@ //===----------------------------------------------------------------------===// static bool checkIsIntegerConstant(mlir::Attribute attr, std::int64_t conVal) { - if (auto iattr = attr.dyn_cast()) + if (auto iattr = mlir::dyn_cast(attr)) return iattr.getInt() == conVal; return false; } @@ -1645,7 +1648,7 @@ matchAndRewrite(mlir::Operation *op, mlir::PatternRewriter &rewriter) const override { auto insval = mlir::dyn_cast_or_null(op); - if (!insval || !insval.getType().isa()) + if (!insval || !mlir::isa(insval.getType())) return mlir::failure(); auto insval2 = mlir::dyn_cast_or_null( insval.getAdt().getDefiningOp()); @@ -1774,7 +1777,7 @@ parser.parseRParen()) return mlir::failure(); // Type list must be "(index, i1)". - if (typeList.size() != 2 || !typeList[0].isa() || + if (typeList.size() != 2 || !mlir::isa(typeList[0]) || !typeList[1].isSignlessInteger(1)) return mlir::failure(); result.addTypes(typeList); @@ -1828,7 +1831,7 @@ auto opNumResults = getNumResults(); if (getFinalValue()) { // Result type must be "(index, i1, ...)". - if (!getResult(0).getType().isa()) + if (!mlir::isa(getResult(0).getType())) return emitOpError("result #0 expected to be index"); if (!getResult(1).getType().isSignlessInteger(1)) return emitOpError("result #1 expected to be i1"); @@ -2101,7 +2104,7 @@ } fir::DoLoopOp fir::getForInductionVarOwner(mlir::Value val) { - auto ivArg = val.dyn_cast(); + auto ivArg = mlir::dyn_cast(val); if (!ivArg) return {}; assert(ivArg.getOwner() && "unlinked block argument"); @@ -2244,7 +2247,7 @@ /// Example: return f32 for !fir.box>. static mlir::Type getBoxScalarEleTy(mlir::Type boxTy) { auto eleTy = fir::dyn_cast_ptrOrBoxEleTy(boxTy); - if (auto seqTy = eleTy.dyn_cast()) + if (auto seqTy = mlir::dyn_cast(eleTy)) return seqTy.getEleTy(); return eleTy; } @@ -2252,8 +2255,8 @@ /// 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 = t1.dyn_cast(); - auto c2 = t2.dyn_cast(); + auto c1 = mlir::dyn_cast(t1); + auto c2 = mlir::dyn_cast(t2); if (!c1 || !c2) return false; if (c1.hasDynamicLen() || c2.hasDynamicLen()) @@ -2275,10 +2278,10 @@ if (auto sliceVal = getSlice()) { // Slicing case - if (sliceVal.getType().cast().getRank() != inputRank) + if (mlir::cast(sliceVal.getType()).getRank() != inputRank) return emitOpError("slice operand rank must match box operand rank"); if (auto shapeVal = getShape()) { - if (auto shiftTy = shapeVal.getType().dyn_cast()) { + if (auto shiftTy = mlir::dyn_cast(shapeVal.getType())) { if (shiftTy.getRank() != inputRank) return emitOpError("shape operand and input box ranks must match " "when there is a slice"); @@ -2298,12 +2301,12 @@ unsigned shapeRank = inputRank; if (auto shapeVal = getShape()) { auto ty = shapeVal.getType(); - if (auto shapeTy = ty.dyn_cast()) { + if (auto shapeTy = mlir::dyn_cast(ty)) { shapeRank = shapeTy.getRank(); - } else if (auto shapeShiftTy = ty.dyn_cast()) { + } else if (auto shapeShiftTy = mlir::dyn_cast(ty)) { shapeRank = shapeShiftTy.getRank(); } else { - auto shiftTy = ty.cast(); + auto shiftTy = mlir::cast(ty); shapeRank = shiftTy.getRank(); if (shapeRank != inputRank) return emitOpError("shape operand and input box ranks must match " @@ -2322,11 +2325,13 @@ // the types is a character with dynamic length, the other type can be any // character type. const bool typeCanMismatch = - inputEleTy.isa() || outEleTy.isa() || - (inputEleTy.isa() && outEleTy.isa()) || - (getSlice() && inputEleTy.isa()) || + mlir::isa(inputEleTy) || + mlir::isa(outEleTy) || + (mlir::isa(inputEleTy) && + mlir::isa(outEleTy)) || + (getSlice() && mlir::isa(inputEleTy)) || (getSlice() && fir::isa_complex(inputEleTy) && - outEleTy.isa()) || + mlir::isa(outEleTy)) || areCompatibleCharacterTypes(inputEleTy, outEleTy); if (!typeCanMismatch) return emitOpError( @@ -2363,7 +2368,7 @@ if (fir::isa_unknown_size_box(resultType)) return emitOpError("cannot save !fir.box of unknown rank or type"); - if (resultType.isa()) { + if (mlir::isa(resultType)) { if (getShape() || !getTypeparams().empty()) return emitOpError( "must not have shape or length operands if the value is a fir.box"); @@ -2374,14 +2379,14 @@ unsigned shapeTyRank = 0; if (auto shapeVal = getShape()) { auto shapeTy = shapeVal.getType(); - if (auto s = shapeTy.dyn_cast()) + if (auto s = mlir::dyn_cast(shapeTy)) shapeTyRank = s.getRank(); else - shapeTyRank = shapeTy.cast().getRank(); + shapeTyRank = mlir::cast(shapeTy).getRank(); } auto eleTy = resultType; - if (auto seqTy = resultType.dyn_cast()) { + if (auto seqTy = mlir::dyn_cast(resultType)) { if (seqTy.getDimension() != shapeTyRank) emitOpError("shape operand must be provided and have the value rank " "when the value is a fir.array"); @@ -2392,11 +2397,11 @@ "shape operand should only be provided if the value is a fir.array"); } - if (auto recTy = eleTy.dyn_cast()) { + if (auto recTy = mlir::dyn_cast(eleTy)) { if (recTy.getNumLenParams() != getTypeparams().size()) emitOpError("length parameters number must match with the value type " "length parameters"); - } else if (auto charTy = eleTy.dyn_cast()) { + } else if (auto charTy = mlir::dyn_cast(eleTy)) { if (getTypeparams().size() > 1) emitOpError("no more than one length parameter must be provided for " "character value"); @@ -2421,10 +2426,8 @@ template static mlir::LogicalResult verifyIntegralSwitchTerminator(OpT op) { - if (!op.getSelector() - .getType() - .template isa()) + if (!mlir::isa( + op.getSelector().getType())) return op.emitOpError("must be an integer"); auto cases = op->template getAttrOfType(op.getCasesAttr()).getValue(); @@ -2436,7 +2439,7 @@ if (op.targetOffsetSize() != count) return op.emitOpError("incorrect number of successor operand groups"); for (decltype(count) i = 0; i != count; ++i) { - if (!cases[i].template isa()) + if (!mlir::isa(cases[i])) return op.emitOpError("invalid case alternative"); } return mlir::success(); @@ -2499,7 +2502,7 @@ if (i) p << ", "; auto &attr = cases[i]; - if (auto intAttr = attr.template dyn_cast_or_null()) + if (auto intAttr = mlir::dyn_cast_if_present(attr)) p << intAttr.getValue(); else p.printAttribute(attr); @@ -2548,7 +2551,7 @@ *owner->getAttrDictionary().getNamed(offsetAttr); return getSubOperands( pos, operands, - targetOffsetAttr.getValue().cast(), + mlir::cast(targetOffsetAttr.getValue()), mlir::MutableOperandRange::OperandSegment(pos, targetOffsetAttr)); } @@ -2670,9 +2673,9 @@ parser.parseComma()) return mlir::failure(); attrs.push_back(attr); - if (attr.dyn_cast_or_null()) { + if (mlir::dyn_cast_if_present(attr)) { argOffs.push_back(0); - } else if (attr.dyn_cast_or_null()) { + } else if (mlir::dyn_cast_if_present(attr)) { mlir::OpAsmParser::UnresolvedOperand oper1; mlir::OpAsmParser::UnresolvedOperand oper2; if (parser.parseOperand(oper1) || parser.parseComma() || @@ -2734,11 +2737,11 @@ if (i) p << ", "; p << cases[i] << ", "; - if (!cases[i].isa()) { + if (!mlir::isa(cases[i])) { auto caseArgs = *getCompareOperands(i); p.printOperand(*caseArgs.begin()); p << ", "; - if (cases[i].isa()) { + if (mlir::isa(cases[i])) { p.printOperand(*(++caseArgs.begin())); p << ", "; } @@ -2776,10 +2779,10 @@ llvm::SmallVector operOffs; int32_t operSize = 0; for (auto attr : compareAttrs) { - if (attr.isa()) { + if (mlir::isa(attr)) { operOffs.push_back(2); operSize += 2; - } else if (attr.isa()) { + } else if (mlir::isa(attr)) { operOffs.push_back(0); } else { operOffs.push_back(1); @@ -2828,10 +2831,10 @@ llvm::SmallVector cmpOpers; auto iter = cmpOpList.begin(); for (auto &attr : compareAttrs) { - if (attr.isa()) { + if (mlir::isa(attr)) { cmpOpers.push_back(mlir::ValueRange({iter, iter + 2})); iter += 2; - } else if (attr.isa()) { + } else if (mlir::isa(attr)) { cmpOpers.push_back(mlir::ValueRange{}); } else { cmpOpers.push_back(mlir::ValueRange({iter, iter + 1})); @@ -2843,10 +2846,8 @@ } mlir::LogicalResult fir::SelectCaseOp::verify() { - if (!getSelector() - .getType() - .isa()) + if (!mlir::isa(getSelector().getType())) return emitOpError("must be an integer, character, or logical"); auto cases = getOperation()->getAttrOfType(getCasesAttr()).getValue(); @@ -2861,9 +2862,11 @@ return emitOpError("incorrect number of successor operand groups"); for (decltype(count) i = 0; i != count; ++i) { auto &attr = cases[i]; - if (!(attr.isa() || - attr.isa() || attr.isa() || - attr.isa() || attr.isa())) + if (!(mlir::isa(attr) || + mlir::isa(attr) || + mlir::isa(attr) || + mlir::isa(attr) || + mlir::isa(attr))) return emitOpError("incorrect select case attribute type"); } return mlir::success(); @@ -3039,14 +3042,14 @@ } mlir::LogicalResult fir::SelectTypeOp::verify() { - if (!(getSelector().getType().isa())) + if (!(mlir::isa(getSelector().getType()))) return emitOpError("must be a fir.class or fir.box type"); - if (auto boxType = getSelector().getType().dyn_cast()) - if (!boxType.getEleTy().isa()) + if (auto boxType = mlir::dyn_cast(getSelector().getType())) + if (!mlir::isa(boxType.getEleTy())) return emitOpError("selector must be polymorphic"); auto typeGuardAttr = getCases(); for (unsigned idx = 0; idx < typeGuardAttr.size(); ++idx) - if (typeGuardAttr[idx].isa() && + if (mlir::isa(typeGuardAttr[idx]) && idx != typeGuardAttr.size() - 1) return emitOpError("default must be the last attribute"); auto count = getNumDest(); @@ -3057,9 +3060,9 @@ if (targetOffsetSize() != count) return emitOpError("incorrect number of successor operand groups"); for (unsigned i = 0; i != count; ++i) { - if (!(typeGuardAttr[i].isa() || - typeGuardAttr[i].isa() || - typeGuardAttr[i].isa())) + if (!(mlir::isa(typeGuardAttr[i]) || + mlir::isa(typeGuardAttr[i]) || + mlir::isa(typeGuardAttr[i]))) return emitOpError("invalid type-case alternative"); } return mlir::success(); @@ -3103,7 +3106,7 @@ mlir::LogicalResult fir::ShapeOp::verify() { auto size = getExtents().size(); - auto shapeTy = getType().dyn_cast(); + auto shapeTy = mlir::dyn_cast(getType()); assert(shapeTy && "must be a shape type"); if (shapeTy.getRank() != size) return emitOpError("shape type rank mismatch"); @@ -3126,7 +3129,7 @@ return emitOpError("incorrect number of args"); if (size % 2 != 0) return emitOpError("requires a multiple of 2 args"); - auto shapeTy = getType().dyn_cast(); + auto shapeTy = mlir::dyn_cast(getType()); assert(shapeTy && "must be a shape shift type"); if (shapeTy.getRank() * 2 != size) return emitOpError("shape type rank mismatch"); @@ -3139,7 +3142,7 @@ mlir::LogicalResult fir::ShiftOp::verify() { auto size = getOrigins().size(); - auto shiftTy = getType().dyn_cast(); + auto shiftTy = mlir::dyn_cast(getType()); assert(shiftTy && "must be a shift type"); if (shiftTy.getRank() != size) return emitOpError("shift type rank mismatch"); @@ -3179,7 +3182,7 @@ return emitOpError("incorrect number of args for triple"); if (size % 3 != 0) return emitOpError("requires a multiple of 3 args"); - auto sliceTy = getType().dyn_cast(); + auto sliceTy = mlir::dyn_cast(getType()); assert(sliceTy && "must be a slice type"); if (sliceTy.getRank() * 3 != size) return emitOpError("slice type rank mismatch"); @@ -3232,8 +3235,8 @@ //===----------------------------------------------------------------------===// inline fir::CharacterType::KindTy stringLitOpGetKind(fir::StringLitOp op) { - auto eleTy = op.getType().cast().getEleTy(); - return eleTy.cast().getFKind(); + auto eleTy = mlir::cast(op.getType()).getEleTy(); + return mlir::cast(eleTy).getFKind(); } bool fir::StringLitOp::isWideValue() { return stringLitOpGetKind(*this) != 1; } @@ -3313,13 +3316,13 @@ llvm::SMLoc trailingTypeLoc; if (parser.parseAttribute(val, "fake", attrs)) return mlir::failure(); - if (auto v = val.dyn_cast()) + if (auto v = mlir::dyn_cast(val)) result.attributes.push_back( builder.getNamedAttr(fir::StringLitOp::value(), v)); - else if (auto v = val.dyn_cast()) + else if (auto v = mlir::dyn_cast(val)) result.attributes.push_back( builder.getNamedAttr(fir::StringLitOp::xlist(), v)); - else if (auto v = val.dyn_cast()) + else if (auto v = mlir::dyn_cast(val)) result.attributes.push_back( builder.getNamedAttr(fir::StringLitOp::xlist(), v)); else @@ -3332,7 +3335,7 @@ parser.parseRParen() || parser.getCurrentLocation(&trailingTypeLoc) || parser.parseColonType(type)) return mlir::failure(); - auto charTy = type.dyn_cast(); + auto charTy = mlir::dyn_cast(type); if (!charTy) return parser.emitError(trailingTypeLoc, "must have character type"); type = fir::CharacterType::get(builder.getContext(), charTy.getFKind(), @@ -3344,19 +3347,19 @@ void fir::StringLitOp::print(mlir::OpAsmPrinter &p) { p << ' ' << getValue() << '('; - p << getSize().cast().getValue() << ") : "; + p << mlir::cast(getSize()).getValue() << ") : "; p.printType(getType()); } mlir::LogicalResult fir::StringLitOp::verify() { - if (getSize().cast().getValue().isNegative()) + if (mlir::cast(getSize()).getValue().isNegative()) return emitOpError("size must be non-negative"); if (auto xl = getOperation()->getAttr(fir::StringLitOp::xlist())) { - if (auto xList = xl.dyn_cast()) { + if (auto xList = mlir::dyn_cast(xl)) { for (auto a : xList) - if (!a.isa()) + if (!mlir::isa(a)) return emitOpError("values in initializer must be integers"); - } else if (xl.isa()) { + } else if (mlir::isa(xl)) { // do nothing } else { return emitOpError("has unexpected attribute"); @@ -3371,7 +3374,7 @@ mlir::LogicalResult fir::UnboxProcOp::verify() { if (auto eleTy = fir::dyn_cast_ptrEleTy(getRefTuple().getType())) - if (eleTy.isa()) + if (mlir::isa(eleTy)) return mlir::success(); return emitOpError("second output argument has bad type"); } @@ -3427,7 +3430,8 @@ // Otherwise, the successor is dependent on the condition. bool condition; - if (auto condAttr = operands.front().dyn_cast_or_null()) { + if (auto condAttr = + mlir::dyn_cast_if_present(operands.front())) { condition = condAttr.getValue().isOne(); } else { // If the condition isn't constant, both regions may be executed. @@ -3446,7 +3450,7 @@ void fir::IfOp::getRegionInvocationBounds( llvm::ArrayRef operands, llvm::SmallVectorImpl &invocationBounds) { - if (auto cond = operands[0].dyn_cast_or_null()) { + if (auto cond = mlir::dyn_cast_if_present(operands[0])) { // 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); @@ -3532,8 +3536,8 @@ //===----------------------------------------------------------------------===// mlir::ParseResult fir::isValidCaseAttr(mlir::Attribute attr) { - if (attr.isa()) + if (mlir::isa(attr)) return mlir::success(); return mlir::failure(); } @@ -3543,9 +3547,9 @@ unsigned o = 0; for (unsigned i = 0; i < dest; ++i) { auto &attr = cases[i]; - if (!attr.dyn_cast_or_null()) { + if (!mlir::dyn_cast_if_present(attr)) { ++o; - if (attr.dyn_cast_or_null()) + if (mlir::dyn_cast_if_present(attr)) ++o; } } @@ -3590,7 +3594,7 @@ bool fir::hasHostAssociationArgument(mlir::func::FuncOp func) { if (auto allArgAttrs = func.getAllArgAttrs()) for (auto attr : allArgAttrs) - if (auto dict = attr.template dyn_cast_or_null()) + if (auto dict = mlir::dyn_cast_if_present(attr)) if (dict.get(fir::getHostAssocAttrName())) return true; return false; @@ -3640,12 +3644,12 @@ }; // If this is a fir.box that was loaded, the fir attributes will be on the // related fir.ref creation. - if (value.getType().isa()) + if (mlir::isa(value.getType())) if (auto definingOp = value.getDefiningOp()) if (auto loadOp = mlir::dyn_cast(definingOp)) value = loadOp.getMemref(); // If this is a function argument, look in the argument attributes. - if (auto blockArg = value.dyn_cast()) { + if (auto blockArg = mlir::dyn_cast(value)) { if (blockArg.getOwner() && blockArg.getOwner()->isEntryBlock()) if (auto funcOp = mlir::dyn_cast( blockArg.getOwner()->getParentOp())) diff --git a/flang/lib/Optimizer/Dialect/FIRType.cpp b/flang/lib/Optimizer/Dialect/FIRType.cpp --- a/flang/lib/Optimizer/Dialect/FIRType.cpp +++ b/flang/lib/Optimizer/Dialect/FIRType.cpp @@ -60,14 +60,15 @@ /// 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 ty.isa() || ty.isa(); + return mlir::isa(ty) || mlir::isa(ty); } bool verifyRecordMemberType(mlir::Type ty) { - return !(ty.isa() || ty.isa() || - ty.isa() || ty.isa() || - ty.isa() || ty.isa() || ty.isa() || - ty.isa() || ty.isa()); + return !(mlir::isa(ty) || mlir::isa(ty) || + mlir::isa(ty) || mlir::isa(ty) || + mlir::isa(ty) || mlir::isa(ty) || + mlir::isa(ty) || mlir::isa(ty) || + mlir::isa(ty)); } bool verifySameLists(llvm::ArrayRef a1, @@ -185,15 +186,15 @@ } bool isa_fir_type(mlir::Type t) { - return llvm::isa(t.getDialect()); + return mlir::isa(t.getDialect()); } bool isa_std_type(mlir::Type t) { - return llvm::isa(t.getDialect()); + return mlir::isa(t.getDialect()); } bool isa_fir_or_std_type(mlir::Type t) { - if (auto funcType = t.dyn_cast()) + if (auto funcType = mlir::dyn_cast(t)) 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 @@ mlir::Type getDerivedType(mlir::Type ty) { return llvm::TypeSwitch(ty) .Case([](auto p) { - if (auto seq = p.getEleTy().template dyn_cast()) + if (auto seq = mlir::dyn_cast(p.getEleTy())) return seq.getEleTy(); return p.getEleTy(); }) @@ -227,12 +228,12 @@ static bool hasDynamicSize(fir::RecordType recTy) { for (auto field : recTy.getTypeList()) { - if (auto arr = field.second.dyn_cast()) { + if (auto arr = mlir::dyn_cast(field.second)) { if (sequenceWithNonConstantShape(arr)) return true; } else if (characterWithDynamicLen(field.second)) { return true; - } else if (auto rec = field.second.dyn_cast()) { + } else if (auto rec = mlir::dyn_cast(field.second)) { if (hasDynamicSize(rec)) return true; } @@ -241,14 +242,14 @@ } bool hasDynamicSize(mlir::Type t) { - if (auto arr = t.dyn_cast()) { + if (auto arr = mlir::dyn_cast(t)) { if (sequenceWithNonConstantShape(arr)) return true; t = arr.getEleTy(); } if (characterWithDynamicLen(t)) return true; - if (auto rec = t.dyn_cast()) + if (auto rec = mlir::dyn_cast(t)) return hasDynamicSize(rec); return false; } @@ -256,33 +257,33 @@ bool isPointerType(mlir::Type ty) { if (auto refTy = fir::dyn_cast_ptrEleTy(ty)) ty = refTy; - if (auto boxTy = ty.dyn_cast()) - return boxTy.getEleTy().isa(); + if (auto boxTy = mlir::dyn_cast(ty)) + return mlir::isa(boxTy.getEleTy()); return false; } bool isAllocatableType(mlir::Type ty) { if (auto refTy = fir::dyn_cast_ptrEleTy(ty)) ty = refTy; - if (auto boxTy = ty.dyn_cast()) - return boxTy.getEleTy().isa(); + if (auto boxTy = mlir::dyn_cast(ty)) + return mlir::isa(boxTy.getEleTy()); return false; } bool isBoxNone(mlir::Type ty) { - if (auto box = ty.dyn_cast()) - return box.getEleTy().isa(); + if (auto box = mlir::dyn_cast(ty)) + return mlir::isa(box.getEleTy()); return false; } bool isBoxedRecordType(mlir::Type ty) { if (auto refTy = fir::dyn_cast_ptrEleTy(ty)) ty = refTy; - if (auto boxTy = ty.dyn_cast()) { - if (boxTy.getEleTy().isa()) + if (auto boxTy = mlir::dyn_cast(ty)) { + if (mlir::isa(boxTy.getEleTy())) return true; mlir::Type innerType = boxTy.unwrapInnerType(); - return innerType && innerType.isa(); + return innerType && mlir::isa(innerType); } return false; } @@ -290,23 +291,23 @@ bool isScalarBoxedRecordType(mlir::Type ty) { if (auto refTy = fir::dyn_cast_ptrEleTy(ty)) ty = refTy; - if (auto boxTy = ty.dyn_cast()) { - if (boxTy.getEleTy().isa()) + if (auto boxTy = mlir::dyn_cast(ty)) { + if (mlir::isa(boxTy.getEleTy())) return true; - if (auto heapTy = boxTy.getEleTy().dyn_cast()) - return heapTy.getEleTy().isa(); - if (auto ptrTy = boxTy.getEleTy().dyn_cast()) - return ptrTy.getEleTy().isa(); + 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()); } return false; } bool isAssumedType(mlir::Type ty) { - if (auto boxTy = ty.dyn_cast()) { - if (boxTy.getEleTy().isa()) + if (auto boxTy = mlir::dyn_cast(ty)) { + if (mlir::isa(boxTy.getEleTy())) return true; - if (auto seqTy = boxTy.getEleTy().dyn_cast()) - return seqTy.getEleTy().isa(); + if (auto seqTy = mlir::dyn_cast(boxTy.getEleTy())) + return mlir::isa(seqTy.getEleTy()); } return false; } @@ -315,7 +316,7 @@ if (auto refTy = fir::dyn_cast_ptrEleTy(ty)) ty = refTy; // CLASS(*) - if (ty.isa()) + if (mlir::isa(ty)) return true; // assumed type are polymorphic. return isAssumedType(ty); @@ -325,11 +326,11 @@ if (auto refTy = fir::dyn_cast_ptrEleTy(ty)) ty = refTy; // CLASS(*) - if (auto clTy = ty.dyn_cast()) { - if (clTy.getEleTy().isa()) + if (auto clTy = mlir::dyn_cast(ty)) { + if (mlir::isa(clTy.getEleTy())) return true; mlir::Type innerType = clTy.unwrapInnerType(); - return innerType && innerType.isa(); + return innerType && mlir::isa(innerType); } // TYPE(*) return isAssumedType(ty); @@ -339,7 +340,7 @@ return llvm::TypeSwitch(ty) .Case([](auto t) { mlir::Type eleTy = t.getEleTy(); - if (auto seqTy = eleTy.dyn_cast()) + if (auto seqTy = mlir::dyn_cast(eleTy)) return seqTy.getEleTy(); return eleTy; }) @@ -348,13 +349,14 @@ } bool isRecordWithAllocatableMember(mlir::Type ty) { - if (auto recTy = ty.dyn_cast()) + if (auto recTy = mlir::dyn_cast(ty)) 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 (memTy.isa() && isRecordWithAllocatableMember(memTy)) + if (mlir::isa(memTy) && + isRecordWithAllocatableMember(memTy)) return true; } return false; @@ -363,7 +365,7 @@ mlir::Type unwrapAllRefAndSeqType(mlir::Type ty) { while (true) { mlir::Type nt = unwrapSequenceType(unwrapRefType(ty)); - if (auto vecTy = nt.dyn_cast()) + if (auto vecTy = mlir::dyn_cast(nt)) nt = vecTy.getEleTy(); if (nt == ty) return ty; @@ -372,11 +374,11 @@ } mlir::Type unwrapSeqOrBoxedSeqType(mlir::Type ty) { - if (auto seqTy = ty.dyn_cast()) + if (auto seqTy = mlir::dyn_cast(ty)) return seqTy.getEleTy(); - if (auto boxTy = ty.dyn_cast()) { + if (auto boxTy = mlir::dyn_cast(ty)) { auto eleTy = unwrapRefType(boxTy.getEleTy()); - if (auto seqTy = eleTy.dyn_cast()) + if (auto seqTy = mlir::dyn_cast(eleTy)) return seqTy.getEleTy(); } return ty; @@ -384,7 +386,7 @@ unsigned getBoxRank(mlir::Type boxTy) { auto eleTy = fir::dyn_cast_ptrOrBoxEleTy(boxTy); - if (auto seqTy = eleTy.dyn_cast()) + if (auto seqTy = mlir::dyn_cast(eleTy)) return seqTy.getDimension(); return 0; } @@ -392,7 +394,7 @@ /// 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 = ty.dyn_cast()) { + if (mlir::IntegerType intTy = mlir::dyn_cast(ty)) { switch (intTy.getWidth()) { case 8: return CFI_type_int8_t; @@ -407,7 +409,7 @@ } llvm_unreachable("unsupported integer type"); } - if (fir::LogicalType logicalTy = ty.dyn_cast()) { + if (fir::LogicalType logicalTy = mlir::dyn_cast(ty)) { switch (kindMap.getLogicalBitsize(logicalTy.getFKind())) { case 8: return CFI_type_Bool; @@ -420,7 +422,7 @@ } llvm_unreachable("unsupported logical type"); } - if (mlir::FloatType floatTy = ty.dyn_cast()) { + if (mlir::FloatType floatTy = mlir::dyn_cast(ty)) { switch (floatTy.getWidth()) { case 16: return floatTy.isBF16() ? CFI_type_bfloat : CFI_type_half_float; @@ -436,13 +438,14 @@ llvm_unreachable("unsupported real type"); } if (fir::isa_complex(ty)) { - if (mlir::ComplexType complexTy = ty.dyn_cast()) { + if (mlir::ComplexType complexTy = mlir::dyn_cast(ty)) { mlir::FloatType floatTy = - complexTy.getElementType().cast(); + mlir::cast(complexTy.getElementType()); if (floatTy.isBF16()) return CFI_type_bfloat_Complex; width = floatTy.getWidth(); - } else if (fir::ComplexType complexTy = ty.dyn_cast()) { + } else if (fir::ComplexType complexTy = + mlir::dyn_cast(ty)) { auto FKind = complexTy.getFKind(); if (FKind == 3) return CFI_type_bfloat_Complex; @@ -462,7 +465,7 @@ } llvm_unreachable("unsupported complex size"); } - if (fir::CharacterType charTy = ty.dyn_cast()) { + if (fir::CharacterType charTy = mlir::dyn_cast(ty)) { switch (kindMap.getCharacterBitsize(charTy.getFKind())) { case 8: return CFI_type_char; @@ -475,7 +478,7 @@ } if (fir::isa_ref_type(ty)) return CFI_type_cptr; - if (ty.isa()) + if (mlir::isa(ty)) return CFI_type_struct; llvm_unreachable("unsupported type"); } @@ -492,12 +495,12 @@ name << "idx"; } else if (ty.isIntOrIndex()) { name << 'i' << ty.getIntOrFloatBitWidth(); - } else if (ty.isa()) { + } else if (mlir::isa(ty)) { name << 'f' << ty.getIntOrFloatBitWidth(); } else if (fir::isa_complex(ty)) { name << 'z'; if (auto cplxTy = mlir::dyn_cast_or_null(ty)) { - auto floatTy = cplxTy.getElementType().cast(); + auto floatTy = mlir::cast(cplxTy.getElementType()); name << floatTy.getWidth(); } else if (auto cplxTy = mlir::dyn_cast_or_null(ty)) { name << kindMap.getRealBitsize(cplxTy.getFKind()); @@ -538,7 +541,7 @@ } // namespace void fir::verifyIntegralType(mlir::Type type) { - if (isaIntegerType(type) || type.isa()) + if (isaIntegerType(type) || mlir::isa(type)) return; llvm::report_fatal_error("expected integral type"); } @@ -550,9 +553,9 @@ } bool fir::isa_unknown_size_box(mlir::Type t) { - if (auto boxTy = t.dyn_cast()) { + if (auto boxTy = mlir::dyn_cast(t)) { auto valueType = fir::unwrapPassByRefType(boxTy); - if (auto seqTy = valueType.dyn_cast()) + if (auto seqTy = mlir::dyn_cast(valueType)) if (seqTy.hasUnknownShape()) return true; } @@ -578,18 +581,18 @@ mlir::LogicalResult BoxProcType::verify(llvm::function_ref emitError, mlir::Type eleTy) { - if (eleTy.isa()) + if (mlir::isa(eleTy)) return mlir::success(); - if (auto refTy = eleTy.dyn_cast()) - if (refTy.isa()) + if (auto refTy = mlir::dyn_cast(eleTy)) + if (mlir::isa(refTy)) return mlir::success(); return emitError() << "invalid type for boxproc" << eleTy << '\n'; } static bool cannotBePointerOrHeapElementType(mlir::Type eleTy) { - return eleTy.isa(); + ReferenceType, TypeDescType>(eleTy); } //===----------------------------------------------------------------------===// @@ -599,7 +602,7 @@ mlir::LogicalResult fir::BoxType::verify(llvm::function_ref emitError, mlir::Type eleTy) { - if (eleTy.isa()) + if (mlir::isa(eleTy)) return emitError() << "invalid element type\n"; // TODO return mlir::success(); @@ -668,10 +671,10 @@ mlir::LogicalResult fir::ClassType::verify(llvm::function_ref emitError, mlir::Type eleTy) { - if (eleTy.isa()) + fir::ComplexType, mlir::ComplexType>(eleTy)) return mlir::success(); return emitError() << "invalid element type\n"; } @@ -936,8 +939,8 @@ mlir::LogicalResult fir::ReferenceType::verify( llvm::function_ref emitError, mlir::Type eleTy) { - if (eleTy.isa()) + if (mlir::isa(eleTy)) return emitError() << "cannot build a reference to type: " << eleTy << '\n'; return mlir::success(); } @@ -1012,9 +1015,10 @@ llvm::ArrayRef shape, mlir::Type eleTy, mlir::AffineMapAttr layoutMap) { // DIMENSION attribute can only be applied to an intrinsic or record type - if (eleTy.isa()) + ReferenceType, TypeDescType, fir::VectorType, SequenceType>( + eleTy)) return emitError() << "cannot build an array of this element type: " << eleTy << '\n'; return mlir::success(); @@ -1085,9 +1089,9 @@ mlir::LogicalResult fir::TypeDescType::verify( llvm::function_ref emitError, mlir::Type eleTy) { - if (eleTy.isa()) + TypeDescType>(eleTy)) return emitError() << "cannot build a type descriptor of type: " << eleTy << '\n'; return mlir::success(); @@ -1124,10 +1128,10 @@ } bool fir::isCharacterProcedureTuple(mlir::Type ty, bool acceptRawFunc) { - mlir::TupleType tuple = ty.dyn_cast(); + mlir::TupleType tuple = mlir::dyn_cast(ty); return tuple && tuple.size() == 2 && - (tuple.getType(0).isa() || - (acceptRawFunc && tuple.getType(0).isa())) && + (mlir::isa(tuple.getType(0)) || + (acceptRawFunc && mlir::isa(tuple.getType(0)))) && fir::isa_integer(tuple.getType(1)); } @@ -1135,7 +1139,8 @@ if (ty.getNumResults() == 0) return false; auto resultType = ty.getResult(0); - return resultType.isa(); + return mlir::isa( + resultType); } /// 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 --- a/flang/lib/Optimizer/Dialect/FortranVariableInterface.cpp +++ b/flang/lib/Optimizer/Dialect/FortranVariableInterface.cpp @@ -18,7 +18,7 @@ fir::FortranVariableOpInterface::verifyDeclareLikeOpImpl(mlir::Value memref) { const unsigned numExplicitTypeParams = getExplicitTypeParams().size(); mlir::Type memType = memref.getType(); - const bool sourceIsBoxValue = memType.isa(); + const bool sourceIsBoxValue = mlir::isa(memType); const bool sourceIsBoxAddress = fir::isBoxAddress(memType); const bool sourceIsBox = sourceIsBoxValue || sourceIsBoxAddress; if (isCharacter()) { @@ -29,7 +29,8 @@ return emitOpError("must be provided exactly one type parameter when its " "base is a character that is not a box"); - } else if (auto recordType = getElementType().dyn_cast()) { + } else if (auto recordType = + mlir::dyn_cast(getElementType())) { if (numExplicitTypeParams < recordType.getNumLenParams() && !sourceIsBox) return emitOpError("must be provided all the derived type length " "parameters when the base is not a box"); @@ -45,16 +46,16 @@ if (sourceIsBoxAddress) return emitOpError("for box address must not have a shape operand"); unsigned shapeRank = 0; - if (auto shapeType = shape.getType().dyn_cast()) { + if (auto shapeType = mlir::dyn_cast(shape.getType())) { shapeRank = shapeType.getRank(); } else if (auto shapeShiftType = - shape.getType().dyn_cast()) { + mlir::dyn_cast(shape.getType())) { 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 = shape.getType().cast().getRank(); + shapeRank = mlir::cast(shape.getType()).getRank(); } std::optional rank = getRank(); diff --git a/flang/lib/Optimizer/HLFIR/IR/HLFIRDialect.cpp b/flang/lib/Optimizer/HLFIR/IR/HLFIRDialect.cpp --- a/flang/lib/Optimizer/HLFIR/IR/HLFIRDialect.cpp +++ b/flang/lib/Optimizer/HLFIR/IR/HLFIRDialect.cpp @@ -84,7 +84,8 @@ return llvm::TypeSwitch(type) .Case([](auto p) { mlir::Type eleType = p.getEleTy(); - return eleType.isa() || !fir::hasDynamicSize(eleType); + return mlir::isa(eleType) || + !fir::hasDynamicSize(eleType); }) .Case([](auto) { return true; }) .Default([](mlir::Type) { return false; }); @@ -92,15 +93,15 @@ bool hlfir::isFortranScalarCharacterType(mlir::Type type) { return isFortranScalarCharacterExprType(type) || - type.isa() || - fir::unwrapPassByRefType(fir::unwrapRefType(type)) - .isa(); + mlir::isa(type) || + mlir::isa( + fir::unwrapPassByRefType(fir::unwrapRefType(type))); } bool hlfir::isFortranScalarCharacterExprType(mlir::Type type) { - if (auto exprType = type.dyn_cast()) + if (auto exprType = mlir::dyn_cast(type)) return exprType.isScalar() && - exprType.getElementType().isa(); + mlir::isa(exprType.getElementType()); return false; } @@ -112,8 +113,8 @@ bool hlfir::isFortranNumericalArrayObject(mlir::Type type) { if (isBoxAddressType(type)) return false; - if (auto arrayTy = - getFortranElementOrSequenceType(type).dyn_cast()) + if (auto arrayTy = mlir::dyn_cast( + getFortranElementOrSequenceType(type))) return isFortranScalarNumericalType(arrayTy.getEleTy()); return false; } @@ -121,8 +122,8 @@ bool hlfir::isFortranNumericalOrLogicalArrayObject(mlir::Type type) { if (isBoxAddressType(type)) return false; - if (auto arrayTy = - getFortranElementOrSequenceType(type).dyn_cast()) { + if (auto arrayTy = mlir::dyn_cast( + getFortranElementOrSequenceType(type))) { mlir::Type eleTy = arrayTy.getEleTy(); return isFortranScalarNumericalType(eleTy) || mlir::isa(eleTy); @@ -133,7 +134,8 @@ bool hlfir::isFortranArrayObject(mlir::Type type) { if (isBoxAddressType(type)) return false; - return !!getFortranElementOrSequenceType(type).dyn_cast(); + return !!mlir::dyn_cast( + getFortranElementOrSequenceType(type)); } bool hlfir::isPassByRefOrIntegerType(mlir::Type type) { @@ -142,7 +144,7 @@ } bool hlfir::isI1Type(mlir::Type type) { - if (mlir::IntegerType integer = type.dyn_cast()) + if (mlir::IntegerType integer = mlir::dyn_cast(type)) if (integer.getWidth() == 1) return true; return false; @@ -151,8 +153,8 @@ bool hlfir::isFortranLogicalArrayObject(mlir::Type type) { if (isBoxAddressType(type)) return false; - if (auto arrayTy = - getFortranElementOrSequenceType(type).dyn_cast()) { + if (auto arrayTy = mlir::dyn_cast( + getFortranElementOrSequenceType(type))) { 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 --- a/flang/lib/Optimizer/HLFIR/IR/HLFIROps.cpp +++ b/flang/lib/Optimizer/HLFIR/IR/HLFIROps.cpp @@ -34,8 +34,8 @@ /// Is this a fir.[ref/ptr/heap]>> type? static bool isAllocatableBoxRef(mlir::Type type) { fir::BaseBoxType boxType = - fir::dyn_cast_ptrEleTy(type).dyn_cast_or_null(); - return boxType && boxType.getEleTy().isa(); + mlir::dyn_cast_if_present(fir::dyn_cast_ptrEleTy(type)); + return boxType && mlir::isa(boxType.getEleTy()); } mlir::LogicalResult hlfir::AssignOp::verify() { @@ -44,7 +44,7 @@ return emitOpError("lhs must be an allocatable when `realloc` is set"); if (mustKeepLhsLengthInAllocatableAssignment() && !(isAllocatableAssignment() && - hlfir::getFortranElementType(lhsType).isa())) + mlir::isa(hlfir::getFortranElementType(lhsType)))) return emitOpError("`realloc` must be set and lhs must be a character " "allocatable when `keep_lhs_length_if_realloc` is set"); return mlir::success(); @@ -59,13 +59,13 @@ mlir::Type hlfir::DeclareOp::getHLFIRVariableType(mlir::Type inputType, bool hasExplicitLowerBounds) { mlir::Type type = fir::unwrapRefType(inputType); - if (type.isa()) + if (mlir::isa(type)) return inputType; - if (auto charType = type.dyn_cast()) + if (auto charType = mlir::dyn_cast(type)) if (charType.hasDynamicLen()) return fir::BoxCharType::get(charType.getContext(), charType.getFKind()); - auto seqType = type.dyn_cast(); + auto seqType = mlir::dyn_cast(type); bool hasDynamicExtents = seqType && fir::sequenceWithNonConstantShape(seqType); mlir::Type eleType = seqType ? seqType.getEleTy() : type; @@ -77,7 +77,8 @@ } static bool hasExplicitLowerBounds(mlir::Value shape) { - return shape && shape.getType().isa(); + return shape && + mlir::isa(shape.getType()); } void hlfir::DeclareOp::build(mlir::OpBuilder &builder, @@ -247,7 +248,7 @@ bool hasBoxComponent; if (getComponent()) { auto component = getComponent().value(); - auto recType = baseElementType.dyn_cast(); + auto recType = mlir::dyn_cast(baseElementType); if (!recType) return emitOpError( "component must be provided only when the memref is a derived type"); @@ -259,14 +260,14 @@ } mlir::Type fieldType = recType.getType(fieldIdx); mlir::Type componentBaseType = getFortranElementOrSequenceType(fieldType); - hasBoxComponent = fieldType.isa(); - if (componentBaseType.isa() && - baseType.isa() && + hasBoxComponent = mlir::isa(fieldType); + if (mlir::isa(componentBaseType) && + mlir::isa(baseType) && (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 (!componentBaseType.isa()) + if (!mlir::isa(componentBaseType)) return emitOpError("indices must not be provided if component appears " "and is not an array component"); if (!getComponentShape()) @@ -274,9 +275,9 @@ "component_shape must be provided when indexing a component"); mlir::Type compShapeType = getComponentShape().getType(); unsigned componentRank = - componentBaseType.cast().getDimension(); - auto shapeType = compShapeType.dyn_cast(); - auto shapeShiftType = compShapeType.dyn_cast(); + mlir::cast(componentBaseType).getDimension(); + auto shapeType = mlir::dyn_cast(compShapeType); + auto shapeShiftType = mlir::dyn_cast(compShapeType); if (!((shapeType && shapeType.getRank() == componentRank) || (shapeShiftType && shapeShiftType.getRank() == componentRank))) return emitOpError("component_shape must be a fir.shape or " @@ -284,33 +285,33 @@ if (numSubscripts > componentRank) return emitOpError("indices number must match array component rank"); } - if (auto baseSeqType = baseType.dyn_cast()) + if (auto baseSeqType = mlir::dyn_cast(baseType)) // 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 = - componentBaseType.dyn_cast()) + mlir::dyn_cast(componentBaseType)) outputRank = componentSeqType.getDimension(); outputElementType = fir::unwrapSequenceType(componentBaseType); } else { outputElementType = baseElementType; unsigned baseTypeRank = - baseType.isa() - ? baseType.cast().getDimension() + mlir::isa(baseType) + ? mlir::cast(baseType).getDimension() : 0; if (numSubscripts != 0) { if (baseTypeRank != numSubscripts) return emitOpError("indices number must match memref rank"); outputRank = subscriptsRank; - } else if (auto baseSeqType = baseType.dyn_cast()) { + } else if (auto baseSeqType = mlir::dyn_cast(baseType)) { outputRank = baseSeqType.getDimension(); } } if (!getSubstring().empty()) { - if (!outputElementType.isa()) + if (!mlir::isa(outputElementType)) return emitOpError("memref or component must have character type if " "substring indices are provided"); if (getSubstring().size() != 2) @@ -320,16 +321,16 @@ if (!fir::isa_complex(outputElementType)) return emitOpError("memref or component must have complex type if " "complex_part is provided"); - if (auto firCplx = outputElementType.dyn_cast()) + if (auto firCplx = mlir::dyn_cast(outputElementType)) outputElementType = firCplx.getElementType(); else outputElementType = - outputElementType.cast().getElementType(); + mlir::cast(outputElementType).getElementType(); } mlir::Type resultBaseType = getFortranElementOrSequenceType(getResult().getType()); unsigned resultRank = 0; - if (auto resultSeqType = resultBaseType.dyn_cast()) + if (auto resultSeqType = mlir::dyn_cast(resultBaseType)) resultRank = resultSeqType.getDimension(); if (resultRank != outputRank) return emitOpError("result type rank is not consistent with operands, " @@ -339,10 +340,10 @@ // result type must match the one that was inferred here, except the character // length may differ because of substrings. if (resultElementType != outputElementType && - !(resultElementType.isa() && - outputElementType.isa()) && - !(resultElementType.isa() && - outputElementType.isa())) + !(mlir::isa(resultElementType) && + mlir::isa(outputElementType)) && + !(mlir::isa(resultElementType) && + mlir::isa(outputElementType))) return emitOpError( "result element type is not consistent with operands, expected ") << outputElementType; @@ -360,22 +361,22 @@ 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 = getShape().getType().dyn_cast(); + auto shapeType = mlir::dyn_cast(getShape().getType()); auto shapeShiftType = - getShape().getType().dyn_cast(); + mlir::dyn_cast(getShape().getType()); 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 (outputElementType.isa()) { + if (mlir::isa(outputElementType)) { if (numLenParam != 1) return emitOpError("must be provided one length parameter when the " "result is a character"); } else if (fir::isRecordWithTypeParameters(outputElementType)) { if (numLenParam != - outputElementType.cast().getNumLenParams()) + mlir::cast(outputElementType).getNumLenParams()) return emitOpError("must be provided the same number of length " "parameters as in the result derived type"); } else if (numLenParam != 0) { @@ -393,18 +394,18 @@ mlir::LogicalResult hlfir::ParentComponentOp::verify() { mlir::Type baseType = hlfir::getFortranElementOrSequenceType(getMemref().getType()); - auto maybeInputSeqType = baseType.dyn_cast(); + auto maybeInputSeqType = mlir::dyn_cast(baseType); unsigned inputTypeRank = maybeInputSeqType ? maybeInputSeqType.getDimension() : 0; unsigned shapeRank = 0; if (mlir::Value shape = getShape()) - if (auto shapeType = shape.getType().dyn_cast()) + if (auto shapeType = mlir::dyn_cast(shape.getType())) 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 = outputBaseType.dyn_cast(); + auto maybeOutputSeqType = mlir::dyn_cast(outputBaseType); unsigned outputTypeRank = maybeOutputSeqType ? maybeOutputSeqType.getDimension() : 0; if (inputTypeRank != outputTypeRank) @@ -418,23 +419,23 @@ return emitOpError( "result type extents are inconsistent with memref type"); fir::RecordType baseRecType = - hlfir::getFortranElementType(baseType).dyn_cast(); - fir::RecordType outRecType = - hlfir::getFortranElementType(outputBaseType).dyn_cast(); + mlir::dyn_cast(hlfir::getFortranElementType(baseType)); + fir::RecordType outRecType = mlir::dyn_cast( + hlfir::getFortranElementType(outputBaseType)); 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 (getType().isa()) + if (mlir::isa(getType())) 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 (!getType().isa() && + if (!mlir::isa(getType()) && (outputTypeRank != 0 || fir::isRecordWithTypeParameters(outRecType))) return emitOpError("result type must be a fir.box if the result is an " "array or has length parameters"); @@ -452,9 +453,8 @@ mlir::Value mask = getMask(); mlir::Value dim = getDim(); - fir::SequenceType maskTy = - hlfir::getFortranElementOrSequenceType(mask.getType()) - .cast(); + fir::SequenceType maskTy = mlir::cast( + hlfir::getFortranElementOrSequenceType(mask.getType())); mlir::Type logicalTy = maskTy.getEleTy(); llvm::ArrayRef maskShape = maskTy.getShape(); @@ -494,13 +494,14 @@ //===----------------------------------------------------------------------===// static unsigned getCharacterKind(mlir::Type t) { - return hlfir::getFortranElementType(t).cast().getFKind(); + return mlir::cast(hlfir::getFortranElementType(t)) + .getFKind(); } static std::optional getCharacterLengthIfStatic(mlir::Type t) { if (auto charType = - hlfir::getFortranElementType(t).dyn_cast()) + mlir::dyn_cast(hlfir::getFortranElementType(t))) if (charType.hasConstantLen()) return charType.getLen(); return std::nullopt; @@ -551,16 +552,14 @@ mlir::Value dim = reductionOp->getDim(); mlir::Value mask = reductionOp->getMask(); - fir::SequenceType arrayTy = - hlfir::getFortranElementOrSequenceType(array.getType()) - .cast(); + fir::SequenceType arrayTy = mlir::cast( + hlfir::getFortranElementOrSequenceType(array.getType())); mlir::Type numTy = arrayTy.getEleTy(); llvm::ArrayRef arrayShape = arrayTy.getShape(); if (mask) { - fir::SequenceType maskSeq = - hlfir::getFortranElementOrSequenceType(mask.getType()) - .dyn_cast(); + fir::SequenceType maskSeq = mlir::dyn_cast( + hlfir::getFortranElementOrSequenceType(mask.getType())); llvm::ArrayRef maskShape; if (maskSeq) @@ -655,19 +654,17 @@ mlir::LogicalResult hlfir::MatmulOp::verify() { mlir::Value lhs = getLhs(); mlir::Value rhs = getRhs(); - fir::SequenceType lhsTy = - hlfir::getFortranElementOrSequenceType(lhs.getType()) - .cast(); - fir::SequenceType rhsTy = - hlfir::getFortranElementOrSequenceType(rhs.getType()) - .cast(); + fir::SequenceType lhsTy = mlir::cast( + hlfir::getFortranElementOrSequenceType(lhs.getType())); + fir::SequenceType rhsTy = mlir::cast( + hlfir::getFortranElementOrSequenceType(rhs.getType())); 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 = getResult().getType().cast(); + hlfir::ExprType resultTy = mlir::cast(getResult().getType()); llvm::ArrayRef resultShape = resultTy.getShape(); mlir::Type resultEleTy = resultTy.getEleTy(); @@ -770,13 +767,12 @@ mlir::LogicalResult hlfir::TransposeOp::verify() { mlir::Value array = getArray(); - fir::SequenceType arrayTy = - hlfir::getFortranElementOrSequenceType(array.getType()) - .cast(); + fir::SequenceType arrayTy = mlir::cast( + hlfir::getFortranElementOrSequenceType(array.getType())); llvm::ArrayRef inShape = arrayTy.getShape(); std::size_t rank = inShape.size(); mlir::Type eleTy = arrayTy.getEleTy(); - hlfir::ExprType resultTy = getResult().getType().cast(); + hlfir::ExprType resultTy = mlir::cast(getResult().getType()); llvm::ArrayRef resultShape = resultTy.getShape(); std::size_t resultRank = resultShape.size(); mlir::Type resultEleTy = resultTy.getEleTy(); @@ -801,19 +797,17 @@ mlir::LogicalResult hlfir::MatmulTransposeOp::verify() { mlir::Value lhs = getLhs(); mlir::Value rhs = getRhs(); - fir::SequenceType lhsTy = - hlfir::getFortranElementOrSequenceType(lhs.getType()) - .cast(); - fir::SequenceType rhsTy = - hlfir::getFortranElementOrSequenceType(rhs.getType()) - .cast(); + fir::SequenceType lhsTy = mlir::cast( + hlfir::getFortranElementOrSequenceType(lhs.getType())); + fir::SequenceType rhsTy = mlir::cast( + hlfir::getFortranElementOrSequenceType(rhs.getType())); 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 = getResult().getType().cast(); + hlfir::ExprType resultTy = mlir::cast(getResult().getType()); llvm::ArrayRef resultShape = resultTy.getShape(); mlir::Type resultEleTy = resultTy.getEleTy(); @@ -899,7 +893,7 @@ mlir::Value mustFree) { hlfir::ExprType::Shape typeShape; mlir::Type type = getFortranElementOrSequenceType(var.getType()); - if (auto seqType = type.dyn_cast()) { + if (auto seqType = mlir::dyn_cast(type)) { typeShape.append(seqType.getShape().begin(), seqType.getShape().end()); type = seqType.getEleTy(); } @@ -922,7 +916,7 @@ odsState.addTypes(resultType); mlir::Region *bodyRegion = odsState.addRegion(); bodyRegion->push_back(new mlir::Block{}); - if (auto exprType = resultType.dyn_cast()) { + if (auto exprType = mlir::dyn_cast(resultType)) { unsigned dim = exprType.getRank(); mlir::Type indexType = builder.getIndexType(); for (unsigned d = 0; d < dim; ++d) @@ -939,7 +933,7 @@ mlir::ValueRange indices, mlir::ValueRange typeparams) { mlir::Type resultType = expr.getType(); - if (auto exprType = resultType.dyn_cast()) + if (auto exprType = mlir::dyn_cast(resultType)) resultType = exprType.getElementExprType(); build(builder, odsState, resultType, expr, indices, typeparams); } @@ -971,20 +965,20 @@ void hlfir::ShapeOfOp::build(mlir::OpBuilder &builder, mlir::OperationState &result, mlir::Value expr) { - hlfir::ExprType exprTy = expr.getType().cast(); + hlfir::ExprType exprTy = mlir::cast(expr.getType()); 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 = resTy.cast(); + fir::ShapeType shape = mlir::cast(resTy); return shape.getRank(); } mlir::LogicalResult hlfir::ShapeOfOp::verify() { mlir::Value expr = getExpr(); - hlfir::ExprType exprTy = expr.getType().cast(); + hlfir::ExprType exprTy = mlir::cast(expr.getType()); std::size_t exprRank = exprTy.getShape().size(); if (exprRank == 0) @@ -1003,7 +997,8 @@ // 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 = shapeOf.getExpr().getType().cast(); + hlfir::ExprType expr = + mlir::cast(shapeOf.getExpr().getType()); mlir::Value shape = hlfir::genExprShape(rewriter, loc, expr); if (!shape) @@ -1028,7 +1023,7 @@ } mlir::LogicalResult hlfir::GetExtentOp::verify() { - fir::ShapeType shapeTy = getShape().getType().cast(); + fir::ShapeType shapeTy = mlir::cast(getShape().getType()); std::uint64_t rank = shapeTy.getRank(); llvm::APInt dim = getDim(); if (dim.sge(rank)) @@ -1151,7 +1146,7 @@ odsState.addOperands(shape); mlir::Region *bodyRegion = odsState.addRegion(); bodyRegion->push_back(new mlir::Block{}); - if (auto shapeType = shape.getType().dyn_cast()) { + if (auto shapeType = mlir::dyn_cast(shape.getType())) { unsigned dim = shapeType.getRank(); mlir::Type indexType = builder.getIndexType(); for (unsigned d = 0; d < dim; ++d) @@ -1168,10 +1163,11 @@ return emitOpError("body region must be terminated by an hlfir.yield"); mlir::Type elementAddrType = yieldOp.getEntity().getType(); if (!hlfir::isFortranVariableType(elementAddrType) || - hlfir::getFortranElementOrSequenceType(elementAddrType) - .isa()) + mlir::isa( + hlfir::getFortranElementOrSequenceType(elementAddrType))) return emitOpError("body must compute the address of a scalar entity"); - unsigned shapeRank = getShape().getType().cast().getRank(); + unsigned shapeRank = + mlir::cast(getShape().getType()).getRank(); if (shapeRank != getIndices().size()) return emitOpError("body number of indices must match shape rank"); return mlir::success(); @@ -1260,8 +1256,8 @@ if (mustBeScalarI1) return hlfir::isI1Type(yieldType); return hlfir::isMaskArgument(yieldType) && - hlfir::getFortranElementOrSequenceType(yieldType) - .isa(); + mlir::isa( + hlfir::getFortranElementOrSequenceType(yieldType)); } mlir::LogicalResult hlfir::ForallMaskOp::verify() { diff --git a/flang/lib/Optimizer/HLFIR/Transforms/BufferizeHLFIR.cpp b/flang/lib/Optimizer/HLFIR/Transforms/BufferizeHLFIR.cpp --- a/flang/lib/Optimizer/HLFIR/Transforms/BufferizeHLFIR.cpp +++ b/flang/lib/Optimizer/HLFIR/Transforms/BufferizeHLFIR.cpp @@ -74,7 +74,7 @@ /// 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 = bufferizedExpr.getType().dyn_cast(); + auto tupleType = mlir::dyn_cast(bufferizedExpr.getType()); if (!tupleType) return hlfir::Entity{bufferizedExpr}; assert(tupleType.size() == 2 && "unexpected tuple type"); @@ -87,7 +87,7 @@ /// Helper to extract the clean-up flag from a tuple created by /// packageBufferizedExpr. static mlir::Value getBufferizedExprMustFreeFlag(mlir::Value bufferizedExpr) { - auto tupleType = bufferizedExpr.getType().dyn_cast(); + auto tupleType = mlir::dyn_cast(bufferizedExpr.getType()); if (!tupleType) return bufferizedExpr; assert(tupleType.size() == 2 && "unexpected tuple type"); @@ -187,8 +187,8 @@ shape = hlfir::genShape(loc, builder, bufferizedExpr); } else { // everything else failed so try to create a shape from static type info - hlfir::ExprType exprTy = - adaptor.getExpr().getType().dyn_cast_or_null(); + hlfir::ExprType exprTy = mlir::dyn_cast_if_present( + adaptor.getExpr().getType()); if (exprTy) shape = hlfir::genExprShape(builder, loc, exprTy); } @@ -359,8 +359,8 @@ // !fir.box>> value must be propagated // as the box address !fir.ref>. mlir::Type associateHlfirVarType = associate.getResultTypes()[0]; - if (hlfirVar.getType().isa() && - !associateHlfirVarType.isa()) + if (mlir::isa(hlfirVar.getType()) && + !mlir::isa(associateHlfirVarType)) hlfirVar = builder.create(loc, associateHlfirVarType, hlfirVar); else @@ -368,10 +368,10 @@ associate.getResult(0).replaceAllUsesWith(hlfirVar); mlir::Type associateFirVarType = associate.getResultTypes()[1]; - if ((firVar.getType().isa() && - !associateFirVarType.isa()) || - (firVar.getType().isa() && - !associateFirVarType.isa())) + if ((mlir::isa(firVar.getType()) && + !mlir::isa(associateFirVarType)) || + (mlir::isa(firVar.getType()) && + !mlir::isa(associateFirVarType))) firVar = builder.create(loc, associateFirVarType, firVar); else @@ -414,9 +414,9 @@ // fir::FreeMemOp operand type must be a fir::HeapType. mlir::Type heapType = fir::HeapType::get( hlfir::getFortranElementOrSequenceType(var.getType())); - if (var.getType().isa()) + if (mlir::isa(var.getType())) var = builder.create(loc, heapType, var); - else if (!var.getType().isa()) + else if (!mlir::isa(var.getType())) var = builder.create(loc, heapType, var); builder.create(loc, var); }; @@ -580,7 +580,7 @@ // 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 (elementValue.getType().isa() && + if (mlir::isa(elementValue.getType()) && wasCreatedInCurrentBlock(elementValue, builder)) builder.create(loc, elementValue); builder.restoreInsertionPoint(insPt); @@ -620,11 +620,12 @@ hlfir::EndAssociateOp, hlfir::SetLengthOp>(); target.markUnknownOpDynamicallyLegal([](mlir::Operation *op) { - return llvm::all_of( - op->getResultTypes(), - [](mlir::Type ty) { return !ty.isa(); }) && + return llvm::all_of(op->getResultTypes(), + [](mlir::Type ty) { + return !mlir::isa(ty); + }) && llvm::all_of(op->getOperandTypes(), [](mlir::Type ty) { - return !ty.isa(); + return !mlir::isa(ty); }); }); if (mlir::failed( diff --git a/flang/lib/Optimizer/HLFIR/Transforms/ConvertToFIR.cpp b/flang/lib/Optimizer/HLFIR/Transforms/ConvertToFIR.cpp --- a/flang/lib/Optimizer/HLFIR/Transforms/ConvertToFIR.cpp +++ b/flang/lib/Optimizer/HLFIR/Transforms/ConvertToFIR.cpp @@ -34,7 +34,7 @@ static mlir::Value genAllocatableTempFromSourceBox(mlir::Location loc, fir::FirOpBuilder &builder, mlir::Value sourceBox) { - assert(sourceBox.getType().isa() && + assert(mlir::isa(sourceBox.getType()) && "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 @@ // This has the huge benefit of dealing with all cases, including // polymorphic entities. mlir::Type fromHeapType = fir::HeapType::get(fir::unwrapRefType( - sourceBox.getType().cast().getEleTy())); + mlir::cast(sourceBox.getType()).getEleTy())); mlir::Type fromBoxHeapType = fir::BoxType::get(fromHeapType); mlir::Value fromMutableBox = fir::factory::genNullBoxStorage(builder, loc, fromBoxHeapType); @@ -69,7 +69,7 @@ auto module = assignOp->getParentOfType(); fir::FirOpBuilder builder(rewriter, fir::getKindMapping(module)); - if (rhs.getType().isa()) { + if (mlir::isa(rhs.getType())) { mlir::emitError(loc, "hlfir must be bufferized with --bufferize-hlfir " "pass before being converted to FIR"); return mlir::failure(); @@ -305,17 +305,16 @@ .getResult(); mlir::Value hlfirBase; mlir::Type hlfirBaseType = declareOp.getBase().getType(); - if (hlfirBaseType.isa()) { + if (mlir::isa(hlfirBaseType)) { auto module = declareOp->getParentOfType(); fir::FirOpBuilder builder(rewriter, fir::getKindMapping(module)); // Helper to generate the hlfir fir.box with the local lower bounds and // type parameters. auto genHlfirBox = [&]() -> mlir::Value { - if (!firBase.getType().isa()) { + if (!mlir::isa(firBase.getType())) { llvm::SmallVector typeParams; - auto maybeCharType = - fir::unwrapSequenceType(fir::unwrapPassByRefType(hlfirBaseType)) - .dyn_cast(); + auto maybeCharType = mlir::dyn_cast( + fir::unwrapSequenceType(fir::unwrapPassByRefType(hlfirBaseType))); if (!maybeCharType || maybeCharType.hasDynamicLen()) typeParams.append(declareOp.getTypeparams().begin(), declareOp.getTypeparams().end()); @@ -353,7 +352,7 @@ }) .getResults()[0]; } - } else if (hlfirBaseType.isa()) { + } else if (mlir::isa(hlfirBaseType)) { assert(declareOp.getTypeparams().size() == 1 && "must contain character length"); hlfirBase = rewriter.create( @@ -410,11 +409,12 @@ // - scalar%scalar_component [substring|complex_part] or // - scalar%static_size_array_comp // - scalar%array(indices) [substring| complex part] - mlir::Type componentType = baseEleTy.cast().getType( - designate.getComponent().value()); + mlir::Type componentType = + mlir::cast(baseEleTy).getType( + designate.getComponent().value()); mlir::Type coorTy = fir::ReferenceType::get(componentType); base = builder.create(loc, coorTy, base, fieldIndex); - if (componentType.isa()) { + if (mlir::isa(componentType)) { auto variableInterface = mlir::cast( designate.getOperation()); if (variableInterface.isAllocatable() || @@ -430,14 +430,14 @@ } else { // array%component[(indices) substring|complex part] cases. // Component ref of array bases are dealt with below in embox/rebox. - assert(designateResultType.isa()); + assert(mlir::isa(designateResultType)); } } - if (designateResultType.isa()) { + if (mlir::isa(designateResultType)) { // Generate embox or rebox. - if (!fir::unwrapPassByRefType(designateResultType) - .isa()) + if (!mlir::isa( + fir::unwrapPassByRefType(designateResultType))) TODO(loc, "addressing polymorphic arrays"); llvm::SmallVector triples; llvm::SmallVector sliceFields; @@ -502,7 +502,7 @@ assert(sliceFields.empty() && substring.empty()); llvm::SmallVector resultType{designateResultType}; mlir::Value resultBox; - if (base.getType().isa()) + if (mlir::isa(base.getType())) resultBox = builder.create(loc, resultType, base, shape, slice); else @@ -516,7 +516,8 @@ // 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 = designateResultType.dyn_cast()) + if (auto boxCharType = + mlir::dyn_cast(designateResultType)) resultAddressType = fir::ReferenceType::get(boxCharType.getEleTy()); // Array element indexing. @@ -549,7 +550,7 @@ // Scalar complex part ref if (designate.getComplexPart()) { // Sequence types should have already been handled by this point - assert(!designateResultType.isa()); + assert(!mlir::isa(designateResultType)); auto index = builder.createIntegerConstant(loc, builder.getIndexType(), *designate.getComplexPart()); auto coorTy = fir::ReferenceType::get(resultEleTy); @@ -557,7 +558,7 @@ } // Cast/embox the computed scalar address if needed. - if (designateResultType.isa()) { + if (mlir::isa(designateResultType)) { assert(designate.getTypeparams().size() == 1 && "must have character length"); auto emboxChar = builder.create( @@ -600,13 +601,13 @@ mlir::PatternRewriter &rewriter) const override { mlir::Location loc = parentComponent.getLoc(); mlir::Type resultType = parentComponent.getType(); - if (!parentComponent.getType().isa()) { + if (!mlir::isa(parentComponent.getType())) { 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 (baseAddr.getType().isa()) + if (mlir::isa(baseAddr.getType())) baseAddr = rewriter.create(loc, baseAddr); rewriter.replaceOpWithNewOp(parentComponent, resultType, baseAddr); @@ -615,7 +616,7 @@ // Array parent component ref or PDTs. hlfir::Entity base{parentComponent.getMemref()}; mlir::Value baseAddr = base.getBase(); - if (!baseAddr.getType().isa()) { + if (!mlir::isa(baseAddr.getType())) { // 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 @@ -677,7 +678,7 @@ // 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 = shape.getType().cast(); + fir::ShapeType shapeTy = mlir::cast(shape.getType()); 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/LowerHLFIROrderedAssignments.cpp b/flang/lib/Optimizer/HLFIR/Transforms/LowerHLFIROrderedAssignments.cpp --- a/flang/lib/Optimizer/HLFIR/Transforms/LowerHLFIROrderedAssignments.cpp +++ b/flang/lib/Optimizer/HLFIR/Transforms/LowerHLFIROrderedAssignments.cpp @@ -884,7 +884,7 @@ mlir::Value loopExtent = computeLoopNestIterationNumber(loc, builder, loopNest); auto sequenceType = - builder.getVarLenSeqTy(entityType).cast(); + mlir::cast(builder.getVarLenSeqTy(entityType)); temp = insertSavedEntity(region, fir::factory::HomogeneousScalarStack{ loc, builder, sequenceType, loopExtent, diff --git a/flang/lib/Optimizer/HLFIR/Transforms/SimplifyHLFIRIntrinsics.cpp b/flang/lib/Optimizer/HLFIR/Transforms/SimplifyHLFIRIntrinsics.cpp --- a/flang/lib/Optimizer/HLFIR/Transforms/SimplifyHLFIRIntrinsics.cpp +++ b/flang/lib/Optimizer/HLFIR/Transforms/SimplifyHLFIRIntrinsics.cpp @@ -95,7 +95,8 @@ // by hlfir.elemental) target.addDynamicallyLegalOp( [](hlfir::TransposeOp transpose) { - return transpose.getType().cast().isPolymorphic(); + return mlir::cast(transpose.getType()) + .isPolymorphic(); }); target.markUnknownOpDynamicallyLegal( [](mlir::Operation *) { return true; }); diff --git a/flang/lib/Optimizer/Transforms/AbstractResult.cpp b/flang/lib/Optimizer/Transforms/AbstractResult.cpp --- a/flang/lib/Optimizer/Transforms/AbstractResult.cpp +++ b/flang/lib/Optimizer/Transforms/AbstractResult.cpp @@ -66,14 +66,14 @@ auto resultType = funcTy.getResult(0); assert(fir::isa_builtin_cptr_type(resultType)); llvm::SmallVector outputTypes; - auto recTy = resultType.dyn_cast(); + auto recTy = mlir::dyn_cast(resultType); 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 resultType.isa() && + return mlir::isa(resultType) && shouldBoxResult; } @@ -115,7 +115,7 @@ bool isResultBuiltinCPtr = fir::isa_builtin_cptr_type(result.getType()); Op newOp; if (isResultBuiltinCPtr) { - auto recTy = result.getType().template dyn_cast(); + auto recTy = mlir::dyn_cast(result.getType()); newResultTypes.emplace_back(recTy.getTypeList()[0].second); } @@ -264,7 +264,7 @@ mlir::LogicalResult matchAndRewrite(fir::AddrOfOp addrOf, mlir::PatternRewriter &rewriter) const override { - auto oldFuncTy = addrOf.getType().cast(); + auto oldFuncTy = mlir::cast(addrOf.getType()); mlir::FunctionType newFuncTy; // TODO: This should be generalized for derived types, and it is // architecture and OS dependent. @@ -316,7 +316,7 @@ return !hasAbstractResult(call.getFunctionType()); }); target.addDynamicallyLegalOp([](fir::AddrOfOp addrOf) { - if (auto funTy = addrOf.getType().dyn_cast()) + if (auto funTy = mlir::dyn_cast(addrOf.getType())) return !hasAbstractResult(funTy); return true; }); @@ -346,7 +346,7 @@ auto loc = func.getLoc(); auto *context = &getContext(); // Convert function type itself if it has an abstract result. - auto funcTy = func.getFunctionType().cast(); + auto funcTy = mlir::cast(func.getFunctionType()); if (hasAbstractResult(funcTy)) { // TODO: This should be generalized for derived types, and it is // architecture and OS dependent. @@ -394,11 +394,11 @@ return mlir::TypeSwitch(type) .Case([](fir::BoxProcType boxProc) { return fir::hasAbstractResult( - boxProc.getEleTy().cast()); + mlir::cast(boxProc.getEleTy())); }) .Case([](fir::PointerType pointer) { return fir::hasAbstractResult( - pointer.getEleTy().cast()); + mlir::cast(pointer.getEleTy())); }) .Default([](auto &&) { return false; }); } diff --git a/flang/lib/Optimizer/Transforms/AddDebugFoundation.cpp b/flang/lib/Optimizer/Transforms/AddDebugFoundation.cpp --- a/flang/lib/Optimizer/Transforms/AddDebugFoundation.cpp +++ b/flang/lib/Optimizer/Transforms/AddDebugFoundation.cpp @@ -54,7 +54,7 @@ mlir::MLIRContext *context = &getContext(); mlir::OpBuilder builder(context); std::string inputFilePath("-"); - if (auto fileLoc = module.getLoc().dyn_cast()) + if (auto fileLoc = mlir::dyn_cast(module.getLoc())) inputFilePath = fileLoc.getFilename().getValue(); auto getFileAttr = [context](llvm::StringRef path) -> mlir::LLVM::DIFileAttr { @@ -73,13 +73,13 @@ mlir::Location l = funcOp->getLoc(); // If fused location has already been created then nothing to do // Otherwise, create a fused location. - if (l.dyn_cast()) + if (mlir::dyn_cast(l)) return; llvm::StringRef funcFilePath; - if (l.dyn_cast()) + if (mlir::dyn_cast(l)) funcFilePath = - l.dyn_cast().getFilename().getValue(); + mlir::dyn_cast(l).getFilename().getValue(); else funcFilePath = inputFilePath; diff --git a/flang/lib/Optimizer/Transforms/AffineDemotion.cpp b/flang/lib/Optimizer/Transforms/AffineDemotion.cpp --- a/flang/lib/Optimizer/Transforms/AffineDemotion.cpp +++ b/flang/lib/Optimizer/Transforms/AffineDemotion.cpp @@ -98,14 +98,15 @@ mlir::LogicalResult matchAndRewrite(fir::ConvertOp op, mlir::PatternRewriter &rewriter) const override { - if (op.getRes().getType().isa()) { + if (mlir::isa(op.getRes().getType())) { // 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 = op.getValue().getType().dyn_cast()) - if (auto arrTy = refTy.getEleTy().dyn_cast()) { + if (auto refTy = + mlir::dyn_cast(op.getValue().getType())) + if (auto arrTy = mlir::dyn_cast(refTy.getEleTy())) { fir::SequenceType::Shape flatShape = { fir::SequenceType::getUnknownExtent()}; auto flatArrTy = fir::SequenceType::get(flatShape, arrTy.getEleTy()); @@ -158,7 +159,7 @@ mlir::ConversionTarget target(*context); target.addIllegalOp(); target.addDynamicallyLegalOp([](fir::ConvertOp op) { - if (op.getRes().getType().isa()) + if (mlir::isa(op.getRes().getType())) return false; return true; }); diff --git a/flang/lib/Optimizer/Transforms/AffinePromotion.cpp b/flang/lib/Optimizer/Transforms/AffinePromotion.cpp --- a/flang/lib/Optimizer/Transforms/AffinePromotion.cpp +++ b/flang/lib/Optimizer/Transforms/AffinePromotion.cpp @@ -63,7 +63,7 @@ } // namespace static bool analyzeCoordinate(mlir::Value coordinate, mlir::Operation *op) { - if (auto blockArg = coordinate.dyn_cast()) { + if (auto blockArg = mlir::dyn_cast(coordinate)) { if (isa(blockArg.getOwner()->getParentOp())) return true; LLVM_DEBUG(llvm::dbgs() << "AffineLoopAnalysis: array coordinate is not a " @@ -111,7 +111,7 @@ bool analyzeReference(mlir::Value memref, mlir::Operation *op) { if (auto acoOp = memref.getDefiningOp()) { - if (acoOp.getMemref().getType().isa()) { + if (mlir::isa(acoOp.getMemref().getType())) { // 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,9 +222,9 @@ return affineBinaryOp(mlir::AffineExprKind::Mod, op.getLhs(), op.getRhs()); if (auto op = value.getDefiningOp()) - if (auto intConstant = op.getValue().dyn_cast()) + if (auto intConstant = mlir::dyn_cast(op.getValue())) return toAffineExpr(intConstant.getInt()); - if (auto blockArg = value.dyn_cast()) { + if (auto blockArg = mlir::dyn_cast(value)) { affineArgs.push_back(value); if (isa(blockArg.getOwner()->getParentOp()) || isa(blockArg.getOwner()->getParentOp())) @@ -331,15 +331,16 @@ static std::optional constantIntegerLike(const mlir::Value value) { if (auto definition = value.getDefiningOp()) - if (auto stepAttr = definition.getValue().dyn_cast()) + if (auto stepAttr = mlir::dyn_cast(definition.getValue())) return stepAttr.getInt(); return {}; } static mlir::Type coordinateArrayElement(fir::ArrayCoorOp op) { if (auto refType = - op.getMemref().getType().dyn_cast_or_null()) { - if (auto seqType = refType.getEleTy().dyn_cast_or_null()) { + mlir::dyn_cast_if_present(op.getMemref().getType())) { + if (auto seqType = + mlir::dyn_cast_if_present(refType.getEleTy())) { return seqType.getEleTy(); } } diff --git a/flang/lib/Optimizer/Transforms/ArrayValueCopy.cpp b/flang/lib/Optimizer/Transforms/ArrayValueCopy.cpp --- a/flang/lib/Optimizer/Transforms/ArrayValueCopy.cpp +++ b/flang/lib/Optimizer/Transforms/ArrayValueCopy.cpp @@ -188,7 +188,7 @@ LLVM_DEBUG(llvm::dbgs() << "popset: " << *op << '\n'); auto popFn = [&](auto rop) { assert(val && "op must have a result value"); - auto resNum = val.cast().getResultNumber(); + auto resNum = mlir::cast(val).getResultNumber(); llvm::SmallVector results; rop.resultToSourceOps(results, resNum); for (auto u : results) @@ -297,7 +297,7 @@ visited.insert(val); // Process a block argument. - if (auto ba = val.dyn_cast()) { + if (auto ba = mlir::dyn_cast(val)) { collectArrayMentionFrom(ba); return; } @@ -462,9 +462,9 @@ } static bool hasPointerType(mlir::Type type) { - if (auto boxTy = type.dyn_cast()) + if (auto boxTy = mlir::dyn_cast(type)) type = boxTy.getEleTy(); - return type.isa(); + return mlir::isa(type); } // This is a NF performance hack. It makes a simple test that the slices of the @@ -513,7 +513,7 @@ auto isPositiveConstant = [](mlir::Value v) -> bool { if (auto conOp = mlir::dyn_cast(v.getDefiningOp())) - if (auto iattr = conOp.getValue().dyn_cast()) + if (auto iattr = mlir::dyn_cast(conOp.getValue())) return iattr.getInt() > 0; return false; }; @@ -721,8 +721,8 @@ conservativeCallConflict(llvm::ArrayRef reaches) { return llvm::any_of(reaches, [](mlir::Operation *op) { if (auto call = mlir::dyn_cast(op)) - if (auto callee = - call.getCallableForCallee().dyn_cast()) { + if (auto callee = mlir::dyn_cast_if_present( + call.getCallableForCallee())) { auto module = op->getParentOfType(); return isInternalPorcedure( module.lookupSymbol(callee)); @@ -878,9 +878,9 @@ if (arrLoad->hasAttr(fir::getOptionalAttrName())) fir::emitFatalError( loc, "shapes from array load of OPTIONAL arrays must not be used"); - if (auto boxTy = arrLoad.getMemref().getType().dyn_cast()) { + if (auto boxTy = mlir::dyn_cast(arrLoad.getMemref().getType())) { auto rank = - dyn_cast_ptrOrBoxEleTy(boxTy).cast().getDimension(); + mlir::cast(dyn_cast_ptrOrBoxEleTy(boxTy)).getDimension(); auto idxTy = rewriter.getIndexType(); for (decltype(rank) dim = 0; dim < rank; ++dim) { auto dimVal = rewriter.create(loc, dim); @@ -916,7 +916,7 @@ static llvm::SmallVector getTypeParamsIfRawData(mlir::Location loc, FirOpBuilder &builder, ArrayLoadOp arrLoad, mlir::Type ty) { - if (ty.isa()) + if (mlir::isa(ty)) return {}; return fir::factory::getTypeParams(loc, builder, arrLoad); } @@ -934,8 +934,8 @@ originated = factory::originateIndices(loc, rewriter, alloc.getType(), shape, indices); auto seqTy = dyn_cast_ptrOrBoxEleTy(alloc.getType()); - assert(seqTy && seqTy.isa()); - const auto dimension = seqTy.cast().getDimension(); + assert(seqTy && mlir::isa(seqTy)); + const auto dimension = mlir::cast(seqTy).getDimension(); auto module = load->getParentOfType(); fir::KindMapping kindMap = getKindMapping(module); FirOpBuilder builder(rewriter, kindMap); @@ -955,7 +955,7 @@ ArrayLoadOp load, CharacterType charTy) { auto charLenTy = builder.getCharacterLengthType(); if (charTy.hasDynamicLen()) { - if (load.getMemref().getType().isa()) { + if (mlir::isa(load.getMemref().getType())) { // The loaded array is an emboxed value. Get the CHARACTER length from // the box value. auto eleSzInBytes = @@ -1016,7 +1016,7 @@ 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 = eleTy.dyn_cast()) { + if (auto charTy = mlir::dyn_cast(eleTy)) { auto len = getCharacterLen(loc, builder, arrLoad, charTy); CharBoxValue toChar(toAddr, len); CharBoxValue fromChar(fromAddr, len); @@ -1038,8 +1038,8 @@ auto eleTy = unwrapSequenceType(unwrapPassByRefType(load.getMemref().getType())); if (hasDynamicSize(eleTy)) { - if (auto charTy = eleTy.dyn_cast()) { - assert(load.getMemref().getType().isa()); + if (auto charTy = mlir::dyn_cast(eleTy)) { + assert(mlir::isa(load.getMemref().getType())); auto module = load->getParentOfType(); fir::KindMapping kindMap = getKindMapping(module); FirOpBuilder builder(rewriter, kindMap); @@ -1057,7 +1057,7 @@ llvm::ArrayRef extents) { llvm::SmallVector nce; auto arrTy = unwrapPassByRefType(memrefTy); - auto seqTy = arrTy.cast(); + auto seqTy = mlir::cast(arrTy); 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 --- a/flang/lib/Optimizer/Transforms/CharacterConversion.cpp +++ b/flang/lib/Optimizer/Transforms/CharacterConversion.cpp @@ -60,8 +60,8 @@ // 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 = fir::unwrapSequenceType(fir::dyn_cast_ptrEleTy(t)) - .cast(); + auto chrTy = mlir::cast( + fir::unwrapSequenceType(fir::dyn_cast_ptrEleTy(t))); 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 --- a/flang/lib/Optimizer/Transforms/LoopVersioning.cpp +++ b/flang/lib/Optimizer/Transforms/LoopVersioning.cpp @@ -92,7 +92,7 @@ static fir::SequenceType getAsSequenceType(mlir::Value *v) { mlir::Type argTy = fir::unwrapPassByRefType(fir::unwrapRefType(v->getType())); - return argTy.dyn_cast(); + return mlir::dyn_cast(argTy); } void LoopVersioningPass::runOnOperation() { @@ -124,10 +124,10 @@ seqTy.getShape()[0] == fir::SequenceType::getUnknownExtent()) { size_t typeSize = 0; mlir::Type elementType = fir::unwrapSeqOrBoxedSeqType(arg.getType()); - if (elementType.isa() || - elementType.isa()) + if (mlir::isa(elementType) || + mlir::isa(elementType)) typeSize = elementType.getIntOrFloatBitWidth() / 8; - else if (auto cty = elementType.dyn_cast()) + else if (auto cty = mlir::dyn_cast(elementType)) typeSize = 2 * cty.getEleType(kindMap).getIntOrFloatBitWidth() / 8; if (typeSize) argsOfInterest.push_back({&arg, typeSize, {}}); diff --git a/flang/lib/Optimizer/Transforms/MemoryAllocation.cpp b/flang/lib/Optimizer/Transforms/MemoryAllocation.cpp --- a/flang/lib/Optimizer/Transforms/MemoryAllocation.cpp +++ b/flang/lib/Optimizer/Transforms/MemoryAllocation.cpp @@ -75,7 +75,7 @@ // TODO: Generalize the algorithm and placement of the freemem nodes. if (alloca->getBlock() != entry) return true; - if (auto seqTy = alloca.getInType().dyn_cast()) { + if (auto seqTy = mlir::dyn_cast(alloca.getInType())) { 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 --- a/flang/lib/Optimizer/Transforms/PolymorphicOpConversion.cpp +++ b/flang/lib/Optimizer/Transforms/PolymorphicOpConversion.cpp @@ -97,8 +97,8 @@ // Get derived type information. mlir::Type declaredType = fir::getDerivedType(dispatch.getObject().getType().getEleTy()); - assert(declaredType.isa() && "expecting fir.type"); - auto recordType = declaredType.dyn_cast(); + assert(mlir::isa(declaredType) && "expecting fir.type"); + auto recordType = mlir::dyn_cast(declaredType); // Lookup for the binding table. auto bindingsIter = bindingTables.find(recordType.getName()); @@ -157,7 +157,7 @@ // Load the bindings descriptor. auto bindingsCompName = Fortran::semantics::bindingDescCompName; - fir::RecordType typeDescRecTy = typeDescTy.cast(); + fir::RecordType typeDescRecTy = mlir::cast(typeDescTy); mlir::Value field = rewriter.create( loc, fieldTy, bindingsCompName, typeDescRecTy, mlir::ValueRange{}); mlir::Type coorTy = @@ -168,8 +168,8 @@ // Load the correct binding. mlir::Value bindings = rewriter.create(loc, bindingBox); - fir::RecordType bindingTy = - fir::unwrapIfDerived(bindingBox.getType().cast()); + fir::RecordType bindingTy = fir::unwrapIfDerived( + mlir::cast(bindingBox.getType())); mlir::Type bindingAddrTy = fir::ReferenceType::get(bindingTy); mlir::Value bindingIdxVal = rewriter.create( loc, rewriter.getIndexType(), rewriter.getIndexAttr(bindingIdx)); @@ -181,7 +181,7 @@ mlir::Value procField = rewriter.create( loc, fieldTy, procCompName, bindingTy, mlir::ValueRange{}); fir::RecordType procTy = - bindingTy.getType(procCompName).cast(); + mlir::cast(bindingTy.getType(procCompName)); mlir::Type procRefTy = fir::ReferenceType::get(procTy); mlir::Value procRef = rewriter.create( loc, procRefTy, bindingAddr, procField); @@ -298,13 +298,13 @@ // 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 = typeGuards[t].dyn_cast()) { + if (auto a = mlir::dyn_cast(typeGuards[t])) { orderedTypeGuards.push_back(t); continue; } - if (auto a = typeGuards[t].dyn_cast()) { - if (auto recTy = a.getType().dyn_cast()) { + if (auto a = mlir::dyn_cast(typeGuards[t])) { + if (auto recTy = mlir::dyn_cast(a.getType())) { auto dt = mod.lookupSymbol(recTy.getName()); assert(dt && "dispatch table not found"); llvm::SmallSet ancestors = @@ -313,8 +313,8 @@ auto it = orderedClassIsGuards.begin(); while (it != orderedClassIsGuards.end()) { fir::SubclassAttr sAttr = - typeGuards[*it].dyn_cast(); - if (auto ty = sAttr.getType().dyn_cast()) { + mlir::dyn_cast(typeGuards[*it]); + if (auto ty = mlir::dyn_cast(sAttr.getType())) { if (ancestors.contains(ty.getName())) break; } @@ -339,7 +339,7 @@ auto *dest = selectType.getSuccessor(idx); std::optional destOps = selectType.getSuccessorOperands(operands, idx); - if (typeGuards[idx].dyn_cast()) + if (mlir::dyn_cast(typeGuards[idx])) rewriter.replaceOpWithNewOp( selectType, dest, destOps.value_or(mlir::ValueRange{})); else if (mlir::failed(genTypeLadderStep(loc, selector, typeGuards[idx], @@ -357,9 +357,9 @@ fir::KindMapping &kindMap) const { mlir::Value cmp; // TYPE IS type guard comparison are all done inlined. - if (auto a = attr.dyn_cast()) { + if (auto a = mlir::dyn_cast(attr)) { if (fir::isa_trivial(a.getType()) || - a.getType().isa()) { + mlir::isa(a.getType())) { // 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 @@ cmp = res; } // CLASS IS type guard statement is done with a runtime call. - } else if (auto a = attr.dyn_cast()) { + } else if (auto a = mlir::dyn_cast(attr)) { // Retrieve the type descriptor from the type guard statement record type. - assert(a.getType().isa() && "expect fir.record type"); - fir::RecordType recTy = a.getType().dyn_cast(); + assert(mlir::isa(a.getType()) && "expect fir.record type"); + fir::RecordType recTy = mlir::dyn_cast(a.getType()); std::string typeDescName = fir::NameUniquer::getTypeDescriptorName(recTy.getName()); auto typeDescGlobal = mod.lookupSymbol(typeDescName); @@ -438,8 +438,8 @@ SelectTypeConv::genTypeDescCompare(mlir::Location loc, mlir::Value selector, mlir::Type ty, mlir::ModuleOp mod, mlir::PatternRewriter &rewriter) const { - assert(ty.isa() && "expect fir.record type"); - fir::RecordType recTy = ty.dyn_cast(); + assert(mlir::isa(ty) && "expect fir.record type"); + fir::RecordType recTy = mlir::dyn_cast(ty); 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 --- a/flang/lib/Optimizer/Transforms/SimplifyIntrinsics.cpp +++ b/flang/lib/Optimizer/Transforms/SimplifyIntrinsics.cpp @@ -225,8 +225,8 @@ // 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 = emboxVal.getType().dyn_cast()) - if (auto seqTy = boxTy.getEleTy().dyn_cast()) + if (auto boxTy = mlir::dyn_cast(emboxVal.getType())) + if (auto seqTy = mlir::dyn_cast(boxTy.getEleTy())) return seqTy.getDimension(); return 0; } @@ -247,9 +247,9 @@ val = defOp->getOperand(0); // The convert operation is expected to convert from one // box type to another box type. - auto boxType = val.getType().cast(); + auto boxType = mlir::cast(val.getType()); auto elementType = fir::unwrapSeqOrBoxedSeqType(boxType); - if (!elementType.isa()) + if (!mlir::isa(elementType)) return elementType; } while (true); } @@ -521,7 +521,7 @@ mlir::Value testInit = initVal(builder, loc, elementType); fir::IfOp ifMinSetOp; - if (elementType.isa()) { + if (mlir::isa(elementType)) { mlir::Value cmp = builder.create( loc, mlir::arith::CmpFPredicate::OEQ, testInit, reductionVal); ifMinSetOp = builder.create(loc, cmp, @@ -585,7 +585,7 @@ // end function RTNAME(Sum)x_simplified auto zero = [](fir::FirOpBuilder builder, mlir::Location loc, mlir::Type elementType) { - if (auto ty = elementType.dyn_cast()) { + if (auto ty = mlir::dyn_cast(elementType)) { const llvm::fltSemantics &sem = ty.getFloatSemantics(); return builder.createRealConstant(loc, elementType, llvm::APFloat::getZero(sem)); @@ -596,9 +596,9 @@ auto genBodyOp = [](fir::FirOpBuilder builder, mlir::Location loc, mlir::Type elementType, mlir::Value elem1, mlir::Value elem2) -> mlir::Value { - if (elementType.isa()) + if (mlir::isa(elementType)) return builder.create(loc, elem1, elem2); - if (elementType.isa()) + if (mlir::isa(elementType)) return builder.create(loc, elem1, elem2); llvm_unreachable("unsupported type"); @@ -618,7 +618,7 @@ mlir::Type elementType) { auto init = [](fir::FirOpBuilder builder, mlir::Location loc, mlir::Type elementType) { - if (auto ty = elementType.dyn_cast()) { + if (auto ty = mlir::dyn_cast(elementType)) { const llvm::fltSemantics &sem = ty.getFloatSemantics(); return builder.createRealConstant( loc, elementType, llvm::APFloat::getLargest(sem, /*Negative=*/true)); @@ -631,9 +631,9 @@ auto genBodyOp = [](fir::FirOpBuilder builder, mlir::Location loc, mlir::Type elementType, mlir::Value elem1, mlir::Value elem2) -> mlir::Value { - if (elementType.isa()) + if (mlir::isa(elementType)) return builder.create(loc, elem1, elem2); - if (elementType.isa()) + if (mlir::isa(elementType)) return builder.create(loc, elem1, elem2); llvm_unreachable("unsupported type"); @@ -762,7 +762,7 @@ mlir::Type resultElemTy) { auto init = [](fir::FirOpBuilder builder, mlir::Location loc, mlir::Type elementType) { - if (auto ty = elementType.dyn_cast()) { + if (auto ty = mlir::dyn_cast(elementType)) { const llvm::fltSemantics &sem = ty.getFloatSemantics(); return builder.createRealConstant( loc, elementType, llvm::APFloat::getLargest(sem, /*Negative=*/false)); @@ -807,10 +807,10 @@ llvm::SmallVector indices) -> mlir::Value { mlir::Value cmp; - if (elementType.isa()) { + if (mlir::isa(elementType)) { cmp = builder.create( loc, mlir::arith::CmpFPredicate::OLT, elem1, elem2); - } else if (elementType.isa()) { + } else if (mlir::isa(elementType)) { cmp = builder.create( loc, mlir::arith::CmpIPredicate::slt, elem1, elem2); } else { @@ -866,7 +866,7 @@ builder.setInsertionPointToStart(&ifOp.getElseRegion().front()); mlir::Value basicValue; - if (elementType.isa()) { + if (mlir::isa(elementType)) { basicValue = builder.createIntegerConstant(loc, elementType, 0); } else { basicValue = builder.createRealConstant(loc, elementType, 0); @@ -920,7 +920,7 @@ mlir::IndexType idxTy = builder.getIndexType(); mlir::Value zero = - resultElementType.isa() + mlir::isa(resultElementType) ? builder.createRealConstant(loc, resultElementType, 0.0) : builder.createIntegerConstant(loc, resultElementType, 0); @@ -977,10 +977,10 @@ // Convert to the result type. elem2 = builder.create(loc, resultElementType, elem2); - if (resultElementType.isa()) + if (mlir::isa(resultElementType)) sumVal = builder.create( loc, builder.create(loc, elem1, elem2), sumVal); - else if (resultElementType.isa()) + else if (mlir::isa(resultElementType)) sumVal = builder.create( loc, builder.create(loc, elem1, elem2), sumVal); else @@ -1058,8 +1058,8 @@ mlir::Type resultType = call.getResult(0).getType(); - if (!resultType.isa() && - !resultType.isa()) + if (!mlir::isa(resultType) && + !mlir::isa(resultType)) return; auto argType = getArgElementType(args[0]); @@ -1105,7 +1105,8 @@ fir::FirOpBuilder builder{getSimplificationBuilder(call, kindMap)}; // Treating logicals as integers makes things a lot easier - fir::LogicalType logicalType = {elementType.dyn_cast()}; + fir::LogicalType logicalType = { + mlir::dyn_cast(elementType)}; fir::KindTy kind = logicalType.getFKind(); mlir::Type intElementType = builder.getIntegerType(kind * 8); @@ -1140,7 +1141,8 @@ fir::FirOpBuilder builder{getSimplificationBuilder(call, kindMap)}; // Treating logicals as integers makes things a lot easier - fir::LogicalType logicalType = {elementType.dyn_cast()}; + fir::LogicalType logicalType = { + mlir::dyn_cast(elementType)}; fir::KindTy kind = logicalType.getFKind(); mlir::Type intElementType = builder.getIntegerType(kind * 8); @@ -1183,7 +1185,7 @@ auto inputBox = findBoxDef(args[1]); mlir::Type inputType = hlfir::getFortranElementType(inputBox.getType()); - if (inputType.isa()) + if (mlir::isa(inputType)) return; int maskRank; @@ -1194,7 +1196,8 @@ } else { maskRank = getDimCount(mask); mlir::Type maskElemTy = hlfir::getFortranElementType(maskDef.getType()); - fir::LogicalType logicalFirType = {maskElemTy.dyn_cast()}; + fir::LogicalType logicalFirType = { + mlir::dyn_cast(maskElemTy)}; kind = logicalFirType.getFKind(); // Convert fir::LogicalType to mlir::Type logicalElemType = logicalFirType; @@ -1301,7 +1304,8 @@ std::string fmfString{getFastMathFlagsString(builder)}; mlir::Type type = call.getResult(0).getType(); - if (!type.isa() && !type.isa()) + if (!mlir::isa(type) && + !mlir::isa(type)) return; // Try to find the element types of the boxed arguments. @@ -1313,11 +1317,11 @@ // Support only floating point and integer arguments // now (e.g. logical is skipped here). - if (!arg1Type->isa() && - !arg1Type->isa()) + if (!mlir::isa(*arg1Type) && + !mlir::isa(*arg1Type)) return; - if (!arg2Type->isa() && - !arg2Type->isa()) + if (!mlir::isa(*arg2Type) && + !mlir::isa(*arg2Type)) return; auto typeGenerator = [&type](fir::FirOpBuilder &builder) { diff --git a/flang/lib/Optimizer/Transforms/StackArrays.cpp b/flang/lib/Optimizer/Transforms/StackArrays.cpp --- a/flang/lib/Optimizer/Transforms/StackArrays.cpp +++ b/flang/lib/Optimizer/Transforms/StackArrays.cpp @@ -348,7 +348,7 @@ } auto retTy = allocmem.getAllocatedType(); - if (!retTy.isa()) { + if (!mlir::isa(retTy)) { 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 --- a/flang/unittests/Optimizer/Builder/ComplexTest.cpp +++ b/flang/unittests/Optimizer/Builder/ComplexTest.cpp @@ -96,6 +96,6 @@ // Convert complex to integer mlir::Value v2 = firBuilder->convertWithSemantics(loc, integerTy1, v1); - EXPECT_TRUE(v2.getType().isa()); + EXPECT_TRUE(mlir::isa(v2.getType())); EXPECT_TRUE(mlir::dyn_cast(v2.getDefiningOp())); } diff --git a/flang/unittests/Optimizer/Builder/DoLoopHelperTest.cpp b/flang/unittests/Optimizer/Builder/DoLoopHelperTest.cpp --- a/flang/unittests/Optimizer/Builder/DoLoopHelperTest.cpp +++ b/flang/unittests/Optimizer/Builder/DoLoopHelperTest.cpp @@ -34,7 +34,7 @@ void checkConstantValue(const mlir::Value &value, int64_t v) { EXPECT_TRUE(mlir::isa(value.getDefiningOp())); auto cstOp = dyn_cast(value.getDefiningOp()); - auto valueAttr = cstOp.getValue().dyn_cast_or_null(); + auto valueAttr = mlir::dyn_cast_if_present(cstOp.getValue()); EXPECT_EQ(v, valueAttr.getInt()); } diff --git a/flang/unittests/Optimizer/Builder/FIRBuilderTest.cpp b/flang/unittests/Optimizer/Builder/FIRBuilderTest.cpp --- a/flang/unittests/Optimizer/Builder/FIRBuilderTest.cpp +++ b/flang/unittests/Optimizer/Builder/FIRBuilderTest.cpp @@ -54,7 +54,7 @@ EXPECT_TRUE(mlir::isa(value.getDefiningOp())); auto cstOp = dyn_cast(value.getDefiningOp()); EXPECT_EQ(ty, cstOp.getType()); - auto valueAttr = cstOp.getValue().dyn_cast_or_null(); + auto valueAttr = mlir::dyn_cast_if_present(cstOp.getValue()); EXPECT_EQ(v, valueAttr.getInt()); } @@ -151,7 +151,7 @@ auto cstOp = dyn_cast(cst.getDefiningOp()); EXPECT_EQ(realTy, cstOp.getType()); EXPECT_EQ( - 0u, cstOp.getValue().cast().getValue().convertToDouble()); + 0u, mlir::cast(cstOp.getValue()).getValue().convertToDouble()); } TEST_F(FIRBuilderTest, createBool) { @@ -164,8 +164,8 @@ TEST_F(FIRBuilderTest, getVarLenSeqTy) { auto builder = getBuilder(); auto ty = builder.getVarLenSeqTy(builder.getI64Type()); - EXPECT_TRUE(ty.isa()); - fir::SequenceType seqTy = ty.dyn_cast(); + EXPECT_TRUE(mlir::isa(ty)); + fir::SequenceType seqTy = mlir::dyn_cast(ty); EXPECT_EQ(1u, seqTy.getDimension()); EXPECT_TRUE(fir::unwrapSequenceType(ty).isInteger(64)); } @@ -216,9 +216,9 @@ EXPECT_FALSE(global.getConstant().has_value()); EXPECT_EQ(i32Type, global.getType()); EXPECT_TRUE(global.getInitVal().has_value()); - EXPECT_TRUE(global.getInitVal().value().isa()); - EXPECT_EQ( - 16, global.getInitVal().value().cast().getValue()); + EXPECT_TRUE(mlir::isa(global.getInitVal().value())); + EXPECT_EQ(16, + mlir::cast(global.getInitVal().value()).getValue()); EXPECT_TRUE(global.getLinkName().has_value()); EXPECT_EQ( builder.createLinkOnceLinkage().getValue(), global.getLinkName().value()); @@ -271,12 +271,12 @@ auto stringLitOps = global.getRegion().front().getOps(); EXPECT_TRUE(llvm::hasSingleElement(stringLitOps)); for (auto stringLit : stringLitOps) { - EXPECT_EQ(10, stringLit.getSize().cast().getValue()); - EXPECT_TRUE(stringLit.getValue().isa()); + EXPECT_EQ( + 10, mlir::cast(stringLit.getSize()).getValue()); + EXPECT_TRUE(mlir::isa(stringLit.getValue())); EXPECT_EQ(0, strcmp("file1.f90\0", - stringLit.getValue() - .dyn_cast() + mlir::dyn_cast(stringLit.getValue()) .getValue() .str() .c_str())); @@ -288,9 +288,9 @@ llvm::StringRef data("mystringlitdata"); auto loc = builder.getUnknownLoc(); auto op = builder.createStringLitOp(loc, data); - EXPECT_EQ(15, op.getSize().cast().getValue()); - EXPECT_TRUE(op.getValue().isa()); - EXPECT_EQ(data, op.getValue().dyn_cast().getValue()); + EXPECT_EQ(15, mlir::cast(op.getSize()).getValue()); + EXPECT_TRUE(mlir::isa(op.getValue())); + EXPECT_EQ(data, mlir::dyn_cast(op.getValue()).getValue()); } TEST_F(FIRBuilderTest, createStringLiteral) { @@ -318,9 +318,11 @@ auto stringLitOps = global.getRegion().front().getOps(); EXPECT_TRUE(llvm::hasSingleElement(stringLitOps)); for (auto stringLit : stringLitOps) { - EXPECT_EQ(16, stringLit.getSize().cast().getValue()); - EXPECT_TRUE(stringLit.getValue().isa()); - EXPECT_EQ(strValue, stringLit.getValue().dyn_cast().getValue()); + EXPECT_EQ( + 16, mlir::cast(stringLit.getSize()).getValue()); + EXPECT_TRUE(mlir::isa(stringLit.getValue())); + EXPECT_EQ( + strValue, mlir::dyn_cast(stringLit.getValue()).getValue()); } } @@ -344,7 +346,7 @@ 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 = op.getType().dyn_cast(); + auto shapeTy = mlir::dyn_cast(op.getType()); EXPECT_EQ(2u, shapeTy.getRank()); EXPECT_EQ(2u, op.getExtents().size()); EXPECT_EQ(c10, op.getExtents()[0]); @@ -372,7 +374,7 @@ auto shape = builder.genShape(loc, shifts, extents); EXPECT_TRUE(mlir::isa(shape.getDefiningOp())); fir::ShapeShiftOp op = dyn_cast(shape.getDefiningOp()); - auto shapeTy = op.getType().dyn_cast(); + auto shapeTy = mlir::dyn_cast(op.getType()); EXPECT_EQ(2u, shapeTy.getRank()); EXPECT_EQ(2u, op.getExtents().size()); EXPECT_EQ(2u, op.getOrigins().size()); @@ -428,7 +430,7 @@ auto cst = mlir::dyn_cast_or_null(zeroInt.getDefiningOp()); EXPECT_TRUE(cst); - auto intAttr = cst.getValue().dyn_cast(); + auto intAttr = mlir::dyn_cast(cst.getValue()); EXPECT_TRUE(intAttr && intAttr.getInt() == 0); mlir::Type f32Ty = mlir::FloatType::getF32(builder.getContext()); @@ -437,7 +439,7 @@ auto cst2 = mlir::dyn_cast_or_null( zeroFloat.getDefiningOp()); EXPECT_TRUE(cst2); - auto floatAttr = cst2.getValue().dyn_cast(); + auto floatAttr = mlir::dyn_cast(cst2.getValue()); EXPECT_TRUE(floatAttr && floatAttr.getValueAsDouble() == 0.); mlir::Type boolTy = mlir::IntegerType::get(builder.getContext(), 1); @@ -446,7 +448,7 @@ auto cst3 = mlir::dyn_cast_or_null( flaseBool.getDefiningOp()); EXPECT_TRUE(cst3); - auto intAttr2 = cst.getValue().dyn_cast(); + auto intAttr2 = mlir::dyn_cast(cst.getValue()); EXPECT_TRUE(intAttr2 && intAttr2.getInt() == 0); } @@ -482,7 +484,7 @@ llvm::SmallVector arrays; auto extent = builder.create(loc, builder.getIndexType()); llvm::SmallVector extents( - arrayType.dyn_cast().getDimension(), + mlir::dyn_cast(arrayType).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 --- a/flang/unittests/Optimizer/RTBuilder.cpp +++ b/flang/unittests/Optimizer/RTBuilder.cpp @@ -27,7 +27,7 @@ mlir::Type c99_cacosf_signature{ fir::runtime::RuntimeTableKey::getTypeModel()( &ctx)}; - auto c99_cacosf_funcTy = c99_cacosf_signature.cast(); + auto c99_cacosf_funcTy = mlir::cast(c99_cacosf_signature); EXPECT_EQ(c99_cacosf_funcTy.getNumInputs(), 1u); EXPECT_EQ(c99_cacosf_funcTy.getNumResults(), 1u); auto cplx_ty = fir::ComplexType::get(&ctx, 4);