| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "vm/compiler.h" | 5 #include "vm/compiler.h" |
| 6 | 6 |
| 7 #include "vm/assembler.h" | 7 #include "vm/assembler.h" |
| 8 #include "vm/ast_printer.h" | 8 #include "vm/ast_printer.h" |
| 9 #include "vm/code_generator.h" | 9 #include "vm/code_generator.h" |
| 10 #include "vm/code_patcher.h" | 10 #include "vm/code_patcher.h" |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 ASSERT(arguments.Count() == kCompileFunctionRuntimeEntry.argument_count()); | 50 ASSERT(arguments.Count() == kCompileFunctionRuntimeEntry.argument_count()); |
| 51 const Function& function = Function::CheckedHandle(arguments.At(0)); | 51 const Function& function = Function::CheckedHandle(arguments.At(0)); |
| 52 ASSERT(!function.HasCode()); | 52 ASSERT(!function.HasCode()); |
| 53 const Error& error = Error::Handle(Compiler::CompileFunction(function)); | 53 const Error& error = Error::Handle(Compiler::CompileFunction(function)); |
| 54 if (!error.IsNull()) { | 54 if (!error.IsNull()) { |
| 55 Exceptions::PropagateError(error); | 55 Exceptions::PropagateError(error); |
| 56 } | 56 } |
| 57 } | 57 } |
| 58 | 58 |
| 59 | 59 |
| 60 // Returns an array indexed by deopt id, containing the extracted ICData. |
| 61 static RawArray* ExtractTypeFeedbackArray(const Code& code) { |
| 62 ASSERT(!code.IsNull() && !code.is_optimized()); |
| 63 GrowableArray<intptr_t> deopt_ids; |
| 64 const GrowableObjectArray& ic_data_objs = |
| 65 GrowableObjectArray::Handle(GrowableObjectArray::New()); |
| 66 const intptr_t max_id = |
| 67 code.ExtractIcDataArraysAtCalls(&deopt_ids, ic_data_objs); |
| 68 const Array& result = Array::Handle(Array::New(max_id + 1)); |
| 69 for (intptr_t i = 0; i < deopt_ids.length(); i++) { |
| 70 intptr_t result_index = deopt_ids[i]; |
| 71 ASSERT(result.At(result_index) == Object::null()); |
| 72 result.SetAt(result_index, Object::Handle(ic_data_objs.At(i))); |
| 73 } |
| 74 return result.raw(); |
| 75 } |
| 76 |
| 77 |
| 60 RawError* Compiler::Compile(const Library& library, const Script& script) { | 78 RawError* Compiler::Compile(const Library& library, const Script& script) { |
| 61 Isolate* isolate = Isolate::Current(); | 79 Isolate* isolate = Isolate::Current(); |
| 62 LongJump* base = isolate->long_jump_base(); | 80 LongJump* base = isolate->long_jump_base(); |
| 63 LongJump jump; | 81 LongJump jump; |
| 64 isolate->set_long_jump_base(&jump); | 82 isolate->set_long_jump_base(&jump); |
| 65 if (setjmp(*jump.Set()) == 0) { | 83 if (setjmp(*jump.Set()) == 0) { |
| 66 if (FLAG_trace_compiler) { | 84 if (FLAG_trace_compiler) { |
| 67 HANDLESCOPE(isolate); | 85 HANDLESCOPE(isolate); |
| 68 const String& script_url = String::Handle(script.url()); | 86 const String& script_url = String::Handle(script.url()); |
| 69 // TODO(iposva): Extract script kind. | 87 // TODO(iposva): Extract script kind. |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 ASSERT(!parsed_function.function().HasOptimizedCode()); | 150 ASSERT(!parsed_function.function().HasOptimizedCode()); |
| 133 // Extract type feedback before the graph is built, as the graph | 151 // Extract type feedback before the graph is built, as the graph |
| 134 // builder uses it to attach it to nodes. | 152 // builder uses it to attach it to nodes. |
| 135 // Do not use type feedback to optimize a function that was | 153 // Do not use type feedback to optimize a function that was |
| 136 // deoptimized too often. | 154 // deoptimized too often. |
| 137 if (parsed_function.function().deoptimization_counter() < | 155 if (parsed_function.function().deoptimization_counter() < |
| 138 FLAG_deoptimization_counter_threshold) { | 156 FLAG_deoptimization_counter_threshold) { |
| 139 const Code& unoptimized_code = | 157 const Code& unoptimized_code = |
| 140 Code::Handle(parsed_function.function().unoptimized_code()); | 158 Code::Handle(parsed_function.function().unoptimized_code()); |
| 141 isolate->set_ic_data_array( | 159 isolate->set_ic_data_array( |
| 142 unoptimized_code.ExtractTypeFeedbackArray()); | 160 ExtractTypeFeedbackArray(unoptimized_code)); |
| 143 } | 161 } |
| 144 } | 162 } |
| 145 | 163 |
| 146 // Build the flow graph. | 164 // Build the flow graph. |
| 147 FlowGraphBuilder builder(parsed_function); | 165 FlowGraphBuilder builder(parsed_function); |
| 148 flow_graph = builder.BuildGraph(FlowGraphBuilder::kNotInlining); | 166 flow_graph = builder.BuildGraph(FlowGraphBuilder::kNotInlining); |
| 149 | 167 |
| 150 // Transform to SSA. | 168 // Transform to SSA. |
| 151 if (optimized) flow_graph->ComputeSSA(0); // Start at virtual register 0. | 169 if (optimized) flow_graph->ComputeSSA(0); // Start at virtual register 0. |
| 152 | 170 |
| (...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 560 result = isolate->object_store()->sticky_error(); | 578 result = isolate->object_store()->sticky_error(); |
| 561 isolate->object_store()->clear_sticky_error(); | 579 isolate->object_store()->clear_sticky_error(); |
| 562 isolate->set_long_jump_base(base); | 580 isolate->set_long_jump_base(base); |
| 563 return result.raw(); | 581 return result.raw(); |
| 564 } | 582 } |
| 565 UNREACHABLE(); | 583 UNREACHABLE(); |
| 566 return Object::null(); | 584 return Object::null(); |
| 567 } | 585 } |
| 568 | 586 |
| 569 } // namespace dart | 587 } // namespace dart |
| OLD | NEW |