Skip to content

Commit

Permalink
[mlir] Mark isa/dyn_cast/cast/... member functions deprecated. (#89998
Browse files Browse the repository at this point in the history
  • Loading branch information
chsigg committed Apr 26, 2024
1 parent 450ac01 commit 950b7ce
Show file tree
Hide file tree
Showing 97 changed files with 1,342 additions and 1,275 deletions.
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,
eleTy.cast<fir::RecordType>().getName());
mlir::cast<fir::RecordType>(eleTy).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(attr.cast<mlir::StringAttr>());
return getFuncTree(mlir::cast<mlir::StringAttr>(attr));
}
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 && addr.getType().template isa<fir::BoxCharType>())
if (addr && mlir::isa<fir::BoxCharType>(addr.getType()))
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 type.cast<fir::BaseBoxType>();
return mlir::cast<fir::BaseBoxType>(type);
}
/// Return the part of the address type after memory and box types. That is
/// the element type, maybe wrapped in a fir.array type.
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 = type.dyn_cast<fir::SequenceType>())
if (auto seqTy = mlir::dyn_cast<fir::SequenceType>(type))
return seqTy.getEleTy();
return type;
}

/// Is the entity an array or an assumed rank ?
bool hasRank() const { return getBaseTy().isa<fir::SequenceType>(); }
bool hasRank() const { return mlir::isa<fir::SequenceType>(getBaseTy()); }
/// Is this an assumed rank ?
bool hasAssumedRank() const {
auto seqTy = getBaseTy().dyn_cast<fir::SequenceType>();
auto seqTy = mlir::dyn_cast<fir::SequenceType>(getBaseTy());
return seqTy && seqTy.hasUnknownShape();
}
/// Returns the rank of the entity. Beware that zero will be returned for
/// both scalars and assumed rank.
unsigned rank() const {
if (auto seqTy = getBaseTy().dyn_cast<fir::SequenceType>())
if (auto seqTy = mlir::dyn_cast<fir::SequenceType>(getBaseTy()))
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 getEleTy().isa<fir::RecordType>(); }
bool isDerived() const { return mlir::isa<fir::RecordType>(getEleTy()); }

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 getBoxTy().getEleTy().isa<fir::PointerType>();
return mlir::isa<fir::PointerType>(getBoxTy().getEleTy());
}
/// Is this an allocatable ?
bool isAllocatable() const {
return getBoxTy().getEleTy().isa<fir::HeapType>();
return mlir::isa<fir::HeapType>(getBoxTy().getEleTy());
}
// 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 (type.template isa<fir::BoxCharType>())
if (mlir::isa<fir::BoxCharType>(type))
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 =
fir::dyn_cast_ptrEleTy(src.getType()).template cast<fir::CharacterType>();
mlir::cast<fir::CharacterType>(fir::dyn_cast_ptrEleTy(src.getType()));
auto dstTy =
fir::dyn_cast_ptrEleTy(dst.getType()).template cast<fir::CharacterType>();
mlir::cast<fir::CharacterType>(fir::dyn_cast_ptrEleTy(dst.getType()));
if (!srcLen && !dstLen && srcTy.getFKind() == dstTy.getFKind() &&
srcTy.getLen() == dstTy.getLen()) {
// same size, so just use load and store
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 = ty.getEleTy().cast<fir::SequenceType>();
return seqTy.getEleTy().cast<fir::CharacterType>();
auto seqTy = mlir::cast<fir::SequenceType>(ty.getEleTy());
return mlir::cast<fir::CharacterType>(seqTy.getEleTy());
};
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 && ty.isa<fir::SequenceType>());
auto seqTy = ty.cast<fir::SequenceType>();
assert(ty && mlir::isa<fir::SequenceType>(ty));
auto seqTy = mlir::cast<fir::SequenceType>(ty);
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 = type.dyn_cast<fir::SequenceType>()) {
if (auto seqTy = mlir::dyn_cast<fir::SequenceType>(type)) {
if (seqTy.hasUnknownShape())
return -1;
return seqTy.getDimension();
}
if (auto exprType = type.dyn_cast<hlfir::ExprType>())
if (auto exprType = mlir::dyn_cast<hlfir::ExprType>(type))
return exprType.getRank();
return 0;
}
Expand All @@ -99,17 +99,17 @@ class Entity : public mlir::Value {

bool hasLengthParameters() const {
mlir::Type eleTy = getFortranElementType();
return eleTy.isa<fir::CharacterType>() ||
return mlir::isa<fir::CharacterType>(eleTy) ||
fir::isRecordWithTypeParameters(eleTy);
}

bool isCharacter() const {
return getFortranElementType().isa<fir::CharacterType>();
return mlir::isa<fir::CharacterType>(getFortranElementType());
}

bool hasIntrinsicType() const {
mlir::Type eleTy = getFortranElementType();
return fir::isa_trivial(eleTy) || eleTy.isa<fir::CharacterType>();
return fir::isa_trivial(eleTy) || mlir::isa<fir::CharacterType>(eleTy);
}

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 shapeTy.isa<fir::ShiftType>() ||
shapeTy.isa<fir::ShapeShiftType>();
return mlir::isa<fir::ShiftType>(shapeTy) ||
mlir::isa<fir::ShapeShiftType>(shapeTy);
}
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 (eleTy.isa<mlir::IntegerType>() && !eleTy.isSignlessInteger()) {
const auto intTy{eleTy.dyn_cast<mlir::IntegerType>()};
if (mlir::isa<mlir::IntegerType>(eleTy) && !eleTy.isSignlessInteger()) {
const auto intTy{mlir::dyn_cast<mlir::IntegerType>(eleTy)};
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(firTy.isa<fir::VectorType>());
assert(mlir::isa<fir::VectorType>(firTy));
VecTypeInfo vecTyInfo;
vecTyInfo.eleTy = firTy.dyn_cast<fir::VectorType>().getEleTy();
vecTyInfo.len = firTy.dyn_cast<fir::VectorType>().getLen();
vecTyInfo.eleTy = mlir::dyn_cast<fir::VectorType>(firTy).getEleTy();
vecTyInfo.len = mlir::dyn_cast<fir::VectorType>(firTy).getLen();
return vecTyInfo;
}

Expand Down
23 changes: 12 additions & 11 deletions flang/include/flang/Optimizer/Dialect/CanonicalizationPatterns.td
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,18 @@ 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<"$0.getType().isa<mlir::IndexType>()">>;
def IndexTypePred : Constraint<CPred<
"mlir::isa<mlir::IndexType>($0.getType())">>;

// Widths are monotonic.
// $0.bits >= $1.bits >= $2.bits or $0.bits <= $1.bits <= $2.bits
def MonotonicTypePred
: 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>())) && "
: 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()))) && "
"(($0.getType().getIntOrFloatBitWidth() <= "
" $1.getType().getIntOrFloatBitWidth() && "
" $1.getType().getIntOrFloatBitWidth() <= "
Expand All @@ -42,8 +43,8 @@ def MonotonicTypePred
" $2.getType().getIntOrFloatBitWidth()))">>;

