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.

314 lines
9.2 KiB

@temp = global float 0x3FF0000000000000
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 i32 @func(i32 %arg.i, i32 %arg.j) {
entry:
%t0 = alloca i32
store i32 %arg.i, i32* %t0
%t1 = alloca i32
store i32 %arg.j, i32* %t1
%t2 = load i32, i32* %t0
%t3 = load i32, i32* %t1
%t4 = add i32 %t2, %t3
%t5 = load i32, i32* %t0
%t6 = load i32, i32* %t1
%t7 = add i32 %t5, %t6
%t8 = add i32 %t7, 1
%t9 = mul i32 %t4, %t8
%t10 = sdiv i32 %t9, 2
%t11 = load i32, i32* %t0
%t12 = add i32 %t10, %t11
%t13 = add i32 %t12, 1
ret i32 %t13
}
define float @Vectordot(float* %arg.v, float* %arg.u, i32 %arg.n) {
entry:
%t15 = alloca i32
%t16 = alloca float
%t14 = alloca i32
store i32 %arg.n, i32* %t14
store i32 0, i32* %t15
store float 0x0000000000000000, float* %t16
br label %while.cond.1
while.cond.1:
%t17 = load i32, i32* %t15
%t18 = load i32, i32* %t14
%t19 = icmp slt i32 %t17, %t18
%t20 = zext i1 %t19 to i32
%t21 = icmp ne i32 %t20, 0
br i1 %t21, label %while.body.2, label %while.end.3
while.body.2:
%t22 = load float, float* %t16
%t23 = load i32, i32* %t15
%t24 = getelementptr inbounds float, float* %arg.v, i32 %t23
%t25 = load float, float* %t24
%t26 = load i32, i32* %t15
%t27 = getelementptr inbounds float, float* %arg.u, i32 %t26
%t28 = load float, float* %t27
%t29 = fmul float %t25, %t28
%t30 = fadd float %t22, %t29
store float %t30, float* %t16
%t31 = load i32, i32* %t15
%t32 = add i32 %t31, 1
store i32 %t32, i32* %t15
br label %while.cond.1
while.end.3:
%t33 = load float, float* %t16
ret float %t33
}
define void @mult1(float* %arg.v, float* %arg.out, i32 %arg.n) {
entry:
%t35 = alloca i32
%t36 = alloca i32
%t37 = alloca float
%t34 = alloca i32
store i32 %arg.n, i32* %t34
store i32 0, i32* %t35
store i32 0, i32* %t36
store float 0x0000000000000000, float* %t37
br label %while.cond.4
while.cond.4:
%t38 = load i32, i32* %t35
%t39 = load i32, i32* %t34
%t40 = icmp slt i32 %t38, %t39
%t41 = zext i1 %t40 to i32
%t42 = icmp ne i32 %t41, 0
br i1 %t42, label %while.body.5, label %while.end.6
while.body.5:
br label %while.cond.7
while.end.6:
ret void
while.cond.7:
%t43 = load i32, i32* %t36
%t44 = load i32, i32* %t34
%t45 = icmp slt i32 %t43, %t44
%t46 = zext i1 %t45 to i32
%t47 = icmp ne i32 %t46, 0
br i1 %t47, label %while.body.8, label %while.end.9
while.body.8:
%t48 = load float, float* %t37
%t49 = load i32, i32* %t36
%t50 = getelementptr inbounds float, float* %arg.v, i32 %t49
%t51 = load float, float* %t50
%t52 = load i32, i32* %t35
%t53 = load i32, i32* %t36
%t54 = call i32 @func(i32 %t52, i32 %t53)
%t55 = sitofp i32 %t54 to float
%t56 = fdiv float %t51, %t55
%t57 = fadd float %t48, %t56
store float %t57, float* %t37
%t58 = load i32, i32* %t36
%t59 = add i32 %t58, 1
store i32 %t59, i32* %t36
br label %while.cond.7
while.end.9:
%t60 = load i32, i32* %t35
%t61 = getelementptr inbounds float, float* %arg.out, i32 %t60
%t62 = load float, float* %t37
store float %t62, float* %t61
%t63 = load i32, i32* %t35
%t64 = add i32 %t63, 1
store i32 %t64, i32* %t35
br label %while.cond.4
}
define void @mult2(float* %arg.v, float* %arg.out, i32 %arg.n) {
entry:
%t66 = alloca i32
%t67 = alloca i32
%t68 = alloca float
%t65 = alloca i32
store i32 %arg.n, i32* %t65
store i32 0, i32* %t66
store i32 0, i32* %t67
store float 0x0000000000000000, float* %t68
br label %while.cond.10
while.cond.10:
%t69 = load i32, i32* %t66
%t70 = load i32, i32* %t65
%t71 = icmp slt i32 %t69, %t70
%t72 = zext i1 %t71 to i32
%t73 = icmp ne i32 %t72, 0
br i1 %t73, label %while.body.11, label %while.end.12
while.body.11:
br label %while.cond.13
while.end.12:
ret void
while.cond.13:
%t74 = load i32, i32* %t67
%t75 = load i32, i32* %t65
%t76 = icmp slt i32 %t74, %t75
%t77 = zext i1 %t76 to i32
%t78 = icmp ne i32 %t77, 0
br i1 %t78, label %while.body.14, label %while.end.15
while.body.14:
%t79 = load float, float* %t68
%t80 = load i32, i32* %t67
%t81 = getelementptr inbounds float, float* %arg.v, i32 %t80
%t82 = load float, float* %t81
%t83 = load i32, i32* %t67
%t84 = load i32, i32* %t66
%t85 = call i32 @func(i32 %t83, i32 %t84)
%t86 = sitofp i32 %t85 to float
%t87 = fdiv float %t82, %t86
%t88 = fadd float %t79, %t87
store float %t88, float* %t68
%t89 = load i32, i32* %t67
%t90 = add i32 %t89, 1
store i32 %t90, i32* %t67
br label %while.cond.13
while.end.15:
%t91 = load i32, i32* %t66
%t92 = getelementptr inbounds float, float* %arg.out, i32 %t91
%t93 = load float, float* %t68
store float %t93, float* %t92
%t94 = load i32, i32* %t66
%t95 = add i32 %t94, 1
store i32 %t95, i32* %t66
br label %while.cond.10
}
define void @mult_combin(float* %arg.v, float* %arg.out, i32 %arg.n, float* %arg.tmp) {
entry:
%t96 = alloca i32
store i32 %arg.n, i32* %t96
%t97 = load i32, i32* %t96
call void @mult1(float* %arg.v, float* %arg.tmp, i32 %t97)
%t99 = load i32, i32* %t96
call void @mult2(float* %arg.tmp, float* %arg.out, i32 %t99)
ret void
}
define float @my_sqrt(float %arg.input) {
entry:
%t101 = alloca float
store float %arg.input, float* %t101
br label %while.cond.16
while.cond.16:
%t102 = load float, float* @temp
%t103 = load float, float* %t101
%t104 = load float, float* @temp
%t105 = fdiv float %t103, %t104
%t106 = fsub float %t102, %t105
%t107 = fcmp ogt float %t106, 0x3EB0C6F7A0000000
%t108 = zext i1 %t107 to i32
%t109 = icmp ne i32 %t108, 0
br i1 %t109, label %while.body.17, label %lor.rhs.19
while.body.17:
%t118 = load float, float* @temp
%t119 = load float, float* %t101
%t120 = load float, float* @temp
%t121 = fdiv float %t119, %t120
%t122 = fadd float %t118, %t121
%t123 = fdiv float %t122, 0x4000000000000000
store float %t123, float* @temp
br label %while.cond.16
while.end.18:
%t124 = load float, float* @temp
ret float %t124
lor.rhs.19:
%t110 = load float, float* @temp
%t111 = load float, float* %t101
%t112 = load float, float* @temp
%t113 = fdiv float %t111, %t112
%t114 = fsub float %t110, %t113
%t115 = fcmp olt float %t114, 0xBEB0C6F7A0000000
%t116 = zext i1 %t115 to i32
%t117 = icmp ne i32 %t116, 0
br i1 %t117, label %while.body.17, label %while.end.18
}
define i32 @main() {
entry:
%t125 = alloca i32
%t131 = alloca float, i32 100000
%t132 = alloca float, i32 100000
%t133 = alloca float, i32 100000
%t134 = alloca i32
%t155 = alloca float
store i32 100000, i32* %t125
%t126 = load i32, i32* %t125
%t127 = icmp sle i32 %t126, 0
%t128 = zext i1 %t127 to i32
%t129 = icmp ne i32 %t128, 0
br i1 %t129, label %if.then.20, label %if.end.21
if.then.20:
store i32 2000, i32* %t125
br label %if.end.21
if.end.21:
call void @starttime()
store i32 0, i32* %t134
br label %while.cond.22
while.cond.22:
%t135 = load i32, i32* %t134
%t136 = load i32, i32* %t125
%t137 = icmp slt i32 %t135, %t136
%t138 = zext i1 %t137 to i32
%t139 = icmp ne i32 %t138, 0
br i1 %t139, label %while.body.23, label %while.end.24
while.body.23:
%t140 = load i32, i32* %t134
%t141 = getelementptr inbounds float, float* %t131, i32 %t140
store float 0x3FF0000000000000, float* %t141
%t142 = load i32, i32* %t134
%t143 = add i32 %t142, 1
store i32 %t143, i32* %t134
br label %while.cond.22
while.end.24:
store i32 0, i32* %t134
br label %while.cond.25
while.cond.25:
%t144 = load i32, i32* %t134
%t145 = icmp slt i32 %t144, 1000
%t146 = zext i1 %t145 to i32
%t147 = icmp ne i32 %t146, 0
br i1 %t147, label %while.body.26, label %while.end.27
while.body.26:
%t148 = load i32, i32* %t125
call void @mult_combin(float* %t131, float* %t132, i32 %t148, float* %t133)
%t150 = load i32, i32* %t125
call void @mult_combin(float* %t132, float* %t131, i32 %t150, float* %t133)
%t152 = load i32, i32* %t134
%t153 = add i32 %t152, 1
store i32 %t153, i32* %t134
br label %while.cond.25
while.end.27:
call void @stoptime()
%t156 = load i32, i32* %t125
%t157 = call float @Vectordot(float* %t131, float* %t132, i32 %t156)
%t158 = load i32, i32* %t125
%t159 = call float @Vectordot(float* %t132, float* %t132, i32 %t158)
%t160 = fdiv float %t157, %t159
%t161 = call float @my_sqrt(float %t160)
store float %t161, float* %t155
%t162 = load float, float* %t155
%t163 = fsub float %t162, 0x3FF0000000000000
%t164 = fcmp ole float %t163, 0x3EB0C6F7A0000000
%t165 = zext i1 %t164 to i32
%t166 = icmp ne i32 %t165, 0
br i1 %t166, label %land.rhs.31, label %if.else.29
if.then.28:
call void @putint(i32 1)
br label %if.end.30
if.else.29:
call void @putint(i32 0)
br label %if.end.30
if.end.30:
call void @putch(i32 10)
ret i32 0
land.rhs.31:
%t167 = load float, float* %t155
%t168 = fsub float %t167, 0x3FF0000000000000
%t169 = fcmp oge float %t168, 0xBEB0C6F7A0000000
%t170 = zext i1 %t169 to i32
%t171 = icmp ne i32 %t170, 0
br i1 %t171, label %if.then.28, label %if.else.29
}