Mercurial > hg > graal-compiler
changeset 22972:0ce3d7818862
Add AllocationStageVerifier.
author | Josef Eisl <josef.eisl@jku.at> |
---|---|
date | Wed, 11 Nov 2015 11:06:55 +0100 |
parents | 6c37ffb6887b |
children | ec3bc5aad543 |
files | graal/com.oracle.graal.lir/src/com/oracle/graal/lir/alloc/AllocationStageVerifier.java graal/com.oracle.graal.lir/src/com/oracle/graal/lir/phases/AllocationStage.java |
diffstat | 2 files changed, 91 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/alloc/AllocationStageVerifier.java Wed Nov 11 11:06:55 2015 +0100 @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.graal.lir.alloc; + +import static com.oracle.graal.lir.LIRValueUtil.isVariable; +import static com.oracle.graal.lir.LIRValueUtil.isVirtualStackSlot; + +import java.util.EnumSet; +import java.util.List; + +import jdk.vm.ci.code.TargetDescription; +import jdk.vm.ci.meta.Value; + +import com.oracle.graal.compiler.common.alloc.RegisterAllocationConfig; +import com.oracle.graal.compiler.common.cfg.AbstractBlockBase; +import com.oracle.graal.lir.LIR; +import com.oracle.graal.lir.LIRInstruction; +import com.oracle.graal.lir.LIRInstruction.OperandFlag; +import com.oracle.graal.lir.LIRInstruction.OperandMode; +import com.oracle.graal.lir.gen.LIRGenerationResult; +import com.oracle.graal.lir.gen.LIRGeneratorTool.MoveFactory; +import com.oracle.graal.lir.phases.AllocationPhase; + +/** + * Verifies that all virtual operands have been replaced by concrete values. + */ +public class AllocationStageVerifier extends AllocationPhase { + + @Override + protected <B extends AbstractBlockBase<B>> void run(TargetDescription target, LIRGenerationResult lirGenRes, List<B> codeEmittingOrder, List<B> linearScanOrder, MoveFactory spillMoveFactory, + RegisterAllocationConfig registerAllocationConfig) { + verifyLIR(lirGenRes.getLIR()); + + } + + protected void verifyLIR(LIR lir) { + for (AbstractBlockBase<?> block : (List<? extends AbstractBlockBase<?>>) lir.getControlFlowGraph().getBlocks()) { + verifyBlock(lir, block); + } + } + + protected void verifyBlock(LIR lir, AbstractBlockBase<?> block) { + for (LIRInstruction inst : lir.getLIRforBlock(block)) { + verifyInstruction(inst); + } + } + + protected void verifyInstruction(LIRInstruction inst) { + inst.visitEachInput(this::verifyOperands); + inst.visitEachOutput(this::verifyOperands); + inst.visitEachAlive(this::verifyOperands); + inst.visitEachTemp(this::verifyOperands); + } + + /** + * @param instruction + * @param value + * @param mode + * @param flags + */ + protected void verifyOperands(LIRInstruction instruction, Value value, OperandMode mode, EnumSet<OperandFlag> flags) { + assert !isVirtualStackSlot(value) && !isVariable(value) : "Virtual values not allowed after allocation stage: " + value; + } + +}
--- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/phases/AllocationStage.java Wed Nov 11 17:14:06 2015 +0100 +++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/phases/AllocationStage.java Wed Nov 11 11:06:55 2015 +0100 @@ -24,6 +24,8 @@ import static com.oracle.graal.compiler.common.BackendOptions.UserOptions.TraceRA; +import com.oracle.graal.compiler.common.GraalOptions; +import com.oracle.graal.lir.alloc.AllocationStageVerifier; import com.oracle.graal.lir.alloc.lsra.LinearScanPhase; import com.oracle.graal.lir.alloc.trace.TraceRegisterAllocationPhase; import com.oracle.graal.lir.dfa.LocationMarkerPhase; @@ -49,5 +51,9 @@ } // currently we mark locations only if we do register allocation appendPhase(new LocationMarkerPhase()); + + if (GraalOptions.DetailedAsserts.getValue()) { + appendPhase(new AllocationStageVerifier()); + } } }