[Mlir-commits] [mlir] 57397eb - Revert "[mlir] Add padding to 1-D Vector in CRunnerUtils.h"
Eric Christopher
llvmlistbot at llvm.org
Mon Mar 2 20:13:48 PST 2020
Author: Eric Christopher
Date: 2020-03-02T20:12:12-08:00
New Revision: 57397eba7a8a7525cee69e10ad90697ff74bb521
URL: https://github.com/llvm/llvm-project/commit/57397eba7a8a7525cee69e10ad90697ff74bb521
DIFF: https://github.com/llvm/llvm-project/commit/57397eba7a8a7525cee69e10ad90697ff74bb521.diff
LOG: Revert "[mlir] Add padding to 1-D Vector in CRunnerUtils.h"
Due to Werror breakage.
This reverts commits a68235d583fccb465694fdfd72eeb8d45d3369c0 and
bcee8982a2931960ca29a9e95e3d10355e7393ab.
Added:
Modified:
mlir/include/mlir/ExecutionEngine/CRunnerUtils.h
mlir/include/mlir/ExecutionEngine/RunnerUtils.h
mlir/lib/ExecutionEngine/CMakeLists.txt
Removed:
################################################################################
diff --git a/mlir/include/mlir/ExecutionEngine/CRunnerUtils.h b/mlir/include/mlir/ExecutionEngine/CRunnerUtils.h
index 28ef8e560667..d82963b1aa03 100644
--- a/mlir/include/mlir/ExecutionEngine/CRunnerUtils.h
+++ b/mlir/include/mlir/ExecutionEngine/CRunnerUtils.h
@@ -39,78 +39,15 @@ template <int N> void dropFront(int64_t arr[N], int64_t *res) {
//===----------------------------------------------------------------------===//
// Codegen-compatible structures for Vector type.
//===----------------------------------------------------------------------===//
-namespace detail {
-template <unsigned N>
-constexpr bool isPowerOf2() {
- return (!(N & (N - 1)));
-}
-
-template <unsigned N>
-constexpr unsigned nextPowerOf2();
-template <>
-constexpr unsigned nextPowerOf2<0>() {
- return 1;
-}
-template <>
-constexpr unsigned nextPowerOf2<1>() {
- return 1;
-}
-template <unsigned N> constexpr unsigned nextPowerOf2() {
- return isPowerOf2<N>() ? N : 2 * nextPowerOf2<(N + 1) / 2>();
-}
-
-template <typename T, int Dim, bool IsPowerOf2>
-class Vector1D;
-
-template <typename T, int Dim>
-struct Vector1D<T, Dim, /*IsPowerOf2=*/true> {
- Vector1D() {
- static_assert(detail::nextPowerOf2<sizeof(T[Dim])>() == sizeof(T[Dim]),
- "size error");
- }
- constexpr T &operator[](unsigned i) { return vector[i]; }
- constexpr const T &operator[](unsigned i) const { return vector[i]; }
-
-private:
- T vector[Dim];
-};
-
-// 1-D vector, padded to the next power of 2 allocation.
-// Specialization occurs to avoid zero size arrays (which fail in -Werror).
-template <typename T, int Dim>
-struct Vector1D<T, Dim, /*IsPowerOf2=*/false> {
- Vector1D() {
- static_assert(detail::nextPowerOf2<sizeof(T[Dim])>() > sizeof(T[Dim]),
- "size error");
- static_assert(detail::nextPowerOf2<sizeof(T[Dim])>() < 2 * sizeof(T[Dim]),
- "size error");
- }
- constexpr T &operator[](unsigned i) { return vector[i]; }
- constexpr const T &operator[](unsigned i) const { return vector[i]; }
-
-private:
- T vector[Dim];
- char padding[detail::nextPowerOf2<sizeof(T[Dim])>() - sizeof(T[Dim])];
-};
-} // end namespace detail
-
-// N-D vectors recurse down to 1-D.
template <typename T, int Dim, int... Dims>
struct Vector {
- constexpr Vector<T, Dims...> &operator[](unsigned i) { return vector[i]; }
- constexpr const Vector<T, Dims...> &operator[](unsigned i) const {
- return vector[i];
- }
-
-private:
Vector<T, Dims...> vector[Dim];
};
-// 1-D vectors in LLVM are automatically padded to the next power of 2.
-// We insert explicit padding in to account for this.
template <typename T, int Dim>
-struct Vector<T, Dim>
- : public detail::Vector1D<T, Dim, detail::isPowerOf2<sizeof(T[Dim])>()> {};
+struct Vector<T, Dim> {
+ T vector[Dim];
+};
template <int D1, typename T>
using Vector1D = Vector<T, D1>;
diff --git a/mlir/include/mlir/ExecutionEngine/RunnerUtils.h b/mlir/include/mlir/ExecutionEngine/RunnerUtils.h
index 16dc54f20da7..2676e648930c 100644
--- a/mlir/include/mlir/ExecutionEngine/RunnerUtils.h
+++ b/mlir/include/mlir/ExecutionEngine/RunnerUtils.h
@@ -92,7 +92,7 @@ void VectorDataPrinter<T, M, Dims...>::print(std::ostream &os,
static_assert(sizeof(val) == M * StaticSizeMult<Dims...>::value * sizeof(T),
"Incorrect vector size!");
// First
- os << "(" << val[0];
+ os << "(" << val.vector[0];
if (M > 1)
os << ", ";
if (sizeof...(Dims) > 1)
@@ -100,14 +100,14 @@ void VectorDataPrinter<T, M, Dims...>::print(std::ostream &os,
// Kernel
for (unsigned i = 1; i + 1 < M; ++i) {
printSpace(os, 2 * sizeof...(Dims));
- os << val[i] << ", ";
+ os << val.vector[i] << ", ";
if (sizeof...(Dims) > 1)
os << "\n";
}
// Last
if (M > 1) {
printSpace(os, sizeof...(Dims));
- os << val[M - 1];
+ os << val.vector[M - 1];
}
os << ")";
}
diff --git a/mlir/lib/ExecutionEngine/CMakeLists.txt b/mlir/lib/ExecutionEngine/CMakeLists.txt
index 37df71642440..dc20e5fd4622 100644
--- a/mlir/lib/ExecutionEngine/CMakeLists.txt
+++ b/mlir/lib/ExecutionEngine/CMakeLists.txt
@@ -36,12 +36,11 @@ target_link_libraries(MLIRExecutionEngine
${outlibs})
add_llvm_library(mlir_c_runner_utils SHARED CRunnerUtils.cpp)
-add_llvm_library(mlir_c_runner_utils_static CRunnerUtils.cpp)
target_compile_definitions(mlir_c_runner_utils PRIVATE mlir_c_runner_utils_EXPORTS)
add_llvm_library(mlir_runner_utils SHARED RunnerUtils.cpp)
target_link_libraries(mlir_runner_utils
- mlir_c_runner_utils_static
+ mlir_c_runner_utils
)
target_compile_definitions(mlir_runner_utils PRIVATE mlir_runner_utils_EXPORTS)
More information about the Mlir-commits
mailing list