< prev index next >

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.common/src/org/graalvm/compiler/core/common/alloc/ComputeBlockOrder.java

Print this page




 236     /**
 237      * Skip the loop header block if the loop consists of more than one block and it has only a
 238      * single loop end block.
 239      */
 240     private static <T extends AbstractBlockBase<T>> boolean skipLoopHeader(AbstractBlockBase<T> block) {
 241         return (block.isLoopHeader() && !block.isLoopEnd() && block.getLoop().numBackedges() == 1);
 242     }
 243 
 244     /**
 245      * Checks that the ordering contains the expected number of blocks.
 246      */
 247     private static boolean checkOrder(List<? extends AbstractBlockBase<?>> order, int expectedBlockCount) {
 248         assert order.size() == expectedBlockCount : String.format("Number of blocks in ordering (%d) does not match expected block count (%d)", order.size(), expectedBlockCount);
 249         return true;
 250     }
 251 
 252     /**
 253      * Comparator for sorting blocks based on loop depth and probability.
 254      */
 255     private static class BlockOrderComparator<T extends AbstractBlockBase<T>> implements Comparator<T> {

 256 
 257         @Override
 258         public int compare(T a, T b) {
 259             // Loop blocks before any loop exit block.


 260             int diff = b.getLoopDepth() - a.getLoopDepth();
 261             if (diff != 0) {
 262                 return diff;

 263             }
 264 
 265             // Blocks with high probability before blocks with low probability.
 266             if (a.probability() > b.probability()) {
 267                 return -1;
 268             } else {
 269                 return 1;
 270             }
 271         }
 272     }
 273 }


 236     /**
 237      * Skip the loop header block if the loop consists of more than one block and it has only a
 238      * single loop end block.
 239      */
 240     private static <T extends AbstractBlockBase<T>> boolean skipLoopHeader(AbstractBlockBase<T> block) {
 241         return (block.isLoopHeader() && !block.isLoopEnd() && block.getLoop().numBackedges() == 1);
 242     }
 243 
 244     /**
 245      * Checks that the ordering contains the expected number of blocks.
 246      */
 247     private static boolean checkOrder(List<? extends AbstractBlockBase<?>> order, int expectedBlockCount) {
 248         assert order.size() == expectedBlockCount : String.format("Number of blocks in ordering (%d) does not match expected block count (%d)", order.size(), expectedBlockCount);
 249         return true;
 250     }
 251 
 252     /**
 253      * Comparator for sorting blocks based on loop depth and probability.
 254      */
 255     private static class BlockOrderComparator<T extends AbstractBlockBase<T>> implements Comparator<T> {
 256         private static final double EPSILON = 1E-6;
 257 
 258         @Override
 259         public int compare(T a, T b) {
 260             // Loop blocks before any loop exit block. The only exception are blocks that are
 261             // (almost) impossible to reach.
 262             if (a.probability() > EPSILON && b.probability() > EPSILON) {
 263                 int diff = b.getLoopDepth() - a.getLoopDepth();
 264                 if (diff != 0) {
 265                     return diff;
 266                 }
 267             }
 268 
 269             // Blocks with high probability before blocks with low probability.
 270             if (a.probability() > b.probability()) {
 271                 return -1;
 272             } else {
 273                 return 1;
 274             }
 275         }
 276     }
 277 }
< prev index next >