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