Skip to content

[mlir] Remove deprecated cast member functions #135556

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 2 commits into from
Apr 14, 2025
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
4 changes: 2 additions & 2 deletions mlir/docs/DeclarativeRewrites.md
Original file line number Diff line number Diff line change
Expand Up @@ -704,8 +704,8 @@ For example, we can write
def HasNoUseOf: Constraint<CPred<"$_self.use_empty()">, "has no use">;

def HasSameElementType : Constraint<
CPred<"$0.cast<ShapedType>().getElementType() == "
"$1.cast<ShapedType>().getElementType()">,
CPred<"cast<ShapedType>($0).getElementType() == "
"cast<ShapedType>($1).getElementType()">,
"has same element type">;

def : Pattern<(TwoResultOp:$results $input),
Expand Down
12 changes: 6 additions & 6 deletions mlir/docs/DefiningDialects/Operations.md
Original file line number Diff line number Diff line change
Expand Up @@ -1397,7 +1397,7 @@ is used. They serve as "hooks" to the enclosing environment. This includes
information of the current operation.
* `$_self` will be replaced with the entity this predicate is attached to.
E.g., `BoolAttr` is an attribute constraint that wraps a
`CPred<"$_self.isa<BoolAttr>()">`. Then for `BoolAttr:$attr`,`$_self` will be
`CPred<"isa<BoolAttr>($_self)">`. Then for `BoolAttr:$attr`,`$_self` will be
replaced by `$attr`. For type constraints, it's a little bit special since
we want the constraints on each type definition reads naturally and we want
to attach type constraints directly to an operand/result, `$_self` will be
Expand All @@ -1409,8 +1409,8 @@ to allow referencing operand/result `$-name`s; such `$-name`s can start with
underscore.

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

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

```tablegen
And<[
CPred<"$_self.isa<IntegerAttr>()">,
CPred<"$isa<IntegerAttr>(_self)()">,
Or<[
CPred<"$_self.cast<IntegerAttr>().getType().isInteger(32)">,
CPred<"$_self.cast<IntegerAttr>().getType().isInteger(64)">
CPred<"cast<IntegerAttr>($_self).getType().isInteger(32)">,
CPred<"cast<IntegerAttr>($_self).getType().isInteger(64)">
]>
]>
```
Expand Down
10 changes: 5 additions & 5 deletions mlir/docs/DefiningDialects/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ extends to all of the MLIR constructs, including [Interfaces](../Interfaces.md)

```tablegen
// Include the definition of the necessary tablegen constructs for defining
// our dialect.
// our dialect.
include "mlir/IR/DialectBase.td"

// Here is a simple definition of a dialect.
Expand Down Expand Up @@ -649,7 +649,7 @@ Type MyDialect::parseType(DialectAsmParser &parser) const {
return dynType;
return Type();
}

...
}
```
Expand All @@ -669,7 +669,7 @@ It is also possible to cast a `Type` known to be defined at runtime to a
`DynamicType`.

```c++
auto dynType = type.cast<DynamicType>();
auto dynType = cast<DynamicType>(type);
auto typeDef = dynType.getTypeDef();
auto args = dynType.getParams();
```
Expand All @@ -679,7 +679,7 @@ auto args = dynType.getParams();
Similar to types defined at runtime, attributes defined at runtime can only have
as argument a list of `Attribute`.

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

