Chromium Code Reviews| 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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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_), | 60 : HGraphBuilder(&info_), |
| 61 arguments_length_(NULL), | 61 arguments_length_(NULL), |
| 62 info_(stub, isolate), | 62 info_(stub, isolate), |
| 63 context_(NULL) { | 63 context_(NULL) { |
| 64 int major_key = stub->MajorKey(); | 64 descriptor_ = stub->GetInterfaceDescriptor(isolate); |
| 65 descriptor_ = isolate->code_stub_interface_descriptor(major_key); | |
| 66 if (descriptor_->register_param_count_ < 0) { | |
| 67 stub->InitializeInterfaceDescriptor(isolate, descriptor_); | |
| 68 } | |
| 69 parameters_.Reset(new HParameter*[descriptor_->register_param_count_]); | 65 parameters_.Reset(new HParameter*[descriptor_->register_param_count_]); |
| 70 } | 66 } |
| 71 virtual bool BuildGraph(); | 67 virtual bool BuildGraph(); |
| 72 | 68 |
| 73 protected: | 69 protected: |
| 74 virtual HValue* BuildCodeStub() = 0; | 70 virtual HValue* BuildCodeStub() = 0; |
| 75 HParameter* GetParameter(int parameter) { | 71 HParameter* GetParameter(int parameter) { |
| 76 ASSERT(parameter < descriptor_->register_param_count_); | 72 ASSERT(parameter < descriptor_->register_param_count_); |
| 77 return parameters_[parameter]; | 73 return parameters_[parameter]; |
| 78 } | 74 } |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 89 private: | 85 private: |
| 90 SmartArrayPointer<HParameter*> parameters_; | 86 SmartArrayPointer<HParameter*> parameters_; |
| 91 HValue* arguments_length_; | 87 HValue* arguments_length_; |
| 92 CompilationInfoWithZone info_; | 88 CompilationInfoWithZone info_; |
| 93 CodeStubInterfaceDescriptor* descriptor_; | 89 CodeStubInterfaceDescriptor* descriptor_; |
| 94 HContext* context_; | 90 HContext* context_; |
| 95 }; | 91 }; |
| 96 | 92 |
| 97 | 93 |
| 98 bool CodeStubGraphBuilderBase::BuildGraph() { | 94 bool CodeStubGraphBuilderBase::BuildGraph() { |
| 95 // Update the static counter each time a new code stub is generated. | |
| 96 isolate()->counters()->code_stubs()->Increment(); | |
| 97 | |
| 99 if (FLAG_trace_hydrogen) { | 98 if (FLAG_trace_hydrogen) { |
| 100 const char* name = CodeStub::MajorName(stub()->MajorKey(), false); | 99 const char* name = CodeStub::MajorName(stub()->MajorKey(), false); |
| 101 PrintF("-----------------------------------------------------------\n"); | 100 PrintF("-----------------------------------------------------------\n"); |
| 102 PrintF("Compiling stub %s using hydrogen\n", name); | 101 PrintF("Compiling stub %s using hydrogen\n", name); |
| 103 isolate()->GetHTracer()->TraceCompilation(&info_); | 102 isolate()->GetHTracer()->TraceCompilation(&info_); |
| 104 } | 103 } |
| 105 | 104 |
| 106 Zone* zone = this->zone(); | 105 Zone* zone = this->zone(); |
| 107 int param_count = descriptor_->register_param_count_; | 106 int param_count = descriptor_->register_param_count_; |
| 108 HEnvironment* start_environment = graph()->start_environment(); | 107 HEnvironment* start_environment = graph()->start_environment(); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 169 } | 168 } |
| 170 | 169 |
| 171 | 170 |
| 172 template <class Stub> | 171 template <class Stub> |
| 173 class CodeStubGraphBuilder: public CodeStubGraphBuilderBase { | 172 class CodeStubGraphBuilder: public CodeStubGraphBuilderBase { |
| 174 public: | 173 public: |
| 175 explicit CodeStubGraphBuilder(Stub* stub) | 174 explicit CodeStubGraphBuilder(Stub* stub) |
| 176 : CodeStubGraphBuilderBase(Isolate::Current(), stub) {} | 175 : CodeStubGraphBuilderBase(Isolate::Current(), stub) {} |
| 177 | 176 |
| 178 protected: | 177 protected: |
| 179 virtual HValue* BuildCodeStub(); | 178 virtual HValue* BuildCodeStub() { |
| 179 if (casted_stub()->IsMiss()) { | |
| 180 return BuildCodeInitializedStub(); | |
| 181 } else { | |
| 182 return BuildCodeUninitializedStub(); | |
| 183 } | |
| 184 } | |
| 185 | |
| 186 virtual HValue* BuildCodeInitializedStub() { | |
| 187 UNIMPLEMENTED(); | |
| 188 return NULL; | |
| 189 } | |
| 190 | |
| 191 virtual HValue* BuildCodeUninitializedStub() { | |
| 192 // Force a deopt that falls back to the runtime. | |
| 193 HValue* undefined = graph()->GetConstantUndefined(); | |
| 194 CheckBuilder builder(this); | |
| 195 builder.CheckNotUndefined(undefined); | |
| 196 builder.End(); | |
| 197 return undefined; | |
| 198 } | |
| 199 | |
| 180 Stub* casted_stub() { return static_cast<Stub*>(stub()); } | 200 Stub* casted_stub() { return static_cast<Stub*>(stub()); } |
| 181 }; | 201 }; |
| 182 | 202 |
| 183 | 203 |
| 184 template <class Stub> | 204 Handle<Code> HydrogenCodeStub::GenerateLightweightMissCode(Isolate* isolate) { |
| 185 static Handle<Code> DoGenerateCode(Stub* stub) { | 205 Factory* factory = isolate->factory(); |
| 186 CodeStubGraphBuilder<Stub> builder(stub); | 206 |
| 187 LChunk* chunk = OptimizeGraph(builder.CreateGraph()); | 207 // Generate the new code. |
| 188 return chunk->Codegen(); | 208 MacroAssembler masm(isolate, NULL, 256); |
| 209 | |
| 210 { | |
| 211 // Update the static counter each time a new code stub is generated. | |
| 212 isolate->counters()->code_stubs()->Increment(); | |
| 213 | |
| 214 // Nested stubs are not allowed for leaves. | |
| 215 AllowStubCallsScope allow_scope(&masm, false); | |
| 216 | |
| 217 // Generate the code for the stub. | |
| 218 masm.set_generating_stub(true); | |
| 219 NoCurrentFrameScope scope(&masm); | |
| 220 GenerateLightweightMiss(&masm); | |
| 221 } | |
| 222 | |
| 223 // Create the code object. | |
| 224 CodeDesc desc; | |
| 225 masm.GetCode(&desc); | |
| 226 | |
| 227 // Copy the generated code into a heap object. | |
| 228 Code::Flags flags = Code::ComputeFlags( | |
| 229 GetCodeKind(), | |
| 230 GetICState(), | |
| 231 GetExtraICState(), | |
| 232 GetStubType(), -1); | |
| 233 Handle<Code> new_object = factory->NewCode( | |
| 234 desc, flags, masm.CodeObject(), NeedsImmovableCode()); | |
| 235 return new_object; | |
| 189 } | 236 } |
| 190 | 237 |
| 191 | 238 |
| 239 template <class Stub> | |
| 240 static Handle<Code> DoGenerateCode(Stub* stub) { | |
| 241 Isolate* isolate = Isolate::Current(); | |
| 242 CodeStub::Major major_key = | |
| 243 static_cast<HydrogenCodeStub*>(stub)->MajorKey(); | |
| 244 CodeStubInterfaceDescriptor* descriptor = | |
| 245 isolate->code_stub_interface_descriptor(major_key); | |
| 246 if (descriptor->register_param_count_ < 0) { | |
| 247 stub->InitializeInterfaceDescriptor(isolate, descriptor); | |
| 248 } | |
| 249 // The miss case without stack parameters can use a light-weight tail-call. | |
|
Jakob Kummerow
2013/04/18 17:43:07
I don't see any tail calls around here.
danno
2013/04/19 06:47:41
Done.
| |
| 250 if (stub->IsMiss() && descriptor->stack_parameter_count_ == NULL) { | |
| 251 return stub->GenerateLightweightMissCode(isolate); | |
| 252 } else { | |
| 253 CodeStubGraphBuilder<Stub> builder(stub); | |
| 254 LChunk* chunk = OptimizeGraph(builder.CreateGraph()); | |
| 255 return chunk->Codegen(); | |
| 256 } | |
| 257 } | |
| 258 | |
| 259 | |
| 192 template <> | 260 template <> |
| 193 HValue* CodeStubGraphBuilder<FastCloneShallowArrayStub>::BuildCodeStub() { | 261 HValue* CodeStubGraphBuilder<FastCloneShallowArrayStub>::BuildCodeStub() { |
| 194 Zone* zone = this->zone(); | 262 Zone* zone = this->zone(); |
| 195 Factory* factory = isolate()->factory(); | 263 Factory* factory = isolate()->factory(); |
| 196 AllocationSiteMode alloc_site_mode = casted_stub()->allocation_site_mode(); | 264 AllocationSiteMode alloc_site_mode = casted_stub()->allocation_site_mode(); |
| 197 FastCloneShallowArrayStub::Mode mode = casted_stub()->mode(); | 265 FastCloneShallowArrayStub::Mode mode = casted_stub()->mode(); |
| 198 int length = casted_stub()->length(); | 266 int length = casted_stub()->length(); |
| 199 | 267 |
| 200 HInstruction* boilerplate = | 268 HInstruction* boilerplate = |
| 201 AddInstruction(new(zone) HLoadKeyed(GetParameter(0), | 269 AddInstruction(new(zone) HLoadKeyed(GetParameter(0), |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 241 alloc_site_mode, | 309 alloc_site_mode, |
| 242 elements_kind, | 310 elements_kind, |
| 243 length)); | 311 length)); |
| 244 } | 312 } |
| 245 | 313 |
| 246 return environment()->Pop(); | 314 return environment()->Pop(); |
| 247 } | 315 } |
| 248 | 316 |
| 249 | 317 |
| 250 Handle<Code> FastCloneShallowArrayStub::GenerateCode() { | 318 Handle<Code> FastCloneShallowArrayStub::GenerateCode() { |
| 251 CodeStubGraphBuilder<FastCloneShallowArrayStub> builder(this); | 319 return DoGenerateCode(this); |
| 252 LChunk* chunk = OptimizeGraph(builder.CreateGraph()); | |
| 253 return chunk->Codegen(); | |
| 254 } | 320 } |
| 255 | 321 |
| 256 | 322 |
| 257 template <> | 323 template <> |
| 258 HValue* CodeStubGraphBuilder<FastCloneShallowObjectStub>::BuildCodeStub() { | 324 HValue* CodeStubGraphBuilder<FastCloneShallowObjectStub>::BuildCodeStub() { |
| 259 Zone* zone = this->zone(); | 325 Zone* zone = this->zone(); |
| 260 Factory* factory = isolate()->factory(); | 326 Factory* factory = isolate()->factory(); |
| 261 | 327 |
| 262 HInstruction* boilerplate = | 328 HInstruction* boilerplate = |
| 263 AddInstruction(new(zone) HLoadKeyed(GetParameter(0), | 329 AddInstruction(new(zone) HLoadKeyed(GetParameter(0), |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 435 current_block()->MarkAsDeoptimizing(); | 501 current_block()->MarkAsDeoptimizing(); |
| 436 return GetParameter(0); | 502 return GetParameter(0); |
| 437 } | 503 } |
| 438 | 504 |
| 439 | 505 |
| 440 Handle<Code> ArrayNArgumentsConstructorStub::GenerateCode() { | 506 Handle<Code> ArrayNArgumentsConstructorStub::GenerateCode() { |
| 441 return DoGenerateCode(this); | 507 return DoGenerateCode(this); |
| 442 } | 508 } |
| 443 | 509 |
| 444 } } // namespace v8::internal | 510 } } // namespace v8::internal |
| OLD | NEW |