pythonic
pythonic

Reputation: 21605

In LLVM, how do you check if a block is a merge block

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

Answers (1)

JohnTortugo
JohnTortugo

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

Related Questions