Commit 681e3312 authored by Igor Sheludko's avatar Igor Sheludko Committed by Commit Bot

[builtins][interpreter] Move BinaryOpAssembler to its own file.

This CL also
1) turns (Add/Subtract)WithFeedbackStub into builtins
2) makes interpreter use BinaryOpAssembler directly
3) drops unused (Multipy/Divide/Modulus)WithFeedbackStubs

BUG=v8:6116

Change-Id: I994aba6442f173535c13dfbaaafae1033de3f2ce
Reviewed-on: https://chromium-review.googlesource.com/458438Reviewed-by: 's avatarRoss McIlroy <rmcilroy@chromium.org>
Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Commit-Queue: Igor Sheludko <ishell@chromium.org>
Cr-Commit-Position: refs/heads/master@{#44042}
parent 04440d28
...@@ -937,6 +937,8 @@ v8_source_set("v8_builtins_generators") { ...@@ -937,6 +937,8 @@ v8_source_set("v8_builtins_generators") {
"src/builtins/builtins-wasm-gen.cc", "src/builtins/builtins-wasm-gen.cc",
"src/ic/accessor-assembler.cc", "src/ic/accessor-assembler.cc",
"src/ic/accessor-assembler.h", "src/ic/accessor-assembler.h",
"src/ic/binary-op-assembler.cc",
"src/ic/binary-op-assembler.h",
"src/ic/keyed-store-generic.cc", "src/ic/keyed-store-generic.cc",
"src/ic/keyed-store-generic.h", "src/ic/keyed-store-generic.h",
"src/interpreter/interpreter-assembler.cc", "src/interpreter/interpreter-assembler.cc",
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "src/builtins/builtins-utils-gen.h" #include "src/builtins/builtins-utils-gen.h"
#include "src/builtins/builtins.h" #include "src/builtins/builtins.h"
#include "src/code-stub-assembler.h" #include "src/code-stub-assembler.h"
#include "src/ic/binary-op-assembler.h"
namespace v8 { namespace v8 {
namespace internal { namespace internal {
...@@ -1392,5 +1393,27 @@ TF_BUILTIN(StrictEqual, CodeStubAssembler) { ...@@ -1392,5 +1393,27 @@ TF_BUILTIN(StrictEqual, CodeStubAssembler) {
Return(StrictEqual(lhs, rhs)); Return(StrictEqual(lhs, rhs));
} }
TF_BUILTIN(AddWithFeedback, BinaryOpAssembler) {
Node* context = Parameter(Descriptor::kContext);
Node* left = Parameter(Descriptor::kLeft);
Node* right = Parameter(Descriptor::kRight);
Node* slot = Parameter(Descriptor::kSlot);
Node* vector = Parameter(Descriptor::kVector);
Return(Generate_AddWithFeedback(context, left, right,
ChangeUint32ToWord(slot), vector));
}
TF_BUILTIN(SubtractWithFeedback, BinaryOpAssembler) {
Node* context = Parameter(Descriptor::kContext);
Node* left = Parameter(Descriptor::kLeft);
Node* right = Parameter(Descriptor::kRight);
Node* slot = Parameter(Descriptor::kSlot);
Node* vector = Parameter(Descriptor::kVector);
Return(Generate_SubtractWithFeedback(context, left, right,
ChangeUint32ToWord(slot), vector));
}
} // namespace internal } // namespace internal
} // namespace v8 } // namespace v8
...@@ -635,6 +635,8 @@ class Isolate; ...@@ -635,6 +635,8 @@ class Isolate;
TFS(GreaterThanOrEqual, BUILTIN, kNoExtraICState, Compare, 1) \ TFS(GreaterThanOrEqual, BUILTIN, kNoExtraICState, Compare, 1) \
TFS(Equal, BUILTIN, kNoExtraICState, Compare, 1) \ TFS(Equal, BUILTIN, kNoExtraICState, Compare, 1) \
TFS(StrictEqual, BUILTIN, kNoExtraICState, Compare, 1) \ TFS(StrictEqual, BUILTIN, kNoExtraICState, Compare, 1) \
TFS(AddWithFeedback, BUILTIN, kNoExtraICState, BinaryOpWithVector, 1) \
TFS(SubtractWithFeedback, BUILTIN, kNoExtraICState, BinaryOpWithVector, 1) \
\ \
/* Object */ \ /* Object */ \
CPP(ObjectAssign) \ CPP(ObjectAssign) \
......
This diff is collapsed.
...@@ -74,11 +74,6 @@ class Node; ...@@ -74,11 +74,6 @@ class Node;
V(CreateAllocationSite) \ V(CreateAllocationSite) \
V(CreateWeakCell) \ V(CreateWeakCell) \
V(StringLength) \ V(StringLength) \
V(AddWithFeedback) \
V(SubtractWithFeedback) \
V(MultiplyWithFeedback) \
V(DivideWithFeedback) \
V(ModulusWithFeedback) \
V(InternalArrayNoArgumentConstructor) \ V(InternalArrayNoArgumentConstructor) \
V(InternalArraySingleArgumentConstructor) \ V(InternalArraySingleArgumentConstructor) \
V(ElementsTransitionAndStore) \ V(ElementsTransitionAndStore) \
...@@ -343,15 +338,6 @@ class CodeStub BASE_EMBEDDED { ...@@ -343,15 +338,6 @@ class CodeStub BASE_EMBEDDED {
void GenerateAssembly(compiler::CodeAssemblerState* state) const override; \ void GenerateAssembly(compiler::CodeAssemblerState* state) const override; \
DEFINE_CODE_STUB(NAME, SUPER) DEFINE_CODE_STUB(NAME, SUPER)
#define DEFINE_TURBOFAN_BINARY_OP_CODE_STUB_WITH_FEEDBACK(NAME, SUPER) \
public: \
static compiler::Node* Generate( \
CodeStubAssembler* assembler, compiler::Node* left, \
compiler::Node* right, compiler::Node* slot_id, \
compiler::Node* feedback_vector, compiler::Node* context); \
void GenerateAssembly(compiler::CodeAssemblerState* state) const override; \
DEFINE_CODE_STUB(NAME, SUPER)
#define DEFINE_TURBOFAN_UNARY_OP_CODE_STUB_WITH_FEEDBACK(NAME, SUPER) \ #define DEFINE_TURBOFAN_UNARY_OP_CODE_STUB_WITH_FEEDBACK(NAME, SUPER) \
public: \ public: \
static compiler::Node* Generate( \ static compiler::Node* Generate( \
...@@ -645,55 +631,6 @@ class StringLengthStub : public TurboFanCodeStub { ...@@ -645,55 +631,6 @@ class StringLengthStub : public TurboFanCodeStub {
DEFINE_TURBOFAN_CODE_STUB(StringLength, TurboFanCodeStub); DEFINE_TURBOFAN_CODE_STUB(StringLength, TurboFanCodeStub);
}; };
class AddWithFeedbackStub final : public TurboFanCodeStub {
public:
explicit AddWithFeedbackStub(Isolate* isolate) : TurboFanCodeStub(isolate) {}
DEFINE_CALL_INTERFACE_DESCRIPTOR(BinaryOpWithVector);
DEFINE_TURBOFAN_BINARY_OP_CODE_STUB_WITH_FEEDBACK(AddWithFeedback,
TurboFanCodeStub);
};
class SubtractWithFeedbackStub final : public TurboFanCodeStub {
public:
explicit SubtractWithFeedbackStub(Isolate* isolate)
: TurboFanCodeStub(isolate) {}
DEFINE_CALL_INTERFACE_DESCRIPTOR(BinaryOpWithVector);
DEFINE_TURBOFAN_BINARY_OP_CODE_STUB_WITH_FEEDBACK(SubtractWithFeedback,
TurboFanCodeStub);
};
class MultiplyWithFeedbackStub final : public TurboFanCodeStub {
public:
explicit MultiplyWithFeedbackStub(Isolate* isolate)
: TurboFanCodeStub(isolate) {}
DEFINE_CALL_INTERFACE_DESCRIPTOR(BinaryOpWithVector);
DEFINE_TURBOFAN_BINARY_OP_CODE_STUB_WITH_FEEDBACK(MultiplyWithFeedback,
TurboFanCodeStub);
};
class DivideWithFeedbackStub final : public TurboFanCodeStub {
public:
explicit DivideWithFeedbackStub(Isolate* isolate)
: TurboFanCodeStub(isolate) {}
DEFINE_CALL_INTERFACE_DESCRIPTOR(BinaryOpWithVector);
DEFINE_TURBOFAN_BINARY_OP_CODE_STUB_WITH_FEEDBACK(DivideWithFeedback,
TurboFanCodeStub);
};
class ModulusWithFeedbackStub final : public TurboFanCodeStub {
public:
explicit ModulusWithFeedbackStub(Isolate* isolate)
: TurboFanCodeStub(isolate) {}
DEFINE_CALL_INTERFACE_DESCRIPTOR(BinaryOpWithVector);
DEFINE_TURBOFAN_BINARY_OP_CODE_STUB_WITH_FEEDBACK(ModulusWithFeedback,
TurboFanCodeStub);
};
class StoreInterceptorStub : public TurboFanCodeStub { class StoreInterceptorStub : public TurboFanCodeStub {
public: public:
explicit StoreInterceptorStub(Isolate* isolate) : TurboFanCodeStub(isolate) {} explicit StoreInterceptorStub(Isolate* isolate) : TurboFanCodeStub(isolate) {}
......
This diff is collapsed.
// 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.
#ifndef V8_SRC_IC_BINARY_OP_ASSEMBLER_H_
#define V8_SRC_IC_BINARY_OP_ASSEMBLER_H_
#include "src/code-stub-assembler.h"
namespace v8 {
namespace internal {
namespace compiler {
class CodeAssemblerState;
}
class BinaryOpAssembler : public CodeStubAssembler {
public:
typedef compiler::Node Node;
explicit BinaryOpAssembler(compiler::CodeAssemblerState* state)
: CodeStubAssembler(state) {}
Node* Generate_AddWithFeedback(Node* context, Node* lhs, Node* rhs,
Node* slot_id, Node* feedback_vector);
Node* Generate_SubtractWithFeedback(Node* context, Node* lhs, Node* rhs,
Node* slot_id, Node* feedback_vector);
Node* Generate_MultiplyWithFeedback(Node* context, Node* lhs, Node* rhs,
Node* slot_id, Node* feedback_vector);
Node* Generate_DivideWithFeedback(Node* context, Node* dividend,
Node* divisor, Node* slot_id,
Node* feedback_vector);
Node* Generate_ModulusWithFeedback(Node* context, Node* dividend,
Node* divisor, Node* slot_id,
Node* feedback_vector);
};
} // namespace internal
} // namespace v8
#endif // V8_SRC_IC_BINARY_OP_ASSEMBLER_H_
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "src/code-factory.h" #include "src/code-factory.h"
#include "src/factory.h" #include "src/factory.h"
#include "src/ic/accessor-assembler.h" #include "src/ic/accessor-assembler.h"
#include "src/ic/binary-op-assembler.h"
#include "src/interpreter/bytecode-flags.h" #include "src/interpreter/bytecode-flags.h"
#include "src/interpreter/bytecodes.h" #include "src/interpreter/bytecodes.h"
#include "src/interpreter/interpreter-assembler.h" #include "src/interpreter/interpreter-assembler.h"
...@@ -39,9 +40,14 @@ class InterpreterGenerator { ...@@ -39,9 +40,14 @@ class InterpreterGenerator {
#undef DECLARE_BYTECODE_HANDLER_GENERATOR #undef DECLARE_BYTECODE_HANDLER_GENERATOR
private: private:
typedef Node* (BinaryOpAssembler::*BinaryOpGenerator)(Node* context,
Node* left, Node* right,
Node* slot,
Node* vector);
// Generates code to perform the binary operation via |Generator|. // Generates code to perform the binary operation via |Generator|.
template <class Generator> void DoBinaryOpWithFeedback(InterpreterAssembler* assembler,
void DoBinaryOpWithFeedback(InterpreterAssembler* assembler); BinaryOpGenerator generator);
// Generates code to perform the comparison via |Generator| while gathering // Generates code to perform the comparison via |Generator| while gathering
// type feedback. // type feedback.
...@@ -963,17 +969,18 @@ void InterpreterGenerator::DoCompareOp(Token::Value compare_op, ...@@ -963,17 +969,18 @@ void InterpreterGenerator::DoCompareOp(Token::Value compare_op,
__ Dispatch(); __ Dispatch();
} }
template <class Generator>
void InterpreterGenerator::DoBinaryOpWithFeedback( void InterpreterGenerator::DoBinaryOpWithFeedback(
InterpreterAssembler* assembler) { InterpreterAssembler* assembler, BinaryOpGenerator generator) {
Node* reg_index = __ BytecodeOperandReg(0); Node* reg_index = __ BytecodeOperandReg(0);
Node* lhs = __ LoadRegister(reg_index); Node* lhs = __ LoadRegister(reg_index);
Node* rhs = __ GetAccumulator(); Node* rhs = __ GetAccumulator();
Node* context = __ GetContext(); Node* context = __ GetContext();
Node* slot_index = __ BytecodeOperandIdx(1); Node* slot_index = __ BytecodeOperandIdx(1);
Node* feedback_vector = __ LoadFeedbackVector(); Node* feedback_vector = __ LoadFeedbackVector();
Node* result = Generator::Generate(assembler, lhs, rhs, slot_index,
feedback_vector, context); BinaryOpAssembler binop_asm(assembler->state());
Node* result =
(binop_asm.*generator)(context, lhs, rhs, slot_index, feedback_vector);
__ SetAccumulator(result); __ SetAccumulator(result);
__ Dispatch(); __ Dispatch();
} }
...@@ -1171,35 +1178,40 @@ void InterpreterGenerator::DoCompareOpWithFeedback( ...@@ -1171,35 +1178,40 @@ void InterpreterGenerator::DoCompareOpWithFeedback(
// //
// Add register <src> to accumulator. // Add register <src> to accumulator.
void InterpreterGenerator::DoAdd(InterpreterAssembler* assembler) { void InterpreterGenerator::DoAdd(InterpreterAssembler* assembler) {
DoBinaryOpWithFeedback<AddWithFeedbackStub>(assembler); DoBinaryOpWithFeedback(assembler,
&BinaryOpAssembler::Generate_AddWithFeedback);
} }
// Sub <src> // Sub <src>
// //
// Subtract register <src> from accumulator. // Subtract register <src> from accumulator.
void InterpreterGenerator::DoSub(InterpreterAssembler* assembler) { void InterpreterGenerator::DoSub(InterpreterAssembler* assembler) {
DoBinaryOpWithFeedback<SubtractWithFeedbackStub>(assembler); DoBinaryOpWithFeedback(assembler,
&BinaryOpAssembler::Generate_SubtractWithFeedback);
} }
// Mul <src> // Mul <src>
// //
// Multiply accumulator by register <src>. // Multiply accumulator by register <src>.
void InterpreterGenerator::DoMul(InterpreterAssembler* assembler) { void InterpreterGenerator::DoMul(InterpreterAssembler* assembler) {
DoBinaryOpWithFeedback<MultiplyWithFeedbackStub>(assembler); DoBinaryOpWithFeedback(assembler,
&BinaryOpAssembler::Generate_MultiplyWithFeedback);
} }
// Div <src> // Div <src>
// //
// Divide register <src> by accumulator. // Divide register <src> by accumulator.
void InterpreterGenerator::DoDiv(InterpreterAssembler* assembler) { void InterpreterGenerator::DoDiv(InterpreterAssembler* assembler) {
DoBinaryOpWithFeedback<DivideWithFeedbackStub>(assembler); DoBinaryOpWithFeedback(assembler,
&BinaryOpAssembler::Generate_DivideWithFeedback);
} }
// Mod <src> // Mod <src>
// //
// Modulo register <src> by accumulator. // Modulo register <src> by accumulator.
void InterpreterGenerator::DoMod(InterpreterAssembler* assembler) { void InterpreterGenerator::DoMod(InterpreterAssembler* assembler) {
DoBinaryOpWithFeedback<ModulusWithFeedbackStub>(assembler); DoBinaryOpWithFeedback(assembler,
&BinaryOpAssembler::Generate_ModulusWithFeedback);
} }
void InterpreterGenerator::DoBitwiseBinaryOp(Token::Value bitwise_op, void InterpreterGenerator::DoBitwiseBinaryOp(Token::Value bitwise_op,
...@@ -1365,11 +1377,9 @@ void InterpreterGenerator::DoAddSmi(InterpreterAssembler* assembler) { ...@@ -1365,11 +1377,9 @@ void InterpreterGenerator::DoAddSmi(InterpreterAssembler* assembler) {
__ Bind(&slowpath); __ Bind(&slowpath);
{ {
Node* context = __ GetContext(); Node* context = __ GetContext();
AddWithFeedbackStub stub(__ isolate()); // TODO(ishell): pass slot as word-size value.
Callable callable = var_result.Bind(__ CallBuiltin(Builtins::kAddWithFeedback, context, left,
Callable(stub.GetCode(), AddWithFeedbackStub::Descriptor(__ isolate())); right, __ TruncateWordToWord32(slot_index),
var_result.Bind(__ CallStub(callable, context, left, right,
__ TruncateWordToWord32(slot_index),
feedback_vector)); feedback_vector));
__ Goto(&end); __ Goto(&end);
} }
...@@ -1419,12 +1429,10 @@ void InterpreterGenerator::DoSubSmi(InterpreterAssembler* assembler) { ...@@ -1419,12 +1429,10 @@ void InterpreterGenerator::DoSubSmi(InterpreterAssembler* assembler) {
__ Bind(&slowpath); __ Bind(&slowpath);
{ {
Node* context = __ GetContext(); Node* context = __ GetContext();
SubtractWithFeedbackStub stub(__ isolate()); // TODO(ishell): pass slot as word-size value.
Callable callable = Callable( var_result.Bind(
stub.GetCode(), SubtractWithFeedbackStub::Descriptor(__ isolate())); __ CallBuiltin(Builtins::kSubtractWithFeedback, context, left, right,
var_result.Bind(__ CallStub(callable, context, left, right, __ TruncateWordToWord32(slot_index), feedback_vector));
__ TruncateWordToWord32(slot_index),
feedback_vector));
__ Goto(&end); __ Goto(&end);
} }
__ Bind(&end); __ Bind(&end);
......
...@@ -998,6 +998,8 @@ ...@@ -998,6 +998,8 @@
'ic/access-compiler.h', 'ic/access-compiler.h',
'ic/accessor-assembler.cc', 'ic/accessor-assembler.cc',
'ic/accessor-assembler.h', 'ic/accessor-assembler.h',
'ic/binary-op-assembler.cc',
'ic/binary-op-assembler.h',
'ic/call-optimization.cc', 'ic/call-optimization.cc',
'ic/call-optimization.h', 'ic/call-optimization.h',
'ic/handler-compiler.cc', 'ic/handler-compiler.cc',
......
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