< prev index next >

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.replacements.test/src/org/graalvm/compiler/replacements/test/ReplacementsParseTest.java

Print this page
rev 52509 : [mq]: graal2


  30 
  31 import org.graalvm.compiler.api.directives.GraalDirectives;
  32 import org.graalvm.compiler.api.replacements.ClassSubstitution;
  33 import org.graalvm.compiler.api.replacements.MethodSubstitution;
  34 import org.graalvm.compiler.api.replacements.SnippetReflectionProvider;
  35 import org.graalvm.compiler.bytecode.BytecodeProvider;
  36 import org.graalvm.compiler.core.common.LIRKind;
  37 import org.graalvm.compiler.core.common.spi.ForeignCallDescriptor;
  38 import org.graalvm.compiler.core.common.spi.ForeignCallLinkage;
  39 import org.graalvm.compiler.core.common.spi.ForeignCallsProvider;
  40 import org.graalvm.compiler.core.common.type.Stamp;
  41 import org.graalvm.compiler.core.common.type.StampFactory;
  42 import org.graalvm.compiler.debug.DebugContext;
  43 import org.graalvm.compiler.graph.GraalGraphError;
  44 import org.graalvm.compiler.graph.Node.ConstantNodeParameter;
  45 import org.graalvm.compiler.graph.Node.NodeIntrinsic;
  46 import org.graalvm.compiler.nodes.FrameState;
  47 import org.graalvm.compiler.nodes.PiNode;
  48 import org.graalvm.compiler.nodes.StructuredGraph;
  49 import org.graalvm.compiler.nodes.ValueNode;
  50 import org.graalvm.compiler.nodes.debug.OpaqueNode;
  51 import org.graalvm.compiler.nodes.extended.ForeignCallNode;
  52 import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext;
  53 import org.graalvm.compiler.nodes.graphbuilderconf.InlineInvokePlugin;
  54 import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver;
  55 import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins;
  56 import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration;
  57 import org.graalvm.compiler.nodes.graphbuilderconf.NodeIntrinsicPluginFactory;
  58 import org.graalvm.compiler.nodes.spi.LoweringTool;
  59 import org.graalvm.compiler.options.OptionValues;
  60 import org.graalvm.compiler.phases.common.CanonicalizerPhase;
  61 import org.graalvm.compiler.phases.common.DeadCodeEliminationPhase;
  62 import org.graalvm.compiler.phases.common.FloatingReadPhase;
  63 import org.graalvm.compiler.phases.common.FrameStateAssignmentPhase;
  64 import org.graalvm.compiler.phases.common.GuardLoweringPhase;
  65 import org.graalvm.compiler.phases.common.LoweringPhase;
  66 import org.graalvm.compiler.phases.tiers.HighTierContext;
  67 import jdk.internal.vm.compiler.word.LocationIdentity;
  68 import org.junit.Assert;
  69 import org.junit.BeforeClass;
  70 import org.junit.Test;


 578             GraalDirectives.deoptimize();
 579         }
 580         return x;
 581     }
 582 
 583     /**
 584      * This is similar to {@link #testNonVoidIntrinsicWithCall()} but has a merge after the call
 585      * which would normally capture the {@link FrameState} but in this case we force the merge to be
 586      * optimized away.
 587      */
 588     @Test
 589     public void testNonVoidIntrinsicWithOptimizedSplit() {
 590         testGraph("nonVoidIntrinsicWithOptimizedSplit");
 591     }
 592 
 593     @SuppressWarnings("try")
 594     private void testGraph(String name) {
 595         StructuredGraph graph = parseEager(name, StructuredGraph.AllowAssumptions.YES);
 596         try (DebugContext.Scope s0 = graph.getDebug().scope(name, graph)) {
 597             for (OpaqueNode node : graph.getNodes().filter(OpaqueNode.class)) {
 598                 node.replaceAndDelete(node.getValue());
 599             }
 600             HighTierContext context = getDefaultHighTierContext();
 601             CanonicalizerPhase canonicalizer = new CanonicalizerPhase();
 602             new LoweringPhase(canonicalizer, LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, context);
 603             new FloatingReadPhase().apply(graph);
 604             canonicalizer.apply(graph, context);
 605             new DeadCodeEliminationPhase().apply(graph);
 606             new GuardLoweringPhase().apply(graph, getDefaultMidTierContext());
 607             new FrameStateAssignmentPhase().apply(graph);
 608         } catch (Throwable e) {
 609             throw graph.getDebug().handle(e);
 610         }
 611     }
 612 
 613     private class DummyInjectionProvider implements NodeIntrinsicPluginFactory.InjectionProvider {
 614         @SuppressWarnings("unchecked")
 615         @Override
 616         public <T> T getInjectedArgument(Class<T> type) {
 617             if (type == ForeignCallsProvider.class) {
 618                 return (T) new ForeignCallsProvider() {




  30 
  31 import org.graalvm.compiler.api.directives.GraalDirectives;
  32 import org.graalvm.compiler.api.replacements.ClassSubstitution;
  33 import org.graalvm.compiler.api.replacements.MethodSubstitution;
  34 import org.graalvm.compiler.api.replacements.SnippetReflectionProvider;
  35 import org.graalvm.compiler.bytecode.BytecodeProvider;
  36 import org.graalvm.compiler.core.common.LIRKind;
  37 import org.graalvm.compiler.core.common.spi.ForeignCallDescriptor;
  38 import org.graalvm.compiler.core.common.spi.ForeignCallLinkage;
  39 import org.graalvm.compiler.core.common.spi.ForeignCallsProvider;
  40 import org.graalvm.compiler.core.common.type.Stamp;
  41 import org.graalvm.compiler.core.common.type.StampFactory;
  42 import org.graalvm.compiler.debug.DebugContext;
  43 import org.graalvm.compiler.graph.GraalGraphError;
  44 import org.graalvm.compiler.graph.Node.ConstantNodeParameter;
  45 import org.graalvm.compiler.graph.Node.NodeIntrinsic;
  46 import org.graalvm.compiler.nodes.FrameState;
  47 import org.graalvm.compiler.nodes.PiNode;
  48 import org.graalvm.compiler.nodes.StructuredGraph;
  49 import org.graalvm.compiler.nodes.ValueNode;
  50 import org.graalvm.compiler.nodes.extended.OpaqueNode;
  51 import org.graalvm.compiler.nodes.extended.ForeignCallNode;
  52 import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext;
  53 import org.graalvm.compiler.nodes.graphbuilderconf.InlineInvokePlugin;
  54 import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver;
  55 import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins;
  56 import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration;
  57 import org.graalvm.compiler.nodes.graphbuilderconf.NodeIntrinsicPluginFactory;
  58 import org.graalvm.compiler.nodes.spi.LoweringTool;
  59 import org.graalvm.compiler.options.OptionValues;
  60 import org.graalvm.compiler.phases.common.CanonicalizerPhase;
  61 import org.graalvm.compiler.phases.common.DeadCodeEliminationPhase;
  62 import org.graalvm.compiler.phases.common.FloatingReadPhase;
  63 import org.graalvm.compiler.phases.common.FrameStateAssignmentPhase;
  64 import org.graalvm.compiler.phases.common.GuardLoweringPhase;
  65 import org.graalvm.compiler.phases.common.LoweringPhase;
  66 import org.graalvm.compiler.phases.tiers.HighTierContext;
  67 import jdk.internal.vm.compiler.word.LocationIdentity;
  68 import org.junit.Assert;
  69 import org.junit.BeforeClass;
  70 import org.junit.Test;


 578             GraalDirectives.deoptimize();
 579         }
 580         return x;
 581     }
 582 
 583     /**
 584      * This is similar to {@link #testNonVoidIntrinsicWithCall()} but has a merge after the call
 585      * which would normally capture the {@link FrameState} but in this case we force the merge to be
 586      * optimized away.
 587      */
 588     @Test
 589     public void testNonVoidIntrinsicWithOptimizedSplit() {
 590         testGraph("nonVoidIntrinsicWithOptimizedSplit");
 591     }
 592 
 593     @SuppressWarnings("try")
 594     private void testGraph(String name) {
 595         StructuredGraph graph = parseEager(name, StructuredGraph.AllowAssumptions.YES);
 596         try (DebugContext.Scope s0 = graph.getDebug().scope(name, graph)) {
 597             for (OpaqueNode node : graph.getNodes().filter(OpaqueNode.class)) {
 598                 node.remove();
 599             }
 600             HighTierContext context = getDefaultHighTierContext();
 601             CanonicalizerPhase canonicalizer = new CanonicalizerPhase();
 602             new LoweringPhase(canonicalizer, LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, context);
 603             new FloatingReadPhase().apply(graph);
 604             canonicalizer.apply(graph, context);
 605             new DeadCodeEliminationPhase().apply(graph);
 606             new GuardLoweringPhase().apply(graph, getDefaultMidTierContext());
 607             new FrameStateAssignmentPhase().apply(graph);
 608         } catch (Throwable e) {
 609             throw graph.getDebug().handle(e);
 610         }
 611     }
 612 
 613     private class DummyInjectionProvider implements NodeIntrinsicPluginFactory.InjectionProvider {
 614         @SuppressWarnings("unchecked")
 615         @Override
 616         public <T> T getInjectedArgument(Class<T> type) {
 617             if (type == ForeignCallsProvider.class) {
 618                 return (T) new ForeignCallsProvider() {


< prev index next >