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.
379 lines
11 KiB
379 lines
11 KiB
@INF = global i32 1073741824
|
|
@a = global [900 x i32] zeroinitializer
|
|
@step = global [8 x i32] [i32 1, i32 0, i32 -1, i32 0, i32 0, i32 1, i32 0, i32 -1]
|
|
@w = global i32 0
|
|
@h = global i32 0
|
|
@x_0 = global i32 0
|
|
@y_0 = global i32 0
|
|
@x_1 = global i32 0
|
|
@y_1 = 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 @search(i32 %arg.x, i32 %arg.y, i32 %arg.n) {
|
|
entry:
|
|
%t7 = alloca i32
|
|
%t8 = alloca i32
|
|
%t13 = alloca i32
|
|
%t14 = alloca i32
|
|
%t16 = alloca i32
|
|
%t95 = alloca i32
|
|
%t0 = alloca i32
|
|
store i32 %arg.x, i32* %t0
|
|
%t1 = alloca i32
|
|
store i32 %arg.y, i32* %t1
|
|
%t2 = alloca i32
|
|
store i32 %arg.n, i32* %t2
|
|
%t3 = load i32, i32* %t2
|
|
%t4 = icmp sgt i32 %t3, 10
|
|
%t5 = zext i1 %t4 to i32
|
|
%t6 = icmp ne i32 %t5, 0
|
|
br i1 %t6, label %if.then.1, label %if.end.2
|
|
if.then.1:
|
|
ret i32 1073741824
|
|
if.end.2:
|
|
store i32 1073741824, i32* %t7
|
|
store i32 0, i32* %t8
|
|
br label %while.cond.3
|
|
while.cond.3:
|
|
%t9 = load i32, i32* %t8
|
|
%t10 = icmp slt i32 %t9, 4
|
|
%t11 = zext i1 %t10 to i32
|
|
%t12 = icmp ne i32 %t11, 0
|
|
br i1 %t12, label %while.body.4, label %while.end.5
|
|
while.body.4:
|
|
store i32 0, i32* %t13
|
|
%t15 = load i32, i32* %t0
|
|
store i32 %t15, i32* %t14
|
|
%t17 = load i32, i32* %t1
|
|
store i32 %t17, i32* %t16
|
|
br label %while.cond.6
|
|
while.end.5:
|
|
%t126 = load i32, i32* %t7
|
|
%t127 = icmp sgt i32 %t126, 10
|
|
%t128 = zext i1 %t127 to i32
|
|
%t129 = icmp ne i32 %t128, 0
|
|
br i1 %t129, label %if.then.24, label %if.end.25
|
|
while.cond.6:
|
|
%t18 = load i32, i32* %t14
|
|
%t19 = load i32, i32* %t16
|
|
%t20 = mul i32 %t18, 30
|
|
%t21 = add i32 %t20, %t19
|
|
%t22 = getelementptr inbounds [900 x i32], [900 x i32]* @a, i32 0, i32 %t21
|
|
%t23 = load i32, i32* %t22
|
|
%t24 = icmp ne i32 %t23, 1
|
|
%t25 = zext i1 %t24 to i32
|
|
%t26 = icmp ne i32 %t25, 0
|
|
br i1 %t26, label %while.body.7, label %while.end.8
|
|
while.body.7:
|
|
%t27 = load i32, i32* %t14
|
|
%t28 = load i32, i32* @x_1
|
|
%t29 = icmp eq i32 %t27, %t28
|
|
%t30 = zext i1 %t29 to i32
|
|
%t31 = icmp ne i32 %t30, 0
|
|
br i1 %t31, label %land.rhs.11, label %if.end.10
|
|
while.end.8:
|
|
%t52 = load i32, i32* %t14
|
|
%t53 = load i32, i32* @x_1
|
|
%t54 = icmp eq i32 %t52, %t53
|
|
%t55 = zext i1 %t54 to i32
|
|
%t56 = icmp ne i32 %t55, 0
|
|
br i1 %t56, label %land.rhs.14, label %if.end.13
|
|
if.then.9:
|
|
br label %while.end.8
|
|
if.end.10:
|
|
%t37 = load i32, i32* %t14
|
|
%t38 = load i32, i32* %t8
|
|
%t39 = mul i32 %t38, 2
|
|
%t40 = getelementptr inbounds [8 x i32], [8 x i32]* @step, i32 0, i32 %t39
|
|
%t41 = load i32, i32* %t40
|
|
%t42 = add i32 %t37, %t41
|
|
store i32 %t42, i32* %t14
|
|
%t43 = load i32, i32* %t16
|
|
%t44 = load i32, i32* %t8
|
|
%t45 = mul i32 %t44, 2
|
|
%t46 = add i32 %t45, 1
|
|
%t47 = getelementptr inbounds [8 x i32], [8 x i32]* @step, i32 0, i32 %t46
|
|
%t48 = load i32, i32* %t47
|
|
%t49 = add i32 %t43, %t48
|
|
store i32 %t49, i32* %t16
|
|
%t50 = load i32, i32* %t13
|
|
%t51 = add i32 %t50, 1
|
|
store i32 %t51, i32* %t13
|
|
br label %while.cond.6
|
|
land.rhs.11:
|
|
%t32 = load i32, i32* %t16
|
|
%t33 = load i32, i32* @y_1
|
|
%t34 = icmp eq i32 %t32, %t33
|
|
%t35 = zext i1 %t34 to i32
|
|
%t36 = icmp ne i32 %t35, 0
|
|
br i1 %t36, label %if.then.9, label %if.end.10
|
|
if.then.12:
|
|
ret i32 1
|
|
if.end.13:
|
|
%t62 = load i32, i32* %t13
|
|
%t63 = icmp sle i32 %t62, 1
|
|
%t64 = zext i1 %t63 to i32
|
|
%t65 = icmp ne i32 %t64, 0
|
|
br i1 %t65, label %if.then.15, label %if.end.16
|
|
land.rhs.14:
|
|
%t57 = load i32, i32* %t16
|
|
%t58 = load i32, i32* @y_1
|
|
%t59 = icmp eq i32 %t57, %t58
|
|
%t60 = zext i1 %t59 to i32
|
|
%t61 = icmp ne i32 %t60, 0
|
|
br i1 %t61, label %if.then.12, label %if.end.13
|
|
if.then.15:
|
|
%t66 = load i32, i32* %t8
|
|
%t67 = add i32 %t66, 1
|
|
store i32 %t67, i32* %t8
|
|
br label %while.cond.3
|
|
if.end.16:
|
|
%t68 = load i32, i32* %t14
|
|
%t69 = icmp eq i32 %t68, 0
|
|
%t70 = zext i1 %t69 to i32
|
|
%t71 = icmp ne i32 %t70, 0
|
|
br i1 %t71, label %if.then.17, label %lor.rhs.21
|
|
if.then.17:
|
|
%t88 = load i32, i32* %t8
|
|
%t89 = add i32 %t88, 1
|
|
store i32 %t89, i32* %t8
|
|
br label %while.cond.3
|
|
if.end.18:
|
|
%t90 = load i32, i32* %t14
|
|
%t91 = load i32, i32* %t16
|
|
%t92 = mul i32 %t90, 30
|
|
%t93 = add i32 %t92, %t91
|
|
%t94 = getelementptr inbounds [900 x i32], [900 x i32]* @a, i32 0, i32 %t93
|
|
store i32 0, i32* %t94
|
|
%t96 = load i32, i32* %t14
|
|
%t97 = load i32, i32* %t8
|
|
%t98 = mul i32 %t97, 2
|
|
%t99 = getelementptr inbounds [8 x i32], [8 x i32]* @step, i32 0, i32 %t98
|
|
%t100 = load i32, i32* %t99
|
|
%t101 = sub i32 %t96, %t100
|
|
%t102 = load i32, i32* %t16
|
|
%t103 = load i32, i32* %t8
|
|
%t104 = mul i32 %t103, 2
|
|
%t105 = add i32 %t104, 1
|
|
%t106 = getelementptr inbounds [8 x i32], [8 x i32]* @step, i32 0, i32 %t105
|
|
%t107 = load i32, i32* %t106
|
|
%t108 = sub i32 %t102, %t107
|
|
%t109 = load i32, i32* %t2
|
|
%t110 = add i32 %t109, 1
|
|
%t111 = call i32 @search(i32 %t101, i32 %t108, i32 %t110)
|
|
%t112 = add i32 %t111, 1
|
|
store i32 %t112, i32* %t95
|
|
%t113 = load i32, i32* %t95
|
|
%t114 = load i32, i32* %t7
|
|
%t115 = icmp slt i32 %t113, %t114
|
|
%t116 = zext i1 %t115 to i32
|
|
%t117 = icmp ne i32 %t116, 0
|
|
br i1 %t117, label %if.then.22, label %if.end.23
|
|
lor.rhs.19:
|
|
%t82 = load i32, i32* %t16
|
|
%t83 = load i32, i32* @w
|
|
%t84 = add i32 %t83, 1
|
|
%t85 = icmp eq i32 %t82, %t84
|
|
%t86 = zext i1 %t85 to i32
|
|
%t87 = icmp ne i32 %t86, 0
|
|
br i1 %t87, label %if.then.17, label %if.end.18
|
|
lor.rhs.20:
|
|
%t78 = load i32, i32* %t16
|
|
%t79 = icmp eq i32 %t78, 0
|
|
%t80 = zext i1 %t79 to i32
|
|
%t81 = icmp ne i32 %t80, 0
|
|
br i1 %t81, label %if.then.17, label %lor.rhs.19
|
|
lor.rhs.21:
|
|
%t72 = load i32, i32* %t14
|
|
%t73 = load i32, i32* @h
|
|
%t74 = add i32 %t73, 1
|
|
%t75 = icmp eq i32 %t72, %t74
|
|
%t76 = zext i1 %t75 to i32
|
|
%t77 = icmp ne i32 %t76, 0
|
|
br i1 %t77, label %if.then.17, label %lor.rhs.20
|
|
if.then.22:
|
|
%t118 = load i32, i32* %t95
|
|
store i32 %t118, i32* %t7
|
|
br label %if.end.23
|
|
if.end.23:
|
|
%t119 = load i32, i32* %t14
|
|
%t120 = load i32, i32* %t16
|
|
%t121 = mul i32 %t119, 30
|
|
%t122 = add i32 %t121, %t120
|
|
%t123 = getelementptr inbounds [900 x i32], [900 x i32]* @a, i32 0, i32 %t122
|
|
store i32 1, i32* %t123
|
|
%t124 = load i32, i32* %t8
|
|
%t125 = add i32 %t124, 1
|
|
store i32 %t125, i32* %t8
|
|
br label %while.cond.3
|
|
if.then.24:
|
|
ret i32 1073741824
|
|
if.end.25:
|
|
%t130 = load i32, i32* %t7
|
|
ret i32 %t130
|
|
}
|
|
define i32 @main() {
|
|
entry:
|
|
%t137 = alloca i32
|
|
%t138 = alloca i32
|
|
%t198 = alloca i32
|
|
%t131 = call i32 @getint()
|
|
store i32 %t131, i32* @w
|
|
%t132 = call i32 @getint()
|
|
store i32 %t132, i32* @h
|
|
br label %while.cond.26
|
|
while.cond.26:
|
|
%t133 = load i32, i32* @w
|
|
%t134 = icmp ne i32 %t133, 0
|
|
%t135 = zext i1 %t134 to i32
|
|
%t136 = icmp ne i32 %t135, 0
|
|
br i1 %t136, label %while.body.27, label %while.end.28
|
|
while.body.27:
|
|
store i32 0, i32* %t137
|
|
store i32 0, i32* %t138
|
|
store i32 0, i32* %t137
|
|
br label %while.cond.29
|
|
while.end.28:
|
|
ret i32 0
|
|
while.cond.29:
|
|
%t139 = load i32, i32* %t137
|
|
%t140 = icmp slt i32 %t139, 30
|
|
%t141 = zext i1 %t140 to i32
|
|
%t142 = icmp ne i32 %t141, 0
|
|
br i1 %t142, label %while.body.30, label %while.end.31
|
|
while.body.30:
|
|
store i32 0, i32* %t138
|
|
br label %while.cond.32
|
|
while.end.31:
|
|
store i32 1, i32* %t137
|
|
br label %while.cond.35
|
|
while.cond.32:
|
|
%t143 = load i32, i32* %t138
|
|
%t144 = icmp slt i32 %t143, 30
|
|
%t145 = zext i1 %t144 to i32
|
|
%t146 = icmp ne i32 %t145, 0
|
|
br i1 %t146, label %while.body.33, label %while.end.34
|
|
while.body.33:
|
|
%t147 = load i32, i32* %t137
|
|
%t148 = load i32, i32* %t138
|
|
%t149 = mul i32 %t147, 30
|
|
%t150 = add i32 %t149, %t148
|
|
%t151 = getelementptr inbounds [900 x i32], [900 x i32]* @a, i32 0, i32 %t150
|
|
store i32 1, i32* %t151
|
|
%t152 = load i32, i32* %t138
|
|
%t153 = add i32 %t152, 1
|
|
store i32 %t153, i32* %t138
|
|
br label %while.cond.32
|
|
while.end.34:
|
|
%t154 = load i32, i32* %t137
|
|
%t155 = add i32 %t154, 1
|
|
store i32 %t155, i32* %t137
|
|
br label %while.cond.29
|
|
while.cond.35:
|
|
%t156 = load i32, i32* %t137
|
|
%t157 = load i32, i32* @h
|
|
%t158 = icmp sle i32 %t156, %t157
|
|
%t159 = zext i1 %t158 to i32
|
|
%t160 = icmp ne i32 %t159, 0
|
|
br i1 %t160, label %while.body.36, label %while.end.37
|
|
while.body.36:
|
|
store i32 1, i32* %t138
|
|
br label %while.cond.38
|
|
while.end.37:
|
|
%t199 = load i32, i32* @x_0
|
|
%t200 = load i32, i32* @y_0
|
|
%t201 = call i32 @search(i32 %t199, i32 %t200, i32 1)
|
|
store i32 %t201, i32* %t198
|
|
%t202 = load i32, i32* %t198
|
|
%t203 = icmp sle i32 %t202, 10
|
|
%t204 = zext i1 %t203 to i32
|
|
%t205 = icmp ne i32 %t204, 0
|
|
br i1 %t205, label %if.then.46, label %if.else.47
|
|
while.cond.38:
|
|
%t161 = load i32, i32* %t138
|
|
%t162 = load i32, i32* @w
|
|
%t163 = icmp sle i32 %t161, %t162
|
|
%t164 = zext i1 %t163 to i32
|
|
%t165 = icmp ne i32 %t164, 0
|
|
br i1 %t165, label %while.body.39, label %while.end.40
|
|
while.body.39:
|
|
%t166 = load i32, i32* %t137
|
|
%t167 = load i32, i32* %t138
|
|
%t168 = mul i32 %t166, 30
|
|
%t169 = add i32 %t168, %t167
|
|
%t170 = getelementptr inbounds [900 x i32], [900 x i32]* @a, i32 0, i32 %t169
|
|
%t171 = call i32 @getint()
|
|
store i32 %t171, i32* %t170
|
|
%t172 = load i32, i32* %t137
|
|
%t173 = load i32, i32* %t138
|
|
%t174 = mul i32 %t172, 30
|
|
%t175 = add i32 %t174, %t173
|
|
%t176 = getelementptr inbounds [900 x i32], [900 x i32]* @a, i32 0, i32 %t175
|
|
%t177 = load i32, i32* %t176
|
|
%t178 = icmp eq i32 %t177, 2
|
|
%t179 = zext i1 %t178 to i32
|
|
%t180 = icmp ne i32 %t179, 0
|
|
br i1 %t180, label %if.then.41, label %if.else.42
|
|
while.end.40:
|
|
%t196 = load i32, i32* %t137
|
|
%t197 = add i32 %t196, 1
|
|
store i32 %t197, i32* %t137
|
|
br label %while.cond.35
|
|
if.then.41:
|
|
%t181 = load i32, i32* %t137
|
|
store i32 %t181, i32* @x_0
|
|
%t182 = load i32, i32* %t138
|
|
store i32 %t182, i32* @y_0
|
|
br label %if.end.43
|
|
if.else.42:
|
|
%t183 = load i32, i32* %t137
|
|
%t184 = load i32, i32* %t138
|
|
%t185 = mul i32 %t183, 30
|
|
%t186 = add i32 %t185, %t184
|
|
%t187 = getelementptr inbounds [900 x i32], [900 x i32]* @a, i32 0, i32 %t186
|
|
%t188 = load i32, i32* %t187
|
|
%t189 = icmp eq i32 %t188, 3
|
|
%t190 = zext i1 %t189 to i32
|
|
%t191 = icmp ne i32 %t190, 0
|
|
br i1 %t191, label %if.then.44, label %if.end.45
|
|
if.end.43:
|
|
%t194 = load i32, i32* %t138
|
|
%t195 = add i32 %t194, 1
|
|
store i32 %t195, i32* %t138
|
|
br label %while.cond.38
|
|
if.then.44:
|
|
%t192 = load i32, i32* %t137
|
|
store i32 %t192, i32* @x_1
|
|
%t193 = load i32, i32* %t138
|
|
store i32 %t193, i32* @y_1
|
|
br label %if.end.45
|
|
if.end.45:
|
|
br label %if.end.43
|
|
if.then.46:
|
|
%t206 = load i32, i32* %t198
|
|
call void @putint(i32 %t206)
|
|
call void @putch(i32 10)
|
|
br label %if.end.48
|
|
if.else.47:
|
|
call void @putint(i32 -1)
|
|
call void @putch(i32 10)
|
|
br label %if.end.48
|
|
if.end.48:
|
|
%t211 = call i32 @getint()
|
|
store i32 %t211, i32* @w
|
|
%t212 = call i32 @getint()
|
|
store i32 %t212, i32* @h
|
|
br label %while.cond.26
|
|
}
|