V8 Project
instruction-selector.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_INSTRUCTION_SELECTOR_H_
6 #define V8_COMPILER_INSTRUCTION_SELECTOR_H_
7 
8 #include <deque>
9 
13 #include "src/zone-containers.h"
14 
15 namespace v8 {
16 namespace internal {
17 namespace compiler {
18 
19 // Forward declarations.
20 struct CallBuffer; // TODO(bmeurer): Remove this.
21 class FlagsContinuation;
22 
23 class InstructionSelector FINAL {
24  public:
25  // Forward declarations.
26  class Features;
27 
29  SourcePositionTable* source_positions,
30  Features features = SupportedFeatures());
31 
32  // Visit code for the entire graph with the included schedule.
34 
35  // ===========================================================================
36  // ============= Architecture-independent code emission methods. =============
37  // ===========================================================================
38 
40  size_t temp_count = 0, InstructionOperand* *temps = NULL);
42  InstructionOperand* a, size_t temp_count = 0,
43  InstructionOperand* *temps = NULL);
46  size_t temp_count = 0, InstructionOperand* *temps = NULL);
49  InstructionOperand* c, size_t temp_count = 0,
50  InstructionOperand* *temps = NULL);
54  size_t temp_count = 0, InstructionOperand* *temps = NULL);
55  Instruction* Emit(InstructionCode opcode, size_t output_count,
56  InstructionOperand** outputs, size_t input_count,
57  InstructionOperand** inputs, size_t temp_count = 0,
58  InstructionOperand* *temps = NULL);
60 
61  // ===========================================================================
62  // ============== Architecture-independent CPU feature methods. ==============
63  // ===========================================================================
64 
65  class Features FINAL {
66  public:
67  Features() : bits_(0) {}
68  explicit Features(unsigned bits) : bits_(bits) {}
69  explicit Features(CpuFeature f) : bits_(1u << f) {}
70  Features(CpuFeature f1, CpuFeature f2) : bits_((1u << f1) | (1u << f2)) {}
71 
72  bool Contains(CpuFeature f) const { return (bits_ & (1u << f)); }
73 
74  private:
75  unsigned bits_;
76  };
77 
78  bool IsSupported(CpuFeature feature) const {
79  return features_.Contains(feature);
80  }
81 
82  // Returns the features supported on the target platform.
83  static Features SupportedFeatures() {
84  return Features(CpuFeatures::SupportedFeatures());
85  }
86 
87  // Checks if {node} is currently live.
88  bool IsLive(Node* node) const { return !IsDefined(node) && IsUsed(node); }
89 
90  private:
91  friend class OperandGenerator;
92 
93  // ===========================================================================
94  // ============ Architecture-independent graph covering methods. =============
95  // ===========================================================================
96 
97  // Checks if {block} will appear directly after {current_block_} when
98  // assembling code, in which case, a fall-through can be used.
99  bool IsNextInAssemblyOrder(const BasicBlock* block) const;
100 
101  // Used in pattern matching during code generation.
102  // Check if {node} can be covered while generating code for the current
103  // instruction. A node can be covered if the {user} of the node has the only
104  // edge and the two are in the same basic block.
105  bool CanCover(Node* user, Node* node) const;
106 
107  // Checks if {node} was already defined, and therefore code was already
108  // generated for it.
109  bool IsDefined(Node* node) const;
110 
111  // Inform the instruction selection that {node} was just defined.
112  void MarkAsDefined(Node* node);
113 
114  // Checks if {node} has any uses, and therefore code has to be generated for
115  // it.
116  bool IsUsed(Node* node) const;
117 
118  // Inform the instruction selection that {node} has at least one use and we
119  // will need to generate code for it.
120  void MarkAsUsed(Node* node);
121 
122  // Checks if {node} is marked as double.
123  bool IsDouble(const Node* node) const;
124 
125  // Inform the register allocator of a double result.
126  void MarkAsDouble(Node* node);
127 
128  // Checks if {node} is marked as reference.
129  bool IsReference(const Node* node) const;
130 
131  // Inform the register allocator of a reference result.
132  void MarkAsReference(Node* node);
133 
134  // Inform the register allocation of the representation of the value produced
135  // by {node}.
136  void MarkAsRepresentation(MachineType rep, Node* node);
137 
138  // Initialize the call buffer with the InstructionOperands, nodes, etc,
139  // corresponding
140  // to the inputs and outputs of the call.
141  // {call_code_immediate} to generate immediate operands to calls of code.
142  // {call_address_immediate} to generate immediate operands to address calls.
143  void InitializeCallBuffer(Node* call, CallBuffer* buffer,
144  bool call_code_immediate,
145  bool call_address_immediate);
146 
149  FrameStateDescriptor* descriptor);
150 
151  // ===========================================================================
152  // ============= Architecture-specific graph covering methods. ===============
153  // ===========================================================================
154 
155  // Visit nodes in the given block and generate code.
156  void VisitBlock(BasicBlock* block);
157 
158  // Visit the node for the control flow at the end of the block, generating
159  // code if necessary.
160  void VisitControl(BasicBlock* block);
161 
162  // Visit the node and generate code, if any.
163  void VisitNode(Node* node);
164 
165 #define DECLARE_GENERATOR(x) void Visit##x(Node* node);
167 #undef DECLARE_GENERATOR
168 
169  void VisitInt32AddWithOverflow(Node* node, FlagsContinuation* cont);
170  void VisitInt32SubWithOverflow(Node* node, FlagsContinuation* cont);
171 
172  void VisitWord32Test(Node* node, FlagsContinuation* cont);
173  void VisitWord64Test(Node* node, FlagsContinuation* cont);
174  void VisitWord32Compare(Node* node, FlagsContinuation* cont);
175  void VisitWord64Compare(Node* node, FlagsContinuation* cont);
176  void VisitFloat64Compare(Node* node, FlagsContinuation* cont);
177 
178  void VisitFinish(Node* node);
179  void VisitParameter(Node* node);
180  void VisitPhi(Node* node);
181  void VisitProjection(Node* node);
182  void VisitConstant(Node* node);
183  void VisitCall(Node* call, BasicBlock* continuation,
184  BasicBlock* deoptimization);
185  void VisitGoto(BasicBlock* target);
186  void VisitBranch(Node* input, BasicBlock* tbranch, BasicBlock* fbranch);
187  void VisitReturn(Node* value);
188  void VisitThrow(Node* value);
189  void VisitDeoptimize(Node* deopt);
190 
191  // ===========================================================================
192 
193  Graph* graph() const { return sequence()->graph(); }
194  Linkage* linkage() const { return sequence()->linkage(); }
195  Schedule* schedule() const { return sequence()->schedule(); }
196  InstructionSequence* sequence() const { return sequence_; }
197  Zone* instruction_zone() const { return sequence()->zone(); }
198  Zone* zone() { return &zone_; }
199 
200  // ===========================================================================
201 
204  SourcePositionTable* source_positions_;
205  Features features_;
206  BasicBlock* current_block_;
210 };
211 
212 } // namespace compiler
213 } // namespace internal
214 } // namespace v8
215 
216 #endif // V8_COMPILER_INSTRUCTION_SELECTOR_H_
static unsigned SupportedFeatures()
Definition: assembler.h:179
void MarkAsReference(Node *node)
FrameStateDescriptor * GetFrameStateDescriptor(Node *node)
void VisitControl(BasicBlock *block)
void VisitWord32Test(Node *node, FlagsContinuation *cont)
bool CanCover(Node *user, Node *node) const
void VisitThrow(Node *value)
Instruction * Emit(InstructionCode opcode, InstructionOperand *output, InstructionOperand *a, InstructionOperand *b, InstructionOperand *c, size_t temp_count=0, InstructionOperand **temps=NULL)
Instruction * Emit(InstructionCode opcode, InstructionOperand *output, size_t temp_count=0, InstructionOperand **temps=NULL)
InstructionSelector(InstructionSequence *sequence, SourcePositionTable *source_positions, Features features=SupportedFeatures())
Instruction * Emit(InstructionCode opcode, InstructionOperand *output, InstructionOperand *a, InstructionOperand *b, InstructionOperand *c, InstructionOperand *d, size_t temp_count=0, InstructionOperand **temps=NULL)
bool IsSupported(CpuFeature feature) const
void VisitReturn(Node *value)
void VisitBlock(BasicBlock *block)
InstructionSequence * sequence() const
ZoneDeque< Instruction * > instructions_
void VisitDeoptimize(Node *deopt)
void VisitInt32SubWithOverflow(Node *node, FlagsContinuation *cont)
void MarkAsDefined(Node *node)
void InitializeCallBuffer(Node *call, CallBuffer *buffer, bool call_code_immediate, bool call_address_immediate)
void VisitWord64Test(Node *node, FlagsContinuation *cont)
void VisitConstant(Node *node)
bool IsDefined(Node *node) const
bool IsNextInAssemblyOrder(const BasicBlock *block) const
bool IsDouble(const Node *node) const
bool IsUsed(Node *node) const
void VisitGoto(BasicBlock *target)
Instruction * Emit(Instruction *instr)
void VisitWord64Compare(Node *node, FlagsContinuation *cont)
SourcePositionTable * source_positions_
void VisitFinish(Node *node)
void MarkAsRepresentation(MachineType rep, Node *node)
Instruction * Emit(InstructionCode opcode, InstructionOperand *output, InstructionOperand *a, InstructionOperand *b, size_t temp_count=0, InstructionOperand **temps=NULL)
void VisitWord32Compare(Node *node, FlagsContinuation *cont)
void VisitBranch(Node *input, BasicBlock *tbranch, BasicBlock *fbranch)
Instruction * Emit(InstructionCode opcode, size_t output_count, InstructionOperand **outputs, size_t input_count, InstructionOperand **inputs, size_t temp_count=0, InstructionOperand **temps=NULL)
void VisitFloat64Compare(Node *node, FlagsContinuation *cont)
void VisitParameter(Node *node)
bool IsReference(const Node *node) const
void VisitProjection(Node *node)
void VisitInt32AddWithOverflow(Node *node, FlagsContinuation *cont)
Instruction * Emit(InstructionCode opcode, InstructionOperand *output, InstructionOperand *a, size_t temp_count=0, InstructionOperand **temps=NULL)
void AddFrameStateInputs(Node *state, InstructionOperandVector *inputs, FrameStateDescriptor *descriptor)
void MarkAsDouble(Node *node)
void VisitCall(Node *call, BasicBlock *continuation, BasicBlock *deoptimization)
#define FINAL
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes enable context specialization in TurboFan execution budget before interrupt is triggered max percentage of megamorphic generic ICs to allow optimization enable use of SAHF instruction if enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable use of MLS instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long enable alignment of csp to bytes on platforms which prefer the register to always be NULL
#define DECLARE_GENERATOR(x)
const FPURegister f1
const FPURegister f2
Debugger support for the V8 JavaScript engine.
Definition: accessors.cc:20
#define MACHINE_OP_LIST(V)
Definition: opcodes.h:165
Features(CpuFeature f1, CpuFeature f2)