Skip to content

Commit 72505a5

Browse files
committed
fixes to ir2vec for func ptr changes
1 parent ed6b42b commit 72505a5

3 files changed

Lines changed: 52 additions & 9 deletions

File tree

src/FlowAware.cpp

Lines changed: 47 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -196,41 +196,77 @@ void IR2Vec_FA::generateFlowAwareEncodings(std::ostream *o,
196196
void IR2Vec_FA::updateFuncVecMap(
197197
llvm::Function *function,
198198
llvm::SmallSet<const llvm::Function *, 16> &visitedFunctions) {
199+
200+
if (!function) {
201+
llvm::errs() << "Received a nullptr function, skipping updateFuncVecMap.\n";
202+
return;
203+
}
204+
205+
llvm::errs() << "Processing function: " << function->getName() << "\n";
206+
199207
visitedFunctions.insert(function);
200208
SmallVector<Function *, 15> funcStack;
201209
funcStack.clear();
210+
llvm::errs () << "reaching updateFuncVecMap?" << "\n";
211+
202212
auto tmpParent = func2Vec(*function, funcStack);
213+
214+
llvm::errs () << "is there any issue in creating the func2Vec embeddings?" << "\n";
203215
// funcVecMap is updated with vectors returned by func2Vec
216+
217+
llvm::errs () << "what is tmpParent here?" << "\n";
218+
for(auto v:tmpParent){
219+
llvm::errs () << v<< ",";
220+
}
221+
llvm::errs () << "\n";
204222
funcVecMap[function] = tmpParent;
205223
auto calledFunctions = funcCallMap[function];
224+
225+
llvm::errs () << "vector of calledFunctions: " << "\n";
226+
for(auto x:calledFunctions){
227+
llvm::errs () << x<< ",";
228+
}
229+
llvm::errs () << "\n";
230+
231+
if(calledFunctions.empty()) return;
232+
206233
for (auto &calledFunction : calledFunctions) {
207234
if (calledFunction && !calledFunction->isDeclaration() &&
208235
visitedFunctions.count(calledFunction) == 0) {
209236
// doing casting since calledFunctions is of type of const
210237
// llvm::Function* and we need llvm::Function* as argument
211238
auto *callee = const_cast<Function *>(calledFunction);
212239
// This function is called recursively to update funcVecMap
240+
llvm::errs() << "Calling updateFuncVecMap for function: " << callee->getName() << "\n";
213241
updateFuncVecMap(callee, visitedFunctions);
214242
}
215243
}
244+
llvm::errs () << "is it coming out of this loop in updateFVM?" << "\n";
216245
}
217246

218247
void IR2Vec_FA::generateFlowAwareEncodingsForFunction(
219248
std::ostream *o, llvm::Function *FuncPtr, std::string funcName,
220249
std::ostream *missCount, std::ostream *cyclicCount) {
221-
250+
llvm::errs () << "able to enter genFAforFunc" << "\n";
222251
int noOfFunc = 0;
223252
for (auto &f : M) {
224-
253+
llvm::errs () << "before getActualName" << "\n";
225254
auto Result = getActualName(&f);
226-
if (!f.isDeclaration() && ((FuncPtr && &f == FuncPtr) ||
227-
(!funcName.empty() && Result == funcName))) {
255+
llvm::errs () << "what is Result here? "<< "\n";
256+
257+
// if (!f.isDeclaration() && ((FuncPtr && &f == FuncPtr) ||
258+
// (!funcName.empty() && Result == funcName))) {
259+
if (!f.isDeclaration() && ((FuncPtr && &f == FuncPtr))){
228260
// If funcName is matched with one of the functions in module, we
229261
// will update funcVecMap of it and it's child functions recursively
262+
llvm::errs () << "able to get a match for the fucn name and ptr" << "\n";
230263
llvm::SmallSet<const Function *, 16> visitedFunctions;
231264
updateFuncVecMap(&f, visitedFunctions);
265+
llvm:errs () << "just after updateFuncVecMap" << "\n";
232266
}
233267
}
268+
269+
llvm::errs () << "is it going out of the loop1?" << "\n";
234270
// iterating over all functions in module instead of funcVecMap to preserve
235271
// order
236272
for (auto &f : M) {
@@ -240,10 +276,15 @@ void IR2Vec_FA::generateFlowAwareEncodingsForFunction(
240276
}
241277
}
242278

279+
llvm::errs () << "is it coming out of loop2?" << "\n";
280+
243281
for (auto &f : M) {
244282
auto Result = getActualName(&f);
245-
if (!f.isDeclaration() && ((FuncPtr && &f == FuncPtr) ||
246-
(!funcName.empty() && Result == funcName))) {
283+
// if (!f.isDeclaration() && ((FuncPtr && &f == FuncPtr) ||
284+
// (!funcName.empty() && Result == funcName))) {
285+
286+
if (!f.isDeclaration() && ((FuncPtr && &f == FuncPtr))){
287+
llvm::errs () << "able to get a match for the fucn name and ptr part2" << "\n";
247288
Vector tmp;
248289
SmallVector<Function *, 15> funcStack;
249290
tmp = funcVecMap[&f];

src/Symbolic.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,9 @@ void IR2Vec_Symbolic::generateSymbolicEncodingsForFunction(
8686
llvm::errs() << "inside the correct generateSymbolicEncodingsForFunction\n";
8787
for (auto &f : M) {
8888
auto Result = getActualName(&f);
89-
if (!f.isDeclaration() && ((FuncPtr && &f == FuncPtr) ||
90-
(!funcName.empty() && Result == funcName))) {
89+
// if (!f.isDeclaration() && ((FuncPtr && &f == FuncPtr) ||
90+
// (!funcName.empty() && Result == funcName))) {
91+
if (!f.isDeclaration() && ((FuncPtr && &f == FuncPtr))){
9192
llvm::errs() << "is not match happening in the if condition?"
9293
<< "\n";
9394
Vector tmp;

src/libIR2Vec.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@ int IR2Vec::Embeddings::generateEncodings(llvm::Module &M,
3737

3838
if (mode == IR2Vec::IR2VecMode::FlowAware) {
3939
IR2Vec_FA FA(M, vocabulary);
40-
40+
llvm::errs () << "going inside the FA logic" << "\n";
4141
if (FuncPtr || !funcName.empty()) {
42+
llvm::errs () << "able to get the function, so entering FA for function generation" << "\n";
4243
FA.generateFlowAwareEncodingsForFunction(o, FuncPtr, funcName);
4344
} else {
4445
FA.generateFlowAwareEncodings(o);

0 commit comments

Comments
 (0)