手写ll违背了SSA的例子

238 阅读1分钟

一段.ll文件,手写的,看似没问题,其实违背了SSA

; factorial.ll

define i32 @factorial(i32 %val) {
entry:
    %i = add i32 0, 2
    %temp = add i32 0, 1
    br label %check_for_condition

check_for_condition:
    %i_leq_val = icmp sle i32 %i, %val
    br i1 %i_leq_val, label %for_body, label %end_loop

for_body:
    %temp = mul i32 %temp, %i
    %i = add i32 %i, 1
    br label %check_for_condition

end_loop:
    ret i32 %temp
}

在这里插入图片描述

使用lli执行该ll中间表示文件。

$ lli factorial.ll 
lli: factorial.ll:14:5: error: multiple definition of local value named 'temp'
    %temp = mul i32 %temp, %i

通过这个例子理解SSA,%temp进行了多次赋值。