Compiler construction 在LLVM中查找基本块的后续项列表
在LLVM中,BasicBlock具有getSinglePreceducer()和getSingleSuceducer()属性,但我需要获得基本块的继承者和前置者的完整列表。如何在llvm中实现这一点 我的代码是Compiler construction 在LLVM中查找基本块的后续项列表,compiler-construction,llvm,compiler-optimization,llvm-clang,Compiler Construction,Llvm,Compiler Optimization,Llvm Clang,在LLVM中,BasicBlock具有getSinglePreceducer()和getSingleSuceducer()属性,但我需要获得基本块的继承者和前置者的完整列表。如何在llvm中实现这一点 我的代码是 virtual bool runOnFunction(Function &F) { for (Function::iterator b = F.begin(), be = F.end(); b != be; ++b) { //
virtual bool runOnFunction(Function &F) {
for (Function::iterator b = F.begin(), be = F.end(); b != be; ++b) {
//Here I need to get the predecessor and successsor of the basic block b
}
}
我同意基本块没有直接属性。取而代之的是,您可以创建一个基本块,然后遍历它 或者,基于对BasicBlock类的读取,您可以从BasicBlock实例创建pred_迭代器和succu迭代器。例如:
for (Function::iterator b = F.begin(), be = F.end(); b != be; ++b)
{
BasicBlock* bb = dyn_cast<BasicBlock>(&*b);
for (pred_iterator pit = pred_begin(bb), pet = pred_end(bb); pit != pet; ++pit)
for(函数::迭代器b=F.begin(),be=F.end();b!=be;++b)
{
基本块*bb=动态铸造(&*b);
for(pred_迭代器pit=pred_begin(bb),pet=pred_end(bb);pit!=pet;++pit)
如果您愿意的话,代码稍微少一点:
#include "llvm/IR/CFG.h"
BasicBlock *BB = ...;
for (BasicBlock *Pred : predecessors(BB)) {
// ...
}
该片段取自