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