1 /* 2 * Copyright (c) 2016, 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 package org.graalvm.compiler.hotspot.amd64; 24 25 import static org.graalvm.compiler.nodeinfo.NodeCycles.CYCLES_15; 26 import static org.graalvm.compiler.nodeinfo.NodeCycles.CYCLES_50; 27 import static org.graalvm.compiler.nodeinfo.NodeCycles.CYCLES_6; 28 import static org.graalvm.compiler.nodeinfo.NodeCycles.CYCLES_80; 29 import static org.graalvm.compiler.nodeinfo.NodeSize.SIZE_30; 30 import static org.graalvm.compiler.nodeinfo.NodeSize.SIZE_4; 31 32 import org.graalvm.compiler.graph.Node; 33 import org.graalvm.compiler.hotspot.nodes.HotSpotNodeCostProvider; 34 import org.graalvm.compiler.nodeinfo.NodeCycles; 35 import org.graalvm.compiler.nodeinfo.NodeSize; 36 import org.graalvm.compiler.nodes.ReturnNode; 37 import org.graalvm.compiler.replacements.nodes.ArrayEqualsNode; 38 import org.graalvm.compiler.replacements.nodes.UnaryMathIntrinsicNode; 39 40 import jdk.vm.ci.amd64.AMD64; 41 import jdk.vm.ci.amd64.AMD64.CPUFeature; 42 import jdk.vm.ci.code.TargetDescription; 43 44 public class AMD64HotSpotNodeCostProvider extends HotSpotNodeCostProvider { 45 private final boolean avx2; 46 private final boolean sse41; 47 48 public AMD64HotSpotNodeCostProvider(TargetDescription target) { 49 this.avx2 = ((AMD64) target.arch).getFeatures().contains(CPUFeature.AVX2); 50 this.sse41 = ((AMD64) target.arch).getFeatures().contains(CPUFeature.SSE4_1); 51 } 52 53 @Override 54 public NodeCycles cycles(Node n) { 55 if (n instanceof UnaryMathIntrinsicNode) { 56 UnaryMathIntrinsicNode u = (UnaryMathIntrinsicNode) n; 57 switch (u.getOperation()) { 58 case LOG: 59 case LOG10: 60 return CYCLES_15; 61 default: 62 break; 63 } 64 } else if (n instanceof ReturnNode) { 65 return CYCLES_6; 66 } else if (n instanceof ArrayEqualsNode) { 67 if (avx2) { 68 return CYCLES_50; 69 } else if (sse41) { 70 return CYCLES_80; 71 } 72 } 73 return super.cycles(n); 74 } 75 76 @Override 77 public NodeSize size(Node n) { 78 if (n instanceof UnaryMathIntrinsicNode) { 79 UnaryMathIntrinsicNode u = (UnaryMathIntrinsicNode) n; 80 switch (u.getOperation()) { 81 case LOG: 82 case LOG10: 83 return SIZE_30; 84 default: 85 break; 86 } 87 } else if (n instanceof ReturnNode) { 88 return SIZE_4; 89 } 90 return super.size(n); 91 } 92 93 }