[llvm] 306ece0 - [llvm][NFC] Simplify alignment calculations in `TrailingObjects` (#161134)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 29 00:45:59 PDT 2025
Author: Victor Chernyakin
Date: 2025-09-29T00:45:55-07:00
New Revision: 306ece0aca25dd6a2109cbd28f1d37b9a0536d94
URL: https://github.com/llvm/llvm-project/commit/306ece0aca25dd6a2109cbd28f1d37b9a0536d94
DIFF: https://github.com/llvm/llvm-project/commit/306ece0aca25dd6a2109cbd28f1d37b9a0536d94.diff
LOG: [llvm][NFC] Simplify alignment calculations in `TrailingObjects` (#161134)
Added:
Modified:
llvm/include/llvm/Support/TrailingObjects.h
Removed:
################################################################################
diff --git a/llvm/include/llvm/Support/TrailingObjects.h b/llvm/include/llvm/Support/TrailingObjects.h
index d7211a930ae49..3eb7c0bd1f379 100644
--- a/llvm/include/llvm/Support/TrailingObjects.h
+++ b/llvm/include/llvm/Support/TrailingObjects.h
@@ -57,25 +57,9 @@
namespace llvm {
namespace trailing_objects_internal {
-/// Helper template to calculate the max alignment requirement for a set of
-/// objects.
-template <typename First, typename... Rest> class AlignmentCalcHelper {
-private:
- enum {
- FirstAlignment = alignof(First),
- RestAlignment = AlignmentCalcHelper<Rest...>::Alignment,
- };
-public:
- enum {
- Alignment = FirstAlignment > RestAlignment ? FirstAlignment : RestAlignment
- };
-};
-
-template <typename First> class AlignmentCalcHelper<First> {
-public:
- enum { Alignment = alignof(First) };
-};
+template <typename... T>
+inline constexpr size_t MaxAlignment = std::max({alignof(T)...});
/// The base class for TrailingObjects* classes.
class TrailingObjectsBase {
@@ -209,11 +193,10 @@ class alignas(Align) TrailingObjectsImpl<Align, BaseTy, TopTrailingObj, PrevTy>
/// See the file comment for details on the usage of the
/// TrailingObjects type.
template <typename BaseTy, typename... TrailingTys>
-class TrailingObjects : private trailing_objects_internal::TrailingObjectsImpl<
- trailing_objects_internal::AlignmentCalcHelper<
- TrailingTys...>::Alignment,
- BaseTy, TrailingObjects<BaseTy, TrailingTys...>,
- BaseTy, TrailingTys...> {
+class TrailingObjects
+ : private trailing_objects_internal::TrailingObjectsImpl<
+ trailing_objects_internal::MaxAlignment<TrailingTys...>, BaseTy,
+ TrailingObjects<BaseTy, TrailingTys...>, BaseTy, TrailingTys...> {
template <int A, typename B, typename T, typename P, typename... M>
friend class trailing_objects_internal::TrailingObjectsImpl;
@@ -221,8 +204,8 @@ class TrailingObjects : private trailing_objects_internal::TrailingObjectsImpl<
template <typename... Tys> class Foo {};
typedef trailing_objects_internal::TrailingObjectsImpl<
- trailing_objects_internal::AlignmentCalcHelper<TrailingTys...>::Alignment,
- BaseTy, TrailingObjects<BaseTy, TrailingTys...>, BaseTy, TrailingTys...>
+ trailing_objects_internal::MaxAlignment<TrailingTys...>, BaseTy,
+ TrailingObjects<BaseTy, TrailingTys...>, BaseTy, TrailingTys...>
ParentType;
using TrailingObjectsBase = trailing_objects_internal::TrailingObjectsBase;
More information about the llvm-commits
mailing list