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

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

Issue 10893027: Inlining of static calls with trivial function bodies. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 3 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 #ifndef VM_FLOW_GRAPH_BUILDER_H_ 5 #ifndef VM_FLOW_GRAPH_BUILDER_H_
6 #define VM_FLOW_GRAPH_BUILDER_H_ 6 #define VM_FLOW_GRAPH_BUILDER_H_
7 7
8 #include "vm/allocation.h" 8 #include "vm/allocation.h"
9 #include "vm/ast.h" 9 #include "vm/ast.h"
10 #include "vm/growable_array.h" 10 #include "vm/growable_array.h"
11 #include "vm/intermediate_language.h" 11 #include "vm/intermediate_language.h"
12 12
13 namespace dart { 13 namespace dart {
14 14
15 class FlowGraph; 15 class FlowGraph;
16 class Instruction; 16 class Instruction;
17 class ParsedFunction; 17 class ParsedFunction;
18 18
19 // Build a flow graph from a parsed function's AST. 19 // Build a flow graph from a parsed function's AST.
20 class FlowGraphBuilder: public ValueObject { 20 class FlowGraphBuilder: public ValueObject {
21 public: 21 public:
22 explicit FlowGraphBuilder(const ParsedFunction& parsed_function); 22 explicit FlowGraphBuilder(const ParsedFunction& parsed_function);
23 23
24 enum InliningContext {
25 kNotInlining,
26 kValueContext,
27 kEffectContext,
28 kTestContext
29 };
30
24 FlowGraph* BuildGraph(); 31 FlowGraph* BuildGraph();
32 FlowGraph* BuildGraphForInlining(InliningContext context);
25 33
26 const ParsedFunction& parsed_function() const { return parsed_function_; } 34 const ParsedFunction& parsed_function() const { return parsed_function_; }
27 35
28 void Bailout(const char* reason); 36 void Bailout(const char* reason);
29 37
30 void set_context_level(intptr_t value) { context_level_ = value; } 38 void set_context_level(intptr_t value) { context_level_ = value; }
31 intptr_t context_level() const { return context_level_; } 39 intptr_t context_level() const { return context_level_; }
32 40
33 // Each try in this function gets its own try index. 41 // Each try in this function gets its own try index.
34 intptr_t AllocateTryIndex() { return ++last_used_try_index_; } 42 intptr_t AllocateTryIndex() { return ++last_used_try_index_; }
35 43
36 // Manage the currently active try index. 44 // Manage the currently active try index.
37 void set_try_index(intptr_t value) { try_index_ = value; } 45 void set_try_index(intptr_t value) { try_index_ = value; }
38 intptr_t try_index() const { return try_index_; } 46 intptr_t try_index() const { return try_index_; }
39 47
40 void AddCatchEntry(TargetEntryInstr* entry); 48 void AddCatchEntry(TargetEntryInstr* entry);
41 49
42 intptr_t copied_parameter_count() const { 50 intptr_t copied_parameter_count() const {
43 return copied_parameter_count_; 51 return copied_parameter_count_;
44 } 52 }
45 intptr_t non_copied_parameter_count() const { 53 intptr_t non_copied_parameter_count() const {
46 return non_copied_parameter_count_; 54 return non_copied_parameter_count_;
47 } 55 }
48 intptr_t stack_local_count() const { 56 intptr_t stack_local_count() const {
49 return stack_local_count_; 57 return stack_local_count_;
50 } 58 }
51 59
60 bool inlining() const { return inlining_context_ != kNotInlining; }
srdjan 2012/08/29 21:31:33 Does this means: can_be_inlined or does it mean th
zerny-google 2012/08/30 07:31:40 It signals that the builder is building a graph to
61 void AddReturnExit(ReturnInstr* return_instr) {
62 if (inlining()) {
63 ASSERT(exits_ != NULL);
64 exits_->Add(return_instr);
65 }
66 }
67
52 private: 68 private:
53 intptr_t parameter_count() const { 69 intptr_t parameter_count() const {
54 return copied_parameter_count_ + non_copied_parameter_count_; 70 return copied_parameter_count_ + non_copied_parameter_count_;
55 } 71 }
56 intptr_t variable_count() const { 72 intptr_t variable_count() const {
57 return parameter_count() + stack_local_count_; 73 return parameter_count() + stack_local_count_;
58 } 74 }
59 75
60 const ParsedFunction& parsed_function_; 76 const ParsedFunction& parsed_function_;
61 77
62 const intptr_t copied_parameter_count_; 78 const intptr_t copied_parameter_count_;
63 const intptr_t non_copied_parameter_count_; 79 const intptr_t non_copied_parameter_count_;
64 const intptr_t stack_local_count_; // Does not include any parameters. 80 const intptr_t stack_local_count_; // Does not include any parameters.
65 81
66 intptr_t context_level_; 82 intptr_t context_level_;
67 intptr_t last_used_try_index_; 83 intptr_t last_used_try_index_;
68 intptr_t try_index_; 84 intptr_t try_index_;
69 GraphEntryInstr* graph_entry_; 85 GraphEntryInstr* graph_entry_;
86 InliningContext inlining_context_;
87 ZoneGrowableArray<ReturnInstr*>* exits_;
70 88
71 DISALLOW_IMPLICIT_CONSTRUCTORS(FlowGraphBuilder); 89 DISALLOW_IMPLICIT_CONSTRUCTORS(FlowGraphBuilder);
72 }; 90 };
73 91
74 92
75 class TestGraphVisitor; 93 class TestGraphVisitor;
76 94
77 // Translate an AstNode to a control-flow graph fragment for its effects 95 // Translate an AstNode to a control-flow graph fragment for its effects
78 // (e.g., a statement or an expression in an effect context). Implements a 96 // (e.g., a statement or an expression in an effect context). Implements a
79 // function from an AstNode and next temporary index to a graph fragment 97 // function from an AstNode and next temporary index to a graph fragment
(...skipping 17 matching lines...) Expand all
97 115
98 FlowGraphBuilder* owner() const { return owner_; } 116 FlowGraphBuilder* owner() const { return owner_; }
99 intptr_t temp_index() const { return temp_index_; } 117 intptr_t temp_index() const { return temp_index_; }
100 Instruction* entry() const { return entry_; } 118 Instruction* entry() const { return entry_; }
101 Instruction* exit() const { return exit_; } 119 Instruction* exit() const { return exit_; }
102 120
103 bool is_empty() const { return entry_ == NULL; } 121 bool is_empty() const { return entry_ == NULL; }
104 bool is_open() const { return is_empty() || exit_ != NULL; } 122 bool is_open() const { return is_empty() || exit_ != NULL; }
105 123
106 void Bailout(const char* reason); 124 void Bailout(const char* reason);
125 void InlineBailout(const char* reason);
107 126
108 // Append a graph fragment to this graph. Assumes this graph is open. 127 // Append a graph fragment to this graph. Assumes this graph is open.
109 void Append(const EffectGraphVisitor& other_fragment); 128 void Append(const EffectGraphVisitor& other_fragment);
110 // Append a computation with one use. Assumes this graph is open. 129 // Append a computation with one use. Assumes this graph is open.
111 UseVal* Bind(Computation* computation); 130 UseVal* Bind(Computation* computation);
112 // Append a computation with no uses. Assumes this graph is open. 131 // Append a computation with no uses. Assumes this graph is open.
113 void Do(Computation* computation); 132 void Do(Computation* computation);
114 // Append a single (non-Definition, non-Entry) instruction. Assumes this 133 // Append a single (non-Definition, non-Entry) instruction. Assumes this
115 // graph is open. 134 // graph is open.
116 void AddInstruction(Instruction* instruction); 135 void AddInstruction(Instruction* instruction);
(...skipping 12 matching lines...) Expand all
129 // Append a 'while loop' test and back edge to this graph, depending on 148 // Append a 'while loop' test and back edge to this graph, depending on
130 // which parts are reachable. Afterward, the graph exit is the false 149 // which parts are reachable. Afterward, the graph exit is the false
131 // successor of the loop condition. 150 // successor of the loop condition.
132 void TieLoop(const TestGraphVisitor& test_fragment, 151 void TieLoop(const TestGraphVisitor& test_fragment,
133 const EffectGraphVisitor& body_fragment); 152 const EffectGraphVisitor& body_fragment);
134 153
135 // Wraps a value in a push-argument instruction and adds the result to the 154 // Wraps a value in a push-argument instruction and adds the result to the
136 // graph. 155 // graph.
137 PushArgumentInstr* PushArgument(Value* value); 156 PushArgumentInstr* PushArgument(Value* value);
138 157
158 // TODO(zerny): This is assuming we actually use all visitors.
Kevin Millikin (Google) 2012/08/29 14:01:04 Not really a TODO, just an assumption.
zerny-google 2012/08/30 07:31:40 Done.
159 void AddReturnExit(ReturnInstr* return_instr) {
160 owner()->AddReturnExit(return_instr);
161 }
162
139 protected: 163 protected:
140 Computation* BuildStoreLocal(const LocalVariable& local, Value* value); 164 Computation* BuildStoreLocal(const LocalVariable& local, Value* value);
141 Computation* BuildLoadLocal(const LocalVariable& local); 165 Computation* BuildLoadLocal(const LocalVariable& local);
142 166
143 // Helpers for translating parts of the AST. 167 // Helpers for translating parts of the AST.
144 void TranslateArgumentList(const ArgumentListNode& node, 168 void TranslateArgumentList(const ArgumentListNode& node,
145 ZoneGrowableArray<Value*>* values); 169 ZoneGrowableArray<Value*>* values);
146 void BuildPushArguments(const ArgumentListNode& node, 170 void BuildPushArguments(const ArgumentListNode& node,
147 ZoneGrowableArray<PushArgumentInstr*>* values); 171 ZoneGrowableArray<PushArgumentInstr*>* values);
148 172
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 // Output parameters. 376 // Output parameters.
353 TargetEntryInstr** true_successor_address_; 377 TargetEntryInstr** true_successor_address_;
354 TargetEntryInstr** false_successor_address_; 378 TargetEntryInstr** false_successor_address_;
355 379
356 intptr_t condition_token_pos_; 380 intptr_t condition_token_pos_;
357 }; 381 };
358 382
359 } // namespace dart 383 } // namespace dart
360 384
361 #endif // VM_FLOW_GRAPH_BUILDER_H_ 385 #endif // VM_FLOW_GRAPH_BUILDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698