OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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_ASSEMBLER_H_ | 5 #ifndef V8_COMPILER_CODE_ASSEMBLER_H_ |
6 #define V8_COMPILER_CODE_ASSEMBLER_H_ | 6 #define V8_COMPILER_CODE_ASSEMBLER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <memory> | 9 #include <memory> |
10 | 10 |
(...skipping 12 matching lines...) Expand all Loading... |
23 | 23 |
24 class Callable; | 24 class Callable; |
25 class CallInterfaceDescriptor; | 25 class CallInterfaceDescriptor; |
26 class Isolate; | 26 class Isolate; |
27 class Factory; | 27 class Factory; |
28 class Zone; | 28 class Zone; |
29 | 29 |
30 namespace compiler { | 30 namespace compiler { |
31 | 31 |
32 class CallDescriptor; | 32 class CallDescriptor; |
33 class CodeAssemblerState; | |
34 class Node; | 33 class Node; |
35 class RawMachineAssembler; | 34 class RawMachineAssembler; |
36 class RawMachineLabel; | 35 class RawMachineLabel; |
37 | 36 |
38 #define CODE_ASSEMBLER_COMPARE_BINARY_OP_LIST(V) \ | 37 #define CODE_ASSEMBLER_COMPARE_BINARY_OP_LIST(V) \ |
39 V(Float32Equal) \ | 38 V(Float32Equal) \ |
40 V(Float32LessThan) \ | 39 V(Float32LessThan) \ |
41 V(Float32LessThanOrEqual) \ | 40 V(Float32LessThanOrEqual) \ |
42 V(Float32GreaterThan) \ | 41 V(Float32GreaterThan) \ |
43 V(Float32GreaterThanOrEqual) \ | 42 V(Float32GreaterThanOrEqual) \ |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 // V8 components that need to generate low-level code using this interface | 166 // V8 components that need to generate low-level code using this interface |
168 // should include this header--and this header only--from the compiler directory | 167 // should include this header--and this header only--from the compiler directory |
169 // (this is actually enforced). Since all interesting data structures are | 168 // (this is actually enforced). Since all interesting data structures are |
170 // forward declared, it's not possible for clients to peek inside the compiler | 169 // forward declared, it's not possible for clients to peek inside the compiler |
171 // internals. | 170 // internals. |
172 // | 171 // |
173 // In addition to providing isolation between TurboFan and code generation | 172 // In addition to providing isolation between TurboFan and code generation |
174 // clients, CodeAssembler also provides an abstraction for creating variables | 173 // clients, CodeAssembler also provides an abstraction for creating variables |
175 // and enhanced Label functionality to merge variable values along paths where | 174 // and enhanced Label functionality to merge variable values along paths where |
176 // they have differing values, including loops. | 175 // they have differing values, including loops. |
177 // | |
178 // The CodeAssembler itself is stateless (and instances are expected to be | |
179 // temporary-scoped and short-lived); all its state is encapsulated into | |
180 // a CodeAssemblerState instance. | |
181 class V8_EXPORT_PRIVATE CodeAssembler { | 176 class V8_EXPORT_PRIVATE CodeAssembler { |
182 public: | 177 public: |
183 explicit CodeAssembler(CodeAssemblerState* state) : state_(state) {} | 178 // Create with CallStub linkage. |
| 179 // |result_size| specifies the number of results returned by the stub. |
| 180 // TODO(rmcilroy): move result_size to the CallInterfaceDescriptor. |
| 181 CodeAssembler(Isolate* isolate, Zone* zone, |
| 182 const CallInterfaceDescriptor& descriptor, Code::Flags flags, |
| 183 const char* name, size_t result_size = 1); |
| 184 |
| 185 // Create with JSCall linkage. |
| 186 CodeAssembler(Isolate* isolate, Zone* zone, int parameter_count, |
| 187 Code::Flags flags, const char* name); |
184 | 188 |
185 virtual ~CodeAssembler(); | 189 virtual ~CodeAssembler(); |
186 | 190 |
187 static Handle<Code> GenerateCode(CodeAssemblerState* state); | 191 Handle<Code> GenerateCode(); |
188 | 192 |
189 bool Is64() const; | 193 bool Is64() const; |
190 bool IsFloat64RoundUpSupported() const; | 194 bool IsFloat64RoundUpSupported() const; |
191 bool IsFloat64RoundDownSupported() const; | 195 bool IsFloat64RoundDownSupported() const; |
192 bool IsFloat64RoundTruncateSupported() const; | 196 bool IsFloat64RoundTruncateSupported() const; |
193 | 197 |
194 class Label; | 198 class Label; |
195 class Variable { | 199 class Variable { |
196 public: | 200 public: |
197 explicit Variable(CodeAssembler* assembler, MachineRepresentation rep); | 201 explicit Variable(CodeAssembler* assembler, MachineRepresentation rep); |
198 ~Variable(); | 202 ~Variable(); |
199 void Bind(Node* value); | 203 void Bind(Node* value); |
200 Node* value() const; | 204 Node* value() const; |
201 MachineRepresentation rep() const; | 205 MachineRepresentation rep() const; |
202 bool IsBound() const; | 206 bool IsBound() const; |
203 | 207 |
204 private: | 208 private: |
205 friend class CodeAssembler; | 209 friend class CodeAssembler; |
206 friend class CodeAssemblerState; | |
207 class Impl; | 210 class Impl; |
208 Impl* impl_; | 211 Impl* impl_; |
209 CodeAssemblerState* state_; | 212 CodeAssembler* assembler_; |
210 }; | 213 }; |
211 | 214 |
212 typedef ZoneList<Variable*> VariableList; | 215 typedef ZoneList<Variable*> VariableList; |
213 | 216 |
214 // =========================================================================== | 217 // =========================================================================== |
215 // Base Assembler | 218 // Base Assembler |
216 // =========================================================================== | 219 // =========================================================================== |
217 | 220 |
218 // Constants. | 221 // Constants. |
219 Node* Int32Constant(int32_t value); | 222 Node* Int32Constant(int32_t value); |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
461 Factory* factory() const; | 464 Factory* factory() const; |
462 Isolate* isolate() const; | 465 Isolate* isolate() const; |
463 Zone* zone() const; | 466 Zone* zone() const; |
464 | 467 |
465 protected: | 468 protected: |
466 // Enables subclasses to perform operations before and after a call. | 469 // Enables subclasses to perform operations before and after a call. |
467 virtual void CallPrologue(); | 470 virtual void CallPrologue(); |
468 virtual void CallEpilogue(); | 471 virtual void CallEpilogue(); |
469 | 472 |
470 private: | 473 private: |
| 474 CodeAssembler(Isolate* isolate, Zone* zone, CallDescriptor* call_descriptor, |
| 475 Code::Flags flags, const char* name); |
| 476 |
471 Node* CallN(CallDescriptor* descriptor, Node* code_target, Node** args); | 477 Node* CallN(CallDescriptor* descriptor, Node* code_target, Node** args); |
472 Node* TailCallN(CallDescriptor* descriptor, Node* code_target, Node** args); | 478 Node* TailCallN(CallDescriptor* descriptor, Node* code_target, Node** args); |
473 | 479 |
474 RawMachineAssembler* raw_assembler() const; | 480 std::unique_ptr<RawMachineAssembler> raw_assembler_; |
475 | 481 Code::Flags flags_; |
476 CodeAssemblerState* state_; | 482 const char* name_; |
| 483 bool code_generated_; |
| 484 ZoneSet<Variable::Impl*> variables_; |
477 | 485 |
478 DISALLOW_COPY_AND_ASSIGN(CodeAssembler); | 486 DISALLOW_COPY_AND_ASSIGN(CodeAssembler); |
479 }; | 487 }; |
480 | 488 |
481 class CodeAssembler::Label { | 489 class CodeAssembler::Label { |
482 public: | 490 public: |
483 enum Type { kDeferred, kNonDeferred }; | 491 enum Type { kDeferred, kNonDeferred }; |
484 | 492 |
485 explicit Label( | 493 explicit Label( |
486 CodeAssembler* assembler, | 494 CodeAssembler* assembler, |
(...skipping 11 matching lines...) Expand all Loading... |
498 ~Label() {} | 506 ~Label() {} |
499 | 507 |
500 private: | 508 private: |
501 friend class CodeAssembler; | 509 friend class CodeAssembler; |
502 | 510 |
503 void Bind(); | 511 void Bind(); |
504 void MergeVariables(); | 512 void MergeVariables(); |
505 | 513 |
506 bool bound_; | 514 bool bound_; |
507 size_t merge_count_; | 515 size_t merge_count_; |
508 CodeAssemblerState* state_; | 516 CodeAssembler* assembler_; |
509 RawMachineLabel* label_; | 517 RawMachineLabel* label_; |
510 // Map of variables that need to be merged to their phi nodes (or placeholders | 518 // Map of variables that need to be merged to their phi nodes (or placeholders |
511 // for those phis). | 519 // for those phis). |
512 std::map<Variable::Impl*, Node*> variable_phis_; | 520 std::map<Variable::Impl*, Node*> variable_phis_; |
513 // Map of variables to the list of value nodes that have been added from each | 521 // Map of variables to the list of value nodes that have been added from each |
514 // merge path in their order of merging. | 522 // merge path in their order of merging. |
515 std::map<Variable::Impl*, std::vector<Node*>> variable_merges_; | 523 std::map<Variable::Impl*, std::vector<Node*>> variable_merges_; |
516 }; | 524 }; |
517 | 525 |
518 class V8_EXPORT_PRIVATE CodeAssemblerState { | |
519 public: | |
520 // Create with CallStub linkage. | |
521 // |result_size| specifies the number of results returned by the stub. | |
522 // TODO(rmcilroy): move result_size to the CallInterfaceDescriptor. | |
523 CodeAssemblerState(Isolate* isolate, Zone* zone, | |
524 const CallInterfaceDescriptor& descriptor, | |
525 Code::Flags flags, const char* name, | |
526 size_t result_size = 1); | |
527 | |
528 // Create with JSCall linkage. | |
529 CodeAssemblerState(Isolate* isolate, Zone* zone, int parameter_count, | |
530 Code::Flags flags, const char* name); | |
531 | |
532 ~CodeAssemblerState(); | |
533 | |
534 private: | |
535 friend class CodeAssembler; | |
536 | |
537 CodeAssemblerState(Isolate* isolate, Zone* zone, | |
538 CallDescriptor* call_descriptor, Code::Flags flags, | |
539 const char* name); | |
540 | |
541 std::unique_ptr<RawMachineAssembler> raw_assembler_; | |
542 Code::Flags flags_; | |
543 const char* name_; | |
544 bool code_generated_; | |
545 ZoneSet<CodeAssembler::Variable::Impl*> variables_; | |
546 | |
547 DISALLOW_COPY_AND_ASSIGN(CodeAssemblerState); | |
548 }; | |
549 | |
550 } // namespace compiler | 526 } // namespace compiler |
551 } // namespace internal | 527 } // namespace internal |
552 } // namespace v8 | 528 } // namespace v8 |
553 | 529 |
554 #endif // V8_COMPILER_CODE_ASSEMBLER_H_ | 530 #endif // V8_COMPILER_CODE_ASSEMBLER_H_ |
OLD | NEW |