用代码属性图表示LLVM-IR
1. LLVM-IR中的特殊指令表示
在LLVM-IR中,一些特殊指令的表示在代码属性图(CPG)中有独特的处理方式。
1.1 ϕ指令示例
下面是使用ϕ指令的代码片段:
define i32 @main(i32 %x) {
%cond = icmp eq i32 %x, 10
br i1 %cond , label %BB1 , label %BB2
BB1:
%a = mul i32 %x, 32768
br label %BB3
BB2:
%b = add i32 %x, 7
br label %BB3
BB3:
%y = phi i32 [ %a, %BB1 ], [ %b, %BB2 ]
ret i32 %y
}
在CPG中建模的ϕ指令代码片段如下:
define i32 @main(i32 %x) {
; VariableDeclaration of %y
%cond = icmp eq i32 %x, 10
br i1 %cond , label %BB1 , label %BB2
BB1:
%a = mul i32 %x, 32768
%y = %a
br label %BB3
BB2:
%b = add i32 %x, 7
%y = %b
br label %BB3
BB3:
ret i32 %y
超级会员免费看
订阅专栏 解锁全文
1458

被折叠的 条评论
为什么被折叠?



