Repository navigation
Expand file tree
/
Copy pathIR.cpp
More file actions
71 lines (56 loc) · 1.84 KB
/
Copy pathIR.cpp
File metadata and controls
71 lines (56 loc) · 1.84 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
#include "IR.h"
#include "IRVisitors.h"
#include <set>
namespace IR {
void getTgtSTEntry(const Instruction_sptr& instr, STEntry_set_sptr& res) {
auto reg = std::dynamic_pointer_cast<Data>(instr);
/// If it is a Data "instruction" and if it is not a constant/immediate
if (reg != nullptr) {
if (std::dynamic_pointer_cast<Immediate>(instr) == nullptr)
res->insert( reg->value() );
}
else {
res->insert( std::dynamic_pointer_cast<Data>(instr->tgt())->value() );
}
}
bool isADefinition(Instruction_sptr instr) {
if ( std::dynamic_pointer_cast<BranchInstruction>(instr) )
return false;
else
return true;
}
BasicBlock_list_sptr Function::topologicalSort() {
auto result = make_shared<BasicBlock_list>();
auto auxi = make_shared<BasicBlock_list>();
std::set<BasicBlock_sptr> visited;
auxi->push_back( this->_entryBasicBlock );
result->push_back( this->_entryBasicBlock );
visited.insert( this->_entryBasicBlock );
while (!auxi->empty()) {
auto curr = auxi->front(); auxi->pop_front();
for (auto& succ : *curr->succs()) {
if (visited.find(succ) != visited.end()) continue;
auxi->push_back( succ );
result->push_back( succ );
visited.insert( succ );
}
}
return result;
}
void Function::addSymbolTable(shared_ptr<SymbolTable> st) {
for (auto entry : st->entries() ) {
if (nameVersions.find(entry.second->getName()) != nameVersions.end()) {
entry.second->rename( entry.second->getName() + "_" + std::to_string(nameVersions[entry.second->getName()]));
}
this->symbolTable()->add( entry.second );
}
}
void Function::appendBasicBlock(BasicBlock_sptr bb) {
bb->id( this->_bbs->size() );
this->_bbs->push_back(bb);
this->_currentBasicBlock = bb;
}
void Function::appendInstruction(shared_ptr<IR::Instruction> instr) {
this->_currentBasicBlock->appendInstruction(instr);
}
}