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.
nudt-compiler-cpp/03_sort1.ir

491 lines
16 KiB

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