Commit 5deb0bc1 authored by klaasb's avatar klaasb Committed by Commit bot

[interpreter] Inline FastCloneShallowArrayStub into bytecode handler

The CreateArrayLiteral bytecode handler now directly inlines the FastCloneShallowArrayStub.

BUG=v8:4280

Review-Url: https://codereview.chromium.org/2341743003
Cr-Commit-Position: refs/heads/master@{#39562}
parent 3b4cc88e
......@@ -5788,15 +5788,15 @@ compiler::Node* NonEmptyShallowClone(CodeStubAssembler* assembler,
// static
compiler::Node* FastCloneShallowArrayStub::Generate(
CodeStubAssembler* assembler, compiler::Node* closure,
compiler::Node* literal_index, compiler::Node* constant_elements,
compiler::Node* context, AllocationSiteMode allocation_site_mode) {
compiler::Node* literal_index, compiler::Node* context,
CodeStubAssembler::Label* call_runtime,
AllocationSiteMode allocation_site_mode) {
typedef CodeStubAssembler::Label Label;
typedef CodeStubAssembler::Variable Variable;
typedef compiler::Node Node;
Label call_runtime(assembler, Label::kDeferred), zero_capacity(assembler),
cow_elements(assembler), fast_elements(assembler),
return_result(assembler);
Label zero_capacity(assembler), cow_elements(assembler),
fast_elements(assembler), return_result(assembler);
Variable result(assembler, MachineRepresentation::kTagged);
Node* literals_array =
......@@ -5808,7 +5808,7 @@ compiler::Node* FastCloneShallowArrayStub::Generate(
Node* undefined = assembler->UndefinedConstant();
assembler->GotoIf(assembler->WordEqual(allocation_site, undefined),
&call_runtime);
call_runtime);
allocation_site = assembler->LoadFixedArrayElement(
literals_array, literal_index,
LiteralsArray::kFirstLiteralIndex * kPointerSize,
......@@ -5900,21 +5900,6 @@ compiler::Node* FastCloneShallowArrayStub::Generate(
assembler->Goto(&return_result);
}
assembler->Bind(&call_runtime);
{
assembler->Comment("call runtime");
Node* flags = assembler->SmiConstant(
Smi::FromInt(ArrayLiteral::kShallowElements |
(allocation_site_mode == TRACK_ALLOCATION_SITE
? 0
: ArrayLiteral::kDisableMementos)));
Node* array =
assembler->CallRuntime(Runtime::kCreateArrayLiteral, context, closure,
literal_index, constant_elements, flags);
result.Bind(array);
assembler->Goto(&return_result);
}
assembler->Bind(&return_result);
return result.value();
}
......@@ -5922,14 +5907,27 @@ compiler::Node* FastCloneShallowArrayStub::Generate(
void FastCloneShallowArrayStub::GenerateAssembly(
CodeStubAssembler* assembler) const {
typedef compiler::Node Node;
typedef CodeStubAssembler::Label Label;
Node* closure = assembler->Parameter(Descriptor::kClosure);
Node* literal_index = assembler->Parameter(Descriptor::kLiteralIndex);
Node* constant_elements = assembler->Parameter(Descriptor::kConstantElements);
Node* context = assembler->Parameter(Descriptor::kContext);
Label call_runtime(assembler, Label::kDeferred);
assembler->Return(Generate(assembler, closure, literal_index, context,
&call_runtime, allocation_site_mode()));
assembler->Return(Generate(assembler, closure, literal_index,
constant_elements, context,
allocation_site_mode()));
assembler->Bind(&call_runtime);
{
assembler->Comment("call runtime");
Node* flags = assembler->SmiConstant(
Smi::FromInt(ArrayLiteral::kShallowElements |
(allocation_site_mode() == TRACK_ALLOCATION_SITE
? 0
: ArrayLiteral::kDisableMementos)));
assembler->Return(assembler->CallRuntime(Runtime::kCreateArrayLiteral,
context, closure, literal_index,
constant_elements, flags));
}
}
void CreateAllocationSiteStub::GenerateAheadOfTime(Isolate* isolate) {
......
......@@ -1274,8 +1274,8 @@ class FastCloneShallowArrayStub : public TurboFanCodeStub {
static compiler::Node* Generate(CodeStubAssembler* assembler,
compiler::Node* closure,
compiler::Node* literal_index,
compiler::Node* constant_elements,
compiler::Node* context,
CodeStubAssembler::Label* call_runtime,
AllocationSiteMode allocation_site_mode);
AllocationSiteMode allocation_site_mode() const {
......
......@@ -10,6 +10,14 @@ namespace v8 {
namespace internal {
namespace interpreter {
// static
uint8_t CreateArrayLiteralFlags::Encode(bool use_fast_shallow_clone,
int runtime_flags) {
uint8_t result = FlagsBits::encode(runtime_flags);
result |= FastShallowCloneBit::encode(use_fast_shallow_clone);
return result;
}
// static
uint8_t CreateObjectLiteralFlags::Encode(bool fast_clone_supported,
int properties_count,
......
......@@ -11,6 +11,17 @@ namespace v8 {
namespace internal {
namespace interpreter {
class CreateArrayLiteralFlags {
public:
class FlagsBits : public BitField8<int, 0, 3> {};
class FastShallowCloneBit : public BitField8<bool, FlagsBits::kNext, 1> {};
static uint8_t Encode(bool use_fast_shallow_clone, int runtime_flags);
private:
DISALLOW_IMPLICIT_CONSTRUCTORS(CreateArrayLiteralFlags);
};
class CreateObjectLiteralFlags {
public:
class FlagsBits : public BitField8<int, 0, 3> {};
......
......@@ -1876,8 +1876,14 @@ void BytecodeGenerator::VisitObjectLiteral(ObjectLiteral* expr) {
void BytecodeGenerator::VisitArrayLiteral(ArrayLiteral* expr) {
// Deep-copy the literal boilerplate.
int runtime_flags = expr->ComputeFlags();
bool use_fast_shallow_clone =
(runtime_flags & ArrayLiteral::kShallowElements) != 0 &&
expr->values()->length() <= JSArray::kInitialMaxFastElementArray;
uint8_t flags =
CreateArrayLiteralFlags::Encode(use_fast_shallow_clone, runtime_flags);
builder()->CreateArrayLiteral(expr->constant_elements(),
expr->literal_index(), expr->ComputeFlags());
expr->literal_index(), flags);
Register index, literal;
// Evaluate all the non-constant subexpressions and store them into the
......
......@@ -2011,21 +2011,47 @@ void Interpreter::DoCreateRegExpLiteral(InterpreterAssembler* assembler) {
// CreateArrayLiteral <element_idx> <literal_idx> <flags>
//
// Creates an array literal for literal index <literal_idx> with flags <flags>
// and constant elements in <element_idx>.
// Creates an array literal for literal index <literal_idx> with
// CreateArrayLiteral flags <flags> and constant elements in <element_idx>.
void Interpreter::DoCreateArrayLiteral(InterpreterAssembler* assembler) {
Node* index = __ BytecodeOperandIdx(0);
Node* constant_elements = __ LoadConstantPoolEntry(index);
Node* literal_index_raw = __ BytecodeOperandIdx(1);
Node* literal_index = __ SmiTag(literal_index_raw);
Node* flags_raw = __ BytecodeOperandFlag(2);
Node* flags = __ SmiTag(flags_raw);
Node* closure = __ LoadRegister(Register::function_closure());
Node* context = __ GetContext();
Node* result = __ CallRuntime(Runtime::kCreateArrayLiteral, context, closure,
Node* bytecode_flags = __ BytecodeOperandFlag(2);
Label fast_shallow_clone(assembler),
call_runtime(assembler, Label::kDeferred);
Node* use_fast_shallow_clone = __ Word32And(
bytecode_flags,
__ Int32Constant(CreateArrayLiteralFlags::FastShallowCloneBit::kMask));
__ BranchIf(use_fast_shallow_clone, &fast_shallow_clone, &call_runtime);
__ Bind(&fast_shallow_clone);
{
DCHECK(FLAG_allocation_site_pretenuring);
Node* result = FastCloneShallowArrayStub::Generate(
assembler, closure, literal_index, context, &call_runtime,
TRACK_ALLOCATION_SITE);
__ SetAccumulator(result);
__ Dispatch();
}
__ Bind(&call_runtime);
{
STATIC_ASSERT(CreateArrayLiteralFlags::FlagsBits::kShift == 0);
Node* flags_raw = __ Word32And(
bytecode_flags,
__ Int32Constant(CreateArrayLiteralFlags::FlagsBits::kMask));
Node* flags = __ SmiTag(flags_raw);
Node* index = __ BytecodeOperandIdx(0);
Node* constant_elements = __ LoadConstantPoolEntry(index);
Node* result =
__ CallRuntime(Runtime::kCreateArrayLiteral, context, closure,
literal_index, constant_elements, flags);
__ SetAccumulator(result);
__ Dispatch();
}
}
// CreateObjectLiteral <element_idx> <literal_idx> <flags>
......
......@@ -15,7 +15,7 @@ parameter count: 1
bytecode array length: 6
bytecodes: [
/* 30 E> */ B(StackCheck),
/* 34 S> */ B(CreateArrayLiteral), U8(0), U8(0), U8(1),
/* 34 S> */ B(CreateArrayLiteral), U8(0), U8(0), U8(9),
/* 51 S> */ B(Return),
]
constant pool: [
......@@ -35,7 +35,7 @@ bytecodes: [
/* 30 E> */ B(StackCheck),
/* 42 S> */ B(LdaSmi), U8(1),
B(Star), R(0),
/* 45 S> */ B(CreateArrayLiteral), U8(0), U8(0), U8(1),
/* 45 S> */ B(CreateArrayLiteral), U8(0), U8(0), U8(9),
B(Star), R(2),
B(LdaZero),
B(Star), R(1),
......@@ -87,7 +87,7 @@ bytecodes: [
B(Star), R(2),
B(LdaZero),
B(Star), R(1),
B(CreateArrayLiteral), U8(1), U8(0), U8(1),
B(CreateArrayLiteral), U8(1), U8(0), U8(9),
B(Star), R(4),
B(LdaZero),
B(Star), R(3),
......@@ -97,7 +97,7 @@ bytecodes: [
B(StaKeyedPropertySloppy), R(2), R(1), U8(7),
B(LdaSmi), U8(1),
B(Star), R(1),
B(CreateArrayLiteral), U8(2), U8(1), U8(1),
B(CreateArrayLiteral), U8(2), U8(1), U8(9),
B(Star), R(4),
B(LdaZero),
B(Star), R(3),
......
......@@ -784,7 +784,7 @@ bytecodes: [
B(Star), R(0),
/* 2591 S> */ B(LdaConstant), U8(255),
B(Star), R(0),
/* 2601 S> */ B(Wide), B(CreateArrayLiteral), U16(256), U16(0), U8(1),
/* 2601 S> */ B(Wide), B(CreateArrayLiteral), U16(256), U16(0), U8(9),
/* 2619 S> */ B(Return),
]
constant pool: [
......
......@@ -77,7 +77,7 @@ bytecode array length: 14
bytecodes: [
/* 10 E> */ B(StackCheck),
/* 15 S> */ B(LdrUndefined), R(0),
B(CreateArrayLiteral), U8(0), U8(0), U8(1),
B(CreateArrayLiteral), U8(0), U8(0), U8(9),
B(Star), R(1),
B(CallJSRuntime), U8(135), R(0), U8(2),
/* 44 S> */ B(Return),
......
......@@ -257,7 +257,7 @@ bytecodes: [
/* 30 E> */ B(StackCheck),
/* 44 S> */ B(LdaSmi), U8(1),
B(Star), R(0),
/* 55 S> */ B(CreateArrayLiteral), U8(0), U8(0), U8(1),
/* 55 S> */ B(CreateArrayLiteral), U8(0), U8(0), U8(9),
B(Star), R(1),
/* 63 S> */ B(Ldar), R(0),
B(ToNumber), R(3),
......
......@@ -108,7 +108,7 @@ bytecodes: [
/* 30 E> */ B(StackCheck),
/* 42 S> */ B(LdaZero),
B(Star), R(0),
/* 59 S> */ B(CreateArrayLiteral), U8(0), U8(0), U8(1),
/* 59 S> */ B(CreateArrayLiteral), U8(0), U8(0), U8(9),
B(JumpIfUndefined), U8(46),
B(JumpIfNull), U8(44),
B(ToObject), R(3),
......@@ -153,7 +153,7 @@ bytecodes: [
/* 30 E> */ B(StackCheck),
/* 42 S> */ B(CreateObjectLiteral), U8(0), U8(0), U8(1), R(1),
B(Mov), R(1), R(0),
/* 77 S> */ B(CreateArrayLiteral), U8(1), U8(1), U8(1),
/* 77 S> */ B(CreateArrayLiteral), U8(1), U8(1), U8(9),
B(JumpIfUndefined), U8(68),
B(JumpIfNull), U8(66),
B(ToObject), R(1),
......@@ -203,9 +203,9 @@ parameter count: 1
bytecode array length: 62
bytecodes: [
/* 30 E> */ B(StackCheck),
/* 42 S> */ B(CreateArrayLiteral), U8(0), U8(0), U8(1),
/* 42 S> */ B(CreateArrayLiteral), U8(0), U8(0), U8(9),
B(Star), R(0),
/* 72 S> */ B(CreateArrayLiteral), U8(1), U8(1), U8(1),
/* 72 S> */ B(CreateArrayLiteral), U8(1), U8(1), U8(9),
B(JumpIfUndefined), U8(49),
B(JumpIfNull), U8(47),
B(ToObject), R(1),
......
......@@ -19,7 +19,7 @@ bytecodes: [
B(Star), R(4),
B(Mov), R(context), R(11),
B(Mov), R(context), R(12),
/* 48 S> */ B(CreateArrayLiteral), U8(0), U8(0), U8(1),
/* 48 S> */ B(CreateArrayLiteral), U8(0), U8(0), U8(9),
B(Star), R(14),
B(LdaConstant), U8(1),
/* 48 E> */ B(LdrKeyedProperty), R(14), U8(4), R(13),
......@@ -303,7 +303,7 @@ bytecodes: [
B(Star), R(4),
B(Mov), R(context), R(11),
B(Mov), R(context), R(12),
/* 48 S> */ B(CreateArrayLiteral), U8(0), U8(0), U8(1),
/* 48 S> */ B(CreateArrayLiteral), U8(0), U8(0), U8(9),
B(Star), R(14),
B(LdaConstant), U8(1),
/* 48 E> */ B(LdrKeyedProperty), R(14), U8(4), R(13),
......@@ -451,7 +451,7 @@ bytecodes: [
B(Star), R(3),
B(Mov), R(context), R(10),
B(Mov), R(context), R(11),
/* 77 S> */ B(CreateArrayLiteral), U8(1), U8(1), U8(1),
/* 77 S> */ B(CreateArrayLiteral), U8(1), U8(1), U8(9),
B(Star), R(13),
B(LdaConstant), U8(2),
/* 77 E> */ B(LdrKeyedProperty), R(13), U8(4), R(12),
......
......@@ -333,7 +333,7 @@ bytecodes: [
B(StaContextSlot), R(1), U8(9), U8(0),
B(Mov), R(context), R(10),
B(Mov), R(context), R(11),
/* 30 S> */ B(CreateArrayLiteral), U8(1), U8(0), U8(1),
/* 30 S> */ B(CreateArrayLiteral), U8(1), U8(0), U8(9),
B(Star), R(13),
B(LdaConstant), U8(2),
/* 30 E> */ B(LdrKeyedProperty), R(13), U8(4), R(12),
......
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