From bf55951cddc1bb5152a9b41b8548ceee8e316303 Mon Sep 17 00:00:00 2001 From: Adam Klein Date: Mon, 11 Sep 2017 09:57:39 -0700 Subject: [PATCH] [bigint] Output ToNumber bytecode for unary plus As part of that change, make ToNumber return in the accumulator. Bug: v8:6791 Change-Id: I8ce0f4fbc7ad8ee7fb4a32a8a499394395010750 Reviewed-on: https://chromium-review.googlesource.com/658082 Reviewed-by: Ross McIlroy Reviewed-by: Georg Neis Commit-Queue: Adam Klein Cr-Commit-Position: refs/heads/master@{#47976} --- src/compiler/bytecode-graph-builder.cc | 5 ++- src/interpreter/bytecode-array-builder.cc | 5 ++- src/interpreter/bytecode-array-builder.h | 4 ++- src/interpreter/bytecode-generator.cc | 18 ++++++---- src/interpreter/bytecode-generator.h | 1 + src/interpreter/bytecodes.h | 2 +- src/interpreter/interpreter-generator.cc | 6 ++-- .../AssignmentsInBinaryExpression.golden | 6 ++-- .../CountOperators.golden | 36 +++++++++---------- .../GlobalCountOperators.golden | 12 +++---- .../bytecode_expectations/Modules.golden | 18 +++++----- .../UnaryOperators.golden | 4 +-- .../bytecode-array-builder-unittest.cc | 2 +- 13 files changed, 63 insertions(+), 56 deletions(-) diff --git a/src/compiler/bytecode-graph-builder.cc b/src/compiler/bytecode-graph-builder.cc index 2da4bbcb02..b8ed7b69a8 100644 --- a/src/compiler/bytecode-graph-builder.cc +++ b/src/compiler/bytecode-graph-builder.cc @@ -2438,7 +2438,7 @@ void BytecodeGraphBuilder::VisitToNumber() { Node* object = environment()->LookupAccumulator(); FeedbackSlot slot = - feedback_vector()->ToSlot(bytecode_iterator().GetIndexOperand(1)); + feedback_vector()->ToSlot(bytecode_iterator().GetIndexOperand(0)); JSTypeHintLowering::LoweringResult lowering = TryBuildSimplifiedToNumber(object, slot); @@ -2450,8 +2450,7 @@ void BytecodeGraphBuilder::VisitToNumber() { node = NewNode(javascript()->ToNumber(), object); } - environment()->BindRegister(bytecode_iterator().GetRegisterOperand(0), node, - Environment::kAttachFrameState); + environment()->BindAccumulator(node, Environment::kAttachFrameState); } void BytecodeGraphBuilder::VisitJump() { BuildJump(); } diff --git a/src/interpreter/bytecode-array-builder.cc b/src/interpreter/bytecode-array-builder.cc index 667b276836..5400da63ab 100644 --- a/src/interpreter/bytecode-array-builder.cc +++ b/src/interpreter/bytecode-array-builder.cc @@ -994,9 +994,8 @@ BytecodeArrayBuilder& BytecodeArrayBuilder::ToName(Register out) { return *this; } -BytecodeArrayBuilder& BytecodeArrayBuilder::ToNumber(Register out, - int feedback_slot) { - OutputToNumber(out, feedback_slot); +BytecodeArrayBuilder& BytecodeArrayBuilder::ToNumber(int feedback_slot) { + OutputToNumber(feedback_slot); return *this; } diff --git a/src/interpreter/bytecode-array-builder.h b/src/interpreter/bytecode-array-builder.h index a01d710e91..fd33071460 100644 --- a/src/interpreter/bytecode-array-builder.h +++ b/src/interpreter/bytecode-array-builder.h @@ -353,7 +353,9 @@ class V8_EXPORT_PRIVATE BytecodeArrayBuilder final // Converts accumulator and stores result in register |out|. BytecodeArrayBuilder& ToObject(Register out); BytecodeArrayBuilder& ToName(Register out); - BytecodeArrayBuilder& ToNumber(Register out, int feedback_slot); + + // Converts accumulator and stores result back in accumulator. + BytecodeArrayBuilder& ToNumber(int feedback_slot); // Flow Control. BytecodeArrayBuilder& Bind(BytecodeLabel* label); diff --git a/src/interpreter/bytecode-generator.cc b/src/interpreter/bytecode-generator.cc index cb5e7fd025..b0a46a01b0 100644 --- a/src/interpreter/bytecode-generator.cc +++ b/src/interpreter/bytecode-generator.cc @@ -3429,6 +3429,12 @@ void BytecodeGenerator::VisitNot(UnaryOperation* expr) { } } +void BytecodeGenerator::VisitPlus(UnaryOperation* expr) { + VisitForAccumulatorValue(expr->expression()); + builder()->SetExpressionPosition(expr); + builder()->ToNumber(feedback_index(expr->UnaryOperationFeedbackSlot())); +} + void BytecodeGenerator::BuildBinaryOperationForUnaryOperation( UnaryOperation* expr, Token::Value binop, int rhs) { VisitForAccumulatorValue(expr->expression()); @@ -3452,11 +3458,11 @@ void BytecodeGenerator::VisitUnaryOperation(UnaryOperation* expr) { case Token::Value::DELETE: VisitDelete(expr); break; - // TODO(adamk): Output specific bytecodes for ADD, SUB, and BIT_NOT - // instead of transforming them to binary operations. case Token::Value::ADD: - BuildBinaryOperationForUnaryOperation(expr, Token::Value::MUL, 1); + VisitPlus(expr); break; + // TODO(adamk): Output specific bytecodes for SUB and BIT_NOT + // instead of transforming them to binary operations. case Token::Value::SUB: BuildBinaryOperationForUnaryOperation(expr, Token::Value::MUL, -1); break; @@ -3588,13 +3594,13 @@ void BytecodeGenerator::VisitCountOperation(CountOperation* expr) { // Save result for postfix expressions. FeedbackSlot count_slot = expr->CountBinaryOpFeedbackSlot(); if (is_postfix) { - // Convert old value into a number before saving it. old_value = register_allocator()->NewRegister(); + // Convert old value into a number before saving it. // TODO(ignition): Think about adding proper PostInc/PostDec bytecodes // instead of this ToNumber + Inc/Dec dance. builder() - ->ToNumber(old_value, feedback_index(count_slot)) - .LoadAccumulatorWithRegister(old_value); + ->ToNumber(feedback_index(count_slot)) + .StoreAccumulatorInRegister(old_value); } // Perform +1/-1 operation. diff --git a/src/interpreter/bytecode-generator.h b/src/interpreter/bytecode-generator.h index cdab3ccd50..38b39e6eef 100644 --- a/src/interpreter/bytecode-generator.h +++ b/src/interpreter/bytecode-generator.h @@ -78,6 +78,7 @@ class BytecodeGenerator final : public AstVisitor { void VisitTypeOf(UnaryOperation* expr); void VisitNot(UnaryOperation* expr); void VisitDelete(UnaryOperation* expr); + void VisitPlus(UnaryOperation* expr); // Visits a typeof expression for the value on which to perform the typeof. void VisitForTypeOfValue(Expression* expr); diff --git a/src/interpreter/bytecodes.h b/src/interpreter/bytecodes.h index 2e4eabf58b..9b7fc8295a 100644 --- a/src/interpreter/bytecodes.h +++ b/src/interpreter/bytecodes.h @@ -215,7 +215,7 @@ namespace interpreter { \ /* Cast operators */ \ V(ToName, AccumulatorUse::kRead, OperandType::kRegOut) \ - V(ToNumber, AccumulatorUse::kRead, OperandType::kRegOut, OperandType::kIdx) \ + V(ToNumber, AccumulatorUse::kReadWrite, OperandType::kIdx) \ V(ToObject, AccumulatorUse::kRead, OperandType::kRegOut) \ \ /* Literals */ \ diff --git a/src/interpreter/interpreter-generator.cc b/src/interpreter/interpreter-generator.cc index ec8c3878ac..33064c55cd 100644 --- a/src/interpreter/interpreter-generator.cc +++ b/src/interpreter/interpreter-generator.cc @@ -1225,7 +1225,7 @@ IGNITION_HANDLER(ToName, InterpreterAssembler) { Dispatch(); } -// ToNumber +// ToNumber // // Convert the object referenced by the accumulator to a number. IGNITION_HANDLER(ToNumber, InterpreterAssembler) { @@ -1264,13 +1264,13 @@ IGNITION_HANDLER(ToNumber, InterpreterAssembler) { } BIND(&if_done); - StoreRegister(var_result.value(), BytecodeOperandReg(0)); // Record the type feedback collected for {object}. - Node* slot_index = BytecodeOperandIdx(1); + Node* slot_index = BytecodeOperandIdx(0); Node* feedback_vector = LoadFeedbackVector(); UpdateFeedback(var_type_feedback.value(), feedback_vector, slot_index); + SetAccumulator(var_result.value()); Dispatch(); } diff --git a/test/cctest/interpreter/bytecode_expectations/AssignmentsInBinaryExpression.golden b/test/cctest/interpreter/bytecode_expectations/AssignmentsInBinaryExpression.golden index dd55ae9856..925795a673 100644 --- a/test/cctest/interpreter/bytecode_expectations/AssignmentsInBinaryExpression.golden +++ b/test/cctest/interpreter/bytecode_expectations/AssignmentsInBinaryExpression.golden @@ -238,7 +238,7 @@ snippet: " " frame size: 3 parameter count: 1 -bytecode array length: 44 +bytecode array length: 43 bytecodes: [ /* 30 E> */ B(StackCheck), /* 42 S> */ B(LdaSmi), I8(17), @@ -249,8 +249,8 @@ bytecodes: [ /* 55 E> */ B(Add), R(1), U8(0), B(Star), R(1), B(Ldar), R(0), - B(ToNumber), R(2), U8(1), - B(Ldar), R(2), + B(ToNumber), U8(1), + B(Star), R(2), B(Inc), U8(1), B(Star), R(0), B(Ldar), R(2), diff --git a/test/cctest/interpreter/bytecode_expectations/CountOperators.golden b/test/cctest/interpreter/bytecode_expectations/CountOperators.golden index 87dcbfdb4b..2aefc7a142 100644 --- a/test/cctest/interpreter/bytecode_expectations/CountOperators.golden +++ b/test/cctest/interpreter/bytecode_expectations/CountOperators.golden @@ -31,13 +31,13 @@ snippet: " " frame size: 2 parameter count: 1 -bytecode array length: 17 +bytecode array length: 16 bytecodes: [ /* 30 E> */ B(StackCheck), /* 42 S> */ B(LdaSmi), I8(1), B(Star), R(0), - /* 45 S> */ B(ToNumber), R(1), U8(0), - B(Ldar), R(1), + /* 45 S> */ B(ToNumber), U8(0), + B(Star), R(1), B(Inc), U8(0), B(Star), R(0), B(Ldar), R(1), @@ -74,13 +74,13 @@ snippet: " " frame size: 2 parameter count: 1 -bytecode array length: 17 +bytecode array length: 16 bytecodes: [ /* 30 E> */ B(StackCheck), /* 42 S> */ B(LdaSmi), I8(1), B(Star), R(0), - /* 45 S> */ B(ToNumber), R(1), U8(0), - B(Ldar), R(1), + /* 45 S> */ B(ToNumber), U8(0), + B(Star), R(1), B(Dec), U8(0), B(Star), R(0), B(Ldar), R(1), @@ -97,14 +97,14 @@ snippet: " " frame size: 3 parameter count: 1 -bytecode array length: 27 +bytecode array length: 26 bytecodes: [ /* 30 E> */ B(StackCheck), /* 42 S> */ B(CreateObjectLiteral), U8(0), U8(0), U8(41), R(1), B(Mov), R(1), R(0), /* 54 S> */ B(LdaNamedProperty), R(1), U8(1), U8(1), - B(ToNumber), R(2), U8(5), - B(Ldar), R(2), + B(ToNumber), U8(5), + B(Star), R(2), B(Inc), U8(5), /* 66 E> */ B(StaNamedProperty), R(1), U8(1), U8(3), B(Ldar), R(2), @@ -146,7 +146,7 @@ snippet: " " frame size: 5 parameter count: 1 -bytecode array length: 32 +bytecode array length: 31 bytecodes: [ /* 30 E> */ B(StackCheck), /* 45 S> */ B(LdaConstant), U8(0), @@ -155,8 +155,8 @@ bytecodes: [ B(Mov), R(2), R(1), /* 72 S> */ B(Ldar), R(0), /* 81 E> */ B(LdaKeyedProperty), R(2), U8(1), - B(ToNumber), R(4), U8(5), - B(Ldar), R(4), + B(ToNumber), U8(5), + B(Star), R(4), B(Dec), U8(5), /* 86 E> */ B(StaKeyedProperty), R(2), R(0), U8(3), B(Ldar), R(4), @@ -227,7 +227,7 @@ snippet: " " frame size: 3 parameter count: 1 -bytecode array length: 29 +bytecode array length: 28 bytecodes: [ B(CreateFunctionContext), U8(1), B(PushContext), R(1), @@ -237,8 +237,8 @@ bytecodes: [ /* 53 S> */ B(CreateClosure), U8(0), U8(0), U8(2), B(Star), R(0), /* 78 S> */ B(LdaCurrentContextSlot), U8(4), - B(ToNumber), R(2), U8(1), - B(Ldar), R(2), + B(ToNumber), U8(1), + B(Star), R(2), B(Dec), U8(1), /* 86 E> */ B(StaCurrentContextSlot), U8(4), B(Ldar), R(2), @@ -256,7 +256,7 @@ snippet: " " frame size: 4 parameter count: 1 -bytecode array length: 29 +bytecode array length: 28 bytecodes: [ /* 30 E> */ B(StackCheck), /* 44 S> */ B(LdaSmi), I8(1), @@ -264,8 +264,8 @@ bytecodes: [ /* 55 S> */ B(CreateArrayLiteral), U8(0), U8(0), U8(37), B(Star), R(1), /* 63 S> */ B(Ldar), R(0), - B(ToNumber), R(3), U8(1), - B(Ldar), R(3), + B(ToNumber), U8(1), + B(Star), R(3), B(Inc), U8(1), B(Star), R(0), B(LdaSmi), I8(2), diff --git a/test/cctest/interpreter/bytecode_expectations/GlobalCountOperators.golden b/test/cctest/interpreter/bytecode_expectations/GlobalCountOperators.golden index 0068d80e71..2e0b987b22 100644 --- a/test/cctest/interpreter/bytecode_expectations/GlobalCountOperators.golden +++ b/test/cctest/interpreter/bytecode_expectations/GlobalCountOperators.golden @@ -36,12 +36,12 @@ snippet: " " frame size: 1 parameter count: 1 -bytecode array length: 17 +bytecode array length: 16 bytecodes: [ /* 26 E> */ B(StackCheck), /* 31 S> */ B(LdaGlobal), U8(0), U8(0), - B(ToNumber), R(0), U8(4), - B(Ldar), R(0), + B(ToNumber), U8(4), + B(Star), R(0), B(Dec), U8(4), /* 44 E> */ B(StaGlobalSloppy), U8(0), U8(2), B(Ldar), R(0), @@ -83,12 +83,12 @@ snippet: " " frame size: 1 parameter count: 1 -bytecode array length: 17 +bytecode array length: 16 bytecodes: [ /* 27 E> */ B(StackCheck), /* 32 S> */ B(LdaGlobal), U8(0), U8(0), - B(ToNumber), R(0), U8(4), - B(Ldar), R(0), + B(ToNumber), U8(4), + B(Star), R(0), B(Inc), U8(4), /* 50 E> */ B(StaGlobalSloppy), U8(0), U8(2), B(Ldar), R(0), diff --git a/test/cctest/interpreter/bytecode_expectations/Modules.golden b/test/cctest/interpreter/bytecode_expectations/Modules.golden index 3519d2752c..f4021d1d78 100644 --- a/test/cctest/interpreter/bytecode_expectations/Modules.golden +++ b/test/cctest/interpreter/bytecode_expectations/Modules.golden @@ -209,7 +209,7 @@ snippet: " " frame size: 5 parameter count: 2 -bytecode array length: 138 +bytecode array length: 137 bytecodes: [ B(Ldar), R(1), B(JumpIfUndefined), U8(18), @@ -259,8 +259,8 @@ bytecodes: [ /* 34 S> */ B(LdaUndefined), /* 34 E> */ B(StaCurrentContextSlot), U8(4), /* 39 S> */ B(LdaModuleVariable), I8(1), U8(1), - B(ToNumber), R(4), U8(1), - B(Ldar), R(4), + B(ToNumber), U8(1), + B(Star), R(4), B(Inc), U8(1), /* 42 E> */ B(StaModuleVariable), I8(1), U8(1), B(Ldar), R(4), @@ -287,7 +287,7 @@ snippet: " " frame size: 5 parameter count: 2 -bytecode array length: 142 +bytecode array length: 141 bytecodes: [ B(Ldar), R(1), B(JumpIfUndefined), U8(18), @@ -339,8 +339,8 @@ bytecodes: [ /* 34 S> */ B(LdaUndefined), /* 34 E> */ B(StaCurrentContextSlot), U8(4), /* 39 S> */ B(LdaModuleVariable), I8(1), U8(1), - B(ToNumber), R(4), U8(1), - B(Ldar), R(4), + B(ToNumber), U8(1), + B(Star), R(4), B(Inc), U8(1), /* 42 E> */ B(StaModuleVariable), I8(1), U8(1), B(Ldar), R(4), @@ -367,7 +367,7 @@ snippet: " " frame size: 5 parameter count: 2 -bytecode array length: 146 +bytecode array length: 145 bytecodes: [ B(Ldar), R(1), B(JumpIfUndefined), U8(18), @@ -419,8 +419,8 @@ bytecodes: [ /* 36 S> */ B(LdaUndefined), /* 36 E> */ B(StaCurrentContextSlot), U8(4), /* 41 S> */ B(LdaModuleVariable), I8(1), U8(1), - B(ToNumber), R(4), U8(1), - B(Ldar), R(4), + B(ToNumber), U8(1), + B(Star), R(4), B(Inc), U8(1), /* 44 E> */ B(CallRuntime), U16(Runtime::kThrowConstAssignError), R(0), U8(0), B(Ldar), R(4), diff --git a/test/cctest/interpreter/bytecode_expectations/UnaryOperators.golden b/test/cctest/interpreter/bytecode_expectations/UnaryOperators.golden index 8c6dc7d450..e6d07f6e55 100644 --- a/test/cctest/interpreter/bytecode_expectations/UnaryOperators.golden +++ b/test/cctest/interpreter/bytecode_expectations/UnaryOperators.golden @@ -139,12 +139,12 @@ snippet: " " frame size: 1 parameter count: 1 -bytecode array length: 9 +bytecode array length: 8 bytecodes: [ /* 30 E> */ B(StackCheck), /* 42 S> */ B(LdaSmi), I8(13), B(Star), R(0), - /* 53 S> */ B(MulSmi), I8(1), U8(0), + /* 53 S> */ B(ToNumber), U8(0), /* 56 S> */ B(Return), ] constant pool: [ diff --git a/test/unittests/interpreter/bytecode-array-builder-unittest.cc b/test/unittests/interpreter/bytecode-array-builder-unittest.cc index 10c77cfaf5..04e6ae30dc 100644 --- a/test/unittests/interpreter/bytecode-array-builder-unittest.cc +++ b/test/unittests/interpreter/bytecode-array-builder-unittest.cc @@ -221,7 +221,7 @@ TEST_F(BytecodeArrayBuilderTest, AllBytecodesGenerated) { .CompareNull(); // Emit conversion operator invocations. - builder.ToNumber(reg, 1).ToObject(reg).ToName(reg); + builder.ToNumber(1).ToObject(reg).ToName(reg); // Emit GetSuperConstructor. builder.GetSuperConstructor(reg);