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 "src/compiler/graph-visualizer.h" | 5 #include "src/compiler/graph-visualizer.h" |
6 | 6 |
7 #include <sstream> | 7 #include <sstream> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "src/code-stubs.h" | 10 #include "src/code-stubs.h" |
| 11 #include "src/compiler/all-nodes.h" |
11 #include "src/compiler/graph.h" | 12 #include "src/compiler/graph.h" |
12 #include "src/compiler/graph-inl.h" | |
13 #include "src/compiler/node.h" | 13 #include "src/compiler/node.h" |
14 #include "src/compiler/node-properties.h" | 14 #include "src/compiler/node-properties.h" |
15 #include "src/compiler/node-properties-inl.h" | 15 #include "src/compiler/node-properties-inl.h" |
16 #include "src/compiler/opcodes.h" | 16 #include "src/compiler/opcodes.h" |
17 #include "src/compiler/operator.h" | 17 #include "src/compiler/operator.h" |
18 #include "src/compiler/register-allocator.h" | 18 #include "src/compiler/register-allocator.h" |
19 #include "src/compiler/schedule.h" | 19 #include "src/compiler/schedule.h" |
20 #include "src/compiler/scheduler.h" | 20 #include "src/compiler/scheduler.h" |
21 #include "src/ostreams.h" | 21 #include "src/ostreams.h" |
22 | 22 |
23 namespace v8 { | 23 namespace v8 { |
24 namespace internal { | 24 namespace internal { |
25 namespace compiler { | 25 namespace compiler { |
26 | 26 |
27 static int SafeId(Node* node) { return node == NULL ? -1 : node->id(); } | 27 static int SafeId(Node* node) { return node == NULL ? -1 : node->id(); } |
28 static const char* SafeMnemonic(Node* node) { | 28 static const char* SafeMnemonic(Node* node) { |
29 return node == NULL ? "null" : node->op()->mnemonic(); | 29 return node == NULL ? "null" : node->op()->mnemonic(); |
30 } | 30 } |
31 | 31 |
32 #define DEAD_COLOR "#999999" | 32 #define DEAD_COLOR "#999999" |
33 | 33 |
34 class AllNodes { | |
35 public: | |
36 enum State { kDead, kGray, kLive }; | |
37 | |
38 AllNodes(Zone* local_zone, const Graph* graph) | |
39 : state(graph->NodeCount(), kDead, local_zone), | |
40 live(local_zone), | |
41 gray(local_zone) { | |
42 Node* end = graph->end(); | |
43 state[end->id()] = kLive; | |
44 live.push_back(end); | |
45 // Find all live nodes reachable from end. | |
46 for (size_t i = 0; i < live.size(); i++) { | |
47 for (Node* const input : live[i]->inputs()) { | |
48 if (input == NULL) { | |
49 // TODO(titzer): print a warning. | |
50 continue; | |
51 } | |
52 if (input->id() >= graph->NodeCount()) { | |
53 // TODO(titzer): print a warning. | |
54 continue; | |
55 } | |
56 if (state[input->id()] != kLive) { | |
57 live.push_back(input); | |
58 state[input->id()] = kLive; | |
59 } | |
60 } | |
61 } | |
62 | |
63 // Find all nodes that are not reachable from end that use live nodes. | |
64 for (size_t i = 0; i < live.size(); i++) { | |
65 for (Node* const use : live[i]->uses()) { | |
66 if (state[use->id()] == kDead) { | |
67 gray.push_back(use); | |
68 state[use->id()] = kGray; | |
69 } | |
70 } | |
71 } | |
72 } | |
73 | |
74 bool IsLive(Node* node) { | |
75 return node != NULL && node->id() < static_cast<int>(state.size()) && | |
76 state[node->id()] == kLive; | |
77 } | |
78 | |
79 ZoneVector<State> state; | |
80 NodeVector live; | |
81 NodeVector gray; | |
82 }; | |
83 | |
84 | |
85 class Escaped { | 34 class Escaped { |
86 public: | 35 public: |
87 explicit Escaped(const std::ostringstream& os, | 36 explicit Escaped(const std::ostringstream& os, |
88 const char* escaped_chars = "<>|{}") | 37 const char* escaped_chars = "<>|{}") |
89 : str_(os.str()), escaped_chars_(escaped_chars) {} | 38 : str_(os.str()), escaped_chars_(escaped_chars) {} |
90 | 39 |
91 friend std::ostream& operator<<(std::ostream& os, const Escaped& e) { | 40 friend std::ostream& operator<<(std::ostream& os, const Escaped& e) { |
92 for (std::string::const_iterator i = e.str_.begin(); i != e.str_.end(); | 41 for (std::string::const_iterator i = e.str_.begin(); i != e.str_.end(); |
93 ++i) { | 42 ++i) { |
94 if (e.needs_escape(*i)) os << "\\"; | 43 if (e.needs_escape(*i)) os << "\\"; |
(...skipping 726 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
821 os << "#" << SafeId(i) << ":" << SafeMnemonic(i); | 770 os << "#" << SafeId(i) << ":" << SafeMnemonic(i); |
822 } | 771 } |
823 os << ")" << std::endl; | 772 os << ")" << std::endl; |
824 } | 773 } |
825 } | 774 } |
826 return os; | 775 return os; |
827 } | 776 } |
828 } | 777 } |
829 } | 778 } |
830 } // namespace v8::internal::compiler | 779 } // namespace v8::internal::compiler |
OLD | NEW |