Skip to content

Commit

Permalink
WIP: refactoring dep resolver
Browse files Browse the repository at this point in the history
  • Loading branch information
examon committed Oct 30, 2018
1 parent 1803ea4 commit 761f317
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 16 deletions.
25 changes: 17 additions & 8 deletions apex/apex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<CallInst>(I)) {
Expand Down Expand Up @@ -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<CallInst>(apex_node.value)) {
CallInst *node_inst = cast<CallInst>(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.
}
}
}
Expand All @@ -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<LLVMNode *> data_dependencies;
std::vector<LLVMNode *> 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<CallInst>(dd->getValue())) {
logPrint("dd is call!");
}
}
// logPrint(" - @I reverse data dependencies: ");
// for (auto &rdd : rev_data_dependencies) {
// rdd->getValue()->dump();
// }
}
}

Expand Down
16 changes: 8 additions & 8 deletions c-code/test_dependencies_minimal.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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;
Expand Down

0 comments on commit 761f317

Please sign in to comment.