| 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_CCTEST_COMPILER_STRUCTURED_MACHINE_ASSEMBLER_H_ | 5 #ifndef V8_CCTEST_COMPILER_STRUCTURED_MACHINE_ASSEMBLER_H_ |
| 6 #define V8_CCTEST_COMPILER_STRUCTURED_MACHINE_ASSEMBLER_H_ | 6 #define V8_CCTEST_COMPILER_STRUCTURED_MACHINE_ASSEMBLER_H_ |
| 7 | 7 |
| 8 #include "src/v8.h" | 8 #include "src/v8.h" |
| 9 | 9 |
| 10 #include "src/compiler/common-operator.h" | 10 #include "src/compiler/common-operator.h" |
| 11 #include "src/compiler/graph-builder.h" | 11 #include "src/compiler/graph-builder.h" |
| 12 #include "src/compiler/machine-node-factory.h" | |
| 13 #include "src/compiler/machine-operator.h" | 12 #include "src/compiler/machine-operator.h" |
| 14 #include "src/compiler/node.h" | 13 #include "src/compiler/node.h" |
| 15 #include "src/compiler/operator.h" | 14 #include "src/compiler/operator.h" |
| 15 #include "src/compiler/raw-machine-assembler.h" |
| 16 | 16 |
| 17 | 17 |
| 18 namespace v8 { | 18 namespace v8 { |
| 19 namespace internal { | 19 namespace internal { |
| 20 namespace compiler { | 20 namespace compiler { |
| 21 | 21 |
| 22 class BasicBlock; | 22 class BasicBlock; |
| 23 class Schedule; | 23 class Schedule; |
| 24 class StructuredMachineAssembler; | 24 class StructuredMachineAssembler; |
| 25 | 25 |
| 26 | 26 |
| 27 class Variable : public ZoneObject { | 27 class Variable : public ZoneObject { |
| 28 public: | 28 public: |
| 29 Node* Get() const; | 29 Node* Get() const; |
| 30 void Set(Node* value) const; | 30 void Set(Node* value) const; |
| 31 | 31 |
| 32 private: | 32 private: |
| 33 Variable(StructuredMachineAssembler* smasm, int offset) | 33 Variable(StructuredMachineAssembler* smasm, int offset) |
| 34 : smasm_(smasm), offset_(offset) {} | 34 : smasm_(smasm), offset_(offset) {} |
| 35 | 35 |
| 36 friend class StructuredMachineAssembler; | 36 friend class StructuredMachineAssembler; |
| 37 friend class StructuredMachineAssemblerFriend; | 37 friend class StructuredMachineAssemblerFriend; |
| 38 StructuredMachineAssembler* const smasm_; | 38 StructuredMachineAssembler* const smasm_; |
| 39 const int offset_; | 39 const int offset_; |
| 40 }; | 40 }; |
| 41 | 41 |
| 42 | 42 |
| 43 class StructuredMachineAssembler | 43 class StructuredMachineAssembler : public RawMachineAssembler { |
| 44 : public GraphBuilder, | |
| 45 public MachineNodeFactory<StructuredMachineAssembler> { | |
| 46 public: | 44 public: |
| 47 class Environment : public ZoneObject { | 45 class Environment : public ZoneObject { |
| 48 public: | 46 public: |
| 49 Environment(Zone* zone, BasicBlock* block, bool is_dead_); | 47 Environment(Zone* zone, BasicBlock* block, bool is_dead_); |
| 50 | 48 |
| 51 private: | 49 private: |
| 52 BasicBlock* block_; | 50 BasicBlock* block_; |
| 53 NodeVector variables_; | 51 NodeVector variables_; |
| 54 bool is_dead_; | 52 bool is_dead_; |
| 55 friend class StructuredMachineAssembler; | 53 friend class StructuredMachineAssembler; |
| 56 DISALLOW_COPY_AND_ASSIGN(Environment); | 54 DISALLOW_COPY_AND_ASSIGN(Environment); |
| 57 }; | 55 }; |
| 58 | 56 |
| 59 class IfBuilder; | 57 class IfBuilder; |
| 60 friend class IfBuilder; | 58 friend class IfBuilder; |
| 61 class LoopBuilder; | 59 class LoopBuilder; |
| 62 friend class LoopBuilder; | 60 friend class LoopBuilder; |
| 63 | 61 |
| 64 StructuredMachineAssembler(Graph* graph, MachineSignature* machine_sig, | 62 StructuredMachineAssembler(Graph* graph, MachineSignature* machine_sig, |
| 65 MachineType word = kMachPtr); | 63 MachineType word = kMachPtr); |
| 66 virtual ~StructuredMachineAssembler() {} | 64 virtual ~StructuredMachineAssembler() {} |
| 67 | 65 |
| 68 Isolate* isolate() const { return zone()->isolate(); } | |
| 69 Zone* zone() const { return graph()->zone(); } | |
| 70 MachineOperatorBuilder* machine() { return &machine_; } | |
| 71 CommonOperatorBuilder* common() { return &common_; } | |
| 72 CallDescriptor* call_descriptor() const { return call_descriptor_; } | |
| 73 size_t parameter_count() const { return machine_sig_->parameter_count(); } | |
| 74 MachineSignature* machine_sig() const { return machine_sig_; } | |
| 75 | |
| 76 // Parameters. | |
| 77 Node* Parameter(size_t index); | |
| 78 // Variables. | 66 // Variables. |
| 79 Variable NewVariable(Node* initial_value); | 67 Variable NewVariable(Node* initial_value); |
| 80 // Control flow. | 68 // Control flow. |
| 81 void Return(Node* value); | 69 void Return(Node* value); |
| 82 | 70 |
| 83 // MachineAssembler is invalid after export. | |
| 84 Schedule* Export(); | |
| 85 | |
| 86 protected: | 71 protected: |
| 87 virtual Node* MakeNode(Operator* op, int input_count, Node** inputs); | 72 virtual Node* MakeNode(Operator* op, int input_count, Node** inputs); |
| 88 | 73 |
| 89 Schedule* schedule() { | |
| 90 DCHECK(ScheduleValid()); | |
| 91 return schedule_; | |
| 92 } | |
| 93 | |
| 94 private: | 74 private: |
| 95 bool ScheduleValid() { return schedule_ != NULL; } | |
| 96 | |
| 97 typedef ZoneVector<Environment*> EnvironmentVector; | 75 typedef ZoneVector<Environment*> EnvironmentVector; |
| 98 | 76 |
| 99 NodeVector* CurrentVars() { return ¤t_environment_->variables_; } | 77 NodeVector* CurrentVars() { return ¤t_environment_->variables_; } |
| 100 Node*& VariableAt(Environment* environment, int offset); | 78 Node*& VariableAt(Environment* environment, int offset); |
| 101 Node* GetVariable(int offset); | 79 Node* GetVariable(int offset); |
| 102 void SetVariable(int offset, Node* value); | 80 void SetVariable(int offset, Node* value); |
| 103 | 81 |
| 104 void AddBranch(Environment* environment, Node* condition, | 82 void AddBranch(Environment* environment, Node* condition, |
| 105 Environment* true_val, Environment* false_val); | 83 Environment* true_val, Environment* false_val); |
| 106 void AddGoto(Environment* from, Environment* to); | 84 void AddGoto(Environment* from, Environment* to); |
| 107 BasicBlock* TrampolineFor(BasicBlock* block); | 85 BasicBlock* TrampolineFor(BasicBlock* block); |
| 108 | 86 |
| 109 void CopyCurrentAsDead(); | 87 void CopyCurrentAsDead(); |
| 110 Environment* Copy(Environment* environment) { | 88 Environment* Copy(Environment* environment) { |
| 111 return Copy(environment, static_cast<int>(environment->variables_.size())); | 89 return Copy(environment, static_cast<int>(environment->variables_.size())); |
| 112 } | 90 } |
| 113 Environment* Copy(Environment* environment, int truncate_at); | 91 Environment* Copy(Environment* environment, int truncate_at); |
| 114 void Merge(EnvironmentVector* environments, int truncate_at); | 92 void Merge(EnvironmentVector* environments, int truncate_at); |
| 115 Environment* CopyForLoopHeader(Environment* environment); | 93 Environment* CopyForLoopHeader(Environment* environment); |
| 116 void MergeBackEdgesToLoopHeader(Environment* header, | 94 void MergeBackEdgesToLoopHeader(Environment* header, |
| 117 EnvironmentVector* environments); | 95 EnvironmentVector* environments); |
| 118 | 96 |
| 119 Schedule* schedule_; | |
| 120 MachineOperatorBuilder machine_; | |
| 121 CommonOperatorBuilder common_; | |
| 122 MachineSignature* machine_sig_; | |
| 123 CallDescriptor* call_descriptor_; | |
| 124 Node** parameters_; | |
| 125 Environment* current_environment_; | 97 Environment* current_environment_; |
| 126 int number_of_variables_; | 98 int number_of_variables_; |
| 127 | 99 |
| 128 friend class Variable; | 100 friend class Variable; |
| 129 // For testing only. | 101 // For testing only. |
| 130 friend class StructuredMachineAssemblerFriend; | 102 friend class StructuredMachineAssemblerFriend; |
| 131 DISALLOW_COPY_AND_ASSIGN(StructuredMachineAssembler); | 103 DISALLOW_COPY_AND_ASSIGN(StructuredMachineAssembler); |
| 132 }; | 104 }; |
| 133 | 105 |
| 134 // IfBuilder constructs of nested if-else expressions which more or less follow | 106 // IfBuilder constructs of nested if-else expressions which more or less follow |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 EnvironmentVector pending_header_merges_; | 262 EnvironmentVector pending_header_merges_; |
| 291 EnvironmentVector pending_exit_merges_; | 263 EnvironmentVector pending_exit_merges_; |
| 292 DISALLOW_COPY_AND_ASSIGN(LoopBuilder); | 264 DISALLOW_COPY_AND_ASSIGN(LoopBuilder); |
| 293 }; | 265 }; |
| 294 | 266 |
| 295 } // namespace compiler | 267 } // namespace compiler |
| 296 } // namespace internal | 268 } // namespace internal |
| 297 } // namespace v8 | 269 } // namespace v8 |
| 298 | 270 |
| 299 #endif // V8_CCTEST_COMPILER_STRUCTURED_MACHINE_ASSEMBLER_H_ | 271 #endif // V8_CCTEST_COMPILER_STRUCTURED_MACHINE_ASSEMBLER_H_ |
| OLD | NEW |