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.sparc;
024
025import static com.oracle.graal.lir.LIRInstruction.OperandFlag.*;
026
027import com.oracle.graal.lir.*;
028import com.oracle.graal.lir.StandardOp.*;
029
030import jdk.internal.jvmci.meta.*;
031
032public abstract class SPARCBlockEndOp extends SPARCLIRInstruction implements BlockEndOp {
033    public static final LIRInstructionClass<SPARCBlockEndOp> TYPE = LIRInstructionClass.create(SPARCBlockEndOp.class);
034
035    @Alive({REG, STACK, CONST}) private Value[] outgoingValues;
036    private int size;
037
038    protected SPARCBlockEndOp(LIRInstructionClass<? extends SPARCBlockEndOp> c) {
039        this(c, null);
040    }
041
042    protected SPARCBlockEndOp(LIRInstructionClass<? extends SPARCBlockEndOp> c, SizeEstimate sizeEstimate) {
043        super(c, sizeEstimate);
044        this.outgoingValues = Value.NO_VALUES;
045        this.size = 0;
046    }
047
048    public void setOutgoingValues(Value[] values) {
049        assert outgoingValues.length == 0;
050        assert values != null;
051        outgoingValues = values;
052        size = values.length;
053    }
054
055    public int getOutgoingSize() {
056        return size;
057    }
058
059    public Value getOutgoingValue(int idx) {
060        assert checkRange(idx);
061        return outgoingValues[idx];
062    }
063
064    private boolean checkRange(int idx) {
065        return idx < size;
066    }
067
068    public void clearOutgoingValues() {
069        outgoingValues = Value.NO_VALUES;
070        size = 0;
071    }
072
073    public int addOutgoingValues(Value[] v) {
074
075        int t = size + v.length;
076        if (t >= outgoingValues.length) {
077            Value[] newArray = new Value[t];
078            System.arraycopy(outgoingValues, 0, newArray, 0, size);
079            outgoingValues = newArray;
080        }
081        System.arraycopy(v, 0, outgoingValues, size, v.length);
082        size = t;
083        return t;
084
085    }
086}