31 IR2Vec::Vector pgmVector;
32 unsigned dataMissCounter;
33 unsigned cyclicCounter;
35 llvm::SmallDenseMap<llvm::StringRef, unsigned> memWriteOps;
36 llvm::SmallDenseMap<const llvm::Instruction *, bool> livelinessMap;
37 llvm::SmallDenseMap<llvm::StringRef, unsigned> memAccessOps;
39 llvm::SmallMapVector<const llvm::Instruction *, IR2Vec::Vector, 128>
41 llvm::SmallMapVector<const llvm::Function *, IR2Vec::Vector, 16> funcVecMap;
43 llvm::SmallMapVector<
const llvm::Function *,
44 llvm::SmallVector<const llvm::Function *, 10>, 16>
47 llvm::SmallMapVector<
const llvm::Instruction *,
48 llvm::SmallVector<const llvm::Instruction *, 10>, 16>
51 llvm::SmallMapVector<
const llvm::Instruction *,
52 llvm::SmallVector<const llvm::Instruction *, 10>, 16>
56 llvm::SmallMapVector<
const llvm::Instruction *,
57 llvm::SmallVector<const llvm::Instruction *, 10>, 16>
58 reverseReachingDefsMap;
60 llvm::SmallVector<const llvm::Instruction *, 20> instSolvedBySolver;
62 llvm::SmallVector<llvm::SmallVector<const llvm::Instruction *, 10>, 10>
65 llvm::SmallMapVector<
const llvm::Instruction *,
66 llvm::SmallVector<llvm::Instruction *, 16>, 16>
69 std::map<int, std::vector<int>> SCCAdjList;
73 IR2Vec::Vector getValue(std::string key);
74 void collectWriteDefsMap(llvm::Module &M);
75 void getTransitiveUse(
76 const llvm::Instruction *root,
const llvm::Instruction *def,
77 llvm::SmallVector<const llvm::Instruction *, 100> &visitedList,
78 llvm::SmallVector<const llvm::Instruction *, 10> toAppend = {});
79 llvm::SmallVector<const llvm::Instruction *, 10>
80 getReachingDefs(
const llvm::Instruction *,
unsigned i);
82 void solveSingleComponent(
83 const llvm::Instruction &I,
84 llvm::SmallMapVector<const llvm::Instruction *, IR2Vec::Vector, 16>
86 void getPartialVec(
const llvm::Instruction &I,
87 llvm::SmallMapVector<
const llvm::Instruction *,
88 IR2Vec::Vector, 16> &instValMap);
90 void solveInsts(llvm::SmallMapVector<
const llvm::Instruction *,
91 IR2Vec::Vector, 16> &instValMap);
92 std::vector<int> topoOrder(
int size);
94 void topoDFS(
int vertex, std::vector<bool> &Visited,
95 std::vector<int> &visitStack);
97 void inst2Vec(
const llvm::Instruction &I,
98 llvm::SmallVector<llvm::Function *, 15> &funcStack,
99 llvm::SmallMapVector<
const llvm::Instruction *, IR2Vec::Vector,
101 void traverseRD(
const llvm::Instruction *inst,
102 std::unordered_map<const llvm::Instruction *, bool> &Visited,
103 llvm::SmallVector<const llvm::Instruction *, 10> &timeStack);
105 void DFSUtil(
const llvm::Instruction *inst,
106 std::unordered_map<const llvm::Instruction *, bool> &Visited,
107 llvm::SmallVector<const llvm::Instruction *, 10> &set);
109 void bb2Vec(llvm::BasicBlock &B,
110 llvm::SmallVector<llvm::Function *, 15> &funcStack);
111 IR2Vec::Vector func2Vec(llvm::Function &F,
112 llvm::SmallVector<llvm::Function *, 15> &funcStack);
114 bool isMemOp(llvm::StringRef opcode,
unsigned &operand,
115 llvm::SmallDenseMap<llvm::StringRef, unsigned> map);
116 std::string splitAndPipeFunctionName(std::string s);
118 void TransitiveReads(llvm::SmallVector<llvm::Instruction *, 16> &Killlist,
119 llvm::Instruction *Inst, llvm::BasicBlock *ParentBB);
120 llvm::SmallVector<llvm::Instruction *, 16>
121 createKilllist(llvm::Instruction *Arg, llvm::Instruction *writeInst);
124 void print(IR2Vec::Vector t,
unsigned pos) { llvm::outs() << t[pos]; }
126 void updateFuncVecMap(
127 llvm::Function *function,
128 llvm::SmallSet<const llvm::Function *, 16> &visitedFunctions);
130 void updateFuncVecMapWithCallee(
const llvm::Function *function);
135 pgmVector = IR2Vec::Vector(DIM, 0);
138 memWriteOps.try_emplace(
"store", 1);
139 memWriteOps.try_emplace(
"cmpxchg", 0);
140 memWriteOps.try_emplace(
"atomicrmw", 0);
142 memAccessOps.try_emplace(
"getelementptr", 0);
143 memAccessOps.try_emplace(
"load", 0);
148 collectWriteDefsMap(M);
150 llvm::CallGraph cg = llvm::CallGraph(M);
152 for (
auto callItr = cg.begin(); callItr != cg.end(); callItr++) {
153 if (callItr->first && !callItr->first->isDeclaration()) {
154 auto ParentFunc = callItr->first;
155 llvm::CallGraphNode *cgn = callItr->second.get();
158 for (
auto It = cgn->begin(); It != cgn->end(); It++) {
160 auto func = It->second->getFunction();
161 if (func && !func->isDeclaration()) {
162 funcCallMap[ParentFunc].push_back(func);
170 void generateFlowAwareEncodings(std::ostream *o =
nullptr,
171 std::ostream *missCount =
nullptr,
172 std::ostream *cyclicCount =
nullptr);
176 void generateFlowAwareEncodingsForFunction(
177 std::ostream *o =
nullptr, std::string name =
"",
178 std::ostream *missCount =
nullptr, std::ostream *cyclicCount =
nullptr);
180 llvm::SmallMapVector<const llvm::Instruction *, IR2Vec::Vector, 128>
185 llvm::SmallMapVector<const llvm::Function *, IR2Vec::Vector, 16>
190 IR2Vec::Vector getProgramVector() {
return pgmVector; }