| 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 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 } | 295 } |
| 296 | 296 |
| 297 | 297 |
| 298 void CompilationInfo::LogDeoptCallPosition(int pc_offset, int inlining_id) { | 298 void CompilationInfo::LogDeoptCallPosition(int pc_offset, int inlining_id) { |
| 299 if (!track_positions_ || IsStub()) return; | 299 if (!track_positions_ || IsStub()) return; |
| 300 DCHECK_LT(static_cast<size_t>(inlining_id), inlined_function_infos_.size()); | 300 DCHECK_LT(static_cast<size_t>(inlining_id), inlined_function_infos_.size()); |
| 301 inlined_function_infos_.at(inlining_id).deopt_pc_offsets.push_back(pc_offset); | 301 inlined_function_infos_.at(inlining_id).deopt_pc_offsets.push_back(pc_offset); |
| 302 } | 302 } |
| 303 | 303 |
| 304 | 304 |
| 305 Handle<Code> CompilationInfo::GenerateCodeStub() { | |
| 306 // Run a "mini pipeline", extracted from compiler.cc. | |
| 307 CHECK(Parser::ParseStatic(parse_info())); | |
| 308 CHECK(Compiler::Analyze(parse_info())); | |
| 309 return compiler::Pipeline(this).GenerateCode(); | |
| 310 } | |
| 311 | |
| 312 | |
| 313 class HOptimizedGraphBuilderWithPositions: public HOptimizedGraphBuilder { | 305 class HOptimizedGraphBuilderWithPositions: public HOptimizedGraphBuilder { |
| 314 public: | 306 public: |
| 315 explicit HOptimizedGraphBuilderWithPositions(CompilationInfo* info) | 307 explicit HOptimizedGraphBuilderWithPositions(CompilationInfo* info) |
| 316 : HOptimizedGraphBuilder(info) { | 308 : HOptimizedGraphBuilder(info) { |
| 317 } | 309 } |
| 318 | 310 |
| 319 #define DEF_VISIT(type) \ | 311 #define DEF_VISIT(type) \ |
| 320 void Visit##type(type* node) override { \ | 312 void Visit##type(type* node) override { \ |
| 321 SourcePosition old_position = SourcePosition::Unknown(); \ | 313 SourcePosition old_position = SourcePosition::Unknown(); \ |
| 322 if (node->position() != RelocInfo::kNoPosition) { \ | 314 if (node->position() != RelocInfo::kNoPosition) { \ |
| (...skipping 610 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 933 function, result, | 925 function, result, |
| 934 Compiler::NOT_CONCURRENT).ToHandle(&opt_code)) { | 926 Compiler::NOT_CONCURRENT).ToHandle(&opt_code)) { |
| 935 result = opt_code; | 927 result = opt_code; |
| 936 } | 928 } |
| 937 } | 929 } |
| 938 | 930 |
| 939 return result; | 931 return result; |
| 940 } | 932 } |
| 941 | 933 |
| 942 | 934 |
| 943 bool Compiler::EnsureCompiled(Handle<JSFunction> function, | 935 MaybeHandle<Code> Compiler::GetStubCode(Handle<JSFunction> function, |
| 944 ClearExceptionFlag flag) { | 936 CodeStub* stub) { |
| 937 // Build a "hybrid" CompilationInfo for a JSFunction/CodeStub pair. |
| 938 Zone zone; |
| 939 ParseInfo parse_info(&zone, function); |
| 940 CompilationInfo info(&parse_info); |
| 941 info.SetFunctionType(stub->GetCallInterfaceDescriptor().GetFunctionType()); |
| 942 info.MarkAsContextSpecializing(); |
| 943 info.MarkAsDeoptimizationEnabled(); |
| 944 info.SetStub(stub); |
| 945 |
| 946 // Run a "mini pipeline", extracted from compiler.cc. |
| 947 if (!ParseAndAnalyze(&parse_info)) return MaybeHandle<Code>(); |
| 948 return compiler::Pipeline(&info).GenerateCode(); |
| 949 } |
| 950 |
| 951 |
| 952 bool Compiler::Compile(Handle<JSFunction> function, ClearExceptionFlag flag) { |
| 945 if (function->is_compiled()) return true; | 953 if (function->is_compiled()) return true; |
| 946 MaybeHandle<Code> maybe_code = Compiler::GetLazyCode(function); | 954 MaybeHandle<Code> maybe_code = Compiler::GetLazyCode(function); |
| 947 Handle<Code> code; | 955 Handle<Code> code; |
| 948 if (!maybe_code.ToHandle(&code)) { | 956 if (!maybe_code.ToHandle(&code)) { |
| 949 if (flag == CLEAR_EXCEPTION) { | 957 if (flag == CLEAR_EXCEPTION) { |
| 950 function->GetIsolate()->clear_pending_exception(); | 958 function->GetIsolate()->clear_pending_exception(); |
| 951 } | 959 } |
| 952 return false; | 960 return false; |
| 953 } | 961 } |
| 954 function->ReplaceCode(*code); | 962 function->ReplaceCode(*code); |
| (...skipping 763 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1718 | 1726 |
| 1719 | 1727 |
| 1720 #if DEBUG | 1728 #if DEBUG |
| 1721 void CompilationInfo::PrintAstForTesting() { | 1729 void CompilationInfo::PrintAstForTesting() { |
| 1722 PrintF("--- Source from AST ---\n%s\n", | 1730 PrintF("--- Source from AST ---\n%s\n", |
| 1723 PrettyPrinter(isolate(), zone()).PrintProgram(literal())); | 1731 PrettyPrinter(isolate(), zone()).PrintProgram(literal())); |
| 1724 } | 1732 } |
| 1725 #endif | 1733 #endif |
| 1726 } // namespace internal | 1734 } // namespace internal |
| 1727 } // namespace v8 | 1735 } // namespace v8 |
| OLD | NEW |