2012-12-18 16:25:45 +00:00
|
|
|
// Copyright 2012 the V8 project authors. All rights reserved.
|
2014-04-29 06:42:26 +00:00
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
2012-12-18 16:25:45 +00:00
|
|
|
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/v8.h"
|
2012-12-18 16:25:45 +00:00
|
|
|
|
2014-09-24 07:08:27 +00:00
|
|
|
#include "src/bailout-reason.h"
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/code-stubs.h"
|
2014-06-10 14:01:08 +00:00
|
|
|
#include "src/field-index.h"
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/hydrogen.h"
|
2014-12-12 13:56:11 +00:00
|
|
|
#include "src/ic/ic.h"
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/lithium.h"
|
2012-12-18 16:25:45 +00:00
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
|
|
|
|
|
2013-01-28 13:24:41 +00:00
|
|
|
static LChunk* OptimizeGraph(HGraph* graph) {
|
2013-06-03 15:32:22 +00:00
|
|
|
DisallowHeapAllocation no_allocation;
|
|
|
|
DisallowHandleAllocation no_handles;
|
|
|
|
DisallowHandleDereference no_deref;
|
2013-01-28 13:24:41 +00:00
|
|
|
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(graph != NULL);
|
2013-08-02 09:53:11 +00:00
|
|
|
BailoutReason bailout_reason = kNoReason;
|
2013-01-28 13:24:41 +00:00
|
|
|
if (!graph->Optimize(&bailout_reason)) {
|
2013-08-02 09:53:11 +00:00
|
|
|
FATAL(GetBailoutReason(bailout_reason));
|
2013-01-28 13:24:41 +00:00
|
|
|
}
|
2012-12-18 16:25:45 +00:00
|
|
|
LChunk* chunk = LChunk::NewChunk(graph);
|
2013-01-28 13:24:41 +00:00
|
|
|
if (chunk == NULL) {
|
2013-08-02 09:53:11 +00:00
|
|
|
FATAL(GetBailoutReason(graph->info()->bailout_reason()));
|
2013-01-28 13:24:41 +00:00
|
|
|
}
|
|
|
|
return chunk;
|
2012-12-18 16:25:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class CodeStubGraphBuilderBase : public HGraphBuilder {
|
|
|
|
public:
|
2014-12-12 12:36:03 +00:00
|
|
|
explicit CodeStubGraphBuilderBase(CompilationInfoWithZone* info)
|
|
|
|
: HGraphBuilder(info),
|
2013-03-08 21:07:55 +00:00
|
|
|
arguments_length_(NULL),
|
2014-12-12 12:36:03 +00:00
|
|
|
info_(info),
|
|
|
|
descriptor_(info->code_stub()),
|
2013-03-08 21:07:55 +00:00
|
|
|
context_(NULL) {
|
2014-09-05 15:20:45 +00:00
|
|
|
int parameter_count = descriptor_.GetEnvironmentParameterCount();
|
2014-07-17 11:50:04 +00:00
|
|
|
parameters_.Reset(new HParameter*[parameter_count]);
|
2013-02-25 14:03:09 +00:00
|
|
|
}
|
2012-12-18 16:25:45 +00:00
|
|
|
virtual bool BuildGraph();
|
|
|
|
|
|
|
|
protected:
|
2013-03-08 21:07:55 +00:00
|
|
|
virtual HValue* BuildCodeStub() = 0;
|
|
|
|
HParameter* GetParameter(int parameter) {
|
2014-09-05 15:20:45 +00:00
|
|
|
DCHECK(parameter < descriptor_.GetEnvironmentParameterCount());
|
2013-03-08 21:07:55 +00:00
|
|
|
return parameters_[parameter];
|
|
|
|
}
|
|
|
|
HValue* GetArgumentsLength() {
|
|
|
|
// This is initialized in BuildGraph()
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(arguments_length_ != NULL);
|
2013-03-08 21:07:55 +00:00
|
|
|
return arguments_length_;
|
|
|
|
}
|
2014-12-12 12:36:03 +00:00
|
|
|
CompilationInfo* info() { return info_; }
|
|
|
|
HydrogenCodeStub* stub() { return info_->code_stub(); }
|
2012-12-28 16:25:38 +00:00
|
|
|
HContext* context() { return context_; }
|
2014-12-12 12:36:03 +00:00
|
|
|
Isolate* isolate() { return info_->isolate(); }
|
2012-12-18 16:25:45 +00:00
|
|
|
|
2014-02-17 13:23:04 +00:00
|
|
|
HLoadNamedField* BuildLoadNamedField(HValue* object,
|
2014-06-10 14:01:08 +00:00
|
|
|
FieldIndex index);
|
2014-08-06 09:31:10 +00:00
|
|
|
void BuildStoreNamedField(HValue* object, HValue* value, FieldIndex index,
|
2014-09-29 13:11:27 +00:00
|
|
|
Representation representation,
|
|
|
|
bool transition_to_field);
|
2014-02-17 13:23:04 +00:00
|
|
|
|
2013-06-05 10:43:18 +00:00
|
|
|
enum ArgumentClass {
|
|
|
|
NONE,
|
|
|
|
SINGLE,
|
|
|
|
MULTIPLE
|
|
|
|
};
|
|
|
|
|
2014-09-22 13:23:27 +00:00
|
|
|
HValue* UnmappedCase(HValue* elements, HValue* key);
|
|
|
|
|
2013-06-05 10:43:18 +00:00
|
|
|
HValue* BuildArrayConstructor(ElementsKind kind,
|
2013-06-28 13:16:14 +00:00
|
|
|
AllocationSiteOverrideMode override_mode,
|
2013-06-05 10:43:18 +00:00
|
|
|
ArgumentClass argument_class);
|
|
|
|
HValue* BuildInternalArrayConstructor(ElementsKind kind,
|
|
|
|
ArgumentClass argument_class);
|
|
|
|
|
2014-03-12 13:29:42 +00:00
|
|
|
// BuildCheckAndInstallOptimizedCode emits code to install the optimized
|
|
|
|
// function found in the optimized code map at map_index in js_function, if
|
|
|
|
// the function at map_index matches the given native_context. Builder is
|
|
|
|
// left in the "Then()" state after the install.
|
|
|
|
void BuildCheckAndInstallOptimizedCode(HValue* js_function,
|
|
|
|
HValue* native_context,
|
|
|
|
IfBuilder* builder,
|
|
|
|
HValue* optimized_map,
|
|
|
|
HValue* map_index);
|
2013-08-27 11:55:08 +00:00
|
|
|
void BuildInstallCode(HValue* js_function, HValue* shared_info);
|
2014-03-12 13:29:42 +00:00
|
|
|
|
|
|
|
HInstruction* LoadFromOptimizedCodeMap(HValue* optimized_map,
|
|
|
|
HValue* iterator,
|
|
|
|
int field_offset);
|
2013-08-27 11:55:08 +00:00
|
|
|
void BuildInstallFromOptimizedCodeMap(HValue* js_function,
|
|
|
|
HValue* shared_info,
|
|
|
|
HValue* native_context);
|
|
|
|
|
2014-12-12 13:56:11 +00:00
|
|
|
// Tail calls handler found at array[map_index + 1].
|
|
|
|
void TailCallHandler(HValue* receiver, HValue* name, HValue* array,
|
|
|
|
HValue* map_index, HValue* slot, HValue* vector);
|
|
|
|
|
|
|
|
// Tail calls handler_code.
|
|
|
|
void TailCallHandler(HValue* receiver, HValue* name, HValue* slot,
|
|
|
|
HValue* vector, HValue* handler_code);
|
|
|
|
|
|
|
|
void TailCallMiss(HValue* receiver, HValue* name, HValue* slot,
|
|
|
|
HValue* vector, bool keyed_load);
|
|
|
|
|
|
|
|
// Handle MONOMORPHIC and POLYMORPHIC LoadIC and KeyedLoadIC cases.
|
|
|
|
void HandleArrayCases(HValue* array, HValue* receiver, HValue* name,
|
|
|
|
HValue* slot, HValue* vector, bool keyed_load);
|
|
|
|
|
2012-12-18 16:25:45 +00:00
|
|
|
private:
|
2013-06-05 10:43:18 +00:00
|
|
|
HValue* BuildArraySingleArgumentConstructor(JSArrayBuilder* builder);
|
|
|
|
HValue* BuildArrayNArgumentsConstructor(JSArrayBuilder* builder,
|
|
|
|
ElementsKind kind);
|
|
|
|
|
2012-12-18 16:25:45 +00:00
|
|
|
SmartArrayPointer<HParameter*> parameters_;
|
2013-03-08 21:07:55 +00:00
|
|
|
HValue* arguments_length_;
|
2014-12-12 12:36:03 +00:00
|
|
|
CompilationInfoWithZone* info_;
|
2014-09-08 15:18:54 +00:00
|
|
|
CodeStubDescriptor descriptor_;
|
2012-12-28 16:25:38 +00:00
|
|
|
HContext* context_;
|
2012-12-18 16:25:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
bool CodeStubGraphBuilderBase::BuildGraph() {
|
2013-04-18 20:37:27 +00:00
|
|
|
// Update the static counter each time a new code stub is generated.
|
|
|
|
isolate()->counters()->code_stubs()->Increment();
|
|
|
|
|
2013-07-24 12:38:52 +00:00
|
|
|
if (FLAG_trace_hydrogen_stubs) {
|
2013-02-08 11:56:15 +00:00
|
|
|
const char* name = CodeStub::MajorName(stub()->MajorKey(), false);
|
2012-12-18 16:25:45 +00:00
|
|
|
PrintF("-----------------------------------------------------------\n");
|
2013-02-08 11:56:15 +00:00
|
|
|
PrintF("Compiling stub %s using hydrogen\n", name);
|
2014-12-12 12:36:03 +00:00
|
|
|
isolate()->GetHTracer()->TraceCompilation(info());
|
2012-12-18 16:25:45 +00:00
|
|
|
}
|
|
|
|
|
2014-09-05 15:20:45 +00:00
|
|
|
int param_count = descriptor_.GetEnvironmentParameterCount();
|
2013-03-08 21:07:55 +00:00
|
|
|
HEnvironment* start_environment = graph()->start_environment();
|
2013-04-17 14:11:39 +00:00
|
|
|
HBasicBlock* next_block = CreateBasicBlock(start_environment);
|
2013-10-21 13:35:48 +00:00
|
|
|
Goto(next_block);
|
2013-02-25 14:03:09 +00:00
|
|
|
next_block->SetJoinId(BailoutId::StubEntry());
|
|
|
|
set_current_block(next_block);
|
|
|
|
|
2014-09-05 15:20:45 +00:00
|
|
|
bool runtime_stack_params = descriptor_.stack_parameter_count().is_valid();
|
2013-11-13 10:07:04 +00:00
|
|
|
HInstruction* stack_parameter_count = NULL;
|
2013-02-25 14:03:09 +00:00
|
|
|
for (int i = 0; i < param_count; ++i) {
|
2014-09-05 15:20:45 +00:00
|
|
|
Representation r = descriptor_.GetEnvironmentParameterRepresentation(i);
|
2014-07-17 11:50:04 +00:00
|
|
|
HParameter* param = Add<HParameter>(i,
|
|
|
|
HParameter::REGISTER_PARAMETER, r);
|
2013-02-25 14:03:09 +00:00
|
|
|
start_environment->Bind(i, param);
|
2012-12-18 16:25:45 +00:00
|
|
|
parameters_[i] = param;
|
2014-09-05 15:20:45 +00:00
|
|
|
if (descriptor_.IsEnvironmentParameterCountRegister(i)) {
|
2013-11-13 10:07:04 +00:00
|
|
|
param->set_type(HType::Smi());
|
|
|
|
stack_parameter_count = param;
|
|
|
|
arguments_length_ = stack_parameter_count;
|
|
|
|
}
|
2012-12-18 16:25:45 +00:00
|
|
|
}
|
2013-02-04 12:01:59 +00:00
|
|
|
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(!runtime_stack_params || arguments_length_ != NULL);
|
2013-11-13 10:07:04 +00:00
|
|
|
if (!runtime_stack_params) {
|
2013-03-12 15:37:23 +00:00
|
|
|
stack_parameter_count = graph()->GetConstantMinus1();
|
|
|
|
arguments_length_ = graph()->GetConstant0();
|
2013-03-08 21:07:55 +00:00
|
|
|
}
|
|
|
|
|
2013-10-22 11:29:05 +00:00
|
|
|
context_ = Add<HContext>();
|
2013-03-08 21:07:55 +00:00
|
|
|
start_environment->BindContext(context_);
|
2013-02-04 12:01:59 +00:00
|
|
|
|
2013-07-23 13:35:10 +00:00
|
|
|
Add<HSimulate>(BailoutId::StubEntry());
|
2012-12-18 16:25:45 +00:00
|
|
|
|
2013-04-11 13:07:37 +00:00
|
|
|
NoObservableSideEffectsScope no_effects(this);
|
|
|
|
|
2013-03-08 21:07:55 +00:00
|
|
|
HValue* return_value = BuildCodeStub();
|
2013-04-02 11:28:01 +00:00
|
|
|
|
|
|
|
// We might have extra expressions to pop from the stack in addition to the
|
2013-05-23 09:17:01 +00:00
|
|
|
// arguments above.
|
2013-04-02 11:28:01 +00:00
|
|
|
HInstruction* stack_pop_count = stack_parameter_count;
|
2014-09-05 15:20:45 +00:00
|
|
|
if (descriptor_.function_mode() == JS_FUNCTION_STUB_MODE) {
|
2013-04-25 16:00:32 +00:00
|
|
|
if (!stack_parameter_count->IsConstant() &&
|
2014-09-05 15:20:45 +00:00
|
|
|
descriptor_.hint_stack_parameter_count() < 0) {
|
2013-11-13 10:07:04 +00:00
|
|
|
HInstruction* constant_one = graph()->GetConstant1();
|
2013-11-22 19:05:21 +00:00
|
|
|
stack_pop_count = AddUncasted<HAdd>(stack_parameter_count, constant_one);
|
2013-04-25 16:00:32 +00:00
|
|
|
stack_pop_count->ClearFlag(HValue::kCanOverflow);
|
2013-11-13 10:07:04 +00:00
|
|
|
// TODO(mvstanton): verify that stack_parameter_count+1 really fits in a
|
|
|
|
// smi.
|
2013-04-25 16:00:32 +00:00
|
|
|
} else {
|
2014-09-05 15:20:45 +00:00
|
|
|
int count = descriptor_.hint_stack_parameter_count();
|
2013-07-31 14:58:39 +00:00
|
|
|
stack_pop_count = Add<HConstant>(count);
|
2013-04-25 16:00:32 +00:00
|
|
|
}
|
2013-04-02 11:28:01 +00:00
|
|
|
}
|
|
|
|
|
2013-05-29 12:36:41 +00:00
|
|
|
if (current_block() != NULL) {
|
2013-07-31 14:58:39 +00:00
|
|
|
HReturn* hreturn_instruction = New<HReturn>(return_value,
|
|
|
|
stack_pop_count);
|
2013-10-21 13:35:48 +00:00
|
|
|
FinishCurrentBlock(hreturn_instruction);
|
2013-04-24 11:32:17 +00:00
|
|
|
}
|
2012-12-18 16:25:45 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-04-02 11:28:01 +00:00
|
|
|
|
2012-12-18 16:25:45 +00:00
|
|
|
template <class Stub>
|
|
|
|
class CodeStubGraphBuilder: public CodeStubGraphBuilderBase {
|
|
|
|
public:
|
2014-12-12 12:36:03 +00:00
|
|
|
explicit CodeStubGraphBuilder(CompilationInfoWithZone* info)
|
|
|
|
: CodeStubGraphBuilderBase(info) {}
|
2012-12-18 16:25:45 +00:00
|
|
|
|
|
|
|
protected:
|
2013-04-18 20:37:27 +00:00
|
|
|
virtual HValue* BuildCodeStub() {
|
2013-05-24 11:44:55 +00:00
|
|
|
if (casted_stub()->IsUninitialized()) {
|
2013-04-18 20:37:27 +00:00
|
|
|
return BuildCodeUninitializedStub();
|
2013-05-24 11:44:55 +00:00
|
|
|
} else {
|
|
|
|
return BuildCodeInitializedStub();
|
2013-04-18 20:37:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual HValue* BuildCodeInitializedStub() {
|
|
|
|
UNIMPLEMENTED();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual HValue* BuildCodeUninitializedStub() {
|
|
|
|
// Force a deopt that falls back to the runtime.
|
|
|
|
HValue* undefined = graph()->GetConstantUndefined();
|
2013-04-22 11:15:43 +00:00
|
|
|
IfBuilder builder(this);
|
|
|
|
builder.IfNot<HCompareObjectEqAndBranch, HValue*>(undefined, undefined);
|
|
|
|
builder.Then();
|
2013-08-09 12:50:42 +00:00
|
|
|
builder.ElseDeopt("Forced deopt to runtime");
|
2013-04-18 20:37:27 +00:00
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
2012-12-18 16:25:45 +00:00
|
|
|
Stub* casted_stub() { return static_cast<Stub*>(stub()); }
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-09-08 15:18:54 +00:00
|
|
|
Handle<Code> HydrogenCodeStub::GenerateLightweightMissCode(
|
|
|
|
ExternalReference miss) {
|
2014-04-24 12:07:40 +00:00
|
|
|
Factory* factory = isolate()->factory();
|
2013-04-18 20:37:27 +00:00
|
|
|
|
|
|
|
// Generate the new code.
|
2014-04-24 12:07:40 +00:00
|
|
|
MacroAssembler masm(isolate(), NULL, 256);
|
2013-04-18 20:37:27 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
// Update the static counter each time a new code stub is generated.
|
2014-04-24 12:07:40 +00:00
|
|
|
isolate()->counters()->code_stubs()->Increment();
|
2013-04-18 20:37:27 +00:00
|
|
|
|
|
|
|
// Generate the code for the stub.
|
|
|
|
masm.set_generating_stub(true);
|
2014-10-13 07:50:21 +00:00
|
|
|
// TODO(yangguo): remove this once we can serialize IC stubs.
|
|
|
|
masm.enable_serializer();
|
2013-04-18 20:37:27 +00:00
|
|
|
NoCurrentFrameScope scope(&masm);
|
2014-09-08 15:18:54 +00:00
|
|
|
GenerateLightweightMiss(&masm, miss);
|
2013-04-18 20:37:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Create the code object.
|
|
|
|
CodeDesc desc;
|
|
|
|
masm.GetCode(&desc);
|
|
|
|
|
|
|
|
// Copy the generated code into a heap object.
|
|
|
|
Code::Flags flags = Code::ComputeFlags(
|
|
|
|
GetCodeKind(),
|
|
|
|
GetICState(),
|
|
|
|
GetExtraICState(),
|
2014-02-14 15:15:08 +00:00
|
|
|
GetStubType());
|
2013-04-18 20:37:27 +00:00
|
|
|
Handle<Code> new_object = factory->NewCode(
|
|
|
|
desc, flags, masm.CodeObject(), NeedsImmovableCode());
|
|
|
|
return new_object;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-20 12:01:49 +00:00
|
|
|
template <class Stub>
|
2014-04-24 12:07:40 +00:00
|
|
|
static Handle<Code> DoGenerateCode(Stub* stub) {
|
|
|
|
Isolate* isolate = stub->isolate();
|
2014-09-08 15:18:54 +00:00
|
|
|
CodeStubDescriptor descriptor(stub);
|
2013-05-24 11:44:55 +00:00
|
|
|
|
|
|
|
// If we are uninitialized we can use a light-weight stub to enter
|
2013-04-18 20:37:27 +00:00
|
|
|
// the runtime that is significantly faster than using the standard
|
|
|
|
// stub-failure deopt mechanism.
|
2014-09-05 15:20:45 +00:00
|
|
|
if (stub->IsUninitialized() && descriptor.has_miss_handler()) {
|
|
|
|
DCHECK(!descriptor.stack_parameter_count().is_valid());
|
2014-09-08 15:18:54 +00:00
|
|
|
return stub->GenerateLightweightMissCode(descriptor.miss_handler());
|
2013-04-18 20:37:27 +00:00
|
|
|
}
|
2014-06-30 13:25:46 +00:00
|
|
|
base::ElapsedTimer timer;
|
2013-10-02 11:27:37 +00:00
|
|
|
if (FLAG_profile_hydrogen_code_stub_compilation) {
|
|
|
|
timer.Start();
|
|
|
|
}
|
2014-12-12 12:36:03 +00:00
|
|
|
CompilationInfoWithZone info(stub, isolate);
|
|
|
|
CodeStubGraphBuilder<Stub> builder(&info);
|
2013-05-24 11:44:55 +00:00
|
|
|
LChunk* chunk = OptimizeGraph(builder.CreateGraph());
|
2013-10-02 11:27:37 +00:00
|
|
|
Handle<Code> code = chunk->Codegen();
|
|
|
|
if (FLAG_profile_hydrogen_code_stub_compilation) {
|
2014-07-03 07:18:30 +00:00
|
|
|
OFStream os(stdout);
|
|
|
|
os << "[Lazy compilation of " << stub << " took "
|
2014-09-30 10:29:32 +00:00
|
|
|
<< timer.Elapsed().InMillisecondsF() << " ms]" << std::endl;
|
2013-10-02 11:27:37 +00:00
|
|
|
}
|
|
|
|
return code;
|
2013-03-20 12:01:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-24 09:31:07 +00:00
|
|
|
template <>
|
|
|
|
HValue* CodeStubGraphBuilder<NumberToStringStub>::BuildCodeStub() {
|
|
|
|
info()->MarkAsSavesCallerDoubles();
|
|
|
|
HValue* number = GetParameter(NumberToStringStub::kNumber);
|
2014-01-21 16:22:52 +00:00
|
|
|
return BuildNumberToString(number, Type::Number(zone()));
|
2013-09-24 09:31:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-24 12:07:40 +00:00
|
|
|
Handle<Code> NumberToStringStub::GenerateCode() {
|
|
|
|
return DoGenerateCode(this);
|
2013-09-24 09:31:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-04 17:55:43 +00:00
|
|
|
template <>
|
|
|
|
HValue* CodeStubGraphBuilder<FastCloneShallowArrayStub>::BuildCodeStub() {
|
|
|
|
Factory* factory = isolate()->factory();
|
2013-04-22 11:15:43 +00:00
|
|
|
HValue* undefined = graph()->GetConstantUndefined();
|
2013-04-04 17:55:43 +00:00
|
|
|
AllocationSiteMode alloc_site_mode = casted_stub()->allocation_site_mode();
|
2014-05-12 07:49:11 +00:00
|
|
|
|
|
|
|
// This stub is very performance sensitive, the generated code must be tuned
|
|
|
|
// so that it doesn't build and eager frame.
|
|
|
|
info()->MarkMustNotHaveEagerFrame();
|
2013-04-04 17:55:43 +00:00
|
|
|
|
2014-12-15 04:33:05 +00:00
|
|
|
HInstruction* allocation_site =
|
|
|
|
Add<HLoadKeyed>(GetParameter(0), GetParameter(1), nullptr, FAST_ELEMENTS);
|
2013-04-22 11:15:43 +00:00
|
|
|
IfBuilder checker(this);
|
2013-07-31 14:58:39 +00:00
|
|
|
checker.IfNot<HCompareObjectEqAndBranch, HValue*>(allocation_site,
|
|
|
|
undefined);
|
2013-04-22 11:15:43 +00:00
|
|
|
checker.Then();
|
2013-04-04 17:55:43 +00:00
|
|
|
|
2013-10-28 09:36:49 +00:00
|
|
|
HObjectAccess access = HObjectAccess::ForAllocationSiteOffset(
|
|
|
|
AllocationSite::kTransitionInfoOffset);
|
2014-12-15 04:33:05 +00:00
|
|
|
HInstruction* boilerplate =
|
|
|
|
Add<HLoadNamedField>(allocation_site, nullptr, access);
|
2014-05-12 07:49:11 +00:00
|
|
|
HValue* elements = AddLoadElements(boilerplate);
|
|
|
|
HValue* capacity = AddLoadFixedArrayLength(elements);
|
|
|
|
IfBuilder zero_capacity(this);
|
|
|
|
zero_capacity.If<HCompareNumericAndBranch>(capacity, graph()->GetConstant0(),
|
|
|
|
Token::EQ);
|
|
|
|
zero_capacity.Then();
|
|
|
|
Push(BuildCloneShallowArrayEmpty(boilerplate,
|
|
|
|
allocation_site,
|
|
|
|
alloc_site_mode));
|
|
|
|
zero_capacity.Else();
|
|
|
|
IfBuilder if_fixed_cow(this);
|
|
|
|
if_fixed_cow.If<HCompareMap>(elements, factory->fixed_cow_array_map());
|
|
|
|
if_fixed_cow.Then();
|
|
|
|
Push(BuildCloneShallowArrayCow(boilerplate,
|
|
|
|
allocation_site,
|
|
|
|
alloc_site_mode,
|
|
|
|
FAST_ELEMENTS));
|
|
|
|
if_fixed_cow.Else();
|
|
|
|
IfBuilder if_fixed(this);
|
|
|
|
if_fixed.If<HCompareMap>(elements, factory->fixed_array_map());
|
|
|
|
if_fixed.Then();
|
|
|
|
Push(BuildCloneShallowArrayNonEmpty(boilerplate,
|
|
|
|
allocation_site,
|
|
|
|
alloc_site_mode,
|
|
|
|
FAST_ELEMENTS));
|
|
|
|
|
|
|
|
if_fixed.Else();
|
|
|
|
Push(BuildCloneShallowArrayNonEmpty(boilerplate,
|
|
|
|
allocation_site,
|
|
|
|
alloc_site_mode,
|
|
|
|
FAST_DOUBLE_ELEMENTS));
|
|
|
|
if_fixed.End();
|
|
|
|
if_fixed_cow.End();
|
|
|
|
zero_capacity.End();
|
2013-04-04 17:55:43 +00:00
|
|
|
|
2013-08-09 12:50:42 +00:00
|
|
|
checker.ElseDeopt("Uninitialized boilerplate literals");
|
2013-07-23 13:35:10 +00:00
|
|
|
checker.End();
|
|
|
|
|
|
|
|
return environment()->Pop();
|
2013-04-04 17:55:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-24 12:07:40 +00:00
|
|
|
Handle<Code> FastCloneShallowArrayStub::GenerateCode() {
|
|
|
|
return DoGenerateCode(this);
|
2013-04-04 17:55:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-26 13:08:08 +00:00
|
|
|
template <>
|
2013-03-08 21:07:55 +00:00
|
|
|
HValue* CodeStubGraphBuilder<FastCloneShallowObjectStub>::BuildCodeStub() {
|
2013-04-22 11:15:43 +00:00
|
|
|
HValue* undefined = graph()->GetConstantUndefined();
|
2013-02-26 13:08:08 +00:00
|
|
|
|
2014-12-15 04:33:05 +00:00
|
|
|
HInstruction* allocation_site =
|
|
|
|
Add<HLoadKeyed>(GetParameter(0), GetParameter(1), nullptr, FAST_ELEMENTS);
|
2013-02-26 13:08:08 +00:00
|
|
|
|
2013-04-22 11:15:43 +00:00
|
|
|
IfBuilder checker(this);
|
2013-10-11 09:25:14 +00:00
|
|
|
checker.IfNot<HCompareObjectEqAndBranch, HValue*>(allocation_site,
|
2013-07-31 14:58:39 +00:00
|
|
|
undefined);
|
2013-04-22 11:15:43 +00:00
|
|
|
checker.And();
|
2013-02-26 13:08:08 +00:00
|
|
|
|
2013-10-28 09:36:49 +00:00
|
|
|
HObjectAccess access = HObjectAccess::ForAllocationSiteOffset(
|
|
|
|
AllocationSite::kTransitionInfoOffset);
|
2014-12-15 04:33:05 +00:00
|
|
|
HInstruction* boilerplate =
|
|
|
|
Add<HLoadNamedField>(allocation_site, nullptr, access);
|
2013-10-11 09:25:14 +00:00
|
|
|
|
2014-10-15 08:48:44 +00:00
|
|
|
int length = casted_stub()->length();
|
|
|
|
if (length == 0) {
|
|
|
|
// Empty objects have some slack added to them.
|
|
|
|
length = JSObject::kInitialGlobalObjectUnusedPropertiesCount;
|
|
|
|
}
|
|
|
|
int size = JSObject::kHeaderSize + length * kPointerSize;
|
2013-10-11 09:25:14 +00:00
|
|
|
int object_size = size;
|
|
|
|
if (FLAG_allocation_site_pretenuring) {
|
|
|
|
size += AllocationMemento::kSize;
|
|
|
|
}
|
|
|
|
|
2014-12-15 04:33:05 +00:00
|
|
|
HValue* boilerplate_map =
|
|
|
|
Add<HLoadNamedField>(boilerplate, nullptr, HObjectAccess::ForMap());
|
2013-10-04 19:04:34 +00:00
|
|
|
HValue* boilerplate_size = Add<HLoadNamedField>(
|
2014-12-15 04:33:05 +00:00
|
|
|
boilerplate_map, nullptr, HObjectAccess::ForMapInstanceSize());
|
2013-10-11 09:25:14 +00:00
|
|
|
HValue* size_in_words = Add<HConstant>(object_size >> kPointerSizeLog2);
|
2013-07-05 10:40:14 +00:00
|
|
|
checker.If<HCompareNumericAndBranch>(boilerplate_size,
|
|
|
|
size_in_words, Token::EQ);
|
2013-04-22 11:15:43 +00:00
|
|
|
checker.Then();
|
2013-02-26 13:08:08 +00:00
|
|
|
|
2013-07-31 14:58:39 +00:00
|
|
|
HValue* size_in_bytes = Add<HConstant>(size);
|
2013-05-24 08:38:21 +00:00
|
|
|
|
2013-07-31 14:58:39 +00:00
|
|
|
HInstruction* object = Add<HAllocate>(size_in_bytes, HType::JSObject(),
|
2013-12-18 22:43:56 +00:00
|
|
|
NOT_TENURED, JS_OBJECT_TYPE);
|
2013-02-26 13:08:08 +00:00
|
|
|
|
2013-10-11 09:25:14 +00:00
|
|
|
for (int i = 0; i < object_size; i += kPointerSize) {
|
2014-02-04 10:48:49 +00:00
|
|
|
HObjectAccess access = HObjectAccess::ForObservableJSObjectOffset(i);
|
2014-12-15 04:33:05 +00:00
|
|
|
Add<HStoreNamedField>(object, access,
|
|
|
|
Add<HLoadNamedField>(boilerplate, nullptr, access));
|
2013-02-26 13:08:08 +00:00
|
|
|
}
|
|
|
|
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(FLAG_allocation_site_pretenuring || (size == object_size));
|
2013-10-11 09:25:14 +00:00
|
|
|
if (FLAG_allocation_site_pretenuring) {
|
2013-12-02 11:24:31 +00:00
|
|
|
BuildCreateAllocationMemento(
|
|
|
|
object, Add<HConstant>(object_size), allocation_site);
|
2013-10-11 09:25:14 +00:00
|
|
|
}
|
|
|
|
|
2013-07-23 13:35:10 +00:00
|
|
|
environment()->Push(object);
|
2013-08-09 12:50:42 +00:00
|
|
|
checker.ElseDeopt("Uninitialized boilerplate in fast clone");
|
2013-07-23 13:35:10 +00:00
|
|
|
checker.End();
|
|
|
|
|
|
|
|
return environment()->Pop();
|
2013-02-26 13:08:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-24 12:07:40 +00:00
|
|
|
Handle<Code> FastCloneShallowObjectStub::GenerateCode() {
|
|
|
|
return DoGenerateCode(this);
|
2013-02-26 13:08:08 +00:00
|
|
|
}
|
|
|
|
|
2013-03-20 12:01:57 +00:00
|
|
|
|
2013-07-08 10:02:16 +00:00
|
|
|
template <>
|
|
|
|
HValue* CodeStubGraphBuilder<CreateAllocationSiteStub>::BuildCodeStub() {
|
2013-07-31 13:45:51 +00:00
|
|
|
HValue* size = Add<HConstant>(AllocationSite::kSize);
|
2013-08-01 08:34:36 +00:00
|
|
|
HInstruction* object = Add<HAllocate>(size, HType::JSObject(), TENURED,
|
|
|
|
JS_OBJECT_TYPE);
|
2013-07-08 10:02:16 +00:00
|
|
|
|
|
|
|
// Store the map
|
2013-09-20 09:27:40 +00:00
|
|
|
Handle<Map> allocation_site_map = isolate()->factory()->allocation_site_map();
|
2013-07-08 10:02:16 +00:00
|
|
|
AddStoreMapConstant(object, allocation_site_map);
|
|
|
|
|
|
|
|
// Store the payload (smi elements kind)
|
2013-07-31 13:45:51 +00:00
|
|
|
HValue* initial_elements_kind = Add<HConstant>(GetInitialFastElementsKind());
|
2013-07-17 11:50:24 +00:00
|
|
|
Add<HStoreNamedField>(object,
|
2013-10-28 09:36:49 +00:00
|
|
|
HObjectAccess::ForAllocationSiteOffset(
|
|
|
|
AllocationSite::kTransitionInfoOffset),
|
2014-02-04 10:48:49 +00:00
|
|
|
initial_elements_kind);
|
2013-07-17 11:50:24 +00:00
|
|
|
|
2013-09-24 10:30:41 +00:00
|
|
|
// Unlike literals, constructed arrays don't have nested sites
|
|
|
|
Add<HStoreNamedField>(object,
|
2013-10-28 09:36:49 +00:00
|
|
|
HObjectAccess::ForAllocationSiteOffset(
|
|
|
|
AllocationSite::kNestedSiteOffset),
|
2014-02-04 10:48:49 +00:00
|
|
|
graph()->GetConstant0());
|
2013-09-24 10:30:41 +00:00
|
|
|
|
2014-01-13 10:28:01 +00:00
|
|
|
// Pretenuring calculation field.
|
2013-11-22 07:34:21 +00:00
|
|
|
Add<HStoreNamedField>(object,
|
|
|
|
HObjectAccess::ForAllocationSiteOffset(
|
2014-01-13 10:28:01 +00:00
|
|
|
AllocationSite::kPretenureDataOffset),
|
2014-02-04 10:48:49 +00:00
|
|
|
graph()->GetConstant0());
|
2013-11-22 07:34:21 +00:00
|
|
|
|
2014-01-13 10:28:01 +00:00
|
|
|
// Pretenuring memento creation count field.
|
2013-11-22 07:34:21 +00:00
|
|
|
Add<HStoreNamedField>(object,
|
|
|
|
HObjectAccess::ForAllocationSiteOffset(
|
2014-01-13 10:28:01 +00:00
|
|
|
AllocationSite::kPretenureCreateCountOffset),
|
2014-02-04 10:48:49 +00:00
|
|
|
graph()->GetConstant0());
|
2013-11-22 07:34:21 +00:00
|
|
|
|
2013-09-19 14:13:34 +00:00
|
|
|
// Store an empty fixed array for the code dependency.
|
|
|
|
HConstant* empty_fixed_array =
|
|
|
|
Add<HConstant>(isolate()->factory()->empty_fixed_array());
|
2014-05-20 11:25:47 +00:00
|
|
|
Add<HStoreNamedField>(
|
2013-09-19 14:13:34 +00:00
|
|
|
object,
|
2013-10-28 09:36:49 +00:00
|
|
|
HObjectAccess::ForAllocationSiteOffset(
|
|
|
|
AllocationSite::kDependentCodeOffset),
|
2014-02-04 10:48:49 +00:00
|
|
|
empty_fixed_array);
|
2013-09-19 14:13:34 +00:00
|
|
|
|
2013-07-31 10:47:44 +00:00
|
|
|
// Link the object to the allocation site list
|
|
|
|
HValue* site_list = Add<HConstant>(
|
|
|
|
ExternalReference::allocation_sites_list_address(isolate()));
|
2014-12-15 04:33:05 +00:00
|
|
|
HValue* site = Add<HLoadNamedField>(site_list, nullptr,
|
|
|
|
HObjectAccess::ForAllocationSiteList());
|
2014-05-20 11:25:47 +00:00
|
|
|
// TODO(mvstanton): This is a store to a weak pointer, which we may want to
|
|
|
|
// mark as such in order to skip the write barrier, once we have a unified
|
|
|
|
// system for weakness. For now we decided to keep it like this because having
|
|
|
|
// an initial write barrier backed store makes this pointer strong until the
|
|
|
|
// next GC, and allocation sites are designed to survive several GCs anyway.
|
|
|
|
Add<HStoreNamedField>(
|
|
|
|
object,
|
2013-10-28 09:36:49 +00:00
|
|
|
HObjectAccess::ForAllocationSiteOffset(AllocationSite::kWeakNextOffset),
|
2014-02-04 10:48:49 +00:00
|
|
|
site);
|
2013-07-31 14:58:39 +00:00
|
|
|
Add<HStoreNamedField>(site_list, HObjectAccess::ForAllocationSiteList(),
|
2014-02-04 10:48:49 +00:00
|
|
|
object);
|
2013-07-08 10:02:16 +00:00
|
|
|
|
2014-02-10 21:38:17 +00:00
|
|
|
HInstruction* feedback_vector = GetParameter(0);
|
|
|
|
HInstruction* slot = GetParameter(1);
|
|
|
|
Add<HStoreKeyed>(feedback_vector, slot, object, FAST_ELEMENTS,
|
|
|
|
INITIALIZING_STORE);
|
|
|
|
return feedback_vector;
|
2013-07-08 10:02:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-24 12:07:40 +00:00
|
|
|
Handle<Code> CreateAllocationSiteStub::GenerateCode() {
|
|
|
|
return DoGenerateCode(this);
|
2013-07-08 10:02:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-11-11 11:16:30 +00:00
|
|
|
template <>
|
2014-11-12 11:34:09 +00:00
|
|
|
HValue* CodeStubGraphBuilder<LoadScriptContextFieldStub>::BuildCodeStub() {
|
2014-11-11 11:16:30 +00:00
|
|
|
int context_index = casted_stub()->context_index();
|
|
|
|
int slot_index = casted_stub()->slot_index();
|
|
|
|
|
2014-11-12 11:34:09 +00:00
|
|
|
HValue* script_context = BuildGetScriptContext(context_index);
|
2014-12-15 04:33:05 +00:00
|
|
|
return Add<HLoadNamedField>(script_context, nullptr,
|
2014-11-11 11:16:30 +00:00
|
|
|
HObjectAccess::ForContextSlot(slot_index));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-11-12 11:34:09 +00:00
|
|
|
Handle<Code> LoadScriptContextFieldStub::GenerateCode() {
|
2014-11-11 11:16:30 +00:00
|
|
|
return DoGenerateCode(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-11-11 15:15:42 +00:00
|
|
|
template <>
|
2014-11-12 11:34:09 +00:00
|
|
|
HValue* CodeStubGraphBuilder<StoreScriptContextFieldStub>::BuildCodeStub() {
|
2014-11-11 15:15:42 +00:00
|
|
|
int context_index = casted_stub()->context_index();
|
|
|
|
int slot_index = casted_stub()->slot_index();
|
|
|
|
|
2014-11-12 11:34:09 +00:00
|
|
|
HValue* script_context = BuildGetScriptContext(context_index);
|
|
|
|
Add<HStoreNamedField>(script_context,
|
2014-11-11 15:15:42 +00:00
|
|
|
HObjectAccess::ForContextSlot(slot_index),
|
|
|
|
GetParameter(2), STORE_TO_INITIALIZED_ENTRY);
|
|
|
|
return GetParameter(2);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-11-12 11:34:09 +00:00
|
|
|
Handle<Code> StoreScriptContextFieldStub::GenerateCode() {
|
2014-11-11 15:15:42 +00:00
|
|
|
return DoGenerateCode(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-12-18 16:25:45 +00:00
|
|
|
template <>
|
2014-07-29 16:07:34 +00:00
|
|
|
HValue* CodeStubGraphBuilder<LoadFastElementStub>::BuildCodeStub() {
|
2012-12-18 16:25:45 +00:00
|
|
|
HInstruction* load = BuildUncheckedMonomorphicElementAccess(
|
2014-09-03 10:51:51 +00:00
|
|
|
GetParameter(LoadDescriptor::kReceiverIndex),
|
|
|
|
GetParameter(LoadDescriptor::kNameIndex), NULL,
|
2014-08-26 09:50:09 +00:00
|
|
|
casted_stub()->is_js_array(), casted_stub()->elements_kind(), LOAD,
|
|
|
|
NEVER_RETURN_HOLE, STANDARD_STORE);
|
2013-03-08 21:07:55 +00:00
|
|
|
return load;
|
2012-12-18 16:25:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-07-29 16:07:34 +00:00
|
|
|
Handle<Code> LoadFastElementStub::GenerateCode() {
|
2014-04-24 12:07:40 +00:00
|
|
|
return DoGenerateCode(this);
|
2012-12-18 16:25:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-02-17 13:23:04 +00:00
|
|
|
HLoadNamedField* CodeStubGraphBuilderBase::BuildLoadNamedField(
|
2014-06-10 14:01:08 +00:00
|
|
|
HValue* object, FieldIndex index) {
|
|
|
|
Representation representation = index.is_double()
|
|
|
|
? Representation::Double()
|
|
|
|
: Representation::Tagged();
|
|
|
|
int offset = index.offset();
|
|
|
|
HObjectAccess access = index.is_inobject()
|
2014-02-17 13:23:04 +00:00
|
|
|
? HObjectAccess::ForObservableJSObjectOffset(offset, representation)
|
|
|
|
: HObjectAccess::ForBackingStoreOffset(offset, representation);
|
2014-11-11 10:24:52 +00:00
|
|
|
if (index.is_double() &&
|
|
|
|
(!FLAG_unbox_double_fields || !index.is_inobject())) {
|
2014-02-17 13:23:04 +00:00
|
|
|
// Load the heap number.
|
|
|
|
object = Add<HLoadNamedField>(
|
2014-12-15 04:33:05 +00:00
|
|
|
object, nullptr, access.WithRepresentation(Representation::Tagged()));
|
2014-02-17 13:23:04 +00:00
|
|
|
// Load the double value from it.
|
|
|
|
access = HObjectAccess::ForHeapNumberValue();
|
|
|
|
}
|
2014-12-15 04:33:05 +00:00
|
|
|
return Add<HLoadNamedField>(object, nullptr, access);
|
2014-02-17 13:23:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-05-02 16:32:47 +00:00
|
|
|
template<>
|
|
|
|
HValue* CodeStubGraphBuilder<LoadFieldStub>::BuildCodeStub() {
|
2014-06-10 14:01:08 +00:00
|
|
|
return BuildLoadNamedField(GetParameter(0), casted_stub()->index());
|
2013-05-02 16:32:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-24 12:07:40 +00:00
|
|
|
Handle<Code> LoadFieldStub::GenerateCode() {
|
|
|
|
return DoGenerateCode(this);
|
2013-05-02 16:32:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-08-06 08:02:21 +00:00
|
|
|
template <>
|
|
|
|
HValue* CodeStubGraphBuilder<LoadConstantStub>::BuildCodeStub() {
|
|
|
|
HValue* map = AddLoadMap(GetParameter(0), NULL);
|
|
|
|
HObjectAccess descriptors_access = HObjectAccess::ForObservableJSObjectOffset(
|
|
|
|
Map::kDescriptorsOffset, Representation::Tagged());
|
2014-12-15 04:33:05 +00:00
|
|
|
HValue* descriptors = Add<HLoadNamedField>(map, nullptr, descriptors_access);
|
2014-08-06 08:02:21 +00:00
|
|
|
HObjectAccess value_access = HObjectAccess::ForObservableJSObjectOffset(
|
2014-09-01 13:55:39 +00:00
|
|
|
DescriptorArray::GetValueOffset(casted_stub()->constant_index()));
|
2014-12-15 04:33:05 +00:00
|
|
|
return Add<HLoadNamedField>(descriptors, nullptr, value_access);
|
2014-08-06 08:02:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<Code> LoadConstantStub::GenerateCode() { return DoGenerateCode(this); }
|
|
|
|
|
|
|
|
|
2014-09-22 13:23:27 +00:00
|
|
|
HValue* CodeStubGraphBuilderBase::UnmappedCase(HValue* elements, HValue* key) {
|
|
|
|
HValue* result;
|
2014-12-15 04:33:05 +00:00
|
|
|
HInstruction* backing_store =
|
|
|
|
Add<HLoadKeyed>(elements, graph()->GetConstant1(), nullptr, FAST_ELEMENTS,
|
|
|
|
ALLOW_RETURN_HOLE);
|
2014-09-22 13:23:27 +00:00
|
|
|
Add<HCheckMaps>(backing_store, isolate()->factory()->fixed_array_map());
|
2014-12-15 04:33:05 +00:00
|
|
|
HValue* backing_store_length = Add<HLoadNamedField>(
|
|
|
|
backing_store, nullptr, HObjectAccess::ForFixedArrayLength());
|
2014-09-22 13:23:27 +00:00
|
|
|
IfBuilder in_unmapped_range(this);
|
|
|
|
in_unmapped_range.If<HCompareNumericAndBranch>(key, backing_store_length,
|
|
|
|
Token::LT);
|
|
|
|
in_unmapped_range.Then();
|
|
|
|
{
|
2014-12-15 04:33:05 +00:00
|
|
|
result = Add<HLoadKeyed>(backing_store, key, nullptr, FAST_HOLEY_ELEMENTS,
|
|
|
|
NEVER_RETURN_HOLE);
|
2014-09-22 13:23:27 +00:00
|
|
|
}
|
|
|
|
in_unmapped_range.ElseDeopt("Outside of range");
|
|
|
|
in_unmapped_range.End();
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <>
|
|
|
|
HValue* CodeStubGraphBuilder<KeyedLoadSloppyArgumentsStub>::BuildCodeStub() {
|
|
|
|
HValue* receiver = GetParameter(LoadDescriptor::kReceiverIndex);
|
|
|
|
HValue* key = GetParameter(LoadDescriptor::kNameIndex);
|
|
|
|
|
|
|
|
// Mapped arguments are actual arguments. Unmapped arguments are values added
|
|
|
|
// to the arguments object after it was created for the call. Mapped arguments
|
|
|
|
// are stored in the context at indexes given by elements[key + 2]. Unmapped
|
|
|
|
// arguments are stored as regular indexed properties in the arguments array,
|
|
|
|
// held at elements[1]. See NewSloppyArguments() in runtime.cc for a detailed
|
|
|
|
// look at argument object construction.
|
|
|
|
//
|
|
|
|
// The sloppy arguments elements array has a special format:
|
|
|
|
//
|
|
|
|
// 0: context
|
|
|
|
// 1: unmapped arguments array
|
|
|
|
// 2: mapped_index0,
|
|
|
|
// 3: mapped_index1,
|
|
|
|
// ...
|
|
|
|
//
|
|
|
|
// length is 2 + min(number_of_actual_arguments, number_of_formal_arguments).
|
|
|
|
// If key + 2 >= elements.length then attempt to look in the unmapped
|
|
|
|
// arguments array (given by elements[1]) and return the value at key, missing
|
|
|
|
// to the runtime if the unmapped arguments array is not a fixed array or if
|
|
|
|
// key >= unmapped_arguments_array.length.
|
|
|
|
//
|
|
|
|
// Otherwise, t = elements[key + 2]. If t is the hole, then look up the value
|
|
|
|
// in the unmapped arguments array, as described above. Otherwise, t is a Smi
|
|
|
|
// index into the context array given at elements[0]. Return the value at
|
|
|
|
// context[t].
|
|
|
|
|
|
|
|
key = AddUncasted<HForceRepresentation>(key, Representation::Smi());
|
|
|
|
IfBuilder positive_smi(this);
|
|
|
|
positive_smi.If<HCompareNumericAndBranch>(key, graph()->GetConstant0(),
|
|
|
|
Token::LT);
|
|
|
|
positive_smi.ThenDeopt("key is negative");
|
|
|
|
positive_smi.End();
|
|
|
|
|
|
|
|
HValue* constant_two = Add<HConstant>(2);
|
2014-12-15 04:33:05 +00:00
|
|
|
HValue* elements = AddLoadElements(receiver, nullptr);
|
|
|
|
HValue* elements_length = Add<HLoadNamedField>(
|
|
|
|
elements, nullptr, HObjectAccess::ForFixedArrayLength());
|
2014-09-22 13:23:27 +00:00
|
|
|
HValue* adjusted_length = AddUncasted<HSub>(elements_length, constant_two);
|
|
|
|
IfBuilder in_range(this);
|
|
|
|
in_range.If<HCompareNumericAndBranch>(key, adjusted_length, Token::LT);
|
|
|
|
in_range.Then();
|
|
|
|
{
|
|
|
|
HValue* index = AddUncasted<HAdd>(key, constant_two);
|
2014-12-15 04:33:05 +00:00
|
|
|
HInstruction* mapped_index = Add<HLoadKeyed>(
|
|
|
|
elements, index, nullptr, FAST_HOLEY_ELEMENTS, ALLOW_RETURN_HOLE);
|
2014-09-22 13:23:27 +00:00
|
|
|
|
|
|
|
IfBuilder is_valid(this);
|
|
|
|
is_valid.IfNot<HCompareObjectEqAndBranch>(mapped_index,
|
|
|
|
graph()->GetConstantHole());
|
|
|
|
is_valid.Then();
|
|
|
|
{
|
|
|
|
// TODO(mvstanton): I'd like to assert from this point, that if the
|
|
|
|
// mapped_index is not the hole that it is indeed, a smi. An unnecessary
|
|
|
|
// smi check is being emitted.
|
2014-12-15 04:33:05 +00:00
|
|
|
HValue* the_context = Add<HLoadKeyed>(elements, graph()->GetConstant0(),
|
|
|
|
nullptr, FAST_ELEMENTS);
|
2014-09-22 13:23:27 +00:00
|
|
|
DCHECK(Context::kHeaderSize == FixedArray::kHeaderSize);
|
2014-12-15 04:33:05 +00:00
|
|
|
HValue* result = Add<HLoadKeyed>(the_context, mapped_index, nullptr,
|
|
|
|
FAST_ELEMENTS, ALLOW_RETURN_HOLE);
|
2014-09-22 13:23:27 +00:00
|
|
|
environment()->Push(result);
|
|
|
|
}
|
|
|
|
is_valid.Else();
|
|
|
|
{
|
|
|
|
HValue* result = UnmappedCase(elements, key);
|
|
|
|
environment()->Push(result);
|
|
|
|
}
|
|
|
|
is_valid.End();
|
|
|
|
}
|
|
|
|
in_range.Else();
|
|
|
|
{
|
|
|
|
HValue* result = UnmappedCase(elements, key);
|
|
|
|
environment()->Push(result);
|
|
|
|
}
|
|
|
|
in_range.End();
|
|
|
|
|
|
|
|
return environment()->Pop();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<Code> KeyedLoadSloppyArgumentsStub::GenerateCode() {
|
|
|
|
return DoGenerateCode(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-08-06 09:31:10 +00:00
|
|
|
void CodeStubGraphBuilderBase::BuildStoreNamedField(
|
|
|
|
HValue* object, HValue* value, FieldIndex index,
|
2014-09-29 13:11:27 +00:00
|
|
|
Representation representation, bool transition_to_field) {
|
2014-08-06 09:31:10 +00:00
|
|
|
DCHECK(!index.is_double() || representation.IsDouble());
|
|
|
|
int offset = index.offset();
|
|
|
|
HObjectAccess access =
|
|
|
|
index.is_inobject()
|
|
|
|
? HObjectAccess::ForObservableJSObjectOffset(offset, representation)
|
|
|
|
: HObjectAccess::ForBackingStoreOffset(offset, representation);
|
|
|
|
|
|
|
|
if (representation.IsDouble()) {
|
2014-11-11 10:24:52 +00:00
|
|
|
if (!FLAG_unbox_double_fields || !index.is_inobject()) {
|
|
|
|
HObjectAccess heap_number_access =
|
|
|
|
access.WithRepresentation(Representation::Tagged());
|
|
|
|
if (transition_to_field) {
|
|
|
|
// The store requires a mutable HeapNumber to be allocated.
|
|
|
|
NoObservableSideEffectsScope no_side_effects(this);
|
|
|
|
HInstruction* heap_number_size = Add<HConstant>(HeapNumber::kSize);
|
|
|
|
|
|
|
|
// TODO(hpayer): Allocation site pretenuring support.
|
|
|
|
HInstruction* heap_number =
|
|
|
|
Add<HAllocate>(heap_number_size, HType::HeapObject(), NOT_TENURED,
|
|
|
|
MUTABLE_HEAP_NUMBER_TYPE);
|
|
|
|
AddStoreMapConstant(heap_number,
|
|
|
|
isolate()->factory()->mutable_heap_number_map());
|
|
|
|
Add<HStoreNamedField>(heap_number, HObjectAccess::ForHeapNumberValue(),
|
|
|
|
value);
|
|
|
|
// Store the new mutable heap number into the object.
|
|
|
|
access = heap_number_access;
|
|
|
|
value = heap_number;
|
|
|
|
} else {
|
|
|
|
// Load the heap number.
|
2014-12-15 04:33:05 +00:00
|
|
|
object = Add<HLoadNamedField>(object, nullptr, heap_number_access);
|
2014-11-11 10:24:52 +00:00
|
|
|
// Store the double value into it.
|
|
|
|
access = HObjectAccess::ForHeapNumberValue();
|
|
|
|
}
|
2014-09-29 13:11:27 +00:00
|
|
|
}
|
2014-08-06 09:31:10 +00:00
|
|
|
} else if (representation.IsHeapObject()) {
|
|
|
|
BuildCheckHeapObject(value);
|
|
|
|
}
|
|
|
|
|
2014-08-07 13:09:33 +00:00
|
|
|
Add<HStoreNamedField>(object, access, value, INITIALIZING_STORE);
|
2014-08-06 09:31:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <>
|
|
|
|
HValue* CodeStubGraphBuilder<StoreFieldStub>::BuildCodeStub() {
|
|
|
|
BuildStoreNamedField(GetParameter(0), GetParameter(2), casted_stub()->index(),
|
2014-09-29 13:11:27 +00:00
|
|
|
casted_stub()->representation(), false);
|
2014-08-06 09:31:10 +00:00
|
|
|
return GetParameter(2);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<Code> StoreFieldStub::GenerateCode() { return DoGenerateCode(this); }
|
|
|
|
|
|
|
|
|
2014-09-29 13:11:27 +00:00
|
|
|
template <>
|
2014-09-30 14:54:14 +00:00
|
|
|
HValue* CodeStubGraphBuilder<StoreTransitionStub>::BuildCodeStub() {
|
|
|
|
HValue* object = GetParameter(StoreTransitionDescriptor::kReceiverIndex);
|
|
|
|
|
|
|
|
switch (casted_stub()->store_mode()) {
|
|
|
|
case StoreTransitionStub::ExtendStorageAndStoreMapAndValue: {
|
2014-12-15 04:33:05 +00:00
|
|
|
HValue* properties = Add<HLoadNamedField>(
|
|
|
|
object, nullptr, HObjectAccess::ForPropertiesPointer());
|
2014-09-30 14:54:14 +00:00
|
|
|
HValue* length = AddLoadFixedArrayLength(properties);
|
|
|
|
HValue* delta =
|
|
|
|
Add<HConstant>(static_cast<int32_t>(JSObject::kFieldsAdded));
|
|
|
|
HValue* new_capacity = AddUncasted<HAdd>(length, delta);
|
|
|
|
|
|
|
|
// Grow properties array.
|
|
|
|
ElementsKind kind = FAST_ELEMENTS;
|
|
|
|
Add<HBoundsCheck>(new_capacity,
|
|
|
|
Add<HConstant>((Page::kMaxRegularHeapObjectSize -
|
|
|
|
FixedArray::kHeaderSize) >>
|
|
|
|
ElementsKindToShiftSize(kind)));
|
|
|
|
|
|
|
|
// Reuse this code for properties backing store allocation.
|
|
|
|
HValue* new_properties =
|
|
|
|
BuildAllocateAndInitializeArray(kind, new_capacity);
|
|
|
|
|
|
|
|
BuildCopyProperties(properties, new_properties, length, new_capacity);
|
|
|
|
|
|
|
|
Add<HStoreNamedField>(object, HObjectAccess::ForPropertiesPointer(),
|
|
|
|
new_properties);
|
|
|
|
}
|
|
|
|
// Fall through.
|
|
|
|
case StoreTransitionStub::StoreMapAndValue:
|
2014-10-07 14:32:19 +00:00
|
|
|
// Store the new value into the "extended" object.
|
2014-09-30 14:54:14 +00:00
|
|
|
BuildStoreNamedField(
|
|
|
|
object, GetParameter(StoreTransitionDescriptor::kValueIndex),
|
|
|
|
casted_stub()->index(), casted_stub()->representation(), true);
|
|
|
|
// Fall through.
|
|
|
|
|
|
|
|
case StoreTransitionStub::StoreMapOnly:
|
|
|
|
// And finally update the map.
|
|
|
|
Add<HStoreNamedField>(object, HObjectAccess::ForMap(),
|
|
|
|
GetParameter(StoreTransitionDescriptor::kMapIndex));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return GetParameter(StoreTransitionDescriptor::kValueIndex);
|
2014-09-29 13:11:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-30 14:54:14 +00:00
|
|
|
Handle<Code> StoreTransitionStub::GenerateCode() {
|
|
|
|
return DoGenerateCode(this);
|
|
|
|
}
|
2014-09-29 13:11:27 +00:00
|
|
|
|
|
|
|
|
2014-08-06 08:02:21 +00:00
|
|
|
template <>
|
2014-03-13 10:57:07 +00:00
|
|
|
HValue* CodeStubGraphBuilder<StringLengthStub>::BuildCodeStub() {
|
2014-06-10 14:01:08 +00:00
|
|
|
HValue* string = BuildLoadNamedField(GetParameter(0),
|
|
|
|
FieldIndex::ForInObjectOffset(JSValue::kValueOffset));
|
|
|
|
return BuildLoadNamedField(string,
|
|
|
|
FieldIndex::ForInObjectOffset(String::kLengthOffset));
|
2013-05-02 16:32:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-24 12:07:40 +00:00
|
|
|
Handle<Code> StringLengthStub::GenerateCode() {
|
|
|
|
return DoGenerateCode(this);
|
2013-05-02 16:32:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-20 10:37:13 +00:00
|
|
|
template <>
|
2014-07-29 16:07:34 +00:00
|
|
|
HValue* CodeStubGraphBuilder<StoreFastElementStub>::BuildCodeStub() {
|
2013-03-20 10:37:13 +00:00
|
|
|
BuildUncheckedMonomorphicElementAccess(
|
2014-09-03 10:51:51 +00:00
|
|
|
GetParameter(StoreDescriptor::kReceiverIndex),
|
|
|
|
GetParameter(StoreDescriptor::kNameIndex),
|
|
|
|
GetParameter(StoreDescriptor::kValueIndex), casted_stub()->is_js_array(),
|
2014-08-26 09:50:09 +00:00
|
|
|
casted_stub()->elements_kind(), STORE, NEVER_RETURN_HOLE,
|
|
|
|
casted_stub()->store_mode());
|
2013-03-20 10:37:13 +00:00
|
|
|
|
|
|
|
return GetParameter(2);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-07-29 16:07:34 +00:00
|
|
|
Handle<Code> StoreFastElementStub::GenerateCode() {
|
2014-04-24 12:07:40 +00:00
|
|
|
return DoGenerateCode(this);
|
2013-03-20 10:37:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-04 12:01:59 +00:00
|
|
|
template <>
|
2013-03-08 21:07:55 +00:00
|
|
|
HValue* CodeStubGraphBuilder<TransitionElementsKindStub>::BuildCodeStub() {
|
2013-02-04 12:01:59 +00:00
|
|
|
info()->MarkAsSavesCallerDoubles();
|
|
|
|
|
2013-07-17 11:37:20 +00:00
|
|
|
BuildTransitionElementsKind(GetParameter(0),
|
|
|
|
GetParameter(1),
|
|
|
|
casted_stub()->from_kind(),
|
|
|
|
casted_stub()->to_kind(),
|
2014-03-18 13:29:29 +00:00
|
|
|
casted_stub()->is_js_array());
|
2013-05-24 08:38:21 +00:00
|
|
|
|
2013-07-17 11:37:20 +00:00
|
|
|
return GetParameter(0);
|
2013-02-04 12:01:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-24 12:07:40 +00:00
|
|
|
Handle<Code> TransitionElementsKindStub::GenerateCode() {
|
|
|
|
return DoGenerateCode(this);
|
2013-03-20 17:20:48 +00:00
|
|
|
}
|
|
|
|
|
2014-11-04 12:58:17 +00:00
|
|
|
|
|
|
|
template <>
|
|
|
|
HValue* CodeStubGraphBuilder<AllocateHeapNumberStub>::BuildCodeStub() {
|
|
|
|
HValue* result =
|
|
|
|
Add<HAllocate>(Add<HConstant>(HeapNumber::kSize), HType::HeapNumber(),
|
|
|
|
NOT_TENURED, HEAP_NUMBER_TYPE);
|
|
|
|
AddStoreMapConstant(result, isolate()->factory()->heap_number_map());
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<Code> AllocateHeapNumberStub::GenerateCode() {
|
|
|
|
return DoGenerateCode(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-05 10:43:18 +00:00
|
|
|
HValue* CodeStubGraphBuilderBase::BuildArrayConstructor(
|
2013-06-28 13:16:14 +00:00
|
|
|
ElementsKind kind,
|
|
|
|
AllocationSiteOverrideMode override_mode,
|
2013-06-05 10:43:18 +00:00
|
|
|
ArgumentClass argument_class) {
|
|
|
|
HValue* constructor = GetParameter(ArrayConstructorStubBase::kConstructor);
|
2014-01-21 16:04:39 +00:00
|
|
|
HValue* alloc_site = GetParameter(ArrayConstructorStubBase::kAllocationSite);
|
2013-07-08 10:02:16 +00:00
|
|
|
JSArrayBuilder array_builder(this, kind, alloc_site, constructor,
|
2013-06-28 13:16:14 +00:00
|
|
|
override_mode);
|
2013-06-05 10:43:18 +00:00
|
|
|
HValue* result = NULL;
|
|
|
|
switch (argument_class) {
|
|
|
|
case NONE:
|
2014-05-12 07:49:11 +00:00
|
|
|
// This stub is very performance sensitive, the generated code must be
|
|
|
|
// tuned so that it doesn't build and eager frame.
|
|
|
|
info()->MarkMustNotHaveEagerFrame();
|
2013-06-05 10:43:18 +00:00
|
|
|
result = array_builder.AllocateEmptyArray();
|
|
|
|
break;
|
|
|
|
case SINGLE:
|
|
|
|
result = BuildArraySingleArgumentConstructor(&array_builder);
|
|
|
|
break;
|
|
|
|
case MULTIPLE:
|
|
|
|
result = BuildArrayNArgumentsConstructor(&array_builder, kind);
|
|
|
|
break;
|
|
|
|
}
|
2013-06-28 13:16:14 +00:00
|
|
|
|
2013-06-05 10:43:18 +00:00
|
|
|
return result;
|
2013-03-01 16:06:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-05 10:43:18 +00:00
|
|
|
HValue* CodeStubGraphBuilderBase::BuildInternalArrayConstructor(
|
|
|
|
ElementsKind kind, ArgumentClass argument_class) {
|
|
|
|
HValue* constructor = GetParameter(
|
|
|
|
InternalArrayConstructorStubBase::kConstructor);
|
|
|
|
JSArrayBuilder array_builder(this, kind, constructor);
|
|
|
|
|
|
|
|
HValue* result = NULL;
|
|
|
|
switch (argument_class) {
|
|
|
|
case NONE:
|
2014-05-12 07:49:11 +00:00
|
|
|
// This stub is very performance sensitive, the generated code must be
|
|
|
|
// tuned so that it doesn't build and eager frame.
|
|
|
|
info()->MarkMustNotHaveEagerFrame();
|
2013-06-05 10:43:18 +00:00
|
|
|
result = array_builder.AllocateEmptyArray();
|
|
|
|
break;
|
|
|
|
case SINGLE:
|
|
|
|
result = BuildArraySingleArgumentConstructor(&array_builder);
|
|
|
|
break;
|
|
|
|
case MULTIPLE:
|
|
|
|
result = BuildArrayNArgumentsConstructor(&array_builder, kind);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return result;
|
2013-03-01 16:06:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-05 10:43:18 +00:00
|
|
|
HValue* CodeStubGraphBuilderBase::BuildArraySingleArgumentConstructor(
|
|
|
|
JSArrayBuilder* array_builder) {
|
2013-04-25 16:00:32 +00:00
|
|
|
// Smi check and range check on the input arg.
|
|
|
|
HValue* constant_one = graph()->GetConstant1();
|
|
|
|
HValue* constant_zero = graph()->GetConstant0();
|
|
|
|
|
2013-07-31 14:58:39 +00:00
|
|
|
HInstruction* elements = Add<HArgumentsElements>(false);
|
2013-10-22 11:29:05 +00:00
|
|
|
HInstruction* argument = Add<HAccessArgumentsAt>(
|
|
|
|
elements, constant_one, constant_zero);
|
2013-04-25 16:00:32 +00:00
|
|
|
|
2013-11-14 12:05:09 +00:00
|
|
|
return BuildAllocateArrayFromLength(array_builder, argument);
|
2013-03-01 16:06:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-05 10:43:18 +00:00
|
|
|
HValue* CodeStubGraphBuilderBase::BuildArrayNArgumentsConstructor(
|
|
|
|
JSArrayBuilder* array_builder, ElementsKind kind) {
|
2013-11-28 09:29:57 +00:00
|
|
|
// Insert a bounds check because the number of arguments might exceed
|
|
|
|
// the kInitialMaxFastElementArray limit. This cannot happen for code
|
|
|
|
// that was parsed, but calling via Array.apply(thisArg, [...]) might
|
|
|
|
// trigger it.
|
|
|
|
HValue* length = GetArgumentsLength();
|
|
|
|
HConstant* max_alloc_length =
|
|
|
|
Add<HConstant>(JSObject::kInitialMaxFastElementArray);
|
|
|
|
HValue* checked_length = Add<HBoundsCheck>(length, max_alloc_length);
|
|
|
|
|
2013-04-25 16:00:32 +00:00
|
|
|
// We need to fill with the hole if it's a smi array in the multi-argument
|
|
|
|
// case because we might have to bail out while copying arguments into
|
|
|
|
// the array because they aren't compatible with a smi array.
|
|
|
|
// If it's a double array, no problem, and if it's fast then no
|
|
|
|
// problem either because doubles are boxed.
|
2013-11-14 12:05:09 +00:00
|
|
|
//
|
|
|
|
// TODO(mvstanton): consider an instruction to memset fill the array
|
|
|
|
// with zero in this case instead.
|
|
|
|
JSArrayBuilder::FillMode fill_mode = IsFastSmiElementsKind(kind)
|
|
|
|
? JSArrayBuilder::FILL_WITH_HOLE
|
|
|
|
: JSArrayBuilder::DONT_FILL_WITH_HOLE;
|
2013-11-28 09:29:57 +00:00
|
|
|
HValue* new_object = array_builder->AllocateArray(checked_length,
|
2014-06-04 09:35:41 +00:00
|
|
|
max_alloc_length,
|
2013-11-28 09:29:57 +00:00
|
|
|
checked_length,
|
2013-11-14 12:05:09 +00:00
|
|
|
fill_mode);
|
2013-06-05 10:43:18 +00:00
|
|
|
HValue* elements = array_builder->GetElementsLocation();
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(elements != NULL);
|
2013-04-25 16:00:32 +00:00
|
|
|
|
|
|
|
// Now populate the elements correctly.
|
|
|
|
LoopBuilder builder(this,
|
|
|
|
context(),
|
|
|
|
LoopBuilder::kPostIncrement);
|
|
|
|
HValue* start = graph()->GetConstant0();
|
2013-11-28 09:29:57 +00:00
|
|
|
HValue* key = builder.BeginBody(start, checked_length, Token::LT);
|
2013-07-31 14:58:39 +00:00
|
|
|
HInstruction* argument_elements = Add<HArgumentsElements>(false);
|
2013-10-22 11:29:05 +00:00
|
|
|
HInstruction* argument = Add<HAccessArgumentsAt>(
|
2013-11-28 09:29:57 +00:00
|
|
|
argument_elements, checked_length, key);
|
2013-04-25 16:00:32 +00:00
|
|
|
|
2014-02-04 10:48:49 +00:00
|
|
|
Add<HStoreKeyed>(elements, key, argument, kind);
|
2013-04-25 16:00:32 +00:00
|
|
|
builder.EndBody();
|
|
|
|
return new_object;
|
2013-03-01 16:06:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-05 10:43:18 +00:00
|
|
|
template <>
|
|
|
|
HValue* CodeStubGraphBuilder<ArrayNoArgumentConstructorStub>::BuildCodeStub() {
|
|
|
|
ElementsKind kind = casted_stub()->elements_kind();
|
2013-06-28 13:16:14 +00:00
|
|
|
AllocationSiteOverrideMode override_mode = casted_stub()->override_mode();
|
2014-01-09 15:07:23 +00:00
|
|
|
return BuildArrayConstructor(kind, override_mode, NONE);
|
2013-06-05 10:43:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-24 12:07:40 +00:00
|
|
|
Handle<Code> ArrayNoArgumentConstructorStub::GenerateCode() {
|
|
|
|
return DoGenerateCode(this);
|
2013-06-05 10:43:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <>
|
|
|
|
HValue* CodeStubGraphBuilder<ArraySingleArgumentConstructorStub>::
|
|
|
|
BuildCodeStub() {
|
|
|
|
ElementsKind kind = casted_stub()->elements_kind();
|
2013-06-28 13:16:14 +00:00
|
|
|
AllocationSiteOverrideMode override_mode = casted_stub()->override_mode();
|
2014-01-09 15:07:23 +00:00
|
|
|
return BuildArrayConstructor(kind, override_mode, SINGLE);
|
2013-06-05 10:43:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-24 12:07:40 +00:00
|
|
|
Handle<Code> ArraySingleArgumentConstructorStub::GenerateCode() {
|
|
|
|
return DoGenerateCode(this);
|
2013-06-05 10:43:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <>
|
|
|
|
HValue* CodeStubGraphBuilder<ArrayNArgumentsConstructorStub>::BuildCodeStub() {
|
|
|
|
ElementsKind kind = casted_stub()->elements_kind();
|
2013-06-28 13:16:14 +00:00
|
|
|
AllocationSiteOverrideMode override_mode = casted_stub()->override_mode();
|
2014-01-09 15:07:23 +00:00
|
|
|
return BuildArrayConstructor(kind, override_mode, MULTIPLE);
|
2013-06-05 10:43:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-24 12:07:40 +00:00
|
|
|
Handle<Code> ArrayNArgumentsConstructorStub::GenerateCode() {
|
|
|
|
return DoGenerateCode(this);
|
2013-03-01 16:06:34 +00:00
|
|
|
}
|
|
|
|
|
2013-04-24 11:32:17 +00:00
|
|
|
|
2013-06-05 10:43:18 +00:00
|
|
|
template <>
|
|
|
|
HValue* CodeStubGraphBuilder<InternalArrayNoArgumentConstructorStub>::
|
|
|
|
BuildCodeStub() {
|
|
|
|
ElementsKind kind = casted_stub()->elements_kind();
|
|
|
|
return BuildInternalArrayConstructor(kind, NONE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-24 12:07:40 +00:00
|
|
|
Handle<Code> InternalArrayNoArgumentConstructorStub::GenerateCode() {
|
|
|
|
return DoGenerateCode(this);
|
2013-06-05 10:43:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <>
|
|
|
|
HValue* CodeStubGraphBuilder<InternalArraySingleArgumentConstructorStub>::
|
|
|
|
BuildCodeStub() {
|
|
|
|
ElementsKind kind = casted_stub()->elements_kind();
|
|
|
|
return BuildInternalArrayConstructor(kind, SINGLE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-24 12:07:40 +00:00
|
|
|
Handle<Code> InternalArraySingleArgumentConstructorStub::GenerateCode() {
|
|
|
|
return DoGenerateCode(this);
|
2013-06-05 10:43:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <>
|
|
|
|
HValue* CodeStubGraphBuilder<InternalArrayNArgumentsConstructorStub>::
|
|
|
|
BuildCodeStub() {
|
|
|
|
ElementsKind kind = casted_stub()->elements_kind();
|
|
|
|
return BuildInternalArrayConstructor(kind, MULTIPLE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-24 12:07:40 +00:00
|
|
|
Handle<Code> InternalArrayNArgumentsConstructorStub::GenerateCode() {
|
|
|
|
return DoGenerateCode(this);
|
2013-06-05 10:43:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-24 11:32:17 +00:00
|
|
|
template <>
|
2013-05-24 11:44:55 +00:00
|
|
|
HValue* CodeStubGraphBuilder<CompareNilICStub>::BuildCodeInitializedStub() {
|
2013-06-12 17:20:37 +00:00
|
|
|
Isolate* isolate = graph()->isolate();
|
2013-04-24 11:32:17 +00:00
|
|
|
CompareNilICStub* stub = casted_stub();
|
|
|
|
HIfContinuation continuation;
|
2013-06-12 17:20:37 +00:00
|
|
|
Handle<Map> sentinel_map(isolate->heap()->meta_map());
|
2014-01-21 16:22:52 +00:00
|
|
|
Type* type = stub->GetType(zone(), sentinel_map);
|
2013-10-21 13:35:48 +00:00
|
|
|
BuildCompareNil(GetParameter(0), type, &continuation);
|
2013-04-24 11:32:17 +00:00
|
|
|
IfBuilder if_nil(this, &continuation);
|
|
|
|
if_nil.Then();
|
|
|
|
if (continuation.IsFalseReachable()) {
|
|
|
|
if_nil.Else();
|
2013-05-27 08:43:58 +00:00
|
|
|
if_nil.Return(graph()->GetConstant0());
|
2013-04-24 11:32:17 +00:00
|
|
|
}
|
|
|
|
if_nil.End();
|
|
|
|
return continuation.IsTrueReachable()
|
2013-05-27 08:43:58 +00:00
|
|
|
? graph()->GetConstant1()
|
2013-04-24 11:32:17 +00:00
|
|
|
: graph()->GetConstantUndefined();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-24 12:07:40 +00:00
|
|
|
Handle<Code> CompareNilICStub::GenerateCode() {
|
|
|
|
return DoGenerateCode(this);
|
2013-04-24 11:32:17 +00:00
|
|
|
}
|
|
|
|
|
2013-05-29 14:49:28 +00:00
|
|
|
|
2013-10-04 08:17:11 +00:00
|
|
|
template <>
|
2013-12-02 13:14:07 +00:00
|
|
|
HValue* CodeStubGraphBuilder<BinaryOpICStub>::BuildCodeInitializedStub() {
|
2014-09-16 12:51:33 +00:00
|
|
|
BinaryOpICState state = casted_stub()->state();
|
2013-10-04 08:17:11 +00:00
|
|
|
|
2013-12-02 13:14:07 +00:00
|
|
|
HValue* left = GetParameter(BinaryOpICStub::kLeft);
|
|
|
|
HValue* right = GetParameter(BinaryOpICStub::kRight);
|
|
|
|
|
2014-01-21 16:22:52 +00:00
|
|
|
Type* left_type = state.GetLeftType(zone());
|
|
|
|
Type* right_type = state.GetRightType(zone());
|
|
|
|
Type* result_type = state.GetResultType(zone());
|
2013-10-04 08:17:11 +00:00
|
|
|
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(!left_type->Is(Type::None()) && !right_type->Is(Type::None()) &&
|
2013-12-02 13:14:07 +00:00
|
|
|
(state.HasSideEffects() || !result_type->Is(Type::None())));
|
2013-10-04 08:17:11 +00:00
|
|
|
|
|
|
|
HValue* result = NULL;
|
2014-01-02 15:31:27 +00:00
|
|
|
HAllocationMode allocation_mode(NOT_TENURED);
|
2013-12-02 13:14:07 +00:00
|
|
|
if (state.op() == Token::ADD &&
|
2013-10-04 08:17:11 +00:00
|
|
|
(left_type->Maybe(Type::String()) || right_type->Maybe(Type::String())) &&
|
|
|
|
!left_type->Is(Type::String()) && !right_type->Is(Type::String())) {
|
2013-10-21 12:42:08 +00:00
|
|
|
// For the generic add stub a fast case for string addition is performance
|
2013-10-04 08:17:11 +00:00
|
|
|
// critical.
|
|
|
|
if (left_type->Maybe(Type::String())) {
|
2013-10-21 12:42:08 +00:00
|
|
|
IfBuilder if_leftisstring(this);
|
|
|
|
if_leftisstring.If<HIsStringAndBranch>(left);
|
|
|
|
if_leftisstring.Then();
|
|
|
|
{
|
2013-11-20 12:00:57 +00:00
|
|
|
Push(BuildBinaryOperation(
|
2013-12-02 13:14:07 +00:00
|
|
|
state.op(), left, right,
|
2014-01-21 16:22:52 +00:00
|
|
|
Type::String(zone()), right_type,
|
2014-01-02 15:31:27 +00:00
|
|
|
result_type, state.fixed_right_arg(),
|
|
|
|
allocation_mode));
|
2013-10-21 12:42:08 +00:00
|
|
|
}
|
|
|
|
if_leftisstring.Else();
|
|
|
|
{
|
2013-11-20 12:00:57 +00:00
|
|
|
Push(BuildBinaryOperation(
|
2013-12-02 13:14:07 +00:00
|
|
|
state.op(), left, right,
|
2013-12-04 09:27:48 +00:00
|
|
|
left_type, right_type, result_type,
|
2014-01-02 15:31:27 +00:00
|
|
|
state.fixed_right_arg(), allocation_mode));
|
2013-10-21 12:42:08 +00:00
|
|
|
}
|
|
|
|
if_leftisstring.End();
|
2013-10-04 08:17:11 +00:00
|
|
|
result = Pop();
|
|
|
|
} else {
|
2013-10-21 12:42:08 +00:00
|
|
|
IfBuilder if_rightisstring(this);
|
|
|
|
if_rightisstring.If<HIsStringAndBranch>(right);
|
|
|
|
if_rightisstring.Then();
|
|
|
|
{
|
2013-11-20 12:00:57 +00:00
|
|
|
Push(BuildBinaryOperation(
|
2013-12-02 13:14:07 +00:00
|
|
|
state.op(), left, right,
|
2014-01-21 16:22:52 +00:00
|
|
|
left_type, Type::String(zone()),
|
2014-01-02 15:31:27 +00:00
|
|
|
result_type, state.fixed_right_arg(),
|
|
|
|
allocation_mode));
|
2013-10-21 12:42:08 +00:00
|
|
|
}
|
|
|
|
if_rightisstring.Else();
|
|
|
|
{
|
2013-11-20 12:00:57 +00:00
|
|
|
Push(BuildBinaryOperation(
|
2013-12-02 13:14:07 +00:00
|
|
|
state.op(), left, right,
|
2013-12-04 09:27:48 +00:00
|
|
|
left_type, right_type, result_type,
|
2014-01-02 15:31:27 +00:00
|
|
|
state.fixed_right_arg(), allocation_mode));
|
2013-10-21 12:42:08 +00:00
|
|
|
}
|
|
|
|
if_rightisstring.End();
|
2013-10-04 08:17:11 +00:00
|
|
|
result = Pop();
|
|
|
|
}
|
|
|
|
} else {
|
2013-11-20 12:00:57 +00:00
|
|
|
result = BuildBinaryOperation(
|
2013-12-02 13:14:07 +00:00
|
|
|
state.op(), left, right,
|
2013-12-04 09:27:48 +00:00
|
|
|
left_type, right_type, result_type,
|
2014-01-02 15:31:27 +00:00
|
|
|
state.fixed_right_arg(), allocation_mode);
|
2013-10-04 08:17:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// If we encounter a generic argument, the number conversion is
|
|
|
|
// observable, thus we cannot afford to bail out after the fact.
|
2013-12-02 13:14:07 +00:00
|
|
|
if (!state.HasSideEffects()) {
|
2013-10-04 08:17:11 +00:00
|
|
|
result = EnforceNumberType(result, result_type);
|
|
|
|
}
|
|
|
|
|
2013-10-14 09:22:34 +00:00
|
|
|
// Reuse the double box of one of the operands if we are allowed to (i.e.
|
|
|
|
// chained binops).
|
2013-12-02 13:14:07 +00:00
|
|
|
if (state.CanReuseDoubleBox()) {
|
|
|
|
HValue* operand = (state.mode() == OVERWRITE_LEFT) ? left : right;
|
2013-10-04 08:17:11 +00:00
|
|
|
IfBuilder if_heap_number(this);
|
2014-04-04 08:46:49 +00:00
|
|
|
if_heap_number.If<HHasInstanceTypeAndBranch>(operand, HEAP_NUMBER_TYPE);
|
2013-10-04 08:17:11 +00:00
|
|
|
if_heap_number.Then();
|
2014-02-04 10:48:49 +00:00
|
|
|
Add<HStoreNamedField>(operand, HObjectAccess::ForHeapNumberValue(), result);
|
2013-10-14 09:22:34 +00:00
|
|
|
Push(operand);
|
2013-10-04 08:17:11 +00:00
|
|
|
if_heap_number.Else();
|
|
|
|
Push(result);
|
|
|
|
if_heap_number.End();
|
|
|
|
result = Pop();
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-24 12:07:40 +00:00
|
|
|
Handle<Code> BinaryOpICStub::GenerateCode() {
|
|
|
|
return DoGenerateCode(this);
|
2013-10-04 08:17:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-01-02 15:31:27 +00:00
|
|
|
template <>
|
|
|
|
HValue* CodeStubGraphBuilder<BinaryOpWithAllocationSiteStub>::BuildCodeStub() {
|
2014-09-16 12:51:33 +00:00
|
|
|
BinaryOpICState state = casted_stub()->state();
|
2014-01-02 15:31:27 +00:00
|
|
|
|
|
|
|
HValue* allocation_site = GetParameter(
|
|
|
|
BinaryOpWithAllocationSiteStub::kAllocationSite);
|
|
|
|
HValue* left = GetParameter(BinaryOpWithAllocationSiteStub::kLeft);
|
|
|
|
HValue* right = GetParameter(BinaryOpWithAllocationSiteStub::kRight);
|
|
|
|
|
2014-01-21 16:22:52 +00:00
|
|
|
Type* left_type = state.GetLeftType(zone());
|
|
|
|
Type* right_type = state.GetRightType(zone());
|
|
|
|
Type* result_type = state.GetResultType(zone());
|
2014-01-02 15:31:27 +00:00
|
|
|
HAllocationMode allocation_mode(allocation_site);
|
|
|
|
|
|
|
|
return BuildBinaryOperation(state.op(), left, right,
|
|
|
|
left_type, right_type, result_type,
|
|
|
|
state.fixed_right_arg(), allocation_mode);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-24 12:07:40 +00:00
|
|
|
Handle<Code> BinaryOpWithAllocationSiteStub::GenerateCode() {
|
|
|
|
return DoGenerateCode(this);
|
2014-01-02 15:31:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-12 10:21:08 +00:00
|
|
|
template <>
|
2014-01-22 13:48:05 +00:00
|
|
|
HValue* CodeStubGraphBuilder<StringAddStub>::BuildCodeInitializedStub() {
|
|
|
|
StringAddStub* stub = casted_stub();
|
2013-11-12 10:21:08 +00:00
|
|
|
StringAddFlags flags = stub->flags();
|
|
|
|
PretenureFlag pretenure_flag = stub->pretenure_flag();
|
|
|
|
|
2014-01-22 13:48:05 +00:00
|
|
|
HValue* left = GetParameter(StringAddStub::kLeft);
|
|
|
|
HValue* right = GetParameter(StringAddStub::kRight);
|
2013-11-12 10:21:08 +00:00
|
|
|
|
|
|
|
// Make sure that both arguments are strings if not known in advance.
|
|
|
|
if ((flags & STRING_ADD_CHECK_LEFT) == STRING_ADD_CHECK_LEFT) {
|
2013-11-22 07:27:26 +00:00
|
|
|
left = BuildCheckString(left);
|
2013-11-12 10:21:08 +00:00
|
|
|
}
|
|
|
|
if ((flags & STRING_ADD_CHECK_RIGHT) == STRING_ADD_CHECK_RIGHT) {
|
2013-11-22 07:27:26 +00:00
|
|
|
right = BuildCheckString(right);
|
2013-11-12 10:21:08 +00:00
|
|
|
}
|
|
|
|
|
2014-01-02 15:31:27 +00:00
|
|
|
return BuildStringAdd(left, right, HAllocationMode(pretenure_flag));
|
2013-11-12 10:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-24 12:07:40 +00:00
|
|
|
Handle<Code> StringAddStub::GenerateCode() {
|
|
|
|
return DoGenerateCode(this);
|
2013-11-12 10:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-05-29 14:49:28 +00:00
|
|
|
template <>
|
|
|
|
HValue* CodeStubGraphBuilder<ToBooleanStub>::BuildCodeInitializedStub() {
|
|
|
|
ToBooleanStub* stub = casted_stub();
|
2014-08-08 12:41:57 +00:00
|
|
|
HValue* true_value = NULL;
|
|
|
|
HValue* false_value = NULL;
|
|
|
|
|
2014-08-28 07:02:53 +00:00
|
|
|
switch (stub->mode()) {
|
2014-08-08 12:41:57 +00:00
|
|
|
case ToBooleanStub::RESULT_AS_SMI:
|
|
|
|
true_value = graph()->GetConstant1();
|
|
|
|
false_value = graph()->GetConstant0();
|
|
|
|
break;
|
|
|
|
case ToBooleanStub::RESULT_AS_ODDBALL:
|
|
|
|
true_value = graph()->GetConstantTrue();
|
|
|
|
false_value = graph()->GetConstantFalse();
|
|
|
|
break;
|
|
|
|
case ToBooleanStub::RESULT_AS_INVERSE_ODDBALL:
|
|
|
|
true_value = graph()->GetConstantFalse();
|
|
|
|
false_value = graph()->GetConstantTrue();
|
|
|
|
break;
|
|
|
|
}
|
2013-05-29 14:49:28 +00:00
|
|
|
|
|
|
|
IfBuilder if_true(this);
|
2014-08-28 07:02:53 +00:00
|
|
|
if_true.If<HBranch>(GetParameter(0), stub->types());
|
2013-05-29 14:49:28 +00:00
|
|
|
if_true.Then();
|
2014-08-08 12:41:57 +00:00
|
|
|
if_true.Return(true_value);
|
2013-05-29 14:49:28 +00:00
|
|
|
if_true.Else();
|
|
|
|
if_true.End();
|
2014-08-08 12:41:57 +00:00
|
|
|
return false_value;
|
2013-05-29 14:49:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-24 12:07:40 +00:00
|
|
|
Handle<Code> ToBooleanStub::GenerateCode() {
|
|
|
|
return DoGenerateCode(this);
|
2013-05-29 14:49:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-07-05 10:34:02 +00:00
|
|
|
template <>
|
|
|
|
HValue* CodeStubGraphBuilder<StoreGlobalStub>::BuildCodeInitializedStub() {
|
|
|
|
StoreGlobalStub* stub = casted_stub();
|
|
|
|
Handle<Object> placeholer_value(Smi::FromInt(0), isolate());
|
|
|
|
Handle<PropertyCell> placeholder_cell =
|
|
|
|
isolate()->factory()->NewPropertyCell(placeholer_value);
|
|
|
|
|
2014-09-03 10:51:51 +00:00
|
|
|
HParameter* value = GetParameter(StoreDescriptor::kValueIndex);
|
2013-07-05 10:34:02 +00:00
|
|
|
|
2014-03-10 12:23:05 +00:00
|
|
|
if (stub->check_global()) {
|
|
|
|
// Check that the map of the global has not changed: use a placeholder map
|
|
|
|
// that will be replaced later with the global object's map.
|
|
|
|
Handle<Map> placeholder_map = isolate()->factory()->meta_map();
|
|
|
|
HValue* global = Add<HConstant>(
|
|
|
|
StoreGlobalStub::global_placeholder(isolate()));
|
2014-05-05 11:03:14 +00:00
|
|
|
Add<HCheckMaps>(global, placeholder_map);
|
2014-03-10 12:23:05 +00:00
|
|
|
}
|
2013-07-05 10:40:14 +00:00
|
|
|
|
2013-07-31 14:58:39 +00:00
|
|
|
HValue* cell = Add<HConstant>(placeholder_cell);
|
2013-07-22 14:15:58 +00:00
|
|
|
HObjectAccess access(HObjectAccess::ForCellPayload(isolate()));
|
2014-12-15 04:33:05 +00:00
|
|
|
HValue* cell_contents = Add<HLoadNamedField>(cell, nullptr, access);
|
2013-07-05 10:34:02 +00:00
|
|
|
|
2013-07-22 14:15:58 +00:00
|
|
|
if (stub->is_constant()) {
|
|
|
|
IfBuilder builder(this);
|
|
|
|
builder.If<HCompareObjectEqAndBranch>(cell_contents, value);
|
|
|
|
builder.Then();
|
2013-08-09 12:50:42 +00:00
|
|
|
builder.ElseDeopt("Unexpected cell contents in constant global store");
|
2013-07-22 14:15:58 +00:00
|
|
|
builder.End();
|
|
|
|
} else {
|
2013-07-05 10:34:02 +00:00
|
|
|
// Load the payload of the global parameter cell. A hole indicates that the
|
|
|
|
// property has been deleted and that the store must be handled by the
|
|
|
|
// runtime.
|
|
|
|
IfBuilder builder(this);
|
2014-09-22 13:23:27 +00:00
|
|
|
HValue* hole_value = graph()->GetConstantHole();
|
2013-07-05 10:34:02 +00:00
|
|
|
builder.If<HCompareObjectEqAndBranch>(cell_contents, hole_value);
|
|
|
|
builder.Then();
|
2013-08-09 12:50:42 +00:00
|
|
|
builder.Deopt("Unexpected cell contents in global store");
|
2013-07-05 10:34:02 +00:00
|
|
|
builder.Else();
|
2014-02-04 10:48:49 +00:00
|
|
|
Add<HStoreNamedField>(cell, access, value);
|
2013-07-05 10:34:02 +00:00
|
|
|
builder.End();
|
|
|
|
}
|
2013-07-22 14:15:58 +00:00
|
|
|
|
2013-07-05 10:34:02 +00:00
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-24 12:07:40 +00:00
|
|
|
Handle<Code> StoreGlobalStub::GenerateCode() {
|
|
|
|
return DoGenerateCode(this);
|
2013-07-05 10:34:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-07-17 11:37:20 +00:00
|
|
|
template<>
|
|
|
|
HValue* CodeStubGraphBuilder<ElementsTransitionAndStoreStub>::BuildCodeStub() {
|
2014-07-14 20:43:41 +00:00
|
|
|
HValue* value = GetParameter(ElementsTransitionAndStoreStub::kValueIndex);
|
|
|
|
HValue* map = GetParameter(ElementsTransitionAndStoreStub::kMapIndex);
|
|
|
|
HValue* key = GetParameter(ElementsTransitionAndStoreStub::kKeyIndex);
|
|
|
|
HValue* object = GetParameter(ElementsTransitionAndStoreStub::kObjectIndex);
|
2013-07-17 11:37:20 +00:00
|
|
|
|
|
|
|
if (FLAG_trace_elements_transitions) {
|
|
|
|
// Tracing elements transitions is the job of the runtime.
|
2013-09-04 07:27:10 +00:00
|
|
|
Add<HDeoptimize>("Tracing elements transitions", Deoptimizer::EAGER);
|
2013-07-17 11:37:20 +00:00
|
|
|
} else {
|
|
|
|
info()->MarkAsSavesCallerDoubles();
|
|
|
|
|
|
|
|
BuildTransitionElementsKind(object, map,
|
|
|
|
casted_stub()->from_kind(),
|
|
|
|
casted_stub()->to_kind(),
|
|
|
|
casted_stub()->is_jsarray());
|
|
|
|
|
2013-08-26 12:28:08 +00:00
|
|
|
BuildUncheckedMonomorphicElementAccess(object, key, value,
|
|
|
|
casted_stub()->is_jsarray(),
|
|
|
|
casted_stub()->to_kind(),
|
2014-02-10 11:43:34 +00:00
|
|
|
STORE, ALLOW_RETURN_HOLE,
|
2013-08-26 12:28:08 +00:00
|
|
|
casted_stub()->store_mode());
|
2013-07-17 11:37:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-24 12:07:40 +00:00
|
|
|
Handle<Code> ElementsTransitionAndStoreStub::GenerateCode() {
|
|
|
|
return DoGenerateCode(this);
|
2013-07-17 11:37:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-03-12 13:29:42 +00:00
|
|
|
void CodeStubGraphBuilderBase::BuildCheckAndInstallOptimizedCode(
|
2013-08-27 11:55:08 +00:00
|
|
|
HValue* js_function,
|
|
|
|
HValue* native_context,
|
2014-03-12 13:29:42 +00:00
|
|
|
IfBuilder* builder,
|
|
|
|
HValue* optimized_map,
|
|
|
|
HValue* map_index) {
|
|
|
|
HValue* osr_ast_id_none = Add<HConstant>(BailoutId::None().ToInt());
|
|
|
|
HValue* context_slot = LoadFromOptimizedCodeMap(
|
|
|
|
optimized_map, map_index, SharedFunctionInfo::kContextOffset);
|
|
|
|
HValue* osr_ast_slot = LoadFromOptimizedCodeMap(
|
|
|
|
optimized_map, map_index, SharedFunctionInfo::kOsrAstIdOffset);
|
|
|
|
builder->If<HCompareObjectEqAndBranch>(native_context,
|
|
|
|
context_slot);
|
|
|
|
builder->AndIf<HCompareObjectEqAndBranch>(osr_ast_slot, osr_ast_id_none);
|
|
|
|
builder->Then();
|
|
|
|
HValue* code_object = LoadFromOptimizedCodeMap(optimized_map,
|
|
|
|
map_index, SharedFunctionInfo::kCachedCodeOffset);
|
|
|
|
// and the literals
|
|
|
|
HValue* literals = LoadFromOptimizedCodeMap(optimized_map,
|
|
|
|
map_index, SharedFunctionInfo::kLiteralsOffset);
|
|
|
|
|
2013-08-27 11:55:08 +00:00
|
|
|
Counters* counters = isolate()->counters();
|
2013-09-16 11:30:10 +00:00
|
|
|
AddIncrementCounter(counters->fast_new_closure_install_optimized());
|
2013-08-27 11:55:08 +00:00
|
|
|
|
|
|
|
// TODO(fschneider): Idea: store proper code pointers in the optimized code
|
|
|
|
// map and either unmangle them on marking or do nothing as the whole map is
|
|
|
|
// discarded on major GC anyway.
|
|
|
|
Add<HStoreCodeEntry>(js_function, code_object);
|
2014-03-12 13:29:42 +00:00
|
|
|
Add<HStoreNamedField>(js_function, HObjectAccess::ForLiteralsPointer(),
|
|
|
|
literals);
|
2013-08-27 11:55:08 +00:00
|
|
|
|
|
|
|
// Now link a function into a list of optimized functions.
|
2014-01-29 09:48:35 +00:00
|
|
|
HValue* optimized_functions_list = Add<HLoadNamedField>(
|
2014-12-15 04:33:05 +00:00
|
|
|
native_context, nullptr,
|
2013-08-27 11:55:08 +00:00
|
|
|
HObjectAccess::ForContextSlot(Context::OPTIMIZED_FUNCTIONS_LIST));
|
|
|
|
Add<HStoreNamedField>(js_function,
|
|
|
|
HObjectAccess::ForNextFunctionLinkPointer(),
|
2014-02-04 10:48:49 +00:00
|
|
|
optimized_functions_list);
|
2013-08-27 11:55:08 +00:00
|
|
|
|
|
|
|
// This store is the only one that should have a write barrier.
|
|
|
|
Add<HStoreNamedField>(native_context,
|
|
|
|
HObjectAccess::ForContextSlot(Context::OPTIMIZED_FUNCTIONS_LIST),
|
2014-02-04 10:48:49 +00:00
|
|
|
js_function);
|
2014-03-12 13:29:42 +00:00
|
|
|
|
|
|
|
// The builder continues in the "then" after this function.
|
2013-08-27 11:55:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CodeStubGraphBuilderBase::BuildInstallCode(HValue* js_function,
|
|
|
|
HValue* shared_info) {
|
|
|
|
Add<HStoreNamedField>(js_function,
|
|
|
|
HObjectAccess::ForNextFunctionLinkPointer(),
|
2014-02-04 10:48:49 +00:00
|
|
|
graph()->GetConstantUndefined());
|
2014-12-15 04:33:05 +00:00
|
|
|
HValue* code_object = Add<HLoadNamedField>(shared_info, nullptr,
|
|
|
|
HObjectAccess::ForCodeOffset());
|
2013-08-27 11:55:08 +00:00
|
|
|
Add<HStoreCodeEntry>(js_function, code_object);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-03-12 13:29:42 +00:00
|
|
|
HInstruction* CodeStubGraphBuilderBase::LoadFromOptimizedCodeMap(
|
|
|
|
HValue* optimized_map,
|
|
|
|
HValue* iterator,
|
|
|
|
int field_offset) {
|
|
|
|
// By making sure to express these loads in the form [<hvalue> + constant]
|
|
|
|
// the keyed load can be hoisted.
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(field_offset >= 0 && field_offset < SharedFunctionInfo::kEntryLength);
|
2014-03-12 13:29:42 +00:00
|
|
|
HValue* field_slot = iterator;
|
|
|
|
if (field_offset > 0) {
|
|
|
|
HValue* field_offset_value = Add<HConstant>(field_offset);
|
|
|
|
field_slot = AddUncasted<HAdd>(iterator, field_offset_value);
|
|
|
|
}
|
2014-12-15 04:33:05 +00:00
|
|
|
HInstruction* field_entry =
|
|
|
|
Add<HLoadKeyed>(optimized_map, field_slot, nullptr, FAST_ELEMENTS);
|
2014-03-12 13:29:42 +00:00
|
|
|
return field_entry;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-08-27 11:55:08 +00:00
|
|
|
void CodeStubGraphBuilderBase::BuildInstallFromOptimizedCodeMap(
|
|
|
|
HValue* js_function,
|
|
|
|
HValue* shared_info,
|
|
|
|
HValue* native_context) {
|
|
|
|
Counters* counters = isolate()->counters();
|
|
|
|
IfBuilder is_optimized(this);
|
2014-01-29 09:48:35 +00:00
|
|
|
HInstruction* optimized_map = Add<HLoadNamedField>(
|
2014-12-15 04:33:05 +00:00
|
|
|
shared_info, nullptr, HObjectAccess::ForOptimizedCodeMap());
|
2013-08-27 11:55:08 +00:00
|
|
|
HValue* null_constant = Add<HConstant>(0);
|
|
|
|
is_optimized.If<HCompareObjectEqAndBranch>(optimized_map, null_constant);
|
|
|
|
is_optimized.Then();
|
|
|
|
{
|
|
|
|
BuildInstallCode(js_function, shared_info);
|
|
|
|
}
|
|
|
|
is_optimized.Else();
|
|
|
|
{
|
2013-09-16 11:30:10 +00:00
|
|
|
AddIncrementCounter(counters->fast_new_closure_try_optimized());
|
2013-08-27 11:55:08 +00:00
|
|
|
// optimized_map points to fixed array of 3-element entries
|
|
|
|
// (native context, optimized code, literals).
|
|
|
|
// Map must never be empty, so check the first elements.
|
2014-03-12 13:29:42 +00:00
|
|
|
HValue* first_entry_index =
|
|
|
|
Add<HConstant>(SharedFunctionInfo::kEntriesStart);
|
2013-08-27 11:55:08 +00:00
|
|
|
IfBuilder already_in(this);
|
2014-03-12 13:29:42 +00:00
|
|
|
BuildCheckAndInstallOptimizedCode(js_function, native_context, &already_in,
|
|
|
|
optimized_map, first_entry_index);
|
2013-08-27 11:55:08 +00:00
|
|
|
already_in.Else();
|
|
|
|
{
|
2014-03-12 13:29:42 +00:00
|
|
|
// Iterate through the rest of map backwards. Do not double check first
|
|
|
|
// entry. After the loop, if no matching optimized code was found,
|
|
|
|
// install unoptimized code.
|
|
|
|
// for(i = map.length() - SharedFunctionInfo::kEntryLength;
|
|
|
|
// i > SharedFunctionInfo::kEntriesStart;
|
|
|
|
// i -= SharedFunctionInfo::kEntryLength) { .. }
|
2013-08-27 11:55:08 +00:00
|
|
|
HValue* shared_function_entry_length =
|
|
|
|
Add<HConstant>(SharedFunctionInfo::kEntryLength);
|
|
|
|
LoopBuilder loop_builder(this,
|
|
|
|
context(),
|
|
|
|
LoopBuilder::kPostDecrement,
|
|
|
|
shared_function_entry_length);
|
2014-01-29 09:48:35 +00:00
|
|
|
HValue* array_length = Add<HLoadNamedField>(
|
2014-12-15 04:33:05 +00:00
|
|
|
optimized_map, nullptr, HObjectAccess::ForFixedArrayLength());
|
2014-03-12 13:29:42 +00:00
|
|
|
HValue* start_pos = AddUncasted<HSub>(array_length,
|
|
|
|
shared_function_entry_length);
|
|
|
|
HValue* slot_iterator = loop_builder.BeginBody(start_pos,
|
|
|
|
first_entry_index,
|
|
|
|
Token::GT);
|
2013-08-27 11:55:08 +00:00
|
|
|
{
|
2014-03-12 13:29:42 +00:00
|
|
|
IfBuilder done_check(this);
|
|
|
|
BuildCheckAndInstallOptimizedCode(js_function, native_context,
|
|
|
|
&done_check,
|
|
|
|
optimized_map,
|
|
|
|
slot_iterator);
|
|
|
|
// Fall out of the loop
|
|
|
|
loop_builder.Break();
|
2013-08-27 11:55:08 +00:00
|
|
|
}
|
|
|
|
loop_builder.EndBody();
|
2014-03-12 13:29:42 +00:00
|
|
|
|
|
|
|
// If slot_iterator equals first entry index, then we failed to find and
|
|
|
|
// install optimized code
|
|
|
|
IfBuilder no_optimized_code_check(this);
|
|
|
|
no_optimized_code_check.If<HCompareNumericAndBranch>(
|
|
|
|
slot_iterator, first_entry_index, Token::EQ);
|
|
|
|
no_optimized_code_check.Then();
|
|
|
|
{
|
|
|
|
// Store the unoptimized code
|
|
|
|
BuildInstallCode(js_function, shared_info);
|
|
|
|
}
|
2013-08-27 11:55:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template<>
|
|
|
|
HValue* CodeStubGraphBuilder<FastNewClosureStub>::BuildCodeStub() {
|
|
|
|
Counters* counters = isolate()->counters();
|
|
|
|
Factory* factory = isolate()->factory();
|
|
|
|
HInstruction* empty_fixed_array =
|
|
|
|
Add<HConstant>(factory->empty_fixed_array());
|
|
|
|
HValue* shared_info = GetParameter(0);
|
|
|
|
|
2013-09-20 09:27:40 +00:00
|
|
|
AddIncrementCounter(counters->fast_new_closure_total());
|
|
|
|
|
2014-11-25 13:21:57 +00:00
|
|
|
// Create a new closure from the given function info in new space
|
|
|
|
HValue* size = Add<HConstant>(JSFunction::kSize);
|
|
|
|
HInstruction* js_function =
|
|
|
|
Add<HAllocate>(size, HType::JSObject(), NOT_TENURED, JS_FUNCTION_TYPE);
|
|
|
|
|
|
|
|
int map_index = Context::FunctionMapIndex(casted_stub()->strict_mode(),
|
|
|
|
casted_stub()->kind());
|
|
|
|
|
|
|
|
// Compute the function map in the current native context and set that
|
|
|
|
// as the map of the allocated object.
|
|
|
|
HInstruction* native_context = BuildGetNativeContext();
|
2014-12-15 04:33:05 +00:00
|
|
|
HInstruction* map_slot_value = Add<HLoadNamedField>(
|
|
|
|
native_context, nullptr, HObjectAccess::ForContextSlot(map_index));
|
2014-11-25 13:21:57 +00:00
|
|
|
Add<HStoreNamedField>(js_function, HObjectAccess::ForMap(), map_slot_value);
|
|
|
|
|
|
|
|
// Initialize the rest of the function.
|
|
|
|
Add<HStoreNamedField>(js_function, HObjectAccess::ForPropertiesPointer(),
|
|
|
|
empty_fixed_array);
|
|
|
|
Add<HStoreNamedField>(js_function, HObjectAccess::ForElementsPointer(),
|
|
|
|
empty_fixed_array);
|
|
|
|
Add<HStoreNamedField>(js_function, HObjectAccess::ForLiteralsPointer(),
|
|
|
|
empty_fixed_array);
|
|
|
|
Add<HStoreNamedField>(js_function, HObjectAccess::ForPrototypeOrInitialMap(),
|
|
|
|
graph()->GetConstantHole());
|
|
|
|
Add<HStoreNamedField>(
|
|
|
|
js_function, HObjectAccess::ForSharedFunctionInfoPointer(), shared_info);
|
|
|
|
Add<HStoreNamedField>(js_function, HObjectAccess::ForFunctionContextPointer(),
|
|
|
|
context());
|
|
|
|
|
|
|
|
// Initialize the code pointer in the function to be the one
|
|
|
|
// found in the shared function info object.
|
|
|
|
// But first check if there is an optimized version for our context.
|
|
|
|
if (FLAG_cache_optimized_code) {
|
|
|
|
BuildInstallFromOptimizedCodeMap(js_function, shared_info, native_context);
|
|
|
|
} else {
|
|
|
|
BuildInstallCode(js_function, shared_info);
|
2014-11-17 08:42:45 +00:00
|
|
|
}
|
2014-11-25 13:21:57 +00:00
|
|
|
|
|
|
|
return js_function;
|
2013-08-27 11:55:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-24 12:07:40 +00:00
|
|
|
Handle<Code> FastNewClosureStub::GenerateCode() {
|
|
|
|
return DoGenerateCode(this);
|
2013-08-27 11:55:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-01-23 08:36:22 +00:00
|
|
|
template<>
|
|
|
|
HValue* CodeStubGraphBuilder<FastNewContextStub>::BuildCodeStub() {
|
|
|
|
int length = casted_stub()->slots() + Context::MIN_CONTEXT_SLOTS;
|
|
|
|
|
|
|
|
// Get the function.
|
|
|
|
HParameter* function = GetParameter(FastNewContextStub::kFunction);
|
|
|
|
|
|
|
|
// Allocate the context in new space.
|
|
|
|
HAllocate* function_context = Add<HAllocate>(
|
|
|
|
Add<HConstant>(length * kPointerSize + FixedArray::kHeaderSize),
|
2014-05-29 04:13:50 +00:00
|
|
|
HType::HeapObject(), NOT_TENURED, FIXED_ARRAY_TYPE);
|
2014-01-23 08:36:22 +00:00
|
|
|
|
|
|
|
// Set up the object header.
|
|
|
|
AddStoreMapConstant(function_context,
|
|
|
|
isolate()->factory()->function_context_map());
|
|
|
|
Add<HStoreNamedField>(function_context,
|
|
|
|
HObjectAccess::ForFixedArrayLength(),
|
2014-02-04 10:48:49 +00:00
|
|
|
Add<HConstant>(length));
|
2014-01-23 08:36:22 +00:00
|
|
|
|
|
|
|
// Set up the fixed slots.
|
|
|
|
Add<HStoreNamedField>(function_context,
|
|
|
|
HObjectAccess::ForContextSlot(Context::CLOSURE_INDEX),
|
2014-02-04 10:48:49 +00:00
|
|
|
function);
|
2014-01-23 08:36:22 +00:00
|
|
|
Add<HStoreNamedField>(function_context,
|
|
|
|
HObjectAccess::ForContextSlot(Context::PREVIOUS_INDEX),
|
2014-02-04 10:48:49 +00:00
|
|
|
context());
|
2014-01-23 08:36:22 +00:00
|
|
|
Add<HStoreNamedField>(function_context,
|
|
|
|
HObjectAccess::ForContextSlot(Context::EXTENSION_INDEX),
|
2014-02-04 10:48:49 +00:00
|
|
|
graph()->GetConstant0());
|
2014-01-23 08:36:22 +00:00
|
|
|
|
|
|
|
// Copy the global object from the previous context.
|
|
|
|
HValue* global_object = Add<HLoadNamedField>(
|
2014-12-15 04:33:05 +00:00
|
|
|
context(), nullptr,
|
2014-01-29 09:48:35 +00:00
|
|
|
HObjectAccess::ForContextSlot(Context::GLOBAL_OBJECT_INDEX));
|
2014-01-23 08:36:22 +00:00
|
|
|
Add<HStoreNamedField>(function_context,
|
|
|
|
HObjectAccess::ForContextSlot(
|
|
|
|
Context::GLOBAL_OBJECT_INDEX),
|
2014-02-04 10:48:49 +00:00
|
|
|
global_object);
|
2014-01-23 08:36:22 +00:00
|
|
|
|
|
|
|
// Initialize the rest of the slots to undefined.
|
|
|
|
for (int i = Context::MIN_CONTEXT_SLOTS; i < length; ++i) {
|
|
|
|
Add<HStoreNamedField>(function_context,
|
|
|
|
HObjectAccess::ForContextSlot(i),
|
2014-02-04 10:48:49 +00:00
|
|
|
graph()->GetConstantUndefined());
|
2014-01-23 08:36:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return function_context;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-24 12:07:40 +00:00
|
|
|
Handle<Code> FastNewContextStub::GenerateCode() {
|
|
|
|
return DoGenerateCode(this);
|
2014-01-23 08:36:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-07-29 16:07:34 +00:00
|
|
|
template <>
|
|
|
|
HValue* CodeStubGraphBuilder<LoadDictionaryElementStub>::BuildCodeStub() {
|
2014-09-03 10:51:51 +00:00
|
|
|
HValue* receiver = GetParameter(LoadDescriptor::kReceiverIndex);
|
|
|
|
HValue* key = GetParameter(LoadDescriptor::kNameIndex);
|
2013-11-15 17:53:35 +00:00
|
|
|
|
|
|
|
Add<HCheckSmi>(key);
|
|
|
|
|
2014-06-12 09:58:10 +00:00
|
|
|
HValue* elements = AddLoadElements(receiver);
|
|
|
|
|
|
|
|
HValue* hash = BuildElementIndexHash(key);
|
|
|
|
|
|
|
|
return BuildUncheckedDictionaryElementLoad(receiver, elements, key, hash);
|
2013-11-15 17:53:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-07-29 16:07:34 +00:00
|
|
|
Handle<Code> LoadDictionaryElementStub::GenerateCode() {
|
2014-04-24 12:07:40 +00:00
|
|
|
return DoGenerateCode(this);
|
2013-11-15 17:53:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-01-29 13:10:35 +00:00
|
|
|
template<>
|
|
|
|
HValue* CodeStubGraphBuilder<RegExpConstructResultStub>::BuildCodeStub() {
|
|
|
|
// Determine the parameters.
|
|
|
|
HValue* length = GetParameter(RegExpConstructResultStub::kLength);
|
|
|
|
HValue* index = GetParameter(RegExpConstructResultStub::kIndex);
|
|
|
|
HValue* input = GetParameter(RegExpConstructResultStub::kInput);
|
|
|
|
|
2014-05-16 15:42:00 +00:00
|
|
|
info()->MarkMustNotHaveEagerFrame();
|
|
|
|
|
2014-01-29 13:10:35 +00:00
|
|
|
return BuildRegExpConstructResult(length, index, input);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-24 12:07:40 +00:00
|
|
|
Handle<Code> RegExpConstructResultStub::GenerateCode() {
|
|
|
|
return DoGenerateCode(this);
|
2014-01-29 13:10:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-06-12 09:58:10 +00:00
|
|
|
template <>
|
2014-07-29 16:07:34 +00:00
|
|
|
class CodeStubGraphBuilder<KeyedLoadGenericStub>
|
|
|
|
: public CodeStubGraphBuilderBase {
|
2014-06-12 09:58:10 +00:00
|
|
|
public:
|
2014-12-12 12:36:03 +00:00
|
|
|
explicit CodeStubGraphBuilder(CompilationInfoWithZone* info)
|
|
|
|
: CodeStubGraphBuilderBase(info) {}
|
2014-06-12 09:58:10 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual HValue* BuildCodeStub();
|
|
|
|
|
|
|
|
void BuildElementsKindLimitCheck(HGraphBuilder::IfBuilder* if_builder,
|
|
|
|
HValue* bit_field2,
|
|
|
|
ElementsKind kind);
|
|
|
|
|
|
|
|
void BuildFastElementLoad(HGraphBuilder::IfBuilder* if_builder,
|
|
|
|
HValue* receiver,
|
|
|
|
HValue* key,
|
|
|
|
HValue* instance_type,
|
|
|
|
HValue* bit_field2,
|
|
|
|
ElementsKind kind);
|
|
|
|
|
|
|
|
void BuildExternalElementLoad(HGraphBuilder::IfBuilder* if_builder,
|
|
|
|
HValue* receiver,
|
|
|
|
HValue* key,
|
|
|
|
HValue* instance_type,
|
|
|
|
HValue* bit_field2,
|
|
|
|
ElementsKind kind);
|
|
|
|
|
2014-07-29 16:07:34 +00:00
|
|
|
KeyedLoadGenericStub* casted_stub() {
|
|
|
|
return static_cast<KeyedLoadGenericStub*>(stub());
|
2014-06-12 09:58:10 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-07-29 16:07:34 +00:00
|
|
|
void CodeStubGraphBuilder<KeyedLoadGenericStub>::BuildElementsKindLimitCheck(
|
|
|
|
HGraphBuilder::IfBuilder* if_builder, HValue* bit_field2,
|
2014-06-12 09:58:10 +00:00
|
|
|
ElementsKind kind) {
|
|
|
|
ElementsKind next_kind = static_cast<ElementsKind>(kind + 1);
|
|
|
|
HValue* kind_limit = Add<HConstant>(
|
|
|
|
static_cast<int>(Map::ElementsKindBits::encode(next_kind)));
|
|
|
|
|
|
|
|
if_builder->If<HCompareNumericAndBranch>(bit_field2, kind_limit, Token::LT);
|
|
|
|
if_builder->Then();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-07-29 16:07:34 +00:00
|
|
|
void CodeStubGraphBuilder<KeyedLoadGenericStub>::BuildFastElementLoad(
|
|
|
|
HGraphBuilder::IfBuilder* if_builder, HValue* receiver, HValue* key,
|
|
|
|
HValue* instance_type, HValue* bit_field2, ElementsKind kind) {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(!IsExternalArrayElementsKind(kind));
|
2014-06-12 09:58:10 +00:00
|
|
|
|
|
|
|
BuildElementsKindLimitCheck(if_builder, bit_field2, kind);
|
|
|
|
|
|
|
|
IfBuilder js_array_check(this);
|
|
|
|
js_array_check.If<HCompareNumericAndBranch>(
|
|
|
|
instance_type, Add<HConstant>(JS_ARRAY_TYPE), Token::EQ);
|
|
|
|
js_array_check.Then();
|
|
|
|
Push(BuildUncheckedMonomorphicElementAccess(receiver, key, NULL,
|
|
|
|
true, kind,
|
|
|
|
LOAD, NEVER_RETURN_HOLE,
|
|
|
|
STANDARD_STORE));
|
|
|
|
js_array_check.Else();
|
|
|
|
Push(BuildUncheckedMonomorphicElementAccess(receiver, key, NULL,
|
|
|
|
false, kind,
|
|
|
|
LOAD, NEVER_RETURN_HOLE,
|
|
|
|
STANDARD_STORE));
|
|
|
|
js_array_check.End();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-07-29 16:07:34 +00:00
|
|
|
void CodeStubGraphBuilder<KeyedLoadGenericStub>::BuildExternalElementLoad(
|
|
|
|
HGraphBuilder::IfBuilder* if_builder, HValue* receiver, HValue* key,
|
|
|
|
HValue* instance_type, HValue* bit_field2, ElementsKind kind) {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(IsExternalArrayElementsKind(kind));
|
2014-06-12 09:58:10 +00:00
|
|
|
|
|
|
|
BuildElementsKindLimitCheck(if_builder, bit_field2, kind);
|
|
|
|
|
|
|
|
Push(BuildUncheckedMonomorphicElementAccess(receiver, key, NULL,
|
|
|
|
false, kind,
|
|
|
|
LOAD, NEVER_RETURN_HOLE,
|
|
|
|
STANDARD_STORE));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-07-29 16:07:34 +00:00
|
|
|
HValue* CodeStubGraphBuilder<KeyedLoadGenericStub>::BuildCodeStub() {
|
2014-09-03 10:51:51 +00:00
|
|
|
HValue* receiver = GetParameter(LoadDescriptor::kReceiverIndex);
|
|
|
|
HValue* key = GetParameter(LoadDescriptor::kNameIndex);
|
2014-06-12 09:58:10 +00:00
|
|
|
|
|
|
|
// Split into a smi/integer case and unique string case.
|
|
|
|
HIfContinuation index_name_split_continuation(graph()->CreateBasicBlock(),
|
|
|
|
graph()->CreateBasicBlock());
|
|
|
|
|
|
|
|
BuildKeyedIndexCheck(key, &index_name_split_continuation);
|
|
|
|
|
|
|
|
IfBuilder index_name_split(this, &index_name_split_continuation);
|
|
|
|
index_name_split.Then();
|
|
|
|
{
|
|
|
|
// Key is an index (number)
|
|
|
|
key = Pop();
|
|
|
|
|
|
|
|
int bit_field_mask = (1 << Map::kIsAccessCheckNeeded) |
|
|
|
|
(1 << Map::kHasIndexedInterceptor);
|
|
|
|
BuildJSObjectCheck(receiver, bit_field_mask);
|
|
|
|
|
2014-12-15 04:33:05 +00:00
|
|
|
HValue* map =
|
|
|
|
Add<HLoadNamedField>(receiver, nullptr, HObjectAccess::ForMap());
|
2014-06-12 09:58:10 +00:00
|
|
|
|
|
|
|
HValue* instance_type =
|
2014-12-15 04:33:05 +00:00
|
|
|
Add<HLoadNamedField>(map, nullptr, HObjectAccess::ForMapInstanceType());
|
2014-06-12 09:58:10 +00:00
|
|
|
|
2014-12-15 04:33:05 +00:00
|
|
|
HValue* bit_field2 =
|
|
|
|
Add<HLoadNamedField>(map, nullptr, HObjectAccess::ForMapBitField2());
|
2014-06-12 09:58:10 +00:00
|
|
|
|
|
|
|
IfBuilder kind_if(this);
|
|
|
|
BuildFastElementLoad(&kind_if, receiver, key, instance_type, bit_field2,
|
|
|
|
FAST_HOLEY_ELEMENTS);
|
|
|
|
|
|
|
|
kind_if.Else();
|
|
|
|
{
|
|
|
|
BuildFastElementLoad(&kind_if, receiver, key, instance_type, bit_field2,
|
|
|
|
FAST_HOLEY_DOUBLE_ELEMENTS);
|
|
|
|
}
|
|
|
|
kind_if.Else();
|
|
|
|
|
|
|
|
// The DICTIONARY_ELEMENTS check generates a "kind_if.Then"
|
|
|
|
BuildElementsKindLimitCheck(&kind_if, bit_field2, DICTIONARY_ELEMENTS);
|
|
|
|
{
|
|
|
|
HValue* elements = AddLoadElements(receiver);
|
|
|
|
|
|
|
|
HValue* hash = BuildElementIndexHash(key);
|
|
|
|
|
|
|
|
Push(BuildUncheckedDictionaryElementLoad(receiver, elements, key, hash));
|
|
|
|
}
|
|
|
|
kind_if.Else();
|
|
|
|
|
|
|
|
// The SLOPPY_ARGUMENTS_ELEMENTS check generates a "kind_if.Then"
|
|
|
|
BuildElementsKindLimitCheck(&kind_if, bit_field2,
|
|
|
|
SLOPPY_ARGUMENTS_ELEMENTS);
|
|
|
|
// Non-strict elements are not handled.
|
2014-07-29 16:07:34 +00:00
|
|
|
Add<HDeoptimize>("non-strict elements in KeyedLoadGenericStub",
|
2014-06-12 09:58:10 +00:00
|
|
|
Deoptimizer::EAGER);
|
|
|
|
Push(graph()->GetConstant0());
|
|
|
|
|
|
|
|
kind_if.Else();
|
|
|
|
BuildExternalElementLoad(&kind_if, receiver, key, instance_type, bit_field2,
|
|
|
|
EXTERNAL_INT8_ELEMENTS);
|
|
|
|
|
|
|
|
kind_if.Else();
|
|
|
|
BuildExternalElementLoad(&kind_if, receiver, key, instance_type, bit_field2,
|
|
|
|
EXTERNAL_UINT8_ELEMENTS);
|
|
|
|
|
|
|
|
kind_if.Else();
|
|
|
|
BuildExternalElementLoad(&kind_if, receiver, key, instance_type, bit_field2,
|
|
|
|
EXTERNAL_INT16_ELEMENTS);
|
|
|
|
|
|
|
|
kind_if.Else();
|
|
|
|
BuildExternalElementLoad(&kind_if, receiver, key, instance_type, bit_field2,
|
|
|
|
EXTERNAL_UINT16_ELEMENTS);
|
|
|
|
|
|
|
|
kind_if.Else();
|
|
|
|
BuildExternalElementLoad(&kind_if, receiver, key, instance_type, bit_field2,
|
|
|
|
EXTERNAL_INT32_ELEMENTS);
|
|
|
|
|
|
|
|
kind_if.Else();
|
|
|
|
BuildExternalElementLoad(&kind_if, receiver, key, instance_type, bit_field2,
|
|
|
|
EXTERNAL_UINT32_ELEMENTS);
|
|
|
|
|
|
|
|
kind_if.Else();
|
|
|
|
BuildExternalElementLoad(&kind_if, receiver, key, instance_type, bit_field2,
|
|
|
|
EXTERNAL_FLOAT32_ELEMENTS);
|
|
|
|
|
|
|
|
kind_if.Else();
|
|
|
|
BuildExternalElementLoad(&kind_if, receiver, key, instance_type, bit_field2,
|
|
|
|
EXTERNAL_FLOAT64_ELEMENTS);
|
|
|
|
|
|
|
|
kind_if.Else();
|
|
|
|
BuildExternalElementLoad(&kind_if, receiver, key, instance_type, bit_field2,
|
|
|
|
EXTERNAL_UINT8_CLAMPED_ELEMENTS);
|
|
|
|
|
2014-07-29 16:07:34 +00:00
|
|
|
kind_if.ElseDeopt("ElementsKind unhandled in KeyedLoadGenericStub");
|
2014-06-12 09:58:10 +00:00
|
|
|
|
|
|
|
kind_if.End();
|
|
|
|
}
|
|
|
|
index_name_split.Else();
|
|
|
|
{
|
|
|
|
// Key is a unique string.
|
|
|
|
key = Pop();
|
|
|
|
|
|
|
|
int bit_field_mask = (1 << Map::kIsAccessCheckNeeded) |
|
|
|
|
(1 << Map::kHasNamedInterceptor);
|
|
|
|
BuildJSObjectCheck(receiver, bit_field_mask);
|
|
|
|
|
|
|
|
HIfContinuation continuation;
|
|
|
|
BuildTestForDictionaryProperties(receiver, &continuation);
|
|
|
|
IfBuilder if_dict_properties(this, &continuation);
|
|
|
|
if_dict_properties.Then();
|
|
|
|
{
|
|
|
|
// Key is string, properties are dictionary mode
|
|
|
|
BuildNonGlobalObjectCheck(receiver);
|
|
|
|
|
|
|
|
HValue* properties = Add<HLoadNamedField>(
|
2014-12-15 04:33:05 +00:00
|
|
|
receiver, nullptr, HObjectAccess::ForPropertiesPointer());
|
2014-06-12 09:58:10 +00:00
|
|
|
|
|
|
|
HValue* hash =
|
2014-12-15 04:33:05 +00:00
|
|
|
Add<HLoadNamedField>(key, nullptr, HObjectAccess::ForNameHashField());
|
2014-06-12 09:58:10 +00:00
|
|
|
|
2014-07-03 08:55:42 +00:00
|
|
|
hash = AddUncasted<HShr>(hash, Add<HConstant>(Name::kHashShift));
|
|
|
|
|
2014-06-12 09:58:10 +00:00
|
|
|
HValue* value = BuildUncheckedDictionaryElementLoad(receiver,
|
|
|
|
properties,
|
|
|
|
key,
|
|
|
|
hash);
|
|
|
|
Push(value);
|
|
|
|
}
|
|
|
|
if_dict_properties.Else();
|
|
|
|
{
|
|
|
|
// Key is string, properties are fast mode
|
|
|
|
HValue* hash = BuildKeyedLookupCacheHash(receiver, key);
|
|
|
|
|
|
|
|
ExternalReference cache_keys_ref =
|
|
|
|
ExternalReference::keyed_lookup_cache_keys(isolate());
|
|
|
|
HValue* cache_keys = Add<HConstant>(cache_keys_ref);
|
|
|
|
|
2014-12-15 04:33:05 +00:00
|
|
|
HValue* map =
|
|
|
|
Add<HLoadNamedField>(receiver, nullptr, HObjectAccess::ForMap());
|
2014-06-12 09:58:10 +00:00
|
|
|
HValue* base_index = AddUncasted<HMul>(hash, Add<HConstant>(2));
|
|
|
|
base_index->ClearFlag(HValue::kCanOverflow);
|
|
|
|
|
2014-07-07 16:24:51 +00:00
|
|
|
HIfContinuation inline_or_runtime_continuation(
|
|
|
|
graph()->CreateBasicBlock(), graph()->CreateBasicBlock());
|
|
|
|
{
|
|
|
|
IfBuilder lookup_ifs[KeyedLookupCache::kEntriesPerBucket];
|
|
|
|
for (int probe = 0; probe < KeyedLookupCache::kEntriesPerBucket;
|
|
|
|
++probe) {
|
|
|
|
IfBuilder* lookup_if = &lookup_ifs[probe];
|
|
|
|
lookup_if->Initialize(this);
|
|
|
|
int probe_base = probe * KeyedLookupCache::kEntryLength;
|
|
|
|
HValue* map_index = AddUncasted<HAdd>(
|
|
|
|
base_index,
|
|
|
|
Add<HConstant>(probe_base + KeyedLookupCache::kMapIndex));
|
|
|
|
map_index->ClearFlag(HValue::kCanOverflow);
|
|
|
|
HValue* key_index = AddUncasted<HAdd>(
|
|
|
|
base_index,
|
|
|
|
Add<HConstant>(probe_base + KeyedLookupCache::kKeyIndex));
|
|
|
|
key_index->ClearFlag(HValue::kCanOverflow);
|
|
|
|
HValue* map_to_check =
|
2014-12-15 04:33:05 +00:00
|
|
|
Add<HLoadKeyed>(cache_keys, map_index, nullptr, FAST_ELEMENTS,
|
|
|
|
NEVER_RETURN_HOLE, 0);
|
2014-07-07 16:24:51 +00:00
|
|
|
lookup_if->If<HCompareObjectEqAndBranch>(map_to_check, map);
|
|
|
|
lookup_if->And();
|
|
|
|
HValue* key_to_check =
|
2014-12-15 04:33:05 +00:00
|
|
|
Add<HLoadKeyed>(cache_keys, key_index, nullptr, FAST_ELEMENTS,
|
|
|
|
NEVER_RETURN_HOLE, 0);
|
2014-07-07 16:24:51 +00:00
|
|
|
lookup_if->If<HCompareObjectEqAndBranch>(key_to_check, key);
|
|
|
|
lookup_if->Then();
|
|
|
|
{
|
|
|
|
ExternalReference cache_field_offsets_ref =
|
|
|
|
ExternalReference::keyed_lookup_cache_field_offsets(isolate());
|
|
|
|
HValue* cache_field_offsets =
|
|
|
|
Add<HConstant>(cache_field_offsets_ref);
|
|
|
|
HValue* index = AddUncasted<HAdd>(hash, Add<HConstant>(probe));
|
|
|
|
index->ClearFlag(HValue::kCanOverflow);
|
2014-12-15 04:33:05 +00:00
|
|
|
HValue* property_index =
|
|
|
|
Add<HLoadKeyed>(cache_field_offsets, index, nullptr,
|
|
|
|
EXTERNAL_INT32_ELEMENTS, NEVER_RETURN_HOLE, 0);
|
2014-07-07 16:24:51 +00:00
|
|
|
Push(property_index);
|
|
|
|
}
|
|
|
|
lookup_if->Else();
|
|
|
|
}
|
|
|
|
for (int i = 0; i < KeyedLookupCache::kEntriesPerBucket; ++i) {
|
|
|
|
lookup_ifs[i].JoinContinuation(&inline_or_runtime_continuation);
|
2014-06-12 09:58:10 +00:00
|
|
|
}
|
|
|
|
}
|
2014-07-07 16:24:51 +00:00
|
|
|
|
|
|
|
IfBuilder inline_or_runtime(this, &inline_or_runtime_continuation);
|
|
|
|
inline_or_runtime.Then();
|
|
|
|
{
|
|
|
|
// Found a cached index, load property inline.
|
|
|
|
Push(Add<HLoadFieldByIndex>(receiver, Pop()));
|
|
|
|
}
|
|
|
|
inline_or_runtime.Else();
|
|
|
|
{
|
|
|
|
// KeyedLookupCache miss; call runtime.
|
|
|
|
Add<HPushArguments>(receiver, key);
|
|
|
|
Push(Add<HCallRuntime>(
|
|
|
|
isolate()->factory()->empty_string(),
|
|
|
|
Runtime::FunctionForId(Runtime::kKeyedGetProperty), 2));
|
|
|
|
}
|
|
|
|
inline_or_runtime.End();
|
2014-06-12 09:58:10 +00:00
|
|
|
}
|
|
|
|
if_dict_properties.End();
|
|
|
|
}
|
|
|
|
index_name_split.End();
|
|
|
|
|
|
|
|
return Pop();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-07-29 16:07:34 +00:00
|
|
|
Handle<Code> KeyedLoadGenericStub::GenerateCode() {
|
2014-06-12 09:58:10 +00:00
|
|
|
return DoGenerateCode(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-12-12 13:56:11 +00:00
|
|
|
void CodeStubGraphBuilderBase::TailCallHandler(HValue* receiver, HValue* name,
|
|
|
|
HValue* array, HValue* map_index,
|
|
|
|
HValue* slot, HValue* vector) {
|
|
|
|
// The handler is at array[map_index + 1]. Compute this with a custom offset
|
|
|
|
// to HLoadKeyed.
|
|
|
|
int offset =
|
|
|
|
GetDefaultHeaderSizeForElementsKind(FAST_ELEMENTS) + kPointerSize;
|
2014-12-15 04:33:05 +00:00
|
|
|
HValue* handler_code = Add<HLoadKeyed>(
|
|
|
|
array, map_index, nullptr, FAST_ELEMENTS, NEVER_RETURN_HOLE, offset);
|
2014-12-12 13:56:11 +00:00
|
|
|
TailCallHandler(receiver, name, slot, vector, handler_code);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CodeStubGraphBuilderBase::TailCallHandler(HValue* receiver, HValue* name,
|
|
|
|
HValue* slot, HValue* vector,
|
|
|
|
HValue* handler_code) {
|
|
|
|
VectorLoadICDescriptor descriptor(isolate());
|
|
|
|
HValue* op_vals[] = {context(), receiver, name, slot, vector};
|
|
|
|
Add<HCallWithDescriptor>(handler_code, 0, descriptor,
|
|
|
|
Vector<HValue*>(op_vals, 5), TAIL_CALL);
|
|
|
|
// We never return here, it is a tail call.
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CodeStubGraphBuilderBase::TailCallMiss(HValue* receiver, HValue* name,
|
|
|
|
HValue* slot, HValue* vector,
|
|
|
|
bool keyed_load) {
|
|
|
|
DCHECK(FLAG_vector_ics);
|
|
|
|
Add<HTailCallThroughMegamorphicCache>(
|
|
|
|
receiver, name, slot, vector,
|
|
|
|
HTailCallThroughMegamorphicCache::ComputeFlags(keyed_load, true));
|
|
|
|
// We never return here, it is a tail call.
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CodeStubGraphBuilderBase::HandleArrayCases(HValue* array, HValue* receiver,
|
|
|
|
HValue* name, HValue* slot,
|
|
|
|
HValue* vector,
|
|
|
|
bool keyed_load) {
|
|
|
|
IfBuilder if_receiver_heap_object(this);
|
|
|
|
if_receiver_heap_object.IfNot<HIsSmiAndBranch>(receiver);
|
|
|
|
if_receiver_heap_object.Then();
|
|
|
|
{
|
|
|
|
HConstant* constant_two = Add<HConstant>(2);
|
|
|
|
HConstant* constant_three = Add<HConstant>(3);
|
|
|
|
|
2014-12-15 04:33:05 +00:00
|
|
|
HValue* receiver_map = AddLoadMap(receiver, nullptr);
|
2014-12-12 13:56:11 +00:00
|
|
|
HValue* start =
|
|
|
|
keyed_load ? graph()->GetConstant1() : graph()->GetConstant0();
|
2014-12-15 04:33:05 +00:00
|
|
|
HValue* array_map = Add<HLoadKeyed>(array, start, nullptr, FAST_ELEMENTS,
|
|
|
|
ALLOW_RETURN_HOLE);
|
2014-12-12 13:56:11 +00:00
|
|
|
IfBuilder if_correct_map(this);
|
|
|
|
if_correct_map.If<HCompareObjectEqAndBranch>(receiver_map, array_map);
|
|
|
|
if_correct_map.Then();
|
|
|
|
{ TailCallHandler(receiver, name, array, start, slot, vector); }
|
|
|
|
if_correct_map.Else();
|
|
|
|
{
|
|
|
|
// If our array has more elements, the ic is polymorphic. Look for the
|
|
|
|
// receiver map in the rest of the array.
|
2014-12-15 04:33:05 +00:00
|
|
|
HValue* length = AddLoadFixedArrayLength(array, nullptr);
|
2014-12-12 13:56:11 +00:00
|
|
|
LoopBuilder builder(this, context(), LoopBuilder::kPostIncrement,
|
|
|
|
constant_two);
|
|
|
|
start = keyed_load ? constant_three : constant_two;
|
|
|
|
HValue* key = builder.BeginBody(start, length, Token::LT);
|
|
|
|
{
|
2014-12-15 04:33:05 +00:00
|
|
|
HValue* array_map = Add<HLoadKeyed>(array, key, nullptr, FAST_ELEMENTS,
|
|
|
|
ALLOW_RETURN_HOLE);
|
2014-12-12 13:56:11 +00:00
|
|
|
IfBuilder if_correct_poly_map(this);
|
|
|
|
if_correct_poly_map.If<HCompareObjectEqAndBranch>(receiver_map,
|
|
|
|
array_map);
|
|
|
|
if_correct_poly_map.Then();
|
|
|
|
{ TailCallHandler(receiver, name, array, key, slot, vector); }
|
|
|
|
}
|
|
|
|
builder.EndBody();
|
|
|
|
}
|
|
|
|
if_correct_map.End();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-08-26 14:12:47 +00:00
|
|
|
template <>
|
|
|
|
HValue* CodeStubGraphBuilder<VectorLoadStub>::BuildCodeStub() {
|
2014-09-03 10:51:51 +00:00
|
|
|
HValue* receiver = GetParameter(VectorLoadICDescriptor::kReceiverIndex);
|
2014-12-12 13:56:11 +00:00
|
|
|
HValue* name = GetParameter(VectorLoadICDescriptor::kNameIndex);
|
|
|
|
HValue* slot = GetParameter(VectorLoadICDescriptor::kSlotIndex);
|
|
|
|
HValue* vector = GetParameter(VectorLoadICDescriptor::kVectorIndex);
|
|
|
|
|
|
|
|
// If the feedback is an array, then the IC is in the monomorphic or
|
|
|
|
// polymorphic state.
|
2014-12-15 04:33:05 +00:00
|
|
|
HValue* feedback =
|
|
|
|
Add<HLoadKeyed>(vector, slot, nullptr, FAST_ELEMENTS, ALLOW_RETURN_HOLE);
|
2014-12-12 13:56:11 +00:00
|
|
|
IfBuilder array_checker(this);
|
|
|
|
array_checker.If<HCompareMap>(feedback,
|
|
|
|
isolate()->factory()->fixed_array_map());
|
|
|
|
array_checker.Then();
|
|
|
|
{ HandleArrayCases(feedback, receiver, name, slot, vector, false); }
|
|
|
|
array_checker.Else();
|
|
|
|
{
|
|
|
|
// Is the IC megamorphic?
|
|
|
|
IfBuilder mega_checker(this);
|
|
|
|
HConstant* megamorphic_symbol =
|
|
|
|
Add<HConstant>(isolate()->factory()->megamorphic_symbol());
|
|
|
|
mega_checker.If<HCompareObjectEqAndBranch>(feedback, megamorphic_symbol);
|
|
|
|
mega_checker.Then();
|
|
|
|
{
|
|
|
|
// Probe the stub cache.
|
|
|
|
Add<HTailCallThroughMegamorphicCache>(
|
|
|
|
receiver, name, slot, vector,
|
|
|
|
HTailCallThroughMegamorphicCache::ComputeFlags(false, false));
|
|
|
|
}
|
|
|
|
mega_checker.End();
|
|
|
|
}
|
|
|
|
array_checker.End();
|
|
|
|
|
|
|
|
TailCallMiss(receiver, name, slot, vector, false);
|
|
|
|
return graph()->GetConstant0();
|
2014-08-26 14:12:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<Code> VectorLoadStub::GenerateCode() { return DoGenerateCode(this); }
|
|
|
|
|
|
|
|
|
|
|
|
template <>
|
|
|
|
HValue* CodeStubGraphBuilder<VectorKeyedLoadStub>::BuildCodeStub() {
|
2014-09-03 10:51:51 +00:00
|
|
|
HValue* receiver = GetParameter(VectorLoadICDescriptor::kReceiverIndex);
|
2014-12-12 13:56:11 +00:00
|
|
|
HValue* name = GetParameter(VectorLoadICDescriptor::kNameIndex);
|
|
|
|
HValue* slot = GetParameter(VectorLoadICDescriptor::kSlotIndex);
|
|
|
|
HValue* vector = GetParameter(VectorLoadICDescriptor::kVectorIndex);
|
|
|
|
HConstant* zero = graph()->GetConstant0();
|
|
|
|
|
|
|
|
// If the feedback is an array, then the IC is in the monomorphic or
|
|
|
|
// polymorphic state.
|
2014-12-15 04:33:05 +00:00
|
|
|
HValue* feedback =
|
|
|
|
Add<HLoadKeyed>(vector, slot, nullptr, FAST_ELEMENTS, ALLOW_RETURN_HOLE);
|
2014-12-12 13:56:11 +00:00
|
|
|
IfBuilder array_checker(this);
|
|
|
|
array_checker.If<HCompareMap>(feedback,
|
|
|
|
isolate()->factory()->fixed_array_map());
|
|
|
|
array_checker.Then();
|
|
|
|
{
|
|
|
|
// If feedback[0] is 0, then the IC has element handlers and name should be
|
|
|
|
// a smi. If feedback[0] is a string, verify that it matches name.
|
2014-12-15 04:33:05 +00:00
|
|
|
HValue* recorded_name = Add<HLoadKeyed>(feedback, zero, nullptr,
|
|
|
|
FAST_ELEMENTS, ALLOW_RETURN_HOLE);
|
2014-12-12 13:56:11 +00:00
|
|
|
|
|
|
|
IfBuilder recorded_name_is_zero(this);
|
|
|
|
recorded_name_is_zero.If<HCompareObjectEqAndBranch>(recorded_name, zero);
|
|
|
|
recorded_name_is_zero.Then();
|
|
|
|
{ Add<HCheckSmi>(name); }
|
|
|
|
recorded_name_is_zero.Else();
|
|
|
|
{
|
|
|
|
IfBuilder strings_match(this);
|
|
|
|
strings_match.IfNot<HCompareObjectEqAndBranch>(name, recorded_name);
|
|
|
|
strings_match.Then();
|
|
|
|
TailCallMiss(receiver, name, slot, vector, true);
|
|
|
|
strings_match.End();
|
|
|
|
}
|
|
|
|
recorded_name_is_zero.End();
|
|
|
|
|
|
|
|
HandleArrayCases(feedback, receiver, name, slot, vector, true);
|
|
|
|
}
|
|
|
|
array_checker.Else();
|
|
|
|
{
|
|
|
|
// Check if the IC is in generic state.
|
|
|
|
IfBuilder generic_checker(this);
|
|
|
|
HConstant* generic_symbol =
|
|
|
|
Add<HConstant>(isolate()->factory()->generic_symbol());
|
|
|
|
generic_checker.If<HCompareObjectEqAndBranch>(feedback, generic_symbol);
|
|
|
|
generic_checker.Then();
|
|
|
|
{
|
|
|
|
// Tail-call to the generic KeyedLoadIC, treating it like a handler.
|
|
|
|
Handle<Code> stub = KeyedLoadIC::generic_stub(isolate());
|
|
|
|
HValue* constant_stub = Add<HConstant>(stub);
|
|
|
|
LoadDescriptor descriptor(isolate());
|
|
|
|
HValue* op_vals[] = {context(), receiver, name};
|
|
|
|
Add<HCallWithDescriptor>(constant_stub, 0, descriptor,
|
|
|
|
Vector<HValue*>(op_vals, 3), TAIL_CALL);
|
|
|
|
// We never return here, it is a tail call.
|
|
|
|
}
|
|
|
|
generic_checker.End();
|
|
|
|
}
|
|
|
|
array_checker.End();
|
|
|
|
|
|
|
|
TailCallMiss(receiver, name, slot, vector, true);
|
|
|
|
return zero;
|
2014-08-26 14:12:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<Code> VectorKeyedLoadStub::GenerateCode() {
|
|
|
|
return DoGenerateCode(this);
|
|
|
|
}
|
2014-09-08 12:51:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
Handle<Code> MegamorphicLoadStub::GenerateCode() {
|
|
|
|
return DoGenerateCode(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <>
|
|
|
|
HValue* CodeStubGraphBuilder<MegamorphicLoadStub>::BuildCodeStub() {
|
|
|
|
HValue* receiver = GetParameter(LoadDescriptor::kReceiverIndex);
|
|
|
|
HValue* name = GetParameter(LoadDescriptor::kNameIndex);
|
|
|
|
|
2014-12-12 13:56:11 +00:00
|
|
|
// We shouldn't generate this when FLAG_vector_ics is true because the
|
|
|
|
// megamorphic case is handled as part of the default stub.
|
|
|
|
DCHECK(!FLAG_vector_ics);
|
|
|
|
|
2014-09-08 12:51:29 +00:00
|
|
|
// Probe the stub cache.
|
2014-12-12 13:56:11 +00:00
|
|
|
Add<HTailCallThroughMegamorphicCache>(receiver, name);
|
2014-09-08 12:51:29 +00:00
|
|
|
|
|
|
|
// We never continue.
|
|
|
|
return graph()->GetConstant0();
|
|
|
|
}
|
2012-12-18 16:25:45 +00:00
|
|
|
} } // namespace v8::internal
|