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-06-03 15:32:22 +00:00
|
|
|
DisallowHeapAllocation no_allocation;
|
|
|
|
DisallowHandleAllocation no_handles;
|
|
|
|
DisallowHandleDereference no_deref;
|
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
|
|
|
|
2013-05-07 21:01:53 +00:00
|
|
|
class ArrayContextChecker {
|
|
|
|
public:
|
|
|
|
ArrayContextChecker(HGraphBuilder* builder, HValue* constructor,
|
|
|
|
HValue* array_function)
|
|
|
|
: checker_(builder) {
|
|
|
|
checker_.If<HCompareObjectEqAndBranch, HValue*>(constructor,
|
|
|
|
array_function);
|
|
|
|
checker_.Then();
|
|
|
|
}
|
|
|
|
|
|
|
|
~ArrayContextChecker() {
|
|
|
|
checker_.ElseDeopt();
|
|
|
|
checker_.End();
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
IfBuilder checker_;
|
|
|
|
};
|
|
|
|
|
2013-06-05 10:43:18 +00:00
|
|
|
enum ArgumentClass {
|
|
|
|
NONE,
|
|
|
|
SINGLE,
|
|
|
|
MULTIPLE
|
|
|
|
};
|
|
|
|
|
|
|
|
HValue* BuildArrayConstructor(ElementsKind kind,
|
2013-06-28 13:16:14 +00:00
|
|
|
ContextCheckMode context_mode,
|
|
|
|
AllocationSiteOverrideMode override_mode,
|
2013-06-05 10:43:18 +00:00
|
|
|
ArgumentClass argument_class);
|
|
|
|
HValue* BuildInternalArrayConstructor(ElementsKind kind,
|
|
|
|
ArgumentClass argument_class);
|
|
|
|
|
2012-12-18 16:25:45 +00:00
|
|
|
private:
|
2013-06-05 10:43:18 +00:00
|
|
|
HValue* BuildArraySingleArgumentConstructor(JSArrayBuilder* builder);
|
|
|
|
HValue* BuildArrayNArgumentsConstructor(JSArrayBuilder* builder,
|
|
|
|
ElementsKind kind);
|
|
|
|
|
2012-12-18 16:25:45 +00:00
|
|
|
SmartArrayPointer<HParameter*> parameters_;
|
2013-03-08 21:07:55 +00:00
|
|
|
HValue* arguments_length_;
|
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-06-13 17:38:10 +00:00
|
|
|
isolate()->factory()->undefined_value());
|
2013-02-04 12:01:59 +00:00
|
|
|
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-04-25 16:00:32 +00:00
|
|
|
stack_parameter_count->set_type(HType::Smi());
|
2013-05-23 09:17:01 +00:00
|
|
|
// It's essential to bind this value to the environment in case of deopt.
|
2013-03-08 21:07:55 +00:00
|
|
|
AddInstruction(stack_parameter_count);
|
2013-04-25 16:00:32 +00:00
|
|
|
start_environment->Bind(param_count, 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
|
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;
|
|
|
|
if (descriptor_->function_mode_ == JS_FUNCTION_STUB_MODE) {
|
2013-04-25 16:00:32 +00:00
|
|
|
if (!stack_parameter_count->IsConstant() &&
|
|
|
|
descriptor_->hint_stack_parameter_count_ < 0) {
|
|
|
|
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);
|
|
|
|
} else {
|
|
|
|
int count = descriptor_->hint_stack_parameter_count_;
|
2013-06-13 17:38:10 +00:00
|
|
|
stack_pop_count = AddInstruction(new(zone) 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-04-24 11:32:17 +00:00
|
|
|
HReturn* hreturn_instruction = new(zone) HReturn(return_value,
|
|
|
|
context_,
|
|
|
|
stack_pop_count);
|
|
|
|
current_block()->Finish(hreturn_instruction);
|
2013-05-29 12:36:41 +00:00
|
|
|
set_current_block(NULL);
|
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:
|
|
|
|
explicit CodeStubGraphBuilder(Stub* stub)
|
|
|
|
: CodeStubGraphBuilderBase(Isolate::Current(), stub) {}
|
|
|
|
|
|
|
|
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();
|
|
|
|
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(),
|
2013-05-02 16:32:47 +00:00
|
|
|
GetStubType(),
|
|
|
|
GetStubFlags());
|
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>
|
|
|
|
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);
|
|
|
|
}
|
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.
|
2013-05-24 11:44:55 +00:00
|
|
|
if (stub->IsUninitialized() && descriptor->has_miss_handler()) {
|
|
|
|
ASSERT(descriptor->stack_parameter_count_ == NULL);
|
2013-04-18 20:37:27 +00:00
|
|
|
return stub->GenerateLightweightMissCode(isolate);
|
|
|
|
}
|
2013-05-24 11:44:55 +00:00
|
|
|
CodeStubGraphBuilder<Stub> builder(stub);
|
|
|
|
LChunk* chunk = OptimizeGraph(builder.CreateGraph());
|
|
|
|
return chunk->Codegen();
|
2013-03-20 12:01:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-07-23 06:02:54 +00:00
|
|
|
template <>
|
|
|
|
HValue* CodeStubGraphBuilder<ToNumberStub>::BuildCodeStub() {
|
|
|
|
HValue* value = GetParameter(0);
|
|
|
|
|
|
|
|
// Check if the parameter is already a SMI or heap number.
|
|
|
|
IfBuilder if_number(this);
|
|
|
|
if_number.If<HIsSmiAndBranch>(value);
|
|
|
|
if_number.OrIf<HCompareMap>(value, isolate()->factory()->heap_number_map());
|
|
|
|
if_number.Then();
|
|
|
|
|
|
|
|
// Return the number.
|
|
|
|
Push(value);
|
|
|
|
|
|
|
|
if_number.Else();
|
|
|
|
|
|
|
|
// Convert the parameter to number using the builtin.
|
|
|
|
HValue* function = AddLoadJSBuiltin(Builtins::TO_NUMBER, context());
|
|
|
|
Add<HPushArgument>(value);
|
|
|
|
Push(Add<HInvokeFunction>(context(), function, 1));
|
|
|
|
|
|
|
|
if_number.End();
|
|
|
|
|
|
|
|
return Pop();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<Code> ToNumberStub::GenerateCode() {
|
|
|
|
return DoGenerateCode(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
2013-07-08 10:02:16 +00:00
|
|
|
HInstruction* allocation_site =
|
2013-04-04 17:55:43 +00:00
|
|
|
AddInstruction(new(zone) HLoadKeyed(GetParameter(0),
|
|
|
|
GetParameter(1),
|
|
|
|
NULL,
|
|
|
|
FAST_ELEMENTS));
|
2013-04-22 11:15:43 +00:00
|
|
|
IfBuilder checker(this);
|
2013-07-08 10:02:16 +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-07-19 13:30:49 +00:00
|
|
|
HObjectAccess access = HObjectAccess::ForAllocationSiteTransitionInfo();
|
2013-07-08 10:02:16 +00:00
|
|
|
HInstruction* boilerplate = AddLoad(allocation_site, access);
|
2013-04-04 17:55:43 +00:00
|
|
|
if (mode == FastCloneShallowArrayStub::CLONE_ANY_ELEMENTS) {
|
2013-05-03 12:21:16 +00:00
|
|
|
HValue* elements = AddLoadElements(boilerplate);
|
2013-04-04 17:55:43 +00:00
|
|
|
|
2013-04-18 10:51:24 +00:00
|
|
|
IfBuilder if_fixed_cow(this);
|
2013-07-05 10:40:14 +00:00
|
|
|
if_fixed_cow.If<HCompareMap>(elements, factory->fixed_cow_array_map());
|
2013-04-18 10:51:24 +00:00
|
|
|
if_fixed_cow.Then();
|
2013-04-04 17:55:43 +00:00
|
|
|
environment()->Push(BuildCloneShallowArray(context(),
|
|
|
|
boilerplate,
|
2013-07-08 10:02:16 +00:00
|
|
|
allocation_site,
|
2013-04-04 17:55:43 +00:00
|
|
|
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);
|
2013-07-05 10:40:14 +00:00
|
|
|
if_fixed.If<HCompareMap>(elements, factory->fixed_array_map());
|
2013-04-18 10:51:24 +00:00
|
|
|
if_fixed.Then();
|
2013-04-04 17:55:43 +00:00
|
|
|
environment()->Push(BuildCloneShallowArray(context(),
|
|
|
|
boilerplate,
|
2013-07-08 10:02:16 +00:00
|
|
|
allocation_site,
|
2013-04-04 17:55:43 +00:00
|
|
|
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,
|
2013-07-08 10:02:16 +00:00
|
|
|
allocation_site,
|
2013-04-04 17:55:43 +00:00
|
|
|
alloc_site_mode,
|
|
|
|
FAST_DOUBLE_ELEMENTS,
|
|
|
|
length));
|
|
|
|
} else {
|
|
|
|
ElementsKind elements_kind = casted_stub()->ComputeElementsKind();
|
|
|
|
environment()->Push(BuildCloneShallowArray(context(),
|
|
|
|
boilerplate,
|
2013-07-08 10:02:16 +00:00
|
|
|
allocation_site,
|
2013-04-04 17:55:43 +00:00
|
|
|
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();
|
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 =
|
2013-06-13 17:38:10 +00:00
|
|
|
AddInstruction(new(zone) HConstant(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-06-13 17:38:10 +00:00
|
|
|
HValue* size_in_bytes = AddInstruction(new(zone) HConstant(size));
|
2013-03-14 08:32:52 +00:00
|
|
|
HAllocate::Flags flags = HAllocate::CAN_ALLOCATE_IN_NEW_SPACE;
|
2013-05-23 08:17:03 +00:00
|
|
|
if (isolate()->heap()->ShouldGloballyPretenure()) {
|
2013-03-14 08:32:52 +00:00
|
|
|
flags = static_cast<HAllocate::Flags>(
|
|
|
|
flags | HAllocate::CAN_ALLOCATE_IN_OLD_POINTER_SPACE);
|
|
|
|
}
|
2013-05-24 08:38:21 +00:00
|
|
|
|
|
|
|
HInstruction* object = AddInstruction(new(zone)
|
|
|
|
HAllocate(context(), size_in_bytes, HType::JSObject(), flags));
|
2013-02-26 13:08:08 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < size; i += kPointerSize) {
|
2013-05-24 08:38:21 +00:00
|
|
|
HObjectAccess access = HObjectAccess::ForJSObjectOffset(i);
|
|
|
|
AddStore(object, access, AddLoad(boilerplate, access));
|
2013-02-26 13:08:08 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2013-07-08 10:02:16 +00:00
|
|
|
template <>
|
|
|
|
HValue* CodeStubGraphBuilder<CreateAllocationSiteStub>::BuildCodeStub() {
|
|
|
|
Zone* zone = this->zone();
|
|
|
|
|
|
|
|
HValue* size = AddInstruction(new(zone) HConstant(AllocationSite::kSize));
|
|
|
|
HAllocate::Flags flags = HAllocate::DefaultFlags();
|
|
|
|
flags = static_cast<HAllocate::Flags>(
|
|
|
|
flags | HAllocate::CAN_ALLOCATE_IN_OLD_POINTER_SPACE);
|
|
|
|
HInstruction* object = AddInstruction(new(zone)
|
|
|
|
HAllocate(context(), size, HType::JSObject(), flags));
|
|
|
|
|
|
|
|
// Store the map
|
|
|
|
Handle<Map> allocation_site_map(isolate()->heap()->allocation_site_map(),
|
|
|
|
isolate());
|
|
|
|
AddStoreMapConstant(object, allocation_site_map);
|
|
|
|
|
|
|
|
// Store the payload (smi elements kind)
|
|
|
|
HValue* initial_elements_kind = AddInstruction(new(zone) HConstant(
|
|
|
|
GetInitialFastElementsKind()));
|
2013-07-17 11:50:24 +00:00
|
|
|
Add<HStoreNamedField>(object,
|
|
|
|
HObjectAccess::ForAllocationSiteTransitionInfo(),
|
|
|
|
initial_elements_kind);
|
|
|
|
|
|
|
|
Add<HLinkObjectInList>(object, HObjectAccess::ForAllocationSiteWeakNext(),
|
|
|
|
HLinkObjectInList::ALLOCATION_SITE_LIST);
|
2013-07-08 10:02:16 +00:00
|
|
|
|
|
|
|
// We use a hammer (SkipWriteBarrier()) to indicate that we know the input
|
|
|
|
// cell is really a Cell, and so no write barrier is needed.
|
|
|
|
// TODO(mvstanton): Add a debug_code check to verify the input cell is really
|
|
|
|
// a cell. (perhaps with a new instruction, HAssert).
|
|
|
|
HInstruction* cell = GetParameter(0);
|
|
|
|
HObjectAccess access = HObjectAccess::ForCellValue();
|
|
|
|
HStoreNamedField* store = AddStore(cell, access, object);
|
|
|
|
store->SkipWriteBarrier();
|
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<Code> CreateAllocationSiteStub::GenerateCode() {
|
|
|
|
return DoGenerateCode(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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-05-27 08:50:52 +00:00
|
|
|
false, NEVER_RETURN_HOLE, STANDARD_STORE);
|
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-05-02 16:32:47 +00:00
|
|
|
template<>
|
|
|
|
HValue* CodeStubGraphBuilder<LoadFieldStub>::BuildCodeStub() {
|
2013-05-24 08:38:21 +00:00
|
|
|
HObjectAccess access = casted_stub()->is_inobject() ?
|
|
|
|
HObjectAccess::ForJSObjectOffset(casted_stub()->offset()) :
|
|
|
|
HObjectAccess::ForBackingStoreOffset(casted_stub()->offset());
|
|
|
|
return AddInstruction(BuildLoadNamedField(GetParameter(0), access,
|
|
|
|
casted_stub()->representation()));
|
2013-05-02 16:32:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<Code> LoadFieldStub::GenerateCode() {
|
|
|
|
return DoGenerateCode(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template<>
|
|
|
|
HValue* CodeStubGraphBuilder<KeyedLoadFieldStub>::BuildCodeStub() {
|
2013-05-24 08:38:21 +00:00
|
|
|
HObjectAccess access = casted_stub()->is_inobject() ?
|
|
|
|
HObjectAccess::ForJSObjectOffset(casted_stub()->offset()) :
|
|
|
|
HObjectAccess::ForBackingStoreOffset(casted_stub()->offset());
|
|
|
|
return AddInstruction(BuildLoadNamedField(GetParameter(0), access,
|
|
|
|
casted_stub()->representation()));
|
2013-05-02 16:32:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<Code> KeyedLoadFieldStub::GenerateCode() {
|
|
|
|
return DoGenerateCode(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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(),
|
2013-05-27 08:50:52 +00:00
|
|
|
true, NEVER_RETURN_HOLE, casted_stub()->store_mode());
|
2013-03-20 10:37:13 +00:00
|
|
|
|
|
|
|
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
|
|
|
info()->MarkAsSavesCallerDoubles();
|
|
|
|
|
2013-07-17 11:37:20 +00:00
|
|
|
BuildTransitionElementsKind(GetParameter(0),
|
|
|
|
GetParameter(1),
|
|
|
|
casted_stub()->from_kind(),
|
|
|
|
casted_stub()->to_kind(),
|
|
|
|
true);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-20 17:20:48 +00:00
|
|
|
Handle<Code> TransitionElementsKindStub::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,
|
|
|
|
ContextCheckMode context_mode,
|
|
|
|
AllocationSiteOverrideMode override_mode,
|
2013-06-05 10:43:18 +00:00
|
|
|
ArgumentClass argument_class) {
|
|
|
|
HValue* constructor = GetParameter(ArrayConstructorStubBase::kConstructor);
|
2013-06-28 13:16:14 +00:00
|
|
|
if (context_mode == CONTEXT_CHECK_REQUIRED) {
|
|
|
|
HInstruction* array_function = BuildGetArrayFunction(context());
|
|
|
|
ArrayContextChecker checker(this, constructor, array_function);
|
|
|
|
}
|
2013-06-05 10:43:18 +00:00
|
|
|
|
2013-06-28 13:16:14 +00:00
|
|
|
HValue* property_cell = GetParameter(ArrayConstructorStubBase::kPropertyCell);
|
2013-07-08 10:02:16 +00:00
|
|
|
// Walk through the property cell to the AllocationSite
|
|
|
|
HValue* alloc_site = AddInstruction(new(zone()) HLoadNamedField(property_cell,
|
|
|
|
HObjectAccess::ForCellValue()));
|
|
|
|
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:
|
|
|
|
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:
|
|
|
|
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();
|
|
|
|
|
|
|
|
HInstruction* elements = AddInstruction(
|
|
|
|
new(zone()) HArgumentsElements(false));
|
|
|
|
HInstruction* argument = AddInstruction(
|
|
|
|
new(zone()) HAccessArgumentsAt(elements, constant_one, constant_zero));
|
|
|
|
|
|
|
|
HConstant* max_alloc_length =
|
2013-05-29 10:47:55 +00:00
|
|
|
new(zone()) HConstant(JSObject::kInitialMaxFastElementArray);
|
2013-04-25 16:00:32 +00:00
|
|
|
AddInstruction(max_alloc_length);
|
|
|
|
const int initial_capacity = JSArray::kPreallocatedArrayElements;
|
2013-05-29 10:47:55 +00:00
|
|
|
HConstant* initial_capacity_node = new(zone()) HConstant(initial_capacity);
|
2013-04-25 16:00:32 +00:00
|
|
|
AddInstruction(initial_capacity_node);
|
|
|
|
|
2013-06-27 14:36:14 +00:00
|
|
|
HBoundsCheck* checked_arg = Add<HBoundsCheck>(argument, max_alloc_length);
|
2013-04-25 16:00:32 +00:00
|
|
|
IfBuilder if_builder(this);
|
2013-07-05 10:40:14 +00:00
|
|
|
if_builder.If<HCompareNumericAndBranch>(checked_arg, constant_zero,
|
|
|
|
Token::EQ);
|
2013-04-25 16:00:32 +00:00
|
|
|
if_builder.Then();
|
|
|
|
Push(initial_capacity_node); // capacity
|
|
|
|
Push(constant_zero); // length
|
|
|
|
if_builder.Else();
|
|
|
|
Push(checked_arg); // capacity
|
|
|
|
Push(checked_arg); // length
|
|
|
|
if_builder.End();
|
|
|
|
|
|
|
|
// Figure out total size
|
|
|
|
HValue* length = Pop();
|
|
|
|
HValue* capacity = Pop();
|
2013-06-05 10:43:18 +00:00
|
|
|
return array_builder->AllocateArray(capacity, length, true);
|
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-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-06-05 10:43:18 +00:00
|
|
|
HValue* length = GetArgumentsLength();
|
2013-04-25 16:00:32 +00:00
|
|
|
bool fill_with_hole = IsFastSmiElementsKind(kind);
|
2013-06-05 10:43:18 +00:00
|
|
|
HValue* new_object = array_builder->AllocateArray(length,
|
|
|
|
length,
|
|
|
|
fill_with_hole);
|
|
|
|
HValue* elements = array_builder->GetElementsLocation();
|
2013-04-25 16:00:32 +00:00
|
|
|
ASSERT(elements != NULL);
|
|
|
|
|
|
|
|
// Now populate the elements correctly.
|
|
|
|
LoopBuilder builder(this,
|
|
|
|
context(),
|
|
|
|
LoopBuilder::kPostIncrement);
|
|
|
|
HValue* start = graph()->GetConstant0();
|
|
|
|
HValue* key = builder.BeginBody(start, length, Token::LT);
|
|
|
|
HInstruction* argument_elements = AddInstruction(
|
|
|
|
new(zone()) HArgumentsElements(false));
|
|
|
|
HInstruction* argument = AddInstruction(new(zone()) HAccessArgumentsAt(
|
|
|
|
argument_elements, length, key));
|
|
|
|
|
|
|
|
AddInstruction(new(zone()) HStoreKeyed(elements, key, argument, kind));
|
|
|
|
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
|
|
|
ContextCheckMode context_mode = casted_stub()->context_mode();
|
|
|
|
AllocationSiteOverrideMode override_mode = casted_stub()->override_mode();
|
|
|
|
return BuildArrayConstructor(kind, context_mode, override_mode, NONE);
|
2013-06-05 10:43:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<Code> ArrayNoArgumentConstructorStub::GenerateCode() {
|
|
|
|
return DoGenerateCode(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <>
|
|
|
|
HValue* CodeStubGraphBuilder<ArraySingleArgumentConstructorStub>::
|
|
|
|
BuildCodeStub() {
|
|
|
|
ElementsKind kind = casted_stub()->elements_kind();
|
2013-06-28 13:16:14 +00:00
|
|
|
ContextCheckMode context_mode = casted_stub()->context_mode();
|
|
|
|
AllocationSiteOverrideMode override_mode = casted_stub()->override_mode();
|
|
|
|
return BuildArrayConstructor(kind, context_mode, override_mode, SINGLE);
|
2013-06-05 10:43:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<Code> ArraySingleArgumentConstructorStub::GenerateCode() {
|
|
|
|
return DoGenerateCode(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <>
|
|
|
|
HValue* CodeStubGraphBuilder<ArrayNArgumentsConstructorStub>::BuildCodeStub() {
|
|
|
|
ElementsKind kind = casted_stub()->elements_kind();
|
2013-06-28 13:16:14 +00:00
|
|
|
ContextCheckMode context_mode = casted_stub()->context_mode();
|
|
|
|
AllocationSiteOverrideMode override_mode = casted_stub()->override_mode();
|
|
|
|
return BuildArrayConstructor(kind, context_mode, override_mode, MULTIPLE);
|
2013-06-05 10:43:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
|
2013-06-05 10:43:18 +00:00
|
|
|
template <>
|
|
|
|
HValue* CodeStubGraphBuilder<InternalArrayNoArgumentConstructorStub>::
|
|
|
|
BuildCodeStub() {
|
|
|
|
ElementsKind kind = casted_stub()->elements_kind();
|
|
|
|
return BuildInternalArrayConstructor(kind, NONE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<Code> InternalArrayNoArgumentConstructorStub::GenerateCode() {
|
|
|
|
return DoGenerateCode(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <>
|
|
|
|
HValue* CodeStubGraphBuilder<InternalArraySingleArgumentConstructorStub>::
|
|
|
|
BuildCodeStub() {
|
|
|
|
ElementsKind kind = casted_stub()->elements_kind();
|
|
|
|
return BuildInternalArrayConstructor(kind, SINGLE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<Code> InternalArraySingleArgumentConstructorStub::GenerateCode() {
|
|
|
|
return DoGenerateCode(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <>
|
|
|
|
HValue* CodeStubGraphBuilder<InternalArrayNArgumentsConstructorStub>::
|
|
|
|
BuildCodeStub() {
|
|
|
|
ElementsKind kind = casted_stub()->elements_kind();
|
|
|
|
return BuildInternalArrayConstructor(kind, MULTIPLE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<Code> InternalArrayNArgumentsConstructorStub::GenerateCode() {
|
|
|
|
return DoGenerateCode(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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());
|
2013-07-11 17:20:57 +00:00
|
|
|
Handle<Type> type = stub->GetType(isolate, sentinel_map);
|
2013-06-12 17:20:37 +00:00
|
|
|
BuildCompareNil(GetParameter(0), type, RelocInfo::kNoPosition, &continuation);
|
2013-04-24 11:32:17 +00:00
|
|
|
IfBuilder if_nil(this, &continuation);
|
|
|
|
if_nil.Then();
|
|
|
|
if (continuation.IsFalseReachable()) {
|
|
|
|
if_nil.Else();
|
2013-05-27 08:43:58 +00:00
|
|
|
if_nil.Return(graph()->GetConstant0());
|
2013-04-24 11:32:17 +00:00
|
|
|
}
|
|
|
|
if_nil.End();
|
|
|
|
return continuation.IsTrueReachable()
|
2013-05-27 08:43:58 +00:00
|
|
|
? graph()->GetConstant1()
|
2013-04-24 11:32:17 +00:00
|
|
|
: graph()->GetConstantUndefined();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<Code> CompareNilICStub::GenerateCode() {
|
|
|
|
return DoGenerateCode(this);
|
|
|
|
}
|
|
|
|
|
2013-05-29 14:49:28 +00:00
|
|
|
|
2013-07-05 09:26:22 +00:00
|
|
|
template <>
|
|
|
|
HValue* CodeStubGraphBuilder<UnaryOpStub>::BuildCodeInitializedStub() {
|
|
|
|
UnaryOpStub* stub = casted_stub();
|
|
|
|
Handle<Type> type = stub->GetType(graph()->isolate());
|
|
|
|
HValue* input = GetParameter(0);
|
|
|
|
|
|
|
|
// Prevent unwanted HChange being inserted to ensure that the stub
|
|
|
|
// deopts on newly encountered types.
|
|
|
|
if (!type->Maybe(Type::Double())) {
|
|
|
|
input = AddInstruction(new(zone())
|
|
|
|
HForceRepresentation(input, Representation::Smi()));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!type->Is(Type::Number())) {
|
|
|
|
// If we expect to see other things than Numbers, we will create a generic
|
|
|
|
// stub, which handles all numbers and calls into the runtime for the rest.
|
|
|
|
IfBuilder if_number(this);
|
|
|
|
if_number.If<HIsNumberAndBranch>(input);
|
|
|
|
if_number.Then();
|
|
|
|
HInstruction* res = BuildUnaryMathOp(input, type, stub->operation());
|
|
|
|
if_number.Return(AddInstruction(res));
|
|
|
|
if_number.Else();
|
|
|
|
HValue* function = AddLoadJSBuiltin(stub->ToJSBuiltin(), context());
|
|
|
|
Add<HPushArgument>(GetParameter(0));
|
|
|
|
HValue* result = Add<HInvokeFunction>(context(), function, 1);
|
|
|
|
if_number.Return(result);
|
|
|
|
if_number.End();
|
|
|
|
return graph()->GetConstantUndefined();
|
|
|
|
}
|
|
|
|
|
|
|
|
return AddInstruction(BuildUnaryMathOp(input, type, stub->operation()));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<Code> UnaryOpStub::GenerateCode() {
|
|
|
|
return DoGenerateCode(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-05-29 14:49:28 +00:00
|
|
|
template <>
|
|
|
|
HValue* CodeStubGraphBuilder<ToBooleanStub>::BuildCodeInitializedStub() {
|
|
|
|
ToBooleanStub* stub = casted_stub();
|
|
|
|
|
|
|
|
IfBuilder if_true(this);
|
|
|
|
if_true.If<HBranch>(GetParameter(0), stub->GetTypes());
|
|
|
|
if_true.Then();
|
2013-07-05 10:34:02 +00:00
|
|
|
if_true.Return(graph()->GetConstant1());
|
2013-05-29 14:49:28 +00:00
|
|
|
if_true.Else();
|
|
|
|
if_true.End();
|
|
|
|
return graph()->GetConstant0();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<Code> ToBooleanStub::GenerateCode() {
|
|
|
|
return DoGenerateCode(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-07-05 10:34:02 +00:00
|
|
|
template <>
|
|
|
|
HValue* CodeStubGraphBuilder<StoreGlobalStub>::BuildCodeInitializedStub() {
|
|
|
|
StoreGlobalStub* stub = casted_stub();
|
|
|
|
Handle<Object> hole(isolate()->heap()->the_hole_value(), isolate());
|
|
|
|
Handle<Object> placeholer_value(Smi::FromInt(0), isolate());
|
|
|
|
Handle<PropertyCell> placeholder_cell =
|
|
|
|
isolate()->factory()->NewPropertyCell(placeholer_value);
|
|
|
|
|
|
|
|
HParameter* receiver = GetParameter(0);
|
|
|
|
HParameter* value = GetParameter(2);
|
|
|
|
|
2013-07-22 14:15:58 +00:00
|
|
|
// Check that the map of the global has not changed: use a placeholder map
|
|
|
|
// that will be replaced later with the global object's map.
|
|
|
|
Handle<Map> placeholder_map = isolate()->factory()->meta_map();
|
|
|
|
AddInstruction(HCheckMaps::New(receiver, placeholder_map, zone()));
|
2013-07-05 10:40:14 +00:00
|
|
|
|
2013-07-22 14:15:58 +00:00
|
|
|
HValue* cell = Add<HConstant>(placeholder_cell, Representation::Tagged());
|
|
|
|
HObjectAccess access(HObjectAccess::ForCellPayload(isolate()));
|
|
|
|
HValue* cell_contents = Add<HLoadNamedField>(cell, access);
|
2013-07-05 10:34:02 +00:00
|
|
|
|
2013-07-22 14:15:58 +00:00
|
|
|
if (stub->is_constant()) {
|
|
|
|
IfBuilder builder(this);
|
|
|
|
builder.If<HCompareObjectEqAndBranch>(cell_contents, value);
|
|
|
|
builder.Then();
|
|
|
|
builder.ElseDeopt();
|
|
|
|
builder.End();
|
|
|
|
} else {
|
2013-07-05 10:34:02 +00:00
|
|
|
// Load the payload of the global parameter cell. A hole indicates that the
|
|
|
|
// property has been deleted and that the store must be handled by the
|
|
|
|
// runtime.
|
|
|
|
IfBuilder builder(this);
|
|
|
|
HValue* hole_value = Add<HConstant>(hole, Representation::Tagged());
|
|
|
|
builder.If<HCompareObjectEqAndBranch>(cell_contents, hole_value);
|
|
|
|
builder.Then();
|
|
|
|
builder.Deopt();
|
|
|
|
builder.Else();
|
|
|
|
Add<HStoreNamedField>(cell, access, value);
|
|
|
|
builder.End();
|
|
|
|
}
|
2013-07-22 14:15:58 +00:00
|
|
|
|
2013-07-05 10:34:02 +00:00
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<Code> StoreGlobalStub::GenerateCode() {
|
|
|
|
return DoGenerateCode(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-07-17 11:37:20 +00:00
|
|
|
template<>
|
|
|
|
HValue* CodeStubGraphBuilder<ElementsTransitionAndStoreStub>::BuildCodeStub() {
|
|
|
|
HValue* value = GetParameter(0);
|
|
|
|
HValue* map = GetParameter(1);
|
|
|
|
HValue* key = GetParameter(2);
|
|
|
|
HValue* object = GetParameter(3);
|
|
|
|
|
|
|
|
if (FLAG_trace_elements_transitions) {
|
|
|
|
// Tracing elements transitions is the job of the runtime.
|
|
|
|
current_block()->FinishExitWithDeoptimization(HDeoptimize::kUseAll);
|
|
|
|
set_current_block(NULL);
|
|
|
|
} else {
|
|
|
|
info()->MarkAsSavesCallerDoubles();
|
|
|
|
|
|
|
|
BuildTransitionElementsKind(object, map,
|
|
|
|
casted_stub()->from_kind(),
|
|
|
|
casted_stub()->to_kind(),
|
|
|
|
casted_stub()->is_jsarray());
|
|
|
|
|
|
|
|
BuildUncheckedMonomorphicElementAccess(object, key, value, NULL,
|
|
|
|
casted_stub()->is_jsarray(),
|
|
|
|
casted_stub()->to_kind(),
|
|
|
|
true, ALLOW_RETURN_HOLE,
|
|
|
|
casted_stub()->store_mode());
|
|
|
|
}
|
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<Code> ElementsTransitionAndStoreStub::GenerateCode() {
|
|
|
|
return DoGenerateCode(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-12-18 16:25:45 +00:00
|
|
|
} } // namespace v8::internal
|