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