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" |
11 #include "src/compiler/linkage.h" | 11 #include "src/compiler/linkage.h" |
12 #include "src/compiler/machine-operator.h" | 12 #include "src/compiler/machine-operator.h" |
13 #include "src/compiler/node.h" | 13 #include "src/compiler/node.h" |
14 #include "src/compiler/operator.h" | 14 #include "src/compiler/operator.h" |
15 #include "src/factory.h" | 15 #include "src/factory.h" |
16 | 16 |
17 namespace v8 { | 17 namespace v8 { |
18 namespace internal { | 18 namespace internal { |
19 namespace compiler { | 19 namespace compiler { |
20 | 20 |
21 class BasicBlock; | 21 class BasicBlock; |
| 22 class RawMachineLabel; |
22 class Schedule; | 23 class Schedule; |
23 | 24 |
| 25 |
24 // The RawMachineAssembler produces a low-level IR graph. All nodes are wired | 26 // 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 | 27 // into a graph and also placed into a schedule immediately, hence subsequent |
26 // code generation can happen without the need for scheduling. | 28 // code generation can happen without the need for scheduling. |
27 // | 29 // |
28 // In order to create a schedule on-the-fly, the assembler keeps track of basic | 30 // 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 | 31 // blocks by having one current basic block being populated and by referencing |
30 // other basic blocks through the use of labels. | 32 // other basic blocks through the use of labels. |
31 // | 33 // |
32 // Also note that the generated graph is only valid together with the generated | 34 // 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 | 35 // schedule, using one without the other is invalid as the graph is inherently |
34 // non-schedulable due to missing control and effect dependencies. | 36 // non-schedulable due to missing control and effect dependencies. |
35 class RawMachineAssembler { | 37 class RawMachineAssembler { |
36 public: | 38 public: |
37 class Label { | |
38 public: | |
39 Label() : block_(NULL), used_(false), bound_(false) {} | |
40 ~Label() { DCHECK(bound_ || !used_); } | |
41 | |
42 private: | |
43 BasicBlock* block_; | |
44 bool used_; | |
45 bool bound_; | |
46 friend class RawMachineAssembler; | |
47 DISALLOW_COPY_AND_ASSIGN(Label); | |
48 }; | |
49 | |
50 RawMachineAssembler(Isolate* isolate, Graph* graph, | 39 RawMachineAssembler(Isolate* isolate, Graph* graph, |
51 CallDescriptor* call_descriptor, | 40 CallDescriptor* call_descriptor, |
52 MachineType word = kMachPtr, | 41 MachineType word = kMachPtr, |
53 MachineOperatorBuilder::Flags flags = | 42 MachineOperatorBuilder::Flags flags = |
54 MachineOperatorBuilder::Flag::kNoFlags); | 43 MachineOperatorBuilder::Flag::kNoFlags); |
55 ~RawMachineAssembler() {} | 44 ~RawMachineAssembler() {} |
56 | 45 |
57 Isolate* isolate() const { return isolate_; } | 46 Isolate* isolate() const { return isolate_; } |
58 Graph* graph() const { return graph_; } | 47 Graph* graph() const { return graph_; } |
59 Zone* zone() const { return graph()->zone(); } | 48 Zone* zone() const { return graph()->zone(); } |
(...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
577 MachineType arg5_type, MachineType arg6_type, | 566 MachineType arg5_type, MachineType arg6_type, |
578 MachineType arg7_type, Node* function, Node* arg0, | 567 MachineType arg7_type, Node* function, Node* arg0, |
579 Node* arg1, Node* arg2, Node* arg3, Node* arg4, | 568 Node* arg1, Node* arg2, Node* arg3, Node* arg4, |
580 Node* arg5, Node* arg6, Node* arg7); | 569 Node* arg5, Node* arg6, Node* arg7); |
581 | 570 |
582 // =========================================================================== | 571 // =========================================================================== |
583 // The following utility methods deal with control flow, hence might switch | 572 // The following utility methods deal with control flow, hence might switch |
584 // the current basic block or create new basic blocks for labels. | 573 // the current basic block or create new basic blocks for labels. |
585 | 574 |
586 // Control flow. | 575 // Control flow. |
587 void Goto(Label* label); | 576 void Goto(RawMachineLabel* label); |
588 void Branch(Node* condition, Label* true_val, Label* false_val); | 577 void Branch(Node* condition, RawMachineLabel* true_val, |
589 void Switch(Node* index, Label* default_label, int32_t* case_values, | 578 RawMachineLabel* false_val); |
590 Label** case_labels, size_t case_count); | 579 void Switch(Node* index, RawMachineLabel* default_label, int32_t* case_values, |
| 580 RawMachineLabel** case_labels, size_t case_count); |
591 void Return(Node* value); | 581 void Return(Node* value); |
592 void Return(Node* v1, Node* v2); | 582 void Return(Node* v1, Node* v2); |
593 void Return(Node* v1, Node* v2, Node* v3); | 583 void Return(Node* v1, Node* v2, Node* v3); |
594 void Bind(Label* label); | 584 void Bind(RawMachineLabel* label); |
595 void Deoptimize(Node* state); | 585 void Deoptimize(Node* state); |
596 | 586 |
597 // Variables. | 587 // Variables. |
598 Node* Phi(MachineType type, Node* n1, Node* n2) { | 588 Node* Phi(MachineType type, Node* n1, Node* n2) { |
599 return AddNode(common()->Phi(type, 2), n1, n2); | 589 return AddNode(common()->Phi(type, 2), n1, n2); |
600 } | 590 } |
601 Node* Phi(MachineType type, Node* n1, Node* n2, Node* n3) { | 591 Node* Phi(MachineType type, Node* n1, Node* n2, Node* n3) { |
602 return AddNode(common()->Phi(type, 3), n1, n2, n3); | 592 return AddNode(common()->Phi(type, 3), n1, n2, n3); |
603 } | 593 } |
604 Node* Phi(MachineType type, Node* n1, Node* n2, Node* n3, Node* n4) { | 594 Node* Phi(MachineType type, Node* n1, Node* n2, Node* n3, Node* n4) { |
(...skipping 12 matching lines...) Expand all Loading... |
617 } | 607 } |
618 | 608 |
619 template <class... TArgs> | 609 template <class... TArgs> |
620 Node* AddNode(const Operator* op, Node* n1, TArgs... args) { | 610 Node* AddNode(const Operator* op, Node* n1, TArgs... args) { |
621 Node* buffer[] = {n1, args...}; | 611 Node* buffer[] = {n1, args...}; |
622 return AddNode(op, sizeof...(args) + 1, buffer); | 612 return AddNode(op, sizeof...(args) + 1, buffer); |
623 } | 613 } |
624 | 614 |
625 private: | 615 private: |
626 Node* MakeNode(const Operator* op, int input_count, Node** inputs); | 616 Node* MakeNode(const Operator* op, int input_count, Node** inputs); |
627 BasicBlock* Use(Label* label); | 617 BasicBlock* Use(RawMachineLabel* label); |
628 BasicBlock* EnsureBlock(Label* label); | 618 BasicBlock* EnsureBlock(RawMachineLabel* label); |
629 BasicBlock* CurrentBlock(); | 619 BasicBlock* CurrentBlock(); |
630 | 620 |
631 Schedule* schedule() { return schedule_; } | 621 Schedule* schedule() { return schedule_; } |
632 size_t parameter_count() const { return machine_sig()->parameter_count(); } | 622 size_t parameter_count() const { return machine_sig()->parameter_count(); } |
633 const MachineSignature* machine_sig() const { | 623 const MachineSignature* machine_sig() const { |
634 return call_descriptor_->GetMachineSignature(); | 624 return call_descriptor_->GetMachineSignature(); |
635 } | 625 } |
636 | 626 |
637 Isolate* isolate_; | 627 Isolate* isolate_; |
638 Graph* graph_; | 628 Graph* graph_; |
639 Schedule* schedule_; | 629 Schedule* schedule_; |
640 MachineOperatorBuilder machine_; | 630 MachineOperatorBuilder machine_; |
641 CommonOperatorBuilder common_; | 631 CommonOperatorBuilder common_; |
642 CallDescriptor* call_descriptor_; | 632 CallDescriptor* call_descriptor_; |
643 NodeVector parameters_; | 633 NodeVector parameters_; |
644 BasicBlock* current_block_; | 634 BasicBlock* current_block_; |
645 | 635 |
646 DISALLOW_COPY_AND_ASSIGN(RawMachineAssembler); | 636 DISALLOW_COPY_AND_ASSIGN(RawMachineAssembler); |
647 }; | 637 }; |
648 | 638 |
| 639 |
| 640 class RawMachineLabel final { |
| 641 public: |
| 642 RawMachineLabel(); |
| 643 ~RawMachineLabel(); |
| 644 |
| 645 private: |
| 646 BasicBlock* block_; |
| 647 bool used_; |
| 648 bool bound_; |
| 649 friend class RawMachineAssembler; |
| 650 DISALLOW_COPY_AND_ASSIGN(RawMachineLabel); |
| 651 }; |
| 652 |
649 } // namespace compiler | 653 } // namespace compiler |
650 } // namespace internal | 654 } // namespace internal |
651 } // namespace v8 | 655 } // namespace v8 |
652 | 656 |
653 #endif // V8_COMPILER_RAW_MACHINE_ASSEMBLER_H_ | 657 #endif // V8_COMPILER_RAW_MACHINE_ASSEMBLER_H_ |
OLD | NEW |