-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_liveness.cpp
66 lines (59 loc) · 1.37 KB
/
test_liveness.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
#include "disasm.h"
#include <iostream>
#include <elfio/elfio.hpp>
#include "cfg.h"
#include "analysis.h"
#include "reg-alloc.h"
int main(int argc, char *argv[]) {
lifter lift;
if (!lift.load(argv[1])) {
std::cerr << "Cannot open input file " << argv[1] << '\n';
return 1;
}
if (lift.instructions.empty()) {
try {
lift.save(argv[argc-1]);
return 0;
}
catch (std::runtime_error& e) {
std::cout << e.what() << '\n';
return 1;
}
}
control_flow_graph cfg = get_cfg(lift);
liveness_analysis(cfg);
for (auto cfgi = cfg.begin(); cfgi != cfg.end(); ++cfgi) {
auto& bb = *cfgi;
if (bb.front().is_data())
continue;
int skip = 0;
auto it = bb.begin();
while(it->is_pseudo()) { ++it; }
for (++it; it != bb.end(); ++it) {
if (it->is_pseudo())
continue;
if (!it->mnemonic.compare(0, 2, "it", 2)) {
skip = 4;
continue;
}
if (skip) {
skip--;
continue;
}
vreg free_reg = vreg();
for (free_reg.num = 0; free_reg.num < 16; free_reg.num++) {
if (it->live_regs.find(free_reg) == it->live_regs.end())
break;
}
if (free_reg.num == 16 || free_reg.num == 13 || free_reg.num == 15)
continue;
bb.insert(it, vins::ins_mov(free_reg, 0xff));
}
}
lift.instructions = cfg_dump(cfg);
try { lift.save(argv[argc-1]); }
catch (std::runtime_error& e) {
std::cout << e.what() << '\n';
return 1;
}
}