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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 6 additions & 6 deletions
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

Lines changed: 5 additions & 5 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 10 additions & 10 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 2 deletions
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

Lines changed: 6 additions & 6 deletions
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

Lines changed: 1 addition & 1 deletion
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
}

0 commit comments

Comments
 (0)