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.
167 lines
4.6 KiB
167 lines
4.6 KiB
@maxN = global i32 1005
|
|
@parent = 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 @find(i32 %arg.root) {
|
|
entry:
|
|
%t0 = alloca i32
|
|
store i32 %arg.root, i32* %t0
|
|
%t1 = load i32, i32* %t0
|
|
%t2 = getelementptr inbounds [1005 x i32], [1005 x i32]* @parent, i32 0, i32 %t1
|
|
%t3 = load i32, i32* %t2
|
|
%t4 = load i32, i32* %t0
|
|
%t5 = icmp eq i32 %t3, %t4
|
|
%t6 = zext i1 %t5 to i32
|
|
%t7 = icmp ne i32 %t6, 0
|
|
br i1 %t7, label %if.then.1, label %if.else.2
|
|
if.then.1:
|
|
%t8 = load i32, i32* %t0
|
|
ret i32 %t8
|
|
if.else.2:
|
|
%t9 = load i32, i32* %t0
|
|
%t10 = getelementptr inbounds [1005 x i32], [1005 x i32]* @parent, i32 0, i32 %t9
|
|
%t11 = load i32, i32* %t0
|
|
%t12 = getelementptr inbounds [1005 x i32], [1005 x i32]* @parent, i32 0, i32 %t11
|
|
%t13 = load i32, i32* %t12
|
|
%t14 = call i32 @find(i32 %t13)
|
|
store i32 %t14, i32* %t10
|
|
%t15 = load i32, i32* %t0
|
|
%t16 = getelementptr inbounds [1005 x i32], [1005 x i32]* @parent, i32 0, i32 %t15
|
|
%t17 = load i32, i32* %t16
|
|
ret i32 %t17
|
|
if.end.3:
|
|
ret i32 0
|
|
}
|
|
define void @merge(i32 %arg.p, i32 %arg.q) {
|
|
entry:
|
|
%t20 = alloca i32
|
|
%t21 = alloca i32
|
|
%t18 = alloca i32
|
|
store i32 %arg.p, i32* %t18
|
|
%t19 = alloca i32
|
|
store i32 %arg.q, i32* %t19
|
|
store i32 0, i32* %t20
|
|
store i32 0, i32* %t21
|
|
%t22 = load i32, i32* %t18
|
|
%t23 = call i32 @find(i32 %t22)
|
|
store i32 %t23, i32* %t20
|
|
%t24 = load i32, i32* %t19
|
|
%t25 = call i32 @find(i32 %t24)
|
|
store i32 %t25, i32* %t21
|
|
%t26 = load i32, i32* %t20
|
|
%t27 = load i32, i32* %t21
|
|
%t28 = icmp ne i32 %t26, %t27
|
|
%t29 = zext i1 %t28 to i32
|
|
%t30 = icmp ne i32 %t29, 0
|
|
br i1 %t30, label %if.then.4, label %if.end.5
|
|
if.then.4:
|
|
%t31 = load i32, i32* %t21
|
|
%t32 = getelementptr inbounds [1005 x i32], [1005 x i32]* @parent, i32 0, i32 %t31
|
|
%t33 = load i32, i32* %t20
|
|
store i32 %t33, i32* %t32
|
|
br label %if.end.5
|
|
if.end.5:
|
|
ret void
|
|
}
|
|
define i32 @main() {
|
|
entry:
|
|
%t34 = alloca i32
|
|
%t36 = alloca i32
|
|
%t38 = alloca i32
|
|
%t39 = alloca i32
|
|
%t40 = alloca i32
|
|
%t63 = alloca i32
|
|
%t35 = call i32 @getint()
|
|
store i32 %t35, i32* %t34
|
|
%t37 = call i32 @getint()
|
|
store i32 %t37, i32* %t36
|
|
store i32 0, i32* %t38
|
|
store i32 0, i32* %t39
|
|
store i32 0, i32* %t40
|
|
store i32 0, i32* %t38
|
|
br label %while.cond.6
|
|
while.cond.6:
|
|
%t41 = load i32, i32* %t38
|
|
%t42 = load i32, i32* %t34
|
|
%t43 = icmp slt i32 %t41, %t42
|
|
%t44 = zext i1 %t43 to i32
|
|
%t45 = icmp ne i32 %t44, 0
|
|
br i1 %t45, label %while.body.7, label %while.end.8
|
|
while.body.7:
|
|
%t46 = load i32, i32* %t38
|
|
%t47 = getelementptr inbounds [1005 x i32], [1005 x i32]* @parent, i32 0, i32 %t46
|
|
%t48 = load i32, i32* %t38
|
|
store i32 %t48, i32* %t47
|
|
%t49 = load i32, i32* %t38
|
|
%t50 = add i32 %t49, 1
|
|
store i32 %t50, i32* %t38
|
|
br label %while.cond.6
|
|
while.end.8:
|
|
store i32 0, i32* %t38
|
|
br label %while.cond.9
|
|
while.cond.9:
|
|
%t51 = load i32, i32* %t38
|
|
%t52 = load i32, i32* %t36
|
|
%t53 = icmp slt i32 %t51, %t52
|
|
%t54 = zext i1 %t53 to i32
|
|
%t55 = icmp ne i32 %t54, 0
|
|
br i1 %t55, label %while.body.10, label %while.end.11
|
|
while.body.10:
|
|
%t56 = call i32 @getint()
|
|
store i32 %t56, i32* %t39
|
|
%t57 = call i32 @getint()
|
|
store i32 %t57, i32* %t40
|
|
%t58 = load i32, i32* %t39
|
|
%t59 = load i32, i32* %t40
|
|
call void @merge(i32 %t58, i32 %t59)
|
|
%t61 = load i32, i32* %t38
|
|
%t62 = add i32 %t61, 1
|
|
store i32 %t62, i32* %t38
|
|
br label %while.cond.9
|
|
while.end.11:
|
|
store i32 0, i32* %t63
|
|
store i32 0, i32* %t38
|
|
br label %while.cond.12
|
|
while.cond.12:
|
|
%t64 = load i32, i32* %t38
|
|
%t65 = load i32, i32* %t34
|
|
%t66 = icmp slt i32 %t64, %t65
|
|
%t67 = zext i1 %t66 to i32
|
|
%t68 = icmp ne i32 %t67, 0
|
|
br i1 %t68, label %while.body.13, label %while.end.14
|
|
while.body.13:
|
|
%t69 = load i32, i32* %t38
|
|
%t70 = getelementptr inbounds [1005 x i32], [1005 x i32]* @parent, i32 0, i32 %t69
|
|
%t71 = load i32, i32* %t70
|
|
%t72 = load i32, i32* %t38
|
|
%t73 = icmp eq i32 %t71, %t72
|
|
%t74 = zext i1 %t73 to i32
|
|
%t75 = icmp ne i32 %t74, 0
|
|
br i1 %t75, label %if.then.15, label %if.end.16
|
|
while.end.14:
|
|
%t80 = load i32, i32* %t63
|
|
call void @putint(i32 %t80)
|
|
ret i32 0
|
|
if.then.15:
|
|
%t76 = load i32, i32* %t63
|
|
%t77 = add i32 %t76, 1
|
|
store i32 %t77, i32* %t63
|
|
br label %if.end.16
|
|
if.end.16:
|
|
%t78 = load i32, i32* %t38
|
|
%t79 = add i32 %t78, 1
|
|
store i32 %t79, i32* %t38
|
|
br label %while.cond.12
|
|
}
|