| OLD | NEW |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef V8_COMPILER_CODE_GENERATOR_H_ | 5 #ifndef V8_COMPILER_CODE_GENERATOR_H_ |
| 6 #define V8_COMPILER_CODE_GENERATOR_H_ | 6 #define V8_COMPILER_CODE_GENERATOR_H_ |
| 7 | 7 |
| 8 #include "src/compiler/gap-resolver.h" | 8 #include "src/compiler/gap-resolver.h" |
| 9 #include "src/compiler/instruction.h" | 9 #include "src/compiler/instruction.h" |
| 10 #include "src/compiler/unwinding-info-writer.h" | 10 #include "src/compiler/unwinding-info-writer.h" |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 | 41 |
| 42 private: | 42 private: |
| 43 Instruction* instr_; | 43 Instruction* instr_; |
| 44 size_t pos_; | 44 size_t pos_; |
| 45 }; | 45 }; |
| 46 | 46 |
| 47 | 47 |
| 48 // Generates native code for a sequence of instructions. | 48 // Generates native code for a sequence of instructions. |
| 49 class CodeGenerator final : public GapResolver::Assembler { | 49 class CodeGenerator final : public GapResolver::Assembler { |
| 50 public: | 50 public: |
| 51 CodeGenerator(Zone* zone, CompilationInfo* info); | 51 explicit CodeGenerator(Frame* frame, Linkage* linkage, |
| 52 InstructionSequence* code, CompilationInfo* info); |
| 52 | 53 |
| 53 // Initialize before calling AssembleCode or FinishCodeObject. | 54 // Generate native code. |
| 54 void Initialize(Frame* frame, Linkage* linkage, InstructionSequence* code); | 55 Handle<Code> GenerateCode(); |
| 55 | |
| 56 // Generate native code. This function can be run off the main thread. | |
| 57 bool AssembleCode(); | |
| 58 | |
| 59 // Finishes the code object generated in AssembleCode. This function returns | |
| 60 // an empty handle if AssembleCode() fails or has not been called. | |
| 61 Handle<Code> FinishCodeObject(); | |
| 62 | 56 |
| 63 InstructionSequence* code() const { return code_; } | 57 InstructionSequence* code() const { return code_; } |
| 64 FrameAccessState* frame_access_state() const { return frame_access_state_; } | 58 FrameAccessState* frame_access_state() const { return frame_access_state_; } |
| 65 const Frame* frame() const { return frame_access_state_->frame(); } | 59 const Frame* frame() const { return frame_access_state_->frame(); } |
| 66 Isolate* isolate() const { return info_->isolate(); } | 60 Isolate* isolate() const { return info_->isolate(); } |
| 67 Linkage* linkage() const { return linkage_; } | 61 Linkage* linkage() const { return linkage_; } |
| 68 bool assemble_code_successful() { return assemble_code_successful_; } | |
| 69 | 62 |
| 70 Label* GetLabel(RpoNumber rpo) { return &labels_[rpo.ToSize()]; } | 63 Label* GetLabel(RpoNumber rpo) { return &labels_[rpo.ToSize()]; } |
| 71 | 64 |
| 72 private: | 65 private: |
| 73 MacroAssembler* masm() { return &masm_; } | 66 MacroAssembler* masm() { return &masm_; } |
| 74 GapResolver* resolver() { return &resolver_; } | 67 GapResolver* resolver() { return &resolver_; } |
| 75 SafepointTableBuilder* safepoints() { return &safepoints_; } | 68 SafepointTableBuilder* safepoints() { return &safepoints_; } |
| 76 Zone* zone() const { return code()->zone(); } | 69 Zone* zone() const { return code()->zone(); } |
| 77 CompilationInfo* info() const { return info_; } | 70 CompilationInfo* info() const { return info_; } |
| 78 | 71 |
| 72 // Create the FrameAccessState object. The Frame is immutable from here on. |
| 73 void CreateFrameAccessState(Frame* frame); |
| 74 |
| 79 // Architecture - specific frame finalization. | 75 // Architecture - specific frame finalization. |
| 80 void FinishFrame(Frame* frame); | 76 void FinishFrame(Frame* frame); |
| 81 | 77 |
| 82 // Checks if {block} will appear directly after {current_block_} when | 78 // Checks if {block} will appear directly after {current_block_} when |
| 83 // assembling code, in which case, a fall-through can be used. | 79 // assembling code, in which case, a fall-through can be used. |
| 84 bool IsNextInAssemblyOrder(RpoNumber block) const; | 80 bool IsNextInAssemblyOrder(RpoNumber block) const; |
| 85 | 81 |
| 86 // Record a safepoint with the given pointer map. | 82 // Record a safepoint with the given pointer map. |
| 87 void RecordSafepoint(ReferenceMap* references, Safepoint::Kind kind, | 83 void RecordSafepoint(ReferenceMap* references, Safepoint::Kind kind, |
| 88 int arguments, Safepoint::DeoptMode deopt_mode); | 84 int arguments, Safepoint::DeoptMode deopt_mode); |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 }; | 250 }; |
| 255 | 251 |
| 256 struct HandlerInfo { | 252 struct HandlerInfo { |
| 257 Label* handler; | 253 Label* handler; |
| 258 int pc_offset; | 254 int pc_offset; |
| 259 }; | 255 }; |
| 260 | 256 |
| 261 friend class OutOfLineCode; | 257 friend class OutOfLineCode; |
| 262 | 258 |
| 263 FrameAccessState* frame_access_state_; | 259 FrameAccessState* frame_access_state_; |
| 264 Linkage* linkage_; | 260 Linkage* const linkage_; |
| 265 InstructionSequence* code_; | 261 InstructionSequence* const code_; |
| 266 UnwindingInfoWriter unwinding_info_writer_; | 262 UnwindingInfoWriter unwinding_info_writer_; |
| 267 CompilationInfo* const info_; | 263 CompilationInfo* const info_; |
| 268 Label* labels_; | 264 Label* const labels_; |
| 269 Label return_label_; | 265 Label return_label_; |
| 270 RpoNumber current_block_; | 266 RpoNumber current_block_; |
| 271 SourcePosition current_source_position_; | 267 SourcePosition current_source_position_; |
| 272 MacroAssembler masm_; | 268 MacroAssembler masm_; |
| 273 GapResolver resolver_; | 269 GapResolver resolver_; |
| 274 SafepointTableBuilder safepoints_; | 270 SafepointTableBuilder safepoints_; |
| 275 ZoneVector<HandlerInfo> handlers_; | 271 ZoneVector<HandlerInfo> handlers_; |
| 276 ZoneDeque<DeoptimizationExit*> deoptimization_exits_; | 272 ZoneDeque<DeoptimizationExit*> deoptimization_exits_; |
| 277 ZoneDeque<DeoptimizationState*> deoptimization_states_; | 273 ZoneDeque<DeoptimizationState*> deoptimization_states_; |
| 278 ZoneDeque<Handle<Object>> deoptimization_literals_; | 274 ZoneDeque<Handle<Object>> deoptimization_literals_; |
| 279 size_t inlined_function_count_; | 275 size_t inlined_function_count_; |
| 280 TranslationBuffer translations_; | 276 TranslationBuffer translations_; |
| 281 int last_lazy_deopt_pc_; | 277 int last_lazy_deopt_pc_; |
| 282 JumpTable* jump_tables_; | 278 JumpTable* jump_tables_; |
| 283 OutOfLineCode* ools_; | 279 OutOfLineCode* ools_; |
| 284 int osr_pc_offset_; | 280 int osr_pc_offset_; |
| 285 SourcePositionTableBuilder source_position_table_builder_; | 281 SourcePositionTableBuilder source_position_table_builder_; |
| 286 bool assemble_code_successful_; | |
| 287 }; | 282 }; |
| 288 | 283 |
| 289 } // namespace compiler | 284 } // namespace compiler |
| 290 } // namespace internal | 285 } // namespace internal |
| 291 } // namespace v8 | 286 } // namespace v8 |
| 292 | 287 |
| 293 #endif // V8_COMPILER_CODE_GENERATOR_H | 288 #endif // V8_COMPILER_CODE_GENERATOR_H |
| OLD | NEW |