-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathir.cpp
103 lines (78 loc) · 2.01 KB
/
ir.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
#include "ir.h"
void test(bool print = false) {
// print = true;
auto bb = new NodeList();
auto* c1 = bb->append(Constant(1));
auto* c2 = bb->append(Constant(2));
auto* a = bb->append(Add(c1, c2));
c1->eraseFromList();
if (print) {
for (auto i : *bb)
std::cout << *i << std::endl;
std::cout << "===============\n";
}
//auto patch = bb->insertBefore(bb->at(1));
auto patch = bb->insertPatchBefore(c2);
auto c3 = patch->append(Constant(3));
if (print) {
for (auto i : *bb)
std::cout << *i << "\n";
std::cout << "===============\n";
}
auto patch2 = bb->insertBefore(bb->at(1));
auto c4 = patch2->append(Constant(4));
if (print) {
for (auto i : *bb)
std::cout << *i << "\n";
std::cout << "===============\n";
}
auto patch3 = bb->insertBefore(bb->at(3));
auto a1 = patch3->append(Add(c3, c4));
bb->append(Add(a1, a));
if (print) {
for (auto i : *bb)
std::cout << *i << "\n";
std::cout << "===============\n";
}
bb->flatten();
if (print) {
for (auto i : *bb)
std::cout << *i << "\n";
std::cout << "===============\n";
}
auto patch4 = bb->insertBefore(bb->at(6));
for (int i = 0; i < 40000; ++i) {
patch4->append(Add(
patch4->append(Constant(i)),
patch4->append(Constant(i))));
}
bb->flatten();
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;
}
using namespace std;
int main(int argc, char *argv[]) {
// test(true);
assert(argc == 2);
int count = atoi(argv[1]);
clock_t begin = clock();
for (int i = 0; i < count; ++i) {
test();
}
clock_t end = clock();
double elapsed_secs = double(end - begin) / CLOCKS_PER_SEC;
std::cerr << "Varray (" << count << ") took : "
<< elapsed_secs << "\n";
return 0;
}