This is an archive of the discontinued LLVM Phabricator instance.

Make llvm::AlignedCharArrayUnion a variadic template.
Needs ReviewPublic

Authored by ruiu on May 2 2016, 8:01 PM.

Details

Reviewers
rsmith
Summary

Instead of a template that supports up to 10 arguments.

Diff Detail

Event Timeline

ruiu updated this revision to Diff 55938.May 2 2016, 8:01 PM
ruiu retitled this revision from to Make llvm::AlignedCharArrayUnion a variadic template..
ruiu updated this object.
ruiu added a reviewer: rsmith.
ruiu added a subscriber: llvm-commits.

Looks good to me. Optional generalization of the metaprogramming if you like.

(actually, could even be generalized further by taking the test functor (max, min, etc) as another template parameter, I suppose)

include/llvm/Support/AlignOf.h
233–243

Could potentially generalize the two variadic impls to take the non-variadic as a trait, if you like?

template<template Trait<typename>, typename T, typename... Ts> struct Max {
  enum {
    X = Trait<T>::value,
    Y = Max<Trait, Ts...>::value,
    value = (X > Y) ? X : Y
  };
};
template<template Trait<typename>, typename T> struct Max<Trait, T> {
  enum { value = Trait<T>::value; };
};

template<typename T> struct SizeOf {
  enum { value = sizeof(T) };
};
template<typename T> struct AlignOf {
  enum { value = alignof(T) };
};
...
Max<SizeOf, Ts...>::value
Max<AlignOf, Ts...>::value
ruiu added a comment.May 2 2016, 8:48 PM

That's interesting, but I think I wouldn't generalize it that much since we only have two templates here. If we have more that would be useful though.

ruiu updated this revision to Diff 55940.May 2 2016, 9:44 PM
  • Make AlignOf to take more than one arguments since there is another place that does the same thing.
dblaikie added inline comments.May 2 2016, 10:15 PM
include/llvm/Support/AlignOf.h
61–65

What's the need for this separate helper rather than the usual variadic template recursion+base case below?

88

I'm not sure we want to generalize the fundamental traits like this over variadic arguments & at this point would be a little more in favor of separating the variadic/max behavior from the basic trait. I don't insist on it, but wouldn't mind a 3rd opinion as it were (but I don't insist on that either). Maybe it does make sense to just make lots of traits inherently variadic if there's a single logical composition? (max rather than min, or sum, or anything else)

ruiu added inline comments.May 2 2016, 10:18 PM
include/llvm/Support/AlignOf.h
61–65

This is to avoid defining Alignment_GreaterEqual_* for both classes.

88

That is understandable. If this seems too much, I'll roll it back the last change so that we are not going to change AlignOf.