llvm - 获取br指令的标签

时间:2017-12-27 15:56:40

标签: label llvm branch llvm-ir llvm-3.0

我的问题很简单。给定类型分支的指令,如何从中提取标签? 例如:

br label %while.cond

应该给我while.cond

br label %while.end

应该给我while.end

br i1 %cmp1, label %if.then, label %if.end

如果,if.then,if.end分别给我。

2 个答案:

答案 0 :(得分:0)

首先检查inst->isConditional(),然后访问inst->getOperand(1)inst->getOperand(2)以防它为真,如果inst->getOperand(0)则为假。

整个BasicBlock是BranchInst实际接受的。如果您想要%if.then行,请在其上调用getName()

答案 1 :(得分:0)

我使用以下代码段来获取您提出的所有上述信息。

 if (inst->getNumSuccessors() == 1)     
     return; //indicates not a branching instruction 

 unsigned int i; 

  for (i = 0; i <= inst->getNumSuccessors(); i++) {       

      llvm::outs() << inst->getOperand(i)->getName(); 

  }