Skip to content
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

Mark mlir::Value::isa/dyn_cast/cast/... member functions deprecated. #89238

Merged
merged 1 commit into from
Apr 22, 2024

Conversation

chsigg
Copy link
Contributor

@chsigg chsigg commented Apr 18, 2024

@llvmbot llvmbot added mlir:core MLIR Core Infrastructure mlir labels Apr 18, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Apr 18, 2024

@llvm/pr-subscribers-flang-fir-hlfir
@llvm/pr-subscribers-mlir-tosa
@llvm/pr-subscribers-mlir-bufferization
@llvm/pr-subscribers-llvm-adt
@llvm/pr-subscribers-mlir-linalg
@llvm/pr-subscribers-mlir

@llvm/pr-subscribers-mlir-core

Author: Christian Sigg (chsigg)

Changes

See https://mlir.llvm.org/deprecation


Full diff: https://github.com/llvm/llvm-project/pull/89238.diff

4 Files Affected:

  • (modified) mlir/include/mlir/IR/Attributes.h (+7-2)
  • (modified) mlir/include/mlir/IR/Location.h (+3)
  • (modified) mlir/include/mlir/IR/Types.h (+6-1)
  • (modified) mlir/include/mlir/IR/Value.h (+5-1)
diff --git a/mlir/include/mlir/IR/Attributes.h b/mlir/include/mlir/IR/Attributes.h
index cc0cee6a31183c..509a67f61c7a6a 100644
--- a/mlir/include/mlir/IR/Attributes.h
+++ b/mlir/include/mlir/IR/Attributes.h
@@ -50,14 +50,19 @@ class Attribute {
   /// Casting utility functions. These are deprecated and will be removed,
   /// please prefer using the `llvm` namespace variants instead.
   template <typename... Tys>
+  [[deprecated("Use isa<U>() instead")]]
   bool isa() const;
   template <typename... Tys>
+  [[deprecated("Use isa_and_nonnull<U>() instead")]]
   bool isa_and_nonnull() const;
   template <typename U>
+  [[deprecated("Use dyn_cast<U>() instead")]]
   U dyn_cast() const;
   template <typename U>
+  [[deprecated("Use dyn_cast_or_null<U>() instead")]]
   U dyn_cast_or_null() const;
   template <typename U>
+  [[deprecated("Use cast<U>() instead")]]
   U cast() const;
 
   /// Return a unique identifier for the concrete attribute type. This is used
@@ -172,7 +177,7 @@ bool Attribute::isa() const {
 
 template <typename... Tys>
 bool Attribute::isa_and_nonnull() const {
-  return llvm::isa_and_present<Tys...>(*this);
+  return llvm::isa_and_nonnull<Tys...>(*this);
 }
 
 template <typename U>
@@ -182,7 +187,7 @@ U Attribute::dyn_cast() const {
 
 template <typename U>
 U Attribute::dyn_cast_or_null() const {
-  return llvm::dyn_cast_if_present<U>(*this);
+  return llvm::dyn_cast_or_null<U>(*this);
 }
 
 template <typename U>
diff --git a/mlir/include/mlir/IR/Location.h b/mlir/include/mlir/IR/Location.h
index d4268e804f4f7a..b7afb160743825 100644
--- a/mlir/include/mlir/IR/Location.h
+++ b/mlir/include/mlir/IR/Location.h
@@ -78,14 +78,17 @@ class Location {
 
   /// Type casting utilities on the underlying location.
   template <typename U>
+  [[deprecated("Use isa<U>() instead")]]
   bool isa() const {
     return llvm::isa<U>(*this);
   }
   template <typename U>
+  [[deprecated("Use dyn_cast<U>() instead")]]
   U dyn_cast() const {
     return llvm::dyn_cast<U>(*this);
   }
   template <typename U>
+  [[deprecated("Use cast<U>() instead")]]
   U cast() const {
     return llvm::cast<U>(*this);
   }
diff --git a/mlir/include/mlir/IR/Types.h b/mlir/include/mlir/IR/Types.h
index a89e13b625bf40..69ef27018bc1b4 100644
--- a/mlir/include/mlir/IR/Types.h
+++ b/mlir/include/mlir/IR/Types.h
@@ -97,14 +97,19 @@ class Type {
   bool operator!() const { return impl == nullptr; }
 
   template <typename... Tys>
+  [[deprecated("Use isa<U>() instead")]]
   bool isa() const;
   template <typename... Tys>
+  [[deprecated("Use isa_and_nonnull<U>() instead")]]
   bool isa_and_nonnull() const;
   template <typename U>
+  [[deprecated("Use dyn_cast<U>() instead")]]
   U dyn_cast() const;
   template <typename U>
+  [[deprecated("Use dyn_cast_or_null<U>() instead")]]
   U dyn_cast_or_null() const;
   template <typename U>
+  [[deprecated("Use cast<U>() instead")]]
   U cast() const;
 
   /// Return a unique identifier for the concrete type. This is used to support
@@ -323,7 +328,7 @@ bool Type::isa() const {
 
 template <typename... Tys>
 bool Type::isa_and_nonnull() const {
-  return llvm::isa_and_present<Tys...>(*this);
+  return llvm::isa_and_nonnull<Tys...>(*this);
 }
 
 template <typename U>
diff --git a/mlir/include/mlir/IR/Value.h b/mlir/include/mlir/IR/Value.h
index a74d0faa1dfc4b..cdbc6cc374368c 100644
--- a/mlir/include/mlir/IR/Value.h
+++ b/mlir/include/mlir/IR/Value.h
@@ -98,21 +98,25 @@ class Value {
   constexpr Value(detail::ValueImpl *impl = nullptr) : impl(impl) {}
 
   template <typename U>
+  [[deprecated("Use isa<U>() instead")]]
   bool isa() const {
     return llvm::isa<U>(*this);
   }
 
   template <typename U>
+  [[deprecated("Use dyn_cast<U>() instead")]]
   U dyn_cast() const {
     return llvm::dyn_cast<U>(*this);
   }
 
   template <typename U>
+  [[deprecated("Use dyn_cast_or_null<U>() instead")]]
   U dyn_cast_or_null() const {
-    return llvm::dyn_cast_if_present<U>(*this);
+    return llvm::dyn_cast_or_null<U>(*this);
   }
 
   template <typename U>
+  [[deprecated("Use cast<U>() instead")]]
   U cast() const {
     return llvm::cast<U>(*this);
   }

Copy link
Collaborator

@joker-eph joker-eph left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Coincidentally I saw these yesterday and wanted to do the same patch! (but unlikely I would have got there anytime soon)

@chsigg chsigg changed the title Mark isa/dyn_cast/cast/... member functions deprecated. Mark mlir::Value::isa/dyn_cast/cast/... member functions deprecated. Apr 18, 2024
@chsigg
Copy link
Contributor Author

chsigg commented Apr 18, 2024

Unfortunately, I realized that the repo is not cleaned up at all yet. I limited this PR to just mlir::Value for now and I will follow up with the other types (Attribute/Location/Type).

Copy link

github-actions bot commented Apr 18, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

@llvmbot llvmbot added flang Flang issues not falling into any other category flang:fir-hlfir labels Apr 19, 2024
@tblah
Copy link
Contributor

tblah commented Apr 21, 2024

Flang changes LGTM. Thanks

@chsigg
Copy link
Contributor Author

chsigg commented Apr 22, 2024

The msvc build failure (fatal error C1060: compiler is out of heap space) seems unrelated.

@chsigg chsigg merged commit 57b2679 into llvm:main Apr 22, 2024
3 of 4 checks passed
@chsigg chsigg deleted the piper_export_cl_626023889 branch April 22, 2024 08:05
jtuyls added a commit to iree-org/iree that referenced this pull request Apr 25, 2024
Integrate with more recent llvm commit get in following change for
downstream iree-amd-aie project:
llvm/llvm-project@286bd42.

API breaking changes:
- Deprecate mlir::Value::isa/dyn_cast/cast/ member functions:
llvm/llvm-project#89238. See also:
https://discourse.llvm.org/t/preferred-casting-style-going-forward/68443

Additionally, the gcc CI build broke on a missing
`iree::compiler::Dialect::Stream::IR` dependency in the
Torch/InputConversion plugin. Therefore, I ran the dependencies check
and fixed all the ones that came up:
- `Torch/InputConversion` depends on `HAL::IR` and `Stream::IR`
- `Torch/torch-mlir` depends on `TorchDialectTransformsGen`,
`MLIRFuncTransforms`, `MLIRGPUDialect`, `MLIRLinalgTransforms` and
`MLIRVectorTransforms`
- `llvm-external-projects/CAPI` depends on `MLIRLinalgTransformOps`
jtuyls added a commit to nod-ai/iree-amd-aie that referenced this pull request Apr 26, 2024
Bump to latest IREE. 

Update for deprecated `mlir::Value::isa/dyn_cast/cast/` member
functions: llvm/llvm-project#89238. See also:
https://discourse.llvm.org/t/preferred-casting-style-going-forward/68443.

This brings in a standalone `forallToFor` transformation which will
avoid duplication in this repo:
llvm/llvm-project#89636
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang:fir-hlfir flang Flang issues not falling into any other category llvm:adt mlir:bufferization Bufferization infrastructure mlir:core MLIR Core Infrastructure mlir:linalg mlir:memref mlir:sparse Sparse compiler in MLIR mlir:tensor mlir:tosa mlir
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants