Mercurial > hg > truffle
view graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/ReadNode.java @ 18649:d138867d61c4
Remove getValueKind() from LocationNode.
author | Roland Schatz <roland.schatz@oracle.com> |
---|---|
date | Tue, 09 Dec 2014 16:55:19 +0100 |
parents | 12bd2b344b08 |
children | f57d86eb036f |
line wrap: on
line source
/* * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package com.oracle.graal.nodes.extended; import com.oracle.graal.api.meta.*; import com.oracle.graal.compiler.common.*; import com.oracle.graal.compiler.common.type.*; import com.oracle.graal.graph.*; import com.oracle.graal.graph.spi.*; import com.oracle.graal.nodeinfo.*; import com.oracle.graal.nodes.*; import com.oracle.graal.nodes.spi.*; import com.oracle.graal.nodes.type.*; import com.oracle.graal.nodes.util.*; /** * Reads an {@linkplain FixedAccessNode accessed} value. */ @NodeInfo public class ReadNode extends FloatableAccessNode implements LIRLowerable, Canonicalizable, PiPushable, Virtualizable, GuardingNode { public static ReadNode create(ValueNode object, ValueNode location, Stamp stamp, BarrierType barrierType) { return new ReadNode(object, location, stamp, barrierType); } protected ReadNode(ValueNode object, ValueNode location, Stamp stamp, BarrierType barrierType) { super(object, location, stamp, null, barrierType); } public static ReadNode create(ValueNode object, ValueNode location, Stamp stamp, GuardingNode guard, BarrierType barrierType) { return new ReadNode(object, location, stamp, guard, barrierType); } protected ReadNode(ValueNode object, ValueNode location, Stamp stamp, GuardingNode guard, BarrierType barrierType) { super(object, location, stamp, guard, barrierType); } public static ReadNode create(ValueNode object, ValueNode location, Stamp stamp, GuardingNode guard, BarrierType barrierType, boolean nullCheck, FrameState stateBefore) { return new ReadNode(object, location, stamp, guard, barrierType, nullCheck, stateBefore); } protected ReadNode(ValueNode object, ValueNode location, Stamp stamp, GuardingNode guard, BarrierType barrierType, boolean nullCheck, FrameState stateBefore) { super(object, location, stamp, guard, barrierType, nullCheck, stateBefore); } public static ReadNode create(ValueNode object, ValueNode location, ValueNode guard, BarrierType barrierType) { return new ReadNode(object, location, guard, barrierType); } protected ReadNode(ValueNode object, ValueNode location, ValueNode guard, BarrierType barrierType) { /* * Used by node intrinsics. Really, you can trust me on that! Since the initial value for * location is a parameter, i.e., a ParameterNode, the constructor cannot use the declared * type LocationNode. */ super(object, location, StampFactory.forNodeIntrinsic(), (GuardingNode) guard, barrierType); } @Override public void generate(NodeLIRBuilderTool gen) { Value address = location().generateAddress(gen, gen.getLIRGeneratorTool(), gen.operand(object())); LIRKind readKind = gen.getLIRGeneratorTool().getLIRKind(stamp()); gen.setResult(this, gen.getLIRGeneratorTool().emitLoad(readKind, address, gen.state(this))); } @Override public Node canonical(CanonicalizerTool tool) { if (usages().isEmpty()) { if (getGuard() != null && !(getGuard() instanceof FixedNode)) { // The guard is necessary even if the read goes away. return ValueAnchorNode.create((ValueNode) getGuard()); } else { // Read without usages or guard can be safely removed. return null; } } if (object() instanceof PiNode && ((PiNode) object()).getGuard() == getGuard()) { return ReadNode.create(((PiNode) object()).getOriginalNode(), location(), stamp(), getGuard(), getBarrierType(), getNullCheck(), stateBefore()); } if (!getNullCheck()) { return canonicalizeRead(this, location(), object(), tool); } else { // if this read is a null check, then replacing it with the value is incorrect for // guard-type usages return this; } } @Override public FloatingAccessNode asFloatingNode(MemoryNode lastLocationAccess) { return graph().unique(FloatingReadNode.create(object(), location(), lastLocationAccess, stamp(), getGuard(), getBarrierType())); } @Override public boolean isAllowedUsageType(InputType type) { return (getNullCheck() && type == InputType.Guard) ? true : super.isAllowedUsageType(type); } public static ValueNode canonicalizeRead(ValueNode read, LocationNode location, ValueNode object, CanonicalizerTool tool) { MetaAccessProvider metaAccess = tool.getMetaAccess(); if (tool.canonicalizeReads()) { if (metaAccess != null && object != null && object.isConstant() && !object.isNullConstant()) { if ((location.getLocationIdentity().isImmutable()) && location instanceof ConstantLocationNode) { long displacement = ((ConstantLocationNode) location).getDisplacement(); Constant constant = read.stamp().readConstant(tool.getConstantReflection().getMemoryAccessProvider(), object.asConstant(), displacement); if (constant != null) { return ConstantNode.forConstant(read.stamp(), constant, metaAccess); } } } if (location.getLocationIdentity().equals(LocationIdentity.ARRAY_LENGTH_LOCATION)) { ValueNode length = GraphUtil.arrayLength(object); if (length != null) { // TODO Does this need a PiCastNode to the positive range? return length; } } } return read; } @Override public boolean push(PiNode parent) { if (!(location() instanceof ConstantLocationNode && parent.stamp() instanceof ObjectStamp && parent.object().stamp() instanceof ObjectStamp)) { return false; } ObjectStamp piStamp = (ObjectStamp) parent.stamp(); ResolvedJavaType receiverType = piStamp.type(); if (receiverType == null) { return false; } ResolvedJavaField field = receiverType.findInstanceFieldWithOffset(((ConstantLocationNode) location()).getDisplacement()); if (field == null) { // field was not declared by receiverType return false; } ObjectStamp valueStamp = (ObjectStamp) parent.object().stamp(); ResolvedJavaType valueType = StampTool.typeOrNull(valueStamp); if (valueType != null && field.getDeclaringClass().isAssignableFrom(valueType)) { if (piStamp.nonNull() == valueStamp.nonNull() && piStamp.alwaysNull() == valueStamp.alwaysNull()) { replaceFirstInput(parent, parent.object()); return true; } } return false; } @Override public void virtualize(VirtualizerTool tool) { throw GraalInternalError.shouldNotReachHere("unexpected ReadNode before PEA"); } public boolean canNullCheck() { return true; } }