2012-12-18 16:25:45 +00:00
|
|
|
// Copyright 2012 the V8 project authors. All rights reserved.
|
|
|
|
// Redistribution and use in source and binary forms, with or without
|
|
|
|
// modification, are permitted provided that the following conditions are
|
|
|
|
// met:
|
|
|
|
//
|
|
|
|
// * Redistributions of source code must retain the above copyright
|
|
|
|
// notice, this list of conditions and the following disclaimer.
|
|
|
|
// * Redistributions in binary form must reproduce the above
|
|
|
|
// copyright notice, this list of conditions and the following
|
|
|
|
// disclaimer in the documentation and/or other materials provided
|
|
|
|
// with the distribution.
|
|
|
|
// * Neither the name of Google Inc. nor the names of its
|
|
|
|
// contributors may be used to endorse or promote products derived
|
|
|
|
// from this software without specific prior written permission.
|
|
|
|
//
|
|
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
#include "v8.h"
|
|
|
|
|
|
|
|
#include "code-stubs.h"
|
|
|
|
#include "hydrogen.h"
|
|
|
|
#include "lithium.h"
|
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
|
|
|
|
|
2013-01-28 13:24:41 +00:00
|
|
|
static LChunk* OptimizeGraph(HGraph* graph) {
|
2013-02-25 14:46:09 +00:00
|
|
|
Isolate* isolate = graph->isolate();
|
2013-01-28 13:24:41 +00:00
|
|
|
AssertNoAllocation no_gc;
|
2013-02-25 14:46:09 +00:00
|
|
|
NoHandleAllocation no_handles(isolate);
|
2013-03-13 16:13:05 +00:00
|
|
|
HandleDereferenceGuard no_deref(isolate, HandleDereferenceGuard::DISALLOW);
|
2013-01-28 13:24:41 +00:00
|
|
|
|
|
|
|
ASSERT(graph != NULL);
|
|
|
|
SmartArrayPointer<char> bailout_reason;
|
|
|
|
if (!graph->Optimize(&bailout_reason)) {
|
|
|
|
FATAL(bailout_reason.is_empty() ? "unknown" : *bailout_reason);
|
|
|
|
}
|
2012-12-18 16:25:45 +00:00
|
|
|
LChunk* chunk = LChunk::NewChunk(graph);
|
2013-01-28 13:24:41 +00:00
|
|
|
if (chunk == NULL) {
|
|
|
|
FATAL(graph->info()->bailout_reason());
|
|
|
|
}
|
|
|
|
return chunk;
|
2012-12-18 16:25:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class CodeStubGraphBuilderBase : public HGraphBuilder {
|
|
|
|
public:
|
|
|
|
CodeStubGraphBuilderBase(Isolate* isolate, HydrogenCodeStub* stub)
|
2013-03-08 21:07:55 +00:00
|
|
|
: HGraphBuilder(&info_),
|
|
|
|
arguments_length_(NULL),
|
|
|
|
info_(stub, isolate),
|
|
|
|
context_(NULL) {
|
2013-04-18 20:37:27 +00:00
|
|
|
descriptor_ = stub->GetInterfaceDescriptor(isolate);
|
2013-02-25 14:03:09 +00:00
|
|
|
parameters_.Reset(new HParameter*[descriptor_->register_param_count_]);
|
|
|
|
}
|
2012-12-18 16:25:45 +00:00
|
|
|
virtual bool BuildGraph();
|
|
|
|
|
|
|
|
protected:
|
2013-03-08 21:07:55 +00:00
|
|
|
virtual HValue* BuildCodeStub() = 0;
|
|
|
|
HParameter* GetParameter(int parameter) {
|
|
|
|
ASSERT(parameter < descriptor_->register_param_count_);
|
|
|
|
return parameters_[parameter];
|
|
|
|
}
|
|
|
|
HValue* GetArgumentsLength() {
|
|
|
|
// This is initialized in BuildGraph()
|
|
|
|
ASSERT(arguments_length_ != NULL);
|
|
|
|
return arguments_length_;
|
|
|
|
}
|
2013-02-04 12:01:59 +00:00
|
|
|
CompilationInfo* info() { return &info_; }
|
2012-12-18 16:25:45 +00:00
|
|
|
HydrogenCodeStub* stub() { return info_.code_stub(); }
|
2012-12-28 16:25:38 +00:00
|
|
|
HContext* context() { return context_; }
|
2013-02-04 12:01:59 +00:00
|
|
|
Isolate* isolate() { return info_.isolate(); }
|
2012-12-18 16:25:45 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
SmartArrayPointer<HParameter*> parameters_;
|
2013-03-08 21:07:55 +00:00
|
|
|
HValue* arguments_length_;
|
2012-12-18 16:25:45 +00:00
|
|
|
CompilationInfoWithZone info_;
|
2013-02-25 14:03:09 +00:00
|
|
|
CodeStubInterfaceDescriptor* 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();
|
|
|
|
|
2012-12-18 16:25:45 +00:00
|
|
|
if (FLAG_trace_hydrogen) {
|
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);
|
2013-03-06 07:25:46 +00:00
|
|
|
isolate()->GetHTracer()->TraceCompilation(&info_);
|
2012-12-18 16:25:45 +00:00
|
|
|
}
|
|
|
|
|
2013-02-25 14:03:09 +00:00
|
|
|
Zone* zone = this->zone();
|
2013-03-08 21:07:55 +00:00
|
|
|
int param_count = descriptor_->register_param_count_;
|
|
|
|
HEnvironment* start_environment = graph()->start_environment();
|
2013-04-17 14:11:39 +00:00
|
|
|
HBasicBlock* next_block = CreateBasicBlock(start_environment);
|
2013-02-25 14:03:09 +00:00
|
|
|
current_block()->Goto(next_block);
|
|
|
|
next_block->SetJoinId(BailoutId::StubEntry());
|
|
|
|
set_current_block(next_block);
|
|
|
|
|
|
|
|
HConstant* undefined_constant = new(zone) HConstant(
|
2013-02-04 12:01:59 +00:00
|
|
|
isolate()->factory()->undefined_value(), Representation::Tagged());
|
|
|
|
AddInstruction(undefined_constant);
|
|
|
|
graph()->set_undefined_constant(undefined_constant);
|
|
|
|
|
2013-02-25 14:03:09 +00:00
|
|
|
for (int i = 0; i < param_count; ++i) {
|
2013-02-05 08:09:32 +00:00
|
|
|
HParameter* param =
|
|
|
|
new(zone) HParameter(i, HParameter::REGISTER_PARAMETER);
|
2012-12-18 16:25:45 +00:00
|
|
|
AddInstruction(param);
|
2013-02-25 14:03:09 +00:00
|
|
|
start_environment->Bind(i, param);
|
2012-12-18 16:25:45 +00:00
|
|
|
parameters_[i] = param;
|
|
|
|
}
|
2013-02-04 12:01:59 +00:00
|
|
|
|
2013-03-08 21:07:55 +00:00
|
|
|
HInstruction* stack_parameter_count;
|
|
|
|
if (descriptor_->stack_parameter_count_ != NULL) {
|
|
|
|
ASSERT(descriptor_->environment_length() == (param_count + 1));
|
|
|
|
stack_parameter_count = new(zone) HParameter(param_count,
|
2013-04-02 11:28:01 +00:00
|
|
|
HParameter::REGISTER_PARAMETER,
|
|
|
|
Representation::Integer32());
|
2013-03-08 21:07:55 +00:00
|
|
|
// it's essential to bind this value to the environment in case of deopt
|
|
|
|
start_environment->Bind(param_count, stack_parameter_count);
|
|
|
|
AddInstruction(stack_parameter_count);
|
2013-03-12 15:37:23 +00:00
|
|
|
arguments_length_ = stack_parameter_count;
|
2013-03-08 21:07:55 +00:00
|
|
|
} else {
|
|
|
|
ASSERT(descriptor_->environment_length() == param_count);
|
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-02-04 12:01:59 +00:00
|
|
|
context_ = new(zone) HContext();
|
|
|
|
AddInstruction(context_);
|
2013-03-08 21:07:55 +00:00
|
|
|
start_environment->BindContext(context_);
|
2013-02-04 12:01:59 +00:00
|
|
|
|
2012-12-18 16:25:45 +00:00
|
|
|
AddSimulate(BailoutId::StubEntry());
|
|
|
|
|
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
|
|
|
|
// arguments above
|
|
|
|
HInstruction* stack_pop_count = stack_parameter_count;
|
|
|
|
if (descriptor_->function_mode_ == JS_FUNCTION_STUB_MODE) {
|
|
|
|
HInstruction* amount = graph()->GetConstant1();
|
|
|
|
stack_pop_count = AddInstruction(
|
|
|
|
HAdd::New(zone, context_, stack_parameter_count, amount));
|
|
|
|
stack_pop_count->ChangeRepresentation(Representation::Integer32());
|
|
|
|
stack_pop_count->ClearFlag(HValue::kCanOverflow);
|
|
|
|
}
|
|
|
|
|
2013-04-24 11:32:17 +00:00
|
|
|
if (!current_block()->IsFinished()) {
|
|
|
|
HReturn* hreturn_instruction = new(zone) HReturn(return_value,
|
|
|
|
context_,
|
|
|
|
stack_pop_count);
|
|
|
|
current_block()->Finish(hreturn_instruction);
|
|
|
|
}
|
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:
|
|
|
|
explicit CodeStubGraphBuilder(Stub* stub)
|
|
|
|
: CodeStubGraphBuilderBase(Isolate::Current(), stub) {}
|
|
|
|
|
|
|
|
protected:
|
2013-04-18 20:37:27 +00:00
|
|
|
virtual HValue* BuildCodeStub() {
|
|
|
|
if (casted_stub()->IsMiss()) {
|
|
|
|
return BuildCodeInitializedStub();
|
|
|
|
} else {
|
|
|
|
return BuildCodeUninitializedStub();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
|
|
|
builder.ElseDeopt();
|
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()); }
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-04-18 20:37:27 +00:00
|
|
|
Handle<Code> HydrogenCodeStub::GenerateLightweightMissCode(Isolate* isolate) {
|
|
|
|
Factory* factory = isolate->factory();
|
|
|
|
|
|
|
|
// Generate the new code.
|
|
|
|
MacroAssembler masm(isolate, NULL, 256);
|
|
|
|
|
|
|
|
{
|
|
|
|
// Update the static counter each time a new code stub is generated.
|
|
|
|
isolate->counters()->code_stubs()->Increment();
|
|
|
|
|
|
|
|
// Nested stubs are not allowed for leaves.
|
|
|
|
AllowStubCallsScope allow_scope(&masm, false);
|
|
|
|
|
|
|
|
// Generate the code for the stub.
|
|
|
|
masm.set_generating_stub(true);
|
|
|
|
NoCurrentFrameScope scope(&masm);
|
|
|
|
GenerateLightweightMiss(&masm);
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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(),
|
|
|
|
GetStubType(), -1);
|
|
|
|
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>
|
|
|
|
static Handle<Code> DoGenerateCode(Stub* stub) {
|
2013-04-18 20:37:27 +00:00
|
|
|
Isolate* isolate = Isolate::Current();
|
|
|
|
CodeStub::Major major_key =
|
|
|
|
static_cast<HydrogenCodeStub*>(stub)->MajorKey();
|
|
|
|
CodeStubInterfaceDescriptor* descriptor =
|
|
|
|
isolate->code_stub_interface_descriptor(major_key);
|
|
|
|
if (descriptor->register_param_count_ < 0) {
|
|
|
|
stub->InitializeInterfaceDescriptor(isolate, descriptor);
|
|
|
|
}
|
|
|
|
// The miss case without stack parameters can use a light-weight stub to enter
|
|
|
|
// the runtime that is significantly faster than using the standard
|
|
|
|
// stub-failure deopt mechanism.
|
|
|
|
if (stub->IsMiss() && descriptor->stack_parameter_count_ == NULL) {
|
|
|
|
return stub->GenerateLightweightMissCode(isolate);
|
|
|
|
} else {
|
|
|
|
CodeStubGraphBuilder<Stub> builder(stub);
|
|
|
|
LChunk* chunk = OptimizeGraph(builder.CreateGraph());
|
|
|
|
return chunk->Codegen();
|
|
|
|
}
|
2013-03-20 12:01:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-04 17:55:43 +00:00
|
|
|
template <>
|
|
|
|
HValue* CodeStubGraphBuilder<FastCloneShallowArrayStub>::BuildCodeStub() {
|
|
|
|
Zone* zone = this->zone();
|
|
|
|
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();
|
|
|
|
FastCloneShallowArrayStub::Mode mode = casted_stub()->mode();
|
|
|
|
int length = casted_stub()->length();
|
|
|
|
|
|
|
|
HInstruction* boilerplate =
|
|
|
|
AddInstruction(new(zone) HLoadKeyed(GetParameter(0),
|
|
|
|
GetParameter(1),
|
|
|
|
NULL,
|
|
|
|
FAST_ELEMENTS));
|
|
|
|
|
2013-04-22 11:15:43 +00:00
|
|
|
IfBuilder checker(this);
|
|
|
|
checker.IfNot<HCompareObjectEqAndBranch, HValue*>(boilerplate, undefined);
|
|
|
|
checker.Then();
|
2013-04-04 17:55:43 +00:00
|
|
|
|
|
|
|
if (mode == FastCloneShallowArrayStub::CLONE_ANY_ELEMENTS) {
|
|
|
|
HValue* elements =
|
|
|
|
AddInstruction(new(zone) HLoadElements(boilerplate, NULL));
|
|
|
|
|
2013-04-18 10:51:24 +00:00
|
|
|
IfBuilder if_fixed_cow(this);
|
|
|
|
if_fixed_cow.IfCompareMap(elements, factory->fixed_cow_array_map());
|
|
|
|
if_fixed_cow.Then();
|
2013-04-04 17:55:43 +00:00
|
|
|
environment()->Push(BuildCloneShallowArray(context(),
|
|
|
|
boilerplate,
|
|
|
|
alloc_site_mode,
|
|
|
|
FAST_ELEMENTS,
|
|
|
|
0/*copy-on-write*/));
|
2013-04-18 10:51:24 +00:00
|
|
|
if_fixed_cow.Else();
|
2013-04-04 17:55:43 +00:00
|
|
|
|
2013-04-18 10:51:24 +00:00
|
|
|
IfBuilder if_fixed(this);
|
|
|
|
if_fixed.IfCompareMap(elements, factory->fixed_array_map());
|
|
|
|
if_fixed.Then();
|
2013-04-04 17:55:43 +00:00
|
|
|
environment()->Push(BuildCloneShallowArray(context(),
|
|
|
|
boilerplate,
|
|
|
|
alloc_site_mode,
|
|
|
|
FAST_ELEMENTS,
|
|
|
|
length));
|
2013-04-18 10:51:24 +00:00
|
|
|
if_fixed.Else();
|
2013-04-04 17:55:43 +00:00
|
|
|
environment()->Push(BuildCloneShallowArray(context(),
|
|
|
|
boilerplate,
|
|
|
|
alloc_site_mode,
|
|
|
|
FAST_DOUBLE_ELEMENTS,
|
|
|
|
length));
|
|
|
|
} else {
|
|
|
|
ElementsKind elements_kind = casted_stub()->ComputeElementsKind();
|
|
|
|
environment()->Push(BuildCloneShallowArray(context(),
|
|
|
|
boilerplate,
|
|
|
|
alloc_site_mode,
|
|
|
|
elements_kind,
|
|
|
|
length));
|
|
|
|
}
|
|
|
|
|
2013-04-22 11:15:43 +00:00
|
|
|
HValue* result = environment()->Pop();
|
|
|
|
checker.ElseDeopt();
|
|
|
|
return result;
|
2013-04-04 17:55:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<Code> FastCloneShallowArrayStub::GenerateCode() {
|
2013-04-18 20:37:27 +00:00
|
|
|
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-02-26 13:08:08 +00:00
|
|
|
Zone* zone = this->zone();
|
|
|
|
Factory* factory = isolate()->factory();
|
2013-04-22 11:15:43 +00:00
|
|
|
HValue* undefined = graph()->GetConstantUndefined();
|
2013-02-26 13:08:08 +00:00
|
|
|
|
|
|
|
HInstruction* boilerplate =
|
|
|
|
AddInstruction(new(zone) HLoadKeyed(GetParameter(0),
|
|
|
|
GetParameter(1),
|
|
|
|
NULL,
|
|
|
|
FAST_ELEMENTS));
|
|
|
|
|
2013-04-22 11:15:43 +00:00
|
|
|
IfBuilder checker(this);
|
|
|
|
checker.IfNot<HCompareObjectEqAndBranch, HValue*>(boilerplate, undefined);
|
|
|
|
checker.And();
|
2013-02-26 13:08:08 +00:00
|
|
|
|
|
|
|
int size = JSObject::kHeaderSize + casted_stub()->length() * kPointerSize;
|
|
|
|
HValue* boilerplate_size =
|
|
|
|
AddInstruction(new(zone) HInstanceSize(boilerplate));
|
|
|
|
HValue* size_in_words =
|
|
|
|
AddInstruction(new(zone) HConstant(size >> kPointerSizeLog2,
|
|
|
|
Representation::Integer32()));
|
2013-04-22 11:15:43 +00:00
|
|
|
checker.IfCompare(boilerplate_size, size_in_words, Token::EQ);
|
|
|
|
checker.Then();
|
2013-02-26 13:08:08 +00:00
|
|
|
|
|
|
|
HValue* size_in_bytes =
|
|
|
|
AddInstruction(new(zone) HConstant(size, Representation::Integer32()));
|
2013-03-14 08:32:52 +00:00
|
|
|
HAllocate::Flags flags = HAllocate::CAN_ALLOCATE_IN_NEW_SPACE;
|
|
|
|
if (FLAG_pretenure_literals) {
|
|
|
|
flags = static_cast<HAllocate::Flags>(
|
|
|
|
flags | HAllocate::CAN_ALLOCATE_IN_OLD_POINTER_SPACE);
|
|
|
|
}
|
2013-02-26 13:08:08 +00:00
|
|
|
HInstruction* object =
|
|
|
|
AddInstruction(new(zone) HAllocate(context(),
|
|
|
|
size_in_bytes,
|
|
|
|
HType::JSObject(),
|
2013-03-14 08:32:52 +00:00
|
|
|
flags));
|
2013-02-26 13:08:08 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < size; i += kPointerSize) {
|
|
|
|
HInstruction* value =
|
|
|
|
AddInstruction(new(zone) HLoadNamedField(boilerplate, true, i));
|
|
|
|
AddInstruction(new(zone) HStoreNamedField(object,
|
2013-02-28 17:03:34 +00:00
|
|
|
factory->empty_string(),
|
2013-02-26 13:08:08 +00:00
|
|
|
value,
|
|
|
|
true, i));
|
|
|
|
}
|
|
|
|
|
2013-04-22 11:15:43 +00:00
|
|
|
checker.ElseDeopt();
|
2013-03-08 21:07:55 +00:00
|
|
|
return object;
|
2013-02-26 13:08:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<Code> FastCloneShallowObjectStub::GenerateCode() {
|
2013-03-20 12:01:49 +00:00
|
|
|
return DoGenerateCode(this);
|
2013-02-26 13:08:08 +00:00
|
|
|
}
|
|
|
|
|
2013-03-20 12:01:57 +00:00
|
|
|
|
2012-12-18 16:25:45 +00:00
|
|
|
template <>
|
2013-03-08 21:07:55 +00:00
|
|
|
HValue* CodeStubGraphBuilder<KeyedLoadFastElementStub>::BuildCodeStub() {
|
2012-12-18 16:25:45 +00:00
|
|
|
HInstruction* load = BuildUncheckedMonomorphicElementAccess(
|
|
|
|
GetParameter(0), GetParameter(1), NULL, NULL,
|
2013-01-29 15:46:34 +00:00
|
|
|
casted_stub()->is_js_array(), casted_stub()->elements_kind(),
|
2013-03-20 10:37:13 +00:00
|
|
|
false, STANDARD_STORE, Representation::Tagged());
|
2013-03-08 21:07:55 +00:00
|
|
|
return load;
|
2012-12-18 16:25:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<Code> KeyedLoadFastElementStub::GenerateCode() {
|
2013-03-20 12:01:49 +00:00
|
|
|
return DoGenerateCode(this);
|
2012-12-18 16:25:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-20 10:37:13 +00:00
|
|
|
template <>
|
|
|
|
HValue* CodeStubGraphBuilder<KeyedStoreFastElementStub>::BuildCodeStub() {
|
|
|
|
BuildUncheckedMonomorphicElementAccess(
|
|
|
|
GetParameter(0), GetParameter(1), GetParameter(2), NULL,
|
|
|
|
casted_stub()->is_js_array(), casted_stub()->elements_kind(),
|
|
|
|
true, casted_stub()->store_mode(), Representation::Tagged());
|
|
|
|
|
|
|
|
return GetParameter(2);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<Code> KeyedStoreFastElementStub::GenerateCode() {
|
2013-03-20 17:20:48 +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
|
|
|
Zone* zone = this->zone();
|
|
|
|
|
|
|
|
HValue* js_array = GetParameter(0);
|
|
|
|
HValue* map = GetParameter(1);
|
|
|
|
|
|
|
|
info()->MarkAsSavesCallerDoubles();
|
|
|
|
|
|
|
|
AddInstruction(new(zone) HTrapAllocationMemento(js_array));
|
|
|
|
|
|
|
|
HInstruction* array_length =
|
2013-04-03 16:25:24 +00:00
|
|
|
AddInstruction(HLoadNamedField::NewArrayLength(
|
|
|
|
zone, js_array, js_array, HType::Smi()));
|
2013-02-04 12:01:59 +00:00
|
|
|
|
2013-03-20 10:37:13 +00:00
|
|
|
ElementsKind to_kind = casted_stub()->to_kind();
|
|
|
|
BuildNewSpaceArrayCheck(array_length, to_kind);
|
2013-02-04 12:01:59 +00:00
|
|
|
|
2013-04-18 10:51:24 +00:00
|
|
|
IfBuilder if_builder(this);
|
2013-02-04 12:01:59 +00:00
|
|
|
|
2013-04-18 10:51:24 +00:00
|
|
|
if_builder.IfCompare(array_length, graph()->GetConstant0(), Token::EQ);
|
|
|
|
if_builder.Then();
|
2013-02-04 12:01:59 +00:00
|
|
|
|
|
|
|
// Nothing to do, just change the map.
|
|
|
|
|
2013-04-18 10:51:24 +00:00
|
|
|
if_builder.Else();
|
2013-02-04 12:01:59 +00:00
|
|
|
|
|
|
|
HInstruction* elements =
|
|
|
|
AddInstruction(new(zone) HLoadElements(js_array, js_array));
|
|
|
|
|
|
|
|
HInstruction* elements_length =
|
|
|
|
AddInstruction(new(zone) HFixedArrayBaseLength(elements));
|
|
|
|
|
|
|
|
HValue* new_elements =
|
2013-04-05 08:35:40 +00:00
|
|
|
BuildAllocateAndInitializeElements(context(), to_kind, elements_length);
|
2013-02-04 12:01:59 +00:00
|
|
|
|
|
|
|
BuildCopyElements(context(), elements,
|
|
|
|
casted_stub()->from_kind(), new_elements,
|
2013-04-18 10:51:24 +00:00
|
|
|
to_kind, array_length, elements_length);
|
2013-03-20 10:37:13 +00:00
|
|
|
|
|
|
|
Factory* factory = isolate()->factory();
|
2013-02-04 12:01:59 +00:00
|
|
|
|
|
|
|
AddInstruction(new(zone) HStoreNamedField(js_array,
|
2013-02-28 17:03:34 +00:00
|
|
|
factory->elements_field_string(),
|
2013-02-04 12:01:59 +00:00
|
|
|
new_elements, true,
|
|
|
|
JSArray::kElementsOffset));
|
|
|
|
|
|
|
|
if_builder.End();
|
|
|
|
|
2013-02-28 17:03:34 +00:00
|
|
|
AddInstruction(new(zone) HStoreNamedField(js_array, factory->length_string(),
|
2013-02-04 12:01:59 +00:00
|
|
|
map, true, JSArray::kMapOffset));
|
2013-03-08 21:07:55 +00:00
|
|
|
return js_array;
|
2013-02-04 12:01:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-20 17:20:48 +00:00
|
|
|
Handle<Code> TransitionElementsKindStub::GenerateCode() {
|
|
|
|
return DoGenerateCode(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-01 16:06:34 +00:00
|
|
|
template <>
|
2013-03-08 21:07:55 +00:00
|
|
|
HValue* CodeStubGraphBuilder<ArrayNoArgumentConstructorStub>::BuildCodeStub() {
|
2013-03-01 16:06:34 +00:00
|
|
|
HInstruction* deopt = new(zone()) HSoftDeoptimize();
|
|
|
|
AddInstruction(deopt);
|
|
|
|
current_block()->MarkAsDeoptimizing();
|
2013-03-08 21:07:55 +00:00
|
|
|
return GetParameter(0);
|
2013-03-01 16:06:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<Code> ArrayNoArgumentConstructorStub::GenerateCode() {
|
2013-03-20 12:01:49 +00:00
|
|
|
return DoGenerateCode(this);
|
2013-03-01 16:06:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <>
|
2013-03-08 21:07:55 +00:00
|
|
|
HValue* CodeStubGraphBuilder<ArraySingleArgumentConstructorStub>::
|
|
|
|
BuildCodeStub() {
|
2013-03-01 16:06:34 +00:00
|
|
|
HInstruction* deopt = new(zone()) HSoftDeoptimize();
|
|
|
|
AddInstruction(deopt);
|
|
|
|
current_block()->MarkAsDeoptimizing();
|
2013-03-08 21:07:55 +00:00
|
|
|
return GetParameter(0);
|
2013-03-01 16:06:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<Code> ArraySingleArgumentConstructorStub::GenerateCode() {
|
2013-03-20 12:01:49 +00:00
|
|
|
return DoGenerateCode(this);
|
2013-03-01 16:06:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <>
|
2013-03-08 21:07:55 +00:00
|
|
|
HValue* CodeStubGraphBuilder<ArrayNArgumentsConstructorStub>::BuildCodeStub() {
|
2013-03-01 16:06:34 +00:00
|
|
|
HInstruction* deopt = new(zone()) HSoftDeoptimize();
|
|
|
|
AddInstruction(deopt);
|
|
|
|
current_block()->MarkAsDeoptimizing();
|
2013-03-08 21:07:55 +00:00
|
|
|
return GetParameter(0);
|
2013-03-01 16:06:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<Code> ArrayNArgumentsConstructorStub::GenerateCode() {
|
2013-03-20 12:01:49 +00:00
|
|
|
return DoGenerateCode(this);
|
2013-03-01 16:06:34 +00:00
|
|
|
}
|
|
|
|
|
2013-04-24 11:32:17 +00:00
|
|
|
|
|
|
|
template <>
|
|
|
|
HValue* CodeStubGraphBuilder<CompareNilICStub>::BuildCodeUninitializedStub() {
|
|
|
|
CompareNilICStub* stub = casted_stub();
|
|
|
|
HIfContinuation continuation;
|
|
|
|
Handle<Map> sentinel_map(graph()->isolate()->heap()->meta_map());
|
|
|
|
BuildCompareNil(GetParameter(0), stub->GetKind(),
|
|
|
|
stub->GetTypes(), sentinel_map,
|
|
|
|
RelocInfo::kNoPosition, &continuation);
|
|
|
|
IfBuilder if_nil(this, &continuation);
|
|
|
|
if_nil.Then();
|
|
|
|
if (continuation.IsFalseReachable()) {
|
|
|
|
if_nil.Else();
|
|
|
|
if_nil.Return(graph()->GetConstantSmi0());
|
|
|
|
}
|
|
|
|
if_nil.End();
|
|
|
|
return continuation.IsTrueReachable()
|
|
|
|
? graph()->GetConstantSmi1()
|
|
|
|
: graph()->GetConstantUndefined();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<Code> CompareNilICStub::GenerateCode() {
|
|
|
|
return DoGenerateCode(this);
|
|
|
|
}
|
|
|
|
|
2012-12-18 16:25:45 +00:00
|
|
|
} } // namespace v8::internal
|