| 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_GRAPH_BUILDER_TESTER_H_ | 5 #ifndef V8_CCTEST_COMPILER_GRAPH_BUILDER_TESTER_H_ |
| 6 #define V8_CCTEST_COMPILER_GRAPH_BUILDER_TESTER_H_ | 6 #define V8_CCTEST_COMPILER_GRAPH_BUILDER_TESTER_H_ |
| 7 | 7 |
| 8 #include "src/v8.h" | 8 #include "src/v8.h" |
| 9 #include "test/cctest/cctest.h" | 9 #include "test/cctest/cctest.h" |
| 10 | 10 |
| 11 #include "src/compiler/common-operator.h" | 11 #include "src/compiler/common-operator.h" |
| 12 #include "src/compiler/graph-builder.h" | |
| 13 #include "src/compiler/linkage.h" | 12 #include "src/compiler/linkage.h" |
| 14 #include "src/compiler/machine-operator.h" | 13 #include "src/compiler/machine-operator.h" |
| 15 #include "src/compiler/operator-properties.h" | 14 #include "src/compiler/operator-properties.h" |
| 16 #include "src/compiler/pipeline.h" | 15 #include "src/compiler/pipeline.h" |
| 17 #include "src/compiler/simplified-operator.h" | 16 #include "src/compiler/simplified-operator.h" |
| 18 #include "test/cctest/compiler/call-tester.h" | 17 #include "test/cctest/compiler/call-tester.h" |
| 19 | 18 |
| 20 namespace v8 { | 19 namespace v8 { |
| 21 namespace internal { | 20 namespace internal { |
| 22 namespace compiler { | 21 namespace compiler { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 34 Graph* main_graph_; | 33 Graph* main_graph_; |
| 35 CommonOperatorBuilder main_common_; | 34 CommonOperatorBuilder main_common_; |
| 36 MachineOperatorBuilder main_machine_; | 35 MachineOperatorBuilder main_machine_; |
| 37 SimplifiedOperatorBuilder main_simplified_; | 36 SimplifiedOperatorBuilder main_simplified_; |
| 38 }; | 37 }; |
| 39 | 38 |
| 40 | 39 |
| 41 template <typename ReturnType> | 40 template <typename ReturnType> |
| 42 class GraphBuilderTester : public HandleAndZoneScope, | 41 class GraphBuilderTester : public HandleAndZoneScope, |
| 43 private GraphAndBuilders, | 42 private GraphAndBuilders, |
| 44 public CallHelper<ReturnType>, | 43 public CallHelper<ReturnType> { |
| 45 public GraphBuilder { | |
| 46 public: | 44 public: |
| 47 explicit GraphBuilderTester(MachineType p0 = kMachNone, | 45 explicit GraphBuilderTester(MachineType p0 = kMachNone, |
| 48 MachineType p1 = kMachNone, | 46 MachineType p1 = kMachNone, |
| 49 MachineType p2 = kMachNone, | 47 MachineType p2 = kMachNone, |
| 50 MachineType p3 = kMachNone, | 48 MachineType p3 = kMachNone, |
| 51 MachineType p4 = kMachNone) | 49 MachineType p4 = kMachNone) |
| 52 : GraphAndBuilders(main_zone()), | 50 : GraphAndBuilders(main_zone()), |
| 53 CallHelper<ReturnType>( | 51 CallHelper<ReturnType>( |
| 54 main_isolate(), | 52 main_isolate(), |
| 55 CSignature::New(main_zone(), MachineTypeForC<ReturnType>(), p0, p1, | 53 CSignature::New(main_zone(), MachineTypeForC<ReturnType>(), p0, p1, |
| 56 p2, p3, p4)), | 54 p2, p3, p4)), |
| 57 GraphBuilder(main_isolate(), main_graph_), | |
| 58 effect_(NULL), | 55 effect_(NULL), |
| 59 return_(NULL), | 56 return_(NULL), |
| 60 parameters_(main_zone()->template NewArray<Node*>(parameter_count())) { | 57 parameters_(main_zone()->template NewArray<Node*>(parameter_count())) { |
| 61 Begin(static_cast<int>(parameter_count())); | 58 Begin(static_cast<int>(parameter_count())); |
| 62 InitParameters(); | 59 InitParameters(); |
| 63 } | 60 } |
| 64 virtual ~GraphBuilderTester() {} | 61 virtual ~GraphBuilderTester() {} |
| 65 | 62 |
| 66 void GenerateCode() { Generate(); } | 63 void GenerateCode() { Generate(); } |
| 67 Node* Parameter(size_t index) { | 64 Node* Parameter(size_t index) { |
| 68 DCHECK(index < parameter_count()); | 65 DCHECK(index < parameter_count()); |
| 69 return parameters_[index]; | 66 return parameters_[index]; |
| 70 } | 67 } |
| 71 | 68 |
| 69 Isolate* isolate() { return main_isolate(); } |
| 70 Graph* graph() const { return main_graph_; } |
| 72 Zone* zone() const { return graph()->zone(); } | 71 Zone* zone() const { return graph()->zone(); } |
| 73 Factory* factory() const { return isolate()->factory(); } | 72 Factory* factory() { return isolate()->factory(); } |
| 74 CommonOperatorBuilder* common() { return &main_common_; } | 73 CommonOperatorBuilder* common() { return &main_common_; } |
| 75 MachineOperatorBuilder* machine() { return &main_machine_; } | 74 MachineOperatorBuilder* machine() { return &main_machine_; } |
| 76 SimplifiedOperatorBuilder* simplified() { return &main_simplified_; } | 75 SimplifiedOperatorBuilder* simplified() { return &main_simplified_; } |
| 77 | 76 |
| 78 // Initialize graph and builder. | 77 // Initialize graph and builder. |
| 79 void Begin(int num_parameters) { | 78 void Begin(int num_parameters) { |
| 80 DCHECK(graph()->start() == NULL); | 79 DCHECK(graph()->start() == NULL); |
| 81 Node* start = graph()->NewNode(common()->Start(num_parameters + 3)); | 80 Node* start = graph()->NewNode(common()->Start(num_parameters + 3)); |
| 82 graph()->SetStart(start); | 81 graph()->SetStart(start); |
| 83 effect_ = start; | 82 effect_ = start; |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 return NewNode(simplified()->StoreField(access), object, value); | 182 return NewNode(simplified()->StoreField(access), object, value); |
| 184 } | 183 } |
| 185 Node* LoadElement(const ElementAccess& access, Node* object, Node* index) { | 184 Node* LoadElement(const ElementAccess& access, Node* object, Node* index) { |
| 186 return NewNode(simplified()->LoadElement(access), object, index); | 185 return NewNode(simplified()->LoadElement(access), object, index); |
| 187 } | 186 } |
| 188 Node* StoreElement(const ElementAccess& access, Node* object, Node* index, | 187 Node* StoreElement(const ElementAccess& access, Node* object, Node* index, |
| 189 Node* value) { | 188 Node* value) { |
| 190 return NewNode(simplified()->StoreElement(access), object, index, value); | 189 return NewNode(simplified()->StoreElement(access), object, index, value); |
| 191 } | 190 } |
| 192 | 191 |
| 192 Node* NewNode(const Operator* op) { |
| 193 return MakeNode(op, 0, static_cast<Node**>(NULL)); |
| 194 } |
| 195 |
| 196 Node* NewNode(const Operator* op, Node* n1) { return MakeNode(op, 1, &n1); } |
| 197 |
| 198 Node* NewNode(const Operator* op, Node* n1, Node* n2) { |
| 199 Node* buffer[] = {n1, n2}; |
| 200 return MakeNode(op, arraysize(buffer), buffer); |
| 201 } |
| 202 |
| 203 Node* NewNode(const Operator* op, Node* n1, Node* n2, Node* n3) { |
| 204 Node* buffer[] = {n1, n2, n3}; |
| 205 return MakeNode(op, arraysize(buffer), buffer); |
| 206 } |
| 207 |
| 208 Node* NewNode(const Operator* op, Node* n1, Node* n2, Node* n3, Node* n4) { |
| 209 Node* buffer[] = {n1, n2, n3, n4}; |
| 210 return MakeNode(op, arraysize(buffer), buffer); |
| 211 } |
| 212 |
| 213 Node* NewNode(const Operator* op, Node* n1, Node* n2, Node* n3, Node* n4, |
| 214 Node* n5) { |
| 215 Node* buffer[] = {n1, n2, n3, n4, n5}; |
| 216 return MakeNode(op, arraysize(buffer), buffer); |
| 217 } |
| 218 |
| 219 Node* NewNode(const Operator* op, Node* n1, Node* n2, Node* n3, Node* n4, |
| 220 Node* n5, Node* n6) { |
| 221 Node* nodes[] = {n1, n2, n3, n4, n5, n6}; |
| 222 return MakeNode(op, arraysize(nodes), nodes); |
| 223 } |
| 224 |
| 225 Node* NewNode(const Operator* op, int value_input_count, |
| 226 Node** value_inputs) { |
| 227 return MakeNode(op, value_input_count, value_inputs); |
| 228 } |
| 229 |
| 193 protected: | 230 protected: |
| 194 virtual Node* MakeNode(const Operator* op, int value_input_count, | 231 Node* MakeNode(const Operator* op, int value_input_count, |
| 195 Node** value_inputs, bool incomplete) final { | 232 Node** value_inputs) { |
| 196 DCHECK(op->ValueInputCount() == value_input_count); | 233 DCHECK(op->ValueInputCount() == value_input_count); |
| 197 | 234 |
| 198 DCHECK(!OperatorProperties::HasContextInput(op)); | 235 DCHECK(!OperatorProperties::HasContextInput(op)); |
| 199 DCHECK_EQ(0, OperatorProperties::GetFrameStateInputCount(op)); | 236 DCHECK_EQ(0, OperatorProperties::GetFrameStateInputCount(op)); |
| 200 bool has_control = op->ControlInputCount() == 1; | 237 bool has_control = op->ControlInputCount() == 1; |
| 201 bool has_effect = op->EffectInputCount() == 1; | 238 bool has_effect = op->EffectInputCount() == 1; |
| 202 | 239 |
| 203 DCHECK(op->ControlInputCount() < 2); | 240 DCHECK(op->ControlInputCount() < 2); |
| 204 DCHECK(op->EffectInputCount() < 2); | 241 DCHECK(op->EffectInputCount() < 2); |
| 205 | 242 |
| 206 Node* result = NULL; | 243 Node* result = NULL; |
| 207 if (!has_control && !has_effect) { | 244 if (!has_control && !has_effect) { |
| 208 result = | 245 result = graph()->NewNode(op, value_input_count, value_inputs); |
| 209 graph()->NewNode(op, value_input_count, value_inputs, incomplete); | |
| 210 } else { | 246 } else { |
| 211 int input_count_with_deps = value_input_count; | 247 int input_count_with_deps = value_input_count; |
| 212 if (has_control) ++input_count_with_deps; | 248 if (has_control) ++input_count_with_deps; |
| 213 if (has_effect) ++input_count_with_deps; | 249 if (has_effect) ++input_count_with_deps; |
| 214 Node** buffer = zone()->template NewArray<Node*>(input_count_with_deps); | 250 Node** buffer = zone()->template NewArray<Node*>(input_count_with_deps); |
| 215 memcpy(buffer, value_inputs, kPointerSize * value_input_count); | 251 memcpy(buffer, value_inputs, kPointerSize * value_input_count); |
| 216 Node** current_input = buffer + value_input_count; | 252 Node** current_input = buffer + value_input_count; |
| 217 if (has_effect) { | 253 if (has_effect) { |
| 218 *current_input++ = effect_; | 254 *current_input++ = effect_; |
| 219 } | 255 } |
| 220 if (has_control) { | 256 if (has_control) { |
| 221 *current_input++ = graph()->start(); | 257 *current_input++ = graph()->start(); |
| 222 } | 258 } |
| 223 result = graph()->NewNode(op, input_count_with_deps, buffer, incomplete); | 259 result = graph()->NewNode(op, input_count_with_deps, buffer); |
| 224 if (has_effect) { | 260 if (has_effect) { |
| 225 effect_ = result; | 261 effect_ = result; |
| 226 } | 262 } |
| 227 // This graph builder does not support control flow. | 263 // This graph builder does not support control flow. |
| 228 CHECK_EQ(0, op->ControlOutputCount()); | 264 CHECK_EQ(0, op->ControlOutputCount()); |
| 229 } | 265 } |
| 230 | 266 |
| 231 return result; | 267 return result; |
| 232 } | 268 } |
| 233 | 269 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 256 Node* return_; | 292 Node* return_; |
| 257 Node** parameters_; | 293 Node** parameters_; |
| 258 MaybeHandle<Code> code_; | 294 MaybeHandle<Code> code_; |
| 259 }; | 295 }; |
| 260 | 296 |
| 261 } // namespace compiler | 297 } // namespace compiler |
| 262 } // namespace internal | 298 } // namespace internal |
| 263 } // namespace v8 | 299 } // namespace v8 |
| 264 | 300 |
| 265 #endif // V8_CCTEST_COMPILER_GRAPH_BUILDER_TESTER_H_ | 301 #endif // V8_CCTEST_COMPILER_GRAPH_BUILDER_TESTER_H_ |
| OLD | NEW |