1 /* 2 * Copyright (c) 2015, 2015, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 package org.graalvm.compiler.lir.alloc.trace; 24 25 import static org.graalvm.compiler.lir.LIRInstruction.OperandFlag.REG; 26 import static org.graalvm.compiler.lir.LIRInstruction.OperandFlag.STACK; 27 28 import java.util.EnumSet; 29 30 import org.graalvm.compiler.lir.CompositeValue; 31 import org.graalvm.compiler.lir.InstructionValueConsumer; 32 import org.graalvm.compiler.lir.InstructionValueProcedure; 33 import org.graalvm.compiler.lir.LIRInstruction; 34 import org.graalvm.compiler.lir.LIRInstruction.OperandFlag; 35 import org.graalvm.compiler.lir.LIRInstruction.OperandMode; 36 37 import jdk.vm.ci.code.RegisterValue; 38 import jdk.vm.ci.meta.AllocatableValue; 39 40 /** 41 * Represents a {@link #register} which has a shadow copy on the {@link #stackslot stack}. 42 */ 43 public final class ShadowedRegisterValue extends CompositeValue { 44 private static final EnumSet<OperandFlag> registerFlags = EnumSet.of(REG); 45 private static final EnumSet<OperandFlag> stackslotFlags = EnumSet.of(STACK); 46 47 @Component({REG}) protected RegisterValue register; 48 @Component({STACK}) protected AllocatableValue stackslot; 49 50 public ShadowedRegisterValue(RegisterValue register, AllocatableValue stackslot) { 51 super(register.getValueKind()); 52 assert (register.getValueKind().equals(stackslot.getValueKind())); 53 this.register = register; 54 this.stackslot = stackslot; 55 } 56 57 public RegisterValue getRegister() { 58 return register; 59 } 60 61 public AllocatableValue getStackSlot() { 62 return stackslot; 63 } 64 65 @Override 66 public CompositeValue forEachComponent(LIRInstruction inst, OperandMode mode, InstructionValueProcedure proc) { 67 RegisterValue newRegister = (RegisterValue) proc.doValue(inst, register, mode, registerFlags); 68 AllocatableValue newStackSlot = (AllocatableValue) proc.doValue(inst, stackslot, mode, stackslotFlags); 69 if (register.equals(newRegister) || stackslot.equals(newStackSlot)) { 70 return this; 71 } 72 return new ShadowedRegisterValue(newRegister, newStackSlot); 73 } 74 75 @Override 76 protected void visitEachComponent(LIRInstruction inst, OperandMode mode, InstructionValueConsumer proc) { 77 proc.visitValue(inst, register, mode, registerFlags); 78 proc.visitValue(inst, stackslot, mode, stackslotFlags); 79 } 80 81 @Override 82 public boolean equals(Object obj) { 83 if (obj == null) { 84 return false; 85 } 86 if (this == obj) { 87 return true; 88 } 89 if (getClass() != obj.getClass()) { 90 return false; 91 } 92 ShadowedRegisterValue other = (ShadowedRegisterValue) obj; 93 assert register != null; 94 assert stackslot != null; 95 assert other.register != null; 96 assert other.stackslot != null; 97 if (!register.equals(other.register)) { 98 return false; 99 } 100 if (!stackslot.equals(other.stackslot)) { 101 return false; 102 } 103 return true; 104 } 105 106 }