You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
2.1 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

; ModuleID = 'while.c'
source_filename = "while.c"
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-pc-linux-gnu"
; 全局变量定义声明已显式初始化值global前不用加common, 未显式初始化值统一赋值0
@a = common global i32 0, align 4
@b = common global i32 0, align 4
;Function 主函数入口
define i32 @main() #0{
0:
; 同样预先分配一个%1并初始化为0
%1 = alloca i32, align 4
store i32 0, i32* %1, align 4
; a 和 b不用再alloca直接赋值
store i32 0, i32* @b, align 4
store i32 3, i32* @a, align 4
; 一个基本块结束进入while条件判断域
br label %2
2: ; preds = %0, %5 ; %0 为入口bb%5为循环体bb
;加载a值
%3 = load i32, i32* @a, align 4
; 比较 a>0
%4 = icmp sgt i32 %3, 0
; 根据while的cond表达式真假跳转 为假标号得根据bb5中标号使用情况确定
br i1 %4, label %5, label %11
5: ;preds = %2
;加载a值和b值
%6 = load i32, i32* @b, align 4
%7 = load i32, i32* @a, align 4
; a+b
%8 = add i32 %6, %7
; 保存结果至b
store i32 %8, i32* @b, align 4
; a = a-1
%9 = load i32, i32* @a, align 4
%10 = sub i32 %9, 1
store i32 %10, i32* @a, align 4
; 循环体内部基本块结束,跳转至循环条件判断入口
br label %2
11: ;preds = %2
;加载b值
%12 = load i32, i32* @b, align 4
ret i32 %12
}
attributes #0 = { noinline nounwind optnone uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
!llvm.module.flags = !{!0}
!llvm.ident = !{!1}
!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{!"clang version 6.0.0-1ubuntu2 (tags/RELEASE_600/final)"}