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 10431006: First step toward an optimizing compiler: (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 7 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_builder.h » ('j') | runtime/vm/flow_graph_optimizer.cc » ('J')
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_builder.h" 16 #include "vm/flow_graph_builder.h"
17 #include "vm/flow_graph_compiler.h" 17 #include "vm/flow_graph_compiler.h"
18 #include "vm/flow_graph_optimizer.h"
18 #include "vm/longjump.h" 19 #include "vm/longjump.h"
19 #include "vm/object.h" 20 #include "vm/object.h"
20 #include "vm/object_store.h" 21 #include "vm/object_store.h"
21 #include "vm/opt_code_generator.h" 22 #include "vm/opt_code_generator.h"
22 #include "vm/os.h" 23 #include "vm/os.h"
23 #include "vm/parser.h" 24 #include "vm/parser.h"
24 #include "vm/scanner.h" 25 #include "vm/scanner.h"
25 #include "vm/timer.h" 26 #include "vm/timer.h"
26 27
27 namespace dart { 28 namespace dart {
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 // Returns an array indexed by computation id, containing the extracted ICData. 87 // Returns an array indexed by computation id, containing the extracted ICData.
87 static RawArray* ExtractTypeFeedbackArray(const Code& code) { 88 static RawArray* ExtractTypeFeedbackArray(const Code& code) {
88 ASSERT(!code.IsNull() && !code.is_optimized()); 89 ASSERT(!code.IsNull() && !code.is_optimized());
89 GrowableArray<intptr_t> computation_ids; 90 GrowableArray<intptr_t> computation_ids;
90 const GrowableObjectArray& ic_data_objs = 91 const GrowableObjectArray& ic_data_objs =
91 GrowableObjectArray::Handle(GrowableObjectArray::New()); 92 GrowableObjectArray::Handle(GrowableObjectArray::New());
92 const intptr_t max_id = 93 const intptr_t max_id =
93 code.ExtractIcDataArraysAtCalls(&computation_ids, ic_data_objs); 94 code.ExtractIcDataArraysAtCalls(&computation_ids, ic_data_objs);
94 const Array& result = Array::Handle(Array::New(max_id + 1)); 95 const Array& result = Array::Handle(Array::New(max_id + 1));
95 for (intptr_t i = 0; i < computation_ids.length(); i++) { 96 for (intptr_t i = 0; i < computation_ids.length(); i++) {
96 ASSERT(result.At(i) == Object::null()); 97 intptr_t result_index = computation_ids[i];
97 result.SetAt(i, Object::Handle(ic_data_objs.At(i))); 98 ASSERT(result.At(result_index) == Object::null());
99 result.SetAt(result_index, Object::Handle(ic_data_objs.At(i)));
98 } 100 }
99 return result.raw(); 101 return result.raw();
100 } 102 }
101 103
102 104
103 RawError* Compiler::Compile(const Library& library, const Script& script) { 105 RawError* Compiler::Compile(const Library& library, const Script& script) {
104 Isolate* isolate = Isolate::Current(); 106 Isolate* isolate = Isolate::Current();
105 LongJump* base = isolate->long_jump_base(); 107 LongJump* base = isolate->long_jump_base();
106 LongJump jump; 108 LongJump jump;
107 isolate->set_long_jump_base(&jump); 109 isolate->set_long_jump_base(&jump);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 Code::Handle(function.unoptimized_code()).EntryPoint()); 148 Code::Handle(function.unoptimized_code()).EntryPoint());
147 } 149 }
148 } 150 }
149 151
150 152
151 // Return false if bailed out. 153 // Return false if bailed out.
152 static bool CompileWithNewCompiler( 154 static bool CompileWithNewCompiler(
153 const ParsedFunction& parsed_function, bool optimized) { 155 const ParsedFunction& parsed_function, bool optimized) {
154 bool is_compiled = false; 156 bool is_compiled = false;
155 Isolate* isolate = Isolate::Current(); 157 Isolate* isolate = Isolate::Current();
158 const intptr_t prev_cid = isolate->computation_id();
159 isolate->set_computation_id(0);
156 LongJump* old_base = isolate->long_jump_base(); 160 LongJump* old_base = isolate->long_jump_base();
157 LongJump bailout_jump; 161 LongJump bailout_jump;
158 isolate->set_long_jump_base(&bailout_jump); 162 isolate->set_long_jump_base(&bailout_jump);
159 if (setjmp(*bailout_jump.Set()) == 0) { 163 if (setjmp(*bailout_jump.Set()) == 0) {
160 GrowableArray<BlockEntryInstr*> block_order; 164 GrowableArray<BlockEntryInstr*> block_order;
161 // TimerScope needs an isolate to be properly terminated in case of a 165 // TimerScope needs an isolate to be properly terminated in case of a
162 // LongJump. 166 // LongJump.
163 { 167 {
164 TimerScope timer(FLAG_compiler_stats, 168 TimerScope timer(FLAG_compiler_stats,
165 &CompilerStats::graphbuilder_timer, 169 &CompilerStats::graphbuilder_timer,
(...skipping 18 matching lines...) Expand all
184 FlowGraphBuilder graph_builder(parsed_function); 188 FlowGraphBuilder graph_builder(parsed_function);
185 graph_builder.BuildGraph(optimized); 189 graph_builder.BuildGraph(optimized);
186 190
187 // The non-optimizing compiler compiles blocks in reverse postorder, 191 // The non-optimizing compiler compiles blocks in reverse postorder,
188 // because it is a 'natural' order for the human reader of the 192 // because it is a 'natural' order for the human reader of the
189 // generated code. 193 // generated code.
190 intptr_t length = graph_builder.postorder_block_entries().length(); 194 intptr_t length = graph_builder.postorder_block_entries().length();
191 for (intptr_t i = length - 1; i >= 0; --i) { 195 for (intptr_t i = length - 1; i >= 0; --i) {
192 block_order.Add(graph_builder.postorder_block_entries()[i]); 196 block_order.Add(graph_builder.postorder_block_entries()[i]);
193 } 197 }
198 if (optimized) {
199 FlowGraphOptimizer optimizer(block_order);
200 optimizer.ApplyICData();
201 }
194 } 202 }
195 203
196 Assembler assembler; 204 Assembler assembler;
197 FlowGraphCompiler graph_compiler(&assembler, parsed_function, 205 FlowGraphCompiler graph_compiler(&assembler, parsed_function,
198 block_order, optimized); 206 block_order, optimized);
199 { 207 {
200 TimerScope timer(FLAG_compiler_stats, 208 TimerScope timer(FLAG_compiler_stats,
201 &CompilerStats::graphcompiler_timer, 209 &CompilerStats::graphcompiler_timer,
202 isolate); 210 isolate);
203 graph_compiler.CompileGraph(); 211 graph_compiler.CompileGraph();
(...skipping 29 matching lines...) Expand all
233 // We bailed out. 241 // We bailed out.
234 Error& bailout_error = Error::Handle( 242 Error& bailout_error = Error::Handle(
235 isolate->object_store()->sticky_error()); 243 isolate->object_store()->sticky_error());
236 isolate->object_store()->clear_sticky_error(); 244 isolate->object_store()->clear_sticky_error();
237 if (FLAG_trace_bailout) { 245 if (FLAG_trace_bailout) {
238 OS::Print("%s\n", bailout_error.ToErrorCString()); 246 OS::Print("%s\n", bailout_error.ToErrorCString());
239 } 247 }
240 is_compiled = false; 248 is_compiled = false;
241 } 249 }
242 isolate->set_long_jump_base(old_base); 250 isolate->set_long_jump_base(old_base);
251 isolate->set_computation_id(prev_cid);
243 return is_compiled; 252 return is_compiled;
244 } 253 }
245 254
246 255
247 static void CompileWithOldCompiler( 256 static void CompileWithOldCompiler(
248 const ParsedFunction& parsed_function, bool optimized) { 257 const ParsedFunction& parsed_function, bool optimized) {
249 const Function& function = parsed_function.function(); 258 const Function& function = parsed_function.function();
250 Assembler assembler; 259 Assembler assembler;
251 if (optimized) { 260 if (optimized) {
252 // Transition to optimized code only from unoptimized code ... 261 // Transition to optimized code only from unoptimized code ...
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
538 isolate->object_store()->clear_sticky_error(); 547 isolate->object_store()->clear_sticky_error();
539 isolate->set_long_jump_base(base); 548 isolate->set_long_jump_base(base);
540 return result.raw(); 549 return result.raw();
541 } 550 }
542 UNREACHABLE(); 551 UNREACHABLE();
543 return Object::null(); 552 return Object::null();
544 } 553 }
545 554
546 555
547 } // namespace dart 556 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | runtime/vm/flow_graph_builder.h » ('j') | runtime/vm/flow_graph_optimizer.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698