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.

480 lines
14 KiB

@n = global i32 1000
@ks = global i32 15
@ps = global i32 4
@input = global [1000000 x float] zeroinitializer
@kernel = global [225 x float] zeroinitializer
@conv_output = global [1000000 x float] zeroinitializer
@pooling_output = global [59049 x float] zeroinitializer
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 @max(float %arg.a, float %arg.b) {
entry:
%t0 = alloca float
store float %arg.a, float* %t0
%t1 = alloca float
store float %arg.b, float* %t1
%t2 = load float, float* %t0
%t3 = load float, float* %t1
%t4 = fcmp ogt float %t2, %t3
%t5 = zext i1 %t4 to i32
%t6 = icmp ne i32 %t5, 0
br i1 %t6, label %if.then.1, label %if.else.2
if.then.1:
%t7 = load float, float* %t0
ret float %t7
if.else.2:
%t8 = load float, float* %t1
ret float %t8
if.end.3:
ret float 0x0000000000000000
}
define float @exp(float %arg.x) {
entry:
%t9 = alloca float
store float %arg.x, float* %t9
%t10 = load float, float* %t9
%t11 = fadd float 0x3FF0000000000000, %t10
%t12 = load float, float* %t9
%t13 = load float, float* %t9
%t14 = fmul float %t12, %t13
%t15 = fdiv float %t14, 0x4000000000000000
%t16 = fadd float %t11, %t15
%t17 = load float, float* %t9
%t18 = load float, float* %t9
%t19 = fmul float %t17, %t18
%t20 = load float, float* %t9
%t21 = fmul float %t19, %t20
%t22 = fdiv float %t21, 0x4018000000000000
%t23 = fadd float %t16, %t22
%t24 = load float, float* %t9
%t25 = load float, float* %t9
%t26 = fmul float %t24, %t25
%t27 = load float, float* %t9
%t28 = fmul float %t26, %t27
%t29 = load float, float* %t9
%t30 = fmul float %t28, %t29
%t31 = fdiv float %t30, 0x4038000000000000
%t32 = fadd float %t23, %t31
ret float %t32
}
define float @sigmoid(float %arg.x) {
entry:
%t33 = alloca float
store float %arg.x, float* %t33
%t34 = load float, float* %t33
%t35 = fsub float 0x0000000000000000, %t34
%t36 = call float @exp(float %t35)
%t37 = fadd float 0x3FF0000000000000, %t36
%t38 = fdiv float 0x3FF0000000000000, %t37
ret float %t38
}
define void @kernel_conv_pooling(float* %arg.A, float* %arg.B, float* %arg.C, float* %arg.kernel, i32 %arg.n, i32 %arg.ks, i32 %arg.ps) {
entry:
%t42 = alloca i32
%t43 = alloca i32
%t44 = alloca i32
%t45 = alloca i32
%t46 = alloca float
%t39 = alloca i32
store i32 %arg.n, i32* %t39
%t40 = alloca i32
store i32 %arg.ks, i32* %t40
%t41 = alloca i32
store i32 %arg.ps, i32* %t41
store i32 0, i32* %t42
store i32 0, i32* %t43
store i32 0, i32* %t44
store i32 0, i32* %t45
store float 0x0000000000000000, float* %t46
store i32 0, i32* %t42
br label %while.cond.4
while.cond.4:
%t47 = load i32, i32* %t42
%t48 = load i32, i32* %t39
%t49 = load i32, i32* %t40
%t50 = sub i32 %t48, %t49
%t51 = add i32 %t50, 1
%t52 = icmp slt i32 %t47, %t51
%t53 = zext i1 %t52 to i32
%t54 = icmp ne i32 %t53, 0
br i1 %t54, label %while.body.5, label %while.end.6
while.body.5:
store i32 0, i32* %t43
br label %while.cond.7
while.end.6:
%t106 = load i32, i32* %t39
%t107 = load i32, i32* %t40
%t108 = sub i32 %t106, %t107
%t109 = add i32 %t108, 1
store i32 %t109, i32* %t39
store i32 0, i32* %t42
br label %while.cond.16
while.cond.7:
%t55 = load i32, i32* %t43
%t56 = load i32, i32* %t39
%t57 = load i32, i32* %t40
%t58 = sub i32 %t56, %t57
%t59 = add i32 %t58, 1
%t60 = icmp slt i32 %t55, %t59
%t61 = zext i1 %t60 to i32
%t62 = icmp ne i32 %t61, 0
br i1 %t62, label %while.body.8, label %while.end.9
while.body.8:
store float 0x0000000000000000, float* %t46
store i32 0, i32* %t44
br label %while.cond.10
while.end.9:
%t104 = load i32, i32* %t42
%t105 = add i32 %t104, 1
store i32 %t105, i32* %t42
br label %while.cond.4
while.cond.10:
%t63 = load i32, i32* %t44
%t64 = load i32, i32* %t40
%t65 = icmp slt i32 %t63, %t64
%t66 = zext i1 %t65 to i32
%t67 = icmp ne i32 %t66, 0
br i1 %t67, label %while.body.11, label %while.end.12
while.body.11:
store i32 0, i32* %t45
br label %while.cond.13
while.end.12:
%t96 = load i32, i32* %t42
%t97 = load i32, i32* %t43
%t98 = mul i32 %t96, 1000
%t99 = add i32 %t98, %t97
%t100 = getelementptr inbounds float, float* %arg.B, i32 %t99
%t101 = load float, float* %t46
store float %t101, float* %t100
%t102 = load i32, i32* %t43
%t103 = add i32 %t102, 1
store i32 %t103, i32* %t43
br label %while.cond.7
while.cond.13:
%t68 = load i32, i32* %t45
%t69 = load i32, i32* %t40
%t70 = icmp slt i32 %t68, %t69
%t71 = zext i1 %t70 to i32
%t72 = icmp ne i32 %t71, 0
br i1 %t72, label %while.body.14, label %while.end.15
while.body.14:
%t73 = load float, float* %t46
%t74 = load i32, i32* %t42
%t75 = load i32, i32* %t44
%t76 = add i32 %t74, %t75
%t77 = load i32, i32* %t43
%t78 = load i32, i32* %t45
%t79 = add i32 %t77, %t78
%t80 = mul i32 %t76, 1000
%t81 = add i32 %t80, %t79
%t82 = getelementptr inbounds float, float* %arg.A, i32 %t81
%t83 = load float, float* %t82
%t84 = load i32, i32* %t44
%t85 = load i32, i32* %t45
%t86 = mul i32 %t84, 15
%t87 = add i32 %t86, %t85
%t88 = getelementptr inbounds float, float* %arg.kernel, i32 %t87
%t89 = load float, float* %t88
%t90 = fmul float %t83, %t89
%t91 = fadd float %t73, %t90
store float %t91, float* %t46
%t92 = load i32, i32* %t45
%t93 = add i32 %t92, 1
store i32 %t93, i32* %t45
br label %while.cond.13
while.end.15:
%t94 = load i32, i32* %t44
%t95 = add i32 %t94, 1
store i32 %t95, i32* %t44
br label %while.cond.10
while.cond.16:
%t110 = load i32, i32* %t42
%t111 = load i32, i32* %t39
%t112 = load i32, i32* %t40
%t113 = sub i32 %t111, %t112
%t114 = add i32 %t113, 1
%t115 = icmp slt i32 %t110, %t114
%t116 = zext i1 %t115 to i32
%t117 = icmp ne i32 %t116, 0
br i1 %t117, label %while.body.17, label %while.end.18
while.body.17:
store i32 0, i32* %t43
br label %while.cond.19
while.end.18:
%t169 = load i32, i32* %t39
%t170 = load i32, i32* %t40
%t171 = sub i32 %t169, %t170
%t172 = add i32 %t171, 1
%t173 = load i32, i32* %t41
%t174 = sdiv i32 %t172, %t173
store i32 %t174, i32* %t39
store i32 0, i32* %t42
br label %while.cond.28
while.cond.19:
%t118 = load i32, i32* %t43
%t119 = load i32, i32* %t39
%t120 = load i32, i32* %t40
%t121 = sub i32 %t119, %t120
%t122 = add i32 %t121, 1
%t123 = icmp slt i32 %t118, %t122
%t124 = zext i1 %t123 to i32
%t125 = icmp ne i32 %t124, 0
br i1 %t125, label %while.body.20, label %while.end.21
while.body.20:
store float 0x0000000000000000, float* %t46
store i32 0, i32* %t44
br label %while.cond.22
while.end.21:
%t167 = load i32, i32* %t42
%t168 = add i32 %t167, 1
store i32 %t168, i32* %t42
br label %while.cond.16
while.cond.22:
%t126 = load i32, i32* %t44
%t127 = load i32, i32* %t40
%t128 = icmp slt i32 %t126, %t127
%t129 = zext i1 %t128 to i32
%t130 = icmp ne i32 %t129, 0
br i1 %t130, label %while.body.23, label %while.end.24
while.body.23:
store i32 0, i32* %t45
br label %while.cond.25
while.end.24:
%t159 = load i32, i32* %t42
%t160 = load i32, i32* %t43
%t161 = mul i32 %t159, 1000
%t162 = add i32 %t161, %t160
%t163 = getelementptr inbounds float, float* %arg.A, i32 %t162
%t164 = load float, float* %t46
store float %t164, float* %t163
%t165 = load i32, i32* %t43
%t166 = add i32 %t165, 1
store i32 %t166, i32* %t43
br label %while.cond.19
while.cond.25:
%t131 = load i32, i32* %t45
%t132 = load i32, i32* %t40
%t133 = icmp slt i32 %t131, %t132
%t134 = zext i1 %t133 to i32
%t135 = icmp ne i32 %t134, 0
br i1 %t135, label %while.body.26, label %while.end.27
while.body.26:
%t136 = load float, float* %t46
%t137 = load i32, i32* %t42
%t138 = load i32, i32* %t44
%t139 = add i32 %t137, %t138
%t140 = load i32, i32* %t43
%t141 = load i32, i32* %t45
%t142 = add i32 %t140, %t141
%t143 = mul i32 %t139, 1000
%t144 = add i32 %t143, %t142
%t145 = getelementptr inbounds float, float* %arg.B, i32 %t144
%t146 = load float, float* %t145
%t147 = load i32, i32* %t44
%t148 = load i32, i32* %t45
%t149 = mul i32 %t147, 15
%t150 = add i32 %t149, %t148
%t151 = getelementptr inbounds float, float* %arg.kernel, i32 %t150
%t152 = load float, float* %t151
%t153 = fmul float %t146, %t152
%t154 = fadd float %t136, %t153
store float %t154, float* %t46
%t155 = load i32, i32* %t45
%t156 = add i32 %t155, 1
store i32 %t156, i32* %t45
br label %while.cond.25
while.end.27:
%t157 = load i32, i32* %t44
%t158 = add i32 %t157, 1
store i32 %t158, i32* %t44
br label %while.cond.22
while.cond.28:
%t175 = load i32, i32* %t42
%t176 = load i32, i32* %t39
%t177 = icmp slt i32 %t175, %t176
%t178 = zext i1 %t177 to i32
%t179 = icmp ne i32 %t178, 0
br i1 %t179, label %while.body.29, label %while.end.30
while.body.29:
store i32 0, i32* %t43
br label %while.cond.31
while.end.30:
store i32 0, i32* %t42
br label %while.cond.40
while.cond.31:
%t180 = load i32, i32* %t43
%t181 = load i32, i32* %t39
%t182 = icmp slt i32 %t180, %t181
%t183 = zext i1 %t182 to i32
%t184 = icmp ne i32 %t183, 0
br i1 %t184, label %while.body.32, label %while.end.33
while.body.32:
%t185 = load i32, i32* %t42
%t186 = load i32, i32* %t41
%t187 = mul i32 %t185, %t186
%t188 = load i32, i32* %t43
%t189 = load i32, i32* %t41
%t190 = mul i32 %t188, %t189
%t191 = mul i32 %t187, 1000
%t192 = add i32 %t191, %t190
%t193 = getelementptr inbounds float, float* %arg.A, i32 %t192
%t194 = load float, float* %t193
store float %t194, float* %t46
store i32 0, i32* %t44
br label %while.cond.34
while.end.33:
%t233 = load i32, i32* %t42
%t234 = add i32 %t233, 1
store i32 %t234, i32* %t42
br label %while.cond.28
while.cond.34:
%t195 = load i32, i32* %t44
%t196 = load i32, i32* %t41
%t197 = icmp slt i32 %t195, %t196
%t198 = zext i1 %t197 to i32
%t199 = icmp ne i32 %t198, 0
br i1 %t199, label %while.body.35, label %while.end.36
while.body.35:
store i32 0, i32* %t45
br label %while.cond.37
while.end.36:
%t225 = load i32, i32* %t42
%t226 = load i32, i32* %t43
%t227 = mul i32 %t225, 243
%t228 = add i32 %t227, %t226
%t229 = getelementptr inbounds float, float* %arg.C, i32 %t228
%t230 = load float, float* %t46
store float %t230, float* %t229
%t231 = load i32, i32* %t43
%t232 = add i32 %t231, 1
store i32 %t232, i32* %t43
br label %while.cond.31
while.cond.37:
%t200 = load i32, i32* %t45
%t201 = load i32, i32* %t41
%t202 = icmp slt i32 %t200, %t201
%t203 = zext i1 %t202 to i32
%t204 = icmp ne i32 %t203, 0
br i1 %t204, label %while.body.38, label %while.end.39
while.body.38:
%t205 = load float, float* %t46
%t206 = load i32, i32* %t42
%t207 = load i32, i32* %t41
%t208 = mul i32 %t206, %t207
%t209 = load i32, i32* %t44
%t210 = add i32 %t208, %t209
%t211 = load i32, i32* %t43
%t212 = load i32, i32* %t41
%t213 = mul i32 %t211, %t212
%t214 = load i32, i32* %t45
%t215 = add i32 %t213, %t214
%t216 = mul i32 %t210, 1000
%t217 = add i32 %t216, %t215
%t218 = getelementptr inbounds float, float* %arg.A, i32 %t217
%t219 = load float, float* %t218
%t220 = call float @max(float %t205, float %t219)
store float %t220, float* %t46
%t221 = load i32, i32* %t45
%t222 = add i32 %t221, 1
store i32 %t222, i32* %t45
br label %while.cond.37
while.end.39:
%t223 = load i32, i32* %t44
%t224 = add i32 %t223, 1
store i32 %t224, i32* %t44
br label %while.cond.34
while.cond.40:
%t235 = load i32, i32* %t42
%t236 = load i32, i32* %t39
%t237 = icmp slt i32 %t235, %t236
%t238 = zext i1 %t237 to i32
%t239 = icmp ne i32 %t238, 0
br i1 %t239, label %while.body.41, label %while.end.42
while.body.41:
store float 0x0000000000000000, float* %t46
store i32 0, i32* %t43
br label %while.cond.43
while.end.42:
ret void
while.cond.43:
%t240 = load i32, i32* %t43
%t241 = load i32, i32* %t39
%t242 = icmp slt i32 %t240, %t241
%t243 = zext i1 %t242 to i32
%t244 = icmp ne i32 %t243, 0
br i1 %t244, label %while.body.44, label %while.end.45
while.body.44:
%t245 = load i32, i32* %t42
%t246 = load i32, i32* %t43
%t247 = mul i32 %t245, 243
%t248 = add i32 %t247, %t246
%t249 = getelementptr inbounds float, float* %arg.C, i32 %t248
%t250 = load i32, i32* %t42
%t251 = load i32, i32* %t43
%t252 = mul i32 %t250, 243
%t253 = add i32 %t252, %t251
%t254 = getelementptr inbounds float, float* %arg.C, i32 %t253
%t255 = load float, float* %t254
%t256 = load i32, i32* %t42
%t257 = load i32, i32* %t43
%t258 = mul i32 %t256, 243
%t259 = add i32 %t258, %t257
%t260 = getelementptr inbounds float, float* %arg.C, i32 %t259
%t261 = load float, float* %t260
%t262 = call float @sigmoid(float %t261)
%t263 = fmul float %t255, %t262
store float %t263, float* %t249
%t264 = load i32, i32* %t43
%t265 = add i32 %t264, 1
store i32 %t265, i32* %t43
br label %while.cond.43
while.end.45:
%t266 = load i32, i32* %t42
%t267 = add i32 %t266, 1
store i32 %t267, i32* %t42
br label %while.cond.40
}
define i32 @main() {
entry:
%t268 = alloca i32
%t269 = load i32, i32* @n
%t270 = load i32, i32* @ks
%t271 = mul i32 2, %t270
%t272 = sub i32 %t269, %t271
%t273 = add i32 %t272, 2
%t274 = load i32, i32* @ps
%t275 = sdiv i32 %t273, %t274
store i32 %t275, i32* %t268
%t276 = getelementptr inbounds [1000000 x float], [1000000 x float]* @input, i32 0, i32 0
%t277 = call i32 @getfarray(float* %t276)
%t278 = getelementptr inbounds [225 x float], [225 x float]* @kernel, i32 0, i32 0
%t279 = call i32 @getfarray(float* %t278)
call void @starttime()
%t281 = load i32, i32* @n
%t282 = load i32, i32* @ks
%t283 = load i32, i32* @ps
%t284 = getelementptr inbounds [1000000 x float], [1000000 x float]* @input, i32 0, i32 0
%t285 = getelementptr inbounds [1000000 x float], [1000000 x float]* @conv_output, i32 0, i32 0
%t286 = getelementptr inbounds [59049 x float], [59049 x float]* @pooling_output, i32 0, i32 0
%t287 = getelementptr inbounds [225 x float], [225 x float]* @kernel, i32 0, i32 0
call void @kernel_conv_pooling(float* %t284, float* %t285, float* %t286, float* %t287, i32 %t281, i32 %t282, i32 %t283)
call void @stoptime()
%t290 = load i32, i32* %t268
%t291 = load i32, i32* %t268
%t292 = mul i32 %t290, %t291
%t293 = getelementptr inbounds [59049 x float], [59049 x float]* @pooling_output, i32 0, i32 0
call void @putfarray(i32 %t292, float* %t293)
ret i32 0
}