This repository was archived by the owner on Jul 7, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathir.cpp
More file actions
103 lines (78 loc) · 1.99 KB
/
ir.cpp
File metadata and controls
103 lines (78 loc) · 1.99 KB
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) {
auto bb = new NodeList();
auto* c1 = bb->insert<Constant>(1);
auto* c2 = bb->insert<Constant>(2);
auto* a = bb->insert<Add>(c1, c2);
if (print) {
for (auto i : *bb)
std::cout << *i << "\n";
std::cout << "===============\n";
}
auto patch = bb->insertBefore(bb->at(1));
auto c3 = patch->insert<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->insert<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->insert<Add>(c3, c4);
bb->insert<Add>(a1, a);
if (print) {
for (auto i : *bb)
std::cout << *i << "\n";
std::cout << "===============\n";
}
bb = 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->insert<Add>(
patch4->insert<Constant>(i),
patch4->insert<Constant>(i));
}
bb = bb->flatten();
int count = 0;
int countI = 0;
// Simulate an analysis:
for (auto i : *bb) {
countI++;
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";
assert(count == 799980004);
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;
}