-
Notifications
You must be signed in to change notification settings - Fork 0
/
ir-ll.cpp
106 lines (84 loc) · 2.22 KB
/
ir-ll.cpp
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
#include "ir-ll.h"
template <typename container>
void test(bool print = false) {
auto bb = new NodeList<container>();
auto* c1 = bb->push_back(new Constant(1));
auto* c2 = bb->push_back(new Constant(2));
auto* a = bb->push_back(new Add(c1, c2));
if (print) {
for (auto i : *bb)
std::cout << *i << "\n";
std::cout << "===============\n";
}
Node* c3 = new Constant(3);
bb->insert(bb->at(1), c3);
if (print) {
for (auto i : *bb)
std::cout << *i << "\n";
std::cout << "===============\n";
}
auto c4 = new Constant(4);
bb->insert(bb->at(1), c4);
if (print) {
for (auto i : *bb)
std::cout << *i << "\n";
std::cout << "===============\n";
}
auto a1 = new Add(c3, c4);
bb->insert(bb->at(3), a1);
bb->push_back(new Add(a1, a));
if (print) {
for (auto i : *bb)
std::cout << *i << "\n";
std::cout << "===============\n";
}
auto patch4 = bb->at(6);
for (int i = 0; i < 40000; ++i) {
auto c1 = new Constant(i);
auto c2 = new Constant(i);
patch4 = bb->insert(patch4, c2);
patch4 = bb->insert(patch4, c1);
++patch4;
++patch4;
patch4 = bb->insert(patch4, new Add(c1, c2));
++patch4;
}
int count = 0;
// Simulate an analysis:
for (auto i : *bb) {
if (i->type == Node::Type::Add) {
Node * l = ((Add*)i)->l();
if (l->type == Node::Type::Constant) {
count += ((Constant*)l)->value;
}
}
}
if (print)
std::cout << count << "\n";
delete bb;
}
int main(int argc, char *argv[]) {
// test<nodeDeque>(true);
assert(argc == 3);
int count = atoi(argv[2]);
if (strcmp("list", argv[1]) == 0) {
clock_t begin = clock();
for (int i = 0; i < count; ++i) {
test<nodeList>();
}
clock_t end = clock();
double elapsed_secs = double(end - begin) / CLOCKS_PER_SEC;
std::cerr << "Linked list (" << count << ") took : "
<< elapsed_secs << "\n";
} else {
clock_t begin = clock();
for (int i = 0; i < count; ++i) {
test<nodeDeque>();
}
clock_t end = clock();
double elapsed_secs = double(end - begin) / CLOCKS_PER_SEC;
std::cerr << "Deque (" << count << ") took : "
<< elapsed_secs << "\n";
}
return 0;
}