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

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

Issue 11953076: Move code around in preparation for better inlining. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 11 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 // An abstraction of the graph context in which an inlined call occurs. 19 // An abstraction of the graph context in which an inlined call occurs.
20 class InliningContext: public ZoneAllocated { 20 class InliningContext: public ZoneAllocated {
21 public: 21 public:
22 // Create the appropriate inlining context for the flow graph context of a
23 // call.
24 static InliningContext* Create(Definition* call);
25
22 virtual void AddExit(ReturnInstr* exit) = 0; 26 virtual void AddExit(ReturnInstr* exit) = 0;
27
28 // Inline a flow graph at a call site.
29 //
30 // Assumes the callee graph was computed by BuildGraph with an inlining
31 // context and transformed to SSA with ComputeSSA with a correct virtual
32 // register number, and that the use lists have been correctly computed.
33 //
34 // After inlining the caller graph will correctly have adjusted the
35 // pre/post orders, the dominator tree and the use lists.
36 virtual void ReplaceCall(FlowGraph* caller_graph,
37 Definition* call,
38 FlowGraph* callee_graph) = 0;
39
40 protected:
41 static void PrepareGraphs(FlowGraph* caller_graph,
42 Definition* call,
43 FlowGraph* callee_graph);
23 }; 44 };
24 45
25 46
26 // The context of a call inlined for its value (including calls inlined for 47 // The context of a call inlined for its value (including calls inlined for
27 // their effects, i.e., when the value is ignored). Collects normal exit 48 // their effects, i.e., when the value is ignored). Collects normal exit
28 // blocks and return values. 49 // blocks and return values.
29 class ValueInliningContext: public InliningContext { 50 class ValueInliningContext: public InliningContext {
30 public: 51 public:
31 ValueInliningContext() : exits_(4) { } 52 ValueInliningContext() : exits_(4) { }
32 53
54 virtual void AddExit(ReturnInstr* exit);
55
56 virtual void ReplaceCall(FlowGraph* caller_graph,
57 Definition* call,
58 FlowGraph* callee_graph);
59
60 private:
61 struct Data {
62 BlockEntryInstr* exit_block;
63 ReturnInstr* exit_return;
64 };
65
33 BlockEntryInstr* ExitBlockAt(intptr_t i) const { 66 BlockEntryInstr* ExitBlockAt(intptr_t i) const {
34 ASSERT(exits_[i].exit_block != NULL); 67 ASSERT(exits_[i].exit_block != NULL);
35 return exits_[i].exit_block; 68 return exits_[i].exit_block;
36 } 69 }
37 Instruction* LastInstructionAt(intptr_t i) const { 70 Instruction* LastInstructionAt(intptr_t i) const {
38 return exits_[i].exit_return->previous(); 71 return exits_[i].exit_return->previous();
39 } 72 }
40 Value* ValueAt(intptr_t i) const { 73 Value* ValueAt(intptr_t i) const {
41 return exits_[i].exit_return->value(); 74 return exits_[i].exit_return->value();
42 } 75 }
43 76
44 intptr_t NumExits() { return exits_.length(); } 77 static int LowestBlockIdFirst(const Data* a, const Data* b);
45 virtual void AddExit(ReturnInstr* exit);
46 void SortExits(); 78 void SortExits();
47 79
48 private:
49 struct Data {
50 BlockEntryInstr* exit_block;
51 ReturnInstr* exit_return;
52 };
53
54 static int LowestBlockIdFirst(const Data* a, const Data* b);
55
56 GrowableArray<Data> exits_; 80 GrowableArray<Data> exits_;
57 }; 81 };
58 82
59 83
60 // Build a flow graph from a parsed function's AST. 84 // Build a flow graph from a parsed function's AST.
61 class FlowGraphBuilder: public ValueObject { 85 class FlowGraphBuilder: public ValueObject {
62 public: 86 public:
63 // The inlining context is NULL if not inlining. 87 // The inlining context is NULL if not inlining.
64 FlowGraphBuilder(const ParsedFunction& parsed_function, 88 FlowGraphBuilder(const ParsedFunction& parsed_function,
65 InliningContext* inlining_context); 89 InliningContext* inlining_context);
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after
437 // Output parameters. 461 // Output parameters.
438 GrowableArray<TargetEntryInstr**> true_successor_addresses_; 462 GrowableArray<TargetEntryInstr**> true_successor_addresses_;
439 GrowableArray<TargetEntryInstr**> false_successor_addresses_; 463 GrowableArray<TargetEntryInstr**> false_successor_addresses_;
440 464
441 intptr_t condition_token_pos_; 465 intptr_t condition_token_pos_;
442 }; 466 };
443 467
444 } // namespace dart 468 } // namespace dart
445 469
446 #endif // VM_FLOW_GRAPH_BUILDER_H_ 470 #endif // VM_FLOW_GRAPH_BUILDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698