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.

52 lines
1.6 KiB

1 year ago
; 中间代码头部尾部参考clang -S -emit-llvm 生成结果
; ModuleID = 'func_test.c'
source_filename = "func_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"
define dso_local i32 @add(i32 %0, i32 %1) #0 {
%3 = alloca i32, align 4
store i32 %0, i32* %3, align 4 ; alloca a
%4 = alloca i32, align 4
store i32 %1, i32* %4, align 4 ; alloca b
%5 = load i32, i32* %3, align 4
%6 = load i32, i32* %4, align 4
%7 = add nsw i32 %5, %6 ; a+b
%8 = sub nsw i32 %7, 1 ; a+b-1
ret i32 %8 ; return a+b-1
}
define dso_local i32 @main() #0 {
%1 = alloca i32, align 4
%2 = alloca i32, align 4
%3 = alloca i32, align 4
store i32 3, i32* %1, align 4 ; a=3
store i32 2, i32* %2, align 4 ; b=2
store i32 5, i32* %3, align 4 ; c=5
%4 = load i32, i32* %1, align 4
%5 = load i32, i32* %2, align 4
%6 = load i32, i32* %3, align 4
%7 = call i32 @add(i32 %4, i32 %5) ; add(a, b)
%8 = add nsw i32 %6, %7 ; c+add(a,b)
ret i32 %8
}
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.ident = !{!5}
!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 7, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 1}
!4 = !{i32 7, !"frame-pointer", i32 2}
!5 = !{!"Ubuntu clang version 14.0.0-1ubuntu1.1"}