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.amd64; 26 27 import static org.graalvm.compiler.nodeinfo.NodeSize.SIZE_512; 28 29 import org.graalvm.compiler.core.common.type.StampFactory; 30 import org.graalvm.compiler.graph.NodeClass; 31 import org.graalvm.compiler.nodeinfo.InputType; 32 import org.graalvm.compiler.nodeinfo.NodeCycles; 33 import org.graalvm.compiler.nodeinfo.NodeInfo; 34 import org.graalvm.compiler.nodes.FixedWithNextNode; 35 import org.graalvm.compiler.nodes.NamedLocationIdentity; 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.LIRLowerable; 41 import org.graalvm.compiler.nodes.spi.NodeLIRBuilderTool; 42 import jdk.internal.vm.compiler.word.LocationIdentity; 43 import jdk.internal.vm.compiler.word.Pointer; 44 45 import jdk.vm.ci.meta.JavaKind; 46 import jdk.vm.ci.meta.Value; 47 48 @NodeInfo(size = SIZE_512, cycles = NodeCycles.CYCLES_UNKNOWN) 49 public class AMD64ArrayIndexOfNode extends FixedWithNextNode implements LIRLowerable, MemoryAccess { 50 51 public static final NodeClass<AMD64ArrayIndexOfNode> TYPE = NodeClass.create(AMD64ArrayIndexOfNode.class); 52 53 private final JavaKind kind; 54 55 @Input private ValueNode arrayPointer; 56 @Input private ValueNode arrayLength; 57 @Input private ValueNode searchValue; 58 59 @OptionalInput(InputType.Memory) private MemoryNode lastLocationAccess; 60 61 public AMD64ArrayIndexOfNode(ValueNode arrayPointer, ValueNode arrayLength, ValueNode searchValue, @ConstantNodeParameter JavaKind kind) { 62 super(TYPE, StampFactory.forKind(JavaKind.Int)); 63 this.kind = kind; 64 this.arrayPointer = arrayPointer; 65 this.arrayLength = arrayLength; 66 this.searchValue = searchValue; 67 } 68 69 @Override 70 public LocationIdentity getLocationIdentity() { 71 return NamedLocationIdentity.getArrayLocation(kind); 72 } 73 74 @Override 75 public void generate(NodeLIRBuilderTool gen) { 76 Value result = gen.getLIRGeneratorTool().emitArrayIndexOf(kind, gen.operand(arrayPointer), gen.operand(arrayLength), gen.operand(searchValue)); 77 gen.setResult(this, result); 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 @NodeIntrinsic 92 public static native int optimizedArrayIndexOf(Pointer arrayPointer, int arrayLength, char searchValue, @ConstantNodeParameter JavaKind kind); 93 }