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.
408 lines
12 KiB
408 lines
12 KiB
@MAX_WIDTH = global i32 1024
|
|
@MAX_HEIGHT = global i32 1024
|
|
@image = global [1048576 x i32] zeroinitializer
|
|
@width = global i32 0
|
|
@height = global i32 0
|
|
@PI = global float 0x400921FB60000000
|
|
@TWO_PI = global float 0x401921FB60000000
|
|
@EPSILON = global float 0x3EB0C6F7A0000000
|
|
|
|
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 float @my_fabs(float %arg.x) {
|
|
entry:
|
|
%t0 = alloca float
|
|
store float %arg.x, float* %t0
|
|
%t1 = load float, float* %t0
|
|
%t2 = fcmp ogt float %t1, 0x0000000000000000
|
|
%t3 = zext i1 %t2 to i32
|
|
%t4 = icmp ne i32 %t3, 0
|
|
br i1 %t4, label %if.then.1, label %if.end.2
|
|
if.then.1:
|
|
%t5 = load float, float* %t0
|
|
ret float %t5
|
|
if.end.2:
|
|
%t6 = load float, float* %t0
|
|
%t7 = fsub float 0x0000000000000000, %t6
|
|
ret float %t7
|
|
}
|
|
define float @p(float %arg.x) {
|
|
entry:
|
|
%t8 = alloca float
|
|
store float %arg.x, float* %t8
|
|
%t9 = load float, float* %t8
|
|
%t10 = fmul float 0x4008000000000000, %t9
|
|
%t11 = load float, float* %t8
|
|
%t12 = fmul float 0x4010000000000000, %t11
|
|
%t13 = load float, float* %t8
|
|
%t14 = fmul float %t12, %t13
|
|
%t15 = load float, float* %t8
|
|
%t16 = fmul float %t14, %t15
|
|
%t17 = fsub float %t10, %t16
|
|
ret float %t17
|
|
}
|
|
define float @my_sin_impl(float %arg.x) {
|
|
entry:
|
|
%t18 = alloca float
|
|
store float %arg.x, float* %t18
|
|
%t19 = load float, float* %t18
|
|
%t20 = call float @my_fabs(float %t19)
|
|
%t21 = load float, float* @EPSILON
|
|
%t22 = fcmp ole float %t20, %t21
|
|
%t23 = zext i1 %t22 to i32
|
|
%t24 = icmp ne i32 %t23, 0
|
|
br i1 %t24, label %if.then.3, label %if.end.4
|
|
if.then.3:
|
|
%t25 = load float, float* %t18
|
|
ret float %t25
|
|
if.end.4:
|
|
%t26 = load float, float* %t18
|
|
%t27 = fdiv float %t26, 0x4008000000000000
|
|
%t28 = call float @my_sin_impl(float %t27)
|
|
%t29 = call float @p(float %t28)
|
|
ret float %t29
|
|
}
|
|
define float @my_sin(float %arg.x) {
|
|
entry:
|
|
%t42 = alloca i32
|
|
%t30 = alloca float
|
|
store float %arg.x, float* %t30
|
|
%t31 = load float, float* %t30
|
|
%t32 = load float, float* @TWO_PI
|
|
%t33 = fcmp ogt float %t31, %t32
|
|
%t34 = zext i1 %t33 to i32
|
|
%t35 = icmp ne i32 %t34, 0
|
|
br i1 %t35, label %if.then.5, label %lor.rhs.7
|
|
if.then.5:
|
|
%t43 = load float, float* %t30
|
|
%t44 = load float, float* @TWO_PI
|
|
%t45 = fdiv float %t43, %t44
|
|
%t46 = fptosi float %t45 to i32
|
|
store i32 %t46, i32* %t42
|
|
%t47 = load float, float* %t30
|
|
%t48 = load i32, i32* %t42
|
|
%t49 = load float, float* @TWO_PI
|
|
%t50 = sitofp i32 %t48 to float
|
|
%t51 = fmul float %t50, %t49
|
|
%t52 = fsub float %t47, %t51
|
|
store float %t52, float* %t30
|
|
br label %if.end.6
|
|
if.end.6:
|
|
%t53 = load float, float* %t30
|
|
%t54 = load float, float* @PI
|
|
%t55 = fcmp ogt float %t53, %t54
|
|
%t56 = zext i1 %t55 to i32
|
|
%t57 = icmp ne i32 %t56, 0
|
|
br i1 %t57, label %if.then.8, label %if.end.9
|
|
lor.rhs.7:
|
|
%t36 = load float, float* %t30
|
|
%t37 = load float, float* @TWO_PI
|
|
%t38 = fsub float 0x0000000000000000, %t37
|
|
%t39 = fcmp olt float %t36, %t38
|
|
%t40 = zext i1 %t39 to i32
|
|
%t41 = icmp ne i32 %t40, 0
|
|
br i1 %t41, label %if.then.5, label %if.end.6
|
|
if.then.8:
|
|
%t58 = load float, float* %t30
|
|
%t59 = load float, float* @TWO_PI
|
|
%t60 = fsub float %t58, %t59
|
|
store float %t60, float* %t30
|
|
br label %if.end.9
|
|
if.end.9:
|
|
%t61 = load float, float* %t30
|
|
%t62 = load float, float* @PI
|
|
%t63 = fsub float 0x0000000000000000, %t62
|
|
%t64 = fcmp olt float %t61, %t63
|
|
%t65 = zext i1 %t64 to i32
|
|
%t66 = icmp ne i32 %t65, 0
|
|
br i1 %t66, label %if.then.10, label %if.end.11
|
|
if.then.10:
|
|
%t67 = load float, float* %t30
|
|
%t68 = load float, float* @TWO_PI
|
|
%t69 = fadd float %t67, %t68
|
|
store float %t69, float* %t30
|
|
br label %if.end.11
|
|
if.end.11:
|
|
%t70 = load float, float* %t30
|
|
%t71 = call float @my_sin_impl(float %t70)
|
|
ret float %t71
|
|
}
|
|
define float @my_cos(float %arg.x) {
|
|
entry:
|
|
%t72 = alloca float
|
|
store float %arg.x, float* %t72
|
|
%t73 = load float, float* %t72
|
|
%t74 = load float, float* @PI
|
|
%t75 = fdiv float %t74, 0x4000000000000000
|
|
%t76 = fadd float %t73, %t75
|
|
%t77 = call float @my_sin(float %t76)
|
|
ret float %t77
|
|
}
|
|
define i32 @read_image() {
|
|
entry:
|
|
%t100 = alloca i32
|
|
%t106 = alloca i32
|
|
%t78 = call i32 @getch()
|
|
%t79 = icmp ne i32 %t78, 80
|
|
%t80 = zext i1 %t79 to i32
|
|
%t81 = icmp ne i32 %t80, 0
|
|
br i1 %t81, label %if.then.12, label %lor.rhs.14
|
|
if.then.12:
|
|
ret i32 -1
|
|
if.end.13:
|
|
%t86 = call i32 @getint()
|
|
store i32 %t86, i32* @width
|
|
%t87 = call i32 @getint()
|
|
store i32 %t87, i32* @height
|
|
%t88 = load i32, i32* @width
|
|
%t89 = icmp sgt i32 %t88, 1024
|
|
%t90 = zext i1 %t89 to i32
|
|
%t91 = icmp ne i32 %t90, 0
|
|
br i1 %t91, label %if.then.15, label %lor.rhs.18
|
|
lor.rhs.14:
|
|
%t82 = call i32 @getch()
|
|
%t83 = icmp ne i32 %t82, 50
|
|
%t84 = zext i1 %t83 to i32
|
|
%t85 = icmp ne i32 %t84, 0
|
|
br i1 %t85, label %if.then.12, label %if.end.13
|
|
if.then.15:
|
|
ret i32 -1
|
|
if.end.16:
|
|
store i32 0, i32* %t100
|
|
br label %while.cond.19
|
|
lor.rhs.17:
|
|
%t96 = call i32 @getint()
|
|
%t97 = icmp ne i32 %t96, 255
|
|
%t98 = zext i1 %t97 to i32
|
|
%t99 = icmp ne i32 %t98, 0
|
|
br i1 %t99, label %if.then.15, label %if.end.16
|
|
lor.rhs.18:
|
|
%t92 = load i32, i32* @height
|
|
%t93 = icmp sgt i32 %t92, 1024
|
|
%t94 = zext i1 %t93 to i32
|
|
%t95 = icmp ne i32 %t94, 0
|
|
br i1 %t95, label %if.then.15, label %lor.rhs.17
|
|
while.cond.19:
|
|
%t101 = load i32, i32* %t100
|
|
%t102 = load i32, i32* @height
|
|
%t103 = icmp slt i32 %t101, %t102
|
|
%t104 = zext i1 %t103 to i32
|
|
%t105 = icmp ne i32 %t104, 0
|
|
br i1 %t105, label %while.body.20, label %while.end.21
|
|
while.body.20:
|
|
store i32 0, i32* %t106
|
|
br label %while.cond.22
|
|
while.end.21:
|
|
ret i32 0
|
|
while.cond.22:
|
|
%t107 = load i32, i32* %t106
|
|
%t108 = load i32, i32* @width
|
|
%t109 = icmp slt i32 %t107, %t108
|
|
%t110 = zext i1 %t109 to i32
|
|
%t111 = icmp ne i32 %t110, 0
|
|
br i1 %t111, label %while.body.23, label %while.end.24
|
|
while.body.23:
|
|
%t112 = load i32, i32* %t100
|
|
%t113 = load i32, i32* @width
|
|
%t114 = mul i32 %t112, %t113
|
|
%t115 = load i32, i32* %t106
|
|
%t116 = add i32 %t114, %t115
|
|
%t117 = getelementptr inbounds [1048576 x i32], [1048576 x i32]* @image, i32 0, i32 %t116
|
|
%t118 = call i32 @getint()
|
|
store i32 %t118, i32* %t117
|
|
%t119 = load i32, i32* %t106
|
|
%t120 = add i32 %t119, 1
|
|
store i32 %t120, i32* %t106
|
|
br label %while.cond.22
|
|
while.end.24:
|
|
%t121 = load i32, i32* %t100
|
|
%t122 = add i32 %t121, 1
|
|
store i32 %t122, i32* %t100
|
|
br label %while.cond.19
|
|
}
|
|
define i32 @rotate(i32 %arg.x, i32 %arg.y, float %arg.rad) {
|
|
entry:
|
|
%t126 = alloca float
|
|
%t129 = alloca float
|
|
%t132 = alloca i32
|
|
%t135 = alloca i32
|
|
%t138 = alloca i32
|
|
%t142 = alloca i32
|
|
%t146 = alloca i32
|
|
%t160 = alloca i32
|
|
%t123 = alloca i32
|
|
store i32 %arg.x, i32* %t123
|
|
%t124 = alloca i32
|
|
store i32 %arg.y, i32* %t124
|
|
%t125 = alloca float
|
|
store float %arg.rad, float* %t125
|
|
%t127 = load float, float* %t125
|
|
%t128 = call float @my_sin(float %t127)
|
|
store float %t128, float* %t126
|
|
%t130 = load float, float* %t125
|
|
%t131 = call float @my_cos(float %t130)
|
|
store float %t131, float* %t129
|
|
%t133 = load i32, i32* @width
|
|
%t134 = sdiv i32 %t133, 2
|
|
store i32 %t134, i32* %t132
|
|
%t136 = load i32, i32* @height
|
|
%t137 = sdiv i32 %t136, 2
|
|
store i32 %t137, i32* %t135
|
|
%t139 = load i32, i32* %t123
|
|
%t140 = load i32, i32* %t132
|
|
%t141 = sub i32 %t139, %t140
|
|
store i32 %t141, i32* %t138
|
|
%t143 = load i32, i32* %t124
|
|
%t144 = load i32, i32* %t135
|
|
%t145 = sub i32 %t143, %t144
|
|
store i32 %t145, i32* %t142
|
|
%t147 = load i32, i32* %t138
|
|
%t148 = load float, float* %t129
|
|
%t149 = sitofp i32 %t147 to float
|
|
%t150 = fmul float %t149, %t148
|
|
%t151 = load i32, i32* %t142
|
|
%t152 = load float, float* %t126
|
|
%t153 = sitofp i32 %t151 to float
|
|
%t154 = fmul float %t153, %t152
|
|
%t155 = fsub float %t150, %t154
|
|
%t156 = load i32, i32* %t132
|
|
%t157 = sitofp i32 %t156 to float
|
|
%t158 = fadd float %t155, %t157
|
|
%t159 = fptosi float %t158 to i32
|
|
store i32 %t159, i32* %t146
|
|
%t161 = load i32, i32* %t138
|
|
%t162 = load float, float* %t126
|
|
%t163 = sitofp i32 %t161 to float
|
|
%t164 = fmul float %t163, %t162
|
|
%t165 = load i32, i32* %t142
|
|
%t166 = load float, float* %t129
|
|
%t167 = sitofp i32 %t165 to float
|
|
%t168 = fmul float %t167, %t166
|
|
%t169 = fadd float %t164, %t168
|
|
%t170 = load i32, i32* %t135
|
|
%t171 = sitofp i32 %t170 to float
|
|
%t172 = fadd float %t169, %t171
|
|
%t173 = fptosi float %t172 to i32
|
|
store i32 %t173, i32* %t160
|
|
%t174 = load i32, i32* %t146
|
|
%t175 = icmp slt i32 %t174, 0
|
|
%t176 = zext i1 %t175 to i32
|
|
%t177 = icmp ne i32 %t176, 0
|
|
br i1 %t177, label %if.then.25, label %lor.rhs.29
|
|
if.then.25:
|
|
ret i32 0
|
|
if.end.26:
|
|
%t192 = load i32, i32* %t160
|
|
%t193 = load i32, i32* @width
|
|
%t194 = mul i32 %t192, %t193
|
|
%t195 = load i32, i32* %t146
|
|
%t196 = add i32 %t194, %t195
|
|
%t197 = getelementptr inbounds [1048576 x i32], [1048576 x i32]* @image, i32 0, i32 %t196
|
|
%t198 = load i32, i32* %t197
|
|
ret i32 %t198
|
|
lor.rhs.27:
|
|
%t187 = load i32, i32* %t160
|
|
%t188 = load i32, i32* @height
|
|
%t189 = icmp sge i32 %t187, %t188
|
|
%t190 = zext i1 %t189 to i32
|
|
%t191 = icmp ne i32 %t190, 0
|
|
br i1 %t191, label %if.then.25, label %if.end.26
|
|
lor.rhs.28:
|
|
%t183 = load i32, i32* %t160
|
|
%t184 = icmp slt i32 %t183, 0
|
|
%t185 = zext i1 %t184 to i32
|
|
%t186 = icmp ne i32 %t185, 0
|
|
br i1 %t186, label %if.then.25, label %lor.rhs.27
|
|
lor.rhs.29:
|
|
%t178 = load i32, i32* %t146
|
|
%t179 = load i32, i32* @width
|
|
%t180 = icmp sge i32 %t178, %t179
|
|
%t181 = zext i1 %t180 to i32
|
|
%t182 = icmp ne i32 %t181, 0
|
|
br i1 %t182, label %if.then.25, label %lor.rhs.28
|
|
}
|
|
define void @write_pgm(float %arg.rad) {
|
|
entry:
|
|
%t211 = alloca i32
|
|
%t217 = alloca i32
|
|
%t199 = alloca float
|
|
store float %arg.rad, float* %t199
|
|
call void @putch(i32 80)
|
|
call void @putch(i32 50)
|
|
call void @putch(i32 10)
|
|
%t203 = load i32, i32* @width
|
|
call void @putint(i32 %t203)
|
|
call void @putch(i32 32)
|
|
%t206 = load i32, i32* @height
|
|
call void @putint(i32 %t206)
|
|
call void @putch(i32 32)
|
|
call void @putint(i32 255)
|
|
call void @putch(i32 10)
|
|
store i32 0, i32* %t211
|
|
br label %while.cond.30
|
|
while.cond.30:
|
|
%t212 = load i32, i32* %t211
|
|
%t213 = load i32, i32* @height
|
|
%t214 = icmp slt i32 %t212, %t213
|
|
%t215 = zext i1 %t214 to i32
|
|
%t216 = icmp ne i32 %t215, 0
|
|
br i1 %t216, label %while.body.31, label %while.end.32
|
|
while.body.31:
|
|
store i32 0, i32* %t217
|
|
br label %while.cond.33
|
|
while.end.32:
|
|
ret void
|
|
while.cond.33:
|
|
%t218 = load i32, i32* %t217
|
|
%t219 = load i32, i32* @width
|
|
%t220 = icmp slt i32 %t218, %t219
|
|
%t221 = zext i1 %t220 to i32
|
|
%t222 = icmp ne i32 %t221, 0
|
|
br i1 %t222, label %while.body.34, label %while.end.35
|
|
while.body.34:
|
|
%t223 = load i32, i32* %t217
|
|
%t224 = load i32, i32* %t211
|
|
%t225 = load float, float* %t199
|
|
%t226 = call i32 @rotate(i32 %t223, i32 %t224, float %t225)
|
|
call void @putint(i32 %t226)
|
|
call void @putch(i32 32)
|
|
%t229 = load i32, i32* %t217
|
|
%t230 = add i32 %t229, 1
|
|
store i32 %t230, i32* %t217
|
|
br label %while.cond.33
|
|
while.end.35:
|
|
call void @putch(i32 10)
|
|
%t232 = load i32, i32* %t211
|
|
%t233 = add i32 %t232, 1
|
|
store i32 %t233, i32* %t211
|
|
br label %while.cond.30
|
|
}
|
|
define i32 @main() {
|
|
entry:
|
|
%t234 = alloca float
|
|
%t235 = call float @getfloat()
|
|
store float %t235, float* %t234
|
|
%t236 = call i32 @getch()
|
|
%t237 = call i32 @read_image()
|
|
%t238 = icmp slt i32 %t237, 0
|
|
%t239 = zext i1 %t238 to i32
|
|
%t240 = icmp ne i32 %t239, 0
|
|
br i1 %t240, label %if.then.36, label %if.end.37
|
|
if.then.36:
|
|
ret i32 -1
|
|
if.end.37:
|
|
%t241 = load float, float* %t234
|
|
call void @write_pgm(float %t241)
|
|
ret i32 0
|
|
}
|