| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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_inliner.h" | 5 #include "vm/flow_graph_inliner.h" |
| 6 | 6 |
| 7 #include "vm/block_scheduler.h" | 7 #include "vm/block_scheduler.h" |
| 8 #include "vm/compiler.h" | 8 #include "vm/compiler.h" |
| 9 #include "vm/flags.h" | 9 #include "vm/flags.h" |
| 10 #include "vm/flow_graph.h" | 10 #include "vm/flow_graph.h" |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 static bool IsCallRecursive(const Function& function, Definition* call) { | 62 static bool IsCallRecursive(const Function& function, Definition* call) { |
| 63 Environment* env = call->env(); | 63 Environment* env = call->env(); |
| 64 while (env != NULL) { | 64 while (env != NULL) { |
| 65 if (function.raw() == env->function().raw()) return true; | 65 if (function.raw() == env->function().raw()) return true; |
| 66 env = env->outer(); | 66 env = env->outer(); |
| 67 } | 67 } |
| 68 return false; | 68 return false; |
| 69 } | 69 } |
| 70 | 70 |
| 71 | 71 |
| 72 // TODO(zerny): Remove the ChildrenVisitor and SourceLabelResetter once we have | |
| 73 // moved the label/join map for control flow out of the AST and into the flow | |
| 74 // graph builder. | |
| 75 | |
| 76 // Default visitor to traverse child nodes. | |
| 77 class ChildrenVisitor : public AstNodeVisitor { | |
| 78 public: | |
| 79 ChildrenVisitor() { } | |
| 80 #define DEFINE_VISIT(BaseName) \ | |
| 81 virtual void Visit##BaseName##Node(BaseName##Node* node) { \ | |
| 82 node->VisitChildren(this); \ | |
| 83 } | |
| 84 | |
| 85 FOR_EACH_NODE(DEFINE_VISIT); | |
| 86 #undef DEFINE_VISIT | |
| 87 }; | |
| 88 | |
| 89 | |
| 90 // Visitor to clear each AST node containing source labels. | |
| 91 class SourceLabelResetter : public ChildrenVisitor { | |
| 92 public: | |
| 93 SourceLabelResetter() { } | |
| 94 virtual void VisitSequenceNode(SequenceNode* node) { | |
| 95 Reset(node, node->label()); | |
| 96 } | |
| 97 virtual void VisitCaseNode(CaseNode* node) { | |
| 98 Reset(node, node->label()); | |
| 99 } | |
| 100 virtual void VisitSwitchNode(SwitchNode* node) { | |
| 101 Reset(node, node->label()); | |
| 102 } | |
| 103 virtual void VisitWhileNode(WhileNode* node) { | |
| 104 Reset(node, node->label()); | |
| 105 } | |
| 106 virtual void VisitDoWhileNode(DoWhileNode* node) { | |
| 107 Reset(node, node->label()); | |
| 108 } | |
| 109 virtual void VisitForNode(ForNode* node) { | |
| 110 Reset(node, node->label()); | |
| 111 } | |
| 112 virtual void VisitJumpNode(JumpNode* node) { | |
| 113 Reset(node, node->label()); | |
| 114 } | |
| 115 void Reset(AstNode* node, SourceLabel* lbl) { | |
| 116 node->VisitChildren(this); | |
| 117 if (lbl == NULL) return; | |
| 118 lbl->join_for_break_ = NULL; | |
| 119 lbl->join_for_continue_ = NULL; | |
| 120 } | |
| 121 }; | |
| 122 | |
| 123 | |
| 124 // Helper to create a parameter stub from an actual argument. | 72 // Helper to create a parameter stub from an actual argument. |
| 125 static Definition* CreateParameterStub(intptr_t i, | 73 static Definition* CreateParameterStub(intptr_t i, |
| 126 Value* argument, | 74 Value* argument, |
| 127 FlowGraph* graph) { | 75 FlowGraph* graph) { |
| 128 ConstantInstr* constant = argument->definition()->AsConstant(); | 76 ConstantInstr* constant = argument->definition()->AsConstant(); |
| 129 if (constant != NULL) { | 77 if (constant != NULL) { |
| 130 return new ConstantInstr(constant->value()); | 78 return new ConstantInstr(constant->value()); |
| 131 } else { | 79 } else { |
| 132 return new ParameterInstr(i, graph->graph_entry()); | 80 return new ParameterInstr(i, graph->graph_entry()); |
| 133 } | 81 } |
| (...skipping 646 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 780 return count; | 728 return count; |
| 781 } | 729 } |
| 782 | 730 |
| 783 // Parse a function reusing the cache if possible. | 731 // Parse a function reusing the cache if possible. |
| 784 ParsedFunction* GetParsedFunction(const Function& function, bool* in_cache) { | 732 ParsedFunction* GetParsedFunction(const Function& function, bool* in_cache) { |
| 785 // TODO(zerny): Use a hash map for the cache. | 733 // TODO(zerny): Use a hash map for the cache. |
| 786 for (intptr_t i = 0; i < function_cache_.length(); ++i) { | 734 for (intptr_t i = 0; i < function_cache_.length(); ++i) { |
| 787 ParsedFunction* parsed_function = function_cache_[i]; | 735 ParsedFunction* parsed_function = function_cache_[i]; |
| 788 if (parsed_function->function().raw() == function.raw()) { | 736 if (parsed_function->function().raw() == function.raw()) { |
| 789 *in_cache = true; | 737 *in_cache = true; |
| 790 SourceLabelResetter reset; | |
| 791 parsed_function->node_sequence()->Visit(&reset); | |
| 792 return parsed_function; | 738 return parsed_function; |
| 793 } | 739 } |
| 794 } | 740 } |
| 795 *in_cache = false; | 741 *in_cache = false; |
| 796 ParsedFunction* parsed_function = new ParsedFunction(function); | 742 ParsedFunction* parsed_function = new ParsedFunction(function); |
| 797 Parser::ParseFunction(parsed_function); | 743 Parser::ParseFunction(parsed_function); |
| 798 parsed_function->AllocateVariables(); | 744 parsed_function->AllocateVariables(); |
| 799 return parsed_function; | 745 return parsed_function; |
| 800 } | 746 } |
| 801 | 747 |
| (...skipping 720 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1522 OS::Print("After Inlining of %s\n", flow_graph_-> | 1468 OS::Print("After Inlining of %s\n", flow_graph_-> |
| 1523 parsed_function().function().ToFullyQualifiedCString()); | 1469 parsed_function().function().ToFullyQualifiedCString()); |
| 1524 FlowGraphPrinter printer(*flow_graph_); | 1470 FlowGraphPrinter printer(*flow_graph_); |
| 1525 printer.PrintBlocks(); | 1471 printer.PrintBlocks(); |
| 1526 } | 1472 } |
| 1527 } | 1473 } |
| 1528 } | 1474 } |
| 1529 } | 1475 } |
| 1530 | 1476 |
| 1531 } // namespace dart | 1477 } // namespace dart |
| OLD | NEW |