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_RAW_MACHINE_ASSEMBLER_H_ | 5 #ifndef V8_COMPILER_RAW_MACHINE_ASSEMBLER_H_ |
6 #define V8_COMPILER_RAW_MACHINE_ASSEMBLER_H_ | 6 #define V8_COMPILER_RAW_MACHINE_ASSEMBLER_H_ |
7 | 7 |
8 #include "src/assembler.h" | 8 #include "src/assembler.h" |
9 #include "src/compiler/common-operator.h" | 9 #include "src/compiler/common-operator.h" |
10 #include "src/compiler/graph.h" | 10 #include "src/compiler/graph.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 class BasicBlock; | 21 class BasicBlock; |
22 class Schedule; | 22 class Schedule; |
23 | 23 |
24 // The RawMachineAssembler produces a low-level IR graph. All nodes are wired | 24 // The RawMachineAssembler produces a low-level IR graph. All nodes are wired |
25 // into a graph and also placed into a schedule immediately, hence subsequent | 25 // into a graph and also placed into a schedule immediately, hence subsequent |
26 // code generation can happen without the need for scheduling. | 26 // code generation can happen without the need for scheduling. |
27 // | 27 // |
28 // In order to create a schedule on-the-fly, the assembler keeps track of basic | 28 // In order to create a schedule on-the-fly, the assembler keeps track of basic |
29 // blocks by having one current basic block being populated and by referencing | 29 // blocks by having one current basic block being populated and by referencing |
30 // other basic blocks through the use of labels. | 30 // other basic blocks through the use of labels. |
| 31 // |
| 32 // Also note that the generated graph is only valid together with the generated |
| 33 // schedule, using one without the other is invalid as the graph is inherently |
| 34 // non-schedulable due to missing control and effect dependencies. |
31 class RawMachineAssembler { | 35 class RawMachineAssembler { |
32 public: | 36 public: |
33 class Label { | 37 class Label { |
34 public: | 38 public: |
35 Label() : block_(NULL), used_(false), bound_(false) {} | 39 Label() : block_(NULL), used_(false), bound_(false) {} |
36 ~Label() { DCHECK(bound_ || !used_); } | 40 ~Label() { DCHECK(bound_ || !used_); } |
37 | 41 |
38 private: | 42 private: |
39 BasicBlock* block_; | 43 BasicBlock* block_; |
40 bool used_; | 44 bool used_; |
(...skipping 13 matching lines...) Expand all Loading... |
54 Graph* graph() const { return graph_; } | 58 Graph* graph() const { return graph_; } |
55 Schedule* schedule() { return schedule_; } | 59 Schedule* schedule() { return schedule_; } |
56 Zone* zone() const { return graph()->zone(); } | 60 Zone* zone() const { return graph()->zone(); } |
57 MachineOperatorBuilder* machine() { return &machine_; } | 61 MachineOperatorBuilder* machine() { return &machine_; } |
58 CommonOperatorBuilder* common() { return &common_; } | 62 CommonOperatorBuilder* common() { return &common_; } |
59 CallDescriptor* call_descriptor() const { return call_descriptor_; } | 63 CallDescriptor* call_descriptor() const { return call_descriptor_; } |
60 size_t parameter_count() const { return machine_sig()->parameter_count(); } | 64 size_t parameter_count() const { return machine_sig()->parameter_count(); } |
61 const MachineSignature* machine_sig() const { | 65 const MachineSignature* machine_sig() const { |
62 return call_descriptor_->GetMachineSignature(); | 66 return call_descriptor_->GetMachineSignature(); |
63 } | 67 } |
64 BasicBlock* CurrentBlock(); | |
65 | 68 |
66 // Finalizes the schedule and exports it to be used for code generation. Note | 69 // Finalizes the schedule and exports it to be used for code generation. Note |
67 // that this RawMachineAssembler becomes invalid after export. | 70 // that this RawMachineAssembler becomes invalid after export. |
68 Schedule* Export(); | 71 Schedule* Export(); |
69 | 72 |
70 // =========================================================================== | 73 // =========================================================================== |
71 // The following utility methods create new nodes with specific operators and | 74 // The following utility methods create new nodes with specific operators and |
72 // place them into the current basic block. They don't perform control flow, | 75 // place them into the current basic block. They don't perform control flow, |
73 // hence will not switch the current basic block. | 76 // hence will not switch the current basic block. |
74 | 77 |
(...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
551 // The following generic node creation methods can be used for operators that | 554 // The following generic node creation methods can be used for operators that |
552 // are not covered by the above utility methods. There should rarely be a need | 555 // are not covered by the above utility methods. There should rarely be a need |
553 // to do that outside of testing though. | 556 // to do that outside of testing though. |
554 | 557 |
555 Node* AddNode(const Operator* op, int input_count, Node** inputs); | 558 Node* AddNode(const Operator* op, int input_count, Node** inputs); |
556 | 559 |
557 Node* AddNode(const Operator* op) { | 560 Node* AddNode(const Operator* op) { |
558 return AddNode(op, 0, static_cast<Node**>(nullptr)); | 561 return AddNode(op, 0, static_cast<Node**>(nullptr)); |
559 } | 562 } |
560 | 563 |
561 Node* AddNode(const Operator* op, Node* n1) { return AddNode(op, 1, &n1); } | |
562 | |
563 template <class... TArgs> | 564 template <class... TArgs> |
564 Node* AddNode(const Operator* op, Node* n1, Node* n2, TArgs... args) { | 565 Node* AddNode(const Operator* op, Node* n1, TArgs... args) { |
565 Node* buffer[] = {n1, n2, args...}; | 566 Node* buffer[] = {n1, args...}; |
566 return AddNode(op, sizeof...(args) + 2, buffer); | 567 return AddNode(op, sizeof...(args) + 1, buffer); |
567 } | 568 } |
568 | 569 |
569 private: | 570 private: |
570 Node* MakeNode(const Operator* op, int input_count, Node** inputs); | 571 Node* MakeNode(const Operator* op, int input_count, Node** inputs); |
571 BasicBlock* Use(Label* label); | 572 BasicBlock* Use(Label* label); |
572 BasicBlock* EnsureBlock(Label* label); | 573 BasicBlock* EnsureBlock(Label* label); |
| 574 BasicBlock* CurrentBlock(); |
573 | 575 |
574 Isolate* isolate_; | 576 Isolate* isolate_; |
575 Graph* graph_; | 577 Graph* graph_; |
576 Schedule* schedule_; | 578 Schedule* schedule_; |
577 MachineOperatorBuilder machine_; | 579 MachineOperatorBuilder machine_; |
578 CommonOperatorBuilder common_; | 580 CommonOperatorBuilder common_; |
579 CallDescriptor* call_descriptor_; | 581 CallDescriptor* call_descriptor_; |
580 Node** parameters_; | 582 Node** parameters_; |
581 BasicBlock* current_block_; | 583 BasicBlock* current_block_; |
582 | 584 |
583 DISALLOW_COPY_AND_ASSIGN(RawMachineAssembler); | 585 DISALLOW_COPY_AND_ASSIGN(RawMachineAssembler); |
584 }; | 586 }; |
585 | 587 |
586 } // namespace compiler | 588 } // namespace compiler |
587 } // namespace internal | 589 } // namespace internal |
588 } // namespace v8 | 590 } // namespace v8 |
589 | 591 |
590 #endif // V8_COMPILER_RAW_MACHINE_ASSEMBLER_H_ | 592 #endif // V8_COMPILER_RAW_MACHINE_ASSEMBLER_H_ |
OLD | NEW |