llvm.org GIT mirror llvm / 2090766
Use dominates(Instruction, Use) in the verifier. This removes a bit of context from the verifier erros, but reduces code duplication in a fairly critical part of LLVM and makes dominates easier to test. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@157845 91177308-0d34-0410-b5e6-96231b3b80d8 Rafael Espindola 8 years ago
2 changed file(s) with 5 addition(s) and 49 deletion(s). Raw diff Collapse all Expand all
15741574
15751575 void Verifier::verifyDominatesUse(Instruction &I, unsigned i) {
15761576 Instruction *Op = cast(I.getOperand(i));
1577 BasicBlock *BB = I.getParent();
1578 BasicBlock *OpBlock = Op->getParent();
1579 PHINode *PN = dyn_cast(&I);
1580
1581 // DT can handle non phi instructions for us.
1582 if (!PN) {
1583 // Definition must dominate use unless use is unreachable!
1584 Assert2(InstsInThisBlock.count(Op) || !DT->isReachableFromEntry(BB) ||
1585 DT->dominates(Op, &I),
1586 "Instruction does not dominate all uses!", Op, &I);
1587 return;
1588 }
1589
1590 // Check that a definition dominates all of its uses.
1591 if (InvokeInst *II = dyn_cast(Op)) {
1592 // Invoke results are only usable in the normal destination, not in the
1593 // exceptional destination.
1594 BasicBlock *NormalDest = II->getNormalDest();
1595
1596
1597 // PHI nodes differ from other nodes because they actually "use" the
1598 // value in the predecessor basic blocks they correspond to.
1599 BasicBlock *UseBlock = BB;
1600 unsigned j = PHINode::getIncomingValueNumForOperand(i);
1601 UseBlock = PN->getIncomingBlock(j);
1602 Assert2(UseBlock, "Invoke operand is PHI node with bad incoming-BB",
1603 Op, &I);
1604
1605 if (UseBlock == OpBlock) {
1606 // Special case of a phi node in the normal destination or the unwind
1607 // destination.
1608 Assert2(BB == NormalDest || !DT->isReachableFromEntry(UseBlock),
1609 "Invoke result not available in the unwind destination!",
1610 Op, &I);
1611 } else {
1612 Assert2(DT->dominates(II, UseBlock) ||
1613 !DT->isReachableFromEntry(UseBlock),
1614 "Invoke result does not dominate all uses!", Op, &I);
1615 }
1616 }
1617
1618 // PHI nodes are more difficult than other nodes because they actually
1619 // "use" the value in the predecessor basic blocks they correspond to.
1620 unsigned j = PHINode::getIncomingValueNumForOperand(i);
1621 BasicBlock *PredBB = PN->getIncomingBlock(j);
1622 Assert2(PredBB && (DT->dominates(OpBlock, PredBB) ||
1623 !DT->isReachableFromEntry(PredBB)),
1577
1578 const Use &U = I.getOperandUse(i);
1579 Assert2(InstsInThisBlock.count(Op) || DT->dominates(Op, U),
16241580 "Instruction does not dominate all uses!", Op, &I);
16251581 }
16261582
1919 %y3 = landingpad i32 personality i32 ()* @g
2020 cleanup
2121 ret void
22 ; CHECK: Invoke result not available in the unwind destination!
22 ; CHECK: Instruction does not dominate all uses!
2323 ; CHECK-NEXT: %y1 = invoke i32 @g()
2424 ; CHECK-NEXT: to label %bb1 unwind label %bb2
2525 ; CHECK-NEXT: %y2 = phi i32 [ %y1, %bb0 ]
3737 bb3:
3838 %y3 = phi i32 [%y1, %bb2]
3939 ret void
40 ; CHECK: Invoke result does not dominate all uses!
40 ; CHECK: Instruction does not dominate all uses!
4141 ; CHECK-NEXT: %y1 = invoke i32 @g()
4242 ; CHECK-NEXT: to label %bb1 unwind label %bb2
4343 ; CHECK-NEXT: %y3 = phi i32 [ %y1, %bb2 ]