llvm.org GIT mirror llvm / d5118c8
Assert that dominates is not given a multiple edge. Finding out if we have multiple edges between two blocks is linear. If the caller is iterating all edges leaving a BB that would be a square time algorithm. It is more efficient to have the callers handle that case. Currently the only callers are: * GVN: already avoids the multiple edge case. * Verifier: could only hit this assert when looking at an invalid invoke. Since it already rejects the invoke, just avoid computing the dominance for it. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@162113 91177308-0d34-0410-b5e6-96231b3b80d8 Rafael Espindola 8 years ago
3 changed file(s) with 17 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
160160
161161 bool DominatorTree::dominates(const BasicBlockEdge &BBE,
162162 const BasicBlock *UseBB) const {
163 // Assert that we have a single edge. We could handle them by simply
164 // returning false, but since isSingleEdge is linear on the number of
165 // edges, the callers can normally handle them more efficiently.
166 assert(BBE.isSingleEdge());
167
163168 // If the BB the edge ends in doesn't dominate the use BB, then the
164169 // edge also doesn't.
165170 const BasicBlock *Start = BBE.getStart();
206211
207212 bool DominatorTree::dominates(const BasicBlockEdge &BBE,
208213 const Use &U) const {
214 // Assert that we have a single edge. We could handle them by simply
215 // returning false, but since isSingleEdge is linear on the number of
216 // edges, the callers can normally handle them more efficiently.
217 assert(BBE.isSingleEdge());
218
209219 Instruction *UserInst = cast(U.getUser());
210220 // A PHI in the end of the edge is dominated by it.
211221 PHINode *PN = dyn_cast(UserInst);
15741574
15751575 void Verifier::verifyDominatesUse(Instruction &I, unsigned i) {
15761576 Instruction *Op = cast(I.getOperand(i));
1577 // If the we have an invalid invoke, don't try to compute the dominance.
1578 // We already reject it in the invoke specific checks and the dominance
1579 // computation doesn't handle multiple edges.
1580 if (InvokeInst *II = dyn_cast(Op)) {
1581 if (II->getNormalDest() == II->getUnwindDest())
1582 return;
1583 }
15771584
15781585 const Use &U = I.getOperandUse(i);
15791586 Assert2(InstsInThisBlock.count(Op) || DT->dominates(Op, U),
1818 br label %L
1919 L: ; preds = %L2, %L1, %L1
2020 ; CHECK: The unwind destination does not have a landingpad instruction
21 ; CHECK: Instruction does not dominate all uses
2221 ret i32 %A
2322 }
2423