-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[llvm][NFC] Simplify alignment calculations in TrailingObjects
#161134
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
Conversation
@llvm/pr-subscribers-llvm-support Author: Victor Chernyakin (localspook) ChangesFull diff: https://github.com/llvm/llvm-project/pull/161134.diff 1 Files Affected:
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;
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice! Thanks!
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/190/builds/28331 Here is the relevant piece of the build log for the reference
|
No description provided.