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

Side by Side Diff: vm/flow_graph_builder.cc

Issue 10398015: Move FlowGraphPrinter to a new file. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
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 | vm/il_printer.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/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/code_descriptors.h" 8 #include "vm/code_descriptors.h"
9 #include "vm/dart_entry.h" 9 #include "vm/dart_entry.h"
10 #include "vm/flags.h" 10 #include "vm/flags.h"
11 #include "vm/il_printer.h"
11 #include "vm/intermediate_language.h" 12 #include "vm/intermediate_language.h"
12 #include "vm/longjump.h" 13 #include "vm/longjump.h"
13 #include "vm/object_store.h" 14 #include "vm/object_store.h"
14 #include "vm/os.h" 15 #include "vm/os.h"
15 #include "vm/parser.h" 16 #include "vm/parser.h"
16 #include "vm/resolver.h" 17 #include "vm/resolver.h"
17 #include "vm/stub_code.h" 18 #include "vm/stub_code.h"
18 19
19 namespace dart { 20 namespace dart {
20 21
(...skipping 2025 matching lines...) Expand 10 before | Expand all | Expand 10 after
2046 BuildLoadContext(node->context_var()); 2047 BuildLoadContext(node->context_var());
2047 EffectGraphVisitor for_finally_block(owner(), temp_index()); 2048 EffectGraphVisitor for_finally_block(owner(), temp_index());
2048 node->finally_block()->Visit(&for_finally_block); 2049 node->finally_block()->Visit(&for_finally_block);
2049 Append(for_finally_block); 2050 Append(for_finally_block);
2050 if (try_index >= 0) { 2051 if (try_index >= 0) {
2051 owner()->set_try_index(try_index); 2052 owner()->set_try_index(try_index);
2052 } 2053 }
2053 } 2054 }
2054 2055
2055 2056
2056 // Graph printing.
2057 class FlowGraphPrinter : public FlowGraphVisitor {
2058 public:
2059 FlowGraphPrinter(const Function& function,
2060 const GrowableArray<BlockEntryInstr*>& block_order)
2061 : FlowGraphVisitor(block_order), function_(function) { }
2062
2063 virtual ~FlowGraphPrinter() {}
2064
2065 // Print the instructions in a block terminated by newlines. Add "goto N"
2066 // to the end of the block if it ends with an unconditional jump to
2067 // another block and that block is not next in reverse postorder.
2068 void VisitBlocks();
2069
2070 // Visiting a computation prints it with no indentation or newline.
2071 #define DECLARE_VISIT_COMPUTATION(ShortName, ClassName) \
2072 virtual void Visit##ShortName(ClassName* comp);
2073
2074 // Visiting an instruction prints it with a four space indent and no
2075 // trailing newline. Basic block entries are labeled with their block
2076 // number.
2077 #define DECLARE_VISIT_INSTRUCTION(ShortName) \
2078 virtual void Visit##ShortName(ShortName##Instr* instr);
2079
2080 FOR_EACH_COMPUTATION(DECLARE_VISIT_COMPUTATION)
2081 FOR_EACH_INSTRUCTION(DECLARE_VISIT_INSTRUCTION)
2082
2083 #undef DECLARE_VISIT_COMPUTATION
2084 #undef DECLARE_VISIT_INSTRUCTION
2085
2086 private:
2087 const Function& function_;
2088
2089 DISALLOW_COPY_AND_ASSIGN(FlowGraphPrinter);
2090 };
2091
2092
2093 void FlowGraphPrinter::VisitBlocks() {
2094 OS::Print("==== %s\n", function_.ToFullyQualifiedCString());
2095
2096 for (intptr_t i = 0; i < block_order_.length(); ++i) {
2097 // Print the block entry.
2098 Instruction* current = block_order_[i]->Accept(this);
2099 // And all the successors until an exit, branch, or a block entry.
2100 while ((current != NULL) && !current->IsBlockEntry()) {
2101 OS::Print("\n");
2102 current = current->Accept(this);
2103 }
2104 BlockEntryInstr* successor =
2105 (current == NULL) ? NULL : current->AsBlockEntry();
2106 if (successor != NULL) {
2107 // For readability label blocks with their reverse postorder index,
2108 // not their postorder block number, so the first block is 0 (not
2109 // n-1).
2110 OS::Print(" goto %d", reverse_index(successor->postorder_number()));
2111 }
2112 OS::Print("\n");
2113 }
2114 }
2115
2116
2117 void FlowGraphPrinter::VisitUse(UseVal* val) {
2118 OS::Print("t%d", val->definition()->temp_index());
2119 }
2120
2121
2122 void FlowGraphPrinter::VisitConstant(ConstantVal* val) {
2123 OS::Print("#%s", val->value().ToCString());
2124 }
2125
2126
2127 void FlowGraphPrinter::VisitAssertAssignable(AssertAssignableComp* comp) {
2128 OS::Print("AssertAssignable(");
2129 comp->value()->Accept(this);
2130 OS::Print(", %s, '%s'",
2131 String::Handle(comp->dst_type().Name()).ToCString(),
2132 comp->dst_name().ToCString());
2133 if (comp->instantiator_type_arguments() != NULL) {
2134 OS::Print(" (instantiator:");
2135 comp->instantiator_type_arguments()->Accept(this);
2136 }
2137 OS::Print(")");
2138 }
2139
2140
2141 void FlowGraphPrinter::VisitAssertBoolean(AssertBooleanComp* comp) {
2142 OS::Print("AssertBoolean(");
2143 comp->value()->Accept(this);
2144 OS::Print(")");
2145 }
2146
2147
2148 void FlowGraphPrinter::VisitCurrentContext(CurrentContextComp* comp) {
2149 OS::Print("CurrentContext");
2150 }
2151
2152
2153 void FlowGraphPrinter::VisitClosureCall(ClosureCallComp* comp) {
2154 OS::Print("ClosureCall(");
2155 comp->context()->Accept(this);
2156 for (intptr_t i = 0; i < comp->ArgumentCount(); ++i) {
2157 OS::Print(", ");
2158 comp->ArgumentAt(i)->Accept(this);
2159 }
2160 OS::Print(")");
2161 }
2162
2163
2164 void FlowGraphPrinter::VisitInstanceCall(InstanceCallComp* comp) {
2165 OS::Print("InstanceCall(%s", comp->function_name().ToCString());
2166 for (intptr_t i = 0; i < comp->ArgumentCount(); ++i) {
2167 OS::Print(", ");
2168 comp->ArgumentAt(i)->Accept(this);
2169 }
2170 OS::Print(")");
2171 }
2172
2173
2174 void FlowGraphPrinter::VisitStrictCompare(StrictCompareComp* comp) {
2175 OS::Print("StrictCompare(%s, ", Token::Str(comp->kind()));
2176 comp->left()->Accept(this);
2177 OS::Print(", ");
2178 comp->right()->Accept(this);
2179 OS::Print(")");
2180 }
2181
2182
2183 void FlowGraphPrinter::VisitEqualityCompare(EqualityCompareComp* comp) {
2184 comp->left()->Accept(this);
2185 OS::Print(" == ");
2186 comp->right()->Accept(this);
2187 }
2188
2189
2190 void FlowGraphPrinter::VisitStaticCall(StaticCallComp* comp) {
2191 OS::Print("StaticCall(%s",
2192 String::Handle(comp->function().name()).ToCString());
2193 for (intptr_t i = 0; i < comp->ArgumentCount(); ++i) {
2194 OS::Print(", ");
2195 comp->ArgumentAt(i)->Accept(this);
2196 }
2197 OS::Print(")");
2198 }
2199
2200
2201 void FlowGraphPrinter::VisitLoadLocal(LoadLocalComp* comp) {
2202 OS::Print("LoadLocal(%s lvl:%d)",
2203 comp->local().name().ToCString(), comp->context_level());
2204 }
2205
2206
2207 void FlowGraphPrinter::VisitStoreLocal(StoreLocalComp* comp) {
2208 OS::Print("StoreLocal(%s, ", comp->local().name().ToCString());
2209 comp->value()->Accept(this);
2210 OS::Print(", lvl: %d)", comp->context_level());
2211 }
2212
2213
2214 void FlowGraphPrinter::VisitNativeCall(NativeCallComp* comp) {
2215 OS::Print("NativeCall(%s)", comp->native_name().ToCString());
2216 }
2217
2218
2219 void FlowGraphPrinter::VisitLoadInstanceField(LoadInstanceFieldComp* comp) {
2220 OS::Print("LoadInstanceField(%s, ",
2221 String::Handle(comp->field().name()).ToCString());
2222 comp->instance()->Accept(this);
2223 OS::Print(")");
2224 }
2225
2226
2227 void FlowGraphPrinter::VisitStoreInstanceField(StoreInstanceFieldComp* comp) {
2228 OS::Print("StoreInstanceField(%s, ",
2229 String::Handle(comp->field().name()).ToCString());
2230 comp->instance()->Accept(this);
2231 OS::Print(", ");
2232 comp->value()->Accept(this);
2233 OS::Print(")");
2234 }
2235
2236
2237 void FlowGraphPrinter::VisitLoadStaticField(LoadStaticFieldComp* comp) {
2238 OS::Print("LoadStaticField(%s)",
2239 String::Handle(comp->field().name()).ToCString());
2240 }
2241
2242
2243 void FlowGraphPrinter::VisitStoreStaticField(StoreStaticFieldComp* comp) {
2244 OS::Print("StoreStaticField(%s, ",
2245 String::Handle(comp->field().name()).ToCString());
2246 comp->value()->Accept(this);
2247 OS::Print(")");
2248 }
2249
2250
2251 void FlowGraphPrinter::VisitStoreIndexed(StoreIndexedComp* comp) {
2252 OS::Print("StoreIndexed(");
2253 comp->array()->Accept(this);
2254 OS::Print(", ");
2255 comp->index()->Accept(this);
2256 OS::Print(", ");
2257 comp->value()->Accept(this);
2258 OS::Print(")");
2259 }
2260
2261
2262 void FlowGraphPrinter::VisitInstanceSetter(InstanceSetterComp* comp) {
2263 OS::Print("InstanceSetter(");
2264 comp->receiver()->Accept(this);
2265 OS::Print(", ");
2266 comp->value()->Accept(this);
2267 OS::Print(")");
2268 }
2269
2270
2271 void FlowGraphPrinter::VisitStaticSetter(StaticSetterComp* comp) {
2272 OS::Print("StaticSetter(");
2273 comp->value()->Accept(this);
2274 OS::Print(")");
2275 }
2276
2277
2278 void FlowGraphPrinter::VisitBooleanNegate(BooleanNegateComp* comp) {
2279 OS::Print("! ");
2280 comp->value()->Accept(this);
2281 }
2282
2283
2284 void FlowGraphPrinter::VisitInstanceOf(InstanceOfComp* comp) {
2285 comp->value()->Accept(this);
2286 OS::Print(" %s %s",
2287 comp->negate_result() ? "ISNOT" : "IS",
2288 String::Handle(comp->type().Name()).ToCString());
2289 if (comp->type_arguments() != NULL) {
2290 OS::Print(" (type-arg:");
2291 comp->type_arguments()->Accept(this);
2292 }
2293 OS::Print(")");
2294 }
2295
2296
2297 void FlowGraphPrinter::VisitAllocateObject(AllocateObjectComp* comp) {
2298 OS::Print("AllocateObject(%s",
2299 Class::Handle(comp->constructor().owner()).ToCString());
2300 for (intptr_t i = 0; i < comp->arguments().length(); i++) {
2301 OS::Print(", ");
2302 comp->arguments()[i]->Accept(this);
2303 }
2304 OS::Print(")");
2305 }
2306
2307
2308 void FlowGraphPrinter::VisitAllocateObjectWithBoundsCheck(
2309 AllocateObjectWithBoundsCheckComp* comp) {
2310 OS::Print("AllocateObjectWithBoundsCheck(%s",
2311 Class::Handle(comp->constructor().owner()).ToCString());
2312 for (intptr_t i = 0; i < comp->arguments().length(); i++) {
2313 OS::Print(", ");
2314 comp->arguments()[i]->Accept(this);
2315 }
2316 OS::Print(")");
2317 }
2318
2319
2320 void FlowGraphPrinter::VisitCreateArray(CreateArrayComp* comp) {
2321 OS::Print("CreateArray(");
2322 for (int i = 0; i < comp->ElementCount(); ++i) {
2323 if (i != 0) OS::Print(", ");
2324 comp->ElementAt(i)->Accept(this);
2325 }
2326 if (comp->ElementCount() > 0) OS::Print(", ");
2327 comp->element_type()->Accept(this);
2328 OS::Print(")");
2329 }
2330
2331
2332 void FlowGraphPrinter::VisitCreateClosure(CreateClosureComp* comp) {
2333 OS::Print("CreateClosure(%s", comp->function().ToCString());
2334 if (comp->type_arguments() != NULL) {
2335 OS::Print(", ");
2336 comp->type_arguments()->Accept(this);
2337 }
2338 OS::Print(")");
2339 }
2340
2341
2342 void FlowGraphPrinter::VisitNativeLoadField(NativeLoadFieldComp* comp) {
2343 OS::Print("NativeLoadField(");
2344 comp->value()->Accept(this);
2345 OS::Print(", %d)", comp->offset_in_bytes());
2346 }
2347
2348
2349 void FlowGraphPrinter::VisitInstantiateTypeArguments(
2350 InstantiateTypeArgumentsComp* comp) {
2351 const String& type_args = String::Handle(comp->type_arguments().Name());
2352 OS::Print("InstantiateTypeArguments(%s, ", type_args.ToCString());
2353 comp->instantiator()->Accept(this);
2354 OS::Print(")");
2355 }
2356
2357
2358 void FlowGraphPrinter::VisitExtractConstructorTypeArguments(
2359 ExtractConstructorTypeArgumentsComp* comp) {
2360 const String& type_args = String::Handle(comp->type_arguments().Name());
2361 OS::Print("ExtractConstructorTypeArguments(%s, ", type_args.ToCString());
2362 comp->instantiator()->Accept(this);
2363 OS::Print(")");
2364 }
2365
2366
2367 void FlowGraphPrinter::VisitExtractConstructorInstantiator(
2368 ExtractConstructorInstantiatorComp* comp) {
2369 OS::Print("ExtractConstructorInstantiator(");
2370 comp->instantiator()->Accept(this);
2371 OS::Print(", ");
2372 comp->discard_value()->Accept(this);
2373 OS::Print(")");
2374 }
2375
2376
2377 void FlowGraphPrinter::VisitAllocateContext(AllocateContextComp* comp) {
2378 OS::Print("AllocateContext(%d)", comp->num_context_variables());
2379 }
2380
2381
2382 void FlowGraphPrinter::VisitChainContext(ChainContextComp* comp) {
2383 OS::Print("ChainContext(");
2384 comp->context_value()->Accept(this);
2385 OS::Print(")");
2386 }
2387
2388
2389 void FlowGraphPrinter::VisitCloneContext(CloneContextComp* comp) {
2390 OS::Print("CloneContext(");
2391 comp->context_value()->Accept(this);
2392 OS::Print(")");
2393 }
2394
2395
2396 void FlowGraphPrinter::VisitCatchEntry(CatchEntryComp* comp) {
2397 OS::Print("CatchEntry(%s, %s)",
2398 comp->exception_var().name().ToCString(),
2399 comp->stacktrace_var().name().ToCString());
2400 }
2401
2402
2403 void FlowGraphPrinter::VisitStoreContext(StoreContextComp* comp) {
2404 OS::Print("StoreContext(");
2405 comp->value()->Accept(this);
2406 OS::Print(")");
2407 }
2408
2409
2410 void FlowGraphPrinter::VisitJoinEntry(JoinEntryInstr* instr) {
2411 OS::Print("%2d: [join]", reverse_index(instr->postorder_number()));
2412 }
2413
2414
2415 void FlowGraphPrinter::VisitTargetEntry(TargetEntryInstr* instr) {
2416 OS::Print("%2d: [target", reverse_index(instr->postorder_number()));
2417 if (instr->HasTryIndex()) {
2418 OS::Print(" catch %d]", instr->try_index());
2419 } else {
2420 OS::Print("]");
2421 }
2422 }
2423
2424
2425 void FlowGraphPrinter::VisitDo(DoInstr* instr) {
2426 OS::Print(" ");
2427 instr->computation()->Accept(this);
2428 }
2429
2430
2431 void FlowGraphPrinter::VisitBind(BindInstr* instr) {
2432 OS::Print(" t%d <- ", instr->temp_index());
2433 instr->computation()->Accept(this);
2434 }
2435
2436
2437 void FlowGraphPrinter::VisitPickTemp(PickTempInstr* instr) {
2438 OS::Print(" t%d <- Pick(t%d)", instr->temp_index(), instr->source());
2439 }
2440
2441
2442 void FlowGraphPrinter::VisitTuckTemp(TuckTempInstr* instr) {
2443 OS::Print(" t%d := t%d", instr->destination(), instr->source());
2444 }
2445
2446
2447 void FlowGraphPrinter::VisitReturn(ReturnInstr* instr) {
2448 OS::Print(" return ");
2449 instr->value()->Accept(this);
2450 }
2451
2452
2453 void FlowGraphPrinter::VisitThrow(ThrowInstr* instr) {
2454 OS::Print("Throw(");
2455 instr->exception()->Accept(this);
2456 OS::Print(")");
2457 }
2458
2459
2460 void FlowGraphPrinter::VisitReThrow(ReThrowInstr* instr) {
2461 OS::Print("ReThrow(");
2462 instr->exception()->Accept(this);
2463 OS::Print(", ");
2464 instr->stack_trace()->Accept(this);
2465 OS::Print(")");
2466 }
2467
2468
2469 void FlowGraphPrinter::VisitBranch(BranchInstr* instr) {
2470 OS::Print(" if ");
2471 instr->value()->Accept(this);
2472 OS::Print(" goto(%d, %d)",
2473 reverse_index(instr->true_successor()->postorder_number()),
2474 reverse_index(instr->false_successor()->postorder_number()));
2475 }
2476
2477
2478 void FlowGraphBuilder::BuildGraph(bool for_optimized) { 2057 void FlowGraphBuilder::BuildGraph(bool for_optimized) {
2479 if (FLAG_print_ast) { 2058 if (FLAG_print_ast) {
2480 // Print the function ast before IL generation. 2059 // Print the function ast before IL generation.
2481 AstPrinter::PrintFunctionNodes(parsed_function()); 2060 AstPrinter::PrintFunctionNodes(parsed_function());
2482 } 2061 }
2483 // Compilation can be nested, preserve the computation-id. 2062 // Compilation can be nested, preserve the computation-id.
2484 Isolate* isolate = Isolate::Current(); 2063 Isolate* isolate = Isolate::Current();
2485 const intptr_t prev_cid = isolate->computation_id(); 2064 const intptr_t prev_cid = isolate->computation_id();
2486 isolate->set_computation_id(0); 2065 isolate->set_computation_id(0);
2487 const Function& function = parsed_function().function(); 2066 const Function& function = parsed_function().function();
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
2619 char* chars = reinterpret_cast<char*>( 2198 char* chars = reinterpret_cast<char*>(
2620 Isolate::Current()->current_zone()->Allocate(len)); 2199 Isolate::Current()->current_zone()->Allocate(len));
2621 OS::SNPrint(chars, len, kFormat, function_name, reason); 2200 OS::SNPrint(chars, len, kFormat, function_name, reason);
2622 const Error& error = Error::Handle( 2201 const Error& error = Error::Handle(
2623 LanguageError::New(String::Handle(String::New(chars)))); 2202 LanguageError::New(String::Handle(String::New(chars))));
2624 Isolate::Current()->long_jump_base()->Jump(1, error); 2203 Isolate::Current()->long_jump_base()->Jump(1, error);
2625 } 2204 }
2626 2205
2627 2206
2628 } // namespace dart 2207 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | vm/il_printer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698