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:
|
2015-03-23 17:30:38 +00:00
|
|
|
explicit CodeStubGraphBuilderBase(CompilationInfo* info)
|
2014-12-12 12:36:03 +00:00
|
|
|
: 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) {
|
2015-07-01 08:45:05 +00:00
|
|
|
int parameter_count = GetParameterCount();
|
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;
|
2015-07-01 08:45:05 +00:00
|
|
|
int GetParameterCount() const {
|
|
|
|
return descriptor_.GetRegisterParameterCount();
|
|
|
|
}
|
2013-03-08 21:07:55 +00:00
|
|
|
HParameter* GetParameter(int parameter) {
|
2015-07-01 08:45:05 +00:00
|
|
|
DCHECK(parameter < GetParameterCount());
|
2013-03-08 21:07:55 +00:00
|
|
|
return parameters_[parameter];
|
|
|
|
}
|
2015-07-01 08:45:05 +00:00
|
|
|
Representation GetParameterRepresentation(int parameter) {
|
|
|
|
return RepresentationFromType(descriptor_.GetParameterType(parameter));
|
|
|
|
}
|
|
|
|
bool IsParameterCountRegister(int index) const {
|
|
|
|
return descriptor_.GetRegisterParameter(index)
|
|
|
|
.is(descriptor_.stack_parameter_count());
|
|
|
|
}
|
2013-03-08 21:07:55 +00:00
|
|
|
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_; }
|
2015-02-10 11:45:59 +00:00
|
|
|
CodeStub* 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
|
|
|
|
2015-06-30 15:24:27 +00:00
|
|
|
HLoadNamedField* BuildLoadNamedField(HValue* object, 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
|
|
|
|
};
|
|
|
|
|
2015-05-28 14:55:59 +00:00
|
|
|
HValue* UnmappedCase(HValue* elements, HValue* key, HValue* value);
|
|
|
|
HValue* EmitKeyedSloppyArguments(HValue* receiver, HValue* key,
|
|
|
|
HValue* value);
|
2014-09-22 13:23:27 +00:00
|
|
|
|
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);
|
2015-06-26 09:07:30 +00:00
|
|
|
void BuildInstallOptimizedCode(HValue* js_function, HValue* native_context,
|
|
|
|
HValue* code_object, HValue* literals);
|
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);
|
|
|
|
|
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);
|
|
|
|
|
2015-07-13 12:38:06 +00:00
|
|
|
base::SmartArrayPointer<HParameter*> parameters_;
|
2013-03-08 21:07:55 +00:00
|
|
|
HValue* arguments_length_;
|
2015-03-23 17:30:38 +00:00
|
|
|
CompilationInfo* 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
|
|
|
}
|
|
|
|
|
2015-07-01 08:45:05 +00:00
|
|
|
int param_count = GetParameterCount();
|
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) {
|
2015-07-01 08:45:05 +00:00
|
|
|
Representation r = GetParameterRepresentation(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;
|
2015-07-01 08:45:05 +00:00
|
|
|
if (IsParameterCountRegister(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:
|
2015-03-23 17:30:38 +00:00
|
|
|
explicit CodeStubGraphBuilder(CompilationInfo* info)
|
2014-12-12 12:36:03 +00:00
|
|
|
: 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();
|
2015-02-05 14:51:45 +00:00
|
|
|
builder.ElseDeopt(Deoptimizer::kForcedDeoptToRuntime);
|
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();
|
|
|
|
}
|
2015-03-23 17:30:38 +00:00
|
|
|
Zone zone;
|
|
|
|
CompilationInfo info(stub, isolate, &zone);
|
2014-12-12 12:36:03 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-05-06 13:31:00 +00:00
|
|
|
// Returns the type string of a value; see ECMA-262, 11.4.3 (p 47).
|
|
|
|
// Possible optimizations: put the type string into the oddballs.
|
|
|
|
template <>
|
|
|
|
HValue* CodeStubGraphBuilder<TypeofStub>::BuildCodeStub() {
|
|
|
|
Factory* factory = isolate()->factory();
|
|
|
|
HConstant* number_string = Add<HConstant>(factory->number_string());
|
|
|
|
HValue* object = GetParameter(TypeofStub::kObject);
|
|
|
|
|
|
|
|
IfBuilder is_smi(this);
|
|
|
|
HValue* smi_check = is_smi.If<HIsSmiAndBranch>(object);
|
|
|
|
is_smi.Then();
|
|
|
|
{ Push(number_string); }
|
|
|
|
is_smi.Else();
|
|
|
|
{
|
|
|
|
IfBuilder is_number(this);
|
|
|
|
is_number.If<HCompareMap>(object, isolate()->factory()->heap_number_map());
|
|
|
|
is_number.Then();
|
|
|
|
{ Push(number_string); }
|
|
|
|
is_number.Else();
|
|
|
|
{
|
|
|
|
HConstant* undefined_string = Add<HConstant>(factory->undefined_string());
|
|
|
|
HValue* map = AddLoadMap(object, smi_check);
|
|
|
|
HValue* instance_type = Add<HLoadNamedField>(
|
|
|
|
map, nullptr, HObjectAccess::ForMapInstanceType());
|
|
|
|
IfBuilder is_string(this);
|
|
|
|
is_string.If<HCompareNumericAndBranch>(
|
|
|
|
instance_type, Add<HConstant>(FIRST_NONSTRING_TYPE), Token::LT);
|
|
|
|
is_string.Then();
|
|
|
|
{ Push(Add<HConstant>(factory->string_string())); }
|
|
|
|
is_string.Else();
|
|
|
|
{
|
|
|
|
HConstant* object_string = Add<HConstant>(factory->object_string());
|
|
|
|
IfBuilder is_oddball(this);
|
|
|
|
is_oddball.If<HCompareNumericAndBranch>(
|
|
|
|
instance_type, Add<HConstant>(ODDBALL_TYPE), Token::EQ);
|
|
|
|
is_oddball.Then();
|
|
|
|
{
|
|
|
|
IfBuilder is_true_or_false(this);
|
|
|
|
is_true_or_false.If<HCompareObjectEqAndBranch>(
|
|
|
|
object, graph()->GetConstantTrue());
|
|
|
|
is_true_or_false.OrIf<HCompareObjectEqAndBranch>(
|
|
|
|
object, graph()->GetConstantFalse());
|
|
|
|
is_true_or_false.Then();
|
|
|
|
{ Push(Add<HConstant>(factory->boolean_string())); }
|
|
|
|
is_true_or_false.Else();
|
|
|
|
{
|
|
|
|
IfBuilder is_null(this);
|
|
|
|
is_null.If<HCompareObjectEqAndBranch>(object,
|
|
|
|
graph()->GetConstantNull());
|
|
|
|
is_null.Then();
|
|
|
|
{ Push(object_string); }
|
|
|
|
is_null.Else();
|
|
|
|
{ Push(undefined_string); }
|
|
|
|
}
|
|
|
|
is_true_or_false.End();
|
|
|
|
}
|
|
|
|
is_oddball.Else();
|
|
|
|
{
|
|
|
|
IfBuilder is_symbol(this);
|
|
|
|
is_symbol.If<HCompareNumericAndBranch>(
|
|
|
|
instance_type, Add<HConstant>(SYMBOL_TYPE), Token::EQ);
|
|
|
|
is_symbol.Then();
|
|
|
|
{ Push(Add<HConstant>(factory->symbol_string())); }
|
|
|
|
is_symbol.Else();
|
|
|
|
{
|
|
|
|
IfBuilder is_function(this);
|
|
|
|
HConstant* js_function = Add<HConstant>(JS_FUNCTION_TYPE);
|
|
|
|
HConstant* js_function_proxy =
|
|
|
|
Add<HConstant>(JS_FUNCTION_PROXY_TYPE);
|
|
|
|
is_function.If<HCompareNumericAndBranch>(instance_type, js_function,
|
|
|
|
Token::EQ);
|
|
|
|
is_function.OrIf<HCompareNumericAndBranch>(
|
|
|
|
instance_type, js_function_proxy, Token::EQ);
|
|
|
|
is_function.Then();
|
|
|
|
{ Push(Add<HConstant>(factory->function_string())); }
|
|
|
|
is_function.Else();
|
|
|
|
{
|
2015-07-16 19:43:21 +00:00
|
|
|
IfBuilder is_float32x4(this);
|
|
|
|
is_float32x4.If<HCompareNumericAndBranch>(
|
|
|
|
instance_type, Add<HConstant>(FLOAT32X4_TYPE), Token::EQ);
|
|
|
|
is_float32x4.Then();
|
|
|
|
{ Push(Add<HConstant>(factory->float32x4_string())); }
|
|
|
|
is_float32x4.Else();
|
2015-05-06 13:31:00 +00:00
|
|
|
{
|
2015-07-16 19:43:21 +00:00
|
|
|
// Is it an undetectable object?
|
|
|
|
IfBuilder is_undetectable(this);
|
|
|
|
is_undetectable.If<HIsUndetectableAndBranch>(object);
|
|
|
|
is_undetectable.Then();
|
|
|
|
{
|
|
|
|
// typeof an undetectable object is 'undefined'.
|
|
|
|
Push(undefined_string);
|
|
|
|
}
|
|
|
|
is_undetectable.Else();
|
|
|
|
{
|
|
|
|
// For any kind of object not handled above, the spec rule for
|
|
|
|
// host objects gives that it is okay to return "object".
|
|
|
|
Push(object_string);
|
|
|
|
}
|
2015-05-06 13:31:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
is_function.End();
|
|
|
|
}
|
|
|
|
is_symbol.End();
|
|
|
|
}
|
|
|
|
is_oddball.End();
|
|
|
|
}
|
|
|
|
is_string.End();
|
|
|
|
}
|
|
|
|
is_number.End();
|
|
|
|
}
|
|
|
|
is_smi.End();
|
|
|
|
|
|
|
|
return environment()->Pop();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<Code> TypeofStub::GenerateCode() { return DoGenerateCode(this); }
|
|
|
|
|
|
|
|
|
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
|
|
|
|
2015-02-05 14:51:45 +00:00
|
|
|
checker.ElseDeopt(Deoptimizer::kUninitializedBoilerplateLiterals);
|
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);
|
2015-02-05 14:51:45 +00:00
|
|
|
checker.ElseDeopt(Deoptimizer::kUninitializedBoilerplateInFastClone);
|
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() {
|
2015-02-04 09:46:05 +00:00
|
|
|
// This stub is performance sensitive, the generated code must be tuned
|
|
|
|
// so that it doesn't build an eager frame.
|
|
|
|
info()->MarkMustNotHaveEagerFrame();
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-02-04 09:46:05 +00:00
|
|
|
template <>
|
|
|
|
HValue* CodeStubGraphBuilder<CreateWeakCellStub>::BuildCodeStub() {
|
|
|
|
// This stub is performance sensitive, the generated code must be tuned
|
|
|
|
// so that it doesn't build an eager frame.
|
|
|
|
info()->MarkMustNotHaveEagerFrame();
|
|
|
|
|
|
|
|
HValue* size = Add<HConstant>(WeakCell::kSize);
|
|
|
|
HInstruction* object =
|
|
|
|
Add<HAllocate>(size, HType::JSObject(), TENURED, JS_OBJECT_TYPE);
|
|
|
|
|
|
|
|
Handle<Map> weak_cell_map = isolate()->factory()->weak_cell_map();
|
|
|
|
AddStoreMapConstant(object, weak_cell_map);
|
|
|
|
|
|
|
|
HInstruction* value = GetParameter(CreateWeakCellDescriptor::kValueIndex);
|
|
|
|
Add<HStoreNamedField>(object, HObjectAccess::ForWeakCellValue(), value);
|
|
|
|
Add<HStoreNamedField>(object, HObjectAccess::ForWeakCellNext(),
|
2015-06-16 11:04:13 +00:00
|
|
|
graph()->GetConstantHole());
|
2015-02-04 09:46:05 +00:00
|
|
|
|
|
|
|
HInstruction* feedback_vector =
|
|
|
|
GetParameter(CreateWeakCellDescriptor::kVectorIndex);
|
|
|
|
HInstruction* slot = GetParameter(CreateWeakCellDescriptor::kSlotIndex);
|
|
|
|
Add<HStoreKeyed>(feedback_vector, slot, object, FAST_ELEMENTS,
|
|
|
|
INITIALIZING_STORE);
|
|
|
|
return graph()->GetConstant0();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<Code> CreateWeakCellStub::GenerateCode() { return DoGenerateCode(this); }
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-04-30 12:34:02 +00:00
|
|
|
template <>
|
|
|
|
HValue* CodeStubGraphBuilder<GrowArrayElementsStub>::BuildCodeStub() {
|
2015-05-05 14:44:02 +00:00
|
|
|
ElementsKind kind = casted_stub()->elements_kind();
|
|
|
|
if (IsFastDoubleElementsKind(kind)) {
|
|
|
|
info()->MarkAsSavesCallerDoubles();
|
|
|
|
}
|
|
|
|
|
2015-04-30 12:34:02 +00:00
|
|
|
HValue* object = GetParameter(GrowArrayElementsDescriptor::kObjectIndex);
|
|
|
|
HValue* key = GetParameter(GrowArrayElementsDescriptor::kKeyIndex);
|
|
|
|
|
|
|
|
HValue* elements = AddLoadElements(object);
|
2015-05-12 08:47:15 +00:00
|
|
|
HValue* current_capacity = Add<HLoadNamedField>(
|
|
|
|
elements, nullptr, HObjectAccess::ForFixedArrayLength());
|
|
|
|
|
2015-04-30 12:34:02 +00:00
|
|
|
HValue* length =
|
|
|
|
casted_stub()->is_js_array()
|
|
|
|
? Add<HLoadNamedField>(object, static_cast<HValue*>(NULL),
|
|
|
|
HObjectAccess::ForArrayLength(kind))
|
|
|
|
: current_capacity;
|
|
|
|
|
|
|
|
return BuildCheckAndGrowElementsCapacity(object, elements, kind, length,
|
|
|
|
current_capacity, key);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<Code> GrowArrayElementsStub::GenerateCode() {
|
|
|
|
return DoGenerateCode(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-12-18 16:25:45 +00:00
|
|
|
template <>
|
2014-07-29 16:07:34 +00:00
|
|
|
HValue* CodeStubGraphBuilder<LoadFastElementStub>::BuildCodeStub() {
|
2015-04-27 08:46:58 +00:00
|
|
|
LoadKeyedHoleMode hole_mode = casted_stub()->convert_hole_to_undefined()
|
|
|
|
? CONVERT_HOLE_TO_UNDEFINED
|
|
|
|
: NEVER_RETURN_HOLE;
|
|
|
|
|
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,
|
2015-04-27 08:46:58 +00:00
|
|
|
hole_mode, 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
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-04-27 09:28:16 +00:00
|
|
|
template <>
|
|
|
|
HValue* CodeStubGraphBuilder<ArrayBufferViewLoadFieldStub>::BuildCodeStub() {
|
|
|
|
return BuildArrayBufferViewFieldAccessor(GetParameter(0), nullptr,
|
|
|
|
casted_stub()->index());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<Code> ArrayBufferViewLoadFieldStub::GenerateCode() {
|
|
|
|
return DoGenerateCode(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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); }
|
|
|
|
|
|
|
|
|
2015-05-28 14:55:59 +00:00
|
|
|
HValue* CodeStubGraphBuilderBase::UnmappedCase(HValue* elements, HValue* key,
|
|
|
|
HValue* value) {
|
|
|
|
HValue* result = NULL;
|
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();
|
|
|
|
{
|
2015-05-28 14:55:59 +00:00
|
|
|
if (value == NULL) {
|
|
|
|
result = Add<HLoadKeyed>(backing_store, key, nullptr, FAST_HOLEY_ELEMENTS,
|
|
|
|
NEVER_RETURN_HOLE);
|
|
|
|
} else {
|
|
|
|
Add<HStoreKeyed>(backing_store, key, value, FAST_HOLEY_ELEMENTS);
|
|
|
|
}
|
2014-09-22 13:23:27 +00:00
|
|
|
}
|
2015-02-05 14:51:45 +00:00
|
|
|
in_unmapped_range.ElseDeopt(Deoptimizer::kOutsideOfRange);
|
2014-09-22 13:23:27 +00:00
|
|
|
in_unmapped_range.End();
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-05-28 14:55:59 +00:00
|
|
|
HValue* CodeStubGraphBuilderBase::EmitKeyedSloppyArguments(HValue* receiver,
|
|
|
|
HValue* key,
|
|
|
|
HValue* value) {
|
2014-09-22 13:23:27 +00:00
|
|
|
// 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].
|
|
|
|
|
2015-05-28 14:55:59 +00:00
|
|
|
bool is_load = value == NULL;
|
|
|
|
|
2014-09-22 13:23:27 +00:00
|
|
|
key = AddUncasted<HForceRepresentation>(key, Representation::Smi());
|
|
|
|
IfBuilder positive_smi(this);
|
|
|
|
positive_smi.If<HCompareNumericAndBranch>(key, graph()->GetConstant0(),
|
|
|
|
Token::LT);
|
2015-02-05 14:51:45 +00:00
|
|
|
positive_smi.ThenDeopt(Deoptimizer::kKeyIsNegative);
|
2014-09-22 13:23:27 +00:00
|
|
|
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);
|
2015-01-21 13:38:06 +00:00
|
|
|
STATIC_ASSERT(Context::kHeaderSize == FixedArray::kHeaderSize);
|
2015-05-28 14:55:59 +00:00
|
|
|
if (is_load) {
|
|
|
|
HValue* result = Add<HLoadKeyed>(the_context, mapped_index, nullptr,
|
|
|
|
FAST_ELEMENTS, ALLOW_RETURN_HOLE);
|
|
|
|
environment()->Push(result);
|
|
|
|
} else {
|
|
|
|
DCHECK(value != NULL);
|
|
|
|
Add<HStoreKeyed>(the_context, mapped_index, value, FAST_ELEMENTS);
|
|
|
|
environment()->Push(value);
|
|
|
|
}
|
2014-09-22 13:23:27 +00:00
|
|
|
}
|
|
|
|
is_valid.Else();
|
|
|
|
{
|
2015-05-28 14:55:59 +00:00
|
|
|
HValue* result = UnmappedCase(elements, key, value);
|
|
|
|
environment()->Push(is_load ? result : value);
|
2014-09-22 13:23:27 +00:00
|
|
|
}
|
|
|
|
is_valid.End();
|
|
|
|
}
|
|
|
|
in_range.Else();
|
|
|
|
{
|
2015-05-28 14:55:59 +00:00
|
|
|
HValue* result = UnmappedCase(elements, key, value);
|
|
|
|
environment()->Push(is_load ? result : value);
|
2014-09-22 13:23:27 +00:00
|
|
|
}
|
|
|
|
in_range.End();
|
|
|
|
|
|
|
|
return environment()->Pop();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-05-28 14:55:59 +00:00
|
|
|
template <>
|
|
|
|
HValue* CodeStubGraphBuilder<KeyedLoadSloppyArgumentsStub>::BuildCodeStub() {
|
|
|
|
HValue* receiver = GetParameter(LoadDescriptor::kReceiverIndex);
|
|
|
|
HValue* key = GetParameter(LoadDescriptor::kNameIndex);
|
|
|
|
|
|
|
|
return EmitKeyedSloppyArguments(receiver, key, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-22 13:23:27 +00:00
|
|
|
Handle<Code> KeyedLoadSloppyArgumentsStub::GenerateCode() {
|
|
|
|
return DoGenerateCode(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-05-28 14:55:59 +00:00
|
|
|
template <>
|
|
|
|
HValue* CodeStubGraphBuilder<KeyedStoreSloppyArgumentsStub>::BuildCodeStub() {
|
|
|
|
HValue* receiver = GetParameter(StoreDescriptor::kReceiverIndex);
|
|
|
|
HValue* key = GetParameter(StoreDescriptor::kNameIndex);
|
|
|
|
HValue* value = GetParameter(StoreDescriptor::kValueIndex);
|
|
|
|
|
|
|
|
return EmitKeyedSloppyArguments(receiver, key, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<Code> KeyedStoreSloppyArgumentsStub::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);
|
2014-12-19 14:51:10 +00:00
|
|
|
BuildCompareNil(GetParameter(0), type, &continuation, kEmbedMapsViaWeakCells);
|
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();
|
|
|
|
{
|
2015-06-08 12:17:58 +00:00
|
|
|
Push(BuildBinaryOperation(state.op(), left, right, Type::String(zone()),
|
|
|
|
right_type, result_type,
|
|
|
|
state.fixed_right_arg(), allocation_mode,
|
|
|
|
state.strength()));
|
2013-10-21 12:42:08 +00:00
|
|
|
}
|
|
|
|
if_leftisstring.Else();
|
|
|
|
{
|
2013-11-20 12:00:57 +00:00
|
|
|
Push(BuildBinaryOperation(
|
2015-06-08 12:17:58 +00:00
|
|
|
state.op(), left, right, left_type, right_type, result_type,
|
|
|
|
state.fixed_right_arg(), allocation_mode, state.strength()));
|
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();
|
|
|
|
{
|
2015-06-08 12:17:58 +00:00
|
|
|
Push(BuildBinaryOperation(state.op(), left, right, left_type,
|
|
|
|
Type::String(zone()), result_type,
|
|
|
|
state.fixed_right_arg(), allocation_mode,
|
|
|
|
state.strength()));
|
2013-10-21 12:42:08 +00:00
|
|
|
}
|
|
|
|
if_rightisstring.Else();
|
|
|
|
{
|
2013-11-20 12:00:57 +00:00
|
|
|
Push(BuildBinaryOperation(
|
2015-06-08 12:17:58 +00:00
|
|
|
state.op(), left, right, left_type, right_type, result_type,
|
|
|
|
state.fixed_right_arg(), allocation_mode, state.strength()));
|
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(
|
2015-06-08 12:17:58 +00:00
|
|
|
state.op(), left, right, left_type, right_type, result_type,
|
|
|
|
state.fixed_right_arg(), allocation_mode, state.strength());
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
2015-06-08 12:17:58 +00:00
|
|
|
return BuildBinaryOperation(state.op(), left, right, left_type, right_type,
|
|
|
|
result_type, state.fixed_right_arg(),
|
|
|
|
allocation_mode, state.strength());
|
2014-01-02 15:31:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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();
|
2014-09-03 10:51:51 +00:00
|
|
|
HParameter* value = GetParameter(StoreDescriptor::kValueIndex);
|
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.
|
2015-02-02 17:56:29 +00:00
|
|
|
HParameter* proxy = GetParameter(StoreDescriptor::kReceiverIndex);
|
|
|
|
HValue* proxy_map =
|
|
|
|
Add<HLoadNamedField>(proxy, nullptr, HObjectAccess::ForMap());
|
|
|
|
HValue* global =
|
|
|
|
Add<HLoadNamedField>(proxy_map, nullptr, HObjectAccess::ForPrototype());
|
2015-04-27 14:01:15 +00:00
|
|
|
HValue* map_cell = Add<HConstant>(isolate()->factory()->NewWeakCell(
|
|
|
|
StoreGlobalStub::global_map_placeholder(isolate())));
|
|
|
|
HValue* expected_map = Add<HLoadNamedField>(
|
|
|
|
map_cell, nullptr, HObjectAccess::ForWeakCellValue());
|
2015-02-02 17:56:29 +00:00
|
|
|
HValue* map =
|
|
|
|
Add<HLoadNamedField>(global, nullptr, HObjectAccess::ForMap());
|
|
|
|
IfBuilder map_check(this);
|
|
|
|
map_check.IfNot<HCompareObjectEqAndBranch>(expected_map, map);
|
2015-02-05 14:51:45 +00:00
|
|
|
map_check.ThenDeopt(Deoptimizer::kUnknownMap);
|
2015-02-02 17:56:29 +00:00
|
|
|
map_check.End();
|
2014-03-10 12:23:05 +00:00
|
|
|
}
|
2013-07-05 10:40:14 +00:00
|
|
|
|
2015-02-03 11:26:52 +00:00
|
|
|
HValue* weak_cell = Add<HConstant>(isolate()->factory()->NewWeakCell(
|
|
|
|
StoreGlobalStub::property_cell_placeholder(isolate())));
|
|
|
|
HValue* cell = Add<HLoadNamedField>(weak_cell, nullptr,
|
|
|
|
HObjectAccess::ForWeakCellValue());
|
2015-03-17 13:27:25 +00:00
|
|
|
Add<HCheckHeapObject>(cell);
|
2015-03-18 12:54:02 +00:00
|
|
|
HObjectAccess access = HObjectAccess::ForPropertyCellValue();
|
2015-04-27 14:01:15 +00:00
|
|
|
// Load the payload of the global parameter cell. A hole indicates that the
|
|
|
|
// cell has been invalidated and that the store must be handled by the
|
|
|
|
// runtime.
|
2014-12-15 04:33:05 +00:00
|
|
|
HValue* cell_contents = Add<HLoadNamedField>(cell, nullptr, access);
|
2013-07-05 10:34:02 +00:00
|
|
|
|
2015-04-27 14:01:15 +00:00
|
|
|
auto cell_type = stub->cell_type();
|
|
|
|
if (cell_type == PropertyCellType::kConstant ||
|
|
|
|
cell_type == PropertyCellType::kUndefined) {
|
|
|
|
// This is always valid for all states a cell can be in.
|
2013-07-22 14:15:58 +00:00
|
|
|
IfBuilder builder(this);
|
|
|
|
builder.If<HCompareObjectEqAndBranch>(cell_contents, value);
|
|
|
|
builder.Then();
|
2015-02-05 14:51:45 +00:00
|
|
|
builder.ElseDeopt(
|
|
|
|
Deoptimizer::kUnexpectedCellContentsInConstantGlobalStore);
|
2013-07-22 14:15:58 +00:00
|
|
|
builder.End();
|
|
|
|
} else {
|
2013-07-05 10:34:02 +00:00
|
|
|
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();
|
2015-02-05 14:51:45 +00:00
|
|
|
builder.Deopt(Deoptimizer::kUnexpectedCellContentsInGlobalStore);
|
2013-07-05 10:34:02 +00:00
|
|
|
builder.Else();
|
2015-04-27 14:01:15 +00:00
|
|
|
// When dealing with constant types, the type may be allowed to change, as
|
|
|
|
// long as optimized code remains valid.
|
|
|
|
if (cell_type == PropertyCellType::kConstantType) {
|
|
|
|
switch (stub->constant_type()) {
|
|
|
|
case PropertyCellConstantType::kSmi:
|
|
|
|
access = access.WithRepresentation(Representation::Smi());
|
|
|
|
break;
|
|
|
|
case PropertyCellConstantType::kStableMap: {
|
|
|
|
// It is sufficient here to check that the value and cell contents
|
|
|
|
// have identical maps, no matter if they are stable or not or if they
|
|
|
|
// are the maps that were originally in the cell or not. If optimized
|
|
|
|
// code will deopt when a cell has a unstable map and if it has a
|
|
|
|
// dependency on a stable map, it will deopt if the map destabilizes.
|
|
|
|
Add<HCheckHeapObject>(value);
|
|
|
|
Add<HCheckHeapObject>(cell_contents);
|
|
|
|
HValue* expected_map = Add<HLoadNamedField>(cell_contents, nullptr,
|
|
|
|
HObjectAccess::ForMap());
|
|
|
|
HValue* map =
|
|
|
|
Add<HLoadNamedField>(value, nullptr, HObjectAccess::ForMap());
|
|
|
|
IfBuilder map_check(this);
|
|
|
|
map_check.IfNot<HCompareObjectEqAndBranch>(expected_map, map);
|
|
|
|
map_check.ThenDeopt(Deoptimizer::kUnknownMap);
|
|
|
|
map_check.End();
|
|
|
|
access = access.WithRepresentation(Representation::HeapObject());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-03-18 11:43:51 +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
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-07-13 09:18:44 +00:00
|
|
|
template <>
|
|
|
|
HValue* CodeStubGraphBuilder<LoadGlobalViaContextStub>::BuildCodeStub() {
|
|
|
|
LoadGlobalViaContextStub* stub = casted_stub();
|
|
|
|
int depth_value = stub->depth();
|
|
|
|
HValue* depth = GetParameter(0);
|
|
|
|
HValue* slot_index = GetParameter(1);
|
|
|
|
HValue* name = GetParameter(2);
|
|
|
|
|
|
|
|
// Choose between dynamic or static context script fetching versions.
|
|
|
|
depth = depth_value < LoadGlobalViaContextStub::kDynamicDepth
|
|
|
|
? nullptr
|
|
|
|
: AddUncasted<HForceRepresentation>(depth, Representation::Smi());
|
|
|
|
slot_index =
|
|
|
|
AddUncasted<HForceRepresentation>(slot_index, Representation::Smi());
|
|
|
|
|
|
|
|
HValue* script_context = BuildGetParentContext(depth, depth_value);
|
|
|
|
HValue* cell =
|
|
|
|
Add<HLoadKeyed>(script_context, slot_index, nullptr, FAST_ELEMENTS);
|
|
|
|
|
|
|
|
HValue* value = Add<HLoadNamedField>(cell, nullptr,
|
|
|
|
HObjectAccess::ForPropertyCellValue());
|
|
|
|
|
|
|
|
IfBuilder builder(this);
|
|
|
|
HValue* hole_value = graph()->GetConstantHole();
|
|
|
|
builder.IfNot<HCompareObjectEqAndBranch, HValue*>(value, hole_value);
|
|
|
|
builder.Then();
|
|
|
|
{ Push(value); }
|
|
|
|
builder.Else();
|
|
|
|
{
|
|
|
|
Add<HPushArguments>(script_context, slot_index, name);
|
|
|
|
Push(Add<HCallRuntime>(
|
|
|
|
isolate()->factory()->empty_string(),
|
|
|
|
Runtime::FunctionForId(Runtime::kLoadGlobalViaContext), 3));
|
|
|
|
}
|
|
|
|
builder.End();
|
|
|
|
return Pop();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<Code> LoadGlobalViaContextStub::GenerateCode() {
|
|
|
|
return DoGenerateCode(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <>
|
|
|
|
HValue* CodeStubGraphBuilder<StoreGlobalViaContextStub>::BuildCodeStub() {
|
|
|
|
StoreGlobalViaContextStub* stub = casted_stub();
|
|
|
|
int depth_value = stub->depth();
|
|
|
|
HValue* depth = GetParameter(0);
|
|
|
|
HValue* slot_index = GetParameter(1);
|
|
|
|
HValue* name = GetParameter(2);
|
|
|
|
HValue* value = GetParameter(3);
|
|
|
|
|
|
|
|
// Choose between dynamic or static context script fetching versions.
|
|
|
|
depth = depth_value < StoreGlobalViaContextStub::kDynamicDepth
|
|
|
|
? nullptr
|
|
|
|
: AddUncasted<HForceRepresentation>(depth, Representation::Smi());
|
|
|
|
slot_index =
|
|
|
|
AddUncasted<HForceRepresentation>(slot_index, Representation::Smi());
|
|
|
|
|
|
|
|
HValue* script_context = BuildGetParentContext(depth, depth_value);
|
|
|
|
HValue* cell =
|
|
|
|
Add<HLoadKeyed>(script_context, slot_index, nullptr, FAST_ELEMENTS);
|
|
|
|
|
|
|
|
// Fast case that requires storing to cell.
|
|
|
|
HIfContinuation if_fast_store_continuation(graph()->CreateBasicBlock(),
|
|
|
|
graph()->CreateBasicBlock());
|
|
|
|
|
|
|
|
// Fast case that does not require storing to cell.
|
|
|
|
HIfContinuation if_fast_no_store_continuation(graph()->CreateBasicBlock(),
|
|
|
|
graph()->CreateBasicBlock());
|
|
|
|
|
|
|
|
// This stub does the same as StoreGlobalStub but in a dynamic manner.
|
|
|
|
|
|
|
|
HValue* cell_contents = Add<HLoadNamedField>(
|
|
|
|
cell, nullptr, HObjectAccess::ForPropertyCellValue());
|
|
|
|
|
|
|
|
IfBuilder if_hole(this);
|
|
|
|
HValue* hole_value = graph()->GetConstantHole();
|
|
|
|
if_hole.IfNot<HCompareObjectEqAndBranch, HValue*>(cell_contents, hole_value);
|
|
|
|
if_hole.Then();
|
|
|
|
{
|
|
|
|
HValue* details = Add<HLoadNamedField>(
|
|
|
|
cell, nullptr, HObjectAccess::ForPropertyCellDetails());
|
|
|
|
HValue* cell_type =
|
|
|
|
BuildDecodeField<PropertyDetails::PropertyCellTypeField>(details);
|
|
|
|
|
|
|
|
// The code below relies on this.
|
|
|
|
STATIC_ASSERT(PropertyCellType::kUndefined < PropertyCellType::kConstant);
|
|
|
|
STATIC_ASSERT(PropertyCellType::kConstant <
|
|
|
|
PropertyCellType::kConstantType);
|
|
|
|
STATIC_ASSERT(PropertyCellType::kConstant < PropertyCellType::kMutable);
|
|
|
|
|
|
|
|
// Handle all cell type cases.
|
|
|
|
IfBuilder if_not_const(this);
|
|
|
|
|
|
|
|
int cell_type_constant = static_cast<int>(PropertyCellType::kConstant);
|
|
|
|
if_not_const.If<HCompareNumericAndBranch, HValue*>(
|
|
|
|
cell_type, Add<HConstant>(cell_type_constant), Token::GT);
|
|
|
|
if_not_const.Then();
|
|
|
|
{
|
|
|
|
// kConstantType or kMutable.
|
|
|
|
IfBuilder if_const_type(this);
|
|
|
|
int cell_type_constant_type =
|
|
|
|
static_cast<int>(PropertyCellType::kConstantType);
|
|
|
|
if_const_type.If<HCompareNumericAndBranch, HValue*>(
|
|
|
|
cell_type, Add<HConstant>(cell_type_constant_type), Token::EQ);
|
|
|
|
if_const_type.Then();
|
|
|
|
{
|
|
|
|
// Check that either both value and cell_contents are smi or
|
|
|
|
// both have the same map.
|
|
|
|
IfBuilder if_cell_is_smi(this);
|
|
|
|
if_cell_is_smi.If<HIsSmiAndBranch>(cell_contents);
|
|
|
|
if_cell_is_smi.Then();
|
|
|
|
{
|
|
|
|
IfBuilder if_value_is_smi(this);
|
|
|
|
if_value_is_smi.If<HIsSmiAndBranch>(value);
|
|
|
|
if_value_is_smi.Then();
|
|
|
|
{
|
|
|
|
// Both cell_contents and value are smis, do store.
|
|
|
|
}
|
|
|
|
if_value_is_smi.Else(); // Slow case.
|
|
|
|
if_value_is_smi.JoinContinuation(&if_fast_store_continuation);
|
|
|
|
}
|
|
|
|
if_cell_is_smi.Else();
|
|
|
|
{
|
|
|
|
IfBuilder if_value_is_heap_object(this);
|
|
|
|
if_value_is_heap_object.IfNot<HIsSmiAndBranch>(value);
|
|
|
|
if_value_is_heap_object.Then();
|
|
|
|
{
|
|
|
|
// Both cell_contents and value are heap objects, do store.
|
|
|
|
HValue* expected_map = Add<HLoadNamedField>(
|
|
|
|
cell_contents, nullptr, HObjectAccess::ForMap());
|
|
|
|
HValue* map =
|
|
|
|
Add<HLoadNamedField>(value, nullptr, HObjectAccess::ForMap());
|
|
|
|
IfBuilder map_check(this);
|
|
|
|
map_check.If<HCompareObjectEqAndBranch>(expected_map, map);
|
|
|
|
map_check.Then();
|
|
|
|
map_check.Else(); // Slow case.
|
|
|
|
map_check.JoinContinuation(&if_fast_store_continuation);
|
|
|
|
|
|
|
|
// The accessor case is handled by the map check above, since
|
|
|
|
// the value must not have a AccessorPair map.
|
|
|
|
}
|
|
|
|
if_value_is_heap_object.Else(); // Slow case.
|
|
|
|
if_value_is_heap_object.JoinContinuation(&if_fast_store_continuation);
|
|
|
|
}
|
|
|
|
if_cell_is_smi.EndUnreachable();
|
|
|
|
}
|
|
|
|
if_const_type.Else();
|
|
|
|
{
|
|
|
|
// Check that the property kind is kData.
|
|
|
|
HValue* kind = BuildDecodeField<PropertyDetails::KindField>(details);
|
|
|
|
HValue* data_kind_value = Add<HConstant>(kData);
|
|
|
|
|
|
|
|
IfBuilder builder(this);
|
|
|
|
builder.If<HCompareNumericAndBranch, HValue*>(kind, data_kind_value,
|
|
|
|
Token::EQ);
|
|
|
|
builder.Then();
|
|
|
|
builder.Else(); // Slow case.
|
|
|
|
builder.JoinContinuation(&if_fast_store_continuation);
|
|
|
|
}
|
|
|
|
if_const_type.EndUnreachable();
|
|
|
|
}
|
|
|
|
if_not_const.Else();
|
|
|
|
{
|
|
|
|
// kUndefined or kConstant, just check that the value matches.
|
|
|
|
IfBuilder builder(this);
|
|
|
|
builder.If<HCompareObjectEqAndBranch>(cell_contents, value);
|
|
|
|
builder.Then();
|
|
|
|
builder.Else(); // Slow case.
|
|
|
|
builder.JoinContinuation(&if_fast_no_store_continuation);
|
|
|
|
}
|
|
|
|
if_not_const.EndUnreachable();
|
|
|
|
}
|
|
|
|
if_hole.Else(); // Slow case.
|
|
|
|
if_hole.JoinContinuation(&if_fast_store_continuation);
|
|
|
|
|
|
|
|
// Do store for fast case.
|
|
|
|
IfBuilder if_fast_store(this, &if_fast_store_continuation);
|
|
|
|
if_fast_store.Then();
|
|
|
|
{
|
|
|
|
// All checks are done, store the value to the cell.
|
|
|
|
Add<HStoreNamedField>(cell, HObjectAccess::ForPropertyCellValue(), value);
|
|
|
|
}
|
|
|
|
if_fast_store.Else();
|
|
|
|
if_fast_store.JoinContinuation(&if_fast_no_store_continuation);
|
|
|
|
|
|
|
|
// Bailout to runtime call for slow case.
|
|
|
|
IfBuilder if_no_fast_store(this, &if_fast_no_store_continuation);
|
|
|
|
if_no_fast_store.Then();
|
|
|
|
{
|
|
|
|
// Nothing else to do.
|
|
|
|
}
|
|
|
|
if_no_fast_store.Else();
|
|
|
|
{
|
|
|
|
// Slow case, call runtime.
|
|
|
|
HInstruction* lang_mode = Add<HConstant>(casted_stub()->language_mode());
|
|
|
|
Add<HPushArguments>(script_context, slot_index, name, value);
|
|
|
|
Add<HPushArguments>(lang_mode);
|
|
|
|
Add<HCallRuntime>(isolate()->factory()->empty_string(),
|
|
|
|
Runtime::FunctionForId(Runtime::kStoreGlobalViaContext),
|
|
|
|
5);
|
|
|
|
}
|
|
|
|
if_no_fast_store.End();
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<Code> StoreGlobalViaContextStub::GenerateCode() {
|
|
|
|
return DoGenerateCode(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <>
|
2013-07-17 11:37:20 +00:00
|
|
|
HValue* CodeStubGraphBuilder<ElementsTransitionAndStoreStub>::BuildCodeStub() {
|
2015-07-22 12:37:14 +00:00
|
|
|
HValue* object = GetParameter(StoreTransitionDescriptor::kReceiverIndex);
|
|
|
|
HValue* key = GetParameter(StoreTransitionDescriptor::kNameIndex);
|
|
|
|
HValue* value = GetParameter(StoreTransitionDescriptor::kValueIndex);
|
|
|
|
HValue* map = GetParameter(StoreTransitionDescriptor::kMapIndex);
|
2013-07-17 11:37:20 +00:00
|
|
|
|
|
|
|
if (FLAG_trace_elements_transitions) {
|
|
|
|
// Tracing elements transitions is the job of the runtime.
|
2015-02-05 14:51:45 +00:00
|
|
|
Add<HDeoptimize>(Deoptimizer::kTracingElementsTransitions,
|
|
|
|
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);
|
|
|
|
|
2015-06-26 09:07:30 +00:00
|
|
|
BuildInstallOptimizedCode(js_function, native_context, code_object, literals);
|
|
|
|
|
|
|
|
// The builder continues in the "then" after this function.
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CodeStubGraphBuilderBase::BuildInstallOptimizedCode(HValue* js_function,
|
|
|
|
HValue* native_context,
|
|
|
|
HValue* code_object,
|
|
|
|
HValue* literals) {
|
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);
|
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();
|
2015-06-26 09:07:30 +00:00
|
|
|
Factory* factory = isolate()->factory();
|
2013-08-27 11:55:08 +00:00
|
|
|
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());
|
2015-07-22 11:46:04 +00:00
|
|
|
// The {optimized_map} points to fixed array of 4-element entries:
|
|
|
|
// (native context, optimized code, literals, ast-id).
|
|
|
|
// Iterate through the {optimized_map} backwards. 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) { ... }
|
2014-03-12 13:29:42 +00:00
|
|
|
HValue* first_entry_index =
|
|
|
|
Add<HConstant>(SharedFunctionInfo::kEntriesStart);
|
2015-07-22 11:46:04 +00:00
|
|
|
HValue* shared_function_entry_length =
|
|
|
|
Add<HConstant>(SharedFunctionInfo::kEntryLength);
|
|
|
|
LoopBuilder loop_builder(this, context(), LoopBuilder::kPostDecrement,
|
|
|
|
shared_function_entry_length);
|
|
|
|
HValue* array_length = Add<HLoadNamedField>(
|
|
|
|
optimized_map, nullptr, HObjectAccess::ForFixedArrayLength());
|
|
|
|
HValue* start_pos =
|
|
|
|
AddUncasted<HSub>(array_length, shared_function_entry_length);
|
|
|
|
HValue* slot_iterator =
|
|
|
|
loop_builder.BeginBody(start_pos, first_entry_index, Token::GTE);
|
2013-08-27 11:55:08 +00:00
|
|
|
{
|
2015-07-22 11:46:04 +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();
|
|
|
|
}
|
|
|
|
loop_builder.EndBody();
|
|
|
|
|
|
|
|
// If {slot_iterator} is less than the first entry index, then we failed to
|
|
|
|
// find a context-dependent code and try context-independent code next.
|
|
|
|
IfBuilder no_optimized_code_check(this);
|
|
|
|
no_optimized_code_check.If<HCompareNumericAndBranch>(
|
|
|
|
slot_iterator, first_entry_index, Token::LT);
|
|
|
|
no_optimized_code_check.Then();
|
|
|
|
{
|
|
|
|
IfBuilder shared_code_check(this);
|
|
|
|
HValue* shared_code =
|
|
|
|
Add<HLoadNamedField>(optimized_map, nullptr,
|
|
|
|
HObjectAccess::ForOptimizedCodeMapSharedCode());
|
|
|
|
shared_code_check.IfNot<HCompareObjectEqAndBranch>(
|
|
|
|
shared_code, graph()->GetConstantUndefined());
|
|
|
|
shared_code_check.Then();
|
2013-08-27 11:55:08 +00:00
|
|
|
{
|
2015-07-22 11:46:04 +00:00
|
|
|
// Store the context-independent optimized code.
|
|
|
|
HValue* literals = Add<HConstant>(factory->empty_fixed_array());
|
|
|
|
BuildInstallOptimizedCode(js_function, native_context, shared_code,
|
|
|
|
literals);
|
2013-08-27 11:55:08 +00:00
|
|
|
}
|
2015-07-22 11:46:04 +00:00
|
|
|
shared_code_check.Else();
|
2014-03-12 13:29:42 +00:00
|
|
|
{
|
2015-07-22 11:46:04 +00:00
|
|
|
// Store the unoptimized code.
|
|
|
|
BuildInstallCode(js_function, shared_info);
|
2014-03-12 13:29:42 +00:00
|
|
|
}
|
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);
|
|
|
|
|
2015-02-04 09:34:05 +00:00
|
|
|
int map_index = Context::FunctionMapIndex(casted_stub()->language_mode(),
|
2014-11-25 13:21:57 +00:00
|
|
|
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());
|
|
|
|
|
2015-06-25 09:44:58 +00:00
|
|
|
// 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.
|
|
|
|
BuildInstallFromOptimizedCodeMap(js_function, shared_info, native_context);
|
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);
|
|
|
|
|
2015-06-30 15:24:27 +00:00
|
|
|
return BuildUncheckedDictionaryElementLoad(receiver, elements, key, hash,
|
|
|
|
casted_stub()->language_mode());
|
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:
|
2015-03-23 17:30:38 +00:00
|
|
|
explicit CodeStubGraphBuilder(CompilationInfo* info)
|
2014-12-12 12:36:03 +00:00
|
|
|
: 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);
|
|
|
|
|
2015-06-30 15:24:27 +00:00
|
|
|
Push(BuildUncheckedDictionaryElementLoad(receiver, elements, key, hash,
|
|
|
|
casted_stub()->language_mode()));
|
2014-06-12 09:58:10 +00:00
|
|
|
}
|
|
|
|
kind_if.Else();
|
|
|
|
|
2015-07-02 14:38:37 +00:00
|
|
|
// The SLOW_SLOPPY_ARGUMENTS_ELEMENTS check generates a "kind_if.Then"
|
|
|
|
STATIC_ASSERT(FAST_SLOPPY_ARGUMENTS_ELEMENTS <
|
|
|
|
SLOW_SLOPPY_ARGUMENTS_ELEMENTS);
|
2014-06-12 09:58:10 +00:00
|
|
|
BuildElementsKindLimitCheck(&kind_if, bit_field2,
|
2015-07-02 14:38:37 +00:00
|
|
|
SLOW_SLOPPY_ARGUMENTS_ELEMENTS);
|
2014-06-12 09:58:10 +00:00
|
|
|
// Non-strict elements are not handled.
|
2015-02-05 14:51:45 +00:00
|
|
|
Add<HDeoptimize>(Deoptimizer::kNonStrictElementsInKeyedLoadGenericStub,
|
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);
|
|
|
|
|
2015-02-05 14:51:45 +00:00
|
|
|
kind_if.ElseDeopt(
|
|
|
|
Deoptimizer::kElementsKindUnhandledInKeyedLoadGenericStub);
|
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));
|
|
|
|
|
2015-06-30 15:24:27 +00:00
|
|
|
HValue* value = BuildUncheckedDictionaryElementLoad(
|
|
|
|
receiver, properties, key, hash, casted_stub()->language_mode());
|
2014-06-12 09:58:10 +00:00
|
|
|
Push(value);
|
|
|
|
}
|
|
|
|
if_dict_properties.Else();
|
|
|
|
{
|
2015-01-30 09:17:01 +00:00
|
|
|
// TODO(dcarney): don't use keyed lookup cache, but convert to use
|
|
|
|
// megamorphic stub cache.
|
|
|
|
UNREACHABLE();
|
2014-06-12 09:58:10 +00:00
|
|
|
// 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.
|
2015-06-19 19:00:45 +00:00
|
|
|
Add<HPushArguments>(receiver, key);
|
2014-07-07 16:24:51 +00:00
|
|
|
Push(Add<HCallRuntime>(
|
|
|
|
isolate()->factory()->empty_string(),
|
2015-06-30 15:24:27 +00:00
|
|
|
Runtime::FunctionForId(is_strong(casted_stub()->language_mode())
|
|
|
|
? Runtime::kKeyedGetPropertyStrong
|
|
|
|
: Runtime::kKeyedGetProperty),
|
|
|
|
2));
|
2014-07-07 16:24:51 +00:00
|
|
|
}
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2015-06-01 22:46:54 +00:00
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|