I still don't understand the differences even after referring to the doxygen page:
getSingleSuccessor()
Return the successor of this block if it has a single successor.
Otherwise return a null pointer.
getUniqueSuccessor()
Return the successor of this block if it has a unique successor.
Otherwise return a null pointer.
and looking to the source code:
// BasicBlock.cpp
const BasicBlock *BasicBlock::getSingleSuccessor() const {
const_succ_iterator SI = succ_begin(this), E = succ_end(this);
if (SI == E) return nullptr; // no successors
const BasicBlock *TheSucc = *SI;
++SI;
return (SI == E) ? TheSucc : nullptr /* multiple successors */;
}
const BasicBlock *BasicBlock::getUniqueSuccessor() const {
const_succ_iterator SI = succ_begin(this), E = succ_end(this);
if (SI == E) return nullptr; // No successors
const BasicBlock *SuccBB = *SI;
++SI;
for (;SI != E; ++SI) {
if (*SI != SuccBB)
return nullptr;
// The same successor appears multiple times in the successor list.
// This is OK.
}
return SuccBB;
}
LLVM IR code generally has one successor for each case label or similar, so for code like this example, getUniqueSuccessor() and getSingleSuccessor() deliver different results:
switch(foo) {
case 0:
case 1:
case 2:
default:
printf("Hello, world\n";
}
The first block has four successors, all of them equal.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With