OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 if (chunk == NULL) { | 50 if (chunk == NULL) { |
51 FATAL(graph->info()->bailout_reason()); | 51 FATAL(graph->info()->bailout_reason()); |
52 } | 52 } |
53 return chunk; | 53 return chunk; |
54 } | 54 } |
55 | 55 |
56 | 56 |
57 class CodeStubGraphBuilderBase : public HGraphBuilder { | 57 class CodeStubGraphBuilderBase : public HGraphBuilder { |
58 public: | 58 public: |
59 CodeStubGraphBuilderBase(Isolate* isolate, HydrogenCodeStub* stub) | 59 CodeStubGraphBuilderBase(Isolate* isolate, HydrogenCodeStub* stub) |
60 : HGraphBuilder(&info_), info_(stub, isolate), context_(NULL) { | 60 : HGraphBuilder(&info_), |
| 61 arguments_length_(NULL), |
| 62 info_(stub, isolate), |
| 63 context_(NULL) { |
61 int major_key = stub->MajorKey(); | 64 int major_key = stub->MajorKey(); |
62 descriptor_ = isolate->code_stub_interface_descriptor(major_key); | 65 descriptor_ = isolate->code_stub_interface_descriptor(major_key); |
63 if (descriptor_->register_param_count_ < 0) { | 66 if (descriptor_->register_param_count_ < 0) { |
64 stub->InitializeInterfaceDescriptor(isolate, descriptor_); | 67 stub->InitializeInterfaceDescriptor(isolate, descriptor_); |
65 } | 68 } |
66 parameters_.Reset(new HParameter*[descriptor_->register_param_count_]); | 69 parameters_.Reset(new HParameter*[descriptor_->register_param_count_]); |
67 } | 70 } |
68 virtual bool BuildGraph(); | 71 virtual bool BuildGraph(); |
69 | 72 |
70 protected: | 73 protected: |
71 virtual void BuildCodeStub() = 0; | 74 virtual HValue* BuildCodeStub() = 0; |
72 HParameter* GetParameter(int parameter) { return parameters_[parameter]; } | 75 HParameter* GetParameter(int parameter) { |
| 76 ASSERT(parameter < descriptor_->register_param_count_); |
| 77 return parameters_[parameter]; |
| 78 } |
| 79 HValue* GetArgumentsLength() { |
| 80 // This is initialized in BuildGraph() |
| 81 ASSERT(arguments_length_ != NULL); |
| 82 return arguments_length_; |
| 83 } |
73 CompilationInfo* info() { return &info_; } | 84 CompilationInfo* info() { return &info_; } |
74 HydrogenCodeStub* stub() { return info_.code_stub(); } | 85 HydrogenCodeStub* stub() { return info_.code_stub(); } |
75 HContext* context() { return context_; } | 86 HContext* context() { return context_; } |
76 Isolate* isolate() { return info_.isolate(); } | 87 Isolate* isolate() { return info_.isolate(); } |
77 | 88 |
78 private: | 89 private: |
79 SmartArrayPointer<HParameter*> parameters_; | 90 SmartArrayPointer<HParameter*> parameters_; |
| 91 HValue* arguments_length_; |
80 CompilationInfoWithZone info_; | 92 CompilationInfoWithZone info_; |
81 CodeStubInterfaceDescriptor* descriptor_; | 93 CodeStubInterfaceDescriptor* descriptor_; |
82 HContext* context_; | 94 HContext* context_; |
83 }; | 95 }; |
84 | 96 |
85 | 97 |
86 bool CodeStubGraphBuilderBase::BuildGraph() { | 98 bool CodeStubGraphBuilderBase::BuildGraph() { |
87 if (FLAG_trace_hydrogen) { | 99 if (FLAG_trace_hydrogen) { |
88 const char* name = CodeStub::MajorName(stub()->MajorKey(), false); | 100 const char* name = CodeStub::MajorName(stub()->MajorKey(), false); |
89 PrintF("-----------------------------------------------------------\n"); | 101 PrintF("-----------------------------------------------------------\n"); |
90 PrintF("Compiling stub %s using hydrogen\n", name); | 102 PrintF("Compiling stub %s using hydrogen\n", name); |
91 isolate()->GetHTracer()->TraceCompilation(&info_); | 103 isolate()->GetHTracer()->TraceCompilation(&info_); |
92 } | 104 } |
93 | 105 |
94 Zone* zone = this->zone(); | 106 Zone* zone = this->zone(); |
| 107 int param_count = descriptor_->register_param_count_; |
| 108 int environment_length = param_count; |
| 109 if (descriptor_->stack_parameter_count_ != NULL) { |
| 110 environment_length += 1; |
| 111 } |
95 HEnvironment* start_environment = | 112 HEnvironment* start_environment = |
96 new(zone) HEnvironment(zone, descriptor_->register_param_count_); | 113 new(zone) HEnvironment(zone, environment_length); |
97 HBasicBlock* next_block = CreateBasicBlock(start_environment); | 114 HBasicBlock* next_block = CreateBasicBlock(start_environment); |
98 | 115 |
99 current_block()->Goto(next_block); | 116 current_block()->Goto(next_block); |
100 next_block->SetJoinId(BailoutId::StubEntry()); | 117 next_block->SetJoinId(BailoutId::StubEntry()); |
101 set_current_block(next_block); | 118 set_current_block(next_block); |
102 | 119 |
103 HConstant* undefined_constant = new(zone) HConstant( | 120 HConstant* undefined_constant = new(zone) HConstant( |
104 isolate()->factory()->undefined_value(), Representation::Tagged()); | 121 isolate()->factory()->undefined_value(), Representation::Tagged()); |
105 AddInstruction(undefined_constant); | 122 AddInstruction(undefined_constant); |
106 graph()->set_undefined_constant(undefined_constant); | 123 graph()->set_undefined_constant(undefined_constant); |
107 | 124 |
108 int param_count = descriptor_->register_param_count_; | |
109 for (int i = 0; i < param_count; ++i) { | 125 for (int i = 0; i < param_count; ++i) { |
110 HParameter* param = | 126 HParameter* param = |
111 new(zone) HParameter(i, HParameter::REGISTER_PARAMETER); | 127 new(zone) HParameter(i, HParameter::REGISTER_PARAMETER); |
112 AddInstruction(param); | 128 AddInstruction(param); |
113 start_environment->Bind(i, param); | 129 start_environment->Bind(i, param); |
114 parameters_[i] = param; | 130 parameters_[i] = param; |
115 } | 131 } |
116 | 132 |
| 133 HInstruction* stack_parameter_count; |
| 134 if (descriptor_->stack_parameter_count_ != NULL) { |
| 135 stack_parameter_count = new(zone) HParameter(param_count, |
| 136 HParameter::REGISTER_PARAMETER); |
| 137 ASSERT(environment_length == (param_count + 1)); |
| 138 // it's essential to bind this value to the environment in case of deopt |
| 139 start_environment->Bind(param_count, stack_parameter_count); |
| 140 AddInstruction(stack_parameter_count); |
| 141 } else { |
| 142 stack_parameter_count = graph()->GetConstant0(); |
| 143 } |
| 144 |
| 145 arguments_length_ = stack_parameter_count; |
| 146 |
117 context_ = new(zone) HContext(); | 147 context_ = new(zone) HContext(); |
118 AddInstruction(context_); | 148 AddInstruction(context_); |
119 start_environment->Bind(param_count, context_); | 149 start_environment->BindContext(context_); |
120 | 150 |
121 AddSimulate(BailoutId::StubEntry()); | 151 AddSimulate(BailoutId::StubEntry()); |
122 | 152 |
123 BuildCodeStub(); | 153 HValue* return_value = BuildCodeStub(); |
124 | 154 HReturn* hreturn_instruction = new(zone) HReturn(return_value, |
| 155 context_, |
| 156 stack_parameter_count); |
| 157 current_block()->Finish(hreturn_instruction); |
125 return true; | 158 return true; |
126 } | 159 } |
127 | 160 |
128 template <class Stub> | 161 template <class Stub> |
129 class CodeStubGraphBuilder: public CodeStubGraphBuilderBase { | 162 class CodeStubGraphBuilder: public CodeStubGraphBuilderBase { |
130 public: | 163 public: |
131 explicit CodeStubGraphBuilder(Stub* stub) | 164 explicit CodeStubGraphBuilder(Stub* stub) |
132 : CodeStubGraphBuilderBase(Isolate::Current(), stub) {} | 165 : CodeStubGraphBuilderBase(Isolate::Current(), stub) {} |
133 | 166 |
134 protected: | 167 protected: |
135 virtual void BuildCodeStub(); | 168 virtual HValue* BuildCodeStub(); |
136 Stub* casted_stub() { return static_cast<Stub*>(stub()); } | 169 Stub* casted_stub() { return static_cast<Stub*>(stub()); } |
137 }; | 170 }; |
138 | 171 |
139 | 172 |
140 template <> | 173 template <> |
141 void CodeStubGraphBuilder<FastCloneShallowObjectStub>::BuildCodeStub() { | 174 HValue* CodeStubGraphBuilder<FastCloneShallowObjectStub>::BuildCodeStub() { |
142 Zone* zone = this->zone(); | 175 Zone* zone = this->zone(); |
143 Factory* factory = isolate()->factory(); | 176 Factory* factory = isolate()->factory(); |
144 | 177 |
145 HInstruction* boilerplate = | 178 HInstruction* boilerplate = |
146 AddInstruction(new(zone) HLoadKeyed(GetParameter(0), | 179 AddInstruction(new(zone) HLoadKeyed(GetParameter(0), |
147 GetParameter(1), | 180 GetParameter(1), |
148 NULL, | 181 NULL, |
149 FAST_ELEMENTS)); | 182 FAST_ELEMENTS)); |
150 | 183 |
151 CheckBuilder builder(this, BailoutId::StubEntry()); | 184 CheckBuilder builder(this, BailoutId::StubEntry()); |
(...skipping 19 matching lines...) Expand all Loading... |
171 HInstruction* value = | 204 HInstruction* value = |
172 AddInstruction(new(zone) HLoadNamedField(boilerplate, true, i)); | 205 AddInstruction(new(zone) HLoadNamedField(boilerplate, true, i)); |
173 AddInstruction(new(zone) HStoreNamedField(object, | 206 AddInstruction(new(zone) HStoreNamedField(object, |
174 factory->empty_string(), | 207 factory->empty_string(), |
175 value, | 208 value, |
176 true, i)); | 209 true, i)); |
177 AddSimulate(BailoutId::StubEntry()); | 210 AddSimulate(BailoutId::StubEntry()); |
178 } | 211 } |
179 | 212 |
180 builder.End(); | 213 builder.End(); |
181 | 214 return object; |
182 HReturn* ret = new(zone) HReturn(object, context()); | |
183 current_block()->Finish(ret); | |
184 } | 215 } |
185 | 216 |
186 | 217 |
187 Handle<Code> FastCloneShallowObjectStub::GenerateCode() { | 218 Handle<Code> FastCloneShallowObjectStub::GenerateCode() { |
188 CodeStubGraphBuilder<FastCloneShallowObjectStub> builder(this); | 219 CodeStubGraphBuilder<FastCloneShallowObjectStub> builder(this); |
189 LChunk* chunk = OptimizeGraph(builder.CreateGraph()); | 220 LChunk* chunk = OptimizeGraph(builder.CreateGraph()); |
190 return chunk->Codegen(Code::COMPILED_STUB); | 221 return chunk->Codegen(Code::COMPILED_STUB); |
191 } | 222 } |
192 | 223 |
193 | 224 |
194 template <> | 225 template <> |
195 void CodeStubGraphBuilder<KeyedLoadFastElementStub>::BuildCodeStub() { | 226 HValue* CodeStubGraphBuilder<KeyedLoadFastElementStub>::BuildCodeStub() { |
196 Zone* zone = this->zone(); | |
197 | |
198 HInstruction* load = BuildUncheckedMonomorphicElementAccess( | 227 HInstruction* load = BuildUncheckedMonomorphicElementAccess( |
199 GetParameter(0), GetParameter(1), NULL, NULL, | 228 GetParameter(0), GetParameter(1), NULL, NULL, |
200 casted_stub()->is_js_array(), casted_stub()->elements_kind(), | 229 casted_stub()->is_js_array(), casted_stub()->elements_kind(), |
201 false, Representation::Tagged()); | 230 false, Representation::Tagged()); |
202 AddInstruction(load); | 231 AddInstruction(load); |
203 | 232 return load; |
204 HReturn* ret = new(zone) HReturn(load, context()); | |
205 current_block()->Finish(ret); | |
206 } | 233 } |
207 | 234 |
208 | 235 |
209 Handle<Code> KeyedLoadFastElementStub::GenerateCode() { | 236 Handle<Code> KeyedLoadFastElementStub::GenerateCode() { |
210 CodeStubGraphBuilder<KeyedLoadFastElementStub> builder(this); | 237 CodeStubGraphBuilder<KeyedLoadFastElementStub> builder(this); |
211 LChunk* chunk = OptimizeGraph(builder.CreateGraph()); | 238 LChunk* chunk = OptimizeGraph(builder.CreateGraph()); |
212 return chunk->Codegen(Code::COMPILED_STUB); | 239 return chunk->Codegen(Code::COMPILED_STUB); |
213 } | 240 } |
214 | 241 |
215 | 242 |
216 template <> | 243 template <> |
217 void CodeStubGraphBuilder<TransitionElementsKindStub>::BuildCodeStub() { | 244 HValue* CodeStubGraphBuilder<TransitionElementsKindStub>::BuildCodeStub() { |
218 Zone* zone = this->zone(); | 245 Zone* zone = this->zone(); |
219 | 246 |
220 HValue* js_array = GetParameter(0); | 247 HValue* js_array = GetParameter(0); |
221 HValue* map = GetParameter(1); | 248 HValue* map = GetParameter(1); |
222 | 249 |
223 info()->MarkAsSavesCallerDoubles(); | 250 info()->MarkAsSavesCallerDoubles(); |
224 | 251 |
225 AddInstruction(new(zone) HTrapAllocationMemento(js_array)); | 252 AddInstruction(new(zone) HTrapAllocationMemento(js_array)); |
226 | 253 |
227 HInstruction* array_length = | 254 HInstruction* array_length = |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 factory->elements_field_string(), | 320 factory->elements_field_string(), |
294 new_elements, true, | 321 new_elements, true, |
295 JSArray::kElementsOffset)); | 322 JSArray::kElementsOffset)); |
296 AddSimulate(BailoutId::StubEntry()); | 323 AddSimulate(BailoutId::StubEntry()); |
297 | 324 |
298 if_builder.End(); | 325 if_builder.End(); |
299 | 326 |
300 AddInstruction(new(zone) HStoreNamedField(js_array, factory->length_string(), | 327 AddInstruction(new(zone) HStoreNamedField(js_array, factory->length_string(), |
301 map, true, JSArray::kMapOffset)); | 328 map, true, JSArray::kMapOffset)); |
302 AddSimulate(BailoutId::StubEntry()); | 329 AddSimulate(BailoutId::StubEntry()); |
303 | 330 return js_array; |
304 HReturn* ret = new(zone) HReturn(js_array, context()); | |
305 current_block()->Finish(ret); | |
306 } | 331 } |
307 | 332 |
308 | 333 |
309 template <> | 334 template <> |
310 void CodeStubGraphBuilder<ArrayNoArgumentConstructorStub>::BuildCodeStub() { | 335 HValue* CodeStubGraphBuilder<ArrayNoArgumentConstructorStub>::BuildCodeStub() { |
311 HInstruction* deopt = new(zone()) HSoftDeoptimize(); | 336 HInstruction* deopt = new(zone()) HSoftDeoptimize(); |
312 AddInstruction(deopt); | 337 AddInstruction(deopt); |
313 current_block()->MarkAsDeoptimizing(); | 338 current_block()->MarkAsDeoptimizing(); |
314 HReturn* ret = new(zone()) HReturn(GetParameter(0), context()); | 339 return GetParameter(0); |
315 current_block()->Finish(ret); | |
316 } | 340 } |
317 | 341 |
318 | 342 |
319 Handle<Code> ArrayNoArgumentConstructorStub::GenerateCode() { | 343 Handle<Code> ArrayNoArgumentConstructorStub::GenerateCode() { |
320 CodeStubGraphBuilder<ArrayNoArgumentConstructorStub> builder(this); | 344 CodeStubGraphBuilder<ArrayNoArgumentConstructorStub> builder(this); |
321 LChunk* chunk = OptimizeGraph(builder.CreateGraph()); | 345 LChunk* chunk = OptimizeGraph(builder.CreateGraph()); |
322 return chunk->Codegen(Code::COMPILED_STUB); | 346 return chunk->Codegen(Code::COMPILED_STUB); |
323 } | 347 } |
324 | 348 |
325 | 349 |
326 template <> | 350 template <> |
327 void CodeStubGraphBuilder<ArraySingleArgumentConstructorStub>::BuildCodeStub() { | 351 HValue* CodeStubGraphBuilder<ArraySingleArgumentConstructorStub>:: |
| 352 BuildCodeStub() { |
328 HInstruction* deopt = new(zone()) HSoftDeoptimize(); | 353 HInstruction* deopt = new(zone()) HSoftDeoptimize(); |
329 AddInstruction(deopt); | 354 AddInstruction(deopt); |
330 current_block()->MarkAsDeoptimizing(); | 355 current_block()->MarkAsDeoptimizing(); |
331 HReturn* ret = new(zone()) HReturn(GetParameter(0), context()); | 356 return GetParameter(0); |
332 current_block()->Finish(ret); | |
333 } | 357 } |
334 | 358 |
335 | 359 |
336 Handle<Code> TransitionElementsKindStub::GenerateCode() { | 360 Handle<Code> TransitionElementsKindStub::GenerateCode() { |
337 CodeStubGraphBuilder<TransitionElementsKindStub> builder(this); | 361 CodeStubGraphBuilder<TransitionElementsKindStub> builder(this); |
338 LChunk* chunk = OptimizeGraph(builder.CreateGraph()); | 362 LChunk* chunk = OptimizeGraph(builder.CreateGraph()); |
339 return chunk->Codegen(Code::COMPILED_STUB); | 363 return chunk->Codegen(Code::COMPILED_STUB); |
340 } | 364 } |
341 | 365 |
342 | 366 |
343 Handle<Code> ArraySingleArgumentConstructorStub::GenerateCode() { | 367 Handle<Code> ArraySingleArgumentConstructorStub::GenerateCode() { |
344 CodeStubGraphBuilder<ArraySingleArgumentConstructorStub> builder(this); | 368 CodeStubGraphBuilder<ArraySingleArgumentConstructorStub> builder(this); |
345 LChunk* chunk = OptimizeGraph(builder.CreateGraph()); | 369 LChunk* chunk = OptimizeGraph(builder.CreateGraph()); |
346 return chunk->Codegen(Code::COMPILED_STUB); | 370 return chunk->Codegen(Code::COMPILED_STUB); |
347 } | 371 } |
348 | 372 |
349 | 373 |
350 template <> | 374 template <> |
351 void CodeStubGraphBuilder<ArrayNArgumentsConstructorStub>::BuildCodeStub() { | 375 HValue* CodeStubGraphBuilder<ArrayNArgumentsConstructorStub>::BuildCodeStub() { |
352 HInstruction* deopt = new(zone()) HSoftDeoptimize(); | 376 HInstruction* deopt = new(zone()) HSoftDeoptimize(); |
353 AddInstruction(deopt); | 377 AddInstruction(deopt); |
354 current_block()->MarkAsDeoptimizing(); | 378 current_block()->MarkAsDeoptimizing(); |
355 HReturn* ret = new(zone()) HReturn(GetParameter(0), context()); | 379 return GetParameter(0); |
356 current_block()->Finish(ret); | |
357 } | 380 } |
358 | 381 |
359 | 382 |
360 Handle<Code> ArrayNArgumentsConstructorStub::GenerateCode() { | 383 Handle<Code> ArrayNArgumentsConstructorStub::GenerateCode() { |
361 CodeStubGraphBuilder<ArrayNArgumentsConstructorStub> builder(this); | 384 CodeStubGraphBuilder<ArrayNArgumentsConstructorStub> builder(this); |
362 LChunk* chunk = OptimizeGraph(builder.CreateGraph()); | 385 LChunk* chunk = OptimizeGraph(builder.CreateGraph()); |
363 return chunk->Codegen(Code::COMPILED_STUB); | 386 return chunk->Codegen(Code::COMPILED_STUB); |
364 } | 387 } |
365 | 388 |
366 } } // namespace v8::internal | 389 } } // namespace v8::internal |
OLD | NEW |