< prev index next >

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot.amd64/src/org/graalvm/compiler/hotspot/amd64/AMD64HotSpotLoweringProvider.java

Print this page


   1 /*
   2  * Copyright (c) 2013, 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.hotspot.amd64;
  26 
  27 import static org.graalvm.compiler.core.common.GraalOptions.GeneratePIC;
  28 import static org.graalvm.compiler.hotspot.HotSpotBackend.Options.GraalArithmeticStubs;
  29 
  30 import org.graalvm.compiler.api.replacements.Snippet;
  31 import org.graalvm.compiler.core.common.spi.ForeignCallsProvider;
  32 import org.graalvm.compiler.debug.DebugHandlersFactory;
  33 import org.graalvm.compiler.graph.Node;
  34 import org.graalvm.compiler.hotspot.GraalHotSpotVMConfig;
  35 import org.graalvm.compiler.hotspot.HotSpotGraalRuntimeProvider;
  36 import org.graalvm.compiler.hotspot.meta.DefaultHotSpotLoweringProvider;
  37 import org.graalvm.compiler.hotspot.meta.HotSpotProviders;
  38 import org.graalvm.compiler.hotspot.meta.HotSpotRegistersProvider;
  39 import org.graalvm.compiler.hotspot.nodes.profiling.ProfileNode;
  40 import org.graalvm.compiler.hotspot.replacements.profiling.ProbabilisticProfileSnippets;
  41 import org.graalvm.compiler.nodes.StructuredGraph;
  42 import org.graalvm.compiler.nodes.calc.FloatConvertNode;
  43 import org.graalvm.compiler.nodes.extended.ForeignCallNode;
  44 import org.graalvm.compiler.nodes.spi.LoweringTool;
  45 import org.graalvm.compiler.options.OptionValues;
  46 import org.graalvm.compiler.replacements.amd64.AMD64ConvertSnippets;
  47 import org.graalvm.compiler.replacements.nodes.UnaryMathIntrinsicNode;


  50 
  51 import jdk.vm.ci.code.TargetDescription;
  52 import jdk.vm.ci.hotspot.HotSpotConstantReflectionProvider;
  53 import jdk.vm.ci.meta.MetaAccessProvider;
  54 import jdk.vm.ci.meta.ResolvedJavaMethod;
  55 
  56 public class AMD64HotSpotLoweringProvider extends DefaultHotSpotLoweringProvider {
  57 
  58     private AMD64ConvertSnippets.Templates convertSnippets;
  59     private ProbabilisticProfileSnippets.Templates profileSnippets;
  60     private AMD64X87MathSnippets.Templates mathSnippets;
  61 
  62     public AMD64HotSpotLoweringProvider(HotSpotGraalRuntimeProvider runtime, MetaAccessProvider metaAccess, ForeignCallsProvider foreignCalls, HotSpotRegistersProvider registers,
  63                     HotSpotConstantReflectionProvider constantReflection, TargetDescription target) {
  64         super(runtime, metaAccess, foreignCalls, registers, constantReflection, target);
  65     }
  66 
  67     @Override
  68     public void initialize(OptionValues options, Iterable<DebugHandlersFactory> factories, HotSpotProviders providers, GraalHotSpotVMConfig config) {
  69         convertSnippets = new AMD64ConvertSnippets.Templates(options, factories, providers, providers.getSnippetReflection(), providers.getCodeCache().getTarget());
  70         profileSnippets = ProfileNode.Options.ProbabilisticProfiling.getValue(options) && !JavaVersionUtil.Java8OrEarlier && GeneratePIC.getValue(options)
  71                         ? new ProbabilisticProfileSnippets.Templates(options, factories, providers, providers.getCodeCache().getTarget())
  72                         : null;
  73         mathSnippets = new AMD64X87MathSnippets.Templates(options, factories, providers, providers.getSnippetReflection(), providers.getCodeCache().getTarget());
  74         super.initialize(options, factories, providers, config);
  75     }
  76 
  77     @Override
  78     public void lower(Node n, LoweringTool tool) {
  79         if (n instanceof FloatConvertNode) {
  80             convertSnippets.lower((FloatConvertNode) n, tool);
  81         } else if (profileSnippets != null && n instanceof ProfileNode) {
  82             profileSnippets.lower((ProfileNode) n, tool);
  83         } else if (n instanceof UnaryMathIntrinsicNode) {
  84             lowerUnaryMath((UnaryMathIntrinsicNode) n, tool);
  85         } else {
  86             super.lower(n, tool);
  87         }
  88     }
  89 
  90     private void lowerUnaryMath(UnaryMathIntrinsicNode math, LoweringTool tool) {


 111                     // should the inputs outside of that interval.
 112                     mathSnippets.lower(math, tool);
 113                     return;
 114                 case LOG:
 115                     math.replaceAtUsages(graph.addOrUnique(new AMD64X87MathIntrinsicNode(math.getValue(), UnaryOperation.LOG)));
 116                     return;
 117                 case LOG10:
 118                     math.replaceAtUsages(graph.addOrUnique(new AMD64X87MathIntrinsicNode(math.getValue(), UnaryOperation.LOG10)));
 119                     return;
 120             }
 121         }
 122 
 123         ForeignCallNode call = graph.add(new ForeignCallNode(foreignCalls, math.getOperation().foreignCallDescriptor, math.getValue()));
 124         graph.addAfterFixed(tool.lastFixedNode(), call);
 125         math.replaceAtUsages(call);
 126     }
 127 
 128     @Override
 129     public Integer smallestCompareWidth() {
 130         return 8;





 131     }
 132 }
   1 /*
   2  * Copyright (c) 2013, 2019, 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.hotspot.amd64;
  26 

  27 import static org.graalvm.compiler.hotspot.HotSpotBackend.Options.GraalArithmeticStubs;
  28 
  29 import org.graalvm.compiler.api.replacements.Snippet;
  30 import org.graalvm.compiler.core.common.spi.ForeignCallsProvider;
  31 import org.graalvm.compiler.debug.DebugHandlersFactory;
  32 import org.graalvm.compiler.graph.Node;
  33 import org.graalvm.compiler.hotspot.GraalHotSpotVMConfig;
  34 import org.graalvm.compiler.hotspot.HotSpotGraalRuntimeProvider;
  35 import org.graalvm.compiler.hotspot.meta.DefaultHotSpotLoweringProvider;
  36 import org.graalvm.compiler.hotspot.meta.HotSpotProviders;
  37 import org.graalvm.compiler.hotspot.meta.HotSpotRegistersProvider;
  38 import org.graalvm.compiler.hotspot.nodes.profiling.ProfileNode;
  39 import org.graalvm.compiler.hotspot.replacements.profiling.ProbabilisticProfileSnippets;
  40 import org.graalvm.compiler.nodes.StructuredGraph;
  41 import org.graalvm.compiler.nodes.calc.FloatConvertNode;
  42 import org.graalvm.compiler.nodes.extended.ForeignCallNode;
  43 import org.graalvm.compiler.nodes.spi.LoweringTool;
  44 import org.graalvm.compiler.options.OptionValues;
  45 import org.graalvm.compiler.replacements.amd64.AMD64ConvertSnippets;
  46 import org.graalvm.compiler.replacements.nodes.UnaryMathIntrinsicNode;


  49 
  50 import jdk.vm.ci.code.TargetDescription;
  51 import jdk.vm.ci.hotspot.HotSpotConstantReflectionProvider;
  52 import jdk.vm.ci.meta.MetaAccessProvider;
  53 import jdk.vm.ci.meta.ResolvedJavaMethod;
  54 
  55 public class AMD64HotSpotLoweringProvider extends DefaultHotSpotLoweringProvider {
  56 
  57     private AMD64ConvertSnippets.Templates convertSnippets;
  58     private ProbabilisticProfileSnippets.Templates profileSnippets;
  59     private AMD64X87MathSnippets.Templates mathSnippets;
  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
  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());
  69         profileSnippets = ProfileNode.Options.ProbabilisticProfiling.getValue(options) && !JavaVersionUtil.Java8OrEarlier
  70                         ? new ProbabilisticProfileSnippets.Templates(options, factories, providers, providers.getCodeCache().getTarget())
  71                         : null;
  72         mathSnippets = new AMD64X87MathSnippets.Templates(options, factories, providers, providers.getSnippetReflection(), providers.getCodeCache().getTarget());
  73         super.initialize(options, factories, providers, config);
  74     }
  75 
  76     @Override
  77     public void lower(Node n, LoweringTool tool) {
  78         if (n instanceof FloatConvertNode) {
  79             convertSnippets.lower((FloatConvertNode) n, tool);
  80         } else if (profileSnippets != null && n instanceof ProfileNode) {
  81             profileSnippets.lower((ProfileNode) n, tool);
  82         } else if (n instanceof UnaryMathIntrinsicNode) {
  83             lowerUnaryMath((UnaryMathIntrinsicNode) n, tool);
  84         } else {
  85             super.lower(n, tool);
  86         }
  87     }
  88 
  89     private void lowerUnaryMath(UnaryMathIntrinsicNode math, LoweringTool tool) {


 110                     // should the inputs outside of that interval.
 111                     mathSnippets.lower(math, tool);
 112                     return;
 113                 case LOG:
 114                     math.replaceAtUsages(graph.addOrUnique(new AMD64X87MathIntrinsicNode(math.getValue(), UnaryOperation.LOG)));
 115                     return;
 116                 case LOG10:
 117                     math.replaceAtUsages(graph.addOrUnique(new AMD64X87MathIntrinsicNode(math.getValue(), UnaryOperation.LOG10)));
 118                     return;
 119             }
 120         }
 121 
 122         ForeignCallNode call = graph.add(new ForeignCallNode(foreignCalls, math.getOperation().foreignCallDescriptor, math.getValue()));
 123         graph.addAfterFixed(tool.lastFixedNode(), call);
 124         math.replaceAtUsages(call);
 125     }
 126 
 127     @Override
 128     public Integer smallestCompareWidth() {
 129         return 8;
 130     }
 131 
 132     @Override
 133     public boolean supportBulkZeroing() {
 134         return true;
 135     }
 136 }
< prev index next >