001/* 002 * Copyright (c) 2013, 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.*; 026import static jdk.internal.jvmci.code.ValueUtil.*; 027 028import java.util.*; 029 030import jdk.internal.jvmci.meta.*; 031 032import com.oracle.graal.asm.sparc.*; 033import com.oracle.graal.lir.*; 034import com.oracle.graal.lir.LIRInstruction.OperandFlag; 035import com.oracle.graal.lir.LIRInstruction.OperandMode; 036 037public final class SPARCIndexedAddressValue extends SPARCAddressValue { 038 039 @Component({REG}) protected AllocatableValue base; 040 @Component({REG}) protected AllocatableValue index; 041 042 private static final EnumSet<OperandFlag> flags = EnumSet.of(OperandFlag.REG); 043 044 public SPARCIndexedAddressValue(LIRKind kind, AllocatableValue base, AllocatableValue index) { 045 super(kind); 046 this.base = base; 047 this.index = index; 048 } 049 050 @Override 051 public CompositeValue forEachComponent(LIRInstruction inst, OperandMode mode, InstructionValueProcedure proc) { 052 AllocatableValue newBase = (AllocatableValue) proc.doValue(inst, base, mode, flags); 053 AllocatableValue newIndex = (AllocatableValue) proc.doValue(inst, index, mode, flags); 054 if (!base.identityEquals(newBase) || !index.identityEquals(newIndex)) { 055 return new SPARCIndexedAddressValue(getLIRKind(), newBase, newIndex); 056 } 057 return this; 058 } 059 060 @Override 061 protected void forEachComponent(LIRInstruction inst, OperandMode mode, InstructionValueConsumer proc) { 062 proc.visitValue(inst, base, mode, flags); 063 proc.visitValue(inst, index, mode, flags); 064 } 065 066 @Override 067 public SPARCAddress toAddress() { 068 return new SPARCAddress(asRegister(base), asRegister(index)); 069 } 070 071 @Override 072 public boolean isValidImplicitNullCheckFor(Value value, int implicitNullCheckLimit) { 073 return false; 074 } 075 076 @Override 077 public String toString() { 078 StringBuilder s = new StringBuilder("["); 079 String sep = ""; 080 if (isLegal(base)) { 081 s.append(base); 082 sep = " + "; 083 } 084 if (isLegal(index)) { 085 s.append(sep).append(index); 086 } 087 s.append("]"); 088 return s.toString(); 089 } 090 091 @Override 092 public boolean equals(Object obj) { 093 if (obj instanceof SPARCIndexedAddressValue) { 094 SPARCIndexedAddressValue addr = (SPARCIndexedAddressValue) obj; 095 return getLIRKind().equals(addr.getLIRKind()) && base.equals(addr.base) && index.equals(addr.index); 096 } 097 return false; 098 } 099 100 @Override 101 public int hashCode() { 102 return base.hashCode() ^ index.hashCode() ^ getLIRKind().hashCode(); 103 } 104}