43972
|
1 |
/*
|
58877
|
2 |
* Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved.
|
43972
|
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 |
*/
|
50858
|
23 |
|
|
24 |
|
43972
|
25 |
package org.graalvm.compiler.nodes.memory;
|
|
26 |
|
|
27 |
import org.graalvm.compiler.core.common.LIRKind;
|
46344
|
28 |
import org.graalvm.compiler.core.common.type.Stamp;
|
46640
|
29 |
import org.graalvm.compiler.graph.Node;
|
43972
|
30 |
import org.graalvm.compiler.graph.NodeClass;
|
46640
|
31 |
import org.graalvm.compiler.graph.spi.Canonicalizable;
|
|
32 |
import org.graalvm.compiler.graph.spi.CanonicalizerTool;
|
43972
|
33 |
import org.graalvm.compiler.nodeinfo.NodeInfo;
|
48190
|
34 |
import org.graalvm.compiler.nodes.NodeView;
|
43972
|
35 |
import org.graalvm.compiler.nodes.ValueNode;
|
|
36 |
import org.graalvm.compiler.nodes.memory.address.AddressNode;
|
|
37 |
import org.graalvm.compiler.nodes.spi.NodeLIRBuilderTool;
|
49873
|
38 |
import jdk.internal.vm.compiler.word.LocationIdentity;
|
43972
|
39 |
|
|
40 |
/**
|
|
41 |
* Writes a given {@linkplain #value() value} a {@linkplain FixedAccessNode memory location}.
|
|
42 |
*/
|
|
43 |
@NodeInfo(nameTemplate = "Write#{p#location/s}")
|
46640
|
44 |
public class WriteNode extends AbstractWriteNode implements LIRLowerableAccess, Canonicalizable {
|
43972
|
45 |
|
|
46 |
public static final NodeClass<WriteNode> TYPE = NodeClass.create(WriteNode.class);
|
58877
|
47 |
private final boolean volatileAccess;
|
43972
|
48 |
|
58877
|
49 |
public WriteNode(AddressNode address, LocationIdentity location, ValueNode value, BarrierType barrierType, boolean volatileAccess) {
|
43972
|
50 |
super(TYPE, address, location, value, barrierType);
|
58877
|
51 |
this.volatileAccess = volatileAccess;
|
43972
|
52 |
}
|
|
53 |
|
46344
|
54 |
protected WriteNode(NodeClass<? extends WriteNode> c, AddressNode address, LocationIdentity location, ValueNode value, BarrierType barrierType) {
|
|
55 |
super(c, address, location, value, barrierType);
|
58877
|
56 |
this.volatileAccess = false;
|
43972
|
57 |
}
|
|
58 |
|
|
59 |
@Override
|
|
60 |
public void generate(NodeLIRBuilderTool gen) {
|
48190
|
61 |
LIRKind writeKind = gen.getLIRGeneratorTool().getLIRKind(value().stamp(NodeView.DEFAULT));
|
43972
|
62 |
gen.getLIRGeneratorTool().getArithmetic().emitStore(writeKind, gen.operand(address), gen.operand(value()), gen.state(this));
|
|
63 |
}
|
|
64 |
|
|
65 |
@Override
|
|
66 |
public boolean canNullCheck() {
|
58877
|
67 |
return !isVolatile();
|
43972
|
68 |
}
|
|
69 |
|
46344
|
70 |
@Override
|
|
71 |
public Stamp getAccessStamp() {
|
48190
|
72 |
return value().stamp(NodeView.DEFAULT);
|
43972
|
73 |
}
|
46640
|
74 |
|
|
75 |
@Override
|
|
76 |
public Node canonical(CanonicalizerTool tool) {
|
|
77 |
if (tool.canonicalizeReads() && hasExactlyOneUsage() && next() instanceof WriteNode) {
|
|
78 |
WriteNode write = (WriteNode) next();
|
58877
|
79 |
if (write.lastLocationAccess == this && write.getAddress() == getAddress() && getAccessStamp().isCompatible(write.getAccessStamp()) && !isVolatile()) {
|
46640
|
80 |
write.setLastLocationAccess(getLastLocationAccess());
|
|
81 |
return write;
|
|
82 |
}
|
|
83 |
}
|
|
84 |
return this;
|
|
85 |
}
|
58877
|
86 |
|
|
87 |
@Override
|
|
88 |
public LocationIdentity getKilledLocationIdentity() {
|
|
89 |
if (isVolatile()) {
|
|
90 |
return LocationIdentity.any();
|
|
91 |
}
|
|
92 |
return getLocationIdentity();
|
|
93 |
}
|
|
94 |
|
|
95 |
public boolean isVolatile() {
|
|
96 |
return volatileAccess;
|
|
97 |
}
|
43972
|
98 |
}
|