llvm.org GIT mirror llvm / 08368ce
Fix up PHI nodes correctly in the presence of unreachable BBs, part two. Also delete a newed pointer, and improve readability a little bit. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@79411 91177308-0d34-0410-b5e6-96231b3b80d8 Nick Lewycky 10 years ago
2 changed file(s) with 52 addition(s) and 7 deletion(s). Raw diff Collapse all Expand all
225225 for (BasicBlock::iterator begin = BB_succ->begin(),
226226 notPhi = BB_succ->getFirstNonPHI(); begin != *notPhi; ++begin) {
227227 Instruction *I = begin;
228 PHINode *PN;
228 PHINode *PN = dyn_cast(I);
229229 int position;
230 if ((PN = dyn_cast(I)) && ((position
231 = getPositionPhi(PN)) != -1)) {
230 if (PN && ((position = getPositionPhi(PN)) != -1)) {
232231 PN->addIncoming(value_stack[position].back(), BB);
233232 }
234233 }
253252 }
254253 }
255254 }
255
256 delete defined;
256257 }
257258
258259 /// Substitute any use in this instruction for the last definition of
306307 /// as an operand of another phi function used in the same BasicBlock,
307308 /// LLVM looks this as an error. So on the second phi, the first phi is called
308309 /// P and the BasicBlock it incomes is B. This P will be replaced by the value
309 /// it has for BasicBlock B.
310 /// it has for BasicBlock B. It also includes undef values for predecessors
311 /// that were not included in the phi.
310312 ///
311313 void SSI::fixPhis() {
312314 for (SmallPtrSet::iterator begin = phisToFix.begin(),
313315 end = phisToFix.end(); begin != end; ++begin) {
314316 PHINode *PN = *begin;
315317 for (unsigned i = 0, e = PN->getNumIncomingValues(); i < e; ++i) {
316 PHINode *PN_father;
317 if ((PN_father = dyn_cast(PN->getIncomingValue(i))) &&
318 PN->getParent() == PN_father->getParent() &&
318 PHINode *PN_father = dyn_cast(PN->getIncomingValue(i));
319 if (PN_father && PN->getParent() == PN_father->getParent() &&
319320 !DT_->dominates(PN->getParent(), PN->getIncomingBlock(i))) {
320321 BasicBlock *BB = PN->getIncomingBlock(i);
321322 int pos = PN_father->getBasicBlockIndex(BB);
322323 PN->setIncomingValue(i, PN_father->getIncomingValue(pos));
324 }
325 }
326 }
327
328 for (DenseMapIterator begin = phis.begin(),
329 end = phis.end(); begin != end; ++begin) {
330 PHINode *PN = begin->first;
331 BasicBlock *BB = PN->getParent();
332 pred_iterator PI = pred_begin(BB), PE = pred_end(BB);
333 SmallVector Preds(PI, PE);
334 for (unsigned size = Preds.size();
335 PI != PE && PN->getNumIncomingValues() != size; ++PI) {
336 bool found = false;
337 for (unsigned i = 0, pn_end = PN->getNumIncomingValues();
338 i < pn_end; ++i) {
339 if (PN->getIncomingBlock(i) == *PI) {
340 found = true;
341 break;
342 }
343 }
344 if (!found) {
345 PN->addIncoming(UndefValue::get(PN->getType()), *PI);
323346 }
324347 }
325348 }
0 ; RUN: llvm-as < %s | opt -ssi-everything -disable-output
1
2 define void @foo() {
3 entry:
4 %tmp0 = load i64* undef, align 4 ; [#uses=3]
5 br i1 undef, label %end_stmt_playback, label %bb16
6
7 readJournalHdr.exit: ; No predecessors!
8 br label %end_stmt_playback
9
10 bb16: ; preds = %bb7
11 %tmp1 = icmp slt i64 0, %tmp0 ; [#uses=1]
12 br i1 %tmp1, label %bb16, label %bb17
13
14 bb17: ; preds = %bb16
15 store i64 %tmp0, i64* undef, align 4
16 br label %end_stmt_playback
17
18 end_stmt_playback: ; preds = %bb17, %readJournalHdr.exit, %bb6, %bb2
19 store i64 %tmp0, i64* undef, align 4
20 ret void
21 }