OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef V8_COMPILER_CODE_GENERATOR_H_ |
| 6 #define V8_COMPILER_CODE_GENERATOR_H_ |
| 7 |
| 8 #include <deque> |
| 9 |
| 10 #include "src/compiler/gap-resolver.h" |
| 11 #include "src/compiler/instruction.h" |
| 12 #include "src/deoptimizer.h" |
| 13 #include "src/macro-assembler.h" |
| 14 #include "src/safepoint-table.h" |
| 15 |
| 16 namespace v8 { |
| 17 namespace internal { |
| 18 namespace compiler { |
| 19 |
| 20 // Generates native code for a sequence of instructions. |
| 21 class CodeGenerator V8_FINAL : public GapResolver::Assembler { |
| 22 public: |
| 23 explicit CodeGenerator(InstructionSequence* code); |
| 24 |
| 25 // Generate native code. |
| 26 Handle<Code> GenerateCode(); |
| 27 |
| 28 InstructionSequence* code() const { return code_; } |
| 29 Frame* frame() const { return code()->frame(); } |
| 30 Graph* graph() const { return code()->graph(); } |
| 31 Isolate* isolate() const { return zone()->isolate(); } |
| 32 Linkage* linkage() const { return code()->linkage(); } |
| 33 Schedule* schedule() const { return code()->schedule(); } |
| 34 |
| 35 private: |
| 36 MacroAssembler* masm() { return &masm_; } |
| 37 GapResolver* resolver() { return &resolver_; } |
| 38 SafepointTableBuilder* safepoints() { return &safepoints_; } |
| 39 Zone* zone() const { return code()->zone(); } |
| 40 |
| 41 // Checks if {block} will appear directly after {current_block_} when |
| 42 // assembling code, in which case, a fall-through can be used. |
| 43 bool IsNextInAssemblyOrder(const BasicBlock* block) const { |
| 44 return block->rpo_number_ == (current_block_->rpo_number_ + 1) && |
| 45 block->deferred_ == current_block_->deferred_; |
| 46 } |
| 47 |
| 48 // Record a safepoint with the given pointer map. |
| 49 void RecordSafepoint(PointerMap* pointers, Safepoint::Kind kind, |
| 50 int arguments, Safepoint::DeoptMode deopt_mode); |
| 51 |
| 52 // Assemble code for the specified instruction. |
| 53 void AssembleInstruction(Instruction* instr); |
| 54 void AssembleSourcePosition(SourcePositionInstruction* instr); |
| 55 void AssembleGap(GapInstruction* gap); |
| 56 |
| 57 // =========================================================================== |
| 58 // ============= Architecture-specific code generation methods. ============== |
| 59 // =========================================================================== |
| 60 |
| 61 void AssembleArchInstruction(Instruction* instr); |
| 62 void AssembleArchBranch(Instruction* instr, FlagsCondition condition); |
| 63 void AssembleArchBoolean(Instruction* instr, FlagsCondition condition); |
| 64 |
| 65 // Generates an architecture-specific, descriptor-specific prologue |
| 66 // to set up a stack frame. |
| 67 void AssemblePrologue(); |
| 68 // Generates an architecture-specific, descriptor-specific return sequence |
| 69 // to tear down a stack frame. |
| 70 void AssembleReturn(); |
| 71 |
| 72 // =========================================================================== |
| 73 // ============== Architecture-specific gap resolver methods. ================ |
| 74 // =========================================================================== |
| 75 |
| 76 // Interface used by the gap resolver to emit moves and swaps. |
| 77 virtual void AssembleMove(InstructionOperand* source, |
| 78 InstructionOperand* destination) V8_OVERRIDE; |
| 79 virtual void AssembleSwap(InstructionOperand* source, |
| 80 InstructionOperand* destination) V8_OVERRIDE; |
| 81 |
| 82 // =========================================================================== |
| 83 // Deoptimization table construction |
| 84 void RecordLazyDeoptimizationEntry(Instruction* instr); |
| 85 void PopulateDeoptimizationData(Handle<Code> code); |
| 86 int DefineDeoptimizationLiteral(Handle<Object> literal); |
| 87 void BuildTranslation(Instruction* instr, int deoptimization_id); |
| 88 void AddNopForSmiCodeInlining(); |
| 89 #if DEBUG |
| 90 static bool IsNopForSmiCodeInlining(Handle<Code> code, int start_pc, |
| 91 int end_pc); |
| 92 #endif // DEBUG |
| 93 // =========================================================================== |
| 94 |
| 95 class LazyDeoptimizationEntry V8_FINAL { |
| 96 public: |
| 97 LazyDeoptimizationEntry(int position_after_call, Label* continuation, |
| 98 Label* deoptimization) |
| 99 : position_after_call_(position_after_call), |
| 100 continuation_(continuation), |
| 101 deoptimization_(deoptimization) {} |
| 102 |
| 103 int position_after_call() const { return position_after_call_; } |
| 104 Label* continuation() const { return continuation_; } |
| 105 Label* deoptimization() const { return deoptimization_; } |
| 106 |
| 107 private: |
| 108 int position_after_call_; |
| 109 Label* continuation_; |
| 110 Label* deoptimization_; |
| 111 }; |
| 112 |
| 113 struct DeoptimizationState : ZoneObject { |
| 114 int translation_id_; |
| 115 |
| 116 explicit DeoptimizationState(int translation_id) |
| 117 : translation_id_(translation_id) {} |
| 118 }; |
| 119 |
| 120 typedef std::deque<LazyDeoptimizationEntry, |
| 121 zone_allocator<LazyDeoptimizationEntry> > |
| 122 LazyDeoptimizationEntries; |
| 123 typedef std::deque<DeoptimizationState*, |
| 124 zone_allocator<DeoptimizationState*> > |
| 125 DeoptimizationStates; |
| 126 typedef std::deque<Handle<Object>, zone_allocator<Handle<Object> > > Literals; |
| 127 |
| 128 InstructionSequence* code_; |
| 129 BasicBlock* current_block_; |
| 130 SourcePosition current_source_position_; |
| 131 MacroAssembler masm_; |
| 132 GapResolver resolver_; |
| 133 SafepointTableBuilder safepoints_; |
| 134 LazyDeoptimizationEntries lazy_deoptimization_entries_; |
| 135 DeoptimizationStates deoptimization_states_; |
| 136 Literals deoptimization_literals_; |
| 137 TranslationBuffer translations_; |
| 138 }; |
| 139 |
| 140 } // namespace compiler |
| 141 } // namespace internal |
| 142 } // namespace v8 |
| 143 |
| 144 #endif // V8_COMPILER_CODE_GENERATOR_H |
OLD | NEW |