1 /* 2 * Copyright (c) 2018, 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.InputType.Memory; 28 import static org.graalvm.compiler.nodeinfo.NodeCycles.CYCLES_UNKNOWN; 29 import static org.graalvm.compiler.nodeinfo.NodeSize.SIZE_512; 30 31 import org.graalvm.compiler.core.common.type.StampFactory; 32 import org.graalvm.compiler.graph.NodeClass; 33 import org.graalvm.compiler.lir.gen.LIRGeneratorTool; 34 import org.graalvm.compiler.nodeinfo.NodeInfo; 35 import org.graalvm.compiler.nodes.FixedWithNextNode; 36 import org.graalvm.compiler.nodes.NamedLocationIdentity; 37 import org.graalvm.compiler.nodes.ValueNode; 38 import org.graalvm.compiler.nodes.ValueNodeUtil; 39 import org.graalvm.compiler.nodes.memory.MemoryAccess; 40 import org.graalvm.compiler.nodes.memory.MemoryCheckpoint; 41 import org.graalvm.compiler.nodes.memory.MemoryNode; 42 import org.graalvm.compiler.nodes.spi.LIRLowerable; 43 import org.graalvm.compiler.nodes.spi.NodeLIRBuilderTool; 44 import jdk.internal.vm.compiler.word.LocationIdentity; 45 import jdk.internal.vm.compiler.word.Pointer; 46 47 import jdk.vm.ci.meta.JavaKind; 48 import jdk.vm.ci.meta.Value; 49 50 @NodeInfo(allowedUsageTypes = Memory, size = SIZE_512, cycles = CYCLES_UNKNOWN) 51 52 public final class AMD64StringUTF16CompressNode extends FixedWithNextNode 53 implements LIRLowerable, MemoryCheckpoint.Multi, MemoryAccess { 54 55 public static final NodeClass<AMD64StringUTF16CompressNode> TYPE = NodeClass.create(AMD64StringUTF16CompressNode.class); 56 57 @Input private ValueNode src; 58 @Input private ValueNode dst; 59 @Input private ValueNode len; 60 final JavaKind readKind; 61 62 @OptionalInput(Memory) private MemoryNode lla; // Last access location registered. 63 64 // java.lang.StringUTF16.compress([CI[BII)I 65 // 66 // int compress(char[] src, int src_indx, byte[] dst, int dst_indx, int len) 67 // 68 // Represented as a graph node by: 69 70 public AMD64StringUTF16CompressNode(ValueNode src, ValueNode dst, ValueNode len, JavaKind readKind) { 71 super(TYPE, StampFactory.forInteger(32)); 72 this.src = src; 73 this.dst = dst; 74 this.len = len; 75 this.readKind = readKind; 76 } 77 78 @Override 79 public LocationIdentity getLocationIdentity() { 80 // Model read access via 'src' using: 81 return NamedLocationIdentity.getArrayLocation(readKind); 82 } 83 84 @Override 85 public LocationIdentity[] getLocationIdentities() { 86 // Model write access via 'dst' using: 87 return new LocationIdentity[]{NamedLocationIdentity.getArrayLocation(JavaKind.Byte)}; 88 } 89 90 @Override 91 public void generate(NodeLIRBuilderTool gen) { 92 LIRGeneratorTool lgt = gen.getLIRGeneratorTool(); 93 Value res = lgt.emitStringUTF16Compress(gen.operand(src), gen.operand(dst), gen.operand(len)); 94 gen.setResult(this, res); 95 } 96 97 @Override 98 public MemoryNode getLastLocationAccess() { 99 return lla; 100 } 101 102 @Override 103 public void setLastLocationAccess(MemoryNode newlla) { 104 updateUsages(ValueNodeUtil.asNode(lla), ValueNodeUtil.asNode(newlla)); 105 lla = newlla; 106 } 107 108 @NodeIntrinsic 109 public static native int compress(Pointer src, Pointer dst, int len, @ConstantNodeParameter JavaKind readKind); 110 }