diff --git a/mlir/include/mlir/ExecutionEngine/CRunnerUtils.h b/mlir/include/mlir/ExecutionEngine/CRunnerUtils.h --- a/mlir/include/mlir/ExecutionEngine/CRunnerUtils.h +++ b/mlir/include/mlir/ExecutionEngine/CRunnerUtils.h @@ -31,7 +31,8 @@ #include -template void dropFront(int64_t arr[N], int64_t *res) { +template +void dropFront(int64_t arr[N], int64_t *res) { for (unsigned i = 1; i < N; ++i) *(res + i - 1) = arr[i]; } @@ -40,23 +41,13 @@ // Codegen-compatible structures for Vector type. //===----------------------------------------------------------------------===// namespace detail { -template -constexpr bool isPowerOf2() { - return (!(N & (N - 1))); -} - -template -constexpr unsigned nextPowerOf2(); -template <> -constexpr unsigned nextPowerOf2<0>() { - return 1; -} -template <> -constexpr unsigned nextPowerOf2<1>() { - return 1; -} -template constexpr unsigned nextPowerOf2() { - return isPowerOf2() ? N : 2 * nextPowerOf2<(N + 1) / 2>(); + +constexpr bool isPowerOf2(int N) { return (!(N & (N - 1))); } + +constexpr unsigned nextPowerOf2(int N) { + if (N <= 1) + return 1; + return isPowerOf2(N) ? N : 2 * nextPowerOf2((N + 1) / 2); } template @@ -65,7 +56,7 @@ template struct Vector1D { Vector1D() { - static_assert(detail::nextPowerOf2() == sizeof(T[Dim]), + static_assert(detail::nextPowerOf2(sizeof(T[Dim])) == sizeof(T[Dim]), "size error"); } constexpr T &operator[](unsigned i) { return vector[i]; } @@ -80,9 +71,9 @@ template struct Vector1D { Vector1D() { - static_assert(detail::nextPowerOf2() > sizeof(T[Dim]), + static_assert(detail::nextPowerOf2(sizeof(T[Dim])) > sizeof(T[Dim]), "size error"); - static_assert(detail::nextPowerOf2() < 2 * sizeof(T[Dim]), + static_assert(detail::nextPowerOf2(sizeof(T[Dim])) < 2 * sizeof(T[Dim]), "size error"); } constexpr T &operator[](unsigned i) { return vector[i]; } @@ -90,7 +81,7 @@ private: T vector[Dim]; - char padding[detail::nextPowerOf2() - sizeof(T[Dim])]; + char padding[detail::nextPowerOf2(sizeof(T[Dim])) - sizeof(T[Dim])]; }; } // end namespace detail @@ -110,7 +101,7 @@ // We insert explicit padding in to account for this. template struct Vector - : public detail::Vector1D()> {}; + : public detail::Vector1D {}; template using Vector1D = Vector; @@ -125,7 +116,8 @@ // Codegen-compatible structures for StridedMemRef type. //===----------------------------------------------------------------------===// /// StridedMemRef descriptor type with static rank. -template struct StridedMemRefType { +template +struct StridedMemRefType { T *basePtr; T *data; int64_t offset; @@ -144,7 +136,8 @@ }; /// StridedMemRef descriptor type specialized for rank 1. -template struct StridedMemRefType { +template +struct StridedMemRefType { T *basePtr; T *data; int64_t offset; @@ -154,7 +147,8 @@ }; /// StridedMemRef descriptor type specialized for rank 0. -template struct StridedMemRefType { +template +struct StridedMemRefType { T *basePtr; T *data; int64_t offset; @@ -164,7 +158,8 @@ // Codegen-compatible structure for UnrankedMemRef type. //===----------------------------------------------------------------------===// // Unranked MemRef -template struct UnrankedMemRefType { +template +struct UnrankedMemRefType { int64_t rank; void *descriptor; };