Skip to content

Commit fac349a

Browse files
authored
Reapply "[mlir] Mark isa/dyn_cast/cast/... member functions depreca… (llvm#90406)
…ted. (llvm#89998)" (llvm#90250) This partially reverts commit 7aedd7d. This change removes calls to the deprecated member functions. It does not mark the functions deprecated yet and does not disable the deprecation warning in TypeSwitch. This seems to cause problems with MSVC.
1 parent c9dae43 commit fac349a

File tree

93 files changed

+1326
-1275
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+1326
-1275
lines changed

flang/include/flang/Lower/Mangler.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ inline std::string mangleArrayLiteral(
9090
return mangleArrayLiteral(x.values().size() * sizeof(x.values()[0]),
9191
x.shape(), Fortran::common::TypeCategory::Derived,
9292
/*kind=*/0, /*charLen=*/-1,
93-
eleTy.cast<fir::RecordType>().getName());
93+
mlir::cast<fir::RecordType>(eleTy).getName());
9494
}
9595

9696
/// Return the compiler-generated name of a static namelist variable descriptor.

flang/include/flang/Optimizer/Analysis/TBAAForest.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ class TBAAForrest {
8888
// name must be used so that we add to the tbaa tree added in the FIR pass
8989
mlir::Attribute attr = func->getAttr(getInternalFuncNameAttrName());
9090
if (attr) {
91-
return getFuncTree(attr.cast<mlir::StringAttr>());
91+
return getFuncTree(mlir::cast<mlir::StringAttr>(attr));
9292
}
9393
return getFuncTree(func.getSymNameAttr());
9494
}

flang/include/flang/Optimizer/Builder/BoxValue.h

