[flang-commits] [flang] 7aedd7d - Revert "[mlir] Mark `isa/dyn_cast/cast/...` member functions deprecated. (#89998)" (#90250)
via flang-commits
flang-commits at lists.llvm.org
Fri Apr 26 12:09:18 PDT 2024
Author: dyung
Date: 2024-04-26T12:09:13-07:00
New Revision: 7aedd7dc754c74a49fe84ed2640e269c25414087
URL: https://github.com/llvm/llvm-project/commit/7aedd7dc754c74a49fe84ed2640e269c25414087
DIFF: https://github.com/llvm/llvm-project/commit/7aedd7dc754c74a49fe84ed2640e269c25414087.diff
LOG: Revert "[mlir] Mark `isa/dyn_cast/cast/...` member functions deprecated. (#89998)" (#90250)
This reverts commit 950b7ce0b88318f9099e9a7c9817d224ebdc6337.
This change is causing build failures on a bot
https://lab.llvm.org/buildbot/#/builders/216/builds/38157
Added:
Modified:
flang/include/flang/Lower/Mangler.h
flang/include/flang/Optimizer/Analysis/TBAAForest.h
flang/include/flang/Optimizer/Builder/BoxValue.h
flang/include/flang/Optimizer/Builder/Factory.h
flang/include/flang/Optimizer/Builder/HLFIRTools.h
flang/include/flang/Optimizer/Builder/IntrinsicCall.h
flang/include/flang/Optimizer/Builder/PPCIntrinsicCall.h
flang/include/flang/Optimizer/Dialect/CanonicalizationPatterns.td
flang/include/flang/Optimizer/Dialect/FIROps.td
flang/include/flang/Optimizer/Dialect/FIRType.h
flang/include/flang/Optimizer/Dialect/FIRTypes.td
flang/include/flang/Optimizer/Dialect/FortranVariableInterface.td
flang/include/flang/Optimizer/HLFIR/HLFIRDialect.h
flang/include/flang/Optimizer/Support/Utils.h
flang/include/flang/Tools/PointerModels.h
flang/lib/Lower/Allocatable.cpp
flang/lib/Lower/Bridge.cpp
flang/lib/Lower/CallInterface.cpp
flang/lib/Lower/ConvertArrayConstructor.cpp
flang/lib/Lower/ConvertCall.cpp
flang/lib/Lower/ConvertConstant.cpp
flang/lib/Lower/ConvertExpr.cpp
flang/lib/Lower/ConvertExprToHLFIR.cpp
flang/lib/Lower/ConvertProcedureDesignator.cpp
flang/lib/Lower/ConvertVariable.cpp
flang/lib/Lower/CustomIntrinsicCall.cpp
flang/lib/Lower/DirectivesCommon.h
flang/lib/Lower/HlfirIntrinsics.cpp
flang/lib/Lower/HostAssociations.cpp
flang/lib/Lower/IO.cpp
flang/lib/Lower/OpenACC.cpp
flang/lib/Lower/OpenMP/ClauseProcessor.cpp
flang/lib/Lower/OpenMP/OpenMP.cpp
flang/lib/Lower/OpenMP/ReductionProcessor.cpp
flang/lib/Lower/VectorSubscripts.cpp
flang/lib/Optimizer/Analysis/AliasAnalysis.cpp
flang/lib/Optimizer/Builder/BoxValue.cpp
flang/lib/Optimizer/Builder/Character.cpp
flang/lib/Optimizer/Builder/Complex.cpp
flang/lib/Optimizer/Builder/FIRBuilder.cpp
flang/lib/Optimizer/Builder/HLFIRTools.cpp
flang/lib/Optimizer/Builder/IntrinsicCall.cpp
flang/lib/Optimizer/Builder/MutableBox.cpp
flang/lib/Optimizer/Builder/PPCIntrinsicCall.cpp
flang/lib/Optimizer/Builder/Runtime/Allocatable.cpp
flang/lib/Optimizer/Builder/Runtime/Character.cpp
flang/lib/Optimizer/Builder/Runtime/Intrinsics.cpp
flang/lib/Optimizer/Builder/Runtime/Ragged.cpp
flang/lib/Optimizer/Builder/Runtime/Reduction.cpp
flang/lib/Optimizer/CodeGen/BoxedProcedure.cpp
flang/lib/Optimizer/CodeGen/CGOps.cpp
flang/lib/Optimizer/CodeGen/CodeGen.cpp
flang/lib/Optimizer/CodeGen/FIROpPatterns.cpp
flang/lib/Optimizer/CodeGen/PreCGRewrite.cpp
flang/lib/Optimizer/CodeGen/TBAABuilder.cpp
flang/lib/Optimizer/CodeGen/Target.cpp
flang/lib/Optimizer/CodeGen/TargetRewrite.cpp
flang/lib/Optimizer/CodeGen/TypeConverter.cpp
flang/lib/Optimizer/Dialect/FIRAttr.cpp
flang/lib/Optimizer/Dialect/FIROps.cpp
flang/lib/Optimizer/Dialect/FIRType.cpp
flang/lib/Optimizer/Dialect/FortranVariableInterface.cpp
flang/lib/Optimizer/HLFIR/IR/HLFIRDialect.cpp
flang/lib/Optimizer/HLFIR/IR/HLFIROps.cpp
flang/lib/Optimizer/HLFIR/Transforms/BufferizeHLFIR.cpp
flang/lib/Optimizer/HLFIR/Transforms/ConvertToFIR.cpp
flang/lib/Optimizer/HLFIR/Transforms/LowerHLFIRIntrinsics.cpp
flang/lib/Optimizer/HLFIR/Transforms/LowerHLFIROrderedAssignments.cpp
flang/lib/Optimizer/HLFIR/Transforms/OptimizedBufferization.cpp
flang/lib/Optimizer/HLFIR/Transforms/SimplifyHLFIRIntrinsics.cpp
flang/lib/Optimizer/Transforms/AbstractResult.cpp
flang/lib/Optimizer/Transforms/AddDebugInfo.cpp
flang/lib/Optimizer/Transforms/AffineDemotion.cpp
flang/lib/Optimizer/Transforms/AffinePromotion.cpp
flang/lib/Optimizer/Transforms/ArrayValueCopy.cpp
flang/lib/Optimizer/Transforms/CharacterConversion.cpp
flang/lib/Optimizer/Transforms/LoopVersioning.cpp
flang/lib/Optimizer/Transforms/MemoryAllocation.cpp
flang/lib/Optimizer/Transforms/PolymorphicOpConversion.cpp
flang/lib/Optimizer/Transforms/SimplifyIntrinsics.cpp
flang/lib/Optimizer/Transforms/StackArrays.cpp
flang/unittests/Optimizer/Builder/ComplexTest.cpp
flang/unittests/Optimizer/Builder/DoLoopHelperTest.cpp
flang/unittests/Optimizer/Builder/FIRBuilderTest.cpp
flang/unittests/Optimizer/RTBuilder.cpp
llvm/include/llvm/ADT/TypeSwitch.h
mlir/include/mlir/Dialect/Linalg/IR/LinalgOps.td
mlir/include/mlir/Dialect/OpenMP/OpenMPOpsInterfaces.td
mlir/include/mlir/Dialect/XeGPU/IR/XeGPUOps.td
mlir/include/mlir/IR/Attributes.h
mlir/include/mlir/IR/BuiltinLocationAttributes.td
mlir/include/mlir/IR/Location.h
mlir/include/mlir/IR/Types.h
mlir/include/mlir/IR/Value.h
mlir/lib/Conversion/ComplexToStandard/ComplexToStandard.cpp
mlir/lib/Dialect/Polynomial/IR/PolynomialAttributes.cpp
mlir/lib/Dialect/Vector/Transforms/VectorLinearize.cpp
Removed:
################################################################################
diff --git a/flang/include/flang/Lower/Mangler.h b/flang/include/flang/Lower/Mangler.h
index 99da96b0d6ba51..41939abe29e5e2 100644
--- a/flang/include/flang/Lower/Mangler.h
+++ b/flang/include/flang/Lower/Mangler.h
@@ -90,7 +90,7 @@ inline std::string mangleArrayLiteral(
return mangleArrayLiteral(x.values().size() * sizeof(x.values()[0]),
x.shape(), Fortran::common::TypeCategory::Derived,
/*kind=*/0, /*charLen=*/-1,
- mlir::cast<fir::RecordType>(eleTy).getName());
+ eleTy.cast<fir::RecordType>().getName());
}
/// Return the compiler-generated name of a static namelist variable descriptor.
diff --git a/flang/include/flang/Optimizer/Analysis/TBAAForest.h b/flang/include/flang/Optimizer/Analysis/TBAAForest.h
index 619ed4939c51c4..b69e50bbe05c7e 100644
--- a/flang/include/flang/Optimizer/Analysis/TBAAForest.h
+++ b/flang/include/flang/Optimizer/Analysis/TBAAForest.h
@@ -88,7 +88,7 @@ class TBAAForrest {
// name must be used so that we add to the tbaa tree added in the FIR pass
mlir::Attribute attr = func->getAttr(getInternalFuncNameAttrName());
if (attr) {
- return getFuncTree(mlir::cast<mlir::StringAttr>(attr));
+ return getFuncTree(attr.cast<mlir::StringAttr>());
}
return getFuncTree(func.getSymNameAttr());
}
diff --git a/flang/include/flang/Optimizer/Builder/BoxValue.h b/flang/include/flang/Optimizer/Builder/BoxValue.h
index 5c7e89dbc08f11..2fed2d48a7a080 100644
--- a/flang/include/flang/Optimizer/Builder/BoxValue.h
+++ b/flang/include/flang/Optimizer/Builder/BoxValue.h
@@ -78,7 +78,7 @@ class CharBoxValue : public AbstractBox {
public:
CharBoxValue(mlir::Value addr, mlir::Value len)
: AbstractBox{addr}, len{len} {
- if (addr && mlir::isa<fir::BoxCharType>(addr.getType()))
+ if (addr && addr.getType().template isa<fir::BoxCharType>())
fir::emitFatalError(addr.getLoc(),
"BoxChar should not be in CharBoxValue");
}
@@ -221,7 +221,7 @@ class AbstractIrBox : public AbstractBox, public AbstractArrayBox {
auto type = getAddr().getType();
if (auto pointedTy = fir::dyn_cast_ptrEleTy(type))
type = pointedTy;
- return mlir::cast<fir::BaseBoxType>(type);
+ return type.cast<fir::BaseBoxType>();
}
/// Return the part of the address type after memory and box types. That is
/// the element type, maybe wrapped in a fir.array type.
@@ -243,22 +243,22 @@ class AbstractIrBox : public AbstractBox, public AbstractArrayBox {
/// Get the scalar type related to the described entity
mlir::Type getEleTy() const {
auto type = getBaseTy();
- if (auto seqTy = mlir::dyn_cast<fir::SequenceType>(type))
+ if (auto seqTy = type.dyn_cast<fir::SequenceType>())
return seqTy.getEleTy();
return type;
}
/// Is the entity an array or an assumed rank ?
- bool hasRank() const { return mlir::isa<fir::SequenceType>(getBaseTy()); }
+ bool hasRank() const { return getBaseTy().isa<fir::SequenceType>(); }
/// Is this an assumed rank ?
bool hasAssumedRank() const {
- auto seqTy = mlir::dyn_cast<fir::SequenceType>(getBaseTy());
+ auto seqTy = getBaseTy().dyn_cast<fir::SequenceType>();
return seqTy && seqTy.hasUnknownShape();
}
/// Returns the rank of the entity. Beware that zero will be returned for
/// both scalars and assumed rank.
unsigned rank() const {
- if (auto seqTy = mlir::dyn_cast<fir::SequenceType>(getBaseTy()))
+ if (auto seqTy = getBaseTy().dyn_cast<fir::SequenceType>())
return seqTy.getDimension();
return 0;
}
@@ -267,7 +267,7 @@ class AbstractIrBox : public AbstractBox, public AbstractArrayBox {
bool isCharacter() const { return fir::isa_char(getEleTy()); }
/// Is this a derived type entity ?
- bool isDerived() const { return mlir::isa<fir::RecordType>(getEleTy()); }
+ bool isDerived() const { return getEleTy().isa<fir::RecordType>(); }
bool isDerivedWithLenParameters() const {
return fir::isRecordWithTypeParameters(getEleTy());
@@ -377,11 +377,11 @@ class MutableBoxValue : public AbstractIrBox {
}
/// Is this a Fortran pointer ?
bool isPointer() const {
- return mlir::isa<fir::PointerType>(getBoxTy().getEleTy());
+ return getBoxTy().getEleTy().isa<fir::PointerType>();
}
/// Is this an allocatable ?
bool isAllocatable() const {
- return mlir::isa<fir::HeapType>(getBoxTy().getEleTy());
+ return getBoxTy().getEleTy().isa<fir::HeapType>();
}
// Replace the fir.ref<fir.box>, keeping any non-deferred parameters.
MutableBoxValue clone(mlir::Value newBox) const {
@@ -488,7 +488,7 @@ class ExtendedValue : public details::matcher<ExtendedValue> {
if (const auto *b = getUnboxed()) {
if (*b) {
auto type = b->getType();
- if (mlir::isa<fir::BoxCharType>(type))
+ if (type.template isa<fir::BoxCharType>())
fir::emitFatalError(b->getLoc(), "BoxChar should be unboxed");
type = fir::unwrapSequenceType(fir::unwrapRefType(type));
if (fir::isa_char(type))
diff --git a/flang/include/flang/Optimizer/Builder/Factory.h b/flang/include/flang/Optimizer/Builder/Factory.h
index 4e5c52ac44e07e..ec294d26ac961c 100644
--- a/flang/include/flang/Optimizer/Builder/Factory.h
+++ b/flang/include/flang/Optimizer/Builder/Factory.h
@@ -43,9 +43,9 @@ template <typename B>
void genCharacterCopy(mlir::Value src, mlir::Value srcLen, mlir::Value dst,
mlir::Value dstLen, B &builder, mlir::Location loc) {
auto srcTy =
- mlir::cast<fir::CharacterType>(fir::dyn_cast_ptrEleTy(src.getType()));
+ fir::dyn_cast_ptrEleTy(src.getType()).template cast<fir::CharacterType>();
auto dstTy =
- mlir::cast<fir::CharacterType>(fir::dyn_cast_ptrEleTy(dst.getType()));
+ fir::dyn_cast_ptrEleTy(dst.getType()).template cast<fir::CharacterType>();
if (!srcLen && !dstLen && srcTy.getFKind() == dstTy.getFKind() &&
srcTy.getLen() == dstTy.getLen()) {
// same size, so just use load and store
@@ -61,8 +61,8 @@ void genCharacterCopy(mlir::Value src, mlir::Value srcLen, mlir::Value dst,
fir::CharacterType::getSingleton(ty.getContext(), ty.getFKind())));
};
auto toEleTy = [&](fir::ReferenceType ty) {
- auto seqTy = mlir::cast<fir::SequenceType>(ty.getEleTy());
- return mlir::cast<fir::CharacterType>(seqTy.getEleTy());
+ auto seqTy = ty.getEleTy().cast<fir::SequenceType>();
+ return seqTy.getEleTy().cast<fir::CharacterType>();
};
auto toCoorTy = [&](fir::ReferenceType ty) {
return fir::ReferenceType::get(toEleTy(ty));
@@ -190,8 +190,8 @@ originateIndices(mlir::Location loc, B &builder, mlir::Type memTy,
if (origins.empty()) {
assert(!shapeVal || mlir::isa<fir::ShapeOp>(shapeVal.getDefiningOp()));
auto ty = fir::dyn_cast_ptrOrBoxEleTy(memTy);
- assert(ty && mlir::isa<fir::SequenceType>(ty));
- auto seqTy = mlir::cast<fir::SequenceType>(ty);
+ assert(ty && ty.isa<fir::SequenceType>());
+ auto seqTy = ty.cast<fir::SequenceType>();
auto one = builder.template create<mlir::arith::ConstantIndexOp>(loc, 1);
const auto dimension = seqTy.getDimension();
if (shapeVal) {
diff --git a/flang/include/flang/Optimizer/Builder/HLFIRTools.h b/flang/include/flang/Optimizer/Builder/HLFIRTools.h
index 6c36f7e84db688..035035601e2f25 100644
--- a/flang/include/flang/Optimizer/Builder/HLFIRTools.h
+++ b/flang/include/flang/Optimizer/Builder/HLFIRTools.h
@@ -77,12 +77,12 @@ class Entity : public mlir::Value {
/// Return the rank of this entity or -1 if it is an assumed rank.
int getRank() const {
mlir::Type type = fir::unwrapPassByRefType(fir::unwrapRefType(getType()));
- if (auto seqTy = mlir::dyn_cast<fir::SequenceType>(type)) {
+ if (auto seqTy = type.dyn_cast<fir::SequenceType>()) {
if (seqTy.hasUnknownShape())
return -1;
return seqTy.getDimension();
}
- if (auto exprType = mlir::dyn_cast<hlfir::ExprType>(type))
+ if (auto exprType = type.dyn_cast<hlfir::ExprType>())
return exprType.getRank();
return 0;
}
@@ -99,17 +99,17 @@ class Entity : public mlir::Value {
bool hasLengthParameters() const {
mlir::Type eleTy = getFortranElementType();
- return mlir::isa<fir::CharacterType>(eleTy) ||
+ return eleTy.isa<fir::CharacterType>() ||
fir::isRecordWithTypeParameters(eleTy);
}
bool isCharacter() const {
- return mlir::isa<fir::CharacterType>(getFortranElementType());
+ return getFortranElementType().isa<fir::CharacterType>();
}
bool hasIntrinsicType() const {
mlir::Type eleTy = getFortranElementType();
- return fir::isa_trivial(eleTy) || mlir::isa<fir::CharacterType>(eleTy);
+ return fir::isa_trivial(eleTy) || eleTy.isa<fir::CharacterType>();
}
bool isDerivedWithLengthParameters() const {
@@ -124,8 +124,8 @@ class Entity : public mlir::Value {
if (auto varIface = getIfVariableInterface()) {
if (auto shape = varIface.getShape()) {
auto shapeTy = shape.getType();
- return mlir::isa<fir::ShiftType>(shapeTy) ||
- mlir::isa<fir::ShapeShiftType>(shapeTy);
+ return shapeTy.isa<fir::ShiftType>() ||
+ shapeTy.isa<fir::ShapeShiftType>();
}
return false;
}
diff --git a/flang/include/flang/Optimizer/Builder/IntrinsicCall.h b/flang/include/flang/Optimizer/Builder/IntrinsicCall.h
index b7d06092676132..604f2bd969eed5 100644
--- a/flang/include/flang/Optimizer/Builder/IntrinsicCall.h
+++ b/flang/include/flang/Optimizer/Builder/IntrinsicCall.h
@@ -663,8 +663,8 @@ static inline mlir::FunctionType genFuncType(mlir::MLIRContext *context,
//===----------------------------------------------------------------------===//
static inline mlir::Type getConvertedElementType(mlir::MLIRContext *context,
mlir::Type eleTy) {
- if (mlir::isa<mlir::IntegerType>(eleTy) && !eleTy.isSignlessInteger()) {
- const auto intTy{mlir::dyn_cast<mlir::IntegerType>(eleTy)};
+ if (eleTy.isa<mlir::IntegerType>() && !eleTy.isSignlessInteger()) {
+ const auto intTy{eleTy.dyn_cast<mlir::IntegerType>()};
auto newEleTy{mlir::IntegerType::get(context, intTy.getWidth())};
return newEleTy;
}
diff --git a/flang/include/flang/Optimizer/Builder/PPCIntrinsicCall.h b/flang/include/flang/Optimizer/Builder/PPCIntrinsicCall.h
index a7c4c075d818ee..1e87bf0f6ad159 100644
--- a/flang/include/flang/Optimizer/Builder/PPCIntrinsicCall.h
+++ b/flang/include/flang/Optimizer/Builder/PPCIntrinsicCall.h
@@ -180,10 +180,10 @@ struct VecTypeInfo {
// Returns a VecTypeInfo with element type and length of given fir vector type.
// Preserves signness of fir vector type if element type of integer.
static inline VecTypeInfo getVecTypeFromFirType(mlir::Type firTy) {
- assert(mlir::isa<fir::VectorType>(firTy));
+ assert(firTy.isa<fir::VectorType>());
VecTypeInfo vecTyInfo;
- vecTyInfo.eleTy = mlir::dyn_cast<fir::VectorType>(firTy).getEleTy();
- vecTyInfo.len = mlir::dyn_cast<fir::VectorType>(firTy).getLen();
+ vecTyInfo.eleTy = firTy.dyn_cast<fir::VectorType>().getEleTy();
+ vecTyInfo.len = firTy.dyn_cast<fir::VectorType>().getLen();
return vecTyInfo;
}
diff --git a/flang/include/flang/Optimizer/Dialect/CanonicalizationPatterns.td b/flang/include/flang/Optimizer/Dialect/CanonicalizationPatterns.td
index 0ef37a37ce94f8..544fc3cdf75eab 100644
--- a/flang/include/flang/Optimizer/Dialect/CanonicalizationPatterns.td
+++ b/flang/include/flang/Optimizer/Dialect/CanonicalizationPatterns.td
@@ -21,18 +21,17 @@ include "flang/Optimizer/Dialect/FIROps.td"
def IdenticalTypePred : Constraint<CPred<"$0.getType() == $1.getType()">>;
def IntegerTypePred : Constraint<CPred<"fir::isa_integer($0.getType())">>;
-def IndexTypePred : Constraint<CPred<
- "mlir::isa<mlir::IndexType>($0.getType())">>;
+def IndexTypePred : Constraint<CPred<"$0.getType().isa<mlir::IndexType>()">>;
// Widths are monotonic.
// $0.bits >= $1.bits >= $2.bits or $0.bits <= $1.bits <= $2.bits
def MonotonicTypePred
- : Constraint<CPred<"((mlir::isa<mlir::IntegerType>($0.getType()) && "
- " mlir::isa<mlir::IntegerType>($1.getType()) && "
- " mlir::isa<mlir::IntegerType>($2.getType())) || "
- " (mlir::isa<mlir::FloatType>($0.getType()) && "
- " mlir::isa<mlir::FloatType>($1.getType()) && "
- " mlir::isa<mlir::FloatType>($2.getType()))) && "
+ : Constraint<CPred<"(($0.getType().isa<mlir::IntegerType>() && "
+ " $1.getType().isa<mlir::IntegerType>() && "
+ " $2.getType().isa<mlir::IntegerType>()) || "
+ " ($0.getType().isa<mlir::FloatType>() && "
+ " $1.getType().isa<mlir::FloatType>() && "
+ " $2.getType().isa<mlir::FloatType>())) && "
"(($0.getType().getIntOrFloatBitWidth() <= "
" $1.getType().getIntOrFloatBitWidth() && "
" $1.getType().getIntOrFloatBitWidth() <= "
@@ -43,8 +42,8 @@ def MonotonicTypePred
" $2.getType().getIntOrFloatBitWidth()))">>;
def IntPred : Constraint<CPred<
- "mlir::isa<mlir::IntegerType>($0.getType()) && "
- "mlir::isa<mlir::IntegerType>($1.getType())">>;
+ "$0.getType().isa<mlir::IntegerType>() && "
+ "$1.getType().isa<mlir::IntegerType>()">>;
// If both are int type and the first is smaller than the second.
// $0.bits <= $1.bits
@@ -102,8 +101,8 @@ def CombineConvertTruncOptPattern
def createConstantOp
: NativeCodeCall<"$_builder.create<mlir::arith::ConstantOp>"
"($_loc, $_builder.getIndexType(), "
- "rewriter.getIndexAttr("
- "mlir::dyn_cast<mlir::IntegerAttr>($1).getInt()))">;
+ "rewriter.getIndexAttr($1.dyn_cast<mlir::IntegerAttr>()"
+ ".getInt()))">;
def ForwardConstantConvertPattern
: Pat<(fir_ConvertOp:$res (Arith_ConstantOp:$cnt $attr)),
diff --git a/flang/include/flang/Optimizer/Dialect/FIROps.td b/flang/include/flang/Optimizer/Dialect/FIROps.td
index 496193e25cab61..92790a691e4731 100644
--- a/flang/include/flang/Optimizer/Dialect/FIROps.td
+++ b/flang/include/flang/Optimizer/Dialect/FIROps.td
@@ -2708,14 +2708,14 @@ def fir_ConvertOp : fir_OneResultOp<"convert", [NoMemoryEffect]> {
let hasCanonicalizer = 1;
}
-def FortranTypeAttr : Attr<And<[CPred<"mlir::isa<mlir::TypeAttr>($_self)">,
- Or<[CPred<"mlir::isa<fir::CharacterType, fir::ComplexType, "
- "fir::IntegerType, fir::LogicalType, fir::RealType, "
- "fir::RecordType>(mlir::cast<mlir::TypeAttr>($_self).getValue())"
- >]>]>, "Fortran surface type"> {
+def FortranTypeAttr : Attr<And<[CPred<"$_self.isa<mlir::TypeAttr>()">,
+ Or<[CPred<"$_self.cast<mlir::TypeAttr>().getValue().isa<fir::CharacterType,"
+ "fir::ComplexType, fir::IntegerType, fir::LogicalType,"
+ "fir::RealType, fir::RecordType>()">]>]>,
+ "Fortran surface type"> {
let storageType = [{ ::mlir::TypeAttr }];
let returnType = "mlir::Type";
- let convertFromStorage = "mlir::cast<mlir::Type>($_self.getValue())";
+ let convertFromStorage = "$_self.getValue().cast<mlir::Type>()";
}
def fir_TypeDescOp : fir_OneResultOp<"type_desc", [NoMemoryEffect]> {
diff --git a/flang/include/flang/Optimizer/Dialect/FIRType.h b/flang/include/flang/Optimizer/Dialect/FIRType.h
index b4344435db9f5f..7fcd9c1babf24f 100644
--- a/flang/include/flang/Optimizer/Dialect/FIRType.h
+++ b/flang/include/flang/Optimizer/Dialect/FIRType.h
@@ -97,36 +97,35 @@ bool isa_fir_or_std_type(mlir::Type t);
/// Is `t` a FIR dialect type that implies a memory (de)reference?
inline bool isa_ref_type(mlir::Type t) {
- return mlir::isa<fir::ReferenceType, fir::PointerType, fir::HeapType,
- fir::LLVMPointerType>(t);
+ return t.isa<fir::ReferenceType, fir::PointerType, fir::HeapType,
+ fir::LLVMPointerType>();
}
/// Is `t` a boxed type?
inline bool isa_box_type(mlir::Type t) {
- return mlir::isa<fir::BaseBoxType, fir::BoxCharType, fir::BoxProcType>(t);
+ return t.isa<fir::BaseBoxType, fir::BoxCharType, fir::BoxProcType>();
}
/// Is `t` a type that is always trivially pass-by-reference? Specifically, this
/// is testing if `t` is a ReferenceType or any box type. Compare this to
/// conformsWithPassByRef(), which includes pointers and allocatables.
inline bool isa_passbyref_type(mlir::Type t) {
- return mlir::isa<fir::ReferenceType, mlir::FunctionType>(t) ||
- isa_box_type(t);
+ return t.isa<fir::ReferenceType, mlir::FunctionType>() || isa_box_type(t);
}
/// Is `t` a type that can conform to be pass-by-reference? Depending on the
/// context, these types may simply demote to pass-by-reference or a reference
/// to them may have to be passed instead. Functions are always referent.
inline bool conformsWithPassByRef(mlir::Type t) {
- return isa_ref_type(t) || isa_box_type(t) || mlir::isa<mlir::FunctionType>(t);
+ return isa_ref_type(t) || isa_box_type(t) || t.isa<mlir::FunctionType>();
}
/// Is `t` a derived (record) type?
-inline bool isa_derived(mlir::Type t) { return mlir::isa<fir::RecordType>(t); }
+inline bool isa_derived(mlir::Type t) { return t.isa<fir::RecordType>(); }
/// Is `t` type(c_ptr) or type(c_funptr)?
inline bool isa_builtin_cptr_type(mlir::Type t) {
- if (auto recTy = mlir::dyn_cast_or_null<fir::RecordType>(t))
+ if (auto recTy = t.dyn_cast_or_null<fir::RecordType>())
return recTy.getName().ends_with("T__builtin_c_ptr") ||
recTy.getName().ends_with("T__builtin_c_funptr");
return false;
@@ -134,7 +133,7 @@ inline bool isa_builtin_cptr_type(mlir::Type t) {
/// Is `t` a FIR dialect aggregate type?
inline bool isa_aggregate(mlir::Type t) {
- return mlir::isa<SequenceType, mlir::TupleType>(t) || fir::isa_derived(t);
+ return t.isa<SequenceType, mlir::TupleType>() || fir::isa_derived(t);
}
/// Extract the `Type` pointed to from a FIR memory reference type. If `t` is
@@ -147,17 +146,17 @@ mlir::Type dyn_cast_ptrOrBoxEleTy(mlir::Type t);
/// Is `t` a FIR Real or MLIR Float type?
inline bool isa_real(mlir::Type t) {
- return mlir::isa<fir::RealType, mlir::FloatType>(t);
+ return t.isa<fir::RealType, mlir::FloatType>();
}
/// Is `t` an integral type?
inline bool isa_integer(mlir::Type t) {
- return mlir::isa<mlir::IndexType, mlir::IntegerType, fir::IntegerType>(t);
+ return t.isa<mlir::IndexType, mlir::IntegerType, fir::IntegerType>();
}
/// Is `t` a vector type?
inline bool isa_vector(mlir::Type t) {
- return mlir::isa<mlir::VectorType, fir::VectorType>(t);
+ return t.isa<mlir::VectorType, fir::VectorType>();
}
mlir::Type parseFirType(FIROpsDialect *, mlir::DialectAsmParser &parser);
@@ -170,22 +169,22 @@ void verifyIntegralType(mlir::Type type);
/// Is `t` a FIR or MLIR Complex type?
inline bool isa_complex(mlir::Type t) {
- return mlir::isa<fir::ComplexType, mlir::ComplexType>(t);
+ return t.isa<fir::ComplexType, mlir::ComplexType>();
}
/// Is `t` a CHARACTER type? Does not check the length.
-inline bool isa_char(mlir::Type t) { return mlir::isa<fir::CharacterType>(t); }
+inline bool isa_char(mlir::Type t) { return t.isa<fir::CharacterType>(); }
/// Is `t` a trivial intrinsic type? CHARACTER is <em>excluded</em> because it
/// is a dependent type.
inline bool isa_trivial(mlir::Type t) {
return isa_integer(t) || isa_real(t) || isa_complex(t) || isa_vector(t) ||
- mlir::isa<fir::LogicalType>(t);
+ t.isa<fir::LogicalType>();
}
/// Is `t` a CHARACTER type with a LEN other than 1?
inline bool isa_char_string(mlir::Type t) {
- if (auto ct = mlir::dyn_cast_or_null<fir::CharacterType>(t))
+ if (auto ct = t.dyn_cast_or_null<fir::CharacterType>())
return ct.getLen() != fir::CharacterType::singleton();
return false;
}
@@ -199,7 +198,7 @@ bool isa_unknown_size_box(mlir::Type t);
/// Returns true iff `t` is a fir.char type and has an unknown length.
inline bool characterWithDynamicLen(mlir::Type t) {
- if (auto charTy = mlir::dyn_cast<fir::CharacterType>(t))
+ if (auto charTy = t.dyn_cast<fir::CharacterType>())
return charTy.hasDynamicLen();
return false;
}
@@ -214,11 +213,11 @@ inline bool sequenceWithNonConstantShape(fir::SequenceType seqTy) {
bool hasDynamicSize(mlir::Type t);
inline unsigned getRankOfShapeType(mlir::Type t) {
- if (auto shTy = mlir::dyn_cast<fir::ShapeType>(t))
+ if (auto shTy = t.dyn_cast<fir::ShapeType>())
return shTy.getRank();
- if (auto shTy = mlir::dyn_cast<fir::ShapeShiftType>(t))
+ if (auto shTy = t.dyn_cast<fir::ShapeShiftType>())
return shTy.getRank();
- if (auto shTy = mlir::dyn_cast<fir::ShiftType>(t))
+ if (auto shTy = t.dyn_cast<fir::ShiftType>())
return shTy.getRank();
return 0;
}
@@ -226,14 +225,14 @@ inline unsigned getRankOfShapeType(mlir::Type t) {
/// Get the memory reference type of the data pointer from the box type,
inline mlir::Type boxMemRefType(fir::BaseBoxType t) {
auto eleTy = t.getEleTy();
- if (!mlir::isa<fir::PointerType, fir::HeapType>(eleTy))
+ if (!eleTy.isa<fir::PointerType, fir::HeapType>())
eleTy = fir::ReferenceType::get(t);
return eleTy;
}
/// If `t` is a SequenceType return its element type, otherwise return `t`.
inline mlir::Type unwrapSequenceType(mlir::Type t) {
- if (auto seqTy = mlir::dyn_cast<fir::SequenceType>(t))
+ if (auto seqTy = t.dyn_cast<fir::SequenceType>())
return seqTy.getEleTy();
return t;
}
@@ -279,7 +278,7 @@ inline fir::SequenceType unwrapUntilSeqType(mlir::Type t) {
t = ty;
continue;
}
- if (auto seqTy = mlir::dyn_cast<fir::SequenceType>(t))
+ if (auto seqTy = t.dyn_cast<fir::SequenceType>())
return seqTy;
return {};
}
@@ -288,8 +287,8 @@ inline fir::SequenceType unwrapUntilSeqType(mlir::Type t) {
/// Unwrap the referential and sequential outer types (if any). Returns the
/// the element if type is fir::RecordType
inline fir::RecordType unwrapIfDerived(fir::BaseBoxType boxTy) {
- return mlir::dyn_cast<fir::RecordType>(
- fir::unwrapSequenceType(fir::unwrapRefType(boxTy.getEleTy())));
+ return fir::unwrapSequenceType(fir::unwrapRefType(boxTy.getEleTy()))
+ .template dyn_cast<fir::RecordType>();
}
/// Return true iff `boxTy` wraps a fir::RecordType with length parameters
@@ -378,7 +377,7 @@ bool isRecordWithDescriptorMember(mlir::Type ty);
/// Return true iff `ty` is a RecordType with type parameters.
inline bool isRecordWithTypeParameters(mlir::Type ty) {
- if (auto recTy = mlir::dyn_cast_or_null<fir::RecordType>(ty))
+ if (auto recTy = ty.dyn_cast_or_null<fir::RecordType>())
return recTy.isDependentType();
return false;
}
@@ -402,14 +401,14 @@ mlir::Type fromRealTypeID(mlir::MLIRContext *context, llvm::Type::TypeID typeID,
int getTypeCode(mlir::Type ty, const KindMapping &kindMap);
inline bool BaseBoxType::classof(mlir::Type type) {
- return mlir::isa<fir::BoxType, fir::ClassType>(type);
+ return type.isa<fir::BoxType, fir::ClassType>();
}
/// Return true iff `ty` is none or fir.array<none>.
inline bool isNoneOrSeqNone(mlir::Type type) {
- if (auto seqTy = mlir::dyn_cast<fir::SequenceType>(type))
- return mlir::isa<mlir::NoneType>(seqTy.getEleTy());
- return mlir::isa<mlir::NoneType>(type);
+ if (auto seqTy = type.dyn_cast<fir::SequenceType>())
+ return seqTy.getEleTy().isa<mlir::NoneType>();
+ return type.isa<mlir::NoneType>();
}
/// Return a fir.box<T> or fir.class<T> if the type is polymorphic. If the type
@@ -429,16 +428,16 @@ inline mlir::Type wrapInClassOrBoxType(mlir::Type eleTy,
/// !fir.array<2xf32> -> !fir.array<2xnone>
/// !fir.heap<!fir.array<2xf32>> -> !fir.heap<!fir.array<2xnone>>
inline mlir::Type updateTypeForUnlimitedPolymorphic(mlir::Type ty) {
- if (auto seqTy = mlir::dyn_cast<fir::SequenceType>(ty))
+ if (auto seqTy = ty.dyn_cast<fir::SequenceType>())
return fir::SequenceType::get(
seqTy.getShape(), updateTypeForUnlimitedPolymorphic(seqTy.getEleTy()));
- if (auto heapTy = mlir::dyn_cast<fir::HeapType>(ty))
+ if (auto heapTy = ty.dyn_cast<fir::HeapType>())
return fir::HeapType::get(
updateTypeForUnlimitedPolymorphic(heapTy.getEleTy()));
- if (auto pointerTy = mlir::dyn_cast<fir::PointerType>(ty))
+ if (auto pointerTy = ty.dyn_cast<fir::PointerType>())
return fir::PointerType::get(
updateTypeForUnlimitedPolymorphic(pointerTy.getEleTy()));
- if (!mlir::isa<mlir::NoneType, fir::RecordType>(ty))
+ if (!ty.isa<mlir::NoneType, fir::RecordType>())
return mlir::NoneType::get(ty.getContext());
return ty;
}
@@ -452,19 +451,18 @@ mlir::Type changeElementType(mlir::Type type, mlir::Type newElementType,
/// Is `t` an address to fir.box or class type?
inline bool isBoxAddress(mlir::Type t) {
- return fir::isa_ref_type(t) &&
- mlir::isa<fir::BaseBoxType>(fir::unwrapRefType(t));
+ return fir::isa_ref_type(t) && fir::unwrapRefType(t).isa<fir::BaseBoxType>();
}
/// Is `t` a fir.box or class address or value type?
inline bool isBoxAddressOrValue(mlir::Type t) {
- return mlir::isa<fir::BaseBoxType>(fir::unwrapRefType(t));
+ return fir::unwrapRefType(t).isa<fir::BaseBoxType>();
}
/// Is this a fir.boxproc address type?
inline bool isBoxProcAddressType(mlir::Type t) {
t = fir::dyn_cast_ptrEleTy(t);
- return t && mlir::isa<fir::BoxProcType>(t);
+ return t && t.isa<fir::BoxProcType>();
}
/// Return a string representation of `ty`.
diff --git a/flang/include/flang/Optimizer/Dialect/FIRTypes.td b/flang/include/flang/Optimizer/Dialect/FIRTypes.td
index 7378ed93944c95..3b876e4642da9a 100644
--- a/flang/include/flang/Optimizer/Dialect/FIRTypes.td
+++ b/flang/include/flang/Optimizer/Dialect/FIRTypes.td
@@ -578,7 +578,7 @@ def fir_VoidType : FIR_Type<"Void", "void"> {
// Whether a type is a BaseBoxType
def IsBaseBoxTypePred
- : CPred<"mlir::isa<::fir::BaseBoxType>($_self)">;
+ : CPred<"$_self.isa<::fir::BaseBoxType>()">;
def fir_BaseBoxType : Type<IsBaseBoxTypePred, "fir.box or fir.class type">;
// Generalized FIR and standard dialect types representing intrinsic types
diff --git a/flang/include/flang/Optimizer/Dialect/FortranVariableInterface.td b/flang/include/flang/Optimizer/Dialect/FortranVariableInterface.td
index 3f78a93a2515ef..6405afbf1bfbc2 100644
--- a/flang/include/flang/Optimizer/Dialect/FortranVariableInterface.td
+++ b/flang/include/flang/Optimizer/Dialect/FortranVariableInterface.td
@@ -75,7 +75,7 @@ def fir_FortranVariableOpInterface : OpInterface<"FortranVariableOpInterface"> {
/// variable.
mlir::Type getElementOrSequenceType() {
mlir::Type type = fir::unwrapPassByRefType(fir::unwrapRefType(getBase().getType()));
- if (auto boxCharType = mlir::dyn_cast<fir::BoxCharType>(type))
+ if (auto boxCharType = type.dyn_cast<fir::BoxCharType>())
return boxCharType.getEleTy();
return type;
}
@@ -87,13 +87,13 @@ def fir_FortranVariableOpInterface : OpInterface<"FortranVariableOpInterface"> {
/// Is the variable an array?
bool isArray() {
- return mlir::isa<fir::SequenceType>(getElementOrSequenceType());
+ return getElementOrSequenceType().isa<fir::SequenceType>();
}
/// Return the rank of the entity if it is known at compile time.
std::optional<unsigned> getRank() {
if (auto sequenceType =
- mlir::dyn_cast<fir::SequenceType>(getElementOrSequenceType())) {
+ getElementOrSequenceType().dyn_cast<fir::SequenceType>()) {
if (sequenceType.hasUnknownShape())
return {};
return sequenceType.getDimension();
@@ -133,7 +133,7 @@ def fir_FortranVariableOpInterface : OpInterface<"FortranVariableOpInterface"> {
/// Is this a Fortran character variable?
bool isCharacter() {
- return mlir::isa<fir::CharacterType>(getElementType());
+ return getElementType().isa<fir::CharacterType>();
}
/// Is this a Fortran character variable with an explicit length?
@@ -149,7 +149,7 @@ def fir_FortranVariableOpInterface : OpInterface<"FortranVariableOpInterface"> {
/// Is this variable represented as a fir.box or fir.class value?
bool isBoxValue() {
- return mlir::isa<fir::BaseBoxType>(getBase().getType());
+ return getBase().getType().isa<fir::BaseBoxType>();
}
/// Is this variable represented as a fir.box or fir.class address?
diff --git a/flang/include/flang/Optimizer/HLFIR/HLFIRDialect.h b/flang/include/flang/Optimizer/HLFIR/HLFIRDialect.h
index 3830237f96f3cc..aa68d0811c4868 100644
--- a/flang/include/flang/Optimizer/HLFIR/HLFIRDialect.h
+++ b/flang/include/flang/Optimizer/HLFIR/HLFIRDialect.h
@@ -40,9 +40,9 @@ namespace hlfir {
inline mlir::Type getFortranElementType(mlir::Type type) {
type = fir::unwrapSequenceType(
fir::unwrapPassByRefType(fir::unwrapRefType(type)));
- if (auto exprType = mlir::dyn_cast<hlfir::ExprType>(type))
+ if (auto exprType = type.dyn_cast<hlfir::ExprType>())
return exprType.getEleTy();
- if (auto boxCharType = mlir::dyn_cast<fir::BoxCharType>(type))
+ if (auto boxCharType = type.dyn_cast<fir::BoxCharType>())
return boxCharType.getEleTy();
return type;
}
@@ -51,12 +51,12 @@ inline mlir::Type getFortranElementType(mlir::Type type) {
/// fir.array type. Otherwise, returns the Fortran element typeof the entity.
inline mlir::Type getFortranElementOrSequenceType(mlir::Type type) {
type = fir::unwrapPassByRefType(fir::unwrapRefType(type));
- if (auto exprType = mlir::dyn_cast<hlfir::ExprType>(type)) {
+ if (auto exprType = type.dyn_cast<hlfir::ExprType>()) {
if (exprType.isArray())
return fir::SequenceType::get(exprType.getShape(), exprType.getEleTy());
return exprType.getEleTy();
}
- if (auto boxCharType = mlir::dyn_cast<fir::BoxCharType>(type))
+ if (auto boxCharType = type.dyn_cast<fir::BoxCharType>())
return boxCharType.getEleTy();
return type;
}
@@ -64,16 +64,16 @@ inline mlir::Type getFortranElementOrSequenceType(mlir::Type type) {
/// Is this a fir.box or fir.class address type?
inline bool isBoxAddressType(mlir::Type type) {
type = fir::dyn_cast_ptrEleTy(type);
- return type && mlir::isa<fir::BaseBoxType>(type);
+ return type && type.isa<fir::BaseBoxType>();
}
/// Is this a fir.box or fir.class address or value type?
inline bool isBoxAddressOrValueType(mlir::Type type) {
- return mlir::isa<fir::BaseBoxType>(fir::unwrapRefType(type));
+ return fir::unwrapRefType(type).isa<fir::BaseBoxType>();
}
inline bool isPolymorphicType(mlir::Type type) {
- if (auto exprType = mlir::dyn_cast<hlfir::ExprType>(type))
+ if (auto exprType = type.dyn_cast<hlfir::ExprType>())
return exprType.isPolymorphic();
return fir::isPolymorphicType(type);
}
@@ -81,14 +81,14 @@ inline bool isPolymorphicType(mlir::Type type) {
/// Is this an SSA value type for the value of a Fortran procedure
/// designator ?
inline bool isFortranProcedureValue(mlir::Type type) {
- return mlir::isa<fir::BoxProcType>(type) ||
- (mlir::isa<mlir::TupleType>(type) &&
+ return type.isa<fir::BoxProcType>() ||
+ (type.isa<mlir::TupleType>() &&
fir::isCharacterProcedureTuple(type, /*acceptRawFunc=*/false));
}
/// Is this an SSA value type for the value of a Fortran expression?
inline bool isFortranValueType(mlir::Type type) {
- return mlir::isa<hlfir::ExprType>(type) || fir::isa_trivial(type) ||
+ return type.isa<hlfir::ExprType>() || fir::isa_trivial(type) ||
isFortranProcedureValue(type);
}
diff --git a/flang/include/flang/Optimizer/Support/Utils.h b/flang/include/flang/Optimizer/Support/Utils.h
index 2da6f24da40e93..2b4fa50e0e4217 100644
--- a/flang/include/flang/Optimizer/Support/Utils.h
+++ b/flang/include/flang/Optimizer/Support/Utils.h
@@ -29,9 +29,7 @@
namespace fir {
/// Return the integer value of a arith::ConstantOp.
inline std::int64_t toInt(mlir::arith::ConstantOp cop) {
- return mlir::cast<mlir::IntegerAttr>(cop.getValue())
- .getValue()
- .getSExtValue();
+ return cop.getValue().cast<mlir::IntegerAttr>().getValue().getSExtValue();
}
// Reconstruct binding tables for dynamic dispatch.
diff --git a/flang/include/flang/Tools/PointerModels.h b/flang/include/flang/Tools/PointerModels.h
index c3c0977d6e54a8..7acaf2f9fda5b3 100644
--- a/flang/include/flang/Tools/PointerModels.h
+++ b/flang/include/flang/Tools/PointerModels.h
@@ -20,7 +20,7 @@ struct OpenMPPointerLikeModel
: public mlir::omp::PointerLikeType::ExternalModel<
OpenMPPointerLikeModel<T>, T> {
mlir::Type getElementType(mlir::Type pointer) const {
- return mlir::cast<T>(pointer).getElementType();
+ return pointer.cast<T>().getElementType();
}
};
@@ -29,7 +29,7 @@ struct OpenACCPointerLikeModel
: public mlir::acc::PointerLikeType::ExternalModel<
OpenACCPointerLikeModel<T>, T> {
mlir::Type getElementType(mlir::Type pointer) const {
- return mlir::cast<T>(pointer).getElementType();
+ return pointer.cast<T>().getElementType();
}
};
diff --git a/flang/lib/Lower/Allocatable.cpp b/flang/lib/Lower/Allocatable.cpp
index a1957c0eb1bb7e..8e84ea2fc5d522 100644
--- a/flang/lib/Lower/Allocatable.cpp
+++ b/flang/lib/Lower/Allocatable.cpp
@@ -162,7 +162,7 @@ static void genRuntimeInitCharacter(fir::FirOpBuilder &builder,
args.push_back(builder.createConvert(loc, inputTypes[0], box.getAddr()));
args.push_back(builder.createConvert(loc, inputTypes[1], len));
if (kind == 0)
- kind = mlir::cast<fir::CharacterType>(box.getEleTy()).getFKind();
+ kind = box.getEleTy().cast<fir::CharacterType>().getFKind();
args.push_back(builder.createIntegerConstant(loc, inputTypes[2], kind));
int rank = box.rank();
args.push_back(builder.createIntegerConstant(loc, inputTypes[3], rank));
@@ -879,7 +879,7 @@ void Fortran::lower::genDeallocateIfAllocated(
builder.genIfThen(loc, isAllocated)
.genThen([&]() {
if (mlir::Type eleType = box.getEleTy();
- mlir::isa<fir::RecordType>(eleType) && box.isPolymorphic()) {
+ eleType.isa<fir::RecordType>() && box.isPolymorphic()) {
mlir::Value declaredTypeDesc = builder.create<fir::TypeDescOp>(
loc, mlir::TypeAttr::get(eleType));
genDeallocateBox(converter, box, loc, sym, declaredTypeDesc);
@@ -918,7 +918,7 @@ void Fortran::lower::genDeallocateStmt(
mlir::Value declaredTypeDesc = {};
if (box.isPolymorphic()) {
mlir::Type eleType = box.getEleTy();
- if (mlir::isa<fir::RecordType>(eleType))
+ if (eleType.isa<fir::RecordType>())
if (const Fortran::semantics::DerivedTypeSpec *derivedTypeSpec =
symbol.GetType()->AsDerived()) {
declaredTypeDesc =
@@ -1007,7 +1007,7 @@ createMutableProperties(Fortran::lower::AbstractConverter &converter,
fir::MutableProperties mutableProperties;
std::string name = converter.mangleName(sym);
mlir::Type baseAddrTy = converter.genType(sym);
- if (auto boxType = mlir::dyn_cast<fir::BaseBoxType>(baseAddrTy))
+ if (auto boxType = baseAddrTy.dyn_cast<fir::BaseBoxType>())
baseAddrTy = boxType.getEleTy();
// Allocate and set a variable to hold the address.
// It will be set to null in setUnallocatedStatus.
@@ -1032,9 +1032,9 @@ createMutableProperties(Fortran::lower::AbstractConverter &converter,
mlir::Type eleTy = baseAddrTy;
if (auto newTy = fir::dyn_cast_ptrEleTy(eleTy))
eleTy = newTy;
- if (auto seqTy = mlir::dyn_cast<fir::SequenceType>(eleTy))
+ if (auto seqTy = eleTy.dyn_cast<fir::SequenceType>())
eleTy = seqTy.getEleTy();
- if (auto record = mlir::dyn_cast<fir::RecordType>(eleTy))
+ if (auto record = eleTy.dyn_cast<fir::RecordType>())
if (record.getNumLenParams() != 0)
TODO(loc, "deferred length type parameters.");
if (fir::isa_char(eleTy) && nonDeferredParams.empty()) {
diff --git a/flang/lib/Lower/Bridge.cpp b/flang/lib/Lower/Bridge.cpp
index 19c00884bd1b7e..f66607dfa22f1b 100644
--- a/flang/lib/Lower/Bridge.cpp
+++ b/flang/lib/Lower/Bridge.cpp
@@ -683,7 +683,7 @@ class FirConverter : public Fortran::lower::AbstractConverter {
auto if_builder = builder->genIfThenElse(loc, isAllocated);
if_builder.genThen([&]() {
std::string name = mangleName(sym) + ".alloc";
- if (auto seqTy = mlir::dyn_cast<fir::SequenceType>(symType)) {
+ if (auto seqTy = symType.dyn_cast<fir::SequenceType>()) {
fir::ExtendedValue read = fir::factory::genMutableBoxRead(
*builder, loc, box, /*mayBePolymorphic=*/false);
if (auto read_arr_box = read.getBoxOf<fir::ArrayBoxValue>()) {
@@ -1132,7 +1132,7 @@ class FirConverter : public Fortran::lower::AbstractConverter {
fir::ExtendedValue lhs = symBoxToExtendedValue(lhs_sb);
fir::ExtendedValue rhs = symBoxToExtendedValue(rhs_sb);
mlir::Type symType = genType(sym);
- if (auto seqTy = mlir::dyn_cast<fir::SequenceType>(symType)) {
+ if (auto seqTy = symType.dyn_cast<fir::SequenceType>()) {
Fortran::lower::StatementContext stmtCtx;
Fortran::lower::createSomeArrayAssignment(*this, lhs, rhs, localSymbols,
stmtCtx);
@@ -1355,7 +1355,7 @@ class FirConverter : public Fortran::lower::AbstractConverter {
return;
}
mlir::Type selectorType = selector.getType();
- bool realSelector = mlir::isa<mlir::FloatType>(selectorType);
+ bool realSelector = selectorType.isa<mlir::FloatType>();
assert((inArithmeticIfContext || !realSelector) && "invalid selector type");
mlir::Value zero;
if (inArithmeticIfContext)
@@ -1630,7 +1630,7 @@ class FirConverter : public Fortran::lower::AbstractConverter {
stmtCtx);
stmtCtx.finalizeAndReset();
// Raise an exception if REAL expr is a NaN.
- if (mlir::isa<mlir::FloatType>(expr.getType()))
+ if (expr.getType().isa<mlir::FloatType>())
expr = builder->create<mlir::arith::AddFOp>(toLocation(), expr, expr);
// An empty valueList indicates to genMultiwayBranch that the branch is
// an ArithmeticIfStmt that has two branches on value 0 or 0.0.
@@ -2807,7 +2807,7 @@ class FirConverter : public Fortran::lower::AbstractConverter {
auto caseValue = valueList.begin();
auto caseBlock = blockList.begin();
for (mlir::Attribute attr : attrList) {
- if (mlir::isa<mlir::UnitAttr>(attr)) {
+ if (attr.isa<mlir::UnitAttr>()) {
genBranch(*caseBlock++);
break;
}
@@ -2825,7 +2825,7 @@ class FirConverter : public Fortran::lower::AbstractConverter {
rhsVal.second);
};
mlir::Block *newBlock = insertBlock(*caseBlock);
- if (mlir::isa<fir::ClosedIntervalAttr>(attr)) {
+ if (attr.isa<fir::ClosedIntervalAttr>()) {
mlir::Block *newBlock2 = insertBlock(*caseBlock);
mlir::Value cond =
genCond(*caseValue++, mlir::arith::CmpIPredicate::sge);
@@ -2838,12 +2838,12 @@ class FirConverter : public Fortran::lower::AbstractConverter {
continue;
}
mlir::arith::CmpIPredicate pred;
- if (mlir::isa<fir::PointIntervalAttr>(attr)) {
+ if (attr.isa<fir::PointIntervalAttr>()) {
pred = mlir::arith::CmpIPredicate::eq;
- } else if (mlir::isa<fir::LowerBoundAttr>(attr)) {
+ } else if (attr.isa<fir::LowerBoundAttr>()) {
pred = mlir::arith::CmpIPredicate::sge;
} else {
- assert(mlir::isa<fir::UpperBoundAttr>(attr) && "unexpected predicate");
+ assert(attr.isa<fir::UpperBoundAttr>() && "unexpected predicate");
pred = mlir::arith::CmpIPredicate::sle;
}
mlir::Value cond = genCond(*caseValue++, pred);
@@ -3105,7 +3105,7 @@ class FirConverter : public Fortran::lower::AbstractConverter {
bool isPointer = fir::isPointerType(baseTy);
bool isAllocatable = fir::isAllocatableType(baseTy);
bool isArray =
- mlir::isa<fir::SequenceType>(fir::dyn_cast_ptrOrBoxEleTy(baseTy));
+ fir::dyn_cast_ptrOrBoxEleTy(baseTy).isa<fir::SequenceType>();
const fir::BoxValue *selectorBox = selector.getBoxOf<fir::BoxValue>();
if (std::holds_alternative<Fortran::parser::Default>(guard.u)) {
// CLASS DEFAULT
@@ -3114,12 +3114,12 @@ class FirConverter : public Fortran::lower::AbstractConverter {
std::get_if<Fortran::parser::TypeSpec>(&guard.u)) {
// TYPE IS
fir::ExactTypeAttr attr =
- mlir::dyn_cast<fir::ExactTypeAttr>(typeGuardAttr);
+ typeGuardAttr.dyn_cast<fir::ExactTypeAttr>();
mlir::Value exactValue;
mlir::Type addrTy = attr.getType();
if (isArray) {
- auto seqTy = mlir::dyn_cast<fir::SequenceType>(
- fir::dyn_cast_ptrOrBoxEleTy(baseTy));
+ auto seqTy = fir::dyn_cast_ptrOrBoxEleTy(baseTy)
+ .dyn_cast<fir::SequenceType>();
addrTy = fir::SequenceType::get(seqTy.getShape(), attr.getType());
}
if (isPointer)
@@ -3141,7 +3141,7 @@ class FirConverter : public Fortran::lower::AbstractConverter {
addAssocEntitySymbol(selectorBox->clone(exact));
} else if (intrinsic->category() ==
Fortran::common::TypeCategory::Character) {
- auto charTy = mlir::dyn_cast<fir::CharacterType>(attr.getType());
+ auto charTy = attr.getType().dyn_cast<fir::CharacterType>();
mlir::Value charLen =
fir::factory::CharacterExprHelper(*builder, loc)
.readLengthFromBox(fir::getBase(selector), charTy);
@@ -3158,12 +3158,11 @@ class FirConverter : public Fortran::lower::AbstractConverter {
} else if (std::holds_alternative<Fortran::parser::DerivedTypeSpec>(
guard.u)) {
// CLASS IS
- fir::SubclassAttr attr =
- mlir::dyn_cast<fir::SubclassAttr>(typeGuardAttr);
+ fir::SubclassAttr attr = typeGuardAttr.dyn_cast<fir::SubclassAttr>();
mlir::Type addrTy = attr.getType();
if (isArray) {
- auto seqTy = mlir::dyn_cast<fir::SequenceType>(
- fir::dyn_cast_ptrOrBoxEleTy(baseTy));
+ auto seqTy = fir::dyn_cast_ptrOrBoxEleTy(baseTy)
+ .dyn_cast<fir::SequenceType>();
addrTy = fir::SequenceType::get(seqTy.getShape(), attr.getType());
}
if (isPointer)
@@ -4140,7 +4139,7 @@ class FirConverter : public Fortran::lower::AbstractConverter {
} else if (isDerivedCategory(lhsType->category())) {
// Handle parent component.
if (Fortran::lower::isParentComponent(assign.lhs)) {
- if (!mlir::isa<fir::BaseBoxType>(fir::getBase(lhs).getType()))
+ if (!fir::getBase(lhs).getType().isa<fir::BaseBoxType>())
lhs = fir::getBase(builder->createBox(loc, lhs));
lhs = Fortran::lower::updateBoxForParentComponent(*this, lhs,
assign.lhs);
@@ -5491,7 +5490,7 @@ Fortran::lower::LoweringBridge::LoweringBridge(
default:
break;
}
- if (!mlir::isa<mlir::UnknownLoc>(diag.getLocation()))
+ if (!diag.getLocation().isa<mlir::UnknownLoc>())
os << diag.getLocation() << ": ";
os << diag << '\n';
os.flush();
diff --git a/flang/lib/Lower/CallInterface.cpp b/flang/lib/Lower/CallInterface.cpp
index c1f54ad3928799..5ad244600328ca 100644
--- a/flang/lib/Lower/CallInterface.cpp
+++ b/flang/lib/Lower/CallInterface.cpp
@@ -1182,7 +1182,7 @@ class Fortran::lower::CallInterfaceImpl {
Property prop = Property::BaseAddress;
if (isValueAttr) {
bool isBuiltinCptrType = fir::isa_builtin_cptr_type(type);
- if (isBindC || (!mlir::isa<fir::SequenceType>(type) &&
+ if (isBindC || (!type.isa<fir::SequenceType>() &&
!obj.attrs.test(Attrs::Optional) &&
(dynamicType.category() !=
Fortran::common::TypeCategory::Derived ||
@@ -1190,7 +1190,7 @@ class Fortran::lower::CallInterfaceImpl {
passBy = PassEntityBy::Value;
prop = Property::Value;
if (isBuiltinCptrType) {
- auto recTy = mlir::dyn_cast<fir::RecordType>(type);
+ auto recTy = type.dyn_cast<fir::RecordType>();
mlir::Type fieldTy = recTy.getTypeList()[0].second;
passType = fir::ReferenceType::get(fieldTy);
} else {
@@ -1714,7 +1714,7 @@ mlir::Type Fortran::lower::getDummyProcedureType(
}
bool Fortran::lower::isCPtrArgByValueType(mlir::Type ty) {
- return mlir::isa<fir::ReferenceType>(ty) &&
+ return ty.isa<fir::ReferenceType>() &&
fir::isa_integer(fir::unwrapRefType(ty));
}
diff --git a/flang/lib/Lower/ConvertArrayConstructor.cpp b/flang/lib/Lower/ConvertArrayConstructor.cpp
index a5b5838fe6b621..24aa9beba6bf48 100644
--- a/flang/lib/Lower/ConvertArrayConstructor.cpp
+++ b/flang/lib/Lower/ConvertArrayConstructor.cpp
@@ -336,7 +336,7 @@ class RuntimeTempStrategy : public StrategyBase {
if (!extent)
extent = builder.createIntegerConstant(loc, builder.getIndexType(), 0);
if (missingLengthParameters) {
- if (mlir::isa<fir::CharacterType>(declaredType.getEleTy()))
+ if (declaredType.getEleTy().isa<fir::CharacterType>())
emboxLengths.push_back(builder.createIntegerConstant(
loc, builder.getCharacterLengthType(), 0));
else
@@ -357,7 +357,7 @@ class RuntimeTempStrategy : public StrategyBase {
bool useSimplePushRuntime(hlfir::Entity value) {
return value.isScalar() &&
- !mlir::isa<fir::CharacterType>(arrayConstructorElementType) &&
+ !arrayConstructorElementType.isa<fir::CharacterType>() &&
!fir::isRecordWithAllocatableMember(arrayConstructorElementType) &&
!fir::isRecordWithTypeParameters(arrayConstructorElementType);
}
@@ -370,7 +370,7 @@ class RuntimeTempStrategy : public StrategyBase {
auto [addrExv, cleanUp] = hlfir::convertToAddress(
loc, builder, value, arrayConstructorElementType);
mlir::Value addr = fir::getBase(addrExv);
- if (mlir::isa<fir::BaseBoxType>(addr.getType()))
+ if (addr.getType().isa<fir::BaseBoxType>())
addr = builder.create<fir::BoxAddrOp>(loc, addr);
fir::runtime::genPushArrayConstructorSimpleScalar(
loc, builder, arrayConstructorVector, addr);
@@ -564,7 +564,7 @@ struct LengthAndTypeCollector<Character<Kind>> {
/// lowering an ac-value and must be delayed?
static bool missingLengthParameters(mlir::Type elementType,
llvm::ArrayRef<mlir::Value> lengths) {
- return (mlir::isa<fir::CharacterType>(elementType) ||
+ return (elementType.isa<fir::CharacterType>() ||
fir::isRecordWithTypeParameters(elementType)) &&
lengths.empty();
}
@@ -702,8 +702,7 @@ static ArrayCtorLoweringStrategy selectArrayCtorLoweringStrategy(
// Based on what was gathered and the result of the analysis, select and
// instantiate the right lowering strategy for the array constructor.
if (!extent || needToEvaluateOneExprToGetLengthParameters ||
- analysis.anyArrayExpr ||
- mlir::isa<fir::RecordType>(declaredType.getEleTy()))
+ analysis.anyArrayExpr || declaredType.getEleTy().isa<fir::RecordType>())
return RuntimeTempStrategy(
loc, builder, stmtCtx, symMap, declaredType,
extent ? std::optional<mlir::Value>(extent) : std::nullopt, lengths,
diff --git a/flang/lib/Lower/ConvertCall.cpp b/flang/lib/Lower/ConvertCall.cpp
index e4a0cc8d473038..c6f7d3410ad5cf 100644
--- a/flang/lib/Lower/ConvertCall.cpp
+++ b/flang/lib/Lower/ConvertCall.cpp
@@ -49,15 +49,15 @@ static fir::ExtendedValue toExtendedValue(mlir::Location loc, mlir::Value base,
llvm::ArrayRef<mlir::Value> extents,
llvm::ArrayRef<mlir::Value> lengths) {
mlir::Type type = base.getType();
- if (mlir::isa<fir::BaseBoxType>(type))
+ if (type.isa<fir::BaseBoxType>())
return fir::BoxValue(base, /*lbounds=*/{}, lengths, extents);
type = fir::unwrapRefType(type);
- if (mlir::isa<fir::BaseBoxType>(type))
+ if (type.isa<fir::BaseBoxType>())
return fir::MutableBoxValue(base, lengths, /*mutableProperties*/ {});
- if (auto seqTy = mlir::dyn_cast<fir::SequenceType>(type)) {
+ if (auto seqTy = type.dyn_cast<fir::SequenceType>()) {
if (seqTy.getDimension() != extents.size())
fir::emitFatalError(loc, "incorrect number of extents for array");
- if (mlir::isa<fir::CharacterType>(seqTy.getEleTy())) {
+ if (seqTy.getEleTy().isa<fir::CharacterType>()) {
if (lengths.empty())
fir::emitFatalError(loc, "missing length for character");
assert(lengths.size() == 1);
@@ -65,7 +65,7 @@ static fir::ExtendedValue toExtendedValue(mlir::Location loc, mlir::Value base,
}
return fir::ArrayBoxValue(base, extents);
}
- if (mlir::isa<fir::CharacterType>(type)) {
+ if (type.isa<fir::CharacterType>()) {
if (lengths.empty())
fir::emitFatalError(loc, "missing length for character");
assert(lengths.size() == 1);
@@ -193,7 +193,7 @@ static mlir::Value remapActualToDummyDescriptor(
llvm::SmallVector<mlir::Value> lengths;
mlir::Type dummyBoxType = caller.getDummyArgumentType(arg);
mlir::Type dummyBaseType = fir::unwrapPassByRefType(dummyBoxType);
- if (mlir::isa<fir::SequenceType>(dummyBaseType))
+ if (dummyBaseType.isa<fir::SequenceType>())
caller.walkDummyArgumentExtents(
arg, [&](const Fortran::lower::SomeExpr &e, bool isAssumedSizeExtent) {
extents.emplace_back(lowerSpecExpr(e, isAssumedSizeExtent));
@@ -338,7 +338,7 @@ std::pair<fir::ExtendedValue, bool> Fortran::lower::genCallOpAndResult(
if (!caller.callerAllocateResult())
return {};
mlir::Type type = caller.getResultStorageType();
- if (mlir::isa<fir::SequenceType>(type))
+ if (type.isa<fir::SequenceType>())
caller.walkResultExtents(
[&](const Fortran::lower::SomeExpr &e, bool isAssumedSizeExtent) {
assert(!isAssumedSizeExtent && "result cannot be assumed-size");
@@ -353,7 +353,7 @@ std::pair<fir::ExtendedValue, bool> Fortran::lower::genCallOpAndResult(
// Result length parameters should not be provided to box storage
// allocation and save_results, but they are still useful information to
// keep in the ExtendedValue if non-deferred.
- if (!mlir::isa<fir::BoxType>(type)) {
+ if (!type.isa<fir::BoxType>()) {
if (fir::isa_char(fir::unwrapSequenceType(type)) && lengths.empty()) {
// Calling an assumed length function. This is only possible if this
// is a call to a character dummy procedure.
@@ -478,7 +478,7 @@ std::pair<fir::ExtendedValue, bool> Fortran::lower::genCallOpAndResult(
// FIR.
if (funcPointer) {
operands.push_back(
- mlir::isa<fir::BoxProcType>(funcPointer.getType())
+ funcPointer.getType().isa<fir::BoxProcType>()
? builder.create<fir::BoxAddrOp>(loc, funcType, funcPointer)
: builder.createConvert(loc, funcType, funcPointer));
}
@@ -492,8 +492,8 @@ std::pair<fir::ExtendedValue, bool> Fortran::lower::genCallOpAndResult(
// arguments of any type and vice versa.
mlir::Value cast;
auto *context = builder.getContext();
- if (mlir::isa<fir::BoxProcType>(snd) &&
- mlir::isa<mlir::FunctionType>(fst.getType())) {
+ if (snd.isa<fir::BoxProcType>() &&
+ fst.getType().isa<mlir::FunctionType>()) {
auto funcTy =
mlir::FunctionType::get(context, std::nullopt, std::nullopt);
auto boxProcTy = builder.getBoxProcType(funcTy);
@@ -734,9 +734,9 @@ std::pair<fir::ExtendedValue, bool> Fortran::lower::genCallOpAndResult(
// Call a BIND(C) function that return a char.
if (caller.characterize().IsBindC() &&
- mlir::isa<fir::CharacterType>(funcType.getResults()[0])) {
+ funcType.getResults()[0].isa<fir::CharacterType>()) {
fir::CharacterType charTy =
- mlir::dyn_cast<fir::CharacterType>(funcType.getResults()[0]);
+ funcType.getResults()[0].dyn_cast<fir::CharacterType>();
mlir::Value len = builder.createIntegerConstant(
loc, builder.getCharacterLengthType(), charTy.getLen());
return {fir::CharBoxValue{callResult, len}, /*resultIsFinalized=*/false};
@@ -890,7 +890,7 @@ extendedValueToHlfirEntity(mlir::Location loc, fir::FirOpBuilder &builder,
mlir::Type firBaseTy = firBase.getType();
if (fir::isa_trivial(firBaseTy))
return hlfir::EntityWithAttributes{firBase};
- if (auto charTy = mlir::dyn_cast<fir::CharacterType>(firBase.getType())) {
+ if (auto charTy = firBase.getType().dyn_cast<fir::CharacterType>()) {
// CHAR() intrinsic and BIND(C) procedures returning CHARACTER(1)
// are lowered to a fir.char<kind,1> that is not in memory.
// This tends to cause a lot of bugs because the rest of the
@@ -1061,7 +1061,7 @@ static hlfir::Entity fixProcedureDummyMismatch(mlir::Location loc,
fir::FirOpBuilder &builder,
hlfir::Entity actual,
mlir::Type dummyType) {
- if (mlir::isa<fir::BoxProcType>(actual.getType()) &&
+ if (actual.getType().isa<fir::BoxProcType>() &&
fir::isCharacterProcedureTuple(dummyType)) {
mlir::Value length =
builder.create<fir::UndefOp>(loc, builder.getCharacterLengthType());
@@ -1070,7 +1070,7 @@ static hlfir::Entity fixProcedureDummyMismatch(mlir::Location loc,
return hlfir::Entity{tuple};
}
assert(fir::isCharacterProcedureTuple(actual.getType()) &&
- mlir::isa<fir::BoxProcType>(dummyType) &&
+ dummyType.isa<fir::BoxProcType>() &&
"unsupported dummy procedure mismatch with the actual argument");
mlir::Value boxProc = fir::factory::extractCharacterProcedureTuple(
builder, loc, actual, /*openBoxProc=*/false)
@@ -1143,7 +1143,7 @@ static PreparedDummyArgument preparePresentUserCallActualArgument(
assert(actual.isProcedure());
// Do nothing if this is a procedure argument. It is already a
// fir.boxproc/fir.tuple<fir.boxproc, len> as it should.
- if (!mlir::isa<fir::BoxProcType>(actual.getType()) &&
+ if (!actual.getType().isa<fir::BoxProcType>() &&
actual.getType() != dummyType)
// The actual argument may be a procedure that returns character (a
// fir.tuple<fir.boxproc, len>) while the dummy is not. Extract the tuple
@@ -1164,7 +1164,7 @@ static PreparedDummyArgument preparePresentUserCallActualArgument(
// dynamic type matters to determine the contiguity.
const bool mustSetDynamicTypeToDummyType =
passingPolymorphicToNonPolymorphic &&
- (actual.isArray() || mlir::isa<fir::BaseBoxType>(dummyType));
+ (actual.isArray() || dummyType.isa<fir::BaseBoxType>());
// The simple contiguity of the actual is "lost" when passing a polymorphic
// to a non polymorphic entity because the dummy dynamic type matters for
@@ -1236,7 +1236,7 @@ static PreparedDummyArgument preparePresentUserCallActualArgument(
preparedDummy.pushExprAssociateCleanUp(associate);
} else if (mustDoCopyInOut) {
// Copy-in non contiguous variables.
- assert(mlir::isa<fir::BaseBoxType>(entity.getType()) &&
+ assert(entity.getType().isa<fir::BaseBoxType>() &&
"expect non simply contiguous variables to be boxes");
if (actualIsAssumedRank)
TODO(loc, "copy-in and copy-out of assumed-rank arguments");
@@ -1294,14 +1294,13 @@ static PreparedDummyArgument preparePresentUserCallActualArgument(
// Step 3: now that the dummy argument storage has been prepared, package
// it according to the interface.
mlir::Value addr;
- if (mlir::isa<fir::BoxCharType>(dummyTypeWithActualRank)) {
+ if (dummyTypeWithActualRank.isa<fir::BoxCharType>()) {
addr = hlfir::genVariableBoxChar(loc, builder, entity);
- } else if (mlir::isa<fir::BaseBoxType>(dummyTypeWithActualRank)) {
+ } else if (dummyTypeWithActualRank.isa<fir::BaseBoxType>()) {
entity = hlfir::genVariableBox(loc, builder, entity);
// Ensures the box has the right attributes and that it holds an
// addendum if needed.
- fir::BaseBoxType actualBoxType =
- mlir::cast<fir::BaseBoxType>(entity.getType());
+ fir::BaseBoxType actualBoxType = entity.getType().cast<fir::BaseBoxType>();
mlir::Type boxEleType = actualBoxType.getEleTy();
// For now, assume it is not OK to pass the allocatable/pointer
// descriptor to a non pointer/allocatable dummy. That is a strict
@@ -1568,7 +1567,7 @@ genUserCall(Fortran::lower::PreparedActualArguments &loweredActuals,
// callee side, and it is illegal to use NULL without a MOLD if any
// dummy length parameters are assumed.
mlir::Type boxTy = fir::dyn_cast_ptrEleTy(argTy);
- assert(boxTy && mlir::isa<fir::BaseBoxType>(boxTy) &&
+ assert(boxTy && boxTy.isa<fir::BaseBoxType>() &&
"must be a fir.box type");
mlir::Value boxStorage =
fir::factory::genNullBoxStorage(builder, loc, boxTy);
@@ -1636,8 +1635,7 @@ genUserCall(Fortran::lower::PreparedActualArguments &loweredActuals,
caller, callSiteType, callContext.resultType,
callContext.isElementalProcWithArrayArgs());
// For procedure pointer function result, just return the call.
- if (callContext.resultType &&
- mlir::isa<fir::BoxProcType>(*callContext.resultType))
+ if (callContext.resultType && callContext.resultType->isa<fir::BoxProcType>())
return hlfir::EntityWithAttributes(fir::getBase(result));
/// Clean-up associations and copy-in.
@@ -2117,9 +2115,9 @@ class ElementalCallBuilder {
hlfir::getFortranElementType(*callContext.resultType);
// Get result length parameters.
llvm::SmallVector<mlir::Value> typeParams;
- if (mlir::isa<fir::CharacterType>(elementType) ||
+ if (elementType.isa<fir::CharacterType>() ||
fir::isRecordWithTypeParameters(elementType)) {
- auto charType = mlir::dyn_cast<fir::CharacterType>(elementType);
+ auto charType = elementType.dyn_cast<fir::CharacterType>();
if (charType && charType.hasConstantLen())
typeParams.push_back(builder.createIntegerConstant(
loc, builder.getIndexType(), charType.getLen()));
@@ -2525,7 +2523,7 @@ genIntrinsicRef(const Fortran::evaluate::SpecificIntrinsic *intrinsic,
}
std::optional<hlfir::EntityWithAttributes> result = genHLFIRIntrinsicRefCore(
loweredActuals, intrinsic, argLowering, callContext);
- if (result && mlir::isa<hlfir::ExprType>(result->getType())) {
+ if (result && result->getType().isa<hlfir::ExprType>()) {
fir::FirOpBuilder *bldr = &callContext.getBuilder();
callContext.stmtCtx.attachCleanup(
[=]() { bldr->create<hlfir::DestroyOp>(loc, *result); });
diff --git a/flang/lib/Lower/ConvertConstant.cpp b/flang/lib/Lower/ConvertConstant.cpp
index 653e874a969c5e..ed389bbe4ae5ed 100644
--- a/flang/lib/Lower/ConvertConstant.cpp
+++ b/flang/lib/Lower/ConvertConstant.cpp
@@ -184,8 +184,8 @@ class DenseGlobalBuilder {
if (!attributeElementType || attributes.empty())
return {};
- assert(mlir::isa<fir::SequenceType>(symTy) && "expecting an array global");
- auto arrTy = mlir::cast<fir::SequenceType>(symTy);
+ assert(symTy.isa<fir::SequenceType>() && "expecting an array global");
+ auto arrTy = symTy.cast<fir::SequenceType>();
llvm::SmallVector<int64_t> tensorShape(arrTy.getShape());
std::reverse(tensorShape.begin(), tensorShape.end());
auto tensorTy =
@@ -423,14 +423,14 @@ static mlir::Value genStructureComponentInit(
// address field, which ought to be an intptr_t on the target.
mlir::Value addr = fir::getBase(
Fortran::lower::genExtAddrInInitializer(converter, loc, expr));
- if (mlir::isa<fir::BoxProcType>(addr.getType()))
+ if (addr.getType().isa<fir::BoxProcType>())
addr = builder.create<fir::BoxAddrOp>(loc, addr);
assert((fir::isa_ref_type(addr.getType()) ||
- mlir::isa<mlir::FunctionType>(addr.getType())) &&
+ addr.getType().isa<mlir::FunctionType>()) &&
"expect reference type for address field");
assert(fir::isa_derived(componentTy) &&
"expect C_PTR, C_FUNPTR to be a record");
- auto cPtrRecTy = mlir::cast<fir::RecordType>(componentTy);
+ auto cPtrRecTy = componentTy.cast<fir::RecordType>();
llvm::StringRef addrFieldName = Fortran::lower::builtin::cptrFieldName;
mlir::Type addrFieldTy = cPtrRecTy.getType(addrFieldName);
auto addrField = builder.create<fir::FieldIndexOp>(
@@ -460,7 +460,7 @@ static mlir::Value genInlinedStructureCtorLitImpl(
Fortran::lower::AbstractConverter &converter, mlir::Location loc,
const Fortran::evaluate::StructureConstructor &ctor, mlir::Type type) {
fir::FirOpBuilder &builder = converter.getFirOpBuilder();
- auto recTy = mlir::cast<fir::RecordType>(type);
+ auto recTy = type.cast<fir::RecordType>();
if (!converter.getLoweringOptions().getLowerToHighLevelFIR()) {
mlir::Value res = builder.create<fir::UndefOp>(loc, recTy);
@@ -587,7 +587,7 @@ genInlinedArrayLit(Fortran::lower::AbstractConverter &converter,
} while (con.IncrementSubscripts(subscripts));
} else if constexpr (T::category == Fortran::common::TypeCategory::Derived) {
do {
- mlir::Type eleTy = mlir::cast<fir::SequenceType>(arrayTy).getEleTy();
+ mlir::Type eleTy = arrayTy.cast<fir::SequenceType>().getEleTy();
mlir::Value elementVal =
genScalarLit(converter, loc, con.At(subscripts), eleTy,
/*outlineInReadOnlyMemory=*/false);
@@ -597,7 +597,7 @@ genInlinedArrayLit(Fortran::lower::AbstractConverter &converter,
} else {
llvm::SmallVector<mlir::Attribute> rangeStartIdx;
uint64_t rangeSize = 0;
- mlir::Type eleTy = mlir::cast<fir::SequenceType>(arrayTy).getEleTy();
+ mlir::Type eleTy = arrayTy.cast<fir::SequenceType>().getEleTy();
do {
auto getElementVal = [&]() {
return builder.createConvert(loc, eleTy,
@@ -620,11 +620,12 @@ genInlinedArrayLit(Fortran::lower::AbstractConverter &converter,
llvm::SmallVector<int64_t> rangeBounds;
llvm::SmallVector<mlir::Attribute> idx = createIdx();
for (size_t i = 0; i < idx.size(); ++i) {
- rangeBounds.push_back(mlir::cast<mlir::IntegerAttr>(rangeStartIdx[i])
+ rangeBounds.push_back(rangeStartIdx[i]
+ .cast<mlir::IntegerAttr>()
.getValue()
.getSExtValue());
rangeBounds.push_back(
- mlir::cast<mlir::IntegerAttr>(idx[i]).getValue().getSExtValue());
+ idx[i].cast<mlir::IntegerAttr>().getValue().getSExtValue());
}
array = builder.create<fir::InsertOnRangeOp>(
loc, arrayTy, array, getElementVal(),
@@ -646,7 +647,7 @@ genOutlineArrayLit(Fortran::lower::AbstractConverter &converter,
mlir::Location loc, mlir::Type arrayTy,
const Fortran::evaluate::Constant<T> &constant) {
fir::FirOpBuilder &builder = converter.getFirOpBuilder();
- mlir::Type eleTy = mlir::cast<fir::SequenceType>(arrayTy).getEleTy();
+ mlir::Type eleTy = arrayTy.cast<fir::SequenceType>().getEleTy();
llvm::StringRef globalName = converter.getUniqueLitName(
loc, std::make_unique<Fortran::lower::SomeExpr>(toEvExpr(constant)),
eleTy);
diff --git a/flang/lib/Lower/ConvertExpr.cpp b/flang/lib/Lower/ConvertExpr.cpp
index 9567685aa3d2e3..fb7807718ff888 100644
--- a/flang/lib/Lower/ConvertExpr.cpp
+++ b/flang/lib/Lower/ConvertExpr.cpp
@@ -267,7 +267,7 @@ arrayLoadExtValue(fir::FirOpBuilder &builder, mlir::Location loc,
mlir::Type ty = fir::applyPathToType(arrTy, path);
if (!ty)
fir::emitFatalError(loc, "path does not apply to type");
- if (!mlir::isa<fir::SequenceType>(ty)) {
+ if (!ty.isa<fir::SequenceType>()) {
if (fir::isa_char(ty)) {
mlir::Value len = newLen;
if (!len)
@@ -282,7 +282,7 @@ arrayLoadExtValue(fir::FirOpBuilder &builder, mlir::Location loc,
}
return newBase;
}
- arrTy = mlir::cast<fir::SequenceType>(ty);
+ arrTy = ty.cast<fir::SequenceType>();
}
auto arrayToExtendedValue =
@@ -412,15 +412,15 @@ static fir::ExtendedValue genLoad(fir::FirOpBuilder &builder,
return addr.match(
[](const fir::CharBoxValue &box) -> fir::ExtendedValue { return box; },
[&](const fir::PolymorphicValue &p) -> fir::ExtendedValue {
- if (mlir::isa<fir::RecordType>(
- fir::unwrapRefType(fir::getBase(p).getType())))
+ if (fir::unwrapRefType(fir::getBase(p).getType())
+ .isa<fir::RecordType>())
return p;
mlir::Value load = builder.create<fir::LoadOp>(loc, fir::getBase(p));
return fir::PolymorphicValue(load, p.getSourceBox());
},
[&](const fir::UnboxedValue &v) -> fir::ExtendedValue {
- if (mlir::isa<fir::RecordType>(
- fir::unwrapRefType(fir::getBase(v).getType())))
+ if (fir::unwrapRefType(fir::getBase(v).getType())
+ .isa<fir::RecordType>())
return v;
return builder.create<fir::LoadOp>(loc, fir::getBase(v));
},
@@ -536,8 +536,8 @@ static mlir::Value
createBoxProcCharTuple(Fortran::lower::AbstractConverter &converter,
mlir::Type argTy, mlir::Value funcAddr,
mlir::Value charLen) {
- auto boxTy = mlir::cast<fir::BoxProcType>(
- mlir::cast<mlir::TupleType>(argTy).getType(0));
+ auto boxTy =
+ argTy.cast<mlir::TupleType>().getType(0).cast<fir::BoxProcType>();
mlir::Location loc = converter.getCurrentLocation();
auto &builder = converter.getFirOpBuilder();
@@ -549,7 +549,7 @@ createBoxProcCharTuple(Fortran::lower::AbstractConverter &converter,
mlir::Type toTy = boxTy.getEleTy();
if (fir::isa_ref_type(fromTy))
funcAddr = builder.createConvert(loc, toTy, funcAddr);
- else if (mlir::isa<fir::BoxProcType>(fromTy))
+ else if (fromTy.isa<fir::BoxProcType>())
funcAddr = builder.create<fir::BoxAddrOp>(loc, toTy, funcAddr);
auto boxProc = [&]() -> mlir::Value {
@@ -575,7 +575,7 @@ absentBoxToUnallocatedBox(fir::FirOpBuilder &builder, mlir::Location loc,
mlir::Value isPresent) {
mlir::Value box = fir::getBase(exv);
mlir::Type boxType = box.getType();
- assert(mlir::isa<fir::BoxType>(boxType) && "argument must be a fir.box");
+ assert(boxType.isa<fir::BoxType>() && "argument must be a fir.box");
mlir::Value emptyBox =
fir::factory::createUnallocatedBox(builder, loc, boxType, std::nullopt);
auto safeToReadBox =
@@ -915,7 +915,7 @@ class ScalarExprLowering {
if (inInitializer)
return Fortran::lower::genInlinedStructureCtorLit(converter, loc, ctor);
mlir::Type ty = translateSomeExprToFIRType(converter, toEvExpr(ctor));
- auto recTy = mlir::cast<fir::RecordType>(ty);
+ auto recTy = ty.cast<fir::RecordType>();
auto fieldTy = fir::FieldType::get(ty.getContext());
mlir::Value res = builder.createTemporary(loc, recTy);
mlir::Value box = builder.createBox(loc, fir::ExtendedValue{res});
@@ -1172,8 +1172,8 @@ class ScalarExprLowering {
if (!charBox)
fir::emitFatalError(loc, "expected scalar character");
mlir::Value charAddr = charBox->getAddr();
- auto charType = mlir::cast<fir::CharacterType>(
- fir::unwrapPassByRefType(charAddr.getType()));
+ auto charType =
+ fir::unwrapPassByRefType(charAddr.getType()).cast<fir::CharacterType>();
if (charType.hasConstantLen()) {
// Erase previous constant length from the base type.
fir::CharacterType::LenType newLen = fir::CharacterType::unknownLen();
@@ -1441,7 +1441,7 @@ class ScalarExprLowering {
auto fldTy = fir::FieldType::get(&converter.getMLIRContext());
// FIXME: need to thread the LEN type parameters here.
for (const Fortran::evaluate::Component *field : list) {
- auto recTy = mlir::cast<fir::RecordType>(ty);
+ auto recTy = ty.cast<fir::RecordType>();
const Fortran::semantics::Symbol &sym = getLastSym(*field);
std::string name = converter.getRecordTypeFieldName(sym);
coorArgs.push_back(builder.create<fir::FieldIndexOp>(
@@ -1478,7 +1478,7 @@ class ScalarExprLowering {
mlir::Type genSubType(mlir::Type arrTy, unsigned dims) {
mlir::Type unwrapTy = fir::dyn_cast_ptrOrBoxEleTy(arrTy);
assert(unwrapTy && "must be a pointer or box type");
- auto seqTy = mlir::cast<fir::SequenceType>(unwrapTy);
+ auto seqTy = unwrapTy.cast<fir::SequenceType>();
llvm::ArrayRef<int64_t> shape = seqTy.getShape();
assert(shape.size() > 0 && "removing columns for sequence sans shape");
assert(dims <= shape.size() && "removing more columns than exist");
@@ -1550,9 +1550,9 @@ class ScalarExprLowering {
}
mlir::Type eleTy = fir::dyn_cast_ptrOrBoxEleTy(base.getType());
- if (auto classTy = mlir::dyn_cast<fir::ClassType>(eleTy))
+ if (auto classTy = eleTy.dyn_cast<fir::ClassType>())
eleTy = classTy.getEleTy();
- auto seqTy = mlir::cast<fir::SequenceType>(eleTy);
+ auto seqTy = eleTy.cast<fir::SequenceType>();
assert(args.size() == seqTy.getDimension());
mlir::Type ty = builder.getRefType(seqTy.getEleTy());
auto addr = builder.create<fir::CoordinateOp>(loc, ty, base, args);
@@ -1571,7 +1571,7 @@ class ScalarExprLowering {
mlir::Location loc = getLoc();
mlir::Value addr = fir::getBase(array);
mlir::Type arrTy = fir::dyn_cast_ptrEleTy(addr.getType());
- auto eleTy = mlir::cast<fir::SequenceType>(arrTy).getEleTy();
+ auto eleTy = arrTy.cast<fir::SequenceType>().getEleTy();
mlir::Type seqTy = builder.getRefType(builder.getVarLenSeqTy(eleTy));
mlir::Type refTy = builder.getRefType(eleTy);
mlir::Value base = builder.createConvert(loc, seqTy, addr);
@@ -1656,7 +1656,7 @@ class ScalarExprLowering {
mlir::Location loc = getLoc();
mlir::Value addr = fir::getBase(exv);
mlir::Type arrTy = fir::dyn_cast_ptrOrBoxEleTy(addr.getType());
- mlir::Type eleTy = mlir::cast<fir::SequenceType>(arrTy).getEleTy();
+ mlir::Type eleTy = arrTy.cast<fir::SequenceType>().getEleTy();
mlir::Type refTy = builder.getRefType(eleTy);
mlir::IndexType idxTy = builder.getIndexType();
llvm::SmallVector<mlir::Value> arrayCoorArgs;
@@ -1766,9 +1766,8 @@ class ScalarExprLowering {
mlir::Location loc = getLoc();
ExtValue exv = genBoxArg(expr);
auto exvTy = fir::getBase(exv).getType();
- if (mlir::isa<mlir::FunctionType>(exvTy)) {
- auto boxProcTy =
- builder.getBoxProcType(mlir::cast<mlir::FunctionType>(exvTy));
+ if (exvTy.isa<mlir::FunctionType>()) {
+ auto boxProcTy = builder.getBoxProcType(exvTy.cast<mlir::FunctionType>());
return builder.create<fir::EmboxProcOp>(loc, boxProcTy,
fir::getBase(exv));
}
@@ -1862,7 +1861,7 @@ class ScalarExprLowering {
// IS_CONTIGUOUS may require an assumed size TYPE(*) to be passed to
// the intrinsic library utility as a fir.box.
if (argRules.lowerAs == fir::LowerIntrinsicArgAs::Box &&
- !mlir::isa<fir::BaseBoxType>(fir::getBase(exv).getType())) {
+ !fir::getBase(exv).getType().isa<fir::BaseBoxType>()) {
operands.emplace_back(
fir::factory::createBoxValue(builder, loc, exv));
continue;
@@ -2006,7 +2005,7 @@ class ScalarExprLowering {
fir::getTypeParams(mold);
mlir::Value charLen;
mlir::Type elementType = fir::unwrapSequenceType(type);
- if (auto charType = mlir::dyn_cast<fir::CharacterType>(elementType)) {
+ if (auto charType = elementType.dyn_cast<fir::CharacterType>()) {
charLen = allocMemTypeParams.empty()
? fir::factory::readCharLen(builder, loc, mold)
: allocMemTypeParams[0];
@@ -2018,7 +2017,7 @@ class ScalarExprLowering {
mlir::Value temp = builder.create<fir::AllocMemOp>(
loc, type, tempName, allocMemTypeParams, extents);
- if (mlir::isa<fir::CharacterType>(fir::unwrapSequenceType(type)))
+ if (fir::unwrapSequenceType(type).isa<fir::CharacterType>())
return fir::CharArrayBoxValue{temp, charLen, extents};
return fir::ArrayBoxValue{temp, extents};
}
@@ -2167,7 +2166,7 @@ class ScalarExprLowering {
// We have to initialize the temp if it may have components
// that need initialization. If there are no components
// requiring initialization, then the call is a no-op.
- if (mlir::isa<fir::RecordType>(getElementTypeOf(temp))) {
+ if (getElementTypeOf(temp).isa<fir::RecordType>()) {
mlir::Value tempBox = fir::getBase(builder.createBox(loc, temp));
fir::runtime::genDerivedTypeInitialize(builder, loc, tempBox);
}
@@ -2313,7 +2312,7 @@ class ScalarExprLowering {
if (!copyOutPair.restrictCopyAndFreeAtRuntime) {
doCopyOut();
- if (mlir::isa<fir::RecordType>(fir::getElementTypeOf(copyOutPair.temp))) {
+ if (fir::getElementTypeOf(copyOutPair.temp).isa<fir::RecordType>()) {
// Destroy components of the temporary (if any).
// If there are no components requiring destruction, then the call
// is a no-op.
@@ -2331,8 +2330,7 @@ class ScalarExprLowering {
builder.genIfThen(loc, *copyOutPair.restrictCopyAndFreeAtRuntime)
.genThen([&]() {
doCopyOut();
- if (mlir::isa<fir::RecordType>(
- fir::getElementTypeOf(copyOutPair.temp))) {
+ if (fir::getElementTypeOf(copyOutPair.temp).isa<fir::RecordType>()) {
// Destroy components of the temporary (if any).
// If there are no components requiring destruction, then the call
// is a no-op.
@@ -2383,7 +2381,7 @@ class ScalarExprLowering {
mlir::Value actualArgBase = fir::getBase(actualArg);
mlir::Value isPresent = builder.create<fir::IsPresentOp>(
loc, builder.getI1Type(), actualArgBase);
- if (!mlir::isa<fir::BoxType>(actualArgBase.getType()))
+ if (!actualArgBase.getType().isa<fir::BoxType>())
return {actualArg, isPresent};
ExtValue safeToReadBox =
absentBoxToUnallocatedBox(builder, loc, actualArg, isPresent);
@@ -2410,7 +2408,7 @@ class ScalarExprLowering {
fir::getAdaptToByRefAttr(builder)});
return fir::CharBoxValue{temp, len};
}
- assert((fir::isa_trivial(type) || mlir::isa<fir::RecordType>(type)) &&
+ assert((fir::isa_trivial(type) || type.isa<fir::RecordType>()) &&
"must be simple scalar");
return builder.createTemporary(loc, type,
llvm::ArrayRef<mlir::NamedAttribute>{
@@ -2587,7 +2585,7 @@ class ScalarExprLowering {
// callee side, and it is illegal to use NULL without a MOLD if any
// dummy length parameters are assumed.
mlir::Type boxTy = fir::dyn_cast_ptrEleTy(argTy);
- assert(boxTy && mlir::isa<fir::BaseBoxType>(boxTy) &&
+ assert(boxTy && boxTy.isa<fir::BaseBoxType>() &&
"must be a fir.box type");
mlir::Value boxStorage = builder.createTemporary(loc, boxTy);
mlir::Value nullBox = fir::factory::createUnallocatedBox(
@@ -2645,11 +2643,10 @@ class ScalarExprLowering {
// If a character procedure was passed instead, handle the
// mismatch.
auto funcTy =
- mlir::dyn_cast<mlir::FunctionType>(x.getAddr().getType());
+ x.getAddr().getType().dyn_cast<mlir::FunctionType>();
if (funcTy && funcTy.getNumResults() == 1 &&
- mlir::isa<fir::BoxCharType>(funcTy.getResult(0))) {
- auto boxTy =
- mlir::cast<fir::BoxCharType>(funcTy.getResult(0));
+ funcTy.getResult(0).isa<fir::BoxCharType>()) {
+ auto boxTy = funcTy.getResult(0).cast<fir::BoxCharType>();
mlir::Value ref = builder.createConvert(
loc, builder.getRefType(boxTy.getEleTy()), x.getAddr());
auto len = builder.create<fir::UndefOp>(
@@ -2670,7 +2667,7 @@ class ScalarExprLowering {
// free-casting the base address to be a !fir.char reference and
// setting the LEN argument to undefined. What could go wrong?
auto dataPtr = fir::getBase(x);
- assert(!mlir::isa<fir::BoxType>(dataPtr.getType()));
+ assert(!dataPtr.getType().template isa<fir::BoxType>());
return builder.convertWithSemantics(
loc, argTy, dataPtr,
/*allowCharacterConversion=*/true);
@@ -2745,7 +2742,7 @@ class ScalarExprLowering {
loc,
fir::ClassType::get(mlir::NoneType::get(builder.getContext())),
box);
- } else if (mlir::isa<fir::BoxType>(box.getType()) &&
+ } else if (box.getType().isa<fir::BoxType>() &&
fir::isPolymorphicType(argTy)) {
box = builder.create<fir::ReboxOp>(loc, argTy, box, mlir::Value{},
/*slice=*/mlir::Value{});
@@ -2794,7 +2791,7 @@ class ScalarExprLowering {
: builder.createBox(getLoc(), genTempExtAddr(*expr),
fir::isPolymorphicType(argTy),
fir::isAssumedType(argTy));
- if (mlir::isa<fir::BoxType>(box.getType()) &&
+ if (box.getType().isa<fir::BoxType>() &&
fir::isPolymorphicType(argTy) && !fir::isAssumedType(argTy)) {
mlir::Type actualTy = argTy;
if (Fortran::lower::isParentComponent(*expr))
@@ -3033,11 +3030,10 @@ class ScalarExprLowering {
Fortran::common::ScopedSet(semant, PushVal);
static bool isAdjustedArrayElementType(mlir::Type t) {
- return fir::isa_char(t) || fir::isa_derived(t) ||
- mlir::isa<fir::SequenceType>(t);
+ return fir::isa_char(t) || fir::isa_derived(t) || t.isa<fir::SequenceType>();
}
static bool elementTypeWasAdjusted(mlir::Type t) {
- if (auto ty = mlir::dyn_cast<fir::ReferenceType>(t))
+ if (auto ty = t.dyn_cast<fir::ReferenceType>())
return isAdjustedArrayElementType(ty.getEleTy());
return false;
}
@@ -3054,15 +3050,15 @@ static void genScalarUserDefinedAssignmentCall(fir::FirOpBuilder &builder,
auto prepareUserDefinedArg =
[](fir::FirOpBuilder &builder, mlir::Location loc,
const fir::ExtendedValue &value, mlir::Type argType) -> mlir::Value {
- if (mlir::isa<fir::BoxCharType>(argType)) {
+ if (argType.isa<fir::BoxCharType>()) {
const fir::CharBoxValue *charBox = value.getCharBox();
assert(charBox && "argument type mismatch in elemental user assignment");
return fir::factory::CharacterExprHelper{builder, loc}.createEmbox(
*charBox);
}
- if (mlir::isa<fir::BaseBoxType>(argType)) {
+ if (argType.isa<fir::BaseBoxType>()) {
mlir::Value box =
- builder.createBox(loc, value, mlir::isa<fir::ClassType>(argType));
+ builder.createBox(loc, value, argType.isa<fir::ClassType>());
return builder.createConvert(loc, argType, box);
}
// Simple pass by address.
@@ -3174,7 +3170,7 @@ convertToArrayBoxValue(mlir::Location loc, fir::FirOpBuilder &builder,
mlir::Value val, mlir::Value len) {
mlir::Type ty = fir::unwrapRefType(val.getType());
mlir::IndexType idxTy = builder.getIndexType();
- auto seqTy = mlir::cast<fir::SequenceType>(ty);
+ auto seqTy = ty.cast<fir::SequenceType>();
auto undef = builder.create<fir::UndefOp>(loc, idxTy);
llvm::SmallVector<mlir::Value> extents(seqTy.getDimension(), undef);
if (fir::isa_char(seqTy.getEleTy()))
@@ -3466,7 +3462,7 @@ class ArrayExprLowering {
[&](const auto &e) {
auto f = genarr(e);
ExtValue exv = f(IterationSpace{});
- if (mlir::isa<fir::BaseBoxType>(fir::getBase(exv).getType()))
+ if (fir::getBase(exv).getType().template isa<fir::BaseBoxType>())
return exv;
fir::emitFatalError(getLoc(), "array must be emboxed");
},
@@ -3491,9 +3487,10 @@ class ArrayExprLowering {
tempRes, dest.getSlice(),
dest.getTypeparams());
- auto arrTy = mlir::cast<fir::SequenceType>(
- fir::dyn_cast_ptrEleTy(tempRes.getType()));
- if (auto charTy = mlir::dyn_cast<fir::CharacterType>(arrTy.getEleTy())) {
+ auto arrTy =
+ fir::dyn_cast_ptrEleTy(tempRes.getType()).cast<fir::SequenceType>();
+ if (auto charTy =
+ arrTy.getEleTy().template dyn_cast<fir::CharacterType>()) {
if (fir::characterWithDynamicLen(charTy))
TODO(loc, "CHARACTER does not have constant LEN");
mlir::Value len = builder.createIntegerConstant(
@@ -3915,18 +3912,17 @@ class ArrayExprLowering {
mlir::Value convertElementForUpdate(mlir::Location loc, mlir::Type eleTy,
mlir::Value origVal) {
if (auto origEleTy = fir::dyn_cast_ptrEleTy(origVal.getType()))
- if (mlir::isa<fir::BaseBoxType>(origEleTy)) {
+ if (origEleTy.isa<fir::BaseBoxType>()) {
// If origVal is a box variable, load it so it is in the value domain.
origVal = builder.create<fir::LoadOp>(loc, origVal);
}
- if (mlir::isa<fir::BoxType>(origVal.getType()) &&
- !mlir::isa<fir::BoxType>(eleTy)) {
+ if (origVal.getType().isa<fir::BoxType>() && !eleTy.isa<fir::BoxType>()) {
if (isPointerAssignment())
TODO(loc, "lhs of pointer assignment returned unexpected value");
TODO(loc, "invalid box conversion in elemental computation");
}
- if (isPointerAssignment() && mlir::isa<fir::BoxType>(eleTy) &&
- !mlir::isa<fir::BoxType>(origVal.getType())) {
+ if (isPointerAssignment() && eleTy.isa<fir::BoxType>() &&
+ !origVal.getType().isa<fir::BoxType>()) {
// This is a pointer assignment and the rhs is a raw reference to a TARGET
// in memory. Embox the reference so it can be stored to the boxed
// POINTER variable.
@@ -3934,7 +3930,7 @@ class ArrayExprLowering {
if (auto eleTy = fir::dyn_cast_ptrEleTy(origVal.getType());
fir::hasDynamicSize(eleTy))
TODO(loc, "TARGET of pointer assignment with runtime size/shape");
- auto memrefTy = fir::boxMemRefType(mlir::cast<fir::BoxType>(eleTy));
+ auto memrefTy = fir::boxMemRefType(eleTy.cast<fir::BoxType>());
auto castTo = builder.createConvert(loc, memrefTy, origVal);
origVal = builder.create<fir::EmboxOp>(loc, eleTy, castTo);
}
@@ -3986,7 +3982,7 @@ class ArrayExprLowering {
auto arrayOp = builder.create<fir::ArrayAccessOp>(
loc, resRefTy, innerArg, iterSpace.iterVec(),
fir::factory::getTypeParams(loc, builder, destination));
- if (auto charTy = mlir::dyn_cast<fir::CharacterType>(eleTy)) {
+ if (auto charTy = eleTy.dyn_cast<fir::CharacterType>()) {
llvm::SmallVector<mlir::Value> substringBounds;
populateBounds(substringBounds, substring);
mlir::Value dstLen = fir::factory::genLenOfCharacter(
@@ -4000,7 +3996,7 @@ class ArrayExprLowering {
loc, destination, builder, arrayOp, exv, eleTy, innerArg);
return abstractArrayExtValue(amend /*FIXME: typeparams?*/);
}
- assert(mlir::isa<fir::SequenceType>(eleTy) && "must be an array");
+ assert(eleTy.isa<fir::SequenceType>() && "must be an array");
TODO(loc, "array (as element) assignment");
}
// By value semantics. The element is being assigned by value.
@@ -4064,7 +4060,7 @@ class ArrayExprLowering {
llvm::SmallVector<mlir::Value> getShape(ArrayOperand array) {
if (array.slice)
return computeSliceShape(array.slice);
- if (mlir::isa<fir::BaseBoxType>(array.memref.getType()))
+ if (array.memref.getType().isa<fir::BaseBoxType>())
return fir::factory::readExtents(builder, getLoc(),
fir::BoxValue{array.memref});
return fir::factory::getExtents(array.shape);
@@ -4137,7 +4133,7 @@ class ArrayExprLowering {
mlir::Location loc = getLoc();
return [=, builder = &converter.getFirOpBuilder()](IterSpace iters) {
mlir::Type arrTy = fir::dyn_cast_ptrOrBoxEleTy(tmp.getType());
- auto eleTy = mlir::cast<fir::SequenceType>(arrTy).getEleTy();
+ auto eleTy = arrTy.cast<fir::SequenceType>().getEleTy();
mlir::Type eleRefTy = builder->getRefType(eleTy);
mlir::IntegerType i1Ty = builder->getI1Type();
// Adjust indices for any shift of the origin of the array.
@@ -4446,15 +4442,15 @@ class ArrayExprLowering {
TODO(loc, "polymorphic array temporary");
if (ccLoadDest)
return (*ccLoadDest)(shape);
- auto seqTy = mlir::dyn_cast<fir::SequenceType>(type);
+ auto seqTy = type.dyn_cast<fir::SequenceType>();
assert(seqTy && "must be an array");
// TODO: Need to thread the LEN parameters here. For character, they may
//
diff er from the operands length (e.g concatenation). So the array loads
// type parameters are not enough.
- if (auto charTy = mlir::dyn_cast<fir::CharacterType>(seqTy.getEleTy()))
+ if (auto charTy = seqTy.getEleTy().dyn_cast<fir::CharacterType>())
if (charTy.hasDynamicLen())
TODO(loc, "character array expression temp with dynamic length");
- if (auto recTy = mlir::dyn_cast<fir::RecordType>(seqTy.getEleTy()))
+ if (auto recTy = seqTy.getEleTy().dyn_cast<fir::RecordType>())
if (recTy.getNumLenParams() > 0)
TODO(loc, "derived type array expression temp with LEN parameters");
if (mlir::Type eleTy = fir::unwrapSequenceType(type);
@@ -4831,7 +4827,7 @@ class ArrayExprLowering {
});
} else {
ExtValue exv = asScalarRef(*expr);
- if (mlir::isa<fir::BaseBoxType>(fir::getBase(exv).getType())) {
+ if (fir::getBase(exv).getType().isa<fir::BaseBoxType>()) {
operands.emplace_back(
[=](IterSpace iters) -> ExtValue { return exv; });
} else {
@@ -5569,7 +5565,7 @@ class ArrayExprLowering {
}
static mlir::Type unwrapBoxEleTy(mlir::Type ty) {
- if (auto boxTy = mlir::dyn_cast<fir::BaseBoxType>(ty))
+ if (auto boxTy = ty.dyn_cast<fir::BaseBoxType>())
return fir::unwrapRefType(boxTy.getEleTy());
return ty;
}
@@ -5579,7 +5575,7 @@ class ArrayExprLowering {
ty = unwrapBoxEleTy(ty);
mlir::Location loc = getLoc();
mlir::IndexType idxTy = builder.getIndexType();
- for (auto extent : mlir::cast<fir::SequenceType>(ty).getShape()) {
+ for (auto extent : ty.cast<fir::SequenceType>().getShape()) {
auto v = extent == fir::SequenceType::getUnknownExtent()
? builder.create<fir::UndefOp>(loc, idxTy).getResult()
: builder.createIntegerConstant(loc, idxTy, extent);
@@ -5642,8 +5638,7 @@ class ArrayExprLowering {
mlir::Location loc = getLoc();
mlir::Value memref = fir::getBase(extMemref);
mlir::Type arrTy = fir::dyn_cast_ptrOrBoxEleTy(memref.getType());
- assert(mlir::isa<fir::SequenceType>(arrTy) &&
- "memory ref must be an array");
+ assert(arrTy.isa<fir::SequenceType>() && "memory ref must be an array");
mlir::Value shape = builder.createShape(loc, extMemref);
mlir::Value slice;
if (components.isSlice()) {
@@ -5693,12 +5688,12 @@ class ArrayExprLowering {
components.suffixComponents);
}
if (components.hasComponents()) {
- auto seqTy = mlir::cast<fir::SequenceType>(arrTy);
+ auto seqTy = arrTy.cast<fir::SequenceType>();
mlir::Type eleTy =
fir::applyPathToType(seqTy.getEleTy(), components.suffixComponents);
if (!eleTy)
fir::emitFatalError(loc, "slicing path is ill-formed");
- if (auto realTy = mlir::dyn_cast<fir::RealType>(eleTy))
+ if (auto realTy = eleTy.dyn_cast<fir::RealType>())
eleTy = Fortran::lower::convertReal(realTy.getContext(),
realTy.getFKind());
@@ -5718,14 +5713,13 @@ class ArrayExprLowering {
// value. The value of the box is forwarded in the continuation.
mlir::Type reduceTy = reduceRank(arrTy, slice);
mlir::Type boxTy = fir::BoxType::get(reduceTy);
- if (mlir::isa<fir::ClassType>(memref.getType()) &&
- !components.hasComponents())
+ if (memref.getType().isa<fir::ClassType>() && !components.hasComponents())
boxTy = fir::ClassType::get(reduceTy);
if (components.substring) {
// Adjust char length to substring size.
fir::CharacterType charTy =
fir::factory::CharacterExprHelper::getCharType(reduceTy);
- auto seqTy = mlir::cast<fir::SequenceType>(reduceTy);
+ auto seqTy = reduceTy.cast<fir::SequenceType>();
// TODO: Use a constant for fir.char LEN if we can compute it.
boxTy = fir::BoxType::get(
fir::SequenceType::get(fir::CharacterType::getUnknownLen(
@@ -5740,7 +5734,7 @@ class ArrayExprLowering {
nonDeferredLenParams = fir::factory::getNonDeferredLenParams(extMemref);
}
mlir::Value embox =
- mlir::isa<fir::BaseBoxType>(memref.getType())
+ memref.getType().isa<fir::BaseBoxType>()
? builder.create<fir::ReboxOp>(loc, boxTy, memref, shape, slice)
.getResult()
: builder
@@ -5751,7 +5745,7 @@ class ArrayExprLowering {
return fir::BoxValue(embox, lbounds, nonDeferredLenParams);
};
}
- auto eleTy = mlir::cast<fir::SequenceType>(arrTy).getEleTy();
+ auto eleTy = arrTy.cast<fir::SequenceType>().getEleTy();
if (isReferentiallyOpaque()) {
// Semantics are an opaque reference to an array.
// This case forwards a continuation that will generate the address
@@ -5766,12 +5760,12 @@ class ArrayExprLowering {
mlir::Value coor = builder.create<fir::ArrayCoorOp>(
loc, refEleTy, memref, shape, slice, indices,
fir::getTypeParams(extMemref));
- if (auto charTy = mlir::dyn_cast<fir::CharacterType>(eleTy)) {
+ if (auto charTy = eleTy.dyn_cast<fir::CharacterType>()) {
llvm::SmallVector<mlir::Value> substringBounds;
populateBounds(substringBounds, components.substring);
if (!substringBounds.empty()) {
mlir::Value dstLen = fir::factory::genLenOfCharacter(
- builder, loc, mlir::cast<fir::SequenceType>(arrTy), memref,
+ builder, loc, arrTy.cast<fir::SequenceType>(), memref,
fir::getTypeParams(extMemref), iters.iterVec(),
substringBounds);
fir::CharBoxValue dstChar(coor, dstLen);
@@ -5869,7 +5863,7 @@ class ArrayExprLowering {
mlir::Type eleRefTy = builder.getRefType(eleTy);
mlir::Value arrayOp = builder.create<fir::ArrayAccessOp>(
loc, eleRefTy, arrLd, iters.iterVec(), arrLdTypeParams);
- if (auto charTy = mlir::dyn_cast<fir::CharacterType>(eleTy)) {
+ if (auto charTy = eleTy.dyn_cast<fir::CharacterType>()) {
llvm::SmallVector<mlir::Value> substringBounds;
populateBounds(substringBounds, components.substring);
if (!substringBounds.empty()) {
@@ -5902,7 +5896,7 @@ class ArrayExprLowering {
const bool hasOptionalAttr =
fir::valueHasFirAttribute(base, fir::getOptionalAttrName());
mlir::Type baseType = fir::unwrapRefType(base.getType());
- const bool isBox = mlir::isa<fir::BoxType>(baseType);
+ const bool isBox = baseType.isa<fir::BoxType>();
const bool isAllocOrPtr =
Fortran::evaluate::IsAllocatableOrPointerObject(expr);
mlir::Type arrType = fir::unwrapPassByRefType(baseType);
@@ -5995,7 +5989,7 @@ class ArrayExprLowering {
if (slice) {
auto slOp = mlir::dyn_cast<fir::SliceOp>(slice.getDefiningOp());
assert(slOp && "expected slice op");
- auto seqTy = mlir::dyn_cast<fir::SequenceType>(arrTy);
+ auto seqTy = arrTy.dyn_cast<fir::SequenceType>();
assert(seqTy && "expected array type");
mlir::Operation::operand_range triples = slOp.getTriples();
fir::SequenceType::Shape shape;
@@ -6059,7 +6053,7 @@ class ArrayExprLowering {
mlir::IndexType idxTy = builder.getIndexType();
mlir::Value multiplier = builder.createIntegerConstant(loc, idxTy, 1);
if (fir::hasDynamicSize(eleTy)) {
- if (auto charTy = mlir::dyn_cast<fir::CharacterType>(eleTy)) {
+ if (auto charTy = eleTy.dyn_cast<fir::CharacterType>()) {
// Array of char with dynamic LEN parameter. Downcast to an array
// of singleton char, and scale by the len type parameter from
// `exv`.
@@ -6080,7 +6074,7 @@ class ArrayExprLowering {
});
fir::CharacterType newEleTy = fir::CharacterType::getSingleton(
eleTy.getContext(), charTy.getFKind());
- if (auto seqTy = mlir::dyn_cast<fir::SequenceType>(resTy)) {
+ if (auto seqTy = resTy.dyn_cast<fir::SequenceType>()) {
assert(eleTy == seqTy.getEleTy());
resTy = fir::SequenceType::get(seqTy.getShape(), newEleTy);
}
@@ -6167,7 +6161,7 @@ class ArrayExprLowering {
if (!eleSz) {
// Compute the element size at runtime.
assert(fir::hasDynamicSize(eleTy));
- if (auto charTy = mlir::dyn_cast<fir::CharacterType>(eleTy)) {
+ if (auto charTy = eleTy.dyn_cast<fir::CharacterType>()) {
auto charBytes =
builder.getKindMap().getCharacterBitsize(charTy.getFKind()) / 8;
mlir::Value bytes =
@@ -6187,7 +6181,7 @@ class ArrayExprLowering {
auto computeCoordinate = [&](mlir::Value buff, mlir::Value off) {
mlir::Type refTy = eleRefTy;
if (fir::hasDynamicSize(eleTy)) {
- if (auto charTy = mlir::dyn_cast<fir::CharacterType>(eleTy)) {
+ if (auto charTy = eleTy.dyn_cast<fir::CharacterType>()) {
// Scale a simple pointer using dynamic length and offset values.
auto chTy = fir::CharacterType::getSingleton(charTy.getContext(),
charTy.getFKind());
@@ -6314,7 +6308,7 @@ class ArrayExprLowering {
builder.createConvert(loc, idxTy, fir::getBase(asScalar(x.upper())));
mlir::Value step =
builder.createConvert(loc, idxTy, fir::getBase(asScalar(x.stride())));
- auto seqTy = mlir::cast<fir::SequenceType>(resTy);
+ auto seqTy = resTy.template cast<fir::SequenceType>();
mlir::Type eleTy = fir::unwrapSequenceType(seqTy);
auto loop =
builder.create<fir::DoLoopOp>(loc, lo, up, step, /*unordered=*/false,
@@ -6381,7 +6375,7 @@ class ArrayExprLowering {
auto evExpr = toEvExpr(x);
mlir::Type resTy = translateSomeExprToFIRType(converter, evExpr);
mlir::IndexType idxTy = builder.getIndexType();
- auto seqTy = mlir::cast<fir::SequenceType>(resTy);
+ auto seqTy = resTy.template cast<fir::SequenceType>();
mlir::Type eleTy = fir::unwrapSequenceType(resTy);
mlir::Value buffSize = builder.createTemporary(loc, idxTy, ".buff.size");
mlir::Value zero = builder.createIntegerConstant(loc, idxTy, 0);
@@ -6725,7 +6719,7 @@ class ArrayExprLowering {
auto fieldTy = fir::FieldType::get(builder.getContext());
std::string name =
converter.getRecordTypeFieldName(getLastSym(*x));
- if (auto recTy = mlir::dyn_cast<fir::RecordType>(ty)) {
+ if (auto recTy = ty.dyn_cast<fir::RecordType>()) {
ty = recTy.getType(name);
auto fld = builder.create<fir::FieldIndexOp>(
loc, fieldTy, name, recTy, fir::getTypeParams(arrayExv));
@@ -6734,7 +6728,7 @@ class ArrayExprLowering {
// Need an intermediate dereference if the boxed value
// appears in the middle of the component path or if it is
// on the right and this is not a pointer assignment.
- if (auto boxTy = mlir::dyn_cast<fir::BaseBoxType>(ty)) {
+ if (auto boxTy = ty.dyn_cast<fir::BaseBoxType>()) {
auto currentFunc = components.getExtendCoorRef();
auto loc = getLoc();
auto *bldr = &converter.getFirOpBuilder();
@@ -6745,9 +6739,9 @@ class ArrayExprLowering {
deref = true;
}
}
- } else if (auto boxTy = mlir::dyn_cast<fir::BaseBoxType>(ty)) {
+ } else if (auto boxTy = ty.dyn_cast<fir::BaseBoxType>()) {
ty = fir::unwrapRefType(boxTy.getEleTy());
- auto recTy = mlir::cast<fir::RecordType>(ty);
+ auto recTy = ty.cast<fir::RecordType>();
ty = recTy.getType(name);
auto fld = builder.create<fir::FieldIndexOp>(
loc, fieldTy, name, recTy, fir::getTypeParams(arrayExv));
@@ -6796,7 +6790,7 @@ class ArrayExprLowering {
auto arrayOp = builder.create<fir::ArrayAccessOp>(
loc, eleRefTy, innerArg, iters.iterVec(),
fir::factory::getTypeParams(loc, builder, load));
- if (auto charTy = mlir::dyn_cast<fir::CharacterType>(eleTy)) {
+ if (auto charTy = eleTy.dyn_cast<fir::CharacterType>()) {
mlir::Value dstLen = fir::factory::genLenOfCharacter(
builder, loc, load, iters.iterVec(), substringBounds);
fir::ArrayAmendOp amend = createCharArrayAmend(
@@ -6812,13 +6806,13 @@ class ArrayExprLowering {
return arrayLoadExtValue(builder, loc, load, iters.iterVec(),
amend);
}
- assert(mlir::isa<fir::SequenceType>(eleTy));
+ assert(eleTy.isa<fir::SequenceType>());
TODO(loc, "array (as element) assignment");
}
if (components.hasExtendCoorRef()) {
auto eleBoxTy =
fir::applyPathToType(innerArg.getType(), iters.iterVec());
- if (!eleBoxTy || !mlir::isa<fir::BoxType>(eleBoxTy))
+ if (!eleBoxTy || !eleBoxTy.isa<fir::BoxType>())
TODO(loc, "assignment in a FORALL involving a designator with a "
"POINTER or ALLOCATABLE component part-ref");
auto arrayOp = builder.create<fir::ArrayAccessOp>(
@@ -6830,7 +6824,7 @@ class ArrayExprLowering {
// assignment, then insert the dereference of the box before any
// conversion and store.
if (!isPointerAssignment()) {
- if (auto boxTy = mlir::dyn_cast<fir::BaseBoxType>(eleTy)) {
+ if (auto boxTy = eleTy.dyn_cast<fir::BaseBoxType>()) {
eleTy = fir::boxMemRefType(boxTy);
addr = builder.create<fir::BoxAddrOp>(loc, eleTy, addr);
eleTy = fir::unwrapRefType(eleTy);
@@ -6891,7 +6885,7 @@ class ArrayExprLowering {
}
if (components.hasExtendCoorRef()) {
auto eleBoxTy = fir::applyPathToType(load.getType(), iters.iterVec());
- if (!eleBoxTy || !mlir::isa<fir::BoxType>(eleBoxTy))
+ if (!eleBoxTy || !eleBoxTy.isa<fir::BoxType>())
TODO(loc, "assignment in a FORALL involving a designator with a "
"POINTER or ALLOCATABLE component part-ref");
auto access = builder.create<fir::ArrayAccessOp>(
@@ -6903,7 +6897,7 @@ class ArrayExprLowering {
}
if (isPointerAssignment()) {
auto eleTy = fir::applyPathToType(load.getType(), iters.iterVec());
- if (!mlir::isa<fir::BoxType>(eleTy)) {
+ if (!eleTy.isa<fir::BoxType>()) {
// Rhs is a regular expression that will need to be boxed before
// assigning to the boxed variable.
auto typeParams = fir::factory::getTypeParams(loc, builder, load);
@@ -7621,7 +7615,7 @@ mlir::Value Fortran::lower::addCrayPointerInst(mlir::Location loc,
auto box = builder.create<fir::EmboxOp>(loc, boxTy, ptrVal, empty, empty,
emptyRange);
mlir::Value addrof =
- (mlir::isa<fir::ReferenceType>(ptrTy))
+ (ptrTy.isa<fir::ReferenceType>())
? builder.create<fir::BoxAddrOp>(loc, ptrTy, box)
: builder.create<fir::BoxAddrOp>(loc, builder.getRefType(ptrTy), box);
diff --git a/flang/lib/Lower/ConvertExprToHLFIR.cpp b/flang/lib/Lower/ConvertExprToHLFIR.cpp
index 93bdf650f9ffbe..6e57b31d022b0b 100644
--- a/flang/lib/Lower/ConvertExprToHLFIR.cpp
+++ b/flang/lib/Lower/ConvertExprToHLFIR.cpp
@@ -138,8 +138,8 @@ class HlfirDesignatorBuilder {
mlir::Location loc = getLoc();
mlir::Type idxTy = builder.getIndexType();
llvm::SmallVector<mlir::Value> extents;
- auto seqTy = mlir::cast<fir::SequenceType>(
- hlfir::getFortranElementOrSequenceType(fieldType));
+ auto seqTy = hlfir::getFortranElementOrSequenceType(fieldType)
+ .cast<fir::SequenceType>();
for (auto extent : seqTy.getShape()) {
if (extent == fir::SequenceType::getUnknownExtent()) {
// We have already generated invalid hlfir.declare
@@ -199,7 +199,7 @@ class HlfirDesignatorBuilder {
const T &designatorNode) {
// Get base's shape if its a sequence type with no previously computed
// result shape
- if (partInfo.base && mlir::isa<fir::SequenceType>(resultValueType) &&
+ if (partInfo.base && resultValueType.isa<fir::SequenceType>() &&
!partInfo.resultShape)
partInfo.resultShape =
hlfir::genShape(getLoc(), getBuilder(), *partInfo.base);
@@ -209,7 +209,7 @@ class HlfirDesignatorBuilder {
return fir::ClassType::get(resultValueType);
// Character scalar with dynamic length needs a fir.boxchar to hold the
// designator length.
- auto charType = mlir::dyn_cast<fir::CharacterType>(resultValueType);
+ auto charType = resultValueType.dyn_cast<fir::CharacterType>();
if (charType && charType.hasDynamicLen())
return fir::BoxCharType::get(charType.getContext(), charType.getFKind());
// Arrays with non default lower bounds or dynamic length or dynamic extent
@@ -218,7 +218,7 @@ class HlfirDesignatorBuilder {
hasNonDefaultLowerBounds(partInfo))
return fir::BoxType::get(resultValueType);
// Non simply contiguous ref require a fir.box to carry the byte stride.
- if (mlir::isa<fir::SequenceType>(resultValueType) &&
+ if (resultValueType.isa<fir::SequenceType>() &&
!Fortran::evaluate::IsSimplyContiguous(
designatorNode, getConverter().getFoldingContext()))
return fir::BoxType::get(resultValueType);
@@ -398,8 +398,8 @@ class HlfirDesignatorBuilder {
partInfo.typeParams[0] =
fir::factory::genMaxWithZero(builder, loc, rawLen);
}
- auto kind = mlir::cast<fir::CharacterType>(
- hlfir::getFortranElementType(baseStringType))
+ auto kind = hlfir::getFortranElementType(baseStringType)
+ .cast<fir::CharacterType>()
.getFKind();
auto newCharTy = fir::CharacterType::get(
baseStringType.getContext(), kind,
@@ -579,7 +579,7 @@ class HlfirDesignatorBuilder {
return createVectorSubscriptElementAddrOp(partInfo, baseType,
resultExtents);
- mlir::Type resultType = mlir::cast<fir::SequenceType>(baseType).getEleTy();
+ mlir::Type resultType = baseType.cast<fir::SequenceType>().getEleTy();
if (!resultTypeShape.empty()) {
// Ranked array section. The result shape comes from the array section
// subscripts.
@@ -612,8 +612,8 @@ class HlfirDesignatorBuilder {
}
static bool hasNonDefaultLowerBounds(const PartInfo &partInfo) {
return partInfo.resultShape &&
- mlir::isa<fir::ShiftType, fir::ShapeShiftType>(
- partInfo.resultShape.getType());
+ (partInfo.resultShape.getType().isa<fir::ShiftType>() ||
+ partInfo.resultShape.getType().isa<fir::ShapeShiftType>());
}
mlir::Type visit(const Fortran::evaluate::Component &component,
@@ -705,7 +705,7 @@ class HlfirDesignatorBuilder {
const Fortran::semantics::Symbol &componentSym = component.GetLastSymbol();
partInfo.componentName = converter.getRecordTypeFieldName(componentSym);
auto recordType =
- mlir::cast<fir::RecordType>(hlfir::getFortranElementType(baseType));
+ hlfir::getFortranElementType(baseType).cast<fir::RecordType>();
if (recordType.isDependentType())
TODO(getLoc(), "Designate derived type with length parameters in HLFIR");
mlir::Type fieldType = recordType.getType(partInfo.componentName);
@@ -718,7 +718,7 @@ class HlfirDesignatorBuilder {
if (fir::isRecordWithTypeParameters(fieldEleType))
TODO(loc,
"lower a component that is a parameterized derived type to HLFIR");
- if (auto charTy = mlir::dyn_cast<fir::CharacterType>(fieldEleType)) {
+ if (auto charTy = fieldEleType.dyn_cast<fir::CharacterType>()) {
mlir::Location loc = getLoc();
mlir::Type idxTy = builder.getIndexType();
if (charTy.hasConstantLen())
@@ -811,7 +811,7 @@ class HlfirDesignatorBuilder {
}
}
builder.setInsertionPoint(elementalAddrOp);
- return mlir::cast<fir::SequenceType>(baseType).getEleTy();
+ return baseType.cast<fir::SequenceType>().getEleTy();
}
/// Yield the designator for the final part-ref inside the
@@ -1665,7 +1665,7 @@ class HlfirBuilder {
mlir::Location loc = getLoc();
fir::FirOpBuilder &builder = getBuilder();
mlir::Type ty = translateSomeExprToFIRType(converter, toEvExpr(ctor));
- auto recTy = mlir::cast<fir::RecordType>(ty);
+ auto recTy = ty.cast<fir::RecordType>();
if (recTy.isDependentType())
TODO(loc, "structure constructor for derived type with length parameters "
diff --git a/flang/lib/Lower/ConvertProcedureDesignator.cpp b/flang/lib/Lower/ConvertProcedureDesignator.cpp
index aa0d7ce54788b1..2446be3a1908b3 100644
--- a/flang/lib/Lower/ConvertProcedureDesignator.cpp
+++ b/flang/lib/Lower/ConvertProcedureDesignator.cpp
@@ -107,11 +107,11 @@ static hlfir::EntityWithAttributes designateProcedurePointerComponent(
procComponentSym);
/// Passed argument may be a descriptor. This is a scalar reference, so the
/// base address can be directly addressed.
- if (mlir::isa<fir::BaseBoxType>(base.getType()))
+ if (base.getType().isa<fir::BaseBoxType>())
base = builder.create<fir::BoxAddrOp>(loc, base);
std::string fieldName = converter.getRecordTypeFieldName(procComponentSym);
auto recordType =
- mlir::cast<fir::RecordType>(hlfir::getFortranElementType(base.getType()));
+ hlfir::getFortranElementType(base.getType()).cast<fir::RecordType>();
mlir::Type fieldType = recordType.getType(fieldName);
// Note: semantics turns x%p() into x%t%p() when the procedure pointer
// component is part of parent component t.
@@ -164,7 +164,7 @@ hlfir::EntityWithAttributes Fortran::lower::convertProcedureDesignatorToHLFIR(
fir::FirOpBuilder &builder = converter.getFirOpBuilder();
mlir::Value funcAddr = fir::getBase(procExv);
- if (!mlir::isa<fir::BoxProcType>(funcAddr.getType())) {
+ if (!funcAddr.getType().isa<fir::BoxProcType>()) {
mlir::Type boxTy =
Fortran::lower::getUntypedBoxProcType(&converter.getMLIRContext());
if (auto host = Fortran::lower::argumentHostAssocs(converter, funcAddr))
diff --git a/flang/lib/Lower/ConvertVariable.cpp b/flang/lib/Lower/ConvertVariable.cpp
index edf1f24a08e5c9..21db0cac11bf6a 100644
--- a/flang/lib/Lower/ConvertVariable.cpp
+++ b/flang/lib/Lower/ConvertVariable.cpp
@@ -389,13 +389,13 @@ static mlir::Value genDefaultInitializerValue(
fir::FirOpBuilder &builder = converter.getFirOpBuilder();
mlir::Type scalarType = symTy;
fir::SequenceType sequenceType;
- if (auto ty = mlir::dyn_cast<fir::SequenceType>(symTy)) {
+ if (auto ty = symTy.dyn_cast<fir::SequenceType>()) {
sequenceType = ty;
scalarType = ty.getEleTy();
}
// Build a scalar default value of the symbol type, looping through the
// components to build each component initial value.
- auto recTy = mlir::cast<fir::RecordType>(scalarType);
+ auto recTy = scalarType.cast<fir::RecordType>();
mlir::Value initialValue = builder.create<fir::UndefOp>(loc, scalarType);
const Fortran::semantics::DeclTypeSpec *declTy = sym.GetType();
assert(declTy && "var with default initialization must have a type");
@@ -493,9 +493,9 @@ static fir::GlobalOp defineGlobal(Fortran::lower::AbstractConverter &converter,
// with a tensor mlir type. This optimization currently only supports
// Fortran arrays of integer, real, complex, or logical. The tensor
// type does not support nested structures.
- if (mlir::isa<fir::SequenceType>(symTy) &&
+ if (symTy.isa<fir::SequenceType>() &&
!Fortran::semantics::IsAllocatableOrPointer(sym)) {
- mlir::Type eleTy = mlir::cast<fir::SequenceType>(symTy).getEleTy();
+ mlir::Type eleTy = symTy.cast<fir::SequenceType>().getEleTy();
if (eleTy.isa<mlir::IntegerType, mlir::FloatType, fir::ComplexType,
fir::LogicalType>()) {
const auto *details =
@@ -1292,7 +1292,7 @@ static void finalizeCommonBlockDefinition(
fir::GlobalOp global,
const Fortran::semantics::MutableSymbolVector &cmnBlkMems) {
fir::FirOpBuilder &builder = converter.getFirOpBuilder();
- mlir::TupleType commonTy = mlir::cast<mlir::TupleType>(global.getType());
+ mlir::TupleType commonTy = global.getType().cast<mlir::TupleType>();
auto initFunc = [&](fir::FirOpBuilder &builder) {
mlir::IndexType idxTy = builder.getIndexType();
mlir::Value cb = builder.create<fir::ZeroOp>(loc, commonTy);
@@ -1407,7 +1407,7 @@ static bool lowerToBoxValue(const Fortran::semantics::Symbol &sym,
mlir::Value dummyArg,
Fortran::lower::AbstractConverter &converter) {
// Only dummy arguments coming as fir.box can be tracked in an BoxValue.
- if (!dummyArg || !mlir::isa<fir::BaseBoxType>(dummyArg.getType()))
+ if (!dummyArg || !dummyArg.getType().isa<fir::BaseBoxType>())
return false;
// Non contiguous arrays must be tracked in an BoxValue.
if (sym.Rank() > 0 && !Fortran::evaluate::IsSimplyContiguous(
@@ -1905,7 +1905,7 @@ void Fortran::lower::mapSymbolAttributes(
// Do not keep scalar characters as fir.box (even when optional).
// Lowering and FIR is not meant to deal with scalar characters as
// fir.box outside of calls.
- auto boxTy = mlir::dyn_cast<fir::BaseBoxType>(dummyArg.getType());
+ auto boxTy = dummyArg.getType().dyn_cast<fir::BaseBoxType>();
mlir::Type refTy = builder.getRefType(boxTy.getEleTy());
mlir::Type lenType = builder.getCharacterLengthType();
mlir::Value addr, len;
@@ -1984,8 +1984,8 @@ void Fortran::lower::mapSymbolAttributes(
// a non pointer/allocatable symbol to be mapped to a MutableBox.
mlir::Type ty = converter.genType(var);
bool isPolymorphic = false;
- if (auto boxTy = mlir::dyn_cast<fir::BaseBoxType>(ty)) {
- isPolymorphic = mlir::isa<fir::ClassType>(ty);
+ if (auto boxTy = ty.dyn_cast<fir::BaseBoxType>()) {
+ isPolymorphic = ty.isa<fir::ClassType>();
ty = boxTy.getEleTy();
}
Fortran::lower::genDeclareSymbol(
@@ -2092,7 +2092,7 @@ void Fortran::lower::mapSymbolAttributes(
mlir::Value addr = preAlloc;
if (arg)
- if (auto boxTy = mlir::dyn_cast<fir::BaseBoxType>(arg.getType())) {
+ if (auto boxTy = arg.getType().dyn_cast<fir::BaseBoxType>()) {
// Contiguous assumed shape that can be tracked without a fir.box.
mlir::Type refTy = builder.getRefType(boxTy.getEleTy());
addr = builder.create<fir::BoxAddrOp>(loc, refTy, arg);
@@ -2134,7 +2134,7 @@ void Fortran::lower::mapSymbolAttributes(
} else if (!len) {
// Assumed length fir.box (possible for contiguous assumed shapes).
// Read length from box.
- assert(arg && mlir::isa<fir::BoxType>(arg.getType()) &&
+ assert(arg && arg.getType().isa<fir::BoxType>() &&
"must be character dummy fir.box");
len = charHelp.readLengthFromBox(arg);
}
diff --git a/flang/lib/Lower/CustomIntrinsicCall.cpp b/flang/lib/Lower/CustomIntrinsicCall.cpp
index 30c6ce7f53b3f8..439fc3d915b4e4 100644
--- a/flang/lib/Lower/CustomIntrinsicCall.cpp
+++ b/flang/lib/Lower/CustomIntrinsicCall.cpp
@@ -227,23 +227,22 @@ lowerIshftc(fir::FirOpBuilder &builder, mlir::Location loc,
args.push_back(getOperand(1, loadOperand));
auto iPC = isPresentCheck(2);
assert(iPC.has_value());
- args.push_back(
- builder
- .genIfOp(loc, {resultType}, *iPC,
- /*withElseRegion=*/true)
- .genThen([&]() {
- fir::ExtendedValue sizeExv = getOperand(2, loadOperand);
- mlir::Value size =
- builder.createConvert(loc, resultType, fir::getBase(sizeExv));
- builder.create<fir::ResultOp>(loc, size);
- })
- .genElse([&]() {
- mlir::Value bitSize = builder.createIntegerConstant(
- loc, resultType,
- mlir::cast<mlir::IntegerType>(resultType).getWidth());
- builder.create<fir::ResultOp>(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<fir::ResultOp>(loc, size);
+ })
+ .genElse([&]() {
+ mlir::Value bitSize = builder.createIntegerConstant(
+ loc, resultType,
+ resultType.cast<mlir::IntegerType>().getWidth());
+ builder.create<fir::ResultOp>(loc, bitSize);
+ })
+ .getResults()[0]);
return genIntrinsicCall(builder, loc, name, resultType, args, stmtCtx);
}
@@ -283,7 +282,7 @@ lowerAssociated(fir::FirOpBuilder &builder, mlir::Location loc,
builder.create<fir::IsPresentOp>(loc, builder.getI1Type(), targetBase);
mlir::Type targetType = fir::unwrapRefType(targetBase.getType());
mlir::Type targetValueType = fir::unwrapPassByRefType(targetType);
- mlir::Type boxType = mlir::isa<fir::BaseBoxType>(targetType)
+ mlir::Type boxType = targetType.isa<fir::BaseBoxType>()
? targetType
: fir::BoxType::get(targetValueType);
fir::BoxValue targetBox =
diff --git a/flang/lib/Lower/DirectivesCommon.h b/flang/lib/Lower/DirectivesCommon.h
index 42bd3868196b20..3ebf3fd965da1e 100644
--- a/flang/lib/Lower/DirectivesCommon.h
+++ b/flang/lib/Lower/DirectivesCommon.h
@@ -642,14 +642,14 @@ getDataOperandBaseAddr(Fortran::lower::AbstractConverter &converter,
isPresent =
builder.create<fir::IsPresentOp>(loc, builder.getI1Type(), rawInput);
- if (auto boxTy = mlir::dyn_cast<fir::BaseBoxType>(
- fir::unwrapRefType(symAddr.getType()))) {
- if (mlir::isa<fir::RecordType>(boxTy.getEleTy()))
+ if (auto boxTy =
+ fir::unwrapRefType(symAddr.getType()).dyn_cast<fir::BaseBoxType>()) {
+ if (boxTy.getEleTy().isa<fir::RecordType>())
TODO(loc, "derived type");
// Load the box when baseAddr is a `fir.ref<fir.box<T>>` or a
// `fir.ref<fir.class<T>>` type.
- if (mlir::isa<fir::ReferenceType>(symAddr.getType())) {
+ if (symAddr.getType().isa<fir::ReferenceType>()) {
if (Fortran::semantics::IsOptional(sym)) {
mlir::Value addr =
builder.genIfOp(loc, {boxTy}, isPresent, /*withElseRegion=*/true)
@@ -722,7 +722,7 @@ genBoundsOpsFromBox(fir::FirOpBuilder &builder, mlir::Location loc,
mlir::Type idxTy = builder.getIndexType();
mlir::Type boundTy = builder.getType<BoundsType>();
- assert(mlir::isa<fir::BaseBoxType>(info.addr.getType()) &&
+ assert(info.addr.getType().isa<fir::BaseBoxType>() &&
"expect fir.box or fir.class");
if (info.isPresent) {
@@ -909,8 +909,7 @@ genBoundsOps(fir::FirOpBuilder &builder, mlir::Location loc,
mlir::Value stride = one;
bool strideInBytes = false;
- if (mlir::isa<fir::BaseBoxType>(
- fir::unwrapRefType(info.addr.getType()))) {
+ if (fir::unwrapRefType(info.addr.getType()).isa<fir::BaseBoxType>()) {
if (info.isPresent) {
stride =
builder
@@ -1021,8 +1020,8 @@ genBoundsOps(fir::FirOpBuilder &builder, mlir::Location loc,
}
}
- if (info.isPresent && mlir::isa<fir::BaseBoxType>(
- fir::unwrapRefType(info.addr.getType()))) {
+ if (info.isPresent &&
+ fir::unwrapRefType(info.addr.getType()).isa<fir::BaseBoxType>()) {
extent =
builder
.genIfOp(loc, idxTy, info.isPresent, /*withElseRegion=*/true)
@@ -1158,7 +1157,7 @@ AddrAndBoundsInfo gatherDataOperandAddrAndBounds(
converter.genExprAddr(operandLocation, designator, stmtCtx);
info.addr = fir::getBase(compExv);
info.rawInput = info.addr;
- if (mlir::isa<fir::SequenceType>(fir::unwrapRefType(info.addr.getType())))
+ if (fir::unwrapRefType(info.addr.getType()).isa<fir::SequenceType>())
bounds = genBaseBoundsOps<BoundsOp, BoundsType>(builder, operandLocation,
converter, compExv,
/*isAssumedSize=*/false);
@@ -1200,14 +1199,13 @@ AddrAndBoundsInfo gatherDataOperandAddrAndBounds(
fir::ExtendedValue dataExv = converter.getSymbolExtendedValue(*symRef);
info =
getDataOperandBaseAddr(converter, builder, *symRef, operandLocation);
- if (mlir::isa<fir::BaseBoxType>(
- fir::unwrapRefType(info.addr.getType()))) {
+ if (fir::unwrapRefType(info.addr.getType()).isa<fir::BaseBoxType>()) {
bounds = genBoundsOpsFromBox<BoundsOp, BoundsType>(
builder, operandLocation, converter, dataExv, info);
}
bool dataExvIsAssumedSize =
Fortran::semantics::IsAssumedSizeArray(symRef->get().GetUltimate());
- if (mlir::isa<fir::SequenceType>(fir::unwrapRefType(info.addr.getType())))
+ if (fir::unwrapRefType(info.addr.getType()).isa<fir::SequenceType>())
bounds = genBaseBoundsOps<BoundsOp, BoundsType>(
builder, operandLocation, converter, dataExv, dataExvIsAssumedSize);
asFortran << symRef->get().name().ToString();
diff --git a/flang/lib/Lower/HlfirIntrinsics.cpp b/flang/lib/Lower/HlfirIntrinsics.cpp
index 310b62697f710d..bda04fa9689beb 100644
--- a/flang/lib/Lower/HlfirIntrinsics.cpp
+++ b/flang/lib/Lower/HlfirIntrinsics.cpp
@@ -265,7 +265,7 @@ HlfirTransformationalIntrinsic::computeResultType(mlir::Value argArray,
mlir::Type stmtResultType) {
mlir::Type normalisedResult =
hlfir::getFortranElementOrSequenceType(stmtResultType);
- if (auto array = mlir::dyn_cast<fir::SequenceType>(normalisedResult)) {
+ if (auto array = normalisedResult.dyn_cast<fir::SequenceType>()) {
hlfir::ExprType::Shape resultShape =
hlfir::ExprType::Shape{array.getShape()};
mlir::Type elementType = array.getEleTy();
@@ -341,7 +341,7 @@ mlir::Value HlfirTransposeLowering::lowerImpl(
hlfir::ExprType::Shape resultShape;
mlir::Type normalisedResult =
hlfir::getFortranElementOrSequenceType(stmtResultType);
- auto array = mlir::cast<fir::SequenceType>(normalisedResult);
+ auto array = normalisedResult.cast<fir::SequenceType>();
llvm::ArrayRef<int64_t> arrayShape = array.getShape();
assert(arrayShape.size() == 2 && "arguments to transpose have a rank of 2");
mlir::Type elementType = array.getEleTy();
diff --git a/flang/lib/Lower/HostAssociations.cpp b/flang/lib/Lower/HostAssociations.cpp
index 75a5bed5665578..2e2656356719f8 100644
--- a/flang/lib/Lower/HostAssociations.cpp
+++ b/flang/lib/Lower/HostAssociations.cpp
@@ -219,7 +219,7 @@ class CapturedCharacterScalars
static mlir::Type getType(Fortran::lower::AbstractConverter &converter,
const Fortran::semantics::Symbol &sym) {
fir::KindTy kind =
- mlir::cast<fir::CharacterType>(converter.genType(sym)).getFKind();
+ converter.genType(sym).cast<fir::CharacterType>().getFKind();
return fir::BoxCharType::get(&converter.getMLIRContext(), kind);
}
@@ -293,7 +293,7 @@ class CapturedPolymorphicScalar
mlir::Location loc = args.loc;
mlir::Value box = args.valueInTuple;
if (Fortran::semantics::IsOptional(sym)) {
- auto boxTy = mlir::cast<fir::BaseBoxType>(box.getType());
+ auto boxTy = box.getType().cast<fir::BaseBoxType>();
auto eleTy = boxTy.getEleTy();
if (!fir::isa_ref_type(eleTy))
eleTy = builder.getRefType(eleTy);
@@ -381,8 +381,8 @@ class CapturedArrays : public CapturedSymbols<CapturedArrays> {
const Fortran::semantics::Symbol &sym) {
mlir::Type type = converter.genType(sym);
bool isPolymorphic = Fortran::semantics::IsPolymorphic(sym);
- assert((mlir::isa<fir::SequenceType>(type) ||
- (isPolymorphic && mlir::isa<fir::ClassType>(type))) &&
+ assert((type.isa<fir::SequenceType>() ||
+ (isPolymorphic && type.isa<fir::ClassType>())) &&
"must be a sequence type");
if (isPolymorphic)
return type;
@@ -459,7 +459,7 @@ class CapturedArrays : public CapturedSymbols<CapturedArrays> {
// (absent boxes are null descriptor addresses, not descriptors containing
// a null base address).
if (Fortran::semantics::IsOptional(sym)) {
- auto boxTy = mlir::cast<fir::BaseBoxType>(box.getType());
+ auto boxTy = box.getType().cast<fir::BaseBoxType>();
auto eleTy = boxTy.getEleTy();
if (!fir::isa_ref_type(eleTy))
eleTy = builder.getRefType(eleTy);
@@ -527,7 +527,7 @@ walkCaptureCategories(T visitor, Fortran::lower::AbstractConverter &converter,
// `t` should be the result of getArgumentType, which has a type of
// `!fir.ref<tuple<...>>`.
static mlir::TupleType unwrapTupleTy(mlir::Type t) {
- return mlir::cast<mlir::TupleType>(fir::dyn_cast_ptrEleTy(t));
+ return fir::dyn_cast_ptrEleTy(t).cast<mlir::TupleType>();
}
static mlir::Value genTupleCoor(fir::FirOpBuilder &builder, mlir::Location loc,
@@ -535,7 +535,7 @@ static mlir::Value genTupleCoor(fir::FirOpBuilder &builder, mlir::Location loc,
mlir::Value offset) {
// fir.ref<fir.ref> and fir.ptr<fir.ref> are forbidden. Use
// fir.llvm_ptr if needed.
- auto ty = mlir::isa<fir::ReferenceType>(varTy)
+ auto ty = varTy.isa<fir::ReferenceType>()
? mlir::Type(fir::LLVMPointerType::get(varTy))
: mlir::Type(builder.getRefType(varTy));
return builder.create<fir::CoordinateOp>(loc, ty, tupleArg, offset);
diff --git a/flang/lib/Lower/IO.cpp b/flang/lib/Lower/IO.cpp
index ed0afad9197df0..ac82276bcddbd0 100644
--- a/flang/lib/Lower/IO.cpp
+++ b/flang/lib/Lower/IO.cpp
@@ -168,7 +168,7 @@ static constexpr fir::runtime::FuncTypeBuilderFunc getTypeModel() {
}
inline int64_t getLength(mlir::Type argTy) {
- return mlir::cast<fir::SequenceType>(argTy).getShape()[0];
+ return argTy.cast<fir::SequenceType>().getShape()[0];
}
/// Get (or generate) the MLIR FuncOp for a given IO runtime function.
@@ -656,11 +656,11 @@ static void genNamelistIO(Fortran::lower::AbstractConverter &converter,
static mlir::func::FuncOp getOutputFunc(mlir::Location loc,
fir::FirOpBuilder &builder,
mlir::Type type, bool isFormatted) {
- if (mlir::isa<fir::RecordType>(fir::unwrapPassByRefType(type)))
+ if (fir::unwrapPassByRefType(type).isa<fir::RecordType>())
return getIORuntimeFunc<mkIOKey(OutputDerivedType)>(loc, builder);
if (!isFormatted)
return getIORuntimeFunc<mkIOKey(OutputDescriptor)>(loc, builder);
- if (auto ty = mlir::dyn_cast<mlir::IntegerType>(type)) {
+ if (auto ty = type.dyn_cast<mlir::IntegerType>()) {
switch (ty.getWidth()) {
case 1:
return getIORuntimeFunc<mkIOKey(OutputLogical)>(loc, builder);
@@ -677,14 +677,14 @@ static mlir::func::FuncOp getOutputFunc(mlir::Location loc,
}
llvm_unreachable("unknown OutputInteger kind");
}
- if (auto ty = mlir::dyn_cast<mlir::FloatType>(type)) {
+ if (auto ty = type.dyn_cast<mlir::FloatType>()) {
if (auto width = ty.getWidth(); width == 32)
return getIORuntimeFunc<mkIOKey(OutputReal32)>(loc, builder);
else if (width == 64)
return getIORuntimeFunc<mkIOKey(OutputReal64)>(loc, builder);
}
auto kindMap = fir::getKindMapping(builder.getModule());
- if (auto ty = mlir::dyn_cast<fir::ComplexType>(type)) {
+ if (auto ty = type.dyn_cast<fir::ComplexType>()) {
// COMPLEX(KIND=k) corresponds to a pair of REAL(KIND=k).
auto width = kindMap.getRealBitsize(ty.getFKind());
if (width == 32)
@@ -692,7 +692,7 @@ static mlir::func::FuncOp getOutputFunc(mlir::Location loc,
else if (width == 64)
return getIORuntimeFunc<mkIOKey(OutputComplex64)>(loc, builder);
}
- if (mlir::isa<fir::LogicalType>(type))
+ if (type.isa<fir::LogicalType>())
return getIORuntimeFunc<mkIOKey(OutputLogical)>(loc, builder);
if (fir::factory::CharacterExprHelper::isCharacterScalar(type)) {
// TODO: What would it mean if the default CHARACTER KIND is set to a wide
@@ -731,14 +731,14 @@ static void genOutputItemList(
mlir::func::FuncOp outputFunc =
getOutputFunc(loc, builder, itemTy, isFormatted);
mlir::Type argType = outputFunc.getFunctionType().getInput(1);
- assert((isFormatted || mlir::isa<fir::BoxType>(argType)) &&
+ assert((isFormatted || argType.isa<fir::BoxType>()) &&
"expect descriptor for unformatted IO runtime");
llvm::SmallVector<mlir::Value> outputFuncArgs = {cookie};
fir::factory::CharacterExprHelper helper{builder, loc};
- if (mlir::isa<fir::BoxType>(argType)) {
+ if (argType.isa<fir::BoxType>()) {
mlir::Value box = fir::getBase(converter.genExprBox(loc, *expr, stmtCtx));
outputFuncArgs.push_back(builder.createConvert(loc, argType, box));
- if (mlir::isa<fir::RecordType>(fir::unwrapPassByRefType(itemTy)))
+ if (fir::unwrapPassByRefType(itemTy).isa<fir::RecordType>())
outputFuncArgs.push_back(getNonTbpDefinedIoTableAddr(converter));
} else if (helper.isCharacterScalar(itemTy)) {
fir::ExtendedValue exv = converter.genExprAddr(loc, expr, stmtCtx);
@@ -773,29 +773,29 @@ static void genOutputItemList(
static mlir::func::FuncOp getInputFunc(mlir::Location loc,
fir::FirOpBuilder &builder,
mlir::Type type, bool isFormatted) {
- if (mlir::isa<fir::RecordType>(fir::unwrapPassByRefType(type)))
+ if (fir::unwrapPassByRefType(type).isa<fir::RecordType>())
return getIORuntimeFunc<mkIOKey(InputDerivedType)>(loc, builder);
if (!isFormatted)
return getIORuntimeFunc<mkIOKey(InputDescriptor)>(loc, builder);
- if (auto ty = mlir::dyn_cast<mlir::IntegerType>(type))
+ if (auto ty = type.dyn_cast<mlir::IntegerType>())
return ty.getWidth() == 1
? getIORuntimeFunc<mkIOKey(InputLogical)>(loc, builder)
: getIORuntimeFunc<mkIOKey(InputInteger)>(loc, builder);
- if (auto ty = mlir::dyn_cast<mlir::FloatType>(type)) {
+ if (auto ty = type.dyn_cast<mlir::FloatType>()) {
if (auto width = ty.getWidth(); width == 32)
return getIORuntimeFunc<mkIOKey(InputReal32)>(loc, builder);
else if (width == 64)
return getIORuntimeFunc<mkIOKey(InputReal64)>(loc, builder);
}
auto kindMap = fir::getKindMapping(builder.getModule());
- if (auto ty = mlir::dyn_cast<fir::ComplexType>(type)) {
+ if (auto ty = type.dyn_cast<fir::ComplexType>()) {
auto width = kindMap.getRealBitsize(ty.getFKind());
if (width == 32)
return getIORuntimeFunc<mkIOKey(InputComplex32)>(loc, builder);
else if (width == 64)
return getIORuntimeFunc<mkIOKey(InputComplex64)>(loc, builder);
}
- if (mlir::isa<fir::LogicalType>(type))
+ if (type.isa<fir::LogicalType>())
return getIORuntimeFunc<mkIOKey(InputLogical)>(loc, builder);
if (fir::factory::CharacterExprHelper::isCharacterScalar(type)) {
auto asciiKind = kindMap.defaultCharacterKind();
@@ -830,12 +830,12 @@ createIoRuntimeCallForItem(Fortran::lower::AbstractConverter &converter,
fir::FirOpBuilder &builder = converter.getFirOpBuilder();
mlir::Type argType = inputFunc.getFunctionType().getInput(1);
llvm::SmallVector<mlir::Value> inputFuncArgs = {cookie};
- if (mlir::isa<fir::BaseBoxType>(argType)) {
+ if (argType.isa<fir::BaseBoxType>()) {
mlir::Value box = fir::getBase(item);
- auto boxTy = mlir::dyn_cast<fir::BaseBoxType>(box.getType());
+ auto boxTy = box.getType().dyn_cast<fir::BaseBoxType>();
assert(boxTy && "must be previously emboxed");
inputFuncArgs.push_back(builder.createConvert(loc, argType, box));
- if (mlir::isa<fir::RecordType>(fir::unwrapPassByRefType(boxTy)))
+ if (fir::unwrapPassByRefType(boxTy).isa<fir::RecordType>())
inputFuncArgs.push_back(getNonTbpDefinedIoTableAddr(converter));
} else {
mlir::Value itemAddr = fir::getBase(item);
@@ -846,16 +846,16 @@ createIoRuntimeCallForItem(Fortran::lower::AbstractConverter &converter,
mlir::Value len = fir::getLen(item);
inputFuncArgs.push_back(builder.createConvert(
loc, inputFunc.getFunctionType().getInput(2), len));
- } else if (mlir::isa<mlir::IntegerType>(itemTy)) {
+ } else if (itemTy.isa<mlir::IntegerType>()) {
inputFuncArgs.push_back(builder.create<mlir::arith::ConstantOp>(
loc, builder.getI32IntegerAttr(
- mlir::cast<mlir::IntegerType>(itemTy).getWidth() / 8)));
+ itemTy.cast<mlir::IntegerType>().getWidth() / 8)));
}
}
auto call = builder.create<fir::CallOp>(loc, inputFunc, inputFuncArgs);
auto itemAddr = fir::getBase(item);
auto itemTy = fir::unwrapRefType(itemAddr.getType());
- if (mlir::isa<fir::LogicalType>(itemTy))
+ if (itemTy.isa<fir::LogicalType>())
boolRefToLogical(loc, builder, itemAddr);
return call.getResult(0);
}
@@ -886,7 +886,7 @@ static void genInputItemList(Fortran::lower::AbstractConverter &converter,
mlir::func::FuncOp inputFunc = getInputFunc(
loc, builder, vectorSubscriptBox.getElementType(), isFormatted);
const bool mustBox =
- mlir::isa<fir::BoxType>(inputFunc.getFunctionType().getInput(1));
+ inputFunc.getFunctionType().getInput(1).isa<fir::BoxType>();
if (!checkResult) {
auto elementalGenerator = [&](const fir::ExtendedValue &element) {
createIoRuntimeCallForItem(converter, loc, inputFunc, cookie,
@@ -911,10 +911,9 @@ static void genInputItemList(Fortran::lower::AbstractConverter &converter,
mlir::Type itemTy = converter.genType(*expr);
mlir::func::FuncOp inputFunc =
getInputFunc(loc, builder, itemTy, isFormatted);
- auto itemExv =
- mlir::isa<fir::BoxType>(inputFunc.getFunctionType().getInput(1))
- ? converter.genExprBox(loc, *expr, stmtCtx)
- : converter.genExprAddr(loc, expr, stmtCtx);
+ auto itemExv = inputFunc.getFunctionType().getInput(1).isa<fir::BoxType>()
+ ? converter.genExprBox(loc, *expr, stmtCtx)
+ : converter.genExprAddr(loc, expr, stmtCtx);
ok = createIoRuntimeCallForItem(converter, loc, inputFunc, cookie, itemExv);
}
}
@@ -1773,8 +1772,8 @@ static mlir::Value genIOUnitNumber(Fortran::lower::AbstractConverter &converter,
auto &builder = converter.getFirOpBuilder();
auto rawUnit = fir::getBase(converter.genExprValue(loc, iounit, stmtCtx));
unsigned rawUnitWidth =
- mlir::cast<mlir::IntegerType>(rawUnit.getType()).getWidth();
- unsigned runtimeArgWidth = mlir::cast<mlir::IntegerType>(ty).getWidth();
+ rawUnit.getType().cast<mlir::IntegerType>().getWidth();
+ unsigned runtimeArgWidth = ty.cast<mlir::IntegerType>().getWidth();
// The IO runtime supports `int` unit numbers, if the unit number may
// overflow when passed to the IO runtime, check that the unit number is
// in range before calling the BeginXXX.
@@ -2332,7 +2331,7 @@ mlir::Value genInquireSpec<Fortran::parser::InquireSpec::IntVar>(
if (!eleTy)
fir::emitFatalError(loc,
"internal error: expected a memory reference type");
- auto width = mlir::cast<mlir::IntegerType>(eleTy).getWidth();
+ auto width = eleTy.cast<mlir::IntegerType>().getWidth();
mlir::IndexType idxTy = builder.getIndexType();
mlir::Value kind = builder.createIntegerConstant(loc, idxTy, width / 8);
llvm::SmallVector<mlir::Value> args = {
diff --git a/flang/lib/Lower/OpenACC.cpp b/flang/lib/Lower/OpenACC.cpp
index eae2afc760e648..b56bdedc07bf53 100644
--- a/flang/lib/Lower/OpenACC.cpp
+++ b/flang/lib/Lower/OpenACC.cpp
@@ -65,7 +65,7 @@ static Op createDataEntryOp(fir::FirOpBuilder &builder, mlir::Location loc,
mlir::acc::DataClause dataClause, mlir::Type retTy,
mlir::Value isPresent = {}) {
mlir::Value varPtrPtr;
- if (auto boxTy = mlir::dyn_cast<fir::BaseBoxType>(baseAddr.getType())) {
+ if (auto boxTy = baseAddr.getType().dyn_cast<fir::BaseBoxType>()) {
if (isPresent) {
mlir::Type ifRetTy = boxTy.getEleTy();
if (!fir::isa_ref_type(ifRetTy))
@@ -2658,7 +2658,7 @@ genACCHostDataOp(Fortran::lower::AbstractConverter &converter,
if (ifCond) {
if (auto cst =
mlir::dyn_cast<mlir::arith::ConstantOp>(ifCond.getDefiningOp()))
- if (auto boolAttr = mlir::dyn_cast<mlir::BoolAttr>(cst.getValue())) {
+ if (auto boolAttr = cst.getValue().dyn_cast<mlir::BoolAttr>()) {
if (boolAttr.getValue()) {
// get rid of the if condition if it is always true.
ifCond = mlir::Value();
diff --git a/flang/lib/Lower/OpenMP/ClauseProcessor.cpp b/flang/lib/Lower/OpenMP/ClauseProcessor.cpp
index 79525d6dfe7a21..4c51b61f6bf029 100644
--- a/flang/lib/Lower/OpenMP/ClauseProcessor.cpp
+++ b/flang/lib/Lower/OpenMP/ClauseProcessor.cpp
@@ -23,10 +23,10 @@ namespace omp {
/// Check for unsupported map operand types.
static void checkMapType(mlir::Location location, mlir::Type type) {
- if (auto refType = mlir::dyn_cast<fir::ReferenceType>(type))
+ if (auto refType = type.dyn_cast<fir::ReferenceType>())
type = refType.getElementType();
- if (auto boxType = mlir::dyn_cast_or_null<fir::BoxType>(type))
- if (!mlir::isa<fir::PointerType>(boxType.getElementType()))
+ if (auto boxType = type.dyn_cast_or_null<fir::BoxType>())
+ if (!boxType.getElementType().isa<fir::PointerType>())
TODO(location, "OMPD_target_data MapOperand BoxType");
}
@@ -814,7 +814,7 @@ createMapInfoOp(fir::FirOpBuilder &builder, mlir::Location loc,
llvm::ArrayRef<mlir::Value> members, uint64_t mapType,
mlir::omp::VariableCaptureKind mapCaptureType, mlir::Type retTy,
bool isVal) {
- if (auto boxTy = mlir::dyn_cast<fir::BaseBoxType>(baseAddr.getType())) {
+ if (auto boxTy = baseAddr.getType().dyn_cast<fir::BaseBoxType>()) {
baseAddr = builder.create<fir::BoxAddrOp>(loc, baseAddr);
retTy = baseAddr.getType();
}
diff --git a/flang/lib/Lower/OpenMP/OpenMP.cpp b/flang/lib/Lower/OpenMP/OpenMP.cpp
index 64ec5ae65c823e..f454f5a45a5150 100644
--- a/flang/lib/Lower/OpenMP/OpenMP.cpp
+++ b/flang/lib/Lower/OpenMP/OpenMP.cpp
@@ -84,7 +84,7 @@ static fir::GlobalOp globalInitialization(
// Create default initialization for non-character scalar.
if (Fortran::semantics::IsAllocatableOrObjectPointer(&sym)) {
- mlir::Type baseAddrType = mlir::dyn_cast<fir::BoxType>(ty).getEleTy();
+ mlir::Type baseAddrType = ty.dyn_cast<fir::BoxType>().getEleTy();
Fortran::lower::createGlobalInitialization(
firOpBuilder, global, [&](fir::FirOpBuilder &b) {
mlir::Value nullAddr =
@@ -778,7 +778,7 @@ static void genBodyOfTargetDataOp(
for (auto [argIndex, argSymbol] : llvm::enumerate(useDeviceSymbols)) {
const mlir::BlockArgument &arg = region.front().getArgument(argIndex);
fir::ExtendedValue extVal = converter.getSymbolExtendedValue(*argSymbol);
- if (auto refType = mlir::dyn_cast<fir::ReferenceType>(arg.getType())) {
+ if (auto refType = arg.getType().dyn_cast<fir::ReferenceType>()) {
if (fir::isa_builtin_cptr_type(refType.getElementType())) {
converter.bindSymbol(*argSymbol, arg);
} else {
@@ -1570,15 +1570,13 @@ genTargetOp(Fortran::lower::AbstractConverter &converter,
Fortran::lower::AddrAndBoundsInfo info = getDataOperandBaseAddr(
converter, firOpBuilder, sym, converter.getCurrentLocation());
- if (mlir::isa<fir::BaseBoxType>(
- fir::unwrapRefType(info.addr.getType())))
+ if (fir::unwrapRefType(info.addr.getType()).isa<fir::BaseBoxType>())
bounds =
Fortran::lower::genBoundsOpsFromBox<mlir::omp::MapBoundsOp,
mlir::omp::MapBoundsType>(
firOpBuilder, converter.getCurrentLocation(), converter,
dataExv, info);
- if (mlir::isa<fir::SequenceType>(
- fir::unwrapRefType(info.addr.getType()))) {
+ if (fir::unwrapRefType(info.addr.getType()).isa<fir::SequenceType>()) {
bool dataExvIsAssumedSize =
Fortran::semantics::IsAssumedSizeArray(sym.GetUltimate());
bounds = Fortran::lower::genBaseBoundsOps<mlir::omp::MapBoundsOp,
@@ -1593,7 +1591,7 @@ genTargetOp(Fortran::lower::AbstractConverter &converter,
mlir::omp::VariableCaptureKind::ByRef;
mlir::Type eleType = baseOp.getType();
- if (auto refType = mlir::dyn_cast<fir::ReferenceType>(baseOp.getType()))
+ if (auto refType = baseOp.getType().dyn_cast<fir::ReferenceType>())
eleType = refType.getElementType();
// If a variable is specified in declare target link and if device
diff --git a/flang/lib/Lower/OpenMP/ReductionProcessor.cpp b/flang/lib/Lower/OpenMP/ReductionProcessor.cpp
index 38edd1b4682155..895340549f7c67 100644
--- a/flang/lib/Lower/OpenMP/ReductionProcessor.cpp
+++ b/flang/lib/Lower/OpenMP/ReductionProcessor.cpp
@@ -138,7 +138,7 @@ ReductionProcessor::getReductionInitValue(mlir::Location loc, mlir::Type type,
TODO(loc, "Reduction of some types is not supported");
switch (redId) {
case ReductionIdentifier::MAX: {
- if (auto ty = mlir::dyn_cast<mlir::FloatType>(type)) {
+ if (auto ty = type.dyn_cast<mlir::FloatType>()) {
const llvm::fltSemantics &sem = ty.getFloatSemantics();
return builder.createRealConstant(
loc, type, llvm::APFloat::getLargest(sem, /*Negative=*/true));
@@ -148,7 +148,7 @@ ReductionProcessor::getReductionInitValue(mlir::Location loc, mlir::Type type,
return builder.createIntegerConstant(loc, type, minInt);
}
case ReductionIdentifier::MIN: {
- if (auto ty = mlir::dyn_cast<mlir::FloatType>(type)) {
+ if (auto ty = type.dyn_cast<mlir::FloatType>()) {
const llvm::fltSemantics &sem = ty.getFloatSemantics();
return builder.createRealConstant(
loc, type, llvm::APFloat::getLargest(sem, /*Negative=*/false));
@@ -188,12 +188,12 @@ ReductionProcessor::getReductionInitValue(mlir::Location loc, mlir::Type type,
return fir::factory::Complex{builder, loc}.createComplex(type, initRe,
initIm);
}
- if (mlir::isa<mlir::FloatType>(type))
+ if (type.isa<mlir::FloatType>())
return builder.create<mlir::arith::ConstantOp>(
loc, type,
builder.getFloatAttr(type, (double)getOperationIdentity(redId, loc)));
- if (mlir::isa<fir::LogicalType>(type)) {
+ if (type.isa<fir::LogicalType>()) {
mlir::Value intConst = builder.create<mlir::arith::ConstantOp>(
loc, builder.getI1Type(),
builder.getIntegerAttr(builder.getI1Type(),
@@ -474,11 +474,11 @@ createReductionCleanupRegion(fir::FirOpBuilder &builder, mlir::Location loc,
// like fir::unwrapSeqOrBoxedSeqType except it also works for non-sequence boxes
static mlir::Type unwrapSeqOrBoxedType(mlir::Type ty) {
- if (auto seqTy = mlir::dyn_cast<fir::SequenceType>(ty))
+ if (auto seqTy = ty.dyn_cast<fir::SequenceType>())
return seqTy.getEleTy();
- if (auto boxTy = mlir::dyn_cast<fir::BaseBoxType>(ty)) {
+ if (auto boxTy = ty.dyn_cast<fir::BaseBoxType>()) {
auto eleTy = fir::unwrapRefType(boxTy.getEleTy());
- if (auto seqTy = mlir::dyn_cast<fir::SequenceType>(eleTy))
+ if (auto seqTy = eleTy.dyn_cast<fir::SequenceType>())
return seqTy.getEleTy();
return eleTy;
}
@@ -790,7 +790,7 @@ void ReductionProcessor::addDeclareReduction(
for (mlir::Value symVal : reductionVars) {
auto redType = mlir::cast<fir::ReferenceType>(symVal.getType());
const auto &kindMap = firOpBuilder.getKindMap();
- if (mlir::isa<fir::LogicalType>(redType.getEleTy()))
+ if (redType.getEleTy().isa<fir::LogicalType>())
decl = createDeclareReduction(firOpBuilder,
getReductionName(intrinsicOp, kindMap,
firOpBuilder.getI1Type(),
@@ -816,7 +816,7 @@ void ReductionProcessor::addDeclareReduction(
mlir::Value symVal = converter.getSymbolAddress(*symbol);
if (auto declOp = symVal.getDefiningOp<hlfir::DeclareOp>())
symVal = declOp.getBase();
- auto redType = mlir::cast<fir::ReferenceType>(symVal.getType());
+ auto redType = symVal.getType().cast<fir::ReferenceType>();
if (!redType.getEleTy().isIntOrIndexOrFloat())
TODO(currentLocation, "User Defined Reduction on non-trivial type");
decl = createDeclareReduction(
diff --git a/flang/lib/Lower/VectorSubscripts.cpp b/flang/lib/Lower/VectorSubscripts.cpp
index d7a311d32d59dd..7439b9f7df8fdb 100644
--- a/flang/lib/Lower/VectorSubscripts.cpp
+++ b/flang/lib/Lower/VectorSubscripts.cpp
@@ -105,7 +105,7 @@ class VectorSubscriptBoxBuilder {
}
mlir::Type gen(const Fortran::evaluate::Component &component) {
- auto recTy = mlir::cast<fir::RecordType>(gen(component.base()));
+ auto recTy = gen(component.base()).cast<fir::RecordType>();
const Fortran::semantics::Symbol &componentSymbol =
component.GetLastSymbol();
// Parent components will not be found here, they are not part
diff --git a/flang/lib/Optimizer/Analysis/AliasAnalysis.cpp b/flang/lib/Optimizer/Analysis/AliasAnalysis.cpp
index f723e8f66e3e4b..c403b9effbfac6 100644
--- a/flang/lib/Optimizer/Analysis/AliasAnalysis.cpp
+++ b/flang/lib/Optimizer/Analysis/AliasAnalysis.cpp
@@ -68,7 +68,7 @@ bool AliasAnalysis::Source::isPointerReference(mlir::Type ty) {
if (!eleTy)
return false;
- return fir::isPointerType(eleTy) || mlir::isa<fir::PointerType>(eleTy);
+ return fir::isPointerType(eleTy) || eleTy.isa<fir::PointerType>();
}
bool AliasAnalysis::Source::isTargetOrPointer() const {
@@ -81,7 +81,7 @@ bool AliasAnalysis::Source::isRecordWithPointerComponent() const {
if (!eleTy)
return false;
// TO DO: Look for pointer components
- return mlir::isa<fir::RecordType>(eleTy);
+ return eleTy.isa<fir::RecordType>();
}
AliasResult AliasAnalysis::alias(Value lhs, Value rhs) {
diff --git a/flang/lib/Optimizer/Builder/BoxValue.cpp b/flang/lib/Optimizer/Builder/BoxValue.cpp
index a90ce5570de7d5..361fa59e204037 100644
--- a/flang/lib/Optimizer/Builder/BoxValue.cpp
+++ b/flang/lib/Optimizer/Builder/BoxValue.cpp
@@ -191,7 +191,7 @@ bool fir::MutableBoxValue::verify() const {
mlir::Type type = fir::dyn_cast_ptrEleTy(getAddr().getType());
if (!type)
return false;
- auto box = mlir::dyn_cast<fir::BaseBoxType>(type);
+ auto box = type.dyn_cast<fir::BaseBoxType>();
if (!box)
return false;
// A boxed value always takes a memory reference,
@@ -210,7 +210,7 @@ bool fir::MutableBoxValue::verify() const {
/// Debug verifier for BoxValue ctor. There is no guarantee this will
/// always be called.
bool fir::BoxValue::verify() const {
- if (!mlir::isa<fir::BaseBoxType>(addr.getType()))
+ if (!addr.getType().isa<fir::BaseBoxType>())
return false;
if (!lbounds.empty() && lbounds.size() != rank())
return false;
diff --git a/flang/lib/Optimizer/Builder/Character.cpp b/flang/lib/Optimizer/Builder/Character.cpp
index b7a7453efdb39b..af0786809cc264 100644
--- a/flang/lib/Optimizer/Builder/Character.cpp
+++ b/flang/lib/Optimizer/Builder/Character.cpp
@@ -26,11 +26,11 @@
/// Unwrap all the ref and box types and return the inner element type.
static mlir::Type unwrapBoxAndRef(mlir::Type type) {
- if (auto boxType = mlir::dyn_cast<fir::BoxCharType>(type))
+ if (auto boxType = type.dyn_cast<fir::BoxCharType>())
return boxType.getEleTy();
while (true) {
type = fir::unwrapRefType(type);
- if (auto boxTy = mlir::dyn_cast<fir::BoxType>(type))
+ if (auto boxTy = type.dyn_cast<fir::BoxType>())
type = boxTy.getEleTy();
else
break;
@@ -41,19 +41,19 @@ static mlir::Type unwrapBoxAndRef(mlir::Type type) {
/// Unwrap base fir.char<kind,len> type.
static fir::CharacterType recoverCharacterType(mlir::Type type) {
type = fir::unwrapSequenceType(unwrapBoxAndRef(type));
- if (auto charTy = mlir::dyn_cast<fir::CharacterType>(type))
+ if (auto charTy = type.dyn_cast<fir::CharacterType>())
return charTy;
llvm::report_fatal_error("expected a character type");
}
bool fir::factory::CharacterExprHelper::isCharacterScalar(mlir::Type type) {
type = unwrapBoxAndRef(type);
- return !mlir::isa<fir::SequenceType>(type) && fir::isa_char(type);
+ return !type.isa<fir::SequenceType>() && fir::isa_char(type);
}
bool fir::factory::CharacterExprHelper::isArray(mlir::Type type) {
type = unwrapBoxAndRef(type);
- if (auto seqTy = mlir::dyn_cast<fir::SequenceType>(type))
+ if (auto seqTy = type.dyn_cast<fir::SequenceType>())
return fir::isa_char(seqTy.getEleTy());
return false;
}
@@ -92,8 +92,7 @@ getCompileTimeLength(const fir::CharBoxValue &box) {
/// Detect the precondition that the value `str` does not reside in memory. Such
/// values will have a type `!fir.array<...x!fir.char<N>>` or `!fir.char<N>`.
LLVM_ATTRIBUTE_UNUSED static bool needToMaterialize(mlir::Value str) {
- return mlir::isa<fir::SequenceType>(str.getType()) ||
- fir::isa_char(str.getType());
+ return str.getType().isa<fir::SequenceType>() || fir::isa_char(str.getType());
}
/// This is called only if `str` does not reside in memory. Such a bare string
@@ -104,7 +103,7 @@ fir::factory::CharacterExprHelper::materializeValue(mlir::Value str) {
assert(needToMaterialize(str));
auto ty = str.getType();
assert(isCharacterScalar(ty) && "expected scalar character");
- auto charTy = mlir::dyn_cast<fir::CharacterType>(ty);
+ auto charTy = ty.dyn_cast<fir::CharacterType>();
if (!charTy || charTy.getLen() == fir::CharacterType::unknownLen()) {
LLVM_DEBUG(llvm::dbgs() << "cannot materialize: " << str << '\n');
llvm_unreachable("must be a !fir.char<N> type");
@@ -130,7 +129,7 @@ fir::factory::CharacterExprHelper::toExtendedValue(mlir::Value character,
if (auto eleType = fir::dyn_cast_ptrEleTy(type))
type = eleType;
- if (auto arrayType = mlir::dyn_cast<fir::SequenceType>(type)) {
+ if (auto arrayType = type.dyn_cast<fir::SequenceType>()) {
type = arrayType.getEleTy();
auto indexType = builder.getIndexType();
for (auto extent : arrayType.getShape()) {
@@ -146,10 +145,10 @@ fir::factory::CharacterExprHelper::toExtendedValue(mlir::Value character,
mlir::emitError(loc, "cannot retrieve array extents from type");
}
- if (auto charTy = mlir::dyn_cast<fir::CharacterType>(type)) {
+ if (auto charTy = type.dyn_cast<fir::CharacterType>()) {
if (!resultLen && charTy.getLen() != fir::CharacterType::unknownLen())
resultLen = builder.createIntegerConstant(loc, lenType, charTy.getLen());
- } else if (auto boxCharType = mlir::dyn_cast<fir::BoxCharType>(type)) {
+ } else if (auto boxCharType = type.dyn_cast<fir::BoxCharType>()) {
auto refType = builder.getRefType(boxCharType.getEleTy());
// If the embox is accessible, use its operand to avoid filling
// the generated fir with embox/unbox.
@@ -169,7 +168,7 @@ fir::factory::CharacterExprHelper::toExtendedValue(mlir::Value character,
if (!resultLen) {
resultLen = boxCharLen;
}
- } else if (mlir::isa<fir::BoxType>(type)) {
+ } else if (type.isa<fir::BoxType>()) {
mlir::emitError(loc, "descriptor or derived type not yet handled");
} else {
llvm_unreachable("Cannot translate mlir::Value to character ExtendedValue");
@@ -222,7 +221,7 @@ fir::factory::CharacterExprHelper::createEmbox(const fir::CharBoxValue &box) {
fir::CharBoxValue fir::factory::CharacterExprHelper::toScalarCharacter(
const fir::CharArrayBoxValue &box) {
- if (mlir::isa<fir::PointerType>(box.getBuffer().getType()))
+ if (box.getBuffer().getType().isa<fir::PointerType>())
TODO(loc, "concatenating non contiguous character array into a scalar");
// TODO: add a fast path multiplying new length at compile time if the info is
@@ -656,7 +655,7 @@ fir::factory::CharacterExprHelper::createUnboxChar(mlir::Value boxChar) {
}
bool fir::factory::CharacterExprHelper::isCharacterLiteral(mlir::Type type) {
- if (auto seqType = mlir::dyn_cast<fir::SequenceType>(type))
+ if (auto seqType = type.dyn_cast<fir::SequenceType>())
return (seqType.getShape().size() == 1) &&
fir::isa_char(seqType.getEleTy());
return false;
@@ -729,9 +728,9 @@ mlir::Value fir::factory::CharacterExprHelper::getLength(mlir::Value memref) {
if (charType.hasConstantLen())
return builder.createIntegerConstant(loc, builder.getCharacterLengthType(),
charType.getLen());
- if (mlir::isa<fir::BoxType>(memrefType))
+ if (memrefType.isa<fir::BoxType>())
return readLengthFromBox(memref);
- if (mlir::isa<fir::BoxCharType>(memrefType))
+ if (memrefType.isa<fir::BoxCharType>())
return createUnboxChar(memref).second;
// Length cannot be deduced from memref.
@@ -743,14 +742,14 @@ fir::factory::extractCharacterProcedureTuple(fir::FirOpBuilder &builder,
mlir::Location loc,
mlir::Value tuple,
bool openBoxProc) {
- mlir::TupleType tupleType = mlir::cast<mlir::TupleType>(tuple.getType());
+ mlir::TupleType tupleType = tuple.getType().cast<mlir::TupleType>();
mlir::Value addr = builder.create<fir::ExtractValueOp>(
loc, tupleType.getType(0), tuple,
builder.getArrayAttr(
{builder.getIntegerAttr(builder.getIndexType(), 0)}));
mlir::Value proc = [&]() -> mlir::Value {
if (openBoxProc)
- if (auto addrTy = mlir::dyn_cast<fir::BoxProcType>(addr.getType()))
+ if (auto addrTy = addr.getType().dyn_cast<fir::BoxProcType>())
return builder.create<fir::BoxAddrOp>(loc, addrTy.getEleTy(), addr);
return addr;
}();
@@ -764,7 +763,7 @@ fir::factory::extractCharacterProcedureTuple(fir::FirOpBuilder &builder,
mlir::Value fir::factory::createCharacterProcedureTuple(
fir::FirOpBuilder &builder, mlir::Location loc, mlir::Type argTy,
mlir::Value addr, mlir::Value len) {
- mlir::TupleType tupleType = mlir::cast<mlir::TupleType>(argTy);
+ mlir::TupleType tupleType = argTy.cast<mlir::TupleType>();
addr = builder.createConvert(loc, tupleType.getType(0), addr);
if (len)
len = builder.createConvert(loc, tupleType.getType(1), len);
@@ -867,7 +866,7 @@ fir::factory::convertCharacterKind(fir::FirOpBuilder &builder,
auto kindMap = builder.getKindMap();
mlir::Value boxCharAddr = srcBoxChar.getAddr();
auto fromTy = boxCharAddr.getType();
- if (auto charTy = mlir::dyn_cast<fir::CharacterType>(fromTy)) {
+ if (auto charTy = fromTy.dyn_cast<fir::CharacterType>()) {
// boxchar is a value, not a variable. Turn it into a temporary.
// As a value, it ought to have a constant LEN value.
assert(charTy.hasConstantLen() && "must have constant length");
@@ -876,7 +875,7 @@ fir::factory::convertCharacterKind(fir::FirOpBuilder &builder,
boxCharAddr = tmp;
}
auto fromBits = kindMap.getCharacterBitsize(
- mlir::cast<fir::CharacterType>(fir::unwrapRefType(fromTy)).getFKind());
+ fir::unwrapRefType(fromTy).cast<fir::CharacterType>().getFKind());
auto toBits = kindMap.getCharacterBitsize(toKind);
if (toBits < fromBits) {
// Scale by relative ratio to give a buffer of the same length.
diff --git a/flang/lib/Optimizer/Builder/Complex.cpp b/flang/lib/Optimizer/Builder/Complex.cpp
index cbcd4f850014ea..e97cb306780897 100644
--- a/flang/lib/Optimizer/Builder/Complex.cpp
+++ b/flang/lib/Optimizer/Builder/Complex.cpp
@@ -14,8 +14,7 @@
mlir::Type
fir::factory::Complex::getComplexPartType(mlir::Type complexType) const {
- return builder.getRealType(
- mlir::cast<fir::ComplexType>(complexType).getFKind());
+ return builder.getRealType(complexType.cast<fir::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
index a6da387637264d..a0fbae5b614cc7 100644
--- a/flang/lib/Optimizer/Builder/FIRBuilder.cpp
+++ b/flang/lib/Optimizer/Builder/FIRBuilder.cpp
@@ -90,7 +90,7 @@ fir::FirOpBuilder::getNamedGlobal(mlir::ModuleOp modOp,
}
mlir::Type fir::FirOpBuilder::getRefType(mlir::Type eleTy) {
- assert(!mlir::isa<fir::ReferenceType>(eleTy) && "cannot be a reference type");
+ assert(!eleTy.isa<fir::ReferenceType>() && "cannot be a reference type");
return fir::ReferenceType::get(eleTy);
}
@@ -147,7 +147,7 @@ mlir::Value
fir::FirOpBuilder::createRealConstant(mlir::Location loc, mlir::Type fltTy,
llvm::APFloat::integerPart val) {
auto apf = [&]() -> llvm::APFloat {
- if (auto ty = mlir::dyn_cast<fir::RealType>(fltTy))
+ if (auto ty = fltTy.dyn_cast<fir::RealType>())
return llvm::APFloat(kindMap.getFloatSemantics(ty.getFKind()), val);
if (fltTy.isF16())
return llvm::APFloat(llvm::APFloat::IEEEhalf(), val);
@@ -169,7 +169,7 @@ fir::FirOpBuilder::createRealConstant(mlir::Location loc, mlir::Type fltTy,
mlir::Value fir::FirOpBuilder::createRealConstant(mlir::Location loc,
mlir::Type fltTy,
const llvm::APFloat &value) {
- if (mlir::isa<mlir::FloatType>(fltTy)) {
+ if (fltTy.isa<mlir::FloatType>()) {
auto attr = getFloatAttr(fltTy, value);
return create<mlir::arith::ConstantOp>(loc, fltTy, attr);
}
@@ -178,7 +178,7 @@ mlir::Value fir::FirOpBuilder::createRealConstant(mlir::Location loc,
static llvm::SmallVector<mlir::Value>
elideExtentsAlreadyInType(mlir::Type type, mlir::ValueRange shape) {
- auto arrTy = mlir::dyn_cast<fir::SequenceType>(type);
+ auto arrTy = type.dyn_cast<fir::SequenceType>();
if (shape.empty() || !arrTy)
return {};
// elide the constant dimensions before construction
@@ -195,7 +195,7 @@ static llvm::SmallVector<mlir::Value>
elideLengthsAlreadyInType(mlir::Type type, mlir::ValueRange lenParams) {
if (lenParams.empty())
return {};
- if (auto arrTy = mlir::dyn_cast<fir::SequenceType>(type))
+ if (auto arrTy = type.dyn_cast<fir::SequenceType>())
type = arrTy.getEleTy();
if (fir::hasDynamicSize(type))
return lenParams;
@@ -264,7 +264,7 @@ mlir::Value fir::FirOpBuilder::createTemporaryAlloc(
mlir::Location loc, mlir::Type type, llvm::StringRef name,
mlir::ValueRange lenParams, mlir::ValueRange shape,
llvm::ArrayRef<mlir::NamedAttribute> attrs) {
- assert(!mlir::isa<fir::ReferenceType>(type) && "cannot be a reference");
+ assert(!type.isa<fir::ReferenceType>() && "cannot be a reference");
// If the alloca is inside an OpenMP Op which will be outlined then pin
// the alloca here.
const bool pinned =
@@ -310,7 +310,7 @@ mlir::Value fir::FirOpBuilder::createHeapTemporary(
llvm::SmallVector<mlir::Value> dynamicLength =
elideLengthsAlreadyInType(type, lenParams);
- assert(!mlir::isa<fir::ReferenceType>(type) && "cannot be a reference");
+ assert(!type.isa<fir::ReferenceType>() && "cannot be a reference");
return create<fir::AllocMemOp>(loc, type, /*unique_name=*/llvm::StringRef{},
name, dynamicLength, dynamicShape, attrs);
}
@@ -376,9 +376,8 @@ mlir::Value fir::FirOpBuilder::convertWithSemantics(
// imaginary part is zero
auto eleTy = helper.getComplexPartType(toTy);
auto cast = createConvert(loc, eleTy, val);
- llvm::APFloat zero{kindMap.getFloatSemantics(
- mlir::cast<fir::ComplexType>(toTy).getFKind()),
- 0};
+ llvm::APFloat zero{
+ kindMap.getFloatSemantics(toTy.cast<fir::ComplexType>().getFKind()), 0};
auto imag = createRealConstant(loc, eleTy, zero);
return helper.createComplex(toTy, cast, imag);
}
@@ -389,14 +388,14 @@ mlir::Value fir::FirOpBuilder::convertWithSemantics(
return createConvert(loc, toTy, rp);
}
if (allowCharacterConversion) {
- if (mlir::isa<fir::BoxCharType>(fromTy)) {
+ if (fromTy.isa<fir::BoxCharType>()) {
// Extract the address of the character string and pass it
fir::factory::CharacterExprHelper charHelper{*this, loc};
std::pair<mlir::Value, mlir::Value> unboxchar =
charHelper.createUnboxChar(val);
return createConvert(loc, toTy, unboxchar.first);
}
- if (auto boxType = mlir::dyn_cast<fir::BoxCharType>(toTy)) {
+ if (auto boxType = toTy.dyn_cast<fir::BoxCharType>()) {
// Extract the address of the actual argument and create a boxed
// character value with an undefined length
// TODO: We should really calculate the total size of the actual
@@ -416,10 +415,10 @@ mlir::Value fir::FirOpBuilder::convertWithSemantics(
"element types expected to match"));
return create<fir::BoxAddrOp>(loc, toTy, val);
}
- if (fir::isa_ref_type(fromTy) && mlir::isa<fir::BoxProcType>(toTy)) {
+ if (fir::isa_ref_type(fromTy) && toTy.isa<fir::BoxProcType>()) {
// Call is expecting a boxed procedure, not a reference to other data type.
// Convert the reference to a procedure and embox it.
- mlir::Type procTy = mlir::cast<fir::BoxProcType>(toTy).getEleTy();
+ mlir::Type procTy = toTy.cast<fir::BoxProcType>().getEleTy();
mlir::Value proc = createConvert(loc, procTy, val);
return create<fir::EmboxProcOp>(loc, toTy, proc);
}
@@ -429,7 +428,7 @@ mlir::Value fir::FirOpBuilder::convertWithSemantics(
if (((fir::isPolymorphicType(fromTy) &&
(fir::isAllocatableType(fromTy) || fir::isPointerType(fromTy)) &&
fir::isPolymorphicType(toTy)) ||
- (fir::isPolymorphicType(fromTy) && mlir::isa<fir::BoxType>(toTy))) &&
+ (fir::isPolymorphicType(fromTy) && toTy.isa<fir::BoxType>())) &&
!(fir::isUnlimitedPolymorphicType(fromTy) && fir::isAssumedType(toTy)))
return create<fir::ReboxOp>(loc, toTy, val, mlir::Value{},
/*slice=*/mlir::Value{});
@@ -582,7 +581,7 @@ mlir::Value fir::FirOpBuilder::createBox(mlir::Location loc,
bool isPolymorphic,
bool isAssumedType) {
mlir::Value itemAddr = fir::getBase(exv);
- if (mlir::isa<fir::BaseBoxType>(itemAddr.getType()))
+ if (itemAddr.getType().isa<fir::BaseBoxType>())
return itemAddr;
auto elementType = fir::dyn_cast_ptrEleTy(itemAddr.getType());
if (!elementType) {
@@ -593,7 +592,7 @@ mlir::Value fir::FirOpBuilder::createBox(mlir::Location loc,
mlir::Type boxTy;
mlir::Value tdesc;
// Avoid to wrap a box/class with box/class.
- if (mlir::isa<fir::BaseBoxType>(elementType)) {
+ if (elementType.isa<fir::BaseBoxType>()) {
boxTy = elementType;
} else {
boxTy = fir::BoxType::get(elementType);
@@ -710,7 +709,7 @@ mlir::Value fir::FirOpBuilder::genAbsentOp(mlir::Location loc,
return create<fir::AbsentOp>(loc, argTy);
auto boxProc =
- create<fir::AbsentOp>(loc, mlir::cast<mlir::TupleType>(argTy).getType(0));
+ create<fir::AbsentOp>(loc, argTy.cast<mlir::TupleType>().getType(0));
mlir::Value charLen = create<fir::UndefOp>(loc, getCharacterLengthType());
return fir::factory::createCharacterProcedureTuple(*this, loc, argTy, boxProc,
charLen);
@@ -959,14 +958,14 @@ static llvm::SmallVector<mlir::Value> getFromBox(mlir::Location loc,
fir::FirOpBuilder &builder,
mlir::Type valTy,
mlir::Value boxVal) {
- if (auto boxTy = mlir::dyn_cast<fir::BaseBoxType>(valTy)) {
+ if (auto boxTy = valTy.dyn_cast<fir::BaseBoxType>()) {
auto eleTy = fir::unwrapAllRefAndSeqType(boxTy.getEleTy());
- if (auto recTy = mlir::dyn_cast<fir::RecordType>(eleTy)) {
+ if (auto recTy = eleTy.dyn_cast<fir::RecordType>()) {
if (recTy.getNumLenParams() > 0) {
// Walk each type parameter in the record and get the value.
TODO(loc, "generate code to get LEN type parameters");
}
- } else if (auto charTy = mlir::dyn_cast<fir::CharacterType>(eleTy)) {
+ } else if (auto charTy = eleTy.dyn_cast<fir::CharacterType>()) {
if (charTy.hasDynamicLen()) {
auto idxTy = builder.getIndexType();
auto eleSz = builder.create<fir::BoxEleSizeOp>(loc, idxTy, boxVal);
@@ -1013,7 +1012,7 @@ llvm::SmallVector<mlir::Value>
fir::factory::getTypeParams(mlir::Location loc, fir::FirOpBuilder &builder,
fir::ArrayLoadOp load) {
mlir::Type memTy = load.getMemref().getType();
- if (auto boxTy = mlir::dyn_cast<fir::BaseBoxType>(memTy))
+ if (auto boxTy = memTy.dyn_cast<fir::BaseBoxType>())
return getFromBox(loc, builder, boxTy, load.getMemref());
return load.getTypeparams();
}
@@ -1040,7 +1039,7 @@ std::string fir::factory::uniqueCGIdent(llvm::StringRef prefix,
mlir::Value fir::factory::locationToFilename(fir::FirOpBuilder &builder,
mlir::Location loc) {
- if (auto flc = mlir::dyn_cast<mlir::FileLineColLoc>(loc)) {
+ if (auto flc = loc.dyn_cast<mlir::FileLineColLoc>()) {
// must be encoded as asciiz, C string
auto fn = flc.getFilename().str() + '\0';
return fir::getBase(createStringLiteral(builder, loc, fn));
@@ -1051,7 +1050,7 @@ mlir::Value fir::factory::locationToFilename(fir::FirOpBuilder &builder,
mlir::Value fir::factory::locationToLineNo(fir::FirOpBuilder &builder,
mlir::Location loc,
mlir::Type type) {
- if (auto flc = mlir::dyn_cast<mlir::FileLineColLoc>(loc))
+ if (auto flc = loc.dyn_cast<mlir::FileLineColLoc>())
return builder.createIntegerConstant(loc, type, flc.getLine());
return builder.createIntegerConstant(loc, type, 0);
}
@@ -1109,10 +1108,10 @@ fir::ExtendedValue fir::factory::componentToExtendedValue(
auto fieldTy = component.getType();
if (auto ty = fir::dyn_cast_ptrEleTy(fieldTy))
fieldTy = ty;
- if (mlir::isa<fir::BaseBoxType>(fieldTy)) {
+ if (fieldTy.isa<fir::BaseBoxType>()) {
llvm::SmallVector<mlir::Value> nonDeferredTypeParams;
auto eleTy = fir::unwrapSequenceType(fir::dyn_cast_ptrOrBoxEleTy(fieldTy));
- if (auto charTy = mlir::dyn_cast<fir::CharacterType>(eleTy)) {
+ if (auto charTy = eleTy.dyn_cast<fir::CharacterType>()) {
auto lenTy = builder.getCharacterLengthType();
if (charTy.hasConstantLen())
nonDeferredTypeParams.emplace_back(
@@ -1121,7 +1120,7 @@ fir::ExtendedValue fir::factory::componentToExtendedValue(
// on a PDT length parameter. There is no way to make a
diff erence with
// deferred length here yet.
}
- if (auto recTy = mlir::dyn_cast<fir::RecordType>(eleTy))
+ if (auto recTy = eleTy.dyn_cast<fir::RecordType>())
if (recTy.getNumLenParams() > 0)
TODO(loc, "allocatable and pointer components non deferred length "
"parameters");
@@ -1130,7 +1129,7 @@ fir::ExtendedValue fir::factory::componentToExtendedValue(
/*mutableProperties=*/{});
}
llvm::SmallVector<mlir::Value> extents;
- if (auto seqTy = mlir::dyn_cast<fir::SequenceType>(fieldTy)) {
+ if (auto seqTy = fieldTy.dyn_cast<fir::SequenceType>()) {
fieldTy = seqTy.getEleTy();
auto idxTy = builder.getIndexType();
for (auto extent : seqTy.getShape()) {
@@ -1139,7 +1138,7 @@ fir::ExtendedValue fir::factory::componentToExtendedValue(
extents.emplace_back(builder.createIntegerConstant(loc, idxTy, extent));
}
}
- if (auto charTy = mlir::dyn_cast<fir::CharacterType>(fieldTy)) {
+ if (auto charTy = fieldTy.dyn_cast<fir::CharacterType>()) {
auto cstLen = charTy.getLen();
if (cstLen == fir::CharacterType::unknownLen())
TODO(loc, "get character component length from length type parameters");
@@ -1149,7 +1148,7 @@ fir::ExtendedValue fir::factory::componentToExtendedValue(
return fir::CharArrayBoxValue{component, len, extents};
return fir::CharBoxValue{component, len};
}
- if (auto recordTy = mlir::dyn_cast<fir::RecordType>(fieldTy))
+ if (auto recordTy = fieldTy.dyn_cast<fir::RecordType>())
if (recordTy.getNumLenParams() != 0)
TODO(loc,
"lower component ref that is a derived type with length parameter");
@@ -1212,14 +1211,14 @@ void fir::factory::genScalarAssignment(fir::FirOpBuilder &builder,
assert(lhs.rank() == 0 && rhs.rank() == 0 && "must be scalars");
auto type = fir::unwrapSequenceType(
fir::unwrapPassByRefType(fir::getBase(lhs).getType()));
- if (mlir::isa<fir::CharacterType>(type)) {
+ if (type.isa<fir::CharacterType>()) {
const fir::CharBoxValue *toChar = lhs.getCharBox();
const fir::CharBoxValue *fromChar = rhs.getCharBox();
assert(toChar && fromChar);
fir::factory::CharacterExprHelper helper{builder, loc};
helper.createAssign(fir::ExtendedValue{*toChar},
fir::ExtendedValue{*fromChar});
- } else if (mlir::isa<fir::RecordType>(type)) {
+ } else if (type.isa<fir::RecordType>()) {
fir::factory::genRecordAssignment(builder, loc, lhs, rhs, needFinalization,
isTemporaryLHS);
} else {
@@ -1240,10 +1239,10 @@ static void genComponentByComponentAssignment(fir::FirOpBuilder &builder,
const fir::ExtendedValue &rhs,
bool isTemporaryLHS) {
auto lbaseType = fir::unwrapPassByRefType(fir::getBase(lhs).getType());
- auto lhsType = mlir::dyn_cast<fir::RecordType>(lbaseType);
+ auto lhsType = lbaseType.dyn_cast<fir::RecordType>();
assert(lhsType && "lhs must be a scalar record type");
auto rbaseType = fir::unwrapPassByRefType(fir::getBase(rhs).getType());
- auto rhsType = mlir::dyn_cast<fir::RecordType>(rbaseType);
+ auto rhsType = rbaseType.dyn_cast<fir::RecordType>();
assert(rhsType && "rhs must be a scalar record type");
auto fieldIndexType = fir::FieldType::get(lhsType.getContext());
for (auto [lhsPair, rhsPair] :
@@ -1262,7 +1261,7 @@ static void genComponentByComponentAssignment(fir::FirOpBuilder &builder,
mlir::Value toCoor = builder.create<fir::CoordinateOp>(
loc, fieldRefType, fir::getBase(lhs), field);
std::optional<fir::DoLoopOp> outerLoop;
- if (auto sequenceType = mlir::dyn_cast<fir::SequenceType>(lFieldTy)) {
+ if (auto sequenceType = lFieldTy.dyn_cast<fir::SequenceType>()) {
// Create loops to assign array components elements by elements.
// Note that, since these are components, they either do not overlap,
// or are the same and exactly overlap. They also have compile time
@@ -1289,9 +1288,10 @@ static void genComponentByComponentAssignment(fir::FirOpBuilder &builder,
fromCoor, indices);
}
if (auto fieldEleTy = fir::unwrapSequenceType(lFieldTy);
- mlir::isa<fir::BaseBoxType>(fieldEleTy)) {
- assert(mlir::isa<fir::PointerType>(
- mlir::cast<fir::BaseBoxType>(fieldEleTy).getEleTy()) &&
+ fieldEleTy.isa<fir::BaseBoxType>()) {
+ assert(fieldEleTy.cast<fir::BaseBoxType>()
+ .getEleTy()
+ .isa<fir::PointerType>() &&
"allocatable members require deep copy");
auto fromPointerValue = builder.create<fir::LoadOp>(loc, fromCoor);
auto castTo = builder.createConvert(loc, fieldEleTy, fromPointerValue);
@@ -1320,11 +1320,11 @@ static bool recordTypeCanBeMemCopied(fir::RecordType recordType) {
for (auto [_, fieldType] : recordType.getTypeList()) {
// Derived type component may have user assignment (so far, we cannot tell
// in FIR, so assume it is always the case, TODO: get the actual info).
- if (mlir::isa<fir::RecordType>(fir::unwrapSequenceType(fieldType)))
+ if (fir::unwrapSequenceType(fieldType).isa<fir::RecordType>())
return false;
// Allocatable components need deep copy.
- if (auto boxType = mlir::dyn_cast<fir::BaseBoxType>(fieldType))
- if (mlir::isa<fir::HeapType>(boxType.getEleTy()))
+ if (auto boxType = fieldType.dyn_cast<fir::BaseBoxType>())
+ if (boxType.getEleTy().isa<fir::HeapType>())
return false;
}
// Constant size components without user defined assignment and pointers can
@@ -1353,10 +1353,9 @@ void fir::factory::genRecordAssignment(fir::FirOpBuilder &builder,
// Box operands may be polymorphic, it is not entirely clear from 10.2.1.3
// if the assignment is performed on the dynamic of declared type. Use the
// runtime assuming it is performed on the dynamic type.
- bool hasBoxOperands =
- mlir::isa<fir::BaseBoxType>(fir::getBase(lhs).getType()) ||
- mlir::isa<fir::BaseBoxType>(fir::getBase(rhs).getType());
- auto recTy = mlir::dyn_cast<fir::RecordType>(baseTy);
+ bool hasBoxOperands = fir::getBase(lhs).getType().isa<fir::BaseBoxType>() ||
+ fir::getBase(rhs).getType().isa<fir::BaseBoxType>();
+ auto recTy = baseTy.dyn_cast<fir::RecordType>();
assert(recTy && "must be a record type");
if ((needFinalization && mayHaveFinalizer(recTy, builder)) ||
hasBoxOperands || !recordTypeCanBeMemCopied(recTy)) {
@@ -1402,7 +1401,7 @@ mlir::Value fir::factory::genLenOfCharacter(
llvm::ArrayRef<mlir::Value> path, llvm::ArrayRef<mlir::Value> substring) {
llvm::SmallVector<mlir::Value> typeParams(arrLoad.getTypeparams());
return genLenOfCharacter(builder, loc,
- mlir::cast<fir::SequenceType>(arrLoad.getType()),
+ arrLoad.getType().cast<fir::SequenceType>(),
arrLoad.getMemref(), typeParams, path, substring);
}
@@ -1430,7 +1429,7 @@ mlir::Value fir::factory::genLenOfCharacter(
lower = builder.createConvert(loc, idxTy, substring.front());
auto eleTy = fir::applyPathToType(seqTy, path);
if (!fir::hasDynamicSize(eleTy)) {
- if (auto charTy = mlir::dyn_cast<fir::CharacterType>(eleTy)) {
+ if (auto charTy = eleTy.dyn_cast<fir::CharacterType>()) {
// Use LEN from the type.
return builder.createIntegerConstant(loc, idxTy, charTy.getLen());
}
@@ -1439,9 +1438,9 @@ mlir::Value fir::factory::genLenOfCharacter(
"application of path did not result in a !fir.char");
}
if (fir::isa_box_type(memref.getType())) {
- if (mlir::isa<fir::BoxCharType>(memref.getType()))
+ if (memref.getType().isa<fir::BoxCharType>())
return builder.create<fir::BoxCharLenOp>(loc, idxTy, memref);
- if (mlir::isa<fir::BoxType>(memref.getType()))
+ if (memref.getType().isa<fir::BoxType>())
return CharacterExprHelper(builder, loc).readLengthFromBox(memref);
fir::emitFatalError(loc, "memref has wrong type");
}
@@ -1458,7 +1457,7 @@ mlir::Value fir::factory::genLenOfCharacter(
mlir::Value fir::factory::createZeroValue(fir::FirOpBuilder &builder,
mlir::Location loc, mlir::Type type) {
mlir::Type i1 = builder.getIntegerType(1);
- if (mlir::isa<fir::LogicalType>(type) || type == i1)
+ if (type.isa<fir::LogicalType>() || type == i1)
return builder.createConvert(loc, type, builder.createBool(loc, false));
if (fir::isa_integer(type))
return builder.createIntegerConstant(loc, type, 0);
@@ -1508,7 +1507,7 @@ mlir::Value fir::factory::genMaxWithZero(fir::FirOpBuilder &builder,
mlir::Value zero = builder.createIntegerConstant(loc, value.getType(), 0);
if (mlir::Operation *definingOp = value.getDefiningOp())
if (auto cst = mlir::dyn_cast<mlir::arith::ConstantOp>(definingOp))
- if (auto intAttr = mlir::dyn_cast<mlir::IntegerAttr>(cst.getValue()))
+ if (auto intAttr = cst.getValue().dyn_cast<mlir::IntegerAttr>())
return intAttr.getInt() > 0 ? value : zero;
mlir::Value valueIsGreater = builder.create<mlir::arith::CmpIOp>(
loc, mlir::arith::CmpIPredicate::sgt, value, zero);
@@ -1520,8 +1519,8 @@ mlir::Value fir::factory::genCPtrOrCFunptrAddr(fir::FirOpBuilder &builder,
mlir::Location loc,
mlir::Value cPtr,
mlir::Type ty) {
- assert(mlir::isa<fir::RecordType>(ty));
- auto recTy = mlir::dyn_cast<fir::RecordType>(ty);
+ assert(ty.isa<fir::RecordType>());
+ auto recTy = ty.dyn_cast<fir::RecordType>();
assert(recTy.getTypeList().size() == 1);
auto fieldName = recTy.getTypeList()[0].first;
mlir::Type fieldTy = recTy.getTypeList()[0].second;
@@ -1583,7 +1582,7 @@ mlir::Value fir::factory::genCPtrOrCFunptrValue(fir::FirOpBuilder &builder,
mlir::Value fir::factory::createNullBoxProc(fir::FirOpBuilder &builder,
mlir::Location loc,
mlir::Type boxType) {
- auto boxTy{mlir::dyn_cast<fir::BoxProcType>(boxType)};
+ auto boxTy{boxType.dyn_cast<fir::BoxProcType>()};
if (!boxTy)
fir::emitFatalError(loc, "Procedure pointer must be of BoxProcType");
auto boxEleTy{fir::unwrapRefType(boxTy.getEleTy())};
diff --git a/flang/lib/Optimizer/Builder/HLFIRTools.cpp b/flang/lib/Optimizer/Builder/HLFIRTools.cpp
index 44779427ab557a..db638ceb40700b 100644
--- a/flang/lib/Optimizer/Builder/HLFIRTools.cpp
+++ b/flang/lib/Optimizer/Builder/HLFIRTools.cpp
@@ -38,10 +38,10 @@ hlfir::getExplicitExtentsFromShape(mlir::Value shape,
} else if (mlir::dyn_cast_or_null<fir::ShiftOp>(shapeOp)) {
return {};
} else if (auto s = mlir::dyn_cast_or_null<hlfir::ShapeOfOp>(shapeOp)) {
- hlfir::ExprType expr = mlir::cast<hlfir::ExprType>(s.getExpr().getType());
+ hlfir::ExprType expr = s.getExpr().getType().cast<hlfir::ExprType>();
llvm::ArrayRef<int64_t> exprShape = expr.getShape();
mlir::Type indexTy = builder.getIndexType();
- fir::ShapeType shapeTy = mlir::cast<fir::ShapeType>(shape.getType());
+ fir::ShapeType shapeTy = shape.getType().cast<fir::ShapeType>();
result.reserve(shapeTy.getRank());
for (unsigned i = 0; i < shapeTy.getRank(); ++i) {
int64_t extent = exprShape[i];
@@ -99,7 +99,7 @@ genLboundsAndExtentsFromBox(mlir::Location loc, fir::FirOpBuilder &builder,
hlfir::Entity boxEntity,
llvm::SmallVectorImpl<mlir::Value> &lbounds,
llvm::SmallVectorImpl<mlir::Value> *extents) {
- assert(mlir::isa<fir::BaseBoxType>(boxEntity.getType()) && "must be a box");
+ assert(boxEntity.getType().isa<fir::BaseBoxType>() && "must be a box");
mlir::Type idxTy = builder.getIndexType();
const int rank = boxEntity.getRank();
for (int i = 0; i < rank; ++i) {
@@ -154,7 +154,7 @@ static mlir::Value genCharacterVariableLength(mlir::Location loc,
hlfir::Entity var) {
if (mlir::Value len = tryGettingNonDeferredCharLen(var))
return len;
- auto charType = mlir::cast<fir::CharacterType>(var.getFortranElementType());
+ auto charType = var.getFortranElementType().cast<fir::CharacterType>();
if (charType.hasConstantLen())
return builder.createIntegerConstant(loc, builder.getIndexType(),
charType.getLen());
@@ -172,7 +172,7 @@ static fir::CharBoxValue genUnboxChar(mlir::Location loc,
if (auto emboxChar = boxChar.getDefiningOp<fir::EmboxCharOp>())
return {emboxChar.getMemref(), emboxChar.getLen()};
mlir::Type refType = fir::ReferenceType::get(
- mlir::cast<fir::BoxCharType>(boxChar.getType()).getEleTy());
+ boxChar.getType().cast<fir::BoxCharType>().getEleTy());
auto unboxed = builder.create<fir::UnboxCharOp>(
loc, refType, builder.getIndexType(), boxChar);
mlir::Value addr = unboxed.getResult(0);
@@ -252,8 +252,8 @@ hlfir::genAssociateExpr(mlir::Location loc, fir::FirOpBuilder &builder,
// and the other static).
mlir::Type varEleTy = getFortranElementType(variableType);
mlir::Type valueEleTy = getFortranElementType(value.getType());
- if (varEleTy != valueEleTy && !(mlir::isa<fir::CharacterType>(valueEleTy) &&
- mlir::isa<fir::CharacterType>(varEleTy))) {
+ if (varEleTy != valueEleTy && !(valueEleTy.isa<fir::CharacterType>() &&
+ varEleTy.isa<fir::CharacterType>())) {
assert(value.isScalar() && fir::isa_trivial(value.getType()));
source = builder.createConvert(loc, fir::unwrapPassByRefType(variableType),
value);
@@ -278,9 +278,9 @@ mlir::Value hlfir::genVariableRawAddress(mlir::Location loc,
if (var.isMutableBox())
baseAddr = builder.create<fir::LoadOp>(loc, baseAddr);
// Get raw address.
- if (mlir::isa<fir::BoxCharType>(var.getType()))
+ if (var.getType().isa<fir::BoxCharType>())
baseAddr = genUnboxChar(loc, builder, var.getBase()).getAddr();
- if (mlir::isa<fir::BaseBoxType>(baseAddr.getType()))
+ if (baseAddr.getType().isa<fir::BaseBoxType>())
baseAddr = builder.create<fir::BoxAddrOp>(loc, baseAddr);
return baseAddr;
}
@@ -289,13 +289,13 @@ mlir::Value hlfir::genVariableBoxChar(mlir::Location loc,
fir::FirOpBuilder &builder,
hlfir::Entity var) {
assert(var.isVariable() && "only address of variables can be taken");
- if (mlir::isa<fir::BoxCharType>(var.getType()))
+ if (var.getType().isa<fir::BoxCharType>())
return var;
mlir::Value addr = genVariableRawAddress(loc, builder, var);
llvm::SmallVector<mlir::Value> lengths;
genLengthParameters(loc, builder, var, lengths);
assert(lengths.size() == 1);
- auto charType = mlir::cast<fir::CharacterType>(var.getFortranElementType());
+ auto charType = var.getFortranElementType().cast<fir::CharacterType>();
auto boxCharType =
fir::BoxCharType::get(builder.getContext(), charType.getFKind());
auto scalarAddr =
@@ -309,7 +309,7 @@ hlfir::Entity hlfir::genVariableBox(mlir::Location loc,
hlfir::Entity var) {
assert(var.isVariable() && "must be a variable");
var = hlfir::derefPointersAndAllocatables(loc, builder, var);
- if (mlir::isa<fir::BaseBoxType>(var.getType()))
+ if (var.getType().isa<fir::BaseBoxType>())
return var;
// Note: if the var is not a fir.box/fir.class at that point, it has default
// lower bounds and is not polymorphic.
@@ -317,11 +317,11 @@ hlfir::Entity hlfir::genVariableBox(mlir::Location loc,
var.isArray() ? hlfir::genShape(loc, builder, var) : mlir::Value{};
llvm::SmallVector<mlir::Value> typeParams;
auto maybeCharType =
- mlir::dyn_cast<fir::CharacterType>(var.getFortranElementType());
+ var.getFortranElementType().dyn_cast<fir::CharacterType>();
if (!maybeCharType || maybeCharType.hasDynamicLen())
hlfir::genLengthParameters(loc, builder, var, typeParams);
mlir::Value addr = var.getBase();
- if (mlir::isa<fir::BoxCharType>(var.getType()))
+ if (var.getType().isa<fir::BoxCharType>())
addr = genVariableRawAddress(loc, builder, var);
mlir::Type boxType = fir::BoxType::get(var.getElementOrSequenceType());
auto embox =
@@ -348,7 +348,7 @@ hlfir::Entity hlfir::getElementAt(mlir::Location loc,
return entity;
llvm::SmallVector<mlir::Value> lenParams;
genLengthParameters(loc, builder, entity, lenParams);
- if (mlir::isa<hlfir::ExprType>(entity.getType()))
+ if (entity.getType().isa<hlfir::ExprType>())
return hlfir::Entity{builder.create<hlfir::ApplyOp>(
loc, entity, oneBasedIndices, lenParams)};
// Build hlfir.designate. The lower bounds may need to be added to
@@ -394,7 +394,7 @@ static mlir::Value genUBound(mlir::Location loc, fir::FirOpBuilder &builder,
llvm::SmallVector<std::pair<mlir::Value, mlir::Value>>
hlfir::genBounds(mlir::Location loc, fir::FirOpBuilder &builder,
Entity entity) {
- if (mlir::isa<hlfir::ExprType>(entity.getType()))
+ if (entity.getType().isa<hlfir::ExprType>())
TODO(loc, "bounds of expressions in hlfir");
auto [exv, cleanup] = translateToExtendedValue(loc, builder, entity);
assert(!cleanup && "translation of entity should not yield cleanup");
@@ -415,8 +415,8 @@ hlfir::genBounds(mlir::Location loc, fir::FirOpBuilder &builder,
llvm::SmallVector<std::pair<mlir::Value, mlir::Value>>
hlfir::genBounds(mlir::Location loc, fir::FirOpBuilder &builder,
mlir::Value shape) {
- assert((mlir::isa<fir::ShapeShiftType>(shape.getType()) ||
- mlir::isa<fir::ShapeType>(shape.getType())) &&
+ assert((shape.getType().isa<fir::ShapeShiftType>() ||
+ shape.getType().isa<fir::ShapeType>()) &&
"shape must contain extents");
auto extents = hlfir::getExplicitExtentsFromShape(shape, builder);
auto lowers = getExplicitLboundsFromShape(shape);
@@ -474,7 +474,7 @@ static mlir::Value computeVariableExtent(mlir::Location loc,
if (typeExtent != fir::SequenceType::getUnknownExtent())
return builder.createIntegerConstant(loc, idxTy, typeExtent);
}
- assert(mlir::isa<fir::BaseBoxType>(variable.getType()) &&
+ assert(variable.getType().isa<fir::BaseBoxType>() &&
"array variable with dynamic extent must be boxed");
mlir::Value dimVal = builder.createIntegerConstant(loc, idxTy, dim);
auto dimInfo = builder.create<fir::BoxDimsOp>(loc, idxTy, idxTy, idxTy,
@@ -496,8 +496,9 @@ llvm::SmallVector<mlir::Value> getVariableExtents(mlir::Location loc,
variable = hlfir::derefPointersAndAllocatables(loc, builder, variable);
// Use the type shape information, and/or the fir.box/fir.class shape
// information if any extents are not static.
- fir::SequenceType seqTy = mlir::cast<fir::SequenceType>(
- hlfir::getFortranElementOrSequenceType(variable.getType()));
+ fir::SequenceType seqTy =
+ hlfir::getFortranElementOrSequenceType(variable.getType())
+ .cast<fir::SequenceType>();
unsigned rank = seqTy.getShape().size();
for (unsigned dim = 0; dim < rank; ++dim)
extents.push_back(
@@ -506,7 +507,7 @@ llvm::SmallVector<mlir::Value> getVariableExtents(mlir::Location loc,
}
static mlir::Value tryRetrievingShapeOrShift(hlfir::Entity entity) {
- if (mlir::isa<hlfir::ExprType>(entity.getType())) {
+ if (entity.getType().isa<hlfir::ExprType>()) {
if (auto elemental = entity.getDefiningOp<hlfir::ElementalOp>())
return elemental.getShape();
return mlir::Value{};
@@ -522,13 +523,13 @@ mlir::Value hlfir::genShape(mlir::Location loc, fir::FirOpBuilder &builder,
entity = followShapeInducingSource(entity);
assert(entity && "what?");
if (auto shape = tryRetrievingShapeOrShift(entity)) {
- if (mlir::isa<fir::ShapeType>(shape.getType()))
+ if (shape.getType().isa<fir::ShapeType>())
return shape;
- if (mlir::isa<fir::ShapeShiftType>(shape.getType()))
+ if (shape.getType().isa<fir::ShapeShiftType>())
if (auto s = shape.getDefiningOp<fir::ShapeShiftOp>())
return builder.create<fir::ShapeOp>(loc, s.getExtents());
}
- if (mlir::isa<hlfir::ExprType>(entity.getType()))
+ if (entity.getType().isa<hlfir::ExprType>())
return builder.create<hlfir::ShapeOfOp>(loc, entity.getBase());
// There is no shape lying around for this entity. Retrieve the extents and
// build a new fir.shape.
@@ -562,8 +563,9 @@ mlir::Value hlfir::genExtent(mlir::Location loc, fir::FirOpBuilder &builder,
entity = hlfir::derefPointersAndAllocatables(loc, builder, entity);
// Use the type shape information, and/or the fir.box/fir.class shape
// information if any extents are not static.
- fir::SequenceType seqTy = mlir::cast<fir::SequenceType>(
- hlfir::getFortranElementOrSequenceType(entity.getType()));
+ fir::SequenceType seqTy =
+ hlfir::getFortranElementOrSequenceType(entity.getType())
+ .cast<fir::SequenceType>();
return computeVariableExtent(loc, builder, entity, seqTy, dim);
}
TODO(loc, "get extent from HLFIR expr without producer holding the shape");
@@ -582,7 +584,7 @@ mlir::Value hlfir::genLBound(mlir::Location loc, fir::FirOpBuilder &builder,
}
if (entity.isMutableBox())
entity = hlfir::derefPointersAndAllocatables(loc, builder, entity);
- assert(mlir::isa<fir::BaseBoxType>(entity.getType()) && "must be a box");
+ assert(entity.getType().isa<fir::BaseBoxType>() && "must be a box");
mlir::Type idxTy = builder.getIndexType();
mlir::Value dimVal = builder.createIntegerConstant(loc, idxTy, dim);
auto dimInfo =
@@ -595,7 +597,7 @@ void hlfir::genLengthParameters(mlir::Location loc, fir::FirOpBuilder &builder,
llvm::SmallVectorImpl<mlir::Value> &result) {
if (!entity.hasLengthParameters())
return;
- if (mlir::isa<hlfir::ExprType>(entity.getType())) {
+ if (entity.getType().isa<hlfir::ExprType>()) {
mlir::Value expr = entity;
if (auto reassoc = expr.getDefiningOp<hlfir::NoReassocOp>())
expr = reassoc.getVal();
@@ -652,8 +654,8 @@ static mlir::Value asEmboxShape(mlir::Location loc, fir::FirOpBuilder &builder,
// fir.shape_shift) since this information is already in the input fir.box,
// it only accepts fir.shift because local lower bounds may not be reflected
// in the fir.box.
- if (mlir::isa<fir::BaseBoxType>(fir::getBase(exv).getType()) &&
- !mlir::isa<fir::ShiftType>(shape.getType()))
+ if (fir::getBase(exv).getType().isa<fir::BaseBoxType>() &&
+ !shape.getType().isa<fir::ShiftType>())
return builder.createShape(loc, exv);
return shape;
}
@@ -684,7 +686,7 @@ hlfir::Entity hlfir::derefPointersAndAllocatables(mlir::Location loc,
if (!entity.isPolymorphic() && !entity.hasLengthParameters())
return hlfir::Entity{builder.create<fir::BoxAddrOp>(loc, boxLoad)};
mlir::Type elementType = boxLoad.getFortranElementType();
- if (auto charType = mlir::dyn_cast<fir::CharacterType>(elementType)) {
+ if (auto charType = elementType.dyn_cast<fir::CharacterType>()) {
mlir::Value base = builder.create<fir::BoxAddrOp>(loc, boxLoad);
if (charType.hasConstantLen())
return hlfir::Entity{base};
@@ -714,7 +716,7 @@ mlir::Type hlfir::getVariableElementType(hlfir::Entity variable) {
mlir::Type eleTy = variable.getFortranElementType();
if (variable.isPolymorphic())
return fir::ClassType::get(eleTy);
- if (auto charType = mlir::dyn_cast<fir::CharacterType>(eleTy)) {
+ if (auto charType = eleTy.dyn_cast<fir::CharacterType>()) {
if (charType.hasDynamicLen())
return fir::BoxCharType::get(charType.getContext(), charType.getFKind());
} else if (fir::isRecordWithTypeParameters(eleTy)) {
@@ -735,7 +737,7 @@ mlir::Type hlfir::getEntityElementType(hlfir::Entity entity) {
static hlfir::ExprType getArrayExprType(mlir::Type elementType,
mlir::Value shape, bool isPolymorphic) {
- unsigned rank = mlir::cast<fir::ShapeType>(shape.getType()).getRank();
+ unsigned rank = shape.getType().cast<fir::ShapeType>().getRank();
hlfir::ExprType::Shape typeShape(rank, hlfir::ExprType::getUnknownExtent());
if (auto shapeOp = shape.getDefiningOp<fir::ShapeOp>())
for (auto extent : llvm::enumerate(shapeOp.getExtents()))
@@ -857,7 +859,7 @@ translateVariableToExtendedValue(mlir::Location loc, fir::FirOpBuilder &builder,
return fir::MutableBoxValue(base, getExplicitTypeParams(variable),
fir::MutableProperties{});
- if (mlir::isa<fir::BaseBoxType>(base.getType())) {
+ if (base.getType().isa<fir::BaseBoxType>()) {
if (!variable.isSimplyContiguous() || variable.isPolymorphic() ||
variable.isDerivedWithLengthParameters() || variable.isOptional()) {
llvm::SmallVector<mlir::Value> nonDefaultLbounds =
@@ -872,7 +874,7 @@ translateVariableToExtendedValue(mlir::Location loc, fir::FirOpBuilder &builder,
if (variable.isScalar()) {
if (variable.isCharacter()) {
- if (mlir::isa<fir::BoxCharType>(base.getType()))
+ if (base.getType().isa<fir::BoxCharType>())
return genUnboxChar(loc, builder, base);
mlir::Value len = genCharacterVariableLength(loc, builder, variable);
return fir::CharBoxValue{base, len};
@@ -881,7 +883,7 @@ translateVariableToExtendedValue(mlir::Location loc, fir::FirOpBuilder &builder,
}
llvm::SmallVector<mlir::Value> extents;
llvm::SmallVector<mlir::Value> nonDefaultLbounds;
- if (mlir::isa<fir::BaseBoxType>(variable.getType()) &&
+ if (variable.getType().isa<fir::BaseBoxType>() &&
!variable.getIfVariableInterface()) {
// This special case avoids generating two sets of identical
// fir.box_dim to get both the lower bounds and extents.
@@ -921,7 +923,7 @@ hlfir::translateToExtendedValue(mlir::Location loc, fir::FirOpBuilder &builder,
return {static_cast<mlir::Value>(entity), std::nullopt};
}
- if (mlir::isa<hlfir::ExprType>(entity.getType())) {
+ if (entity.getType().isa<hlfir::ExprType>()) {
mlir::NamedAttribute byRefAttr = fir::getAdaptToByRefAttr(builder);
hlfir::AssociateOp associate = hlfir::genAssociateExpr(
loc, builder, entity, entity.getType(), "", byRefAttr);
diff --git a/flang/lib/Optimizer/Builder/IntrinsicCall.cpp b/flang/lib/Optimizer/Builder/IntrinsicCall.cpp
index 9d72e76e2369d0..e28d14cd318d36 100644
--- a/flang/lib/Optimizer/Builder/IntrinsicCall.cpp
+++ b/flang/lib/Optimizer/Builder/IntrinsicCall.cpp
@@ -786,7 +786,7 @@ mlir::Value genLibSplitComplexArgsCall(fir::FirOpBuilder &builder,
auto getSplitComplexArgsType = [&builder, &args]() -> mlir::FunctionType {
mlir::Type ctype = args[0].getType();
- auto fKind = mlir::cast<fir::ComplexType>(ctype).getFKind();
+ auto fKind = ctype.cast<fir::ComplexType>().getFKind();
mlir::Type ftype;
if (fKind == 2)
@@ -894,8 +894,8 @@ mlir::Value genComplexMathOp(fir::FirOpBuilder &builder, mlir::Location loc,
LLVM_DEBUG(llvm::dbgs() << "Generating '" << mathLibFuncName
<< "' operation with type ";
mathLibFuncType.dump(); llvm::dbgs() << "\n");
- auto type = mlir::cast<fir::ComplexType>(mathLibFuncType.getInput(0));
- auto kind = mlir::cast<fir::RealType>(type.getElementType()).getFKind();
+ auto type = mathLibFuncType.getInput(0).cast<fir::ComplexType>();
+ auto kind = type.getElementType().cast<fir::RealType>().getFKind();
auto realTy = builder.getRealType(kind);
auto mComplexTy = mlir::ComplexType::get(realTy);
@@ -1394,14 +1394,14 @@ class FunctionDistance {
// Floating point can be mlir::FloatType or fir::real
static unsigned getFloatingPointWidth(mlir::Type t) {
- if (auto f{mlir::dyn_cast<mlir::FloatType>(t)})
+ if (auto f{t.dyn_cast<mlir::FloatType>()})
return f.getWidth();
// FIXME: Get width another way for fir.real/complex
// - use fir/KindMapping.h and llvm::Type
// - or use evaluate/type.h
- if (auto r{mlir::dyn_cast<fir::RealType>(t)})
+ if (auto r{t.dyn_cast<fir::RealType>()})
return r.getFKind() * 4;
- if (auto cplx{mlir::dyn_cast<fir::ComplexType>(t)})
+ if (auto cplx{t.dyn_cast<fir::ComplexType>()})
return cplx.getFKind() * 4;
llvm_unreachable("not a floating-point type");
}
@@ -1410,8 +1410,8 @@ class FunctionDistance {
if (from == to)
return Conversion::None;
- if (auto fromIntTy{mlir::dyn_cast<mlir::IntegerType>(from)}) {
- if (auto toIntTy{mlir::dyn_cast<mlir::IntegerType>(to)}) {
+ if (auto fromIntTy{from.dyn_cast<mlir::IntegerType>()}) {
+ if (auto toIntTy{to.dyn_cast<mlir::IntegerType>()}) {
return fromIntTy.getWidth() > toIntTy.getWidth() ? Conversion::Narrow
: Conversion::Extend;
}
@@ -1423,8 +1423,8 @@ class FunctionDistance {
: Conversion::Extend;
}
- if (auto fromCplxTy{mlir::dyn_cast<fir::ComplexType>(from)}) {
- if (auto toCplxTy{mlir::dyn_cast<fir::ComplexType>(to)}) {
+ if (auto fromCplxTy{from.dyn_cast<fir::ComplexType>()}) {
+ if (auto toCplxTy{to.dyn_cast<fir::ComplexType>()}) {
return getFloatingPointWidth(fromCplxTy) >
getFloatingPointWidth(toCplxTy)
? Conversion::Narrow
@@ -1550,10 +1550,10 @@ fir::ExtendedValue toExtendedValue(mlir::Value val, fir::FirOpBuilder &builder,
if (charHelper.isCharacterScalar(type))
return charHelper.toExtendedValue(val);
- if (auto refType = mlir::dyn_cast<fir::ReferenceType>(type))
+ if (auto refType = type.dyn_cast<fir::ReferenceType>())
type = refType.getEleTy();
- if (auto arrayType = mlir::dyn_cast<fir::SequenceType>(type)) {
+ if (auto arrayType = type.dyn_cast<fir::SequenceType>()) {
type = arrayType.getEleTy();
for (fir::SequenceType::Extent extent : arrayType.getShape()) {
if (extent == fir::SequenceType::getUnknownExtent())
@@ -1566,8 +1566,7 @@ fir::ExtendedValue toExtendedValue(mlir::Value val, fir::FirOpBuilder &builder,
// have been used in the interface).
if (extents.size() + 1 < arrayType.getShape().size())
mlir::emitError(loc, "cannot retrieve array extents from type");
- } else if (mlir::isa<fir::BoxType>(type) ||
- mlir::isa<fir::RecordType>(type)) {
+ } else if (type.isa<fir::BoxType>() || type.isa<fir::RecordType>()) {
fir::emitFatalError(loc, "not yet implemented: descriptor or derived type");
}
@@ -1581,10 +1580,10 @@ mlir::Value toValue(const fir::ExtendedValue &val, fir::FirOpBuilder &builder,
if (const fir::CharBoxValue *charBox = val.getCharBox()) {
mlir::Value buffer = charBox->getBuffer();
auto buffTy = buffer.getType();
- if (mlir::isa<mlir::FunctionType>(buffTy))
+ if (buffTy.isa<mlir::FunctionType>())
fir::emitFatalError(
loc, "A character's buffer type cannot be a function type.");
- if (mlir::isa<fir::BoxCharType>(buffTy))
+ if (buffTy.isa<fir::BoxCharType>())
return buffer;
return fir::factory::CharacterExprHelper{builder, loc}.createEmboxChar(
buffer, charBox->getLen());
@@ -1828,27 +1827,27 @@ IntrinsicLibrary::invokeGenerator(SubroutineGenerator generator,
/// Note: mlir has Type::dump(ostream) methods but it may add "!" that is not
/// suitable for function names.
static std::string typeToString(mlir::Type t) {
- if (auto refT{mlir::dyn_cast<fir::ReferenceType>(t)})
+ if (auto refT{t.dyn_cast<fir::ReferenceType>()})
return "ref_" + typeToString(refT.getEleTy());
- if (auto i{mlir::dyn_cast<mlir::IntegerType>(t)}) {
+ if (auto i{t.dyn_cast<mlir::IntegerType>()}) {
return "i" + std::to_string(i.getWidth());
}
- if (auto cplx{mlir::dyn_cast<fir::ComplexType>(t)}) {
+ if (auto cplx{t.dyn_cast<fir::ComplexType>()}) {
return "z" + std::to_string(cplx.getFKind());
}
- if (auto real{mlir::dyn_cast<fir::RealType>(t)}) {
+ if (auto real{t.dyn_cast<fir::RealType>()}) {
return "r" + std::to_string(real.getFKind());
}
- if (auto f{mlir::dyn_cast<mlir::FloatType>(t)}) {
+ if (auto f{t.dyn_cast<mlir::FloatType>()}) {
return "f" + std::to_string(f.getWidth());
}
- if (auto logical{mlir::dyn_cast<fir::LogicalType>(t)}) {
+ if (auto logical{t.dyn_cast<fir::LogicalType>()}) {
return "l" + std::to_string(logical.getFKind());
}
- if (auto character{mlir::dyn_cast<fir::CharacterType>(t)}) {
+ if (auto character{t.dyn_cast<fir::CharacterType>()}) {
return "c" + std::to_string(character.getFKind());
}
- if (auto boxCharacter{mlir::dyn_cast<fir::BoxCharType>(t)}) {
+ if (auto boxCharacter{t.dyn_cast<fir::BoxCharType>()}) {
return "bc" + std::to_string(boxCharacter.getEleTy().getFKind());
}
llvm_unreachable("no mangling for type");
@@ -1908,7 +1907,7 @@ mlir::func::FuncOp IntrinsicLibrary::getWrapper(GeneratorType generator,
mlir::Location localLoc = localBuilder->getUnknownLoc();
llvm::SmallVector<mlir::Value> localArguments;
for (mlir::BlockArgument bArg : function.front().getArguments()) {
- auto refType = mlir::dyn_cast<fir::ReferenceType>(bArg.getType());
+ auto refType = bArg.getType().dyn_cast<fir::ReferenceType>();
if (loadRefArguments && refType) {
auto loaded = localBuilder->create<fir::LoadOp>(localLoc, bArg);
localArguments.push_back(loaded);
@@ -2061,7 +2060,7 @@ mlir::SymbolRefAttr IntrinsicLibrary::getUnrestrictedIntrinsicSymbolRefAttr(
if (!funcOp) {
llvm::SmallVector<mlir::Type> argTypes;
for (mlir::Type type : signature.getInputs()) {
- if (auto refType = mlir::dyn_cast<fir::ReferenceType>(type))
+ if (auto refType = type.dyn_cast<fir::ReferenceType>())
argTypes.push_back(refType.getEleTy());
else
argTypes.push_back(type);
@@ -2146,7 +2145,7 @@ mlir::Value IntrinsicLibrary::genAbs(mlir::Type resultType,
// math::AbsFOp but it does not support all fir floating point types.
return genRuntimeCall("abs", resultType, args);
}
- if (auto intType = mlir::dyn_cast<mlir::IntegerType>(type)) {
+ if (auto intType = type.dyn_cast<mlir::IntegerType>()) {
// At the time of this implementation there is no abs op in mlir.
// So, implement abs here without branching.
mlir::Value shift =
@@ -2380,8 +2379,8 @@ IntrinsicLibrary::genAssociated(mlir::Type resultType,
llvm::ArrayRef<fir::ExtendedValue> args) {
assert(args.size() == 2);
mlir::Type ptrTy = fir::getBase(args[0]).getType();
- if (ptrTy && (fir::isBoxProcAddressType(ptrTy) ||
- mlir::isa<fir::BoxProcType>(ptrTy))) {
+ if (ptrTy &&
+ (fir::isBoxProcAddressType(ptrTy) || ptrTy.isa<fir::BoxProcType>())) {
mlir::Value pointerBoxProc =
fir::isBoxProcAddressType(ptrTy)
? builder.create<fir::LoadOp>(loc, fir::getBase(args[0]))
@@ -2393,7 +2392,7 @@ IntrinsicLibrary::genAssociated(mlir::Type resultType,
mlir::Value target = fir::getBase(args[1]);
if (fir::isBoxProcAddressType(target.getType()))
target = builder.create<fir::LoadOp>(loc, target);
- if (mlir::isa<fir::BoxProcType>(target.getType()))
+ if (target.getType().isa<fir::BoxProcType>())
target = builder.create<fir::BoxAddrOp>(loc, target);
mlir::Type intPtrTy = builder.getIntPtrType();
mlir::Value pointerInt =
@@ -2650,7 +2649,7 @@ static mlir::Value getAddrFromBox(fir::FirOpBuilder &builder,
mlir::Value argValue = fir::getBase(arg);
mlir::Value addr{nullptr};
if (isFunc) {
- auto funcTy = mlir::cast<fir::BoxProcType>(argValue.getType()).getEleTy();
+ auto funcTy = argValue.getType().cast<fir::BoxProcType>().getEleTy();
addr = builder.create<fir::BoxAddrOp>(loc, funcTy, argValue);
} else {
const auto *box = arg.getBoxOf<fir::BoxValue>();
@@ -3030,7 +3029,7 @@ void IntrinsicLibrary::genDateAndTime(llvm::ArrayRef<fir::ExtendedValue> args) {
mlir::Value IntrinsicLibrary::genDim(mlir::Type resultType,
llvm::ArrayRef<mlir::Value> args) {
assert(args.size() == 2);
- if (mlir::isa<mlir::IntegerType>(resultType)) {
+ if (resultType.isa<mlir::IntegerType>()) {
mlir::Value zero = builder.createIntegerConstant(loc, resultType, 0);
auto
diff = builder.create<mlir::arith::SubIOp>(loc, args[0], args[1]);
auto cmp = builder.create<mlir::arith::CmpIOp>(
@@ -3575,7 +3574,7 @@ IntrinsicLibrary::genReduction(FN func, FD funcDim, llvm::StringRef errMsg,
if (absentDim || rank == 1) {
mlir::Type ty = array.getType();
mlir::Type arrTy = fir::dyn_cast_ptrOrBoxEleTy(ty);
- auto eleTy = mlir::cast<fir::SequenceType>(arrTy).getEleTy();
+ auto eleTy = arrTy.cast<fir::SequenceType>().getEleTy();
if (fir::isa_complex(eleTy)) {
mlir::Value result = builder.createTemporary(loc, eleTy);
func(builder, loc, array, mask, result);
@@ -3647,7 +3646,7 @@ mlir::Value IntrinsicLibrary::genIbits(mlir::Type resultType,
mlir::Value pos = builder.createConvert(loc, resultType, args[1]);
mlir::Value len = builder.createConvert(loc, resultType, args[2]);
mlir::Value bitSize = builder.createIntegerConstant(
- loc, resultType, mlir::cast<mlir::IntegerType>(resultType).getWidth());
+ loc, resultType, resultType.cast<mlir::IntegerType>().getWidth());
auto shiftCount = builder.create<mlir::arith::SubIOp>(loc, bitSize, len);
mlir::Value zero = builder.createIntegerConstant(loc, resultType, 0);
mlir::Value ones = builder.createAllOnesInteger(loc, resultType);
@@ -3687,7 +3686,7 @@ IntrinsicLibrary::genIchar(mlir::Type resultType,
mlir::Value buffer = charBox->getBuffer();
mlir::Type bufferTy = buffer.getType();
mlir::Value charVal;
- if (auto charTy = mlir::dyn_cast<fir::CharacterType>(bufferTy)) {
+ if (auto charTy = bufferTy.dyn_cast<fir::CharacterType>()) {
assert(charTy.singleton());
charVal = buffer;
} else {
@@ -3760,7 +3759,7 @@ void IntrinsicLibrary::genRaiseExcept(int except, mlir::Value cond) {
static std::pair<mlir::Value, mlir::Type>
getFieldRef(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Value rec) {
auto recType =
- mlir::dyn_cast<fir::RecordType>(fir::unwrapPassByRefType(rec.getType()));
+ fir::unwrapPassByRefType(rec.getType()).dyn_cast<fir::RecordType>();
assert(recType.getTypeList().size() == 1 && "expected exactly one component");
auto [fieldName, fieldTy] = recType.getTypeList().front();
mlir::Value field = builder.create<fir::FieldIndexOp>(
@@ -3809,7 +3808,7 @@ mlir::Value IntrinsicLibrary::genIeeeClass(mlir::Type resultType,
assert(args.size() == 1);
mlir::Value realVal = args[0];
- mlir::FloatType realType = mlir::dyn_cast<mlir::FloatType>(realVal.getType());
+ mlir::FloatType realType = realVal.getType().dyn_cast<mlir::FloatType>();
const unsigned intWidth = realType.getWidth();
mlir::Type intType = builder.getIntegerType(intWidth);
mlir::Value intVal =
@@ -4057,10 +4056,8 @@ IntrinsicLibrary::genIeeeCopySign(mlir::Type resultType,
assert(args.size() == 2);
mlir::Value xRealVal = args[0];
mlir::Value yRealVal = args[1];
- mlir::FloatType xRealType =
- mlir::dyn_cast<mlir::FloatType>(xRealVal.getType());
- mlir::FloatType yRealType =
- mlir::dyn_cast<mlir::FloatType>(yRealVal.getType());
+ mlir::FloatType xRealType = xRealVal.getType().dyn_cast<mlir::FloatType>();
+ mlir::FloatType yRealType = yRealVal.getType().dyn_cast<mlir::FloatType>();
if (yRealType == mlir::FloatType::getBF16(builder.getContext())) {
// Workaround: CopySignOp and BitcastOp don't work for kind 3 arg Y.
@@ -4109,7 +4106,7 @@ void IntrinsicLibrary::genIeeeGetFlag(llvm::ArrayRef<fir::ExtendedValue> args) {
mlir::Value flag = fir::getBase(args[0]);
mlir::Value flagValue = fir::getBase(args[1]);
mlir::Type resultTy =
- mlir::dyn_cast<fir::ReferenceType>(flagValue.getType()).getEleTy();
+ flagValue.getType().dyn_cast<fir::ReferenceType>().getEleTy();
mlir::Type i32Ty = builder.getIntegerType(32);
mlir::Value zero = builder.createIntegerConstant(loc, i32Ty, 0);
auto [fieldRef, ignore] = getFieldRef(builder, loc, flag);
@@ -4133,7 +4130,7 @@ void IntrinsicLibrary::genIeeeGetHaltingMode(
mlir::Value flag = fir::getBase(args[0]);
mlir::Value halting = fir::getBase(args[1]);
mlir::Type resultTy =
- mlir::dyn_cast<fir::ReferenceType>(halting.getType()).getEleTy();
+ halting.getType().dyn_cast<fir::ReferenceType>().getEleTy();
mlir::Type i32Ty = builder.getIntegerType(32);
mlir::Value zero = builder.createIntegerConstant(loc, i32Ty, 0);
auto [fieldRef, ignore] = getFieldRef(builder, loc, flag);
@@ -4251,7 +4248,7 @@ mlir::Value IntrinsicLibrary::genIeeeLogb(mlir::Type resultType,
// : ieee_copy_sign(X, 1.0) // +infinity or NaN
assert(args.size() == 1);
mlir::Value realVal = args[0];
- mlir::FloatType realType = mlir::dyn_cast<mlir::FloatType>(realVal.getType());
+ mlir::FloatType realType = realVal.getType().dyn_cast<mlir::FloatType>();
int bitWidth = realType.getWidth();
mlir::Type intType = builder.getIntegerType(realType.getWidth());
mlir::Value intVal =
@@ -4548,7 +4545,7 @@ mlir::Value IntrinsicLibrary::genIeeeSignbit(mlir::Type resultType,
// Check if the sign bit of arg X is set.
assert(args.size() == 1);
mlir::Value realVal = args[0];
- mlir::FloatType realType = mlir::dyn_cast<mlir::FloatType>(realVal.getType());
+ mlir::FloatType realType = realVal.getType().dyn_cast<mlir::FloatType>();
int bitWidth = realType.getWidth();
if (realType == mlir::FloatType::getBF16(builder.getContext())) {
// Workaround: can't bitcast or convert real(3) to integer(2) or real(2).
@@ -4645,7 +4642,7 @@ mlir::Value IntrinsicLibrary::genIeeeValue(mlir::Type resultType,
// A compiler generated call has one argument:
// - arg[0] is an index constant
assert(args.size() == 1 || args.size() == 2);
- mlir::FloatType realType = mlir::dyn_cast<mlir::FloatType>(resultType);
+ mlir::FloatType realType = resultType.dyn_cast<mlir::FloatType>();
int bitWidth = realType.getWidth();
mlir::Type intType = builder.getIntegerType(bitWidth);
mlir::Type valueTy = bitWidth <= 64 ? intType : builder.getIntegerType(64);
@@ -4887,7 +4884,7 @@ mlir::Value IntrinsicLibrary::genIshft(mlir::Type resultType,
// : I << abs(SHIFT)
assert(args.size() == 2);
mlir::Value bitSize = builder.createIntegerConstant(
- loc, resultType, mlir::cast<mlir::IntegerType>(resultType).getWidth());
+ loc, resultType, resultType.cast<mlir::IntegerType>().getWidth());
mlir::Value zero = builder.createIntegerConstant(loc, resultType, 0);
mlir::Value shift = builder.createConvert(loc, resultType, args[1]);
mlir::Value absShift = genAbs(resultType, {shift});
@@ -4923,7 +4920,7 @@ mlir::Value IntrinsicLibrary::genIshftc(mlir::Type resultType,
// Return: SHIFT == 0 || SIZE == abs(SHIFT) ? I : (unchanged | left | right)
assert(args.size() == 3);
mlir::Value bitSize = builder.createIntegerConstant(
- loc, resultType, mlir::cast<mlir::IntegerType>(resultType).getWidth());
+ loc, resultType, resultType.cast<mlir::IntegerType>().getWidth());
mlir::Value I = args[0];
mlir::Value shift = builder.createConvert(loc, resultType, args[1]);
mlir::Value size =
@@ -5030,7 +5027,7 @@ IntrinsicLibrary::genLoc(mlir::Type resultType,
mlir::Value box = fir::getBase(args[0]);
assert(fir::isa_box_type(box.getType()) &&
"argument must have been lowered to box type");
- bool isFunc = mlir::isa<fir::BoxProcType>(box.getType());
+ bool isFunc = box.getType().isa<fir::BoxProcType>();
if (!isOptional(box)) {
mlir::Value argAddr = getAddrFromBox(builder, loc, args[0], isFunc);
return builder.createConvert(loc, resultType, argAddr);
@@ -5159,7 +5156,7 @@ IntrinsicLibrary::genMerge(mlir::Type,
auto convertToStaticType = [&](mlir::Value polymorphic,
mlir::Value other) -> mlir::Value {
mlir::Type otherType = other.getType();
- if (mlir::isa<fir::BaseBoxType>(otherType))
+ if (otherType.isa<fir::BaseBoxType>())
return builder.create<fir::ReboxOp>(loc, otherType, polymorphic,
/*shape*/ mlir::Value{},
/*slice=*/mlir::Value{});
@@ -5212,7 +5209,7 @@ mlir::Value IntrinsicLibrary::genMergeBits(mlir::Type resultType,
mlir::Value IntrinsicLibrary::genMod(mlir::Type resultType,
llvm::ArrayRef<mlir::Value> args) {
assert(args.size() == 2);
- if (mlir::isa<mlir::IntegerType>(resultType))
+ if (resultType.isa<mlir::IntegerType>())
return builder.create<mlir::arith::RemSIOp>(loc, args[0], args[1]);
// Use runtime.
@@ -5234,7 +5231,7 @@ mlir::Value IntrinsicLibrary::genModulo(mlir::Type resultType,
// - Otherwise, when A/P < 0 and MOD(A,P) !=0, then MODULO(A, P) =
// A-FLOOR(A/P)*P = A-(INT(A/P)-1)*P = A-INT(A/P)*P+P = MOD(A,P)+P
// Note that A/P < 0 if and only if A and P signs are
diff erent.
- if (mlir::isa<mlir::IntegerType>(resultType)) {
+ if (resultType.isa<mlir::IntegerType>()) {
auto remainder =
builder.create<mlir::arith::RemSIOp>(loc, args[0], args[1]);
auto argXor = builder.create<mlir::arith::XOrIOp>(loc, args[0], args[1]);
@@ -5347,7 +5344,7 @@ void IntrinsicLibrary::genMvbits(llvm::ArrayRef<fir::ExtendedValue> args) {
mlir::Value zero = builder.createIntegerConstant(loc, resultType, 0);
mlir::Value ones = builder.createAllOnesInteger(loc, resultType);
mlir::Value bitSize = builder.createIntegerConstant(
- loc, resultType, mlir::cast<mlir::IntegerType>(resultType).getWidth());
+ loc, resultType, resultType.cast<mlir::IntegerType>().getWidth());
auto shiftCount = builder.create<mlir::arith::SubIOp>(loc, bitSize, len);
auto mask = builder.create<mlir::arith::ShRUIOp>(loc, ones, shiftCount);
auto unchangedTmp1 = builder.create<mlir::arith::ShLIOp>(loc, mask, topos);
@@ -5631,7 +5628,7 @@ IntrinsicLibrary::genReshape(mlir::Type resultType,
assert(fir::BoxValue(shape).rank() == 1);
mlir::Type shapeTy = shape.getType();
mlir::Type shapeArrTy = fir::dyn_cast_ptrOrBoxEleTy(shapeTy);
- auto resultRank = mlir::cast<fir::SequenceType>(shapeArrTy).getShape()[0];
+ auto resultRank = shapeArrTy.cast<fir::SequenceType>().getShape()[0];
if (resultRank == fir::SequenceType::getUnknownExtent())
TODO(loc, "intrinsic: reshape requires computing rank of result");
@@ -5924,7 +5921,7 @@ void IntrinsicLibrary::genSignalSubroutine(
mlir::Value IntrinsicLibrary::genSign(mlir::Type resultType,
llvm::ArrayRef<mlir::Value> args) {
assert(args.size() == 2);
- if (mlir::isa<mlir::IntegerType>(resultType)) {
+ if (resultType.isa<mlir::IntegerType>()) {
mlir::Value abs = genAbs(resultType, {args[0]});
mlir::Value zero = builder.createIntegerConstant(loc, resultType, 0);
auto neg = builder.create<mlir::arith::SubIOp>(loc, zero, abs);
diff --git a/flang/lib/Optimizer/Builder/MutableBox.cpp b/flang/lib/Optimizer/Builder/MutableBox.cpp
index 76b920dba86979..d4012e9c3d9d93 100644
--- a/flang/lib/Optimizer/Builder/MutableBox.cpp
+++ b/flang/lib/Optimizer/Builder/MutableBox.cpp
@@ -28,7 +28,7 @@ createNewFirBox(fir::FirOpBuilder &builder, mlir::Location loc,
const fir::MutableBoxValue &box, mlir::Value addr,
mlir::ValueRange lbounds, mlir::ValueRange extents,
mlir::ValueRange lengths, mlir::Value tdesc = {}) {
- if (mlir::isa<fir::BaseBoxType>(addr.getType()))
+ if (addr.getType().isa<fir::BaseBoxType>())
// The entity is already boxed.
return builder.createConvert(loc, box.getBoxTy(), addr);
@@ -53,21 +53,20 @@ createNewFirBox(fir::FirOpBuilder &builder, mlir::Location loc,
// error in the embox).
llvm::SmallVector<mlir::Value> cleanedLengths;
auto cleanedAddr = addr;
- if (auto charTy = mlir::dyn_cast<fir::CharacterType>(box.getEleTy())) {
+ if (auto charTy = box.getEleTy().dyn_cast<fir::CharacterType>()) {
// Cast address to box type so that both input and output type have
// unknown or constant lengths.
auto bt = box.getBaseTy();
auto addrTy = addr.getType();
- auto type = mlir::isa<fir::HeapType>(addrTy) ? fir::HeapType::get(bt)
- : mlir::isa<fir::PointerType>(addrTy)
- ? fir::PointerType::get(bt)
- : builder.getRefType(bt);
+ auto type = addrTy.isa<fir::HeapType>() ? fir::HeapType::get(bt)
+ : addrTy.isa<fir::PointerType>() ? fir::PointerType::get(bt)
+ : builder.getRefType(bt);
cleanedAddr = builder.createConvert(loc, type, addr);
if (charTy.getLen() == fir::CharacterType::unknownLen())
cleanedLengths.append(lengths.begin(), lengths.end());
} else if (fir::isUnlimitedPolymorphicType(box.getBoxTy())) {
- if (auto charTy = mlir::dyn_cast<fir::CharacterType>(
- fir::dyn_cast_ptrEleTy(addr.getType()))) {
+ if (auto charTy = fir::dyn_cast_ptrEleTy(addr.getType())
+ .dyn_cast<fir::CharacterType>()) {
if (charTy.getLen() == fir::CharacterType::unknownLen())
cleanedLengths.append(lengths.begin(), lengths.end());
}
@@ -329,18 +328,18 @@ class MutablePropertyWriter {
mlir::Value fir::factory::createUnallocatedBox(
fir::FirOpBuilder &builder, mlir::Location loc, mlir::Type boxType,
mlir::ValueRange nonDeferredParams, mlir::Value typeSourceBox) {
- auto baseAddrType = mlir::dyn_cast<fir::BaseBoxType>(boxType).getEleTy();
+ auto baseAddrType = boxType.dyn_cast<fir::BaseBoxType>().getEleTy();
if (!fir::isa_ref_type(baseAddrType))
baseAddrType = builder.getRefType(baseAddrType);
auto type = fir::unwrapRefType(baseAddrType);
auto eleTy = fir::unwrapSequenceType(type);
- if (auto recTy = mlir::dyn_cast<fir::RecordType>(eleTy))
+ if (auto recTy = eleTy.dyn_cast<fir::RecordType>())
if (recTy.getNumLenParams() > 0)
TODO(loc, "creating unallocated fir.box of derived type with length "
"parameters");
auto nullAddr = builder.createNullConstant(loc, baseAddrType);
mlir::Value shape;
- if (auto seqTy = mlir::dyn_cast<fir::SequenceType>(type)) {
+ if (auto seqTy = type.dyn_cast<fir::SequenceType>()) {
auto zero = builder.createIntegerConstant(loc, builder.getIndexType(), 0);
llvm::SmallVector<mlir::Value> extents(seqTy.getDimension(), zero);
shape = builder.createShape(
@@ -349,7 +348,7 @@ mlir::Value fir::factory::createUnallocatedBox(
// Provide dummy length parameters if they are dynamic. If a length parameter
// is deferred. It is set to zero here and will be set on allocation.
llvm::SmallVector<mlir::Value> lenParams;
- if (auto charTy = mlir::dyn_cast<fir::CharacterType>(eleTy)) {
+ if (auto charTy = eleTy.dyn_cast<fir::CharacterType>()) {
if (charTy.getLen() == fir::CharacterType::unknownLen()) {
if (!nonDeferredParams.empty()) {
lenParams.push_back(nonDeferredParams[0]);
@@ -593,7 +592,7 @@ void fir::factory::associateMutableBoxWithRemap(
auto cast = [&](mlir::Value addr) -> mlir::Value {
// Cast base addr to new sequence type.
auto ty = fir::dyn_cast_ptrEleTy(addr.getType());
- if (auto seqTy = mlir::dyn_cast<fir::SequenceType>(ty)) {
+ if (auto seqTy = ty.dyn_cast<fir::SequenceType>()) {
fir::SequenceType::Shape shape(newRank,
fir::SequenceType::getUnknownExtent());
ty = fir::SequenceType::get(shape, seqTy.getEleTy());
@@ -674,10 +673,10 @@ void fir::factory::disassociateMutableBox(fir::FirOpBuilder &builder,
if (box.isPolymorphic() && polymorphicSetType) {
// 7.3.2.3 point 7. The dynamic type of a disassociated pointer is the
// same as its declared type.
- auto boxTy = mlir::dyn_cast<fir::BaseBoxType>(box.getBoxTy());
+ auto boxTy = box.getBoxTy().dyn_cast<fir::BaseBoxType>();
auto eleTy = fir::unwrapPassByRefType(boxTy.getEleTy());
mlir::Type derivedType = fir::getDerivedType(eleTy);
- if (auto recTy = mlir::dyn_cast<fir::RecordType>(derivedType)) {
+ if (auto recTy = derivedType.dyn_cast<fir::RecordType>()) {
fir::runtime::genNullifyDerivedType(builder, loc, box.getAddr(), recTy,
box.rank());
return;
@@ -691,7 +690,7 @@ getNewLengths(fir::FirOpBuilder &builder, mlir::Location loc,
const fir::MutableBoxValue &box, mlir::ValueRange lenParams) {
llvm::SmallVector<mlir::Value> lengths;
auto idxTy = builder.getIndexType();
- if (auto charTy = mlir::dyn_cast<fir::CharacterType>(box.getEleTy())) {
+ if (auto charTy = box.getEleTy().dyn_cast<fir::CharacterType>()) {
if (charTy.getLen() == fir::CharacterType::unknownLen()) {
if (box.hasNonDeferredLenParams()) {
lengths.emplace_back(
@@ -718,7 +717,7 @@ static mlir::Value allocateAndInitNewStorage(fir::FirOpBuilder &builder,
auto lengths = getNewLengths(builder, loc, box, lenParams);
auto newStorage = builder.create<fir::AllocMemOp>(
loc, box.getBaseTy(), allocName, lengths, extents);
- if (mlir::isa<fir::RecordType>(box.getEleTy())) {
+ if (box.getEleTy().isa<fir::RecordType>()) {
// TODO: skip runtime initialization if this is not required. Currently,
// there is no way to know here if a derived type needs it or not. But the
// information is available at compile time and could be reflected here
@@ -743,7 +742,7 @@ void fir::factory::genInlinedAllocation(
lengths, safeExtents);
MutablePropertyWriter{builder, loc, box}.updateMutableBox(
heap, lbounds, safeExtents, lengths);
- if (mlir::isa<fir::RecordType>(box.getEleTy())) {
+ if (box.getEleTy().isa<fir::RecordType>()) {
// TODO: skip runtime initialization if this is not required. Currently,
// there is no way to know here if a derived type needs it or not. But the
// information is available at compile time and could be reflected here
diff --git a/flang/lib/Optimizer/Builder/PPCIntrinsicCall.cpp b/flang/lib/Optimizer/Builder/PPCIntrinsicCall.cpp
index 7f09e882284465..160118e2c050a3 100644
--- a/flang/lib/Optimizer/Builder/PPCIntrinsicCall.cpp
+++ b/flang/lib/Optimizer/Builder/PPCIntrinsicCall.cpp
@@ -1119,7 +1119,7 @@ PPCIntrinsicLibrary::genVecAbs(mlir::Type resultType,
funcOp = builder.createFunction(loc, fname, ftype);
auto callOp{builder.create<fir::CallOp>(loc, funcOp, argBases[0])};
return callOp.getResult(0);
- } else if (auto eleTy = mlir::dyn_cast<mlir::IntegerType>(vTypeInfo.eleTy)) {
+ } else if (auto eleTy = vTypeInfo.eleTy.dyn_cast<mlir::IntegerType>()) {
// vec_abs(arg1) = max(0 - arg1, arg1)
auto newVecTy{mlir::VectorType::get(vTypeInfo.len, eleTy)};
@@ -1173,13 +1173,12 @@ fir::ExtendedValue PPCIntrinsicLibrary::genVecAddAndMulSubXor(
assert(args.size() == 2);
auto argBases{getBasesForArgs(args)};
auto argsTy{getTypesForArgs(argBases)};
- assert(mlir::isa<fir::VectorType>(argsTy[0]) &&
- mlir::isa<fir::VectorType>(argsTy[1]));
+ assert(argsTy[0].isa<fir::VectorType>() && argsTy[1].isa<fir::VectorType>());
auto vecTyInfo{getVecTypeFromFir(argBases[0])};
- const auto isInteger{mlir::isa<mlir::IntegerType>(vecTyInfo.eleTy)};
- const auto isFloat{mlir::isa<mlir::FloatType>(vecTyInfo.eleTy)};
+ const auto isInteger{vecTyInfo.eleTy.isa<mlir::IntegerType>()};
+ const auto isFloat{vecTyInfo.eleTy.isa<mlir::FloatType>()};
assert((isInteger || isFloat) && "unknown vector type");
auto vargs{convertVecArgs(builder, loc, vecTyInfo, argBases)};
@@ -1213,7 +1212,7 @@ fir::ExtendedValue PPCIntrinsicLibrary::genVecAddAndMulSubXor(
arg2 = vargs[1];
} else if (isFloat) {
// bitcast the arguments to integer
- auto wd{mlir::dyn_cast<mlir::FloatType>(vecTyInfo.eleTy).getWidth()};
+ auto wd{vecTyInfo.eleTy.dyn_cast<mlir::FloatType>().getWidth()};
auto ftype{builder.getIntegerType(wd)};
auto bcVecTy{mlir::VectorType::get(vecTyInfo.len, ftype)};
arg1 = builder.create<mlir::vector::BitCastOp>(loc, bcVecTy, vargs[0]);
@@ -1451,7 +1450,7 @@ PPCIntrinsicLibrary::genVecCmp(mlir::Type resultType,
mlir::Value res{nullptr};
- if (auto eTy = mlir::dyn_cast<mlir::IntegerType>(vecTyInfo.eleTy)) {
+ if (auto eTy = vecTyInfo.eleTy.dyn_cast<mlir::IntegerType>()) {
constexpr int firstArg{0};
constexpr int secondArg{1};
std::map<VecOp, std::array<int, 2>> argOrder{
@@ -1560,7 +1559,7 @@ PPCIntrinsicLibrary::genVecConvert(mlir::Type resultType,
case VecOp::Ctf: {
assert(args.size() == 2);
auto convArg{builder.createConvert(loc, i32Ty, argBases[1])};
- auto eTy{mlir::dyn_cast<mlir::IntegerType>(vecTyInfo.eleTy)};
+ auto eTy{vecTyInfo.eleTy.dyn_cast<mlir::IntegerType>()};
assert(eTy && "Unsupported vector type");
const auto isUnsigned{eTy.isUnsignedInteger()};
const auto width{eTy.getWidth()};
@@ -1588,9 +1587,10 @@ PPCIntrinsicLibrary::genVecConvert(mlir::Type resultType,
: builder.create<mlir::LLVM::SIToFPOp>(loc, ty, vArg1)};
// construct vector<1./(1<<arg1), 1.0/(1<<arg1)>
- auto constInt{mlir::dyn_cast_or_null<mlir::IntegerAttr>(
+ auto constInt{
mlir::dyn_cast<mlir::arith::ConstantOp>(argBases[1].getDefiningOp())
- .getValue())};
+ .getValue()
+ .dyn_cast_or_null<mlir::IntegerAttr>()};
assert(constInt && "expected integer constant argument");
double f{1.0 / (1 << constInt.getInt())};
llvm::SmallVector<double> vals{f, f};
@@ -1815,7 +1815,7 @@ static mlir::Value addOffsetToAddress(fir::FirOpBuilder &builder,
static mlir::Value reverseVectorElements(fir::FirOpBuilder &builder,
mlir::Location loc, mlir::Value v,
int64_t len) {
- assert(mlir::isa<mlir::VectorType>(v.getType()));
+ assert(v.getType().isa<mlir::VectorType>());
assert(len > 0);
llvm::SmallVector<int64_t, 16> mask;
for (int64_t i = 0; i < len; ++i) {
@@ -2144,9 +2144,10 @@ PPCIntrinsicLibrary::genVecPerm(mlir::Type resultType,
}
case VecOp::Permi: {
// arg3 is a constant
- auto constIntOp{mlir::dyn_cast_or_null<mlir::IntegerAttr>(
+ auto constIntOp{
mlir::dyn_cast<mlir::arith::ConstantOp>(argBases[2].getDefiningOp())
- .getValue())};
+ .getValue()
+ .dyn_cast_or_null<mlir::IntegerAttr>()};
assert(constIntOp && "expected integer constant argument");
auto constInt{constIntOp.getInt()};
// arg1, arg2, and result type share same VecTypeInfo
@@ -2320,9 +2321,10 @@ PPCIntrinsicLibrary::genVecShift(mlir::Type resultType,
}
} else if (vop == VecOp::Sld || vop == VecOp::Sldw) {
assert(args.size() == 3);
- auto constIntOp = mlir::dyn_cast_or_null<mlir::IntegerAttr>(
+ auto constIntOp =
mlir::dyn_cast<mlir::arith::ConstantOp>(argBases[2].getDefiningOp())
- .getValue());
+ .getValue()
+ .dyn_cast_or_null<mlir::IntegerAttr>();
assert(constIntOp && "expected integer constant argument");
// Bitcast to vector<16xi8>
@@ -2795,16 +2797,16 @@ void PPCIntrinsicLibrary::genMmaIntr(llvm::ArrayRef<fir::ExtendedValue> args) {
auto vType{v.getType()};
mlir::Type targetType{intrFuncType.getInput(j)};
if (vType != targetType) {
- if (mlir::isa<mlir::VectorType>(targetType)) {
+ if (targetType.isa<mlir::VectorType>()) {
// Perform vector type conversion for arguments passed by value.
- auto eleTy{mlir::dyn_cast<fir::VectorType>(vType).getEleTy()};
- auto len{mlir::dyn_cast<fir::VectorType>(vType).getLen()};
+ auto eleTy{vType.dyn_cast<fir::VectorType>().getEleTy()};
+ auto len{vType.dyn_cast<fir::VectorType>().getLen()};
mlir::VectorType mlirType = mlir::VectorType::get(len, eleTy);
auto v0{builder.createConvert(loc, mlirType, v)};
auto v1{builder.create<mlir::vector::BitCastOp>(loc, targetType, v0)};
intrArgs.push_back(v1);
- } else if (mlir::isa<mlir::IntegerType>(targetType) &&
- mlir::isa<mlir::IntegerType>(vType)) {
+ } else if (targetType.isa<mlir::IntegerType>() &&
+ vType.isa<mlir::IntegerType>()) {
auto v0{builder.createConvert(loc, targetType, v)};
intrArgs.push_back(v0);
} else {
@@ -2859,7 +2861,7 @@ void PPCIntrinsicLibrary::genVecStore(llvm::ArrayRef<fir::ExtendedValue> args) {
if (arg1TyInfo.isFloat32()) {
stTy = mlir::VectorType::get(len, i32ty);
fname = "llvm.ppc.altivec.stvewx";
- } else if (mlir::isa<mlir::IntegerType>(arg1TyInfo.eleTy)) {
+ } else if (arg1TyInfo.eleTy.isa<mlir::IntegerType>()) {
stTy = mlir::VectorType::get(len, mlir::IntegerType::get(context, width));
switch (width) {
diff --git a/flang/lib/Optimizer/Builder/Runtime/Allocatable.cpp b/flang/lib/Optimizer/Builder/Runtime/Allocatable.cpp
index 70a88ff18cb1da..abff0e150ab4ad 100644
--- a/flang/lib/Optimizer/Builder/Runtime/Allocatable.cpp
+++ b/flang/lib/Optimizer/Builder/Runtime/Allocatable.cpp
@@ -27,7 +27,7 @@ mlir::Value fir::runtime::genMoveAlloc(fir::FirOpBuilder &builder,
if (fir::isPolymorphicType(from.getType()) &&
!fir::isUnlimitedPolymorphicType(from.getType())) {
fir::ClassType clTy =
- mlir::dyn_cast<fir::ClassType>(fir::dyn_cast_ptrEleTy(from.getType()));
+ fir::dyn_cast_ptrEleTy(from.getType()).dyn_cast<fir::ClassType>();
mlir::Type derivedType = fir::unwrapInnerType(clTy.getEleTy());
declaredTypeDesc =
builder.create<fir::TypeDescOp>(loc, mlir::TypeAttr::get(derivedType));
diff --git a/flang/lib/Optimizer/Builder/Runtime/Character.cpp b/flang/lib/Optimizer/Builder/Runtime/Character.cpp
index b16819915d5abb..f3663439fdd59e 100644
--- a/flang/lib/Optimizer/Builder/Runtime/Character.cpp
+++ b/flang/lib/Optimizer/Builder/Runtime/Character.cpp
@@ -39,15 +39,15 @@ static void genCharacterSearch(FN func, fir::FirOpBuilder &builder,
/// Helper function to recover the KIND from the FIR type.
static int discoverKind(mlir::Type ty) {
- if (auto charTy = mlir::dyn_cast<fir::CharacterType>(ty))
+ if (auto charTy = ty.dyn_cast<fir::CharacterType>())
return charTy.getFKind();
if (auto eleTy = fir::dyn_cast_ptrEleTy(ty))
return discoverKind(eleTy);
- if (auto arrTy = mlir::dyn_cast<fir::SequenceType>(ty))
+ if (auto arrTy = ty.dyn_cast<fir::SequenceType>())
return discoverKind(arrTy.getEleTy());
- if (auto boxTy = mlir::dyn_cast<fir::BoxCharType>(ty))
+ if (auto boxTy = ty.dyn_cast<fir::BoxCharType>())
return discoverKind(boxTy.getEleTy());
- if (auto boxTy = mlir::dyn_cast<fir::BoxType>(ty))
+ if (auto boxTy = ty.dyn_cast<fir::BoxType>())
return discoverKind(boxTy.getEleTy());
llvm_unreachable("unexpected character type");
}
diff --git a/flang/lib/Optimizer/Builder/Runtime/Intrinsics.cpp b/flang/lib/Optimizer/Builder/Runtime/Intrinsics.cpp
index 8b78a1688c7318..57c47da0f3f85c 100644
--- a/flang/lib/Optimizer/Builder/Runtime/Intrinsics.cpp
+++ b/flang/lib/Optimizer/Builder/Runtime/Intrinsics.cpp
@@ -228,8 +228,7 @@ void fir::runtime::genSystemClock(fir::FirOpBuilder &builder,
fir::IfOp ifOp{};
const bool isOptionalArg =
fir::valueHasFirAttribute(arg, fir::getOptionalAttrName());
- if (mlir::dyn_cast<fir::PointerType>(type) ||
- mlir::dyn_cast<fir::HeapType>(type)) {
+ if (type.dyn_cast<fir::PointerType>() || type.dyn_cast<fir::HeapType>()) {
// Check for a disassociated pointer or an unallocated allocatable.
assert(!isOptionalArg && "invalid optional argument");
ifOp = builder.create<fir::IfOp>(loc, builder.genIsNotNullAddr(loc, arg),
@@ -243,8 +242,7 @@ void fir::runtime::genSystemClock(fir::FirOpBuilder &builder,
builder.setInsertionPointToStart(&ifOp.getThenRegion().front());
mlir::Type kindTy = func.getFunctionType().getInput(0);
int integerKind = 8;
- if (auto intType =
- mlir::dyn_cast<mlir::IntegerType>(fir::unwrapRefType(type)))
+ if (auto intType = fir::unwrapRefType(type).dyn_cast<mlir::IntegerType>())
integerKind = intType.getWidth() / 8;
mlir::Value kind = builder.createIntegerConstant(loc, kindTy, integerKind);
mlir::Value res =
diff --git a/flang/lib/Optimizer/Builder/Runtime/Ragged.cpp b/flang/lib/Optimizer/Builder/Runtime/Ragged.cpp
index e5d0fb0fb27a93..4d33282a35d9d7 100644
--- a/flang/lib/Optimizer/Builder/Runtime/Ragged.cpp
+++ b/flang/lib/Optimizer/Builder/Runtime/Ragged.cpp
@@ -32,8 +32,7 @@ void fir::runtime::genRaggedArrayAllocate(mlir::Location loc,
// Position of the bufferPointer in the header struct.
auto one = builder.createIntegerConstant(loc, i32Ty, 1);
auto eleTy = fir::unwrapSequenceType(fir::unwrapRefType(header.getType()));
- auto ptrTy =
- builder.getRefType(mlir::cast<mlir::TupleType>(eleTy).getType(1));
+ auto ptrTy = builder.getRefType(eleTy.cast<mlir::TupleType>().getType(1));
auto ptr = builder.create<fir::CoordinateOp>(loc, ptrTy, header, one);
auto heap = builder.create<fir::LoadOp>(loc, ptr);
auto cmp = builder.genIsNullAddr(loc, heap);
diff --git a/flang/lib/Optimizer/Builder/Runtime/Reduction.cpp b/flang/lib/Optimizer/Builder/Runtime/Reduction.cpp
index d4076067bf103e..66fbaddcbda1aa 100644
--- a/flang/lib/Optimizer/Builder/Runtime/Reduction.cpp
+++ b/flang/lib/Optimizer/Builder/Runtime/Reduction.cpp
@@ -666,7 +666,7 @@ void fir::runtime::genMaxloc(fir::FirOpBuilder &builder, mlir::Location loc,
mlir::func::FuncOp func;
auto ty = arrayBox.getType();
auto arrTy = fir::dyn_cast_ptrOrBoxEleTy(ty);
- auto eleTy = mlir::cast<fir::SequenceType>(arrTy).getEleTy();
+ auto eleTy = arrTy.cast<fir::SequenceType>().getEleTy();
fir::factory::CharacterExprHelper charHelper{builder, loc};
if (eleTy.isF32())
func = fir::runtime::getRuntimeFunc<mkRTKey(MaxlocReal4)>(loc, builder);
@@ -713,7 +713,7 @@ mlir::Value fir::runtime::genMaxval(fir::FirOpBuilder &builder,
mlir::func::FuncOp func;
auto ty = arrayBox.getType();
auto arrTy = fir::dyn_cast_ptrOrBoxEleTy(ty);
- auto eleTy = mlir::cast<fir::SequenceType>(arrTy).getEleTy();
+ auto eleTy = arrTy.cast<fir::SequenceType>().getEleTy();
auto dim = builder.createIntegerConstant(loc, builder.getIndexType(), 0);
if (eleTy.isF32())
@@ -781,7 +781,7 @@ void fir::runtime::genMinloc(fir::FirOpBuilder &builder, mlir::Location loc,
mlir::func::FuncOp func;
auto ty = arrayBox.getType();
auto arrTy = fir::dyn_cast_ptrOrBoxEleTy(ty);
- auto eleTy = mlir::cast<fir::SequenceType>(arrTy).getEleTy();
+ auto eleTy = arrTy.cast<fir::SequenceType>().getEleTy();
fir::factory::CharacterExprHelper charHelper{builder, loc};
if (eleTy.isF32())
func = fir::runtime::getRuntimeFunc<mkRTKey(MinlocReal4)>(loc, builder);
@@ -853,7 +853,7 @@ mlir::Value fir::runtime::genMinval(fir::FirOpBuilder &builder,
mlir::func::FuncOp func;
auto ty = arrayBox.getType();
auto arrTy = fir::dyn_cast_ptrOrBoxEleTy(ty);
- auto eleTy = mlir::cast<fir::SequenceType>(arrTy).getEleTy();
+ auto eleTy = arrTy.cast<fir::SequenceType>().getEleTy();
auto dim = builder.createIntegerConstant(loc, builder.getIndexType(), 0);
if (eleTy.isF32())
@@ -895,7 +895,7 @@ void fir::runtime::genNorm2Dim(fir::FirOpBuilder &builder, mlir::Location loc,
mlir::func::FuncOp func;
auto ty = arrayBox.getType();
auto arrTy = fir::dyn_cast_ptrOrBoxEleTy(ty);
- auto eleTy = mlir::cast<fir::SequenceType>(arrTy).getEleTy();
+ auto eleTy = arrTy.cast<fir::SequenceType>().getEleTy();
if (eleTy.isF128())
func = fir::runtime::getRuntimeFunc<ForcedNorm2DimReal16>(loc, builder);
else
@@ -917,7 +917,7 @@ mlir::Value fir::runtime::genNorm2(fir::FirOpBuilder &builder,
mlir::func::FuncOp func;
auto ty = arrayBox.getType();
auto arrTy = fir::dyn_cast_ptrOrBoxEleTy(ty);
- auto eleTy = mlir::cast<fir::SequenceType>(arrTy).getEleTy();
+ auto eleTy = arrTy.cast<fir::SequenceType>().getEleTy();
auto dim = builder.createIntegerConstant(loc, builder.getIndexType(), 0);
if (eleTy.isF32())
@@ -968,7 +968,7 @@ mlir::Value fir::runtime::genProduct(fir::FirOpBuilder &builder,
mlir::func::FuncOp func;
auto ty = arrayBox.getType();
auto arrTy = fir::dyn_cast_ptrOrBoxEleTy(ty);
- auto eleTy = mlir::cast<fir::SequenceType>(arrTy).getEleTy();
+ auto eleTy = arrTy.cast<fir::SequenceType>().getEleTy();
auto dim = builder.createIntegerConstant(loc, builder.getIndexType(), 0);
if (eleTy.isF32())
@@ -1069,7 +1069,7 @@ mlir::Value fir::runtime::genDotProduct(fir::FirOpBuilder &builder,
else if (eleTy.isInteger(builder.getKindMap().getIntegerBitsize(16)))
func =
fir::runtime::getRuntimeFunc<ForcedDotProductInteger16>(loc, builder);
- else if (mlir::isa<fir::LogicalType>(eleTy))
+ else if (eleTy.isa<fir::LogicalType>())
func =
fir::runtime::getRuntimeFunc<mkRTKey(DotProductLogical)>(loc, builder);
else
@@ -1111,7 +1111,7 @@ mlir::Value fir::runtime::genSum(fir::FirOpBuilder &builder, mlir::Location loc,
mlir::func::FuncOp func;
auto ty = arrayBox.getType();
auto arrTy = fir::dyn_cast_ptrOrBoxEleTy(ty);
- auto eleTy = mlir::cast<fir::SequenceType>(arrTy).getEleTy();
+ auto eleTy = arrTy.cast<fir::SequenceType>().getEleTy();
auto dim = builder.createIntegerConstant(loc, builder.getIndexType(), 0);
if (eleTy.isF32())
@@ -1173,7 +1173,7 @@ mlir::Value fir::runtime::genSum(fir::FirOpBuilder &builder, mlir::Location loc,
mlir::func::FuncOp func; \
auto ty = arrayBox.getType(); \
auto arrTy = fir::dyn_cast_ptrOrBoxEleTy(ty); \
- auto eleTy = mlir::cast<fir::SequenceType>(arrTy).getEleTy(); \
+ auto eleTy = arrTy.cast<fir::SequenceType>().getEleTy(); \
auto dim = builder.createIntegerConstant(loc, builder.getIndexType(), 0); \
\
if (eleTy.isInteger(builder.getKindMap().getIntegerBitsize(1))) \
diff --git a/flang/lib/Optimizer/CodeGen/BoxedProcedure.cpp b/flang/lib/Optimizer/CodeGen/BoxedProcedure.cpp
index 5229d40f2250df..48173033ecbe20 100644
--- a/flang/lib/Optimizer/CodeGen/BoxedProcedure.cpp
+++ b/flang/lib/Optimizer/CodeGen/BoxedProcedure.cpp
@@ -51,9 +51,9 @@ class BoxprocTypeRewriter : public mlir::TypeConverter {
/// not at all depending on the implementation target's characteristics and
/// preference.
bool needsConversion(mlir::Type ty) {
- if (mlir::isa<BoxProcType>(ty))
+ if (ty.isa<BoxProcType>())
return true;
- if (auto funcTy = mlir::dyn_cast<mlir::FunctionType>(ty)) {
+ if (auto funcTy = ty.dyn_cast<mlir::FunctionType>()) {
for (auto t : funcTy.getInputs())
if (needsConversion(t))
return true;
@@ -62,13 +62,13 @@ class BoxprocTypeRewriter : public mlir::TypeConverter {
return true;
return false;
}
- if (auto tupleTy = mlir::dyn_cast<mlir::TupleType>(ty)) {
+ if (auto tupleTy = ty.dyn_cast<mlir::TupleType>()) {
for (auto t : tupleTy.getTypes())
if (needsConversion(t))
return true;
return false;
}
- if (auto recTy = mlir::dyn_cast<RecordType>(ty)) {
+ if (auto recTy = ty.dyn_cast<RecordType>()) {
auto visited = visitedTypes.find(ty);
if (visited != visitedTypes.end())
return visited->second;
@@ -97,11 +97,11 @@ class BoxprocTypeRewriter : public mlir::TypeConverter {
visitedTypes.find(ty)->second = result;
return result;
}
- if (auto boxTy = mlir::dyn_cast<BaseBoxType>(ty))
+ if (auto boxTy = ty.dyn_cast<BaseBoxType>())
return needsConversion(boxTy.getEleTy());
if (isa_ref_type(ty))
return needsConversion(unwrapRefType(ty));
- if (auto t = mlir::dyn_cast<SequenceType>(ty))
+ if (auto t = ty.dyn_cast<SequenceType>())
return needsConversion(unwrapSequenceType(ty));
return false;
}
@@ -246,7 +246,7 @@ class BoxedProcedurePass
if (typeConverter.needsConversion(ty)) {
rewriter.startOpModification(func);
auto toTy =
- mlir::cast<mlir::FunctionType>(typeConverter.convertType(ty));
+ typeConverter.convertType(ty).cast<mlir::FunctionType>();
if (!func.empty())
for (auto e : llvm::enumerate(toTy.getInputs())) {
unsigned i = e.index();
@@ -263,7 +263,7 @@ class BoxedProcedurePass
// Rewrite all `fir.emboxproc` ops to either `fir.convert` or a thunk
// as required.
mlir::Type toTy = typeConverter.convertType(
- mlir::cast<BoxProcType>(embox.getType()).getEleTy());
+ embox.getType().cast<BoxProcType>().getEleTy());
rewriter.setInsertionPoint(embox);
if (embox.getHost()) {
// Create the thunk.
diff --git a/flang/lib/Optimizer/CodeGen/CGOps.cpp b/flang/lib/Optimizer/CodeGen/CGOps.cpp
index 44d07d26dd2b68..c3bcdeaf86db59 100644
--- a/flang/lib/Optimizer/CodeGen/CGOps.cpp
+++ b/flang/lib/Optimizer/CodeGen/CGOps.cpp
@@ -41,24 +41,24 @@ unsigned fir::cg::XEmboxOp::getOutRank() {
}
unsigned fir::cg::XReboxOp::getOutRank() {
- if (auto seqTy = mlir::dyn_cast<fir::SequenceType>(
- fir::dyn_cast_ptrOrBoxEleTy(getType())))
+ if (auto seqTy =
+ fir::dyn_cast_ptrOrBoxEleTy(getType()).dyn_cast<fir::SequenceType>())
return seqTy.getDimension();
return 0;
}
unsigned fir::cg::XReboxOp::getRank() {
- if (auto seqTy = mlir::dyn_cast<fir::SequenceType>(
- fir::dyn_cast_ptrOrBoxEleTy(getBox().getType())))
+ if (auto seqTy = fir::dyn_cast_ptrOrBoxEleTy(getBox().getType())
+ .dyn_cast<fir::SequenceType>())
return seqTy.getDimension();
return 0;
}
unsigned fir::cg::XArrayCoorOp::getRank() {
auto memrefTy = getMemref().getType();
- if (mlir::isa<fir::BaseBoxType>(memrefTy))
- if (auto seqty = mlir::dyn_cast<fir::SequenceType>(
- fir::dyn_cast_ptrOrBoxEleTy(memrefTy)))
+ if (memrefTy.isa<fir::BaseBoxType>())
+ if (auto seqty =
+ fir::dyn_cast_ptrOrBoxEleTy(memrefTy).dyn_cast<fir::SequenceType>())
return seqty.getDimension();
return getShape().size();
}
diff --git a/flang/lib/Optimizer/CodeGen/CodeGen.cpp b/flang/lib/Optimizer/CodeGen/CodeGen.cpp
index 19628ac71b0b21..921eac2f8f4b60 100644
--- a/flang/lib/Optimizer/CodeGen/CodeGen.cpp
+++ b/flang/lib/Optimizer/CodeGen/CodeGen.cpp
@@ -101,7 +101,7 @@ static int64_t getConstantIntValue(mlir::Value val) {
}
static unsigned getTypeDescFieldId(mlir::Type ty) {
- auto isArray = mlir::isa<fir::SequenceType>(fir::dyn_cast_ptrOrBoxEleTy(ty));
+ auto isArray = fir::dyn_cast_ptrOrBoxEleTy(ty).isa<fir::SequenceType>();
return isArray ? kOptTypePtrPosInBox : kDimsPosInBox;
}
static unsigned getLenParamFieldId(mlir::Type ty) {
@@ -147,7 +147,7 @@ genAllocationScaleSize(OP op, mlir::Type ity,
mlir::ConversionPatternRewriter &rewriter) {
mlir::Location loc = op.getLoc();
mlir::Type dataTy = op.getInType();
- auto seqTy = mlir::dyn_cast<fir::SequenceType>(dataTy);
+ auto seqTy = dataTy.dyn_cast<fir::SequenceType>();
fir::SequenceType::Extent constSize = 1;
if (seqTy) {
int constRows = seqTy.getConstantRows();
@@ -191,13 +191,13 @@ struct AllocaOpConversion : public fir::FIROpConversion<fir::AllocaOp> {
for (; i < end; ++i)
lenParams.push_back(operands[i]);
mlir::Type scalarType = fir::unwrapSequenceType(alloc.getInType());
- if (auto chrTy = mlir::dyn_cast<fir::CharacterType>(scalarType)) {
+ if (auto chrTy = scalarType.dyn_cast<fir::CharacterType>()) {
fir::CharacterType rawCharTy = fir::CharacterType::getUnknownLen(
chrTy.getContext(), chrTy.getFKind());
llvmObjectType = convertType(rawCharTy);
assert(end == 1);
size = integerCast(loc, rewriter, ity, lenParams[0]);
- } else if (auto recTy = mlir::dyn_cast<fir::RecordType>(scalarType)) {
+ } else if (auto recTy = scalarType.dyn_cast<fir::RecordType>()) {
mlir::LLVM::LLVMFuncOp memSizeFn =
getDependentTypeMemSizeFn(recTy, alloc, rewriter);
if (!memSizeFn)
@@ -265,8 +265,7 @@ struct BoxAddrOpConversion : public fir::FIROpConversion<fir::BoxAddrOp> {
mlir::ConversionPatternRewriter &rewriter) const override {
mlir::Value a = adaptor.getOperands()[0];
auto loc = boxaddr.getLoc();
- if (auto argty =
- mlir::dyn_cast<fir::BaseBoxType>(boxaddr.getVal().getType())) {
+ if (auto argty = boxaddr.getVal().getType().dyn_cast<fir::BaseBoxType>()) {
TypePair boxTyPair = getBoxTypePair(argty);
rewriter.replaceOp(boxaddr,
getBaseAddrFromBox(loc, boxTyPair, a, rewriter));
@@ -477,25 +476,24 @@ struct StringLitOpConversion : public fir::FIROpConversion<fir::StringLitOp> {
mlir::ConversionPatternRewriter &rewriter) const override {
auto ty = convertType(constop.getType());
auto attr = constop.getValue();
- if (mlir::isa<mlir::StringAttr>(attr)) {
+ if (attr.isa<mlir::StringAttr>()) {
rewriter.replaceOpWithNewOp<mlir::LLVM::ConstantOp>(constop, ty, attr);
return mlir::success();
}
- auto charTy = mlir::cast<fir::CharacterType>(constop.getType());
+ auto charTy = constop.getType().cast<fir::CharacterType>();
unsigned bits = lowerTy().characterBitsize(charTy);
mlir::Type intTy = rewriter.getIntegerType(bits);
mlir::Location loc = constop.getLoc();
mlir::Value cst = rewriter.create<mlir::LLVM::UndefOp>(loc, ty);
- if (auto arr = mlir::dyn_cast<mlir::DenseElementsAttr>(attr)) {
+ if (auto arr = attr.dyn_cast<mlir::DenseElementsAttr>()) {
cst = rewriter.create<mlir::LLVM::ConstantOp>(loc, ty, arr);
- } else if (auto arr = mlir::dyn_cast<mlir::ArrayAttr>(attr)) {
+ } else if (auto arr = attr.dyn_cast<mlir::ArrayAttr>()) {
for (auto a : llvm::enumerate(arr.getValue())) {
// convert each character to a precise bitsize
auto elemAttr = mlir::IntegerAttr::get(
intTy,
- mlir::cast<mlir::IntegerAttr>(a.value()).getValue().zextOrTrunc(
- bits));
+ a.value().cast<mlir::IntegerAttr>().getValue().zextOrTrunc(bits));
auto elemCst =
rewriter.create<mlir::LLVM::ConstantOp>(loc, intTy, elemAttr);
cst = rewriter.create<mlir::LLVM::InsertValueOp>(loc, cst, elemCst,
@@ -530,9 +528,9 @@ struct CallOpConversion : public fir::FIROpConversion<fir::CallOp> {
} // namespace
static mlir::Type getComplexEleTy(mlir::Type complex) {
- if (auto cc = mlir::dyn_cast<mlir::ComplexType>(complex))
+ if (auto cc = complex.dyn_cast<mlir::ComplexType>())
return cc.getElementType();
- return mlir::cast<fir::ComplexType>(complex).getElementType();
+ return complex.cast<fir::ComplexType>().getElementType();
}
namespace {
@@ -601,7 +599,7 @@ struct ConstcOpConversion : public fir::FIROpConversion<fir::ConstcOp> {
}
inline llvm::APFloat getValue(mlir::Attribute attr) const {
- return mlir::cast<fir::RealAttr>(attr).getValue();
+ return attr.cast<fir::RealAttr>().getValue();
}
};
@@ -610,7 +608,7 @@ struct ConvertOpConversion : public fir::FIROpConversion<fir::ConvertOp> {
using FIROpConversion::FIROpConversion;
static bool isFloatingPointTy(mlir::Type ty) {
- return mlir::isa<mlir::FloatType>(ty);
+ return ty.isa<mlir::FloatType>();
}
mlir::LogicalResult
@@ -630,8 +628,7 @@ struct ConvertOpConversion : public fir::FIROpConversion<fir::ConvertOp> {
auto loc = convert.getLoc();
auto i1Type = mlir::IntegerType::get(convert.getContext(), 1);
- if (mlir::isa<fir::LogicalType>(fromFirTy) ||
- mlir::isa<fir::LogicalType>(toFirTy)) {
+ if (fromFirTy.isa<fir::LogicalType>() || toFirTy.isa<fir::LogicalType>()) {
// By specification fir::LogicalType value may be any number,
// where non-zero value represents .true. and zero value represents
// .false.
@@ -644,8 +641,7 @@ struct ConvertOpConversion : public fir::FIROpConversion<fir::ConvertOp> {
// Conversion from narrow logical to wide logical may be implemented
// as a zero or sign extension of the input, but it may use value
// normalization as well.
- if (!mlir::isa<mlir::IntegerType>(fromTy) ||
- !mlir::isa<mlir::IntegerType>(toTy))
+ if (!fromTy.isa<mlir::IntegerType>() || !toTy.isa<mlir::IntegerType>())
return mlir::emitError(loc)
<< "unsupported types for logical conversion: " << fromTy
<< " -> " << toTy;
@@ -726,13 +722,13 @@ struct ConvertOpConversion : public fir::FIROpConversion<fir::ConvertOp> {
rewriter.replaceOp(convert, v);
return mlir::success();
}
- if (mlir::isa<mlir::IntegerType>(toTy)) {
+ if (toTy.isa<mlir::IntegerType>()) {
rewriter.replaceOpWithNewOp<mlir::LLVM::FPToSIOp>(convert, toTy, op0);
return mlir::success();
}
- } else if (mlir::isa<mlir::IntegerType>(fromTy)) {
+ } else if (fromTy.isa<mlir::IntegerType>()) {
// Integer to integer conversion.
- if (mlir::isa<mlir::IntegerType>(toTy)) {
+ if (toTy.isa<mlir::IntegerType>()) {
auto fromBits = mlir::LLVM::getPrimitiveTypeSizeInBits(fromTy);
auto toBits = mlir::LLVM::getPrimitiveTypeSizeInBits(toTy);
assert(fromBits != toBits);
@@ -753,18 +749,18 @@ struct ConvertOpConversion : public fir::FIROpConversion<fir::ConvertOp> {
return mlir::success();
}
// Integer to pointer conversion.
- if (mlir::isa<mlir::LLVM::LLVMPointerType>(toTy)) {
+ if (toTy.isa<mlir::LLVM::LLVMPointerType>()) {
rewriter.replaceOpWithNewOp<mlir::LLVM::IntToPtrOp>(convert, toTy, op0);
return mlir::success();
}
- } else if (mlir::isa<mlir::LLVM::LLVMPointerType>(fromTy)) {
+ } else if (fromTy.isa<mlir::LLVM::LLVMPointerType>()) {
// Pointer to integer conversion.
- if (mlir::isa<mlir::IntegerType>(toTy)) {
+ if (toTy.isa<mlir::IntegerType>()) {
rewriter.replaceOpWithNewOp<mlir::LLVM::PtrToIntOp>(convert, toTy, op0);
return mlir::success();
}
// Pointer to pointer conversion.
- if (mlir::isa<mlir::LLVM::LLVMPointerType>(toTy)) {
+ if (toTy.isa<mlir::LLVM::LLVMPointerType>()) {
rewriter.replaceOpWithNewOp<mlir::LLVM::BitcastOp>(convert, toTy, op0);
return mlir::success();
}
@@ -846,11 +842,11 @@ struct EmboxCharOpConversion : public fir::FIROpConversion<fir::EmboxCharOp> {
auto llvmStruct = rewriter.create<mlir::LLVM::UndefOp>(loc, llvmStructTy);
mlir::Type lenTy =
- mlir::cast<mlir::LLVM::LLVMStructType>(llvmStructTy).getBody()[1];
+ llvmStructTy.cast<mlir::LLVM::LLVMStructType>().getBody()[1];
mlir::Value lenAfterCast = integerCast(loc, rewriter, lenTy, charBufferLen);
mlir::Type addrTy =
- mlir::cast<mlir::LLVM::LLVMStructType>(llvmStructTy).getBody()[0];
+ llvmStructTy.cast<mlir::LLVM::LLVMStructType>().getBody()[0];
if (addrTy != charBuffer.getType())
charBuffer =
rewriter.create<mlir::LLVM::BitcastOp>(loc, addrTy, charBuffer);
@@ -983,10 +979,9 @@ static mlir::SymbolRefAttr getFree(fir::FreeMemOp op,
static unsigned getDimension(mlir::LLVM::LLVMArrayType ty) {
unsigned result = 1;
- for (auto eleTy =
- mlir::dyn_cast<mlir::LLVM::LLVMArrayType>(ty.getElementType());
- eleTy; eleTy = mlir::dyn_cast<mlir::LLVM::LLVMArrayType>(
- eleTy.getElementType()))
+ for (auto eleTy = ty.getElementType().dyn_cast<mlir::LLVM::LLVMArrayType>();
+ eleTy;
+ eleTy = eleTy.getElementType().dyn_cast<mlir::LLVM::LLVMArrayType>())
++result;
return result;
}
@@ -1057,9 +1052,9 @@ struct EmboxCommonConversion : public fir::FIROpConversion<OP> {
static int getCFIAttr(fir::BaseBoxType boxTy) {
auto eleTy = boxTy.getEleTy();
- if (mlir::isa<fir::PointerType>(eleTy))
+ if (eleTy.isa<fir::PointerType>())
return CFI_attribute_pointer;
- if (mlir::isa<fir::HeapType>(eleTy))
+ if (eleTy.isa<fir::HeapType>())
return CFI_attribute_allocatable;
return CFI_attribute_other;
}
@@ -1087,29 +1082,27 @@ struct EmboxCommonConversion : public fir::FIROpConversion<OP> {
auto i64Ty = mlir::IntegerType::get(rewriter.getContext(), 64);
if (auto eleTy = fir::dyn_cast_ptrEleTy(boxEleTy))
boxEleTy = eleTy;
- if (auto seqTy = mlir::dyn_cast<fir::SequenceType>(boxEleTy))
+ if (auto seqTy = boxEleTy.dyn_cast<fir::SequenceType>())
return getSizeAndTypeCode(loc, rewriter, seqTy.getEleTy(), lenParams);
- if (mlir::isa<mlir::NoneType>(
- boxEleTy)) // unlimited polymorphic or assumed type
+ if (boxEleTy.isa<mlir::NoneType>()) // unlimited polymorphic or assumed type
return {rewriter.create<mlir::LLVM::ConstantOp>(loc, i64Ty, 0),
this->genConstantOffset(loc, rewriter, CFI_type_other)};
mlir::Value typeCodeVal = this->genConstantOffset(
loc, rewriter,
fir::getTypeCode(boxEleTy, this->lowerTy().getKindMap()));
- if (fir::isa_integer(boxEleTy) ||
- mlir::dyn_cast<fir::LogicalType>(boxEleTy) || fir::isa_real(boxEleTy) ||
- fir::isa_complex(boxEleTy))
+ if (fir::isa_integer(boxEleTy) || boxEleTy.dyn_cast<fir::LogicalType>() ||
+ fir::isa_real(boxEleTy) || fir::isa_complex(boxEleTy))
return {genTypeStrideInBytes(loc, i64Ty, rewriter,
this->convertType(boxEleTy)),
typeCodeVal};
- if (auto charTy = mlir::dyn_cast<fir::CharacterType>(boxEleTy))
+ if (auto charTy = boxEleTy.dyn_cast<fir::CharacterType>())
return {getCharacterByteSize(loc, rewriter, charTy, lenParams),
typeCodeVal};
if (fir::isa_ref_type(boxEleTy)) {
auto ptrTy = ::getLlvmPtrType(rewriter.getContext());
return {genTypeStrideInBytes(loc, i64Ty, rewriter, ptrTy), typeCodeVal};
}
- if (mlir::isa<fir::RecordType>(boxEleTy))
+ if (boxEleTy.isa<fir::RecordType>())
return {genTypeStrideInBytes(loc, i64Ty, rewriter,
this->convertType(boxEleTy)),
typeCodeVal};
@@ -1218,8 +1211,8 @@ struct EmboxCommonConversion : public fir::FIROpConversion<OP> {
if (!typeDesc) {
if (useInputType) {
mlir::Type innerType = fir::unwrapInnerType(inputType);
- if (innerType && mlir::isa<fir::RecordType>(innerType)) {
- auto recTy = mlir::dyn_cast<fir::RecordType>(innerType);
+ if (innerType && innerType.template isa<fir::RecordType>()) {
+ auto recTy = innerType.template dyn_cast<fir::RecordType>();
typeDesc = getTypeDescriptor(mod, rewriter, loc, recTy);
} else {
// Unlimited polymorphic type descriptor with no record type. Set
@@ -1257,7 +1250,7 @@ struct EmboxCommonConversion : public fir::FIROpConversion<OP> {
mlir::ValueRange lenParams, mlir::Value sourceBox = {},
mlir::Type sourceBoxType = {}) const {
auto loc = box.getLoc();
- auto boxTy = mlir::dyn_cast<fir::BaseBoxType>(box.getType());
+ auto boxTy = box.getType().template dyn_cast<fir::BaseBoxType>();
bool useInputType = fir::isPolymorphicType(boxTy) &&
!fir::isUnlimitedPolymorphicType(inputType);
llvm::SmallVector<mlir::Value> typeparams = lenParams;
@@ -1300,8 +1293,8 @@ struct EmboxCommonConversion : public fir::FIROpConversion<OP> {
mlir::ValueRange lenParams,
mlir::Value typeDesc = {}) const {
auto loc = box.getLoc();
- auto boxTy = mlir::dyn_cast<fir::BaseBoxType>(box.getType());
- auto inputBoxTy = mlir::dyn_cast<fir::BaseBoxType>(box.getBox().getType());
+ auto boxTy = box.getType().dyn_cast<fir::BaseBoxType>();
+ auto inputBoxTy = box.getBox().getType().dyn_cast<fir::BaseBoxType>();
auto inputBoxTyPair = this->getBoxTypePair(inputBoxTy);
llvm::SmallVector<mlir::Value> typeparams = lenParams;
if (!box.getSubstr().empty() && fir::hasDynamicSize(boxTy.getEleTy()))
@@ -1350,7 +1343,7 @@ struct EmboxCommonConversion : public fir::FIROpConversion<OP> {
mlir::Type resultTy = llvmBaseObjectType;
// Fortran is column major, llvm GEP is row major: reverse the indices here.
for (mlir::Value interiorIndex : llvm::reverse(cstInteriorIndices)) {
- auto arrayTy = mlir::dyn_cast<mlir::LLVM::LLVMArrayType>(resultTy);
+ auto arrayTy = resultTy.dyn_cast<mlir::LLVM::LLVMArrayType>();
if (!arrayTy)
fir::emitFatalError(
loc,
@@ -1362,7 +1355,7 @@ struct EmboxCommonConversion : public fir::FIROpConversion<OP> {
convertSubcomponentIndices(loc, resultTy, componentIndices, &resultTy);
gepArgs.append(gepIndices.begin(), gepIndices.end());
if (substringOffset) {
- if (auto arrayTy = mlir::dyn_cast<mlir::LLVM::LLVMArrayType>(resultTy)) {
+ if (auto arrayTy = resultTy.dyn_cast<mlir::LLVM::LLVMArrayType>()) {
gepArgs.push_back(*substringOffset);
resultTy = arrayTy.getElementType();
} else {
@@ -1511,18 +1504,18 @@ struct XEmboxOpConversion : public EmboxCommonConversion<fir::cg::XEmboxOp> {
unsigned constRows = 0;
mlir::Value ptrOffset = zero;
mlir::Type memEleTy = fir::dyn_cast_ptrEleTy(xbox.getMemref().getType());
- assert(mlir::isa<fir::SequenceType>(memEleTy));
- auto seqTy = mlir::cast<fir::SequenceType>(memEleTy);
+ assert(memEleTy.isa<fir::SequenceType>());
+ auto seqTy = memEleTy.cast<fir::SequenceType>();
mlir::Type seqEleTy = seqTy.getEleTy();
// Adjust the element scaling factor if the element is a dependent type.
if (fir::hasDynamicSize(seqEleTy)) {
- if (auto charTy = mlir::dyn_cast<fir::CharacterType>(seqEleTy)) {
+ if (auto charTy = seqEleTy.dyn_cast<fir::CharacterType>()) {
// The GEP pointer type decays to llvm.ptr<i[width]>.
// The scaling factor is the runtime value of the length.
assert(!adaptor.getLenParams().empty());
prevPtrOff = FIROpConversion::integerCast(
loc, rewriter, i64Ty, adaptor.getLenParams().back());
- } else if (mlir::isa<fir::RecordType>(seqEleTy)) {
+ } else if (seqEleTy.isa<fir::RecordType>()) {
// prevPtrOff = ;
TODO(loc, "generate call to calculate size of PDT");
} else {
@@ -1547,7 +1540,7 @@ struct XEmboxOpConversion : public EmboxCommonConversion<fir::cg::XEmboxOp> {
} else if (hasSubstr) {
// We have a substring. The step value needs to be the number of bytes
// per CHARACTER element.
- auto charTy = mlir::cast<fir::CharacterType>(seqEleTy);
+ auto charTy = seqEleTy.cast<fir::CharacterType>();
if (fir::hasDynamicSize(charTy)) {
prevDimByteStride =
getCharacterByteSize(loc, rewriter, charTy, adaptor.getLenParams());
@@ -1596,7 +1589,7 @@ struct XEmboxOpConversion : public EmboxCommonConversion<fir::cg::XEmboxOp> {
// Lower bound is normalized to 0 for BIND(C) interoperability.
mlir::Value lb = zero;
const bool isaPointerOrAllocatable =
- mlir::isa<fir::PointerType, fir::HeapType>(eleTy);
+ eleTy.isa<fir::PointerType>() || eleTy.isa<fir::HeapType>();
// Lower bound is defaults to 1 for POINTER, ALLOCATABLE, and
// denormalized descriptors.
if (isaPointerOrAllocatable || !normalizedLowerBound(xbox))
@@ -1702,7 +1695,7 @@ struct XReboxOpConversion : public EmboxCommonConversion<fir::cg::XReboxOp> {
// Create new descriptor and fill its non-shape related data.
llvm::SmallVector<mlir::Value, 2> lenParams;
mlir::Type inputEleTy = getInputEleTy(rebox);
- if (auto charTy = mlir::dyn_cast<fir::CharacterType>(inputEleTy)) {
+ if (auto charTy = inputEleTy.dyn_cast<fir::CharacterType>()) {
if (charTy.hasConstantLen()) {
mlir::Value len =
genConstantIndex(loc, idxTy, rewriter, charTy.getLen());
@@ -1719,15 +1712,15 @@ struct XReboxOpConversion : public EmboxCommonConversion<fir::cg::XReboxOp> {
}
lenParams.emplace_back(len);
}
- } else if (auto recTy = mlir::dyn_cast<fir::RecordType>(inputEleTy)) {
+ } else if (auto recTy = inputEleTy.dyn_cast<fir::RecordType>()) {
if (recTy.getNumLenParams() != 0)
TODO(loc, "reboxing descriptor of derived type with length parameters");
}
// Rebox on polymorphic entities needs to carry over the dynamic type.
mlir::Value typeDescAddr;
- if (mlir::isa<fir::ClassType>(inputBoxTyPair.fir) &&
- mlir::isa<fir::ClassType>(rebox.getType()))
+ if (inputBoxTyPair.fir.isa<fir::ClassType>() &&
+ rebox.getType().isa<fir::ClassType>())
typeDescAddr =
loadTypeDescAddress(loc, inputBoxTyPair, loweredBox, rewriter);
@@ -1915,7 +1908,7 @@ struct XReboxOpConversion : public EmboxCommonConversion<fir::cg::XReboxOp> {
/// Return scalar element type of the input box.
static mlir::Type getInputEleTy(fir::cg::XReboxOp rebox) {
auto ty = fir::dyn_cast_ptrOrBoxEleTy(rebox.getBox().getType());
- if (auto seqTy = mlir::dyn_cast<fir::SequenceType>(ty))
+ if (auto seqTy = ty.dyn_cast<fir::SequenceType>())
return seqTy.getEleTy();
return ty;
}
@@ -1943,7 +1936,7 @@ struct ValueOpCommon {
assert(ty && "type is null");
const auto end = indices.size();
for (std::remove_const_t<decltype(end)> i = 0; i < end; ++i) {
- if (auto seq = mlir::dyn_cast<mlir::LLVM::LLVMArrayType>(ty)) {
+ if (auto seq = ty.dyn_cast<mlir::LLVM::LLVMArrayType>()) {
const auto dim = getDimension(seq);
if (dim > 1) {
auto ub = std::min(i + dim, end);
@@ -1951,7 +1944,7 @@ struct ValueOpCommon {
i += dim - 1;
}
ty = getArrayElementType(seq);
- } else if (auto st = mlir::dyn_cast<mlir::LLVM::LLVMStructType>(ty)) {
+ } else if (auto st = ty.dyn_cast<mlir::LLVM::LLVMStructType>()) {
ty = st.getBody()[indices[i]];
} else {
llvm_unreachable("index into invalid type");
@@ -1970,7 +1963,7 @@ struct ValueOpCommon {
auto fieldName = i->cast<mlir::StringAttr>().getValue();
++i;
auto ty = i->cast<mlir::TypeAttr>().getValue();
- auto index = mlir::cast<fir::RecordType>(ty).getFieldIndex(fieldName);
+ auto index = ty.cast<fir::RecordType>().getFieldIndex(fieldName);
indices.push_back(index);
}
}
@@ -1980,7 +1973,7 @@ struct ValueOpCommon {
private:
static mlir::Type getArrayElementType(mlir::LLVM::LLVMArrayType ty) {
auto eleTy = ty.getElementType();
- while (auto arrTy = mlir::dyn_cast<mlir::LLVM::LLVMArrayType>(eleTy))
+ while (auto arrTy = eleTy.dyn_cast<mlir::LLVM::LLVMArrayType>())
eleTy = arrTy.getElementType();
return eleTy;
}
@@ -2048,7 +2041,7 @@ struct InsertOnRangeOpConversion
auto type = adaptor.getOperands()[0].getType();
// Iteratively extract the array dimensions from the type.
- while (auto t = mlir::dyn_cast<mlir::LLVM::LLVMArrayType>(type)) {
+ while (auto t = type.dyn_cast<mlir::LLVM::LLVMArrayType>()) {
dims.push_back(t.getNumElements());
type = t.getElementType();
}
@@ -2114,8 +2107,7 @@ struct XArrayCoorOpConversion
mlir::Value offset = genConstantIndex(loc, idxTy, rewriter, 0);
const bool isShifted = !coor.getShift().empty();
const bool isSliced = !coor.getSlice().empty();
- const bool baseIsBoxed =
- mlir::isa<fir::BaseBoxType>(coor.getMemref().getType());
+ const bool baseIsBoxed = coor.getMemref().getType().isa<fir::BaseBoxType>();
TypePair baseBoxTyPair =
baseIsBoxed ? getBoxTypePair(coor.getMemref().getType()) : TypePair{};
mlir::LLVM::IntegerOverflowFlags nsw =
@@ -2193,8 +2185,7 @@ struct XArrayCoorOpConversion
// components.
mlir::Type elementType =
getLlvmObjectTypeFromBoxType(coor.getMemref().getType());
- while (auto arrayTy =
- mlir::dyn_cast<mlir::LLVM::LLVMArrayType>(elementType))
+ while (auto arrayTy = elementType.dyn_cast<mlir::LLVM::LLVMArrayType>())
elementType = arrayTy.getElementType();
args.clear();
args.push_back(0);
@@ -2284,12 +2275,11 @@ struct CoordinateOpConversion
}
// Boxed type - get the base pointer from the box
- if (mlir::dyn_cast<fir::BaseBoxType>(baseObjectTy))
+ if (baseObjectTy.dyn_cast<fir::BaseBoxType>())
return doRewriteBox(coor, operands, loc, rewriter);
// Reference, pointer or a heap type
- if (mlir::isa<fir::ReferenceType, fir::PointerType, fir::HeapType>(
- baseObjectTy))
+ if (baseObjectTy.isa<fir::ReferenceType, fir::PointerType, fir::HeapType>())
return doRewriteRefOrPtr(coor, llvmObjectTy, operands, loc, rewriter);
return rewriter.notifyMatchFailure(
@@ -2305,7 +2295,7 @@ struct CoordinateOpConversion
}
static bool hasSubDimensions(mlir::Type type) {
- return mlir::isa<fir::SequenceType, fir::RecordType, mlir::TupleType>(type);
+ return type.isa<fir::SequenceType, fir::RecordType, mlir::TupleType>();
}
/// Check whether this form of `!fir.coordinate_of` is supported. These
@@ -2320,14 +2310,14 @@ struct CoordinateOpConversion
bool ptrEle = false;
for (; i < numOfCoors; ++i) {
mlir::Value nxtOpnd = coors[i];
- if (auto arrTy = mlir::dyn_cast<fir::SequenceType>(type)) {
+ if (auto arrTy = type.dyn_cast<fir::SequenceType>()) {
subEle = true;
i += arrTy.getDimension() - 1;
type = arrTy.getEleTy();
- } else if (auto recTy = mlir::dyn_cast<fir::RecordType>(type)) {
+ } else if (auto recTy = type.dyn_cast<fir::RecordType>()) {
subEle = true;
type = recTy.getType(getFieldNumber(recTy, nxtOpnd));
- } else if (auto tupTy = mlir::dyn_cast<mlir::TupleType>(type)) {
+ } else if (auto tupTy = type.dyn_cast<mlir::TupleType>()) {
subEle = true;
type = tupTy.getType(getConstantIntValue(nxtOpnd));
} else {
@@ -2345,14 +2335,14 @@ struct CoordinateOpConversion
static bool arraysHaveKnownShape(mlir::Type type, mlir::ValueRange coors) {
for (std::size_t i = 0, sz = coors.size(); i < sz; ++i) {
mlir::Value nxtOpnd = coors[i];
- if (auto arrTy = mlir::dyn_cast<fir::SequenceType>(type)) {
+ if (auto arrTy = type.dyn_cast<fir::SequenceType>()) {
if (fir::sequenceWithNonConstantShape(arrTy))
return false;
i += arrTy.getDimension() - 1;
type = arrTy.getEleTy();
- } else if (auto strTy = mlir::dyn_cast<fir::RecordType>(type)) {
+ } else if (auto strTy = type.dyn_cast<fir::RecordType>()) {
type = strTy.getType(getFieldNumber(strTy, nxtOpnd));
- } else if (auto strTy = mlir::dyn_cast<mlir::TupleType>(type)) {
+ } else if (auto strTy = type.dyn_cast<mlir::TupleType>()) {
type = strTy.getType(getConstantIntValue(nxtOpnd));
} else {
return true;
@@ -2367,8 +2357,7 @@ struct CoordinateOpConversion
mlir::Location loc,
mlir::ConversionPatternRewriter &rewriter) const {
mlir::Type boxObjTy = coor.getBaseType();
- assert(mlir::dyn_cast<fir::BaseBoxType>(boxObjTy) &&
- "This is not a `fir.box`");
+ assert(boxObjTy.dyn_cast<fir::BaseBoxType>() && "This is not a `fir.box`");
TypePair boxTyPair = getBoxTypePair(boxObjTy);
mlir::Value boxBaseAddr = operands[0];
@@ -2410,7 +2399,7 @@ struct CoordinateOpConversion
mlir::LLVM::IntegerOverflowFlags::nsw;
for (unsigned i = 1, last = operands.size(); i < last; ++i) {
- if (auto arrTy = mlir::dyn_cast<fir::SequenceType>(cpnTy)) {
+ if (auto arrTy = cpnTy.dyn_cast<fir::SequenceType>()) {
if (i != 1)
TODO(loc, "fir.array nested inside other array and/or derived type");
// Applies byte strides from the box. Ignore lower bound from box
@@ -2432,7 +2421,7 @@ struct CoordinateOpConversion
llvm::ArrayRef<mlir::LLVM::GEPArg>{off});
i += arrTy.getDimension() - 1;
cpnTy = arrTy.getEleTy();
- } else if (auto recTy = mlir::dyn_cast<fir::RecordType>(cpnTy)) {
+ } else if (auto recTy = cpnTy.dyn_cast<fir::RecordType>()) {
mlir::Value nxtOpnd = operands[i];
cpnTy = recTy.getType(getFieldNumber(recTy, nxtOpnd));
auto llvmRecTy = lowerTy().convertType(recTy);
@@ -2467,7 +2456,7 @@ struct CoordinateOpConversion
// If only the column is `?`, then we can simply place the column value in
// the 0-th GEP position.
- if (auto arrTy = mlir::dyn_cast<fir::SequenceType>(cpnTy)) {
+ if (auto arrTy = cpnTy.dyn_cast<fir::SequenceType>()) {
if (!hasKnownShape) {
const unsigned sz = arrTy.getDimension();
if (arraysHaveKnownShape(arrTy.getEleTy(),
@@ -2511,29 +2500,29 @@ struct CoordinateOpConversion
dims = dimsLeft - 1;
continue;
}
- cpnTy = mlir::cast<fir::SequenceType>(cpnTy).getEleTy();
+ cpnTy = cpnTy.cast<fir::SequenceType>().getEleTy();
// append array range in reverse (FIR arrays are column-major)
offs.append(arrIdx.rbegin(), arrIdx.rend());
arrIdx.clear();
dims.reset();
continue;
}
- if (auto arrTy = mlir::dyn_cast<fir::SequenceType>(cpnTy)) {
+ if (auto arrTy = cpnTy.dyn_cast<fir::SequenceType>()) {
int d = arrTy.getDimension() - 1;
if (d > 0) {
dims = d;
arrIdx.push_back(nxtOpnd);
continue;
}
- cpnTy = mlir::cast<fir::SequenceType>(cpnTy).getEleTy();
+ cpnTy = cpnTy.cast<fir::SequenceType>().getEleTy();
offs.push_back(nxtOpnd);
continue;
}
// check if the i-th coordinate relates to a field
- if (auto recTy = mlir::dyn_cast<fir::RecordType>(cpnTy))
+ if (auto recTy = cpnTy.dyn_cast<fir::RecordType>())
cpnTy = recTy.getType(getFieldNumber(recTy, nxtOpnd));
- else if (auto tupTy = mlir::dyn_cast<mlir::TupleType>(cpnTy))
+ else if (auto tupTy = cpnTy.dyn_cast<mlir::TupleType>())
cpnTy = tupTy.getType(getConstantIntValue(nxtOpnd));
else
cpnTy = nullptr;
@@ -2562,7 +2551,7 @@ struct FieldIndexOpConversion : public fir::FIROpConversion<fir::FieldIndexOp> {
mlir::LogicalResult
matchAndRewrite(fir::FieldIndexOp field, OpAdaptor adaptor,
mlir::ConversionPatternRewriter &rewriter) const override {
- auto recTy = mlir::cast<fir::RecordType>(field.getOnType());
+ auto recTy = field.getOnType().cast<fir::RecordType>();
unsigned index = recTy.getFieldIndex(field.getFieldId());
if (!fir::hasDynamicSize(recTy)) {
@@ -2615,8 +2604,8 @@ struct TypeDescOpConversion : public fir::FIROpConversion<fir::TypeDescOp> {
matchAndRewrite(fir::TypeDescOp typeDescOp, OpAdaptor adaptor,
mlir::ConversionPatternRewriter &rewriter) const override {
mlir::Type inTy = typeDescOp.getInType();
- assert(mlir::isa<fir::RecordType>(inTy) && "expecting fir.type");
- auto recordType = mlir::dyn_cast<fir::RecordType>(inTy);
+ assert(inTy.isa<fir::RecordType>() && "expecting fir.type");
+ auto recordType = inTy.dyn_cast<fir::RecordType>();
auto module = typeDescOp.getOperation()->getParentOfType<mlir::ModuleOp>();
std::string typeDescName =
fir::NameUniquer::getTypeDescriptorName(recordType.getName());
@@ -2743,7 +2732,7 @@ struct GlobalOpConversion : public fir::FIROpConversion<fir::GlobalOp> {
mlir::Type vecType = mlir::VectorType::get(
insertOp.getType().getShape(), constant.getType());
auto denseAttr = mlir::DenseElementsAttr::get(
- mlir::cast<mlir::ShapedType>(vecType), constant.getValue());
+ vecType.cast<mlir::ShapedType>(), constant.getValue());
rewriter.setInsertionPointAfter(insertOp);
rewriter.replaceOpWithNewOp<mlir::arith::ConstantOp>(
insertOp, seqTyAttr, denseAttr);
@@ -2819,7 +2808,7 @@ struct LoadOpConversion : public fir::FIROpConversion<fir::LoadOp> {
matchAndRewrite(fir::LoadOp load, OpAdaptor adaptor,
mlir::ConversionPatternRewriter &rewriter) const override {
mlir::Type llvmLoadTy = convertObjectType(load.getType());
- if (auto boxTy = mlir::dyn_cast<fir::BaseBoxType>(load.getType())) {
+ if (auto boxTy = load.getType().dyn_cast<fir::BaseBoxType>()) {
// 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<fir.box> and fir.box end up being the same llvm types and
@@ -2932,7 +2921,7 @@ struct SelectCaseOpConversion : public fir::FIROpConversion<fir::SelectCaseOp> {
llvm::ArrayRef<mlir::Attribute> cases = caseOp.getCases().getValue();
// Type can be CHARACTER, INTEGER, or LOGICAL (C1145)
auto ty = caseOp.getSelector().getType();
- if (mlir::isa<fir::CharacterType>(ty)) {
+ if (ty.isa<fir::CharacterType>()) {
TODO(caseOp.getLoc(), "fir.select_case codegen with character type");
return mlir::failure();
}
@@ -2946,25 +2935,25 @@ struct SelectCaseOpConversion : public fir::FIROpConversion<fir::SelectCaseOp> {
*caseOp.getCompareOperands(adaptor.getOperands(), t);
mlir::Value caseArg = *(cmpOps.value().begin());
mlir::Attribute attr = cases[t];
- if (mlir::isa<fir::PointIntervalAttr>(attr)) {
+ if (attr.isa<fir::PointIntervalAttr>()) {
auto cmp = rewriter.create<mlir::LLVM::ICmpOp>(
loc, mlir::LLVM::ICmpPredicate::eq, selector, caseArg);
genCaseLadderStep(loc, cmp, dest, destOps, rewriter);
continue;
}
- if (mlir::isa<fir::LowerBoundAttr>(attr)) {
+ if (attr.isa<fir::LowerBoundAttr>()) {
auto cmp = rewriter.create<mlir::LLVM::ICmpOp>(
loc, mlir::LLVM::ICmpPredicate::sle, caseArg, selector);
genCaseLadderStep(loc, cmp, dest, destOps, rewriter);
continue;
}
- if (mlir::isa<fir::UpperBoundAttr>(attr)) {
+ if (attr.isa<fir::UpperBoundAttr>()) {
auto cmp = rewriter.create<mlir::LLVM::ICmpOp>(
loc, mlir::LLVM::ICmpPredicate::sle, selector, caseArg);
genCaseLadderStep(loc, cmp, dest, destOps, rewriter);
continue;
}
- if (mlir::isa<fir::ClosedIntervalAttr>(attr)) {
+ if (attr.isa<fir::ClosedIntervalAttr>()) {
auto cmp = rewriter.create<mlir::LLVM::ICmpOp>(
loc, mlir::LLVM::ICmpPredicate::sle, caseArg, selector);
auto *thisBlock = rewriter.getInsertionBlock();
@@ -2980,7 +2969,7 @@ struct SelectCaseOpConversion : public fir::FIROpConversion<fir::SelectCaseOp> {
rewriter.setInsertionPointToEnd(newBlock2);
continue;
}
- assert(mlir::isa<mlir::UnitAttr>(attr));
+ assert(attr.isa<mlir::UnitAttr>());
assert((t + 1 == conds) && "unit must be last");
genBrOp(caseOp, dest, destOps, rewriter);
}
@@ -3008,7 +2997,7 @@ static void selectMatchAndRewrite(const fir::LLVMTypeConverter &lowering,
mlir::Block *dest = select.getSuccessor(t);
auto destOps = select.getSuccessorOperands(adaptor.getOperands(), t);
const mlir::Attribute &attr = cases[t];
- if (auto intAttr = mlir::dyn_cast<mlir::IntegerAttr>(attr)) {
+ if (auto intAttr = attr.template dyn_cast<mlir::IntegerAttr>()) {
destinations.push_back(dest);
destinationsOperands.push_back(destOps ? *destOps : mlir::ValueRange{});
caseValues.push_back(intAttr.getInt());
@@ -3082,7 +3071,7 @@ struct StoreOpConversion : public fir::FIROpConversion<fir::StoreOp> {
mlir::Location loc = store.getLoc();
mlir::Type storeTy = store.getValue().getType();
mlir::LLVM::StoreOp newStoreOp;
- if (auto boxTy = mlir::dyn_cast<fir::BaseBoxType>(storeTy)) {
+ if (auto boxTy = storeTy.dyn_cast<fir::BaseBoxType>()) {
// fir.box value is actually in memory, load it first before storing it.
mlir::Type llvmBoxTy = lowerTy().convertBoxTypeAsStruct(boxTy);
auto val = rewriter.create<mlir::LLVM::LoadOp>(loc, llvmBoxTy,
@@ -3197,9 +3186,9 @@ struct IsPresentOpConversion : public fir::FIROpConversion<fir::IsPresentOp> {
mlir::Location loc = isPresent.getLoc();
auto ptr = adaptor.getOperands()[0];
- if (mlir::isa<fir::BoxCharType>(isPresent.getVal().getType())) {
+ if (isPresent.getVal().getType().isa<fir::BoxCharType>()) {
[[maybe_unused]] auto structTy =
- mlir::cast<mlir::LLVM::LLVMStructType>(ptr.getType());
+ ptr.getType().cast<mlir::LLVM::LLVMStructType>();
assert(!structTy.isOpaque() && !structTy.getBody().empty());
ptr = rewriter.create<mlir::LLVM::ExtractValueOp>(loc, ptr, 0);
@@ -3225,8 +3214,8 @@ struct AbsentOpConversion : public fir::FIROpConversion<fir::AbsentOp> {
mlir::Type ty = convertType(absent.getType());
mlir::Location loc = absent.getLoc();
- if (mlir::isa<fir::BoxCharType>(absent.getType())) {
- auto structTy = mlir::cast<mlir::LLVM::LLVMStructType>(ty);
+ if (absent.getType().isa<fir::BoxCharType>()) {
+ auto structTy = ty.cast<mlir::LLVM::LLVMStructType>();
assert(!structTy.isOpaque() && !structTy.getBody().empty());
auto undefStruct = rewriter.create<mlir::LLVM::UndefOp>(loc, ty);
auto nullField =
diff --git a/flang/lib/Optimizer/CodeGen/FIROpPatterns.cpp b/flang/lib/Optimizer/CodeGen/FIROpPatterns.cpp
index 00c5f77cde7ce8..26871d88881555 100644
--- a/flang/lib/Optimizer/CodeGen/FIROpPatterns.cpp
+++ b/flang/lib/Optimizer/CodeGen/FIROpPatterns.cpp
@@ -20,7 +20,7 @@ static inline mlir::Type getLlvmPtrType(mlir::MLIRContext *context,
}
static unsigned getTypeDescFieldId(mlir::Type ty) {
- auto isArray = mlir::isa<fir::SequenceType>(fir::dyn_cast_ptrOrBoxEleTy(ty));
+ auto isArray = fir::dyn_cast_ptrOrBoxEleTy(ty).isa<fir::SequenceType>();
return isArray ? kOptTypePtrPosInBox : kDimsPosInBox;
}
@@ -37,7 +37,7 @@ ConvertFIRToLLVMPattern::ConvertFIRToLLVMPattern(
// reference.
mlir::Type
ConvertFIRToLLVMPattern::convertObjectType(mlir::Type firType) const {
- if (auto boxTy = mlir::dyn_cast<fir::BaseBoxType>(firType))
+ if (auto boxTy = firType.dyn_cast<fir::BaseBoxType>())
return lowerTy().convertBoxTypeAsStruct(boxTy);
return lowerTy().convertType(firType);
}
@@ -69,7 +69,7 @@ ConvertFIRToLLVMPattern::integerCast(mlir::Location loc,
auto valTy = val.getType();
// If the value was not yet lowered, lower its type so that it can
// be used in getPrimitiveTypeSizeInBits.
- if (!mlir::isa<mlir::IntegerType>(valTy))
+ if (!valTy.isa<mlir::IntegerType>())
valTy = convertType(valTy);
auto toSize = mlir::LLVM::getPrimitiveTypeSizeInBits(ty);
auto fromSize = mlir::LLVM::getPrimitiveTypeSizeInBits(valTy);
@@ -91,7 +91,7 @@ ConvertFIRToLLVMPattern::getBoxTypePair(mlir::Type firBoxTy) const {
mlir::Value ConvertFIRToLLVMPattern::getValueFromBox(
mlir::Location loc, TypePair boxTy, mlir::Value box, mlir::Type resultTy,
mlir::ConversionPatternRewriter &rewriter, int boxValue) const {
- if (mlir::isa<mlir::LLVM::LLVMPointerType>(box.getType())) {
+ if (box.getType().isa<mlir::LLVM::LLVMPointerType>()) {
auto pty = getLlvmPtrType(resultTy.getContext());
auto p = rewriter.create<mlir::LLVM::GEPOp>(
loc, pty, boxTy.llvm, box,
@@ -133,7 +133,7 @@ llvm::SmallVector<mlir::Value, 3> ConvertFIRToLLVMPattern::getDimsFromBox(
mlir::Value ConvertFIRToLLVMPattern::loadDimFieldFromBox(
mlir::Location loc, TypePair boxTy, mlir::Value box, mlir::Value dim,
int off, mlir::Type ty, mlir::ConversionPatternRewriter &rewriter) const {
- assert(mlir::isa<mlir::LLVM::LLVMPointerType>(box.getType()) &&
+ assert(box.getType().isa<mlir::LLVM::LLVMPointerType>() &&
"descriptor inquiry with runtime dim can only be done on descriptor "
"in memory");
mlir::LLVM::GEPOp p = genGEP(loc, boxTy.llvm, rewriter, box, 0,
@@ -146,7 +146,7 @@ mlir::Value ConvertFIRToLLVMPattern::loadDimFieldFromBox(
mlir::Value ConvertFIRToLLVMPattern::getDimFieldFromBox(
mlir::Location loc, TypePair boxTy, mlir::Value box, int dim, int off,
mlir::Type ty, mlir::ConversionPatternRewriter &rewriter) const {
- if (mlir::isa<mlir::LLVM::LLVMPointerType>(box.getType())) {
+ if (box.getType().isa<mlir::LLVM::LLVMPointerType>()) {
mlir::LLVM::GEPOp p = genGEP(loc, boxTy.llvm, rewriter, box, 0,
static_cast<int>(kDimsPosInBox), dim, off);
auto loadOp = rewriter.create<mlir::LLVM::LoadOp>(loc, ty, p);
@@ -184,12 +184,12 @@ mlir::Value ConvertFIRToLLVMPattern::getElementSizeFromBox(
mlir::Type ConvertFIRToLLVMPattern::getBoxEleTy(
mlir::Type type, llvm::ArrayRef<std::int64_t> indexes) const {
for (unsigned i : indexes) {
- if (auto t = mlir::dyn_cast<mlir::LLVM::LLVMStructType>(type)) {
+ if (auto t = type.dyn_cast<mlir::LLVM::LLVMStructType>()) {
assert(!t.isOpaque() && i < t.getBody().size());
type = t.getBody()[i];
- } else if (auto t = mlir::dyn_cast<mlir::LLVM::LLVMArrayType>(type)) {
+ } else if (auto t = type.dyn_cast<mlir::LLVM::LLVMArrayType>()) {
type = t.getElementType();
- } else if (auto t = mlir::dyn_cast<mlir::VectorType>(type)) {
+ } else if (auto t = type.dyn_cast<mlir::VectorType>()) {
type = t.getElementType();
} else {
fir::emitFatalError(mlir::UnknownLoc::get(type.getContext()),
diff --git a/flang/lib/Optimizer/CodeGen/PreCGRewrite.cpp b/flang/lib/Optimizer/CodeGen/PreCGRewrite.cpp
index ce7ee22d5d7744..665bf09b8fc33b 100644
--- a/flang/lib/Optimizer/CodeGen/PreCGRewrite.cpp
+++ b/flang/lib/Optimizer/CodeGen/PreCGRewrite.cpp
@@ -86,10 +86,10 @@ class EmboxConversion : public mlir::OpRewritePattern<fir::EmboxOp> {
// If the embox does not include a shape, then do not convert it
if (auto shapeVal = embox.getShape())
return rewriteDynamicShape(embox, rewriter, shapeVal);
- if (mlir::isa<fir::ClassType>(embox.getType()))
+ if (embox.getType().isa<fir::ClassType>())
TODO(embox.getLoc(), "embox conversion for fir.class type");
- if (auto boxTy = mlir::dyn_cast<fir::BoxType>(embox.getType()))
- if (auto seqTy = mlir::dyn_cast<fir::SequenceType>(boxTy.getEleTy()))
+ if (auto boxTy = embox.getType().dyn_cast<fir::BoxType>())
+ if (auto seqTy = boxTy.getEleTy().dyn_cast<fir::SequenceType>())
if (!seqTy.hasDynamicExtents())
return rewriteStaticShape(embox, rewriter, seqTy);
return mlir::failure();
@@ -294,9 +294,10 @@ class CodeGenRewrite : public fir::impl::CodeGenRewriteBase<CodeGenRewrite> {
target.addIllegalOp<fir::ReboxOp>();
target.addIllegalOp<fir::DeclareOp>();
target.addDynamicallyLegalOp<fir::EmboxOp>([](fir::EmboxOp embox) {
- return !(embox.getShape() ||
- mlir::isa<fir::SequenceType>(
- mlir::cast<fir::BaseBoxType>(embox.getType()).getEleTy()));
+ return !(embox.getShape() || embox.getType()
+ .cast<fir::BaseBoxType>()
+ .getEleTy()
+ .isa<fir::SequenceType>());
});
mlir::RewritePatternSet patterns(&context);
fir::populatePreCGRewritePatterns(patterns);
diff --git a/flang/lib/Optimizer/CodeGen/TBAABuilder.cpp b/flang/lib/Optimizer/CodeGen/TBAABuilder.cpp
index a21384e8d59462..b1b0e9b766a625 100644
--- a/flang/lib/Optimizer/CodeGen/TBAABuilder.cpp
+++ b/flang/lib/Optimizer/CodeGen/TBAABuilder.cpp
@@ -120,7 +120,7 @@ void TBAABuilder::attachTBAATag(AliasAnalysisOpInterface op, Type baseFIRType,
// with both data and descriptor accesses.
// Conservatively set any-access tag if there is any descriptor member.
tbaaTagSym = getAnyAccessTag(func);
- } else if (mlir::isa<fir::BaseBoxType>(baseFIRType)) {
+ } else if (baseFIRType.isa<fir::BaseBoxType>()) {
tbaaTagSym = getBoxAccessTag(baseFIRType, accessFIRType, gep, func);
} else {
tbaaTagSym = getDataAccessTag(baseFIRType, accessFIRType, gep, func);
diff --git a/flang/lib/Optimizer/CodeGen/Target.cpp b/flang/lib/Optimizer/CodeGen/Target.cpp
index 652e2bddc1b896..cea7a1f97f419f 100644
--- a/flang/lib/Optimizer/CodeGen/Target.cpp
+++ b/flang/lib/Optimizer/CodeGen/Target.cpp
@@ -41,9 +41,9 @@ llvm::StringRef Attributes::getIntExtensionAttrName() const {
static const llvm::fltSemantics &floatToSemantics(const KindMapping &kindMap,
mlir::Type type) {
assert(isa_real(type));
- if (auto ty = mlir::dyn_cast<fir::RealType>(type))
+ if (auto ty = type.dyn_cast<fir::RealType>())
return kindMap.getFloatSemantics(ty.getFKind());
- return mlir::cast<mlir::FloatType>(type).getFloatSemantics();
+ return type.cast<mlir::FloatType>().getFloatSemantics();
}
static void typeTodo(const llvm::fltSemantics *sem, mlir::Location loc,
diff --git a/flang/lib/Optimizer/CodeGen/TargetRewrite.cpp b/flang/lib/Optimizer/CodeGen/TargetRewrite.cpp
index 616de78d002609..7bf31ec3869598 100644
--- a/flang/lib/Optimizer/CodeGen/TargetRewrite.cpp
+++ b/flang/lib/Optimizer/CodeGen/TargetRewrite.cpp
@@ -137,7 +137,7 @@ class TargetRewrite : public fir::impl::TargetRewritePassBase<TargetRewrite> {
if (!hasPortableSignature(dispatch.getFunctionType(), op))
convertCallOp(dispatch);
} else if (auto addr = mlir::dyn_cast<fir::AddrOfOp>(op)) {
- if (mlir::isa<mlir::FunctionType>(addr.getType()) &&
+ if (addr.getType().isa<mlir::FunctionType>() &&
!hasPortableSignature(addr.getType(), op))
convertAddrOp(addr);
}
@@ -601,7 +601,7 @@ class TargetRewrite : public fir::impl::TargetRewritePassBase<TargetRewrite> {
/// Taking the address of a function. Modify the signature as needed.
void convertAddrOp(fir::AddrOfOp addrOp) {
rewriter->setInsertionPoint(addrOp);
- auto addrTy = mlir::cast<mlir::FunctionType>(addrOp.getType());
+ auto addrTy = addrOp.getType().cast<mlir::FunctionType>();
fir::CodeGenSpecifics::Marshalling newInTyAndAttrs;
llvm::SmallVector<mlir::Type> newResTys;
auto loc = addrOp.getLoc();
@@ -705,23 +705,22 @@ class TargetRewrite : public fir::impl::TargetRewritePassBase<TargetRewrite> {
/// return `true`. Otherwise, the signature is not portable and `false` is
/// returned.
bool hasPortableSignature(mlir::Type signature, mlir::Operation *op) {
- assert(mlir::isa<mlir::FunctionType>(signature));
- auto func = mlir::dyn_cast<mlir::FunctionType>(signature);
+ assert(signature.isa<mlir::FunctionType>());
+ auto func = signature.dyn_cast<mlir::FunctionType>();
bool hasCCallingConv = isFuncWithCCallingConvention(op);
for (auto ty : func.getResults())
- if ((mlir::isa<fir::BoxCharType>(ty) && !noCharacterConversion) ||
+ if ((ty.isa<fir::BoxCharType>() && !noCharacterConversion) ||
(fir::isa_complex(ty) && !noComplexConversion) ||
- (mlir::isa<mlir::IntegerType>(ty) && hasCCallingConv)) {
+ (ty.isa<mlir::IntegerType>() && hasCCallingConv)) {
LLVM_DEBUG(llvm::dbgs() << "rewrite " << signature << " for target\n");
return false;
}
for (auto ty : func.getInputs())
- if (((mlir::isa<fir::BoxCharType>(ty) ||
- fir::isCharacterProcedureTuple(ty)) &&
+ if (((ty.isa<fir::BoxCharType>() || fir::isCharacterProcedureTuple(ty)) &&
!noCharacterConversion) ||
(fir::isa_complex(ty) && !noComplexConversion) ||
- (mlir::isa<mlir::IntegerType>(ty) && hasCCallingConv) ||
- (mlir::isa<fir::RecordType>(ty) && !noStructConversion)) {
+ (ty.isa<mlir::IntegerType>() && hasCCallingConv) ||
+ (ty.isa<fir::RecordType>() && !noStructConversion)) {
LLVM_DEBUG(llvm::dbgs() << "rewrite " << signature << " for target\n");
return false;
}
@@ -741,7 +740,7 @@ class TargetRewrite : public fir::impl::TargetRewritePassBase<TargetRewrite> {
/// Rewrite the signatures and body of the `FuncOp`s in the module for
/// the immediately subsequent target code gen.
void convertSignature(mlir::func::FuncOp func) {
- auto funcTy = mlir::cast<mlir::FunctionType>(func.getFunctionType());
+ auto funcTy = func.getFunctionType().cast<mlir::FunctionType>();
if (hasPortableSignature(funcTy, func) && !hasHostAssociations(func))
return;
llvm::SmallVector<mlir::Type> newResTys;
diff --git a/flang/lib/Optimizer/CodeGen/TypeConverter.cpp b/flang/lib/Optimizer/CodeGen/TypeConverter.cpp
index fb2ec3f0b2f5e7..8fa423f35806ef 100644
--- a/flang/lib/Optimizer/CodeGen/TypeConverter.cpp
+++ b/flang/lib/Optimizer/CodeGen/TypeConverter.cpp
@@ -103,10 +103,10 @@ LLVMTypeConverter::LLVMTypeConverter(mlir::ModuleOp module, bool applyTBAA,
for (auto mem : tuple.getTypes()) {
// Prevent fir.box from degenerating to a pointer to a descriptor in the
// context of a tuple type.
- if (auto box = mlir::dyn_cast<fir::BaseBoxType>(mem))
+ if (auto box = mem.dyn_cast<fir::BaseBoxType>())
members.push_back(convertBoxTypeAsStruct(box));
else
- members.push_back(mlir::cast<mlir::Type>(convertType(mem)));
+ members.push_back(convertType(mem).cast<mlir::Type>());
}
return mlir::LLVM::LLVMStructType::getLiteral(&getContext(), members,
/*isPacked=*/false);
@@ -181,10 +181,10 @@ std::optional<mlir::LogicalResult> LLVMTypeConverter::convertRecordType(
for (auto mem : derived.getTypeList()) {
// Prevent fir.box from degenerating to a pointer to a descriptor in the
// context of a record type.
- if (auto box = mlir::dyn_cast<fir::BaseBoxType>(mem.second))
+ if (auto box = mem.second.dyn_cast<fir::BaseBoxType>())
members.push_back(convertBoxTypeAsStruct(box));
else
- members.push_back(mlir::cast<mlir::Type>(convertType(mem.second)));
+ members.push_back(convertType(mem.second).cast<mlir::Type>());
}
if (mlir::failed(st.setBody(members, /*isPacked=*/false)))
return mlir::failure();
@@ -196,7 +196,7 @@ std::optional<mlir::LogicalResult> LLVMTypeConverter::convertRecordType(
// Extended descriptors are required for derived types.
bool LLVMTypeConverter::requiresExtendedDesc(mlir::Type boxElementType) const {
auto eleTy = fir::unwrapSequenceType(boxElementType);
- return mlir::isa<fir::RecordType>(eleTy);
+ return eleTy.isa<fir::RecordType>();
}
// This corresponds to the descriptor as defined in ISO_Fortran_binding.h and
@@ -211,8 +211,7 @@ mlir::Type LLVMTypeConverter::convertBoxTypeAsStruct(BaseBoxType box,
ele = removeIndirection;
auto eleTy = convertType(ele);
// base_addr*
- if (mlir::isa<SequenceType>(ele) &&
- mlir::isa<mlir::LLVM::LLVMPointerType>(eleTy))
+ if (ele.isa<SequenceType>() && eleTy.isa<mlir::LLVM::LLVMPointerType>())
dataDescFields.push_back(eleTy);
else
dataDescFields.push_back(
@@ -237,7 +236,7 @@ mlir::Type LLVMTypeConverter::convertBoxTypeAsStruct(BaseBoxType box,
getDescFieldTypeModel<kF18AddendumPosInBox>()(&getContext()));
// [dims]
if (rank == unknownRank()) {
- if (auto seqTy = mlir::dyn_cast<SequenceType>(ele))
+ if (auto seqTy = ele.dyn_cast<SequenceType>())
rank = seqTy.getDimension();
else
rank = 0;
@@ -253,8 +252,7 @@ mlir::Type LLVMTypeConverter::convertBoxTypeAsStruct(BaseBoxType box,
auto rowTy =
getExtendedDescFieldTypeModel<kOptRowTypePosInBox>()(&getContext());
dataDescFields.push_back(mlir::LLVM::LLVMArrayType::get(rowTy, 1));
- if (auto recTy =
- mlir::dyn_cast<fir::RecordType>(fir::unwrapSequenceType(ele)))
+ if (auto recTy = fir::unwrapSequenceType(ele).dyn_cast<fir::RecordType>())
if (recTy.getNumLenParams() > 0) {
// The descriptor design needs to be clarified regarding the number of
// length parameters in the addendum. Since it can change for
diff --git a/flang/lib/Optimizer/Dialect/FIRAttr.cpp b/flang/lib/Optimizer/Dialect/FIRAttr.cpp
index 9ea3a0568f6916..e43710f5627ee0 100644
--- a/flang/lib/Optimizer/Dialect/FIRAttr.cpp
+++ b/flang/lib/Optimizer/Dialect/FIRAttr.cpp
@@ -264,23 +264,23 @@ void fir::FortranVariableFlagsAttr::print(mlir::AsmPrinter &printer) const {
void fir::printFirAttribute(FIROpsDialect *dialect, mlir::Attribute attr,
mlir::DialectAsmPrinter &p) {
auto &os = p.getStream();
- if (auto exact = mlir::dyn_cast<fir::ExactTypeAttr>(attr)) {
+ if (auto exact = attr.dyn_cast<fir::ExactTypeAttr>()) {
os << fir::ExactTypeAttr::getAttrName() << '<';
p.printType(exact.getType());
os << '>';
- } else if (auto sub = mlir::dyn_cast<fir::SubclassAttr>(attr)) {
+ } else if (auto sub = attr.dyn_cast<fir::SubclassAttr>()) {
os << fir::SubclassAttr::getAttrName() << '<';
p.printType(sub.getType());
os << '>';
- } else if (mlir::dyn_cast_or_null<fir::PointIntervalAttr>(attr)) {
+ } else if (attr.dyn_cast_or_null<fir::PointIntervalAttr>()) {
os << fir::PointIntervalAttr::getAttrName();
- } else if (mlir::dyn_cast_or_null<fir::ClosedIntervalAttr>(attr)) {
+ } else if (attr.dyn_cast_or_null<fir::ClosedIntervalAttr>()) {
os << fir::ClosedIntervalAttr::getAttrName();
- } else if (mlir::dyn_cast_or_null<fir::LowerBoundAttr>(attr)) {
+ } else if (attr.dyn_cast_or_null<fir::LowerBoundAttr>()) {
os << fir::LowerBoundAttr::getAttrName();
- } else if (mlir::dyn_cast_or_null<fir::UpperBoundAttr>(attr)) {
+ } else if (attr.dyn_cast_or_null<fir::UpperBoundAttr>()) {
os << fir::UpperBoundAttr::getAttrName();
- } else if (auto a = mlir::dyn_cast_or_null<fir::RealAttr>(attr)) {
+ } else if (auto a = attr.dyn_cast_or_null<fir::RealAttr>()) {
os << fir::RealAttr::getAttrName() << '<' << a.getFKind() << ", i x";
llvm::SmallString<40> ss;
a.getValue().bitcastToAPInt().toStringUnsigned(ss, 16);
diff --git a/flang/lib/Optimizer/Dialect/FIROps.cpp b/flang/lib/Optimizer/Dialect/FIROps.cpp
index a39087aeb358b9..24af94f9b90a1d 100644
--- a/flang/lib/Optimizer/Dialect/FIROps.cpp
+++ b/flang/lib/Optimizer/Dialect/FIROps.cpp
@@ -57,7 +57,7 @@ static void propagateAttributes(mlir::Operation *fromOp,
static bool verifyInType(mlir::Type inType,
llvm::SmallVectorImpl<llvm::StringRef> &visited,
unsigned dynamicExtents = 0) {
- if (auto st = mlir::dyn_cast<fir::SequenceType>(inType)) {
+ if (auto st = inType.dyn_cast<fir::SequenceType>()) {
auto shape = st.getShape();
if (shape.size() == 0)
return true;
@@ -67,7 +67,7 @@ static bool verifyInType(mlir::Type inType,
if (dynamicExtents-- == 0)
return true;
}
- } else if (auto rt = mlir::dyn_cast<fir::RecordType>(inType)) {
+ } else if (auto rt = inType.dyn_cast<fir::RecordType>()) {
// don't recurse if we're already visiting this one
if (llvm::is_contained(visited, rt.getName()))
return false;
@@ -84,13 +84,13 @@ static bool verifyInType(mlir::Type inType,
static bool verifyTypeParamCount(mlir::Type inType, unsigned numParams) {
auto ty = fir::unwrapSequenceType(inType);
if (numParams > 0) {
- if (auto recTy = mlir::dyn_cast<fir::RecordType>(ty))
+ if (auto recTy = ty.dyn_cast<fir::RecordType>())
return numParams != recTy.getNumLenParams();
- if (auto chrTy = mlir::dyn_cast<fir::CharacterType>(ty))
+ if (auto chrTy = ty.dyn_cast<fir::CharacterType>())
return !(numParams == 1 && chrTy.hasDynamicLen());
return true;
}
- if (auto chrTy = mlir::dyn_cast<fir::CharacterType>(ty))
+ if (auto chrTy = ty.dyn_cast<fir::CharacterType>())
return !chrTy.hasConstantLen();
return false;
}
@@ -171,13 +171,13 @@ static void printAllocatableOp(mlir::OpAsmPrinter &p, OP &op) {
/// Create a legal memory reference as return type
static mlir::Type wrapAllocaResultType(mlir::Type intype) {
// FIR semantics: memory references to memory references are disallowed
- if (mlir::isa<fir::ReferenceType>(intype))
+ if (intype.isa<fir::ReferenceType>())
return {};
return fir::ReferenceType::get(intype);
}
mlir::Type fir::AllocaOp::getAllocatedType() {
- return mlir::cast<fir::ReferenceType>(getType()).getEleTy();
+ return getType().cast<fir::ReferenceType>().getEleTy();
}
mlir::Type fir::AllocaOp::getRefTy(mlir::Type ty) {
@@ -270,7 +270,7 @@ mlir::LogicalResult fir::AllocaOp::verify() {
if (verifyTypeParamCount(getInType(), numLenParams()))
return emitOpError("LEN params do not correspond to type");
mlir::Type outType = getType();
- if (!mlir::isa<fir::ReferenceType>(outType))
+ if (!outType.isa<fir::ReferenceType>())
return emitOpError("must be a !fir.ref type");
if (fir::isa_unknown_size_box(fir::dyn_cast_ptrEleTy(outType)))
return emitOpError("cannot allocate !fir.box of unknown rank or type");
@@ -286,14 +286,14 @@ static mlir::Type wrapAllocMemResultType(mlir::Type intype) {
// Fortran semantics: C852 an entity cannot be both ALLOCATABLE and POINTER
// 8.5.3 note 1 prohibits ALLOCATABLE procedures as well
// FIR semantics: one may not allocate a memory reference value
- if (mlir::isa<fir::ReferenceType, fir::HeapType, fir::PointerType,
- mlir::FunctionType>(intype))
+ if (intype.isa<fir::ReferenceType, fir::HeapType, fir::PointerType,
+ mlir::FunctionType>())
return {};
return fir::HeapType::get(intype);
}
mlir::Type fir::AllocMemOp::getAllocatedType() {
- return mlir::cast<fir::HeapType>(getType()).getEleTy();
+ return getType().cast<fir::HeapType>().getEleTy();
}
mlir::Type fir::AllocMemOp::getRefTy(mlir::Type ty) {
@@ -348,7 +348,7 @@ mlir::LogicalResult fir::AllocMemOp::verify() {
if (verifyTypeParamCount(getInType(), numLenParams()))
return emitOpError("LEN params do not correspond to type");
mlir::Type outType = getType();
- if (!mlir::dyn_cast<fir::HeapType>(outType))
+ if (!outType.dyn_cast<fir::HeapType>())
return emitOpError("must be a !fir.heap type");
if (fir::isa_unknown_size_box(fir::dyn_cast_ptrEleTy(outType)))
return emitOpError("cannot allocate !fir.box of unknown rank or type");
@@ -364,13 +364,13 @@ mlir::LogicalResult fir::AllocMemOp::verify() {
static bool validTypeParams(mlir::Type dynTy, mlir::ValueRange typeParams) {
dynTy = fir::unwrapAllRefAndSeqType(dynTy);
// A box value will contain type parameter values itself.
- if (mlir::isa<fir::BoxType>(dynTy))
+ if (dynTy.isa<fir::BoxType>())
return typeParams.size() == 0;
// Derived type must have all type parameters satisfied.
- if (auto recTy = mlir::dyn_cast<fir::RecordType>(dynTy))
+ if (auto recTy = dynTy.dyn_cast<fir::RecordType>())
return typeParams.size() == recTy.getNumLenParams();
// Characters with non-constant LEN must have a type parameter value.
- if (auto charTy = mlir::dyn_cast<fir::CharacterType>(dynTy))
+ if (auto charTy = dynTy.dyn_cast<fir::CharacterType>())
if (charTy.hasDynamicLen())
return typeParams.size() == 1;
// Otherwise, any type parameters are invalid.
@@ -379,7 +379,7 @@ static bool validTypeParams(mlir::Type dynTy, mlir::ValueRange typeParams) {
mlir::LogicalResult fir::ArrayCoorOp::verify() {
auto eleTy = fir::dyn_cast_ptrOrBoxEleTy(getMemref().getType());
- auto arrTy = mlir::dyn_cast<fir::SequenceType>(eleTy);
+ auto arrTy = eleTy.dyn_cast<fir::SequenceType>();
if (!arrTy)
return emitOpError("must be a reference to an array");
auto arrDim = arrTy.getDimension();
@@ -387,14 +387,14 @@ mlir::LogicalResult fir::ArrayCoorOp::verify() {
if (auto shapeOp = getShape()) {
auto shapeTy = shapeOp.getType();
unsigned shapeTyRank = 0;
- if (auto s = mlir::dyn_cast<fir::ShapeType>(shapeTy)) {
+ if (auto s = shapeTy.dyn_cast<fir::ShapeType>()) {
shapeTyRank = s.getRank();
- } else if (auto ss = mlir::dyn_cast<fir::ShapeShiftType>(shapeTy)) {
+ } else if (auto ss = shapeTy.dyn_cast<fir::ShapeShiftType>()) {
shapeTyRank = ss.getRank();
} else {
- auto s = mlir::cast<fir::ShiftType>(shapeTy);
+ auto s = shapeTy.cast<fir::ShiftType>();
shapeTyRank = s.getRank();
- if (!mlir::isa<fir::BaseBoxType>(getMemref().getType()))
+ if (!getMemref().getType().isa<fir::BaseBoxType>())
return emitOpError("shift can only be provided with fir.box memref");
}
if (arrDim && arrDim != shapeTyRank)
@@ -407,7 +407,7 @@ mlir::LogicalResult fir::ArrayCoorOp::verify() {
if (auto sl = mlir::dyn_cast_or_null<fir::SliceOp>(sliceOp.getDefiningOp()))
if (!sl.getSubstr().empty())
return emitOpError("array_coor cannot take a slice with substring");
- if (auto sliceTy = mlir::dyn_cast<fir::SliceType>(sliceOp.getType()))
+ if (auto sliceTy = sliceOp.getType().dyn_cast<fir::SliceType>())
if (sliceTy.getRank() != arrDim)
return emitOpError("rank of dimension in slice mismatched");
}
@@ -422,13 +422,13 @@ mlir::LogicalResult fir::ArrayCoorOp::verify() {
//===----------------------------------------------------------------------===//
static mlir::Type adjustedElementType(mlir::Type t) {
- if (auto ty = mlir::dyn_cast<fir::ReferenceType>(t)) {
+ if (auto ty = t.dyn_cast<fir::ReferenceType>()) {
auto eleTy = ty.getEleTy();
if (fir::isa_char(eleTy))
return eleTy;
if (fir::isa_derived(eleTy))
return eleTy;
- if (mlir::isa<fir::SequenceType>(eleTy))
+ if (eleTy.isa<fir::SequenceType>())
return eleTy;
}
return t;
@@ -448,7 +448,7 @@ std::vector<mlir::Value> fir::ArrayLoadOp::getExtents() {
mlir::LogicalResult fir::ArrayLoadOp::verify() {
auto eleTy = fir::dyn_cast_ptrOrBoxEleTy(getMemref().getType());
- auto arrTy = mlir::dyn_cast<fir::SequenceType>(eleTy);
+ auto arrTy = eleTy.dyn_cast<fir::SequenceType>();
if (!arrTy)
return emitOpError("must be a reference to an array");
auto arrDim = arrTy.getDimension();
@@ -456,14 +456,14 @@ mlir::LogicalResult fir::ArrayLoadOp::verify() {
if (auto shapeOp = getShape()) {
auto shapeTy = shapeOp.getType();
unsigned shapeTyRank = 0u;
- if (auto s = mlir::dyn_cast<fir::ShapeType>(shapeTy)) {
+ if (auto s = shapeTy.dyn_cast<fir::ShapeType>()) {
shapeTyRank = s.getRank();
- } else if (auto ss = mlir::dyn_cast<fir::ShapeShiftType>(shapeTy)) {
+ } else if (auto ss = shapeTy.dyn_cast<fir::ShapeShiftType>()) {
shapeTyRank = ss.getRank();
} else {
- auto s = mlir::cast<fir::ShiftType>(shapeTy);
+ auto s = shapeTy.cast<fir::ShiftType>();
shapeTyRank = s.getRank();
- if (!mlir::isa<fir::BaseBoxType>(getMemref().getType()))
+ if (!getMemref().getType().isa<fir::BaseBoxType>())
return emitOpError("shift can only be provided with fir.box memref");
}
if (arrDim && arrDim != shapeTyRank)
@@ -474,7 +474,7 @@ mlir::LogicalResult fir::ArrayLoadOp::verify() {
if (auto sl = mlir::dyn_cast_or_null<fir::SliceOp>(sliceOp.getDefiningOp()))
if (!sl.getSubstr().empty())
return emitOpError("array_load cannot take a slice with substring");
- if (auto sliceTy = mlir::dyn_cast<fir::SliceType>(sliceOp.getType()))
+ if (auto sliceTy = sliceOp.getType().dyn_cast<fir::SliceType>())
if (sliceTy.getRank() != arrDim)
return emitOpError("rank of dimension in slice mismatched");
}
@@ -502,7 +502,7 @@ mlir::LogicalResult fir::ArrayMergeStoreOp::verify() {
// This is an intra-object merge, where the slice is projecting the
// subfields that are to be overwritten by the merge operation.
auto eleTy = fir::dyn_cast_ptrOrBoxEleTy(getMemref().getType());
- if (auto seqTy = mlir::dyn_cast<fir::SequenceType>(eleTy)) {
+ if (auto seqTy = eleTy.dyn_cast<fir::SequenceType>()) {
auto projTy =
fir::applyPathToType(seqTy.getEleTy(), sliceOp.getFields());
if (fir::unwrapSequenceType(getOriginal().getType()) != projTy)
@@ -540,7 +540,7 @@ mlir::Type validArraySubobject(A op) {
}
mlir::LogicalResult fir::ArrayFetchOp::verify() {
- auto arrTy = mlir::cast<fir::SequenceType>(getSequence().getType());
+ auto arrTy = getSequence().getType().cast<fir::SequenceType>();
auto indSize = getIndices().size();
if (indSize < arrTy.getDimension())
return emitOpError("number of indices != dimension of array");
@@ -562,7 +562,7 @@ mlir::LogicalResult fir::ArrayFetchOp::verify() {
//===----------------------------------------------------------------------===//
mlir::LogicalResult fir::ArrayAccessOp::verify() {
- auto arrTy = mlir::cast<fir::SequenceType>(getSequence().getType());
+ auto arrTy = getSequence().getType().cast<fir::SequenceType>();
std::size_t indSize = getIndices().size();
if (indSize < arrTy.getDimension())
return emitOpError("number of indices != dimension of array");
@@ -584,7 +584,7 @@ mlir::LogicalResult fir::ArrayAccessOp::verify() {
mlir::LogicalResult fir::ArrayUpdateOp::verify() {
if (fir::isa_ref_type(getMerge().getType()))
return emitOpError("does not support reference type for merge");
- auto arrTy = mlir::cast<fir::SequenceType>(getSequence().getType());
+ auto arrTy = getSequence().getType().cast<fir::SequenceType>();
auto indSize = getIndices().size();
if (indSize < arrTy.getDimension())
return emitOpError("number of indices != dimension of array");
@@ -604,7 +604,7 @@ mlir::LogicalResult fir::ArrayUpdateOp::verify() {
//===----------------------------------------------------------------------===//
mlir::LogicalResult fir::ArrayModifyOp::verify() {
- auto arrTy = mlir::cast<fir::SequenceType>(getSequence().getType());
+ auto arrTy = getSequence().getType().cast<fir::SequenceType>();
auto indSize = getIndices().size();
if (indSize < arrTy.getDimension())
return emitOpError("number of indices must match array dimension");
@@ -740,7 +740,7 @@ mlir::ParseResult fir::CallOp::parse(mlir::OpAsmParser &parser,
parser.parseType(type))
return mlir::failure();
- auto funcType = mlir::dyn_cast<mlir::FunctionType>(type);
+ auto funcType = type.dyn_cast<mlir::FunctionType>();
if (!funcType)
return parser.emitError(parser.getNameLoc(), "expected function type");
if (isDirect) {
@@ -785,7 +785,7 @@ void fir::CallOp::build(mlir::OpBuilder &builder, mlir::OperationState &result,
mlir::LogicalResult fir::CharConvertOp::verify() {
auto unwrap = [&](mlir::Type t) {
t = fir::unwrapSequenceType(fir::dyn_cast_ptrEleTy(t));
- return mlir::dyn_cast<fir::CharacterType>(t);
+ return t.dyn_cast<fir::CharacterType>();
};
auto inTy = unwrap(getFrom().getType());
auto outTy = unwrap(getTo().getType());
@@ -832,13 +832,13 @@ static mlir::ParseResult parseCmpOp(mlir::OpAsmParser &parser,
parser.resolveOperands(ops, type, result.operands))
return mlir::failure();
- if (!mlir::isa<mlir::StringAttr>(predicateNameAttr))
+ if (!predicateNameAttr.isa<mlir::StringAttr>())
return parser.emitError(parser.getNameLoc(),
"expected string comparison predicate attribute");
// Rewrite string attribute to an enum value.
llvm::StringRef predicateName =
- mlir::cast<mlir::StringAttr>(predicateNameAttr).getValue();
+ predicateNameAttr.cast<mlir::StringAttr>().getValue();
auto predicate = fir::CmpcOp::getPredicateByName(predicateName);
auto builder = parser.getBuilder();
mlir::Type i1Type = builder.getI1Type();
@@ -906,7 +906,7 @@ void fir::ConstcOp::print(mlir::OpAsmPrinter &p) {
}
mlir::LogicalResult fir::ConstcOp::verify() {
- if (!mlir::isa<fir::ComplexType>(getType()))
+ if (!getType().isa<fir::ComplexType>())
return emitOpError("must be a !fir.complex type");
return mlir::success();
}
@@ -929,16 +929,15 @@ mlir::OpFoldResult fir::ConvertOp::fold(FoldAdaptor adaptor) {
if (matchPattern(getValue(), mlir::m_Op<fir::ConvertOp>())) {
auto inner = mlir::cast<fir::ConvertOp>(getValue().getDefiningOp());
// (convert (convert 'a : logical -> i1) : i1 -> logical) ==> forward 'a
- if (auto toTy = mlir::dyn_cast<fir::LogicalType>(getType()))
- if (auto fromTy =
- mlir::dyn_cast<fir::LogicalType>(inner.getValue().getType()))
- if (mlir::isa<mlir::IntegerType>(inner.getType()) && (toTy == fromTy))
+ if (auto toTy = getType().dyn_cast<fir::LogicalType>())
+ if (auto fromTy = inner.getValue().getType().dyn_cast<fir::LogicalType>())
+ if (inner.getType().isa<mlir::IntegerType>() && (toTy == fromTy))
return inner.getValue();
// (convert (convert 'a : i1 -> logical) : logical -> i1) ==> forward 'a
- if (auto toTy = mlir::dyn_cast<mlir::IntegerType>(getType()))
+ if (auto toTy = getType().dyn_cast<mlir::IntegerType>())
if (auto fromTy =
- mlir::dyn_cast<mlir::IntegerType>(inner.getValue().getType()))
- if (mlir::isa<fir::LogicalType>(inner.getType()) && (toTy == fromTy) &&
+ inner.getValue().getType().dyn_cast<mlir::IntegerType>())
+ if (inner.getType().isa<fir::LogicalType>() && (toTy == fromTy) &&
(fromTy.getWidth() == 1))
return inner.getValue();
}
@@ -946,7 +945,7 @@ mlir::OpFoldResult fir::ConvertOp::fold(FoldAdaptor adaptor) {
}
bool fir::ConvertOp::isInteger(mlir::Type ty) {
- return mlir::isa<mlir::IntegerType, mlir::IndexType, fir::IntegerType>(ty);
+ return ty.isa<mlir::IntegerType, mlir::IndexType, fir::IntegerType>();
}
bool fir::ConvertOp::isIntegerCompatible(mlir::Type ty) {
@@ -954,13 +953,13 @@ bool fir::ConvertOp::isIntegerCompatible(mlir::Type ty) {
}
bool fir::ConvertOp::isFloatCompatible(mlir::Type ty) {
- return mlir::isa<mlir::FloatType, fir::RealType>(ty);
+ return ty.isa<mlir::FloatType, fir::RealType>();
}
bool fir::ConvertOp::isPointerCompatible(mlir::Type ty) {
- return mlir::isa<fir::ReferenceType, fir::PointerType, fir::HeapType,
- fir::LLVMPointerType, mlir::MemRefType, mlir::FunctionType,
- fir::TypeDescType>(ty);
+ return ty.isa<fir::ReferenceType, fir::PointerType, fir::HeapType,
+ fir::LLVMPointerType, mlir::MemRefType, mlir::FunctionType,
+ fir::TypeDescType>();
}
static std::optional<mlir::Type> getVectorElementType(mlir::Type ty) {
@@ -1027,14 +1026,12 @@ bool fir::ConvertOp::canBeConverted(mlir::Type inType, mlir::Type outType) {
(isFloatCompatible(inType) && isFloatCompatible(outType)) ||
(isIntegerCompatible(inType) && isPointerCompatible(outType)) ||
(isPointerCompatible(inType) && isIntegerCompatible(outType)) ||
- (mlir::isa<fir::BoxType>(inType) &&
- mlir::isa<fir::BoxType>(outType)) ||
- (mlir::isa<fir::BoxProcType>(inType) &&
- mlir::isa<fir::BoxProcType>(outType)) ||
+ (inType.isa<fir::BoxType>() && outType.isa<fir::BoxType>()) ||
+ (inType.isa<fir::BoxProcType>() && outType.isa<fir::BoxProcType>()) ||
(fir::isa_complex(inType) && fir::isa_complex(outType)) ||
(fir::isBoxedRecordType(inType) && fir::isPolymorphicType(outType)) ||
(fir::isPolymorphicType(inType) && fir::isPolymorphicType(outType)) ||
- (fir::isPolymorphicType(inType) && mlir::isa<BoxType>(outType)) ||
+ (fir::isPolymorphicType(inType) && outType.isa<BoxType>()) ||
areVectorsCompatible(inType, outType);
}
@@ -1082,7 +1079,7 @@ mlir::LogicalResult fir::CoordinateOp::verify() {
const mlir::Type refTy = getRef().getType();
if (fir::isa_ref_type(refTy)) {
auto eleTy = fir::dyn_cast_ptrEleTy(refTy);
- if (auto arrTy = mlir::dyn_cast<fir::SequenceType>(eleTy)) {
+ if (auto arrTy = eleTy.dyn_cast<fir::SequenceType>()) {
if (arrTy.hasUnknownShape())
return emitOpError("cannot find coordinate in unknown shape");
if (arrTy.getConstantRows() < arrTy.getDimension() - 1)
@@ -1097,8 +1094,8 @@ mlir::LogicalResult fir::CoordinateOp::verify() {
const unsigned numCoors = getCoor().size();
for (auto coorOperand : llvm::enumerate(getCoor())) {
auto co = coorOperand.value();
- if (dimension == 0 && mlir::isa<fir::SequenceType>(eleTy)) {
- dimension = mlir::cast<fir::SequenceType>(eleTy).getDimension();
+ if (dimension == 0 && eleTy.isa<fir::SequenceType>()) {
+ dimension = eleTy.cast<fir::SequenceType>().getDimension();
if (dimension == 0)
return emitOpError("cannot apply to array of unknown rank");
}
@@ -1107,7 +1104,7 @@ mlir::LogicalResult fir::CoordinateOp::verify() {
// Recovering a LEN type parameter only makes sense from a boxed
// value. For a bare reference, the LEN type parameters must be
// passed as additional arguments to `index`.
- if (mlir::isa<fir::BoxType>(refTy)) {
+ if (refTy.isa<fir::BoxType>()) {
if (coorOperand.index() != numCoors - 1)
return emitOpError("len_param_index must be last argument");
if (getNumOperands() != 2)
@@ -1120,7 +1117,7 @@ mlir::LogicalResult fir::CoordinateOp::verify() {
} else if (auto index = mlir::dyn_cast<fir::FieldIndexOp>(defOp)) {
if (eleTy != index.getOnType())
emitOpError("field_index type not compatible with reference type");
- if (auto recTy = mlir::dyn_cast<fir::RecordType>(eleTy)) {
+ if (auto recTy = eleTy.dyn_cast<fir::RecordType>()) {
eleTy = recTy.getType(index.getFieldName());
continue;
}
@@ -1129,21 +1126,21 @@ mlir::LogicalResult fir::CoordinateOp::verify() {
}
if (dimension) {
if (--dimension == 0)
- eleTy = mlir::cast<fir::SequenceType>(eleTy).getEleTy();
+ eleTy = eleTy.cast<fir::SequenceType>().getEleTy();
} else {
- if (auto t = mlir::dyn_cast<mlir::TupleType>(eleTy)) {
+ if (auto t = eleTy.dyn_cast<mlir::TupleType>()) {
// FIXME: Generally, we don't know which field of the tuple is being
// referred to unless the operand is a constant. Just assume everything
// is good in the tuple case for now.
return mlir::success();
- } else if (auto t = mlir::dyn_cast<fir::RecordType>(eleTy)) {
+ } else if (auto t = eleTy.dyn_cast<fir::RecordType>()) {
// FIXME: This is the same as the tuple case.
return mlir::success();
- } else if (auto t = mlir::dyn_cast<fir::ComplexType>(eleTy)) {
+ } else if (auto t = eleTy.dyn_cast<fir::ComplexType>()) {
eleTy = t.getElementType();
- } else if (auto t = mlir::dyn_cast<mlir::ComplexType>(eleTy)) {
+ } else if (auto t = eleTy.dyn_cast<mlir::ComplexType>()) {
eleTy = t.getElementType();
- } else if (auto t = mlir::dyn_cast<fir::CharacterType>(eleTy)) {
+ } else if (auto t = eleTy.dyn_cast<fir::CharacterType>()) {
if (t.getLen() == fir::CharacterType::singleton())
return emitOpError("cannot apply to character singleton");
eleTy = fir::CharacterType::getSingleton(t.getContext(), t.getFKind());
@@ -1219,17 +1216,17 @@ mlir::LogicalResult fir::TypeInfoOp::verify() {
mlir::LogicalResult fir::EmboxOp::verify() {
auto eleTy = fir::dyn_cast_ptrEleTy(getMemref().getType());
bool isArray = false;
- if (auto seqTy = mlir::dyn_cast<fir::SequenceType>(eleTy)) {
+ if (auto seqTy = eleTy.dyn_cast<fir::SequenceType>()) {
eleTy = seqTy.getEleTy();
isArray = true;
}
if (hasLenParams()) {
auto lenPs = numLenParams();
- if (auto rt = mlir::dyn_cast<fir::RecordType>(eleTy)) {
+ if (auto rt = eleTy.dyn_cast<fir::RecordType>()) {
if (lenPs != rt.getNumLenParams())
return emitOpError("number of LEN params does not correspond"
" to the !fir.type type");
- } else if (auto strTy = mlir::dyn_cast<fir::CharacterType>(eleTy)) {
+ } else if (auto strTy = eleTy.dyn_cast<fir::CharacterType>()) {
if (strTy.getLen() != fir::CharacterType::unknownLen())
return emitOpError("CHARACTER already has static LEN");
} else {
@@ -1243,7 +1240,7 @@ mlir::LogicalResult fir::EmboxOp::verify() {
return emitOpError("shape must not be provided for a scalar");
if (getSlice() && !isArray)
return emitOpError("slice must not be provided for a scalar");
- if (getSourceBox() && !mlir::isa<fir::ClassType>(getResult().getType()))
+ if (getSourceBox() && !getResult().getType().isa<fir::ClassType>())
return emitOpError("source_box must be used with fir.class result type");
return mlir::success();
}
@@ -1254,7 +1251,7 @@ mlir::LogicalResult fir::EmboxOp::verify() {
mlir::LogicalResult fir::EmboxCharOp::verify() {
auto eleTy = fir::dyn_cast_ptrEleTy(getMemref().getType());
- if (!mlir::dyn_cast_or_null<fir::CharacterType>(eleTy))
+ if (!eleTy.dyn_cast_or_null<fir::CharacterType>())
return mlir::failure();
return mlir::success();
}
@@ -1266,8 +1263,8 @@ mlir::LogicalResult fir::EmboxCharOp::verify() {
mlir::LogicalResult fir::EmboxProcOp::verify() {
// host bindings (optional) must be a reference to a tuple
if (auto h = getHost()) {
- if (auto r = mlir::dyn_cast<fir::ReferenceType>(h.getType()))
- if (mlir::isa<mlir::TupleType>(r.getEleTy()))
+ if (auto r = h.getType().dyn_cast<fir::ReferenceType>())
+ if (r.getEleTy().isa<mlir::TupleType>())
return mlir::success();
return mlir::failure();
}
@@ -1303,7 +1300,7 @@ void fir::TypeDescOp::print(mlir::OpAsmPrinter &p) {
mlir::LogicalResult fir::TypeDescOp::verify() {
mlir::Type resultTy = getType();
- if (auto tdesc = mlir::dyn_cast<fir::TypeDescType>(resultTy)) {
+ if (auto tdesc = resultTy.dyn_cast<fir::TypeDescType>()) {
if (tdesc.getOfTy() != getInType())
return emitOpError("wrapped type mismatched");
return mlir::success();
@@ -1530,7 +1527,7 @@ mlir::ParseResult parseFieldLikeOp(mlir::OpAsmParser &parser,
return mlir::failure();
result.addAttribute(fir::FieldIndexOp::getFieldAttrName(),
builder.getStringAttr(fieldName));
- if (!mlir::dyn_cast<fir::RecordType>(recty))
+ if (!recty.dyn_cast<fir::RecordType>())
return mlir::failure();
result.addAttribute(fir::FieldIndexOp::getTypeAttrName(),
mlir::TypeAttr::get(recty));
@@ -1674,7 +1671,7 @@ mlir::LogicalResult fir::InsertOnRangeOp::verify() {
//===----------------------------------------------------------------------===//
static bool checkIsIntegerConstant(mlir::Attribute attr, std::int64_t conVal) {
- if (auto iattr = mlir::dyn_cast<mlir::IntegerAttr>(attr))
+ if (auto iattr = attr.dyn_cast<mlir::IntegerAttr>())
return iattr.getInt() == conVal;
return false;
}
@@ -1693,7 +1690,7 @@ struct UndoComplexPattern : public mlir::RewritePattern {
matchAndRewrite(mlir::Operation *op,
mlir::PatternRewriter &rewriter) const override {
auto insval = mlir::dyn_cast_or_null<fir::InsertValueOp>(op);
- if (!insval || !mlir::isa<fir::ComplexType>(insval.getType()))
+ if (!insval || !insval.getType().isa<fir::ComplexType>())
return mlir::failure();
auto insval2 = mlir::dyn_cast_or_null<fir::InsertValueOp>(
insval.getAdt().getDefiningOp());
@@ -1822,7 +1819,7 @@ mlir::ParseResult fir::IterWhileOp::parse(mlir::OpAsmParser &parser,
parser.parseRParen())
return mlir::failure();
// Type list must be "(index, i1)".
- if (typeList.size() != 2 || !mlir::isa<mlir::IndexType>(typeList[0]) ||
+ if (typeList.size() != 2 || !typeList[0].isa<mlir::IndexType>() ||
!typeList[1].isSignlessInteger(1))
return mlir::failure();
result.addTypes(typeList);
@@ -1876,7 +1873,7 @@ mlir::LogicalResult fir::IterWhileOp::verify() {
auto opNumResults = getNumResults();
if (getFinalValue()) {
// Result type must be "(index, i1, ...)".
- if (!mlir::isa<mlir::IndexType>(getResult(0).getType()))
+ if (!getResult(0).getType().isa<mlir::IndexType>())
return emitOpError("result #0 expected to be index");
if (!getResult(1).getType().isSignlessInteger(1))
return emitOpError("result #1 expected to be i1");
@@ -2319,7 +2316,7 @@ void fir::DTEntryOp::print(mlir::OpAsmPrinter &p) {
/// Example: return f32 for !fir.box<!fir.heap<!fir.array<?x?xf32>>.
static mlir::Type getBoxScalarEleTy(mlir::Type boxTy) {
auto eleTy = fir::dyn_cast_ptrOrBoxEleTy(boxTy);
- if (auto seqTy = mlir::dyn_cast<fir::SequenceType>(eleTy))
+ if (auto seqTy = eleTy.dyn_cast<fir::SequenceType>())
return seqTy.getEleTy();
return eleTy;
}
@@ -2327,8 +2324,8 @@ static mlir::Type getBoxScalarEleTy(mlir::Type boxTy) {
/// Test if \p t1 and \p t2 are compatible character types (if they can
/// represent the same type at runtime).
static bool areCompatibleCharacterTypes(mlir::Type t1, mlir::Type t2) {
- auto c1 = mlir::dyn_cast<fir::CharacterType>(t1);
- auto c2 = mlir::dyn_cast<fir::CharacterType>(t2);
+ auto c1 = t1.dyn_cast<fir::CharacterType>();
+ auto c2 = t2.dyn_cast<fir::CharacterType>();
if (!c1 || !c2)
return false;
if (c1.hasDynamicLen() || c2.hasDynamicLen())
@@ -2350,10 +2347,10 @@ mlir::LogicalResult fir::ReboxOp::verify() {
if (auto sliceVal = getSlice()) {
// Slicing case
- if (mlir::cast<fir::SliceType>(sliceVal.getType()).getRank() != inputRank)
+ if (sliceVal.getType().cast<fir::SliceType>().getRank() != inputRank)
return emitOpError("slice operand rank must match box operand rank");
if (auto shapeVal = getShape()) {
- if (auto shiftTy = mlir::dyn_cast<fir::ShiftType>(shapeVal.getType())) {
+ if (auto shiftTy = shapeVal.getType().dyn_cast<fir::ShiftType>()) {
if (shiftTy.getRank() != inputRank)
return emitOpError("shape operand and input box ranks must match "
"when there is a slice");
@@ -2373,12 +2370,12 @@ mlir::LogicalResult fir::ReboxOp::verify() {
unsigned shapeRank = inputRank;
if (auto shapeVal = getShape()) {
auto ty = shapeVal.getType();
- if (auto shapeTy = mlir::dyn_cast<fir::ShapeType>(ty)) {
+ if (auto shapeTy = ty.dyn_cast<fir::ShapeType>()) {
shapeRank = shapeTy.getRank();
- } else if (auto shapeShiftTy = mlir::dyn_cast<fir::ShapeShiftType>(ty)) {
+ } else if (auto shapeShiftTy = ty.dyn_cast<fir::ShapeShiftType>()) {
shapeRank = shapeShiftTy.getRank();
} else {
- auto shiftTy = mlir::cast<fir::ShiftType>(ty);
+ auto shiftTy = ty.cast<fir::ShiftType>();
shapeRank = shiftTy.getRank();
if (shapeRank != inputRank)
return emitOpError("shape operand and input box ranks must match "
@@ -2397,13 +2394,11 @@ mlir::LogicalResult fir::ReboxOp::verify() {
// the types is a character with dynamic length, the other type can be any
// character type.
const bool typeCanMismatch =
- mlir::isa<fir::RecordType>(inputEleTy) ||
- mlir::isa<mlir::NoneType>(outEleTy) ||
- (mlir::isa<mlir::NoneType>(inputEleTy) &&
- mlir::isa<fir::RecordType>(outEleTy)) ||
- (getSlice() && mlir::isa<fir::CharacterType>(inputEleTy)) ||
+ inputEleTy.isa<fir::RecordType>() || outEleTy.isa<mlir::NoneType>() ||
+ (inputEleTy.isa<mlir::NoneType>() && outEleTy.isa<fir::RecordType>()) ||
+ (getSlice() && inputEleTy.isa<fir::CharacterType>()) ||
(getSlice() && fir::isa_complex(inputEleTy) &&
- mlir::isa<mlir::FloatType>(outEleTy)) ||
+ outEleTy.isa<mlir::FloatType>()) ||
areCompatibleCharacterTypes(inputEleTy, outEleTy);
if (!typeCanMismatch)
return emitOpError(
@@ -2440,7 +2435,7 @@ mlir::LogicalResult fir::SaveResultOp::verify() {
if (fir::isa_unknown_size_box(resultType))
return emitOpError("cannot save !fir.box of unknown rank or type");
- if (mlir::isa<fir::BoxType>(resultType)) {
+ if (resultType.isa<fir::BoxType>()) {
if (getShape() || !getTypeparams().empty())
return emitOpError(
"must not have shape or length operands if the value is a fir.box");
@@ -2451,14 +2446,14 @@ mlir::LogicalResult fir::SaveResultOp::verify() {
unsigned shapeTyRank = 0;
if (auto shapeVal = getShape()) {
auto shapeTy = shapeVal.getType();
- if (auto s = mlir::dyn_cast<fir::ShapeType>(shapeTy))
+ if (auto s = shapeTy.dyn_cast<fir::ShapeType>())
shapeTyRank = s.getRank();
else
- shapeTyRank = mlir::cast<fir::ShapeShiftType>(shapeTy).getRank();
+ shapeTyRank = shapeTy.cast<fir::ShapeShiftType>().getRank();
}
auto eleTy = resultType;
- if (auto seqTy = mlir::dyn_cast<fir::SequenceType>(resultType)) {
+ if (auto seqTy = resultType.dyn_cast<fir::SequenceType>()) {
if (seqTy.getDimension() != shapeTyRank)
emitOpError("shape operand must be provided and have the value rank "
"when the value is a fir.array");
@@ -2469,11 +2464,11 @@ mlir::LogicalResult fir::SaveResultOp::verify() {
"shape operand should only be provided if the value is a fir.array");
}
- if (auto recTy = mlir::dyn_cast<fir::RecordType>(eleTy)) {
+ if (auto recTy = eleTy.dyn_cast<fir::RecordType>()) {
if (recTy.getNumLenParams() != getTypeparams().size())
emitOpError("length parameters number must match with the value type "
"length parameters");
- } else if (auto charTy = mlir::dyn_cast<fir::CharacterType>(eleTy)) {
+ } else if (auto charTy = eleTy.dyn_cast<fir::CharacterType>()) {
if (getTypeparams().size() > 1)
emitOpError("no more than one length parameter must be provided for "
"character value");
@@ -2513,7 +2508,7 @@ static mlir::LogicalResult verifyIntegralSwitchTerminator(OpT op) {
if (op.targetOffsetSize() != count)
return op.emitOpError("incorrect number of successor operand groups");
for (decltype(count) i = 0; i != count; ++i) {
- if (!mlir::isa<mlir::IntegerAttr, mlir::UnitAttr>(cases[i]))
+ if (!cases[i].template isa<mlir::IntegerAttr, mlir::UnitAttr>())
return op.emitOpError("invalid case alternative");
}
return mlir::success();
@@ -2625,7 +2620,7 @@ getMutableSuccessorOperands(unsigned pos, mlir::MutableOperandRange operands,
*owner->getAttrDictionary().getNamed(offsetAttr);
return getSubOperands(
pos, operands,
- mlir::cast<mlir::DenseI32ArrayAttr>(targetOffsetAttr.getValue()),
+ targetOffsetAttr.getValue().cast<mlir::DenseI32ArrayAttr>(),
mlir::MutableOperandRange::OperandSegment(pos, targetOffsetAttr));
}
@@ -2747,9 +2742,9 @@ mlir::ParseResult fir::SelectCaseOp::parse(mlir::OpAsmParser &parser,
parser.parseComma())
return mlir::failure();
attrs.push_back(attr);
- if (mlir::dyn_cast_or_null<mlir::UnitAttr>(attr)) {
+ if (attr.dyn_cast_or_null<mlir::UnitAttr>()) {
argOffs.push_back(0);
- } else if (mlir::dyn_cast_or_null<fir::ClosedIntervalAttr>(attr)) {
+ } else if (attr.dyn_cast_or_null<fir::ClosedIntervalAttr>()) {
mlir::OpAsmParser::UnresolvedOperand oper1;
mlir::OpAsmParser::UnresolvedOperand oper2;
if (parser.parseOperand(oper1) || parser.parseComma() ||
@@ -2811,11 +2806,11 @@ void fir::SelectCaseOp::print(mlir::OpAsmPrinter &p) {
if (i)
p << ", ";
p << cases[i] << ", ";
- if (!mlir::isa<mlir::UnitAttr>(cases[i])) {
+ if (!cases[i].isa<mlir::UnitAttr>()) {
auto caseArgs = *getCompareOperands(i);
p.printOperand(*caseArgs.begin());
p << ", ";
- if (mlir::isa<fir::ClosedIntervalAttr>(cases[i])) {
+ if (cases[i].isa<fir::ClosedIntervalAttr>()) {
p.printOperand(*(++caseArgs.begin()));
p << ", ";
}
@@ -2853,10 +2848,10 @@ void fir::SelectCaseOp::build(mlir::OpBuilder &builder,
llvm::SmallVector<int32_t> operOffs;
int32_t operSize = 0;
for (auto attr : compareAttrs) {
- if (mlir::isa<fir::ClosedIntervalAttr>(attr)) {
+ if (attr.isa<fir::ClosedIntervalAttr>()) {
operOffs.push_back(2);
operSize += 2;
- } else if (mlir::isa<mlir::UnitAttr>(attr)) {
+ } else if (attr.isa<mlir::UnitAttr>()) {
operOffs.push_back(0);
} else {
operOffs.push_back(1);
@@ -2905,10 +2900,10 @@ void fir::SelectCaseOp::build(mlir::OpBuilder &builder,
llvm::SmallVector<mlir::ValueRange> cmpOpers;
auto iter = cmpOpList.begin();
for (auto &attr : compareAttrs) {
- if (mlir::isa<fir::ClosedIntervalAttr>(attr)) {
+ if (attr.isa<fir::ClosedIntervalAttr>()) {
cmpOpers.push_back(mlir::ValueRange({iter, iter + 2}));
iter += 2;
- } else if (mlir::isa<mlir::UnitAttr>(attr)) {
+ } else if (attr.isa<mlir::UnitAttr>()) {
cmpOpers.push_back(mlir::ValueRange{});
} else {
cmpOpers.push_back(mlir::ValueRange({iter, iter + 1}));
@@ -2920,8 +2915,10 @@ void fir::SelectCaseOp::build(mlir::OpBuilder &builder,
}
mlir::LogicalResult fir::SelectCaseOp::verify() {
- if (!mlir::isa<mlir::IntegerType, mlir::IndexType, fir::IntegerType,
- fir::LogicalType, fir::CharacterType>(getSelector().getType()))
+ if (!getSelector()
+ .getType()
+ .isa<mlir::IntegerType, mlir::IndexType, fir::IntegerType,
+ fir::LogicalType, fir::CharacterType>())
return emitOpError("must be an integer, character, or logical");
auto cases =
getOperation()->getAttrOfType<mlir::ArrayAttr>(getCasesAttr()).getValue();
@@ -2936,11 +2933,9 @@ mlir::LogicalResult fir::SelectCaseOp::verify() {
return emitOpError("incorrect number of successor operand groups");
for (decltype(count) i = 0; i != count; ++i) {
auto &attr = cases[i];
- if (!(mlir::isa<fir::PointIntervalAttr>(attr) ||
- mlir::isa<fir::LowerBoundAttr>(attr) ||
- mlir::isa<fir::UpperBoundAttr>(attr) ||
- mlir::isa<fir::ClosedIntervalAttr>(attr) ||
- mlir::isa<mlir::UnitAttr>(attr)))
+ if (!(attr.isa<fir::PointIntervalAttr>() ||
+ attr.isa<fir::LowerBoundAttr>() || attr.isa<fir::UpperBoundAttr>() ||
+ attr.isa<fir::ClosedIntervalAttr>() || attr.isa<mlir::UnitAttr>()))
return emitOpError("incorrect select case attribute type");
}
return mlir::success();
@@ -3116,14 +3111,14 @@ void fir::SelectTypeOp::print(mlir::OpAsmPrinter &p) {
}
mlir::LogicalResult fir::SelectTypeOp::verify() {
- if (!mlir::isa<fir::BaseBoxType>(getSelector().getType()))
+ if (!(getSelector().getType().isa<fir::BaseBoxType>()))
return emitOpError("must be a fir.class or fir.box type");
- if (auto boxType = mlir::dyn_cast<fir::BoxType>(getSelector().getType()))
- if (!mlir::isa<mlir::NoneType>(boxType.getEleTy()))
+ if (auto boxType = getSelector().getType().dyn_cast<fir::BoxType>())
+ if (!boxType.getEleTy().isa<mlir::NoneType>())
return emitOpError("selector must be polymorphic");
auto typeGuardAttr = getCases();
for (unsigned idx = 0; idx < typeGuardAttr.size(); ++idx)
- if (mlir::isa<mlir::UnitAttr>(typeGuardAttr[idx]) &&
+ if (typeGuardAttr[idx].isa<mlir::UnitAttr>() &&
idx != typeGuardAttr.size() - 1)
return emitOpError("default must be the last attribute");
auto count = getNumDest();
@@ -3134,8 +3129,9 @@ mlir::LogicalResult fir::SelectTypeOp::verify() {
if (targetOffsetSize() != count)
return emitOpError("incorrect number of successor operand groups");
for (unsigned i = 0; i != count; ++i) {
- if (!mlir::isa<fir::ExactTypeAttr, fir::SubclassAttr, mlir::UnitAttr>(
- typeGuardAttr[i]))
+ if (!(typeGuardAttr[i].isa<fir::ExactTypeAttr>() ||
+ typeGuardAttr[i].isa<fir::SubclassAttr>() ||
+ typeGuardAttr[i].isa<mlir::UnitAttr>()))
return emitOpError("invalid type-case alternative");
}
return mlir::success();
@@ -3179,7 +3175,7 @@ void fir::SelectTypeOp::build(mlir::OpBuilder &builder,
mlir::LogicalResult fir::ShapeOp::verify() {
auto size = getExtents().size();
- auto shapeTy = mlir::dyn_cast<fir::ShapeType>(getType());
+ auto shapeTy = getType().dyn_cast<fir::ShapeType>();
assert(shapeTy && "must be a shape type");
if (shapeTy.getRank() != size)
return emitOpError("shape type rank mismatch");
@@ -3202,7 +3198,7 @@ mlir::LogicalResult fir::ShapeShiftOp::verify() {
return emitOpError("incorrect number of args");
if (size % 2 != 0)
return emitOpError("requires a multiple of 2 args");
- auto shapeTy = mlir::dyn_cast<fir::ShapeShiftType>(getType());
+ auto shapeTy = getType().dyn_cast<fir::ShapeShiftType>();
assert(shapeTy && "must be a shape shift type");
if (shapeTy.getRank() * 2 != size)
return emitOpError("shape type rank mismatch");
@@ -3215,7 +3211,7 @@ mlir::LogicalResult fir::ShapeShiftOp::verify() {
mlir::LogicalResult fir::ShiftOp::verify() {
auto size = getOrigins().size();
- auto shiftTy = mlir::dyn_cast<fir::ShiftType>(getType());
+ auto shiftTy = getType().dyn_cast<fir::ShiftType>();
assert(shiftTy && "must be a shift type");
if (shiftTy.getRank() != size)
return emitOpError("shift type rank mismatch");
@@ -3255,7 +3251,7 @@ mlir::LogicalResult fir::SliceOp::verify() {
return emitOpError("incorrect number of args for triple");
if (size % 3 != 0)
return emitOpError("requires a multiple of 3 args");
- auto sliceTy = mlir::dyn_cast<fir::SliceType>(getType());
+ auto sliceTy = getType().dyn_cast<fir::SliceType>();
assert(sliceTy && "must be a slice type");
if (sliceTy.getRank() * 3 != size)
return emitOpError("slice type rank mismatch");
@@ -3313,8 +3309,8 @@ void fir::StoreOp::build(mlir::OpBuilder &builder, mlir::OperationState &result,
//===----------------------------------------------------------------------===//
inline fir::CharacterType::KindTy stringLitOpGetKind(fir::StringLitOp op) {
- auto eleTy = mlir::cast<fir::SequenceType>(op.getType()).getEleTy();
- return mlir::cast<fir::CharacterType>(eleTy).getFKind();
+ auto eleTy = op.getType().cast<fir::SequenceType>().getEleTy();
+ return eleTy.cast<fir::CharacterType>().getFKind();
}
bool fir::StringLitOp::isWideValue() { return stringLitOpGetKind(*this) != 1; }
@@ -3394,13 +3390,13 @@ mlir::ParseResult fir::StringLitOp::parse(mlir::OpAsmParser &parser,
llvm::SMLoc trailingTypeLoc;
if (parser.parseAttribute(val, "fake", attrs))
return mlir::failure();
- if (auto v = mlir::dyn_cast<mlir::StringAttr>(val))
+ if (auto v = val.dyn_cast<mlir::StringAttr>())
result.attributes.push_back(
builder.getNamedAttr(fir::StringLitOp::value(), v));
- else if (auto v = mlir::dyn_cast<mlir::DenseElementsAttr>(val))
+ else if (auto v = val.dyn_cast<mlir::DenseElementsAttr>())
result.attributes.push_back(
builder.getNamedAttr(fir::StringLitOp::xlist(), v));
- else if (auto v = mlir::dyn_cast<mlir::ArrayAttr>(val))
+ else if (auto v = val.dyn_cast<mlir::ArrayAttr>())
result.attributes.push_back(
builder.getNamedAttr(fir::StringLitOp::xlist(), v));
else
@@ -3413,7 +3409,7 @@ mlir::ParseResult fir::StringLitOp::parse(mlir::OpAsmParser &parser,
parser.parseRParen() || parser.getCurrentLocation(&trailingTypeLoc) ||
parser.parseColonType(type))
return mlir::failure();
- auto charTy = mlir::dyn_cast<fir::CharacterType>(type);
+ auto charTy = type.dyn_cast<fir::CharacterType>();
if (!charTy)
return parser.emitError(trailingTypeLoc, "must have character type");
type = fir::CharacterType::get(builder.getContext(), charTy.getFKind(),
@@ -3425,19 +3421,19 @@ mlir::ParseResult fir::StringLitOp::parse(mlir::OpAsmParser &parser,
void fir::StringLitOp::print(mlir::OpAsmPrinter &p) {
p << ' ' << getValue() << '(';
- p << mlir::cast<mlir::IntegerAttr>(getSize()).getValue() << ") : ";
+ p << getSize().cast<mlir::IntegerAttr>().getValue() << ") : ";
p.printType(getType());
}
mlir::LogicalResult fir::StringLitOp::verify() {
- if (mlir::cast<mlir::IntegerAttr>(getSize()).getValue().isNegative())
+ if (getSize().cast<mlir::IntegerAttr>().getValue().isNegative())
return emitOpError("size must be non-negative");
if (auto xl = getOperation()->getAttr(fir::StringLitOp::xlist())) {
- if (auto xList = mlir::dyn_cast<mlir::ArrayAttr>(xl)) {
+ if (auto xList = xl.dyn_cast<mlir::ArrayAttr>()) {
for (auto a : xList)
- if (!mlir::isa<mlir::IntegerAttr>(a))
+ if (!a.isa<mlir::IntegerAttr>())
return emitOpError("values in initializer must be integers");
- } else if (mlir::isa<mlir::DenseElementsAttr>(xl)) {
+ } else if (xl.isa<mlir::DenseElementsAttr>()) {
// do nothing
} else {
return emitOpError("has unexpected attribute");
@@ -3452,7 +3448,7 @@ mlir::LogicalResult fir::StringLitOp::verify() {
mlir::LogicalResult fir::UnboxProcOp::verify() {
if (auto eleTy = fir::dyn_cast_ptrEleTy(getRefTuple().getType()))
- if (mlir::isa<mlir::TupleType>(eleTy))
+ if (eleTy.isa<mlir::TupleType>())
return mlir::success();
return emitOpError("second output argument has bad type");
}
@@ -3531,7 +3527,7 @@ void fir::IfOp::getEntrySuccessorRegions(
void fir::IfOp::getRegionInvocationBounds(
llvm::ArrayRef<mlir::Attribute> operands,
llvm::SmallVectorImpl<mlir::InvocationBounds> &invocationBounds) {
- if (auto cond = mlir::dyn_cast_or_null<mlir::BoolAttr>(operands[0])) {
+ if (auto cond = operands[0].dyn_cast_or_null<mlir::BoolAttr>()) {
// If the condition is known, then one region is known to be executed once
// and the other zero times.
invocationBounds.emplace_back(0, cond.getValue() ? 1 : 0);
@@ -3650,8 +3646,8 @@ void fir::BoxOffsetOp::build(mlir::OpBuilder &builder,
//===----------------------------------------------------------------------===//
mlir::ParseResult fir::isValidCaseAttr(mlir::Attribute attr) {
- if (mlir::isa<mlir::UnitAttr, fir::ClosedIntervalAttr, fir::PointIntervalAttr,
- fir::LowerBoundAttr, fir::UpperBoundAttr>(attr))
+ if (attr.isa<mlir::UnitAttr, fir::ClosedIntervalAttr, fir::PointIntervalAttr,
+ fir::LowerBoundAttr, fir::UpperBoundAttr>())
return mlir::success();
return mlir::failure();
}
@@ -3661,9 +3657,9 @@ unsigned fir::getCaseArgumentOffset(llvm::ArrayRef<mlir::Attribute> cases,
unsigned o = 0;
for (unsigned i = 0; i < dest; ++i) {
auto &attr = cases[i];
- if (!mlir::dyn_cast_or_null<mlir::UnitAttr>(attr)) {
+ if (!attr.dyn_cast_or_null<mlir::UnitAttr>()) {
++o;
- if (mlir::dyn_cast_or_null<fir::ClosedIntervalAttr>(attr))
+ if (attr.dyn_cast_or_null<fir::ClosedIntervalAttr>())
++o;
}
}
@@ -3726,7 +3722,7 @@ fir::GlobalOp fir::createGlobalOp(mlir::Location loc, mlir::ModuleOp module,
bool fir::hasHostAssociationArgument(mlir::func::FuncOp func) {
if (auto allArgAttrs = func.getAllArgAttrs())
for (auto attr : allArgAttrs)
- if (auto dict = mlir::dyn_cast_or_null<mlir::DictionaryAttr>(attr))
+ if (auto dict = attr.template dyn_cast_or_null<mlir::DictionaryAttr>())
if (dict.get(fir::getHostAssocAttrName()))
return true;
return false;
@@ -3776,7 +3772,7 @@ valueCheckFirAttributes(mlir::Value value,
};
// If this is a fir.box that was loaded, the fir attributes will be on the
// related fir.ref<fir.box> creation.
- if (mlir::isa<fir::BoxType>(value.getType()))
+ if (value.getType().isa<fir::BoxType>())
if (auto definingOp = value.getDefiningOp())
if (auto loadOp = mlir::dyn_cast<fir::LoadOp>(definingOp))
value = loadOp.getMemref();
@@ -3841,10 +3837,10 @@ bool fir::anyFuncArgsHaveAttr(mlir::func::FuncOp func, llvm::StringRef attr) {
std::optional<std::int64_t> fir::getIntIfConstant(mlir::Value value) {
if (auto *definingOp = value.getDefiningOp()) {
if (auto cst = mlir::dyn_cast<mlir::arith::ConstantOp>(definingOp))
- if (auto intAttr = mlir::dyn_cast<mlir::IntegerAttr>(cst.getValue()))
+ if (auto intAttr = cst.getValue().dyn_cast<mlir::IntegerAttr>())
return intAttr.getInt();
if (auto llConstOp = mlir::dyn_cast<mlir::LLVM::ConstantOp>(definingOp))
- if (auto attr = mlir::dyn_cast<mlir::IntegerAttr>(llConstOp.getValue()))
+ if (auto attr = llConstOp.getValue().dyn_cast<mlir::IntegerAttr>())
return attr.getValue().getSExtValue();
}
return {};
@@ -4006,15 +4002,15 @@ mlir::LogicalResult fir::CUDAKernelOp::verify() {
mlir::LogicalResult fir::CUDAAllocateOp::verify() {
if (getPinned() && getStream())
return emitOpError("pinned and stream cannot appears at the same time");
- if (!mlir::isa<fir::BaseBoxType>(fir::unwrapRefType(getBox().getType())))
+ if (!fir::unwrapRefType(getBox().getType()).isa<fir::BaseBoxType>())
return emitOpError(
"expect box to be a reference to a class or box type value");
if (getSource() &&
- !mlir::isa<fir::BaseBoxType>(fir::unwrapRefType(getSource().getType())))
+ !fir::unwrapRefType(getSource().getType()).isa<fir::BaseBoxType>())
return emitOpError(
"expect source to be a reference to/or a class or box type value");
if (getErrmsg() &&
- !mlir::isa<fir::BoxType>(fir::unwrapRefType(getErrmsg().getType())))
+ !fir::unwrapRefType(getErrmsg().getType()).isa<fir::BoxType>())
return emitOpError(
"expect errmsg to be a reference to/or a box type value");
if (getErrmsg() && !getHasStat())
@@ -4023,11 +4019,11 @@ mlir::LogicalResult fir::CUDAAllocateOp::verify() {
}
mlir::LogicalResult fir::CUDADeallocateOp::verify() {
- if (!mlir::isa<fir::BaseBoxType>(fir::unwrapRefType(getBox().getType())))
+ if (!fir::unwrapRefType(getBox().getType()).isa<fir::BaseBoxType>())
return emitOpError(
"expect box to be a reference to class or box type value");
if (getErrmsg() &&
- !mlir::isa<fir::BoxType>(fir::unwrapRefType(getErrmsg().getType())))
+ !fir::unwrapRefType(getErrmsg().getType()).isa<fir::BoxType>())
return emitOpError(
"expect errmsg to be a reference to/or a box type value");
if (getErrmsg() && !getHasStat())
diff --git a/flang/lib/Optimizer/Dialect/FIRType.cpp b/flang/lib/Optimizer/Dialect/FIRType.cpp
index 38a6a09d1808a6..5c4cad6d208344 100644
--- a/flang/lib/Optimizer/Dialect/FIRType.cpp
+++ b/flang/lib/Optimizer/Dialect/FIRType.cpp
@@ -61,13 +61,14 @@ TYPE parseTypeSingleton(mlir::AsmParser &parser) {
/// Is `ty` a standard or FIR integer type?
static bool isaIntegerType(mlir::Type ty) {
// TODO: why aren't we using isa_integer? investigatation required.
- return mlir::isa<mlir::IntegerType, fir::IntegerType>(ty);
+ return ty.isa<mlir::IntegerType>() || ty.isa<fir::IntegerType>();
}
bool verifyRecordMemberType(mlir::Type ty) {
- return !mlir::isa<BoxCharType, ShapeType, ShapeShiftType, ShiftType,
- SliceType, FieldType, LenType, ReferenceType, TypeDescType>(
- ty);
+ return !(ty.isa<BoxCharType>() || ty.isa<ShapeType>() ||
+ ty.isa<ShapeShiftType>() || ty.isa<ShiftType>() ||
+ ty.isa<SliceType>() || ty.isa<FieldType>() || ty.isa<LenType>() ||
+ ty.isa<ReferenceType>() || ty.isa<TypeDescType>());
}
bool verifySameLists(llvm::ArrayRef<RecordType::TypePair> a1,
@@ -193,7 +194,7 @@ bool isa_std_type(mlir::Type t) {
}
bool isa_fir_or_std_type(mlir::Type t) {
- if (auto funcType = mlir::dyn_cast<mlir::FunctionType>(t))
+ if (auto funcType = t.dyn_cast<mlir::FunctionType>())
return llvm::all_of(funcType.getInputs(), isa_fir_or_std_type) &&
llvm::all_of(funcType.getResults(), isa_fir_or_std_type);
return isa_fir_type(t) || isa_std_type(t);
@@ -202,7 +203,7 @@ bool isa_fir_or_std_type(mlir::Type t) {
mlir::Type getDerivedType(mlir::Type ty) {
return llvm::TypeSwitch<mlir::Type, mlir::Type>(ty)
.Case<fir::PointerType, fir::HeapType, fir::SequenceType>([](auto p) {
- if (auto seq = mlir::dyn_cast<fir::SequenceType>(p.getEleTy()))
+ if (auto seq = p.getEleTy().template dyn_cast<fir::SequenceType>())
return seq.getEleTy();
return p.getEleTy();
})
@@ -227,12 +228,12 @@ mlir::Type dyn_cast_ptrOrBoxEleTy(mlir::Type t) {
static bool hasDynamicSize(fir::RecordType recTy) {
for (auto field : recTy.getTypeList()) {
- if (auto arr = mlir::dyn_cast<fir::SequenceType>(field.second)) {
+ if (auto arr = field.second.dyn_cast<fir::SequenceType>()) {
if (sequenceWithNonConstantShape(arr))
return true;
} else if (characterWithDynamicLen(field.second)) {
return true;
- } else if (auto rec = mlir::dyn_cast<fir::RecordType>(field.second)) {
+ } else if (auto rec = field.second.dyn_cast<fir::RecordType>()) {
if (hasDynamicSize(rec))
return true;
}
@@ -241,14 +242,14 @@ static bool hasDynamicSize(fir::RecordType recTy) {
}
bool hasDynamicSize(mlir::Type t) {
- if (auto arr = mlir::dyn_cast<fir::SequenceType>(t)) {
+ if (auto arr = t.dyn_cast<fir::SequenceType>()) {
if (sequenceWithNonConstantShape(arr))
return true;
t = arr.getEleTy();
}
if (characterWithDynamicLen(t))
return true;
- if (auto rec = mlir::dyn_cast<fir::RecordType>(t))
+ if (auto rec = t.dyn_cast<fir::RecordType>())
return hasDynamicSize(rec);
return false;
}
@@ -268,33 +269,33 @@ mlir::Type extractSequenceType(mlir::Type ty) {
bool isPointerType(mlir::Type ty) {
if (auto refTy = fir::dyn_cast_ptrEleTy(ty))
ty = refTy;
- if (auto boxTy = mlir::dyn_cast<fir::BaseBoxType>(ty))
- return mlir::isa<fir::PointerType>(boxTy.getEleTy());
+ if (auto boxTy = ty.dyn_cast<fir::BaseBoxType>())
+ return boxTy.getEleTy().isa<fir::PointerType>();
return false;
}
bool isAllocatableType(mlir::Type ty) {
if (auto refTy = fir::dyn_cast_ptrEleTy(ty))
ty = refTy;
- if (auto boxTy = mlir::dyn_cast<fir::BaseBoxType>(ty))
- return mlir::isa<fir::HeapType>(boxTy.getEleTy());
+ if (auto boxTy = ty.dyn_cast<fir::BaseBoxType>())
+ return boxTy.getEleTy().isa<fir::HeapType>();
return false;
}
bool isBoxNone(mlir::Type ty) {
- if (auto box = mlir::dyn_cast<fir::BoxType>(ty))
- return mlir::isa<mlir::NoneType>(box.getEleTy());
+ if (auto box = ty.dyn_cast<fir::BoxType>())
+ return box.getEleTy().isa<mlir::NoneType>();
return false;
}
bool isBoxedRecordType(mlir::Type ty) {
if (auto refTy = fir::dyn_cast_ptrEleTy(ty))
ty = refTy;
- if (auto boxTy = mlir::dyn_cast<fir::BoxType>(ty)) {
- if (mlir::isa<fir::RecordType>(boxTy.getEleTy()))
+ if (auto boxTy = ty.dyn_cast<fir::BoxType>()) {
+ if (boxTy.getEleTy().isa<fir::RecordType>())
return true;
mlir::Type innerType = boxTy.unwrapInnerType();
- return innerType && mlir::isa<fir::RecordType>(innerType);
+ return innerType && innerType.isa<fir::RecordType>();
}
return false;
}
@@ -302,13 +303,13 @@ bool isBoxedRecordType(mlir::Type ty) {
bool isScalarBoxedRecordType(mlir::Type ty) {
if (auto refTy = fir::dyn_cast_ptrEleTy(ty))
ty = refTy;
- if (auto boxTy = mlir::dyn_cast<fir::BaseBoxType>(ty)) {
- if (mlir::isa<fir::RecordType>(boxTy.getEleTy()))
+ if (auto boxTy = ty.dyn_cast<fir::BaseBoxType>()) {
+ if (boxTy.getEleTy().isa<fir::RecordType>())
return true;
- if (auto heapTy = mlir::dyn_cast<fir::HeapType>(boxTy.getEleTy()))
- return mlir::isa<fir::RecordType>(heapTy.getEleTy());
- if (auto ptrTy = mlir::dyn_cast<fir::PointerType>(boxTy.getEleTy()))
- return mlir::isa<fir::RecordType>(ptrTy.getEleTy());
+ if (auto heapTy = boxTy.getEleTy().dyn_cast<fir::HeapType>())
+ return heapTy.getEleTy().isa<fir::RecordType>();
+ if (auto ptrTy = boxTy.getEleTy().dyn_cast<fir::PointerType>())
+ return ptrTy.getEleTy().isa<fir::RecordType>();
}
return false;
}
@@ -362,10 +363,10 @@ bool isPolymorphicType(mlir::Type ty) {
bool isUnlimitedPolymorphicType(mlir::Type ty) {
// CLASS(*)
if (auto clTy = mlir::dyn_cast<fir::ClassType>(fir::unwrapRefType(ty))) {
- if (mlir::isa<mlir::NoneType>(clTy.getEleTy()))
+ if (clTy.getEleTy().isa<mlir::NoneType>())
return true;
mlir::Type innerType = clTy.unwrapInnerType();
- return innerType && mlir::isa<mlir::NoneType>(innerType);
+ return innerType && innerType.isa<mlir::NoneType>();
}
// TYPE(*)
return isAssumedType(ty);
@@ -375,7 +376,7 @@ mlir::Type unwrapInnerType(mlir::Type ty) {
return llvm::TypeSwitch<mlir::Type, mlir::Type>(ty)
.Case<fir::PointerType, fir::HeapType, fir::SequenceType>([](auto t) {
mlir::Type eleTy = t.getEleTy();
- if (auto seqTy = mlir::dyn_cast<fir::SequenceType>(eleTy))
+ if (auto seqTy = eleTy.dyn_cast<fir::SequenceType>())
return seqTy.getEleTy();
return eleTy;
})
@@ -384,14 +385,13 @@ mlir::Type unwrapInnerType(mlir::Type ty) {
}
bool isRecordWithAllocatableMember(mlir::Type ty) {
- if (auto recTy = mlir::dyn_cast<fir::RecordType>(ty))
+ if (auto recTy = ty.dyn_cast<fir::RecordType>())
for (auto [field, memTy] : recTy.getTypeList()) {
if (fir::isAllocatableType(memTy))
return true;
// A record type cannot recursively include itself as a direct member.
// There must be an intervening `ptr` type, so recursion is safe here.
- if (mlir::isa<fir::RecordType>(memTy) &&
- isRecordWithAllocatableMember(memTy))
+ if (memTy.isa<fir::RecordType>() && isRecordWithAllocatableMember(memTy))
return true;
}
return false;
@@ -399,12 +399,11 @@ bool isRecordWithAllocatableMember(mlir::Type ty) {
bool isRecordWithDescriptorMember(mlir::Type ty) {
ty = unwrapSequenceType(ty);
- if (auto recTy = mlir::dyn_cast<fir::RecordType>(ty))
+ if (auto recTy = ty.dyn_cast<fir::RecordType>())
for (auto [field, memTy] : recTy.getTypeList()) {
if (mlir::isa<fir::BaseBoxType>(memTy))
return true;
- if (mlir::isa<fir::RecordType>(memTy) &&
- isRecordWithDescriptorMember(memTy))
+ if (memTy.isa<fir::RecordType>() && isRecordWithDescriptorMember(memTy))
return true;
}
return false;
@@ -413,7 +412,7 @@ bool isRecordWithDescriptorMember(mlir::Type ty) {
mlir::Type unwrapAllRefAndSeqType(mlir::Type ty) {
while (true) {
mlir::Type nt = unwrapSequenceType(unwrapRefType(ty));
- if (auto vecTy = mlir::dyn_cast<fir::VectorType>(nt))
+ if (auto vecTy = nt.dyn_cast<fir::VectorType>())
nt = vecTy.getEleTy();
if (nt == ty)
return ty;
@@ -422,11 +421,11 @@ mlir::Type unwrapAllRefAndSeqType(mlir::Type ty) {
}
mlir::Type unwrapSeqOrBoxedSeqType(mlir::Type ty) {
- if (auto seqTy = mlir::dyn_cast<fir::SequenceType>(ty))
+ if (auto seqTy = ty.dyn_cast<fir::SequenceType>())
return seqTy.getEleTy();
- if (auto boxTy = mlir::dyn_cast<fir::BaseBoxType>(ty)) {
+ if (auto boxTy = ty.dyn_cast<fir::BaseBoxType>()) {
auto eleTy = unwrapRefType(boxTy.getEleTy());
- if (auto seqTy = mlir::dyn_cast<fir::SequenceType>(eleTy))
+ if (auto seqTy = eleTy.dyn_cast<fir::SequenceType>())
return seqTy.getEleTy();
}
return ty;
@@ -434,7 +433,7 @@ mlir::Type unwrapSeqOrBoxedSeqType(mlir::Type ty) {
unsigned getBoxRank(mlir::Type boxTy) {
auto eleTy = fir::dyn_cast_ptrOrBoxEleTy(boxTy);
- if (auto seqTy = mlir::dyn_cast<fir::SequenceType>(eleTy))
+ if (auto seqTy = eleTy.dyn_cast<fir::SequenceType>())
return seqTy.getDimension();
return 0;
}
@@ -442,7 +441,7 @@ unsigned getBoxRank(mlir::Type boxTy) {
/// Return the ISO_C_BINDING intrinsic module value of type \p ty.
int getTypeCode(mlir::Type ty, const fir::KindMapping &kindMap) {
unsigned width = 0;
- if (mlir::IntegerType intTy = mlir::dyn_cast<mlir::IntegerType>(ty)) {
+ if (mlir::IntegerType intTy = ty.dyn_cast<mlir::IntegerType>()) {
switch (intTy.getWidth()) {
case 8:
return CFI_type_int8_t;
@@ -457,7 +456,7 @@ int getTypeCode(mlir::Type ty, const fir::KindMapping &kindMap) {
}
llvm_unreachable("unsupported integer type");
}
- if (fir::LogicalType logicalTy = mlir::dyn_cast<fir::LogicalType>(ty)) {
+ if (fir::LogicalType logicalTy = ty.dyn_cast<fir::LogicalType>()) {
switch (kindMap.getLogicalBitsize(logicalTy.getFKind())) {
case 8:
return CFI_type_Bool;
@@ -470,7 +469,7 @@ int getTypeCode(mlir::Type ty, const fir::KindMapping &kindMap) {
}
llvm_unreachable("unsupported logical type");
}
- if (mlir::FloatType floatTy = mlir::dyn_cast<mlir::FloatType>(ty)) {
+ if (mlir::FloatType floatTy = ty.dyn_cast<mlir::FloatType>()) {
switch (floatTy.getWidth()) {
case 16:
return floatTy.isBF16() ? CFI_type_bfloat : CFI_type_half_float;
@@ -486,14 +485,13 @@ int getTypeCode(mlir::Type ty, const fir::KindMapping &kindMap) {
llvm_unreachable("unsupported real type");
}
if (fir::isa_complex(ty)) {
- if (mlir::ComplexType complexTy = mlir::dyn_cast<mlir::ComplexType>(ty)) {
+ if (mlir::ComplexType complexTy = ty.dyn_cast<mlir::ComplexType>()) {
mlir::FloatType floatTy =
- mlir::cast<mlir::FloatType>(complexTy.getElementType());
+ complexTy.getElementType().cast<mlir::FloatType>();
if (floatTy.isBF16())
return CFI_type_bfloat_Complex;
width = floatTy.getWidth();
- } else if (fir::ComplexType complexTy =
- mlir::dyn_cast<fir::ComplexType>(ty)) {
+ } else if (fir::ComplexType complexTy = ty.dyn_cast<fir::ComplexType>()) {
auto FKind = complexTy.getFKind();
if (FKind == 3)
return CFI_type_bfloat_Complex;
@@ -513,7 +511,7 @@ int getTypeCode(mlir::Type ty, const fir::KindMapping &kindMap) {
}
llvm_unreachable("unsupported complex size");
}
- if (fir::CharacterType charTy = mlir::dyn_cast<fir::CharacterType>(ty)) {
+ if (fir::CharacterType charTy = ty.dyn_cast<fir::CharacterType>()) {
switch (kindMap.getCharacterBitsize(charTy.getFKind())) {
case 8:
return CFI_type_char;
@@ -526,7 +524,7 @@ int getTypeCode(mlir::Type ty, const fir::KindMapping &kindMap) {
}
if (fir::isa_ref_type(ty))
return CFI_type_cptr;
- if (mlir::isa<fir::RecordType>(ty))
+ if (ty.isa<fir::RecordType>())
return CFI_type_struct;
llvm_unreachable("unsupported type");
}
@@ -544,12 +542,12 @@ std::string getTypeAsString(mlir::Type ty, const fir::KindMapping &kindMap,
name << "idx";
} else if (ty.isIntOrIndex()) {
name << 'i' << ty.getIntOrFloatBitWidth();
- } else if (mlir::isa<mlir::FloatType>(ty)) {
+ } else if (ty.isa<mlir::FloatType>()) {
name << 'f' << ty.getIntOrFloatBitWidth();
} else if (fir::isa_complex(ty)) {
name << 'z';
if (auto cplxTy = mlir::dyn_cast_or_null<mlir::ComplexType>(ty)) {
- auto floatTy = mlir::cast<mlir::FloatType>(cplxTy.getElementType());
+ auto floatTy = cplxTy.getElementType().cast<mlir::FloatType>();
name << floatTy.getWidth();
} else if (auto cplxTy = mlir::dyn_cast_or_null<fir::ComplexType>(ty)) {
name << kindMap.getRealBitsize(cplxTy.getFKind());
@@ -646,7 +644,7 @@ static llvm::SmallPtrSet<detail::RecordTypeStorage const *, 4>
} // namespace
void fir::verifyIntegralType(mlir::Type type) {
- if (isaIntegerType(type) || mlir::isa<mlir::IndexType>(type))
+ if (isaIntegerType(type) || type.isa<mlir::IndexType>())
return;
llvm::report_fatal_error("expected integral type");
}
@@ -658,9 +656,9 @@ void fir::printFirType(FIROpsDialect *, mlir::Type ty,
}
bool fir::isa_unknown_size_box(mlir::Type t) {
- if (auto boxTy = mlir::dyn_cast<fir::BaseBoxType>(t)) {
+ if (auto boxTy = t.dyn_cast<fir::BaseBoxType>()) {
auto valueType = fir::unwrapPassByRefType(boxTy);
- if (auto seqTy = mlir::dyn_cast<fir::SequenceType>(valueType))
+ if (auto seqTy = valueType.dyn_cast<fir::SequenceType>())
if (seqTy.hasUnknownShape())
return true;
}
@@ -686,10 +684,10 @@ void fir::BoxProcType::print(mlir::AsmPrinter &printer) const {
mlir::LogicalResult
BoxProcType::verify(llvm::function_ref<mlir::InFlightDiagnostic()> emitError,
mlir::Type eleTy) {
- if (mlir::isa<mlir::FunctionType>(eleTy))
+ if (eleTy.isa<mlir::FunctionType>())
return mlir::success();
- if (auto refTy = mlir::dyn_cast<ReferenceType>(eleTy))
- if (mlir::isa<mlir::FunctionType>(refTy))
+ if (auto refTy = eleTy.dyn_cast<ReferenceType>())
+ if (refTy.isa<mlir::FunctionType>())
return mlir::success();
return emitError() << "invalid type for boxproc" << eleTy << '\n';
}
@@ -707,7 +705,7 @@ static bool cannotBePointerOrHeapElementType(mlir::Type eleTy) {
mlir::LogicalResult
fir::BoxType::verify(llvm::function_ref<mlir::InFlightDiagnostic()> emitError,
mlir::Type eleTy) {
- if (mlir::isa<fir::BaseBoxType>(eleTy))
+ if (eleTy.isa<fir::BaseBoxType>())
return emitError() << "invalid element type\n";
// TODO
return mlir::success();
@@ -1238,10 +1236,10 @@ bool fir::VectorType::isValidElementType(mlir::Type t) {
}
bool fir::isCharacterProcedureTuple(mlir::Type ty, bool acceptRawFunc) {
- mlir::TupleType tuple = mlir::dyn_cast<mlir::TupleType>(ty);
+ mlir::TupleType tuple = ty.dyn_cast<mlir::TupleType>();
return tuple && tuple.size() == 2 &&
- (mlir::isa<fir::BoxProcType>(tuple.getType(0)) ||
- (acceptRawFunc && mlir::isa<mlir::FunctionType>(tuple.getType(0)))) &&
+ (tuple.getType(0).isa<fir::BoxProcType>() ||
+ (acceptRawFunc && tuple.getType(0).isa<mlir::FunctionType>())) &&
fir::isa_integer(tuple.getType(1));
}
@@ -1249,8 +1247,7 @@ bool fir::hasAbstractResult(mlir::FunctionType ty) {
if (ty.getNumResults() == 0)
return false;
auto resultType = ty.getResult(0);
- return mlir::isa<fir::SequenceType, fir::BaseBoxType, fir::RecordType>(
- resultType);
+ return resultType.isa<fir::SequenceType, fir::BaseBoxType, fir::RecordType>();
}
/// Convert llvm::Type::TypeID to mlir::Type. \p kind is provided for error
diff --git a/flang/lib/Optimizer/Dialect/FortranVariableInterface.cpp b/flang/lib/Optimizer/Dialect/FortranVariableInterface.cpp
index 70b1a2f3d8446f..94f1689dfb0585 100644
--- a/flang/lib/Optimizer/Dialect/FortranVariableInterface.cpp
+++ b/flang/lib/Optimizer/Dialect/FortranVariableInterface.cpp
@@ -18,7 +18,7 @@ mlir::LogicalResult
fir::FortranVariableOpInterface::verifyDeclareLikeOpImpl(mlir::Value memref) {
const unsigned numExplicitTypeParams = getExplicitTypeParams().size();
mlir::Type memType = memref.getType();
- const bool sourceIsBoxValue = mlir::isa<fir::BaseBoxType>(memType);
+ const bool sourceIsBoxValue = memType.isa<fir::BaseBoxType>();
const bool sourceIsBoxAddress = fir::isBoxAddress(memType);
const bool sourceIsBox = sourceIsBoxValue || sourceIsBoxAddress;
if (isCharacter()) {
@@ -29,8 +29,7 @@ fir::FortranVariableOpInterface::verifyDeclareLikeOpImpl(mlir::Value memref) {
return emitOpError("must be provided exactly one type parameter when its "
"base is a character that is not a box");
- } else if (auto recordType =
- mlir::dyn_cast<fir::RecordType>(getElementType())) {
+ } else if (auto recordType = getElementType().dyn_cast<fir::RecordType>()) {
if (numExplicitTypeParams < recordType.getNumLenParams() && !sourceIsBox)
return emitOpError("must be provided all the derived type length "
"parameters when the base is not a box");
@@ -46,16 +45,16 @@ fir::FortranVariableOpInterface::verifyDeclareLikeOpImpl(mlir::Value memref) {
if (sourceIsBoxAddress)
return emitOpError("for box address must not have a shape operand");
unsigned shapeRank = 0;
- if (auto shapeType = mlir::dyn_cast<fir::ShapeType>(shape.getType())) {
+ if (auto shapeType = shape.getType().dyn_cast<fir::ShapeType>()) {
shapeRank = shapeType.getRank();
} else if (auto shapeShiftType =
- mlir::dyn_cast<fir::ShapeShiftType>(shape.getType())) {
+ shape.getType().dyn_cast<fir::ShapeShiftType>()) {
shapeRank = shapeShiftType.getRank();
} else {
if (!sourceIsBoxValue)
emitOpError("of array entity with a raw address base must have a "
"shape operand that is a shape or shapeshift");
- shapeRank = mlir::cast<fir::ShiftType>(shape.getType()).getRank();
+ shapeRank = shape.getType().cast<fir::ShiftType>().getRank();
}
std::optional<unsigned> rank = getRank();
diff --git a/flang/lib/Optimizer/HLFIR/IR/HLFIRDialect.cpp b/flang/lib/Optimizer/HLFIR/IR/HLFIRDialect.cpp
index 0b61c0edce622b..08b2b0538c732a 100644
--- a/flang/lib/Optimizer/HLFIR/IR/HLFIRDialect.cpp
+++ b/flang/lib/Optimizer/HLFIR/IR/HLFIRDialect.cpp
@@ -84,8 +84,7 @@ bool hlfir::isFortranVariableType(mlir::Type type) {
return llvm::TypeSwitch<mlir::Type, bool>(type)
.Case<fir::ReferenceType, fir::PointerType, fir::HeapType>([](auto p) {
mlir::Type eleType = p.getEleTy();
- return mlir::isa<fir::BaseBoxType>(eleType) ||
- !fir::hasDynamicSize(eleType);
+ return eleType.isa<fir::BaseBoxType>() || !fir::hasDynamicSize(eleType);
})
.Case<fir::BaseBoxType, fir::BoxCharType>([](auto) { return true; })
.Case<fir::VectorType>([](auto) { return true; })
@@ -94,15 +93,15 @@ bool hlfir::isFortranVariableType(mlir::Type type) {
bool hlfir::isFortranScalarCharacterType(mlir::Type type) {
return isFortranScalarCharacterExprType(type) ||
- mlir::isa<fir::BoxCharType>(type) ||
- mlir::isa<fir::CharacterType>(
- fir::unwrapPassByRefType(fir::unwrapRefType(type)));
+ type.isa<fir::BoxCharType>() ||
+ fir::unwrapPassByRefType(fir::unwrapRefType(type))
+ .isa<fir::CharacterType>();
}
bool hlfir::isFortranScalarCharacterExprType(mlir::Type type) {
- if (auto exprType = mlir::dyn_cast<hlfir::ExprType>(type))
+ if (auto exprType = type.dyn_cast<hlfir::ExprType>())
return exprType.isScalar() &&
- mlir::isa<fir::CharacterType>(exprType.getElementType());
+ exprType.getElementType().isa<fir::CharacterType>();
return false;
}
@@ -122,8 +121,8 @@ bool hlfir::isFortranScalarNumericalType(mlir::Type type) {
bool hlfir::isFortranNumericalArrayObject(mlir::Type type) {
if (isBoxAddressType(type))
return false;
- if (auto arrayTy = mlir::dyn_cast<fir::SequenceType>(
- getFortranElementOrSequenceType(type)))
+ if (auto arrayTy =
+ getFortranElementOrSequenceType(type).dyn_cast<fir::SequenceType>())
return isFortranScalarNumericalType(arrayTy.getEleTy());
return false;
}
@@ -131,8 +130,8 @@ bool hlfir::isFortranNumericalArrayObject(mlir::Type type) {
bool hlfir::isFortranNumericalOrLogicalArrayObject(mlir::Type type) {
if (isBoxAddressType(type))
return false;
- if (auto arrayTy = mlir::dyn_cast<fir::SequenceType>(
- getFortranElementOrSequenceType(type))) {
+ if (auto arrayTy =
+ getFortranElementOrSequenceType(type).dyn_cast<fir::SequenceType>()) {
mlir::Type eleTy = arrayTy.getEleTy();
return isFortranScalarNumericalType(eleTy) ||
mlir::isa<fir::LogicalType>(eleTy);
@@ -143,8 +142,7 @@ bool hlfir::isFortranNumericalOrLogicalArrayObject(mlir::Type type) {
bool hlfir::isFortranArrayObject(mlir::Type type) {
if (isBoxAddressType(type))
return false;
- return !!mlir::dyn_cast<fir::SequenceType>(
- getFortranElementOrSequenceType(type));
+ return !!getFortranElementOrSequenceType(type).dyn_cast<fir::SequenceType>();
}
bool hlfir::isPassByRefOrIntegerType(mlir::Type type) {
@@ -153,7 +151,7 @@ bool hlfir::isPassByRefOrIntegerType(mlir::Type type) {
}
bool hlfir::isI1Type(mlir::Type type) {
- if (mlir::IntegerType integer = mlir::dyn_cast<mlir::IntegerType>(type))
+ if (mlir::IntegerType integer = type.dyn_cast<mlir::IntegerType>())
if (integer.getWidth() == 1)
return true;
return false;
@@ -162,8 +160,8 @@ bool hlfir::isI1Type(mlir::Type type) {
bool hlfir::isFortranLogicalArrayObject(mlir::Type type) {
if (isBoxAddressType(type))
return false;
- if (auto arrayTy = mlir::dyn_cast<fir::SequenceType>(
- getFortranElementOrSequenceType(type))) {
+ if (auto arrayTy =
+ getFortranElementOrSequenceType(type).dyn_cast<fir::SequenceType>()) {
mlir::Type eleTy = arrayTy.getEleTy();
return mlir::isa<fir::LogicalType>(eleTy);
}
diff --git a/flang/lib/Optimizer/HLFIR/IR/HLFIROps.cpp b/flang/lib/Optimizer/HLFIR/IR/HLFIROps.cpp
index 0d62ca4954e6bf..8bad4e445082d2 100644
--- a/flang/lib/Optimizer/HLFIR/IR/HLFIROps.cpp
+++ b/flang/lib/Optimizer/HLFIR/IR/HLFIROps.cpp
@@ -74,8 +74,8 @@ getIntrinsicEffects(mlir::Operation *self,
/// Is this a fir.[ref/ptr/heap]<fir.[box/class]<fir.heap<T>>> type?
static bool isAllocatableBoxRef(mlir::Type type) {
fir::BaseBoxType boxType =
- mlir::dyn_cast_or_null<fir::BaseBoxType>(fir::dyn_cast_ptrEleTy(type));
- return boxType && mlir::isa<fir::HeapType>(boxType.getEleTy());
+ fir::dyn_cast_ptrEleTy(type).dyn_cast_or_null<fir::BaseBoxType>();
+ return boxType && boxType.getEleTy().isa<fir::HeapType>();
}
mlir::LogicalResult hlfir::AssignOp::verify() {
@@ -84,7 +84,7 @@ mlir::LogicalResult hlfir::AssignOp::verify() {
return emitOpError("lhs must be an allocatable when `realloc` is set");
if (mustKeepLhsLengthInAllocatableAssignment() &&
!(isAllocatableAssignment() &&
- mlir::isa<fir::CharacterType>(hlfir::getFortranElementType(lhsType))))
+ hlfir::getFortranElementType(lhsType).isa<fir::CharacterType>()))
return emitOpError("`realloc` must be set and lhs must be a character "
"allocatable when `keep_lhs_length_if_realloc` is set");
return mlir::success();
@@ -99,13 +99,13 @@ mlir::LogicalResult hlfir::AssignOp::verify() {
mlir::Type hlfir::DeclareOp::getHLFIRVariableType(mlir::Type inputType,
bool hasExplicitLowerBounds) {
mlir::Type type = fir::unwrapRefType(inputType);
- if (mlir::isa<fir::BaseBoxType>(type))
+ if (type.isa<fir::BaseBoxType>())
return inputType;
- if (auto charType = mlir::dyn_cast<fir::CharacterType>(type))
+ if (auto charType = type.dyn_cast<fir::CharacterType>())
if (charType.hasDynamicLen())
return fir::BoxCharType::get(charType.getContext(), charType.getFKind());
- auto seqType = mlir::dyn_cast<fir::SequenceType>(type);
+ auto seqType = type.dyn_cast<fir::SequenceType>();
bool hasDynamicExtents =
seqType && fir::sequenceWithNonConstantShape(seqType);
mlir::Type eleType = seqType ? seqType.getEleTy() : type;
@@ -117,8 +117,7 @@ mlir::Type hlfir::DeclareOp::getHLFIRVariableType(mlir::Type inputType,
}
static bool hasExplicitLowerBounds(mlir::Value shape) {
- return shape &&
- mlir::isa<fir::ShapeShiftType, fir::ShiftType>(shape.getType());
+ return shape && shape.getType().isa<fir::ShapeShiftType, fir::ShiftType>();
}
void hlfir::DeclareOp::build(mlir::OpBuilder &builder,
@@ -289,7 +288,7 @@ mlir::LogicalResult hlfir::DesignateOp::verify() {
bool hasBoxComponent;
if (getComponent()) {
auto component = getComponent().value();
- auto recType = mlir::dyn_cast<fir::RecordType>(baseElementType);
+ auto recType = baseElementType.dyn_cast<fir::RecordType>();
if (!recType)
return emitOpError(
"component must be provided only when the memref is a derived type");
@@ -301,14 +300,14 @@ mlir::LogicalResult hlfir::DesignateOp::verify() {
}
mlir::Type fieldType = recType.getType(fieldIdx);
mlir::Type componentBaseType = getFortranElementOrSequenceType(fieldType);
- hasBoxComponent = mlir::isa<fir::BaseBoxType>(fieldType);
- if (mlir::isa<fir::SequenceType>(componentBaseType) &&
- mlir::isa<fir::SequenceType>(baseType) &&
+ hasBoxComponent = fieldType.isa<fir::BaseBoxType>();
+ if (componentBaseType.isa<fir::SequenceType>() &&
+ baseType.isa<fir::SequenceType>() &&
(numSubscripts == 0 || subscriptsRank > 0))
return emitOpError("indices must be provided and must not contain "
"triplets when both memref and component are arrays");
if (numSubscripts != 0) {
- if (!mlir::isa<fir::SequenceType>(componentBaseType))
+ if (!componentBaseType.isa<fir::SequenceType>())
return emitOpError("indices must not be provided if component appears "
"and is not an array component");
if (!getComponentShape())
@@ -316,9 +315,9 @@ mlir::LogicalResult hlfir::DesignateOp::verify() {
"component_shape must be provided when indexing a component");
mlir::Type compShapeType = getComponentShape().getType();
unsigned componentRank =
- mlir::cast<fir::SequenceType>(componentBaseType).getDimension();
- auto shapeType = mlir::dyn_cast<fir::ShapeType>(compShapeType);
- auto shapeShiftType = mlir::dyn_cast<fir::ShapeShiftType>(compShapeType);
+ componentBaseType.cast<fir::SequenceType>().getDimension();
+ auto shapeType = compShapeType.dyn_cast<fir::ShapeType>();
+ auto shapeShiftType = compShapeType.dyn_cast<fir::ShapeShiftType>();
if (!((shapeType && shapeType.getRank() == componentRank) ||
(shapeShiftType && shapeShiftType.getRank() == componentRank)))
return emitOpError("component_shape must be a fir.shape or "
@@ -326,33 +325,33 @@ mlir::LogicalResult hlfir::DesignateOp::verify() {
if (numSubscripts > componentRank)
return emitOpError("indices number must match array component rank");
}
- if (auto baseSeqType = mlir::dyn_cast<fir::SequenceType>(baseType))
+ if (auto baseSeqType = baseType.dyn_cast<fir::SequenceType>())
// This case must come first to cover "array%array_comp(i, j)" that has
// subscripts for the component but whose rank come from the base.
outputRank = baseSeqType.getDimension();
else if (numSubscripts != 0)
outputRank = subscriptsRank;
else if (auto componentSeqType =
- mlir::dyn_cast<fir::SequenceType>(componentBaseType))
+ componentBaseType.dyn_cast<fir::SequenceType>())
outputRank = componentSeqType.getDimension();
outputElementType = fir::unwrapSequenceType(componentBaseType);
} else {
outputElementType = baseElementType;
unsigned baseTypeRank =
- mlir::isa<fir::SequenceType>(baseType)
- ? mlir::cast<fir::SequenceType>(baseType).getDimension()
+ baseType.isa<fir::SequenceType>()
+ ? baseType.cast<fir::SequenceType>().getDimension()
: 0;
if (numSubscripts != 0) {
if (baseTypeRank != numSubscripts)
return emitOpError("indices number must match memref rank");
outputRank = subscriptsRank;
- } else if (auto baseSeqType = mlir::dyn_cast<fir::SequenceType>(baseType)) {
+ } else if (auto baseSeqType = baseType.dyn_cast<fir::SequenceType>()) {
outputRank = baseSeqType.getDimension();
}
}
if (!getSubstring().empty()) {
- if (!mlir::isa<fir::CharacterType>(outputElementType))
+ if (!outputElementType.isa<fir::CharacterType>())
return emitOpError("memref or component must have character type if "
"substring indices are provided");
if (getSubstring().size() != 2)
@@ -362,16 +361,16 @@ mlir::LogicalResult hlfir::DesignateOp::verify() {
if (!fir::isa_complex(outputElementType))
return emitOpError("memref or component must have complex type if "
"complex_part is provided");
- if (auto firCplx = mlir::dyn_cast<fir::ComplexType>(outputElementType))
+ if (auto firCplx = outputElementType.dyn_cast<fir::ComplexType>())
outputElementType = firCplx.getElementType();
else
outputElementType =
- mlir::cast<mlir::ComplexType>(outputElementType).getElementType();
+ outputElementType.cast<mlir::ComplexType>().getElementType();
}
mlir::Type resultBaseType =
getFortranElementOrSequenceType(getResult().getType());
unsigned resultRank = 0;
- if (auto resultSeqType = mlir::dyn_cast<fir::SequenceType>(resultBaseType))
+ if (auto resultSeqType = resultBaseType.dyn_cast<fir::SequenceType>())
resultRank = resultSeqType.getDimension();
if (resultRank != outputRank)
return emitOpError("result type rank is not consistent with operands, "
@@ -381,10 +380,10 @@ mlir::LogicalResult hlfir::DesignateOp::verify() {
// result type must match the one that was inferred here, except the character
// length may
diff er because of substrings.
if (resultElementType != outputElementType &&
- !(mlir::isa<fir::CharacterType>(resultElementType) &&
- mlir::isa<fir::CharacterType>(outputElementType)) &&
- !(mlir::isa<mlir::FloatType>(resultElementType) &&
- mlir::isa<fir::RealType>(outputElementType)))
+ !(resultElementType.isa<fir::CharacterType>() &&
+ outputElementType.isa<fir::CharacterType>()) &&
+ !(resultElementType.isa<mlir::FloatType>() &&
+ outputElementType.isa<fir::RealType>()))
return emitOpError(
"result element type is not consistent with operands, expected ")
<< outputElementType;
@@ -402,22 +401,22 @@ mlir::LogicalResult hlfir::DesignateOp::verify() {
return emitOpError("shape must be provided if and only if the result is "
"an array that is not a box address");
if (resultRank != 0) {
- auto shapeType = mlir::dyn_cast<fir::ShapeType>(getShape().getType());
+ auto shapeType = getShape().getType().dyn_cast<fir::ShapeType>();
auto shapeShiftType =
- mlir::dyn_cast<fir::ShapeShiftType>(getShape().getType());
+ getShape().getType().dyn_cast<fir::ShapeShiftType>();
if (!((shapeType && shapeType.getRank() == resultRank) ||
(shapeShiftType && shapeShiftType.getRank() == resultRank)))
return emitOpError("shape must be a fir.shape or fir.shapeshift with "
"the rank of the result");
}
auto numLenParam = getTypeparams().size();
- if (mlir::isa<fir::CharacterType>(outputElementType)) {
+ if (outputElementType.isa<fir::CharacterType>()) {
if (numLenParam != 1)
return emitOpError("must be provided one length parameter when the "
"result is a character");
} else if (fir::isRecordWithTypeParameters(outputElementType)) {
if (numLenParam !=
- mlir::cast<fir::RecordType>(outputElementType).getNumLenParams())
+ outputElementType.cast<fir::RecordType>().getNumLenParams())
return emitOpError("must be provided the same number of length "
"parameters as in the result derived type");
} else if (numLenParam != 0) {
@@ -435,18 +434,18 @@ mlir::LogicalResult hlfir::DesignateOp::verify() {
mlir::LogicalResult hlfir::ParentComponentOp::verify() {
mlir::Type baseType =
hlfir::getFortranElementOrSequenceType(getMemref().getType());
- auto maybeInputSeqType = mlir::dyn_cast<fir::SequenceType>(baseType);
+ auto maybeInputSeqType = baseType.dyn_cast<fir::SequenceType>();
unsigned inputTypeRank =
maybeInputSeqType ? maybeInputSeqType.getDimension() : 0;
unsigned shapeRank = 0;
if (mlir::Value shape = getShape())
- if (auto shapeType = mlir::dyn_cast<fir::ShapeType>(shape.getType()))
+ if (auto shapeType = shape.getType().dyn_cast<fir::ShapeType>())
shapeRank = shapeType.getRank();
if (inputTypeRank != shapeRank)
return emitOpError(
"must be provided a shape if and only if the base is an array");
mlir::Type outputBaseType = hlfir::getFortranElementOrSequenceType(getType());
- auto maybeOutputSeqType = mlir::dyn_cast<fir::SequenceType>(outputBaseType);
+ auto maybeOutputSeqType = outputBaseType.dyn_cast<fir::SequenceType>();
unsigned outputTypeRank =
maybeOutputSeqType ? maybeOutputSeqType.getDimension() : 0;
if (inputTypeRank != outputTypeRank)
@@ -460,23 +459,23 @@ mlir::LogicalResult hlfir::ParentComponentOp::verify() {
return emitOpError(
"result type extents are inconsistent with memref type");
fir::RecordType baseRecType =
- mlir::dyn_cast<fir::RecordType>(hlfir::getFortranElementType(baseType));
- fir::RecordType outRecType = mlir::dyn_cast<fir::RecordType>(
- hlfir::getFortranElementType(outputBaseType));
+ hlfir::getFortranElementType(baseType).dyn_cast<fir::RecordType>();
+ fir::RecordType outRecType =
+ hlfir::getFortranElementType(outputBaseType).dyn_cast<fir::RecordType>();
if (!baseRecType || !outRecType)
return emitOpError("result type and input type must be derived types");
// Note: result should not be a fir.class: its dynamic type is being set to
// the parent type and allowing fir.class would break the operation codegen:
// it would keep the input dynamic type.
- if (mlir::isa<fir::ClassType>(getType()))
+ if (getType().isa<fir::ClassType>())
return emitOpError("result type must not be polymorphic");
// The array results are known to not be dis-contiguous in most cases (the
// exception being if the parent type was extended by a type without any
// components): require a fir.box to be used for the result to carry the
// strides.
- if (!mlir::isa<fir::BoxType>(getType()) &&
+ if (!getType().isa<fir::BoxType>() &&
(outputTypeRank != 0 || fir::isRecordWithTypeParameters(outRecType)))
return emitOpError("result type must be a fir.box if the result is an "
"array or has length parameters");
@@ -497,8 +496,9 @@ verifyLogicalReductionOp(LogicalReductionOp reductionOp) {
mlir::Value mask = reductionOp->getMask();
mlir::Value dim = reductionOp->getDim();
- fir::SequenceType maskTy = mlir::cast<fir::SequenceType>(
- hlfir::getFortranElementOrSequenceType(mask.getType()));
+ fir::SequenceType maskTy =
+ hlfir::getFortranElementOrSequenceType(mask.getType())
+ .cast<fir::SequenceType>();
mlir::Type logicalTy = maskTy.getEleTy();
llvm::ArrayRef<int64_t> maskShape = maskTy.getShape();
@@ -576,8 +576,9 @@ mlir::LogicalResult hlfir::CountOp::verify() {
mlir::Value mask = getMask();
mlir::Value dim = getDim();
- fir::SequenceType maskTy = mlir::cast<fir::SequenceType>(
- hlfir::getFortranElementOrSequenceType(mask.getType()));
+ fir::SequenceType maskTy =
+ hlfir::getFortranElementOrSequenceType(mask.getType())
+ .cast<fir::SequenceType>();
llvm::ArrayRef<int64_t> maskShape = maskTy.getShape();
mlir::Type resultType = results[0];
@@ -612,14 +613,13 @@ void hlfir::CountOp::getEffects(
//===----------------------------------------------------------------------===//
static unsigned getCharacterKind(mlir::Type t) {
- return mlir::cast<fir::CharacterType>(hlfir::getFortranElementType(t))
- .getFKind();
+ return hlfir::getFortranElementType(t).cast<fir::CharacterType>().getFKind();
}
static std::optional<fir::CharacterType::LenType>
getCharacterLengthIfStatic(mlir::Type t) {
if (auto charType =
- mlir::dyn_cast<fir::CharacterType>(hlfir::getFortranElementType(t)))
+ hlfir::getFortranElementType(t).dyn_cast<fir::CharacterType>())
if (charType.hasConstantLen())
return charType.getLen();
return std::nullopt;
@@ -672,13 +672,15 @@ verifyArrayAndMaskForReductionOp(NumericalReductionOp reductionOp) {
mlir::Value array = reductionOp->getArray();
mlir::Value mask = reductionOp->getMask();
- fir::SequenceType arrayTy = mlir::cast<fir::SequenceType>(
- hlfir::getFortranElementOrSequenceType(array.getType()));
+ fir::SequenceType arrayTy =
+ hlfir::getFortranElementOrSequenceType(array.getType())
+ .cast<fir::SequenceType>();
llvm::ArrayRef<int64_t> arrayShape = arrayTy.getShape();
if (mask) {
- fir::SequenceType maskSeq = mlir::dyn_cast<fir::SequenceType>(
- hlfir::getFortranElementOrSequenceType(mask.getType()));
+ fir::SequenceType maskSeq =
+ hlfir::getFortranElementOrSequenceType(mask.getType())
+ .dyn_cast<fir::SequenceType>();
llvm::ArrayRef<int64_t> maskShape;
if (maskSeq)
@@ -718,8 +720,9 @@ verifyNumericalReductionOp(NumericalReductionOp reductionOp) {
mlir::Value array = reductionOp->getArray();
mlir::Value dim = reductionOp->getDim();
- fir::SequenceType arrayTy = mlir::cast<fir::SequenceType>(
- hlfir::getFortranElementOrSequenceType(array.getType()));
+ fir::SequenceType arrayTy =
+ hlfir::getFortranElementOrSequenceType(array.getType())
+ .cast<fir::SequenceType>();
mlir::Type numTy = arrayTy.getEleTy();
llvm::ArrayRef<int64_t> arrayShape = arrayTy.getShape();
@@ -787,12 +790,13 @@ verifyCharacterReductionOp(CharacterReductionOp reductionOp) {
mlir::Value array = reductionOp->getArray();
mlir::Value dim = reductionOp->getDim();
- fir::SequenceType arrayTy = mlir::cast<fir::SequenceType>(
- hlfir::getFortranElementOrSequenceType(array.getType()));
+ fir::SequenceType arrayTy =
+ hlfir::getFortranElementOrSequenceType(array.getType())
+ .cast<fir::SequenceType>();
mlir::Type numTy = arrayTy.getEleTy();
llvm::ArrayRef<int64_t> arrayShape = arrayTy.getShape();
- auto resultExpr = mlir::cast<hlfir::ExprType>(results[0]);
+ auto resultExpr = results[0].cast<hlfir::ExprType>();
mlir::Type resultType = resultExpr.getEleTy();
assert(mlir::isa<fir::CharacterType>(resultType) &&
"result must be character");
@@ -877,8 +881,9 @@ verifyResultForMinMaxLoc(NumericalReductionOp reductionOp) {
mlir::Value array = reductionOp->getArray();
mlir::Value dim = reductionOp->getDim();
- fir::SequenceType arrayTy = mlir::cast<fir::SequenceType>(
- hlfir::getFortranElementOrSequenceType(array.getType()));
+ fir::SequenceType arrayTy =
+ hlfir::getFortranElementOrSequenceType(array.getType())
+ .cast<fir::SequenceType>();
llvm::ArrayRef<int64_t> arrayShape = arrayTy.getShape();
mlir::Type resultType = results[0];
@@ -988,10 +993,12 @@ void hlfir::SumOp::getEffects(
mlir::LogicalResult hlfir::DotProductOp::verify() {
mlir::Value lhs = getLhs();
mlir::Value rhs = getRhs();
- fir::SequenceType lhsTy = mlir::cast<fir::SequenceType>(
- hlfir::getFortranElementOrSequenceType(lhs.getType()));
- fir::SequenceType rhsTy = mlir::cast<fir::SequenceType>(
- hlfir::getFortranElementOrSequenceType(rhs.getType()));
+ fir::SequenceType lhsTy =
+ hlfir::getFortranElementOrSequenceType(lhs.getType())
+ .cast<fir::SequenceType>();
+ fir::SequenceType rhsTy =
+ hlfir::getFortranElementOrSequenceType(rhs.getType())
+ .cast<fir::SequenceType>();
llvm::ArrayRef<int64_t> lhsShape = lhsTy.getShape();
llvm::ArrayRef<int64_t> rhsShape = rhsTy.getShape();
std::size_t lhsRank = lhsShape.size();
@@ -1044,17 +1051,19 @@ void hlfir::DotProductOp::getEffects(
mlir::LogicalResult hlfir::MatmulOp::verify() {
mlir::Value lhs = getLhs();
mlir::Value rhs = getRhs();
- fir::SequenceType lhsTy = mlir::cast<fir::SequenceType>(
- hlfir::getFortranElementOrSequenceType(lhs.getType()));
- fir::SequenceType rhsTy = mlir::cast<fir::SequenceType>(
- hlfir::getFortranElementOrSequenceType(rhs.getType()));
+ fir::SequenceType lhsTy =
+ hlfir::getFortranElementOrSequenceType(lhs.getType())
+ .cast<fir::SequenceType>();
+ fir::SequenceType rhsTy =
+ hlfir::getFortranElementOrSequenceType(rhs.getType())
+ .cast<fir::SequenceType>();
llvm::ArrayRef<int64_t> lhsShape = lhsTy.getShape();
llvm::ArrayRef<int64_t> rhsShape = rhsTy.getShape();
std::size_t lhsRank = lhsShape.size();
std::size_t rhsRank = rhsShape.size();
mlir::Type lhsEleTy = lhsTy.getEleTy();
mlir::Type rhsEleTy = rhsTy.getEleTy();
- hlfir::ExprType resultTy = mlir::cast<hlfir::ExprType>(getResult().getType());
+ hlfir::ExprType resultTy = getResult().getType().cast<hlfir::ExprType>();
llvm::ArrayRef<int64_t> resultShape = resultTy.getShape();
mlir::Type resultEleTy = resultTy.getEleTy();
@@ -1171,12 +1180,13 @@ void hlfir::MatmulOp::getEffects(
mlir::LogicalResult hlfir::TransposeOp::verify() {
mlir::Value array = getArray();
- fir::SequenceType arrayTy = mlir::cast<fir::SequenceType>(
- hlfir::getFortranElementOrSequenceType(array.getType()));
+ fir::SequenceType arrayTy =
+ hlfir::getFortranElementOrSequenceType(array.getType())
+ .cast<fir::SequenceType>();
llvm::ArrayRef<int64_t> inShape = arrayTy.getShape();
std::size_t rank = inShape.size();
mlir::Type eleTy = arrayTy.getEleTy();
- hlfir::ExprType resultTy = mlir::cast<hlfir::ExprType>(getResult().getType());
+ hlfir::ExprType resultTy = getResult().getType().cast<hlfir::ExprType>();
llvm::ArrayRef<int64_t> resultShape = resultTy.getShape();
std::size_t resultRank = resultShape.size();
mlir::Type resultEleTy = resultTy.getEleTy();
@@ -1214,17 +1224,19 @@ void hlfir::TransposeOp::getEffects(
mlir::LogicalResult hlfir::MatmulTransposeOp::verify() {
mlir::Value lhs = getLhs();
mlir::Value rhs = getRhs();
- fir::SequenceType lhsTy = mlir::cast<fir::SequenceType>(
- hlfir::getFortranElementOrSequenceType(lhs.getType()));
- fir::SequenceType rhsTy = mlir::cast<fir::SequenceType>(
- hlfir::getFortranElementOrSequenceType(rhs.getType()));
+ fir::SequenceType lhsTy =
+ hlfir::getFortranElementOrSequenceType(lhs.getType())
+ .cast<fir::SequenceType>();
+ fir::SequenceType rhsTy =
+ hlfir::getFortranElementOrSequenceType(rhs.getType())
+ .cast<fir::SequenceType>();
llvm::ArrayRef<int64_t> lhsShape = lhsTy.getShape();
llvm::ArrayRef<int64_t> rhsShape = rhsTy.getShape();
std::size_t lhsRank = lhsShape.size();
std::size_t rhsRank = rhsShape.size();
mlir::Type lhsEleTy = lhsTy.getEleTy();
mlir::Type rhsEleTy = rhsTy.getEleTy();
- hlfir::ExprType resultTy = mlir::cast<hlfir::ExprType>(getResult().getType());
+ hlfir::ExprType resultTy = getResult().getType().cast<hlfir::ExprType>();
llvm::ArrayRef<int64_t> resultShape = resultTy.getShape();
mlir::Type resultEleTy = resultTy.getEleTy();
@@ -1369,7 +1381,7 @@ void hlfir::AsExprOp::build(mlir::OpBuilder &builder,
hlfir::ExprType::Shape typeShape;
bool isPolymorphic = fir::isPolymorphicType(var.getType());
mlir::Type type = getFortranElementOrSequenceType(var.getType());
- if (auto seqType = mlir::dyn_cast<fir::SequenceType>(type)) {
+ if (auto seqType = type.dyn_cast<fir::SequenceType>()) {
typeShape.append(seqType.getShape().begin(), seqType.getShape().end());
type = seqType.getEleTy();
}
@@ -1415,7 +1427,7 @@ static void buildElemental(mlir::OpBuilder &builder,
isUnordered ? builder.getUnitAttr() : nullptr);
mlir::Region *bodyRegion = odsState.addRegion();
bodyRegion->push_back(new mlir::Block{});
- if (auto shapeType = mlir::dyn_cast<fir::ShapeType>(shape.getType())) {
+ if (auto shapeType = shape.getType().dyn_cast<fir::ShapeType>()) {
unsigned dim = shapeType.getRank();
mlir::Type indexType = builder.getIndexType();
for (unsigned d = 0; d < dim; ++d)
@@ -1456,7 +1468,7 @@ void hlfir::ApplyOp::build(mlir::OpBuilder &builder,
mlir::ValueRange indices,
mlir::ValueRange typeparams) {
mlir::Type resultType = expr.getType();
- if (auto exprType = mlir::dyn_cast<hlfir::ExprType>(resultType))
+ if (auto exprType = resultType.dyn_cast<hlfir::ExprType>())
resultType = exprType.getElementExprType();
build(builder, odsState, resultType, expr, indices, typeparams);
}
@@ -1505,20 +1517,20 @@ void hlfir::CopyInOp::build(mlir::OpBuilder &builder,
void hlfir::ShapeOfOp::build(mlir::OpBuilder &builder,
mlir::OperationState &result, mlir::Value expr) {
- hlfir::ExprType exprTy = mlir::cast<hlfir::ExprType>(expr.getType());
+ hlfir::ExprType exprTy = expr.getType().cast<hlfir::ExprType>();
mlir::Type type = fir::ShapeType::get(builder.getContext(), exprTy.getRank());
build(builder, result, type, expr);
}
std::size_t hlfir::ShapeOfOp::getRank() {
mlir::Type resTy = getResult().getType();
- fir::ShapeType shape = mlir::cast<fir::ShapeType>(resTy);
+ fir::ShapeType shape = resTy.cast<fir::ShapeType>();
return shape.getRank();
}
mlir::LogicalResult hlfir::ShapeOfOp::verify() {
mlir::Value expr = getExpr();
- hlfir::ExprType exprTy = mlir::cast<hlfir::ExprType>(expr.getType());
+ hlfir::ExprType exprTy = expr.getType().cast<hlfir::ExprType>();
std::size_t exprRank = exprTy.getShape().size();
if (exprRank == 0)
@@ -1537,8 +1549,7 @@ hlfir::ShapeOfOp::canonicalize(ShapeOfOp shapeOf,
// if extent information is available at compile time, immediately fold the
// hlfir.shape_of into a fir.shape
mlir::Location loc = shapeOf.getLoc();
- hlfir::ExprType expr =
- mlir::cast<hlfir::ExprType>(shapeOf.getExpr().getType());
+ hlfir::ExprType expr = shapeOf.getExpr().getType().cast<hlfir::ExprType>();
mlir::Value shape = hlfir::genExprShape(rewriter, loc, expr);
if (!shape)
@@ -1563,7 +1574,7 @@ void hlfir::GetExtentOp::build(mlir::OpBuilder &builder,
}
mlir::LogicalResult hlfir::GetExtentOp::verify() {
- fir::ShapeType shapeTy = mlir::cast<fir::ShapeType>(getShape().getType());
+ fir::ShapeType shapeTy = getShape().getType().cast<fir::ShapeType>();
std::uint64_t rank = shapeTy.getRank();
llvm::APInt dim = getDim();
if (dim.sge(rank))
@@ -1698,11 +1709,10 @@ mlir::LogicalResult hlfir::ElementalAddrOp::verify() {
return emitOpError("body region must be terminated by an hlfir.yield");
mlir::Type elementAddrType = yieldOp.getEntity().getType();
if (!hlfir::isFortranVariableType(elementAddrType) ||
- mlir::isa<fir::SequenceType>(
- hlfir::getFortranElementOrSequenceType(elementAddrType)))
+ hlfir::getFortranElementOrSequenceType(elementAddrType)
+ .isa<fir::SequenceType>())
return emitOpError("body must compute the address of a scalar entity");
- unsigned shapeRank =
- mlir::cast<fir::ShapeType>(getShape().getType()).getRank();
+ unsigned shapeRank = getShape().getType().cast<fir::ShapeType>().getRank();
if (shapeRank != getIndices().size())
return emitOpError("body number of indices must match shape rank");
return mlir::success();
@@ -1807,8 +1817,8 @@ static bool yieldsLogical(mlir::Region ®ion, bool mustBeScalarI1) {
if (mustBeScalarI1)
return hlfir::isI1Type(yieldType);
return hlfir::isMaskArgument(yieldType) &&
- mlir::isa<fir::SequenceType>(
- hlfir::getFortranElementOrSequenceType(yieldType));
+ hlfir::getFortranElementOrSequenceType(yieldType)
+ .isa<fir::SequenceType>();
}
mlir::LogicalResult hlfir::ForallMaskOp::verify() {
diff --git a/flang/lib/Optimizer/HLFIR/Transforms/BufferizeHLFIR.cpp b/flang/lib/Optimizer/HLFIR/Transforms/BufferizeHLFIR.cpp
index d4e4835ee7265c..1c4f82e2de818b 100644
--- a/flang/lib/Optimizer/HLFIR/Transforms/BufferizeHLFIR.cpp
+++ b/flang/lib/Optimizer/HLFIR/Transforms/BufferizeHLFIR.cpp
@@ -77,7 +77,7 @@ static mlir::Value packageBufferizedExpr(mlir::Location loc,
/// currently enforced by the verifiers that only accept HLFIR value or
/// variable types which do not include tuples.
static hlfir::Entity getBufferizedExprStorage(mlir::Value bufferizedExpr) {
- auto tupleType = mlir::dyn_cast<mlir::TupleType>(bufferizedExpr.getType());
+ auto tupleType = bufferizedExpr.getType().dyn_cast<mlir::TupleType>();
if (!tupleType)
return hlfir::Entity{bufferizedExpr};
assert(tupleType.size() == 2 && "unexpected tuple type");
@@ -90,7 +90,7 @@ static hlfir::Entity getBufferizedExprStorage(mlir::Value bufferizedExpr) {
/// Helper to extract the clean-up flag from a tuple created by
/// packageBufferizedExpr.
static mlir::Value getBufferizedExprMustFreeFlag(mlir::Value bufferizedExpr) {
- auto tupleType = mlir::dyn_cast<mlir::TupleType>(bufferizedExpr.getType());
+ auto tupleType = bufferizedExpr.getType().dyn_cast<mlir::TupleType>();
if (!tupleType)
return bufferizedExpr;
assert(tupleType.size() == 2 && "unexpected tuple type");
@@ -218,7 +218,7 @@ struct ShapeOfOpConversion
} else {
// everything else failed so try to create a shape from static type info
hlfir::ExprType exprTy =
- mlir::dyn_cast_or_null<hlfir::ExprType>(adaptor.getExpr().getType());
+ adaptor.getExpr().getType().dyn_cast_or_null<hlfir::ExprType>();
if (exprTy)
shape = hlfir::genExprShape(builder, loc, exprTy);
}
@@ -480,10 +480,10 @@ struct AssociateOpConversion
assert(mlir::isa<fir::ClassType>(sourceVar.getType()) &&
fir::isAllocatableType(sourceVar.getType()));
assert(sourceVar.getType() == assocType);
- } else if ((mlir::isa<fir::BaseBoxType>(sourceVar.getType()) &&
- !mlir::isa<fir::BaseBoxType>(assocType)) ||
- ((mlir::isa<fir::BoxCharType>(sourceVar.getType()) &&
- !mlir::isa<fir::BoxCharType>(assocType)))) {
+ } else if ((sourceVar.getType().isa<fir::BaseBoxType>() &&
+ !assocType.isa<fir::BaseBoxType>()) ||
+ ((sourceVar.getType().isa<fir::BoxCharType>() &&
+ !assocType.isa<fir::BoxCharType>()))) {
sourceVar = builder.create<fir::BoxAddrOp>(loc, assocType, sourceVar);
} else {
sourceVar = builder.createConvert(loc, assocType, sourceVar);
@@ -590,13 +590,13 @@ static void genBufferDestruction(mlir::Location loc, fir::FirOpBuilder &builder,
// for MERGE with polymorphic results.
if (mustFinalize)
TODO(loc, "finalizing polymorphic temporary in HLFIR");
- } else if (mlir::isa<fir::BaseBoxType, fir::BoxCharType>(var.getType())) {
+ } else if (var.getType().isa<fir::BaseBoxType, fir::BoxCharType>()) {
if (mustFinalize && !mlir::isa<fir::BaseBoxType>(var.getType()))
fir::emitFatalError(loc, "non-finalizable variable");
addr = builder.create<fir::BoxAddrOp>(loc, heapType, var);
} else {
- if (!mlir::isa<fir::HeapType>(var.getType()))
+ if (!var.getType().isa<fir::HeapType>())
addr = builder.create<fir::ConvertOp>(loc, heapType, var);
if (mustFinalize || deallocComponents) {
@@ -831,7 +831,7 @@ struct ElementalOpConversion
// the assign, insert an hlfir.destroy to mark the expression end-of-life.
// If the expression creation allocated a buffer on the heap inside the
// loop, this will ensure the buffer properly deallocated.
- if (mlir::isa<hlfir::ExprType>(elementValue.getType()) &&
+ if (elementValue.getType().isa<hlfir::ExprType>() &&
wasCreatedInCurrentBlock(elementValue, builder))
builder.create<hlfir::DestroyOp>(loc, elementValue);
}
@@ -926,12 +926,11 @@ class BufferizeHLFIR : public hlfir::impl::BufferizeHLFIRBase<BufferizeHLFIR> {
hlfir::EndAssociateOp, hlfir::SetLengthOp>();
target.markUnknownOpDynamicallyLegal([](mlir::Operation *op) {
- return llvm::all_of(op->getResultTypes(),
- [](mlir::Type ty) {
- return !mlir::isa<hlfir::ExprType>(ty);
- }) &&
+ return llvm::all_of(
+ op->getResultTypes(),
+ [](mlir::Type ty) { return !ty.isa<hlfir::ExprType>(); }) &&
llvm::all_of(op->getOperandTypes(), [](mlir::Type ty) {
- return !mlir::isa<hlfir::ExprType>(ty);
+ return !ty.isa<hlfir::ExprType>();
});
});
if (mlir::failed(
diff --git a/flang/lib/Optimizer/HLFIR/Transforms/ConvertToFIR.cpp b/flang/lib/Optimizer/HLFIR/Transforms/ConvertToFIR.cpp
index 517285dce133de..cd534bae4ad2a7 100644
--- a/flang/lib/Optimizer/HLFIR/Transforms/ConvertToFIR.cpp
+++ b/flang/lib/Optimizer/HLFIR/Transforms/ConvertToFIR.cpp
@@ -34,7 +34,7 @@ using namespace mlir;
static mlir::Value genAllocatableTempFromSourceBox(mlir::Location loc,
fir::FirOpBuilder &builder,
mlir::Value sourceBox) {
- assert(mlir::isa<fir::BaseBoxType>(sourceBox.getType()) &&
+ assert(sourceBox.getType().isa<fir::BaseBoxType>() &&
"must be a base box type");
// Use the runtime to make a quick and dirty temp with the rhs value.
// Overkill for scalar rhs that could be done in much more clever ways.
@@ -44,7 +44,7 @@ static mlir::Value genAllocatableTempFromSourceBox(mlir::Location loc,
// This has the huge benefit of dealing with all cases, including
// polymorphic entities.
mlir::Type fromHeapType = fir::HeapType::get(fir::unwrapRefType(
- mlir::cast<fir::BaseBoxType>(sourceBox.getType()).getEleTy()));
+ sourceBox.getType().cast<fir::BaseBoxType>().getEleTy()));
mlir::Type fromBoxHeapType = fir::BoxType::get(fromHeapType);
mlir::Value fromMutableBox =
fir::factory::genNullBoxStorage(builder, loc, fromBoxHeapType);
@@ -69,7 +69,7 @@ class AssignOpConversion : public mlir::OpRewritePattern<hlfir::AssignOp> {
auto module = assignOp->getParentOfType<mlir::ModuleOp>();
fir::FirOpBuilder builder(rewriter, module);
- if (mlir::isa<hlfir::ExprType>(rhs.getType())) {
+ if (rhs.getType().isa<hlfir::ExprType>()) {
mlir::emitError(loc, "hlfir must be bufferized with --bufferize-hlfir "
"pass before being converted to FIR");
return mlir::failure();
@@ -343,15 +343,16 @@ class DeclareOpConversion : public mlir::OpRewritePattern<hlfir::DeclareOp> {
auto firBase = firDeclareOp.getResult();
mlir::Value hlfirBase;
mlir::Type hlfirBaseType = declareOp.getBase().getType();
- if (mlir::isa<fir::BaseBoxType>(hlfirBaseType)) {
+ if (hlfirBaseType.isa<fir::BaseBoxType>()) {
fir::FirOpBuilder builder(rewriter, declareOp.getOperation());
// Helper to generate the hlfir fir.box with the local lower bounds and
// type parameters.
auto genHlfirBox = [&]() -> mlir::Value {
- if (!mlir::isa<fir::BaseBoxType>(firBase.getType())) {
+ if (!firBase.getType().isa<fir::BaseBoxType>()) {
llvm::SmallVector<mlir::Value> typeParams;
- auto maybeCharType = mlir::dyn_cast<fir::CharacterType>(
- fir::unwrapSequenceType(fir::unwrapPassByRefType(hlfirBaseType)));
+ auto maybeCharType =
+ fir::unwrapSequenceType(fir::unwrapPassByRefType(hlfirBaseType))
+ .dyn_cast<fir::CharacterType>();
if (!maybeCharType || maybeCharType.hasDynamicLen())
typeParams.append(declareOp.getTypeparams().begin(),
declareOp.getTypeparams().end());
@@ -398,7 +399,7 @@ class DeclareOpConversion : public mlir::OpRewritePattern<hlfir::DeclareOp> {
})
.getResults()[0];
}
- } else if (mlir::isa<fir::BoxCharType>(hlfirBaseType)) {
+ } else if (hlfirBaseType.isa<fir::BoxCharType>()) {
assert(declareOp.getTypeparams().size() == 1 &&
"must contain character length");
hlfirBase = rewriter.create<fir::EmboxCharOp>(
@@ -479,12 +480,11 @@ class DesignateOpConversion
// - scalar%scalar_component [substring|complex_part] or
// - scalar%static_size_array_comp
// - scalar%array(indices) [substring| complex part]
- mlir::Type componentType =
- mlir::cast<fir::RecordType>(baseEleTy).getType(
- designate.getComponent().value());
+ mlir::Type componentType = baseEleTy.cast<fir::RecordType>().getType(
+ designate.getComponent().value());
mlir::Type coorTy = fir::ReferenceType::get(componentType);
base = builder.create<fir::CoordinateOp>(loc, coorTy, base, fieldIndex);
- if (mlir::isa<fir::BaseBoxType>(componentType)) {
+ if (componentType.isa<fir::BaseBoxType>()) {
auto variableInterface = mlir::cast<fir::FortranVariableOpInterface>(
designate.getOperation());
if (variableInterface.isAllocatable() ||
@@ -500,14 +500,14 @@ class DesignateOpConversion
} else {
// array%component[(indices) substring|complex part] cases.
// Component ref of array bases are dealt with below in embox/rebox.
- assert(mlir::isa<fir::BaseBoxType>(designateResultType));
+ assert(designateResultType.isa<fir::BaseBoxType>());
}
}
- if (mlir::isa<fir::BaseBoxType>(designateResultType)) {
+ if (designateResultType.isa<fir::BaseBoxType>()) {
// Generate embox or rebox.
mlir::Type eleTy = fir::unwrapPassByRefType(designateResultType);
- bool isScalarDesignator = !mlir::isa<fir::SequenceType>(eleTy);
+ bool isScalarDesignator = !eleTy.isa<fir::SequenceType>();
mlir::Value sourceBox;
if (isScalarDesignator) {
// The base box will be used for emboxing the scalar element.
@@ -583,7 +583,7 @@ class DesignateOpConversion
assert(sliceFields.empty() && substring.empty());
llvm::SmallVector<mlir::Type> resultType{designateResultType};
mlir::Value resultBox;
- if (mlir::isa<fir::BaseBoxType>(base.getType()))
+ if (base.getType().isa<fir::BaseBoxType>())
resultBox =
builder.create<fir::ReboxOp>(loc, resultType, base, shape, slice);
else
@@ -598,8 +598,7 @@ class DesignateOpConversion
// first element of a contiguous array section with compile time constant
// shape. The base may be an array, or a scalar.
mlir::Type resultAddressType = designateResultType;
- if (auto boxCharType =
- mlir::dyn_cast<fir::BoxCharType>(designateResultType))
+ if (auto boxCharType = designateResultType.dyn_cast<fir::BoxCharType>())
resultAddressType = fir::ReferenceType::get(boxCharType.getEleTy());
// Array element indexing.
@@ -621,7 +620,7 @@ class DesignateOpConversion
// Scalar complex part ref
if (designate.getComplexPart()) {
// Sequence types should have already been handled by this point
- assert(!mlir::isa<fir::SequenceType>(designateResultType));
+ assert(!designateResultType.isa<fir::SequenceType>());
auto index = builder.createIntegerConstant(loc, builder.getIndexType(),
*designate.getComplexPart());
auto coorTy = fir::ReferenceType::get(resultEleTy);
@@ -629,7 +628,7 @@ class DesignateOpConversion
}
// Cast/embox the computed scalar address if needed.
- if (mlir::isa<fir::BoxCharType>(designateResultType)) {
+ if (designateResultType.isa<fir::BoxCharType>()) {
assert(designate.getTypeparams().size() == 1 &&
"must have character length");
auto emboxChar = builder.create<fir::EmboxCharOp>(
@@ -672,13 +671,13 @@ class ParentComponentOpConversion
mlir::PatternRewriter &rewriter) const override {
mlir::Location loc = parentComponent.getLoc();
mlir::Type resultType = parentComponent.getType();
- if (!mlir::isa<fir::BoxType>(parentComponent.getType())) {
+ if (!parentComponent.getType().isa<fir::BoxType>()) {
mlir::Value baseAddr = parentComponent.getMemref();
// Scalar parent component ref without any length type parameters. The
// input may be a fir.class if it is polymorphic, since this is a scalar
// and the output will be monomorphic, the base address can be extracted
// from the fir.class.
- if (mlir::isa<fir::BaseBoxType>(baseAddr.getType()))
+ if (baseAddr.getType().isa<fir::BaseBoxType>())
baseAddr = rewriter.create<fir::BoxAddrOp>(loc, baseAddr);
rewriter.replaceOpWithNewOp<fir::ConvertOp>(parentComponent, resultType,
baseAddr);
@@ -687,7 +686,7 @@ class ParentComponentOpConversion
// Array parent component ref or PDTs.
hlfir::Entity base{parentComponent.getMemref()};
mlir::Value baseAddr = base.getBase();
- if (!mlir::isa<fir::BaseBoxType>(baseAddr.getType())) {
+ if (!baseAddr.getType().isa<fir::BaseBoxType>()) {
// Embox cannot directly be used to address parent components: it expects
// the output type to match the input type when there are no slices. When
// the types have at least one component, a slice to the first element can
@@ -749,7 +748,7 @@ class GetExtentOpConversion
// the hlfir.shape_of operation which led to the creation of this get_extent
// operation should now have been lowered to a fir.shape operation
if (auto s = mlir::dyn_cast_or_null<fir::ShapeOp>(shapeOp)) {
- fir::ShapeType shapeTy = mlir::cast<fir::ShapeType>(shape.getType());
+ fir::ShapeType shapeTy = shape.getType().cast<fir::ShapeType>();
llvm::APInt dim = getExtentOp.getDim();
uint64_t dimVal = dim.getLimitedValue(shapeTy.getRank());
mlir::Value extent = s.getExtents()[dimVal];
diff --git a/flang/lib/Optimizer/HLFIR/Transforms/LowerHLFIRIntrinsics.cpp b/flang/lib/Optimizer/HLFIR/Transforms/LowerHLFIRIntrinsics.cpp
index e9dbb7095d0ebb..0142fb0cfb0bb0 100644
--- a/flang/lib/Optimizer/HLFIR/Transforms/LowerHLFIRIntrinsics.cpp
+++ b/flang/lib/Optimizer/HLFIR/Transforms/LowerHLFIRIntrinsics.cpp
@@ -185,7 +185,7 @@ class HlfirIntrinsicConversion : public mlir::OpRewritePattern<OP> {
// the width for use in runtime intrinsic calls.
static unsigned getKindForType(mlir::Type ty) {
mlir::Type eltty = hlfir::getFortranElementType(ty);
- unsigned width = mlir::cast<mlir::IntegerType>(eltty).getWidth();
+ unsigned width = eltty.cast<mlir::IntegerType>().getWidth();
return width / 8;
}
diff --git a/flang/lib/Optimizer/HLFIR/Transforms/LowerHLFIROrderedAssignments.cpp b/flang/lib/Optimizer/HLFIR/Transforms/LowerHLFIROrderedAssignments.cpp
index 63b52c0cd0bc4f..84101353a740a0 100644
--- a/flang/lib/Optimizer/HLFIR/Transforms/LowerHLFIROrderedAssignments.cpp
+++ b/flang/lib/Optimizer/HLFIR/Transforms/LowerHLFIROrderedAssignments.cpp
@@ -1090,7 +1090,7 @@ void OrderedAssignmentRewriter::generateSaveEntity(
mlir::Value loopExtent =
computeLoopNestIterationNumber(loc, builder, loopNest);
auto sequenceType =
- mlir::cast<fir::SequenceType>(builder.getVarLenSeqTy(entityType));
+ builder.getVarLenSeqTy(entityType).cast<fir::SequenceType>();
temp = insertSavedEntity(region,
fir::factory::HomogeneousScalarStack{
loc, builder, sequenceType, loopExtent,
diff --git a/flang/lib/Optimizer/HLFIR/Transforms/OptimizedBufferization.cpp b/flang/lib/Optimizer/HLFIR/Transforms/OptimizedBufferization.cpp
index 8d68c70216082c..685c73d6762570 100644
--- a/flang/lib/Optimizer/HLFIR/Transforms/OptimizedBufferization.cpp
+++ b/flang/lib/Optimizer/HLFIR/Transforms/OptimizedBufferization.cpp
@@ -249,7 +249,7 @@ static bool areIdenticalOrDisjointSlices(mlir::Value ref1, mlir::Value ref2) {
auto isPositiveConstant = [](mlir::Value v) -> bool {
if (auto conOp =
mlir::dyn_cast<mlir::arith::ConstantOp>(v.getDefiningOp()))
- if (auto iattr = mlir::dyn_cast<mlir::IntegerAttr>(conOp.getValue()))
+ if (auto iattr = conOp.getValue().dyn_cast<mlir::IntegerAttr>())
return iattr.getInt() > 0;
return false;
};
@@ -601,7 +601,7 @@ mlir::LogicalResult VariableAssignBufferization::matchAndRewrite(
// TODO: ExprType check is here to avoid conflicts with
// ElementalAssignBufferization pattern. We need to combine
// these matchers into a single one that applies to AssignOp.
- if (mlir::isa<hlfir::ExprType>(rhs.getType()))
+ if (rhs.getType().isa<hlfir::ExprType>())
return rewriter.notifyMatchFailure(assign, "RHS is not in memory");
if (!rhs.isArray())
@@ -834,7 +834,7 @@ class MinMaxlocElementalConversion : public mlir::OpRewritePattern<Op> {
unsigned rank = mlir::cast<hlfir::ExprType>(mloc.getType()).getShape()[0];
mlir::Type arrayType = array.getType();
- if (!mlir::isa<fir::BoxType>(arrayType))
+ if (!arrayType.isa<fir::BoxType>())
return rewriter.notifyMatchFailure(
mloc, "Currently requires a boxed type input");
mlir::Type elementType = hlfir::getFortranElementType(arrayType);
@@ -850,7 +850,7 @@ class MinMaxlocElementalConversion : public mlir::OpRewritePattern<Op> {
auto init = [isMax](fir::FirOpBuilder builder, mlir::Location loc,
mlir::Type elementType) {
- if (auto ty = mlir::dyn_cast<mlir::FloatType>(elementType)) {
+ if (auto ty = elementType.dyn_cast<mlir::FloatType>()) {
const llvm::fltSemantics &sem = ty.getFloatSemantics();
llvm::APFloat limit = llvm::APFloat::getInf(sem, /*Negative=*/isMax);
return builder.createRealConstant(loc, elementType, limit);
@@ -901,7 +901,7 @@ class MinMaxlocElementalConversion : public mlir::OpRewritePattern<Op> {
// Compare with the max reduction value
mlir::Value cmp;
- if (mlir::isa<mlir::FloatType>(elementType)) {
+ if (elementType.isa<mlir::FloatType>()) {
// For FP reductions we want the first smallest value to be used, that
// is not NaN. A OGL/OLT condition will usually work for this unless all
// the values are Nan or Inf. This follows the same logic as
@@ -918,7 +918,7 @@ class MinMaxlocElementalConversion : public mlir::OpRewritePattern<Op> {
loc, mlir::arith::CmpFPredicate::OEQ, elem, elem);
cmpNan = builder.create<mlir::arith::AndIOp>(loc, cmpNan, cmpNan2);
cmp = builder.create<mlir::arith::OrIOp>(loc, cmp, cmpNan);
- } else if (mlir::isa<mlir::IntegerType>(elementType)) {
+ } else if (elementType.isa<mlir::IntegerType>()) {
cmp = builder.create<mlir::arith::CmpIOp>(
loc,
isMax ? mlir::arith::CmpIPredicate::sgt
diff --git a/flang/lib/Optimizer/HLFIR/Transforms/SimplifyHLFIRIntrinsics.cpp b/flang/lib/Optimizer/HLFIR/Transforms/SimplifyHLFIRIntrinsics.cpp
index b761563eba0f88..2751575ce9821c 100644
--- a/flang/lib/Optimizer/HLFIR/Transforms/SimplifyHLFIRIntrinsics.cpp
+++ b/flang/lib/Optimizer/HLFIR/Transforms/SimplifyHLFIRIntrinsics.cpp
@@ -103,8 +103,7 @@ class SimplifyHLFIRIntrinsics
// by hlfir.elemental)
target.addDynamicallyLegalOp<hlfir::TransposeOp>(
[](hlfir::TransposeOp transpose) {
- return mlir::cast<hlfir::ExprType>(transpose.getType())
- .isPolymorphic();
+ return transpose.getType().cast<hlfir::ExprType>().isPolymorphic();
});
target.markUnknownOpDynamicallyLegal(
[](mlir::Operation *) { return true; });
diff --git a/flang/lib/Optimizer/Transforms/AbstractResult.cpp b/flang/lib/Optimizer/Transforms/AbstractResult.cpp
index 85472cdc5103a7..eb4dd637bb167e 100644
--- a/flang/lib/Optimizer/Transforms/AbstractResult.cpp
+++ b/flang/lib/Optimizer/Transforms/AbstractResult.cpp
@@ -65,14 +65,14 @@ static mlir::FunctionType getCPtrFunctionType(mlir::FunctionType funcTy) {
auto resultType = funcTy.getResult(0);
assert(fir::isa_builtin_cptr_type(resultType));
llvm::SmallVector<mlir::Type> outputTypes;
- auto recTy = mlir::dyn_cast<fir::RecordType>(resultType);
+ auto recTy = resultType.dyn_cast<fir::RecordType>();
outputTypes.emplace_back(recTy.getTypeList()[0].second);
return mlir::FunctionType::get(funcTy.getContext(), funcTy.getInputs(),
outputTypes);
}
static bool mustEmboxResult(mlir::Type resultType, bool shouldBoxResult) {
- return mlir::isa<fir::SequenceType, fir::RecordType>(resultType) &&
+ return resultType.isa<fir::SequenceType, fir::RecordType>() &&
shouldBoxResult;
}
@@ -114,7 +114,7 @@ class CallConversion : public mlir::OpRewritePattern<Op> {
bool isResultBuiltinCPtr = fir::isa_builtin_cptr_type(result.getType());
Op newOp;
if (isResultBuiltinCPtr) {
- auto recTy = mlir::dyn_cast<fir::RecordType>(result.getType());
+ auto recTy = result.getType().template dyn_cast<fir::RecordType>();
newResultTypes.emplace_back(recTy.getTypeList()[0].second);
}
@@ -261,7 +261,7 @@ class AddrOfOpConversion : public mlir::OpRewritePattern<fir::AddrOfOp> {
mlir::LogicalResult
matchAndRewrite(fir::AddrOfOp addrOf,
mlir::PatternRewriter &rewriter) const override {
- auto oldFuncTy = mlir::cast<mlir::FunctionType>(addrOf.getType());
+ auto oldFuncTy = addrOf.getType().cast<mlir::FunctionType>();
mlir::FunctionType newFuncTy;
// TODO: This should be generalized for derived types, and it is
// architecture and OS dependent.
@@ -296,7 +296,7 @@ class AbstractResultOpt
auto loc = func.getLoc();
auto *context = &getContext();
// Convert function type itself if it has an abstract result.
- auto funcTy = mlir::cast<mlir::FunctionType>(func.getFunctionType());
+ auto funcTy = func.getFunctionType().cast<mlir::FunctionType>();
if (hasAbstractResult(funcTy)) {
// TODO: This should be generalized for derived types, and it is
// architecture and OS dependent.
@@ -343,11 +343,11 @@ class AbstractResultOpt
return mlir::TypeSwitch<mlir::Type, bool>(type)
.Case([](fir::BoxProcType boxProc) {
return fir::hasAbstractResult(
- mlir::cast<mlir::FunctionType>(boxProc.getEleTy()));
+ boxProc.getEleTy().cast<mlir::FunctionType>());
})
.Case([](fir::PointerType pointer) {
return fir::hasAbstractResult(
- mlir::cast<mlir::FunctionType>(pointer.getEleTy()));
+ pointer.getEleTy().cast<mlir::FunctionType>());
})
.Default([](auto &&) { return false; });
}
@@ -411,7 +411,7 @@ class AbstractResultOpt
return !hasAbstractResult(call.getFunctionType());
});
target.addDynamicallyLegalOp<fir::AddrOfOp>([](fir::AddrOfOp addrOf) {
- if (auto funTy = mlir::dyn_cast<mlir::FunctionType>(addrOf.getType()))
+ if (auto funTy = addrOf.getType().dyn_cast<mlir::FunctionType>())
return !hasAbstractResult(funTy);
return true;
});
diff --git a/flang/lib/Optimizer/Transforms/AddDebugInfo.cpp b/flang/lib/Optimizer/Transforms/AddDebugInfo.cpp
index 18d98a11ef3c40..68584bef055b61 100644
--- a/flang/lib/Optimizer/Transforms/AddDebugInfo.cpp
+++ b/flang/lib/Optimizer/Transforms/AddDebugInfo.cpp
@@ -69,7 +69,7 @@ void AddDebugInfoPass::runOnOperation() {
// In that case, 'inputFilename' may be empty. Location embedded in the
// module will be used to get file name and its directory.
if (inputFilename.empty()) {
- if (auto fileLoc = mlir::dyn_cast<mlir::FileLineColLoc>(module.getLoc())) {
+ if (auto fileLoc = module.getLoc().dyn_cast<mlir::FileLineColLoc>()) {
fileName = llvm::sys::path::filename(fileLoc.getFilename().getValue());
filePath = llvm::sys::path::parent_path(fileLoc.getFilename().getValue());
} else
@@ -94,14 +94,14 @@ void AddDebugInfoPass::runOnOperation() {
mlir::Location l = funcOp->getLoc();
// If fused location has already been created then nothing to do
// Otherwise, create a fused location.
- if (mlir::dyn_cast<mlir::FusedLoc>(l))
+ if (l.dyn_cast<mlir::FusedLoc>())
return;
unsigned int CC = (funcOp.getName() == fir::NameUniquer::doProgramEntry())
? llvm::dwarf::getCallingConvention("DW_CC_program")
: llvm::dwarf::getCallingConvention("DW_CC_normal");
- if (auto funcLoc = mlir::dyn_cast<mlir::FileLineColLoc>(l)) {
+ if (auto funcLoc = l.dyn_cast<mlir::FileLineColLoc>()) {
fileName = llvm::sys::path::filename(funcLoc.getFilename().getValue());
filePath = llvm::sys::path::parent_path(funcLoc.getFilename().getValue());
}
diff --git a/flang/lib/Optimizer/Transforms/AffineDemotion.cpp b/flang/lib/Optimizer/Transforms/AffineDemotion.cpp
index b4523a060f5a52..da29ae880700e6 100644
--- a/flang/lib/Optimizer/Transforms/AffineDemotion.cpp
+++ b/flang/lib/Optimizer/Transforms/AffineDemotion.cpp
@@ -98,15 +98,14 @@ class ConvertConversion : public mlir::OpRewritePattern<fir::ConvertOp> {
mlir::LogicalResult
matchAndRewrite(fir::ConvertOp op,
mlir::PatternRewriter &rewriter) const override {
- if (mlir::isa<mlir::MemRefType>(op.getRes().getType())) {
+ if (op.getRes().getType().isa<mlir::MemRefType>()) {
// 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.array<5xi32>>) ->
// !fir.ref<!fir.array<?xi32>>
- if (auto refTy =
- mlir::dyn_cast<fir::ReferenceType>(op.getValue().getType()))
- if (auto arrTy = mlir::dyn_cast<fir::SequenceType>(refTy.getEleTy())) {
+ if (auto refTy = op.getValue().getType().dyn_cast<fir::ReferenceType>())
+ if (auto arrTy = refTy.getEleTy().dyn_cast<fir::SequenceType>()) {
fir::SequenceType::Shape flatShape = {
fir::SequenceType::getUnknownExtent()};
auto flatArrTy = fir::SequenceType::get(flatShape, arrTy.getEleTy());
@@ -159,7 +158,7 @@ class AffineDialectDemotion
mlir::ConversionTarget target(*context);
target.addIllegalOp<memref::AllocOp>();
target.addDynamicallyLegalOp<fir::ConvertOp>([](fir::ConvertOp op) {
- if (mlir::isa<mlir::MemRefType>(op.getRes().getType()))
+ if (op.getRes().getType().isa<mlir::MemRefType>())
return false;
return true;
});
diff --git a/flang/lib/Optimizer/Transforms/AffinePromotion.cpp b/flang/lib/Optimizer/Transforms/AffinePromotion.cpp
index 7d0131ac6fa4e3..64531cb1868efe 100644
--- a/flang/lib/Optimizer/Transforms/AffinePromotion.cpp
+++ b/flang/lib/Optimizer/Transforms/AffinePromotion.cpp
@@ -111,7 +111,7 @@ struct AffineLoopAnalysis {
bool analyzeReference(mlir::Value memref, mlir::Operation *op) {
if (auto acoOp = memref.getDefiningOp<ArrayCoorOp>()) {
- if (mlir::isa<fir::BoxType>(acoOp.getMemref().getType())) {
+ if (acoOp.getMemref().getType().isa<fir::BoxType>()) {
// TODO: Look if and how fir.box can be promoted to affine.
LLVM_DEBUG(llvm::dbgs() << "AffineLoopAnalysis: cannot promote loop, "
"array memory operation uses fir.box\n";
@@ -222,7 +222,7 @@ struct AffineIfCondition {
return affineBinaryOp(mlir::AffineExprKind::Mod, op.getLhs(),
op.getRhs());
if (auto op = value.getDefiningOp<mlir::arith::ConstantOp>())
- if (auto intConstant = mlir::dyn_cast<IntegerAttr>(op.getValue()))
+ if (auto intConstant = op.getValue().dyn_cast<IntegerAttr>())
return toAffineExpr(intConstant.getInt());
if (auto blockArg = mlir::dyn_cast<mlir::BlockArgument>(value)) {
affineArgs.push_back(value);
@@ -331,16 +331,15 @@ static mlir::AffineMap createArrayIndexAffineMap(unsigned dimensions,
static std::optional<int64_t> constantIntegerLike(const mlir::Value value) {
if (auto definition = value.getDefiningOp<mlir::arith::ConstantOp>())
- if (auto stepAttr = mlir::dyn_cast<IntegerAttr>(definition.getValue()))
+ if (auto stepAttr = definition.getValue().dyn_cast<IntegerAttr>())
return stepAttr.getInt();
return {};
}
static mlir::Type coordinateArrayElement(fir::ArrayCoorOp op) {
if (auto refType =
- mlir::dyn_cast_or_null<ReferenceType>(op.getMemref().getType())) {
- if (auto seqType =
- mlir::dyn_cast_or_null<SequenceType>(refType.getEleTy())) {
+ op.getMemref().getType().dyn_cast_or_null<ReferenceType>()) {
+ if (auto seqType = refType.getEleTy().dyn_cast_or_null<SequenceType>()) {
return seqType.getEleTy();
}
}
diff --git a/flang/lib/Optimizer/Transforms/ArrayValueCopy.cpp b/flang/lib/Optimizer/Transforms/ArrayValueCopy.cpp
index ebc1862225256c..a08d58383d3a91 100644
--- a/flang/lib/Optimizer/Transforms/ArrayValueCopy.cpp
+++ b/flang/lib/Optimizer/Transforms/ArrayValueCopy.cpp
@@ -461,9 +461,9 @@ void ArrayCopyAnalysisBase::arrayMentions(
}
static bool hasPointerType(mlir::Type type) {
- if (auto boxTy = mlir::dyn_cast<BoxType>(type))
+ if (auto boxTy = type.dyn_cast<BoxType>())
type = boxTy.getEleTy();
- return mlir::isa<fir::PointerType>(type);
+ return type.isa<fir::PointerType>();
}
// This is a NF performance hack. It makes a simple test that the slices of the
@@ -512,7 +512,7 @@ static bool mutuallyExclusiveSliceRange(ArrayLoadOp ld, ArrayMergeStoreOp st) {
auto isPositiveConstant = [](mlir::Value v) -> bool {
if (auto conOp =
mlir::dyn_cast<mlir::arith::ConstantOp>(v.getDefiningOp()))
- if (auto iattr = mlir::dyn_cast<mlir::IntegerAttr>(conOp.getValue()))
+ if (auto iattr = conOp.getValue().dyn_cast<mlir::IntegerAttr>())
return iattr.getInt() > 0;
return false;
};
@@ -725,8 +725,8 @@ static bool
conservativeCallConflict(llvm::ArrayRef<mlir::Operation *> reaches) {
return llvm::any_of(reaches, [](mlir::Operation *op) {
if (auto call = mlir::dyn_cast<fir::CallOp>(op))
- if (auto callee = mlir::dyn_cast<mlir::SymbolRefAttr>(
- call.getCallableForCallee())) {
+ if (auto callee =
+ call.getCallableForCallee().dyn_cast<mlir::SymbolRefAttr>()) {
auto module = op->getParentOfType<mlir::ModuleOp>();
return isInternalProcedure(
module.lookupSymbol<mlir::func::FuncOp>(callee));
@@ -891,9 +891,9 @@ static mlir::Value getOrReadExtentsAndShapeOp(
if (arrLoad->hasAttr(fir::getOptionalAttrName()))
fir::emitFatalError(
loc, "shapes from array load of OPTIONAL arrays must not be used");
- if (auto boxTy = mlir::dyn_cast<BoxType>(arrLoad.getMemref().getType())) {
+ if (auto boxTy = arrLoad.getMemref().getType().dyn_cast<BoxType>()) {
auto rank =
- mlir::cast<SequenceType>(dyn_cast_ptrOrBoxEleTy(boxTy)).getDimension();
+ dyn_cast_ptrOrBoxEleTy(boxTy).cast<SequenceType>().getDimension();
auto idxTy = rewriter.getIndexType();
for (decltype(rank) dim = 0; dim < rank; ++dim) {
auto dimVal = rewriter.create<mlir::arith::ConstantIndexOp>(loc, dim);
@@ -929,7 +929,7 @@ static mlir::Type toRefType(mlir::Type ty) {
static llvm::SmallVector<mlir::Value>
getTypeParamsIfRawData(mlir::Location loc, FirOpBuilder &builder,
ArrayLoadOp arrLoad, mlir::Type ty) {
- if (mlir::isa<BoxType>(ty))
+ if (ty.isa<BoxType>())
return {};
return fir::factory::getTypeParams(loc, builder, arrLoad);
}
@@ -947,8 +947,8 @@ static mlir::Value genCoorOp(mlir::PatternRewriter &rewriter,
originated = factory::originateIndices(loc, rewriter, alloc.getType(),
shape, indices);
auto seqTy = dyn_cast_ptrOrBoxEleTy(alloc.getType());
- assert(seqTy && mlir::isa<SequenceType>(seqTy));
- const auto dimension = mlir::cast<SequenceType>(seqTy).getDimension();
+ assert(seqTy && seqTy.isa<SequenceType>());
+ const auto dimension = seqTy.cast<SequenceType>().getDimension();
auto module = load->getParentOfType<mlir::ModuleOp>();
FirOpBuilder builder(rewriter, module);
auto typeparams = getTypeParamsIfRawData(loc, builder, load, alloc.getType());
@@ -967,7 +967,7 @@ static mlir::Value getCharacterLen(mlir::Location loc, FirOpBuilder &builder,
ArrayLoadOp load, CharacterType charTy) {
auto charLenTy = builder.getCharacterLengthType();
if (charTy.hasDynamicLen()) {
- if (mlir::isa<BoxType>(load.getMemref().getType())) {
+ if (load.getMemref().getType().isa<BoxType>()) {
// The loaded array is an emboxed value. Get the CHARACTER length from
// the box value.
auto eleSzInBytes =
@@ -1027,7 +1027,7 @@ void genArrayCopy(mlir::Location loc, mlir::PatternRewriter &rewriter,
getTypeParamsIfRawData(loc, builder, arrLoad, dst.getType()));
auto eleTy = unwrapSequenceType(unwrapPassByRefType(dst.getType()));
// Copy from (to) object to (from) temp copy of same object.
- if (auto charTy = mlir::dyn_cast<CharacterType>(eleTy)) {
+ if (auto charTy = eleTy.dyn_cast<CharacterType>()) {
auto len = getCharacterLen(loc, builder, arrLoad, charTy);
CharBoxValue toChar(toAddr, len);
CharBoxValue fromChar(fromAddr, len);
@@ -1049,8 +1049,8 @@ genArrayLoadTypeParameters(mlir::Location loc, mlir::PatternRewriter &rewriter,
auto eleTy =
unwrapSequenceType(unwrapPassByRefType(load.getMemref().getType()));
if (hasDynamicSize(eleTy)) {
- if (auto charTy = mlir::dyn_cast<CharacterType>(eleTy)) {
- assert(mlir::isa<BoxType>(load.getMemref().getType()));
+ if (auto charTy = eleTy.dyn_cast<CharacterType>()) {
+ assert(load.getMemref().getType().isa<BoxType>());
auto module = load->getParentOfType<mlir::ModuleOp>();
FirOpBuilder builder(rewriter, module);
return {getCharacterLen(loc, builder, load, charTy)};
@@ -1067,7 +1067,7 @@ findNonconstantExtents(mlir::Type memrefTy,
llvm::ArrayRef<mlir::Value> extents) {
llvm::SmallVector<mlir::Value> nce;
auto arrTy = unwrapPassByRefType(memrefTy);
- auto seqTy = mlir::cast<SequenceType>(arrTy);
+ auto seqTy = arrTy.cast<SequenceType>();
for (auto [s, x] : llvm::zip(seqTy.getShape(), extents))
if (s == SequenceType::getUnknownExtent())
nce.emplace_back(x);
diff --git a/flang/lib/Optimizer/Transforms/CharacterConversion.cpp b/flang/lib/Optimizer/Transforms/CharacterConversion.cpp
index 44baad73aa258e..87ea72dbca9bbc 100644
--- a/flang/lib/Optimizer/Transforms/CharacterConversion.cpp
+++ b/flang/lib/Optimizer/Transforms/CharacterConversion.cpp
@@ -60,8 +60,8 @@ class CharacterConvertConversion
// For each code point in the `from` string, convert naively to the `to`
// string code point. Conversion is done blindly on size only, not value.
auto getCharBits = [&](mlir::Type t) {
- auto chrTy = mlir::cast<fir::CharacterType>(
- fir::unwrapSequenceType(fir::dyn_cast_ptrEleTy(t)));
+ auto chrTy = fir::unwrapSequenceType(fir::dyn_cast_ptrEleTy(t))
+ .cast<fir::CharacterType>();
return kindMap.getCharacterBitsize(chrTy.getFKind());
};
auto fromBits = getCharBits(conv.getFrom().getType());
diff --git a/flang/lib/Optimizer/Transforms/LoopVersioning.cpp b/flang/lib/Optimizer/Transforms/LoopVersioning.cpp
index 38cdc2b1388d40..0afc9c24b45b0f 100644
--- a/flang/lib/Optimizer/Transforms/LoopVersioning.cpp
+++ b/flang/lib/Optimizer/Transforms/LoopVersioning.cpp
@@ -147,7 +147,7 @@ struct ArgsUsageInLoop {
static fir::SequenceType getAsSequenceType(mlir::Value *v) {
mlir::Type argTy = fir::unwrapPassByRefType(fir::unwrapRefType(v->getType()));
- return mlir::dyn_cast<fir::SequenceType>(argTy);
+ return argTy.dyn_cast<fir::SequenceType>();
}
/// if a value comes from a fir.declare, follow it to the original source,
diff --git a/flang/lib/Optimizer/Transforms/MemoryAllocation.cpp b/flang/lib/Optimizer/Transforms/MemoryAllocation.cpp
index ada67b4201e15e..40b452a6202b07 100644
--- a/flang/lib/Optimizer/Transforms/MemoryAllocation.cpp
+++ b/flang/lib/Optimizer/Transforms/MemoryAllocation.cpp
@@ -65,7 +65,7 @@ keepStackAllocation(fir::AllocaOp alloca, mlir::Block *entry,
// TODO: Generalize the algorithm and placement of the freemem nodes.
if (alloca->getBlock() != entry)
return true;
- if (auto seqTy = mlir::dyn_cast<fir::SequenceType>(alloca.getInType())) {
+ if (auto seqTy = alloca.getInType().dyn_cast<fir::SequenceType>()) {
if (fir::hasDynamicSize(seqTy)) {
// Move all arrays with runtime determined size to the heap.
if (options.dynamicArrayOnHeap)
diff --git a/flang/lib/Optimizer/Transforms/PolymorphicOpConversion.cpp b/flang/lib/Optimizer/Transforms/PolymorphicOpConversion.cpp
index d933dc58f3757f..93efea434cb12e 100644
--- a/flang/lib/Optimizer/Transforms/PolymorphicOpConversion.cpp
+++ b/flang/lib/Optimizer/Transforms/PolymorphicOpConversion.cpp
@@ -97,8 +97,8 @@ struct DispatchOpConv : public OpConversionPattern<fir::DispatchOp> {
// Get derived type information.
mlir::Type declaredType =
fir::getDerivedType(dispatch.getObject().getType().getEleTy());
- assert(mlir::isa<fir::RecordType>(declaredType) && "expecting fir.type");
- auto recordType = mlir::dyn_cast<fir::RecordType>(declaredType);
+ assert(declaredType.isa<fir::RecordType>() && "expecting fir.type");
+ auto recordType = declaredType.dyn_cast<fir::RecordType>();
// Lookup for the binding table.
auto bindingsIter = bindingTables.find(recordType.getName());
@@ -157,7 +157,7 @@ struct DispatchOpConv : public OpConversionPattern<fir::DispatchOp> {
// Load the bindings descriptor.
auto bindingsCompName = Fortran::semantics::bindingDescCompName;
- fir::RecordType typeDescRecTy = mlir::cast<fir::RecordType>(typeDescTy);
+ fir::RecordType typeDescRecTy = typeDescTy.cast<fir::RecordType>();
mlir::Value field = rewriter.create<fir::FieldIndexOp>(
loc, fieldTy, bindingsCompName, typeDescRecTy, mlir::ValueRange{});
mlir::Type coorTy =
@@ -168,8 +168,8 @@ struct DispatchOpConv : public OpConversionPattern<fir::DispatchOp> {
// Load the correct binding.
mlir::Value bindings = rewriter.create<fir::BoxAddrOp>(loc, bindingBox);
- fir::RecordType bindingTy = fir::unwrapIfDerived(
- mlir::cast<fir::BaseBoxType>(bindingBox.getType()));
+ fir::RecordType bindingTy =
+ fir::unwrapIfDerived(bindingBox.getType().cast<fir::BaseBoxType>());
mlir::Type bindingAddrTy = fir::ReferenceType::get(bindingTy);
mlir::Value bindingIdxVal = rewriter.create<mlir::arith::ConstantOp>(
loc, rewriter.getIndexType(), rewriter.getIndexAttr(bindingIdx));
@@ -181,7 +181,7 @@ struct DispatchOpConv : public OpConversionPattern<fir::DispatchOp> {
mlir::Value procField = rewriter.create<fir::FieldIndexOp>(
loc, fieldTy, procCompName, bindingTy, mlir::ValueRange{});
fir::RecordType procTy =
- mlir::cast<fir::RecordType>(bindingTy.getType(procCompName));
+ bindingTy.getType(procCompName).cast<fir::RecordType>();
mlir::Type procRefTy = fir::ReferenceType::get(procTy);
mlir::Value procRef = rewriter.create<fir::CoordinateOp>(
loc, procRefTy, bindingAddr, procField);
@@ -298,13 +298,13 @@ mlir::LogicalResult SelectTypeConv::matchAndRewrite(
// before in the list to respect point 3. above. Otherwise it is just
// added in order at the end.
for (unsigned t = 0; t < typeGuardNum; ++t) {
- if (auto a = mlir::dyn_cast<fir::ExactTypeAttr>(typeGuards[t])) {
+ if (auto a = typeGuards[t].dyn_cast<fir::ExactTypeAttr>()) {
orderedTypeGuards.push_back(t);
continue;
}
- if (auto a = mlir::dyn_cast<fir::SubclassAttr>(typeGuards[t])) {
- if (auto recTy = mlir::dyn_cast<fir::RecordType>(a.getType())) {
+ if (auto a = typeGuards[t].dyn_cast<fir::SubclassAttr>()) {
+ if (auto recTy = a.getType().dyn_cast<fir::RecordType>()) {
auto dt = mod.lookupSymbol<fir::TypeInfoOp>(recTy.getName());
assert(dt && "dispatch table not found");
llvm::SmallSet<llvm::StringRef, 4> ancestors =
@@ -313,8 +313,8 @@ mlir::LogicalResult SelectTypeConv::matchAndRewrite(
auto it = orderedClassIsGuards.begin();
while (it != orderedClassIsGuards.end()) {
fir::SubclassAttr sAttr =
- mlir::dyn_cast<fir::SubclassAttr>(typeGuards[*it]);
- if (auto ty = mlir::dyn_cast<fir::RecordType>(sAttr.getType())) {
+ typeGuards[*it].dyn_cast<fir::SubclassAttr>();
+ if (auto ty = sAttr.getType().dyn_cast<fir::RecordType>()) {
if (ancestors.contains(ty.getName()))
break;
}
@@ -339,7 +339,7 @@ mlir::LogicalResult SelectTypeConv::matchAndRewrite(
auto *dest = selectType.getSuccessor(idx);
std::optional<mlir::ValueRange> destOps =
selectType.getSuccessorOperands(operands, idx);
- if (mlir::dyn_cast<mlir::UnitAttr>(typeGuards[idx]))
+ if (typeGuards[idx].dyn_cast<mlir::UnitAttr>())
rewriter.replaceOpWithNewOp<mlir::cf::BranchOp>(
selectType, dest, destOps.value_or(mlir::ValueRange{}));
else if (mlir::failed(genTypeLadderStep(loc, selector, typeGuards[idx],
@@ -357,9 +357,9 @@ mlir::LogicalResult SelectTypeConv::genTypeLadderStep(
fir::KindMapping &kindMap) const {
mlir::Value cmp;
// TYPE IS type guard comparison are all done inlined.
- if (auto a = mlir::dyn_cast<fir::ExactTypeAttr>(attr)) {
+ if (auto a = attr.dyn_cast<fir::ExactTypeAttr>()) {
if (fir::isa_trivial(a.getType()) ||
- mlir::isa<fir::CharacterType>(a.getType())) {
+ a.getType().isa<fir::CharacterType>()) {
// For type guard statement with Intrinsic type spec the type code of
// the descriptor is compared.
int code = fir::getTypeCode(a.getType(), kindMap);
@@ -383,10 +383,10 @@ mlir::LogicalResult SelectTypeConv::genTypeLadderStep(
cmp = res;
}
// CLASS IS type guard statement is done with a runtime call.
- } else if (auto a = mlir::dyn_cast<fir::SubclassAttr>(attr)) {
+ } else if (auto a = attr.dyn_cast<fir::SubclassAttr>()) {
// Retrieve the type descriptor from the type guard statement record type.
- assert(mlir::isa<fir::RecordType>(a.getType()) && "expect fir.record type");
- fir::RecordType recTy = mlir::dyn_cast<fir::RecordType>(a.getType());
+ assert(a.getType().isa<fir::RecordType>() && "expect fir.record type");
+ fir::RecordType recTy = a.getType().dyn_cast<fir::RecordType>();
std::string typeDescName =
fir::NameUniquer::getTypeDescriptorName(recTy.getName());
auto typeDescGlobal = mod.lookupSymbol<fir::GlobalOp>(typeDescName);
@@ -438,8 +438,8 @@ mlir::Value
SelectTypeConv::genTypeDescCompare(mlir::Location loc, mlir::Value selector,
mlir::Type ty, mlir::ModuleOp mod,
mlir::PatternRewriter &rewriter) const {
- assert(mlir::isa<fir::RecordType>(ty) && "expect fir.record type");
- fir::RecordType recTy = mlir::dyn_cast<fir::RecordType>(ty);
+ assert(ty.isa<fir::RecordType>() && "expect fir.record type");
+ fir::RecordType recTy = ty.dyn_cast<fir::RecordType>();
std::string typeDescName =
fir::NameUniquer::getTypeDescriptorName(recTy.getName());
auto typeDescGlobal = mod.lookupSymbol<fir::GlobalOp>(typeDescName);
diff --git a/flang/lib/Optimizer/Transforms/SimplifyIntrinsics.cpp b/flang/lib/Optimizer/Transforms/SimplifyIntrinsics.cpp
index 601bf04ce5e9b3..a4f2f5238e4038 100644
--- a/flang/lib/Optimizer/Transforms/SimplifyIntrinsics.cpp
+++ b/flang/lib/Optimizer/Transforms/SimplifyIntrinsics.cpp
@@ -215,8 +215,8 @@ static unsigned getDimCount(mlir::Value val) {
// the first ConvertOp that has non-opaque box type that we meet
// going through the ConvertOp chain.
if (mlir::Value emboxVal = findBoxDef(val))
- if (auto boxTy = mlir::dyn_cast<fir::BoxType>(emboxVal.getType()))
- if (auto seqTy = mlir::dyn_cast<fir::SequenceType>(boxTy.getEleTy()))
+ if (auto boxTy = emboxVal.getType().dyn_cast<fir::BoxType>())
+ if (auto seqTy = boxTy.getEleTy().dyn_cast<fir::SequenceType>())
return seqTy.getDimension();
return 0;
}
@@ -237,9 +237,9 @@ static std::optional<mlir::Type> getArgElementType(mlir::Value val) {
val = defOp->getOperand(0);
// The convert operation is expected to convert from one
// box type to another box type.
- auto boxType = mlir::cast<fir::BoxType>(val.getType());
+ auto boxType = val.getType().cast<fir::BoxType>();
auto elementType = fir::unwrapSeqOrBoxedSeqType(boxType);
- if (!mlir::isa<mlir::NoneType>(elementType))
+ if (!elementType.isa<mlir::NoneType>())
return elementType;
} while (true);
}
@@ -381,7 +381,7 @@ static void genRuntimeSumBody(fir::FirOpBuilder &builder,
// end function RTNAME(Sum)<T>x<rank>_simplified
auto zero = [](fir::FirOpBuilder builder, mlir::Location loc,
mlir::Type elementType) {
- if (auto ty = mlir::dyn_cast<mlir::FloatType>(elementType)) {
+ if (auto ty = elementType.dyn_cast<mlir::FloatType>()) {
const llvm::fltSemantics &sem = ty.getFloatSemantics();
return builder.createRealConstant(loc, elementType,
llvm::APFloat::getZero(sem));
@@ -392,9 +392,9 @@ static void genRuntimeSumBody(fir::FirOpBuilder &builder,
auto genBodyOp = [](fir::FirOpBuilder builder, mlir::Location loc,
mlir::Type elementType, mlir::Value elem1,
mlir::Value elem2) -> mlir::Value {
- if (mlir::isa<mlir::FloatType>(elementType))
+ if (elementType.isa<mlir::FloatType>())
return builder.create<mlir::arith::AddFOp>(loc, elem1, elem2);
- if (mlir::isa<mlir::IntegerType>(elementType))
+ if (elementType.isa<mlir::IntegerType>())
return builder.create<mlir::arith::AddIOp>(loc, elem1, elem2);
llvm_unreachable("unsupported type");
@@ -414,7 +414,7 @@ static void genRuntimeMaxvalBody(fir::FirOpBuilder &builder,
mlir::Type elementType) {
auto init = [](fir::FirOpBuilder builder, mlir::Location loc,
mlir::Type elementType) {
- if (auto ty = mlir::dyn_cast<mlir::FloatType>(elementType)) {
+ if (auto ty = elementType.dyn_cast<mlir::FloatType>()) {
const llvm::fltSemantics &sem = ty.getFloatSemantics();
return builder.createRealConstant(
loc, elementType, llvm::APFloat::getLargest(sem, /*Negative=*/true));
@@ -427,7 +427,7 @@ static void genRuntimeMaxvalBody(fir::FirOpBuilder &builder,
auto genBodyOp = [](fir::FirOpBuilder builder, mlir::Location loc,
mlir::Type elementType, mlir::Value elem1,
mlir::Value elem2) -> mlir::Value {
- if (mlir::isa<mlir::FloatType>(elementType)) {
+ if (elementType.isa<mlir::FloatType>()) {
// arith.maxf later converted to llvm.intr.maxnum does not work
// correctly for NaNs and -0.0 (see maxnum/minnum pattern matching
// in LLVM's InstCombine pass). Moreover, llvm.intr.maxnum
@@ -439,7 +439,7 @@ static void genRuntimeMaxvalBody(fir::FirOpBuilder &builder,
loc, mlir::arith::CmpFPredicate::OGT, elem1, elem2);
return builder.create<mlir::arith::SelectOp>(loc, compare, elem1, elem2);
}
- if (mlir::isa<mlir::IntegerType>(elementType))
+ if (elementType.isa<mlir::IntegerType>())
return builder.create<mlir::arith::MaxSIOp>(loc, elem1, elem2);
llvm_unreachable("unsupported type");
@@ -662,7 +662,7 @@ static void genRuntimeMinMaxlocBody(fir::FirOpBuilder &builder,
mlir::Type resultElemTy, bool isDim) {
auto init = [isMax](fir::FirOpBuilder builder, mlir::Location loc,
mlir::Type elementType) {
- if (auto ty = mlir::dyn_cast<mlir::FloatType>(elementType)) {
+ if (auto ty = elementType.dyn_cast<mlir::FloatType>()) {
const llvm::fltSemantics &sem = ty.getFloatSemantics();
llvm::APFloat limit = llvm::APFloat::getInf(sem, /*Negative=*/isMax);
return builder.createRealConstant(loc, elementType, limit);
@@ -744,7 +744,7 @@ static void genRuntimeMinMaxlocBody(fir::FirOpBuilder &builder,
mlir::Value elem = builder.create<fir::LoadOp>(loc, addr);
mlir::Value cmp;
- if (mlir::isa<mlir::FloatType>(elementType)) {
+ if (elementType.isa<mlir::FloatType>()) {
// For FP reductions we want the first smallest value to be used, that
// is not NaN. A OGL/OLT condition will usually work for this unless all
// the values are Nan or Inf. This follows the same logic as
@@ -761,7 +761,7 @@ static void genRuntimeMinMaxlocBody(fir::FirOpBuilder &builder,
loc, mlir::arith::CmpFPredicate::OEQ, elem, elem);
cmpNan = builder.create<mlir::arith::AndIOp>(loc, cmpNan, cmpNan2);
cmp = builder.create<mlir::arith::OrIOp>(loc, cmp, cmpNan);
- } else if (mlir::isa<mlir::IntegerType>(elementType)) {
+ } else if (elementType.isa<mlir::IntegerType>()) {
cmp = builder.create<mlir::arith::CmpIOp>(
loc,
isMax ? mlir::arith::CmpIPredicate::sgt
@@ -839,7 +839,7 @@ static void genRuntimeMinMaxlocBody(fir::FirOpBuilder &builder,
builder.setInsertionPointToStart(&ifOp.getElseRegion().front());
mlir::Value basicValue;
- if (mlir::isa<mlir::IntegerType>(elementType)) {
+ if (elementType.isa<mlir::IntegerType>()) {
basicValue = builder.createIntegerConstant(loc, elementType, 0);
} else {
basicValue = builder.createRealConstant(loc, elementType, 0);
@@ -921,7 +921,7 @@ static void genRuntimeDotBody(fir::FirOpBuilder &builder,
mlir::IndexType idxTy = builder.getIndexType();
mlir::Value zero =
- mlir::isa<mlir::FloatType>(resultElementType)
+ resultElementType.isa<mlir::FloatType>()
? builder.createRealConstant(loc, resultElementType, 0.0)
: builder.createIntegerConstant(loc, resultElementType, 0);
@@ -978,10 +978,10 @@ static void genRuntimeDotBody(fir::FirOpBuilder &builder,
// Convert to the result type.
elem2 = builder.create<fir::ConvertOp>(loc, resultElementType, elem2);
- if (mlir::isa<mlir::FloatType>(resultElementType))
+ if (resultElementType.isa<mlir::FloatType>())
sumVal = builder.create<mlir::arith::AddFOp>(
loc, builder.create<mlir::arith::MulFOp>(loc, elem1, elem2), sumVal);
- else if (mlir::isa<mlir::IntegerType>(resultElementType))
+ else if (resultElementType.isa<mlir::IntegerType>())
sumVal = builder.create<mlir::arith::AddIOp>(
loc, builder.create<mlir::arith::MulIOp>(loc, elem1, elem2), sumVal);
else
@@ -1056,8 +1056,8 @@ void SimplifyIntrinsicsPass::simplifyIntOrFloatReduction(
mlir::Type resultType = call.getResult(0).getType();
- if (!mlir::isa<mlir::FloatType>(resultType) &&
- !mlir::isa<mlir::IntegerType>(resultType))
+ if (!resultType.isa<mlir::FloatType>() &&
+ !resultType.isa<mlir::IntegerType>())
return;
auto argType = getArgElementType(args[0]);
@@ -1103,8 +1103,7 @@ void SimplifyIntrinsicsPass::simplifyLogicalDim0Reduction(
fir::FirOpBuilder builder{getSimplificationBuilder(call, kindMap)};
// Treating logicals as integers makes things a lot easier
- fir::LogicalType logicalType = {
- mlir::dyn_cast<fir::LogicalType>(elementType)};
+ fir::LogicalType logicalType = {elementType.dyn_cast<fir::LogicalType>()};
fir::KindTy kind = logicalType.getFKind();
mlir::Type intElementType = builder.getIntegerType(kind * 8);
@@ -1139,8 +1138,7 @@ void SimplifyIntrinsicsPass::simplifyLogicalDim1Reduction(
fir::FirOpBuilder builder{getSimplificationBuilder(call, kindMap)};
// Treating logicals as integers makes things a lot easier
- fir::LogicalType logicalType = {
- mlir::dyn_cast<fir::LogicalType>(elementType)};
+ fir::LogicalType logicalType = {elementType.dyn_cast<fir::LogicalType>()};
fir::KindTy kind = logicalType.getFKind();
mlir::Type intElementType = builder.getIntegerType(kind * 8);
@@ -1184,7 +1182,7 @@ void SimplifyIntrinsicsPass::simplifyMinMaxlocReduction(
auto inputBox = findBoxDef(args[1]);
mlir::Type inputType = hlfir::getFortranElementType(inputBox.getType());
- if (mlir::isa<fir::CharacterType>(inputType))
+ if (inputType.isa<fir::CharacterType>())
return;
int maskRank;
@@ -1195,8 +1193,7 @@ void SimplifyIntrinsicsPass::simplifyMinMaxlocReduction(
} else {
maskRank = getDimCount(mask);
mlir::Type maskElemTy = hlfir::getFortranElementType(maskDef.getType());
- fir::LogicalType logicalFirType = {
- mlir::dyn_cast<fir::LogicalType>(maskElemTy)};
+ fir::LogicalType logicalFirType = {maskElemTy.dyn_cast<fir::LogicalType>()};
kind = logicalFirType.getFKind();
// Convert fir::LogicalType to mlir::Type
logicalElemType = logicalFirType;
@@ -1305,8 +1302,7 @@ void SimplifyIntrinsicsPass::runOnOperation() {
std::string fmfString{builder.getFastMathFlagsString()};
mlir::Type type = call.getResult(0).getType();
- if (!mlir::isa<mlir::FloatType>(type) &&
- !mlir::isa<mlir::IntegerType>(type))
+ if (!type.isa<mlir::FloatType>() && !type.isa<mlir::IntegerType>())
return;
// Try to find the element types of the boxed arguments.
diff --git a/flang/lib/Optimizer/Transforms/StackArrays.cpp b/flang/lib/Optimizer/Transforms/StackArrays.cpp
index 16bbb1c3564604..c81524dd16a77e 100644
--- a/flang/lib/Optimizer/Transforms/StackArrays.cpp
+++ b/flang/lib/Optimizer/Transforms/StackArrays.cpp
@@ -351,7 +351,7 @@ void AllocationAnalysis::visitOperation(mlir::Operation *op,
}
auto retTy = allocmem.getAllocatedType();
- if (!mlir::isa<fir::SequenceType>(retTy)) {
+ if (!retTy.isa<fir::SequenceType>()) {
LLVM_DEBUG(llvm::dbgs()
<< "--Allocation is not for an array: skipping\n");
return;
diff --git a/flang/unittests/Optimizer/Builder/ComplexTest.cpp b/flang/unittests/Optimizer/Builder/ComplexTest.cpp
index 17171512470ac8..5364eec904ff4e 100644
--- a/flang/unittests/Optimizer/Builder/ComplexTest.cpp
+++ b/flang/unittests/Optimizer/Builder/ComplexTest.cpp
@@ -96,6 +96,6 @@ TEST_F(ComplexTest, verifyConvertWithSemantics) {
// Convert complex to integer
mlir::Value v2 = firBuilder->convertWithSemantics(loc, integerTy1, v1);
- EXPECT_TRUE(mlir::isa<mlir::IntegerType>(v2.getType()));
+ EXPECT_TRUE(v2.getType().isa<mlir::IntegerType>());
EXPECT_TRUE(mlir::dyn_cast<fir::ConvertOp>(v2.getDefiningOp()));
}
diff --git a/flang/unittests/Optimizer/Builder/DoLoopHelperTest.cpp b/flang/unittests/Optimizer/Builder/DoLoopHelperTest.cpp
index d0a9342914a39c..7e7206dbf934de 100644
--- a/flang/unittests/Optimizer/Builder/DoLoopHelperTest.cpp
+++ b/flang/unittests/Optimizer/Builder/DoLoopHelperTest.cpp
@@ -34,7 +34,7 @@ struct DoLoopHelperTest : public testing::Test {
void checkConstantValue(const mlir::Value &value, int64_t v) {
EXPECT_TRUE(mlir::isa<mlir::arith::ConstantOp>(value.getDefiningOp()));
auto cstOp = dyn_cast<mlir::arith::ConstantOp>(value.getDefiningOp());
- auto valueAttr = dyn_cast_or_null<IntegerAttr>(cstOp.getValue());
+ auto valueAttr = cstOp.getValue().dyn_cast_or_null<IntegerAttr>();
EXPECT_EQ(v, valueAttr.getInt());
}
diff --git a/flang/unittests/Optimizer/Builder/FIRBuilderTest.cpp b/flang/unittests/Optimizer/Builder/FIRBuilderTest.cpp
index e5e5454ee88ad2..b6a1f9c9db8f0f 100644
--- a/flang/unittests/Optimizer/Builder/FIRBuilderTest.cpp
+++ b/flang/unittests/Optimizer/Builder/FIRBuilderTest.cpp
@@ -54,7 +54,7 @@ static void checkIntegerConstant(mlir::Value value, mlir::Type ty, int64_t v) {
EXPECT_TRUE(mlir::isa<mlir::arith::ConstantOp>(value.getDefiningOp()));
auto cstOp = dyn_cast<mlir::arith::ConstantOp>(value.getDefiningOp());
EXPECT_EQ(ty, cstOp.getType());
- auto valueAttr = mlir::dyn_cast_or_null<IntegerAttr>(cstOp.getValue());
+ auto valueAttr = cstOp.getValue().dyn_cast_or_null<IntegerAttr>();
EXPECT_EQ(v, valueAttr.getInt());
}
@@ -151,7 +151,7 @@ TEST_F(FIRBuilderTest, createRealZeroConstant) {
auto cstOp = dyn_cast<arith::ConstantOp>(cst.getDefiningOp());
EXPECT_EQ(realTy, cstOp.getType());
EXPECT_EQ(
- 0u, mlir::cast<FloatAttr>(cstOp.getValue()).getValue().convertToDouble());
+ 0u, cstOp.getValue().cast<FloatAttr>().getValue().convertToDouble());
}
TEST_F(FIRBuilderTest, createBool) {
@@ -164,8 +164,8 @@ TEST_F(FIRBuilderTest, createBool) {
TEST_F(FIRBuilderTest, getVarLenSeqTy) {
auto builder = getBuilder();
auto ty = builder.getVarLenSeqTy(builder.getI64Type());
- EXPECT_TRUE(mlir::isa<fir::SequenceType>(ty));
- fir::SequenceType seqTy = mlir::dyn_cast<fir::SequenceType>(ty);
+ EXPECT_TRUE(ty.isa<fir::SequenceType>());
+ fir::SequenceType seqTy = ty.dyn_cast<fir::SequenceType>();
EXPECT_EQ(1u, seqTy.getDimension());
EXPECT_TRUE(fir::unwrapSequenceType(ty).isInteger(64));
}
@@ -216,9 +216,9 @@ TEST_F(FIRBuilderTest, createGlobal2) {
EXPECT_FALSE(global.getConstant().has_value());
EXPECT_EQ(i32Type, global.getType());
EXPECT_TRUE(global.getInitVal().has_value());
- EXPECT_TRUE(mlir::isa<mlir::IntegerAttr>(global.getInitVal().value()));
- EXPECT_EQ(16,
- mlir::cast<mlir::IntegerAttr>(global.getInitVal().value()).getValue());
+ EXPECT_TRUE(global.getInitVal().value().isa<mlir::IntegerAttr>());
+ EXPECT_EQ(
+ 16, global.getInitVal().value().cast<mlir::IntegerAttr>().getValue());
EXPECT_TRUE(global.getLinkName().has_value());
EXPECT_EQ(
builder.createLinkOnceLinkage().getValue(), global.getLinkName().value());
@@ -271,12 +271,12 @@ TEST_F(FIRBuilderTest, locationToFilename) {
auto stringLitOps = global.getRegion().front().getOps<fir::StringLitOp>();
EXPECT_TRUE(llvm::hasSingleElement(stringLitOps));
for (auto stringLit : stringLitOps) {
- EXPECT_EQ(
- 10, mlir::cast<mlir::IntegerAttr>(stringLit.getSize()).getValue());
- EXPECT_TRUE(mlir::isa<StringAttr>(stringLit.getValue()));
+ EXPECT_EQ(10, stringLit.getSize().cast<mlir::IntegerAttr>().getValue());
+ EXPECT_TRUE(stringLit.getValue().isa<StringAttr>());
EXPECT_EQ(0,
strcmp("file1.f90\0",
- mlir::dyn_cast<StringAttr>(stringLit.getValue())
+ stringLit.getValue()
+ .dyn_cast<StringAttr>()
.getValue()
.str()
.c_str()));
@@ -288,9 +288,9 @@ TEST_F(FIRBuilderTest, createStringLitOp) {
llvm::StringRef data("mystringlitdata");
auto loc = builder.getUnknownLoc();
auto op = builder.createStringLitOp(loc, data);
- EXPECT_EQ(15, mlir::cast<mlir::IntegerAttr>(op.getSize()).getValue());
- EXPECT_TRUE(mlir::isa<StringAttr>(op.getValue()));
- EXPECT_EQ(data, mlir::dyn_cast<StringAttr>(op.getValue()).getValue());
+ EXPECT_EQ(15, op.getSize().cast<mlir::IntegerAttr>().getValue());
+ EXPECT_TRUE(op.getValue().isa<StringAttr>());
+ EXPECT_EQ(data, op.getValue().dyn_cast<StringAttr>().getValue());
}
TEST_F(FIRBuilderTest, createStringLiteral) {
@@ -318,11 +318,9 @@ TEST_F(FIRBuilderTest, createStringLiteral) {
auto stringLitOps = global.getRegion().front().getOps<fir::StringLitOp>();
EXPECT_TRUE(llvm::hasSingleElement(stringLitOps));
for (auto stringLit : stringLitOps) {
- EXPECT_EQ(
- 16, mlir::cast<mlir::IntegerAttr>(stringLit.getSize()).getValue());
- EXPECT_TRUE(mlir::isa<StringAttr>(stringLit.getValue()));
- EXPECT_EQ(
- strValue, mlir::dyn_cast<StringAttr>(stringLit.getValue()).getValue());
+ EXPECT_EQ(16, stringLit.getSize().cast<mlir::IntegerAttr>().getValue());
+ EXPECT_TRUE(stringLit.getValue().isa<StringAttr>());
+ EXPECT_EQ(strValue, stringLit.getValue().dyn_cast<StringAttr>().getValue());
}
}
@@ -346,7 +344,7 @@ TEST_F(FIRBuilderTest, allocateLocal) {
static void checkShapeOp(mlir::Value shape, mlir::Value c10, mlir::Value c100) {
EXPECT_TRUE(mlir::isa<fir::ShapeOp>(shape.getDefiningOp()));
fir::ShapeOp op = dyn_cast<fir::ShapeOp>(shape.getDefiningOp());
- auto shapeTy = mlir::dyn_cast<fir::ShapeType>(op.getType());
+ auto shapeTy = op.getType().dyn_cast<fir::ShapeType>();
EXPECT_EQ(2u, shapeTy.getRank());
EXPECT_EQ(2u, op.getExtents().size());
EXPECT_EQ(c10, op.getExtents()[0]);
@@ -374,7 +372,7 @@ TEST_F(FIRBuilderTest, genShapeWithExtentsAndShapeShift) {
auto shape = builder.genShape(loc, shifts, extents);
EXPECT_TRUE(mlir::isa<fir::ShapeShiftOp>(shape.getDefiningOp()));
fir::ShapeShiftOp op = dyn_cast<fir::ShapeShiftOp>(shape.getDefiningOp());
- auto shapeTy = mlir::dyn_cast<fir::ShapeShiftType>(op.getType());
+ auto shapeTy = op.getType().dyn_cast<fir::ShapeShiftType>();
EXPECT_EQ(2u, shapeTy.getRank());
EXPECT_EQ(2u, op.getExtents().size());
EXPECT_EQ(2u, op.getOrigins().size());
@@ -430,7 +428,7 @@ TEST_F(FIRBuilderTest, createZeroValue) {
auto cst =
mlir::dyn_cast_or_null<mlir::arith::ConstantOp>(zeroInt.getDefiningOp());
EXPECT_TRUE(cst);
- auto intAttr = mlir::dyn_cast<mlir::IntegerAttr>(cst.getValue());
+ auto intAttr = cst.getValue().dyn_cast<mlir::IntegerAttr>();
EXPECT_TRUE(intAttr && intAttr.getInt() == 0);
mlir::Type f32Ty = mlir::FloatType::getF32(builder.getContext());
@@ -439,7 +437,7 @@ TEST_F(FIRBuilderTest, createZeroValue) {
auto cst2 = mlir::dyn_cast_or_null<mlir::arith::ConstantOp>(
zeroFloat.getDefiningOp());
EXPECT_TRUE(cst2);
- auto floatAttr = mlir::dyn_cast<mlir::FloatAttr>(cst2.getValue());
+ auto floatAttr = cst2.getValue().dyn_cast<mlir::FloatAttr>();
EXPECT_TRUE(floatAttr && floatAttr.getValueAsDouble() == 0.);
mlir::Type boolTy = mlir::IntegerType::get(builder.getContext(), 1);
@@ -448,7 +446,7 @@ TEST_F(FIRBuilderTest, createZeroValue) {
auto cst3 = mlir::dyn_cast_or_null<mlir::arith::ConstantOp>(
flaseBool.getDefiningOp());
EXPECT_TRUE(cst3);
- auto intAttr2 = mlir::dyn_cast<mlir::IntegerAttr>(cst.getValue());
+ auto intAttr2 = cst.getValue().dyn_cast<mlir::IntegerAttr>();
EXPECT_TRUE(intAttr2 && intAttr2.getInt() == 0);
}
@@ -484,7 +482,7 @@ TEST_F(FIRBuilderTest, getBaseTypeOf) {
llvm::SmallVector<fir::ExtendedValue, 4> arrays;
auto extent = builder.create<fir::UndefOp>(loc, builder.getIndexType());
llvm::SmallVector<mlir::Value> extents(
- mlir::dyn_cast<fir::SequenceType>(arrayType).getDimension(),
+ arrayType.dyn_cast<fir::SequenceType>().getDimension(),
extent.getResult());
arrays.emplace_back(fir::ArrayBoxValue(ptrValArray, extents));
arrays.emplace_back(fir::BoxValue(boxValArray));
diff --git a/flang/unittests/Optimizer/RTBuilder.cpp b/flang/unittests/Optimizer/RTBuilder.cpp
index d6cf96c4351c2b..7fff7f71fc3b61 100644
--- a/flang/unittests/Optimizer/RTBuilder.cpp
+++ b/flang/unittests/Optimizer/RTBuilder.cpp
@@ -27,7 +27,7 @@ TEST(RTBuilderTest, ComplexRuntimeInterface) {
mlir::Type c99_cacosf_signature{
fir::runtime::RuntimeTableKey<decltype(c99_cacosf)>::getTypeModel()(
&ctx)};
- auto c99_cacosf_funcTy = mlir::cast<mlir::FunctionType>(c99_cacosf_signature);
+ auto c99_cacosf_funcTy = c99_cacosf_signature.cast<mlir::FunctionType>();
EXPECT_EQ(c99_cacosf_funcTy.getNumInputs(), 1u);
EXPECT_EQ(c99_cacosf_funcTy.getNumResults(), 1u);
auto cplx_ty = fir::ComplexType::get(&ctx, 4);
diff --git a/llvm/include/llvm/ADT/TypeSwitch.h b/llvm/include/llvm/ADT/TypeSwitch.h
index 14ad56ad575ffc..10a2d48e918db9 100644
--- a/llvm/include/llvm/ADT/TypeSwitch.h
+++ b/llvm/include/llvm/ADT/TypeSwitch.h
@@ -74,10 +74,7 @@ template <typename DerivedT, typename T> class TypeSwitchBase {
ValueT &&value,
std::enable_if_t<is_detected<has_dyn_cast_t, ValueT, CastT>::value> * =
nullptr) {
- // Silence warnings about MLIR's deprecated dyn_cast member functions.
- LLVM_SUPPRESS_DEPRECATED_DECLARATIONS_PUSH
return value.template dyn_cast<CastT>();
- LLVM_SUPPRESS_DEPRECATED_DECLARATIONS_POP
}
/// Attempt to dyn_cast the given `value` to `CastT`. This overload is
diff --git a/mlir/include/mlir/Dialect/Linalg/IR/LinalgOps.td b/mlir/include/mlir/Dialect/Linalg/IR/LinalgOps.td
index 64c538367267dc..da12e7c83b22b8 100644
--- a/mlir/include/mlir/Dialect/Linalg/IR/LinalgOps.td
+++ b/mlir/include/mlir/Dialect/Linalg/IR/LinalgOps.td
@@ -138,10 +138,10 @@ def Linalg_SoftmaxOp : Linalg_Op<"softmax",
let extraClassDeclaration = [{
ShapedType getInputOperandType() {
- return cast<ShapedType>(getInput().getType());
+ return getInput().getType().cast<ShapedType>();
}
ShapedType getOutputOperandType() {
- return cast<ShapedType>(getOutput().getType());
+ return getOutput().getType().cast<ShapedType>();
}
int64_t getInputOperandRank() {
return getInputOperandType().getRank();
diff --git a/mlir/include/mlir/Dialect/OpenMP/OpenMPOpsInterfaces.td b/mlir/include/mlir/Dialect/OpenMP/OpenMPOpsInterfaces.td
index d9569d9d294d84..ab9b78e755d9d5 100644
--- a/mlir/include/mlir/Dialect/OpenMP/OpenMPOpsInterfaces.td
+++ b/mlir/include/mlir/Dialect/OpenMP/OpenMPOpsInterfaces.td
@@ -234,8 +234,8 @@ def OffloadModuleInterface : OpInterface<"OffloadModuleInterface"> {
/*methodName=*/"getIsTargetDevice",
(ins), [{}], [{
if (Attribute isTargetDevice = $_op->getAttr("omp.is_target_device"))
- if (::llvm::isa<mlir::BoolAttr>(isTargetDevice))
- return ::llvm::dyn_cast<BoolAttr>(isTargetDevice).getValue();
+ if (isTargetDevice.isa<mlir::BoolAttr>())
+ return isTargetDevice.dyn_cast<BoolAttr>().getValue();
return false;
}]>,
InterfaceMethod<
@@ -259,7 +259,7 @@ def OffloadModuleInterface : OpInterface<"OffloadModuleInterface"> {
/*methodName=*/"getIsGPU",
(ins), [{}], [{
if (Attribute isTargetCGAttr = $_op->getAttr("omp.is_gpu"))
- if (auto isTargetCGVal = ::llvm::dyn_cast<BoolAttr>(isTargetCGAttr))
+ if (auto isTargetCGVal = isTargetCGAttr.dyn_cast<BoolAttr>())
return isTargetCGVal.getValue();
return false;
}]>,
@@ -332,7 +332,7 @@ def OffloadModuleInterface : OpInterface<"OffloadModuleInterface"> {
/*methodName=*/"getRequires",
(ins), [{}], [{
if (Attribute requiresAttr = $_op->getAttr("omp.requires"))
- if (auto requiresVal = ::llvm::dyn_cast<mlir::omp::ClauseRequiresAttr>(requiresAttr))
+ if (auto requiresVal = requiresAttr.dyn_cast<mlir::omp::ClauseRequiresAttr>())
return requiresVal.getValue();
return mlir::omp::ClauseRequires::none;
}]>,
diff --git a/mlir/include/mlir/Dialect/XeGPU/IR/XeGPUOps.td b/mlir/include/mlir/Dialect/XeGPU/IR/XeGPUOps.td
index e477d9a0ca3f1e..88f2e1acfeeb58 100644
--- a/mlir/include/mlir/Dialect/XeGPU/IR/XeGPUOps.td
+++ b/mlir/include/mlir/Dialect/XeGPU/IR/XeGPUOps.td
@@ -164,10 +164,10 @@ def XeGPU_CreateNdDescOp: XeGPU_Op<"create_nd_tdesc", [Pure, ViewLikeOpInterface
/// source operand. They overide static shape from source memref type.
ArrayRef<int64_t> getStaticSizes() {
auto attr = getConstShapeAttr();
- if (llvm::isa<IntegerType>(getSourceType()) || attr)
+ if (getSourceType().isa<IntegerType>() || attr)
return attr;
- auto memrefType = llvm::dyn_cast<MemRefType>(getSourceType());
+ auto memrefType = getSourceType().dyn_cast<MemRefType>();
assert(memrefType && "Incorrect use of getStaticSizes");
return memrefType.getShape();
}
@@ -179,10 +179,10 @@ def XeGPU_CreateNdDescOp: XeGPU_Op<"create_nd_tdesc", [Pure, ViewLikeOpInterface
/// source operand. They overide static strides from source memref type.
ArrayRef<int64_t> getStaticStrides() {
auto attr = getConstStridesAttr();
- if (llvm::isa<IntegerType>(getSourceType()) || attr)
+ if (getSourceType().isa<IntegerType>() || attr)
return attr;
- auto memrefType = llvm::dyn_cast<MemRefType>(getSourceType());
+ auto memrefType = getSourceType().dyn_cast<MemRefType>();
assert(memrefType && "Incorrect use of getStaticStrides");
auto [strides, offset] = getStridesAndOffset(memrefType);
// reuse the storage of ConstStridesAttr since strides from
@@ -196,7 +196,7 @@ def XeGPU_CreateNdDescOp: XeGPU_Op<"create_nd_tdesc", [Pure, ViewLikeOpInterface
/// `static_shape` and `static_strides` attributes.
std::array<unsigned, 3> getArrayAttrMaxRanks() {
unsigned rank;
- if (auto ty = llvm::dyn_cast<MemRefType>(getSourceType())) {
+ if (auto ty = getSourceType().dyn_cast<MemRefType>()) {
rank = ty.getRank();
} else {
rank = (unsigned)getMixedOffsets().size();
diff --git a/mlir/include/mlir/IR/Attributes.h b/mlir/include/mlir/IR/Attributes.h
index 8a077865b51b5f..cc0cee6a31183c 100644
--- a/mlir/include/mlir/IR/Attributes.h
+++ b/mlir/include/mlir/IR/Attributes.h
@@ -50,19 +50,14 @@ class Attribute {
/// Casting utility functions. These are deprecated and will be removed,
/// please prefer using the `llvm` namespace variants instead.
template <typename... Tys>
- [[deprecated("Use mlir::isa<U>() instead")]]
bool isa() const;
template <typename... Tys>
- [[deprecated("Use mlir::isa_and_nonnull<U>() instead")]]
bool isa_and_nonnull() const;
template <typename U>
- [[deprecated("Use mlir::dyn_cast<U>() instead")]]
U dyn_cast() const;
template <typename U>
- [[deprecated("Use mlir::dyn_cast_or_null<U>() instead")]]
U dyn_cast_or_null() const;
template <typename U>
- [[deprecated("Use mlir::cast<U>() instead")]]
U cast() const;
/// Return a unique identifier for the concrete attribute type. This is used
diff --git a/mlir/include/mlir/IR/BuiltinLocationAttributes.td b/mlir/include/mlir/IR/BuiltinLocationAttributes.td
index 5a72404dea15bb..dfcc180071f72a 100644
--- a/mlir/include/mlir/IR/BuiltinLocationAttributes.td
+++ b/mlir/include/mlir/IR/BuiltinLocationAttributes.td
@@ -228,8 +228,7 @@ def OpaqueLoc : Builtin_LocationAttr<"OpaqueLoc"> {
template <typename T> static T getUnderlyingLocation(Location location) {
assert(isa<T>(location));
return reinterpret_cast<T>(
- mlir::cast<mlir::OpaqueLoc>(static_cast<LocationAttr>(location))
- .getUnderlyingLocation());
+ location.cast<mlir::OpaqueLoc>().getUnderlyingLocation());
}
/// Returns a pointer to some data structure that opaque location stores.
@@ -238,17 +237,15 @@ def OpaqueLoc : Builtin_LocationAttr<"OpaqueLoc"> {
template <typename T>
static T getUnderlyingLocationOrNull(Location location) {
return isa<T>(location)
- ? reinterpret_cast<T>(mlir::cast<mlir::OpaqueLoc>(
- static_cast<LocationAttr>(location))
- .getUnderlyingLocation())
- : T(nullptr);
+ ? reinterpret_cast<T>(
+ location.cast<mlir::OpaqueLoc>().getUnderlyingLocation())
+ : T(nullptr);
}
/// Checks whether provided location is opaque location and contains a
/// pointer to an object of particular type.
template <typename T> static bool isa(Location location) {
- auto opaque_loc =
- mlir::dyn_cast<OpaqueLoc>(static_cast<LocationAttr>(location));
+ auto opaque_loc = location.dyn_cast<OpaqueLoc>();
return opaque_loc && opaque_loc.getUnderlyingTypeID() == TypeID::get<T>();
}
}];
diff --git a/mlir/include/mlir/IR/Location.h b/mlir/include/mlir/IR/Location.h
index 423b4d19b5b944..aa8314f38cdfac 100644
--- a/mlir/include/mlir/IR/Location.h
+++ b/mlir/include/mlir/IR/Location.h
@@ -78,17 +78,14 @@ class Location {
/// Type casting utilities on the underlying location.
template <typename U>
- [[deprecated("Use mlir::isa<U>() instead")]]
bool isa() const {
return llvm::isa<U>(*this);
}
template <typename U>
- [[deprecated("Use mlir::dyn_cast<U>() instead")]]
U dyn_cast() const {
return llvm::dyn_cast<U>(*this);
}
template <typename U>
- [[deprecated("Use mlir::cast<U>() instead")]]
U cast() const {
return llvm::cast<U>(*this);
}
diff --git a/mlir/include/mlir/IR/Types.h b/mlir/include/mlir/IR/Types.h
index 65824531fdc908..a89e13b625bf40 100644
--- a/mlir/include/mlir/IR/Types.h
+++ b/mlir/include/mlir/IR/Types.h
@@ -97,19 +97,14 @@ class Type {
bool operator!() const { return impl == nullptr; }
template <typename... Tys>
- [[deprecated("Use mlir::isa<U>() instead")]]
bool isa() const;
template <typename... Tys>
- [[deprecated("Use mlir::isa_and_nonnull<U>() instead")]]
bool isa_and_nonnull() const;
template <typename U>
- [[deprecated("Use mlir::dyn_cast<U>() instead")]]
U dyn_cast() const;
template <typename U>
- [[deprecated("Use mlir::dyn_cast_or_null<U>() instead")]]
U dyn_cast_or_null() const;
template <typename U>
- [[deprecated("Use mlir::cast<U>() instead")]]
U cast() const;
/// Return a unique identifier for the concrete type. This is used to support
diff --git a/mlir/include/mlir/IR/Value.h b/mlir/include/mlir/IR/Value.h
index a7344c64e6730d..cdbc6cc374368c 100644
--- a/mlir/include/mlir/IR/Value.h
+++ b/mlir/include/mlir/IR/Value.h
@@ -98,25 +98,25 @@ class Value {
constexpr Value(detail::ValueImpl *impl = nullptr) : impl(impl) {}
template <typename U>
- [[deprecated("Use mlir::isa<U>() instead")]]
+ [[deprecated("Use isa<U>() instead")]]
bool isa() const {
return llvm::isa<U>(*this);
}
template <typename U>
- [[deprecated("Use mlir::dyn_cast<U>() instead")]]
+ [[deprecated("Use dyn_cast<U>() instead")]]
U dyn_cast() const {
return llvm::dyn_cast<U>(*this);
}
template <typename U>
- [[deprecated("Use mlir::dyn_cast_or_null<U>() instead")]]
+ [[deprecated("Use dyn_cast_or_null<U>() instead")]]
U dyn_cast_or_null() const {
return llvm::dyn_cast_or_null<U>(*this);
}
template <typename U>
- [[deprecated("Use mlir::cast<U>() instead")]]
+ [[deprecated("Use cast<U>() instead")]]
U cast() const {
return llvm::cast<U>(*this);
}
diff --git a/mlir/lib/Conversion/ComplexToStandard/ComplexToStandard.cpp b/mlir/lib/Conversion/ComplexToStandard/ComplexToStandard.cpp
index c2a83f90bcbe9d..4a15976d40c763 100644
--- a/mlir/lib/Conversion/ComplexToStandard/ComplexToStandard.cpp
+++ b/mlir/lib/Conversion/ComplexToStandard/ComplexToStandard.cpp
@@ -857,7 +857,7 @@ struct SqrtOpConversion : public OpConversionPattern<complex::SqrtOp> {
ImplicitLocOpBuilder b(op.getLoc(), rewriter);
auto type = cast<ComplexType>(op.getType());
- auto elementType = cast<FloatType>(type.getElementType());
+ auto elementType = type.getElementType().cast<FloatType>();
arith::FastMathFlags fmf = op.getFastMathFlagsAttr().getValue();
auto cst = [&](APFloat v) {
diff --git a/mlir/lib/Dialect/Polynomial/IR/PolynomialAttributes.cpp b/mlir/lib/Dialect/Polynomial/IR/PolynomialAttributes.cpp
index f1ec2be72a33ab..ee09c73bb3c4ae 100644
--- a/mlir/lib/Dialect/Polynomial/IR/PolynomialAttributes.cpp
+++ b/mlir/lib/Dialect/Polynomial/IR/PolynomialAttributes.cpp
@@ -172,7 +172,7 @@ Attribute RingAttr::parse(AsmParser &parser, Type type) {
if (failed(parser.parseEqual()))
return {};
- IntegerType iType = mlir::dyn_cast<IntegerType>(ty);
+ IntegerType iType = ty.dyn_cast<IntegerType>();
if (!iType) {
parser.emitError(parser.getCurrentLocation(),
"coefficientType must specify an integer type");
diff --git a/mlir/lib/Dialect/Vector/Transforms/VectorLinearize.cpp b/mlir/lib/Dialect/Vector/Transforms/VectorLinearize.cpp
index 802a64b0805ee4..69999f0918c103 100644
--- a/mlir/lib/Dialect/Vector/Transforms/VectorLinearize.cpp
+++ b/mlir/lib/Dialect/Vector/Transforms/VectorLinearize.cpp
@@ -140,7 +140,7 @@ struct LinearizeVectorExtractStridedSlice final
ConversionPatternRewriter &rewriter) const override {
Type dstType = getTypeConverter()->convertType(extractOp.getType());
assert(!(extractOp.getVector().getType().isScalable() ||
- cast<VectorType>(dstType).isScalable()) &&
+ dstType.cast<VectorType>().isScalable()) &&
"scalable vectors are not supported.");
if (!isLessThanTargetBitWidth(extractOp, targetVectorBitWidth))
return rewriter.notifyMatchFailure(
@@ -172,7 +172,7 @@ struct LinearizeVectorExtractStridedSlice final
// Get total number of extracted slices.
int64_t nExtractedSlices = 1;
for (Attribute size : sizes) {
- nExtractedSlices *= cast<IntegerAttr>(size).getInt();
+ nExtractedSlices *= size.cast<IntegerAttr>().getInt();
}
// Compute the strides of the source vector considering first k dimensions.
llvm::SmallVector<int64_t, 4> sourceStrides(kD, extractGranularitySize);
@@ -189,7 +189,7 @@ struct LinearizeVectorExtractStridedSlice final
// Compute extractedStrides.
for (int i = kD - 2; i >= 0; --i) {
extractedStrides[i] =
- extractedStrides[i + 1] * cast<IntegerAttr>(sizes[i + 1]).getInt();
+ extractedStrides[i + 1] * sizes[i + 1].cast<IntegerAttr>().getInt();
}
// Iterate over all extracted slices from 0 to nExtractedSlices - 1
// and compute the multi-dimensional index and the corresponding linearized
@@ -207,7 +207,7 @@ struct LinearizeVectorExtractStridedSlice final
int64_t linearizedIndex = 0;
for (int64_t j = 0; j < kD; ++j) {
linearizedIndex +=
- (cast<IntegerAttr>(offsets[j]).getInt() + multiDimIndex[j]) *
+ (offsets[j].cast<IntegerAttr>().getInt() + multiDimIndex[j]) *
sourceStrides[j];
}
// Fill the indices array form linearizedIndex to linearizedIndex +
@@ -254,7 +254,7 @@ struct LinearizeVectorShuffle final
Type dstType = getTypeConverter()->convertType(shuffleOp.getType());
assert(!(shuffleOp.getV1VectorType().isScalable() ||
shuffleOp.getV2VectorType().isScalable() ||
- cast<VectorType>(dstType).isScalable()) &&
+ dstType.cast<VectorType>().isScalable()) &&
"scalable vectors are not supported.");
if (!isLessThanTargetBitWidth(shuffleOp, targetVectorBitWidth))
return rewriter.notifyMatchFailure(
@@ -324,7 +324,7 @@ struct LinearizeVectorExtract final
ConversionPatternRewriter &rewriter) const override {
Type dstTy = getTypeConverter()->convertType(extractOp.getType());
assert(!(extractOp.getVector().getType().isScalable() ||
- cast<VectorType>(dstTy).isScalable()) &&
+ dstTy.cast<VectorType>().isScalable()) &&
"scalable vectors are not supported.");
if (!isLessThanTargetBitWidth(extractOp, targetVectorBitWidth))
return rewriter.notifyMatchFailure(
@@ -405,7 +405,9 @@ void mlir::vector::populateVectorLinearizeShuffleLikeOpsPatterns(
[=](vector::ShuffleOp shuffleOp) -> bool {
return isLessThanTargetBitWidth(shuffleOp, targetBitWidth)
? (typeConverter.isLegal(shuffleOp) &&
- cast<mlir::VectorType>(shuffleOp.getResult().getType())
+ shuffleOp.getResult()
+ .getType()
+ .cast<mlir::VectorType>()
.getRank() == 1)
: true;
});
More information about the flang-commits
mailing list