< prev index next >

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.loop/src/org/graalvm/compiler/loop/LoopFragmentWhole.java

Print this page




   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.loop;
  26 
  27 import jdk.internal.vm.compiler.collections.EconomicSet;
  28 import org.graalvm.compiler.core.common.cfg.Loop;
  29 import org.graalvm.compiler.debug.DebugContext;
  30 import org.graalvm.compiler.graph.Graph;
  31 import org.graalvm.compiler.graph.Graph.DuplicationReplacement;
  32 import org.graalvm.compiler.graph.Node;
  33 import org.graalvm.compiler.graph.NodeBitMap;
  34 import org.graalvm.compiler.nodes.EndNode;
  35 import org.graalvm.compiler.nodes.FixedNode;
  36 import org.graalvm.compiler.nodes.LoopBeginNode;
  37 import org.graalvm.compiler.nodes.LoopExitNode;
  38 import org.graalvm.compiler.nodes.StructuredGraph;
  39 import org.graalvm.compiler.nodes.ValueNode;
  40 import org.graalvm.compiler.nodes.cfg.Block;
  41 
  42 public class LoopFragmentWhole extends LoopFragment {
  43 
  44     public LoopFragmentWhole(LoopEx loop) {
  45         super(loop);
  46     }
  47 
  48     public LoopFragmentWhole(LoopFragmentWhole original) {
  49         super(null, original);
  50     }
  51 
  52     @Override
  53     public LoopFragmentWhole duplicate() {
  54         LoopFragmentWhole loopFragmentWhole = new LoopFragmentWhole(this);
  55         loopFragmentWhole.reify();
  56         return loopFragmentWhole;
  57     }
  58 
  59     private void reify() {
  60         assert this.isDuplicate();
  61 
  62         patchNodes(null);
  63 
  64         mergeEarlyExits();
  65     }
  66 
  67     @Override
  68     public NodeBitMap nodes() {
  69         if (nodes == null) {
  70             Loop<Block> loop = loop().loop();
  71             nodes = LoopFragment.computeNodes(graph(), LoopFragment.toHirBlocks(loop.getBlocks()), LoopFragment.toHirExits(loop.getExits()));
  72         }
  73         return nodes;
  74     }
  75 
  76     @Override
  77     protected ValueNode prim(ValueNode b) {
  78         return getDuplicatedNode(b);
  79     }
  80 
  81     @Override
  82     protected DuplicationReplacement getDuplicationReplacement() {
  83         final FixedNode entry = loop().entryPoint();
  84         final Graph graph = this.graph();
  85         return new DuplicationReplacement() {
  86 
  87             private EndNode endNode;
  88 
  89             @Override
  90             public Node replacement(Node o) {
  91                 if (o == entry) {
  92                     if (endNode == null) {
  93                         endNode = graph.add(new EndNode());
  94                     }
  95                     return endNode;
  96                 }
  97                 return o;
  98             }
  99         };
 100     }
 101 
 102     public FixedNode entryPoint() {
 103         if (isDuplicate()) {
 104             LoopBeginNode newLoopBegin = getDuplicatedNode(original().loop().loopBegin());
 105             return newLoopBegin.forwardEnd();
 106         }
 107         return loop().entryPoint();
 108     }
 109 
 110     @Override
 111     protected void finishDuplication() {
 112         // TODO (gd) ?
 113     }
 114 
 115     void cleanupLoopExits() {
 116         LoopBeginNode loopBegin = original().loop().loopBegin();
 117         assert nodes == null || nodes.contains(loopBegin);
 118         StructuredGraph graph = loopBegin.graph();
 119         if (graph.getGuardsStage() == StructuredGraph.GuardsStage.AFTER_FSA) {
 120             // After FrameStateAssignment ControlFlowGraph treats loop exits differently which means
 121             // that the LoopExitNodes can be in a block which post dominates the true loop exit. For
 122             // cloning to work right they must agree.
 123             EconomicSet<LoopExitNode> exits = EconomicSet.create();
 124             for (Block exitBlock : original().loop().loop().getExits()) {
 125                 LoopExitNode exitNode = exitBlock.getLoopExit();
 126                 if (exitNode == null) {
 127                     exitNode = graph.add(new LoopExitNode(loopBegin));
 128                     graph.addAfterFixed(exitBlock.getBeginNode(), exitNode);
 129                     if (nodes != null) {
 130                         nodes.mark(exitNode);
 131                     }
 132                     graph.getDebug().dump(DebugContext.VERBOSE_LEVEL, graph, "Adjusting loop exit node for %s", loopBegin);
 133                 }
 134                 exits.add(exitNode);
 135             }
 136             for (LoopExitNode exitNode : loopBegin.loopExits()) {
 137                 if (!exits.contains(exitNode)) {
 138                     if (nodes != null) {
 139                         nodes.clear(exitNode);
 140                     }
 141                     graph.removeFixed(exitNode);
 142                 }
 143             }
 144         }
 145 
 146     }
 147 
 148     @Override
 149     protected void beforeDuplication() {
 150         cleanupLoopExits();
 151     }
 152 
 153     @Override
 154     public void insertBefore(LoopEx loop) {
 155         // TODO Auto-generated method stub
 156 
 157     }
 158 }


   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.loop;
  26 

  27 import org.graalvm.compiler.core.common.cfg.Loop;

  28 import org.graalvm.compiler.graph.Graph;
  29 import org.graalvm.compiler.graph.Graph.DuplicationReplacement;
  30 import org.graalvm.compiler.graph.Node;
  31 import org.graalvm.compiler.graph.NodeBitMap;
  32 import org.graalvm.compiler.nodes.EndNode;
  33 import org.graalvm.compiler.nodes.FixedNode;
  34 import org.graalvm.compiler.nodes.LoopBeginNode;


  35 import org.graalvm.compiler.nodes.ValueNode;
  36 import org.graalvm.compiler.nodes.cfg.Block;
  37 
  38 public class LoopFragmentWhole extends LoopFragment {
  39 
  40     public LoopFragmentWhole(LoopEx loop) {
  41         super(loop);
  42     }
  43 
  44     public LoopFragmentWhole(LoopFragmentWhole original) {
  45         super(null, original);
  46     }
  47 
  48     @Override
  49     public LoopFragmentWhole duplicate() {
  50         LoopFragmentWhole loopFragmentWhole = new LoopFragmentWhole(this);
  51         loopFragmentWhole.reify();
  52         return loopFragmentWhole;
  53     }
  54 
  55     private void reify() {
  56         assert this.isDuplicate();
  57 
  58         patchNodes(null);
  59 
  60         mergeEarlyExits();
  61     }
  62 
  63     @Override
  64     public NodeBitMap nodes() {
  65         if (nodes == null) {
  66             Loop<Block> loop = loop().loop();
  67             nodes = LoopFragment.computeNodes(graph(), LoopFragment.toHirBlocks(loop.getBlocks()), LoopFragment.toHirBlocks(loop.getLoopExits()));
  68         }
  69         return nodes;
  70     }
  71 
  72     @Override
  73     protected ValueNode prim(ValueNode b) {
  74         return getDuplicatedNode(b);
  75     }
  76 
  77     @Override
  78     protected DuplicationReplacement getDuplicationReplacement() {
  79         final FixedNode entry = loop().entryPoint();
  80         final Graph graph = this.graph();
  81         return new DuplicationReplacement() {
  82 
  83             private EndNode endNode;
  84 
  85             @Override
  86             public Node replacement(Node o) {
  87                 if (o == entry) {
  88                     if (endNode == null) {
  89                         endNode = graph.add(new EndNode());
  90                     }
  91                     return endNode;
  92                 }
  93                 return o;
  94             }
  95         };
  96     }
  97 
  98     public FixedNode entryPoint() {
  99         if (isDuplicate()) {
 100             LoopBeginNode newLoopBegin = getDuplicatedNode(original().loop().loopBegin());
 101             return newLoopBegin.forwardEnd();
 102         }
 103         return loop().entryPoint();
 104     }
 105 
 106     @Override






































 107     protected void beforeDuplication() {
 108         // nothing to do
 109     }
 110 
 111     @Override
 112     public void insertBefore(LoopEx loop) {
 113         // TODO Auto-generated method stub
 114 
 115     }
 116 }
< prev index next >