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.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.spi.*;
035
036/**
037 * A floating read of a value from memory specified in terms of an object base and an object
038 * relative location. This node does not null check the object.
039 */
040@NodeInfo(nameTemplate = "Read#{p#location/s}")
041public final class FloatingReadNode extends FloatingAccessNode implements LIRLowerable, Canonicalizable {
042    public static final NodeClass<FloatingReadNode> TYPE = NodeClass.create(FloatingReadNode.class);
043
044    @OptionalInput(InputType.Memory) MemoryNode lastLocationAccess;
045
046    public FloatingReadNode(AddressNode address, LocationIdentity location, MemoryNode lastLocationAccess, Stamp stamp) {
047        this(address, location, lastLocationAccess, stamp, null, BarrierType.NONE);
048    }
049
050    public FloatingReadNode(AddressNode address, LocationIdentity location, MemoryNode lastLocationAccess, Stamp stamp, GuardingNode guard) {
051        this(address, location, lastLocationAccess, stamp, guard, BarrierType.NONE);
052    }
053
054    public FloatingReadNode(AddressNode address, LocationIdentity location, MemoryNode lastLocationAccess, Stamp stamp, GuardingNode guard, BarrierType barrierType) {
055        super(TYPE, address, location, stamp, guard, barrierType);
056        this.lastLocationAccess = lastLocationAccess;
057    }
058
059    public MemoryNode getLastLocationAccess() {
060        return lastLocationAccess;
061    }
062
063    public void setLastLocationAccess(MemoryNode newlla) {
064        updateUsages(ValueNodeUtil.asNode(lastLocationAccess), ValueNodeUtil.asNode(newlla));
065        lastLocationAccess = newlla;
066    }
067
068    @Override
069    public void generate(NodeLIRBuilderTool gen) {
070        LIRKind readKind = gen.getLIRGeneratorTool().getLIRKind(stamp());
071        gen.setResult(this, gen.getLIRGeneratorTool().emitLoad(readKind, gen.operand(address), null));
072    }
073
074    @Override
075    public Node canonical(CanonicalizerTool tool) {
076        if (getAddress() instanceof OffsetAddressNode) {
077            OffsetAddressNode objAddress = (OffsetAddressNode) getAddress();
078            if (objAddress.getBase() instanceof PiNode && ((PiNode) objAddress.getBase()).getGuard() == getGuard()) {
079                OffsetAddressNode newAddress = new OffsetAddressNode(((PiNode) objAddress.getBase()).getOriginalNode(), objAddress.getOffset());
080                return new FloatingReadNode(newAddress, getLocationIdentity(), getLastLocationAccess(), stamp(), getGuard(), getBarrierType());
081            }
082        }
083        return ReadNode.canonicalizeRead(this, getAddress(), getLocationIdentity(), tool);
084    }
085
086    @Override
087    public FixedAccessNode asFixedNode() {
088        return graph().add(new ReadNode(getAddress(), getLocationIdentity(), stamp(), getGuard(), getBarrierType()));
089    }
090
091    @Override
092    public boolean verify() {
093        MemoryNode lla = getLastLocationAccess();
094        assert lla != null || getLocationIdentity().isImmutable() : "lastLocationAccess of " + this + " shouldn't be null for mutable location identity " + getLocationIdentity();
095        return super.verify();
096    }
097}