Home | History | Annotate | Download | only in compiler
      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_DEAD_CODE_ELIMINATION_H_
      6 #define V8_COMPILER_DEAD_CODE_ELIMINATION_H_
      7 
      8 #include "src/compiler/graph-reducer.h"
      9 
     10 namespace v8 {
     11 namespace internal {
     12 namespace compiler {
     13 
     14 // Forward declarations.
     15 class CommonOperatorBuilder;
     16 
     17 
     18 // Propagates {Dead} control through the graph and thereby removes dead code.
     19 // Note that this does not include trimming dead uses from the graph, and it
     20 // also does not include detecting dead code by any other means than seeing a
     21 // {Dead} control input; that is left to other reducers.
     22 class DeadCodeElimination final : public AdvancedReducer {
     23  public:
     24   DeadCodeElimination(Editor* editor, Graph* graph,
     25                       CommonOperatorBuilder* common);
     26   ~DeadCodeElimination() final {}
     27 
     28   Reduction Reduce(Node* node) final;
     29 
     30  private:
     31   Reduction ReduceEnd(Node* node);
     32   Reduction ReduceLoopOrMerge(Node* node);
     33   Reduction ReduceNode(Node* node);
     34 
     35   void TrimMergeOrPhi(Node* node, int size);
     36 
     37   Graph* graph() const { return graph_; }
     38   CommonOperatorBuilder* common() const { return common_; }
     39   Node* dead() const { return dead_; }
     40 
     41   Graph* const graph_;
     42   CommonOperatorBuilder* const common_;
     43   Node* const dead_;
     44 
     45   DISALLOW_COPY_AND_ASSIGN(DeadCodeElimination);
     46 };
     47 
     48 }  // namespace compiler
     49 }  // namespace internal
     50 }  // namespace v8
     51 
     52 #endif  // V8_COMPILER_DEAD_CODE_ELIMINATION_H_
     53