+10-10
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class CharBoxValue : public AbstractBox {
7878
public:
7979
CharBoxValue(mlir::Value addr, mlir::Value len)
8080
: AbstractBox{addr}, len{len} {
81-
if (addr && addr.getType().template isa<fir::BoxCharType>())
81+
if (addr && mlir::isa<fir::BoxCharType>(addr.getType()))
8282
fir::emitFatalError(addr.getLoc(),
8383
"BoxChar should not be in CharBoxValue");
8484
}
@@ -221,7 +221,7 @@ class AbstractIrBox : public AbstractBox, public AbstractArrayBox {
221221
auto type = getAddr().getType();
222222
if (auto pointedTy = fir::dyn_cast_ptrEleTy(type))
223223
type = pointedTy;
224-
return type.cast<fir::BaseBoxType>();
224+
return mlir::cast<fir::BaseBoxType>(type);
225225
}
226226
/// Return the part of the address type after memory and box types. That is
227227
/// the element type, maybe wrapped in a fir.array type.
@@ -243,22 +243,22 @@ class AbstractIrBox : public AbstractBox, public AbstractArrayBox {
243243
/// Get the scalar type related to the described entity
244244
mlir::Type getEleTy() const {
245245
auto type = getBaseTy();
246-
if (auto seqTy = type.dyn_cast<fir::SequenceType>())
246+
if (auto seqTy = mlir::dyn_cast<fir::SequenceType>(type))
247247
return seqTy.getEleTy();
248248
return type;
249249
}
250250

251251
/// Is the entity an array or an assumed rank ?
252-
bool hasRank() const { return getBaseTy().isa<fir::SequenceType>(); }
252+
bool hasRank() const { return mlir::isa<fir::SequenceType>(getBaseTy()); }
253253
/// Is this an assumed rank ?
254254
bool hasAssumedRank() const {
255-
auto seqTy = getBaseTy().dyn_cast<fir::SequenceType>();
255+
auto seqTy = mlir::dyn_cast<fir::SequenceType>(getBaseTy());
256256
return seqTy && seqTy.hasUnknownShape();
257257
}
258258
/// Returns the rank of the entity. Beware that zero will be returned for
259259
/// both scalars and assumed rank.
260260
unsigned rank() const {
261-
if (auto seqTy = getBaseTy().dyn_cast<fir::SequenceType>())
261+
if (auto seqTy = mlir::dyn_cast<fir::SequenceType>(getBaseTy()))
262262
return seqTy.getDimension();
263263
return 0;
264264
}
@@ -267,7 +267,7 @@ class AbstractIrBox : public AbstractBox, public AbstractArrayBox {
267267
bool isCharacter() const { return fir::isa_char(getEleTy()); }
268268

269269
/// Is this a derived type entity ?
270-
bool isDerived() const { return getEleTy().isa<fir::RecordType>(); }
270+
bool isDerived() const { return mlir::isa<fir::RecordType>(getEleTy()); }
271271

272272
bool isDerivedWithLenParameters() const {
273273
return fir::isRecordWithTypeParameters(getEleTy());
@@ -377,11 +377,11 @@ class MutableBoxValue : public AbstractIrBox {
377377
}
378378
/// Is this a Fortran pointer ?
379379
bool isPointer() const {
380-
return getBoxTy().getEleTy().isa<fir::PointerType>();
380+
return mlir::isa<fir::PointerType>(getBoxTy().getEleTy());
381381
}
382382
/// Is this an allocatable ?
383383
bool isAllocatable() const {
384-
return getBoxTy().getEleTy().isa<fir::HeapType>();
384+
return mlir::isa<fir::HeapType>(getBoxTy().getEleTy());
385385
}
386386
// Replace the fir.ref<fir.box>, keeping any non-deferred parameters.
387387
MutableBoxValue clone(mlir::Value newBox) const {
@@ -488,7 +488,7 @@ class ExtendedValue : public details::matcher<ExtendedValue> {
488488
if (const auto *b = getUnboxed()) {
489489
if (*b) {
490490
auto type = b->getType();
491-
if (type.template isa<fir::BoxCharType>())
491+
if (mlir::isa<fir::BoxCharType>(type))
492492
fir::emitFatalError(b->getLoc(), "BoxChar should be unboxed");
493493
type = fir::unwrapSequenceType(fir::unwrapRefType(type));
494494
if (fir::isa_char(type))

flang/include/flang/Optimizer/Builder/Factory.h

+6-6
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ template <typename B>
4343
void genCharacterCopy(mlir::Value src, mlir::Value srcLen, mlir::Value dst,
4444
mlir::Value dstLen, B &builder, mlir::Location loc) {
4545
auto srcTy =
46-
fir::dyn_cast_ptrEleTy(src.getType()).template cast<fir::CharacterType>();
46+
mlir::cast<fir::CharacterType>(fir::dyn_cast_ptrEleTy(src.getType()));
4747
auto dstTy =
48-
fir::dyn_cast_ptrEleTy(dst.getType()).template cast<fir::CharacterType>();
48+
mlir::cast<fir::CharacterType>(fir::dyn_cast_ptrEleTy(dst.getType()));
4949
if (!srcLen && !dstLen && srcTy.getFKind() == dstTy.getFKind() &&
5050
srcTy.getLen() == dstTy.getLen()) {
5151
// same size, so just use load and store
@@ -61,8 +61,8 @@ void genCharacterCopy(mlir::Value src, mlir::Value srcLen, mlir::Value dst,
6161
fir::CharacterType::getSingleton(ty.getContext(), ty.getFKind())));
6262
};
6363
auto toEleTy = [&](fir::ReferenceType ty) {
64-
auto seqTy = ty.getEleTy().cast<fir::SequenceType>();
65-
return seqTy.getEleTy().cast<fir::CharacterType>();
64+
auto seqTy = mlir::cast<fir::SequenceType>(ty.getEleTy());
65+
return mlir::cast<fir::CharacterType>(seqTy.getEleTy());
6666
};
6767
auto toCoorTy = [&](fir::ReferenceType ty) {
6868
return fir::ReferenceType::get(toEleTy(ty));
@@ -190,8 +190,8 @@ originateIndices(mlir::Location loc, B &builder, mlir::Type memTy,
190190
if (origins.empty()) {
191191
assert(!shapeVal || mlir::isa<fir::ShapeOp>(shapeVal.getDefiningOp()));
192192
auto ty = fir::dyn_cast_ptrOrBoxEleTy(memTy);
193-
assert(ty && ty.isa<fir::SequenceType>());
194-
auto seqTy = ty.cast<fir::SequenceType>();
193+
assert(ty && mlir::isa<fir::SequenceType>(ty));
194+
auto seqTy = mlir::cast<fir::SequenceType>(ty);
195195
auto one = builder.template create<mlir::arith::ConstantIndexOp>(loc, 1);
196196
const auto dimension = seqTy.getDimension();
197197
if (shapeVal) {

flang/include/flang/Optimizer/Builder/HLFIRTools.h

+7-7
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,12 @@ class Entity : public mlir::Value {
7777
/// Return the rank of this entity or -1 if it is an assumed rank.
7878
int getRank() const {
7979
mlir::Type type = fir::unwrapPassByRefType(fir::unwrapRefType(getType()));
80-
if (auto seqTy = type.dyn_cast<fir::SequenceType>()) {
80+
if (auto seqTy = mlir::dyn_cast<fir::SequenceType>(type)) {
8181
if (seqTy.hasUnknownShape())
8282
return -1;
8383
return seqTy.getDimension();
8484
}
85-
if (auto exprType = type.dyn_cast<hlfir::ExprType>())
85+
if (auto exprType = mlir::dyn_cast<hlfir::ExprType>(type))
8686
return exprType.getRank();
8787
return 0;
8888
}
@@ -99,17 +99,17 @@ class Entity : public mlir::Value {
9999

100100
bool hasLengthParameters() const {
101101
mlir::Type eleTy = getFortranElementType();
102-
return eleTy.isa<fir::CharacterType>() ||
102+
return mlir::isa<fir::CharacterType>(eleTy) ||
103103
fir::isRecordWithTypeParameters(eleTy);
104104
}
105105

106106
bool isCharacter() const {
107-
return getFortranElementType().isa<fir::CharacterType>();
107+
return mlir::isa<fir::CharacterType>(getFortranElementType());
108108
}
109109

110110
bool hasIntrinsicType() const {
111111
mlir::Type eleTy = getFortranElementType();
112-
return fir::isa_trivial(eleTy) || eleTy.isa<fir::CharacterType>();
112+
return fir::isa_trivial(eleTy) || mlir::isa<fir::CharacterType>(eleTy);
113113
}
114114

115115
bool isDerivedWithLengthParameters() const {
@@ -124,8 +124,8 @@ class Entity : public mlir::Value {
124124
if (auto varIface = getIfVariableInterface()) {
125125
if (auto shape = varIface.getShape()) {
126126
auto shapeTy = shape.getType();
127-
return shapeTy.isa<fir::ShiftType>() ||
128-
shapeTy.isa<fir::ShapeShiftType>();
127+
return mlir::isa<fir::ShiftType>(shapeTy) ||
128+
mlir::isa<fir::ShapeShiftType>(shapeTy);
129129
}
130130
return false;
131131
}

flang/include/flang/Optimizer/Builder/IntrinsicCall.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -663,8 +663,8 @@ static inline mlir::FunctionType genFuncType(mlir::MLIRContext *context,
663663
//===----------------------------------------------------------------------===//
664664
static inline mlir::Type getConvertedElementType(mlir::MLIRContext *context,
665665
mlir::Type eleTy) {
666-
if (eleTy.isa<mlir::IntegerType>() && !eleTy.isSignlessInteger()) {
667-
const auto intTy{eleTy.dyn_cast<mlir::IntegerType>()};
666+
if (mlir::isa<mlir::IntegerType>(eleTy) && !eleTy.isSignlessInteger()) {
667+
const auto intTy{mlir::dyn_cast<mlir::IntegerType>(eleTy)};
668668
auto newEleTy{mlir::IntegerType::get(context, intTy.getWidth())};
669669
return newEleTy;
670670
}

flang/include/flang/Optimizer/Builder/PPCIntrinsicCall.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -180,10 +180,10 @@ struct VecTypeInfo {
180180
// Returns a VecTypeInfo with element type and length of given fir vector type.
181181
// Preserves signness of fir vector type if element type of integer.
182182
static inline VecTypeInfo getVecTypeFromFirType(mlir::Type firTy) {
183-
assert(firTy.isa<fir::VectorType>());
183+
assert(mlir::isa<fir::VectorType>(firTy));
184184
VecTypeInfo vecTyInfo;
185-
vecTyInfo.eleTy = firTy.dyn_cast<fir::VectorType>().getEleTy();
186-
vecTyInfo.len = firTy.dyn_cast<fir::VectorType>().getLen();
185+
vecTyInfo.eleTy = mlir::dyn_cast<fir::VectorType>(firTy).getEleTy();
186+
vecTyInfo.len = mlir::dyn_cast<fir::VectorType>(firTy).getLen();
187187
return vecTyInfo;
188188
}
189189

flang/include/flang/Optimizer/Dialect/CanonicalizationPatterns.td

+12-11
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,18 @@ include "flang/Optimizer/Dialect/FIROps.td"
2121

2222
def IdenticalTypePred : Constraint<CPred<"$0.getType() == $1.getType()">>;
2323
def IntegerTypePred : Constraint<CPred<"fir::isa_integer($0.getType())">>;
24-
def IndexTypePred : Constraint<CPred<"$0.getType().isa<mlir::IndexType>()">>;
24+
def IndexTypePred : Constraint<CPred<
25+
"mlir::isa<mlir::IndexType>($0.getType())">>;
2526

2627
// Widths are monotonic.
2728
// $0.bits >= $1.bits >= $2.bits or $0.bits <= $1.bits <= $2.bits
2829
def MonotonicTypePred
29-
: Constraint<CPred<"(($0.getType().isa<mlir::IntegerType>() && "
30-
" $1.getType().isa<mlir::IntegerType>() && "
31-
" $2.getType().isa<mlir::IntegerType>()) || "
32-
" ($0.getType().isa<mlir::FloatType>() && "
33-
" $1.getType().isa<mlir::FloatType>() && "
34-
" $2.getType().isa<mlir::FloatType>())) && "
30+
: Constraint<CPred<"((mlir::isa<mlir::IntegerType>($0.getType()) && "
31+
" mlir::isa<mlir::IntegerType>($1.getType()) && "
32+
" mlir::isa<mlir::IntegerType>($2.getType())) || "
33+
" (mlir::isa<mlir::FloatType>($0.getType()) && "
34+
" mlir::isa<mlir::FloatType>($1.getType()) && "
35+
" mlir::isa<mlir::FloatType>($2.getType()))) && "
3536
"(($0.getType().getIntOrFloatBitWidth() <= "
3637
" $1.getType().getIntOrFloatBitWidth() && "
3738
" $1.getType().getIntOrFloatBitWidth() <= "
@@ -42,8 +43,8 @@ def MonotonicTypePred
4243
" $2.getType().getIntOrFloatBitWidth()))">>;
4344

4445
def IntPred : Constraint<CPred<
45-
"$0.getType().isa<mlir::IntegerType>() && "
46-
"$1.getType().isa<mlir::IntegerType>()">>;
46+
"mlir::isa<mlir::IntegerType>($0.getType()) && "
47+
"mlir::isa<mlir::IntegerType>($1.getType())">>;
4748

4849
// If both are int type and the first is smaller than the second.
4950
// $0.bits <= $1.bits
@@ -101,8 +102,8 @@ def CombineConvertTruncOptPattern
101102
def createConstantOp
102103
: NativeCodeCall<"$_builder.create<mlir::arith::ConstantOp>"
103104
"($_loc, $_builder.getIndexType(), "
104-
"rewriter.getIndexAttr($1.dyn_cast<mlir::IntegerAttr>()"
105-
".getInt()))">;
105+
"rewriter.getIndexAttr("
106+
"mlir::dyn_cast<mlir::IntegerAttr>($1).getInt()))">;
106107

107108
def ForwardConstantConvertPattern
108109
: Pat<(fir_ConvertOp:$res (Arith_ConstantOp:$cnt $attr)),

flang/include/flang/Optimizer/Dialect/FIROps.td

+6-6
Original file line numberDiff line numberDiff line change
@@ -2708,14 +2708,14 @@ def fir_ConvertOp : fir_OneResultOp<"convert", [NoMemoryEffect]> {
27082708
let hasCanonicalizer = 1;
27092709
}
27102710

2711-
def FortranTypeAttr : Attr<And<[CPred<"$_self.isa<mlir::TypeAttr>()">,
2712-
Or<[CPred<"$_self.cast<mlir::TypeAttr>().getValue().isa<fir::CharacterType,"
2713-
"fir::ComplexType, fir::IntegerType, fir::LogicalType,"
2714-
"fir::RealType, fir::RecordType>()">]>]>,
2715-
"Fortran surface type"> {
2711+
def FortranTypeAttr : Attr<And<[CPred<"mlir::isa<mlir::TypeAttr>($_self)">,
2712+
Or<[CPred<"mlir::isa<fir::CharacterType, fir::ComplexType, "
2713+
"fir::IntegerType, fir::LogicalType, fir::RealType, "
2714+
"fir::RecordType>(mlir::cast<mlir::TypeAttr>($_self).getValue())"
2715+
>]>]>, "Fortran surface type"> {
27162716
let storageType = [{ ::mlir::TypeAttr }];
27172717
let returnType = "mlir::Type";
2718-
let convertFromStorage = "$_self.getValue().cast<mlir::Type>()";
2718+
let convertFromStorage = "mlir::cast<mlir::Type>($_self.getValue())";
27192719
}
27202720

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

0 commit comments

Comments
 (0)