michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- michael@0: * vim: set ts=8 sts=4 et sw=4 tw=99: michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef jit_UnreachableCodeElimination_h michael@0: #define jit_UnreachableCodeElimination_h michael@0: michael@0: #include "jit/MIRGraph.h" michael@0: michael@0: namespace js { michael@0: namespace jit { michael@0: michael@0: class MIRGraph; michael@0: michael@0: class UnreachableCodeElimination michael@0: { michael@0: typedef Vector BlockList; michael@0: michael@0: MIRGenerator *mir_; michael@0: MIRGraph &graph_; michael@0: uint32_t marked_; michael@0: bool redundantPhis_; michael@0: bool rerunAliasAnalysis_; michael@0: bool disableAliasAnalysis_; michael@0: michael@0: bool prunePointlessBranchesAndMarkReachableBlocks(); michael@0: void checkDependencyAndRemoveUsesFromUnmarkedBlocks(MDefinition *instr); michael@0: bool removeUnmarkedBlocksAndClearDominators(); michael@0: bool removeUnmarkedBlocksAndCleanup(); michael@0: michael@0: bool enqueue(MBasicBlock *block, BlockList &list); michael@0: MBasicBlock *optimizableSuccessor(MBasicBlock *block); michael@0: michael@0: public: michael@0: UnreachableCodeElimination(MIRGenerator *mir, MIRGraph &graph) michael@0: : mir_(mir), michael@0: graph_(graph), michael@0: marked_(0), michael@0: redundantPhis_(false), michael@0: rerunAliasAnalysis_(false), michael@0: disableAliasAnalysis_(false) michael@0: {} michael@0: michael@0: // Walks the graph and discovers what is reachable. Removes everything else. michael@0: bool analyze(); michael@0: michael@0: // Removes any blocks that are not marked. Assumes that these blocks are not michael@0: // reachable. The parameter |marked| should be the number of blocks that michael@0: // are marked. michael@0: bool removeUnmarkedBlocks(size_t marked); michael@0: michael@0: // Call this function to prevent alias analysis to run a second time if we michael@0: // do not need it. michael@0: void disableAliasAnalysis() { michael@0: disableAliasAnalysis_ = true; michael@0: } michael@0: }; michael@0: michael@0: } /* namespace jit */ michael@0: } /* namespace js */ michael@0: michael@0: #endif /* jit_UnreachableCodeElimination_h */