Commit b305c7df authored by epertoso's avatar epertoso Committed by Commit bot

[interpreter] Make the binary op with Smi bytecode handlers collect type feedback.

Drive-by fix: the order of parameters in the BinaryOpWithFeedback TurboFan code stubs now reflects the convention of having the context at the end.

BUG=v8:5273

Review-Url: https://codereview.chromium.org/2263253002
Cr-Commit-Position: refs/heads/master@{#38832}
parent 6cfa92fb
......@@ -297,6 +297,17 @@ void BinaryOpWithAllocationSiteDescriptor::InitializePlatformSpecific(
data->InitializePlatformSpecific(arraysize(registers), registers);
}
void BinaryOpWithVectorDescriptor::InitializePlatformSpecific(
CallInterfaceDescriptorData* data) {
// register state
// r1 -- lhs
// r0 -- rhs
// r4 -- slot id
// r3 -- vector
Register registers[] = {r1, r0, r4, r3};
data->InitializePlatformSpecific(arraysize(registers), registers);
}
void CountOpDescriptor::InitializePlatformSpecific(
CallInterfaceDescriptorData* data) {
Register registers[] = {r1};
......
......@@ -327,6 +327,17 @@ void BinaryOpWithAllocationSiteDescriptor::InitializePlatformSpecific(
data->InitializePlatformSpecific(arraysize(registers), registers);
}
void BinaryOpWithVectorDescriptor::InitializePlatformSpecific(
CallInterfaceDescriptorData* data) {
// register state
// x1 -- lhs
// x0 -- rhs
// x4 -- slot id
// x3 -- vector
Register registers[] = {x1, x0, x4, x3};
data->InitializePlatformSpecific(arraysize(registers), registers);
}
void CountOpDescriptor::InitializePlatformSpecific(
CallInterfaceDescriptorData* data) {
Register registers[] = {x1};
......
......@@ -909,8 +909,8 @@ compiler::Node* AddStub::Generate(CodeStubAssembler* assembler,
// static
compiler::Node* AddWithFeedbackStub::Generate(
CodeStubAssembler* assembler, compiler::Node* lhs, compiler::Node* rhs,
compiler::Node* context, compiler::Node* type_feedback_vector,
compiler::Node* slot_id) {
compiler::Node* slot_id, compiler::Node* type_feedback_vector,
compiler::Node* context) {
typedef CodeStubAssembler::Label Label;
typedef compiler::Node Node;
typedef CodeStubAssembler::Variable Variable;
......@@ -1217,8 +1217,8 @@ compiler::Node* SubtractStub::Generate(CodeStubAssembler* assembler,
// static
compiler::Node* SubtractWithFeedbackStub::Generate(
CodeStubAssembler* assembler, compiler::Node* lhs, compiler::Node* rhs,
compiler::Node* context, compiler::Node* type_feedback_vector,
compiler::Node* slot_id) {
compiler::Node* slot_id, compiler::Node* type_feedback_vector,
compiler::Node* context) {
typedef CodeStubAssembler::Label Label;
typedef compiler::Node Node;
typedef CodeStubAssembler::Variable Variable;
......@@ -1506,8 +1506,8 @@ compiler::Node* MultiplyStub::Generate(CodeStubAssembler* assembler,
// static
compiler::Node* MultiplyWithFeedbackStub::Generate(
CodeStubAssembler* assembler, compiler::Node* lhs, compiler::Node* rhs,
compiler::Node* context, compiler::Node* type_feedback_vector,
compiler::Node* slot_id) {
compiler::Node* slot_id, compiler::Node* type_feedback_vector,
compiler::Node* context) {
using compiler::Node;
typedef CodeStubAssembler::Label Label;
typedef CodeStubAssembler::Variable Variable;
......@@ -1841,8 +1841,8 @@ compiler::Node* DivideStub::Generate(CodeStubAssembler* assembler,
// static
compiler::Node* DivideWithFeedbackStub::Generate(
CodeStubAssembler* assembler, compiler::Node* dividend,
compiler::Node* divisor, compiler::Node* context,
compiler::Node* type_feedback_vector, compiler::Node* slot_id) {
compiler::Node* divisor, compiler::Node* slot_id,
compiler::Node* type_feedback_vector, compiler::Node* context) {
using compiler::Node;
typedef CodeStubAssembler::Label Label;
typedef CodeStubAssembler::Variable Variable;
......@@ -2176,8 +2176,8 @@ compiler::Node* ModulusStub::Generate(CodeStubAssembler* assembler,
// static
compiler::Node* ModulusWithFeedbackStub::Generate(
CodeStubAssembler* assembler, compiler::Node* dividend,
compiler::Node* divisor, compiler::Node* context,
compiler::Node* type_feedback_vector, compiler::Node* slot_id) {
compiler::Node* divisor, compiler::Node* slot_id,
compiler::Node* type_feedback_vector, compiler::Node* context) {
using compiler::Node;
typedef CodeStubAssembler::Label Label;
typedef CodeStubAssembler::Variable Variable;
......
......@@ -441,8 +441,8 @@ class CodeStub BASE_EMBEDDED {
public: \
static compiler::Node* Generate( \
CodeStubAssembler* assembler, compiler::Node* left, \
compiler::Node* right, compiler::Node* context, \
compiler::Node* type_feedback_vector, compiler::Node* slot_id); \
compiler::Node* right, compiler::Node* slot_id, \
compiler::Node* type_feedback_vector, compiler::Node* context); \
void GenerateAssembly(CodeStubAssembler* assembler) const override { \
assembler->Return( \
Generate(assembler, assembler->Parameter(0), assembler->Parameter(1), \
......@@ -777,7 +777,7 @@ class AddWithFeedbackStub final : public TurboFanCodeStub {
public:
explicit AddWithFeedbackStub(Isolate* isolate) : TurboFanCodeStub(isolate) {}
DEFINE_CALL_INTERFACE_DESCRIPTOR(BinaryOp);
DEFINE_CALL_INTERFACE_DESCRIPTOR(BinaryOpWithVector);
DEFINE_TURBOFAN_BINARY_OP_CODE_STUB_WITH_FEEDBACK(AddWithFeedback,
TurboFanCodeStub);
};
......@@ -795,7 +795,7 @@ class SubtractWithFeedbackStub final : public TurboFanCodeStub {
explicit SubtractWithFeedbackStub(Isolate* isolate)
: TurboFanCodeStub(isolate) {}
DEFINE_CALL_INTERFACE_DESCRIPTOR(BinaryOp);
DEFINE_CALL_INTERFACE_DESCRIPTOR(BinaryOpWithVector);
DEFINE_TURBOFAN_BINARY_OP_CODE_STUB_WITH_FEEDBACK(SubtractWithFeedback,
TurboFanCodeStub);
};
......@@ -813,7 +813,7 @@ class MultiplyWithFeedbackStub final : public TurboFanCodeStub {
explicit MultiplyWithFeedbackStub(Isolate* isolate)
: TurboFanCodeStub(isolate) {}
DEFINE_CALL_INTERFACE_DESCRIPTOR(BinaryOp);
DEFINE_CALL_INTERFACE_DESCRIPTOR(BinaryOpWithVector);
DEFINE_TURBOFAN_BINARY_OP_CODE_STUB_WITH_FEEDBACK(MultiplyWithFeedback,
TurboFanCodeStub);
};
......@@ -831,7 +831,7 @@ class DivideWithFeedbackStub final : public TurboFanCodeStub {
explicit DivideWithFeedbackStub(Isolate* isolate)
: TurboFanCodeStub(isolate) {}
DEFINE_CALL_INTERFACE_DESCRIPTOR(BinaryOp);
DEFINE_CALL_INTERFACE_DESCRIPTOR(BinaryOpWithVector);
DEFINE_TURBOFAN_BINARY_OP_CODE_STUB_WITH_FEEDBACK(DivideWithFeedback,
TurboFanCodeStub);
};
......@@ -849,7 +849,7 @@ class ModulusWithFeedbackStub final : public TurboFanCodeStub {
explicit ModulusWithFeedbackStub(Isolate* isolate)
: TurboFanCodeStub(isolate) {}
DEFINE_CALL_INTERFACE_DESCRIPTOR(BinaryOp);
DEFINE_CALL_INTERFACE_DESCRIPTOR(BinaryOpWithVector);
DEFINE_TURBOFAN_BINARY_OP_CODE_STUB_WITH_FEEDBACK(ModulusWithFeedback,
TurboFanCodeStub);
};
......
......@@ -1203,21 +1203,10 @@ void BytecodeGraphBuilder::BuildBinaryOp(const Operator* js_op) {
// Helper function to create binary operation hint from the recorded type
// feedback.
BinaryOperationHint BytecodeGraphBuilder::GetBinaryOperationHint() {
FeedbackVectorSlot slot =
feedback_vector()->ToSlot(bytecode_iterator().GetIndexOperand(1));
DCHECK_EQ(FeedbackVectorSlotKind::GENERAL, feedback_vector()->GetKind(slot));
Object* feedback = feedback_vector()->Get(slot);
BinaryOperationHint hint = BinaryOperationHint::kAny;
if (feedback->IsSmi()) {
hint = BinaryOperationHintFromFeedback((Smi::cast(feedback))->value());
}
return hint;
}
BinaryOperationHint BytecodeGraphBuilder::GetBinaryOperationHintForIncDec() {
FeedbackVectorSlot slot =
feedback_vector()->ToSlot(bytecode_iterator().GetIndexOperand(0));
BinaryOperationHint BytecodeGraphBuilder::GetBinaryOperationHint(
int operand_index) {
FeedbackVectorSlot slot = feedback_vector()->ToSlot(
bytecode_iterator().GetIndexOperand(operand_index));
DCHECK_EQ(FeedbackVectorSlotKind::GENERAL, feedback_vector()->GetKind(slot));
Object* feedback = feedback_vector()->Get(slot);
BinaryOperationHint hint = BinaryOperationHint::kAny;
......@@ -1228,47 +1217,58 @@ BinaryOperationHint BytecodeGraphBuilder::GetBinaryOperationHintForIncDec() {
}
void BytecodeGraphBuilder::VisitAdd() {
BuildBinaryOp(javascript()->Add(GetBinaryOperationHint()));
BuildBinaryOp(
javascript()->Add(GetBinaryOperationHint(kBinaryOperationHintIndex)));
}
void BytecodeGraphBuilder::VisitSub() {
BuildBinaryOp(javascript()->Subtract(GetBinaryOperationHint()));
BuildBinaryOp(javascript()->Subtract(
GetBinaryOperationHint(kBinaryOperationHintIndex)));
}
void BytecodeGraphBuilder::VisitMul() {
BuildBinaryOp(javascript()->Multiply(GetBinaryOperationHint()));
BuildBinaryOp(javascript()->Multiply(
GetBinaryOperationHint(kBinaryOperationHintIndex)));
}
void BytecodeGraphBuilder::VisitDiv() {
BuildBinaryOp(javascript()->Divide(GetBinaryOperationHint()));
BuildBinaryOp(
javascript()->Divide(GetBinaryOperationHint(kBinaryOperationHintIndex)));
}
void BytecodeGraphBuilder::VisitMod() {
BuildBinaryOp(javascript()->Modulus(GetBinaryOperationHint()));
BuildBinaryOp(
javascript()->Modulus(GetBinaryOperationHint(kBinaryOperationHintIndex)));
}
void BytecodeGraphBuilder::VisitBitwiseOr() {
BuildBinaryOp(javascript()->BitwiseOr(GetBinaryOperationHint()));
BuildBinaryOp(javascript()->BitwiseOr(
GetBinaryOperationHint(kBinaryOperationHintIndex)));
}
void BytecodeGraphBuilder::VisitBitwiseXor() {
BuildBinaryOp(javascript()->BitwiseXor(GetBinaryOperationHint()));
BuildBinaryOp(javascript()->BitwiseXor(
GetBinaryOperationHint(kBinaryOperationHintIndex)));
}
void BytecodeGraphBuilder::VisitBitwiseAnd() {
BuildBinaryOp(javascript()->BitwiseAnd(GetBinaryOperationHint()));
BuildBinaryOp(javascript()->BitwiseAnd(
GetBinaryOperationHint(kBinaryOperationHintIndex)));
}
void BytecodeGraphBuilder::VisitShiftLeft() {
BuildBinaryOp(javascript()->ShiftLeft(GetBinaryOperationHint()));
BuildBinaryOp(javascript()->ShiftLeft(
GetBinaryOperationHint(kBinaryOperationHintIndex)));
}
void BytecodeGraphBuilder::VisitShiftRight() {
BuildBinaryOp(javascript()->ShiftRight(GetBinaryOperationHint()));
BuildBinaryOp(javascript()->ShiftRight(
GetBinaryOperationHint(kBinaryOperationHintIndex)));
}
void BytecodeGraphBuilder::VisitShiftRightLogical() {
BuildBinaryOp(javascript()->ShiftRightLogical(GetBinaryOperationHint()));
BuildBinaryOp(javascript()->ShiftRightLogical(
GetBinaryOperationHint(kBinaryOperationHintIndex)));
}
void BytecodeGraphBuilder::BuildBinaryOpWithImmediate(const Operator* js_op) {
......@@ -1281,33 +1281,33 @@ void BytecodeGraphBuilder::BuildBinaryOpWithImmediate(const Operator* js_op) {
}
void BytecodeGraphBuilder::VisitAddSmi() {
BinaryOperationHint hint = BinaryOperationHint::kAny;
BuildBinaryOpWithImmediate(javascript()->Add(hint));
BuildBinaryOpWithImmediate(
javascript()->Add(GetBinaryOperationHint(kBinaryOperationSmiHintIndex)));
}
void BytecodeGraphBuilder::VisitSubSmi() {
BinaryOperationHint hint = BinaryOperationHint::kAny;
BuildBinaryOpWithImmediate(javascript()->Subtract(hint));
BuildBinaryOpWithImmediate(javascript()->Subtract(
GetBinaryOperationHint(kBinaryOperationSmiHintIndex)));
}
void BytecodeGraphBuilder::VisitBitwiseOrSmi() {
BinaryOperationHint hint = BinaryOperationHint::kAny;
BuildBinaryOpWithImmediate(javascript()->BitwiseOr(hint));
BuildBinaryOpWithImmediate(javascript()->BitwiseOr(
GetBinaryOperationHint(kBinaryOperationSmiHintIndex)));
}
void BytecodeGraphBuilder::VisitBitwiseAndSmi() {
BinaryOperationHint hint = BinaryOperationHint::kAny;
BuildBinaryOpWithImmediate(javascript()->BitwiseAnd(hint));
BuildBinaryOpWithImmediate(javascript()->BitwiseAnd(
GetBinaryOperationHint(kBinaryOperationSmiHintIndex)));
}
void BytecodeGraphBuilder::VisitShiftLeftSmi() {
BinaryOperationHint hint = BinaryOperationHint::kAny;
BuildBinaryOpWithImmediate(javascript()->ShiftLeft(hint));
BuildBinaryOpWithImmediate(javascript()->ShiftLeft(
GetBinaryOperationHint(kBinaryOperationSmiHintIndex)));
}
void BytecodeGraphBuilder::VisitShiftRightSmi() {
BinaryOperationHint hint = BinaryOperationHint::kAny;
BuildBinaryOpWithImmediate(javascript()->ShiftRight(hint));
BuildBinaryOpWithImmediate(javascript()->ShiftRight(
GetBinaryOperationHint(kBinaryOperationSmiHintIndex)));
}
void BytecodeGraphBuilder::VisitInc() {
......@@ -1315,7 +1315,7 @@ void BytecodeGraphBuilder::VisitInc() {
// Note: Use subtract -1 here instead of add 1 to ensure we always convert to
// a number, not a string.
const Operator* js_op =
javascript()->Subtract(GetBinaryOperationHintForIncDec());
javascript()->Subtract(GetBinaryOperationHint(kCountOperationHintIndex));
Node* node = NewNode(js_op, environment()->LookupAccumulator(),
jsgraph()->Constant(-1));
environment()->BindAccumulator(node, &states);
......@@ -1324,7 +1324,7 @@ void BytecodeGraphBuilder::VisitInc() {
void BytecodeGraphBuilder::VisitDec() {
FrameStateBeforeAndAfter states(this);
const Operator* js_op =
javascript()->Subtract(GetBinaryOperationHintForIncDec());
javascript()->Subtract(GetBinaryOperationHint(kCountOperationHintIndex));
Node* node = NewNode(js_op, environment()->LookupAccumulator(),
jsgraph()->OneConstant());
environment()->BindAccumulator(node, &states);
......
......@@ -137,11 +137,7 @@ class BytecodeGraphBuilder {
// Helper function to create binary operation hint from the recorded
// type feedback.
BinaryOperationHint GetBinaryOperationHint();
// Helper function to create an binary operation hint from the recorded
// type feedback in Inc/Dec handlers.
BinaryOperationHint GetBinaryOperationHintForIncDec();
BinaryOperationHint GetBinaryOperationHint(int operand_index);
// Control flow plumbing.
void BuildJump();
......@@ -262,6 +258,10 @@ class BytecodeGraphBuilder {
// Control nodes that exit the function body.
ZoneVector<Node*> exit_controls_;
static int const kBinaryOperationHintIndex = 1;
static int const kCountOperationHintIndex = 0;
static int const kBinaryOperationSmiHintIndex = 2;
DISALLOW_COPY_AND_ASSIGN(BytecodeGraphBuilder);
};
......
......@@ -303,6 +303,17 @@ void BinaryOpWithAllocationSiteDescriptor::InitializePlatformSpecific(
data->InitializePlatformSpecific(arraysize(registers), registers, NULL);
}
void BinaryOpWithVectorDescriptor::InitializePlatformSpecific(
CallInterfaceDescriptorData* data) {
// register state
// edx -- lhs
// eax -- rhs
// edi -- slot id
// ebx -- vector
Register registers[] = {edx, eax, edi, ebx};
data->InitializePlatformSpecific(arraysize(registers), registers);
}
void CountOpDescriptor::InitializePlatformSpecific(
CallInterfaceDescriptorData* data) {
Register registers[] = {eax};
......
......@@ -318,6 +318,21 @@ void StoreWithVectorDescriptor::InitializePlatformSpecific(
data->InitializePlatformSpecific(arraysize(registers), registers);
}
FunctionType*
BinaryOpWithVectorDescriptor::BuildCallInterfaceDescriptorFunctionType(
Isolate* isolate, int parameter_count) {
DCHECK_EQ(parameter_count, kParameterCount);
Zone* zone = isolate->interface_descriptor_zone();
FunctionType* function =
Type::Function(AnyTagged(zone), Type::Undefined(), kParameterCount, zone)
->AsFunction();
function->InitParameter(kLeft, AnyTagged(zone));
function->InitParameter(kRight, AnyTagged(zone));
function->InitParameter(kSlot, UntaggedIntegral32(zone));
function->InitParameter(kVector, AnyTagged(zone));
return function;
}
const Register ApiGetterDescriptor::ReceiverRegister() {
return LoadDescriptor::ReceiverRegister();
}
......
......@@ -74,6 +74,7 @@ class PlatformInterfaceDescriptor;
V(Compare) \
V(BinaryOp) \
V(BinaryOpWithAllocationSite) \
V(BinaryOpWithVector) \
V(CountOp) \
V(StringAdd) \
V(StringCompare) \
......@@ -722,6 +723,13 @@ class BinaryOpWithAllocationSiteDescriptor : public CallInterfaceDescriptor {
CallInterfaceDescriptor)
};
class BinaryOpWithVectorDescriptor : public CallInterfaceDescriptor {
public:
DEFINE_PARAMETERS(kLeft, kRight, kSlot, kVector)
DECLARE_DESCRIPTOR_WITH_CUSTOM_FUNCTION_TYPE(BinaryOpWithVectorDescriptor,
CallInterfaceDescriptor)
};
class CountOpDescriptor final : public CallInterfaceDescriptor {
public:
DECLARE_DESCRIPTOR(CountOpDescriptor, CallInterfaceDescriptor)
......
......@@ -139,7 +139,8 @@ void TransformLdaSmiBinaryOpToBinaryOpWithSmi(Bytecode new_bytecode,
BytecodeNode* const last,
BytecodeNode* const current) {
DCHECK_EQ(last->bytecode(), Bytecode::kLdaSmi);
current->set_bytecode(new_bytecode, last->operand(0), current->operand(0));
current->set_bytecode(new_bytecode, last->operand(0), current->operand(0),
current->operand(1));
if (last->source_info().is_valid()) {
current->source_info().Clone(last->source_info());
}
......@@ -149,7 +150,8 @@ void TransformLdaZeroBinaryOpToBinaryOpWithZero(Bytecode new_bytecode,
BytecodeNode* const last,
BytecodeNode* const current) {
DCHECK_EQ(last->bytecode(), Bytecode::kLdaZero);
current->set_bytecode(new_bytecode, 0, current->operand(0));
current->set_bytecode(new_bytecode, 0, current->operand(0),
current->operand(1));
if (last->source_info().is_valid()) {
current->source_info().Clone(last->source_info());
}
......
......@@ -174,6 +174,14 @@ class BytecodeNode final : ZoneObject {
operands_[0] = operand0;
operands_[1] = operand1;
}
void set_bytecode(Bytecode bytecode, uint32_t operand0, uint32_t operand1,
uint32_t operand2) {
DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), 3);
bytecode_ = bytecode;
operands_[0] = operand0;
operands_[1] = operand1;
operands_[2] = operand2;
}
// Clone |other|.
void Clone(const BytecodeNode* const other);
......
......@@ -165,16 +165,18 @@ namespace interpreter {
OperandType::kIdx) \
\
/* Binary operators with immediate operands */ \
V(AddSmi, AccumulatorUse::kWrite, OperandType::kImm, OperandType::kReg) \
V(SubSmi, AccumulatorUse::kWrite, OperandType::kImm, OperandType::kReg) \
V(AddSmi, AccumulatorUse::kWrite, OperandType::kImm, OperandType::kReg, \
OperandType::kIdx) \
V(SubSmi, AccumulatorUse::kWrite, OperandType::kImm, OperandType::kReg, \
OperandType::kIdx) \
V(BitwiseOrSmi, AccumulatorUse::kWrite, OperandType::kImm, \
OperandType::kReg) \
OperandType::kReg, OperandType::kIdx) \
V(BitwiseAndSmi, AccumulatorUse::kWrite, OperandType::kImm, \
OperandType::kReg) \
OperandType::kReg, OperandType::kIdx) \
V(ShiftLeftSmi, AccumulatorUse::kWrite, OperandType::kImm, \
OperandType::kReg) \
OperandType::kReg, OperandType::kIdx) \
V(ShiftRightSmi, AccumulatorUse::kWrite, OperandType::kImm, \
OperandType::kReg) \
OperandType::kReg, OperandType::kIdx) \
\
/* Unary Operators */ \
V(Inc, AccumulatorUse::kReadWrite, OperandType::kIdx) \
......
......@@ -810,8 +810,8 @@ void Interpreter::DoBinaryOpWithFeedback(InterpreterAssembler* assembler) {
Node* context = __ GetContext();
Node* slot_index = __ BytecodeOperandIdx(1);
Node* type_feedback_vector = __ LoadTypeFeedbackVector();
Node* result = Generator::Generate(assembler, lhs, rhs, context,
type_feedback_vector, slot_index);
Node* result = Generator::Generate(assembler, lhs, rhs, slot_index,
type_feedback_vector, context);
__ SetAccumulator(result);
__ Dispatch();
}
......@@ -987,6 +987,8 @@ void Interpreter::DoAddSmi(InterpreterAssembler* assembler) {
Node* left = __ LoadRegister(reg_index);
Node* raw_int = __ BytecodeOperandImm(0);
Node* right = __ SmiTag(raw_int);
Node* slot_index = __ BytecodeOperandIdx(2);
Node* type_feedback_vector = __ LoadTypeFeedbackVector();
// {right} is known to be a Smi.
// Check if the {left} is a Smi take the fast path.
......@@ -1002,6 +1004,8 @@ void Interpreter::DoAddSmi(InterpreterAssembler* assembler) {
__ BranchIf(overflow, &slowpath, &if_notoverflow);
__ Bind(&if_notoverflow);
{
__ UpdateFeedback(__ Int32Constant(BinaryOperationFeedback::kSignedSmall),
type_feedback_vector, slot_index);
var_result.Bind(__ Projection(0, pair));
__ Goto(&end);
}
......@@ -1009,8 +1013,11 @@ void Interpreter::DoAddSmi(InterpreterAssembler* assembler) {
__ Bind(&slowpath);
{
Node* context = __ GetContext();
Callable callable = CodeFactory::Add(__ isolate());
var_result.Bind(__ CallStub(callable, context, left, right));
AddWithFeedbackStub stub(__ isolate());
Callable callable =
Callable(stub.GetCode(), AddWithFeedbackStub::Descriptor(__ isolate()));
Node* args[] = {left, right, slot_index, type_feedback_vector, context};
var_result.Bind(__ CallStubN(callable, args, 1));
__ Goto(&end);
}
__ Bind(&end);
......@@ -1033,6 +1040,8 @@ void Interpreter::DoSubSmi(InterpreterAssembler* assembler) {
Node* left = __ LoadRegister(reg_index);
Node* raw_int = __ BytecodeOperandImm(0);
Node* right = __ SmiTag(raw_int);
Node* slot_index = __ BytecodeOperandIdx(2);
Node* type_feedback_vector = __ LoadTypeFeedbackVector();
// {right} is known to be a Smi.
// Check if the {left} is a Smi take the fast path.
......@@ -1048,6 +1057,8 @@ void Interpreter::DoSubSmi(InterpreterAssembler* assembler) {
__ BranchIf(overflow, &slowpath, &if_notoverflow);
__ Bind(&if_notoverflow);
{
__ UpdateFeedback(__ Int32Constant(BinaryOperationFeedback::kSignedSmall),
type_feedback_vector, slot_index);
var_result.Bind(__ Projection(0, pair));
__ Goto(&end);
}
......@@ -1055,8 +1066,11 @@ void Interpreter::DoSubSmi(InterpreterAssembler* assembler) {
__ Bind(&slowpath);
{
Node* context = __ GetContext();
Callable callable = CodeFactory::Subtract(__ isolate());
var_result.Bind(__ CallStub(callable, context, left, right));
SubtractWithFeedbackStub stub(__ isolate());
Callable callable = Callable(
stub.GetCode(), SubtractWithFeedbackStub::Descriptor(__ isolate()));
Node* args[] = {left, right, slot_index, type_feedback_vector, context};
var_result.Bind(__ CallStubN(callable, args, 1));
__ Goto(&end);
}
__ Bind(&end);
......@@ -1076,10 +1090,20 @@ void Interpreter::DoBitwiseOrSmi(InterpreterAssembler* assembler) {
Node* raw_int = __ BytecodeOperandImm(0);
Node* right = __ SmiTag(raw_int);
Node* context = __ GetContext();
Node* lhs_value = __ TruncateTaggedToWord32(context, left);
Node* slot_index = __ BytecodeOperandIdx(2);
Node* type_feedback_vector = __ LoadTypeFeedbackVector();
Variable var_lhs_type_feedback(assembler, MachineRepresentation::kWord32);
Node* lhs_value = __ TruncateTaggedToWord32WithFeedback(
context, left, &var_lhs_type_feedback);
Node* rhs_value = __ SmiToWord32(right);
Node* value = __ Word32Or(lhs_value, rhs_value);
Node* result = __ ChangeInt32ToTagged(value);
Node* result_type =
__ Select(__ WordIsSmi(result),
__ Int32Constant(BinaryOperationFeedback::kSignedSmall),
__ Int32Constant(BinaryOperationFeedback::kNumber));
__ UpdateFeedback(__ Word32Or(result_type, var_lhs_type_feedback.value()),
type_feedback_vector, slot_index);
__ SetAccumulator(result);
__ Dispatch();
}
......@@ -1094,10 +1118,20 @@ void Interpreter::DoBitwiseAndSmi(InterpreterAssembler* assembler) {
Node* raw_int = __ BytecodeOperandImm(0);
Node* right = __ SmiTag(raw_int);
Node* context = __ GetContext();
Node* lhs_value = __ TruncateTaggedToWord32(context, left);
Node* slot_index = __ BytecodeOperandIdx(2);
Node* type_feedback_vector = __ LoadTypeFeedbackVector();
Variable var_lhs_type_feedback(assembler, MachineRepresentation::kWord32);
Node* lhs_value = __ TruncateTaggedToWord32WithFeedback(
context, left, &var_lhs_type_feedback);
Node* rhs_value = __ SmiToWord32(right);
Node* value = __ Word32And(lhs_value, rhs_value);
Node* result = __ ChangeInt32ToTagged(value);
Node* result_type =
__ Select(__ WordIsSmi(result),
__ Int32Constant(BinaryOperationFeedback::kSignedSmall),
__ Int32Constant(BinaryOperationFeedback::kNumber));
__ UpdateFeedback(__ Word32Or(result_type, var_lhs_type_feedback.value()),
type_feedback_vector, slot_index);
__ SetAccumulator(result);
__ Dispatch();
}
......@@ -1113,11 +1147,21 @@ void Interpreter::DoShiftLeftSmi(InterpreterAssembler* assembler) {
Node* raw_int = __ BytecodeOperandImm(0);
Node* right = __ SmiTag(raw_int);
Node* context = __ GetContext();
Node* lhs_value = __ TruncateTaggedToWord32(context, left);
Node* slot_index = __ BytecodeOperandIdx(2);
Node* type_feedback_vector = __ LoadTypeFeedbackVector();
Variable var_lhs_type_feedback(assembler, MachineRepresentation::kWord32);
Node* lhs_value = __ TruncateTaggedToWord32WithFeedback(
context, left, &var_lhs_type_feedback);
Node* rhs_value = __ SmiToWord32(right);
Node* shift_count = __ Word32And(rhs_value, __ Int32Constant(0x1f));
Node* value = __ Word32Shl(lhs_value, shift_count);
Node* result = __ ChangeInt32ToTagged(value);
Node* result_type =
__ Select(__ WordIsSmi(result),
__ Int32Constant(BinaryOperationFeedback::kSignedSmall),
__ Int32Constant(BinaryOperationFeedback::kNumber));
__ UpdateFeedback(__ Word32Or(result_type, var_lhs_type_feedback.value()),
type_feedback_vector, slot_index);
__ SetAccumulator(result);
__ Dispatch();
}
......@@ -1133,11 +1177,21 @@ void Interpreter::DoShiftRightSmi(InterpreterAssembler* assembler) {
Node* raw_int = __ BytecodeOperandImm(0);
Node* right = __ SmiTag(raw_int);
Node* context = __ GetContext();
Node* lhs_value = __ TruncateTaggedToWord32(context, left);
Node* slot_index = __ BytecodeOperandIdx(2);
Node* type_feedback_vector = __ LoadTypeFeedbackVector();
Variable var_lhs_type_feedback(assembler, MachineRepresentation::kWord32);
Node* lhs_value = __ TruncateTaggedToWord32WithFeedback(
context, left, &var_lhs_type_feedback);
Node* rhs_value = __ SmiToWord32(right);
Node* shift_count = __ Word32And(rhs_value, __ Int32Constant(0x1f));
Node* value = __ Word32Sar(lhs_value, shift_count);
Node* result = __ ChangeInt32ToTagged(value);
Node* result_type =
__ Select(__ WordIsSmi(result),
__ Int32Constant(BinaryOperationFeedback::kSignedSmall),
__ Int32Constant(BinaryOperationFeedback::kNumber));
__ UpdateFeedback(__ Word32Or(result_type, var_lhs_type_feedback.value()),
type_feedback_vector, slot_index);
__ SetAccumulator(result);
__ Dispatch();
}
......
......@@ -295,6 +295,17 @@ void BinaryOpWithAllocationSiteDescriptor::InitializePlatformSpecific(
data->InitializePlatformSpecific(arraysize(registers), registers, NULL);
}
void BinaryOpWithVectorDescriptor::InitializePlatformSpecific(
CallInterfaceDescriptorData* data) {
// register state
// a1 -- lhs
// a0 -- rhs
// t0 -- slot id
// a3 -- vector
Register registers[] = {a1, a0, t0, a3};
data->InitializePlatformSpecific(arraysize(registers), registers);
}
void CountOpDescriptor::InitializePlatformSpecific(
CallInterfaceDescriptorData* data) {
Register registers[] = {a1};
......
......@@ -294,6 +294,17 @@ void BinaryOpWithAllocationSiteDescriptor::InitializePlatformSpecific(
data->InitializePlatformSpecific(arraysize(registers), registers, NULL);
}
void BinaryOpWithVectorDescriptor::InitializePlatformSpecific(
CallInterfaceDescriptorData* data) {
// register state
// a1 -- lhs
// a0 -- rhs
// a4 -- slot id
// a3 -- vector
Register registers[] = {a1, a0, a4, a3};
data->InitializePlatformSpecific(arraysize(registers), registers);
}
void CountOpDescriptor::InitializePlatformSpecific(
CallInterfaceDescriptorData* data) {
Register registers[] = {a1};
......
......@@ -293,6 +293,17 @@ void BinaryOpWithAllocationSiteDescriptor::InitializePlatformSpecific(
data->InitializePlatformSpecific(arraysize(registers), registers);
}
void BinaryOpWithVectorDescriptor::InitializePlatformSpecific(
CallInterfaceDescriptorData* data) {
// register state
// r4 -- lhs
// r3 -- rhs
// r7 -- slot id
// r6 -- vector
Register registers[] = {r4, r3, r7, r6};
data->InitializePlatformSpecific(arraysize(registers), registers);
}
void CountOpDescriptor::InitializePlatformSpecific(
CallInterfaceDescriptorData* data) {
Register registers[] = {r4};
......
......@@ -294,6 +294,17 @@ void BinaryOpWithAllocationSiteDescriptor::InitializePlatformSpecific(
data->InitializePlatformSpecific(arraysize(registers), registers);
}
void BinaryOpWithVectorDescriptor::InitializePlatformSpecific(
CallInterfaceDescriptorData* data) {
// register state
// rdx -- lhs
// rax -- rhs
// rdi -- slot id
// rbx -- vector
Register registers[] = {rdx, rax, rdi, rbx};
data->InitializePlatformSpecific(arraysize(registers), registers);
}
void CountOpDescriptor::InitializePlatformSpecific(
CallInterfaceDescriptorData* data) {
Register registers[] = {rax};
......
......@@ -301,6 +301,17 @@ void BinaryOpWithAllocationSiteDescriptor::InitializePlatformSpecific(
data->InitializePlatformSpecific(arraysize(registers), registers, NULL);
}
void BinaryOpWithVectorDescriptor::InitializePlatformSpecific(
CallInterfaceDescriptorData* data) {
// register state
// edx -- lhs
// eax -- rhs
// edi -- slot id
// ebx -- vector
Register registers[] = {edx, eax, edi, ebx};
data->InitializePlatformSpecific(arraysize(registers), registers);
}
void CountOpDescriptor::InitializePlatformSpecific(
CallInterfaceDescriptorData* data) {
Register registers[] = {eax};
......
......@@ -31,7 +31,7 @@ snippet: "
"
frame size: 3
parameter count: 1
bytecode array length: 34
bytecode array length: 35
bytecodes: [
/* 30 E> */ B(StackCheck),
/* 42 S> */ B(LdaSmi), U8(1),
......@@ -44,7 +44,7 @@ bytecodes: [
/* 54 E> */ B(StaKeyedPropertySloppy), R(2), R(1), U8(2),
B(LdaSmi), U8(1),
B(Star), R(1),
/* 57 E> */ B(AddSmi), U8(1), R(0),
/* 57 E> */ B(AddSmi), U8(1), R(0), U8(1),
B(StaKeyedPropertySloppy), R(2), R(1), U8(2),
B(Ldar), R(2),
/* 66 S> */ B(Return),
......@@ -79,7 +79,7 @@ snippet: "
"
frame size: 5
parameter count: 1
bytecode array length: 64
bytecode array length: 65
bytecodes: [
/* 30 E> */ B(StackCheck),
/* 42 S> */ B(LdaSmi), U8(1),
......@@ -102,7 +102,7 @@ bytecodes: [
B(Star), R(4),
B(LdaZero),
B(Star), R(3),
/* 66 E> */ B(AddSmi), U8(2), R(0),
/* 66 E> */ B(AddSmi), U8(2), R(0), U8(3),
B(StaKeyedPropertySloppy), R(4), R(3), U8(4),
B(Ldar), R(4),
B(StaKeyedPropertySloppy), R(2), R(1), U8(6),
......
......@@ -197,7 +197,7 @@ snippet: "
"
frame size: 5
parameter count: 1
bytecode array length: 71
bytecode array length: 72
bytecodes: [
/* 30 E> */ B(StackCheck),
/* 42 S> */ B(LdaSmi), U8(10),
......@@ -209,7 +209,7 @@ bytecodes: [
B(Star), R(0),
/* 68 E> */ B(Add), R(2), U8(1),
B(Star), R(3),
/* 76 E> */ B(AddSmi), U8(1), R(0),
/* 76 E> */ B(AddSmi), U8(1), R(0), U8(2),
B(Star), R(4),
B(LdaSmi), U8(2),
B(Star), R(1),
......
......@@ -19,12 +19,12 @@ snippet: "
"
frame size: 1
parameter count: 1
bytecode array length: 14
bytecode array length: 15
bytecodes: [
/* 30 E> */ B(StackCheck),
/* 42 S> */ B(LdaZero),
B(Star), R(0),
/* 56 S> */ B(AddSmi), U8(1), R(0),
/* 56 S> */ B(AddSmi), U8(1), R(0), U8(1),
B(Star), R(0),
/* 69 S> */ B(Jump), U8(2),
/* 97 S> */ B(Ldar), R(0),
......
......@@ -24,7 +24,7 @@ snippet: "
"
frame size: 6
parameter count: 1
bytecode array length: 35
bytecode array length: 36
bytecodes: [
B(Mov), R(closure), R(0),
/* 99 E> */ B(StackCheck),
......@@ -37,7 +37,7 @@ bytecodes: [
B(Star), R(1),
/* 117 E> */ B(Call), R(1), R(this), U8(1), U8(1),
B(Star), R(3),
B(AddSmi), U8(1), R(3),
B(AddSmi), U8(1), R(3), U8(7),
/* 131 S> */ B(Return),
]
constant pool: [
......
......@@ -13,12 +13,12 @@ snippet: "
"
frame size: 2
parameter count: 1
bytecode array length: 15
bytecode array length: 16
bytecodes: [
/* 30 E> */ B(StackCheck),
/* 42 S> */ B(LdaSmi), U8(1),
B(Star), R(0),
/* 45 S> */ B(AddSmi), U8(2), R(0),
/* 45 S> */ B(AddSmi), U8(2), R(0), U8(1),
B(Mov), R(0), R(1),
B(Star), R(0),
B(LdaUndefined),
......@@ -109,7 +109,7 @@ snippet: "
"
frame size: 2
parameter count: 1
bytecode array length: 25
bytecode array length: 26
bytecodes: [
B(CreateFunctionContext), U8(1),
B(PushContext), R(0),
......@@ -118,7 +118,7 @@ bytecodes: [
/* 42 E> */ B(StaContextSlot), R(context), U8(4),
/* 45 S> */ B(CreateClosure), U8(0), U8(2),
/* 75 S> */ B(LdrContextSlot), R(context), U8(4), R(1),
B(BitwiseOrSmi), U8(24), R(1),
B(BitwiseOrSmi), U8(24), R(1), U8(1),
/* 77 E> */ B(StaContextSlot), R(context), U8(4),
B(LdaUndefined),
/* 84 S> */ B(Return),
......
......@@ -16,11 +16,11 @@ snippet: "
"
frame size: 1
parameter count: 1
bytecode array length: 11
bytecode array length: 12
bytecodes: [
/* 26 E> */ B(StackCheck),
/* 31 S> */ B(LdrGlobal), U8(1), R(0),
B(BitwiseAndSmi), U8(1), R(0),
B(BitwiseAndSmi), U8(1), R(0), U8(3),
/* 45 E> */ B(StaGlobalSloppy), U8(0), U8(4),
/* 51 S> */ B(Return),
]
......@@ -38,11 +38,11 @@ snippet: "
"
frame size: 1
parameter count: 1
bytecode array length: 11
bytecode array length: 12
bytecodes: [
/* 27 E> */ B(StackCheck),
/* 32 S> */ B(LdrGlobal), U8(1), R(0),
B(AddSmi), U8(1), R(0),
B(AddSmi), U8(1), R(0), U8(3),
/* 51 E> */ B(StaGlobalSloppy), U8(0), U8(4),
/* 57 S> */ B(Return),
]
......
......@@ -116,13 +116,13 @@ snippet: "
"
frame size: 2
parameter count: 1
bytecode array length: 22
bytecode array length: 23
bytecodes: [
/* 10 E> */ B(StackCheck),
/* 25 S> */ B(LdaSmi), U8(1),
B(Star), R(0),
/* 30 S> */ B(JumpIfToBooleanFalse), U8(12),
/* 43 S> */ B(AddSmi), U8(1), R(0),
/* 30 S> */ B(JumpIfToBooleanFalse), U8(13),
/* 43 S> */ B(AddSmi), U8(1), R(0), U8(1),
B(Mov), R(0), R(1),
B(Star), R(0),
B(Jump), U8(5),
......
......@@ -74,13 +74,13 @@ snippet: "
"
frame size: 2
parameter count: 1
bytecode array length: 20
bytecode array length: 21
bytecodes: [
/* 30 E> */ B(StackCheck),
/* 42 S> */ B(LdaSmi), U8(1),
B(Star), R(0),
/* 45 S> */ B(CreateObjectLiteral), U8(0), U8(0), U8(1), R(1),
/* 67 E> */ B(AddSmi), U8(1), R(0),
/* 67 E> */ B(AddSmi), U8(1), R(0), U8(1),
B(StaNamedPropertySloppy), R(1), U8(1), U8(2),
B(Ldar), R(1),
/* 76 S> */ B(Return),
......
......@@ -32,12 +32,12 @@ snippet: "
"
frame size: 1
parameter count: 1
bytecode array length: 8
bytecode array length: 9
bytecodes: [
/* 30 E> */ B(StackCheck),
/* 42 S> */ B(LdaZero),
B(Star), R(0),
/* 45 S> */ B(AddSmi), U8(3), R(0),
/* 45 S> */ B(AddSmi), U8(3), R(0), U8(1),
/* 59 S> */ B(Return),
]
constant pool: [
......@@ -51,12 +51,12 @@ snippet: "
"
frame size: 1
parameter count: 1
bytecode array length: 8
bytecode array length: 9
bytecodes: [
/* 30 E> */ B(StackCheck),
/* 42 S> */ B(LdaZero),
B(Star), R(0),
/* 45 S> */ B(SubSmi), U8(3), R(0),
/* 45 S> */ B(SubSmi), U8(3), R(0), U8(1),
/* 59 S> */ B(Return),
]
constant pool: [
......@@ -130,12 +130,12 @@ snippet: "
"
frame size: 1
parameter count: 1
bytecode array length: 9
bytecode array length: 10
bytecodes: [
/* 30 E> */ B(StackCheck),
/* 42 S> */ B(LdaSmi), U8(1),
B(Star), R(0),
/* 45 S> */ B(BitwiseOrSmi), U8(2), R(0),
/* 45 S> */ B(BitwiseOrSmi), U8(2), R(0), U8(1),
/* 59 S> */ B(Return),
]
constant pool: [
......@@ -169,12 +169,12 @@ snippet: "
"
frame size: 1
parameter count: 1
bytecode array length: 9
bytecode array length: 10
bytecodes: [
/* 30 E> */ B(StackCheck),
/* 42 S> */ B(LdaSmi), U8(1),
B(Star), R(0),
/* 45 S> */ B(BitwiseAndSmi), U8(2), R(0),
/* 45 S> */ B(BitwiseAndSmi), U8(2), R(0), U8(1),
/* 59 S> */ B(Return),
]
constant pool: [
......@@ -188,12 +188,12 @@ snippet: "
"
frame size: 1
parameter count: 1
bytecode array length: 9
bytecode array length: 10
bytecodes: [
/* 30 E> */ B(StackCheck),
/* 42 S> */ B(LdaSmi), U8(10),
B(Star), R(0),
/* 46 S> */ B(ShiftLeftSmi), U8(3), R(0),
/* 46 S> */ B(ShiftLeftSmi), U8(3), R(0), U8(1),
/* 61 S> */ B(Return),
]
constant pool: [
......@@ -207,12 +207,12 @@ snippet: "
"
frame size: 1
parameter count: 1
bytecode array length: 9
bytecode array length: 10
bytecodes: [
/* 30 E> */ B(StackCheck),
/* 42 S> */ B(LdaSmi), U8(10),
B(Star), R(0),
/* 46 S> */ B(ShiftRightSmi), U8(3), R(0),
/* 46 S> */ B(ShiftRightSmi), U8(3), R(0), U8(1),
/* 61 S> */ B(Return),
]
constant pool: [
......
......@@ -481,7 +481,7 @@ snippet: "
"
frame size: 5
parameter count: 1
bytecode array length: 58
bytecode array length: 59
bytecodes: [
/* 30 E> */ B(StackCheck),
/* 42 S> */ B(LdaSmi), U8(1),
......@@ -493,9 +493,9 @@ bytecodes: [
B(JumpIfToBooleanTrue), U8(10),
B(LdaSmi), U8(2),
B(TestEqualStrict), R(3),
B(JumpIfTrue), U8(32),
B(Jump), U8(34),
/* 77 E> */ B(AddSmi), U8(1), R(2),
B(JumpIfTrue), U8(33),
B(Jump), U8(35),
/* 77 E> */ B(AddSmi), U8(1), R(2), U8(1),
B(Star), R(1),
/* 70 S> */ B(LdaSmi), U8(2),
B(TestEqualStrict), R(1),
......
......@@ -17,18 +17,18 @@ snippet: "
"
frame size: 1
parameter count: 1
bytecode array length: 21
bytecode array length: 22
bytecodes: [
/* 30 E> */ B(StackCheck),
/* 42 S> */ B(LdaZero),
B(Star), R(0),
/* 54 S> */ B(LdaSmi), U8(10),
/* 54 E> */ B(TestEqual), R(0),
B(JumpIfTrue), U8(10),
B(JumpIfTrue), U8(11),
/* 45 E> */ B(StackCheck),
/* 65 S> */ B(AddSmi), U8(10), R(0),
/* 65 S> */ B(AddSmi), U8(10), R(0), U8(1),
B(Star), R(0),
B(Jump), U8(-12),
B(Jump), U8(-13),
/* 79 S> */ B(Ldar), R(0),
/* 89 S> */ B(Return),
]
......@@ -97,7 +97,7 @@ snippet: "
"
frame size: 4
parameter count: 1
bytecode array length: 22
bytecode array length: 23
bytecodes: [
/* 30 E> */ B(StackCheck),
/* 42 S> */ B(Wide), B(LdaSmi), U16(1234),
......@@ -105,7 +105,7 @@ bytecodes: [
/* 56 S> */ B(Nop),
/* 66 E> */ B(Mul), R(0), U8(1),
B(Star), R(3),
B(SubSmi), U8(1), R(3),
B(SubSmi), U8(1), R(3), U8(2),
B(LdrUndefined), R(1),
B(Ldar), R(1),
/* 74 S> */ B(Nop),
......
......@@ -281,7 +281,7 @@ TEST(InterpreterShiftOpsSmi) {
.Return();
Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(isolate);
InterpreterTester tester(isolate, bytecode_array);
InterpreterTester tester(isolate, bytecode_array, vector);
auto callable = tester.GetCallable<>();
Handle<Object> return_value = callable().ToHandleChecked();
Handle<Object> expected_value =
......@@ -321,7 +321,7 @@ TEST(InterpreterBinaryOpsSmi) {
.Return();
Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(isolate);
InterpreterTester tester(isolate, bytecode_array);
InterpreterTester tester(isolate, bytecode_array, vector);
auto callable = tester.GetCallable<>();
Handle<Object> return_value = callable().ToHandleChecked();
Handle<Object> expected_value =
......@@ -362,7 +362,7 @@ TEST(InterpreterBinaryOpsHeapNumber) {
.Return();
Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(isolate);
InterpreterTester tester(isolate, bytecode_array);
InterpreterTester tester(isolate, bytecode_array, vector);
auto callable = tester.GetCallable<>();
Handle<Object> return_value = callable().ToHandleChecked();
Handle<Object> expected_value =
......@@ -655,6 +655,110 @@ TEST(InterpreterBinaryOpTypeFeedback) {
}
}
TEST(InterpreterBinaryOpSmiTypeFeedback) {
HandleAndZoneScope handles;
i::Isolate* isolate = handles.main_isolate();
i::Zone zone(isolate->allocator());
struct BinaryOpExpectation {
Token::Value op;
Handle<Object> arg1;
int32_t arg2;
Handle<Object> result;
int32_t feedback;
};
BinaryOpExpectation const kTestCases[] = {
// ADD
{Token::Value::ADD, Handle<Smi>(Smi::FromInt(2), isolate), 42,
Handle<Smi>(Smi::FromInt(44), isolate),
BinaryOperationFeedback::kSignedSmall},
{Token::Value::ADD, Handle<Smi>(Smi::FromInt(2), isolate), Smi::kMaxValue,
isolate->factory()->NewHeapNumber(Smi::kMaxValue + 2.0),
BinaryOperationFeedback::kNumber},
{Token::Value::ADD, isolate->factory()->NewHeapNumber(3.1415), 2,
isolate->factory()->NewHeapNumber(3.1415 + 2.0),
BinaryOperationFeedback::kNumber},
{Token::Value::ADD, isolate->factory()->NewStringFromAsciiChecked("2"), 2,
isolate->factory()->NewStringFromAsciiChecked("22"),
BinaryOperationFeedback::kAny},
// SUB
{Token::Value::SUB, Handle<Smi>(Smi::FromInt(2), isolate), 42,
Handle<Smi>(Smi::FromInt(-40), isolate),
BinaryOperationFeedback::kSignedSmall},
{Token::Value::SUB, Handle<Smi>(Smi::FromInt(Smi::kMinValue), isolate), 1,
isolate->factory()->NewHeapNumber(Smi::kMinValue - 1.0),
BinaryOperationFeedback::kNumber},
{Token::Value::SUB, isolate->factory()->NewHeapNumber(3.1415), 2,
isolate->factory()->NewHeapNumber(3.1415 - 2.0),
BinaryOperationFeedback::kNumber},
{Token::Value::SUB, isolate->factory()->NewStringFromAsciiChecked("2"), 2,
Handle<Smi>(Smi::FromInt(0), isolate), BinaryOperationFeedback::kAny},
// BIT_OR
{Token::Value::BIT_OR, Handle<Smi>(Smi::FromInt(4), isolate), 1,
Handle<Smi>(Smi::FromInt(5), isolate),
BinaryOperationFeedback::kSignedSmall},
{Token::Value::BIT_OR, isolate->factory()->NewHeapNumber(3.1415), 8,
Handle<Smi>(Smi::FromInt(11), isolate),
BinaryOperationFeedback::kNumber},
{Token::Value::BIT_OR, isolate->factory()->NewStringFromAsciiChecked("2"),
1, Handle<Smi>(Smi::FromInt(3), isolate), BinaryOperationFeedback::kAny},
// BIT_AND
{Token::Value::BIT_AND, Handle<Smi>(Smi::FromInt(3), isolate), 1,
Handle<Smi>(Smi::FromInt(1), isolate),
BinaryOperationFeedback::kSignedSmall},
{Token::Value::BIT_AND, isolate->factory()->NewHeapNumber(3.1415), 2,
Handle<Smi>(Smi::FromInt(2), isolate), BinaryOperationFeedback::kNumber},
{Token::Value::BIT_AND,
isolate->factory()->NewStringFromAsciiChecked("2"), 1,
Handle<Smi>(Smi::FromInt(0), isolate), BinaryOperationFeedback::kAny},
// SHL
{Token::Value::SHL, Handle<Smi>(Smi::FromInt(3), isolate), 1,
Handle<Smi>(Smi::FromInt(6), isolate),
BinaryOperationFeedback::kSignedSmall},
{Token::Value::SHL, isolate->factory()->NewHeapNumber(3.1415), 2,
Handle<Smi>(Smi::FromInt(12), isolate),
BinaryOperationFeedback::kNumber},
{Token::Value::SHL, isolate->factory()->NewStringFromAsciiChecked("2"), 1,
Handle<Smi>(Smi::FromInt(4), isolate), BinaryOperationFeedback::kAny},
// SAR
{Token::Value::SAR, Handle<Smi>(Smi::FromInt(3), isolate), 1,
Handle<Smi>(Smi::FromInt(1), isolate),
BinaryOperationFeedback::kSignedSmall},
{Token::Value::SAR, isolate->factory()->NewHeapNumber(3.1415), 2,
Handle<Smi>(Smi::FromInt(0), isolate), BinaryOperationFeedback::kNumber},
{Token::Value::SAR, isolate->factory()->NewStringFromAsciiChecked("2"), 1,
Handle<Smi>(Smi::FromInt(1), isolate), BinaryOperationFeedback::kAny}};
for (const BinaryOpExpectation& test_case : kTestCases) {
BytecodeArrayBuilder builder(isolate, handles.main_zone(), 1, 0, 1);
i::FeedbackVectorSpec feedback_spec(&zone);
i::FeedbackVectorSlot slot0 = feedback_spec.AddGeneralSlot();
Handle<i::TypeFeedbackVector> vector =
i::NewTypeFeedbackVector(isolate, &feedback_spec);
Register reg(0);
builder.LoadLiteral(test_case.arg1)
.StoreAccumulatorInRegister(reg)
.LoadLiteral(Smi::FromInt(test_case.arg2))
.BinaryOperation(test_case.op, reg, vector->GetIndex(slot0))
.Return();
Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(isolate);
InterpreterTester tester(isolate, bytecode_array, vector);
auto callable = tester.GetCallable<>();
Handle<Object> return_val = callable().ToHandleChecked();
Object* feedback0 = vector->Get(slot0);
CHECK(feedback0->IsSmi());
CHECK_EQ(test_case.feedback, static_cast<Smi*>(feedback0)->value());
CHECK(Object::Equals(test_case.result, return_val).ToChecked());
}
}
TEST(InterpreterUnaryOpFeedback) {
HandleAndZoneScope handles;
i::Isolate* isolate = handles.main_isolate();
......@@ -1311,7 +1415,7 @@ TEST(InterpreterJumps) {
.Return();
Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(isolate);
InterpreterTester tester(isolate, bytecode_array);
InterpreterTester tester(isolate, bytecode_array, vector);
auto callable = tester.GetCallable<>();
Handle<Object> return_value = callable().ToHandleChecked();
CHECK_EQ(Smi::cast(*return_value)->value(), 7);
......@@ -1361,7 +1465,7 @@ TEST(InterpreterConditionalJumps) {
.Return();
Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(isolate);
InterpreterTester tester(isolate, bytecode_array);
InterpreterTester tester(isolate, bytecode_array, vector);
auto callable = tester.GetCallable<>();
Handle<Object> return_value = callable().ToHandleChecked();
CHECK_EQ(Smi::cast(*return_value)->value(), 7);
......@@ -1411,7 +1515,7 @@ TEST(InterpreterConditionalJumps2) {
.Return();
Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(isolate);
InterpreterTester tester(isolate, bytecode_array);
InterpreterTester tester(isolate, bytecode_array, vector);
auto callable = tester.GetCallable<>();
Handle<Object> return_value = callable().ToHandleChecked();
CHECK_EQ(Smi::cast(*return_value)->value(), 7);
......@@ -1469,7 +1573,7 @@ TEST(InterpreterJumpConstantWith16BitOperand) {
}
CHECK(found_16bit_constant_jump);
InterpreterTester tester(isolate, bytecode_array);
InterpreterTester tester(isolate, bytecode_array, vector);
auto callable = tester.GetCallable<>();
Handle<Object> return_value = callable().ToHandleChecked();
CHECK_EQ(Smi::cast(*return_value)->value(), 256.0 / 2 * (1 + 256));
......
......@@ -458,15 +458,17 @@ TEST_F(BytecodePeepholeOptimizerTest, MergeLdaSmiWithBinaryOp) {
BytecodeNode first(Bytecode::kLdaSmi, imm_operand);
first.source_info().Clone({3, true});
uint32_t reg_operand = Register(0).ToOperand();
BytecodeNode second(operator_replacement[0], reg_operand, 1);
uint32_t idx_operand = 1;
BytecodeNode second(operator_replacement[0], reg_operand, idx_operand);
optimizer()->Write(&first);
optimizer()->Write(&second);
Flush();
CHECK_EQ(write_count(), 1);
CHECK_EQ(last_written().bytecode(), operator_replacement[1]);
CHECK_EQ(last_written().operand_count(), 2);
CHECK_EQ(last_written().operand_count(), 3);
CHECK_EQ(last_written().operand(0), imm_operand);
CHECK_EQ(last_written().operand(1), reg_operand);
CHECK_EQ(last_written().operand(2), idx_operand);
CHECK_EQ(last_written().source_info(), first.source_info());
Reset();
}
......@@ -509,15 +511,17 @@ TEST_F(BytecodePeepholeOptimizerTest, MergeLdaZeroWithBinaryOp) {
for (auto operator_replacement : operator_replacement_pairs) {
BytecodeNode first(Bytecode::kLdaZero);
uint32_t reg_operand = Register(0).ToOperand();
BytecodeNode second(operator_replacement[0], reg_operand, 1);
uint32_t idx_operand = 1;
BytecodeNode second(operator_replacement[0], reg_operand, idx_operand);
optimizer()->Write(&first);
optimizer()->Write(&second);
Flush();
CHECK_EQ(write_count(), 1);
CHECK_EQ(last_written().bytecode(), operator_replacement[1]);
CHECK_EQ(last_written().operand_count(), 2);
CHECK_EQ(last_written().operand_count(), 3);
CHECK_EQ(last_written().operand(0), 0);
CHECK_EQ(last_written().operand(1), reg_operand);
CHECK_EQ(last_written().operand(2), idx_operand);
Reset();
}
}
......
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