43972
|
1 |
/*
|
|
2 |
* Copyright (c) 2013, 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.hotspot.HotSpotBackend.Options.GraalArithmeticStubs;
|
|
26 |
import static org.graalvm.compiler.hotspot.amd64.AMD64HotSpotForeignCallsProvider.ARITHMETIC_COS_STUB;
|
|
27 |
import static org.graalvm.compiler.hotspot.amd64.AMD64HotSpotForeignCallsProvider.ARITHMETIC_EXP_STUB;
|
|
28 |
import static org.graalvm.compiler.hotspot.amd64.AMD64HotSpotForeignCallsProvider.ARITHMETIC_LOG10_STUB;
|
|
29 |
import static org.graalvm.compiler.hotspot.amd64.AMD64HotSpotForeignCallsProvider.ARITHMETIC_LOG_STUB;
|
46344
|
30 |
import static org.graalvm.compiler.hotspot.amd64.AMD64HotSpotForeignCallsProvider.ARITHMETIC_POW_STUB;
|
43972
|
31 |
import static org.graalvm.compiler.hotspot.amd64.AMD64HotSpotForeignCallsProvider.ARITHMETIC_SIN_STUB;
|
|
32 |
import static org.graalvm.compiler.hotspot.amd64.AMD64HotSpotForeignCallsProvider.ARITHMETIC_TAN_STUB;
|
|
33 |
|
|
34 |
import org.graalvm.compiler.core.common.spi.ForeignCallDescriptor;
|
|
35 |
import org.graalvm.compiler.core.common.spi.ForeignCallsProvider;
|
46640
|
36 |
import org.graalvm.compiler.debug.DebugHandlersFactory;
|
43972
|
37 |
import org.graalvm.compiler.graph.Node;
|
|
38 |
import org.graalvm.compiler.hotspot.GraalHotSpotVMConfig;
|
|
39 |
import org.graalvm.compiler.hotspot.HotSpotGraalRuntimeProvider;
|
|
40 |
import org.graalvm.compiler.hotspot.meta.DefaultHotSpotLoweringProvider;
|
|
41 |
import org.graalvm.compiler.hotspot.meta.HotSpotProviders;
|
|
42 |
import org.graalvm.compiler.hotspot.meta.HotSpotRegistersProvider;
|
|
43 |
import org.graalvm.compiler.hotspot.nodes.profiling.ProfileNode;
|
|
44 |
import org.graalvm.compiler.hotspot.replacements.profiling.ProbabilisticProfileSnippets;
|
|
45 |
import org.graalvm.compiler.nodes.calc.FloatConvertNode;
|
|
46 |
import org.graalvm.compiler.nodes.spi.LoweringTool;
|
46344
|
47 |
import org.graalvm.compiler.options.OptionValues;
|
43972
|
48 |
import org.graalvm.compiler.replacements.amd64.AMD64ConvertSnippets;
|
|
49 |
import org.graalvm.compiler.replacements.nodes.BinaryMathIntrinsicNode.BinaryOperation;
|
|
50 |
import org.graalvm.compiler.replacements.nodes.UnaryMathIntrinsicNode.UnaryOperation;
|
|
51 |
|
|
52 |
import jdk.vm.ci.code.TargetDescription;
|
|
53 |
import jdk.vm.ci.hotspot.HotSpotConstantReflectionProvider;
|
|
54 |
import jdk.vm.ci.meta.MetaAccessProvider;
|
|
55 |
|
|
56 |
public class AMD64HotSpotLoweringProvider extends DefaultHotSpotLoweringProvider {
|
|
57 |
|
|
58 |
private AMD64ConvertSnippets.Templates convertSnippets;
|
|
59 |
private ProbabilisticProfileSnippets.Templates profileSnippets;
|
|
60 |
|
|
61 |
public AMD64HotSpotLoweringProvider(HotSpotGraalRuntimeProvider runtime, MetaAccessProvider metaAccess, ForeignCallsProvider foreignCalls, HotSpotRegistersProvider registers,
|
|
62 |
HotSpotConstantReflectionProvider constantReflection, TargetDescription target) {
|
|
63 |
super(runtime, metaAccess, foreignCalls, registers, constantReflection, target);
|
|
64 |
}
|
|
65 |
|
|
66 |
@Override
|
46640
|
67 |
public void initialize(OptionValues options, Iterable<DebugHandlersFactory> factories, HotSpotProviders providers, GraalHotSpotVMConfig config) {
|
|
68 |
convertSnippets = new AMD64ConvertSnippets.Templates(options, factories, providers, providers.getSnippetReflection(), providers.getCodeCache().getTarget());
|
46344
|
69 |
profileSnippets = ProfileNode.Options.ProbabilisticProfiling.getValue(options)
|
48861
|
70 |
? new ProbabilisticProfileSnippets.Templates(options, factories, providers, providers.getCodeCache().getTarget())
|
|
71 |
: null;
|
46640
|
72 |
super.initialize(options, factories, providers, config);
|
43972
|
73 |
}
|
|
74 |
|
|
75 |
@Override
|
|
76 |
public void lower(Node n, LoweringTool tool) {
|
|
77 |
if (n instanceof FloatConvertNode) {
|
|
78 |
convertSnippets.lower((FloatConvertNode) n, tool);
|
|
79 |
} else if (profileSnippets != null && n instanceof ProfileNode) {
|
|
80 |
profileSnippets.lower((ProfileNode) n, tool);
|
|
81 |
} else {
|
|
82 |
super.lower(n, tool);
|
|
83 |
}
|
|
84 |
}
|
|
85 |
|
|
86 |
@Override
|
|
87 |
protected ForeignCallDescriptor toForeignCall(UnaryOperation operation) {
|
46344
|
88 |
if (GraalArithmeticStubs.getValue(runtime.getOptions())) {
|
43972
|
89 |
switch (operation) {
|
|
90 |
case LOG:
|
|
91 |
return ARITHMETIC_LOG_STUB;
|
|
92 |
case LOG10:
|
|
93 |
return ARITHMETIC_LOG10_STUB;
|
|
94 |
case SIN:
|
|
95 |
return ARITHMETIC_SIN_STUB;
|
|
96 |
case COS:
|
|
97 |
return ARITHMETIC_COS_STUB;
|
|
98 |
case TAN:
|
|
99 |
return ARITHMETIC_TAN_STUB;
|
|
100 |
case EXP:
|
|
101 |
return ARITHMETIC_EXP_STUB;
|
|
102 |
}
|
|
103 |
} else if (operation == UnaryOperation.EXP) {
|
|
104 |
return operation.foreignCallDescriptor;
|
|
105 |
}
|
|
106 |
// Lower only using LIRGenerator
|
|
107 |
return null;
|
|
108 |
}
|
|
109 |
|
|
110 |
@Override
|
|
111 |
protected ForeignCallDescriptor toForeignCall(BinaryOperation operation) {
|
46344
|
112 |
if (GraalArithmeticStubs.getValue(runtime.getOptions())) {
|
43972
|
113 |
switch (operation) {
|
|
114 |
case POW:
|
|
115 |
return ARITHMETIC_POW_STUB;
|
|
116 |
}
|
|
117 |
} else if (operation == BinaryOperation.POW) {
|
|
118 |
return operation.foreignCallDescriptor;
|
|
119 |
}
|
|
120 |
// Lower only using LIRGenerator
|
|
121 |
return null;
|
|
122 |
}
|
|
123 |
|
|
124 |
@Override
|
46393
|
125 |
public Integer smallestCompareWidth() {
|
|
126 |
return 8;
|
43972
|
127 |
}
|
|
128 |
}
|