diff graal/GraalCompiler/src/com/sun/c1x/ir/ComputeLinearScanOrder.java @ 2707:7ed72769d51a

exception handling related changes: * changed blockPredecessors to list of Instructions, instead of Blocks * removed explicit predecessor management in BlockBegin, now using predecessors from Graph structure * replaced generated LIR exception entries with exception dispatch chains in IR * added Unwind and ExceptionDispatch instructions * removed ExceptionEntry flag in BlockBegin and all code depending on it * removed exceptionHandler list from Instruction, replaced by exception Edge on Invoke and Throw * replaced list of ExceptionHandlers with single exception edge in debug info misc: * changed GraphvizPrinter layout (smaller ports on large nodes) * removed defunct run config
author Lukas Stadler <lukas.stadler@jku.at>
date Wed, 18 May 2011 18:09:20 +0200
parents 6ab73784566a
children 4272b7af2d17
line wrap: on
line diff
--- a/graal/GraalCompiler/src/com/sun/c1x/ir/ComputeLinearScanOrder.java	Fri May 13 17:09:20 2011 -0700
+++ b/graal/GraalCompiler/src/com/sun/c1x/ir/ComputeLinearScanOrder.java	Wed May 18 18:09:20 2011 +0200
@@ -140,7 +140,7 @@
      * 3. Number loop header blocks.
      * 4. Create a list with all loop end blocks.
      */
-    private void countEdges(BlockBegin cur, BlockBegin parent) {
+    private void countEdges(final BlockBegin cur, BlockBegin parent) {
         if (C1XOptions.TraceLinearScanLevel >= 3) {
             TTY.println("Counting edges for block B%d%s", cur.blockID, parent == null ? "" : " coming from B" + parent.blockID);
         }
@@ -158,15 +158,6 @@
 
             parent.setBlockFlag(BlockBegin.BlockFlag.LinearScanLoopEnd);
 
-            // When a loop header is also the start of an exception handler, then the backward branch is
-            // an exception edge. Because such edges are usually critical edges which cannot be split, the
-            // loop must be excluded here from processing.
-            if (cur.checkBlockFlag(BlockBegin.BlockFlag.ExceptionEntry)) {
-                // Make sure that dominators are correct in this weird situation
-                iterativeDominators = true;
-                return;
-            }
-
             loopEndBlocks.add(parent);
             return;
         }
@@ -186,13 +177,11 @@
         setActive(cur);
 
         // recursive call for all successors
-        int i;
-        for (i = cur.numberOfSux() - 1; i >= 0; i--) {
-            countEdges(cur.suxAt(i), cur);
-        }
-        for (i = cur.numberOfExceptionHandlers() - 1; i >= 0; i--) {
-            countEdges(cur.exceptionHandlerAt(i), cur);
-        }
+        cur.allSuccessorsDo(true, new BlockClosure() {
+            public void apply(BlockBegin block) {
+                countEdges(block, cur);
+            }
+        });
 
         clearActive(cur);
 
@@ -250,7 +239,7 @@
                 // recursive processing of all predecessors ends when start block of loop is reached
                 if (cur != loopStart) {
                     for (int j = cur.numberOfPreds() - 1; j >= 0; j--) {
-                        BlockBegin pred = cur.predAt(j).begin();
+                        BlockBegin pred = cur.predAt(j).block();
 
                         if (!isBlockInLoop(loopIdx, pred)) {
                             // this predecessor has not been processed yet, so add it to work list
@@ -319,12 +308,11 @@
                 cur.setLoopIndex(minLoopIdx);
 
                 // append all unvisited successors to work list
-                for (i = cur.numberOfSux() - 1; i >= 0; i--) {
-                    workList.add(cur.suxAt(i));
-                }
-                for (i = cur.numberOfExceptionHandlers() - 1; i >= 0; i--) {
-                    workList.add(cur.exceptionHandlerAt(i));
-                }
+                cur.allSuccessorsDo(true, new BlockClosure() {
+                    public void apply(BlockBegin block) {
+                        workList.add(block);
+                    }
+                });
             }
         } while (!workList.isEmpty());
     }
@@ -352,12 +340,7 @@
             if (C1XOptions.TraceLinearScanLevel >= 4) {
                 TTY.println("DOM: initializing dominator of B%d to B%d", cur.blockID, parent.blockID);
             }
-            if (cur.isExceptionEntry()) {
-                assert parent.dominator() != null;
-                cur.setDominator(parent.dominator());
-            } else {
-                cur.setDominator(parent);
-            }
+            cur.setDominator(parent);
 
         } else if (!(cur.checkBlockFlag(BlockBegin.BlockFlag.LinearScanLoopHeader) && parent.checkBlockFlag(BlockBegin.BlockFlag.LinearScanLoopEnd))) {
             if (C1XOptions.TraceLinearScanLevel >= 4) {
@@ -412,10 +395,10 @@
         }
         curBit--;
 
-        // exceptions handlers are added as late as possible
-        if (!cur.checkBlockFlag(BlockBegin.BlockFlag.ExceptionEntry)) {
-            weight |= (1 << curBit);
-        }
+//        // exceptions handlers are added as late as possible
+//        if (!cur.checkBlockFlag(BlockBegin.BlockFlag.ExceptionEntry)) {
+//            weight |= (1 << curBit);
+//        }
         curBit--;
 
         // guarantee that weight is > 0
@@ -505,27 +488,17 @@
         }
 
         do {
-            BlockBegin cur = workList.remove(workList.size() - 1);
+            final BlockBegin cur = workList.remove(workList.size() - 1);
             appendBlock(cur);
 
-            int i;
-            int numSux = cur.numberOfSux();
-            // changed loop order to get "intuitive" order of if- and else-blocks
-            for (i = 0; i < numSux; i++) {
-                BlockBegin sux = cur.suxAt(i);
-                computeDominator(sux, cur);
-                if (readyForProcessing(sux)) {
-                    sortIntoWorkList(sux);
+            cur.allSuccessorsDo(false, new BlockClosure() {
+                public void apply(BlockBegin block) {
+                    computeDominator(block, cur);
+                    if (readyForProcessing(block)) {
+                        sortIntoWorkList(block);
+                    }
                 }
-            }
-            numSux = cur.numberOfExceptionHandlers();
-            for (i = 0; i < numSux; i++) {
-                BlockBegin sux = cur.exceptionHandlerAt(i);
-                computeDominator(sux, cur);
-                if (readyForProcessing(sux)) {
-                    sortIntoWorkList(sux);
-                }
-            }
+            });
         } while (workList.size() > 0);
     }
 
