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_INSTRUCTION_SELECTOR_H_ | 5 #ifndef V8_COMPILER_INSTRUCTION_SELECTOR_H_ |
6 #define V8_COMPILER_INSTRUCTION_SELECTOR_H_ | 6 #define V8_COMPILER_INSTRUCTION_SELECTOR_H_ |
7 | 7 |
8 #include <deque> | 8 #include <deque> |
9 | 9 |
10 #include "src/compiler/common-operator.h" | 10 #include "src/compiler/common-operator.h" |
11 #include "src/compiler/instruction.h" | 11 #include "src/compiler/instruction.h" |
12 #include "src/compiler/machine-operator.h" | 12 #include "src/compiler/machine-operator.h" |
13 #include "src/zone-containers.h" | 13 #include "src/zone-containers.h" |
14 | 14 |
15 namespace v8 { | 15 namespace v8 { |
16 namespace internal { | 16 namespace internal { |
17 namespace compiler { | 17 namespace compiler { |
18 | 18 |
19 // Forward declarations. | 19 // Forward declarations. |
20 struct CallBuffer; // TODO(bmeurer): Remove this. | 20 struct CallBuffer; // TODO(bmeurer): Remove this. |
21 class FlagsContinuation; | 21 class FlagsContinuation; |
22 | 22 |
23 class InstructionSelector V8_FINAL { | 23 class InstructionSelector V8_FINAL { |
24 public: | 24 public: |
25 explicit InstructionSelector(InstructionSequence* sequence, | 25 // Forward declarations. |
26 SourcePositionTable* source_positions); | 26 class Features; |
| 27 |
| 28 InstructionSelector(InstructionSequence* sequence, |
| 29 SourcePositionTable* source_positions, |
| 30 Features features = SupportedFeatures()); |
27 | 31 |
28 // Visit code for the entire graph with the included schedule. | 32 // Visit code for the entire graph with the included schedule. |
29 void SelectInstructions(); | 33 void SelectInstructions(); |
30 | 34 |
31 // =========================================================================== | 35 // =========================================================================== |
32 // ============= Architecture-independent code emission methods. ============= | 36 // ============= Architecture-independent code emission methods. ============= |
33 // =========================================================================== | 37 // =========================================================================== |
34 | 38 |
35 Instruction* Emit(InstructionCode opcode, InstructionOperand* output, | 39 Instruction* Emit(InstructionCode opcode, InstructionOperand* output, |
36 size_t temp_count = 0, InstructionOperand* *temps = NULL); | 40 size_t temp_count = 0, InstructionOperand* *temps = NULL); |
(...skipping 10 matching lines...) Expand all Loading... |
47 Instruction* Emit(InstructionCode opcode, InstructionOperand* output, | 51 Instruction* Emit(InstructionCode opcode, InstructionOperand* output, |
48 InstructionOperand* a, InstructionOperand* b, | 52 InstructionOperand* a, InstructionOperand* b, |
49 InstructionOperand* c, InstructionOperand* d, | 53 InstructionOperand* c, InstructionOperand* d, |
50 size_t temp_count = 0, InstructionOperand* *temps = NULL); | 54 size_t temp_count = 0, InstructionOperand* *temps = NULL); |
51 Instruction* Emit(InstructionCode opcode, size_t output_count, | 55 Instruction* Emit(InstructionCode opcode, size_t output_count, |
52 InstructionOperand** outputs, size_t input_count, | 56 InstructionOperand** outputs, size_t input_count, |
53 InstructionOperand** inputs, size_t temp_count = 0, | 57 InstructionOperand** inputs, size_t temp_count = 0, |
54 InstructionOperand* *temps = NULL); | 58 InstructionOperand* *temps = NULL); |
55 Instruction* Emit(Instruction* instr); | 59 Instruction* Emit(Instruction* instr); |
56 | 60 |
| 61 // =========================================================================== |
| 62 // ============== Architecture-independent CPU feature methods. ============== |
| 63 // =========================================================================== |
| 64 |
| 65 class Features V8_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 |
57 private: | 87 private: |
58 friend class OperandGenerator; | 88 friend class OperandGenerator; |
59 | 89 |
60 // =========================================================================== | 90 // =========================================================================== |
61 // ============ Architecture-independent graph covering methods. ============= | 91 // ============ Architecture-independent graph covering methods. ============= |
62 // =========================================================================== | 92 // =========================================================================== |
63 | 93 |
64 // Checks if {block} will appear directly after {current_block_} when | 94 // Checks if {block} will appear directly after {current_block_} when |
65 // assembling code, in which case, a fall-through can be used. | 95 // assembling code, in which case, a fall-through can be used. |
66 bool IsNextInAssemblyOrder(const BasicBlock* block) const; | 96 bool IsNextInAssemblyOrder(const BasicBlock* block) const; |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 Zone* zone() { return &zone_; } | 191 Zone* zone() { return &zone_; } |
162 | 192 |
163 // =========================================================================== | 193 // =========================================================================== |
164 | 194 |
165 typedef zone_allocator<Instruction*> InstructionPtrZoneAllocator; | 195 typedef zone_allocator<Instruction*> InstructionPtrZoneAllocator; |
166 typedef std::deque<Instruction*, InstructionPtrZoneAllocator> Instructions; | 196 typedef std::deque<Instruction*, InstructionPtrZoneAllocator> Instructions; |
167 | 197 |
168 Zone zone_; | 198 Zone zone_; |
169 InstructionSequence* sequence_; | 199 InstructionSequence* sequence_; |
170 SourcePositionTable* source_positions_; | 200 SourcePositionTable* source_positions_; |
| 201 Features features_; |
171 BasicBlock* current_block_; | 202 BasicBlock* current_block_; |
172 Instructions instructions_; | 203 Instructions instructions_; |
173 BoolVector defined_; | 204 BoolVector defined_; |
174 BoolVector used_; | 205 BoolVector used_; |
175 }; | 206 }; |
176 | 207 |
177 } // namespace compiler | 208 } // namespace compiler |
178 } // namespace internal | 209 } // namespace internal |
179 } // namespace v8 | 210 } // namespace v8 |
180 | 211 |
181 #endif // V8_COMPILER_INSTRUCTION_SELECTOR_H_ | 212 #endif // V8_COMPILER_INSTRUCTION_SELECTOR_H_ |
OLD | NEW |