Mercurial > hg > graal-jvmci-8
comparison graal/GraalCompiler/src/com/sun/c1x/alloc/RegisterVerifier.java @ 2718:c1ce2a53d6c3
Attempt to remove dependency between backend and BlockBegin.
author | Thomas Wuerthinger <thomas@wuerthinger.net> |
---|---|
date | Thu, 19 May 2011 16:05:42 +0200 |
parents | 7ed72769d51a |
children | a2f62de90c76 |
comparison
equal
deleted
inserted
replaced
2717:bd85cf08720a | 2718:c1ce2a53d6c3 |
---|---|
36 * @author Thomas Wuerthinger | 36 * @author Thomas Wuerthinger |
37 */ | 37 */ |
38 final class RegisterVerifier { | 38 final class RegisterVerifier { |
39 | 39 |
40 LinearScan allocator; | 40 LinearScan allocator; |
41 List<BlockBegin> workList; // all blocks that must be processed | 41 List<LIRBlock> workList; // all blocks that must be processed |
42 ArrayMap<Interval[]> savedStates; // saved information of previous check | 42 ArrayMap<Interval[]> savedStates; // saved information of previous check |
43 | 43 |
44 // simplified access to methods of LinearScan | 44 // simplified access to methods of LinearScan |
45 C1XCompilation compilation() { | 45 C1XCompilation compilation() { |
46 return allocator.compilation; | 46 return allocator.compilation; |
54 int stateSize() { | 54 int stateSize() { |
55 return allocator.operands.maxRegisterNumber() + 1; | 55 return allocator.operands.maxRegisterNumber() + 1; |
56 } | 56 } |
57 | 57 |
58 // accessors | 58 // accessors |
59 Interval[] stateForBlock(BlockBegin block) { | 59 Interval[] stateForBlock(LIRBlock block) { |
60 return savedStates.get(block.blockID); | 60 return savedStates.get(block.blockID()); |
61 } | 61 } |
62 | 62 |
63 void setStateForBlock(BlockBegin block, Interval[] savedState) { | 63 void setStateForBlock(LIRBlock block, Interval[] savedState) { |
64 savedStates.put(block.blockID, savedState); | 64 savedStates.put(block.blockID(), savedState); |
65 } | 65 } |
66 | 66 |
67 void addToWorkList(BlockBegin block) { | 67 void addToWorkList(LIRBlock block) { |
68 if (!workList.contains(block)) { | 68 if (!workList.contains(block)) { |
69 workList.add(block); | 69 workList.add(block); |
70 } | 70 } |
71 } | 71 } |
72 | 72 |
73 RegisterVerifier(LinearScan allocator) { | 73 RegisterVerifier(LinearScan allocator) { |
74 this.allocator = allocator; | 74 this.allocator = allocator; |
75 workList = new ArrayList<BlockBegin>(16); | 75 workList = new ArrayList<LIRBlock>(16); |
76 this.savedStates = new ArrayMap<Interval[]>(); | 76 this.savedStates = new ArrayMap<Interval[]>(); |
77 | 77 |
78 } | 78 } |
79 | 79 |
80 void verify(BlockBegin start) { | 80 void verify(LIRBlock start) { |
81 // setup input registers (method arguments) for first block | 81 // setup input registers (method arguments) for first block |
82 Interval[] inputState = new Interval[stateSize()]; | 82 Interval[] inputState = new Interval[stateSize()]; |
83 CiCallingConvention args = compilation().frameMap().incomingArguments(); | 83 CiCallingConvention args = compilation().frameMap().incomingArguments(); |
84 for (int n = 0; n < args.locations.length; n++) { | 84 for (int n = 0; n < args.locations.length; n++) { |
85 CiValue operand = args.locations[n]; | 85 CiValue operand = args.locations[n]; |
93 setStateForBlock(start, inputState); | 93 setStateForBlock(start, inputState); |
94 addToWorkList(start); | 94 addToWorkList(start); |
95 | 95 |
96 // main loop for verification | 96 // main loop for verification |
97 do { | 97 do { |
98 BlockBegin block = workList.get(0); | 98 LIRBlock block = workList.get(0); |
99 workList.remove(0); | 99 workList.remove(0); |
100 | 100 |
101 processBlock(block); | 101 processBlock(block); |
102 } while (!workList.isEmpty()); | 102 } while (!workList.isEmpty()); |
103 } | 103 } |
104 | 104 |
105 void processBlock(BlockBegin block) { | 105 void processBlock(LIRBlock block) { |
106 if (C1XOptions.TraceLinearScanLevel >= 2) { | 106 if (C1XOptions.TraceLinearScanLevel >= 2) { |
107 TTY.println(); | 107 TTY.println(); |
108 TTY.println("processBlock B%d", block.blockID); | 108 TTY.println("processBlock B%d", block.blockID()); |
109 } | 109 } |
110 | 110 |
111 // must copy state because it is modified | 111 // must copy state because it is modified |
112 Interval[] inputState = copy(stateForBlock(block)); | 112 Interval[] inputState = copy(stateForBlock(block)); |
113 | 113 |
127 | 127 |
128 // process all operations of the block | 128 // process all operations of the block |
129 processOperations(block.lir(), inputState); | 129 processOperations(block.lir(), inputState); |
130 | 130 |
131 // iterate all successors | 131 // iterate all successors |
132 for (BlockBegin succ : block.end().blockSuccessors()) { | 132 for (LIRBlock succ : block.blockSuccessors()) { |
133 processSuccessor(succ, inputState); | 133 processSuccessor(succ, inputState); |
134 } | 134 } |
135 } | 135 } |
136 | 136 |
137 void processXhandler(BlockBegin xhandler, Interval[] inputState) { | 137 void processXhandler(LIRBlock xhandler, Interval[] inputState) { |
138 if (C1XOptions.TraceLinearScanLevel >= 2) { | 138 if (C1XOptions.TraceLinearScanLevel >= 2) { |
139 TTY.println("processXhandler B%d", xhandler.blockID); | 139 TTY.println("processXhandler B%d", xhandler.blockID()); |
140 } | 140 } |
141 | 141 |
142 // must copy state because it is modified | 142 // must copy state because it is modified |
143 inputState = copy(inputState); | 143 inputState = copy(inputState); |
144 | 144 |
146 processOperations(xhandler.lir(), inputState); | 146 processOperations(xhandler.lir(), inputState); |
147 } | 147 } |
148 processSuccessor(xhandler, inputState); | 148 processSuccessor(xhandler, inputState); |
149 } | 149 } |
150 | 150 |
151 void processSuccessor(BlockBegin block, Interval[] inputState) { | 151 void processSuccessor(LIRBlock block, Interval[] inputState) { |
152 Interval[] savedState = stateForBlock(block); | 152 Interval[] savedState = stateForBlock(block); |
153 | 153 |
154 if (savedState != null) { | 154 if (savedState != null) { |
155 // this block was already processed before. | 155 // this block was already processed before. |
156 // check if new inputState is consistent with savedState | 156 // check if new inputState is consistent with savedState |
166 // then the old calculation was correct. | 166 // then the old calculation was correct. |
167 savedStateCorrect = false; | 167 savedStateCorrect = false; |
168 savedState[i] = null; | 168 savedState[i] = null; |
169 | 169 |
170 if (C1XOptions.TraceLinearScanLevel >= 4) { | 170 if (C1XOptions.TraceLinearScanLevel >= 4) { |
171 TTY.println("processSuccessor B%d: invalidating slot %d", block.blockID, i); | 171 TTY.println("processSuccessor B%d: invalidating slot %d", block.blockID(), i); |
172 } | 172 } |
173 } | 173 } |
174 } | 174 } |
175 } | 175 } |
176 | 176 |
177 if (savedStateCorrect) { | 177 if (savedStateCorrect) { |
178 // already processed block with correct inputState | 178 // already processed block with correct inputState |
179 if (C1XOptions.TraceLinearScanLevel >= 2) { | 179 if (C1XOptions.TraceLinearScanLevel >= 2) { |
180 TTY.println("processSuccessor B%d: previous visit already correct", block.blockID); | 180 TTY.println("processSuccessor B%d: previous visit already correct", block.blockID()); |
181 } | 181 } |
182 } else { | 182 } else { |
183 // must re-visit this block | 183 // must re-visit this block |
184 if (C1XOptions.TraceLinearScanLevel >= 2) { | 184 if (C1XOptions.TraceLinearScanLevel >= 2) { |
185 TTY.println("processSuccessor B%d: must re-visit because input state changed", block.blockID); | 185 TTY.println("processSuccessor B%d: must re-visit because input state changed", block.blockID()); |
186 } | 186 } |
187 addToWorkList(block); | 187 addToWorkList(block); |
188 } | 188 } |
189 | 189 |
190 } else { | 190 } else { |
191 // block was not processed before, so set initial inputState | 191 // block was not processed before, so set initial inputState |
192 if (C1XOptions.TraceLinearScanLevel >= 2) { | 192 if (C1XOptions.TraceLinearScanLevel >= 2) { |
193 TTY.println("processSuccessor B%d: initial visit", block.blockID); | 193 TTY.println("processSuccessor B%d: initial visit", block.blockID()); |
194 } | 194 } |
195 | 195 |
196 setStateForBlock(block, copy(inputState)); | 196 setStateForBlock(block, copy(inputState)); |
197 addToWorkList(block); | 197 addToWorkList(block); |
198 } | 198 } |