```c++
auto dynAttr = attr.cast<DynamicAttr>();
auto dynAttr = cast<DynamicAttr>(attr);
auto attrDef = dynAttr.getAttrDef();
auto args = dynAttr.getParams();
```
Expand Down
2 changes: 1 addition & 1 deletion mlir/docs/Diagnostics.md
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ shown below:
// function should not recurse into the child location. Recursion into nested
// location is performed as necessary by the caller.
auto shouldShowFn = [](Location loc) -> bool {
FileLineColLoc fileLoc = loc.dyn_cast<FileLineColLoc>();
FileLineColLoc fileLoc = dyn_cast<FileLineColLoc>(loc);

// We don't perform any filtering on non-file locations.
// Reminder: The caller will recurse into any necessary child locations.
Expand Down
2 changes: 1 addition & 1 deletion mlir/docs/Interfaces.md
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ struct ExampleTypeInterfaceTraits {
struct ExternalModel : public FallbackModel<ConcreteModel> {
unsigned exampleInterfaceHook(Type type) const override {
// Default implementation can be provided here.
return type.cast<ConcreteType>().callSomeTypeSpecificMethod();
return cast<ConcreteType>(type).callSomeTypeSpecificMethod();
}
};
};
Expand Down
20 changes: 10 additions & 10 deletions mlir/docs/PDLL.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ def HasNoUseOf: Constraint<CPred<"$_self.use_empty()">, "has no use">;

// Check if two values have a ShapedType with the same element type.
def HasSameElementType : Constraint<
CPred<"$0.getType().cast<ShapedType>().getElementType() == "
"$1.getType().cast<ShapedType>().getElementType()">,
CPred<"cast<ShapedType>($0.getType()).getElementType() == "
"cast<ShapedType>($1.getType()).getElementType()">,
"values have same element type">;

def : Pattern<(TwoResultOp:$results $input),
Expand All @@ -161,8 +161,8 @@ Constraint HasNoUseOf(value: Value) [{
return success(value.use_empty());
}];
Constraint HasSameElementType(value1: Value, value2: Value) [{
return success(value1.getType().cast<ShapedType>().getElementType() ==
value2.getType().cast<ShapedType>().getElementType());
return success(cast<ShapedType>(value1.getType()).getElementType() ==
cast<ShapedType>(value2.getType()).getElementType());
}];

Pattern {
Expand Down Expand Up @@ -1105,8 +1105,8 @@ static LogicalResult hasOneUseImpl(PatternRewriter &rewriter, Value value) {
}
static LogicalResult hasSameElementTypeImpl(PatternRewriter &rewriter,
Value value1, Value Value2) {
return success(value1.getType().cast<ShapedType>().getElementType() ==
value2.getType().cast<ShapedType>().getElementType());
return success(cast<ShapedType>(value1.getType()).getElementType() ==
cast<ShapedType>(value2.getType()).getElementType());
}

void registerNativeConstraints(RewritePatternSet &patterns) {
Expand All @@ -1129,8 +1129,8 @@ Constraint HasOneUse(value: Value) [{
return success(value.hasOneUse());
}];
Constraint HasSameElementType(value1: Value, value2: Value) [{
return success(value1.getType().cast<ShapedType>().getElementType() ==
value2.getType().cast<ShapedType>().getElementType());
return success(cast<ShapedType>(value1.getType()).getElementType() ==
cast<ShapedType>(value2.getType()).getElementType());
}];

Pattern {
Expand Down Expand Up @@ -1160,8 +1160,8 @@ LogicalResult HasOneUse(PatternRewriter &rewriter, Value value) {
return success(value.hasOneUse());
}
LogicalResult HasSameElementType(Value value1, Value value2) {
return success(value1.getType().cast<ShapedType>().getElementType() ==
value2.getType().cast<ShapedType>().getElementType());
return success(cast<ShapedType>(value1.getType()).getElementType() ==
cast<ShapedType>(value2.getType()).getElementType());
}
```

Expand Down
2 changes: 1 addition & 1 deletion mlir/docs/Tutorials/QuickstartRewrites.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ static Value createTFLLeakyRelu(PatternRewriter &rewriter, Operation *op,
Value operand, Attribute attr) {
return rewriter.create<mlir::TFL::LeakyReluOp>(
op->getLoc(), operands[0].getType(), /*arg=*/operands[0],
/*alpha=*/attrs[0].cast<FloatAttr>());
/*alpha=*/cast<FloatAttr>(attrs[0]));
}
```

Expand Down
3 changes: 1 addition & 2 deletions mlir/docs/Tutorials/Toy/Ch-5.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ void ToyToAffineLoweringPass::runOnOperation() {
// only treat it as `legal` if its operands are legal.
target.addIllegalDialect<ToyDialect>();
target.addDynamicallyLegalOp<toy::PrintOp>([](toy::PrintOp op) {
return llvm::none_of(op->getOperandTypes(),
[](Type type) { return type.isa<TensorType>(); });
return llvm::none_of(op->getOperandTypes(), llvm::IsaPred<TensorType>);
});
...
}
Expand Down
12 changes: 6 additions & 6 deletions mlir/docs/Tutorials/Toy/Ch-7.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ within the Dialect. A simple example is shown below:
// using StructType in a similar way to Tensor or MemRef. We use `DialectType`
// to demarcate the StructType as belonging to the Toy dialect.
def Toy_StructType :
DialectType<Toy_Dialect, CPred<"$_self.isa<StructType>()">,
DialectType<Toy_Dialect, CPred<"isa<StructType>($_self)">,
"Toy struct type">;

// Provide a definition of the types that are used within the Toy dialect.
Expand Down Expand Up @@ -274,7 +274,7 @@ mlir::Type ToyDialect::parseType(mlir::DialectAsmParser &parser) const {
return nullptr;

// Check that the type is either a TensorType or another StructType.
if (!elementType.isa<mlir::TensorType, StructType>()) {
if (!isa<mlir::TensorType, StructType>(elementType)) {
parser.emitError(typeLoc, "element type for a struct must either "
"be a TensorType or a StructType, got: ")
<< elementType;
Expand Down Expand Up @@ -467,7 +467,7 @@ OpFoldResult StructConstantOp::fold(FoldAdaptor adaptor) {

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

Expand All @@ -487,11 +487,11 @@ mlir::Operation *ToyDialect::materializeConstant(mlir::OpBuilder &builder,
mlir::Attribute value,
mlir::Type type,
mlir::Location loc) {
if (type.isa<StructType>())
if (isa<StructType>(type))
return builder.create<StructConstantOp>(loc, type,
value.cast<mlir::ArrayAttr>());
cast<mlir::ArrayAttr>(value));
return builder.create<ConstantOp>(loc, type,
value.cast<mlir::DenseElementsAttr>());
cast<mlir::DenseElementsAttr>(value));
}
```

Expand Down
2 changes: 1 addition & 1 deletion mlir/docs/Tutorials/UnderstandingTheIRStructure.md
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ some information about them:
} else {
// If there is no defining op, the Value is necessarily a Block
// argument.
auto blockArg = operand.cast<BlockArgument>();
auto blockArg = cast<BlockArgument>(operand);
llvm::outs() << " - Operand produced by Block argument, number "
<< blockArg.getArgNumber() << "\n";
}
Expand Down
2 changes: 1 addition & 1 deletion mlir/docs/Tutorials/transform/Ch4.md
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ mlir::transform::HasOperandSatisfyingOp::apply(
transform::detail::prepareValueMappings(
yieldedMappings, getBody().front().getTerminator()->getOperands(),
state);
results.setParams(getPosition().cast<OpResult>(),
results.setParams(cast<OpResult>(getPosition()),
{rewriter.getI32IntegerAttr(operand.getOperandNumber())});
for (auto &&[result, mapping] : llvm::zip(getResults(), yieldedMappings))
results.setMappedValues(result, mapping);
Expand Down
4 changes: 2 additions & 2 deletions mlir/examples/transform-opt/mlir-transform-opt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,15 +136,15 @@ class DiagnosticHandlerWrapper {
/// Verifies the captured "expected-*" diagnostics if required.
llvm::LogicalResult verify() const {
if (auto *ptr =
handler.dyn_cast<mlir::SourceMgrDiagnosticVerifierHandler *>()) {
dyn_cast<mlir::SourceMgrDiagnosticVerifierHandler *>(handler)) {
return ptr->verify();
}
return mlir::success();
}

/// Destructs the object of the same type as allocated.
~DiagnosticHandlerWrapper() {
if (auto *ptr = handler.dyn_cast<mlir::SourceMgrDiagnosticHandler *>()) {
if (auto *ptr = dyn_cast<mlir::SourceMgrDiagnosticHandler *>(handler)) {
delete ptr;
} else {
delete cast<mlir::SourceMgrDiagnosticVerifierHandler *>(handler);
Expand Down
37 changes: 0 additions & 37 deletions mlir/include/mlir/IR/AffineExpr.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,19 +81,6 @@ class AffineExpr {

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

template <typename U>
[[deprecated("Use llvm::isa<U>() instead")]] constexpr bool isa() const;

template <typename U>
[[deprecated("Use llvm::dyn_cast<U>() instead")]] U dyn_cast() const;

template <typename U>
[[deprecated("Use llvm::dyn_cast_or_null<U>() instead")]] U
dyn_cast_or_null() const;

template <typename U>
[[deprecated("Use llvm::cast<U>() instead")]] U cast() const;

MLIRContext *getContext() const;

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

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

template <typename U>
constexpr bool AffineExpr::isa() const {
if constexpr (std::is_same_v<U, AffineBinaryOpExpr>)
return getKind() <= AffineExprKind::LAST_AFFINE_BINARY_OP;
if constexpr (std::is_same_v<U, AffineDimExpr>)
return getKind() == AffineExprKind::DimId;
if constexpr (std::is_same_v<U, AffineSymbolExpr>)
return getKind() == AffineExprKind::SymbolId;
if constexpr (std::is_same_v<U, AffineConstantExpr>)
return getKind() == AffineExprKind::Constant;
}
template <typename U>
U AffineExpr::dyn_cast() const {
return llvm::dyn_cast<U>(*this);
}
template <typename U>
U AffineExpr::dyn_cast_or_null() const {
return llvm::dyn_cast_or_null<U>(*this);
}
template <typename U>
U AffineExpr::cast() const {
return llvm::cast<U>(*this);
}

/// Simplify an affine expression by flattening and some amount of simple
/// analysis. This has complexity linear in the number of nodes in 'expr'.
/// Returns the simplified expression, which is the same as the input expression
Expand Down
43 changes: 0 additions & 43 deletions mlir/include/mlir/IR/Attributes.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,24 +47,6 @@ class Attribute {

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

/// Casting utility functions. These are deprecated and will be removed,
/// please prefer using the `llvm` namespace variants instead.
template <typename... Tys>
[[deprecated("Use mlir::isa<U>() instead")]]
bool isa() const;
template <typename... Tys>
[[deprecated("Use mlir::isa_and_nonnull<U>() instead")]]
bool isa_and_nonnull() const;
template <typename U>
[[deprecated("Use mlir::dyn_cast<U>() instead")]]
U dyn_cast() const;
template <typename U>
[[deprecated("Use mlir::dyn_cast_or_null<U>() instead")]]
U dyn_cast_or_null() const;
template <typename U>
[[deprecated("Use mlir::cast<U>() instead")]]
U cast() const;

/// Return a unique identifier for the concrete attribute type. This is used
/// to support dynamic type casting.
TypeID getTypeID() { return impl->getAbstractAttribute().getTypeID(); }
Expand Down Expand Up @@ -170,31 +152,6 @@ inline raw_ostream &operator<<(raw_ostream &os, Attribute attr) {
return os;
}

template <typename... Tys>
bool Attribute::isa() const {
return llvm::isa<Tys...>(*this);
}

template <typename... Tys>
bool Attribute::isa_and_nonnull() const {
return llvm::isa_and_present<Tys...>(*this);
}

template <typename U>
U Attribute::dyn_cast() const {
return llvm::dyn_cast<U>(*this);
}

template <typename U>
U Attribute::dyn_cast_or_null() const {
return llvm::dyn_cast_if_present<U>(*this);
}

template <typename U>
U Attribute::cast() const {
return llvm::cast<U>(*this);
}

inline ::llvm::hash_code hash_value(Attribute arg) {
return DenseMapInfo<const Attribute::ImplType *>::getHashValue(arg.impl);
}
Expand Down
4 changes: 2 additions & 2 deletions mlir/include/mlir/IR/ExtensibleDialect.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ class IsDynamicAttr : public TraitBase<ConcreteType, IsDynamicAttr> {};
/// A dynamic attribute instance. This is an attribute whose definition is
/// defined at runtime.
/// It is possible to check if an attribute is a dynamic attribute using
/// `my_attr.isa<DynamicAttr>()`, and getting the attribute definition of a
/// `isa<DynamicAttr>(myAttr)`, and getting the attribute definition of a
/// dynamic attribute using the `DynamicAttr::getAttrDef` method.
/// All dynamic attributes have the same storage, which is an array of
/// attributes.
Expand Down Expand Up @@ -306,7 +306,7 @@ class IsDynamicType : public TypeTrait::TraitBase<ConcreteType, IsDynamicType> {
/// A dynamic type instance. This is a type whose definition is defined at
/// runtime.
/// It is possible to check if a type is a dynamic type using
/// `my_type.isa<DynamicType>()`, and getting the type definition of a dynamic
/// `isa<DynamicType>(myType)`, and getting the type definition of a dynamic
/// type using the `DynamicType::getTypeDef` method.
/// All dynamic types have the same storage, which is an array of attributes.
class DynamicType
Expand Down
Loading