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 RawLabel; | |
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(RawLabel* label); |
588 void Branch(Node* condition, Label* true_val, Label* false_val); | 577 void Branch(Node* condition, RawLabel* true_val, RawLabel* false_val); |
589 void Switch(Node* index, Label* default_label, int32_t* case_values, | 578 void Switch(Node* index, RawLabel* default_label, int32_t* case_values, |
590 Label** case_labels, size_t case_count); | 579 RawLabel** case_labels, size_t case_count); |
591 void Return(Node* value); | 580 void Return(Node* value); |
592 void Return(Node* v1, Node* v2); | 581 void Return(Node* v1, Node* v2); |
593 void Return(Node* v1, Node* v2, Node* v3); | 582 void Return(Node* v1, Node* v2, Node* v3); |
594 void Bind(Label* label); | 583 void Bind(RawLabel* label); |
595 void Deoptimize(Node* state); | 584 void Deoptimize(Node* state); |
596 | 585 |
597 // Variables. | 586 // Variables. |
598 Node* Phi(MachineType type, Node* n1, Node* n2) { | 587 Node* Phi(MachineType type, Node* n1, Node* n2) { |
599 return AddNode(common()->Phi(type, 2), n1, n2); | 588 return AddNode(common()->Phi(type, 2), n1, n2); |
600 } | 589 } |
601 Node* Phi(MachineType type, Node* n1, Node* n2, Node* n3) { | 590 Node* Phi(MachineType type, Node* n1, Node* n2, Node* n3) { |
602 return AddNode(common()->Phi(type, 3), n1, n2, n3); | 591 return AddNode(common()->Phi(type, 3), n1, n2, n3); |
603 } | 592 } |
604 Node* Phi(MachineType type, Node* n1, Node* n2, Node* n3, Node* n4) { | 593 Node* Phi(MachineType type, Node* n1, Node* n2, Node* n3, Node* n4) { |
(...skipping 12 matching lines...) Expand all Loading... | |
617 } | 606 } |
618 | 607 |
619 template <class... TArgs> | 608 template <class... TArgs> |
620 Node* AddNode(const Operator* op, Node* n1, TArgs... args) { | 609 Node* AddNode(const Operator* op, Node* n1, TArgs... args) { |
621 Node* buffer[] = {n1, args...}; | 610 Node* buffer[] = {n1, args...}; |
622 return AddNode(op, sizeof...(args) + 1, buffer); | 611 return AddNode(op, sizeof...(args) + 1, buffer); |
623 } | 612 } |
624 | 613 |
625 private: | 614 private: |
626 Node* MakeNode(const Operator* op, int input_count, Node** inputs); | 615 Node* MakeNode(const Operator* op, int input_count, Node** inputs); |
627 BasicBlock* Use(Label* label); | 616 BasicBlock* Use(RawLabel* label); |
628 BasicBlock* EnsureBlock(Label* label); | 617 BasicBlock* EnsureBlock(RawLabel* label); |
629 BasicBlock* CurrentBlock(); | 618 BasicBlock* CurrentBlock(); |
630 | 619 |
631 Schedule* schedule() { return schedule_; } | 620 Schedule* schedule() { return schedule_; } |
632 size_t parameter_count() const { return machine_sig()->parameter_count(); } | 621 size_t parameter_count() const { return machine_sig()->parameter_count(); } |
633 const MachineSignature* machine_sig() const { | 622 const MachineSignature* machine_sig() const { |
634 return call_descriptor_->GetMachineSignature(); | 623 return call_descriptor_->GetMachineSignature(); |
635 } | 624 } |
636 | 625 |
637 Isolate* isolate_; | 626 Isolate* isolate_; |
638 Graph* graph_; | 627 Graph* graph_; |
639 Schedule* schedule_; | 628 Schedule* schedule_; |
640 MachineOperatorBuilder machine_; | 629 MachineOperatorBuilder machine_; |
641 CommonOperatorBuilder common_; | 630 CommonOperatorBuilder common_; |
642 CallDescriptor* call_descriptor_; | 631 CallDescriptor* call_descriptor_; |
643 NodeVector parameters_; | 632 NodeVector parameters_; |
644 BasicBlock* current_block_; | 633 BasicBlock* current_block_; |
645 | 634 |
646 DISALLOW_COPY_AND_ASSIGN(RawMachineAssembler); | 635 DISALLOW_COPY_AND_ASSIGN(RawMachineAssembler); |
647 }; | 636 }; |
648 | 637 |
638 | |
639 class RawLabel { | |
Benedikt Meurer
2015/11/28 19:51:30
Nit: Can we mark it as final?
vogelheim
2015/11/30 09:55:16
Done.
| |
640 public: | |
641 RawLabel() : block_(NULL), used_(false), bound_(false) {} | |
Benedikt Meurer
2015/11/28 19:51:31
Nit: Can we put the implementation of both constru
vogelheim
2015/11/30 09:55:16
Done.
| |
642 ~RawLabel() { DCHECK(bound_ || !used_); } | |
643 | |
644 private: | |
645 BasicBlock* block_; | |
646 bool used_; | |
647 bool bound_; | |
648 friend class RawMachineAssembler; | |
649 DISALLOW_COPY_AND_ASSIGN(RawLabel); | |
650 }; | |
651 | |
649 } // namespace compiler | 652 } // namespace compiler |
650 } // namespace internal | 653 } // namespace internal |
651 } // namespace v8 | 654 } // namespace v8 |
652 | 655 |
653 #endif // V8_COMPILER_RAW_MACHINE_ASSEMBLER_H_ | 656 #endif // V8_COMPILER_RAW_MACHINE_ASSEMBLER_H_ |
OLD | NEW |