V8 Project
code-generator.h
Go to the documentation of this file.
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 
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 FINAL : public GapResolver::Assembler {
22  public:
24 
25  // Generate native code.
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.
54  void AssembleSourcePosition(SourcePositionInstruction* instr);
56 
57  // ===========================================================================
58  // ============= Architecture-specific code generation methods. ==============
59  // ===========================================================================
60 
64 
65  void AssembleDeoptimizerCall(int deoptimization_id);
66 
67  // Generates an architecture-specific, descriptor-specific prologue
68  // to set up a stack frame.
70  // Generates an architecture-specific, descriptor-specific return sequence
71  // to tear down a stack frame.
73 
74  // ===========================================================================
75  // ============== Architecture-specific gap resolver methods. ================
76  // ===========================================================================
77 
78  // Interface used by the gap resolver to emit moves and swaps.
79  virtual void AssembleMove(InstructionOperand* source,
80  InstructionOperand* destination) OVERRIDE;
81  virtual void AssembleSwap(InstructionOperand* source,
82  InstructionOperand* destination) OVERRIDE;
83 
84  // ===========================================================================
85  // Deoptimization table construction
90  size_t frame_state_offset);
91  int BuildTranslation(Instruction* instr, int pc_offset,
92  size_t frame_state_offset,
93  OutputFrameStateCombine state_combine);
95  FrameStateDescriptor* descriptor, Instruction* instr,
96  Translation* translation, size_t frame_state_offset,
97  OutputFrameStateCombine state_combine);
98  void AddTranslationForOperand(Translation* translation, Instruction* instr,
99  InstructionOperand* op);
103 
104  // ===========================================================================
106  public:
107  BailoutId bailout_id() const { return bailout_id_; }
108  int translation_id() const { return translation_id_; }
109  int pc_offset() const { return pc_offset_; }
110 
111  DeoptimizationState(BailoutId bailout_id, int translation_id, int pc_offset)
112  : bailout_id_(bailout_id),
113  translation_id_(translation_id),
114  pc_offset_(pc_offset) {}
115 
116  private:
120  };
121 
123  BasicBlock* current_block_;
124  SourcePosition current_source_position_;
126  GapResolver resolver_;
127  SafepointTableBuilder safepoints_;
130  TranslationBuffer translations_;
132 };
133 
134 } // namespace compiler
135 } // namespace internal
136 } // namespace v8
137 
138 #endif // V8_COMPILER_CODE_GENERATOR_H
SafepointTableBuilder * safepoints()
void AddTranslationForOperand(Translation *translation, Instruction *instr, InstructionOperand *op)
InstructionSequence * code() const
Schedule * schedule() const
void PopulateDeoptimizationData(Handle< Code > code)
SourcePosition current_source_position_
void AssembleArchBranch(Instruction *instr, FlagsCondition condition)
ZoneDeque< DeoptimizationState * > deoptimization_states_
FrameStateDescriptor * GetFrameStateDescriptor(Instruction *instr, size_t frame_state_offset)
void AssembleArchBoolean(Instruction *instr, FlagsCondition condition)
void AssembleDeoptimizerCall(int deoptimization_id)
void RecordSafepoint(PointerMap *pointers, Safepoint::Kind kind, int arguments, Safepoint::DeoptMode deopt_mode)
void AssembleGap(GapInstruction *gap)
bool IsNextInAssemblyOrder(const BasicBlock *block) const
TranslationBuffer translations_
void AssembleArchInstruction(Instruction *instr)
InstructionSequence * code_
virtual void AssembleMove(InstructionOperand *source, InstructionOperand *destination) OVERRIDE
void AddSafepointAndDeopt(Instruction *instr)
int BuildTranslation(Instruction *instr, int pc_offset, size_t frame_state_offset, OutputFrameStateCombine state_combine)
CodeGenerator(InstructionSequence *code)
virtual void AssembleSwap(InstructionOperand *source, InstructionOperand *destination) OVERRIDE
void AssembleSourcePosition(SourcePositionInstruction *instr)
ZoneDeque< Handle< Object > > deoptimization_literals_
void AssembleInstruction(Instruction *instr)
Handle< Code > GenerateCode()
SafepointTableBuilder safepoints_
int DefineDeoptimizationLiteral(Handle< Object > literal)
void BuildTranslationForFrameStateDescriptor(FrameStateDescriptor *descriptor, Instruction *instr, Translation *translation, size_t frame_state_offset, OutputFrameStateCombine state_combine)
#define OVERRIDE
#define FINAL
Debugger support for the V8 JavaScript engine.
Definition: accessors.cc:20
DeoptimizationState(BailoutId bailout_id, int translation_id, int pc_offset)