-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDataFlowNode.cxx
78 lines (71 loc) · 2.62 KB
/
DataFlowNode.cxx
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
#include "DataFlowNode.hxx"
#include <iostream>
#include "asserts.hxx"
#include <valgrind/memcheck.h>
void DataSourceNode::createPushNode(std::shared_ptr<codegenState> state, llvm::Value* value){
VALGRIND_CHECK_VALUE_IS_DEFINED(value);
state->stack.push_back(std::shared_ptr<RegisterPushNode>(new RegisterPushNode(value)));
}
void DataSourceNode::createMemStore(std::shared_ptr<codegenState> state, llvm::Value* address, llvm::Value* value){
if (llvm::isa<llvm::Constant>(address)) {
state->cache[address] = std::shared_ptr<DataSourceNode>(new MemoryStoreNode(value));
} else {
state->cache.clear();
}
assertdefined(state->TheModule)
assertdefined(address)
assertdefined(value)
llvm::Function* StoreInstr = state->TheModule->getFunction("StoreInstr");
assertdefined(StoreInstr)
state->Builder.CreateCall2(StoreInstr,address,value);
}
llvm::Value* DataConsumerNode::createPopNode(std::shared_ptr<codegenState> state) {
if (state->stack.size() != 0) {
std::shared_ptr<DataSourceNode> item = state->stack.back();
assertdefined(item)
state->stack.pop_back();
llvm::Value* result = item->getValue(state);
assertdefined(result)
return result;
} else {
return StackPopNode::createPopNode(state);
}
}
llvm::Value* DataConsumerNode::createMemRetrive(std::shared_ptr<codegenState> state, llvm::Value* address) {
if (!state->cache.count(address)) {
assertdefined(address)
llvm::Function* RetriveInstr = state->TheModule->getFunction("RetriveInstr");
assertdefined(RetriveInstr)
llvm::Value* value = state->Builder.CreateCall(RetriveInstr,address,"retrivedval");
assertdefined(value)
return value;
}
return state->cache.at(address)->getValue(state);
}
void DataConsumerNode::SaveStack(std::shared_ptr<codegenState> state, bool cleargeninfo) {
for(std::shared_ptr<DataSourceNode>& item : state->stack) {
StackPushNode pusher(item->getValue(state));
pusher.CodeGen(state);
}
if (cleargeninfo) {
state->stack.clear();
state->cache.clear();
}
}
void StackPushNode::CodeGen(std::shared_ptr<codegenState> state){
if (this->Codegened) return; //only codegen once
llvm::Function* PushInstr = state->TheModule->getFunction("PushInstr");
state->Builder.CreateCall(PushInstr, this->value);
this->Codegened = true;
}
llvm::Value* RegisterPushNode::getValue(std::shared_ptr<codegenState> state) {
llvm::Value* result = this->value;
assertdefined(result)
return result;
}
llvm::Value* StackPopNode::createPopNode(std::shared_ptr<codegenState> state) {
llvm::Function* PopInstr = state->TheModule->getFunction("PopInstr");
llvm::Value* result = state->Builder.CreateCall(PopInstr,"popedval");
assertdefined(result)
return result;
}