OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 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 #include <vector> | 5 #include <vector> |
6 | 6 |
7 #include "src/v8.h" | 7 #include "src/v8.h" |
8 | 8 |
9 #include "graph-tester.h" | 9 #include "graph-tester.h" |
10 #include "src/compiler/common-operator.h" | 10 #include "src/compiler/common-operator.h" |
11 #include "src/compiler/graph.h" | 11 #include "src/compiler/graph.h" |
12 #include "src/compiler/graph-inl.h" | |
13 #include "src/compiler/graph-visualizer.h" | 12 #include "src/compiler/graph-visualizer.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" |
16 | 15 |
17 using namespace v8::internal; | 16 using namespace v8::internal; |
18 using namespace v8::internal::compiler; | 17 using namespace v8::internal::compiler; |
19 | 18 |
20 static Operator dummy_operator(IrOpcode::kParameter, Operator::kNoWrite, | 19 static Operator dummy_operator(IrOpcode::kParameter, Operator::kNoWrite, |
21 "dummy", 0, 0, 0, 1, 0, 0); | 20 "dummy", 0, 0, 0, 1, 0, 0); |
22 | 21 |
23 class PreNodeVisitor : public NullNodeVisitor { | |
24 public: | |
25 void Pre(Node* node) { | |
26 printf("NODE ID: %d\n", node->id()); | |
27 nodes_.push_back(node); | |
28 } | |
29 std::vector<Node*> nodes_; | |
30 }; | |
31 | |
32 | |
33 class PostNodeVisitor : public NullNodeVisitor { | |
34 public: | |
35 void Post(Node* node) { | |
36 printf("NODE ID: %d\n", node->id()); | |
37 nodes_.push_back(node); | |
38 } | |
39 std::vector<Node*> nodes_; | |
40 }; | |
41 | |
42 | |
43 TEST(TestInputNodePreOrderVisitSimple) { | |
44 GraphWithStartNodeTester graph; | |
45 Node* n2 = graph.NewNode(&dummy_operator, graph.start()); | |
46 Node* n3 = graph.NewNode(&dummy_operator, n2); | |
47 Node* n4 = graph.NewNode(&dummy_operator, n2, n3); | |
48 Node* n5 = graph.NewNode(&dummy_operator, n4, n2); | |
49 graph.SetEnd(n5); | |
50 | |
51 PreNodeVisitor node_visitor; | |
52 graph.VisitNodeInputsFromEnd(&node_visitor); | |
53 CHECK_EQ(5, static_cast<int>(node_visitor.nodes_.size())); | |
54 CHECK(n5->id() == node_visitor.nodes_[0]->id()); | |
55 CHECK(n4->id() == node_visitor.nodes_[1]->id()); | |
56 CHECK(n2->id() == node_visitor.nodes_[2]->id()); | |
57 CHECK(graph.start()->id() == node_visitor.nodes_[3]->id()); | |
58 CHECK(n3->id() == node_visitor.nodes_[4]->id()); | |
59 } | |
60 | |
61 | |
62 TEST(TestPrintNodeGraphToNodeGraphviz) { | 22 TEST(TestPrintNodeGraphToNodeGraphviz) { |
63 GraphWithStartNodeTester graph; | 23 GraphWithStartNodeTester graph; |
64 Node* n2 = graph.NewNode(&dummy_operator, graph.start()); | 24 Node* n2 = graph.NewNode(&dummy_operator, graph.start()); |
65 Node* n3 = graph.NewNode(&dummy_operator, graph.start()); | 25 Node* n3 = graph.NewNode(&dummy_operator, graph.start()); |
66 Node* n4 = graph.NewNode(&dummy_operator, n2); | 26 Node* n4 = graph.NewNode(&dummy_operator, n2); |
67 Node* n5 = graph.NewNode(&dummy_operator, n2); | 27 Node* n5 = graph.NewNode(&dummy_operator, n2); |
68 Node* n6 = graph.NewNode(&dummy_operator, n3); | 28 Node* n6 = graph.NewNode(&dummy_operator, n3); |
69 Node* n7 = graph.NewNode(&dummy_operator, n3); | 29 Node* n7 = graph.NewNode(&dummy_operator, n3); |
70 Node* n8 = graph.NewNode(&dummy_operator, n5); | 30 Node* n8 = graph.NewNode(&dummy_operator, n5); |
71 Node* n9 = graph.NewNode(&dummy_operator, n5); | 31 Node* n9 = graph.NewNode(&dummy_operator, n5); |
72 Node* n10 = graph.NewNode(&dummy_operator, n9); | 32 Node* n10 = graph.NewNode(&dummy_operator, n9); |
73 Node* n11 = graph.NewNode(&dummy_operator, n9); | 33 Node* n11 = graph.NewNode(&dummy_operator, n9); |
74 Node* end_dependencies[6] = {n4, n8, n10, n11, n6, n7}; | 34 Node* end_dependencies[6] = {n4, n8, n10, n11, n6, n7}; |
75 Node* n12 = graph.NewNode(&dummy_operator, 6, end_dependencies); | 35 Node* n12 = graph.NewNode(&dummy_operator, 6, end_dependencies); |
76 graph.SetEnd(n12); | 36 graph.SetEnd(n12); |
77 | 37 |
78 OFStream os(stdout); | 38 OFStream os(stdout); |
79 os << AsDOT(graph); | 39 os << AsDOT(graph); |
80 } | 40 } |
OLD | NEW |