forked from XiaoYaoYouUSTC/Cminusf-Compiler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathif_hand.ll
66 lines (55 loc) · 2.29 KB
/
if_hand.ll
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
; ModuleID = 'if.c'
source_filename = "if.c"
;target information,copy from gcd_array.ll
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
;define main function
define dso_local i32 @main() #0 {
;the first basic block
;Here is some boring but meaningful experience
;At the beginning of the lab,I thought about the extra variation in
;the code geneated by clang for a long time
;After reading the gcd_array.ll generated by clang,I got its' use
;All in all,the function will move into the basic block especially for returning
;a value from every basic block.
;Maybe we can return a value in different basic blocks,but to make the code clear
;,we should use this variation to return a value in the same block
;define the return variation
%1=alloca i32
;define a
%2=alloca float
;set initial value of return variation
store i32 0,i32* %1
;set a=5.555
;Learning from the example and the Internet,we have to use the way that float
;number stored in the memory to show the 5.555
store float 0x40163851E0000000,float* %2
;compare a with 1
%3=load float,float* %2
%4=fcmp ugt float %3,1.0
;if a>1,goto return 233,or skip the action of if
br i1 %4,label %5,label %6
;the second basic block
5: ;preds=%0
;To be honest,we can just'ret i32 233' and don't 'br'
;set return value 233 and goto the return
store i32 233,i32* %1
br label %7
;the third basic block
6: ;preds=%0
;set return value 0 and goto the return
store i32 0,i32* %1
br label %7
;the forth basic block
7: ;preds=%5,%6
;get the return value
%8=load i32,i32* %1
;return
ret i32 %8
}
;other information,copy from gcd_array.ll
attributes #0 = { noinline nounwind optnone uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "frame-pointer"="all" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
!llvm.module.flags = !{!0}
!llvm.ident = !{!1}
!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{!"clang version 10.0.1 "}