| 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(); |
| 95 HEnvironment* start_environment = | 107 int param_count = descriptor_->register_param_count_; |
| 96 new(zone) HEnvironment(zone, descriptor_->register_param_count_); | 108 HEnvironment* start_environment = graph()->start_environment(); |
| 97 HBasicBlock* next_block = CreateBasicBlock(start_environment); | 109 HBasicBlock* next_block = CreateBasicBlock(start_environment); |
| 98 | |
| 99 current_block()->Goto(next_block); | 110 current_block()->Goto(next_block); |
| 100 next_block->SetJoinId(BailoutId::StubEntry()); | 111 next_block->SetJoinId(BailoutId::StubEntry()); |
| 101 set_current_block(next_block); | 112 set_current_block(next_block); |
| 102 | 113 |
| 103 HConstant* undefined_constant = new(zone) HConstant( | 114 HConstant* undefined_constant = new(zone) HConstant( |
| 104 isolate()->factory()->undefined_value(), Representation::Tagged()); | 115 isolate()->factory()->undefined_value(), Representation::Tagged()); |
| 105 AddInstruction(undefined_constant); | 116 AddInstruction(undefined_constant); |
| 106 graph()->set_undefined_constant(undefined_constant); | 117 graph()->set_undefined_constant(undefined_constant); |
| 107 | 118 |
| 108 int param_count = descriptor_->register_param_count_; | |
| 109 for (int i = 0; i < param_count; ++i) { | 119 for (int i = 0; i < param_count; ++i) { |
| 110 HParameter* param = | 120 HParameter* param = |
| 111 new(zone) HParameter(i, HParameter::REGISTER_PARAMETER); | 121 new(zone) HParameter(i, HParameter::REGISTER_PARAMETER); |
| 112 AddInstruction(param); | 122 AddInstruction(param); |
| 113 start_environment->Bind(i, param); | 123 start_environment->Bind(i, param); |
| 114 parameters_[i] = param; | 124 parameters_[i] = param; |
| 115 } | 125 } |
| 116 | 126 |
| 127 HInstruction* stack_parameter_count; |
| 128 if (descriptor_->stack_parameter_count_ != NULL) { |
| 129 ASSERT(descriptor_->environment_length() == (param_count + 1)); |
| 130 stack_parameter_count = new(zone) HParameter(param_count, |
| 131 HParameter::REGISTER_PARAMETER); |
| 132 // it's essential to bind this value to the environment in case of deopt |
| 133 start_environment->Bind(param_count, stack_parameter_count); |
| 134 AddInstruction(stack_parameter_count); |
| 135 } else { |
| 136 ASSERT(descriptor_->environment_length() == param_count); |
| 137 stack_parameter_count = AddInstruction(new(zone) |
| 138 HConstant(-1, Representation::Integer32())); |
| 139 } |
| 140 |
| 141 arguments_length_ = stack_parameter_count; |
| 142 |
| 117 context_ = new(zone) HContext(); | 143 context_ = new(zone) HContext(); |
| 118 AddInstruction(context_); | 144 AddInstruction(context_); |
| 119 start_environment->Bind(param_count, context_); | 145 start_environment->BindContext(context_); |
| 120 | 146 |
| 121 AddSimulate(BailoutId::StubEntry()); | 147 AddSimulate(BailoutId::StubEntry()); |
| 122 | 148 |
| 123 BuildCodeStub(); | 149 HValue* return_value = BuildCodeStub(); |
| 124 | 150 HReturn* hreturn_instruction = new(zone) HReturn(return_value, |
| 151 context_, |
| 152 stack_parameter_count); |
| 153 current_block()->Finish(hreturn_instruction); |
| 125 return true; | 154 return true; |
| 126 } | 155 } |
| 127 | 156 |
| 128 template <class Stub> | 157 template <class Stub> |
| 129 class CodeStubGraphBuilder: public CodeStubGraphBuilderBase { | 158 class CodeStubGraphBuilder: public CodeStubGraphBuilderBase { |
| 130 public: | 159 public: |
| 131 explicit CodeStubGraphBuilder(Stub* stub) | 160 explicit CodeStubGraphBuilder(Stub* stub) |
| 132 : CodeStubGraphBuilderBase(Isolate::Current(), stub) {} | 161 : CodeStubGraphBuilderBase(Isolate::Current(), stub) {} |
| 133 | 162 |
| 134 protected: | 163 protected: |
| 135 virtual void BuildCodeStub(); | 164 virtual HValue* BuildCodeStub(); |
| 136 Stub* casted_stub() { return static_cast<Stub*>(stub()); } | 165 Stub* casted_stub() { return static_cast<Stub*>(stub()); } |
| 137 }; | 166 }; |
| 138 | 167 |
| 139 | 168 |
| 140 template <> | 169 template <> |
| 141 void CodeStubGraphBuilder<FastCloneShallowObjectStub>::BuildCodeStub() { | 170 HValue* CodeStubGraphBuilder<FastCloneShallowObjectStub>::BuildCodeStub() { |
| 142 Zone* zone = this->zone(); | 171 Zone* zone = this->zone(); |
| 143 Factory* factory = isolate()->factory(); | 172 Factory* factory = isolate()->factory(); |
| 144 | 173 |
| 145 HInstruction* boilerplate = | 174 HInstruction* boilerplate = |
| 146 AddInstruction(new(zone) HLoadKeyed(GetParameter(0), | 175 AddInstruction(new(zone) HLoadKeyed(GetParameter(0), |
| 147 GetParameter(1), | 176 GetParameter(1), |
| 148 NULL, | 177 NULL, |
| 149 FAST_ELEMENTS)); | 178 FAST_ELEMENTS)); |
| 150 | 179 |
| 151 CheckBuilder builder(this, BailoutId::StubEntry()); | 180 CheckBuilder builder(this, BailoutId::StubEntry()); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 171 HInstruction* value = | 200 HInstruction* value = |
| 172 AddInstruction(new(zone) HLoadNamedField(boilerplate, true, i)); | 201 AddInstruction(new(zone) HLoadNamedField(boilerplate, true, i)); |
| 173 AddInstruction(new(zone) HStoreNamedField(object, | 202 AddInstruction(new(zone) HStoreNamedField(object, |
| 174 factory->empty_string(), | 203 factory->empty_string(), |
| 175 value, | 204 value, |
| 176 true, i)); | 205 true, i)); |
| 177 AddSimulate(BailoutId::StubEntry()); | 206 AddSimulate(BailoutId::StubEntry()); |
| 178 } | 207 } |
| 179 | 208 |
| 180 builder.End(); | 209 builder.End(); |
| 181 | 210 return object; |
| 182 HReturn* ret = new(zone) HReturn(object, context()); | |
| 183 current_block()->Finish(ret); | |
| 184 } | 211 } |
| 185 | 212 |
| 186 | 213 |
| 187 Handle<Code> FastCloneShallowObjectStub::GenerateCode() { | 214 Handle<Code> FastCloneShallowObjectStub::GenerateCode() { |
| 188 CodeStubGraphBuilder<FastCloneShallowObjectStub> builder(this); | 215 CodeStubGraphBuilder<FastCloneShallowObjectStub> builder(this); |
| 189 LChunk* chunk = OptimizeGraph(builder.CreateGraph()); | 216 LChunk* chunk = OptimizeGraph(builder.CreateGraph()); |
| 190 return chunk->Codegen(Code::COMPILED_STUB); | 217 return chunk->Codegen(Code::COMPILED_STUB); |
| 191 } | 218 } |
| 192 | 219 |
| 193 | 220 |
| 194 template <> | 221 template <> |
| 195 void CodeStubGraphBuilder<KeyedLoadFastElementStub>::BuildCodeStub() { | 222 HValue* CodeStubGraphBuilder<KeyedLoadFastElementStub>::BuildCodeStub() { |
| 196 Zone* zone = this->zone(); | |
| 197 | |
| 198 HInstruction* load = BuildUncheckedMonomorphicElementAccess( | 223 HInstruction* load = BuildUncheckedMonomorphicElementAccess( |
| 199 GetParameter(0), GetParameter(1), NULL, NULL, | 224 GetParameter(0), GetParameter(1), NULL, NULL, |
| 200 casted_stub()->is_js_array(), casted_stub()->elements_kind(), | 225 casted_stub()->is_js_array(), casted_stub()->elements_kind(), |
| 201 false, Representation::Tagged()); | 226 false, Representation::Tagged()); |
| 202 AddInstruction(load); | 227 AddInstruction(load); |
| 203 | 228 return load; |
| 204 HReturn* ret = new(zone) HReturn(load, context()); | |
| 205 current_block()->Finish(ret); | |
| 206 } | 229 } |
| 207 | 230 |
| 208 | 231 |
| 209 Handle<Code> KeyedLoadFastElementStub::GenerateCode() { | 232 Handle<Code> KeyedLoadFastElementStub::GenerateCode() { |
| 210 CodeStubGraphBuilder<KeyedLoadFastElementStub> builder(this); | 233 CodeStubGraphBuilder<KeyedLoadFastElementStub> builder(this); |
| 211 LChunk* chunk = OptimizeGraph(builder.CreateGraph()); | 234 LChunk* chunk = OptimizeGraph(builder.CreateGraph()); |
| 212 return chunk->Codegen(Code::COMPILED_STUB); | 235 return chunk->Codegen(Code::COMPILED_STUB); |
| 213 } | 236 } |
| 214 | 237 |
| 215 | 238 |
| 216 template <> | 239 template <> |
| 217 void CodeStubGraphBuilder<TransitionElementsKindStub>::BuildCodeStub() { | 240 HValue* CodeStubGraphBuilder<TransitionElementsKindStub>::BuildCodeStub() { |
| 218 Zone* zone = this->zone(); | 241 Zone* zone = this->zone(); |
| 219 | 242 |
| 220 HValue* js_array = GetParameter(0); | 243 HValue* js_array = GetParameter(0); |
| 221 HValue* map = GetParameter(1); | 244 HValue* map = GetParameter(1); |
| 222 | 245 |
| 223 info()->MarkAsSavesCallerDoubles(); | 246 info()->MarkAsSavesCallerDoubles(); |
| 224 | 247 |
| 225 AddInstruction(new(zone) HTrapAllocationMemento(js_array)); | 248 AddInstruction(new(zone) HTrapAllocationMemento(js_array)); |
| 226 | 249 |
| 227 HInstruction* array_length = | 250 HInstruction* array_length = |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 293 factory->elements_field_string(), | 316 factory->elements_field_string(), |
| 294 new_elements, true, | 317 new_elements, true, |
| 295 JSArray::kElementsOffset)); | 318 JSArray::kElementsOffset)); |
| 296 AddSimulate(BailoutId::StubEntry()); | 319 AddSimulate(BailoutId::StubEntry()); |
| 297 | 320 |
| 298 if_builder.End(); | 321 if_builder.End(); |
| 299 | 322 |
| 300 AddInstruction(new(zone) HStoreNamedField(js_array, factory->length_string(), | 323 AddInstruction(new(zone) HStoreNamedField(js_array, factory->length_string(), |
| 301 map, true, JSArray::kMapOffset)); | 324 map, true, JSArray::kMapOffset)); |
| 302 AddSimulate(BailoutId::StubEntry()); | 325 AddSimulate(BailoutId::StubEntry()); |
| 303 | 326 return js_array; |
| 304 HReturn* ret = new(zone) HReturn(js_array, context()); | |
| 305 current_block()->Finish(ret); | |
| 306 } | 327 } |
| 307 | 328 |
| 308 | 329 |
| 309 template <> | 330 template <> |
| 310 void CodeStubGraphBuilder<ArrayNoArgumentConstructorStub>::BuildCodeStub() { | 331 HValue* CodeStubGraphBuilder<ArrayNoArgumentConstructorStub>::BuildCodeStub() { |
| 311 HInstruction* deopt = new(zone()) HSoftDeoptimize(); | 332 HInstruction* deopt = new(zone()) HSoftDeoptimize(); |
| 312 AddInstruction(deopt); | 333 AddInstruction(deopt); |
| 313 current_block()->MarkAsDeoptimizing(); | 334 current_block()->MarkAsDeoptimizing(); |
| 314 HReturn* ret = new(zone()) HReturn(GetParameter(0), context()); | 335 return GetParameter(0); |
| 315 current_block()->Finish(ret); | |
| 316 } | 336 } |
| 317 | 337 |
| 318 | 338 |
| 319 Handle<Code> ArrayNoArgumentConstructorStub::GenerateCode() { | 339 Handle<Code> ArrayNoArgumentConstructorStub::GenerateCode() { |
| 320 CodeStubGraphBuilder<ArrayNoArgumentConstructorStub> builder(this); | 340 CodeStubGraphBuilder<ArrayNoArgumentConstructorStub> builder(this); |
| 321 LChunk* chunk = OptimizeGraph(builder.CreateGraph()); | 341 LChunk* chunk = OptimizeGraph(builder.CreateGraph()); |
| 322 return chunk->Codegen(Code::COMPILED_STUB); | 342 return chunk->Codegen(Code::COMPILED_STUB); |
| 323 } | 343 } |
| 324 | 344 |
| 325 | 345 |
| 326 template <> | 346 template <> |
| 327 void CodeStubGraphBuilder<ArraySingleArgumentConstructorStub>::BuildCodeStub() { | 347 HValue* CodeStubGraphBuilder<ArraySingleArgumentConstructorStub>:: |
| 348 BuildCodeStub() { |
| 328 HInstruction* deopt = new(zone()) HSoftDeoptimize(); | 349 HInstruction* deopt = new(zone()) HSoftDeoptimize(); |
| 329 AddInstruction(deopt); | 350 AddInstruction(deopt); |
| 330 current_block()->MarkAsDeoptimizing(); | 351 current_block()->MarkAsDeoptimizing(); |
| 331 HReturn* ret = new(zone()) HReturn(GetParameter(0), context()); | 352 return GetParameter(0); |
| 332 current_block()->Finish(ret); | |
| 333 } | 353 } |
| 334 | 354 |
| 335 | 355 |
| 336 Handle<Code> TransitionElementsKindStub::GenerateCode() { | 356 Handle<Code> TransitionElementsKindStub::GenerateCode() { |
| 337 CodeStubGraphBuilder<TransitionElementsKindStub> builder(this); | 357 CodeStubGraphBuilder<TransitionElementsKindStub> builder(this); |
| 338 LChunk* chunk = OptimizeGraph(builder.CreateGraph()); | 358 LChunk* chunk = OptimizeGraph(builder.CreateGraph()); |
| 339 return chunk->Codegen(Code::COMPILED_STUB); | 359 return chunk->Codegen(Code::COMPILED_STUB); |
| 340 } | 360 } |
| 341 | 361 |
| 342 | 362 |
| 343 Handle<Code> ArraySingleArgumentConstructorStub::GenerateCode() { | 363 Handle<Code> ArraySingleArgumentConstructorStub::GenerateCode() { |
| 344 CodeStubGraphBuilder<ArraySingleArgumentConstructorStub> builder(this); | 364 CodeStubGraphBuilder<ArraySingleArgumentConstructorStub> builder(this); |
| 345 LChunk* chunk = OptimizeGraph(builder.CreateGraph()); | 365 LChunk* chunk = OptimizeGraph(builder.CreateGraph()); |
| 346 return chunk->Codegen(Code::COMPILED_STUB); | 366 return chunk->Codegen(Code::COMPILED_STUB); |
| 347 } | 367 } |
| 348 | 368 |
| 349 | 369 |
| 350 template <> | 370 template <> |
| 351 void CodeStubGraphBuilder<ArrayNArgumentsConstructorStub>::BuildCodeStub() { | 371 HValue* CodeStubGraphBuilder<ArrayNArgumentsConstructorStub>::BuildCodeStub() { |
| 352 HInstruction* deopt = new(zone()) HSoftDeoptimize(); | 372 HInstruction* deopt = new(zone()) HSoftDeoptimize(); |
| 353 AddInstruction(deopt); | 373 AddInstruction(deopt); |
| 354 current_block()->MarkAsDeoptimizing(); | 374 current_block()->MarkAsDeoptimizing(); |
| 355 HReturn* ret = new(zone()) HReturn(GetParameter(0), context()); | 375 return GetParameter(0); |
| 356 current_block()->Finish(ret); | |
| 357 } | 376 } |
| 358 | 377 |
| 359 | 378 |
| 360 Handle<Code> ArrayNArgumentsConstructorStub::GenerateCode() { | 379 Handle<Code> ArrayNArgumentsConstructorStub::GenerateCode() { |
| 361 CodeStubGraphBuilder<ArrayNArgumentsConstructorStub> builder(this); | 380 CodeStubGraphBuilder<ArrayNArgumentsConstructorStub> builder(this); |
| 362 LChunk* chunk = OptimizeGraph(builder.CreateGraph()); | 381 LChunk* chunk = OptimizeGraph(builder.CreateGraph()); |
| 363 return chunk->Codegen(Code::COMPILED_STUB); | 382 return chunk->Codegen(Code::COMPILED_STUB); |
| 364 } | 383 } |
| 365 | 384 |
| 366 } } // namespace v8::internal | 385 } } // namespace v8::internal |
| OLD | NEW |