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.

49 lines
2.3 KiB

1 year ago
; 中间代码头部尾部参考clang -S -emit-llvm 生成结果
; 头部:记录程序信息包括源文件名称、数据布局、目标平台
; ModuleID = 'while_test.c'
source_filename = "while_test.c"
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-pc-linux-gnu"
@b = common dso_local global i32 0, align 4 ; int b
@a = common dso_local global i32 0, align 4 ; int a
define dso_local i32 @main() #0 {
store i32 0, i32* @b, align 4 ; b = 0
store i32 3, i32* @a, align 4 ; a = 3
br label %1
1: ; label 1
%2 = load i32, i32* @a, align 4
%3 = icmp sgt i32 %2, 0 ; a > 0?
br i1 %3, label %4, label %9 ; true->4 false->9
4: ; label 4 while true
%5 = load i32, i32* @b, align 4 ; [b]+a
%6 = load i32, i32* @a, align 4 ; b+[a]
%7 = add nsw i32 %5, %6 ; b+a
store i32 %7, i32* @b, align 4; b = b+a
%8 = sub nsw i32 %6 , 1 ; a-1
store i32 %8, i32* @a, align 4 ; a = a-1
br label %1
9: ; label 9
%10 = load i32, i32* @b, align 4
ret i32 %10 ; return b
}
; 尾部记录LLVM模块标识
attributes #0 = { noinline nounwind optnone uwtable "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
!llvm.module.flags = !{!0, !1, !2, !3, !4} ; LLVM模块的一些标志
!llvm.ident = !{!5} ; LLVM的标识信息
!0 = !{i32 1, !"wchar_size", i32 4} ; LLVM模块标志表示wchar_t的大小为4
!1 = !{i32 7, !"PIC Level", i32 2} ; LLVM模块标志表示启用位置无关代码的级别为2
!2 = !{i32 7, !"PIE Level", i32 2} ; LLVM模块标志表示启用可执行和链接的级别为2
!3 = !{i32 7, !"uwtable", i32 1} ; LLVM模块标志表示启用表格异常处理
!4 = !{i32 7, !"frame-pointer", i32 2} ; LLVM模块标志表示帧指针的使用级别为2
!5 = !{!"Ubuntu clang version 14.0.0-1ubuntu1.1"} ; LLVM的标识信息表示使用的编译器版本为Ubuntu clang version 14.0.0-1ubuntu1.1
!6 = distinct !{!6, !7} ; 定义了一个distinct节点
!7 = !{!"llvm.loop.mustprogress"} ; 定义了一个LLVM循环的特性