def IntPred : Constraint<CPred<
"$0.getType().isa<mlir::IntegerType>() && "
"$1.getType().isa<mlir::IntegerType>()">>;
"mlir::isa<mlir::IntegerType>($0.getType()) && "
"mlir::isa<mlir::IntegerType>($1.getType())">>;

// If both are int type and the first is smaller than the second.
// $0.bits <= $1.bits
Expand Down Expand Up @@ -101,8 +102,8 @@ def CombineConvertTruncOptPattern
def createConstantOp
: NativeCodeCall<"$_builder.create<mlir::arith::ConstantOp>"
"($_loc, $_builder.getIndexType(), "
"rewriter.getIndexAttr($1.dyn_cast<mlir::IntegerAttr>()"
".getInt()))">;
"rewriter.getIndexAttr("
"mlir::dyn_cast<mlir::IntegerAttr>($1).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<"$_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"> {
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"> {
let storageType = [{ ::mlir::TypeAttr }];
let returnType = "mlir::Type";
let convertFromStorage = "$_self.getValue().cast<mlir::Type>()";
let convertFromStorage = "mlir::cast<mlir::Type>($_self.getValue())";
}

def fir_TypeDescOp : fir_OneResultOp<"type_desc", [NoMemoryEffect]> {
Expand Down

0 comments on commit 950b7ce

Please sign in to comment.