[Mlir-commits] [mlir] [mlir] Add `[[lifetimebound]]` to Range classes. (PR #123091)

Christian Sigg llvmlistbot at llvm.org
Mon Jan 20 01:10:33 PST 2025


https://github.com/chsigg updated https://github.com/llvm/llvm-project/pull/123091

>From 7f592e5fd03b797bc12bdace5e583fc8c90d8cd4 Mon Sep 17 00:00:00 2001
From: Christian Sigg <csigg at google.com>
Date: Wed, 15 Jan 2025 18:08:15 +0100
Subject: [PATCH 1/3] Add `[[lifetimebound]]` to Range classes.

---
 mlir/include/mlir/IR/BlockSupport.h | 8 ++++----
 mlir/include/mlir/IR/Region.h       | 4 ++--
 mlir/include/mlir/IR/TypeRange.h    | 5 +++--
 mlir/include/mlir/IR/ValueRange.h   | 8 +++++---
 4 files changed, 14 insertions(+), 11 deletions(-)

diff --git a/mlir/include/mlir/IR/BlockSupport.h b/mlir/include/mlir/IR/BlockSupport.h
index ff508891ac2ffc..b28ba9b03d0ebf 100644
--- a/mlir/include/mlir/IR/BlockSupport.h
+++ b/mlir/include/mlir/IR/BlockSupport.h
@@ -74,8 +74,8 @@ class SuccessorRange final
 public:
   using RangeBaseT::RangeBaseT;
   SuccessorRange();
-  SuccessorRange(Block *block);
-  SuccessorRange(Operation *term);
+  SuccessorRange(Block *block LLVM_LIFETIME_BOUND);
+  SuccessorRange(Operation *term LLVM_LIFETIME_BOUND);
 
 private:
   /// See `llvm::detail::indexed_accessor_range_base` for details.
@@ -110,9 +110,9 @@ class BlockRange final
   BlockRange(SuccessorRange successors);
   template <typename Arg, typename = std::enable_if_t<std::is_constructible<
                               ArrayRef<Block *>, Arg>::value>>
-  BlockRange(Arg &&arg)
+  BlockRange(Arg &&arg LLVM_LIFETIME_BOUND)
       : BlockRange(ArrayRef<Block *>(std::forward<Arg>(arg))) {}
-  BlockRange(std::initializer_list<Block *> blocks)
+  BlockRange(std::initializer_list<Block *> blocks LLVM_LIFETIME_BOUND)
       : BlockRange(ArrayRef<Block *>(blocks)) {}
 
 private:
diff --git a/mlir/include/mlir/IR/Region.h b/mlir/include/mlir/IR/Region.h
index 93fc9dbb430eec..22cb7037772ddb 100644
--- a/mlir/include/mlir/IR/Region.h
+++ b/mlir/include/mlir/IR/Region.h
@@ -357,12 +357,12 @@ class RegionRange
 
   template <typename Arg, typename = std::enable_if_t<std::is_constructible<
                               ArrayRef<std::unique_ptr<Region>>, Arg>::value>>
-  RegionRange(Arg &&arg)
+  RegionRange(Arg &&arg LLVM_LIFETIME_BOUND)
       : RegionRange(ArrayRef<std::unique_ptr<Region>>(std::forward<Arg>(arg))) {
   }
   template <typename Arg>
   RegionRange(
-      Arg &&arg,
+      Arg &&arg LLVM_LIFETIME_BOUND,
       std::enable_if_t<std::is_constructible<ArrayRef<Region *>, Arg>::value>
           * = nullptr)
       : RegionRange(ArrayRef<Region *>(std::forward<Arg>(arg))) {}
diff --git a/mlir/include/mlir/IR/TypeRange.h b/mlir/include/mlir/IR/TypeRange.h
index 99fabab334f922..9c2fbb3884188e 100644
--- a/mlir/include/mlir/IR/TypeRange.h
+++ b/mlir/include/mlir/IR/TypeRange.h
@@ -46,8 +46,9 @@ class TypeRange : public llvm::detail::indexed_accessor_range_base<
                                          values.end().getCurrent()))) {}
   template <typename Arg, typename = std::enable_if_t<std::is_constructible<
                               ArrayRef<Type>, Arg>::value>>
