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

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

Issue 10447133: FlowGraphCompiler is not a visitor any longer. Start consolidating shared code between the x64 and … (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 6 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_COMPILER_X64_H_ 5 #ifndef VM_FLOW_GRAPH_COMPILER_X64_H_
6 #define VM_FLOW_GRAPH_COMPILER_X64_H_ 6 #define VM_FLOW_GRAPH_COMPILER_X64_H_
7 7
8 #ifndef VM_FLOW_GRAPH_COMPILER_H_ 8 #ifndef VM_FLOW_GRAPH_COMPILER_H_
9 #error Include flow_graph_compiler.h instead of flow_graph_compiler_x64.h. 9 #error Include flow_graph_compiler.h instead of flow_graph_compiler_x64.h.
10 #endif 10 #endif
11 11
12 #include "vm/assembler.h" 12 #include "vm/assembler.h"
13 #include "vm/assembler_macros.h" 13 #include "vm/assembler_macros.h"
14 #include "vm/code_descriptors.h" 14 #include "vm/code_descriptors.h"
15 #include "vm/code_generator.h" 15 #include "vm/code_generator.h"
16 #include "vm/flow_graph_compiler_shared.h"
16 #include "vm/intermediate_language.h" 17 #include "vm/intermediate_language.h"
17 18
18 namespace dart { 19 namespace dart {
19 20
20 class Code; 21 class Code;
21 class DeoptimizationStub; 22 class DeoptimizationStub;
22 class ExceptionHandlerList; 23 class ExceptionHandlerList;
23 template <typename T> class GrowableArray; 24 template <typename T> class GrowableArray;
24 class ParsedFunction; 25 class ParsedFunction;
25 26
26 class FlowGraphCompiler : public FlowGraphVisitor { 27 class FlowGraphCompiler : public FlowGraphCompilerShared {
27 public: 28 public:
28 FlowGraphCompiler(Assembler* assembler, 29 FlowGraphCompiler(Assembler* assembler,
29 const ParsedFunction& parsed_function, 30 const ParsedFunction& parsed_function,
30 const GrowableArray<BlockEntryInstr*>& block_order, 31 const GrowableArray<BlockEntryInstr*>& block_order,
31 bool is_optimizing); 32 bool is_optimizing);
32 33
33 virtual ~FlowGraphCompiler();
34
35 void CompileGraph(); 34 void CompileGraph();
36 35
37 // Infrastructure copied from class CodeGenerator or stubbed out.
38 void FinalizePcDescriptors(const Code& code);
39 void FinalizeStackmaps(const Code& code);
40 void FinalizeVarDescriptors(const Code& code);
41 void FinalizeExceptionHandlers(const Code& code);
42 void FinalizeComments(const Code& code); 36 void FinalizeComments(const Code& code);
43 37
44 Assembler* assembler() const { return assembler_; } 38 Assembler* assembler() const { return assembler_; }
45 39
46 Label* AddDeoptStub(intptr_t deopt_id, 40 Label* AddDeoptStub(intptr_t deopt_id,
47 intptr_t deopt_token_index, 41 intptr_t deopt_token_index,
48 intptr_t try_index_, 42 intptr_t try_index_,
49 DeoptReasonId reason, 43 DeoptReasonId reason,
50 Register reg1, 44 Register reg1,
51 Register reg2); 45 Register reg2);
52 46
53 bool is_optimizing() const { return is_optimizing_; } 47 bool is_optimizing() const { return is_optimizing_; }
54 const ParsedFunction& parsed_function() const { return parsed_function_; }
55 48
56 void GenerateCallRuntime(intptr_t cid, 49 void GenerateCallRuntime(intptr_t cid,
57 intptr_t token_index, 50 intptr_t token_index,
58 intptr_t try_index, 51 intptr_t try_index,
59 const RuntimeEntry& entry); 52 const RuntimeEntry& entry);
60 void AddCurrentDescriptor(PcDescriptors::Kind kind, 53 void AddCurrentDescriptor(PcDescriptors::Kind kind,
61 intptr_t cid, 54 intptr_t cid,
62 intptr_t token_index, 55 intptr_t token_index,
63 intptr_t try_index); 56 intptr_t try_index);
64 57
65 // Returns true if the next block after current in the current block order 58 // Returns true if the next block after current in the current block order
66 // is the given block. 59 // is the given block.
67 bool IsNextBlock(TargetEntryInstr* block_entry) const { 60 bool IsNextBlock(TargetEntryInstr* block_entry) const {
68 intptr_t current_index = reverse_index(current_block()->postorder_number()); 61 intptr_t current_index = reverse_index(current_block()->postorder_number());
69 return block_order_[current_index + 1] == block_entry; 62 return block_order_[current_index + 1] == block_entry;
70 } 63 }
71 64
72 // Returns assembler label associated with the given block entry.
73 Label* GetBlockLabel(TargetEntryInstr* block_entry) const {
74 intptr_t block_index = block_entry->postorder_number();
75 return &block_info_[block_index]->label;
76 }
77
78 private: 65 private:
79 friend class DeoptimizationStub; 66 friend class DeoptimizationStub;
80 67
68 // Map a block number in a forward iteration into the block number in the
69 // corresponding reverse iteration. Used to obtain an index into
70 // block_order for reverse iterations.
71 intptr_t reverse_index(intptr_t index) const {
72 return block_order_.length() - index - 1;
73 }
74
81 // TODO(fschneider): Clean up friend-class declarations once all code 75 // TODO(fschneider): Clean up friend-class declarations once all code
82 // generator templates have been moved to intermediate_language_x64.cc. 76 // generator templates have been moved to intermediate_language_x64.cc.
83 #define DECLARE_FRIEND(ShortName, ClassName) friend class ClassName; 77 #define DECLARE_FRIEND(ShortName, ClassName) friend class ClassName;
84 FOR_EACH_COMPUTATION(DECLARE_FRIEND) 78 FOR_EACH_COMPUTATION(DECLARE_FRIEND)
85 #undef DECLARE_FRIEND 79 #undef DECLARE_FRIEND
86 80
87 static const int kLocalsOffsetFromFP = (-1 * kWordSize); 81 static const int kLocalsOffsetFromFP = (-1 * kWordSize);
88 82
89 // Constructor is lighweight, major initialization work should occur here.
90 // This makes it easier to measure time spent in the compiler.
91 void InitCompiler();
92
93 struct BlockInfo : public ZoneAllocated {
94 public:
95 BlockInfo() : label() { }
96
97 Label label;
98 };
99
100 BlockEntryInstr* current_block() const { return current_block_; } 83 BlockEntryInstr* current_block() const { return current_block_; }
101 84
102 // Bail out of the flow graph compiler. Does not return to the caller. 85 // Bail out of the flow graph compiler. Does not return to the caller.
103 void Bailout(const char* reason); 86 void Bailout(const char* reason);
104 87
105 virtual void VisitBlocks(); 88 virtual void VisitBlocks();
106 89
107 // Emit code to perform a computation, leaving its value in RAX.
108 #define DECLARE_VISIT_COMPUTATION(ShortName, ClassName) \
109 virtual void Visit##ShortName(ClassName* comp);
110
111 // Each visit function compiles a type of instruction.
112 #define DECLARE_VISIT_INSTRUCTION(ShortName) \
113 virtual void Visit##ShortName(ShortName##Instr* instr);
114
115 FOR_EACH_COMPUTATION(DECLARE_VISIT_COMPUTATION)
116 FOR_EACH_INSTRUCTION(DECLARE_VISIT_INSTRUCTION)
117
118 #undef DECLARE_VISIT_COMPUTATION
119 #undef DECLARE_VISIT_INSTRUCTION
120
121 void EmitInstructionPrologue(Instruction* instr); 90 void EmitInstructionPrologue(Instruction* instr);
122 91
123 // Emit code to load a Value into register 'dst'. 92 // Emit code to load a Value into register 'dst'.
124 void LoadValue(Register dst, Value* value); 93 void LoadValue(Register dst, Value* value);
125 94
126 void EmitComment(Instruction* instr); 95 void EmitComment(Instruction* instr);
127 96
128 // Emit an instance call. 97 // Emit an instance call.
129 void EmitInstanceCall(intptr_t cid, 98 void EmitInstanceCall(intptr_t cid,
130 intptr_t token_index, 99 intptr_t token_index,
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 intptr_t StackSize() const; 170 intptr_t StackSize() const;
202 171
203 bool TryIntrinsify(); 172 bool TryIntrinsify();
204 void IntrinsifyGetter(); 173 void IntrinsifyGetter();
205 void IntrinsifySetter(); 174 void IntrinsifySetter();
206 static bool CanOptimize(); 175 static bool CanOptimize();
207 176
208 void GenerateDeferredCode(); 177 void GenerateDeferredCode();
209 178
210 Assembler* assembler_; 179 Assembler* assembler_;
211 const ParsedFunction& parsed_function_; 180 const GrowableArray<BlockEntryInstr*>& block_order_;
212 181
213 // Compiler specific per-block state. Indexed by postorder block number 182 // Compiler specific per-block state. Indexed by postorder block number
214 // for convenience. This is not the block's index in the block order, 183 // for convenience. This is not the block's index in the block order,
215 // which is reverse postorder. 184 // which is reverse postorder.
216 GrowableArray<BlockInfo*> block_info_;
217 BlockEntryInstr* current_block_; 185 BlockEntryInstr* current_block_;
218 DescriptorList* pc_descriptors_list_;
219 StackmapBuilder* stackmap_builder_;
220 ExceptionHandlerList* exception_handlers_list_;
221 GrowableArray<DeoptimizationStub*> deopt_stubs_; 186 GrowableArray<DeoptimizationStub*> deopt_stubs_;
222 const bool is_optimizing_; 187 const bool is_optimizing_;
223 188
224 DISALLOW_COPY_AND_ASSIGN(FlowGraphCompiler); 189 DISALLOW_COPY_AND_ASSIGN(FlowGraphCompiler);
225 }; 190 };
226 191
227 } // namespace dart 192 } // namespace dart
228 193
229 #endif // VM_FLOW_GRAPH_COMPILER_X64_H_ 194 #endif // VM_FLOW_GRAPH_COMPILER_X64_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698