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.
218 lines
6.2 KiB
218 lines
6.2 KiB
@maxN = global i32 1000
|
|
@space = global i32 32
|
|
@array = global [1000 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 void @swap(i32 %arg.i, i32 %arg.j) {
|
|
entry:
|
|
%t2 = alloca i32
|
|
%t0 = alloca i32
|
|
store i32 %arg.i, i32* %t0
|
|
%t1 = alloca i32
|
|
store i32 %arg.j, i32* %t1
|
|
%t3 = load i32, i32* %t0
|
|
%t4 = getelementptr inbounds [1000 x i32], [1000 x i32]* @array, i32 0, i32 %t3
|
|
%t5 = load i32, i32* %t4
|
|
store i32 %t5, i32* %t2
|
|
%t6 = load i32, i32* %t0
|
|
%t7 = getelementptr inbounds [1000 x i32], [1000 x i32]* @array, i32 0, i32 %t6
|
|
%t8 = load i32, i32* %t1
|
|
%t9 = getelementptr inbounds [1000 x i32], [1000 x i32]* @array, i32 0, i32 %t8
|
|
%t10 = load i32, i32* %t9
|
|
store i32 %t10, i32* %t7
|
|
%t11 = load i32, i32* %t1
|
|
%t12 = getelementptr inbounds [1000 x i32], [1000 x i32]* @array, i32 0, i32 %t11
|
|
%t13 = load i32, i32* %t2
|
|
store i32 %t13, i32* %t12
|
|
ret void
|
|
}
|
|
define i32 @findPivot(i32 %arg.start, i32 %arg.end) {
|
|
entry:
|
|
%t16 = alloca i32
|
|
%t20 = alloca i32
|
|
%t22 = alloca i32
|
|
%t14 = alloca i32
|
|
store i32 %arg.start, i32* %t14
|
|
%t15 = alloca i32
|
|
store i32 %arg.end, i32* %t15
|
|
%t17 = load i32, i32* %t15
|
|
%t18 = getelementptr inbounds [1000 x i32], [1000 x i32]* @array, i32 0, i32 %t17
|
|
%t19 = load i32, i32* %t18
|
|
store i32 %t19, i32* %t16
|
|
%t21 = load i32, i32* %t14
|
|
store i32 %t21, i32* %t20
|
|
%t23 = load i32, i32* %t14
|
|
store i32 %t23, i32* %t22
|
|
br label %while.cond.1
|
|
while.cond.1:
|
|
%t24 = load i32, i32* %t22
|
|
%t25 = load i32, i32* %t15
|
|
%t26 = icmp slt i32 %t24, %t25
|
|
%t27 = zext i1 %t26 to i32
|
|
%t28 = icmp ne i32 %t27, 0
|
|
br i1 %t28, label %while.body.2, label %while.end.3
|
|
while.body.2:
|
|
%t29 = load i32, i32* %t22
|
|
%t30 = getelementptr inbounds [1000 x i32], [1000 x i32]* @array, i32 0, i32 %t29
|
|
%t31 = load i32, i32* %t30
|
|
%t32 = load i32, i32* %t16
|
|
%t33 = icmp sle i32 %t31, %t32
|
|
%t34 = zext i1 %t33 to i32
|
|
%t35 = icmp ne i32 %t34, 0
|
|
br i1 %t35, label %if.then.4, label %if.end.5
|
|
while.end.3:
|
|
%t43 = load i32, i32* %t20
|
|
%t44 = load i32, i32* %t15
|
|
call void @swap(i32 %t43, i32 %t44)
|
|
%t46 = load i32, i32* %t20
|
|
ret i32 %t46
|
|
if.then.4:
|
|
%t36 = load i32, i32* %t22
|
|
%t37 = load i32, i32* %t20
|
|
call void @swap(i32 %t36, i32 %t37)
|
|
%t39 = load i32, i32* %t20
|
|
%t40 = add i32 %t39, 1
|
|
store i32 %t40, i32* %t20
|
|
br label %if.end.5
|
|
if.end.5:
|
|
%t41 = load i32, i32* %t22
|
|
%t42 = add i32 %t41, 1
|
|
store i32 %t42, i32* %t22
|
|
br label %while.cond.1
|
|
}
|
|
define void @findSmallest(i32 %arg.low, i32 %arg.high, i32 %arg.k, i32 %arg.n) {
|
|
entry:
|
|
%t56 = alloca i32
|
|
%t65 = alloca i32
|
|
%t47 = alloca i32
|
|
store i32 %arg.low, i32* %t47
|
|
%t48 = alloca i32
|
|
store i32 %arg.high, i32* %t48
|
|
%t49 = alloca i32
|
|
store i32 %arg.k, i32* %t49
|
|
%t50 = alloca i32
|
|
store i32 %arg.n, i32* %t50
|
|
%t51 = load i32, i32* %t47
|
|
%t52 = load i32, i32* %t48
|
|
%t53 = icmp eq i32 %t51, %t52
|
|
%t54 = zext i1 %t53 to i32
|
|
%t55 = icmp ne i32 %t54, 0
|
|
br i1 %t55, label %if.then.6, label %if.else.7
|
|
if.then.6:
|
|
ret void
|
|
if.else.7:
|
|
%t57 = load i32, i32* %t47
|
|
%t58 = load i32, i32* %t48
|
|
%t59 = call i32 @findPivot(i32 %t57, i32 %t58)
|
|
store i32 %t59, i32* %t56
|
|
%t60 = load i32, i32* %t49
|
|
%t61 = load i32, i32* %t56
|
|
%t62 = icmp eq i32 %t60, %t61
|
|
%t63 = zext i1 %t62 to i32
|
|
%t64 = icmp ne i32 %t63, 0
|
|
br i1 %t64, label %if.then.9, label %if.else.10
|
|
if.end.8:
|
|
ret void
|
|
if.then.9:
|
|
store i32 0, i32* %t65
|
|
br label %while.cond.12
|
|
if.else.10:
|
|
%t78 = load i32, i32* %t49
|
|
%t79 = load i32, i32* %t56
|
|
%t80 = icmp slt i32 %t78, %t79
|
|
%t81 = zext i1 %t80 to i32
|
|
%t82 = icmp ne i32 %t81, 0
|
|
br i1 %t82, label %if.then.15, label %if.else.16
|
|
if.end.11:
|
|
br label %if.end.8
|
|
while.cond.12:
|
|
%t66 = load i32, i32* %t65
|
|
%t67 = load i32, i32* %t56
|
|
%t68 = icmp slt i32 %t66, %t67
|
|
%t69 = zext i1 %t68 to i32
|
|
%t70 = icmp ne i32 %t69, 0
|
|
br i1 %t70, label %while.body.13, label %while.end.14
|
|
while.body.13:
|
|
%t71 = load i32, i32* %t65
|
|
%t72 = getelementptr inbounds [1000 x i32], [1000 x i32]* @array, i32 0, i32 %t71
|
|
%t73 = load i32, i32* %t72
|
|
call void @putint(i32 %t73)
|
|
call void @putch(i32 32)
|
|
%t76 = load i32, i32* %t65
|
|
%t77 = add i32 %t76, 1
|
|
store i32 %t77, i32* %t65
|
|
br label %while.cond.12
|
|
while.end.14:
|
|
br label %if.end.11
|
|
if.then.15:
|
|
%t83 = load i32, i32* %t47
|
|
%t84 = load i32, i32* %t56
|
|
%t85 = sub i32 %t84, 1
|
|
%t86 = load i32, i32* %t49
|
|
%t87 = load i32, i32* %t50
|
|
call void @findSmallest(i32 %t83, i32 %t85, i32 %t86, i32 %t87)
|
|
br label %if.end.17
|
|
if.else.16:
|
|
%t89 = load i32, i32* %t56
|
|
%t90 = add i32 %t89, 1
|
|
%t91 = load i32, i32* %t48
|
|
%t92 = load i32, i32* %t49
|
|
%t93 = load i32, i32* %t50
|
|
call void @findSmallest(i32 %t90, i32 %t91, i32 %t92, i32 %t93)
|
|
br label %if.end.17
|
|
if.end.17:
|
|
br label %if.end.11
|
|
}
|
|
define i32 @main() {
|
|
entry:
|
|
%t95 = alloca i32
|
|
%t97 = alloca i32
|
|
%t99 = alloca i32
|
|
%t110 = alloca i32
|
|
%t111 = alloca i32
|
|
%t96 = call i32 @getint()
|
|
store i32 %t96, i32* %t95
|
|
%t98 = call i32 @getint()
|
|
store i32 %t98, i32* %t97
|
|
store i32 0, i32* %t99
|
|
br label %while.cond.18
|
|
while.cond.18:
|
|
%t100 = load i32, i32* %t99
|
|
%t101 = load i32, i32* %t95
|
|
%t102 = icmp slt i32 %t100, %t101
|
|
%t103 = zext i1 %t102 to i32
|
|
%t104 = icmp ne i32 %t103, 0
|
|
br i1 %t104, label %while.body.19, label %while.end.20
|
|
while.body.19:
|
|
%t105 = load i32, i32* %t99
|
|
%t106 = getelementptr inbounds [1000 x i32], [1000 x i32]* @array, i32 0, i32 %t105
|
|
%t107 = call i32 @getint()
|
|
store i32 %t107, i32* %t106
|
|
%t108 = load i32, i32* %t99
|
|
%t109 = add i32 %t108, 1
|
|
store i32 %t109, i32* %t99
|
|
br label %while.cond.18
|
|
while.end.20:
|
|
store i32 0, i32* %t110
|
|
%t112 = load i32, i32* %t95
|
|
%t113 = sub i32 %t112, 1
|
|
store i32 %t113, i32* %t111
|
|
%t114 = load i32, i32* %t110
|
|
%t115 = load i32, i32* %t111
|
|
%t116 = load i32, i32* %t97
|
|
%t117 = load i32, i32* %t95
|
|
call void @findSmallest(i32 %t114, i32 %t115, i32 %t116, i32 %t117)
|
|
ret i32 0
|
|
}
|