| 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/compiler.h" | 5 #include "src/compiler.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "src/ast-numbering.h" | 9 #include "src/ast-numbering.h" |
| 10 #include "src/bootstrapper.h" | 10 #include "src/bootstrapper.h" |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 return parse_info_ && parse_info_->literal() != nullptr; | 112 return parse_info_ && parse_info_->literal() != nullptr; |
| 113 } | 113 } |
| 114 | 114 |
| 115 | 115 |
| 116 bool CompilationInfo::has_scope() const { | 116 bool CompilationInfo::has_scope() const { |
| 117 return parse_info_ && parse_info_->scope() != nullptr; | 117 return parse_info_ && parse_info_->scope() != nullptr; |
| 118 } | 118 } |
| 119 | 119 |
| 120 | 120 |
| 121 CompilationInfo::CompilationInfo(ParseInfo* parse_info) | 121 CompilationInfo::CompilationInfo(ParseInfo* parse_info) |
| 122 : CompilationInfo(parse_info, nullptr, BASE, parse_info->isolate(), | 122 : CompilationInfo(parse_info, nullptr, nullptr, BASE, parse_info->isolate(), |
| 123 parse_info->zone()) { | 123 parse_info->zone()) { |
| 124 // Compiling for the snapshot typically results in different code than | 124 // Compiling for the snapshot typically results in different code than |
| 125 // compiling later on. This means that code recompiled with deoptimization | 125 // compiling later on. This means that code recompiled with deoptimization |
| 126 // support won't be "equivalent" (as defined by SharedFunctionInfo:: | 126 // support won't be "equivalent" (as defined by SharedFunctionInfo:: |
| 127 // EnableDeoptimizationSupport), so it will replace the old code and all | 127 // EnableDeoptimizationSupport), so it will replace the old code and all |
| 128 // its type feedback. To avoid this, always compile functions in the snapshot | 128 // its type feedback. To avoid this, always compile functions in the snapshot |
| 129 // with deoptimization support. | 129 // with deoptimization support. |
| 130 if (isolate_->serializer_enabled()) EnableDeoptimizationSupport(); | 130 if (isolate_->serializer_enabled()) EnableDeoptimizationSupport(); |
| 131 | 131 |
| 132 if (FLAG_context_specialization) MarkAsContextSpecializing(); | 132 if (FLAG_context_specialization) MarkAsContextSpecializing(); |
| 133 if (FLAG_turbo_inlining) MarkAsInliningEnabled(); | 133 if (FLAG_turbo_inlining) MarkAsInliningEnabled(); |
| 134 if (FLAG_turbo_source_positions) MarkAsSourcePositionsEnabled(); | 134 if (FLAG_turbo_source_positions) MarkAsSourcePositionsEnabled(); |
| 135 if (FLAG_turbo_splitting) MarkAsSplittingEnabled(); | 135 if (FLAG_turbo_splitting) MarkAsSplittingEnabled(); |
| 136 if (FLAG_turbo_types) MarkAsTypingEnabled(); | 136 if (FLAG_turbo_types) MarkAsTypingEnabled(); |
| 137 | 137 |
| 138 if (has_shared_info()) { | 138 if (has_shared_info()) { |
| 139 if (shared_info()->is_compiled()) { | 139 if (shared_info()->is_compiled()) { |
| 140 // We should initialize the CompilationInfo feedback vector from the | 140 // We should initialize the CompilationInfo feedback vector from the |
| 141 // passed in shared info, rather than creating a new one. | 141 // passed in shared info, rather than creating a new one. |
| 142 feedback_vector_ = Handle<TypeFeedbackVector>( | 142 feedback_vector_ = Handle<TypeFeedbackVector>( |
| 143 shared_info()->feedback_vector(), parse_info->isolate()); | 143 shared_info()->feedback_vector(), parse_info->isolate()); |
| 144 } | 144 } |
| 145 if (shared_info()->never_compiled()) MarkAsFirstCompile(); | 145 if (shared_info()->never_compiled()) MarkAsFirstCompile(); |
| 146 } | 146 } |
| 147 } | 147 } |
| 148 | 148 |
| 149 | 149 |
| 150 CompilationInfo::CompilationInfo(CodeStub* stub, Isolate* isolate, Zone* zone) | 150 CompilationInfo::CompilationInfo(CodeStub* stub, Isolate* isolate, Zone* zone) |
| 151 : CompilationInfo(nullptr, stub, STUB, isolate, zone) {} | 151 : CompilationInfo(nullptr, stub, CodeStub::MajorName(stub->MajorKey()), |
| 152 STUB, isolate, zone) {} |
| 152 | 153 |
| 154 CompilationInfo::CompilationInfo(const char* debug_name, Isolate* isolate, |
| 155 Zone* zone) |
| 156 : CompilationInfo(nullptr, nullptr, debug_name, STUB, isolate, zone) {} |
| 153 | 157 |
| 154 CompilationInfo::CompilationInfo(ParseInfo* parse_info, CodeStub* code_stub, | 158 CompilationInfo::CompilationInfo(ParseInfo* parse_info, CodeStub* code_stub, |
| 155 Mode mode, Isolate* isolate, Zone* zone) | 159 const char* code_stub_debug_name, Mode mode, |
| 160 Isolate* isolate, Zone* zone) |
| 156 : parse_info_(parse_info), | 161 : parse_info_(parse_info), |
| 157 isolate_(isolate), | 162 isolate_(isolate), |
| 158 flags_(0), | 163 flags_(0), |
| 159 code_stub_(code_stub), | 164 code_stub_(code_stub), |
| 160 mode_(mode), | 165 mode_(mode), |
| 161 osr_ast_id_(BailoutId::None()), | 166 osr_ast_id_(BailoutId::None()), |
| 162 zone_(zone), | 167 zone_(zone), |
| 163 deferred_handles_(nullptr), | 168 deferred_handles_(nullptr), |
| 164 dependencies_(isolate, zone), | 169 dependencies_(isolate, zone), |
| 165 bailout_reason_(kNoReason), | 170 bailout_reason_(kNoReason), |
| 166 prologue_offset_(Code::kPrologueOffsetNotSet), | 171 prologue_offset_(Code::kPrologueOffsetNotSet), |
| 167 no_frame_ranges_(isolate->cpu_profiler()->is_profiling() | 172 no_frame_ranges_(isolate->cpu_profiler()->is_profiling() |
| 168 ? new List<OffsetRange>(2) | 173 ? new List<OffsetRange>(2) |
| 169 : nullptr), | 174 : nullptr), |
| 170 track_positions_(FLAG_hydrogen_track_positions || | 175 track_positions_(FLAG_hydrogen_track_positions || |
| 171 isolate->cpu_profiler()->is_profiling()), | 176 isolate->cpu_profiler()->is_profiling()), |
| 172 opt_count_(has_shared_info() ? shared_info()->opt_count() : 0), | 177 opt_count_(has_shared_info() ? shared_info()->opt_count() : 0), |
| 173 parameter_count_(0), | 178 parameter_count_(0), |
| 174 optimization_id_(-1), | 179 optimization_id_(-1), |
| 175 osr_expr_stack_height_(0), | 180 osr_expr_stack_height_(0), |
| 176 function_type_(nullptr) { | 181 function_type_(nullptr), |
| 182 code_stub_debug_name_(code_stub_debug_name) { |
| 177 // Parameter count is number of stack parameters. | 183 // Parameter count is number of stack parameters. |
| 178 if (code_stub_ != NULL) { | 184 if (code_stub_ != NULL) { |
| 179 CodeStubDescriptor descriptor(code_stub_); | 185 CodeStubDescriptor descriptor(code_stub_); |
| 180 parameter_count_ = descriptor.GetStackParameterCount(); | 186 parameter_count_ = descriptor.GetStackParameterCount(); |
| 181 if (descriptor.function_mode() == NOT_JS_FUNCTION_STUB_MODE) { | 187 if (descriptor.function_mode() == NOT_JS_FUNCTION_STUB_MODE) { |
| 182 parameter_count_--; | 188 parameter_count_--; |
| 183 } | 189 } |
| 184 } | 190 } |
| 185 } | 191 } |
| 186 | 192 |
| 187 | 193 |
| 188 CompilationInfo::~CompilationInfo() { | 194 CompilationInfo::~CompilationInfo() { |
| 189 DisableFutureOptimization(); | 195 DisableFutureOptimization(); |
| 190 delete deferred_handles_; | 196 delete deferred_handles_; |
| 191 delete no_frame_ranges_; | 197 delete no_frame_ranges_; |
| 192 #ifdef DEBUG | 198 #ifdef DEBUG |
| 193 // Check that no dependent maps have been added or added dependent maps have | 199 // Check that no dependent maps have been added or added dependent maps have |
| 194 // been rolled back or committed. | 200 // been rolled back or committed. |
| 195 DCHECK(dependencies()->IsEmpty()); | 201 DCHECK(dependencies()->IsEmpty()); |
| 196 #endif // DEBUG | 202 #endif // DEBUG |
| 197 } | 203 } |
| 198 | 204 |
| 199 | 205 |
| 206 void CompilationInfo::SetStub(CodeStub* code_stub) { |
| 207 SetMode(STUB); |
| 208 code_stub_ = code_stub; |
| 209 code_stub_debug_name_ = CodeStub::MajorName(code_stub->MajorKey()); |
| 210 } |
| 211 |
| 212 |
| 200 int CompilationInfo::num_parameters() const { | 213 int CompilationInfo::num_parameters() const { |
| 201 return has_scope() ? scope()->num_parameters() : parameter_count_; | 214 return has_scope() ? scope()->num_parameters() : parameter_count_; |
| 202 } | 215 } |
| 203 | 216 |
| 204 | 217 |
| 205 int CompilationInfo::num_parameters_including_this() const { | 218 int CompilationInfo::num_parameters_including_this() const { |
| 206 return num_parameters() + (is_this_defined() ? 1 : 0); | 219 return num_parameters() + (is_this_defined() ? 1 : 0); |
| 207 } | 220 } |
| 208 | 221 |
| 209 | 222 |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 | 316 |
| 304 | 317 |
| 305 Handle<Code> CompilationInfo::GenerateCodeStub() { | 318 Handle<Code> CompilationInfo::GenerateCodeStub() { |
| 306 // Run a "mini pipeline", extracted from compiler.cc. | 319 // Run a "mini pipeline", extracted from compiler.cc. |
| 307 CHECK(Parser::ParseStatic(parse_info())); | 320 CHECK(Parser::ParseStatic(parse_info())); |
| 308 CHECK(Compiler::Analyze(parse_info())); | 321 CHECK(Compiler::Analyze(parse_info())); |
| 309 return compiler::Pipeline(this).GenerateCode(); | 322 return compiler::Pipeline(this).GenerateCode(); |
| 310 } | 323 } |
| 311 | 324 |
| 312 | 325 |
| 326 base::SmartArrayPointer<char> CompilationInfo::GetDebugName() const { |
| 327 if (IsStub()) { |
| 328 size_t len = strlen(code_stub_debug_name_) + 1; |
| 329 base::SmartArrayPointer<char> name(new char[len]); |
| 330 memcpy(name.get(), code_stub_debug_name_, len); |
| 331 return name; |
| 332 } else { |
| 333 AllowHandleDereference allow_deref; |
| 334 return literal()->debug_name()->ToCString(); |
| 335 } |
| 336 } |
| 337 |
| 338 |
| 313 class HOptimizedGraphBuilderWithPositions: public HOptimizedGraphBuilder { | 339 class HOptimizedGraphBuilderWithPositions: public HOptimizedGraphBuilder { |
| 314 public: | 340 public: |
| 315 explicit HOptimizedGraphBuilderWithPositions(CompilationInfo* info) | 341 explicit HOptimizedGraphBuilderWithPositions(CompilationInfo* info) |
| 316 : HOptimizedGraphBuilder(info) { | 342 : HOptimizedGraphBuilder(info) { |
| 317 } | 343 } |
| 318 | 344 |
| 319 #define DEF_VISIT(type) \ | 345 #define DEF_VISIT(type) \ |
| 320 void Visit##type(type* node) override { \ | 346 void Visit##type(type* node) override { \ |
| 321 SourcePosition old_position = SourcePosition::Unknown(); \ | 347 SourcePosition old_position = SourcePosition::Unknown(); \ |
| 322 if (node->position() != RelocInfo::kNoPosition) { \ | 348 if (node->position() != RelocInfo::kNoPosition) { \ |
| (...skipping 1395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1718 | 1744 |
| 1719 | 1745 |
| 1720 #if DEBUG | 1746 #if DEBUG |
| 1721 void CompilationInfo::PrintAstForTesting() { | 1747 void CompilationInfo::PrintAstForTesting() { |
| 1722 PrintF("--- Source from AST ---\n%s\n", | 1748 PrintF("--- Source from AST ---\n%s\n", |
| 1723 PrettyPrinter(isolate(), zone()).PrintProgram(literal())); | 1749 PrettyPrinter(isolate(), zone()).PrintProgram(literal())); |
| 1724 } | 1750 } |
| 1725 #endif | 1751 #endif |
| 1726 } // namespace internal | 1752 } // namespace internal |
| 1727 } // namespace v8 | 1753 } // namespace v8 |
| OLD | NEW |