forked from NUDT-compiler/nudt-compiler-cpp
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.
274 lines
8.1 KiB
274 lines
8.1 KiB
@RADIUS = global float 0x4016000000000000
|
|
@PI = global float 0x400921FB60000000
|
|
@EPS = global float 0x3EB0C6F7A0000000
|
|
@PI_HEX = global float 0x400921FB60000000
|
|
@HEX2 = global float 0x3FB4000000000000
|
|
@FACT = global float 0xC0E01D0000000000
|
|
@EVAL1 = global float 0x4057C21FC0000000
|
|
@EVAL2 = global float 0x4041475CE0000000
|
|
@EVAL3 = global float 0x4041475CE0000000
|
|
@CONV1 = global float 0x406D200000000000
|
|
@CONV2 = global float 0x40AFFE0000000000
|
|
@MAX = global i32 1000000000
|
|
@TWO = global i32 2
|
|
@THREE = global i32 3
|
|
@FIVE = global i32 5
|
|
|
|
declare i32 @getint()
|
|
declare float @getfloat()
|
|
declare i32 @getarray(i32* %arg.a)
|
|
declare i32 @getfarray(float* %arg.a)
|
|
declare i32 @getch()
|
|
declare void @putint(i32 %arg.x)
|
|
declare void @putfloat(float %arg.x)
|
|
declare void @putarray(i32 %arg.n, i32* %arg.a)
|
|
declare void @putfarray(i32 %arg.n, float* %arg.a)
|
|
declare void @putch(i32 %arg.x)
|
|
declare void @starttime()
|
|
declare void @stoptime()
|
|
define float @float_abs(float %arg.x) {
|
|
entry:
|
|
%t0 = alloca float
|
|
store float %arg.x, float* %t0
|
|
%t1 = load float, float* %t0
|
|
%t2 = fcmp olt float %t1, 0x0000000000000000
|
|
%t3 = zext i1 %t2 to i32
|
|
%t4 = icmp ne i32 %t3, 0
|
|
br i1 %t4, label %if.then.1, label %if.end.2
|
|
if.then.1:
|
|
%t5 = load float, float* %t0
|
|
%t6 = fsub float 0x0000000000000000, %t5
|
|
ret float %t6
|
|
if.end.2:
|
|
%t7 = load float, float* %t0
|
|
ret float %t7
|
|
}
|
|
define float @circle_area(i32 %arg.radius) {
|
|
entry:
|
|
%t8 = alloca i32
|
|
store i32 %arg.radius, i32* %t8
|
|
%t9 = load float, float* @PI
|
|
%t10 = load i32, i32* %t8
|
|
%t11 = sitofp i32 %t10 to float
|
|
%t12 = fmul float %t9, %t11
|
|
%t13 = load i32, i32* %t8
|
|
%t14 = sitofp i32 %t13 to float
|
|
%t15 = fmul float %t12, %t14
|
|
%t16 = load i32, i32* %t8
|
|
%t17 = load i32, i32* %t8
|
|
%t18 = mul i32 %t16, %t17
|
|
%t19 = load float, float* @PI
|
|
%t20 = sitofp i32 %t18 to float
|
|
%t21 = fmul float %t20, %t19
|
|
%t22 = fadd float %t15, %t21
|
|
%t23 = fdiv float %t22, 0x4000000000000000
|
|
ret float %t23
|
|
}
|
|
define i32 @float_eq(float %arg.a, float %arg.b) {
|
|
entry:
|
|
%t24 = alloca float
|
|
store float %arg.a, float* %t24
|
|
%t25 = alloca float
|
|
store float %arg.b, float* %t25
|
|
%t26 = load float, float* %t24
|
|
%t27 = load float, float* %t25
|
|
%t28 = fsub float %t26, %t27
|
|
%t29 = call float @float_abs(float %t28)
|
|
%t30 = load float, float* @EPS
|
|
%t31 = fcmp olt float %t29, %t30
|
|
%t32 = zext i1 %t31 to i32
|
|
%t33 = icmp ne i32 %t32, 0
|
|
br i1 %t33, label %if.then.3, label %if.else.4
|
|
if.then.3:
|
|
ret i32 1
|
|
if.else.4:
|
|
ret i32 0
|
|
if.end.5:
|
|
ret i32 0
|
|
}
|
|
define void @error() {
|
|
entry:
|
|
call void @putch(i32 101)
|
|
call void @putch(i32 114)
|
|
call void @putch(i32 114)
|
|
call void @putch(i32 111)
|
|
call void @putch(i32 114)
|
|
call void @putch(i32 10)
|
|
ret void
|
|
}
|
|
define void @ok() {
|
|
entry:
|
|
call void @putch(i32 111)
|
|
call void @putch(i32 107)
|
|
call void @putch(i32 10)
|
|
ret void
|
|
}
|
|
define void @assert(i32 %arg.cond) {
|
|
entry:
|
|
%t43 = alloca i32
|
|
store i32 %arg.cond, i32* %t43
|
|
%t44 = load i32, i32* %t43
|
|
%t45 = icmp eq i32 %t44, 0
|
|
%t46 = zext i1 %t45 to i32
|
|
%t47 = icmp ne i32 %t46, 0
|
|
br i1 %t47, label %if.then.6, label %if.else.7
|
|
if.then.6:
|
|
call void @error()
|
|
br label %if.end.8
|
|
if.else.7:
|
|
call void @ok()
|
|
br label %if.end.8
|
|
if.end.8:
|
|
ret void
|
|
}
|
|
define void @assert_not(i32 %arg.cond) {
|
|
entry:
|
|
%t50 = alloca i32
|
|
store i32 %arg.cond, i32* %t50
|
|
%t51 = load i32, i32* %t50
|
|
%t52 = icmp ne i32 %t51, 0
|
|
br i1 %t52, label %if.then.9, label %if.else.10
|
|
if.then.9:
|
|
call void @error()
|
|
br label %if.end.11
|
|
if.else.10:
|
|
call void @ok()
|
|
br label %if.end.11
|
|
if.end.11:
|
|
ret void
|
|
}
|
|
define i32 @main() {
|
|
entry:
|
|
%t87 = alloca i32
|
|
%t88 = alloca i32
|
|
%t89 = alloca float, i32 10
|
|
%t100 = alloca i32
|
|
%t106 = alloca float
|
|
%t108 = alloca float
|
|
%t114 = alloca float
|
|
%t55 = load float, float* @HEX2
|
|
%t56 = load float, float* @FACT
|
|
%t57 = call i32 @float_eq(float %t55, float %t56)
|
|
call void @assert_not(i32 %t57)
|
|
%t59 = load float, float* @EVAL1
|
|
%t60 = load float, float* @EVAL2
|
|
%t61 = call i32 @float_eq(float %t59, float %t60)
|
|
call void @assert_not(i32 %t61)
|
|
%t63 = load float, float* @EVAL2
|
|
%t64 = load float, float* @EVAL3
|
|
%t65 = call i32 @float_eq(float %t63, float %t64)
|
|
call void @assert(i32 %t65)
|
|
%t67 = load float, float* @RADIUS
|
|
%t68 = fptosi float %t67 to i32
|
|
%t69 = call float @circle_area(i32 %t68)
|
|
%t70 = call float @circle_area(i32 5)
|
|
%t71 = call i32 @float_eq(float %t69, float %t70)
|
|
call void @assert(i32 %t71)
|
|
%t73 = load float, float* @CONV1
|
|
%t74 = load float, float* @CONV2
|
|
%t75 = call i32 @float_eq(float %t73, float %t74)
|
|
call void @assert_not(i32 %t75)
|
|
%t77 = fcmp one float 0x3FF8000000000000, 0x0000000000000000
|
|
br i1 %t77, label %if.then.12, label %if.end.13
|
|
if.then.12:
|
|
call void @ok()
|
|
br label %if.end.13
|
|
if.end.13:
|
|
%t79 = icmp ne i32 1, 0
|
|
br i1 %t79, label %if.then.14, label %if.end.15
|
|
if.then.14:
|
|
call void @ok()
|
|
br label %if.end.15
|
|
if.end.15:
|
|
%t81 = fcmp one float 0x0000000000000000, 0x0000000000000000
|
|
br i1 %t81, label %land.rhs.18, label %if.end.17
|
|
if.then.16:
|
|
call void @error()
|
|
br label %if.end.17
|
|
if.end.17:
|
|
%t84 = icmp ne i32 0, 0
|
|
br i1 %t84, label %if.then.19, label %lor.rhs.21
|
|
land.rhs.18:
|
|
%t82 = icmp ne i32 3, 0
|
|
br i1 %t82, label %if.then.16, label %if.end.17
|
|
if.then.19:
|
|
call void @ok()
|
|
br label %if.end.20
|
|
if.end.20:
|
|
store i32 1, i32* %t87
|
|
store i32 0, i32* %t88
|
|
%t90 = getelementptr inbounds float, float* %t89, i32 0
|
|
store float 0x3FF0000000000000, float* %t90
|
|
%t91 = getelementptr inbounds float, float* %t89, i32 1
|
|
store float 0x4000000000000000, float* %t91
|
|
%t92 = getelementptr inbounds float, float* %t89, i32 2
|
|
store float 0x0000000000000000, float* %t92
|
|
%t93 = getelementptr inbounds float, float* %t89, i32 3
|
|
store float 0x0000000000000000, float* %t93
|
|
%t94 = getelementptr inbounds float, float* %t89, i32 4
|
|
store float 0x0000000000000000, float* %t94
|
|
%t95 = getelementptr inbounds float, float* %t89, i32 5
|
|
store float 0x0000000000000000, float* %t95
|
|
%t96 = getelementptr inbounds float, float* %t89, i32 6
|
|
store float 0x0000000000000000, float* %t96
|
|
%t97 = getelementptr inbounds float, float* %t89, i32 7
|
|
store float 0x0000000000000000, float* %t97
|
|
%t98 = getelementptr inbounds float, float* %t89, i32 8
|
|
store float 0x0000000000000000, float* %t98
|
|
%t99 = getelementptr inbounds float, float* %t89, i32 9
|
|
store float 0x0000000000000000, float* %t99
|
|
%t101 = call i32 @getfarray(float* %t89)
|
|
store i32 %t101, i32* %t100
|
|
br label %while.cond.22
|
|
lor.rhs.21:
|
|
%t85 = fcmp one float 0x3FD3333340000000, 0x0000000000000000
|
|
br i1 %t85, label %if.then.19, label %if.end.20
|
|
while.cond.22:
|
|
%t102 = load i32, i32* %t87
|
|
%t103 = icmp slt i32 %t102, 1000000000
|
|
%t104 = zext i1 %t103 to i32
|
|
%t105 = icmp ne i32 %t104, 0
|
|
br i1 %t105, label %while.body.23, label %while.end.24
|
|
while.body.23:
|
|
%t107 = call float @getfloat()
|
|
store float %t107, float* %t106
|
|
%t109 = load float, float* @PI
|
|
%t110 = load float, float* %t106
|
|
%t111 = fmul float %t109, %t110
|
|
%t112 = load float, float* %t106
|
|
%t113 = fmul float %t111, %t112
|
|
store float %t113, float* %t108
|
|
%t115 = load float, float* %t106
|
|
%t116 = fptosi float %t115 to i32
|
|
%t117 = call float @circle_area(i32 %t116)
|
|
store float %t117, float* %t114
|
|
%t118 = load i32, i32* %t88
|
|
%t119 = getelementptr inbounds float, float* %t89, i32 %t118
|
|
%t120 = load i32, i32* %t88
|
|
%t121 = getelementptr inbounds float, float* %t89, i32 %t120
|
|
%t122 = load float, float* %t121
|
|
%t123 = load float, float* %t106
|
|
%t124 = fadd float %t122, %t123
|
|
store float %t124, float* %t119
|
|
%t125 = load float, float* %t108
|
|
call void @putfloat(float %t125)
|
|
call void @putch(i32 32)
|
|
%t128 = load float, float* %t114
|
|
%t129 = fptosi float %t128 to i32
|
|
call void @putint(i32 %t129)
|
|
call void @putch(i32 10)
|
|
%t132 = load i32, i32* %t87
|
|
%t133 = sitofp i32 %t132 to float
|
|
%t134 = fmul float %t133, 0x4024000000000000
|
|
%t135 = fptosi float %t134 to i32
|
|
store i32 %t135, i32* %t87
|
|
%t136 = load i32, i32* %t88
|
|
%t137 = add i32 %t136, 1
|
|
store i32 %t137, i32* %t88
|
|
br label %while.cond.22
|
|
while.end.24:
|
|
%t138 = load i32, i32* %t100
|
|
call void @putfarray(i32 %t138, float* %t89)
|
|
ret i32 0
|
|
}
|