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

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

Issue 10388161: Initial work on computing SSA. (Closed) Base URL: https://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/flow_graph_builder.h" 5 #include "vm/flow_graph_builder.h"
6 6
7 #include "vm/ast_printer.h" 7 #include "vm/ast_printer.h"
8 #include "vm/bit_vector.h" 8 #include "vm/bit_vector.h"
9 #include "vm/code_descriptors.h" 9 #include "vm/code_descriptors.h"
10 #include "vm/dart_entry.h" 10 #include "vm/dart_entry.h"
(...skipping 2261 matching lines...) Expand 10 before | Expand all | Expand 10 after
2272 intptr_t next_index = (*parent)[current_index]; 2272 intptr_t next_index = (*parent)[current_index];
2273 if (next_index > start_index) { 2273 if (next_index > start_index) {
2274 CompressPath(start_index, next_index, parent, label); 2274 CompressPath(start_index, next_index, parent, label);
2275 (*label)[current_index] = 2275 (*label)[current_index] =
2276 Utils::Minimum((*label)[current_index], (*label)[next_index]); 2276 Utils::Minimum((*label)[current_index], (*label)[next_index]);
2277 (*parent)[current_index] = (*parent)[next_index]; 2277 (*parent)[current_index] = (*parent)[next_index];
2278 } 2278 }
2279 } 2279 }
2280 2280
2281 2281
2282 void FlowGraphBuilder::InsertPhis(GrowableArray<BlockEntryInstr*>* preorder,
2283 GrowableArray<BitVector*>* assigned_vars,
2284 intptr_t var_count,
2285 GrowableArray<BitVector*>* dom_frontier) {
2286 int block_count = preorder->length();
2287 // Map preorder block number to the highest variable index that has a phi
2288 // in that block. Use it to avoid inserting multiple phis for the same
2289 // variable.
2290 int* has_already = new int[block_count];
2291 // Map preorder block number to the highest variable index for which the
2292 // block went on the worklist. Use it to avoid adding the same block to
2293 // the worklist more than once for the same variable.
2294 int* work = new int[block_count];
2295
2296 // Initialize has_already and work.
2297 for (intptr_t block_index = 0; block_index < block_count; ++block_index) {
2298 has_already[block_index] = -1;
2299 work[block_index] = -1;
2300 }
2301
2302 // Insert phis for each variable in turn.
2303 GrowableArray<BlockEntryInstr*> worklist;
2304 for (intptr_t var_index = 0; var_index < var_count; ++var_index) {
2305 // Add to the worklist each block containing an assignment.
2306 for (intptr_t block_index = 0; block_index < block_count; ++block_index) {
2307 if ((*assigned_vars)[block_index]->Contains(var_index)) {
2308 work[block_index] = var_index;
2309 worklist.Add((*preorder)[block_index]);
2310 }
2311 }
2312
2313 while (!worklist.is_empty()) {
2314 BlockEntryInstr* current = worklist.Last();
2315 worklist.RemoveLast();
2316 // Ensure a phi for each block in the dominance frontier of current.
2317 BitVector::Iterator it((*dom_frontier)[current->preorder_number()]);
2318 while (!it.Done()) {
2319 int index = it.Current();
2320 if (has_already[index] < var_index) {
2321 BlockEntryInstr* block = (*preorder)[index];
2322 ASSERT(block->IsJoinEntry());
2323 block->AsJoinEntry()->InsertPhi(var_index);
2324 has_already[index] = var_index;
2325 if (work[index] < var_index) {
2326 work[index] = var_index;
2327 worklist.Add(block);
2328 }
2329 }
2330 }
2331 }
2332 }
2333
2334 delete[] work;
2335 delete[] has_already;
2336 }
2337
2338
2339 void FlowGraphBuilder::RenameLocals(intptr_t var_count) {
2340 // Renaming environment is an array of values or NULL.
2341
2342 // Top-down recursive traversal of the dominator tree. Pass a copy of the
2343 // renaming environment to all children but the last one.
2344
2345 // Visit each instruction in the block.
2346
2347 // For each StoreLocal at current context level that is not captured,
2348 // remove it from the graph and add it's rhs to the renaming environment.
2349
2350 // For each LoadLocal at current context level that is not captured,
2351 // remove it from the graph.
2352
2353 // For each use of a load local or store local, replace it with the value
2354 // in the environment.
2355
2356 // If the node does not dominate anything, process any phis in the
2357 // successor.
2358 }
2359
2360
2282 void FlowGraphBuilder::Bailout(const char* reason) { 2361 void FlowGraphBuilder::Bailout(const char* reason) {
2283 const char* kFormat = "FlowGraphBuilder Bailout: %s %s"; 2362 const char* kFormat = "FlowGraphBuilder Bailout: %s %s";
2284 const char* function_name = parsed_function_.function().ToCString(); 2363 const char* function_name = parsed_function_.function().ToCString();
2285 intptr_t len = OS::SNPrint(NULL, 0, kFormat, function_name, reason) + 1; 2364 intptr_t len = OS::SNPrint(NULL, 0, kFormat, function_name, reason) + 1;
2286 char* chars = reinterpret_cast<char*>( 2365 char* chars = reinterpret_cast<char*>(
2287 Isolate::Current()->current_zone()->Allocate(len)); 2366 Isolate::Current()->current_zone()->Allocate(len));
2288 OS::SNPrint(chars, len, kFormat, function_name, reason); 2367 OS::SNPrint(chars, len, kFormat, function_name, reason);
2289 const Error& error = Error::Handle( 2368 const Error& error = Error::Handle(
2290 LanguageError::New(String::Handle(String::New(chars)))); 2369 LanguageError::New(String::Handle(String::New(chars))));
2291 Isolate::Current()->long_jump_base()->Jump(1, error); 2370 Isolate::Current()->long_jump_base()->Jump(1, error);
2292 } 2371 }
2293 2372
2294 2373
2295 } // namespace dart 2374 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698