OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #include "src/code-stubs.h" | 7 #include "src/code-stubs.h" |
8 #include "src/field-index.h" | 8 #include "src/field-index.h" |
9 #include "src/hydrogen.h" | 9 #include "src/hydrogen.h" |
10 #include "src/lithium.h" | 10 #include "src/lithium.h" |
(...skipping 20 matching lines...) Expand all Loading... |
31 } | 31 } |
32 | 32 |
33 | 33 |
34 class CodeStubGraphBuilderBase : public HGraphBuilder { | 34 class CodeStubGraphBuilderBase : public HGraphBuilder { |
35 public: | 35 public: |
36 CodeStubGraphBuilderBase(Isolate* isolate, HydrogenCodeStub* stub) | 36 CodeStubGraphBuilderBase(Isolate* isolate, HydrogenCodeStub* stub) |
37 : HGraphBuilder(&info_), | 37 : HGraphBuilder(&info_), |
38 arguments_length_(NULL), | 38 arguments_length_(NULL), |
39 info_(stub, isolate), | 39 info_(stub, isolate), |
40 context_(NULL) { | 40 context_(NULL) { |
41 descriptor_ = stub->GetInterfaceDescriptor(); | 41 stub->InitializeInterfaceDescriptor(&descriptor_); |
42 int parameter_count = descriptor_->GetEnvironmentParameterCount(); | 42 int parameter_count = descriptor_.GetEnvironmentParameterCount(); |
43 parameters_.Reset(new HParameter*[parameter_count]); | 43 parameters_.Reset(new HParameter*[parameter_count]); |
44 } | 44 } |
45 virtual bool BuildGraph(); | 45 virtual bool BuildGraph(); |
46 | 46 |
47 protected: | 47 protected: |
48 virtual HValue* BuildCodeStub() = 0; | 48 virtual HValue* BuildCodeStub() = 0; |
49 HParameter* GetParameter(int parameter) { | 49 HParameter* GetParameter(int parameter) { |
50 DCHECK(parameter < descriptor_->GetEnvironmentParameterCount()); | 50 DCHECK(parameter < descriptor_.GetEnvironmentParameterCount()); |
51 return parameters_[parameter]; | 51 return parameters_[parameter]; |
52 } | 52 } |
53 HValue* GetArgumentsLength() { | 53 HValue* GetArgumentsLength() { |
54 // This is initialized in BuildGraph() | 54 // This is initialized in BuildGraph() |
55 DCHECK(arguments_length_ != NULL); | 55 DCHECK(arguments_length_ != NULL); |
56 return arguments_length_; | 56 return arguments_length_; |
57 } | 57 } |
58 CompilationInfo* info() { return &info_; } | 58 CompilationInfo* info() { return &info_; } |
59 HydrogenCodeStub* stub() { return info_.code_stub(); } | 59 HydrogenCodeStub* stub() { return info_.code_stub(); } |
60 HContext* context() { return context_; } | 60 HContext* context() { return context_; } |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 HValue* native_context); | 96 HValue* native_context); |
97 | 97 |
98 private: | 98 private: |
99 HValue* BuildArraySingleArgumentConstructor(JSArrayBuilder* builder); | 99 HValue* BuildArraySingleArgumentConstructor(JSArrayBuilder* builder); |
100 HValue* BuildArrayNArgumentsConstructor(JSArrayBuilder* builder, | 100 HValue* BuildArrayNArgumentsConstructor(JSArrayBuilder* builder, |
101 ElementsKind kind); | 101 ElementsKind kind); |
102 | 102 |
103 SmartArrayPointer<HParameter*> parameters_; | 103 SmartArrayPointer<HParameter*> parameters_; |
104 HValue* arguments_length_; | 104 HValue* arguments_length_; |
105 CompilationInfoWithZone info_; | 105 CompilationInfoWithZone info_; |
106 CodeStubInterfaceDescriptor* descriptor_; | 106 CodeStubInterfaceDescriptor descriptor_; |
107 HContext* context_; | 107 HContext* context_; |
108 }; | 108 }; |
109 | 109 |
110 | 110 |
111 bool CodeStubGraphBuilderBase::BuildGraph() { | 111 bool CodeStubGraphBuilderBase::BuildGraph() { |
112 // Update the static counter each time a new code stub is generated. | 112 // Update the static counter each time a new code stub is generated. |
113 isolate()->counters()->code_stubs()->Increment(); | 113 isolate()->counters()->code_stubs()->Increment(); |
114 | 114 |
115 if (FLAG_trace_hydrogen_stubs) { | 115 if (FLAG_trace_hydrogen_stubs) { |
116 const char* name = CodeStub::MajorName(stub()->MajorKey(), false); | 116 const char* name = CodeStub::MajorName(stub()->MajorKey(), false); |
117 PrintF("-----------------------------------------------------------\n"); | 117 PrintF("-----------------------------------------------------------\n"); |
118 PrintF("Compiling stub %s using hydrogen\n", name); | 118 PrintF("Compiling stub %s using hydrogen\n", name); |
119 isolate()->GetHTracer()->TraceCompilation(&info_); | 119 isolate()->GetHTracer()->TraceCompilation(&info_); |
120 } | 120 } |
121 | 121 |
122 int param_count = descriptor_->GetEnvironmentParameterCount(); | 122 int param_count = descriptor_.GetEnvironmentParameterCount(); |
123 HEnvironment* start_environment = graph()->start_environment(); | 123 HEnvironment* start_environment = graph()->start_environment(); |
124 HBasicBlock* next_block = CreateBasicBlock(start_environment); | 124 HBasicBlock* next_block = CreateBasicBlock(start_environment); |
125 Goto(next_block); | 125 Goto(next_block); |
126 next_block->SetJoinId(BailoutId::StubEntry()); | 126 next_block->SetJoinId(BailoutId::StubEntry()); |
127 set_current_block(next_block); | 127 set_current_block(next_block); |
128 | 128 |
129 bool runtime_stack_params = descriptor_->stack_parameter_count().is_valid(); | 129 bool runtime_stack_params = descriptor_.stack_parameter_count().is_valid(); |
130 HInstruction* stack_parameter_count = NULL; | 130 HInstruction* stack_parameter_count = NULL; |
131 for (int i = 0; i < param_count; ++i) { | 131 for (int i = 0; i < param_count; ++i) { |
132 Representation r = descriptor_->GetEnvironmentParameterRepresentation(i); | 132 Representation r = descriptor_.GetEnvironmentParameterRepresentation(i); |
133 HParameter* param = Add<HParameter>(i, | 133 HParameter* param = Add<HParameter>(i, |
134 HParameter::REGISTER_PARAMETER, r); | 134 HParameter::REGISTER_PARAMETER, r); |
135 start_environment->Bind(i, param); | 135 start_environment->Bind(i, param); |
136 parameters_[i] = param; | 136 parameters_[i] = param; |
137 if (descriptor_->IsEnvironmentParameterCountRegister(i)) { | 137 if (descriptor_.IsEnvironmentParameterCountRegister(i)) { |
138 param->set_type(HType::Smi()); | 138 param->set_type(HType::Smi()); |
139 stack_parameter_count = param; | 139 stack_parameter_count = param; |
140 arguments_length_ = stack_parameter_count; | 140 arguments_length_ = stack_parameter_count; |
141 } | 141 } |
142 } | 142 } |
143 | 143 |
144 DCHECK(!runtime_stack_params || arguments_length_ != NULL); | 144 DCHECK(!runtime_stack_params || arguments_length_ != NULL); |
145 if (!runtime_stack_params) { | 145 if (!runtime_stack_params) { |
146 stack_parameter_count = graph()->GetConstantMinus1(); | 146 stack_parameter_count = graph()->GetConstantMinus1(); |
147 arguments_length_ = graph()->GetConstant0(); | 147 arguments_length_ = graph()->GetConstant0(); |
148 } | 148 } |
149 | 149 |
150 context_ = Add<HContext>(); | 150 context_ = Add<HContext>(); |
151 start_environment->BindContext(context_); | 151 start_environment->BindContext(context_); |
152 | 152 |
153 Add<HSimulate>(BailoutId::StubEntry()); | 153 Add<HSimulate>(BailoutId::StubEntry()); |
154 | 154 |
155 NoObservableSideEffectsScope no_effects(this); | 155 NoObservableSideEffectsScope no_effects(this); |
156 | 156 |
157 HValue* return_value = BuildCodeStub(); | 157 HValue* return_value = BuildCodeStub(); |
158 | 158 |
159 // We might have extra expressions to pop from the stack in addition to the | 159 // We might have extra expressions to pop from the stack in addition to the |
160 // arguments above. | 160 // arguments above. |
161 HInstruction* stack_pop_count = stack_parameter_count; | 161 HInstruction* stack_pop_count = stack_parameter_count; |
162 if (descriptor_->function_mode() == JS_FUNCTION_STUB_MODE) { | 162 if (descriptor_.function_mode() == JS_FUNCTION_STUB_MODE) { |
163 if (!stack_parameter_count->IsConstant() && | 163 if (!stack_parameter_count->IsConstant() && |
164 descriptor_->hint_stack_parameter_count() < 0) { | 164 descriptor_.hint_stack_parameter_count() < 0) { |
165 HInstruction* constant_one = graph()->GetConstant1(); | 165 HInstruction* constant_one = graph()->GetConstant1(); |
166 stack_pop_count = AddUncasted<HAdd>(stack_parameter_count, constant_one); | 166 stack_pop_count = AddUncasted<HAdd>(stack_parameter_count, constant_one); |
167 stack_pop_count->ClearFlag(HValue::kCanOverflow); | 167 stack_pop_count->ClearFlag(HValue::kCanOverflow); |
168 // TODO(mvstanton): verify that stack_parameter_count+1 really fits in a | 168 // TODO(mvstanton): verify that stack_parameter_count+1 really fits in a |
169 // smi. | 169 // smi. |
170 } else { | 170 } else { |
171 int count = descriptor_->hint_stack_parameter_count(); | 171 int count = descriptor_.hint_stack_parameter_count(); |
172 stack_pop_count = Add<HConstant>(count); | 172 stack_pop_count = Add<HConstant>(count); |
173 } | 173 } |
174 } | 174 } |
175 | 175 |
176 if (current_block() != NULL) { | 176 if (current_block() != NULL) { |
177 HReturn* hreturn_instruction = New<HReturn>(return_value, | 177 HReturn* hreturn_instruction = New<HReturn>(return_value, |
178 stack_pop_count); | 178 stack_pop_count); |
179 FinishCurrentBlock(hreturn_instruction); | 179 FinishCurrentBlock(hreturn_instruction); |
180 } | 180 } |
181 return true; | 181 return true; |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 GetStubType()); | 244 GetStubType()); |
245 Handle<Code> new_object = factory->NewCode( | 245 Handle<Code> new_object = factory->NewCode( |
246 desc, flags, masm.CodeObject(), NeedsImmovableCode()); | 246 desc, flags, masm.CodeObject(), NeedsImmovableCode()); |
247 return new_object; | 247 return new_object; |
248 } | 248 } |
249 | 249 |
250 | 250 |
251 template <class Stub> | 251 template <class Stub> |
252 static Handle<Code> DoGenerateCode(Stub* stub) { | 252 static Handle<Code> DoGenerateCode(Stub* stub) { |
253 Isolate* isolate = stub->isolate(); | 253 Isolate* isolate = stub->isolate(); |
254 CodeStub::Major major_key = static_cast<CodeStub*>(stub)->MajorKey(); | 254 CodeStubInterfaceDescriptor descriptor; |
255 CodeStubInterfaceDescriptor* descriptor = | 255 stub->InitializeInterfaceDescriptor(&descriptor); |
256 isolate->code_stub_interface_descriptor(major_key); | |
257 if (!descriptor->IsInitialized()) { | |
258 stub->InitializeInterfaceDescriptor(descriptor); | |
259 } | |
260 | 256 |
261 // If we are uninitialized we can use a light-weight stub to enter | 257 // If we are uninitialized we can use a light-weight stub to enter |
262 // the runtime that is significantly faster than using the standard | 258 // the runtime that is significantly faster than using the standard |
263 // stub-failure deopt mechanism. | 259 // stub-failure deopt mechanism. |
264 if (stub->IsUninitialized() && descriptor->has_miss_handler()) { | 260 if (stub->IsUninitialized() && descriptor.has_miss_handler()) { |
265 DCHECK(!descriptor->stack_parameter_count().is_valid()); | 261 DCHECK(!descriptor.stack_parameter_count().is_valid()); |
266 return stub->GenerateLightweightMissCode(); | 262 return stub->GenerateLightweightMissCode(); |
267 } | 263 } |
268 base::ElapsedTimer timer; | 264 base::ElapsedTimer timer; |
269 if (FLAG_profile_hydrogen_code_stub_compilation) { | 265 if (FLAG_profile_hydrogen_code_stub_compilation) { |
270 timer.Start(); | 266 timer.Start(); |
271 } | 267 } |
272 CodeStubGraphBuilder<Stub> builder(isolate, stub); | 268 CodeStubGraphBuilder<Stub> builder(isolate, stub); |
273 LChunk* chunk = OptimizeGraph(builder.CreateGraph()); | 269 LChunk* chunk = OptimizeGraph(builder.CreateGraph()); |
274 // TODO(yangguo) remove this once the code serializer handles code stubs. | 270 // TODO(yangguo) remove this once the code serializer handles code stubs. |
275 if (FLAG_serialize_toplevel) chunk->info()->PrepareForSerializing(); | 271 if (FLAG_serialize_toplevel) chunk->info()->PrepareForSerializing(); |
(...skipping 1530 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1806 HValue* receiver = GetParameter(VectorLoadICDescriptor::kReceiverIndex); | 1802 HValue* receiver = GetParameter(VectorLoadICDescriptor::kReceiverIndex); |
1807 Add<HDeoptimize>("Always deopt", Deoptimizer::EAGER); | 1803 Add<HDeoptimize>("Always deopt", Deoptimizer::EAGER); |
1808 return receiver; | 1804 return receiver; |
1809 } | 1805 } |
1810 | 1806 |
1811 | 1807 |
1812 Handle<Code> VectorKeyedLoadStub::GenerateCode() { | 1808 Handle<Code> VectorKeyedLoadStub::GenerateCode() { |
1813 return DoGenerateCode(this); | 1809 return DoGenerateCode(this); |
1814 } | 1810 } |
1815 } } // namespace v8::internal | 1811 } } // namespace v8::internal |
OLD | NEW |