Mercurial > hg > graal-compiler
annotate graal/GraalCompiler/src/com/sun/c1x/ir/ComputeLinearScanOrder.java @ 2833:1cd59ca9ac86
Removed Throw HIR instruction. Removed special handling for exceptions in register allocator.
author | Thomas Wuerthinger <thomas@wuerthinger.net> |
---|---|
date | Tue, 31 May 2011 13:30:23 +0200 |
parents | 775c31be565c |
children | 9b8c194c1b1f |
rev | line source |
---|---|
2507
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
1 /* |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
2 * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved. |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
4 * |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
8 * |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
13 * accompanied this code). |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
14 * |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
18 * |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
21 * questions. |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
22 */ |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
23 |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
24 package com.sun.c1x.ir; |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
25 |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
26 import java.util.*; |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
27 |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
28 import com.sun.c1x.*; |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
29 import com.sun.c1x.debug.*; |
2778
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
30 import com.sun.c1x.lir.*; |
2507
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
31 import com.sun.c1x.util.*; |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
32 import com.sun.cri.ci.*; |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
33 |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
34 public final class ComputeLinearScanOrder { |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
35 |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
36 private final int maxBlockId; // the highest blockId of a block |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
37 private int numBlocks; // total number of blocks (smaller than maxBlockId) |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
38 private int numLoops; // total number of loops |
2778
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
39 private boolean iterativeDominators; // method requires iterative computation of dominators |
2507
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
40 |
2778
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
41 List<LIRBlock> linearScanOrder; // the resulting list of blocks in correct order |
2507
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
42 |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
43 final CiBitMap visitedBlocks; // used for recursive processing of blocks |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
44 final CiBitMap activeBlocks; // used for recursive processing of blocks |
2778
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
45 final CiBitMap dominatorBlocks; // temporary BitMap used for computation of dominator |
2507
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
46 final int[] forwardBranches; // number of incoming forward branches for each block |
2778
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
47 final List<LIRBlock> loopEndBlocks; // list of all loop end blocks collected during countEdges |
2507
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
48 BitMap2D loopMap; // two-dimensional bit set: a bit is set if a block is contained in a loop |
2778
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
49 final List<LIRBlock> workList; // temporary list (used in markLoops and computeOrder) |
2507
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
50 |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
51 // accessors for visitedBlocks and activeBlocks |
2778
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
52 void initVisited() { |
2507
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
53 activeBlocks.clearAll(); |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
54 visitedBlocks.clearAll(); |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
55 } |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
56 |
2778
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
57 boolean isVisited(LIRBlock b) { |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
58 return visitedBlocks.get(b.blockID()); |
2507
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
59 } |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
60 |
2778
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
61 boolean isActive(LIRBlock b) { |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
62 return activeBlocks.get(b.blockID()); |
2507
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
63 } |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
64 |
2778
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
65 void setVisited(LIRBlock b) { |
2507
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
66 assert !isVisited(b) : "already set"; |
2778
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
67 visitedBlocks.set(b.blockID()); |
2507
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
68 } |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
69 |
2778
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
70 void setActive(LIRBlock b) { |
2507
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
71 assert !isActive(b) : "already set"; |
2778
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
72 activeBlocks.set(b.blockID()); |
2507
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
73 } |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
74 |
2778
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
75 void clearActive(LIRBlock b) { |
2507
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
76 assert isActive(b) : "not already"; |
2778
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
77 activeBlocks.clear(b.blockID()); |
2507
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
78 } |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
79 |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
80 // accessors for forwardBranches |
2778
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
81 void incForwardBranches(LIRBlock b) { |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
82 forwardBranches[b.blockID()]++; |
2507
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
83 } |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
84 |
2778
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
85 int decForwardBranches(LIRBlock b) { |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
86 return --forwardBranches[b.blockID()]; |
2507
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
87 } |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
88 |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
89 // accessors for loopMap |
2778
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
90 boolean isBlockInLoop(int loopIdx, LIRBlock b) { |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
91 return loopMap.at(loopIdx, b.blockID()); |
2507
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
92 } |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
93 |
2778
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
94 void setBlockInLoop(int loopIdx, LIRBlock b) { |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
95 loopMap.setBit(loopIdx, b.blockID()); |
2507
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
96 } |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
97 |
2778
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
98 void clearBlockInLoop(int loopIdx, int blockId) { |
2507
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
99 loopMap.clearBit(loopIdx, blockId); |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
100 } |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
101 |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
102 // accessors for final result |
2778
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
103 public List<LIRBlock> linearScanOrder() { |
2507
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
104 return linearScanOrder; |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
105 } |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
106 |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
107 public int numLoops() { |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
108 return numLoops; |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
109 } |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
110 |
2778
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
111 public ComputeLinearScanOrder(int maxBlockId, LIRBlock startBlock) { |
2507
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
112 |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
113 this.maxBlockId = maxBlockId; |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
114 visitedBlocks = new CiBitMap(maxBlockId); |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
115 activeBlocks = new CiBitMap(maxBlockId); |
2778
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
116 dominatorBlocks = new CiBitMap(maxBlockId); |
2507
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
117 forwardBranches = new int[maxBlockId]; |
2778
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
118 loopEndBlocks = new ArrayList<LIRBlock>(8); |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
119 workList = new ArrayList<LIRBlock>(8); |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
120 |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
121 splitCriticalEdges(); |
2507
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
122 |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
123 countEdges(startBlock, null); |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
124 |
2778
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
125 if (numLoops > 0) { |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
126 markLoops(); |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
127 clearNonNaturalLoops(startBlock); |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
128 assignLoopDepth(startBlock); |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
129 } |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
130 |
2507
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
131 computeOrder(startBlock); |
2778
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
132 |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
133 printBlocks(); |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
134 assert verify(); |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
135 } |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
136 |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
137 void splitCriticalEdges() { |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
138 // TODO: move critical edge splitting from IR to here |
2507
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
139 } |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
140 |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
141 /** |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
142 * Traverses the CFG to analyze block and edge info. The analysis performed is: |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
143 * |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
144 * 1. Count of total number of blocks. |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
145 * 2. Count of all incoming edges and backward incoming edges. |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
146 * 3. Number loop header blocks. |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
147 * 4. Create a list with all loop end blocks. |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
148 */ |
2778
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
149 void countEdges(LIRBlock cur, LIRBlock parent) { |
2507
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
150 if (C1XOptions.TraceLinearScanLevel >= 3) { |
2778
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
151 TTY.println("Counting edges for block B%d%s", cur.blockID(), parent == null ? "" : " coming from B" + parent.blockID()); |
2507
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
152 } |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
153 |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
154 if (isActive(cur)) { |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
155 if (C1XOptions.TraceLinearScanLevel >= 3) { |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
156 TTY.println("backward branch"); |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
157 } |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
158 assert isVisited(cur) : "block must be visited when block is active"; |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
159 assert parent != null : "must have parent"; |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
160 |
2778
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
161 cur.setLinearScanLoopHeader(); |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
162 cur.setBackwardBranchTarget(true); |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
163 parent.setLinearScanLoopEnd(); |
2507
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
164 |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
165 loopEndBlocks.add(parent); |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
166 return; |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
167 } |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
168 |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
169 // increment number of incoming forward branches |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
170 incForwardBranches(cur); |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
171 |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
172 if (isVisited(cur)) { |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
173 if (C1XOptions.TraceLinearScanLevel >= 3) { |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
174 TTY.println("block already visited"); |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
175 } |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
176 return; |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
177 } |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
178 |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
179 numBlocks++; |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
180 setVisited(cur); |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
181 setActive(cur); |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
182 |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
183 // recursive call for all successors |
2778
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
184 int i; |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
185 for (i = cur.numberOfSux() - 1; i >= 0; i--) { |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
186 countEdges(cur.suxAt(i), cur); |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
187 } |
2507
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
188 |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
189 clearActive(cur); |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
190 |
2778
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
191 // Each loop has a unique number. |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
192 // When multiple loops are nested, assignLoopDepth assumes that the |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
193 // innermost loop has the lowest number. This is guaranteed by setting |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
194 // the loop number after the recursive calls for the successors above |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
195 // have returned. |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
196 if (cur.isLinearScanLoopHeader()) { |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
197 assert cur.loopIndex() == -1 : "cannot set loop-index twice"; |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
198 if (C1XOptions.TraceLinearScanLevel >= 3) { |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
199 TTY.println("Block B%d is loop header of loop %d", cur.blockID(), numLoops); |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
200 } |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
201 |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
202 cur.setLoopIndex(numLoops); |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
203 numLoops++; |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
204 } |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
205 |
2507
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
206 if (C1XOptions.TraceLinearScanLevel >= 3) { |
2778
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
207 TTY.println("Finished counting edges for block B%d", cur.blockID()); |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
208 } |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
209 } |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
210 |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
211 void markLoops() { |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
212 if (C1XOptions.TraceLinearScanLevel >= 3) { |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
213 TTY.println("----- marking loops"); |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
214 } |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
215 |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
216 loopMap = new BitMap2D(numLoops, maxBlockId); |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
217 |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
218 for (int i = loopEndBlocks.size() - 1; i >= 0; i--) { |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
219 LIRBlock loopEnd = loopEndBlocks.get(i); |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
220 LIRBlock loopStart = loopEnd.suxAt(0); |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
221 int loopIdx = loopStart.loopIndex(); |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
222 |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
223 if (C1XOptions.TraceLinearScanLevel >= 3) { |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
224 TTY.println("Processing loop from B%d to B%d (loop %d):", loopStart.blockID(), loopEnd.blockID(), loopIdx); |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
225 } |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
226 assert loopEnd.isLinearScanLoopEnd() : "loop end flag must be set"; |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
227 // assert loopEnd.numberOfSux() == 1 : "incorrect number of successors"; |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
228 assert loopStart.isLinearScanLoopHeader() : "loop header flag must be set"; |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
229 assert loopIdx >= 0 && loopIdx < numLoops : "loop index not set"; |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
230 assert workList.isEmpty() : "work list must be empty before processing"; |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
231 |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
232 // add the end-block of the loop to the working list |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
233 workList.add(loopEnd); |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
234 setBlockInLoop(loopIdx, loopEnd); |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
235 do { |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
236 LIRBlock cur = workList.remove(workList.size() - 1); |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
237 |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
238 if (C1XOptions.TraceLinearScanLevel >= 3) { |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
239 TTY.println(" processing B%d", cur.blockID()); |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
240 } |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
241 assert isBlockInLoop(loopIdx, cur) : "bit in loop map must be set when block is in work list"; |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
242 |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
243 // recursive processing of all predecessors ends when start block of loop is reached |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
244 if (cur != loopStart) { |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
245 for (int j = cur.numberOfPreds() - 1; j >= 0; j--) { |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
246 LIRBlock pred = cur.predAt(j); |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
247 |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
248 if (!isBlockInLoop(loopIdx, pred)) { |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
249 // this predecessor has not been processed yet, so add it to work list |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
250 if (C1XOptions.TraceLinearScanLevel >= 3) { |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
251 TTY.println(" pushing B%d", pred.blockID()); |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
252 } |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
253 workList.add(pred); |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
254 setBlockInLoop(loopIdx, pred); |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
255 } |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
256 } |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
257 } |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
258 } while (!workList.isEmpty()); |
2507
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
259 } |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
260 } |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
261 |
2778
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
262 // check for non-natural loops (loops where the loop header does not dominate |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
263 // all other loop blocks = loops with multiple entries). |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
264 // such loops are ignored |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
265 void clearNonNaturalLoops(LIRBlock startBlock) { |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
266 for (int i = numLoops - 1; i >= 0; i--) { |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
267 if (isBlockInLoop(i, startBlock)) { |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
268 // loop i contains the entry block of the method. |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
269 // this is not a natural loop, so ignore it |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
270 if (C1XOptions.TraceLinearScanLevel >= 2) { |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
271 TTY.println("Loop %d is non-natural, so it is ignored", i); |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
272 } |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
273 |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
274 for (int blockId = maxBlockId - 1; blockId >= 0; blockId--) { |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
275 clearBlockInLoop(i, blockId); |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
276 } |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
277 iterativeDominators = true; |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
278 } |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
279 } |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
280 } |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
281 |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
282 void assignLoopDepth(LIRBlock startBlock) { |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
283 if (C1XOptions.TraceLinearScanLevel >= 3) { |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
284 TTY.println("----- computing loop-depth and weight"); |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
285 } |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
286 initVisited(); |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
287 |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
288 assert workList.isEmpty() : "work list must be empty before processing"; |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
289 workList.add(startBlock); |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
290 |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
291 do { |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
292 LIRBlock cur = workList.remove(workList.size() - 1); |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
293 |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
294 if (!isVisited(cur)) { |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
295 setVisited(cur); |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
296 if (C1XOptions.TraceLinearScanLevel >= 4) { |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
297 TTY.println("Computing loop depth for block B%d", cur.blockID()); |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
298 } |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
299 |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
300 // compute loop-depth and loop-index for the block |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
301 assert cur.loopDepth() == 0 : "cannot set loop-depth twice"; |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
302 int i; |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
303 int loopDepth = 0; |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
304 int minLoopIdx = -1; |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
305 for (i = numLoops - 1; i >= 0; i--) { |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
306 if (isBlockInLoop(i, cur)) { |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
307 loopDepth++; |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
308 minLoopIdx = i; |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
309 } |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
310 } |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
311 cur.setLoopDepth(loopDepth); |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
312 cur.setLoopIndex(minLoopIdx); |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
313 |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
314 // append all unvisited successors to work list |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
315 for (i = cur.numberOfSux() - 1; i >= 0; i--) { |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
316 workList.add(cur.suxAt(i)); |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
317 } |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
318 } |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
319 } while (!workList.isEmpty()); |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
320 } |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
321 |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
322 int computeWeight(LIRBlock cur) { |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
323 LIRBlock singleSux = null; |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
324 if (cur.numberOfSux() == 1) { |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
325 singleSux = cur.suxAt(0); |
2507
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
326 } |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
327 |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
328 // limit loop-depth to 15 bit (only for security reason, it will never be so big) |
2778
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
329 int weight = (cur.loopDepth() & 0x7FFF) << 16; |
2507
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
330 |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
331 int curBit = 15; |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
332 |
2778
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
333 // this is necessary for the (very rare) case that two successive blocks have |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
334 // the same loop depth, but a different loop index (can happen for endless loops |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
335 // with exception handlers) |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
336 if (!cur.isLinearScanLoopHeader()) { |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
337 weight |= 1 << curBit; |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
338 } |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
339 curBit--; |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
340 |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
341 // loop end blocks (blocks that end with a backward branch) are added |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
342 // after all other blocks of the loop. |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
343 if (!cur.isLinearScanLoopEnd()) { |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
344 weight |= 1 << curBit; |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
345 } |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
346 curBit--; |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
347 |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
348 // critical edge split blocks are preferred because then they have a greater |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
349 // probability to be completely empty |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
350 //if (cur.isCriticalEdgeSplit()) { |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
351 // weight |= 1 << curBit; |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
352 //} |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
353 //curBit--; |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
354 |
2507
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
355 // exceptions should not be thrown in normal control flow, so these blocks |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
356 // are added as late as possible |
2778
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
357 // if (!(cur.end() instanceof Throw) && (singleSux == null || !(singleSux.end() instanceof Throw))) { |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
358 // weight |= 1 << curBit; |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
359 // } |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
360 // curBit--; |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
361 // if (!(cur.end() instanceof Return) && (singleSux == null || !(singleSux.end() instanceof Return))) { |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
362 // weight |= 1 << curBit; |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
363 // } |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
364 // curBit--; |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
365 |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
366 // exceptions handlers are added as late as possible |
2833
1cd59ca9ac86
Removed Throw HIR instruction. Removed special handling for exceptions in register allocator.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2832
diff
changeset
|
367 // if (!cur.isExceptionEntry()) { |
1cd59ca9ac86
Removed Throw HIR instruction. Removed special handling for exceptions in register allocator.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2832
diff
changeset
|
368 // weight |= 1 << curBit; |
1cd59ca9ac86
Removed Throw HIR instruction. Removed special handling for exceptions in register allocator.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2832
diff
changeset
|
369 // } |
1cd59ca9ac86
Removed Throw HIR instruction. Removed special handling for exceptions in register allocator.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2832
diff
changeset
|
370 // curBit--; |
2507
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
371 |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
372 // guarantee that weight is > 0 |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
373 weight |= 1; |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
374 |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
375 assert curBit >= 0 : "too many flags"; |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
376 assert weight > 0 : "weight cannot become negative"; |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
377 |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
378 return weight; |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
379 } |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
380 |
2778
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
381 boolean readyForProcessing(LIRBlock cur) { |
2507
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
382 // Discount the edge just traveled. |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
383 // When the number drops to zero, all forward branches were processed |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
384 if (decForwardBranches(cur) != 0) { |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
385 return false; |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
386 } |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
387 |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
388 assert !linearScanOrder.contains(cur) : "block already processed (block can be ready only once)"; |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
389 assert !workList.contains(cur) : "block already in work-list (block can be ready only once)"; |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
390 return true; |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
391 } |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
392 |
2778
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
393 void sortIntoWorkList(LIRBlock cur) { |
2507
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
394 assert !workList.contains(cur) : "block already in work list"; |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
395 |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
396 int curWeight = computeWeight(cur); |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
397 |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
398 // the linearScanNumber is used to cache the weight of a block |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
399 cur.setLinearScanNumber(curWeight); |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
400 |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
401 if (C1XOptions.StressLinearScan) { |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
402 workList.add(0, cur); |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
403 return; |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
404 } |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
405 |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
406 workList.add(null); // provide space for new element |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
407 |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
408 int insertIdx = workList.size() - 1; |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
409 while (insertIdx > 0 && workList.get(insertIdx - 1).linearScanNumber() > curWeight) { |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
410 workList.set(insertIdx, workList.get(insertIdx - 1)); |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
411 insertIdx--; |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
412 } |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
413 workList.set(insertIdx, cur); |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
414 |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
415 if (C1XOptions.TraceLinearScanLevel >= 3) { |
2778
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
416 TTY.println("Sorted B%d into worklist. new worklist:", cur.blockID()); |
2507
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
417 for (int i = 0; i < workList.size(); i++) { |
2778
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
418 TTY.println(String.format("%8d B%02d weight:%6x", i, workList.get(i).blockID(), workList.get(i).linearScanNumber())); |
2507
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
419 } |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
420 } |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
421 |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
422 for (int i = 0; i < workList.size(); i++) { |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
423 assert workList.get(i).linearScanNumber() > 0 : "weight not set"; |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
424 assert i == 0 || workList.get(i - 1).linearScanNumber() <= workList.get(i).linearScanNumber() : "incorrect order in worklist"; |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
425 } |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
426 } |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
427 |
2778
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
428 void appendBlock(LIRBlock cur) { |
2507
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
429 if (C1XOptions.TraceLinearScanLevel >= 3) { |
2778
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
430 TTY.println("appending block B%d (weight 0x%06x) to linear-scan order", cur.blockID(), cur.linearScanNumber()); |
2507
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
431 } |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
432 assert !linearScanOrder.contains(cur) : "cannot add the same block twice"; |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
433 |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
434 // currently, the linear scan order and code emit order are equal. |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
435 // therefore the linearScanNumber and the weight of a block must also |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
436 // be equal. |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
437 cur.setLinearScanNumber(linearScanOrder.size()); |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
438 linearScanOrder.add(cur); |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
439 } |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
440 |
2778
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
441 void computeOrder(LIRBlock startBlock) { |
2507
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
442 if (C1XOptions.TraceLinearScanLevel >= 3) { |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
443 TTY.println("----- computing final block order"); |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
444 } |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
445 |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
446 // the start block is always the first block in the linear scan order |
2778
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
447 linearScanOrder = new ArrayList<LIRBlock>(numBlocks); |
2788
df4c5254c5cc
Towards goto removal.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2778
diff
changeset
|
448 // appendBlock(startBlock); |
2778
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
449 |
2788
df4c5254c5cc
Towards goto removal.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2778
diff
changeset
|
450 LIRBlock stdEntry = startBlock; //.suxAt(0); |
2507
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
451 |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
452 // start processing with standard entry block |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
453 assert workList.isEmpty() : "list must be empty before processing"; |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
454 |
2778
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
455 if (readyForProcessing(stdEntry)) { |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
456 sortIntoWorkList(stdEntry); |
2507
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
457 } else { |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
458 throw new CiBailout("the stdEntry must be ready for processing (otherwise, the method has no start block)"); |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
459 } |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
460 |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
461 do { |
2778
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
462 LIRBlock cur = workList.remove(workList.size() - 1); |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
463 |
2507
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
464 appendBlock(cur); |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
465 |
2778
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
466 int i; |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
467 int numSux = cur.numberOfSux(); |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
468 // changed loop order to get "intuitive" order of if- and else-blocks |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
469 for (i = 0; i < numSux; i++) { |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
470 LIRBlock sux = cur.suxAt(i); |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
471 if (readyForProcessing(sux)) { |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
472 sortIntoWorkList(sux); |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
473 } |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
474 } |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
475 } while (workList.size() > 0); |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
476 } |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
477 |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
478 public void printBlocks() { |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
479 if (C1XOptions.TraceLinearScanLevel >= 2) { |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
480 TTY.println("----- loop information:"); |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
481 for (LIRBlock cur : linearScanOrder) { |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
482 TTY.print(String.format("%4d: B%02d: ", cur.linearScanNumber(), cur.blockID())); |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
483 for (int loopIdx = 0; loopIdx < numLoops; loopIdx++) { |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
484 TTY.print(String.format("%d = %b ", loopIdx, isBlockInLoop(loopIdx, cur))); |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
485 } |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
486 TTY.println(String.format(" . loopIndex: %2d, loopDepth: %2d", cur.loopIndex(), cur.loopDepth())); |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
487 } |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
488 } |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
489 |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
490 if (C1XOptions.TraceLinearScanLevel >= 1) { |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
491 TTY.println("----- linear-scan block order:"); |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
492 for (LIRBlock cur : linearScanOrder) { |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
493 TTY.print(String.format("%4d: B%02d loop: %2d depth: %2d", cur.linearScanNumber(), cur.blockID(), cur.loopIndex(), cur.loopDepth())); |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
494 |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
495 TTY.print(cur.isLinearScanLoopHeader() ? " lh" : " "); |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
496 TTY.print(cur.isLinearScanLoopEnd() ? " le" : " "); |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
497 |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
498 TTY.print(" dom: null "); |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
499 |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
500 |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
501 if (cur.numberOfPreds() > 0) { |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
502 TTY.print(" preds: "); |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
503 for (int j = 0; j < cur.numberOfPreds(); j++) { |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
504 LIRBlock pred = cur.predAt(j); |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
505 TTY.print("B%d ", pred.blockID()); |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
506 } |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
507 } |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
508 if (cur.numberOfSux() > 0) { |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
509 TTY.print(" sux: "); |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
510 for (int j = 0; j < cur.numberOfSux(); j++) { |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
511 LIRBlock sux = cur.suxAt(j); |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
512 TTY.print("B%d ", sux.blockID()); |
2707
7ed72769d51a
exception handling related changes:
Lukas Stadler <lukas.stadler@jku.at>
parents:
2674
diff
changeset
|
513 } |
2507
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
514 } |
2778
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
515 TTY.println(); |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
516 } |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
517 } |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
518 } |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
519 |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
520 boolean verify() { |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
521 /* assert linearScanOrder.size() == numBlocks : "wrong number of blocks in list"; |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
522 |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
523 if (C1XOptions.StressLinearScan) { |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
524 // blocks are scrambled when StressLinearScan is used |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
525 return true; |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
526 } |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
527 |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
528 // check that all successors of a block have a higher linear-scan-number |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
529 // and that all predecessors of a block have a lower linear-scan-number |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
530 // (only backward branches of loops are ignored) |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
531 int i; |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
532 for (i = 0; i < linearScanOrder.size(); i++) { |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
533 BlockBegin cur = linearScanOrder.get(i); |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
534 |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
535 assert cur.linearScanNumber() == i : "incorrect linearScanNumber"; |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
536 assert cur.linearScanNumber() >= 0 && cur.linearScanNumber() == linearScanOrder.indexOf(cur) : "incorrect linearScanNumber"; |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
537 |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
538 for (BlockBegin sux : cur.end().successors()) { |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
539 assert sux.linearScanNumber() >= 0 && sux.linearScanNumber() == linearScanOrder.indexOf(sux) : "incorrect linearScanNumber"; |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
540 if (!cur.checkBlockFlag(BlockBegin.BlockFlag.LinearScanLoopEnd)) { |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
541 assert cur.linearScanNumber() < sux.linearScanNumber() : "invalid order"; |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
542 } |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
543 if (cur.loopDepth() == sux.loopDepth()) { |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
544 assert cur.loopIndex() == sux.loopIndex() || sux.checkBlockFlag(BlockBegin.BlockFlag.LinearScanLoopHeader) : "successing blocks with same loop depth must have same loop index"; |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
545 } |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
546 } |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
547 |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
548 for (BlockBegin pred : cur.predecessors()) { |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
549 assert pred.linearScanNumber() >= 0 && pred.linearScanNumber() == linearScanOrder.indexOf(pred) : "incorrect linearScanNumber"; |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
550 if (!cur.checkBlockFlag(BlockBegin.BlockFlag.LinearScanLoopHeader)) { |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
551 assert cur.linearScanNumber() > pred.linearScanNumber() : "invalid order"; |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
552 } |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
553 if (cur.loopDepth() == pred.loopDepth()) { |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
554 assert cur.loopIndex() == pred.loopIndex() || cur.checkBlockFlag(BlockBegin.BlockFlag.LinearScanLoopHeader) : "successing blocks with same loop depth must have same loop index"; |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
555 } |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
556 |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
557 assert cur.dominator().linearScanNumber() <= pred.linearScanNumber() : "dominator must be before predecessors"; |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
558 } |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
559 |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
560 // check dominator |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
561 if (i == 0) { |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
562 assert cur.dominator() == null : "first block has no dominator"; |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
563 } else { |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
564 assert cur.dominator() != null : "all but first block must have dominator"; |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
565 } |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
566 assert cur.numberOfPreds() != 1 || cur.dominator() == cur.predAt(0) || cur.isExceptionEntry() : "Single predecessor must also be dominator"; |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
567 } |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
568 |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
569 // check that all loops are continuous |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
570 for (int loopIdx = 0; loopIdx < numLoops; loopIdx++) { |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
571 int blockIdx = 0; |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
572 assert !isBlockInLoop(loopIdx, linearScanOrder.get(blockIdx)) : "the first block must not be present in any loop"; |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
573 |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
574 // skip blocks before the loop |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
575 while (blockIdx < numBlocks && !isBlockInLoop(loopIdx, linearScanOrder.get(blockIdx))) { |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
576 blockIdx++; |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
577 } |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
578 // skip blocks of loop |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
579 while (blockIdx < numBlocks && isBlockInLoop(loopIdx, linearScanOrder.get(blockIdx))) { |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
580 blockIdx++; |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
581 } |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
582 // after the first non-loop block : there must not be another loop-block |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
583 while (blockIdx < numBlocks) { |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
584 assert !isBlockInLoop(loopIdx, linearScanOrder.get(blockIdx)) : "loop not continuous in linear-scan order"; |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
585 blockIdx++; |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
586 } |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
587 } |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
588 */ |
2ac7b30b7290
Enabled new block finding algorithm.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2773
diff
changeset
|
589 return true; |
2507
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
590 } |
9ec15d6914ca
Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff
changeset
|
591 } |