| OLD | NEW |
| 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_; } | |
| 45 | |
| 46 Label* AddDeoptStub(intptr_t deopt_id, | |
| 47 intptr_t deopt_token_index, | |
| 48 intptr_t try_index_, | |
| 49 DeoptReasonId reason, | |
| 50 Register reg1, | |
| 51 Register reg2); | |
| 52 | |
| 53 bool is_optimizing() const { return is_optimizing_; } | |
| 54 const ParsedFunction& parsed_function() const { return parsed_function_; } | |
| 55 | |
| 56 void GenerateCallRuntime(intptr_t cid, | 38 void GenerateCallRuntime(intptr_t cid, |
| 57 intptr_t token_index, | 39 intptr_t token_index, |
| 58 intptr_t try_index, | 40 intptr_t try_index, |
| 59 const RuntimeEntry& entry); | 41 const RuntimeEntry& entry); |
| 60 void AddCurrentDescriptor(PcDescriptors::Kind kind, | |
| 61 intptr_t cid, | |
| 62 intptr_t token_index, | |
| 63 intptr_t try_index); | |
| 64 | |
| 65 // Returns true if the next block after current in the current block order | |
| 66 // is the given block. | |
| 67 bool IsNextBlock(TargetEntryInstr* block_entry) const { | |
| 68 intptr_t current_index = reverse_index(current_block()->postorder_number()); | |
| 69 return block_order_[current_index + 1] == block_entry; | |
| 70 } | |
| 71 | |
| 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 | 42 |
| 78 private: | 43 private: |
| 79 friend class DeoptimizationStub; | 44 friend class DeoptimizationStub; |
| 80 | 45 |
| 81 // TODO(fschneider): Clean up friend-class declarations once all code | 46 // TODO(fschneider): Clean up friend-class declarations once all code |
| 82 // generator templates have been moved to intermediate_language_x64.cc. | 47 // generator templates have been moved to intermediate_language_x64.cc. |
| 83 #define DECLARE_FRIEND(ShortName, ClassName) friend class ClassName; | 48 #define DECLARE_FRIEND(ShortName, ClassName) friend class ClassName; |
| 84 FOR_EACH_COMPUTATION(DECLARE_FRIEND) | 49 FOR_EACH_COMPUTATION(DECLARE_FRIEND) |
| 85 #undef DECLARE_FRIEND | 50 #undef DECLARE_FRIEND |
| 86 | 51 |
| 87 static const int kLocalsOffsetFromFP = (-1 * kWordSize); | 52 static const int kLocalsOffsetFromFP = (-1 * kWordSize); |
| 88 | 53 |
| 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_; } | |
| 101 | |
| 102 // Bail out of the flow graph compiler. Does not return to the caller. | 54 // Bail out of the flow graph compiler. Does not return to the caller. |
| 103 void Bailout(const char* reason); | 55 void Bailout(const char* reason); |
| 104 | 56 |
| 105 virtual void VisitBlocks(); | 57 virtual void VisitBlocks(); |
| 106 | 58 |
| 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); | 59 void EmitInstructionPrologue(Instruction* instr); |
| 122 | 60 |
| 123 // Emit code to load a Value into register 'dst'. | 61 // Emit code to load a Value into register 'dst'. |
| 124 void LoadValue(Register dst, Value* value); | 62 void LoadValue(Register dst, Value* value); |
| 125 | 63 |
| 126 void EmitComment(Instruction* instr); | 64 void EmitComment(Instruction* instr); |
| 127 | 65 |
| 128 // Emit an instance call. | 66 // Emit an instance call. |
| 129 void EmitInstanceCall(intptr_t cid, | 67 void EmitInstanceCall(intptr_t cid, |
| 130 intptr_t token_index, | 68 intptr_t token_index, |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 const String& dst_name); | 129 const String& dst_name); |
| 192 | 130 |
| 193 void GenerateInstanceOf(intptr_t cid, | 131 void GenerateInstanceOf(intptr_t cid, |
| 194 intptr_t token_index, | 132 intptr_t token_index, |
| 195 intptr_t try_index, | 133 intptr_t try_index, |
| 196 const AbstractType& type, | 134 const AbstractType& type, |
| 197 bool negate_result); | 135 bool negate_result); |
| 198 | 136 |
| 199 void CopyParameters(); | 137 void CopyParameters(); |
| 200 | 138 |
| 201 intptr_t StackSize() const; | |
| 202 | |
| 203 bool TryIntrinsify(); | 139 bool TryIntrinsify(); |
| 204 void IntrinsifyGetter(); | 140 void IntrinsifyGetter(); |
| 205 void IntrinsifySetter(); | 141 void IntrinsifySetter(); |
| 206 static bool CanOptimize(); | 142 static bool CanOptimize(); |
| 207 | 143 |
| 208 void GenerateDeferredCode(); | |
| 209 | |
| 210 Assembler* assembler_; | |
| 211 const ParsedFunction& parsed_function_; | |
| 212 | |
| 213 // Compiler specific per-block state. Indexed by postorder block number | |
| 214 // for convenience. This is not the block's index in the block order, | |
| 215 // which is reverse postorder. | |
| 216 GrowableArray<BlockInfo*> block_info_; | |
| 217 BlockEntryInstr* current_block_; | |
| 218 DescriptorList* pc_descriptors_list_; | |
| 219 StackmapBuilder* stackmap_builder_; | |
| 220 ExceptionHandlerList* exception_handlers_list_; | |
| 221 GrowableArray<DeoptimizationStub*> deopt_stubs_; | |
| 222 const bool is_optimizing_; | |
| 223 | |
| 224 DISALLOW_COPY_AND_ASSIGN(FlowGraphCompiler); | 144 DISALLOW_COPY_AND_ASSIGN(FlowGraphCompiler); |
| 225 }; | 145 }; |
| 226 | 146 |
| 227 } // namespace dart | 147 } // namespace dart |
| 228 | 148 |
| 229 #endif // VM_FLOW_GRAPH_COMPILER_X64_H_ | 149 #endif // VM_FLOW_GRAPH_COMPILER_X64_H_ |
| OLD | NEW |