diff options
author | Michaël Zasso <targos@protonmail.com> | 2017-10-18 15:03:02 -0700 |
---|---|---|
committer | Michaël Zasso <targos@protonmail.com> | 2017-10-18 17:01:41 -0700 |
commit | 3d1b3df9486c0e7708065257f7311902f6b7b366 (patch) | |
tree | cb051bdeaead11e06dcd97725783e0f113afb1bf /deps/v8/test/unittests/compiler | |
parent | e2cddbb8ccdb7b3c4a40c8acc630f68703bc77b5 (diff) | |
download | node-new-3d1b3df9486c0e7708065257f7311902f6b7b366.tar.gz |
deps: update V8 to 6.2.414.32
PR-URL: https://github.com/nodejs/node/pull/15362
Reviewed-By: Myles Borins <myles.borins@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Diffstat (limited to 'deps/v8/test/unittests/compiler')
14 files changed, 204 insertions, 513 deletions
diff --git a/deps/v8/test/unittests/compiler/bytecode-analysis-unittest.cc b/deps/v8/test/unittests/compiler/bytecode-analysis-unittest.cc index 16414d0863..310f264c74 100644 --- a/deps/v8/test/unittests/compiler/bytecode-analysis-unittest.cc +++ b/deps/v8/test/unittests/compiler/bytecode-analysis-unittest.cc @@ -232,28 +232,35 @@ TEST_F(BytecodeAnalysisTest, SimpleLoop) { interpreter::Register reg_1(1); interpreter::Register reg_2(2); + // Kill r0. builder.StoreAccumulatorInRegister(reg_0); - expected_liveness.emplace_back("..LL", "L.LL"); + expected_liveness.emplace_back("..LL", "L.L."); { interpreter::LoopBuilder loop_builder(&builder, nullptr, nullptr); loop_builder.LoopHeader(); + builder.LoadUndefined(); + expected_liveness.emplace_back("L.L.", "L.LL"); + builder.JumpIfTrue(ToBooleanMode::kConvertToBoolean, loop_builder.break_labels()->New()); expected_liveness.emplace_back("L.LL", "L.L."); + // Gen r0. builder.LoadAccumulatorWithRegister(reg_0); expected_liveness.emplace_back("L...", "L..L"); + // Kill r2. builder.StoreAccumulatorInRegister(reg_2); - expected_liveness.emplace_back("L..L", "L.LL"); + expected_liveness.emplace_back("L..L", "L.L."); loop_builder.BindContinueTarget(); loop_builder.JumpToHeader(0); - expected_liveness.emplace_back("L.LL", "L.LL"); + expected_liveness.emplace_back("L.L.", "L.L."); } + // Gen r2. builder.LoadAccumulatorWithRegister(reg_2); expected_liveness.emplace_back("..L.", "...L"); @@ -273,15 +280,18 @@ TEST_F(BytecodeAnalysisTest, TryCatch) { interpreter::Register reg_1(1); interpreter::Register reg_context(2); + // Kill r0. builder.StoreAccumulatorInRegister(reg_0); expected_liveness.emplace_back(".LLL", "LLL."); interpreter::TryCatchBuilder try_builder(&builder, HandlerTable::CAUGHT); try_builder.BeginTry(reg_context); { + // Gen r0. builder.LoadAccumulatorWithRegister(reg_0); expected_liveness.emplace_back("LLL.", ".LLL"); + // Kill r0. builder.StoreAccumulatorInRegister(reg_0); expected_liveness.emplace_back(".LLL", ".LL."); @@ -311,20 +321,21 @@ TEST_F(BytecodeAnalysisTest, TryCatch) { } TEST_F(BytecodeAnalysisTest, DiamondInLoop) { + // For a logic diamond inside a loop, the liveness down one path of the + // diamond should eventually propagate up the other path when the loop is + // reprocessed. + interpreter::BytecodeArrayBuilder builder(isolate(), zone(), 3, 3); std::vector<std::pair<std::string, std::string>> expected_liveness; interpreter::Register reg_0(0); - interpreter::Register reg_1(1); - interpreter::Register reg_2(2); - - builder.StoreAccumulatorInRegister(reg_0); - expected_liveness.emplace_back("...L", "L..L"); { interpreter::LoopBuilder loop_builder(&builder, nullptr, nullptr); loop_builder.LoopHeader(); + builder.LoadUndefined(); + expected_liveness.emplace_back("L...", "L..L"); builder.JumpIfTrue(ToBooleanMode::kConvertToBoolean, loop_builder.break_labels()->New()); expected_liveness.emplace_back("L..L", "L..L"); @@ -332,26 +343,29 @@ TEST_F(BytecodeAnalysisTest, DiamondInLoop) { interpreter::BytecodeLabel ld1_label; interpreter::BytecodeLabel end_label; builder.JumpIfTrue(ToBooleanMode::kConvertToBoolean, &ld1_label); - expected_liveness.emplace_back("L..L", "L..L"); + expected_liveness.emplace_back("L..L", "L..."); { builder.Jump(&end_label); - expected_liveness.emplace_back("L..L", "L..L"); + expected_liveness.emplace_back("L...", "L..."); } builder.Bind(&ld1_label); { + // Gen r0. builder.LoadAccumulatorWithRegister(reg_0); - expected_liveness.emplace_back("L...", "L..L"); + expected_liveness.emplace_back("L...", "L..."); } builder.Bind(&end_label); loop_builder.BindContinueTarget(); loop_builder.JumpToHeader(0); - expected_liveness.emplace_back("L..L", "L..L"); + expected_liveness.emplace_back("L...", "L..."); } + builder.LoadUndefined(); + expected_liveness.emplace_back("....", "...L"); builder.Return(); expected_liveness.emplace_back("...L", "...."); @@ -361,43 +375,65 @@ TEST_F(BytecodeAnalysisTest, DiamondInLoop) { } TEST_F(BytecodeAnalysisTest, KillingLoopInsideLoop) { + // For a loop inside a loop, the inner loop has to be processed after the + // outer loop has been processed, to ensure that it can propagate the + // information in its header. Consider + // + // 0: do { + // 1: acc = r0; + // 2: acc = r1; + // 3: do { + // 4: r0 = acc; + // 5: break; + // 6: } while(true); + // 7: } while(true); + // + // r0 should should be dead at 3 and 6, while r1 is live throughout. On the + // initial pass, r1 is dead from 3-7. On the outer loop pass, it becomes live + // in 3 and 7 (but not 4-6 because 6 only reads liveness from 3). Only after + // the inner loop pass does it become live in 4-6. It's necessary, however, to + // still process the inner loop when processing the outer loop, to ensure that + // r1 becomes live in 3 (via 5), but r0 stays dead (because of 4). + interpreter::BytecodeArrayBuilder builder(isolate(), zone(), 3, 3); std::vector<std::pair<std::string, std::string>> expected_liveness; interpreter::Register reg_0(0); interpreter::Register reg_1(1); - builder.StoreAccumulatorInRegister(reg_0); - expected_liveness.emplace_back(".L.L", "LL.."); - { interpreter::LoopBuilder loop_builder(&builder, nullptr, nullptr); loop_builder.LoopHeader(); + // Gen r0. builder.LoadAccumulatorWithRegister(reg_0); expected_liveness.emplace_back("LL..", ".L.."); + // Gen r1. builder.LoadAccumulatorWithRegister(reg_1); expected_liveness.emplace_back(".L..", ".L.L"); builder.JumpIfTrue(ToBooleanMode::kConvertToBoolean, loop_builder.break_labels()->New()); - expected_liveness.emplace_back(".L.L", ".L.L"); + expected_liveness.emplace_back(".L.L", ".L.."); { interpreter::LoopBuilder inner_loop_builder(&builder, nullptr, nullptr); inner_loop_builder.LoopHeader(); + // Kill r0. + builder.LoadUndefined(); + expected_liveness.emplace_back(".L..", ".L.L"); builder.StoreAccumulatorInRegister(reg_0); expected_liveness.emplace_back(".L.L", "LL.L"); builder.JumpIfTrue(ToBooleanMode::kConvertToBoolean, inner_loop_builder.break_labels()->New()); - expected_liveness.emplace_back("LL.L", "LL.L"); + expected_liveness.emplace_back("LL.L", "LL.."); inner_loop_builder.BindContinueTarget(); inner_loop_builder.JumpToHeader(1); - expected_liveness.emplace_back(".L.L", ".L.L"); + expected_liveness.emplace_back(".L..", ".L.."); } loop_builder.BindContinueTarget(); @@ -405,6 +441,8 @@ TEST_F(BytecodeAnalysisTest, KillingLoopInsideLoop) { expected_liveness.emplace_back("LL..", "LL.."); } + builder.LoadUndefined(); + expected_liveness.emplace_back("....", "...L"); builder.Return(); expected_liveness.emplace_back("...L", "...."); diff --git a/deps/v8/test/unittests/compiler/graph-reducer-unittest.cc b/deps/v8/test/unittests/compiler/graph-reducer-unittest.cc index 82aae2f3dd..f6f5994932 100644 --- a/deps/v8/test/unittests/compiler/graph-reducer-unittest.cc +++ b/deps/v8/test/unittests/compiler/graph-reducer-unittest.cc @@ -45,12 +45,12 @@ const uint8_t kOpcodeC2 = 32; static TestOperator kOpA0(kOpcodeA0, Operator::kNoWrite, "opa1", 0, 1); static TestOperator kOpA1(kOpcodeA1, Operator::kNoProperties, "opa2", 1, 1); static TestOperator kOpA2(kOpcodeA2, Operator::kNoProperties, "opa3", 2, 1); -static TestOperator kOpB0(kOpcodeB0, Operator::kNoWrite, "opa0", 0, 0); -static TestOperator kOpB1(kOpcodeB1, Operator::kNoWrite, "opa1", 1, 0); -static TestOperator kOpB2(kOpcodeB2, Operator::kNoWrite, "opa2", 2, 0); -static TestOperator kOpC0(kOpcodeC0, Operator::kNoWrite, "opc0", 0, 0); -static TestOperator kOpC1(kOpcodeC1, Operator::kNoWrite, "opc1", 1, 0); -static TestOperator kOpC2(kOpcodeC2, Operator::kNoWrite, "opc2", 2, 0); +static TestOperator kOpB0(kOpcodeB0, Operator::kNoWrite, "opb0", 0, 1); +static TestOperator kOpB1(kOpcodeB1, Operator::kNoWrite, "opb1", 1, 1); +static TestOperator kOpB2(kOpcodeB2, Operator::kNoWrite, "opb2", 2, 1); +static TestOperator kOpC0(kOpcodeC0, Operator::kNoWrite, "opc0", 0, 1); +static TestOperator kOpC1(kOpcodeC1, Operator::kNoWrite, "opc1", 1, 1); +static TestOperator kOpC2(kOpcodeC2, Operator::kNoWrite, "opc2", 2, 1); struct MockReducer : public Reducer { MOCK_CONST_METHOD0(reducer_name, const char*()); diff --git a/deps/v8/test/unittests/compiler/instruction-selector-unittest.cc b/deps/v8/test/unittests/compiler/instruction-selector-unittest.cc index a00fc98517..3444e0542a 100644 --- a/deps/v8/test/unittests/compiler/instruction-selector-unittest.cc +++ b/deps/v8/test/unittests/compiler/instruction-selector-unittest.cc @@ -48,7 +48,7 @@ InstructionSelectorTest::Stream InstructionSelectorTest::StreamBuilder::Build( selector.SelectInstructions(); if (FLAG_trace_turbo) { OFStream out(stdout); - PrintableInstructionSequence printable = {RegisterConfiguration::Turbofan(), + PrintableInstructionSequence printable = {RegisterConfiguration::Default(), &sequence}; out << "=== Code sequence after instruction selection ===" << std::endl << printable; diff --git a/deps/v8/test/unittests/compiler/js-builtin-reducer-unittest.cc b/deps/v8/test/unittests/compiler/js-builtin-reducer-unittest.cc index 3237feaa45..a0ea6f376e 100644 --- a/deps/v8/test/unittests/compiler/js-builtin-reducer-unittest.cc +++ b/deps/v8/test/unittests/compiler/js-builtin-reducer-unittest.cc @@ -34,8 +34,7 @@ class JSBuiltinReducerTest : public TypedGraphTest { // TODO(titzer): mock the GraphReducer here for better unit testing. GraphReducer graph_reducer(zone(), graph()); - JSBuiltinReducer reducer(&graph_reducer, &jsgraph, - JSBuiltinReducer::kNoFlags, nullptr, + JSBuiltinReducer reducer(&graph_reducer, &jsgraph, nullptr, native_context()); return reducer.Reduce(node); } diff --git a/deps/v8/test/unittests/compiler/js-intrinsic-lowering-unittest.cc b/deps/v8/test/unittests/compiler/js-intrinsic-lowering-unittest.cc index 34da77dec4..a9ef25b60c 100644 --- a/deps/v8/test/unittests/compiler/js-intrinsic-lowering-unittest.cc +++ b/deps/v8/test/unittests/compiler/js-intrinsic-lowering-unittest.cc @@ -37,8 +37,7 @@ class JSIntrinsicLoweringTest : public GraphTest { &machine); // TODO(titzer): mock the GraphReducer here for better unit testing. GraphReducer graph_reducer(zone(), graph()); - JSIntrinsicLowering reducer(&graph_reducer, &jsgraph, - JSIntrinsicLowering::kDeoptimizationEnabled); + JSIntrinsicLowering reducer(&graph_reducer, &jsgraph); return reducer.Reduce(node); } diff --git a/deps/v8/test/unittests/compiler/js-operator-unittest.cc b/deps/v8/test/unittests/compiler/js-operator-unittest.cc index ad0553313f..886fbe02ce 100644 --- a/deps/v8/test/unittests/compiler/js-operator-unittest.cc +++ b/deps/v8/test/unittests/compiler/js-operator-unittest.cc @@ -42,7 +42,6 @@ const SharedOperator kSharedOperators[] = { } SHARED(ToNumber, Operator::kNoProperties, 1, 1, 1, 1, 1, 1, 2), SHARED(ToString, Operator::kNoProperties, 1, 1, 1, 1, 1, 1, 2), - SHARED(ToPrimitiveToString, Operator::kNoProperties, 1, 1, 1, 1, 1, 1, 2), SHARED(ToName, Operator::kNoProperties, 1, 1, 1, 1, 1, 1, 2), SHARED(ToObject, Operator::kFoldable, 1, 1, 1, 1, 1, 1, 2), SHARED(Create, Operator::kNoProperties, 2, 1, 1, 1, 1, 1, 2), diff --git a/deps/v8/test/unittests/compiler/js-typed-lowering-unittest.cc b/deps/v8/test/unittests/compiler/js-typed-lowering-unittest.cc index 8a1efe0801..868c8b3052 100644 --- a/deps/v8/test/unittests/compiler/js-typed-lowering-unittest.cc +++ b/deps/v8/test/unittests/compiler/js-typed-lowering-unittest.cc @@ -4,7 +4,6 @@ #include "src/compiler/js-typed-lowering.h" #include "src/code-factory.h" -#include "src/compilation-dependencies.h" #include "src/compiler/access-builder.h" #include "src/compiler/js-graph.h" #include "src/compiler/js-operator.h" @@ -28,26 +27,17 @@ namespace compiler { namespace { -const ExternalArrayType kExternalArrayTypes[] = { - kExternalUint8Array, kExternalInt8Array, kExternalUint16Array, - kExternalInt16Array, kExternalUint32Array, kExternalInt32Array, - kExternalFloat32Array, kExternalFloat64Array}; - const size_t kIndices[] = {0, 1, 42, 100, 1024}; Type* const kJSTypes[] = {Type::Undefined(), Type::Null(), Type::Boolean(), Type::Number(), Type::String(), Type::Object()}; -STATIC_ASSERT(LANGUAGE_END == 2); -const LanguageMode kLanguageModes[] = {SLOPPY, STRICT}; - } // namespace class JSTypedLoweringTest : public TypedGraphTest { public: - JSTypedLoweringTest() - : TypedGraphTest(3), javascript_(zone()), deps_(isolate(), zone()) {} + JSTypedLoweringTest() : TypedGraphTest(3), javascript_(zone()) {} ~JSTypedLoweringTest() override {} protected: @@ -58,9 +48,7 @@ class JSTypedLoweringTest : public TypedGraphTest { &machine); // TODO(titzer): mock the GraphReducer here for better unit testing. GraphReducer graph_reducer(zone(), graph()); - JSTypedLowering reducer(&graph_reducer, &deps_, - JSTypedLowering::kDeoptimizationEnabled, &jsgraph, - zone()); + JSTypedLowering reducer(&graph_reducer, &jsgraph, zone()); return reducer.Reduce(node); } @@ -74,7 +62,6 @@ class JSTypedLoweringTest : public TypedGraphTest { private: JSOperatorBuilder javascript_; - CompilationDependencies deps_; }; @@ -250,23 +237,6 @@ TEST_F(JSTypedLoweringTest, JSToStringWithBoolean) { IsHeapConstant(factory()->false_string()))); } -// ----------------------------------------------------------------------------- -// JSToPrimitiveToString - -TEST_F(JSTypedLoweringTest, JSToPrimitiveToStringWithBoolean) { - Node* const input = Parameter(Type::Boolean(), 0); - Node* const context = Parameter(Type::Any(), 1); - Node* const frame_state = EmptyFrameState(); - Node* const effect = graph()->start(); - Node* const control = graph()->start(); - Reduction r = Reduce(graph()->NewNode(javascript()->ToString(), input, - context, frame_state, effect, control)); - ASSERT_TRUE(r.Changed()); - EXPECT_THAT(r.replacement(), - IsSelect(MachineRepresentation::kTagged, input, - IsHeapConstant(factory()->true_string()), - IsHeapConstant(factory()->false_string()))); -} // ----------------------------------------------------------------------------- // JSStrictEqual @@ -469,212 +439,6 @@ TEST_F(JSTypedLoweringTest, JSStoreContext) { // ----------------------------------------------------------------------------- -// JSLoadProperty - - -TEST_F(JSTypedLoweringTest, JSLoadPropertyFromExternalTypedArray) { - const size_t kLength = 17; - double backing_store[kLength]; - Handle<JSArrayBuffer> buffer = - NewArrayBuffer(backing_store, sizeof(backing_store)); - VectorSlotPair feedback; - TRACED_FOREACH(ExternalArrayType, type, kExternalArrayTypes) { - Handle<JSTypedArray> array = - factory()->NewJSTypedArray(type, buffer, 0, kLength); - int const element_size = static_cast<int>(array->element_size()); - - Node* key = Parameter( - Type::Range(kMinInt / element_size, kMaxInt / element_size, zone())); - Node* base = HeapConstant(array); - Node* context = UndefinedConstant(); - Node* effect = graph()->start(); - Node* control = graph()->start(); - Reduction r = - Reduce(graph()->NewNode(javascript()->LoadProperty(feedback), base, key, - context, EmptyFrameState(), effect, control)); - - Matcher<Node*> offset_matcher = - element_size == 1 - ? key - : IsNumberShiftLeft(key, - IsNumberConstant(WhichPowerOf2(element_size))); - - ASSERT_TRUE(r.Changed()); - EXPECT_THAT( - r.replacement(), - IsLoadBuffer(BufferAccess(type), - IsPointerConstant(bit_cast<intptr_t>(&backing_store[0])), - offset_matcher, - IsNumberConstant(array->byte_length()->Number()), effect, - control)); - } -} - - -TEST_F(JSTypedLoweringTest, JSLoadPropertyFromExternalTypedArrayWithSafeKey) { - const size_t kLength = 17; - double backing_store[kLength]; - Handle<JSArrayBuffer> buffer = - NewArrayBuffer(backing_store, sizeof(backing_store)); - VectorSlotPair feedback; - TRACED_FOREACH(ExternalArrayType, type, kExternalArrayTypes) { - Handle<JSTypedArray> array = - factory()->NewJSTypedArray(type, buffer, 0, kLength); - ElementAccess access = AccessBuilder::ForTypedArrayElement(type, true); - - int min = random_number_generator()->NextInt(static_cast<int>(kLength)); - int max = random_number_generator()->NextInt(static_cast<int>(kLength)); - if (min > max) std::swap(min, max); - Node* key = Parameter(Type::Range(min, max, zone())); - Node* base = HeapConstant(array); - Node* context = UndefinedConstant(); - Node* effect = graph()->start(); - Node* control = graph()->start(); - Reduction r = - Reduce(graph()->NewNode(javascript()->LoadProperty(feedback), base, key, - context, EmptyFrameState(), effect, control)); - - ASSERT_TRUE(r.Changed()); - EXPECT_THAT( - r.replacement(), - IsLoadElement(access, - IsPointerConstant(bit_cast<intptr_t>(&backing_store[0])), - key, effect, control)); - } -} - - -// ----------------------------------------------------------------------------- -// JSStoreProperty - - -TEST_F(JSTypedLoweringTest, JSStorePropertyToExternalTypedArray) { - const size_t kLength = 17; - double backing_store[kLength]; - Handle<JSArrayBuffer> buffer = - NewArrayBuffer(backing_store, sizeof(backing_store)); - TRACED_FOREACH(ExternalArrayType, type, kExternalArrayTypes) { - TRACED_FOREACH(LanguageMode, language_mode, kLanguageModes) { - Handle<JSTypedArray> array = - factory()->NewJSTypedArray(type, buffer, 0, kLength); - int const element_size = static_cast<int>(array->element_size()); - - Node* key = Parameter( - Type::Range(kMinInt / element_size, kMaxInt / element_size, zone())); - Node* base = HeapConstant(array); - Node* value = - Parameter(AccessBuilder::ForTypedArrayElement(type, true).type); - Node* context = UndefinedConstant(); - Node* effect = graph()->start(); - Node* control = graph()->start(); - VectorSlotPair feedback; - const Operator* op = javascript()->StoreProperty(language_mode, feedback); - Node* node = graph()->NewNode(op, base, key, value, context, - EmptyFrameState(), effect, control); - Reduction r = Reduce(node); - - Matcher<Node*> offset_matcher = - element_size == 1 - ? key - : IsNumberShiftLeft( - key, IsNumberConstant(WhichPowerOf2(element_size))); - - ASSERT_TRUE(r.Changed()); - EXPECT_THAT( - r.replacement(), - IsStoreBuffer( - BufferAccess(type), - IsPointerConstant(bit_cast<intptr_t>(&backing_store[0])), - offset_matcher, IsNumberConstant(array->byte_length()->Number()), - value, effect, control)); - } - } -} - - -TEST_F(JSTypedLoweringTest, JSStorePropertyToExternalTypedArrayWithConversion) { - const size_t kLength = 17; - double backing_store[kLength]; - Handle<JSArrayBuffer> buffer = - NewArrayBuffer(backing_store, sizeof(backing_store)); - TRACED_FOREACH(ExternalArrayType, type, kExternalArrayTypes) { - TRACED_FOREACH(LanguageMode, language_mode, kLanguageModes) { - Handle<JSTypedArray> array = - factory()->NewJSTypedArray(type, buffer, 0, kLength); - int const element_size = static_cast<int>(array->element_size()); - - Node* key = Parameter( - Type::Range(kMinInt / element_size, kMaxInt / element_size, zone())); - Node* base = HeapConstant(array); - Node* value = Parameter(Type::PlainPrimitive()); - Node* context = UndefinedConstant(); - Node* effect = graph()->start(); - Node* control = graph()->start(); - VectorSlotPair feedback; - const Operator* op = javascript()->StoreProperty(language_mode, feedback); - Node* node = graph()->NewNode(op, base, key, value, context, - EmptyFrameState(), effect, control); - Reduction r = Reduce(node); - - Matcher<Node*> offset_matcher = - element_size == 1 - ? key - : IsNumberShiftLeft( - key, IsNumberConstant(WhichPowerOf2(element_size))); - - Matcher<Node*> value_matcher = IsPlainPrimitiveToNumber(value); - - ASSERT_TRUE(r.Changed()); - EXPECT_THAT( - r.replacement(), - IsStoreBuffer( - BufferAccess(type), - IsPointerConstant(bit_cast<intptr_t>(&backing_store[0])), - offset_matcher, IsNumberConstant(array->byte_length()->Number()), - value_matcher, effect, control)); - } - } -} - - -TEST_F(JSTypedLoweringTest, JSStorePropertyToExternalTypedArrayWithSafeKey) { - const size_t kLength = 17; - double backing_store[kLength]; - Handle<JSArrayBuffer> buffer = - NewArrayBuffer(backing_store, sizeof(backing_store)); - TRACED_FOREACH(ExternalArrayType, type, kExternalArrayTypes) { - TRACED_FOREACH(LanguageMode, language_mode, kLanguageModes) { - Handle<JSTypedArray> array = - factory()->NewJSTypedArray(type, buffer, 0, kLength); - ElementAccess access = AccessBuilder::ForTypedArrayElement(type, true); - - int min = random_number_generator()->NextInt(static_cast<int>(kLength)); - int max = random_number_generator()->NextInt(static_cast<int>(kLength)); - if (min > max) std::swap(min, max); - Node* key = Parameter(Type::Range(min, max, zone())); - Node* base = HeapConstant(array); - Node* value = Parameter(access.type); - Node* context = UndefinedConstant(); - Node* effect = graph()->start(); - Node* control = graph()->start(); - VectorSlotPair feedback; - const Operator* op = javascript()->StoreProperty(language_mode, feedback); - Node* node = graph()->NewNode(op, base, key, value, context, - EmptyFrameState(), effect, control); - Reduction r = Reduce(node); - - ASSERT_TRUE(r.Changed()); - EXPECT_THAT( - r.replacement(), - IsStoreElement( - access, IsPointerConstant(bit_cast<intptr_t>(&backing_store[0])), - key, value, effect, control)); - } - } -} - - -// ----------------------------------------------------------------------------- // JSLoadNamed diff --git a/deps/v8/test/unittests/compiler/load-elimination-unittest.cc b/deps/v8/test/unittests/compiler/load-elimination-unittest.cc index e4b35e8203..8cf5bd3236 100644 --- a/deps/v8/test/unittests/compiler/load-elimination-unittest.cc +++ b/deps/v8/test/unittests/compiler/load-elimination-unittest.cc @@ -404,17 +404,15 @@ TEST_F(LoadEliminationTest, LoadFieldWithTypeMismatch) { load_elimination.Reduce(graph()->start()); - Node* store = effect = graph()->NewNode(simplified()->StoreField(access), - object, value, effect, control); + effect = graph()->NewNode(simplified()->StoreField(access), object, value, + effect, control); load_elimination.Reduce(effect); Node* load = graph()->NewNode(simplified()->LoadField(access), object, effect, control); - EXPECT_CALL(editor, - ReplaceWithValue(load, IsTypeGuard(value, control), store, _)); Reduction r = load_elimination.Reduce(load); ASSERT_TRUE(r.Changed()); - EXPECT_THAT(r.replacement(), IsTypeGuard(value, control)); + EXPECT_EQ(load, r.replacement()); } TEST_F(LoadEliminationTest, LoadElementWithTypeMismatch) { @@ -431,18 +429,15 @@ TEST_F(LoadEliminationTest, LoadElementWithTypeMismatch) { load_elimination.Reduce(graph()->start()); - Node* store = effect = - graph()->NewNode(simplified()->StoreElement(access), object, index, value, - effect, control); + effect = graph()->NewNode(simplified()->StoreElement(access), object, index, + value, effect, control); load_elimination.Reduce(effect); Node* load = graph()->NewNode(simplified()->LoadElement(access), object, index, effect, control); - EXPECT_CALL(editor, - ReplaceWithValue(load, IsTypeGuard(value, control), store, _)); Reduction r = load_elimination.Reduce(load); ASSERT_TRUE(r.Changed()); - EXPECT_THAT(r.replacement(), IsTypeGuard(value, control)); + EXPECT_EQ(load, r.replacement()); } TEST_F(LoadEliminationTest, AliasAnalysisForFinishRegion) { diff --git a/deps/v8/test/unittests/compiler/mips/instruction-selector-mips-unittest.cc b/deps/v8/test/unittests/compiler/mips/instruction-selector-mips-unittest.cc index d1336940a3..b041597ccd 100644 --- a/deps/v8/test/unittests/compiler/mips/instruction-selector-mips-unittest.cc +++ b/deps/v8/test/unittests/compiler/mips/instruction-selector-mips-unittest.cc @@ -1119,8 +1119,8 @@ TEST_P(InstructionSelectorMemoryAccessUnalignedImmTest, StoreZero) { const MemoryAccessImm2 memacc = GetParam(); TRACED_FOREACH(int32_t, index, memacc.immediates) { StreamBuilder m(this, MachineType::Int32(), MachineType::Pointer()); - bool unaligned_store_supported = m.machine()->UnalignedStoreSupported( - MachineType::TypeForRepresentation(memacc.type.representation()), 1); + bool unaligned_store_supported = + m.machine()->UnalignedStoreSupported(memacc.type.representation()); m.UnalignedStore(memacc.type.representation(), m.Parameter(0), m.Int32Constant(index), m.Int32Constant(0)); m.Return(m.Int32Constant(0)); diff --git a/deps/v8/test/unittests/compiler/mips64/instruction-selector-mips64-unittest.cc b/deps/v8/test/unittests/compiler/mips64/instruction-selector-mips64-unittest.cc index 387267c241..5c57e5ce9f 100644 --- a/deps/v8/test/unittests/compiler/mips64/instruction-selector-mips64-unittest.cc +++ b/deps/v8/test/unittests/compiler/mips64/instruction-selector-mips64-unittest.cc @@ -1561,8 +1561,8 @@ TEST_P(InstructionSelectorMemoryAccessUnalignedImmTest, StoreZero) { const MemoryAccessImm2 memacc = GetParam(); TRACED_FOREACH(int32_t, index, memacc.immediates) { StreamBuilder m(this, MachineType::Int32(), MachineType::Pointer()); - bool unaligned_store_supported = m.machine()->UnalignedStoreSupported( - MachineType::TypeForRepresentation(memacc.type.representation()), 1); + bool unaligned_store_supported = + m.machine()->UnalignedStoreSupported(memacc.type.representation()); m.UnalignedStore(memacc.type.representation(), m.Parameter(0), m.Int32Constant(index), m.Int32Constant(0)); m.Return(m.Int32Constant(0)); diff --git a/deps/v8/test/unittests/compiler/node-test-utils.cc b/deps/v8/test/unittests/compiler/node-test-utils.cc index 764a4da2d7..0e903f9c76 100644 --- a/deps/v8/test/unittests/compiler/node-test-utils.cc +++ b/deps/v8/test/unittests/compiler/node-test-utils.cc @@ -966,132 +966,6 @@ class IsStoreFieldMatcher final : public NodeMatcher { const Matcher<Node*> control_matcher_; }; - -class IsLoadBufferMatcher final : public NodeMatcher { - public: - IsLoadBufferMatcher(const Matcher<BufferAccess>& access_matcher, - const Matcher<Node*>& buffer_matcher, - const Matcher<Node*>& offset_matcher, - const Matcher<Node*>& length_matcher, - const Matcher<Node*>& effect_matcher, - const Matcher<Node*>& control_matcher) - : NodeMatcher(IrOpcode::kLoadBuffer), - access_matcher_(access_matcher), - buffer_matcher_(buffer_matcher), - offset_matcher_(offset_matcher), - length_matcher_(length_matcher), - effect_matcher_(effect_matcher), - control_matcher_(control_matcher) {} - - void DescribeTo(std::ostream* os) const final { - NodeMatcher::DescribeTo(os); - *os << " whose access ("; - access_matcher_.DescribeTo(os); - *os << "), buffer ("; - buffer_matcher_.DescribeTo(os); - *os << "), offset ("; - offset_matcher_.DescribeTo(os); - *os << "), length ("; - length_matcher_.DescribeTo(os); - *os << "), effect ("; - effect_matcher_.DescribeTo(os); - *os << ") and control ("; - control_matcher_.DescribeTo(os); - *os << ")"; - } - - bool MatchAndExplain(Node* node, MatchResultListener* listener) const final { - return (NodeMatcher::MatchAndExplain(node, listener) && - PrintMatchAndExplain(BufferAccessOf(node->op()), "access", - access_matcher_, listener) && - PrintMatchAndExplain(NodeProperties::GetValueInput(node, 0), - "buffer", buffer_matcher_, listener) && - PrintMatchAndExplain(NodeProperties::GetValueInput(node, 1), - "offset", offset_matcher_, listener) && - PrintMatchAndExplain(NodeProperties::GetValueInput(node, 2), - "length", length_matcher_, listener) && - PrintMatchAndExplain(NodeProperties::GetEffectInput(node), "effect", - effect_matcher_, listener) && - PrintMatchAndExplain(NodeProperties::GetControlInput(node), - "control", control_matcher_, listener)); - } - - private: - const Matcher<BufferAccess> access_matcher_; - const Matcher<Node*> buffer_matcher_; - const Matcher<Node*> offset_matcher_; - const Matcher<Node*> length_matcher_; - const Matcher<Node*> effect_matcher_; - const Matcher<Node*> control_matcher_; -}; - - -class IsStoreBufferMatcher final : public NodeMatcher { - public: - IsStoreBufferMatcher(const Matcher<BufferAccess>& access_matcher, - const Matcher<Node*>& buffer_matcher, - const Matcher<Node*>& offset_matcher, - const Matcher<Node*>& length_matcher, - const Matcher<Node*>& value_matcher, - const Matcher<Node*>& effect_matcher, - const Matcher<Node*>& control_matcher) - : NodeMatcher(IrOpcode::kStoreBuffer), - access_matcher_(access_matcher), - buffer_matcher_(buffer_matcher), - offset_matcher_(offset_matcher), - length_matcher_(length_matcher), - value_matcher_(value_matcher), - effect_matcher_(effect_matcher), - control_matcher_(control_matcher) {} - - void DescribeTo(std::ostream* os) const final { - NodeMatcher::DescribeTo(os); - *os << " whose access ("; - access_matcher_.DescribeTo(os); - *os << "), buffer ("; - buffer_matcher_.DescribeTo(os); - *os << "), offset ("; - offset_matcher_.DescribeTo(os); - *os << "), length ("; - length_matcher_.DescribeTo(os); - *os << "), value ("; - value_matcher_.DescribeTo(os); - *os << "), effect ("; - effect_matcher_.DescribeTo(os); - *os << ") and control ("; - control_matcher_.DescribeTo(os); - *os << ")"; - } - - bool MatchAndExplain(Node* node, MatchResultListener* listener) const final { - return (NodeMatcher::MatchAndExplain(node, listener) && - PrintMatchAndExplain(BufferAccessOf(node->op()), "access", - access_matcher_, listener) && - PrintMatchAndExplain(NodeProperties::GetValueInput(node, 0), - "buffer", buffer_matcher_, listener) && - PrintMatchAndExplain(NodeProperties::GetValueInput(node, 1), - "offset", offset_matcher_, listener) && - PrintMatchAndExplain(NodeProperties::GetValueInput(node, 2), - "length", length_matcher_, listener) && - PrintMatchAndExplain(NodeProperties::GetValueInput(node, 3), - "value", value_matcher_, listener) && - PrintMatchAndExplain(NodeProperties::GetEffectInput(node), "effect", - effect_matcher_, listener) && - PrintMatchAndExplain(NodeProperties::GetControlInput(node), - "control", control_matcher_, listener)); - } - - private: - const Matcher<BufferAccess> access_matcher_; - const Matcher<Node*> buffer_matcher_; - const Matcher<Node*> offset_matcher_; - const Matcher<Node*> length_matcher_; - const Matcher<Node*> value_matcher_; - const Matcher<Node*> effect_matcher_; - const Matcher<Node*> control_matcher_; -}; - - class IsLoadElementMatcher final : public NodeMatcher { public: IsLoadElementMatcher(const Matcher<ElementAccess>& access_matcher, @@ -2088,32 +1962,6 @@ Matcher<Node*> IsStoreField(const Matcher<FieldAccess>& access_matcher, control_matcher)); } - -Matcher<Node*> IsLoadBuffer(const Matcher<BufferAccess>& access_matcher, - const Matcher<Node*>& buffer_matcher, - const Matcher<Node*>& offset_matcher, - const Matcher<Node*>& length_matcher, - const Matcher<Node*>& effect_matcher, - const Matcher<Node*>& control_matcher) { - return MakeMatcher(new IsLoadBufferMatcher(access_matcher, buffer_matcher, - offset_matcher, length_matcher, - effect_matcher, control_matcher)); -} - - -Matcher<Node*> IsStoreBuffer(const Matcher<BufferAccess>& access_matcher, - const Matcher<Node*>& buffer_matcher, - const Matcher<Node*>& offset_matcher, - const Matcher<Node*>& length_matcher, - const Matcher<Node*>& value_matcher, - const Matcher<Node*>& effect_matcher, - const Matcher<Node*>& control_matcher) { - return MakeMatcher(new IsStoreBufferMatcher( - access_matcher, buffer_matcher, offset_matcher, length_matcher, - value_matcher, effect_matcher, control_matcher)); -} - - Matcher<Node*> IsLoadElement(const Matcher<ElementAccess>& access_matcher, const Matcher<Node*>& base_matcher, const Matcher<Node*>& index_matcher, diff --git a/deps/v8/test/unittests/compiler/persistent-unittest.cc b/deps/v8/test/unittests/compiler/persistent-unittest.cc new file mode 100644 index 0000000000..d65eda0e88 --- /dev/null +++ b/deps/v8/test/unittests/compiler/persistent-unittest.cc @@ -0,0 +1,126 @@ +// 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 <tuple> + +#include "src/base/utils/random-number-generator.h" +#include "src/compiler/persistent-map.h" +#include "test/unittests/test-utils.h" + +namespace v8 { +namespace internal { +namespace compiler { + +// A random distribution that produces both small values and arbitrary numbers. +static int small_big_distr(base::RandomNumberGenerator* rand) { + return rand->NextInt() / std::max(1, rand->NextInt() / 100); +} + +TEST(PersistentMap, RefTest) { + base::RandomNumberGenerator rand(92834738); + AccountingAllocator allocator; + Zone zone(&allocator, ZONE_NAME); + std::vector<PersistentMap<int, int>> pers_maps; + pers_maps.emplace_back(&zone); + std::vector<std::map<int, int>> ref_maps(1); + for (int i = 0; i < 100000; ++i) { + if (rand.NextInt(2) == 0) { + // Read value; + int key = small_big_distr(&rand); + if (ref_maps[0].count(key) > 0) { + ASSERT_EQ(pers_maps[0].Get(key), ref_maps[0][key]); + } else { + ASSERT_EQ(pers_maps[0].Get(key), 0); + } + } + if (rand.NextInt(2) == 0) { + // Add value; + int key = small_big_distr(&rand); + int value = small_big_distr(&rand); + pers_maps[0].Set(key, value); + ref_maps[0][key] = value; + } + if (rand.NextInt(1000) == 0) { + // Create empty map. + pers_maps.emplace_back(&zone); + ref_maps.emplace_back(); + } + if (rand.NextInt(100) == 0) { + // Copy and move around maps. + int num_maps = static_cast<int>(pers_maps.size()); + int source = rand.NextInt(num_maps - 1) + 1; + int target = rand.NextInt(num_maps - 1) + 1; + pers_maps[target] = std::move(pers_maps[0]); + ref_maps[target] = std::move(ref_maps[0]); + pers_maps[0] = pers_maps[source]; + ref_maps[0] = ref_maps[source]; + } + } + for (size_t i = 0; i < pers_maps.size(); ++i) { + std::set<int> keys; + for (auto pair : pers_maps[i]) { + ASSERT_EQ(keys.count(pair.first), 0u); + keys.insert(pair.first); + ASSERT_EQ(ref_maps[i][pair.first], pair.second); + } + for (auto pair : ref_maps[i]) { + int value = pers_maps[i].Get(pair.first); + ASSERT_EQ(pair.second, value); + if (value != 0) { + ASSERT_EQ(keys.count(pair.first), 1u); + keys.erase(pair.first); + } + } + ASSERT_TRUE(keys.empty()); + } +} + +TEST(PersistentMap, Zip) { + base::RandomNumberGenerator rand(92834738); + AccountingAllocator allocator; + Zone zone(&allocator, ZONE_NAME); + + // Provoke hash collisions to stress the iterator. + struct bad_hash { + size_t operator()(int key) { return static_cast<size_t>(key) % 1000; } + }; + PersistentMap<int, int, bad_hash> a(&zone); + PersistentMap<int, int, bad_hash> b(&zone); + + int sum_a = 0; + int sum_b = 0; + + for (int i = 0; i < 30000; ++i) { + int key = small_big_distr(&rand); + int value = small_big_distr(&rand); + if (rand.NextBool()) { + sum_a += value; + a.Set(key, a.Get(key) + value); + } else { + sum_b += value; + b.Set(key, b.Get(key) + value); + } + } + + int sum = sum_a + sum_b; + + for (auto pair : a) { + sum_a -= pair.second; + } + ASSERT_EQ(0, sum_a); + + for (auto pair : b) { + sum_b -= pair.second; + } + ASSERT_EQ(0, sum_b); + + for (auto triple : a.Zip(b)) { + sum -= std::get<1>(triple) + std::get<2>(triple); + } + ASSERT_EQ(0, sum); +} + +} // namespace compiler +} // namespace internal +} // namespace v8 diff --git a/deps/v8/test/unittests/compiler/simplified-operator-unittest.cc b/deps/v8/test/unittests/compiler/simplified-operator-unittest.cc index d32dcaec12..d77c762ce6 100644 --- a/deps/v8/test/unittests/compiler/simplified-operator-unittest.cc +++ b/deps/v8/test/unittests/compiler/simplified-operator-unittest.cc @@ -123,81 +123,6 @@ INSTANTIATE_TEST_CASE_P(SimplifiedOperatorTest, SimplifiedPureOperatorTest, // ----------------------------------------------------------------------------- -// Buffer access operators. - - -namespace { - -const ExternalArrayType kExternalArrayTypes[] = { - kExternalUint8Array, kExternalInt8Array, kExternalUint16Array, - kExternalInt16Array, kExternalUint32Array, kExternalInt32Array, - kExternalFloat32Array, kExternalFloat64Array}; - -} // namespace - - -class SimplifiedBufferAccessOperatorTest - : public TestWithZone, - public ::testing::WithParamInterface<ExternalArrayType> {}; - - -TEST_P(SimplifiedBufferAccessOperatorTest, InstancesAreGloballyShared) { - BufferAccess const access(GetParam()); - SimplifiedOperatorBuilder simplified1(zone()); - SimplifiedOperatorBuilder simplified2(zone()); - EXPECT_EQ(simplified1.LoadBuffer(access), simplified2.LoadBuffer(access)); - EXPECT_EQ(simplified1.StoreBuffer(access), simplified2.StoreBuffer(access)); -} - - -TEST_P(SimplifiedBufferAccessOperatorTest, LoadBuffer) { - SimplifiedOperatorBuilder simplified(zone()); - BufferAccess const access(GetParam()); - const Operator* op = simplified.LoadBuffer(access); - - EXPECT_EQ(IrOpcode::kLoadBuffer, op->opcode()); - EXPECT_EQ(Operator::kNoDeopt | Operator::kNoThrow | Operator::kNoWrite, - op->properties()); - EXPECT_EQ(access, BufferAccessOf(op)); - - EXPECT_EQ(3, op->ValueInputCount()); - EXPECT_EQ(1, op->EffectInputCount()); - EXPECT_EQ(1, op->ControlInputCount()); - EXPECT_EQ(5, OperatorProperties::GetTotalInputCount(op)); - - EXPECT_EQ(1, op->ValueOutputCount()); - EXPECT_EQ(1, op->EffectOutputCount()); - EXPECT_EQ(0, op->ControlOutputCount()); -} - - -TEST_P(SimplifiedBufferAccessOperatorTest, StoreBuffer) { - SimplifiedOperatorBuilder simplified(zone()); - BufferAccess const access(GetParam()); - const Operator* op = simplified.StoreBuffer(access); - - EXPECT_EQ(IrOpcode::kStoreBuffer, op->opcode()); - EXPECT_EQ(Operator::kNoDeopt | Operator::kNoRead | Operator::kNoThrow, - op->properties()); - EXPECT_EQ(access, BufferAccessOf(op)); - - EXPECT_EQ(4, op->ValueInputCount()); - EXPECT_EQ(1, op->EffectInputCount()); - EXPECT_EQ(1, op->ControlInputCount()); - EXPECT_EQ(6, OperatorProperties::GetTotalInputCount(op)); - - EXPECT_EQ(0, op->ValueOutputCount()); - EXPECT_EQ(1, op->EffectOutputCount()); - EXPECT_EQ(0, op->ControlOutputCount()); -} - - -INSTANTIATE_TEST_CASE_P(SimplifiedOperatorTest, - SimplifiedBufferAccessOperatorTest, - ::testing::ValuesIn(kExternalArrayTypes)); - - -// ----------------------------------------------------------------------------- // Element access operators. diff --git a/deps/v8/test/unittests/compiler/typed-optimization-unittest.cc b/deps/v8/test/unittests/compiler/typed-optimization-unittest.cc index 4b583fd461..820ef56e60 100644 --- a/deps/v8/test/unittests/compiler/typed-optimization-unittest.cc +++ b/deps/v8/test/unittests/compiler/typed-optimization-unittest.cc @@ -72,9 +72,7 @@ class TypedOptimizationTest : public TypedGraphTest { &machine); // TODO(titzer): mock the GraphReducer here for better unit testing. GraphReducer graph_reducer(zone(), graph()); - TypedOptimization reducer(&graph_reducer, &deps_, - TypedOptimization::kDeoptimizationEnabled, - &jsgraph); + TypedOptimization reducer(&graph_reducer, &deps_, &jsgraph); return reducer.Reduce(node); } |