-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMem2Reg.h
More file actions
60 lines (53 loc) · 1.61 KB
/
Mem2Reg.h
File metadata and controls
60 lines (53 loc) · 1.61 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
#ifndef SYSYF_MEM2REG_H
#define SYSYF_MEM2REG_H
#include "BasicBlock.h"
#include "Function.h"
#include "GlobalVariable.h"
#include "IRBuilder.h"
#include "Instruction.h"
#include "Module.h"
#include "Pass.h"
#include "internal_types.h"
#include <memory>
namespace SysYF {
namespace IR {
class Mem2Reg : public Pass{
private:
WeakPtr<Function> func_;
WeakPtr<IRBuilder> builder;
WeakPtrMap<BasicBlock, WeakPtrVec<Value>> define_var;
const std::string name = "Mem2Reg";
WeakPtrMap<Value, WeakPtr<Value>> lvalue_connection;
WeakPtrSet<Value> no_union_set;
public:
explicit Mem2Reg(WeakPtr<Module> m) : Pass(m) {}
~Mem2Reg(){};
void execute() final;
void genPhi();
void insideBlockForwarding();
void valueDefineCounting();
void valueForwarding(Ptr<BasicBlock> bb);
void removeAlloc();
const std::string get_name() const override {return name;}
bool isLocalVarOp(Ptr<Instruction> inst){
if (inst->get_instr_type() == Instruction::OpID::store){
auto sinst = static_pointer_cast<StoreInst>(inst);
auto lvalue = sinst->get_lval();
auto glob = dynamic_pointer_cast<GlobalVariable>(lvalue);
auto array_element_ptr = dynamic_pointer_cast<GetElementPtrInst>(lvalue);
return !glob && !array_element_ptr;
}
else if (inst->get_instr_type() == Instruction::OpID::load){
auto linst = static_pointer_cast<LoadInst>(inst);
auto lvalue = linst->get_lval();
auto glob = dynamic_pointer_cast<GlobalVariable>(lvalue);
auto array_element_ptr = dynamic_pointer_cast<GetElementPtrInst>(lvalue);
return !glob && !array_element_ptr;
}
else
return false;
}
};
}
}
#endif // SYSYF_MEM2REG_H