llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
25.96k stars 10.6k forks source link

[flang] Use `isa/dyn_cast/cast/...` free functions. #90432

Closed chsigg closed 2 weeks ago

chsigg commented 2 weeks ago

The corresponding member functions are deprecated.

llvmbot commented 2 weeks ago

@llvm/pr-subscribers-flang-codegen

@llvm/pr-subscribers-flang-fir-hlfir

Author: Christian Sigg (chsigg)

Changes The corresponding member functions are deprecated. --- Full diff: https://github.com/llvm/llvm-project/pull/90432.diff 5 Files Affected: - (modified) flang/lib/Lower/ConvertVariable.cpp (+2-2) - (modified) flang/lib/Optimizer/CodeGen/CodeGen.cpp (+4-4) - (modified) flang/lib/Optimizer/Dialect/FIROps.cpp (+3-5) - (modified) flang/lib/Optimizer/Dialect/FIRType.cpp (+10-10) - (modified) flang/lib/Optimizer/Transforms/SimplifyIntrinsics.cpp (+2-4) ``````````diff diff --git a/flang/lib/Lower/ConvertVariable.cpp b/flang/lib/Lower/ConvertVariable.cpp index edf1f24a08e5c9..413563fe95ca38 100644 --- a/flang/lib/Lower/ConvertVariable.cpp +++ b/flang/lib/Lower/ConvertVariable.cpp @@ -496,8 +496,8 @@ static fir::GlobalOp defineGlobal(Fortran::lower::AbstractConverter &converter, if (mlir::isa(symTy) && !Fortran::semantics::IsAllocatableOrPointer(sym)) { mlir::Type eleTy = mlir::cast(symTy).getEleTy(); - if (eleTy.isa()) { + if (mlir::isa(eleTy)) { const auto *details = sym.detailsIf(); if (details->init()) { diff --git a/flang/lib/Optimizer/CodeGen/CodeGen.cpp b/flang/lib/Optimizer/CodeGen/CodeGen.cpp index 19628ac71b0b21..b4705aa4799258 100644 --- a/flang/lib/Optimizer/CodeGen/CodeGen.cpp +++ b/flang/lib/Optimizer/CodeGen/CodeGen.cpp @@ -1964,12 +1964,12 @@ struct ValueOpCommon { mlir::ArrayAttr arrAttr) { llvm::SmallVector indices; for (auto i = arrAttr.begin(), e = arrAttr.end(); i != e; ++i) { - if (auto intAttr = i->dyn_cast()) { + if (auto intAttr = mlir::dyn_cast(*i)) { indices.push_back(intAttr.getInt()); } else { - auto fieldName = i->cast().getValue(); + auto fieldName = mlir::cast(*i).getValue(); ++i; - auto ty = i->cast().getValue(); + auto ty = mlir::cast(*i).getValue(); auto index = mlir::cast(ty).getFieldIndex(fieldName); indices.push_back(index); } @@ -3014,7 +3014,7 @@ static void selectMatchAndRewrite(const fir::LLVMTypeConverter &lowering, caseValues.push_back(intAttr.getInt()); continue; } - assert(attr.template dyn_cast_or_null()); + assert(mlir::dyn_cast_or_null(attr)); assert((t + 1 == conds) && "unit must be last"); defaultDestination = dest; defaultOperands = destOps ? *destOps : mlir::ValueRange{}; diff --git a/flang/lib/Optimizer/Dialect/FIROps.cpp b/flang/lib/Optimizer/Dialect/FIROps.cpp index a39087aeb358b9..6773d0adced0ce 100644 --- a/flang/lib/Optimizer/Dialect/FIROps.cpp +++ b/flang/lib/Optimizer/Dialect/FIROps.cpp @@ -2498,10 +2498,8 @@ static constexpr llvm::StringRef getTargetOffsetAttr() { template static mlir::LogicalResult verifyIntegralSwitchTerminator(OpT op) { - if (!op.getSelector() - .getType() - .template isa()) + if (!mlir::isa( + op.getSelector().getType())) return op.emitOpError("must be an integer"); auto cases = op->template getAttrOfType(op.getCasesAttr()).getValue(); @@ -2576,7 +2574,7 @@ static void printIntegralSwitchTerminator(OpT op, mlir::OpAsmPrinter &p) { if (i) p << ", "; auto &attr = cases[i]; - if (auto intAttr = attr.template dyn_cast_or_null()) + if (auto intAttr = mlir::dyn_cast_or_null(attr)) p << intAttr.getValue(); else p.printAttribute(attr); diff --git a/flang/lib/Optimizer/Dialect/FIRType.cpp b/flang/lib/Optimizer/Dialect/FIRType.cpp index 38a6a09d1808a6..d9c387ad950e82 100644 --- a/flang/lib/Optimizer/Dialect/FIRType.cpp +++ b/flang/lib/Optimizer/Dialect/FIRType.cpp @@ -695,9 +695,9 @@ BoxProcType::verify(llvm::function_ref emitError, } static bool cannotBePointerOrHeapElementType(mlir::Type eleTy) { - return eleTy.isa(); + ReferenceType, TypeDescType>(eleTy); } //===----------------------------------------------------------------------===// @@ -776,10 +776,10 @@ void fir::CharacterType::print(mlir::AsmPrinter &printer) const { mlir::LogicalResult fir::ClassType::verify(llvm::function_ref emitError, mlir::Type eleTy) { - if (eleTy.isa()) + fir::ComplexType, mlir::ComplexType>(eleTy)) return mlir::success(); return emitError() << "invalid element type\n"; } @@ -1050,8 +1050,8 @@ void fir::ReferenceType::print(mlir::AsmPrinter &printer) const { mlir::LogicalResult fir::ReferenceType::verify( llvm::function_ref emitError, mlir::Type eleTy) { - if (eleTy.isa()) + if (mlir::isa(eleTy)) return emitError() << "cannot build a reference to type: " << eleTy << '\n'; return mlir::success(); } @@ -1126,9 +1126,9 @@ mlir::LogicalResult fir::SequenceType::verify( llvm::ArrayRef shape, mlir::Type eleTy, mlir::AffineMapAttr layoutMap) { // DIMENSION attribute can only be applied to an intrinsic or record type - if (eleTy.isa()) + ReferenceType, TypeDescType, SequenceType>(eleTy)) return emitError() << "cannot build an array of this element type: " << eleTy << '\n'; return mlir::success(); @@ -1199,9 +1199,9 @@ void fir::TypeDescType::print(mlir::AsmPrinter &printer) const { mlir::LogicalResult fir::TypeDescType::verify( llvm::function_ref emitError, mlir::Type eleTy) { - if (eleTy.isa()) + TypeDescType>(eleTy)) return emitError() << "cannot build a type descriptor of type: " << eleTy << '\n'; return mlir::success(); diff --git a/flang/lib/Optimizer/Transforms/SimplifyIntrinsics.cpp b/flang/lib/Optimizer/Transforms/SimplifyIntrinsics.cpp index 601bf04ce5e9b3..c61179a7460e32 100644 --- a/flang/lib/Optimizer/Transforms/SimplifyIntrinsics.cpp +++ b/flang/lib/Optimizer/Transforms/SimplifyIntrinsics.cpp @@ -1318,11 +1318,9 @@ void SimplifyIntrinsicsPass::runOnOperation() { // Support only floating point and integer arguments // now (e.g. logical is skipped here). - if (!arg1Type->isa() && - !arg1Type->isa()) + if (!mlir::isa(*arg1Type)) return; - if (!arg2Type->isa() && - !arg2Type->isa()) + if (!mlir::isa(*arg2Type)) return; auto typeGenerator = [&type](fir::FirOpBuilder &builder) { ``````````
chsigg commented 2 weeks ago

This PR contains the NFC flang bits of PR #90413.

DavidSpickett commented 2 weeks ago

FYI there are a still a bunch of warnings coming out of MLIR (https://lab.llvm.org/buildbot/#/builders/268/builds/13096) and flang (https://lab.llvm.org/buildbot/#/builders/175/builds/47268).

You won't be getting email about this because your commit email is a noreply address. I'm not saying you have to set an email there, but this is one consequence of not doing so.

I can probably figure out flang, but would appreciate you tracking down the mlir ones, or telling me what patches are in flight since I see some changes in already.