31 IR2Vec::VocabTy &vocabulary;
32 IR2Vec::Vector pgmVector;
33 unsigned dataMissCounter;
34 unsigned cyclicCounter;
36 llvm::SmallDenseMap<llvm::StringRef, unsigned> memWriteOps;
37 llvm::SmallDenseMap<const llvm::Instruction *, bool> livelinessMap;
38 llvm::SmallDenseMap<llvm::StringRef, unsigned> memAccessOps;
40 llvm::SmallMapVector<const llvm::Instruction *, IR2Vec::Vector, 128>
42 llvm::SmallMapVector<const llvm::BasicBlock *, IR2Vec::Vector, 16> bbVecMap;
43 llvm::SmallMapVector<const llvm::Function *, IR2Vec::Vector, 16> funcVecMap;
45 llvm::SmallMapVector<
const llvm::Function *,
46 llvm::SmallVector<const llvm::Function *, 10>, 16>
49 llvm::SmallMapVector<
const llvm::Instruction *,
50 llvm::SmallVector<const llvm::Instruction *, 10>, 16>
53 llvm::SmallMapVector<
const llvm::Instruction *,
54 llvm::SmallVector<const llvm::Instruction *, 10>, 16>
58 llvm::SmallMapVector<
const llvm::Instruction *,
59 llvm::SmallVector<const llvm::Instruction *, 10>, 16>
60 reverseReachingDefsMap;
62 llvm::SmallVector<const llvm::Instruction *, 20> instSolvedBySolver;
64 llvm::SmallVector<llvm::SmallVector<const llvm::Instruction *, 10>, 10>
67 llvm::SmallMapVector<
const llvm::Instruction *,
68 llvm::SmallVector<llvm::Instruction *, 16>, 16>
71 std::map<int, std::vector<int>> SCCAdjList;
75 IR2Vec::Vector getValue(std::string key);
76 void collectWriteDefsMap(llvm::Module &M);
77 void getTransitiveUse(
78 const llvm::Instruction *root,
const llvm::Instruction *def,
79 llvm::SmallVector<const llvm::Instruction *, 100> &visitedList,
80 llvm::SmallVector<const llvm::Instruction *, 10> toAppend = {});
81 llvm::SmallVector<const llvm::Instruction *, 10>
82 getReachingDefs(
const llvm::Instruction *,
unsigned i);
84 void solveSingleComponent(
85 const llvm::Instruction &I,
86 llvm::SmallMapVector<const llvm::Instruction *, IR2Vec::Vector, 16>
88 void getPartialVec(
const llvm::Instruction &I,
89 llvm::SmallMapVector<
const llvm::Instruction *,
90 IR2Vec::Vector, 16> &instValMap);
92 void solveInsts(llvm::SmallMapVector<
const llvm::Instruction *,
93 IR2Vec::Vector, 16> &instValMap);
94 std::vector<int> topoOrder(
int size);
96 void topoDFS(
int vertex, std::vector<bool> &Visited,
97 std::vector<int> &visitStack);
99 void inst2Vec(
const llvm::Instruction &I,
100 llvm::SmallVector<llvm::Function *, 15> &funcStack,
101 llvm::SmallMapVector<
const llvm::Instruction *, IR2Vec::Vector,
103 void traverseRD(
const llvm::Instruction *inst,
104 std::unordered_map<const llvm::Instruction *, bool> &Visited,
105 llvm::SmallVector<const llvm::Instruction *, 10> &timeStack);
107 void DFSUtil(
const llvm::Instruction *inst,
108 std::unordered_map<const llvm::Instruction *, bool> &Visited,
109 llvm::SmallVector<const llvm::Instruction *, 10> &set);
111 void bb2Vec(llvm::BasicBlock &B,
112 llvm::SmallVector<llvm::Function *, 15> &funcStack);
113 IR2Vec::Vector func2Vec(llvm::Function &F,
114 llvm::SmallVector<llvm::Function *, 15> &funcStack);
116 bool isMemOp(llvm::StringRef opcode,
unsigned &operand,
117 llvm::SmallDenseMap<llvm::StringRef, unsigned> map);
118 std::string splitAndPipeFunctionName(std::string s);
120 void TransitiveReads(llvm::SmallVector<llvm::Instruction *, 16> &Killlist,
121 llvm::Instruction *Inst, llvm::BasicBlock *ParentBB);
122 llvm::SmallVector<llvm::Instruction *, 16>
123 createKilllist(llvm::Instruction *Arg, llvm::Instruction *writeInst);
126 void print(IR2Vec::Vector t,
unsigned pos) { llvm::outs() << t[pos]; }
128 void updateFuncVecMap(
129 llvm::Function *function,
130 llvm::SmallSet<const llvm::Function *, 16> &visitedFunctions);
132 void updateFuncVecMapWithCallee(
const llvm::Function *function);
135 IR2Vec_FA(llvm::Module &M, IR2Vec::VocabTy &vocab) : M{M}, vocabulary{vocab} {
137 pgmVector = IR2Vec::Vector(IR2Vec::DIM, 0);
140 memWriteOps.try_emplace(
"store", 1);
141 memWriteOps.try_emplace(
"cmpxchg", 0);
142 memWriteOps.try_emplace(
"atomicrmw", 0);
144 memAccessOps.try_emplace(
"getelementptr", 0);
145 memAccessOps.try_emplace(
"load", 0);
150 collectWriteDefsMap(M);
152 llvm::CallGraph cg = llvm::CallGraph(M);
154 for (
auto callItr = cg.begin(); callItr != cg.end(); callItr++) {
155 if (callItr->first && !callItr->first->isDeclaration()) {
156 auto ParentFunc = callItr->first;
157 llvm::CallGraphNode *cgn = callItr->second.get();
160 for (
auto It = cgn->begin(); It != cgn->end(); It++) {
162 auto func = It->second->getFunction();
163 if (func && !func->isDeclaration()) {
164 funcCallMap[ParentFunc].push_back(func);
172 void generateFlowAwareEncodings(std::ostream *o =
nullptr,
173 std::ostream *missCount =
nullptr,
174 std::ostream *cyclicCount =
nullptr);
178 void generateFlowAwareEncodingsForFunction(
179 std::ostream *o =
nullptr, std::string name =
"",
180 std::ostream *missCount =
nullptr, std::ostream *cyclicCount =
nullptr);
182 llvm::SmallMapVector<const llvm::Instruction *, IR2Vec::Vector, 128>
187 llvm::SmallMapVector<const llvm::BasicBlock *, IR2Vec::Vector, 16>
192 llvm::SmallMapVector<const llvm::Function *, IR2Vec::Vector, 16>
197 IR2Vec::Vector getProgramVector() {
return pgmVector; }