js/src/jit/UnreachableCodeElimination.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/jit/UnreachableCodeElimination.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,64 @@
     1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
     1.5 + * vim: set ts=8 sts=4 et sw=4 tw=99:
     1.6 + * This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +#ifndef jit_UnreachableCodeElimination_h
    1.11 +#define jit_UnreachableCodeElimination_h
    1.12 +
    1.13 +#include "jit/MIRGraph.h"
    1.14 +
    1.15 +namespace js {
    1.16 +namespace jit {
    1.17 +
    1.18 +class MIRGraph;
    1.19 +
    1.20 +class UnreachableCodeElimination
    1.21 +{
    1.22 +    typedef Vector<MBasicBlock *, 16, SystemAllocPolicy> BlockList;
    1.23 +
    1.24 +    MIRGenerator *mir_;
    1.25 +    MIRGraph &graph_;
    1.26 +    uint32_t marked_;
    1.27 +    bool redundantPhis_;
    1.28 +    bool rerunAliasAnalysis_;
    1.29 +    bool disableAliasAnalysis_;
    1.30 +
    1.31 +    bool prunePointlessBranchesAndMarkReachableBlocks();
    1.32 +    void checkDependencyAndRemoveUsesFromUnmarkedBlocks(MDefinition *instr);
    1.33 +    bool removeUnmarkedBlocksAndClearDominators();
    1.34 +    bool removeUnmarkedBlocksAndCleanup();
    1.35 +
    1.36 +    bool enqueue(MBasicBlock *block, BlockList &list);
    1.37 +    MBasicBlock *optimizableSuccessor(MBasicBlock *block);
    1.38 +
    1.39 +  public:
    1.40 +    UnreachableCodeElimination(MIRGenerator *mir, MIRGraph &graph)
    1.41 +      : mir_(mir),
    1.42 +        graph_(graph),
    1.43 +        marked_(0),
    1.44 +        redundantPhis_(false),
    1.45 +        rerunAliasAnalysis_(false),
    1.46 +        disableAliasAnalysis_(false)
    1.47 +    {}
    1.48 +
    1.49 +    // Walks the graph and discovers what is reachable. Removes everything else.
    1.50 +    bool analyze();
    1.51 +
    1.52 +    // Removes any blocks that are not marked.  Assumes that these blocks are not
    1.53 +    // reachable.  The parameter |marked| should be the number of blocks that
    1.54 +    // are marked.
    1.55 +    bool removeUnmarkedBlocks(size_t marked);
    1.56 +
    1.57 +    // Call this function to prevent alias analysis to run a second time if we
    1.58 +    // do not need it.
    1.59 +    void disableAliasAnalysis() {
    1.60 +        disableAliasAnalysis_ = true;
    1.61 +    }
    1.62 +};
    1.63 +
    1.64 +} /* namespace jit */
    1.65 +} /* namespace js */
    1.66 +
    1.67 +#endif /* jit_UnreachableCodeElimination_h */

mercurial