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_CONTROL_FLOW_OPTIMIZER_H_
6 #define V8_COMPILER_CONTROL_FLOW_OPTIMIZER_H_
7 
8 #include "src/compiler/node-marker.h"
9 #include "src/globals.h"
10 #include "src/zone/zone-containers.h"
11 
12 namespace v8 {
13 namespace internal {
14 namespace compiler {
15 
16 // Forward declarations.
17 class CommonOperatorBuilder;
18 class Graph;
19 class MachineOperatorBuilder;
20 class Node;
21 
22 class V8_EXPORT_PRIVATE ControlFlowOptimizer final {
23  public:
24   ControlFlowOptimizer(Graph* graph, CommonOperatorBuilder* common,
25                        MachineOperatorBuilder* machine, Zone* zone);
26 
27   void Optimize();
28 
29  private:
30   void Enqueue(Node* node);
31   void VisitNode(Node* node);
32   void VisitBranch(Node* node);
33 
34   bool TryBuildSwitch(Node* node);
35   bool TryCloneBranch(Node* node);
36 
graph()37   Graph* graph() const { return graph_; }
common()38   CommonOperatorBuilder* common() const { return common_; }
machine()39   MachineOperatorBuilder* machine() const { return machine_; }
zone()40   Zone* zone() const { return zone_; }
41 
42   Graph* const graph_;
43   CommonOperatorBuilder* const common_;
44   MachineOperatorBuilder* const machine_;
45   ZoneQueue<Node*> queue_;
46   NodeMarker<bool> queued_;
47   Zone* const zone_;
48 
49   DISALLOW_COPY_AND_ASSIGN(ControlFlowOptimizer);
50 };
51 
52 }  // namespace compiler
53 }  // namespace internal
54 }  // namespace v8
55 
56 #endif  // V8_COMPILER_CONTROL_FLOW_OPTIMIZER_H_
57