src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.microbenchmarks/src/org/graalvm/compiler/microbenchmarks/lir/trace/TraceLSRAIntervalBuildingBench.java
branchJDK-8200758-branch
changeset 57069 b8385a806d2b
parent 57068 eb6d315c4e39
parent 52934 8deeb7bba516
child 57070 42783e8e73de
equal deleted inserted replaced
57068:eb6d315c4e39 57069:b8385a806d2b
     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 
       
    24 
       
    25 package org.graalvm.compiler.microbenchmarks.lir.trace;
       
    26 
       
    27 import org.graalvm.compiler.core.common.alloc.RegisterAllocationConfig;
       
    28 import org.graalvm.compiler.core.common.alloc.Trace;
       
    29 import org.graalvm.compiler.core.common.alloc.TraceBuilderResult;
       
    30 import org.graalvm.compiler.lir.alloc.trace.GlobalLivenessAnalysisPhase;
       
    31 import org.graalvm.compiler.lir.alloc.trace.GlobalLivenessInfo;
       
    32 import org.graalvm.compiler.lir.alloc.trace.TraceBuilderPhase;
       
    33 import org.graalvm.compiler.lir.alloc.trace.TraceRegisterAllocationPhase;
       
    34 import org.graalvm.compiler.lir.alloc.trace.lsra.TraceLinearScanLifetimeAnalysisPhase;
       
    35 import org.graalvm.compiler.lir.alloc.trace.lsra.TraceLinearScanLifetimeAnalysisPhase.Analyser;
       
    36 import org.graalvm.compiler.lir.alloc.trace.lsra.TraceLinearScanPhase;
       
    37 import org.graalvm.compiler.lir.alloc.trace.lsra.TraceLinearScanPhase.TraceLinearScan;
       
    38 import org.graalvm.compiler.lir.gen.LIRGenerationResult;
       
    39 import org.graalvm.compiler.lir.gen.LIRGeneratorTool.MoveFactory;
       
    40 import org.graalvm.compiler.lir.phases.AllocationPhase;
       
    41 import org.graalvm.compiler.lir.phases.AllocationPhase.AllocationContext;
       
    42 import org.graalvm.compiler.lir.phases.LIRPhaseSuite;
       
    43 import org.graalvm.compiler.lir.phases.LIRSuites;
       
    44 import org.graalvm.compiler.microbenchmarks.graal.GraalBenchmark;
       
    45 import org.graalvm.compiler.microbenchmarks.lir.GraalCompilerState;
       
    46 import org.graalvm.compiler.options.OptionValues;
       
    47 import org.openjdk.jmh.annotations.Benchmark;
       
    48 import org.openjdk.jmh.annotations.Level;
       
    49 import org.openjdk.jmh.annotations.Param;
       
    50 import org.openjdk.jmh.annotations.Setup;
       
    51 
       
    52 import jdk.vm.ci.code.TargetDescription;
       
    53 
       
    54 /**
       
    55  * Benchmarks {@link TraceLinearScan TraceRA} {@link TraceLinearScanLifetimeAnalysisPhase lifetime
       
    56  * analysis phase}.
       
    57  */
       
    58 public class TraceLSRAIntervalBuildingBench extends GraalBenchmark {
       
    59 
       
    60     private static class DummyTraceAllocatorPhase extends AllocationPhase {
       
    61         private TraceLinearScan allocator;
       
    62 
       
    63         @Override
       
    64         @SuppressWarnings("try")
       
    65         protected void run(TargetDescription target, LIRGenerationResult lirGenRes, AllocationContext context) {
       
    66             MoveFactory spillMoveFactory = context.spillMoveFactory;
       
    67             RegisterAllocationConfig registerAllocationConfig = context.registerAllocationConfig;
       
    68             TraceBuilderResult resultTraces = context.contextLookup(TraceBuilderResult.class);
       
    69             GlobalLivenessInfo livenessInfo = context.contextLookup(GlobalLivenessInfo.class);
       
    70             assert livenessInfo != null;
       
    71             TraceLinearScanPhase phase = new TraceLinearScanPhase(target, lirGenRes, spillMoveFactory, registerAllocationConfig, resultTraces, false, null, livenessInfo);
       
    72             for (Trace trace : resultTraces.getTraces()) {
       
    73                 allocator = phase.createAllocator(trace);
       
    74                 Analyser a = new TraceLinearScanLifetimeAnalysisPhase.Analyser(allocator, resultTraces);
       
    75                 a.analyze();
       
    76             }
       
    77         }
       
    78     }
       
    79 
       
    80     public abstract static class AllocationState extends GraalCompilerState {
       
    81 
       
    82         private static final DummyTraceAllocatorPhase LTA_PHASE = new DummyTraceAllocatorPhase();
       
    83         private static final GlobalLivenessAnalysisPhase LIVENESS_ANALYSIS_PHASE = new GlobalLivenessAnalysisPhase();
       
    84         private static final TraceBuilderPhase TRACE_BUILDER_PHASE = new TraceBuilderPhase();
       
    85 
       
    86         private AllocationContext allocationContext;
       
    87 
       
    88         @Override
       
    89         protected LIRSuites getLIRSuites() {
       
    90             LIRSuites ls = super.getLIRSuites();
       
    91             LIRPhaseSuite<AllocationContext> allocationStage = new LIRPhaseSuite<>();
       
    92             allocationStage.appendPhase(TRACE_BUILDER_PHASE);
       
    93             allocationStage.appendPhase(LIVENESS_ANALYSIS_PHASE);
       
    94             return new LIRSuites(ls.getPreAllocationOptimizationStage(), allocationStage, ls.getPostAllocationOptimizationStage());
       
    95         }
       
    96 
       
    97         @Override
       
    98         protected OptionValues getGraphOptions() {
       
    99             return new OptionValues(super.getGraphOptions(), TraceRegisterAllocationPhase.Options.TraceRAuseInterTraceHints, false);
       
   100         }
       
   101 
       
   102         @Setup(Level.Trial)
       
   103         public void setup() {
       
   104             initializeMethod();
       
   105             prepareRequest();
       
   106             emitFrontEnd();
       
   107             generateLIR();
       
   108             preAllocationStage();
       
   109             // context for all allocation phases
       
   110             allocationContext = createAllocationContext();
       
   111             applyLIRPhase(TRACE_BUILDER_PHASE, allocationContext);
       
   112             applyLIRPhase(LIVENESS_ANALYSIS_PHASE, allocationContext);
       
   113         }
       
   114 
       
   115         public TraceLinearScan compile() {
       
   116             applyLIRPhase(LTA_PHASE, allocationContext);
       
   117             return LTA_PHASE.allocator;
       
   118         }
       
   119 
       
   120     }
       
   121 
       
   122     public static class State extends AllocationState {
       
   123         @MethodDescString @Param({
       
   124                         "java.lang.String#equals",
       
   125                         "java.util.HashMap#computeIfAbsent"
       
   126         }) public String method;
       
   127     }
       
   128 
       
   129     @Benchmark
       
   130     public TraceLinearScan buildIntervals(State s) {
       
   131         return s.compile();
       
   132     }
       
   133 }