• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2015 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef V8_COMPILER_GRAPH_TRIMMER_H_
6 #define V8_COMPILER_GRAPH_TRIMMER_H_
7 
8 #include "src/compiler/node-marker.h"
9 
10 namespace v8 {
11 namespace internal {
12 namespace compiler {
13 
14 // Forward declarations.
15 class Graph;
16 
17 
18 // Trims dead nodes from the node graph.
19 class GraphTrimmer final {
20  public:
21   GraphTrimmer(Zone* zone, Graph* graph);
22   ~GraphTrimmer();
23 
24   // Trim nodes in the {graph} that are not reachable from {graph->end()}.
25   void TrimGraph();
26 
27   // Trim nodes in the {graph} that are not reachable from either {graph->end()}
28   // or any of the roots in the sequence [{begin},{end}[.
29   template <typename ForwardIterator>
TrimGraph(ForwardIterator begin,ForwardIterator end)30   void TrimGraph(ForwardIterator begin, ForwardIterator end) {
31     while (begin != end) MarkAsLive(*begin++);
32     TrimGraph();
33   }
34 
35  private:
IsLive(Node * const node)36   V8_INLINE bool IsLive(Node* const node) { return is_live_.Get(node); }
MarkAsLive(Node * const node)37   V8_INLINE void MarkAsLive(Node* const node) {
38     if (!node->IsDead() && !IsLive(node)) {
39       is_live_.Set(node, true);
40       live_.push_back(node);
41     }
42   }
43 
graph()44   Graph* graph() const { return graph_; }
45 
46   Graph* const graph_;
47   NodeMarker<bool> is_live_;
48   NodeVector live_;
49 
50   DISALLOW_COPY_AND_ASSIGN(GraphTrimmer);
51 };
52 
53 }  // namespace compiler
54 }  // namespace internal
55 }  // namespace v8
56 
57 #endif  // V8_COMPILER_GRAPH_TRIMMER_H_
58