forked from rift-lecture/rift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
boxing_removal.cpp
62 lines (51 loc) · 1.78 KB
/
boxing_removal.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
#include <iostream>
#include <ciso646>
#include <iostream>
#include "boxing_removal.h"
#include "compiler.h"
#include "rift.h"
using namespace llvm;
using namespace std;
namespace rift {
char BoxingRemoval::ID = 0;
bool BoxingRemoval::runOnFunction(llvm::Function & f) {
// std::cout << "running boxing removal optimization..." << std::endl;
bool changed = false;
while (true) {
bool c = false;
for (auto & b : f) {
auto i = b.begin();
while (i != b.end()) {
bool erase = false;
if (CallInst * ci = dyn_cast<CallInst>(i)) {
if (ci->getCalledFunction()->getAttributes().hasAttribute(AttributeSet::FunctionIndex, Attribute::ReadNone)) {
if (ci->use_empty())
erase = true;
}
/* StringRef s = ci->getCalledFunction()->getName();
if (s != "call" and s != "genericEval" and s != "characterEval" and s != "envGet" and s != "envSet") {
if (ci->use_empty())
erase = true;
} */
}
if (erase) {
llvm::Instruction * v = i;
++i;
v->eraseFromParent();
c = true;
} else {
++i;
}
}
}
changed = changed or c;
if (not c)
break;
}
if (DEBUG) {
cout << "After boxing removal: ---------------------------------------" << endl;
f.dump();
}
return changed;
}
} // namespace rift