Commit 776d4d87 authored by rmcilroy's avatar rmcilroy Committed by Commit bot

[Interpreter] Inline Inc/Dec code stubs into bytecode handlers.

BUG=v8:4280
LOG=N

Review-Url: https://codereview.chromium.org/1980463003
Cr-Commit-Position: refs/heads/master@{#36314}
parent 3560d9bd
......@@ -1651,25 +1651,27 @@ compiler::Node* BitwiseXorStub::Generate(CodeStubAssembler* assembler,
return result;
}
void IncStub::GenerateAssembly(CodeStubAssembler* assembler) const {
// static
compiler::Node* IncStub::Generate(CodeStubAssembler* assembler,
compiler::Node* value,
compiler::Node* context) {
typedef CodeStubAssembler::Label Label;
typedef compiler::Node Node;
typedef CodeStubAssembler::Variable Variable;
Node* context = assembler->Parameter(1);
// Shared entry for floating point increment.
Label do_finc(assembler);
Label do_finc(assembler), end(assembler);
Variable var_finc_value(assembler, MachineRepresentation::kFloat64);
// We might need to try again due to ToNumber conversion.
Variable value_var(assembler, MachineRepresentation::kTagged);
Variable result_var(assembler, MachineRepresentation::kTagged);
Label start(assembler, &value_var);
value_var.Bind(assembler->Parameter(0));
value_var.Bind(value);
assembler->Goto(&start);
assembler->Bind(&start);
{
Node* value = value_var.value();
value = value_var.value();
Label if_issmi(assembler), if_isnotsmi(assembler);
assembler->Branch(assembler->WordIsSmi(value), &if_issmi, &if_isnotsmi);
......@@ -1686,7 +1688,8 @@ void IncStub::GenerateAssembly(CodeStubAssembler* assembler) const {
assembler->Branch(overflow, &if_overflow, &if_notoverflow);
assembler->Bind(&if_notoverflow);
assembler->Return(assembler->Projection(0, pair));
result_var.Bind(assembler->Projection(0, pair));
assembler->Goto(&end);
assembler->Bind(&if_overflow);
{
......@@ -1715,7 +1718,8 @@ void IncStub::GenerateAssembly(CodeStubAssembler* assembler) const {
assembler->Bind(&if_valuenotnumber);
{
// Convert to a Number first and try again.
Callable callable = CodeFactory::NonNumberToNumber(isolate());
Callable callable =
CodeFactory::NonNumberToNumber(assembler->isolate());
value_var.Bind(assembler->CallStub(callable, context, value));
assembler->Goto(&start);
}
......@@ -1727,30 +1731,35 @@ void IncStub::GenerateAssembly(CodeStubAssembler* assembler) const {
Node* finc_value = var_finc_value.value();
Node* one = assembler->Float64Constant(1.0);
Node* finc_result = assembler->Float64Add(finc_value, one);
Node* result = assembler->ChangeFloat64ToTagged(finc_result);
assembler->Return(result);
result_var.Bind(assembler->ChangeFloat64ToTagged(finc_result));
assembler->Goto(&end);
}
assembler->Bind(&end);
return result_var.value();
}
void DecStub::GenerateAssembly(CodeStubAssembler* assembler) const {
// static
compiler::Node* DecStub::Generate(CodeStubAssembler* assembler,
compiler::Node* value,
compiler::Node* context) {
typedef CodeStubAssembler::Label Label;
typedef compiler::Node Node;
typedef CodeStubAssembler::Variable Variable;
Node* context = assembler->Parameter(1);
// Shared entry for floating point decrement.
Label do_fdec(assembler);
Label do_fdec(assembler), end(assembler);
Variable var_fdec_value(assembler, MachineRepresentation::kFloat64);
// We might need to try again due to ToNumber conversion.
Variable value_var(assembler, MachineRepresentation::kTagged);
Variable result_var(assembler, MachineRepresentation::kTagged);
Label start(assembler, &value_var);
value_var.Bind(assembler->Parameter(0));
value_var.Bind(value);
assembler->Goto(&start);
assembler->Bind(&start);
{
Node* value = value_var.value();
value = value_var.value();
Label if_issmi(assembler), if_isnotsmi(assembler);
assembler->Branch(assembler->WordIsSmi(value), &if_issmi, &if_isnotsmi);
......@@ -1767,7 +1776,8 @@ void DecStub::GenerateAssembly(CodeStubAssembler* assembler) const {
assembler->Branch(overflow, &if_overflow, &if_notoverflow);
assembler->Bind(&if_notoverflow);
assembler->Return(assembler->Projection(0, pair));
result_var.Bind(assembler->Projection(0, pair));
assembler->Goto(&end);
assembler->Bind(&if_overflow);
{
......@@ -1796,7 +1806,8 @@ void DecStub::GenerateAssembly(CodeStubAssembler* assembler) const {
assembler->Bind(&if_valuenotnumber);
{
// Convert to a Number first and try again.
Callable callable = CodeFactory::NonNumberToNumber(isolate());
Callable callable =
CodeFactory::NonNumberToNumber(assembler->isolate());
value_var.Bind(assembler->CallStub(callable, context, value));
assembler->Goto(&start);
}
......@@ -1808,9 +1819,12 @@ void DecStub::GenerateAssembly(CodeStubAssembler* assembler) const {
Node* fdec_value = var_fdec_value.value();
Node* one = assembler->Float64Constant(1.0);
Node* fdec_result = assembler->Float64Sub(fdec_value, one);
Node* result = assembler->ChangeFloat64ToTagged(fdec_result);
assembler->Return(result);
result_var.Bind(assembler->ChangeFloat64ToTagged(fdec_result));
assembler->Goto(&end);
}
assembler->Bind(&end);
return result_var.value();
}
void InstanceOfStub::GenerateAssembly(CodeStubAssembler* assembler) const {
......
......@@ -414,6 +414,17 @@ class CodeStub BASE_EMBEDDED {
} \
DEFINE_CODE_STUB(NAME, SUPER)
#define DEFINE_TURBOFAN_UNARY_OP_CODE_STUB(NAME, SUPER) \
public: \
static compiler::Node* Generate(CodeStubAssembler* assembler, \
compiler::Node* value, \
compiler::Node* context); \
void GenerateAssembly(CodeStubAssembler* assembler) const override { \
assembler->Return(Generate(assembler, assembler->Parameter(0), \
assembler->Parameter(1))); \
} \
DEFINE_CODE_STUB(NAME, SUPER)
#define DEFINE_HANDLER_CODE_STUB(NAME, SUPER) \
public: \
Handle<Code> GenerateCode() override; \
......@@ -782,7 +793,7 @@ class IncStub final : public TurboFanCodeStub {
explicit IncStub(Isolate* isolate) : TurboFanCodeStub(isolate) {}
DEFINE_CALL_INTERFACE_DESCRIPTOR(CountOp);
DEFINE_TURBOFAN_CODE_STUB(Inc, TurboFanCodeStub);
DEFINE_TURBOFAN_UNARY_OP_CODE_STUB(Inc, TurboFanCodeStub);
};
class DecStub final : public TurboFanCodeStub {
......@@ -790,7 +801,7 @@ class DecStub final : public TurboFanCodeStub {
explicit DecStub(Isolate* isolate) : TurboFanCodeStub(isolate) {}
DEFINE_CALL_INTERFACE_DESCRIPTOR(CountOp);
DEFINE_TURBOFAN_CODE_STUB(Dec, TurboFanCodeStub);
DEFINE_TURBOFAN_UNARY_OP_CODE_STUB(Dec, TurboFanCodeStub);
};
class InstanceOfStub final : public TurboFanCodeStub {
......
......@@ -836,30 +836,27 @@ void Interpreter::DoShiftRightLogical(InterpreterAssembler* assembler) {
DoBinaryOp<ShiftRightLogicalStub>(assembler);
}
void Interpreter::DoCountOp(Callable callable,
InterpreterAssembler* assembler) {
Node* target = __ HeapConstant(callable.code());
template <class Generator>
void Interpreter::DoUnaryOp(InterpreterAssembler* assembler) {
Node* value = __ GetAccumulator();
Node* context = __ GetContext();
Node* result = __ CallStub(callable.descriptor(), target, context, value);
Node* result = Generator::Generate(assembler, value, context);
__ SetAccumulator(result);
__ Dispatch();
}
// Inc
//
// Increments value in the accumulator by one.
void Interpreter::DoInc(InterpreterAssembler* assembler) {
DoCountOp(CodeFactory::Inc(isolate_), assembler);
DoUnaryOp<IncStub>(assembler);
}
// Dec
//
// Decrements value in the accumulator by one.
void Interpreter::DoDec(InterpreterAssembler* assembler) {
DoCountOp(CodeFactory::Dec(isolate_), assembler);
DoUnaryOp<DecStub>(assembler);
}
void Interpreter::DoLogicalNotOp(Node* value, InterpreterAssembler* assembler) {
......
......@@ -70,19 +70,20 @@ class Interpreter {
BYTECODE_LIST(DECLARE_BYTECODE_HANDLER_GENERATOR)
#undef DECLARE_BYTECODE_HANDLER_GENERATOR
// Generates code to perform the binary operations via |callable|.
// Generates code to perform the binary operation via |callable|.
void DoBinaryOp(Callable callable, InterpreterAssembler* assembler);
// Generates code to perform the binary operations via |function_id|.
// Generates code to perform the binary operation via |function_id|.
void DoBinaryOp(Runtime::FunctionId function_id,
InterpreterAssembler* assembler);
// Generates code to perform the binary operations via |Generator|.
// Generates code to perform the binary operation via |Generator|.
template <class Generator>
void DoBinaryOp(InterpreterAssembler* assembler);
// Generates code to perform the count operations via |callable|.
void DoCountOp(Callable callable, InterpreterAssembler* assembler);
// Generates code to perform the unary operation via |Generator|.
template <class Generator>
void DoUnaryOp(InterpreterAssembler* assembler);
// Generates code to perform the comparison operation associated with
// |compare_op|.
......
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