Skip to content

Revert "[mlir] Mark isa/dyn_cast/cast/... member functions deprecated. (#89998)" #90250

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion flang/include/flang/Lower/Mangler.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion flang/include/flang/Optimizer/Analysis/TBAAForest.h
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
20 changes: 10 additions & 10 deletions flang/include/flang/Optimizer/Builder/BoxValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down Expand Up @@ -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.
Expand All @@ -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;
}
Expand All @@ -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());
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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))
Expand Down
12 changes: 6 additions & 6 deletions flang/include/flang/Optimizer/Builder/Factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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));
Expand Down Expand Up @@ -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) {
Expand Down
14 changes: 7 additions & 7 deletions flang/include/flang/Optimizer/Builder/HLFIRTools.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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 {
Expand All @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions flang/include/flang/Optimizer/Builder/IntrinsicCall.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
6 changes: 3 additions & 3 deletions flang/include/flang/Optimizer/Builder/PPCIntrinsicCall.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
23 changes: 11 additions & 12 deletions flang/include/flang/Optimizer/Dialect/CanonicalizationPatterns.td
Original file line number Diff line number Diff line change
Expand Up @@ -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() <= "
Expand All @@ -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
Expand Down Expand Up @@ -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)),
Expand Down
12 changes: 6 additions & 6 deletions flang/include/flang/Optimizer/Dialect/FIROps.td
Original file line number Diff line number Diff line change
Expand Up @@ -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]> {
Expand Down
Loading
Loading