src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.loop/src/org/graalvm/compiler/loop/LoopsData.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File hotspot Sdiff src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.loop/src/org/graalvm/compiler/loop

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

Print this page




  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 package org.graalvm.compiler.loop;
  24 
  25 import java.util.ArrayList;
  26 import java.util.Collection;
  27 import java.util.LinkedList;
  28 import java.util.List;
  29 
  30 import org.graalvm.compiler.core.common.cfg.Loop;
  31 import org.graalvm.compiler.debug.Debug;
  32 import org.graalvm.compiler.debug.Debug.Scope;
  33 import org.graalvm.compiler.nodes.LoopBeginNode;
  34 import org.graalvm.compiler.nodes.StructuredGraph;
  35 import org.graalvm.compiler.nodes.ValueNode;
  36 import org.graalvm.compiler.nodes.cfg.Block;
  37 import org.graalvm.compiler.nodes.cfg.ControlFlowGraph;
  38 import org.graalvm.util.Equivalence;
  39 import org.graalvm.util.EconomicMap;
  40 import org.graalvm.util.EconomicSet;

  41 
  42 public class LoopsData {
  43     private final EconomicMap<LoopBeginNode, LoopEx> loopBeginToEx = EconomicMap.create(Equivalence.IDENTITY);
  44     private final ControlFlowGraph cfg;
  45     private final List<LoopEx> loops;
  46 
  47     @SuppressWarnings("try")
  48     public LoopsData(final StructuredGraph graph) {
  49         try (Scope s = Debug.scope("ControlFlowGraph")) {

  50             cfg = ControlFlowGraph.compute(graph, true, true, true, true);
  51         } catch (Throwable e) {
  52             throw Debug.handle(e);
  53         }
  54         assert checkLoopOrder(cfg.getLoops());
  55         loops = new ArrayList<>(cfg.getLoops().size());
  56         for (Loop<Block> loop : cfg.getLoops()) {
  57             LoopEx ex = new LoopEx(loop, this);
  58             loops.add(ex);
  59             loopBeginToEx.put(ex.loopBegin(), ex);
  60         }
  61     }
  62 
  63     /**
  64      * Checks that loops are ordered such that outer loops appear first.
  65      */
  66     private static boolean checkLoopOrder(Iterable<Loop<Block>> loops) {
  67         EconomicSet<Loop<Block>> seen = EconomicSet.create(Equivalence.IDENTITY);
  68         for (Loop<Block> loop : loops) {
  69             if (loop.getParent() != null && !seen.contains(loop.getParent())) {
  70                 return false;
  71             }
  72             seen.add(loop);




  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 package org.graalvm.compiler.loop;
  24 
  25 import java.util.ArrayList;
  26 import java.util.Collection;
  27 import java.util.LinkedList;
  28 import java.util.List;
  29 
  30 import org.graalvm.compiler.core.common.cfg.Loop;
  31 import org.graalvm.compiler.debug.DebugContext;

  32 import org.graalvm.compiler.nodes.LoopBeginNode;
  33 import org.graalvm.compiler.nodes.StructuredGraph;
  34 import org.graalvm.compiler.nodes.ValueNode;
  35 import org.graalvm.compiler.nodes.cfg.Block;
  36 import org.graalvm.compiler.nodes.cfg.ControlFlowGraph;

  37 import org.graalvm.util.EconomicMap;
  38 import org.graalvm.util.EconomicSet;
  39 import org.graalvm.util.Equivalence;
  40 
  41 public class LoopsData {
  42     private final EconomicMap<LoopBeginNode, LoopEx> loopBeginToEx = EconomicMap.create(Equivalence.IDENTITY);
  43     private final ControlFlowGraph cfg;
  44     private final List<LoopEx> loops;
  45 
  46     @SuppressWarnings("try")
  47     public LoopsData(final StructuredGraph graph) {
  48         DebugContext debug = graph.getDebug();
  49         try (DebugContext.Scope s = debug.scope("ControlFlowGraph")) {
  50             cfg = ControlFlowGraph.compute(graph, true, true, true, true);
  51         } catch (Throwable e) {
  52             throw debug.handle(e);
  53         }
  54         assert checkLoopOrder(cfg.getLoops());
  55         loops = new ArrayList<>(cfg.getLoops().size());
  56         for (Loop<Block> loop : cfg.getLoops()) {
  57             LoopEx ex = new LoopEx(loop, this);
  58             loops.add(ex);
  59             loopBeginToEx.put(ex.loopBegin(), ex);
  60         }
  61     }
  62 
  63     /**
  64      * Checks that loops are ordered such that outer loops appear first.
  65      */
  66     private static boolean checkLoopOrder(Iterable<Loop<Block>> loops) {
  67         EconomicSet<Loop<Block>> seen = EconomicSet.create(Equivalence.IDENTITY);
  68         for (Loop<Block> loop : loops) {
  69             if (loop.getParent() != null && !seen.contains(loop.getParent())) {
  70                 return false;
  71             }
  72             seen.add(loop);


src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.loop/src/org/graalvm/compiler/loop/LoopsData.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File