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