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.
360 lines
10 KiB
360 lines
10 KiB
@n = global i32 0
|
|
@m = global i32 0
|
|
@maxn = global i32 1005
|
|
@maxm = global i32 5005
|
|
@to = global [5005 x i32] zeroinitializer
|
|
@next = global [5005 x i32] zeroinitializer
|
|
@head = global [1005 x i32] zeroinitializer
|
|
@cnt = global i32 0
|
|
@que = global [1005 x i32] zeroinitializer
|
|
@h = global i32 0
|
|
@tail = global i32 0
|
|
@inq = global [1005 x i32] 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 i32 @quick_read() {
|
|
entry:
|
|
%t0 = alloca i32
|
|
%t2 = alloca i32
|
|
%t3 = alloca i32
|
|
%t1 = call i32 @getch()
|
|
store i32 %t1, i32* %t0
|
|
store i32 0, i32* %t2
|
|
store i32 0, i32* %t3
|
|
br label %while.cond.1
|
|
while.cond.1:
|
|
%t4 = load i32, i32* %t0
|
|
%t5 = icmp slt i32 %t4, 48
|
|
%t6 = zext i1 %t5 to i32
|
|
%t7 = icmp ne i32 %t6, 0
|
|
br i1 %t7, label %while.body.2, label %lor.rhs.4
|
|
while.body.2:
|
|
%t12 = load i32, i32* %t0
|
|
%t13 = icmp eq i32 %t12, 45
|
|
%t14 = zext i1 %t13 to i32
|
|
%t15 = icmp ne i32 %t14, 0
|
|
br i1 %t15, label %if.then.5, label %if.end.6
|
|
while.end.3:
|
|
br label %while.cond.7
|
|
lor.rhs.4:
|
|
%t8 = load i32, i32* %t0
|
|
%t9 = icmp sgt i32 %t8, 57
|
|
%t10 = zext i1 %t9 to i32
|
|
%t11 = icmp ne i32 %t10, 0
|
|
br i1 %t11, label %while.body.2, label %while.end.3
|
|
if.then.5:
|
|
store i32 1, i32* %t3
|
|
br label %if.end.6
|
|
if.end.6:
|
|
%t16 = call i32 @getch()
|
|
store i32 %t16, i32* %t0
|
|
br label %while.cond.1
|
|
while.cond.7:
|
|
%t17 = load i32, i32* %t0
|
|
%t18 = icmp sge i32 %t17, 48
|
|
%t19 = zext i1 %t18 to i32
|
|
%t20 = icmp ne i32 %t19, 0
|
|
br i1 %t20, label %land.rhs.10, label %while.end.9
|
|
while.body.8:
|
|
%t25 = load i32, i32* %t2
|
|
%t26 = mul i32 %t25, 10
|
|
%t27 = load i32, i32* %t0
|
|
%t28 = add i32 %t26, %t27
|
|
%t29 = sub i32 %t28, 48
|
|
store i32 %t29, i32* %t2
|
|
%t30 = call i32 @getch()
|
|
store i32 %t30, i32* %t0
|
|
br label %while.cond.7
|
|
while.end.9:
|
|
%t31 = load i32, i32* %t3
|
|
%t32 = icmp ne i32 %t31, 0
|
|
br i1 %t32, label %if.then.11, label %if.else.12
|
|
land.rhs.10:
|
|
%t21 = load i32, i32* %t0
|
|
%t22 = icmp sle i32 %t21, 57
|
|
%t23 = zext i1 %t22 to i32
|
|
%t24 = icmp ne i32 %t23, 0
|
|
br i1 %t24, label %while.body.8, label %while.end.9
|
|
if.then.11:
|
|
%t33 = load i32, i32* %t2
|
|
%t34 = sub i32 0, %t33
|
|
ret i32 %t34
|
|
if.else.12:
|
|
%t35 = load i32, i32* %t2
|
|
ret i32 %t35
|
|
if.end.13:
|
|
ret i32 0
|
|
}
|
|
define void @add_edge(i32 %arg.from, i32 %arg.To) {
|
|
entry:
|
|
%t36 = alloca i32
|
|
store i32 %arg.from, i32* %t36
|
|
%t37 = alloca i32
|
|
store i32 %arg.To, i32* %t37
|
|
%t38 = load i32, i32* @cnt
|
|
%t39 = getelementptr inbounds [5005 x i32], [5005 x i32]* @to, i32 0, i32 %t38
|
|
%t40 = load i32, i32* %t37
|
|
store i32 %t40, i32* %t39
|
|
%t41 = load i32, i32* @cnt
|
|
%t42 = getelementptr inbounds [5005 x i32], [5005 x i32]* @next, i32 0, i32 %t41
|
|
%t43 = load i32, i32* %t36
|
|
%t44 = getelementptr inbounds [1005 x i32], [1005 x i32]* @head, i32 0, i32 %t43
|
|
%t45 = load i32, i32* %t44
|
|
store i32 %t45, i32* %t42
|
|
%t46 = load i32, i32* %t36
|
|
%t47 = getelementptr inbounds [1005 x i32], [1005 x i32]* @head, i32 0, i32 %t46
|
|
%t48 = load i32, i32* @cnt
|
|
store i32 %t48, i32* %t47
|
|
%t49 = load i32, i32* @cnt
|
|
%t50 = add i32 %t49, 1
|
|
store i32 %t50, i32* @cnt
|
|
%t51 = load i32, i32* @cnt
|
|
%t52 = getelementptr inbounds [5005 x i32], [5005 x i32]* @to, i32 0, i32 %t51
|
|
%t53 = load i32, i32* %t36
|
|
store i32 %t53, i32* %t52
|
|
%t54 = load i32, i32* @cnt
|
|
%t55 = getelementptr inbounds [5005 x i32], [5005 x i32]* @next, i32 0, i32 %t54
|
|
%t56 = load i32, i32* %t37
|
|
%t57 = getelementptr inbounds [1005 x i32], [1005 x i32]* @head, i32 0, i32 %t56
|
|
%t58 = load i32, i32* %t57
|
|
store i32 %t58, i32* %t55
|
|
%t59 = load i32, i32* %t37
|
|
%t60 = getelementptr inbounds [1005 x i32], [1005 x i32]* @head, i32 0, i32 %t59
|
|
%t61 = load i32, i32* @cnt
|
|
store i32 %t61, i32* %t60
|
|
%t62 = load i32, i32* @cnt
|
|
%t63 = add i32 %t62, 1
|
|
store i32 %t63, i32* @cnt
|
|
ret void
|
|
}
|
|
define void @init() {
|
|
entry:
|
|
%t64 = alloca i32
|
|
store i32 0, i32* %t64
|
|
br label %while.cond.14
|
|
while.cond.14:
|
|
%t65 = load i32, i32* %t64
|
|
%t66 = icmp slt i32 %t65, 1005
|
|
%t67 = zext i1 %t66 to i32
|
|
%t68 = icmp ne i32 %t67, 0
|
|
br i1 %t68, label %while.body.15, label %while.end.16
|
|
while.body.15:
|
|
%t69 = load i32, i32* %t64
|
|
%t70 = getelementptr inbounds [1005 x i32], [1005 x i32]* @head, i32 0, i32 %t69
|
|
store i32 -1, i32* %t70
|
|
%t71 = load i32, i32* %t64
|
|
%t72 = add i32 %t71, 1
|
|
store i32 %t72, i32* %t64
|
|
br label %while.cond.14
|
|
while.end.16:
|
|
ret void
|
|
}
|
|
define void @inqueue(i32 %arg.x) {
|
|
entry:
|
|
%t73 = alloca i32
|
|
store i32 %arg.x, i32* %t73
|
|
%t74 = load i32, i32* %t73
|
|
%t75 = getelementptr inbounds [1005 x i32], [1005 x i32]* @inq, i32 0, i32 %t74
|
|
store i32 1, i32* %t75
|
|
%t76 = load i32, i32* @tail
|
|
%t77 = add i32 %t76, 1
|
|
store i32 %t77, i32* @tail
|
|
%t78 = load i32, i32* @tail
|
|
%t79 = getelementptr inbounds [1005 x i32], [1005 x i32]* @que, i32 0, i32 %t78
|
|
%t80 = load i32, i32* %t73
|
|
store i32 %t80, i32* %t79
|
|
ret void
|
|
}
|
|
define i32 @pop_queue() {
|
|
entry:
|
|
%t83 = alloca i32
|
|
%t81 = load i32, i32* @h
|
|
%t82 = add i32 %t81, 1
|
|
store i32 %t82, i32* @h
|
|
%t84 = load i32, i32* @h
|
|
%t85 = getelementptr inbounds [1005 x i32], [1005 x i32]* @que, i32 0, i32 %t84
|
|
%t86 = load i32, i32* %t85
|
|
store i32 %t86, i32* %t83
|
|
%t87 = load i32, i32* @h
|
|
%t88 = getelementptr inbounds [1005 x i32], [1005 x i32]* @que, i32 0, i32 %t87
|
|
%t89 = load i32, i32* %t88
|
|
ret i32 %t89
|
|
}
|
|
define i32 @same(i32 %arg.s, i32 %arg.t) {
|
|
entry:
|
|
%t94 = alloca i32
|
|
%t100 = alloca i32
|
|
%t107 = alloca i32
|
|
%t130 = alloca i32
|
|
%t90 = alloca i32
|
|
store i32 %arg.s, i32* %t90
|
|
%t91 = alloca i32
|
|
store i32 %arg.t, i32* %t91
|
|
store i32 0, i32* @h
|
|
store i32 0, i32* @tail
|
|
%t92 = load i32, i32* %t90
|
|
call void @inqueue(i32 %t92)
|
|
store i32 0, i32* %t94
|
|
br label %while.cond.17
|
|
while.cond.17:
|
|
%t95 = load i32, i32* @h
|
|
%t96 = load i32, i32* @tail
|
|
%t97 = icmp slt i32 %t95, %t96
|
|
%t98 = zext i1 %t97 to i32
|
|
%t99 = icmp ne i32 %t98, 0
|
|
br i1 %t99, label %while.body.18, label %while.end.19
|
|
while.body.18:
|
|
%t101 = call i32 @pop_queue()
|
|
store i32 %t101, i32* %t100
|
|
%t102 = load i32, i32* %t100
|
|
%t103 = load i32, i32* %t91
|
|
%t104 = icmp eq i32 %t102, %t103
|
|
%t105 = zext i1 %t104 to i32
|
|
%t106 = icmp ne i32 %t105, 0
|
|
br i1 %t106, label %if.then.20, label %if.end.21
|
|
while.end.19:
|
|
store i32 0, i32* %t130
|
|
br label %while.cond.27
|
|
if.then.20:
|
|
store i32 1, i32* %t94
|
|
br label %if.end.21
|
|
if.end.21:
|
|
%t108 = load i32, i32* %t100
|
|
%t109 = getelementptr inbounds [1005 x i32], [1005 x i32]* @head, i32 0, i32 %t108
|
|
%t110 = load i32, i32* %t109
|
|
store i32 %t110, i32* %t107
|
|
br label %while.cond.22
|
|
while.cond.22:
|
|
%t111 = load i32, i32* %t107
|
|
%t112 = icmp ne i32 %t111, -1
|
|
%t113 = zext i1 %t112 to i32
|
|
%t114 = icmp ne i32 %t113, 0
|
|
br i1 %t114, label %while.body.23, label %while.end.24
|
|
while.body.23:
|
|
%t115 = load i32, i32* %t107
|
|
%t116 = getelementptr inbounds [5005 x i32], [5005 x i32]* @to, i32 0, i32 %t115
|
|
%t117 = load i32, i32* %t116
|
|
%t118 = getelementptr inbounds [1005 x i32], [1005 x i32]* @inq, i32 0, i32 %t117
|
|
%t119 = load i32, i32* %t118
|
|
%t120 = icmp eq i32 %t119, 0
|
|
%t121 = zext i1 %t120 to i32
|
|
%t122 = icmp ne i32 %t121, 0
|
|
br i1 %t122, label %if.then.25, label %if.end.26
|
|
while.end.24:
|
|
br label %while.cond.17
|
|
if.then.25:
|
|
%t123 = load i32, i32* %t107
|
|
%t124 = getelementptr inbounds [5005 x i32], [5005 x i32]* @to, i32 0, i32 %t123
|
|
%t125 = load i32, i32* %t124
|
|
call void @inqueue(i32 %t125)
|
|
br label %if.end.26
|
|
if.end.26:
|
|
%t127 = load i32, i32* %t107
|
|
%t128 = getelementptr inbounds [5005 x i32], [5005 x i32]* @next, i32 0, i32 %t127
|
|
%t129 = load i32, i32* %t128
|
|
store i32 %t129, i32* %t107
|
|
br label %while.cond.22
|
|
while.cond.27:
|
|
%t131 = load i32, i32* %t130
|
|
%t132 = load i32, i32* @tail
|
|
%t133 = icmp sle i32 %t131, %t132
|
|
%t134 = zext i1 %t133 to i32
|
|
%t135 = icmp ne i32 %t134, 0
|
|
br i1 %t135, label %while.body.28, label %while.end.29
|
|
while.body.28:
|
|
%t136 = load i32, i32* %t130
|
|
%t137 = getelementptr inbounds [1005 x i32], [1005 x i32]* @que, i32 0, i32 %t136
|
|
%t138 = load i32, i32* %t137
|
|
%t139 = getelementptr inbounds [1005 x i32], [1005 x i32]* @inq, i32 0, i32 %t138
|
|
store i32 0, i32* %t139
|
|
%t140 = load i32, i32* %t130
|
|
%t141 = add i32 %t140, 1
|
|
store i32 %t141, i32* %t130
|
|
br label %while.cond.27
|
|
while.end.29:
|
|
%t142 = load i32, i32* %t94
|
|
ret i32 %t142
|
|
}
|
|
define i32 @main() {
|
|
entry:
|
|
%t148 = alloca i32
|
|
%t163 = alloca i32
|
|
%t165 = alloca i32
|
|
%t172 = alloca i32
|
|
%t174 = alloca i32
|
|
%t143 = call i32 @quick_read()
|
|
store i32 %t143, i32* @n
|
|
%t144 = call i32 @quick_read()
|
|
store i32 %t144, i32* @m
|
|
call void @init()
|
|
br label %while.cond.30
|
|
while.cond.30:
|
|
%t146 = load i32, i32* @m
|
|
%t147 = icmp ne i32 %t146, 0
|
|
br i1 %t147, label %while.body.31, label %while.end.32
|
|
while.body.31:
|
|
%t149 = call i32 @getch()
|
|
store i32 %t149, i32* %t148
|
|
br label %while.cond.33
|
|
while.end.32:
|
|
ret i32 0
|
|
while.cond.33:
|
|
%t150 = load i32, i32* %t148
|
|
%t151 = icmp ne i32 %t150, 81
|
|
%t152 = zext i1 %t151 to i32
|
|
%t153 = icmp ne i32 %t152, 0
|
|
br i1 %t153, label %land.rhs.36, label %while.end.35
|
|
while.body.34:
|
|
%t158 = call i32 @getch()
|
|
store i32 %t158, i32* %t148
|
|
br label %while.cond.33
|
|
while.end.35:
|
|
%t159 = load i32, i32* %t148
|
|
%t160 = icmp eq i32 %t159, 81
|
|
%t161 = zext i1 %t160 to i32
|
|
%t162 = icmp ne i32 %t161, 0
|
|
br i1 %t162, label %if.then.37, label %if.else.38
|
|
land.rhs.36:
|
|
%t154 = load i32, i32* %t148
|
|
%t155 = icmp ne i32 %t154, 85
|
|
%t156 = zext i1 %t155 to i32
|
|
%t157 = icmp ne i32 %t156, 0
|
|
br i1 %t157, label %while.body.34, label %while.end.35
|
|
if.then.37:
|
|
%t164 = call i32 @quick_read()
|
|
store i32 %t164, i32* %t163
|
|
%t166 = call i32 @quick_read()
|
|
store i32 %t166, i32* %t165
|
|
%t167 = load i32, i32* %t163
|
|
%t168 = load i32, i32* %t165
|
|
%t169 = call i32 @same(i32 %t167, i32 %t168)
|
|
call void @putint(i32 %t169)
|
|
call void @putch(i32 10)
|
|
br label %if.end.39
|
|
if.else.38:
|
|
%t173 = call i32 @quick_read()
|
|
store i32 %t173, i32* %t172
|
|
%t175 = call i32 @quick_read()
|
|
store i32 %t175, i32* %t174
|
|
%t176 = load i32, i32* %t172
|
|
%t177 = load i32, i32* %t174
|
|
call void @add_edge(i32 %t176, i32 %t177)
|
|
br label %if.end.39
|
|
if.end.39:
|
|
%t179 = load i32, i32* @m
|
|
%t180 = sub i32 %t179, 1
|
|
store i32 %t180, i32* @m
|
|
br label %while.cond.30
|
|
}
|