-  TypeRange(Arg &&arg) : TypeRange(ArrayRef<Type>(std::forward<Arg>(arg))) {}
-  TypeRange(std::initializer_list<Type> types)
+  TypeRange(Arg &&arg LLVM_LIFETIME_BOUND)
+      : TypeRange(ArrayRef<Type>(std::forward<Arg>(arg))) {}
+  TypeRange(std::initializer_list<Type> types LLVM_LIFETIME_BOUND)
       : TypeRange(ArrayRef<Type>(types)) {}
 
 private:
diff --git a/mlir/include/mlir/IR/ValueRange.h b/mlir/include/mlir/IR/ValueRange.h
index 4b421c08d8418e..a807b77ad077f8 100644
--- a/mlir/include/mlir/IR/ValueRange.h
+++ b/mlir/include/mlir/IR/ValueRange.h
@@ -391,9 +391,11 @@ class ValueRange final
             typename = std::enable_if_t<
                 std::is_constructible<ArrayRef<Value>, Arg>::value &&
                 !std::is_convertible<Arg, Value>::value>>
-  ValueRange(Arg &&arg) : ValueRange(ArrayRef<Value>(std::forward<Arg>(arg))) {}
-  ValueRange(const Value &value) : ValueRange(&value, /*count=*/1) {}
-  ValueRange(const std::initializer_list<Value> &values)
+  ValueRange(Arg &&arg LLVM_LIFETIME_BOUND)
+      : ValueRange(ArrayRef<Value>(std::forward<Arg>(arg))) {}
+  ValueRange(const Value &value LLVM_LIFETIME_BOUND)
+      : ValueRange(&value, /*count=*/1) {}
+  ValueRange(const std::initializer_list<Value> &values LLVM_LIFETIME_BOUND)
       : ValueRange(ArrayRef<Value>(values)) {}
   ValueRange(iterator_range<OperandRange::iterator> values)
       : ValueRange(OperandRange(values)) {}

>From 7acc288190c7544dd73256c5d125884e89b38fab Mon Sep 17 00:00:00 2001
From: Christian Sigg <csigg at google.com>
Date: Wed, 15 Jan 2025 18:45:11 +0100
Subject: [PATCH 2/3] Undo change for SuccessorRange

---
 mlir/include/mlir/IR/BlockSupport.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/mlir/include/mlir/IR/BlockSupport.h b/mlir/include/mlir/IR/BlockSupport.h
index b28ba9b03d0ebf..292938e46c27ed 100644
--- a/mlir/include/mlir/IR/BlockSupport.h
+++ b/mlir/include/mlir/IR/BlockSupport.h
@@ -74,8 +74,8 @@ class SuccessorRange final
 public:
   using RangeBaseT::RangeBaseT;
   SuccessorRange();
-  SuccessorRange(Block *block LLVM_LIFETIME_BOUND);
-  SuccessorRange(Operation *term LLVM_LIFETIME_BOUND);
+  SuccessorRange(Block *block);
+  SuccessorRange(Operation *term);
 
 private:
   /// See `llvm::detail::indexed_accessor_range_base` for details.

>From 64bb7334117b52f070ad4644423217e37d27e1f0 Mon Sep 17 00:00:00 2001
From: Christian Sigg <csigg at google.com>
Date: Mon, 20 Jan 2025 10:10:24 +0100
Subject: [PATCH 3/3] remove trailing whitespace

---
 mlir/include/mlir/IR/TypeRange.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mlir/include/mlir/IR/TypeRange.h b/mlir/include/mlir/IR/TypeRange.h
index 9ee97cfe42680e..9c2fbb3884188e 100644
--- a/mlir/include/mlir/IR/TypeRange.h
+++ b/mlir/include/mlir/IR/TypeRange.h
@@ -46,7 +46,7 @@ class TypeRange : public llvm::detail::indexed_accessor_range_base<
                                          values.end().getCurrent()))) {}
   template <typename Arg, typename = std::enable_if_t<std::is_constructible<
                               ArrayRef<Type>, Arg>::value>>
-  TypeRange(Arg &&arg LLVM_LIFETIME_BOUND) 
+  TypeRange(Arg &&arg LLVM_LIFETIME_BOUND)
       : TypeRange(ArrayRef<Type>(std::forward<Arg>(arg))) {}
   TypeRange(std::initializer_list<Type> types LLVM_LIFETIME_BOUND)
       : TypeRange(ArrayRef<Type>(types)) {}



More information about the Mlir-commits mailing list