Reputation: 21605
I'm writing an LLVM Pass. My pass needs to know which block is a merge block, that is, a block which has more than 1 predecessors. How can I test for this in my code?
Upvotes: 5
Views: 630
Reputation: 6625
You can iterate over all predecessors like this:
#include "llvm/Support/CFG.h"
BasicBlock *BB = ...;
for (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI) {
BasicBlock *Pred = *PI;
// ...
}
you can verify if an BB have more than one predecessor using this:
BasicBlock *BB = ...;
if (BB->getSinglePredecessor() != null) /// one predecessor
{ ... }
else /// more than one predecessor
{ ... }
Upvotes: 4