| Index: test/unittests/compiler/bytecode-graph-builder-unittest.cc
|
| diff --git a/test/unittests/compiler/bytecode-graph-builder-unittest.cc b/test/unittests/compiler/bytecode-graph-builder-unittest.cc
|
| index 3135db022939b822b0331cfbac78b2b22942cc5c..4fdc7ca098149c01fad845d385ac10031211de12 100644
|
| --- a/test/unittests/compiler/bytecode-graph-builder-unittest.cc
|
| +++ b/test/unittests/compiler/bytecode-graph-builder-unittest.cc
|
| @@ -28,6 +28,41 @@ namespace compiler {
|
| static const LanguageMode kLanguageModes[] = {LanguageMode::SLOPPY,
|
| LanguageMode::STRICT};
|
|
|
| +static const Token::Value kBinaryOperators[] = {
|
| + Token::Value::BIT_OR, Token::Value::BIT_XOR, Token::Value::BIT_AND,
|
| + Token::Value::SHL, Token::Value::SAR, Token::Value::SHR,
|
| + Token::Value::ADD, Token::Value::SUB, Token::Value::MUL,
|
| + Token::Value::DIV, Token::Value::MOD};
|
| +
|
| +static IrOpcode::Value getIrOpcode(Token::Value token) {
|
| + switch (token) {
|
| + case Token::Value::BIT_OR:
|
| + return IrOpcode::Value::kJSBitwiseOr;
|
| + case Token::Value::BIT_XOR:
|
| + return IrOpcode::Value::kJSBitwiseXor;
|
| + case Token::Value::BIT_AND:
|
| + return IrOpcode::Value::kJSBitwiseAnd;
|
| + case Token::Value::SHL:
|
| + return IrOpcode::Value::kJSShiftLeft;
|
| + case Token::Value::SAR:
|
| + return IrOpcode::Value::kJSShiftRight;
|
| + case Token::Value::SHR:
|
| + return IrOpcode::Value::kJSShiftRightLogical;
|
| + case Token::Value::ADD:
|
| + return IrOpcode::Value::kJSAdd;
|
| + case Token::Value::SUB:
|
| + return IrOpcode::Value::kJSSubtract;
|
| + case Token::Value::MUL:
|
| + return IrOpcode::Value::kJSMultiply;
|
| + case Token::Value::DIV:
|
| + return IrOpcode::Value::kJSDivide;
|
| + case Token::Value::MOD:
|
| + return IrOpcode::Value::kJSModulus;
|
| + default:
|
| + UNREACHABLE();
|
| + }
|
| +}
|
| +
|
| Handle<TypeFeedbackVector> NewTypeFeedbackVector(Isolate* isolate,
|
| FeedbackVectorSpec* spec) {
|
| Handle<TypeFeedbackMetadata> vector_metadata =
|
| @@ -274,37 +309,115 @@ TEST_F(BytecodeGraphBuilderTest, SimpleExpressionWithParameters) {
|
| .Return();
|
|
|
| Graph* graph = GetCompletedGraph(array_builder.ToBytecodeArray());
|
| + Node* start = graph->start();
|
| Node* end = graph->end();
|
| EXPECT_EQ(1, end->InputCount());
|
| Node* ret = end->InputAt(0);
|
| // NB binary operation is <reg> <op> <acc>. The register represents
|
| // the left-hand side, which is why parameters appear in opposite
|
| // order to construction via the builder.
|
| - EXPECT_THAT(ret, IsReturn(IsJSAdd(IsParameter(2), IsParameter(1)), _, _));
|
| + Matcher<Node*> js_add_node = IsJSBinaryOperation(
|
| + IrOpcode::kJSAdd, IsParameter(2), IsParameter(1), start, start);
|
| + EXPECT_THAT(ret, IsReturn(js_add_node, _, _));
|
| }
|
|
|
|
|
| TEST_F(BytecodeGraphBuilderTest, SimpleExpressionWithRegister) {
|
| + TRACED_FOREACH(Token::Value, token, kBinaryOperators) {
|
| + interpreter::BytecodeArrayBuilder array_builder(isolate(), zone());
|
| + static const int kLeft = -655371;
|
| + static const int kRight = +2000000;
|
| + array_builder.set_locals_count(1);
|
| + array_builder.set_context_count(0);
|
| + array_builder.set_parameter_count(1);
|
| + array_builder.LoadLiteral(Smi::FromInt(kLeft))
|
| + .StoreAccumulatorInRegister(interpreter::Register(0))
|
| + .LoadLiteral(Smi::FromInt(kRight))
|
| + .BinaryOperation(token, interpreter::Register(0), Strength::WEAK)
|
| + .Return();
|
| +
|
| + Graph* graph = GetCompletedGraph(array_builder.ToBytecodeArray());
|
| + Node* end = graph->end();
|
| + EXPECT_EQ(1, end->InputCount());
|
| + Node* start = graph->start();
|
| + Node* ret = end->InputAt(0);
|
| + Matcher<Node*> compute_node =
|
| + IsJSBinaryOperation(getIrOpcode(token), IsNumberConstant(kLeft),
|
| + IsNumberConstant(kRight), start, start);
|
| + EXPECT_THAT(ret, IsReturn(compute_node, _, _));
|
| + }
|
| +}
|
| +
|
| +
|
| +TEST_F(BytecodeGraphBuilderTest, ToBoolean) {
|
| interpreter::BytecodeArrayBuilder array_builder(isolate(), zone());
|
| - static const int kLeft = -655371;
|
| - static const int kRight = +2000000;
|
| array_builder.set_locals_count(1);
|
| array_builder.set_context_count(0);
|
| - array_builder.set_parameter_count(1);
|
| - array_builder.LoadLiteral(Smi::FromInt(kLeft))
|
| - .StoreAccumulatorInRegister(interpreter::Register(0))
|
| - .LoadLiteral(Smi::FromInt(kRight))
|
| - .BinaryOperation(Token::Value::ADD, interpreter::Register(0),
|
| - Strength::WEAK)
|
| + array_builder.set_parameter_count(2);
|
| + array_builder.LoadAccumulatorWithRegister(array_builder.Parameter(1))
|
| + .CastAccumulatorToBoolean()
|
| .Return();
|
|
|
| Graph* graph = GetCompletedGraph(array_builder.ToBytecodeArray());
|
| - Node* end = graph->end();
|
| - EXPECT_EQ(1, end->InputCount());
|
| - Node* ret = end->InputAt(0);
|
| - EXPECT_THAT(
|
| - ret, IsReturn(IsJSAdd(IsNumberConstant(kLeft), IsNumberConstant(kRight)),
|
| - _, _));
|
| + Node* ret = graph->end()->InputAt(0);
|
| + Node* start = graph->start();
|
| +
|
| + Matcher<Node*> to_boolean_node = IsJSToBoolean(IsParameter(1), start);
|
| + EXPECT_THAT(ret, IsReturn(to_boolean_node, _, _));
|
| +}
|
| +
|
| +
|
| +TEST_F(BytecodeGraphBuilderTest, ToName) {
|
| + interpreter::BytecodeArrayBuilder array_builder(isolate(), zone());
|
| + array_builder.set_locals_count(1);
|
| + array_builder.set_context_count(0);
|
| + array_builder.set_parameter_count(2);
|
| + array_builder.LoadAccumulatorWithRegister(array_builder.Parameter(1))
|
| + .CastAccumulatorToName()
|
| + .Return();
|
| +
|
| + Graph* graph = GetCompletedGraph(array_builder.ToBytecodeArray());
|
| + Node* ret = graph->end()->InputAt(0);
|
| + Node* start = graph->start();
|
| +
|
| + Matcher<Node*> to_name_node = IsJSToName(IsParameter(1), start, start);
|
| + EXPECT_THAT(ret, IsReturn(to_name_node, _, _));
|
| +}
|
| +
|
| +
|
| +TEST_F(BytecodeGraphBuilderTest, ToObject) {
|
| + interpreter::BytecodeArrayBuilder array_builder(isolate(), zone());
|
| + array_builder.set_locals_count(1);
|
| + array_builder.set_context_count(0);
|
| + array_builder.set_parameter_count(2);
|
| + array_builder.LoadAccumulatorWithRegister(array_builder.Parameter(1))
|
| + .CastAccumulatorToJSObject()
|
| + .Return();
|
| +
|
| + Graph* graph = GetCompletedGraph(array_builder.ToBytecodeArray());
|
| + Node* ret = graph->end()->InputAt(0);
|
| + Node* start = graph->start();
|
| +
|
| + Matcher<Node*> to_object_node = IsJSToObject(IsParameter(1), start, start);
|
| + EXPECT_THAT(ret, IsReturn(to_object_node, _, _));
|
| +}
|
| +
|
| +
|
| +TEST_F(BytecodeGraphBuilderTest, ToNumber) {
|
| + interpreter::BytecodeArrayBuilder array_builder(isolate(), zone());
|
| + array_builder.set_locals_count(1);
|
| + array_builder.set_context_count(0);
|
| + array_builder.set_parameter_count(2);
|
| + array_builder.LoadAccumulatorWithRegister(array_builder.Parameter(1))
|
| + .CastAccumulatorToNumber()
|
| + .Return();
|
| +
|
| + Graph* graph = GetCompletedGraph(array_builder.ToBytecodeArray());
|
| + Node* ret = graph->end()->InputAt(0);
|
| + Node* start = graph->start();
|
| +
|
| + Matcher<Node*> to_number_node = IsToNumber(IsParameter(1), _, start, start);
|
| + EXPECT_THAT(ret, IsReturn(to_number_node, _, _));
|
| }
|
|
|
|
|
| @@ -541,8 +654,9 @@ TEST_F(BytecodeGraphBuilderTest, LogicalNot) {
|
| NewTypeFeedbackVector(isolate(), &feedback_spec);
|
| Graph* graph = GetCompletedGraph(array_builder.ToBytecodeArray(), vector);
|
|
|
| + Node* start = graph->start();
|
| Node* ret = graph->end()->InputAt(0);
|
| - EXPECT_THAT(ret, IsReturn(IsJSUnaryNot(IsParameter(1)), _, _));
|
| + EXPECT_THAT(ret, IsReturn(IsJSUnaryNot(IsParameter(1), start), _, _));
|
| }
|
|
|
|
|
| @@ -560,8 +674,9 @@ TEST_F(BytecodeGraphBuilderTest, TypeOf) {
|
| NewTypeFeedbackVector(isolate(), &feedback_spec);
|
| Graph* graph = GetCompletedGraph(array_builder.ToBytecodeArray(), vector);
|
|
|
| + Node* start = graph->start();
|
| Node* ret = graph->end()->InputAt(0);
|
| - EXPECT_THAT(ret, IsReturn(IsJSTypeOf(IsParameter(1)), _, _));
|
| + EXPECT_THAT(ret, IsReturn(IsJSTypeOf(IsParameter(1), start), _, _));
|
| }
|
|
|
|
|
|
|