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

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

Issue 10356051: First steps toward a two stages new 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
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"
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 } 131 }
132 132
133 133
134 static void CompileParsedFunctionHelper( 134 static void CompileParsedFunctionHelper(
135 const ParsedFunction& parsed_function, bool optimized) { 135 const ParsedFunction& parsed_function, bool optimized) {
136 Isolate* isolate = Isolate::Current(); 136 Isolate* isolate = Isolate::Current();
137 TimerScope timer(FLAG_compiler_stats, &CompilerStats::codegen_timer); 137 TimerScope timer(FLAG_compiler_stats, &CompilerStats::codegen_timer);
138 const Function& function = parsed_function.function(); 138 const Function& function = parsed_function.function();
139 const char* function_fullname = function.ToFullyQualifiedCString(); 139 const char* function_fullname = function.ToFullyQualifiedCString();
140 bool is_compiled = false; 140 bool is_compiled = false;
141 if (FLAG_use_new_compiler) { 141 // TODO(srdjan): Remove once the old compiler has been ripped out.
142 ASSERT(!optimized); 142 #if defined(TARGET_ARCH_X64)
143 const bool use_new_compiler = true;
144 #else
145 const bool use_new_compiler = FLAG_use_new_compiler;
146 #endif
147 if (use_new_compiler) {
143 LongJump* old_base = isolate->long_jump_base(); 148 LongJump* old_base = isolate->long_jump_base();
144 LongJump bailout_jump; 149 LongJump bailout_jump;
145 isolate->set_long_jump_base(&bailout_jump); 150 isolate->set_long_jump_base(&bailout_jump);
146 if (setjmp(*bailout_jump.Set()) == 0) { 151 if (setjmp(*bailout_jump.Set()) == 0) {
147 FlowGraphBuilder graph_builder(parsed_function); 152 FlowGraphBuilder graph_builder(parsed_function);
148 graph_builder.BuildGraph(); 153 graph_builder.BuildGraph(optimized);
149 154
150 // The non-optimizing compiler compiles blocks in reverse postorder, 155 // The non-optimizing compiler compiles blocks in reverse postorder,
151 // because it is a 'natural' order for the human reader of the 156 // because it is a 'natural' order for the human reader of the
152 // generated code. 157 // generated code.
153 intptr_t length = graph_builder.postorder_block_entries().length(); 158 intptr_t length = graph_builder.postorder_block_entries().length();
154 GrowableArray<BlockEntryInstr*> block_order(length); 159 GrowableArray<BlockEntryInstr*> block_order(length);
155 for (intptr_t i = length - 1; i >= 0; --i) { 160 for (intptr_t i = length - 1; i >= 0; --i) {
156 block_order.Add(graph_builder.postorder_block_entries()[i]); 161 block_order.Add(graph_builder.postorder_block_entries()[i]);
157 } 162 }
158 163
164 if (optimized) {
165 // Transition to optimized code only from unoptimized code ...
166 // for now.
167 ASSERT(function.HasCode());
168 ASSERT(!function.HasOptimizedCode());
169 // Do not use type feedback to optimize a function that was
170 // deoptimized too often.
171 if (parsed_function.function().deoptimization_counter() <
172 FLAG_deoptimization_counter_threshold) {
173 // Extract type feedback etc.
174 }
175 }
159 Assembler assembler; 176 Assembler assembler;
160 FlowGraphCompiler graph_compiler(&assembler, parsed_function, 177 FlowGraphCompiler graph_compiler(&assembler, parsed_function,
161 block_order); 178 block_order, optimized);
162 graph_compiler.CompileGraph(); 179 graph_compiler.CompileGraph();
163 180
164 TimerScope timer(FLAG_compiler_stats, 181 TimerScope timer(FLAG_compiler_stats,
165 &CompilerStats::codefinalizer_timer); 182 &CompilerStats::codefinalizer_timer);
166 const Code& code = 183 const Code& code =
167 Code::Handle(Code::FinalizeCode(function_fullname, &assembler)); 184 Code::Handle(Code::FinalizeCode(function_fullname, &assembler));
168 code.set_is_optimized(false); 185 code.set_is_optimized(optimized);
169 graph_compiler.FinalizePcDescriptors(code); 186 graph_compiler.FinalizePcDescriptors(code);
170 graph_compiler.FinalizeStackmaps(code); 187 graph_compiler.FinalizeStackmaps(code);
171 graph_compiler.FinalizeVarDescriptors(code); 188 graph_compiler.FinalizeVarDescriptors(code);
172 graph_compiler.FinalizeExceptionHandlers(code); 189 graph_compiler.FinalizeExceptionHandlers(code);
173 function.set_unoptimized_code(code); 190 if (optimized) {
174 function.SetCode(code); 191 function.SetCode(code);
175 ASSERT(CodePatcher::CodeIsPatchable(code)); 192 CodePatcher::PatchEntry(Code::Handle(function.unoptimized_code()));
193 if (FLAG_trace_compiler) {
194 OS::Print("--> patching entry 0x%x\n",
195 Code::Handle(function.unoptimized_code()).EntryPoint());
196 }
197 } else {
198 function.set_unoptimized_code(code);
199 function.SetCode(code);
200 ASSERT(CodePatcher::CodeIsPatchable(code));
201 }
176 is_compiled = true; 202 is_compiled = true;
177 } else { 203 } else {
178 // We bailed out. 204 // We bailed out.
179 Error& bailout_error = Error::Handle( 205 Error& bailout_error = Error::Handle(
180 isolate->object_store()->sticky_error()); 206 isolate->object_store()->sticky_error());
181 isolate->object_store()->clear_sticky_error(); 207 isolate->object_store()->clear_sticky_error();
182 if (FLAG_trace_bailout) { 208 if (FLAG_trace_bailout) {
183 OS::Print("%s\n", bailout_error.ToErrorCString()); 209 OS::Print("%s\n", bailout_error.ToErrorCString());
184 } 210 }
185 } 211 }
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 isolate->object_store()->clear_sticky_error(); 466 isolate->object_store()->clear_sticky_error();
441 isolate->set_long_jump_base(base); 467 isolate->set_long_jump_base(base);
442 return result.raw(); 468 return result.raw();
443 } 469 }
444 UNREACHABLE(); 470 UNREACHABLE();
445 return Object::null(); 471 return Object::null();
446 } 472 }
447 473
448 474
449 } // namespace dart 475 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698