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.common.*; 026import jdk.internal.jvmci.meta.*; 027 028import com.oracle.graal.graph.*; 029import com.oracle.graal.graph.spi.*; 030import com.oracle.graal.nodeinfo.*; 031import com.oracle.graal.nodes.*; 032import com.oracle.graal.nodes.extended.*; 033import com.oracle.graal.nodes.memory.address.*; 034import com.oracle.graal.nodes.memory.address.AddressNode.Address; 035import com.oracle.graal.nodes.spi.*; 036 037/** 038 * Writes a given {@linkplain #value() value} a {@linkplain FixedAccessNode memory location}. 039 */ 040@NodeInfo(nameTemplate = "Write#{p#location/s}") 041public final class WriteNode extends AbstractWriteNode implements LIRLowerable, Simplifiable, Virtualizable { 042 043 public static final NodeClass<WriteNode> TYPE = NodeClass.create(WriteNode.class); 044 045 private WriteNode(ValueNode address, LocationIdentity location, ValueNode value, BarrierType barrierType) { 046 this((AddressNode) address, location, value, barrierType); 047 } 048 049 public WriteNode(AddressNode address, LocationIdentity location, ValueNode value, BarrierType barrierType) { 050 super(TYPE, address, location, value, barrierType); 051 } 052 053 public WriteNode(AddressNode address, LocationIdentity location, ValueNode value, BarrierType barrierType, boolean initialization) { 054 super(TYPE, address, location, value, barrierType, initialization); 055 } 056 057 public WriteNode(AddressNode address, LocationIdentity location, ValueNode value, BarrierType barrierType, GuardingNode guard, boolean initialization) { 058 super(TYPE, address, location, value, barrierType, guard, initialization); 059 } 060 061 @Override 062 public void generate(NodeLIRBuilderTool gen) { 063 LIRKind writeKind = gen.getLIRGeneratorTool().getLIRKind(value().stamp()); 064 gen.getLIRGeneratorTool().emitStore(writeKind, gen.operand(address), gen.operand(value()), gen.state(this)); 065 } 066 067 @Override 068 public void simplify(SimplifierTool tool) { 069 if (getAddress() instanceof OffsetAddressNode) { 070 OffsetAddressNode objAddress = (OffsetAddressNode) getAddress(); 071 if (objAddress.getBase() instanceof PiNode && ((PiNode) objAddress.getBase()).getGuard() == getGuard()) { 072 OffsetAddressNode newAddress = graph().unique(new OffsetAddressNode(((PiNode) objAddress.getBase()).getOriginalNode(), objAddress.getOffset())); 073 setAddress(newAddress); 074 tool.addToWorkList(newAddress); 075 } 076 } 077 } 078 079 @NodeIntrinsic 080 public static native void writeMemory(Address address, @ConstantNodeParameter LocationIdentity location, Object value, @ConstantNodeParameter BarrierType barrierType); 081 082 @Override 083 public void virtualize(VirtualizerTool tool) { 084 throw JVMCIError.shouldNotReachHere("unexpected WriteNode before PEA"); 085 } 086 087 public boolean canNullCheck() { 088 return true; 089 } 090}