src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.loop.phases/src/org/graalvm/compiler/loop/phases/LoopFullUnrollPhase.java
branchdatagramsocketimpl-branch
changeset 58678 9cf78a70fa4f
parent 52910 583fd71c47d6
child 58679 9c3209ff7550
equal deleted inserted replaced
58677:13588c901957 58678:9cf78a70fa4f
     1 /*
     1 /*
     2  * Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     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
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
    22  */
    22  */
    23 
    23 
    24 
    24 
    25 package org.graalvm.compiler.loop.phases;
    25 package org.graalvm.compiler.loop.phases;
    26 
    26 
       
    27 import org.graalvm.compiler.core.common.GraalOptions;
    27 import org.graalvm.compiler.debug.CounterKey;
    28 import org.graalvm.compiler.debug.CounterKey;
    28 import org.graalvm.compiler.debug.DebugContext;
    29 import org.graalvm.compiler.debug.DebugContext;
    29 import org.graalvm.compiler.loop.LoopEx;
    30 import org.graalvm.compiler.loop.LoopEx;
    30 import org.graalvm.compiler.loop.LoopPolicies;
    31 import org.graalvm.compiler.loop.LoopPolicies;
    31 import org.graalvm.compiler.loop.LoopsData;
    32 import org.graalvm.compiler.loop.LoopsData;
    32 import org.graalvm.compiler.nodes.StructuredGraph;
    33 import org.graalvm.compiler.nodes.StructuredGraph;
       
    34 import org.graalvm.compiler.nodes.spi.CoreProviders;
    33 import org.graalvm.compiler.phases.common.CanonicalizerPhase;
    35 import org.graalvm.compiler.phases.common.CanonicalizerPhase;
    34 import org.graalvm.compiler.phases.tiers.PhaseContext;
       
    35 
    36 
    36 public class LoopFullUnrollPhase extends LoopPhase<LoopPolicies> {
    37 public class LoopFullUnrollPhase extends LoopPhase<LoopPolicies> {
    37 
    38 
    38     private static final CounterKey FULLY_UNROLLED_LOOPS = DebugContext.counter("FullUnrolls");
    39     private static final CounterKey FULLY_UNROLLED_LOOPS = DebugContext.counter("FullUnrolls");
    39     private final CanonicalizerPhase canonicalizer;
    40     private final CanonicalizerPhase canonicalizer;
    42         super(policies);
    43         super(policies);
    43         this.canonicalizer = canonicalizer;
    44         this.canonicalizer = canonicalizer;
    44     }
    45     }
    45 
    46 
    46     @Override
    47     @Override
    47     protected void run(StructuredGraph graph, PhaseContext context) {
    48     protected void run(StructuredGraph graph, CoreProviders context) {
    48         DebugContext debug = graph.getDebug();
    49         if (GraalOptions.FullUnroll.getValue(graph.getOptions())) {
    49         if (graph.hasLoops()) {
    50             DebugContext debug = graph.getDebug();
    50             boolean peeled;
    51             if (graph.hasLoops()) {
    51             do {
    52                 boolean peeled;
    52                 peeled = false;
    53                 do {
    53                 final LoopsData dataCounted = new LoopsData(graph);
    54                     peeled = false;
    54                 dataCounted.detectedCountedLoops();
    55                     final LoopsData dataCounted = new LoopsData(graph);
    55                 for (LoopEx loop : dataCounted.countedLoops()) {
    56                     dataCounted.detectedCountedLoops();
    56                     if (getPolicies().shouldFullUnroll(loop)) {
    57                     for (LoopEx loop : dataCounted.countedLoops()) {
    57                         debug.log("FullUnroll %s", loop);
    58                         if (getPolicies().shouldFullUnroll(loop)) {
    58                         LoopTransformations.fullUnroll(loop, context, canonicalizer);
    59                             debug.log("FullUnroll %s", loop);
    59                         FULLY_UNROLLED_LOOPS.increment(debug);
    60                             LoopTransformations.fullUnroll(loop, context, canonicalizer);
    60                         debug.dump(DebugContext.DETAILED_LEVEL, graph, "FullUnroll %s", loop);
    61                             FULLY_UNROLLED_LOOPS.increment(debug);
    61                         peeled = true;
    62                             debug.dump(DebugContext.DETAILED_LEVEL, graph, "FullUnroll %s", loop);
    62                         break;
    63                             peeled = true;
       
    64                             break;
       
    65                         }
    63                     }
    66                     }
    64                 }
    67                     dataCounted.deleteUnusedNodes();
    65                 dataCounted.deleteUnusedNodes();
    68                 } while (peeled);
    66             } while (peeled);
    69             }
    67         }
    70         }
    68     }
    71     }
    69 
    72 
    70     @Override
    73     @Override
    71     public boolean checkContract() {
    74     public boolean checkContract() {