001/* 002 * Copyright (c) 2011, 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.nodes.memory; 024 025import jdk.internal.jvmci.meta.*; 026 027import com.oracle.graal.compiler.common.type.*; 028import com.oracle.graal.graph.*; 029import com.oracle.graal.nodeinfo.*; 030import com.oracle.graal.nodes.*; 031import com.oracle.graal.nodes.extended.*; 032import com.oracle.graal.nodes.memory.address.*; 033 034@NodeInfo(allowedUsageTypes = {InputType.Memory}) 035public abstract class AbstractWriteNode extends FixedAccessNode implements StateSplit, MemoryCheckpoint.Single, MemoryAccess, GuardingNode { 036 037 public static final NodeClass<AbstractWriteNode> TYPE = NodeClass.create(AbstractWriteNode.class); 038 @Input ValueNode value; 039 @OptionalInput(InputType.State) FrameState stateAfter; 040 @OptionalInput(InputType.Memory) Node lastLocationAccess; 041 042 protected final boolean initialization; 043 044 public FrameState stateAfter() { 045 return stateAfter; 046 } 047 048 public void setStateAfter(FrameState x) { 049 assert x == null || x.isAlive() : "frame state must be in a graph"; 050 updateUsages(stateAfter, x); 051 stateAfter = x; 052 } 053 054 public boolean hasSideEffect() { 055 return true; 056 } 057 058 public ValueNode value() { 059 return value; 060 } 061 062 /** 063 * Returns whether this write is the initialization of the written location. If it is true, the 064 * old value of the memory location is either uninitialized or zero. If it is false, the memory 065 * location is guaranteed to contain a valid value or zero. 066 */ 067 public boolean isInitialization() { 068 return initialization; 069 } 070 071 protected AbstractWriteNode(NodeClass<? extends AbstractWriteNode> c, AddressNode address, LocationIdentity location, ValueNode value, BarrierType barrierType) { 072 this(c, address, location, value, barrierType, false); 073 } 074 075 protected AbstractWriteNode(NodeClass<? extends AbstractWriteNode> c, AddressNode address, LocationIdentity location, ValueNode value, BarrierType barrierType, boolean initialization) { 076 super(c, address, location, StampFactory.forVoid(), barrierType); 077 this.value = value; 078 this.initialization = initialization; 079 } 080 081 protected AbstractWriteNode(NodeClass<? extends AbstractWriteNode> c, AddressNode address, LocationIdentity location, ValueNode value, BarrierType barrierType, GuardingNode guard, 082 boolean initialization) { 083 super(c, address, location, StampFactory.forVoid(), guard, barrierType, false, null); 084 this.value = value; 085 this.initialization = initialization; 086 } 087 088 @Override 089 public boolean isAllowedUsageType(InputType type) { 090 return (type == InputType.Guard && getNullCheck()) ? true : super.isAllowedUsageType(type); 091 } 092 093 public MemoryNode getLastLocationAccess() { 094 return (MemoryNode) lastLocationAccess; 095 } 096 097 public void setLastLocationAccess(MemoryNode lla) { 098 Node newLla = ValueNodeUtil.asNode(lla); 099 updateUsages(lastLocationAccess, newLla); 100 lastLocationAccess = newLla; 101 } 102}