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);
|
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:
|
|
|
|
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() {
|
2013-08-09 12:50:42 +00:00
|
|
|
checker_.ElseDeopt("Array constructor called from different context");
|
2013-05-07 21:01:53 +00:00
|
|
|
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);
|
|
|
|
|
2013-08-27 11:55:08 +00:00
|
|
|
void BuildInstallOptimizedCode(HValue* js_function, HValue* native_context,
|
|
|
|
HValue* code_object);
|
|
|
|
void BuildInstallCode(HValue* js_function, HValue* shared_info);
|
|
|
|
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);
|
|
|
|
|
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();
|
|
|
|
|
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);
|
2013-03-06 07:25:46 +00:00
|
|
|
isolate()->GetHTracer()->TraceCompilation(&info_);
|
2012-12-18 16:25:45 +00:00
|
|
|
}
|
|
|
|
|
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-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);
|
|
|
|
|
2013-11-13 10:07:04 +00:00
|
|
|
bool runtime_stack_params = descriptor_->stack_parameter_count_.is_valid();
|
|
|
|
HInstruction* stack_parameter_count = NULL;
|
2013-02-25 14:03:09 +00:00
|
|
|
for (int i = 0; i < param_count; ++i) {
|
2013-11-13 10:07:04 +00:00
|
|
|
Representation r = descriptor_->IsParameterCountRegister(i)
|
|
|
|
? Representation::Integer32()
|
|
|
|
: Representation::Tagged();
|
|
|
|
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;
|
2013-11-13 10:07:04 +00:00
|
|
|
if (descriptor_->IsParameterCountRegister(i)) {
|
|
|
|
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
|
|
|
|
2013-11-13 10:07:04 +00:00
|
|
|
ASSERT(!runtime_stack_params || arguments_length_ != NULL);
|
|
|
|
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;
|
|
|
|
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) {
|
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 {
|
|
|
|
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:
|
2013-11-16 15:22:09 +00:00
|
|
|
CodeStubGraphBuilder(Isolate* isolate, Stub* stub)
|
2013-09-03 06:57:16 +00:00
|
|
|
: CodeStubGraphBuilderBase(isolate, stub) {}
|
2012-12-18 16:25:45 +00:00
|
|
|
|
|
|
|
protected:
|
2013-04-18 20:37:27 +00:00
|
|
|
virtual HValue* BuildCodeStub() {
|
2013-05-24 11:44:55 +00:00
|
|
|
if (casted_stub()->IsUninitialized()) {
|
2013-04-18 20:37:27 +00:00
|
|
|
return BuildCodeUninitializedStub();
|
2013-05-24 11:44:55 +00:00
|
|
|
} else {
|
|
|
|
return BuildCodeInitializedStub();
|
2013-04-18 20:37:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual HValue* BuildCodeInitializedStub() {
|
|
|
|
UNIMPLEMENTED();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual HValue* BuildCodeUninitializedStub() {
|
|
|
|
// Force a deopt that falls back to the runtime.
|
|
|
|
HValue* undefined = graph()->GetConstantUndefined();
|
2013-04-22 11:15:43 +00:00
|
|
|
IfBuilder builder(this);
|
|
|
|
builder.IfNot<HCompareObjectEqAndBranch, HValue*>(undefined, undefined);
|
|
|
|
builder.Then();
|
2013-08-09 12:50:42 +00:00
|
|
|
builder.ElseDeopt("Forced deopt to runtime");
|
2013-04-18 20:37:27 +00:00
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
2012-12-18 16:25:45 +00:00
|
|
|
Stub* casted_stub() { return static_cast<Stub*>(stub()); }
|
|
|
|
};
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
// 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>
|
2013-09-03 06:57:16 +00:00
|
|
|
static Handle<Code> DoGenerateCode(Isolate* isolate, Stub* stub) {
|
2013-04-18 20:37:27 +00:00
|
|
|
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()) {
|
2013-10-18 14:55:21 +00:00
|
|
|
ASSERT(!descriptor->stack_parameter_count_.is_valid());
|
2013-04-18 20:37:27 +00:00
|
|
|
return stub->GenerateLightweightMissCode(isolate);
|
|
|
|
}
|
2013-10-02 11:27:37 +00:00
|
|
|
ElapsedTimer timer;
|
|
|
|
if (FLAG_profile_hydrogen_code_stub_compilation) {
|
|
|
|
timer.Start();
|
|
|
|
}
|
2013-09-03 06:57:16 +00:00
|
|
|
CodeStubGraphBuilder<Stub> builder(isolate, stub);
|
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) {
|
|
|
|
double ms = timer.Elapsed().InMillisecondsF();
|
2013-12-09 07:41:20 +00:00
|
|
|
PrintF("[Lazy compilation of %s took %0.3f ms]\n",
|
|
|
|
stub->GetName().get(), ms);
|
2013-10-02 11:27:37 +00:00
|
|
|
}
|
|
|
|
return code;
|
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.
|
2013-07-31 14:58:39 +00:00
|
|
|
HValue* function = AddLoadJSBuiltin(Builtins::TO_NUMBER);
|
2013-07-23 06:02:54 +00:00
|
|
|
Add<HPushArgument>(value);
|
2013-07-31 14:58:39 +00:00
|
|
|
Push(Add<HInvokeFunction>(function, 1));
|
2013-07-23 06:02:54 +00:00
|
|
|
|
|
|
|
if_number.End();
|
|
|
|
|
|
|
|
return Pop();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-03 06:57:16 +00:00
|
|
|
Handle<Code> ToNumberStub::GenerateCode(Isolate* isolate) {
|
|
|
|
return DoGenerateCode(isolate, this);
|
2013-07-23 06:02:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-24 09:31:07 +00:00
|
|
|
template <>
|
|
|
|
HValue* CodeStubGraphBuilder<NumberToStringStub>::BuildCodeStub() {
|
|
|
|
info()->MarkAsSavesCallerDoubles();
|
|
|
|
HValue* number = GetParameter(NumberToStringStub::kNumber);
|
2013-10-21 12:42:08 +00:00
|
|
|
return BuildNumberToString(number, handle(Type::Number(), isolate()));
|
2013-09-24 09:31:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<Code> NumberToStringStub::GenerateCode(Isolate* isolate) {
|
|
|
|
return DoGenerateCode(isolate, 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();
|
|
|
|
FastCloneShallowArrayStub::Mode mode = casted_stub()->mode();
|
|
|
|
int length = casted_stub()->length();
|
|
|
|
|
2013-07-31 14:58:39 +00:00
|
|
|
HInstruction* allocation_site = Add<HLoadKeyed>(GetParameter(0),
|
|
|
|
GetParameter(1),
|
|
|
|
static_cast<HValue*>(NULL),
|
|
|
|
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);
|
2013-07-31 14:58:39 +00:00
|
|
|
HInstruction* boilerplate = Add<HLoadNamedField>(allocation_site, access);
|
2013-09-13 13:50:16 +00:00
|
|
|
HValue* push_value;
|
2013-04-04 17:55:43 +00:00
|
|
|
if (mode == FastCloneShallowArrayStub::CLONE_ANY_ELEMENTS) {
|
2013-08-21 14:49:56 +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-09-13 13:50:16 +00:00
|
|
|
push_value = BuildCloneShallowArray(boilerplate,
|
|
|
|
allocation_site,
|
|
|
|
alloc_site_mode,
|
|
|
|
FAST_ELEMENTS,
|
|
|
|
0/*copy-on-write*/);
|
|
|
|
environment()->Push(push_value);
|
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-09-13 13:50:16 +00:00
|
|
|
push_value = BuildCloneShallowArray(boilerplate,
|
|
|
|
allocation_site,
|
|
|
|
alloc_site_mode,
|
|
|
|
FAST_ELEMENTS,
|
|
|
|
length);
|
|
|
|
environment()->Push(push_value);
|
2013-04-18 10:51:24 +00:00
|
|
|
if_fixed.Else();
|
2013-09-13 13:50:16 +00:00
|
|
|
push_value = BuildCloneShallowArray(boilerplate,
|
|
|
|
allocation_site,
|
|
|
|
alloc_site_mode,
|
|
|
|
FAST_DOUBLE_ELEMENTS,
|
|
|
|
length);
|
|
|
|
environment()->Push(push_value);
|
2013-04-04 17:55:43 +00:00
|
|
|
} else {
|
|
|
|
ElementsKind elements_kind = casted_stub()->ComputeElementsKind();
|
2013-09-13 13:50:16 +00:00
|
|
|
push_value = BuildCloneShallowArray(boilerplate,
|
|
|
|
allocation_site,
|
|
|
|
alloc_site_mode,
|
|
|
|
elements_kind,
|
|
|
|
length);
|
|
|
|
environment()->Push(push_value);
|
2013-04-04 17:55:43 +00:00
|
|
|
}
|
|
|
|
|
2013-08-09 12:50:42 +00:00
|
|
|
checker.ElseDeopt("Uninitialized boilerplate literals");
|
2013-07-23 13:35:10 +00:00
|
|
|
checker.End();
|
|
|
|
|
|
|
|
return environment()->Pop();
|
2013-04-04 17:55:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-03 06:57:16 +00:00
|
|
|
Handle<Code> FastCloneShallowArrayStub::GenerateCode(Isolate* isolate) {
|
|
|
|
return DoGenerateCode(isolate, 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
|
|
|
|
2013-10-11 09:25:14 +00:00
|
|
|
HInstruction* allocation_site = Add<HLoadKeyed>(GetParameter(0),
|
|
|
|
GetParameter(1),
|
|
|
|
static_cast<HValue*>(NULL),
|
|
|
|
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);
|
2013-10-11 09:25:14 +00:00
|
|
|
HInstruction* boilerplate = Add<HLoadNamedField>(allocation_site, access);
|
|
|
|
|
2013-02-26 13:08:08 +00:00
|
|
|
int size = JSObject::kHeaderSize + casted_stub()->length() * kPointerSize;
|
2013-10-11 09:25:14 +00:00
|
|
|
int object_size = size;
|
|
|
|
if (FLAG_allocation_site_pretenuring) {
|
|
|
|
size += AllocationMemento::kSize;
|
|
|
|
}
|
|
|
|
|
2013-10-04 19:04:34 +00:00
|
|
|
HValue* boilerplate_map = Add<HLoadNamedField>(
|
|
|
|
boilerplate, HObjectAccess::ForMap());
|
|
|
|
HValue* boilerplate_size = Add<HLoadNamedField>(
|
|
|
|
boilerplate_map, 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) {
|
2013-05-24 08:38:21 +00:00
|
|
|
HObjectAccess access = HObjectAccess::ForJSObjectOffset(i);
|
2013-07-31 14:58:39 +00:00
|
|
|
Add<HStoreNamedField>(object, access,
|
|
|
|
Add<HLoadNamedField>(boilerplate, access));
|
2013-02-26 13:08:08 +00:00
|
|
|
}
|
|
|
|
|
2013-10-11 09:25:14 +00:00
|
|
|
ASSERT(FLAG_allocation_site_pretenuring || (size == object_size));
|
|
|
|
if (FLAG_allocation_site_pretenuring) {
|
2013-12-02 11:24:31 +00:00
|
|
|
BuildCreateAllocationMemento(
|
|
|
|
object, Add<HConstant>(object_size), allocation_site);
|
2013-10-11 09:25:14 +00:00
|
|
|
}
|
|
|
|
|
2013-07-23 13:35:10 +00:00
|
|
|
environment()->Push(object);
|
2013-08-09 12:50:42 +00:00
|
|
|
checker.ElseDeopt("Uninitialized boilerplate in fast clone");
|
2013-07-23 13:35:10 +00:00
|
|
|
checker.End();
|
|
|
|
|
|
|
|
return environment()->Pop();
|
2013-02-26 13:08:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-03 06:57:16 +00:00
|
|
|
Handle<Code> FastCloneShallowObjectStub::GenerateCode(Isolate* isolate) {
|
|
|
|
return DoGenerateCode(isolate, this);
|
2013-02-26 13:08:08 +00:00
|
|
|
}
|
|
|
|
|
2013-03-20 12:01:57 +00:00
|
|
|
|
2013-07-08 10:02:16 +00:00
|
|
|
template <>
|
|
|
|
HValue* CodeStubGraphBuilder<CreateAllocationSiteStub>::BuildCodeStub() {
|
2013-07-31 13:45:51 +00:00
|
|
|
HValue* size = Add<HConstant>(AllocationSite::kSize);
|
2013-08-01 08:34:36 +00:00
|
|
|
HInstruction* object = Add<HAllocate>(size, HType::JSObject(), TENURED,
|
|
|
|
JS_OBJECT_TYPE);
|
2013-07-08 10:02:16 +00:00
|
|
|
|
|
|
|
// Store the map
|
2013-09-20 09:27:40 +00:00
|
|
|
Handle<Map> allocation_site_map = isolate()->factory()->allocation_site_map();
|
2013-07-08 10:02:16 +00:00
|
|
|
AddStoreMapConstant(object, allocation_site_map);
|
|
|
|
|
|
|
|
// Store the payload (smi elements kind)
|
2013-07-31 13:45:51 +00:00
|
|
|
HValue* initial_elements_kind = Add<HConstant>(GetInitialFastElementsKind());
|
2013-07-17 11:50:24 +00:00
|
|
|
Add<HStoreNamedField>(object,
|
2013-10-28 09:36:49 +00:00
|
|
|
HObjectAccess::ForAllocationSiteOffset(
|
|
|
|
AllocationSite::kTransitionInfoOffset),
|
2013-07-17 11:50:24 +00:00
|
|
|
initial_elements_kind);
|
|
|
|
|
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),
|
2013-09-24 10:30:41 +00:00
|
|
|
graph()->GetConstant0());
|
|
|
|
|
2013-11-22 07:34:21 +00:00
|
|
|
// Pretenuring calculation fields.
|
|
|
|
Add<HStoreNamedField>(object,
|
|
|
|
HObjectAccess::ForAllocationSiteOffset(
|
|
|
|
AllocationSite::kMementoFoundCountOffset),
|
|
|
|
graph()->GetConstant0());
|
|
|
|
|
|
|
|
Add<HStoreNamedField>(object,
|
|
|
|
HObjectAccess::ForAllocationSiteOffset(
|
|
|
|
AllocationSite::kMementoCreateCountOffset),
|
|
|
|
graph()->GetConstant0());
|
|
|
|
|
|
|
|
Add<HStoreNamedField>(object,
|
|
|
|
HObjectAccess::ForAllocationSiteOffset(
|
|
|
|
AllocationSite::kPretenureDecisionOffset),
|
|
|
|
graph()->GetConstant0());
|
|
|
|
|
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());
|
|
|
|
HStoreNamedField* store = Add<HStoreNamedField>(
|
|
|
|
object,
|
2013-10-28 09:36:49 +00:00
|
|
|
HObjectAccess::ForAllocationSiteOffset(
|
|
|
|
AllocationSite::kDependentCodeOffset),
|
2013-09-19 14:13:34 +00:00
|
|
|
empty_fixed_array);
|
|
|
|
|
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()));
|
2013-07-31 14:58:39 +00:00
|
|
|
HValue* site = Add<HLoadNamedField>(site_list,
|
|
|
|
HObjectAccess::ForAllocationSiteList());
|
2013-09-19 14:13:34 +00:00
|
|
|
store = Add<HStoreNamedField>(object,
|
2013-10-28 09:36:49 +00:00
|
|
|
HObjectAccess::ForAllocationSiteOffset(AllocationSite::kWeakNextOffset),
|
|
|
|
site);
|
2013-07-31 10:47:44 +00:00
|
|
|
store->SkipWriteBarrier();
|
2013-07-31 14:58:39 +00:00
|
|
|
Add<HStoreNamedField>(site_list, HObjectAccess::ForAllocationSiteList(),
|
|
|
|
object);
|
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();
|
2013-07-31 14:58:39 +00:00
|
|
|
store = Add<HStoreNamedField>(cell, access, object);
|
2013-07-08 10:02:16 +00:00
|
|
|
store->SkipWriteBarrier();
|
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-03 06:57:16 +00:00
|
|
|
Handle<Code> CreateAllocationSiteStub::GenerateCode(Isolate* isolate) {
|
|
|
|
return DoGenerateCode(isolate, this);
|
2013-07-08 10:02:16 +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(
|
2013-08-26 12:28:08 +00:00
|
|
|
GetParameter(0), GetParameter(1), 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
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-03 06:57:16 +00:00
|
|
|
Handle<Code> KeyedLoadFastElementStub::GenerateCode(Isolate* isolate) {
|
|
|
|
return DoGenerateCode(isolate, this);
|
2012-12-18 16:25:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-05-02 16:32:47 +00:00
|
|
|
template<>
|
|
|
|
HValue* CodeStubGraphBuilder<LoadFieldStub>::BuildCodeStub() {
|
2013-07-25 09:37:52 +00:00
|
|
|
Representation rep = casted_stub()->representation();
|
2013-05-24 08:38:21 +00:00
|
|
|
HObjectAccess access = casted_stub()->is_inobject() ?
|
2013-07-25 09:37:52 +00:00
|
|
|
HObjectAccess::ForJSObjectOffset(casted_stub()->offset(), rep) :
|
|
|
|
HObjectAccess::ForBackingStoreOffset(casted_stub()->offset(), rep);
|
2013-10-22 11:29:05 +00:00
|
|
|
return AddLoadNamedField(GetParameter(0), access);
|
2013-05-02 16:32:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-03 06:57:16 +00:00
|
|
|
Handle<Code> LoadFieldStub::GenerateCode(Isolate* isolate) {
|
|
|
|
return DoGenerateCode(isolate, this);
|
2013-05-02 16:32:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template<>
|
|
|
|
HValue* CodeStubGraphBuilder<KeyedLoadFieldStub>::BuildCodeStub() {
|
2013-07-25 09:37:52 +00:00
|
|
|
Representation rep = casted_stub()->representation();
|
2013-05-24 08:38:21 +00:00
|
|
|
HObjectAccess access = casted_stub()->is_inobject() ?
|
2013-07-25 09:37:52 +00:00
|
|
|
HObjectAccess::ForJSObjectOffset(casted_stub()->offset(), rep) :
|
|
|
|
HObjectAccess::ForBackingStoreOffset(casted_stub()->offset(), rep);
|
2013-10-22 11:29:05 +00:00
|
|
|
return AddLoadNamedField(GetParameter(0), access);
|
2013-05-02 16:32:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-03 06:57:16 +00:00
|
|
|
Handle<Code> KeyedLoadFieldStub::GenerateCode(Isolate* isolate) {
|
|
|
|
return DoGenerateCode(isolate, this);
|
2013-05-02 16:32:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-15 10:52:05 +00:00
|
|
|
template<>
|
|
|
|
HValue* CodeStubGraphBuilder<KeyedArrayCallStub>::BuildCodeStub() {
|
|
|
|
int argc = casted_stub()->argc() + 1;
|
|
|
|
info()->set_parameter_count(argc);
|
|
|
|
|
|
|
|
HValue* receiver = Add<HParameter>(1);
|
2013-12-03 17:59:31 +00:00
|
|
|
BuildCheckHeapObject(receiver);
|
2013-11-15 10:52:05 +00:00
|
|
|
|
|
|
|
// Load the expected initial array map from the context.
|
|
|
|
JSArrayBuilder array_builder(this, casted_stub()->elements_kind());
|
|
|
|
HValue* map = array_builder.EmitMapCode();
|
|
|
|
|
|
|
|
HValue* checked_receiver = Add<HCheckMapValue>(receiver, map);
|
|
|
|
|
|
|
|
HValue* function = BuildUncheckedMonomorphicElementAccess(
|
|
|
|
checked_receiver, GetParameter(0),
|
|
|
|
NULL, true, casted_stub()->elements_kind(),
|
|
|
|
false, NEVER_RETURN_HOLE, STANDARD_STORE);
|
|
|
|
return Add<HCallFunction>(function, argc, TAIL_CALL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<Code> KeyedArrayCallStub::GenerateCode(Isolate* isolate) {
|
|
|
|
return DoGenerateCode(isolate, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-20 10:37:13 +00:00
|
|
|
template <>
|
|
|
|
HValue* CodeStubGraphBuilder<KeyedStoreFastElementStub>::BuildCodeStub() {
|
|
|
|
BuildUncheckedMonomorphicElementAccess(
|
2013-08-26 12:28:08 +00:00
|
|
|
GetParameter(0), GetParameter(1), GetParameter(2),
|
2013-03-20 10:37:13 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-03 06:57:16 +00:00
|
|
|
Handle<Code> KeyedStoreFastElementStub::GenerateCode(Isolate* isolate) {
|
|
|
|
return DoGenerateCode(isolate, 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-09-03 06:57:16 +00:00
|
|
|
Handle<Code> TransitionElementsKindStub::GenerateCode(Isolate* isolate) {
|
|
|
|
return DoGenerateCode(isolate, this);
|
2013-03-20 17:20:48 +00:00
|
|
|
}
|
|
|
|
|
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) {
|
2013-07-31 14:58:39 +00:00
|
|
|
HInstruction* array_function = BuildGetArrayFunction();
|
2013-06-28 13:16:14 +00:00
|
|
|
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
|
2013-07-31 14:58:39 +00:00
|
|
|
HValue* alloc_site = Add<HLoadNamedField>(property_cell,
|
|
|
|
HObjectAccess::ForCellValue());
|
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:
|
|
|
|
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();
|
|
|
|
|
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,
|
|
|
|
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();
|
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();
|
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
|
|
|
|
2013-07-31 14:58:39 +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
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-03 06:57:16 +00:00
|
|
|
Handle<Code> ArrayNoArgumentConstructorStub::GenerateCode(Isolate* isolate) {
|
|
|
|
return DoGenerateCode(isolate, 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
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-03 06:57:16 +00:00
|
|
|
Handle<Code> ArraySingleArgumentConstructorStub::GenerateCode(
|
|
|
|
Isolate* isolate) {
|
|
|
|
return DoGenerateCode(isolate, 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
|
|
|
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-09-03 06:57:16 +00:00
|
|
|
Handle<Code> ArrayNArgumentsConstructorStub::GenerateCode(Isolate* isolate) {
|
|
|
|
return DoGenerateCode(isolate, 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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-03 06:57:16 +00:00
|
|
|
Handle<Code> InternalArrayNoArgumentConstructorStub::GenerateCode(
|
|
|
|
Isolate* isolate) {
|
|
|
|
return DoGenerateCode(isolate, this);
|
2013-06-05 10:43:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <>
|
|
|
|
HValue* CodeStubGraphBuilder<InternalArraySingleArgumentConstructorStub>::
|
|
|
|
BuildCodeStub() {
|
|
|
|
ElementsKind kind = casted_stub()->elements_kind();
|
|
|
|
return BuildInternalArrayConstructor(kind, SINGLE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-03 06:57:16 +00:00
|
|
|
Handle<Code> InternalArraySingleArgumentConstructorStub::GenerateCode(
|
|
|
|
Isolate* isolate) {
|
|
|
|
return DoGenerateCode(isolate, this);
|
2013-06-05 10:43:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <>
|
|
|
|
HValue* CodeStubGraphBuilder<InternalArrayNArgumentsConstructorStub>::
|
|
|
|
BuildCodeStub() {
|
|
|
|
ElementsKind kind = casted_stub()->elements_kind();
|
|
|
|
return BuildInternalArrayConstructor(kind, MULTIPLE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-03 06:57:16 +00:00
|
|
|
Handle<Code> InternalArrayNArgumentsConstructorStub::GenerateCode(
|
|
|
|
Isolate* isolate) {
|
|
|
|
return DoGenerateCode(isolate, 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());
|
2013-07-11 17:20:57 +00:00
|
|
|
Handle<Type> type = stub->GetType(isolate, sentinel_map);
|
2013-10-21 13:35:48 +00:00
|
|
|
BuildCompareNil(GetParameter(0), type, &continuation);
|
2013-04-24 11:32:17 +00:00
|
|
|
IfBuilder if_nil(this, &continuation);
|
|
|
|
if_nil.Then();
|
|
|
|
if (continuation.IsFalseReachable()) {
|
|
|
|
if_nil.Else();
|
2013-05-27 08:43:58 +00:00
|
|
|
if_nil.Return(graph()->GetConstant0());
|
2013-04-24 11:32:17 +00:00
|
|
|
}
|
|
|
|
if_nil.End();
|
|
|
|
return continuation.IsTrueReachable()
|
2013-05-27 08:43:58 +00:00
|
|
|
? graph()->GetConstant1()
|
2013-04-24 11:32:17 +00:00
|
|
|
: graph()->GetConstantUndefined();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-03 06:57:16 +00:00
|
|
|
Handle<Code> CompareNilICStub::GenerateCode(Isolate* isolate) {
|
|
|
|
return DoGenerateCode(isolate, 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() {
|
|
|
|
BinaryOpIC::State 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);
|
|
|
|
|
|
|
|
Handle<Type> left_type = state.GetLeftType(isolate());
|
|
|
|
Handle<Type> right_type = state.GetRightType(isolate());
|
|
|
|
Handle<Type> result_type = state.GetResultType(isolate());
|
2013-10-04 08:17:11 +00:00
|
|
|
|
|
|
|
ASSERT(!left_type->Is(Type::None()) && !right_type->Is(Type::None()) &&
|
2013-12-02 13:14:07 +00:00
|
|
|
(state.HasSideEffects() || !result_type->Is(Type::None())));
|
2013-10-04 08:17:11 +00:00
|
|
|
|
|
|
|
HValue* result = NULL;
|
2014-01-02 15:31:27 +00:00
|
|
|
HAllocationMode allocation_mode(NOT_TENURED);
|
2013-12-02 13:14:07 +00:00
|
|
|
if (state.op() == Token::ADD &&
|
2013-10-04 08:17:11 +00:00
|
|
|
(left_type->Maybe(Type::String()) || right_type->Maybe(Type::String())) &&
|
|
|
|
!left_type->Is(Type::String()) && !right_type->Is(Type::String())) {
|
2013-10-21 12:42:08 +00:00
|
|
|
// For the generic add stub a fast case for string addition is performance
|
2013-10-04 08:17:11 +00:00
|
|
|
// critical.
|
|
|
|
if (left_type->Maybe(Type::String())) {
|
2013-10-21 12:42:08 +00:00
|
|
|
IfBuilder if_leftisstring(this);
|
|
|
|
if_leftisstring.If<HIsStringAndBranch>(left);
|
|
|
|
if_leftisstring.Then();
|
|
|
|
{
|
2013-11-20 12:00:57 +00:00
|
|
|
Push(BuildBinaryOperation(
|
2013-12-02 13:14:07 +00:00
|
|
|
state.op(), left, right,
|
2013-10-21 12:42:08 +00:00
|
|
|
handle(Type::String(), isolate()), right_type,
|
2014-01-02 15:31:27 +00:00
|
|
|
result_type, state.fixed_right_arg(),
|
|
|
|
allocation_mode));
|
2013-10-21 12:42:08 +00:00
|
|
|
}
|
|
|
|
if_leftisstring.Else();
|
|
|
|
{
|
2013-11-20 12:00:57 +00:00
|
|
|
Push(BuildBinaryOperation(
|
2013-12-02 13:14:07 +00:00
|
|
|
state.op(), left, right,
|
2013-12-04 09:27:48 +00:00
|
|
|
left_type, right_type, result_type,
|
2014-01-02 15:31:27 +00:00
|
|
|
state.fixed_right_arg(), allocation_mode));
|
2013-10-21 12:42:08 +00:00
|
|
|
}
|
|
|
|
if_leftisstring.End();
|
2013-10-04 08:17:11 +00:00
|
|
|
result = Pop();
|
|
|
|
} else {
|
2013-10-21 12:42:08 +00:00
|
|
|
IfBuilder if_rightisstring(this);
|
|
|
|
if_rightisstring.If<HIsStringAndBranch>(right);
|
|
|
|
if_rightisstring.Then();
|
|
|
|
{
|
2013-11-20 12:00:57 +00:00
|
|
|
Push(BuildBinaryOperation(
|
2013-12-02 13:14:07 +00:00
|
|
|
state.op(), left, right,
|
2013-10-21 12:42:08 +00:00
|
|
|
left_type, handle(Type::String(), isolate()),
|
2014-01-02 15:31:27 +00:00
|
|
|
result_type, state.fixed_right_arg(),
|
|
|
|
allocation_mode));
|
2013-10-21 12:42:08 +00:00
|
|
|
}
|
|
|
|
if_rightisstring.Else();
|
|
|
|
{
|
2013-11-20 12:00:57 +00:00
|
|
|
Push(BuildBinaryOperation(
|
2013-12-02 13:14:07 +00:00
|
|
|
state.op(), left, right,
|
2013-12-04 09:27:48 +00:00
|
|
|
left_type, right_type, result_type,
|
2014-01-02 15:31:27 +00:00
|
|
|
state.fixed_right_arg(), allocation_mode));
|
2013-10-21 12:42:08 +00:00
|
|
|
}
|
|
|
|
if_rightisstring.End();
|
2013-10-04 08:17:11 +00:00
|
|
|
result = Pop();
|
|
|
|
}
|
|
|
|
} else {
|
2013-11-20 12:00:57 +00:00
|
|
|
result = BuildBinaryOperation(
|
2013-12-02 13:14:07 +00:00
|
|
|
state.op(), left, right,
|
2013-12-04 09:27:48 +00:00
|
|
|
left_type, right_type, result_type,
|
2014-01-02 15:31:27 +00:00
|
|
|
state.fixed_right_arg(), allocation_mode);
|
2013-10-04 08:17:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// If we encounter a generic argument, the number conversion is
|
|
|
|
// observable, thus we cannot afford to bail out after the fact.
|
2013-12-02 13:14:07 +00:00
|
|
|
if (!state.HasSideEffects()) {
|
2013-10-04 08:17:11 +00:00
|
|
|
if (result_type->Is(Type::Smi())) {
|
2013-12-02 13:14:07 +00:00
|
|
|
if (state.op() == Token::SHR) {
|
2013-10-04 08:17:11 +00:00
|
|
|
// TODO(olivf) Replace this by a SmiTagU Instruction.
|
|
|
|
// 0x40000000: this number would convert to negative when interpreting
|
|
|
|
// the register as signed value;
|
|
|
|
IfBuilder if_of(this);
|
|
|
|
if_of.IfNot<HCompareNumericAndBranch>(result,
|
|
|
|
Add<HConstant>(static_cast<int>(SmiValuesAre32Bits()
|
|
|
|
? 0x80000000 : 0x40000000)), Token::EQ_STRICT);
|
|
|
|
if_of.Then();
|
|
|
|
if_of.ElseDeopt("UInt->Smi oveflow");
|
|
|
|
if_of.End();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
result = EnforceNumberType(result, result_type);
|
|
|
|
}
|
|
|
|
|
2013-10-14 09:22:34 +00:00
|
|
|
// Reuse the double box of one of the operands if we are allowed to (i.e.
|
|
|
|
// chained binops).
|
2013-12-02 13:14:07 +00:00
|
|
|
if (state.CanReuseDoubleBox()) {
|
|
|
|
HValue* operand = (state.mode() == OVERWRITE_LEFT) ? left : right;
|
2013-10-04 08:17:11 +00:00
|
|
|
IfBuilder if_heap_number(this);
|
2013-10-14 09:22:34 +00:00
|
|
|
if_heap_number.IfNot<HIsSmiAndBranch>(operand);
|
2013-10-04 08:17:11 +00:00
|
|
|
if_heap_number.Then();
|
2013-10-14 09:22:34 +00:00
|
|
|
Add<HStoreNamedField>(operand, HObjectAccess::ForHeapNumberValue(), result);
|
|
|
|
Push(operand);
|
2013-10-04 08:17:11 +00:00
|
|
|
if_heap_number.Else();
|
|
|
|
Push(result);
|
|
|
|
if_heap_number.End();
|
|
|
|
result = Pop();
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-12-02 13:14:07 +00:00
|
|
|
Handle<Code> BinaryOpICStub::GenerateCode(Isolate* isolate) {
|
2013-10-04 08:17:11 +00:00
|
|
|
return DoGenerateCode(isolate, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-01-02 15:31:27 +00:00
|
|
|
template <>
|
|
|
|
HValue* CodeStubGraphBuilder<BinaryOpWithAllocationSiteStub>::BuildCodeStub() {
|
|
|
|
BinaryOpIC::State state = casted_stub()->state();
|
|
|
|
|
|
|
|
HValue* allocation_site = GetParameter(
|
|
|
|
BinaryOpWithAllocationSiteStub::kAllocationSite);
|
|
|
|
HValue* left = GetParameter(BinaryOpWithAllocationSiteStub::kLeft);
|
|
|
|
HValue* right = GetParameter(BinaryOpWithAllocationSiteStub::kRight);
|
|
|
|
|
|
|
|
Handle<Type> left_type = state.GetLeftType(isolate());
|
|
|
|
Handle<Type> right_type = state.GetRightType(isolate());
|
|
|
|
Handle<Type> result_type = state.GetResultType(isolate());
|
|
|
|
HAllocationMode allocation_mode(allocation_site);
|
|
|
|
|
|
|
|
return BuildBinaryOperation(state.op(), left, right,
|
|
|
|
left_type, right_type, result_type,
|
|
|
|
state.fixed_right_arg(), allocation_mode);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<Code> BinaryOpWithAllocationSiteStub::GenerateCode(Isolate* isolate) {
|
|
|
|
return DoGenerateCode(isolate, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-12 10:21:08 +00:00
|
|
|
template <>
|
|
|
|
HValue* CodeStubGraphBuilder<NewStringAddStub>::BuildCodeInitializedStub() {
|
|
|
|
NewStringAddStub* stub = casted_stub();
|
|
|
|
StringAddFlags flags = stub->flags();
|
|
|
|
PretenureFlag pretenure_flag = stub->pretenure_flag();
|
|
|
|
|
|
|
|
HValue* left = GetParameter(NewStringAddStub::kLeft);
|
|
|
|
HValue* right = GetParameter(NewStringAddStub::kRight);
|
|
|
|
|
|
|
|
// 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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<Code> NewStringAddStub::GenerateCode(Isolate* isolate) {
|
|
|
|
return DoGenerateCode(isolate, 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();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-03 06:57:16 +00:00
|
|
|
Handle<Code> ToBooleanStub::GenerateCode(Isolate* isolate) {
|
|
|
|
return DoGenerateCode(isolate, this);
|
2013-05-29 14:49:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-07-05 10:34:02 +00:00
|
|
|
template <>
|
|
|
|
HValue* CodeStubGraphBuilder<StoreGlobalStub>::BuildCodeInitializedStub() {
|
|
|
|
StoreGlobalStub* stub = casted_stub();
|
|
|
|
Handle<Object> 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();
|
2013-07-31 14:58:39 +00:00
|
|
|
Add<HCheckMaps>(receiver, placeholder_map, top_info());
|
2013-07-05 10:40:14 +00:00
|
|
|
|
2013-07-31 14:58:39 +00:00
|
|
|
HValue* cell = Add<HConstant>(placeholder_cell);
|
2013-07-22 14:15:58 +00:00
|
|
|
HObjectAccess access(HObjectAccess::ForCellPayload(isolate()));
|
|
|
|
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();
|
2013-08-09 12:50:42 +00:00
|
|
|
builder.ElseDeopt("Unexpected cell contents in constant global store");
|
2013-07-22 14:15:58 +00:00
|
|
|
builder.End();
|
|
|
|
} else {
|
2013-07-05 10:34:02 +00:00
|
|
|
// Load the payload of the global parameter cell. A hole indicates that the
|
|
|
|
// property has been deleted and that the store must be handled by the
|
|
|
|
// runtime.
|
|
|
|
IfBuilder builder(this);
|
2013-07-31 14:58:39 +00:00
|
|
|
HValue* hole_value = Add<HConstant>(hole);
|
2013-07-05 10:34:02 +00:00
|
|
|
builder.If<HCompareObjectEqAndBranch>(cell_contents, hole_value);
|
|
|
|
builder.Then();
|
2013-08-09 12:50:42 +00:00
|
|
|
builder.Deopt("Unexpected cell contents in global store");
|
2013-07-05 10:34:02 +00:00
|
|
|
builder.Else();
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-03 06:57:16 +00:00
|
|
|
Handle<Code> StoreGlobalStub::GenerateCode(Isolate* isolate) {
|
|
|
|
return DoGenerateCode(isolate, this);
|
2013-07-05 10:34:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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.
|
2013-09-04 07:27:10 +00:00
|
|
|
Add<HDeoptimize>("Tracing elements transitions", Deoptimizer::EAGER);
|
2013-07-17 11:37:20 +00:00
|
|
|
} else {
|
|
|
|
info()->MarkAsSavesCallerDoubles();
|
|
|
|
|
|
|
|
BuildTransitionElementsKind(object, map,
|
|
|
|
casted_stub()->from_kind(),
|
|
|
|
casted_stub()->to_kind(),
|
|
|
|
casted_stub()->is_jsarray());
|
|
|
|
|
2013-08-26 12:28:08 +00:00
|
|
|
BuildUncheckedMonomorphicElementAccess(object, key, value,
|
|
|
|
casted_stub()->is_jsarray(),
|
|
|
|
casted_stub()->to_kind(),
|
|
|
|
true, ALLOW_RETURN_HOLE,
|
|
|
|
casted_stub()->store_mode());
|
2013-07-17 11:37:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-03 06:57:16 +00:00
|
|
|
Handle<Code> ElementsTransitionAndStoreStub::GenerateCode(Isolate* isolate) {
|
|
|
|
return DoGenerateCode(isolate, this);
|
2013-07-17 11:37:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-08-27 11:55:08 +00:00
|
|
|
void CodeStubGraphBuilderBase::BuildInstallOptimizedCode(
|
|
|
|
HValue* js_function,
|
|
|
|
HValue* native_context,
|
|
|
|
HValue* code_object) {
|
|
|
|
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);
|
|
|
|
|
|
|
|
// Now link a function into a list of optimized functions.
|
|
|
|
HValue* optimized_functions_list = Add<HLoadNamedField>(native_context,
|
|
|
|
HObjectAccess::ForContextSlot(Context::OPTIMIZED_FUNCTIONS_LIST));
|
|
|
|
Add<HStoreNamedField>(js_function,
|
|
|
|
HObjectAccess::ForNextFunctionLinkPointer(),
|
|
|
|
optimized_functions_list);
|
|
|
|
|
|
|
|
// This store is the only one that should have a write barrier.
|
|
|
|
Add<HStoreNamedField>(native_context,
|
|
|
|
HObjectAccess::ForContextSlot(Context::OPTIMIZED_FUNCTIONS_LIST),
|
|
|
|
js_function);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CodeStubGraphBuilderBase::BuildInstallCode(HValue* js_function,
|
|
|
|
HValue* shared_info) {
|
|
|
|
Add<HStoreNamedField>(js_function,
|
|
|
|
HObjectAccess::ForNextFunctionLinkPointer(),
|
|
|
|
graph()->GetConstantUndefined());
|
|
|
|
HValue* code_object = Add<HLoadNamedField>(shared_info,
|
|
|
|
HObjectAccess::ForCodeOffset());
|
|
|
|
Add<HStoreCodeEntry>(js_function, code_object);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CodeStubGraphBuilderBase::BuildInstallFromOptimizedCodeMap(
|
|
|
|
HValue* js_function,
|
|
|
|
HValue* shared_info,
|
|
|
|
HValue* native_context) {
|
|
|
|
Counters* counters = isolate()->counters();
|
|
|
|
IfBuilder is_optimized(this);
|
|
|
|
HInstruction* optimized_map = Add<HLoadNamedField>(shared_info,
|
|
|
|
HObjectAccess::ForOptimizedCodeMap());
|
|
|
|
HValue* null_constant = Add<HConstant>(0);
|
|
|
|
is_optimized.If<HCompareObjectEqAndBranch>(optimized_map, null_constant);
|
|
|
|
is_optimized.Then();
|
|
|
|
{
|
|
|
|
BuildInstallCode(js_function, shared_info);
|
|
|
|
}
|
|
|
|
is_optimized.Else();
|
|
|
|
{
|
2013-09-16 11:30:10 +00:00
|
|
|
AddIncrementCounter(counters->fast_new_closure_try_optimized());
|
2013-08-27 11:55:08 +00:00
|
|
|
// optimized_map points to fixed array of 3-element entries
|
|
|
|
// (native context, optimized code, literals).
|
|
|
|
// Map must never be empty, so check the first elements.
|
|
|
|
Label install_optimized;
|
|
|
|
HValue* first_context_slot = Add<HLoadNamedField>(optimized_map,
|
|
|
|
HObjectAccess::ForFirstContextSlot());
|
2013-12-23 14:42:42 +00:00
|
|
|
HValue* first_osr_ast_slot = Add<HLoadNamedField>(optimized_map,
|
|
|
|
HObjectAccess::ForFirstOsrAstIdSlot());
|
|
|
|
HValue* osr_ast_id_none = Add<HConstant>(BailoutId::None().ToInt());
|
2013-08-27 11:55:08 +00:00
|
|
|
IfBuilder already_in(this);
|
|
|
|
already_in.If<HCompareObjectEqAndBranch>(native_context,
|
|
|
|
first_context_slot);
|
2013-12-23 14:42:42 +00:00
|
|
|
already_in.AndIf<HCompareObjectEqAndBranch>(first_osr_ast_slot,
|
|
|
|
osr_ast_id_none);
|
2013-08-27 11:55:08 +00:00
|
|
|
already_in.Then();
|
|
|
|
{
|
|
|
|
HValue* code_object = Add<HLoadNamedField>(optimized_map,
|
|
|
|
HObjectAccess::ForFirstCodeSlot());
|
|
|
|
BuildInstallOptimizedCode(js_function, native_context, code_object);
|
|
|
|
}
|
|
|
|
already_in.Else();
|
|
|
|
{
|
|
|
|
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,
|
|
|
|
HObjectAccess::ForFixedArrayLength());
|
2013-12-23 14:42:42 +00:00
|
|
|
HValue* slot_iterator = loop_builder.BeginBody(array_length,
|
2013-08-27 11:55:08 +00:00
|
|
|
graph()->GetConstant0(),
|
|
|
|
Token::GT);
|
|
|
|
{
|
|
|
|
// Iterate through the rest of map backwards.
|
|
|
|
// Do not double check first entry.
|
|
|
|
HValue* second_entry_index =
|
|
|
|
Add<HConstant>(SharedFunctionInfo::kSecondEntryIndex);
|
|
|
|
IfBuilder restore_check(this);
|
2013-12-23 14:42:42 +00:00
|
|
|
restore_check.If<HCompareNumericAndBranch>(
|
|
|
|
slot_iterator, second_entry_index, Token::EQ);
|
2013-08-27 11:55:08 +00:00
|
|
|
restore_check.Then();
|
|
|
|
{
|
|
|
|
// Store the unoptimized code
|
|
|
|
BuildInstallCode(js_function, shared_info);
|
|
|
|
loop_builder.Break();
|
|
|
|
}
|
|
|
|
restore_check.Else();
|
|
|
|
{
|
2013-12-23 14:42:42 +00:00
|
|
|
STATIC_ASSERT(SharedFunctionInfo::kContextOffset == 0);
|
|
|
|
STATIC_ASSERT(SharedFunctionInfo::kEntryLength -
|
|
|
|
SharedFunctionInfo::kOsrAstIdOffset == 1);
|
|
|
|
HValue* native_context_slot = AddUncasted<HSub>(
|
|
|
|
slot_iterator, shared_function_entry_length);
|
|
|
|
HValue* osr_ast_id_slot = AddUncasted<HSub>(
|
|
|
|
slot_iterator, graph()->GetConstant1());
|
|
|
|
HInstruction* native_context_entry = Add<HLoadKeyed>(optimized_map,
|
|
|
|
native_context_slot, static_cast<HValue*>(NULL), FAST_ELEMENTS);
|
|
|
|
HInstruction* osr_ast_id_entry = Add<HLoadKeyed>(optimized_map,
|
|
|
|
osr_ast_id_slot, static_cast<HValue*>(NULL), FAST_ELEMENTS);
|
2013-08-27 11:55:08 +00:00
|
|
|
IfBuilder done_check(this);
|
|
|
|
done_check.If<HCompareObjectEqAndBranch>(native_context,
|
2013-12-23 14:42:42 +00:00
|
|
|
native_context_entry);
|
|
|
|
done_check.AndIf<HCompareObjectEqAndBranch>(osr_ast_id_entry,
|
|
|
|
osr_ast_id_none);
|
2013-08-27 11:55:08 +00:00
|
|
|
done_check.Then();
|
|
|
|
{
|
|
|
|
// Hit: fetch the optimized code.
|
2013-12-23 14:42:42 +00:00
|
|
|
HValue* code_slot = AddUncasted<HAdd>(
|
|
|
|
native_context_slot, graph()->GetConstant1());
|
2013-08-27 11:55:08 +00:00
|
|
|
HValue* code_object = Add<HLoadKeyed>(optimized_map,
|
2013-12-23 14:42:42 +00:00
|
|
|
code_slot, static_cast<HValue*>(NULL), FAST_ELEMENTS);
|
2013-08-27 11:55:08 +00:00
|
|
|
BuildInstallOptimizedCode(js_function, native_context, code_object);
|
|
|
|
|
|
|
|
// Fall out of the loop
|
|
|
|
loop_builder.Break();
|
|
|
|
}
|
|
|
|
done_check.Else();
|
|
|
|
done_check.End();
|
|
|
|
}
|
|
|
|
restore_check.End();
|
|
|
|
}
|
|
|
|
loop_builder.EndBody();
|
|
|
|
}
|
|
|
|
already_in.End();
|
|
|
|
}
|
|
|
|
is_optimized.End();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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());
|
|
|
|
|
2013-08-27 11:55:08 +00:00
|
|
|
// Create a new closure from the given function info in new space
|
|
|
|
HValue* size = Add<HConstant>(JSFunction::kSize);
|
|
|
|
HInstruction* js_function = Add<HAllocate>(size, HType::JSObject(),
|
|
|
|
NOT_TENURED, JS_FUNCTION_TYPE);
|
|
|
|
|
|
|
|
int map_index = Context::FunctionMapIndex(casted_stub()->language_mode(),
|
|
|
|
casted_stub()->is_generator());
|
|
|
|
|
|
|
|
// Compute the function map in the current native context and set that
|
|
|
|
// as the map of the allocated object.
|
|
|
|
HInstruction* native_context = BuildGetNativeContext();
|
|
|
|
HInstruction* map_slot_value = Add<HLoadNamedField>(native_context,
|
|
|
|
HObjectAccess::ForContextSlot(map_index));
|
|
|
|
Add<HStoreNamedField>(js_function, HObjectAccess::ForMap(), map_slot_value);
|
|
|
|
|
|
|
|
// Initialize the rest of the function.
|
|
|
|
Add<HStoreNamedField>(js_function, HObjectAccess::ForPropertiesPointer(),
|
|
|
|
empty_fixed_array);
|
|
|
|
Add<HStoreNamedField>(js_function, HObjectAccess::ForElementsPointer(),
|
|
|
|
empty_fixed_array);
|
|
|
|
Add<HStoreNamedField>(js_function, HObjectAccess::ForLiteralsPointer(),
|
|
|
|
empty_fixed_array);
|
|
|
|
Add<HStoreNamedField>(js_function, HObjectAccess::ForPrototypeOrInitialMap(),
|
|
|
|
graph()->GetConstantHole());
|
|
|
|
Add<HStoreNamedField>(js_function,
|
|
|
|
HObjectAccess::ForSharedFunctionInfoPointer(),
|
|
|
|
shared_info);
|
|
|
|
Add<HStoreNamedField>(js_function, HObjectAccess::ForFunctionContextPointer(),
|
|
|
|
context());
|
|
|
|
|
|
|
|
// Initialize the code pointer in the function to be the one
|
|
|
|
// found in the shared function info object.
|
|
|
|
// But first check if there is an optimized version for our context.
|
|
|
|
if (FLAG_cache_optimized_code) {
|
|
|
|
BuildInstallFromOptimizedCodeMap(js_function, shared_info, native_context);
|
|
|
|
} else {
|
|
|
|
BuildInstallCode(js_function, shared_info);
|
|
|
|
}
|
|
|
|
|
|
|
|
return js_function;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-03 06:57:16 +00:00
|
|
|
Handle<Code> FastNewClosureStub::GenerateCode(Isolate* isolate) {
|
|
|
|
return DoGenerateCode(isolate, this);
|
2013-08-27 11:55:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-16 15:22:09 +00:00
|
|
|
template<>
|
2013-11-15 17:53:35 +00:00
|
|
|
HValue* CodeStubGraphBuilder<KeyedLoadDictionaryElementStub>::BuildCodeStub() {
|
2013-11-16 15:22:09 +00:00
|
|
|
HValue* receiver = GetParameter(0);
|
2013-11-15 17:53:35 +00:00
|
|
|
HValue* key = GetParameter(1);
|
|
|
|
|
|
|
|
Add<HCheckSmi>(key);
|
|
|
|
|
2013-11-16 15:22:09 +00:00
|
|
|
return BuildUncheckedDictionaryElementLoad(receiver, key);
|
2013-11-15 17:53:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<Code> KeyedLoadDictionaryElementStub::GenerateCode(Isolate* isolate) {
|
|
|
|
return DoGenerateCode(isolate, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-12-18 16:25:45 +00:00
|
|
|
} } // namespace v8::internal
|