# HG changeset patch # User Roland Schatz # Date 1362057324 -3600 # Node ID ea1c2bed2bfa5fc783a2b2e41160239607c6cef7 # Parent 0c76156918129f291026b1d8cb0e50ca9344e2da Common superclass for RegisterValue, StackSlot and Variable. diff -r 0c7615691812 -r ea1c2bed2bfa graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/AllocatableValue.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/AllocatableValue.java Thu Feb 28 14:15:24 2013 +0100 @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2013, 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.api.code; + +import com.oracle.graal.api.meta.*; + +/** + * Common base class for values that can be manipulated by the register allocator. + */ +public abstract class AllocatableValue extends Value { + + private static final long serialVersionUID = 153019506717492133L; + + /** + * Marker to tell the register allocator that no storage location needs to be allocated for this + * value. + */ + @SuppressWarnings("serial") public static final AllocatableValue UNUSED = new AllocatableValue(Kind.Illegal) { + + @Override + public String toString() { + return "-"; + } + }; + + public AllocatableValue(Kind kind) { + super(kind); + } + +} diff -r 0c7615691812 -r ea1c2bed2bfa graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/RegisterValue.java --- a/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/RegisterValue.java Thu Feb 28 14:15:24 2013 +0100 +++ b/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/RegisterValue.java Thu Feb 28 14:15:24 2013 +0100 @@ -30,7 +30,7 @@ * {@link Register#asValue(Kind)} to retrieve the canonical {@link RegisterValue} instance for a * given (register,kind) pair. */ -public final class RegisterValue extends Value { +public final class RegisterValue extends AllocatableValue { private static final long serialVersionUID = 7999341472196897163L; diff -r 0c7615691812 -r ea1c2bed2bfa graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/StackSlot.java --- a/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/StackSlot.java Thu Feb 28 14:15:24 2013 +0100 +++ b/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/StackSlot.java Thu Feb 28 14:15:24 2013 +0100 @@ -30,7 +30,7 @@ * Represents a compiler spill slot or an outgoing stack-based argument in a method's frame or an * incoming stack-based argument in a method's {@linkplain #isInCallerFrame() caller's frame}. */ -public final class StackSlot extends Value { +public final class StackSlot extends AllocatableValue { private static final long serialVersionUID = -7725071921307318433L; diff -r 0c7615691812 -r ea1c2bed2bfa graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/ValueUtil.java --- a/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/ValueUtil.java Thu Feb 28 14:15:24 2013 +0100 +++ b/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/ValueUtil.java Thu Feb 28 14:15:24 2013 +0100 @@ -58,6 +58,16 @@ return (Constant) value; } + public static boolean isAllocatableValue(Value value) { + assert value != null; + return value instanceof AllocatableValue; + } + + public static AllocatableValue asAllocatableValue(Value value) { + assert value != null; + return (AllocatableValue) value; + } + public static boolean isStackSlot(Value value) { assert value != null; return value instanceof StackSlot; diff -r 0c7615691812 -r ea1c2bed2bfa graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/gen/LIRGenerator.java --- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/gen/LIRGenerator.java Thu Feb 28 14:15:24 2013 +0100 +++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/gen/LIRGenerator.java Thu Feb 28 14:15:24 2013 +0100 @@ -193,6 +193,14 @@ @Override public abstract Variable emitMove(Value input); + public AllocatableValue asAllocatable(Value value) { + if (isAllocatableValue(value)) { + return asAllocatableValue(value); + } else { + return emitMove(value); + } + } + public Variable load(Value value) { if (!isVariable(value)) { return emitMove(value); diff -r 0c7615691812 -r ea1c2bed2bfa graal/com.oracle.graal.lir/src/com/oracle/graal/lir/LIRInstruction.java --- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/LIRInstruction.java Thu Feb 28 14:15:24 2013 +0100 +++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/LIRInstruction.java Thu Feb 28 14:15:24 2013 +0100 @@ -181,6 +181,11 @@ ILLEGAL, /** + * The value can be {@link AllocatableValue#UNUSED}. + */ + UNUSED, + + /** * The register allocator should try to assign a certain register to improve code quality. * Use {@link LIRInstruction#forEachRegisterHint} to access the register hints. */ diff -r 0c7615691812 -r ea1c2bed2bfa graal/com.oracle.graal.lir/src/com/oracle/graal/lir/LIRVerifier.java --- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/LIRVerifier.java Thu Feb 28 14:15:24 2013 +0100 +++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/LIRVerifier.java Thu Feb 28 14:15:24 2013 +0100 @@ -232,7 +232,8 @@ private static Value allowed(Object op, Value value, OperandMode mode, EnumSet flags) { if ((isVariable(value) && flags.contains(OperandFlag.REG)) || (isRegister(value) && flags.contains(OperandFlag.REG)) || (isStackSlot(value) && flags.contains(OperandFlag.STACK)) || - (isConstant(value) && flags.contains(OperandFlag.CONST) && mode != OperandMode.DEF) || (isIllegal(value) && flags.contains(OperandFlag.ILLEGAL))) { + (isConstant(value) && flags.contains(OperandFlag.CONST) && mode != OperandMode.DEF) || (isIllegal(value) && flags.contains(OperandFlag.ILLEGAL)) || + (value == AllocatableValue.UNUSED && flags.contains(OperandFlag.UNUSED))) { return value; } TTY.println("instruction %s", op); diff -r 0c7615691812 -r ea1c2bed2bfa graal/com.oracle.graal.lir/src/com/oracle/graal/lir/Variable.java --- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/Variable.java Thu Feb 28 14:15:24 2013 +0100 +++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/Variable.java Thu Feb 28 14:15:24 2013 +0100 @@ -29,7 +29,7 @@ * Represents a value that is yet to be bound to a machine location (such as a {@link RegisterValue} * or {@link StackSlot}) by a register allocator. */ -public final class Variable extends Value { +public final class Variable extends AllocatableValue { private static final long serialVersionUID = 4507578431686109809L;