Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c++

llvm

clang

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?

like image 606
pythonic Avatar asked Oct 09 '22 03:10

pythonic


1 Answers

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
{ ... }
like image 132
JohnTortugo Avatar answered Oct 18 '22 10:10

JohnTortugo