Skip to content

Commit 0078cf7

Browse files
authored
[mlir] Remove deprecated cast member functions (#135556)
These have been deprecated for over two years now in favor of free functions. See the relevant discourse thread: https://discourse.llvm.org/t/preferred-casting-style-going-forward/68443 and the deprecation notice: https://mlir.llvm.org/deprecation/.
1 parent cbbf562 commit 0078cf7

File tree

28 files changed

+51
-244
lines changed

28 files changed

+51
-244
lines changed

mlir/docs/DeclarativeRewrites.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -704,8 +704,8 @@ For example, we can write
704704
def HasNoUseOf: Constraint<CPred<"$_self.use_empty()">, "has no use">;
705705
706706
def HasSameElementType : Constraint<
707-
CPred<"$0.cast<ShapedType>().getElementType() == "
708-
"$1.cast<ShapedType>().getElementType()">,
707+
CPred<"cast<ShapedType>($0).getElementType() == "
708+
"cast<ShapedType>($1).getElementType()">,
709709
"has same element type">;
710710
711711
def : Pattern<(TwoResultOp:$results $input),

mlir/docs/DefiningDialects/Operations.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -1397,7 +1397,7 @@ is used. They serve as "hooks" to the enclosing environment. This includes
13971397
information of the current operation.
13981398
* `$_self` will be replaced with the entity this predicate is attached to.
13991399
E.g., `BoolAttr` is an attribute constraint that wraps a
1400-
`CPred<"$_self.isa<BoolAttr>()">`. Then for `BoolAttr:$attr`,`$_self` will be
1400+
`CPred<"isa<BoolAttr>($_self)">`. Then for `BoolAttr:$attr`,`$_self` will be
14011401
replaced by `$attr`. For type constraints, it's a little bit special since
14021402
we want the constraints on each type definition reads naturally and we want
14031403
to attach type constraints directly to an operand/result, `$_self` will be
@@ -1409,8 +1409,8 @@ to allow referencing operand/result `$-name`s; such `$-name`s can start with
14091409
underscore.
14101410

14111411
For example, to write an attribute `attr` is an `IntegerAttr`, in C++ you can
1412-
just call `attr.isa<IntegerAttr>()`. The code can be wrapped in a `CPred` as
1413-
`$_self.isa<IntegerAttr>()`, with `$_self` as the special placeholder to be
1412+
just call `isa<IntegerAttr>(attr)`. The code can be wrapped in a `CPred` as
1413+
`isa<IntegerAttr>($_self)`, with `$_self` as the special placeholder to be
14141414
replaced by the current attribute `attr` at expansion time.
14151415

14161416
For more complicated predicates, you can wrap it in a single `CPred`, or you can
@@ -1419,10 +1419,10 @@ that an attribute `attr` is a 32-bit or 64-bit integer, you can write it as
14191419

14201420
```tablegen
14211421
And<[
1422-
CPred<"$_self.isa<IntegerAttr>()">,
1422+
CPred<"$isa<IntegerAttr>(_self)()">,
14231423
Or<[
1424-
CPred<"$_self.cast<IntegerAttr>().getType().isInteger(32)">,
1425-
CPred<"$_self.cast<IntegerAttr>().getType().isInteger(64)">
1424+
CPred<"cast<IntegerAttr>($_self).getType().isInteger(32)">,
1425+
CPred<"cast<IntegerAttr>($_self).getType().isInteger(64)">
14261426
]>
14271427
]>
14281428
```

mlir/docs/DefiningDialects/_index.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ extends to all of the MLIR constructs, including [Interfaces](../Interfaces.md)
4343

4444
```tablegen
4545
// Include the definition of the necessary tablegen constructs for defining
46-
// our dialect.
46+
// our dialect.
4747
include "mlir/IR/DialectBase.td"
4848
4949
// Here is a simple definition of a dialect.
@@ -649,7 +649,7 @@ Type MyDialect::parseType(DialectAsmParser &parser) const {
649649
return dynType;
650650
return Type();
651651
}
652-
652+
653653
...
654654
}
655655
```
@@ -669,7 +669,7 @@ It is also possible to cast a `Type` known to be defined at runtime to a
669669
`DynamicType`.
670670
671671
```c++
672-
auto dynType = type.cast<DynamicType>();
672+
auto dynType = cast<DynamicType>(type);
673673
auto typeDef = dynType.getTypeDef();
674674
auto args = dynType.getParams();
675675
```
@@ -679,7 +679,7 @@ auto args = dynType.getParams();
679679
Similar to types defined at runtime, attributes defined at runtime can only have
680680
as argument a list of `Attribute`.
681681

682-
Similarily to types, an attribute is defined at runtime using the class
682+
Similarly to types, an attribute is defined at runtime using the class
683683
`DynamicAttrDefinition`, which is created using the `DynamicAttrDefinition::get`
684684
functions. An attribute definition requires a name, the dialect that will
685685
register the attribute, and a parameter verifier. It can also define optionally
@@ -767,7 +767,7 @@ It is also possible to cast an `Attribute` known to be defined at runtime to a
767767
`DynamicAttr`.
768768

769769
```c++
770-
auto dynAttr = attr.cast<DynamicAttr>();
770+
auto dynAttr = cast<DynamicAttr>(attr);
771771
auto attrDef = dynAttr.getAttrDef();
772772
auto args = dynAttr.getParams();
773773
```

mlir/docs/Diagnostics.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ shown below:
293293
// function should not recurse into the child location. Recursion into nested
294294
// location is performed as necessary by the caller.
295295
auto shouldShowFn = [](Location loc) -> bool {
296-
FileLineColLoc fileLoc = loc.dyn_cast<FileLineColLoc>();
296+
FileLineColLoc fileLoc = dyn_cast<FileLineColLoc>(loc);
297297
298298
// We don't perform any filtering on non-file locations.
299299
// Reminder: The caller will recurse into any necessary child locations.

mlir/docs/Interfaces.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ struct ExampleTypeInterfaceTraits {
256256
struct ExternalModel : public FallbackModel<ConcreteModel> {
257257
unsigned exampleInterfaceHook(Type type) const override {
258258
// Default implementation can be provided here.
259-
return type.cast<ConcreteType>().callSomeTypeSpecificMethod();
259+
return cast<ConcreteType>(type).callSomeTypeSpecificMethod();
260260
}
261261
};
262262
};

mlir/docs/PDLL.md

+10-10
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,8 @@ def HasNoUseOf: Constraint<CPred<"$_self.use_empty()">, "has no use">;
139139
140140
// Check if two values have a ShapedType with the same element type.
141141
def HasSameElementType : Constraint<
142-
CPred<"$0.getType().cast<ShapedType>().getElementType() == "
143-
"$1.getType().cast<ShapedType>().getElementType()">,
142+
CPred<"cast<ShapedType>($0.getType()).getElementType() == "
143+
"cast<ShapedType>($1.getType()).getElementType()">,
144144
"values have same element type">;
145145
146146
def : Pattern<(TwoResultOp:$results $input),
@@ -161,8 +161,8 @@ Constraint HasNoUseOf(value: Value) [{
161161
return success(value.use_empty());
162162
}];
163163
Constraint HasSameElementType(value1: Value, value2: Value) [{
164-
return success(value1.getType().cast<ShapedType>().getElementType() ==
165-
value2.getType().cast<ShapedType>().getElementType());
164+
return success(cast<ShapedType>(value1.getType()).getElementType() ==
165+
cast<ShapedType>(value2.getType()).getElementType());
166166
}];
167167
168168
Pattern {
@@ -1105,8 +1105,8 @@ static LogicalResult hasOneUseImpl(PatternRewriter &rewriter, Value value) {
11051105
}
11061106
static LogicalResult hasSameElementTypeImpl(PatternRewriter &rewriter,
11071107
Value value1, Value Value2) {
1108-
return success(value1.getType().cast<ShapedType>().getElementType() ==
1109-
value2.getType().cast<ShapedType>().getElementType());
1108+
return success(cast<ShapedType>(value1.getType()).getElementType() ==
1109+
cast<ShapedType>(value2.getType()).getElementType());
11101110
}
11111111

11121112
void registerNativeConstraints(RewritePatternSet &patterns) {
@@ -1129,8 +1129,8 @@ Constraint HasOneUse(value: Value) [{
11291129
return success(value.hasOneUse());
11301130
}];
11311131
Constraint HasSameElementType(value1: Value, value2: Value) [{
1132-
return success(value1.getType().cast<ShapedType>().getElementType() ==
1133-
value2.getType().cast<ShapedType>().getElementType());
1132+
return success(cast<ShapedType>(value1.getType()).getElementType() ==
1133+
cast<ShapedType>(value2.getType()).getElementType());
11341134
}];
11351135
11361136
Pattern {
@@ -1160,8 +1160,8 @@ LogicalResult HasOneUse(PatternRewriter &rewriter, Value value) {
11601160
return success(value.hasOneUse());
11611161
}
11621162
LogicalResult HasSameElementType(Value value1, Value value2) {
1163-
return success(value1.getType().cast<ShapedType>().getElementType() ==
1164-
value2.getType().cast<ShapedType>().getElementType());
1163+
return success(cast<ShapedType>(value1.getType()).getElementType() ==
1164+
cast<ShapedType>(value2.getType()).getElementType());
11651165
}
11661166
```
11671167

mlir/docs/Tutorials/QuickstartRewrites.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ static Value createTFLLeakyRelu(PatternRewriter &rewriter, Operation *op,
132132
Value operand, Attribute attr) {
133133
return rewriter.create<mlir::TFL::LeakyReluOp>(
134134
op->getLoc(), operands[0].getType(), /*arg=*/operands[0],
135-
/*alpha=*/attrs[0].cast<FloatAttr>());
135+
/*alpha=*/cast<FloatAttr>(attrs[0]));
136136
}
137137
```
138138

mlir/docs/Tutorials/Toy/Ch-5.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,7 @@ void ToyToAffineLoweringPass::runOnOperation() {
7575
// only treat it as `legal` if its operands are legal.
7676
target.addIllegalDialect<ToyDialect>();
7777
target.addDynamicallyLegalOp<toy::PrintOp>([](toy::PrintOp op) {
78-
return llvm::none_of(op->getOperandTypes(),
79-
[](Type type) { return type.isa<TensorType>(); });
78+
return llvm::none_of(op->getOperandTypes(), llvm::IsaPred<TensorType>);
8079
});
8180
...
8281
}

mlir/docs/Tutorials/Toy/Ch-7.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ within the Dialect. A simple example is shown below:
203203
// using StructType in a similar way to Tensor or MemRef. We use `DialectType`
204204
// to demarcate the StructType as belonging to the Toy dialect.
205205
def Toy_StructType :
206-
DialectType<Toy_Dialect, CPred<"$_self.isa<StructType>()">,
206+
DialectType<Toy_Dialect, CPred<"isa<StructType>($_self)">,
207207
"Toy struct type">;
208208
209209
// Provide a definition of the types that are used within the Toy dialect.
@@ -274,7 +274,7 @@ mlir::Type ToyDialect::parseType(mlir::DialectAsmParser &parser) const {
274274
return nullptr;
275275
276276
// Check that the type is either a TensorType or another StructType.
277-
if (!elementType.isa<mlir::TensorType, StructType>()) {
277+
if (!isa<mlir::TensorType, StructType>(elementType)) {
278278
parser.emitError(typeLoc, "element type for a struct must either "
279279
"be a TensorType or a StructType, got: ")
280280
<< elementType;
@@ -467,7 +467,7 @@ OpFoldResult StructConstantOp::fold(FoldAdaptor adaptor) {
467467

468468
/// Fold simple struct access operations that access into a constant.
469469
OpFoldResult StructAccessOp::fold(FoldAdaptor adaptor) {
470-
auto structAttr = adaptor.getInput().dyn_cast_or_null<mlir::ArrayAttr>();
470+
auto structAttr = dyn_cast_or_null<mlir::ArrayAttr>(adaptor.getInput());
471471
if (!structAttr)
472472
return nullptr;
473473

@@ -487,11 +487,11 @@ mlir::Operation *ToyDialect::materializeConstant(mlir::OpBuilder &builder,
487487
mlir::Attribute value,
488488
mlir::Type type,
489489
mlir::Location loc) {
490-
if (type.isa<StructType>())
490+
if (isa<StructType>(type))
491491
return builder.create<StructConstantOp>(loc, type,
492-
value.cast<mlir::ArrayAttr>());
492+
cast<mlir::ArrayAttr>(value));
493493
return builder.create<ConstantOp>(loc, type,
494-
value.cast<mlir::DenseElementsAttr>());
494+
cast<mlir::DenseElementsAttr>(value));
495495
}
496496
```
497497

mlir/docs/Tutorials/UnderstandingTheIRStructure.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ some information about them:
236236
} else {
237237
// If there is no defining op, the Value is necessarily a Block
238238
// argument.
239-
auto blockArg = operand.cast<BlockArgument>();
239+
auto blockArg = cast<BlockArgument>(operand);
240240
llvm::outs() << " - Operand produced by Block argument, number "
241241
<< blockArg.getArgNumber() << "\n";
242242
}

mlir/docs/Tutorials/transform/Ch4.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ mlir::transform::HasOperandSatisfyingOp::apply(
355355
transform::detail::prepareValueMappings(
356356
yieldedMappings, getBody().front().getTerminator()->getOperands(),
357357
state);
358-
results.setParams(getPosition().cast<OpResult>(),
358+
results.setParams(cast<OpResult>(getPosition()),
359359
{rewriter.getI32IntegerAttr(operand.getOperandNumber())});
360360
for (auto &&[result, mapping] : llvm::zip(getResults(), yieldedMappings))
361361
results.setMappedValues(result, mapping);

mlir/examples/transform-opt/mlir-transform-opt.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -136,15 +136,15 @@ class DiagnosticHandlerWrapper {
136136
/// Verifies the captured "expected-*" diagnostics if required.
137137
llvm::LogicalResult verify() const {
138138
if (auto *ptr =
139-
handler.dyn_cast<mlir::SourceMgrDiagnosticVerifierHandler *>()) {
139+
dyn_cast<mlir::SourceMgrDiagnosticVerifierHandler *>(handler)) {
140140
return ptr->verify();
141141
}
142142
return mlir::success();
143143
}
144144

145145
/// Destructs the object of the same type as allocated.
146146
~DiagnosticHandlerWrapper() {
147-
if (auto *ptr = handler.dyn_cast<mlir::SourceMgrDiagnosticHandler *>()) {
147+
if (auto *ptr = dyn_cast<mlir::SourceMgrDiagnosticHandler *>(handler)) {
148148
delete ptr;
149149
} else {
150150
delete cast<mlir::SourceMgrDiagnosticVerifierHandler *>(handler);

mlir/include/mlir/IR/AffineExpr.h

-37
Original file line numberDiff line numberDiff line change
@@ -81,19 +81,6 @@ class AffineExpr {
8181

8282
bool operator!() const { return expr == nullptr; }
8383

84-
template <typename U>
85-
[[deprecated("Use llvm::isa<U>() instead")]] constexpr bool isa() const;
86-
87-
template <typename U>
88-
[[deprecated("Use llvm::dyn_cast<U>() instead")]] U dyn_cast() const;
89-
90-
template <typename U>
91-
[[deprecated("Use llvm::dyn_cast_or_null<U>() instead")]] U
92-
dyn_cast_or_null() const;
93-
94-
template <typename U>
95-
[[deprecated("Use llvm::cast<U>() instead")]] U cast() const;
96-
9784
MLIRContext *getContext() const;
9885

9986
/// Return the classification for this type.
@@ -288,30 +275,6 @@ AffineExpr getAffineExprFromFlatForm(ArrayRef<int64_t> flatExprs,
288275

289276
raw_ostream &operator<<(raw_ostream &os, AffineExpr expr);
290277

291-
template <typename U>
292-
constexpr bool AffineExpr::isa() const {
293-
if constexpr (std::is_same_v<U, AffineBinaryOpExpr>)
294-
return getKind() <= AffineExprKind::LAST_AFFINE_BINARY_OP;
295-
if constexpr (std::is_same_v<U, AffineDimExpr>)
296-
return getKind() == AffineExprKind::DimId;
297-
if constexpr (std::is_same_v<U, AffineSymbolExpr>)
298-
return getKind() == AffineExprKind::SymbolId;
299-
if constexpr (std::is_same_v<U, AffineConstantExpr>)
300-
return getKind() == AffineExprKind::Constant;
301-
}
302-
template <typename U>
303-
U AffineExpr::dyn_cast() const {
304-
return llvm::dyn_cast<U>(*this);
305-
}
306-
template <typename U>
307-
U AffineExpr::dyn_cast_or_null() const {
308-
return llvm::dyn_cast_or_null<U>(*this);
309-
}
310-
template <typename U>
311-
U AffineExpr::cast() const {
312-
return llvm::cast<U>(*this);
313-
}
314-
315278
/// Simplify an affine expression by flattening and some amount of simple
316279
/// analysis. This has complexity linear in the number of nodes in 'expr'.
317280
/// Returns the simplified expression, which is the same as the input expression

mlir/include/mlir/IR/Attributes.h

-43
Original file line numberDiff line numberDiff line change
@@ -47,24 +47,6 @@ class Attribute {
4747

4848
bool operator!() const { return impl == nullptr; }
4949

50-
/// Casting utility functions. These are deprecated and will be removed,
51-
/// please prefer using the `llvm` namespace variants instead.
52-
template <typename... Tys>
53-
[[deprecated("Use mlir::isa<U>() instead")]]
54-
bool isa() const;
55-
template <typename... Tys>
56-
[[deprecated("Use mlir::isa_and_nonnull<U>() instead")]]
57-
bool isa_and_nonnull() const;
58-
template <typename U>
59-
[[deprecated("Use mlir::dyn_cast<U>() instead")]]
60-
U dyn_cast() const;
61-
template <typename U>
62-
[[deprecated("Use mlir::dyn_cast_or_null<U>() instead")]]
63-
U dyn_cast_or_null() const;
64-
template <typename U>
65-
[[deprecated("Use mlir::cast<U>() instead")]]
66-
U cast() const;
67-
6850
/// Return a unique identifier for the concrete attribute type. This is used
6951
/// to support dynamic type casting.
7052
TypeID getTypeID() { return impl->getAbstractAttribute().getTypeID(); }
@@ -170,31 +152,6 @@ inline raw_ostream &operator<<(raw_ostream &os, Attribute attr) {
170152
return os;
171153
}
172154

173-
template <typename... Tys>
174-
bool Attribute::isa() const {
175-
return llvm::isa<Tys...>(*this);
176-
}
177-
178-
template <typename... Tys>
179-
bool Attribute::isa_and_nonnull() const {
180-
return llvm::isa_and_present<Tys...>(*this);
181-
}
182-
183-
template <typename U>
184-
U Attribute::dyn_cast() const {
185-
return llvm::dyn_cast<U>(*this);
186-
}
187-
188-
template <typename U>
189-
U Attribute::dyn_cast_or_null() const {
190-
return llvm::dyn_cast_if_present<U>(*this);
191-
}
192-
193-
template <typename U>
194-
U Attribute::cast() const {
195-
return llvm::cast<U>(*this);
196-
}
197-
198155
inline ::llvm::hash_code hash_value(Attribute arg) {
199156
return DenseMapInfo<const Attribute::ImplType *>::getHashValue(arg.impl);
200157
}

mlir/include/mlir/IR/ExtensibleDialect.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ class IsDynamicAttr : public TraitBase<ConcreteType, IsDynamicAttr> {};
149149
/// A dynamic attribute instance. This is an attribute whose definition is
150150
/// defined at runtime.
151151
/// It is possible to check if an attribute is a dynamic attribute using
152-
/// `my_attr.isa<DynamicAttr>()`, and getting the attribute definition of a
152+
/// `isa<DynamicAttr>(myAttr)`, and getting the attribute definition of a
153153
/// dynamic attribute using the `DynamicAttr::getAttrDef` method.
154154
/// All dynamic attributes have the same storage, which is an array of
155155
/// attributes.
@@ -306,7 +306,7 @@ class IsDynamicType : public TypeTrait::TraitBase<ConcreteType, IsDynamicType> {
306306
/// A dynamic type instance. This is a type whose definition is defined at
307307
/// runtime.
308308
/// It is possible to check if a type is a dynamic type using
309-
/// `my_type.isa<DynamicType>()`, and getting the type definition of a dynamic
309+
/// `isa<DynamicType>(myType)`, and getting the type definition of a dynamic
310310
/// type using the `DynamicType::getTypeDef` method.
311311
/// All dynamic types have the same storage, which is an array of attributes.
312312
class DynamicType

0 commit comments

Comments
 (0)