1/* 2 * Copyright (c) 2011, 2016, 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 */ 23package org.graalvm.compiler.nodes.memory; 24 25import static org.graalvm.compiler.nodeinfo.NodeCycles.CYCLES_2; 26import static org.graalvm.compiler.nodeinfo.NodeSize.SIZE_1; 27 28import org.graalvm.compiler.core.common.type.StampFactory; 29import org.graalvm.compiler.graph.Node; 30import org.graalvm.compiler.graph.NodeClass; 31import org.graalvm.compiler.nodeinfo.InputType; 32import org.graalvm.compiler.nodeinfo.NodeInfo; 33import org.graalvm.compiler.nodes.FrameState; 34import org.graalvm.compiler.nodes.StateSplit; 35import org.graalvm.compiler.nodes.ValueNode; 36import org.graalvm.compiler.nodes.ValueNodeUtil; 37import org.graalvm.compiler.nodes.extended.GuardingNode; 38import org.graalvm.compiler.nodes.memory.address.AddressNode; 39import org.graalvm.word.LocationIdentity; 40 41@NodeInfo(allowedUsageTypes = {InputType.Memory, InputType.Guard}, cycles = CYCLES_2, size = SIZE_1) 42public abstract class AbstractWriteNode extends FixedAccessNode implements StateSplit, MemoryCheckpoint.Single, MemoryAccess, GuardingNode { 43 44 public static final NodeClass<AbstractWriteNode> TYPE = NodeClass.create(AbstractWriteNode.class); 45 @Input ValueNode value; 46 @OptionalInput(InputType.State) FrameState stateAfter; 47 @OptionalInput(InputType.Memory) Node lastLocationAccess; 48 49 @Override 50 public FrameState stateAfter() { 51 return stateAfter; 52 } 53 54 @Override 55 public void setStateAfter(FrameState x) { 56 assert x == null || x.isAlive() : "frame state must be in a graph"; 57 updateUsages(stateAfter, x); 58 stateAfter = x; 59 } 60 61 @Override 62 public boolean hasSideEffect() { 63 return true; 64 } 65 66 public ValueNode value() { 67 return value; 68 } 69 70 protected AbstractWriteNode(NodeClass<? extends AbstractWriteNode> c, AddressNode address, LocationIdentity location, ValueNode value, BarrierType barrierType) { 71 super(c, address, location, StampFactory.forVoid(), barrierType); 72 this.value = value; 73 } 74 75 @Override 76 public boolean isAllowedUsageType(InputType type) { 77 return (type == InputType.Guard && getNullCheck()) ? true : super.isAllowedUsageType(type); 78 } 79 80 @Override 81 public MemoryNode getLastLocationAccess() { 82 return (MemoryNode) lastLocationAccess; 83 } 84 85 @Override 86 public void setLastLocationAccess(MemoryNode lla) { 87 Node newLla = ValueNodeUtil.asNode(lla); 88 updateUsages(lastLocationAccess, newLla); 89 lastLocationAccess = newLla; 90 } 91} 92