Commit ab639e4a authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

Revert "[test] Avoid unnecessary std::vector allocations"

This reverts commit e737b4ce.

Reason for revert: On windows, V8_INFINITY is not constexpr

Original change's description:
> [test] Avoid unnecessary std::vector allocations
> 
> Instead of copying an array of fixed values into an std::vector for
> each usage of the FOR_INPUTS macro, just iterate the constant data
> directly.
> This also makes the <type>_vector() functions return {constexpr Vector}
> instead of {std::vector}.
> 
> R=​tebbi@chromium.org
> 
> Change-Id: Ifc3e5509b2fbf5e383c967c2f46acf2b07f7b5b4
> Reviewed-on: https://chromium-review.googlesource.com/725427
> Reviewed-by: Tobias Tebbi <tebbi@chromium.org>
> Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#48688}

TBR=clemensh@chromium.org,tebbi@chromium.org

Change-Id: Iccb52941d4efe71b49b41572c3d922a5d78bdfd2
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://chromium-review.googlesource.com/725899Reviewed-by: 's avatarClemens Hammacher <clemensh@chromium.org>
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#48691}
parent 5f846240
......@@ -19,14 +19,14 @@ namespace internal {
template <typename T>
class Vector {
public:
constexpr Vector() : start_(nullptr), length_(0) {}
Vector() : start_(nullptr), length_(0) {}
Vector(T* data, size_t length) : start_(data), length_(length) {
DCHECK(length == 0 || data != nullptr);
}
template <int N>
explicit constexpr Vector(T (&arr)[N]) : start_(arr), length_(N) {}
explicit Vector(T (&arr)[N]) : start_(arr), length_(N) {}
static Vector<T> New(int length) {
return Vector<T>(NewArray<T>(length), length);
......@@ -47,13 +47,13 @@ class Vector {
}
// Returns the length of the vector as a size_t.
constexpr size_t size() const { return length_; }
size_t size() const { return length_; }
// Returns whether or not the vector is empty.
constexpr bool is_empty() const { return length_ == 0; }
bool is_empty() const { return length_ == 0; }
// Returns the pointer to the start of the data in the vector.
constexpr T* start() const { return start_; }
T* start() const { return start_; }
// Access individual vector elements - checks bounds in debug mode.
T& operator[](size_t index) const {
......@@ -65,14 +65,11 @@ class Vector {
T& first() { return start_[0]; }
T& last() {
DCHECK_LT(0, length_);
return start_[length_ - 1];
}
T& last() { return start_[length_ - 1]; }
typedef T* iterator;
constexpr iterator begin() const { return start_; }
constexpr iterator end() const { return start_ + length_; }
inline iterator begin() const { return &start_[0]; }
inline iterator end() const { return &start_[length_]; }
// Returns a clone of this vector with a new backing store.
Vector<T> Clone() const {
......@@ -133,8 +130,8 @@ class Vector {
// Factory method for creating empty vectors.
static Vector<T> empty() { return Vector<T>(nullptr, 0); }
template <typename S>
static constexpr Vector<T> cast(Vector<S> input) {
template<typename S>
static Vector<T> cast(Vector<S> input) {
return Vector<T>(reinterpret_cast<T*>(input.start()),
input.length() * sizeof(S) / sizeof(T));
}
......@@ -217,7 +214,7 @@ inline Vector<char> MutableCStrVector(char* data, int max) {
}
template <typename T, int N>
inline constexpr Vector<T> ArrayVector(T (&arr)[N]) {
inline Vector<T> ArrayVector(T (&arr)[N]) {
return Vector<T>(arr);
}
......
......@@ -87,7 +87,6 @@ v8_source_set("cctest_sources") {
"compiler/test-run-unwinding-info.cc",
"compiler/test-run-variables.cc",
"compiler/test-run-wasm-machops.cc",
"compiler/value-helper.cc",
"compiler/value-helper.h",
"expression-type-collector-macros.h",
"gay-fixed.cc",
......
......@@ -75,7 +75,6 @@
'compiler/test-run-stubs.cc',
'compiler/test-run-variables.cc',
'compiler/test-run-wasm-machops.cc',
'compiler/value-helper.cc',
'compiler/value-helper.h',
'cctest.cc',
'cctest.h',
......
......@@ -285,7 +285,7 @@ TEST(CompareWrapper) {
void Int32BinopInputShapeTester::TestAllInputShapes() {
Vector<const int32_t> inputs = ValueHelper::int32_vector();
std::vector<int32_t> inputs = ValueHelper::int32_vector();
int num_int_inputs = static_cast<int>(inputs.size());
if (num_int_inputs > 16) num_int_inputs = 16; // limit to 16 inputs
......
// Copyright 2017 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "test/cctest/compiler/value-helper.h"
namespace v8 {
namespace internal {
namespace compiler {
// Define constexpr arrays of ValueHelper for external references.
constexpr int8_t ValueHelper::int8_array[];
constexpr int16_t ValueHelper::int16_array[];
constexpr uint32_t ValueHelper::uint32_array[];
constexpr uint64_t ValueHelper::uint64_array[];
constexpr float ValueHelper::float32_array[];
constexpr double ValueHelper::float64_array[];
} // namespace compiler
} // namespace internal
} // namespace v8
This diff is collapsed.
......@@ -100,7 +100,8 @@ TEST(TestCWasmEntryArgPassing_int32) {
WASM_I32_ADD(WASM_I32_MUL(WASM_I32V_1(2), WASM_GET_LOCAL(0)), WASM_ONE)},
[](int32_t a) { return 2 * a + 1; });
FOR_INT32_INPUTS(v) { tester.CheckCall(*v); }
std::vector<int32_t> test_values = compiler::ValueHelper::int32_vector();
for (int32_t v : test_values) tester.CheckCall(v);
}
// Pass int64_t, return double.
......@@ -110,7 +111,10 @@ TEST(TestCWasmEntryArgPassing_double_int64) {
WASM_F64_SCONVERT_I64(WASM_GET_LOCAL(0))},
[](int64_t a) { return static_cast<double>(a); });
FOR_INT64_INPUTS(v) { tester.CheckCall(*v); }
std::vector<int64_t> test_values_i64 = compiler::ValueHelper::int64_vector();
for (int64_t v : test_values_i64) {
tester.CheckCall(v);
}
}
// Pass double, return int64_t.
......@@ -120,7 +124,9 @@ TEST(TestCWasmEntryArgPassing_int64_double) {
WASM_I64_SCONVERT_F64(WASM_GET_LOCAL(0))},
[](double d) { return static_cast<int64_t>(d); });
FOR_INT64_INPUTS(i) { tester.CheckCall(*i); }
for (int64_t i : compiler::ValueHelper::int64_vector()) {
tester.CheckCall(i);
}
}
// Pass float, return double.
......@@ -132,7 +138,8 @@ TEST(TestCWasmEntryArgPassing_float_double) {
WASM_F64(1))},
[](float f) { return 2. * static_cast<double>(f) + 1.; });
FOR_FLOAT32_INPUTS(f) { tester.CheckCall(*f); }
std::vector<float> test_values = compiler::ValueHelper::float32_vector();
for (float f : test_values) tester.CheckCall(f);
}
// Pass two doubles, return double.
......@@ -142,8 +149,11 @@ TEST(TestCWasmEntryArgPassing_double_double) {
WASM_F64_ADD(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))},
[](double a, double b) { return a + b; });
FOR_FLOAT64_INPUTS(d1) {
FOR_FLOAT64_INPUTS(d2) { tester.CheckCall(*d1, *d2); }
std::vector<double> test_values = compiler::ValueHelper::float64_vector();
for (double d1 : test_values) {
for (double d2 : test_values) {
tester.CheckCall(d1, d2);
}
}
}
......@@ -166,11 +176,10 @@ TEST(TestCWasmEntryArgPassing_AllTypes) {
return 0. + a + b + c + d;
});
Vector<const int32_t> test_values_i32 = compiler::ValueHelper::int32_vector();
Vector<const int64_t> test_values_i64 = compiler::ValueHelper::int64_vector();
Vector<const float> test_values_f32 = compiler::ValueHelper::float32_vector();
Vector<const double> test_values_f64 =
compiler::ValueHelper::float64_vector();
std::vector<int32_t> test_values_i32 = compiler::ValueHelper::int32_vector();
std::vector<int64_t> test_values_i64 = compiler::ValueHelper::int64_vector();
std::vector<float> test_values_f32 = compiler::ValueHelper::float32_vector();
std::vector<double> test_values_f64 = compiler::ValueHelper::float64_vector();
size_t max_len =
std::max(std::max(test_values_i32.size(), test_values_i64.size()),
std::max(test_values_f32.size(), test_values_f64.size()));
......
......@@ -101,7 +101,8 @@ TEST(TestArgumentPassing_int32) {
WASM_GET_LOCAL(0), WASM_CALL_FUNCTION0(f2.function_index())},
[](int32_t a) { return 2 * a + 1; });
FOR_INT32_INPUTS(v) { helper.CheckCall(*v); }
std::vector<int32_t> test_values = compiler::ValueHelper::int32_vector();
for (int32_t v : test_values) helper.CheckCall(v);
}
// Pass int64_t, return double.
......@@ -124,13 +125,17 @@ TEST(TestArgumentPassing_double_int64) {
return static_cast<double>(a64 | b64);
});
FOR_INT32_INPUTS(v1) {
FOR_INT32_INPUTS(v2) { helper.CheckCall(*v1, *v2); }
std::vector<int32_t> test_values_i32 = compiler::ValueHelper::int32_vector();
for (int32_t v1 : test_values_i32) {
for (int32_t v2 : test_values_i32) {
helper.CheckCall(v1, v2);
}
}
FOR_INT64_INPUTS(v) {
int32_t v1 = static_cast<int32_t>(*v);
int32_t v2 = static_cast<int32_t>(*v >> 32);
std::vector<int64_t> test_values_i64 = compiler::ValueHelper::int64_vector();
for (int64_t v : test_values_i64) {
int32_t v1 = static_cast<int32_t>(v);
int32_t v2 = static_cast<int32_t>(v >> 32);
helper.CheckCall(v1, v2);
helper.CheckCall(v2, v1);
}
......@@ -171,7 +176,8 @@ TEST(TestArgumentPassing_float_double) {
WASM_GET_LOCAL(0), WASM_CALL_FUNCTION0(f2.function_index())},
[](float f) { return 2. * static_cast<double>(f) + 1.; });
FOR_FLOAT32_INPUTS(f) { helper.CheckCall(*f); }
std::vector<float> test_values = compiler::ValueHelper::float32_vector();
for (float f : test_values) helper.CheckCall(f);
}
// Pass two doubles, return double.
......@@ -187,8 +193,11 @@ TEST(TestArgumentPassing_double_double) {
WASM_CALL_FUNCTION0(f2.function_index())},
[](double a, double b) { return a + b; });
FOR_FLOAT64_INPUTS(d1) {
FOR_FLOAT64_INPUTS(d2) { helper.CheckCall(*d1, *d2); }
std::vector<double> test_values = compiler::ValueHelper::float64_vector();
for (double d1 : test_values) {
for (double d2 : test_values) {
helper.CheckCall(d1, d2);
}
}
}
......@@ -233,11 +242,10 @@ TEST(TestArgumentPassing_AllTypes) {
helper.CheckCall(a, b1, b0, c, d);
};
Vector<const int32_t> test_values_i32 = compiler::ValueHelper::int32_vector();
Vector<const int64_t> test_values_i64 = compiler::ValueHelper::int64_vector();
Vector<const float> test_values_f32 = compiler::ValueHelper::float32_vector();
Vector<const double> test_values_f64 =
compiler::ValueHelper::float64_vector();
std::vector<int32_t> test_values_i32 = compiler::ValueHelper::int32_vector();
std::vector<int64_t> test_values_i64 = compiler::ValueHelper::int64_vector();
std::vector<float> test_values_f32 = compiler::ValueHelper::float32_vector();
std::vector<double> test_values_f64 = compiler::ValueHelper::float64_vector();
size_t max_len =
std::max(std::max(test_values_i32.size(), test_values_i64.size()),
std::max(test_values_f32.size(), test_values_f64.size()));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment