我正在写一个LLVM Pass.我的传递需要知道哪个块是合并块,即具有多于1个前驱的块.如何在我的代码中测试?
您可以像这样迭代所有前辈:
#include "llvm/Support/CFG.h"
BasicBlock *BB = ...;
for (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI) {
BasicBlock *Pred = *PI;
// ...
}
Run Code Online (Sandbox Code Playgroud)
您可以使用以下方法验证 BB 是否有多个前任:
BasicBlock *BB = ...;
if (BB->getSinglePredecessor() != null) /// one predecessor
{ ... }
else /// more than one predecessor
{ ... }
Run Code Online (Sandbox Code Playgroud)