@@ -539,17 +512,11 @@
             BlockBegin block = linearScanOrder.get(i);
 
             assert block.numberOfPreds() > 0;
-            BlockBegin dominator = block.predAt(0).begin();
-            if (block.isExceptionEntry()) {
-                dominator = dominator.dominator();
-            }
+            BlockBegin dominator = block.predAt(0).block();
 
             int numPreds = block.numberOfPreds();
             for (int j = 1; j < numPreds; j++) {
-                BlockBegin curPred = block.predAt(j).begin();
-                if (block.isExceptionEntry()) {
-                    curPred = curPred.dominator();
-                }
+                BlockBegin curPred = block.predAt(j).block();
                 dominator = commonDominator(dominator, curPred);
             }
 
@@ -601,7 +568,6 @@
             for (BlockBegin cur : linearScanOrder) {
                 TTY.print(String.format("%4d: B%02d    loop: %2d  depth: %2d", cur.linearScanNumber(), cur.blockID, cur.loopIndex(), cur.loopDepth()));
 
-                TTY.print(cur.isExceptionEntry() ? " ex" : "   ");
                 TTY.print(cur.isCriticalEdgeSplit() ? " ce" : "   ");
                 TTY.print(cur.checkBlockFlag(BlockBegin.BlockFlag.LinearScanLoopHeader) ? " lh" : "   ");
                 TTY.print(cur.checkBlockFlag(BlockBegin.BlockFlag.LinearScanLoopEnd) ? " le" : "   ");
@@ -615,7 +581,7 @@
                 if (cur.numberOfPreds() > 0) {
                     TTY.print("    preds: ");
                     for (int j = 0; j < cur.numberOfPreds(); j++) {
-                        BlockBegin pred = cur.predAt(j).begin();
+                        BlockBegin pred = cur.predAt(j).block();
                         TTY.print("B%d ", pred.blockID);
                     }
                 }
@@ -626,13 +592,6 @@
                         TTY.print("B%d ", sux.blockID);
                     }
                 }
-                if (cur.numberOfExceptionHandlers() > 0) {
-                    TTY.print("    ex: ");
-                    for (int j = 0; j < cur.numberOfExceptionHandlers(); j++) {
-                        BlockBegin ex = cur.exceptionHandlerAt(j);
-                        TTY.print("B%d ", ex.blockID);
-                    }
-                }
                 TTY.println();
             }
         }
@@ -666,8 +625,8 @@
                 }
             }
 
-            for (BlockEnd pred : cur.blockPredecessors()) {
-                BlockBegin begin = pred.begin();
+            for (Instruction pred : cur.blockPredecessors()) {
+                BlockBegin begin = pred.block();
                 assert begin.linearScanNumber() >= 0 && begin.linearScanNumber() == linearScanOrder.indexOf(begin) : "incorrect linearScanNumber";
                 if (!cur.checkBlockFlag(BlockBegin.BlockFlag.LinearScanLoopHeader)) {
                     assert cur.linearScanNumber() > begin.linearScanNumber() : "invalid order";
@@ -685,7 +644,7 @@
             } else {
                 assert cur.dominator() != null : "all but first block must have dominator";
             }
-            assert cur.numberOfPreds() != 1 || cur.dominator() == cur.predAt(0).begin() || cur.isExceptionEntry() : "Single predecessor must also be dominator";
+            assert cur.numberOfPreds() != 1 || cur.dominator() == cur.predAt(0).block() : "Single predecessor must also be dominator";
         }
 
         // check that all loops are continuous