Commit 22028463 authored by klaasb's avatar klaasb Committed by Commit bot

[interpreter] Add a register operand to ToNumber

ToNumber's result is always directly stored to a register using a Star
bytecode. Fuse it into ToNumber.

BUG=v8:4280
LOG=n

Review-Url: https://codereview.chromium.org/2165953002
Cr-Commit-Position: refs/heads/master@{#37976}
parent c8a0dce9
......@@ -1319,7 +1319,11 @@ void BytecodeGraphBuilder::VisitToObject() {
}
void BytecodeGraphBuilder::VisitToNumber() {
BuildCastOperator(javascript()->ToNumber());
FrameStateBeforeAndAfter states(this);
Node* value =
NewNode(javascript()->ToNumber(), environment()->LookupAccumulator());
environment()->BindRegister(bytecode_iterator().GetRegisterOperand(0), value,
&states);
}
void BytecodeGraphBuilder::VisitJump() { BuildJump(); }
......
......@@ -387,8 +387,9 @@ BytecodeArrayBuilder& BytecodeArrayBuilder::CastAccumulatorToName() {
return *this;
}
BytecodeArrayBuilder& BytecodeArrayBuilder::CastAccumulatorToNumber() {
Output(Bytecode::kToNumber);
BytecodeArrayBuilder& BytecodeArrayBuilder::CastAccumulatorToNumber(
Register out) {
Output(Bytecode::kToNumber, RegisterOperand(out));
return *this;
}
......
......@@ -215,7 +215,8 @@ class BytecodeArrayBuilder final : public ZoneObject {
BytecodeArrayBuilder& CastAccumulatorToBoolean();
BytecodeArrayBuilder& CastAccumulatorToJSObject();
BytecodeArrayBuilder& CastAccumulatorToName();
BytecodeArrayBuilder& CastAccumulatorToNumber();
// Does not update the accumulator but stores to |out| instead.
BytecodeArrayBuilder& CastAccumulatorToNumber(Register out);
// Flow Control.
BytecodeArrayBuilder& Bind(BytecodeLabel* label);
......
......@@ -2790,7 +2790,7 @@ void BytecodeGenerator::VisitCountOperation(CountOperation* expr) {
old_value = register_allocator()->outer()->NewRegister();
// Convert old value into a number before saving it.
builder()->CastAccumulatorToNumber().StoreAccumulatorInRegister(old_value);
builder()->CastAccumulatorToNumber(old_value);
}
// Perform +1/-1 operation.
......
......@@ -212,7 +212,7 @@ namespace interpreter {
\
/* Cast operators */ \
V(ToName, AccumulatorUse::kReadWrite) \
V(ToNumber, AccumulatorUse::kReadWrite) \
V(ToNumber, AccumulatorUse::kRead, OperandType::kRegOut) \
V(ToObject, AccumulatorUse::kReadWrite) \
\
/* Literals */ \
......
......@@ -997,13 +997,17 @@ void Interpreter::DoShiftRightSmi(InterpreterAssembler* assembler) {
__ Dispatch();
}
void Interpreter::DoUnaryOp(Callable callable,
InterpreterAssembler* assembler) {
Node* Interpreter::BuildUnaryOp(Callable callable,
InterpreterAssembler* assembler) {
Node* target = __ HeapConstant(callable.code());
Node* accumulator = __ GetAccumulator();
Node* context = __ GetContext();
Node* result =
__ CallStub(callable.descriptor(), target, context, accumulator);
return __ CallStub(callable.descriptor(), target, context, accumulator);
}
void Interpreter::DoUnaryOp(Callable callable,
InterpreterAssembler* assembler) {
Node* result = BuildUnaryOp(callable, assembler);
__ SetAccumulator(result);
__ Dispatch();
}
......@@ -1028,7 +1032,9 @@ void Interpreter::DoToName(InterpreterAssembler* assembler) {
//
// Cast the object referenced by the accumulator to a number.
void Interpreter::DoToNumber(InterpreterAssembler* assembler) {
DoUnaryOp(CodeFactory::ToNumber(isolate_), assembler);
Node* result = BuildUnaryOp(CodeFactory::ToNumber(isolate_), assembler);
__ StoreRegister(result, __ BytecodeOperandReg(0));
__ Dispatch();
}
// ToObject
......
......@@ -79,7 +79,8 @@ class Interpreter {
template <class Generator>
void DoBinaryOpWithImmediate(InterpreterAssembler* assembler);
// Generates code to perform the unary operation via |callable|.
// Generates code to perform the unary operation via |callable| and stores
// the result to the accumulator.
void DoUnaryOp(Callable callable, InterpreterAssembler* assembler);
// Generates code to perform the unary operation via |Generator|.
......@@ -152,6 +153,10 @@ class Interpreter {
compiler::Node* cache_length,
InterpreterAssembler* assembler);
// Generates code to perform the unary operation via |callable|.
compiler::Node* BuildUnaryOp(Callable callable,
InterpreterAssembler* assembler);
uintptr_t GetDispatchCounter(Bytecode from, Bytecode to) const;
// Get dispatch table index of bytecode.
......
......@@ -99,7 +99,7 @@ snippet: "
"
frame size: 3
parameter count: 1
bytecode array length: 29
bytecode array length: 28
bytecodes: [
/* 30 E> */ B(StackCheck),
/* 42 S> */ B(LdaSmi), U8(55),
......@@ -112,8 +112,7 @@ bytecodes: [
B(Star), R(0),
/* 68 E> */ B(Add), R(2),
B(Star), R(0),
/* 75 S> */ B(ToNumber),
B(Star), R(1),
/* 75 S> */ B(ToNumber), R(1),
B(Inc),
B(Star), R(0),
/* 80 S> */ B(Nop),
......@@ -246,7 +245,7 @@ snippet: "
"
frame size: 4
parameter count: 1
bytecode array length: 37
bytecode array length: 36
bytecodes: [
/* 30 E> */ B(StackCheck),
/* 42 S> */ B(LdaSmi), U8(17),
......@@ -257,8 +256,7 @@ bytecodes: [
/* 57 E> */ B(Add), R(1),
B(Star), R(2),
B(Ldar), R(0),
B(ToNumber),
B(Star), R(1),
B(ToNumber), R(1),
B(Inc),
B(Star), R(0),
B(Ldar), R(1),
......
......@@ -681,13 +681,13 @@ snippet: "
"
frame size: 7
parameter count: 1
bytecode array length: 119
bytecode array length: 118
bytecodes: [
/* 30 E> */ B(StackCheck),
/* 42 S> */ B(LdaZero),
B(Star), R(1),
/* 52 S> */ B(Ldar), R(1),
B(JumpIfToBooleanFalse), U8(111),
B(JumpIfToBooleanFalse), U8(110),
/* 45 E> */ B(StackCheck),
B(LdaConstant), U8(0),
B(Star), R(4),
......@@ -714,14 +714,13 @@ bytecodes: [
B(JumpIfToBooleanFalse), U8(8),
/* 113 S> */ B(PopContext), R(3),
B(PopContext), R(3),
B(Jump), U8(43),
B(Jump), U8(42),
/* 126 S> */ B(LdaContextSlot), R(context), U8(4),
B(JumpIfNotHole), U8(11),
B(LdaConstant), U8(3),
B(Star), R(4),
B(CallRuntime), U16(Runtime::kThrowReferenceError), R(4), U8(1),
B(ToNumber),
B(Star), R(4),
B(ToNumber), R(4),
B(Inc),
B(Star), R(5),
/* 127 E> */ B(LdaContextSlot), R(context), U8(4),
......@@ -732,7 +731,7 @@ bytecodes: [
B(Ldar), R(5),
B(StaContextSlot), R(context), U8(4),
B(PopContext), R(3),
B(Jump), U8(-111),
B(Jump), U8(-110),
B(LdaUndefined),
/* 137 S> */ B(Return),
]
......
......@@ -33,13 +33,12 @@ snippet: "
"
frame size: 2
parameter count: 1
bytecode array length: 14
bytecode array length: 13
bytecodes: [
/* 30 E> */ B(StackCheck),
/* 42 S> */ B(LdaSmi), U8(1),
B(Star), R(0),
/* 45 S> */ B(ToNumber),
B(Star), R(1),
/* 45 S> */ B(ToNumber), R(1),
B(Inc),
B(Star), R(0),
B(Ldar), R(1),
......@@ -76,13 +75,12 @@ snippet: "
"
frame size: 2
parameter count: 1
bytecode array length: 14
bytecode array length: 13
bytecodes: [
/* 30 E> */ B(StackCheck),
/* 42 S> */ B(LdaSmi), U8(1),
B(Star), R(0),
/* 45 S> */ B(ToNumber),
B(Star), R(1),
/* 45 S> */ B(ToNumber), R(1),
B(Dec),
B(Star), R(0),
B(Ldar), R(1),
......@@ -99,15 +97,14 @@ snippet: "
"
frame size: 3
parameter count: 1
bytecode array length: 24
bytecode array length: 23
bytecodes: [
/* 30 E> */ B(StackCheck),
/* 42 S> */ B(CreateObjectLiteral), U8(0), U8(0), U8(1),
B(Star), R(1),
B(Star), R(0),
/* 54 S> */ B(LdaNamedProperty), R(0), U8(1), U8(1),
B(ToNumber),
B(Star), R(2),
B(ToNumber), R(2),
B(Inc),
/* 66 E> */ B(StaNamedPropertySloppy), R(0), U8(1), U8(3),
B(Ldar), R(2),
......@@ -150,7 +147,7 @@ snippet: "
"
frame size: 5
parameter count: 1
bytecode array length: 29
bytecode array length: 28
bytecodes: [
/* 30 E> */ B(StackCheck),
/* 45 S> */ B(LdaConstant), U8(0),
......@@ -160,8 +157,7 @@ bytecodes: [
B(Star), R(1),
/* 72 S> */ B(Ldar), R(0),
/* 81 E> */ B(LdaKeyedProperty), R(1), U8(1),
B(ToNumber),
B(Star), R(4),
B(ToNumber), R(4),
B(Dec),
/* 86 E> */ B(StaKeyedPropertySloppy), R(1), R(0), U8(3),
B(Ldar), R(4),
......@@ -233,7 +229,7 @@ snippet: "
"
frame size: 3
parameter count: 1
bytecode array length: 31
bytecode array length: 30
bytecodes: [
B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), U8(1),
B(PushContext), R(1),
......@@ -243,8 +239,7 @@ bytecodes: [
/* 53 S> */ B(CreateClosure), U8(0), U8(2),
B(Star), R(0),
/* 78 S> */ B(LdaContextSlot), R(context), U8(4),
B(ToNumber),
B(Star), R(2),
B(ToNumber), R(2),
B(Dec),
/* 86 E> */ B(StaContextSlot), R(context), U8(4),
B(Ldar), R(2),
......@@ -262,7 +257,7 @@ snippet: "
"
frame size: 4
parameter count: 1
bytecode array length: 26
bytecode array length: 25
bytecodes: [
/* 30 E> */ B(StackCheck),
/* 44 S> */ B(LdaSmi), U8(1),
......@@ -270,8 +265,7 @@ bytecodes: [
/* 55 S> */ B(CreateArrayLiteral), U8(0), U8(0), U8(3),
B(Star), R(1),
/* 63 S> */ B(Ldar), R(0),
B(ToNumber),
B(Star), R(3),
B(ToNumber), R(3),
B(Inc),
B(Star), R(0),
B(LdaSmi), U8(2),
......
......@@ -38,12 +38,11 @@ snippet: "
"
frame size: 1
parameter count: 1
bytecode array length: 13
bytecode array length: 12
bytecodes: [
/* 26 E> */ B(StackCheck),
/* 31 S> */ B(LdaGlobal), U8(1),
B(ToNumber),
B(Star), R(0),
B(ToNumber), R(0),
B(Dec),
/* 44 E> */ B(StaGlobalSloppy), U8(0), U8(3),
B(Ldar), R(0),
......@@ -85,12 +84,11 @@ snippet: "
"
frame size: 1
parameter count: 1
bytecode array length: 13
bytecode array length: 12
bytecodes: [
/* 27 E> */ B(StackCheck),
/* 32 S> */ B(LdaGlobal), U8(1),
B(ToNumber),
B(Star), R(0),
B(ToNumber), R(0),
B(Inc),
/* 50 E> */ B(StaGlobalSloppy), U8(0), U8(3),
B(Ldar), R(0),
......
......@@ -329,7 +329,7 @@ snippet: "
"
frame size: 3
parameter count: 1
bytecode array length: 1410
bytecode array length: 1409
bytecodes: [
/* 30 E> */ B(StackCheck),
/* 42 S> */ B(LdaConstant), U8(0),
......@@ -960,7 +960,7 @@ bytecodes: [
B(Star), R(1),
/* 4108 S> */ B(LdaSmi), U8(3),
/* 4108 E> */ B(TestLessThan), R(1),
B(Wide), B(JumpIfFalse), U16(38),
B(Wide), B(JumpIfFalse), U16(37),
/* 4090 E> */ B(StackCheck),
/* 4122 S> */ B(LdaSmi), U8(1),
/* 4128 E> */ B(TestEqual), R(1),
......@@ -969,13 +969,12 @@ bytecodes: [
/* 4146 S> */ B(LdaSmi), U8(2),
/* 4152 E> */ B(TestEqual), R(1),
B(Wide), B(JumpIfFalse), U16(7),
/* 4158 S> */ B(Wide), B(Jump), U16(13),
/* 4158 S> */ B(Wide), B(Jump), U16(12),
/* 4114 S> */ B(Ldar), R(1),
B(ToNumber),
B(Star), R(2),
B(ToNumber), R(2),
B(Inc),
B(Star), R(1),
B(Jump), U8(-41),
B(Jump), U8(-40),
/* 4167 S> */ B(LdaSmi), U8(3),
/* 4177 S> */ B(Return),
]
......
......@@ -893,7 +893,7 @@ snippet: "
"
frame size: 158
parameter count: 1
bytecode array length: 56
bytecode array length: 55
bytecodes: [
/* 30 E> */ B(StackCheck),
/* 1503 S> */ B(LdaZero),
......@@ -904,18 +904,17 @@ bytecodes: [
B(Wide), B(Star), R16(128),
/* 1538 S> */ B(LdaSmi), U8(64),
/* 1538 E> */ B(Wide), B(TestLessThan), R16(128),
B(JumpIfFalse), U8(33),
B(JumpIfFalse), U8(32),
/* 1518 E> */ B(StackCheck),
/* 1555 S> */ B(Wide), B(Ldar), R16(128),
/* 1561 E> */ B(Add), R(1),
B(Wide), B(Mov), R16(1), R16(157),
B(Star), R(1),
/* 1548 S> */ B(Wide), B(Ldar), R16(128),
B(ToNumber),
B(Wide), B(Star), R16(157),
B(Wide), B(ToNumber), R16(157),
B(Inc),
B(Wide), B(Star), R16(128),
B(Jump), U8(-37),
B(Jump), U8(-36),
/* 1567 S> */ B(Wide), B(Ldar), R16(128),
/* 1580 S> */ B(Return),
]
......
......@@ -180,7 +180,7 @@ TEST_F(BytecodeArrayBuilderTest, AllBytecodesGenerated) {
.CompareOperation(Token::Value::IN, reg);
// Emit cast operator invocations.
builder.CastAccumulatorToNumber()
builder.CastAccumulatorToNumber(reg)
.CastAccumulatorToJSObject()
.CastAccumulatorToName();
......
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