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.
200 lines
5.7 KiB
200 lines
5.7 KiB
@matrix = global [20000000 x i32] zeroinitializer
|
|
@a = global [100000 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 @transpose(i32 %arg.n, i32* %arg.matrix, i32 %arg.rowsize) {
|
|
entry:
|
|
%t2 = alloca i32
|
|
%t6 = alloca i32
|
|
%t7 = alloca i32
|
|
%t25 = alloca i32
|
|
%t0 = alloca i32
|
|
store i32 %arg.n, i32* %t0
|
|
%t1 = alloca i32
|
|
store i32 %arg.rowsize, i32* %t1
|
|
%t3 = load i32, i32* %t0
|
|
%t4 = load i32, i32* %t1
|
|
%t5 = sdiv i32 %t3, %t4
|
|
store i32 %t5, i32* %t2
|
|
store i32 0, i32* %t6
|
|
store i32 0, i32* %t7
|
|
br label %while.cond.1
|
|
while.cond.1:
|
|
%t8 = load i32, i32* %t6
|
|
%t9 = load i32, i32* %t2
|
|
%t10 = icmp slt i32 %t8, %t9
|
|
%t11 = zext i1 %t10 to i32
|
|
%t12 = icmp ne i32 %t11, 0
|
|
br i1 %t12, label %while.body.2, label %while.end.3
|
|
while.body.2:
|
|
store i32 0, i32* %t7
|
|
br label %while.cond.4
|
|
while.end.3:
|
|
ret i32 -1
|
|
while.cond.4:
|
|
%t13 = load i32, i32* %t7
|
|
%t14 = load i32, i32* %t1
|
|
%t15 = icmp slt i32 %t13, %t14
|
|
%t16 = zext i1 %t15 to i32
|
|
%t17 = icmp ne i32 %t16, 0
|
|
br i1 %t17, label %while.body.5, label %while.end.6
|
|
while.body.5:
|
|
%t18 = load i32, i32* %t6
|
|
%t19 = load i32, i32* %t7
|
|
%t20 = icmp slt i32 %t18, %t19
|
|
%t21 = zext i1 %t20 to i32
|
|
%t22 = icmp ne i32 %t21, 0
|
|
br i1 %t22, label %if.then.7, label %if.end.8
|
|
while.end.6:
|
|
%t55 = load i32, i32* %t6
|
|
%t56 = add i32 %t55, 1
|
|
store i32 %t56, i32* %t6
|
|
br label %while.cond.1
|
|
if.then.7:
|
|
%t23 = load i32, i32* %t7
|
|
%t24 = add i32 %t23, 1
|
|
store i32 %t24, i32* %t7
|
|
br label %while.cond.4
|
|
if.end.8:
|
|
%t26 = load i32, i32* %t6
|
|
%t27 = load i32, i32* %t1
|
|
%t28 = mul i32 %t26, %t27
|
|
%t29 = load i32, i32* %t7
|
|
%t30 = add i32 %t28, %t29
|
|
%t31 = getelementptr inbounds i32, i32* %arg.matrix, i32 %t30
|
|
%t32 = load i32, i32* %t31
|
|
store i32 %t32, i32* %t25
|
|
%t33 = load i32, i32* %t7
|
|
%t34 = load i32, i32* %t2
|
|
%t35 = mul i32 %t33, %t34
|
|
%t36 = load i32, i32* %t6
|
|
%t37 = add i32 %t35, %t36
|
|
%t38 = getelementptr inbounds i32, i32* %arg.matrix, i32 %t37
|
|
%t39 = load i32, i32* %t6
|
|
%t40 = load i32, i32* %t1
|
|
%t41 = mul i32 %t39, %t40
|
|
%t42 = load i32, i32* %t7
|
|
%t43 = add i32 %t41, %t42
|
|
%t44 = getelementptr inbounds i32, i32* %arg.matrix, i32 %t43
|
|
%t45 = load i32, i32* %t44
|
|
store i32 %t45, i32* %t38
|
|
%t46 = load i32, i32* %t6
|
|
%t47 = load i32, i32* %t1
|
|
%t48 = mul i32 %t46, %t47
|
|
%t49 = load i32, i32* %t7
|
|
%t50 = add i32 %t48, %t49
|
|
%t51 = getelementptr inbounds i32, i32* %arg.matrix, i32 %t50
|
|
%t52 = load i32, i32* %t25
|
|
store i32 %t52, i32* %t51
|
|
%t53 = load i32, i32* %t7
|
|
%t54 = add i32 %t53, 1
|
|
store i32 %t54, i32* %t7
|
|
br label %while.cond.4
|
|
}
|
|
define i32 @main() {
|
|
entry:
|
|
%t57 = alloca i32
|
|
%t59 = alloca i32
|
|
%t63 = alloca i32
|
|
%t87 = alloca i32
|
|
%t58 = call i32 @getint()
|
|
store i32 %t58, i32* %t57
|
|
%t60 = getelementptr inbounds [100000 x i32], [100000 x i32]* @a, i32 0, i32 0
|
|
%t61 = call i32 @getarray(i32* %t60)
|
|
store i32 %t61, i32* %t59
|
|
call void @starttime()
|
|
store i32 0, i32* %t63
|
|
br label %while.cond.9
|
|
while.cond.9:
|
|
%t64 = load i32, i32* %t63
|
|
%t65 = load i32, i32* %t57
|
|
%t66 = icmp slt i32 %t64, %t65
|
|
%t67 = zext i1 %t66 to i32
|
|
%t68 = icmp ne i32 %t67, 0
|
|
br i1 %t68, label %while.body.10, label %while.end.11
|
|
while.body.10:
|
|
%t69 = load i32, i32* %t63
|
|
%t70 = getelementptr inbounds [20000000 x i32], [20000000 x i32]* @matrix, i32 0, i32 %t69
|
|
%t71 = load i32, i32* %t63
|
|
store i32 %t71, i32* %t70
|
|
%t72 = load i32, i32* %t63
|
|
%t73 = add i32 %t72, 1
|
|
store i32 %t73, i32* %t63
|
|
br label %while.cond.9
|
|
while.end.11:
|
|
store i32 0, i32* %t63
|
|
br label %while.cond.12
|
|
while.cond.12:
|
|
%t74 = load i32, i32* %t63
|
|
%t75 = load i32, i32* %t59
|
|
%t76 = icmp slt i32 %t74, %t75
|
|
%t77 = zext i1 %t76 to i32
|
|
%t78 = icmp ne i32 %t77, 0
|
|
br i1 %t78, label %while.body.13, label %while.end.14
|
|
while.body.13:
|
|
%t79 = load i32, i32* %t57
|
|
%t80 = load i32, i32* %t63
|
|
%t81 = getelementptr inbounds [100000 x i32], [100000 x i32]* @a, i32 0, i32 %t80
|
|
%t82 = load i32, i32* %t81
|
|
%t83 = getelementptr inbounds [20000000 x i32], [20000000 x i32]* @matrix, i32 0, i32 0
|
|
%t84 = call i32 @transpose(i32 %t79, i32* %t83, i32 %t82)
|
|
%t85 = load i32, i32* %t63
|
|
%t86 = add i32 %t85, 1
|
|
store i32 %t86, i32* %t63
|
|
br label %while.cond.12
|
|
while.end.14:
|
|
store i32 0, i32* %t87
|
|
store i32 0, i32* %t63
|
|
br label %while.cond.15
|
|
while.cond.15:
|
|
%t88 = load i32, i32* %t63
|
|
%t89 = load i32, i32* %t59
|
|
%t90 = icmp slt i32 %t88, %t89
|
|
%t91 = zext i1 %t90 to i32
|
|
%t92 = icmp ne i32 %t91, 0
|
|
br i1 %t92, label %while.body.16, label %while.end.17
|
|
while.body.16:
|
|
%t93 = load i32, i32* %t87
|
|
%t94 = load i32, i32* %t63
|
|
%t95 = load i32, i32* %t63
|
|
%t96 = mul i32 %t94, %t95
|
|
%t97 = load i32, i32* %t63
|
|
%t98 = getelementptr inbounds [20000000 x i32], [20000000 x i32]* @matrix, i32 0, i32 %t97
|
|
%t99 = load i32, i32* %t98
|
|
%t100 = mul i32 %t96, %t99
|
|
%t101 = add i32 %t93, %t100
|
|
store i32 %t101, i32* %t87
|
|
%t102 = load i32, i32* %t63
|
|
%t103 = add i32 %t102, 1
|
|
store i32 %t103, i32* %t63
|
|
br label %while.cond.15
|
|
while.end.17:
|
|
%t104 = load i32, i32* %t87
|
|
%t105 = icmp slt i32 %t104, 0
|
|
%t106 = zext i1 %t105 to i32
|
|
%t107 = icmp ne i32 %t106, 0
|
|
br i1 %t107, label %if.then.18, label %if.end.19
|
|
if.then.18:
|
|
%t108 = load i32, i32* %t87
|
|
%t109 = sub i32 0, %t108
|
|
store i32 %t109, i32* %t87
|
|
br label %if.end.19
|
|
if.end.19:
|
|
call void @stoptime()
|
|
%t111 = load i32, i32* %t87
|
|
call void @putint(i32 %t111)
|
|
call void @putch(i32 10)
|
|
ret i32 0
|
|
}
|