1 /*
2  * Copyright (c) 2013, 2015, 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  */
23 
24 
25 package org.graalvm.compiler.replacements;
26 
27 import static org.graalvm.compiler.nodeinfo.NodeCycles.CYCLES_IGNORED;
28 import static org.graalvm.compiler.nodeinfo.NodeSize.SIZE_IGNORED;
29 
30 import org.graalvm.compiler.core.common.type.Stamp;
31 import org.graalvm.compiler.graph.NodeClass;
32 import org.graalvm.compiler.graph.NodeInputList;
33 import org.graalvm.compiler.nodeinfo.InputType;
34 import org.graalvm.compiler.nodeinfo.NodeInfo;
35 import org.graalvm.compiler.nodes.FixedWithNextNode;
36 import org.graalvm.compiler.nodes.ValueNode;
37 import org.graalvm.compiler.nodes.ValueNodeUtil;
38 import org.graalvm.compiler.nodes.memory.MemoryAccess;
39 import org.graalvm.compiler.nodes.memory.MemoryNode;
40 import org.graalvm.compiler.nodes.spi.Lowerable;
41 import org.graalvm.compiler.nodes.spi.LoweringTool;
42 import jdk.internal.vm.compiler.word.LocationIdentity;
43 
44 @NodeInfo(cycles = CYCLES_IGNORED, size = SIZE_IGNORED)
45 public class SnippetLowerableMemoryNode extends FixedWithNextNode implements Lowerable, MemoryAccess {
46     public static final NodeClass<SnippetLowerableMemoryNode> TYPE = NodeClass.create(SnippetLowerableMemoryNode.class);
47 
48     public interface SnippetLowering {
lower(SnippetLowerableMemoryNode node, LoweringTool tool)49         void lower(SnippetLowerableMemoryNode node, LoweringTool tool);
50     }
51 
52     @Input protected NodeInputList<ValueNode> arguments;
53     @OptionalInput(InputType.Memory) protected MemoryNode lastLocationAccess;
54     private final LocationIdentity locationIdentity;
55     SnippetLowering lowering;
56 
SnippetLowerableMemoryNode(SnippetLowering lowering, LocationIdentity locationIdentity, Stamp stamp, ValueNode... arguments)57     public SnippetLowerableMemoryNode(SnippetLowering lowering, LocationIdentity locationIdentity, Stamp stamp, ValueNode... arguments) {
58         super(TYPE, stamp);
59         this.arguments = new NodeInputList<>(this, arguments);
60         this.lowering = lowering;
61         this.locationIdentity = locationIdentity;
62     }
63 
getArgument(int i)64     public ValueNode getArgument(int i) {
65         return arguments.get(i);
66     }
67 
getArgumentCount()68     public int getArgumentCount() {
69         return arguments.size();
70     }
71 
72     @Override
lower(LoweringTool tool)73     public void lower(LoweringTool tool) {
74         lowering.lower(this, tool);
75     }
76 
77     @Override
getLocationIdentity()78     public LocationIdentity getLocationIdentity() {
79         return locationIdentity;
80     }
81 
82     @Override
getLastLocationAccess()83     public MemoryNode getLastLocationAccess() {
84         return lastLocationAccess;
85     }
86 
87     @Override
setLastLocationAccess(MemoryNode lla)88     public void setLastLocationAccess(MemoryNode lla) {
89         updateUsages(ValueNodeUtil.asNode(lastLocationAccess), ValueNodeUtil.asNode(lla));
90         lastLocationAccess = lla;
91     }
92 }
93