コード例 #1
0
bool
UnreachableCodeElimination::removeUnmarkedBlocksAndClearDominators()
{
    // Removes blocks that are not marked from the graph.  For blocks
    // that *are* marked, clears the mark and adjusts the id to its
    // new value.  Also adds blocks that are immediately reachable
    // from an unmarked block to the frontier.

    size_t id = marked_;
    for (PostorderIterator iter(graph_.poBegin()); iter != graph_.poEnd();) {
        if (mir_->shouldCancel("Eliminate Unreachable Code"))
            return false;

        MBasicBlock *block = *iter;
        iter++;

        // Unconditionally clear the dominators.  It's somewhat complex to
        // adjust the values and relatively fast to just recompute.
        block->clearDominatorInfo();

        if (block->isMarked()) {
            block->setId(--id);
            for (MPhiIterator iter(block->phisBegin()); iter != block->phisEnd(); iter++)
                checkDependencyAndRemoveUsesFromUnmarkedBlocks(*iter);
            for (MInstructionIterator iter(block->begin()); iter != block->end(); iter++)
                checkDependencyAndRemoveUsesFromUnmarkedBlocks(*iter);
        } else {
            for (size_t i = 0, c = block->numSuccessors(); i < c; i++) {
                MBasicBlock *succ = block->getSuccessor(i);
                if (succ->isMarked()) {
                    // succ is on the frontier of blocks to be removed:
                    succ->removePredecessor(block);

                    if (!redundantPhis_) {
                        for (MPhiIterator iter(succ->phisBegin()); iter != succ->phisEnd(); iter++) {
                            if (iter->operandIfRedundant()) {
                                redundantPhis_ = true;
                                break;
                            }
                        }
                    }
                }
            }

            graph_.removeBlock(block);
        }
    }

    JS_ASSERT(id == 0);

    return true;
}
コード例 #2
0
bool
MIRGraph::removeSuccessorBlocks(MBasicBlock* start)
{
    if (!start->hasLastIns())
        return true;

    start->mark();

    // Mark all successors.
    Vector<MBasicBlock*, 4, SystemAllocPolicy> blocks;
    for (size_t i = 0; i < start->numSuccessors(); i++) {
        if (start->getSuccessor(i)->isMarked())
            continue;
        if (!blocks.append(start->getSuccessor(i)))
            return false;
        start->getSuccessor(i)->mark();
    }
    for (size_t i = 0; i < blocks.length(); i++) {
        MBasicBlock* block = blocks[i];
        if (!block->hasLastIns())
            continue;

        for (size_t j = 0; j < block->numSuccessors(); j++) {
            if (block->getSuccessor(j)->isMarked())
                continue;
            if (!blocks.append(block->getSuccessor(j)))
                return false;
            block->getSuccessor(j)->mark();
        }
    }

    if (osrBlock()) {
        if (osrBlock()->getSuccessor(0)->isMarked())
            osrBlock()->mark();
    }

    // Remove blocks.
    // If they don't have any predecessor
    for (size_t i = 0; i < blocks.length(); i++) {
        MBasicBlock* block = blocks[i];
        bool allMarked = true;
        for (size_t i = 0; i < block->numPredecessors(); i++) {
            if (block->getPredecessor(i)->isMarked())
                continue;
            allMarked = false;
            break;
        }
        if (allMarked) {
            removeBlock(block);
        } else {
            MOZ_ASSERT(block != osrBlock());
            for (size_t j = 0; j < block->numPredecessors(); ) {
                if (!block->getPredecessor(j)->isMarked()) {
                    j++;
                    continue;
                }
                block->removePredecessor(block->getPredecessor(j));
            }
            // This shouldn't have any instructions yet.
            MOZ_ASSERT(block->begin() == block->end());
        }
    }

    if (osrBlock()) {
        if (osrBlock()->getSuccessor(0)->isDead())
            removeBlock(osrBlock());
    }

    for (size_t i = 0; i < blocks.length(); i++)
        blocks[i]->unmark();
    start->unmark();

    return true;
}
コード例 #3
0
bool
UnreachableCodeElimination::removeUnmarkedBlocksAndClearDominators()
{
    // Removes blocks that are not marked from the graph.  For blocks
    // that *are* marked, clears the mark and adjusts the id to its
    // new value.  Also adds blocks that are immediately reachable
    // from an unmarked block to the frontier.

    size_t id = marked_;
    for (PostorderIterator iter(graph_.poBegin()); iter != graph_.poEnd();) {
        if (mir_->shouldCancel("Eliminate Unreachable Code"))
            return false;

        MBasicBlock *block = *iter;
        iter++;

        // Unconditionally clear the dominators.  It's somewhat complex to
        // adjust the values and relatively fast to just recompute.
        block->clearDominatorInfo();

        if (block->isMarked()) {
            block->setId(--id);
            for (MPhiIterator iter(block->phisBegin()); iter != block->phisEnd(); iter++)
                checkDependencyAndRemoveUsesFromUnmarkedBlocks(*iter);
            for (MInstructionIterator iter(block->begin()); iter != block->end(); iter++)
                checkDependencyAndRemoveUsesFromUnmarkedBlocks(*iter);
        } else {
            if (block->numPredecessors() > 1) {
                // If this block had phis, then any reachable
                // predecessors need to have the successorWithPhis
                // flag cleared.
                for (size_t i = 0; i < block->numPredecessors(); i++)
                    block->getPredecessor(i)->setSuccessorWithPhis(nullptr, 0);
            }

            if (block->isLoopBackedge()) {
                // NB. We have to update the loop header if we
                // eliminate the backedge. At first I thought this
                // check would be insufficient, because it would be
                // possible to have code like this:
                //
                //    while (true) {
                //       ...;
                //       if (1 == 1) break;
                //    }
                //
                // in which the backedge is removed as part of
                // rewriting the condition, but no actual blocks are
                // removed.  However, in all such cases, the backedge
                // would be a critical edge and hence the critical
                // edge block is being removed.
                block->loopHeaderOfBackedge()->clearLoopHeader();
            }

            for (size_t i = 0, c = block->numSuccessors(); i < c; i++) {
                MBasicBlock *succ = block->getSuccessor(i);
                if (succ->isMarked()) {
                    // succ is on the frontier of blocks to be removed:
                    succ->removePredecessor(block);

                    if (!redundantPhis_) {
                        for (MPhiIterator iter(succ->phisBegin()); iter != succ->phisEnd(); iter++) {
                            if (iter->operandIfRedundant()) {
                                redundantPhis_ = true;
                                break;
                            }
                        }
                    }
                }
            }

            // When we remove a call, we can't leave the corresponding MPassArg
            // in the graph. Since lowering will fail. Replace it with the
            // argument for the exceptional case when it is kept alive in a
            // ResumePoint. DCE will remove the unused MPassArg instruction.
            for (MInstructionIterator iter(block->begin()); iter != block->end(); iter++) {
                if (iter->isCall()) {
                    MCall *call = iter->toCall();
                    for (size_t i = 0; i < call->numStackArgs(); i++) {
                        JS_ASSERT(call->getArg(i)->isPassArg());
                        JS_ASSERT(call->getArg(i)->hasOneDefUse());
                        MPassArg *arg = call->getArg(i)->toPassArg();
                        arg->replaceAllUsesWith(arg->getArgument());
                    }
                }
            }

            graph_.removeBlock(block);
        }
    }

    JS_ASSERT(id == 0);

    return true;
}