From 761f3179497616da9463f341c4f1cd26d02803a7 Mon Sep 17 00:00:00 2001 From: Tomas Meszaros Date: Tue, 30 Oct 2018 07:26:22 +0100 Subject: [PATCH] WIP: refactoring dep resolver --- apex/apex.cpp | 25 +++++++++++++++++-------- c-code/test_dependencies_minimal.c | 16 ++++++++-------- 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/apex/apex.cpp b/apex/apex.cpp index db58388..f6ee91c 100644 --- a/apex/apex.cpp +++ b/apex/apex.cpp @@ -50,9 +50,9 @@ bool APEXPass::runOnModule(Module &M) { logPrintUnderline("Dependency resolver: START"); // Investigate each function in @path. - for (auto &fcn : path) { - logPrint("FCN: " + fcn->getGlobalIdentifier()); - for (auto &BB : *fcn) { + for (auto &fcn_in_path : path) { + logPrint("FCN: " + fcn_in_path->getGlobalIdentifier()); + for (auto &BB : *fcn_in_path) { // Go over instructions for each function in @path. for (auto &I : BB) { if (false == isa(I)) { @@ -82,15 +82,16 @@ bool APEXPass::runOnModule(Module &M) { APEXDependencyNode *I_apex = nullptr; for (APEXDependencyFunction apex_fcn : apex_dg.functions) { std::string apex_fcn_name = apex_fcn.value->getName(); - if (apex_fcn_name == fcn->getGlobalIdentifier()) { - + if (apex_fcn_name == fcn_in_path->getGlobalIdentifier()) { for (APEXDependencyNode apex_node : apex_fcn.nodes) { if (true == isa(apex_node.value)) { CallInst *node_inst = cast(apex_node.value); Function *node_called_fcn = node_inst->getCalledFunction(); if (node_called_fcn == called_fcn) { I_apex = &apex_node; - logPrint(" - found @I in @apex_dg"); + logPrintFlat(" - found @I: "); + I_apex->value->dump(); + goto I_FOUND; // Get out of the loops. } } } @@ -101,16 +102,24 @@ bool APEXPass::runOnModule(Module &M) { exit(-1); } + I_FOUND: // Now, check if @I has some data dependencies that are fcn calls. std::vector data_dependencies; std::vector rev_data_dependencies; LLVMNode *I_apex_node = I_apex->node; apexDgFindDataDependencies(apex_dg, *I_apex_node, data_dependencies, rev_data_dependencies); - // TODO: dependencies in vectors look weird/broken. - for (auto &dd : data_dependencies) { + logPrint(" - @I data dependencies: "); + for (LLVMNode *dd : data_dependencies) { dd->getValue()->dump(); + if (true == isa(dd->getValue())) { + logPrint("dd is call!"); + } } + // logPrint(" - @I reverse data dependencies: "); + // for (auto &rdd : rev_data_dependencies) { + // rdd->getValue()->dump(); + // } } } diff --git a/c-code/test_dependencies_minimal.c b/c-code/test_dependencies_minimal.c index d03d5c6..1f66bd9 100644 --- a/c-code/test_dependencies_minimal.c +++ b/c-code/test_dependencies_minimal.c @@ -24,12 +24,12 @@ int y (int n) { // return tmp; //} -//int n(void) { -// printf("n: in\n"); -// int y_ret = y(10); -// printf("n: out\n"); -// return y_ret; -//} +int n(void) { + printf("n: in\n"); + int y_ret = y(10); + printf("n: out\n"); + return y_ret; +} int main(void) { printf("main: in\n"); @@ -41,8 +41,8 @@ int main(void) { // int z_ret = z(); // int z_store = z_ret; -// int n_ret = n(); -// int n_store = n_ret; + int n_ret = n(); + int n_store = n_ret; printf("main: out\n"); return 0;