AbstractWriteNode.java revision 12651:6ef01bd40ce2
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_3;
26import static org.graalvm.compiler.nodeinfo.NodeSize.SIZE_1;
27
28import org.graalvm.compiler.core.common.LocationIdentity;
29import org.graalvm.compiler.core.common.type.StampFactory;
30import org.graalvm.compiler.graph.Node;
31import org.graalvm.compiler.graph.NodeClass;
32import org.graalvm.compiler.nodeinfo.InputType;
33import org.graalvm.compiler.nodeinfo.NodeInfo;
34import org.graalvm.compiler.nodes.FrameState;
35import org.graalvm.compiler.nodes.StateSplit;
36import org.graalvm.compiler.nodes.ValueNode;
37import org.graalvm.compiler.nodes.ValueNodeUtil;
38import org.graalvm.compiler.nodes.extended.GuardingNode;
39import org.graalvm.compiler.nodes.memory.address.AddressNode;
40
41@NodeInfo(allowedUsageTypes = {InputType.Memory, InputType.Guard}, cycles = CYCLES_3, 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    protected final boolean initialization;
50
51    @Override
52    public FrameState stateAfter() {
53        return stateAfter;
54    }
55
56    @Override
57    public void setStateAfter(FrameState x) {
58        assert x == null || x.isAlive() : "frame state must be in a graph";
59        updateUsages(stateAfter, x);
60        stateAfter = x;
61    }
62
63    @Override
64    public boolean hasSideEffect() {
65        return true;
66    }
67
68    public ValueNode value() {
69        return value;
70    }
71
72    /**
73     * Returns whether this write is the initialization of the written location. If it is true, the
74     * old value of the memory location is either uninitialized or zero. If it is false, the memory
75     * location is guaranteed to contain a valid value or zero.
76     */
77    public boolean isInitialization() {
78        return initialization;
79    }
80
81    protected AbstractWriteNode(NodeClass<? extends AbstractWriteNode> c, AddressNode address, LocationIdentity location, ValueNode value, BarrierType barrierType) {
82        this(c, address, location, value, barrierType, false);
83    }
84
85    protected AbstractWriteNode(NodeClass<? extends AbstractWriteNode> c, AddressNode address, LocationIdentity location, ValueNode value, BarrierType barrierType, boolean initialization) {
86        super(c, address, location, StampFactory.forVoid(), barrierType);
87        this.value = value;
88        this.initialization = initialization;
89    }
90
91    protected AbstractWriteNode(NodeClass<? extends AbstractWriteNode> c, AddressNode address, LocationIdentity location, ValueNode value, BarrierType barrierType, GuardingNode guard,
92                    boolean initialization) {
93        super(c, address, location, StampFactory.forVoid(), guard, barrierType, false, null);
94        this.value = value;
95        this.initialization = initialization;
96    }
97
98    @Override
99    public boolean isAllowedUsageType(InputType type) {
100        return (type == InputType.Guard && getNullCheck()) ? true : super.isAllowedUsageType(type);
101    }
102
103    @Override
104    public MemoryNode getLastLocationAccess() {
105        return (MemoryNode) lastLocationAccess;
106    }
107
108    @Override
109    public void setLastLocationAccess(MemoryNode lla) {
110        Node newLla = ValueNodeUtil.asNode(lla);
111        updateUsages(lastLocationAccess, newLla);
112        lastLocationAccess = newLla;
113    }
114}
115