说IR代码看起来像:
define void @_Z1mbb(i1 zeroext %r, i1 zeroext %y) nounwind {
entry:
%r.addr = alloca i8, align 1
%y.addr = alloca i8, align 1
%l = alloca i8, align 1
%frombool = zext i1 %r to i8
store i8 %frombool, i8* %r.addr, align 1
%frombool1 = zext i1 %y to i8
store i8 %frombool1, i8* %y.addr, align 1
%0 = load i8* %y.addr, align 1
%tobool = trunc i8 %0 to i1
br i1 %tobool, label %lor.end, label %lor.rhs
lor.rhs: ; preds = %entry
%1 = load i8* %r.addr, align 1
%tobool2 = trunc i8 %1 to i1
br label %lor.end
lor.end: ; preds = %lor.rhs, %entry
%2 = phi i1 [ true, %entry ], [ %tobool2, %lor.rhs ]
%frombool3 = zext i1 %2 to i8
store i8 %frombool3, i8* %l, align 1
ret void
}
phinode有2对
[ true, %entry ], [ %tobool2, %lor.rhs ]
。如何提取%entry
和%lor.rhs
并找到每对对应的基本块?任何帮助将不胜感激。 最佳答案
PHI->getgetNumIncomingValues()
:返回PHINode中传入值的数量
对于您的phi节点:
%2 = phi i1 [ true, %entry ], [ %tobool2, %lor.rhs ]
PHI->getIncomingValue(0)
:给出true
PHI->getIncomingBlock(0)
:给出%entry
也有块和值的迭代器。
http://llvm.org/doxygen/classllvm_1_1PHINode.html
请务必参考doxygen文档,以查看与类相关的所有API(例如:PHINode)。