Skip to content

Commit bd9fdce

Browse files
authored
[flang] Use isa/dyn_cast/cast/... free functions. (#90432)
The corresponding member functions are deprecated.
1 parent 4a8f2f2 commit bd9fdce

File tree

5 files changed

+21
-25
lines changed

5 files changed

+21
-25
lines changed

flang/lib/Lower/ConvertVariable.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -496,8 +496,8 @@ static fir::GlobalOp defineGlobal(Fortran::lower::AbstractConverter &converter,
496496
if (mlir::isa<fir::SequenceType>(symTy) &&
497497
!Fortran::semantics::IsAllocatableOrPointer(sym)) {
498498
mlir::Type eleTy = mlir::cast<fir::SequenceType>(symTy).getEleTy();
499-
if (eleTy.isa<mlir::IntegerType, mlir::FloatType, fir::ComplexType,
500-
fir::LogicalType>()) {
499+
if (mlir::isa<mlir::IntegerType, mlir::FloatType, fir::ComplexType,
500+
fir::LogicalType>(eleTy)) {
501501
const auto *details =
502502
sym.detailsIf<Fortran::semantics::ObjectEntityDetails>();
503503
if (details->init()) {

flang/lib/Optimizer/CodeGen/CodeGen.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1964,12 +1964,12 @@ struct ValueOpCommon {
19641964
mlir::ArrayAttr arrAttr) {
19651965
llvm::SmallVector<int64_t> indices;
19661966
for (auto i = arrAttr.begin(), e = arrAttr.end(); i != e; ++i) {
1967-
if (auto intAttr = i->dyn_cast<mlir::IntegerAttr>()) {
1967+
if (auto intAttr = mlir::dyn_cast<mlir::IntegerAttr>(*i)) {
19681968
indices.push_back(intAttr.getInt());
19691969
} else {
1970-
auto fieldName = i->cast<mlir::StringAttr>().getValue();
1970+
auto fieldName = mlir::cast<mlir::StringAttr>(*i).getValue();
19711971
++i;
1972-
auto ty = i->cast<mlir::TypeAttr>().getValue();
1972+
auto ty = mlir::cast<mlir::TypeAttr>(*i).getValue();
19731973
auto index = mlir::cast<fir::RecordType>(ty).getFieldIndex(fieldName);
19741974
indices.push_back(index);
19751975
}
@@ -3014,7 +3014,7 @@ static void selectMatchAndRewrite(const fir::LLVMTypeConverter &lowering,
30143014
caseValues.push_back(intAttr.getInt());
30153015
continue;
30163016
}
3017-
assert(attr.template dyn_cast_or_null<mlir::UnitAttr>());
3017+
assert(mlir::dyn_cast_or_null<mlir::UnitAttr>(attr));
30183018
assert((t + 1 == conds) && "unit must be last");
30193019
defaultDestination = dest;
30203020
defaultOperands = destOps ? *destOps : mlir::ValueRange{};

flang/lib/Optimizer/Dialect/FIROps.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2498,10 +2498,8 @@ static constexpr llvm::StringRef getTargetOffsetAttr() {
24982498

24992499
template <typename OpT>
25002500
static mlir::LogicalResult verifyIntegralSwitchTerminator(OpT op) {
2501-
if (!op.getSelector()
2502-
.getType()
2503-
.template isa<mlir::IntegerType, mlir::IndexType,
2504-
fir::IntegerType>())
2501+
if (!mlir::isa<mlir::IntegerType, mlir::IndexType, fir::IntegerType>(
2502+
op.getSelector().getType()))
25052503
return op.emitOpError("must be an integer");
25062504
auto cases =
25072505
op->template getAttrOfType<mlir::ArrayAttr>(op.getCasesAttr()).getValue();
@@ -2576,7 +2574,7 @@ static void printIntegralSwitchTerminator(OpT op, mlir::OpAsmPrinter &p) {
25762574
if (i)
25772575
p << ", ";
25782576
auto &attr = cases[i];
2579-
if (auto intAttr = attr.template dyn_cast_or_null<mlir::IntegerAttr>())
2577+
if (auto intAttr = mlir::dyn_cast_or_null<mlir::IntegerAttr>(attr))
25802578
p << intAttr.getValue();
25812579
else
25822580
p.printAttribute(attr);

flang/lib/Optimizer/Dialect/FIRType.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -695,9 +695,9 @@ BoxProcType::verify(llvm::function_ref<mlir::InFlightDiagnostic()> emitError,
695695
}
696696

697697
static bool cannotBePointerOrHeapElementType(mlir::Type eleTy) {
698-
return eleTy.isa<BoxType, BoxCharType, BoxProcType, ShapeType, ShapeShiftType,
698+
return mlir::isa<BoxType, BoxCharType, BoxProcType, ShapeType, ShapeShiftType,
699699
SliceType, FieldType, LenType, HeapType, PointerType,
700-
ReferenceType, TypeDescType>();
700+
ReferenceType, TypeDescType>(eleTy);
701701
}
702702

703703
//===----------------------------------------------------------------------===//
@@ -776,10 +776,10 @@ void fir::CharacterType::print(mlir::AsmPrinter &printer) const {
776776
mlir::LogicalResult
777777
fir::ClassType::verify(llvm::function_ref<mlir::InFlightDiagnostic()> emitError,
778778
mlir::Type eleTy) {
779-
if (eleTy.isa<fir::RecordType, fir::SequenceType, fir::HeapType,
779+
if (mlir::isa<fir::RecordType, fir::SequenceType, fir::HeapType,
780780
fir::PointerType, mlir::NoneType, mlir::IntegerType,
781781
mlir::FloatType, fir::CharacterType, fir::LogicalType,
782-
fir::ComplexType, mlir::ComplexType>())
782+
fir::ComplexType, mlir::ComplexType>(eleTy))
783783
return mlir::success();
784784
return emitError() << "invalid element type\n";
785785
}
@@ -1050,8 +1050,8 @@ void fir::ReferenceType::print(mlir::AsmPrinter &printer) const {
10501050
mlir::LogicalResult fir::ReferenceType::verify(
10511051
llvm::function_ref<mlir::InFlightDiagnostic()> emitError,
10521052
mlir::Type eleTy) {
1053-
if (eleTy.isa<ShapeType, ShapeShiftType, SliceType, FieldType, LenType,
1054-
ReferenceType, TypeDescType>())
1053+
if (mlir::isa<ShapeType, ShapeShiftType, SliceType, FieldType, LenType,
1054+
ReferenceType, TypeDescType>(eleTy))
10551055
return emitError() << "cannot build a reference to type: " << eleTy << '\n';
10561056
return mlir::success();
10571057
}
@@ -1126,9 +1126,9 @@ mlir::LogicalResult fir::SequenceType::verify(
11261126
llvm::ArrayRef<int64_t> shape, mlir::Type eleTy,
11271127
mlir::AffineMapAttr layoutMap) {
11281128
// DIMENSION attribute can only be applied to an intrinsic or record type
1129-
if (eleTy.isa<BoxType, BoxCharType, BoxProcType, ShapeType, ShapeShiftType,
1129+
if (mlir::isa<BoxType, BoxCharType, BoxProcType, ShapeType, ShapeShiftType,
11301130
ShiftType, SliceType, FieldType, LenType, HeapType, PointerType,
1131-
ReferenceType, TypeDescType, SequenceType>())
1131+
ReferenceType, TypeDescType, SequenceType>(eleTy))
11321132
return emitError() << "cannot build an array of this element type: "
11331133
<< eleTy << '\n';
11341134
return mlir::success();
@@ -1199,9 +1199,9 @@ void fir::TypeDescType::print(mlir::AsmPrinter &printer) const {
11991199
mlir::LogicalResult fir::TypeDescType::verify(
12001200
llvm::function_ref<mlir::InFlightDiagnostic()> emitError,
12011201
mlir::Type eleTy) {
1202-
if (eleTy.isa<BoxType, BoxCharType, BoxProcType, ShapeType, ShapeShiftType,
1202+
if (mlir::isa<BoxType, BoxCharType, BoxProcType, ShapeType, ShapeShiftType,
12031203
ShiftType, SliceType, FieldType, LenType, ReferenceType,
1204-
TypeDescType>())
1204+
TypeDescType>(eleTy))
12051205
return emitError() << "cannot build a type descriptor of type: " << eleTy
12061206
<< '\n';
12071207
return mlir::success();

flang/lib/Optimizer/Transforms/SimplifyIntrinsics.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1318,11 +1318,9 @@ void SimplifyIntrinsicsPass::runOnOperation() {
13181318

13191319
// Support only floating point and integer arguments
13201320
// now (e.g. logical is skipped here).
1321-
if (!arg1Type->isa<mlir::FloatType>() &&
1322-
!arg1Type->isa<mlir::IntegerType>())
1321+
if (!mlir::isa<mlir::FloatType, mlir::IntegerType>(*arg1Type))
13231322
return;
1324-
if (!arg2Type->isa<mlir::FloatType>() &&
1325-
!arg2Type->isa<mlir::IntegerType>())
1323+
if (!mlir::isa<mlir::FloatType, mlir::IntegerType>(*arg2Type))
13261324
return;
13271325

13281326
auto typeGenerator = [&type](fir::FirOpBuilder &builder) {

0 commit comments

Comments
 (0)