Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(53)

Side by Side Diff: runtime/vm/compiler.cc

Issue 10857016: Refactored FlowGraphBuilder into a separate FlowGraph representation. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Revision based on Kevin's review. Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | runtime/vm/flow_graph.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #include "vm/dart_entry.h" 11 #include "vm/dart_entry.h"
12 #include "vm/debugger.h" 12 #include "vm/debugger.h"
13 #include "vm/disassembler.h" 13 #include "vm/disassembler.h"
14 #include "vm/exceptions.h" 14 #include "vm/exceptions.h"
15 #include "vm/flags.h" 15 #include "vm/flags.h"
16 #include "vm/flow_graph.h"
16 #include "vm/flow_graph_allocator.h" 17 #include "vm/flow_graph_allocator.h"
17 #include "vm/flow_graph_builder.h" 18 #include "vm/flow_graph_builder.h"
18 #include "vm/flow_graph_compiler.h" 19 #include "vm/flow_graph_compiler.h"
19 #include "vm/flow_graph_optimizer.h" 20 #include "vm/flow_graph_optimizer.h"
20 #include "vm/il_printer.h" 21 #include "vm/il_printer.h"
21 #include "vm/longjump.h" 22 #include "vm/longjump.h"
22 #include "vm/object.h" 23 #include "vm/object.h"
23 #include "vm/object_store.h" 24 #include "vm/object_store.h"
24 #include "vm/os.h" 25 #include "vm/os.h"
25 #include "vm/parser.h" 26 #include "vm/parser.h"
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 TimerScope timer(FLAG_compiler_stats, &CompilerStats::codegen_timer); 126 TimerScope timer(FLAG_compiler_stats, &CompilerStats::codegen_timer);
126 bool is_compiled = false; 127 bool is_compiled = false;
127 Isolate* isolate = Isolate::Current(); 128 Isolate* isolate = Isolate::Current();
128 ASSERT(isolate->ic_data_array() == Array::null()); // Must be reset to null. 129 ASSERT(isolate->ic_data_array() == Array::null()); // Must be reset to null.
129 const intptr_t prev_deopt_id = isolate->deopt_id(); 130 const intptr_t prev_deopt_id = isolate->deopt_id();
130 isolate->set_deopt_id(0); 131 isolate->set_deopt_id(0);
131 LongJump* old_base = isolate->long_jump_base(); 132 LongJump* old_base = isolate->long_jump_base();
132 LongJump bailout_jump; 133 LongJump bailout_jump;
133 isolate->set_long_jump_base(&bailout_jump); 134 isolate->set_long_jump_base(&bailout_jump);
134 if (setjmp(*bailout_jump.Set()) == 0) { 135 if (setjmp(*bailout_jump.Set()) == 0) {
135 GrowableArray<BlockEntryInstr*> block_order; 136 FlowGraph* flow_graph = NULL;
136 // TimerScope needs an isolate to be properly terminated in case of a 137 // TimerScope needs an isolate to be properly terminated in case of a
137 // LongJump. 138 // LongJump.
138 { 139 {
139 TimerScope timer(FLAG_compiler_stats, 140 TimerScope timer(FLAG_compiler_stats,
140 &CompilerStats::graphbuilder_timer, 141 &CompilerStats::graphbuilder_timer,
141 isolate); 142 isolate);
142 if (optimized) { 143 if (optimized) {
143 // Transition to optimized code only from unoptimized code ... 144 // Transition to optimized code only from unoptimized code ...
144 // for now. 145 // for now.
145 ASSERT(parsed_function.function().HasCode()); 146 ASSERT(parsed_function.function().HasCode());
146 ASSERT(!parsed_function.function().HasOptimizedCode()); 147 ASSERT(!parsed_function.function().HasOptimizedCode());
147 // Extract type feedback before the graph is built, as the graph 148 // Extract type feedback before the graph is built, as the graph
148 // builder uses it to attach it to nodes. 149 // builder uses it to attach it to nodes.
149 // Do not use type feedback to optimize a function that was 150 // Do not use type feedback to optimize a function that was
150 // deoptimized too often. 151 // deoptimized too often.
151 if (parsed_function.function().deoptimization_counter() < 152 if (parsed_function.function().deoptimization_counter() <
152 FLAG_deoptimization_counter_threshold) { 153 FLAG_deoptimization_counter_threshold) {
153 const Code& unoptimized_code = 154 const Code& unoptimized_code =
154 Code::Handle(parsed_function.function().unoptimized_code()); 155 Code::Handle(parsed_function.function().unoptimized_code());
155 isolate->set_ic_data_array( 156 isolate->set_ic_data_array(
156 ExtractTypeFeedbackArray(unoptimized_code)); 157 ExtractTypeFeedbackArray(unoptimized_code));
157 } 158 }
158 } 159 }
159 FlowGraphBuilder graph_builder(parsed_function);
160 graph_builder.BuildGraph(optimized, use_ssa);
161 160
162 // The non-optimizing compiler compiles blocks in reverse postorder, 161 // Build the flow graph.
163 // because it is a 'natural' order for the human reader of the 162 FlowGraphBuilder builder(parsed_function);
164 // generated code. 163 flow_graph = builder.BuildGraph();
165 intptr_t length = graph_builder.postorder_block_entries().length(); 164
166 for (intptr_t i = length - 1; i >= 0; --i) { 165 // Transform to SSA.
167 block_order.Add(graph_builder.postorder_block_entries()[i]); 166 if (optimized && use_ssa) flow_graph->ComputeSSA();
167
168 if (FLAG_print_flow_graph) {
169 OS::Print("Before Optimizations\n");
170 FlowGraphPrinter printer(*flow_graph);
171 printer.PrintBlocks();
168 } 172 }
173 if (Dart::flow_graph_writer() != NULL) {
174 // Write flow graph to file.
175 FlowGraphVisualizer printer(*flow_graph);
176 printer.PrintFunction();
177 }
178
169 if (optimized) { 179 if (optimized) {
170 FlowGraphOptimizer optimizer(block_order); 180 FlowGraphOptimizer optimizer(*flow_graph);
171 optimizer.ApplyICData(); 181 optimizer.ApplyICData();
172 182
173 // Propagate types and eliminate more type tests. 183 // Propagate types and eliminate more type tests.
174 FlowGraphTypePropagator propagator(parsed_function, block_order); 184 FlowGraphTypePropagator propagator(*flow_graph);
175 propagator.PropagateTypes(); 185 propagator.PropagateTypes();
176 186
177 // Do optimizations that depend on the propagated type information. 187 // Do optimizations that depend on the propagated type information.
178 optimizer.OptimizeComputations(); 188 optimizer.OptimizeComputations();
179 189
180 if (use_ssa) { 190 if (use_ssa) {
181 // Perform register allocation on the SSA graph. 191 // Perform register allocation on the SSA graph.
182 FlowGraphAllocator allocator(block_order, &graph_builder); 192 FlowGraphAllocator allocator(*flow_graph);
183 allocator.AllocateRegisters(); 193 allocator.AllocateRegisters();
184 } 194 }
195
185 if (FLAG_print_flow_graph) { 196 if (FLAG_print_flow_graph) {
186 OS::Print("After Optimizations:\n"); 197 OS::Print("After Optimizations:\n");
187 FlowGraphPrinter printer(Function::Handle(), block_order); 198 FlowGraphPrinter printer(*flow_graph);
188 printer.PrintBlocks(); 199 printer.PrintBlocks();
189 } 200 }
190 } 201 }
191 } 202 }
192 203
193 bool is_leaf = false; 204 bool is_leaf = false;
194 if (optimized) { 205 if (optimized) {
195 FlowGraphAnalyzer analyzer(block_order); 206 FlowGraphAnalyzer analyzer(*flow_graph);
196 analyzer.Analyze(); 207 analyzer.Analyze();
197 is_leaf = analyzer.is_leaf(); 208 is_leaf = analyzer.is_leaf();
198 } 209 }
199 Assembler assembler; 210 Assembler assembler;
200 FlowGraphCompiler graph_compiler(&assembler, 211 FlowGraphCompiler graph_compiler(&assembler,
201 parsed_function, 212 *flow_graph,
202 block_order,
203 optimized, 213 optimized,
204 optimized && use_ssa, 214 optimized && use_ssa,
205 is_leaf); 215 is_leaf);
206 { 216 {
207 TimerScope timer(FLAG_compiler_stats, 217 TimerScope timer(FLAG_compiler_stats,
208 &CompilerStats::graphcompiler_timer, 218 &CompilerStats::graphcompiler_timer,
209 isolate); 219 isolate);
210 graph_compiler.CompileGraph(); 220 graph_compiler.CompileGraph();
211 } 221 }
212 { 222 {
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after
531 result = isolate->object_store()->sticky_error(); 541 result = isolate->object_store()->sticky_error();
532 isolate->object_store()->clear_sticky_error(); 542 isolate->object_store()->clear_sticky_error();
533 isolate->set_long_jump_base(base); 543 isolate->set_long_jump_base(base);
534 return result.raw(); 544 return result.raw();
535 } 545 }
536 UNREACHABLE(); 546 UNREACHABLE();
537 return Object::null(); 547 return Object::null();
538 } 548 }
539 549
540 } // namespace dart 550 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | runtime/vm/flow_graph.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698