-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfunctions.c
112 lines (90 loc) · 2.6 KB
/
functions.c
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
// No arguments forward declaration
int fnoargs();
// No arguments
int fnoargs() {
return 5;
}
int fnoargs_caller() {
return fnoargs();
}
// Single argument forward declaration
int fonearg(int a);
// Single argument
int fonearg(int a) {
return a;
}
int fonearg_caller(int a) {
return fonearg(a);
}
// Multiple arguments forward declaration
int fthreeargs(int a, int b, int c);
// Multiple arguments
int fthreeargs(int a, int b, int c) {
return a + b + c;
}
int fthreeargs_caller(int a, int b, int c) {
return fthreeargs(a, b, c);
}
// Different parameter types
float ffloat(float a) {
return fonearg_caller(a);
}
// Recursive functions
int ffib(int a) {
if (a == 0) {
return 0;
} else if (a == 1) {
return 1;
} else {
return ffib(a-1) + ffib(a-2);
}
}
int ffact(int a) {
if (a == 0) {
return 1;
}
return a * ffact(a-1);
}
int fsum(int a) {
if (a == 0) {
return 0;
}
return a + fsum(a-1);
}
// Indirect recursive functions
// XXX These have mismatches, looks like epycc is doing last call optimization
// while clang isn't? Should look further into it, clang seems to have the
// inline threshold around 25 for -O2 (with "-mllvm --inline-threshold=21"
// produces the same code as without, and different code than with 20)
// They used to be 5 mismatches, but the new IR diff code increfased the
// number of mismatches because of also counting the missing instructions.
// XXX In addition, clang inserts a phi node to unify return paths while epycc
// doesn't (and is one jump shorter because of that)
// XXX Note these two may generate different code depending on the function
// names and cause the mismatch to toggle between 7 and 20. Maybe there's
// some leftover in epycc, llvmlite, the flags or llvm is not idempotent?
int fsum_indirect2__mm07(int a);
int fsum_indirect1__mm06(int a) {
if (a == 0) {
return 0;
}
return (a * 2) + fsum_indirect2__mm07(a - 1);
}
int fsum_indirect2__mm07(int a) {
if (a == 0) {
return 0;
}
return a + fsum_indirect1__mm06(a - 1);
}
// Extended return type forward declaration
unsigned long long fulonglong(int a);
unsigned long long fulonglong(int a) {
return a;
}
// No parameter name and extended parameter type forward declaration
int fforward_noparamname(unsigned int, int b);
int fforward_noparamname(unsigned int a, int b) {
return a;
}
// XXX Missing function pointer types
// XXX Missing varargs