[Mlir-commits] [llvm] [mlir] [mlir] Add Repeated<T> constructors for TypeRange and ValueRange (PR #186923)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Tue Mar 17 11:53:57 PDT 2026


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff origin/main HEAD --extensions cpp,h -- llvm/include/llvm/ADT/PointerUnion.h llvm/include/llvm/ADT/Repeated.h llvm/unittests/ADT/PointerUnionTest.cpp llvm/unittests/ADT/RepeatedTest.cpp mlir/include/mlir/IR/TypeRange.h mlir/include/mlir/IR/ValueRange.h mlir/include/mlir/Support/LLVM.h mlir/lib/Conversion/GPUCommon/GPUOpsLowering.cpp mlir/lib/Conversion/MathToSPIRV/MathToSPIRV.cpp mlir/lib/Conversion/TosaToSCF/TosaToSCF.cpp mlir/lib/Conversion/VectorToAMX/VectorToAMX.cpp mlir/lib/Dialect/Bufferization/Transforms/OwnershipBasedBufferDeallocation.cpp mlir/lib/Dialect/Vector/Transforms/VectorTransferOpTransforms.cpp mlir/lib/Dialect/Vector/Utils/VectorUtils.cpp mlir/lib/IR/OperationSupport.cpp mlir/lib/IR/TypeRange.cpp mlir/unittests/IR/OperationSupportTest.cpp --diff_from_common_commit
``````````

:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/llvm/include/llvm/ADT/PointerUnion.h b/llvm/include/llvm/ADT/PointerUnion.h
index e2f6dfa99..cc293fd8c 100644
--- a/llvm/include/llvm/ADT/PointerUnion.h
+++ b/llvm/include/llvm/ADT/PointerUnion.h
@@ -292,8 +292,7 @@ struct TagEntry {
 };
 
 /// True if types are in non-decreasing NumLowBitsAvailable order.
-template <typename... PTs>
-constexpr bool typesInAscendingBitOrder() {
+template <typename... PTs> constexpr bool typesInAscendingBitOrder() {
   if constexpr (sizeof...(PTs) <= 1)
     return true;
   else {
@@ -306,8 +305,7 @@ constexpr bool typesInAscendingBitOrder() {
 }
 
 /// True if the variable-length encoding has enough capacity for all types.
-template <typename... PTs>
-constexpr bool extendedTagsFit() {
+template <typename... PTs> constexpr bool extendedTagsFit() {
   if constexpr (sizeof...(PTs) == 0)
     return true;
   else {
@@ -374,8 +372,7 @@ constexpr std::array<TagEntry, sizeof...(PTs)> computeExtendedTags() {
 /// Do not use this class directly; use the VariablePointerUnion alias, which
 /// falls back to the faster PointerUnion when all types have sufficient
 /// alignment for a fixed-width tag.
-template <typename... PTs>
-class VariablePointerUnionImpl {
+template <typename... PTs> class VariablePointerUnionImpl {
   static_assert(TypesAreDistinct<PTs...>::value,
                 "VariablePointerUnion alternative types cannot be repeated");
   static_assert(typesInAscendingBitOrder<PTs...>(),
@@ -405,8 +402,7 @@ class VariablePointerUnionImpl {
     return ((v == TagTable[Is].value) || ...);
   }
 
-  template <typename T>
-  static intptr_t encode(T V) {
+  template <typename T> static intptr_t encode(T V) {
     constexpr size_t Idx = FirstIndexOfType<T, PTs...>::value;
     void *vp =
         const_cast<void *>(PointerLikeTypeTraits<T>::getAsVoidPointer(V));
@@ -475,9 +471,7 @@ public:
         reinterpret_cast<const First *>(Val.getPointerAddress()));
   }
 
-  void *getOpaqueValue() const {
-    return reinterpret_cast<void *>(Val.asInt());
-  }
+  void *getOpaqueValue() const { return reinterpret_cast<void *>(Val.asInt()); }
 
   static inline VariablePointerUnionImpl getFromOpaqueValue(void *VP) {
     VariablePointerUnionImpl V;
@@ -503,12 +497,10 @@ public:
 
 /// Helper to enforce ascending bit order even when the alias resolves to
 /// plain PointerUnion, ensuring cross-platform portability.
-template <typename... PTs>
-struct VariablePointerUnionChecker {
-  static_assert(
-      typesInAscendingBitOrder<PTs...>(),
-      "VariablePointerUnion types must be in ascending "
-      "NumLowBitsAvailable order for cross-platform portability");
+template <typename... PTs> struct VariablePointerUnionChecker {
+  static_assert(typesInAscendingBitOrder<PTs...>(),
+                "VariablePointerUnion types must be in ascending "
+                "NumLowBitsAvailable order for cross-platform portability");
   using type = std::conditional_t<
       (lowBitsAvailable<PTs...>() >= bitsRequired(sizeof...(PTs))),
       PointerUnion<PTs...>, VariablePointerUnionImpl<PTs...>>;
@@ -518,8 +510,7 @@ struct VariablePointerUnionChecker {
 
 // Specialization of CastInfo for VariablePointerUnionImpl
 template <typename To, typename... PTs>
-struct CastInfo<To,
-                pointer_union_detail::VariablePointerUnionImpl<PTs...>>
+struct CastInfo<To, pointer_union_detail::VariablePointerUnionImpl<PTs...>>
     : public DefaultDoCastIfPossible<
           To, pointer_union_detail::VariablePointerUnionImpl<PTs...>,
           CastInfo<To,
@@ -545,13 +536,12 @@ struct CastInfo<To,
 };
 
 template <typename To, typename... PTs>
-struct CastInfo<
-    To, const pointer_union_detail::VariablePointerUnionImpl<PTs...>>
+struct CastInfo<To,
+                const pointer_union_detail::VariablePointerUnionImpl<PTs...>>
     : public ConstStrippingForwardingCast<
-          To,
-          const pointer_union_detail::VariablePointerUnionImpl<PTs...>,
-          CastInfo<To, pointer_union_detail::VariablePointerUnionImpl<
-                           PTs...>>> {};
+          To, const pointer_union_detail::VariablePointerUnionImpl<PTs...>,
+          CastInfo<To,
+                   pointer_union_detail::VariablePointerUnionImpl<PTs...>>> {};
 
 template <typename... PTs>
 struct PointerLikeTypeTraits<
@@ -571,8 +561,7 @@ struct PointerLikeTypeTraits<
 };
 
 template <typename... PTs>
-struct DenseMapInfo<
-    pointer_union_detail::VariablePointerUnionImpl<PTs...>> {
+struct DenseMapInfo<pointer_union_detail::VariablePointerUnionImpl<PTs...>> {
   using Union = pointer_union_detail::VariablePointerUnionImpl<PTs...>;
   using FirstInfo = DenseMapInfo<TypeAtIndex<0, PTs...>>;
 
@@ -587,9 +576,7 @@ struct DenseMapInfo<
     return DenseMapInfo<intptr_t>::getHashValue(key);
   }
 
-  static bool isEqual(const Union &LHS, const Union &RHS) {
-    return LHS == RHS;
-  }
+  static bool isEqual(const Union &LHS, const Union &RHS) { return LHS == RHS; }
 };
 
 /// A pointer union that uses variable-length tag encoding to support more
diff --git a/llvm/unittests/ADT/PointerUnionTest.cpp b/llvm/unittests/ADT/PointerUnionTest.cpp
index a9972bca1..f6e8895b1 100644
--- a/llvm/unittests/ADT/PointerUnionTest.cpp
+++ b/llvm/unittests/ADT/PointerUnionTest.cpp
@@ -309,25 +309,25 @@ using VPU3 = VariablePointerUnion<Align4<0> *, Align4<1> *, Align4<2> *,
 // When all types have sufficient bits, alias resolves to PointerUnion.
 static_assert(std::is_same_v<VariablePointerUnion<Align8<0> *, Align8<1> *,
                                                   Align8<2> *, Align8<3> *>,
-                             PointerUnion<Align8<0> *, Align8<1> *,
-                                          Align8<2> *, Align8<3> *>>,
+                             PointerUnion<Align8<0> *, Align8<1> *, Align8<2> *,
+                                          Align8<3> *>>,
               "Same-alignment VPU should resolve to PointerUnion");
 
 // Boundary: 8 types with 3 bits each, needs exactly 3 bits -> PointerUnion.
 static_assert(
-    std::is_same_v<VariablePointerUnion<Align8<0> *, Align8<1> *, Align8<2> *,
-                                        Align8<3> *, Align8<4> *, Align8<5> *,
-                                        Align8<6> *, Align8<7> *>,
-                   PointerUnion<Align8<0> *, Align8<1> *, Align8<2> *,
-                                Align8<3> *, Align8<4> *, Align8<5> *,
-                                Align8<6> *, Align8<7> *>>,
+    std::is_same_v<
+        VariablePointerUnion<Align8<0> *, Align8<1> *, Align8<2> *, Align8<3> *,
+                             Align8<4> *, Align8<5> *, Align8<6> *,
+                             Align8<7> *>,
+        PointerUnion<Align8<0> *, Align8<1> *, Align8<2> *, Align8<3> *,
+                     Align8<4> *, Align8<5> *, Align8<6> *, Align8<7> *>>,
     "8-type same-alignment VPU should still be PointerUnion");
 
 // Mixed alignment should use the Impl.
-static_assert(!std::is_same_v<VPU2, PointerUnion<Align4<0> *, Align4<1> *,
-                                                  Align4<2> *, Align8<0> *,
-                                                  Align8<1> *>>,
-              "Mixed-alignment VPU should use VariablePointerUnionImpl");
+static_assert(
+    !std::is_same_v<VPU2, PointerUnion<Align4<0> *, Align4<1> *, Align4<2> *,
+                                       Align8<0> *, Align8<1> *>>,
+    "Mixed-alignment VPU should use VariablePointerUnionImpl");
 
 // NumLowBitsAvailable is 0 for VariablePointerUnionImpl.
 static_assert(PointerLikeTypeTraits<VPU2>::NumLowBitsAvailable == 0);
diff --git a/llvm/unittests/ADT/RepeatedTest.cpp b/llvm/unittests/ADT/RepeatedTest.cpp
index 673f67db7..f61ed8f49 100644
--- a/llvm/unittests/ADT/RepeatedTest.cpp
+++ b/llvm/unittests/ADT/RepeatedTest.cpp
@@ -101,7 +101,9 @@ TEST(RepeatedTest, Alignment) {
   // tag bits), but must also respect T's natural alignment when it exceeds 16.
   static_assert(alignof(Repeated<char>) == 16);
 
-  struct alignas(32) Over { int x; };
+  struct alignas(32) Over {
+    int x;
+  };
   static_assert(alignof(Repeated<Over>) == 32);
 
   SUCCEED();

``````````

</details>


https://github.com/llvm/llvm-project/pull/186923


More information about the Mlir-commits mailing list