001/*
002 * Copyright (c) 2015, 2015, Oracle and/or its affiliates. All rights reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation.
008 *
009 * This code is distributed in the hope that it will be useful, but WITHOUT
010 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
011 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
012 * version 2 for more details (a copy is included in the LICENSE file that
013 * accompanied this code).
014 *
015 * You should have received a copy of the GNU General Public License version
016 * 2 along with this work; if not, write to the Free Software Foundation,
017 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
018 *
019 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
020 * or visit www.oracle.com if you need additional information or have any
021 * questions.
022 */
023package com.oracle.graal.lir.alloc.lsra.ssa;
024
025import java.util.*;
026
027import jdk.internal.jvmci.code.*;
028
029import com.oracle.graal.debug.*;
030import com.oracle.graal.debug.Debug.*;
031import com.oracle.graal.compiler.common.alloc.*;
032import com.oracle.graal.compiler.common.cfg.*;
033import com.oracle.graal.lir.alloc.lsra.*;
034import com.oracle.graal.lir.gen.*;
035import com.oracle.graal.lir.gen.LIRGeneratorTool.SpillMoveFactory;
036import com.oracle.graal.lir.ssa.*;
037
038public final class SSALinearScan extends LinearScan {
039
040    public SSALinearScan(TargetDescription target, LIRGenerationResult res, SpillMoveFactory spillMoveFactory, RegisterAllocationConfig regAllocConfig,
041                    List<? extends AbstractBlockBase<?>> sortedBlocks) {
042        super(target, res, spillMoveFactory, regAllocConfig, sortedBlocks);
043    }
044
045    @Override
046    protected MoveResolver createMoveResolver() {
047        SSAMoveResolver moveResolver = new SSAMoveResolver(this);
048        assert moveResolver.checkEmpty();
049        return moveResolver;
050    }
051
052    @Override
053    protected LinearScanLifetimeAnalysisPhase createLifetimeAnalysisPhase() {
054        return new SSALinearScanLifetimeAnalysisPhase(this);
055    }
056
057    @Override
058    protected LinearScanResolveDataFlowPhase createResolveDataFlowPhase() {
059        return new SSALinarScanResolveDataFlowPhase(this);
060    }
061
062    @Override
063    protected LinearScanEliminateSpillMovePhase createSpillMoveEliminationPhase() {
064        return new SSALinearScanEliminateSpillMovePhase(this);
065    }
066
067    @Override
068    protected void beforeSpillMoveElimination() {
069        /*
070         * PHI Ins are needed for the RegisterVerifier, otherwise PHIs where the Out and In value
071         * matches (ie. there is no resolution move) are falsely detected as errors.
072         */
073        try (Scope s1 = Debug.scope("Remove Phi In")) {
074            for (AbstractBlockBase<?> toBlock : sortedBlocks()) {
075                if (toBlock.getPredecessorCount() > 1) {
076                    SSAUtil.removePhiIn(getLIR(), toBlock);
077                }
078            }
079        }
080    }
081
082}