package org.graalvm.compiler.lir.sparc;
import static org.graalvm.compiler.lir.LIRInstruction.OperandFlag.REG;
import static jdk.vm.ci.code.ValueUtil.asRegister;
import static jdk.vm.ci.code.ValueUtil.isLegal;
import java.util.EnumSet;
import org.graalvm.compiler.asm.sparc.SPARCAddress;
import org.graalvm.compiler.lir.CompositeValue;
import org.graalvm.compiler.lir.InstructionValueConsumer;
import org.graalvm.compiler.lir.InstructionValueProcedure;
import org.graalvm.compiler.lir.LIRInstruction;
import org.graalvm.compiler.lir.LIRInstruction.OperandFlag;
import org.graalvm.compiler.lir.LIRInstruction.OperandMode;
import jdk.vm.ci.meta.AllocatableValue;
import jdk.vm.ci.meta.Value;
import jdk.vm.ci.meta.ValueKind;
public final class SPARCIndexedAddressValue extends SPARCAddressValue {
@Component({REG}) protected AllocatableValue base;
@Component({REG}) protected AllocatableValue index;
private static final EnumSet<OperandFlag> flags = EnumSet.of(OperandFlag.REG);
public SPARCIndexedAddressValue(ValueKind<?> kind, AllocatableValue base, AllocatableValue index) {
super(kind);
this.base = base;
this.index = index;
}
@Override
public CompositeValue forEachComponent(LIRInstruction inst, OperandMode mode, InstructionValueProcedure proc) {
AllocatableValue newBase = (AllocatableValue) proc.doValue(inst, base, mode, flags);
AllocatableValue newIndex = (AllocatableValue) proc.doValue(inst, index, mode, flags);
if (!base.identityEquals(newBase) || !index.identityEquals(newIndex)) {
return new SPARCIndexedAddressValue(getValueKind(), newBase, newIndex);
}
return this;
}
@Override
protected void visitEachComponent(LIRInstruction inst, OperandMode mode, InstructionValueConsumer proc) {
proc.visitValue(inst, base, mode, flags);
proc.visitValue(inst, index, mode, flags);
}
@Override
public SPARCAddress toAddress() {
return new SPARCAddress(asRegister(base), asRegister(index));
}
@Override
public boolean isValidImplicitNullCheckFor(Value value, int implicitNullCheckLimit) {
return false;
}
@Override
public String toString() {
StringBuilder s = new StringBuilder("[");
String sep = "";
if (isLegal(base)) {
s.append(base);
sep = " + ";
}
if (isLegal(index)) {
s.append(sep).append(index);
}
s.append("]");
return s.toString();
}
@Override
public boolean equals(Object obj) {
if (obj instanceof SPARCIndexedAddressValue) {
SPARCIndexedAddressValue addr = (SPARCIndexedAddressValue) obj;
return getValueKind().equals(addr.getValueKind()) && base.equals(addr.base) && index.equals(addr.index);
}
return false;
}
@Override
public int hashCode() {
return base.hashCode() ^ index.hashCode() ^ getValueKind().hashCode();
}
}