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 | 8 |
9 #include "vm/ast_printer.h" | 9 #include "vm/ast_printer.h" |
10 #include "vm/code_generator.h" | 10 #include "vm/code_generator.h" |
11 #include "vm/code_patcher.h" | 11 #include "vm/code_patcher.h" |
12 #include "vm/dart_entry.h" | 12 #include "vm/dart_entry.h" |
13 #include "vm/debugger.h" | 13 #include "vm/debugger.h" |
14 #include "vm/deopt_instructions.h" | 14 #include "vm/deopt_instructions.h" |
15 #include "vm/disassembler.h" | 15 #include "vm/disassembler.h" |
16 #include "vm/exceptions.h" | 16 #include "vm/exceptions.h" |
17 #include "vm/flags.h" | 17 #include "vm/flags.h" |
18 #include "vm/flow_graph.h" | 18 #include "vm/flow_graph.h" |
19 #include "vm/flow_graph_allocator.h" | 19 #include "vm/flow_graph_allocator.h" |
20 #include "vm/flow_graph_builder.h" | 20 #include "vm/flow_graph_builder.h" |
21 #include "vm/flow_graph_compiler.h" | 21 #include "vm/flow_graph_compiler.h" |
22 #include "vm/flow_graph_inliner.h" | 22 #include "vm/flow_graph_inliner.h" |
23 #include "vm/flow_graph_optimizer.h" | 23 #include "vm/flow_graph_optimizer.h" |
| 24 #include "vm/flow_graph_type_propagator.h" |
24 #include "vm/il_printer.h" | 25 #include "vm/il_printer.h" |
25 #include "vm/longjump.h" | 26 #include "vm/longjump.h" |
26 #include "vm/object.h" | 27 #include "vm/object.h" |
27 #include "vm/object_store.h" | 28 #include "vm/object_store.h" |
28 #include "vm/os.h" | 29 #include "vm/os.h" |
29 #include "vm/parser.h" | 30 #include "vm/parser.h" |
30 #include "vm/scanner.h" | 31 #include "vm/scanner.h" |
31 #include "vm/symbols.h" | 32 #include "vm/symbols.h" |
32 #include "vm/timer.h" | 33 #include "vm/timer.h" |
33 | 34 |
(...skipping 12 matching lines...) Expand all Loading... |
46 DEFINE_FLAG(bool, propagate_types, true, "Do static type propagation."); | 47 DEFINE_FLAG(bool, propagate_types, true, "Do static type propagation."); |
47 DEFINE_FLAG(int, deoptimization_counter_threshold, 16, | 48 DEFINE_FLAG(int, deoptimization_counter_threshold, 16, |
48 "How many times we allow deoptimization before we disallow optimization."); | 49 "How many times we allow deoptimization before we disallow optimization."); |
49 DEFINE_FLAG(bool, use_inlining, true, "Enable call-site inlining"); | 50 DEFINE_FLAG(bool, use_inlining, true, "Enable call-site inlining"); |
50 DEFINE_FLAG(bool, range_analysis, true, "Enable range analysis"); | 51 DEFINE_FLAG(bool, range_analysis, true, "Enable range analysis"); |
51 DEFINE_FLAG(bool, verify_compiler, false, | 52 DEFINE_FLAG(bool, verify_compiler, false, |
52 "Enable compiler verification assertions"); | 53 "Enable compiler verification assertions"); |
53 DECLARE_FLAG(bool, print_flow_graph); | 54 DECLARE_FLAG(bool, print_flow_graph); |
54 DECLARE_FLAG(bool, print_flow_graph_optimized); | 55 DECLARE_FLAG(bool, print_flow_graph_optimized); |
55 DECLARE_FLAG(bool, trace_failed_optimization_attempts); | 56 DECLARE_FLAG(bool, trace_failed_optimization_attempts); |
56 | 57 DECLARE_FLAG(bool, trace_type_propagation); |
57 | 58 |
58 // Compile a function. Should call only if the function has not been compiled. | 59 // Compile a function. Should call only if the function has not been compiled. |
59 // Arg0: function object. | 60 // Arg0: function object. |
60 DEFINE_RUNTIME_ENTRY(CompileFunction, 1) { | 61 DEFINE_RUNTIME_ENTRY(CompileFunction, 1) { |
61 ASSERT(arguments.ArgCount() == kCompileFunctionRuntimeEntry.argument_count()); | 62 ASSERT(arguments.ArgCount() == kCompileFunctionRuntimeEntry.argument_count()); |
62 const Function& function = Function::CheckedHandle(arguments.ArgAt(0)); | 63 const Function& function = Function::CheckedHandle(arguments.ArgAt(0)); |
63 ASSERT(!function.HasCode()); | 64 ASSERT(!function.HasCode()); |
64 const Error& error = Error::Handle(Compiler::CompileFunction(function)); | 65 const Error& error = Error::Handle(Compiler::CompileFunction(function)); |
65 if (!error.IsNull()) { | 66 if (!error.IsNull()) { |
66 Exceptions::PropagateError(error); | 67 Exceptions::PropagateError(error); |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 | 184 |
184 // Inlining (mutates the flow graph) | 185 // Inlining (mutates the flow graph) |
185 if (FLAG_use_inlining) { | 186 if (FLAG_use_inlining) { |
186 TimerScope timer(FLAG_compiler_stats, | 187 TimerScope timer(FLAG_compiler_stats, |
187 &CompilerStats::graphinliner_timer); | 188 &CompilerStats::graphinliner_timer); |
188 FlowGraphInliner inliner(flow_graph); | 189 FlowGraphInliner inliner(flow_graph); |
189 inliner.Inline(); | 190 inliner.Inline(); |
190 // Use lists are maintained and validated by the inliner. | 191 // Use lists are maintained and validated by the inliner. |
191 } | 192 } |
192 | 193 |
| 194 if (FLAG_trace_type_propagation) { |
| 195 OS::Print("Before type propagation:\n"); |
| 196 FlowGraphPrinter printer(*flow_graph); |
| 197 printer.PrintBlocks(); |
| 198 } |
| 199 |
193 // Propagate types and eliminate more type tests. | 200 // Propagate types and eliminate more type tests. |
194 if (FLAG_propagate_types) { | 201 if (FLAG_propagate_types) { |
195 FlowGraphTypePropagator propagator(flow_graph); | 202 FlowGraphTypePropagator propagator(flow_graph); |
196 propagator.PropagateTypes(); | 203 propagator.Propagate(); |
197 } | 204 } |
198 | 205 |
199 // Propagate sminess from CheckSmi to phis. | 206 if (FLAG_trace_type_propagation) { |
| 207 OS::Print("After type propagation:\n"); |
| 208 FlowGraphPrinter printer(*flow_graph); |
| 209 printer.PrintBlocks(); |
| 210 } |
| 211 |
200 flow_graph->ComputeUseLists(); | 212 flow_graph->ComputeUseLists(); |
201 optimizer.PropagateSminess(); | |
202 | 213 |
203 // Use propagated class-ids to optimize further. | 214 // Use propagated class-ids to optimize further. |
204 optimizer.ApplyClassIds(); | 215 optimizer.ApplyClassIds(); |
205 | 216 |
206 // Recompute use lists after applying class ids. | 217 // Recompute use lists after applying class ids. |
207 flow_graph->ComputeUseLists(); | 218 flow_graph->ComputeUseLists(); |
208 | 219 |
209 // Do optimizations that depend on the propagated type information. | 220 // Do optimizations that depend on the propagated type information. |
210 optimizer.Canonicalize(); | 221 optimizer.Canonicalize(); |
211 | 222 |
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
639 Object::Handle(isolate->object_store()->sticky_error()); | 650 Object::Handle(isolate->object_store()->sticky_error()); |
640 isolate->object_store()->clear_sticky_error(); | 651 isolate->object_store()->clear_sticky_error(); |
641 isolate->set_long_jump_base(base); | 652 isolate->set_long_jump_base(base); |
642 return result.raw(); | 653 return result.raw(); |
643 } | 654 } |
644 UNREACHABLE(); | 655 UNREACHABLE(); |
645 return Object::null(); | 656 return Object::null(); |
646 } | 657 } |
647 | 658 |
648 } // namespace dart | 659 } // namespace dart |
OLD | NEW |