From 90fb0bf6b97b31df0db87cb5f13e331bd2dfd647 Mon Sep 17 00:00:00 2001 From: ALEXks Date: Sun, 5 Nov 2023 13:08:57 +0300 Subject: [PATCH] added refactoring of FuncInfo, fixed ACC_ROUTINE inserting --- .../experts/Sapfor_2017/_src/CFGraph/IR.cpp | 12 +- .../_src/CreateInterTree/CreateInterTree.cpp | 3 +- .../_src/DirectiveProcessing/shadow.cpp | 5 +- .../_src/DvmhRegions/DvmhRegionInserter.cpp | 116 ++++++++++++++---- .../_src/DvmhRegions/DvmhRegionInserter.h | 2 +- .../_src/GraphCall/graph_calls.cpp | 66 +++++----- .../Sapfor_2017/_src/GraphCall/graph_calls.h | 21 +++- .../_src/GraphCall/graph_calls_base.cpp | 18 +-- .../Sapfor_2017/_src/Inliner/inliner.cpp | 6 +- .../_src/LoopAnalyzer/loop_analyzer.cpp | 10 +- .../resolve_par_reg_conflicts.cpp | 8 +- sapfor/experts/Sapfor_2017/_src/Sapfor.cpp | 12 +- .../_src/Transformations/checkpoints.cpp | 3 +- .../Transformations/function_purifying.cpp | 9 +- .../Transformations/uniq_call_chain_dup.cpp | 17 +-- .../Sapfor_2017/_src/Utils/SgUtils.cpp | 3 +- .../experts/Sapfor_2017/_src/Utils/version.h | 2 +- .../_src/VisualizerCalls/BuildGraph.cpp | 10 +- 18 files changed, 214 insertions(+), 109 deletions(-) diff --git a/sapfor/experts/Sapfor_2017/_src/CFGraph/IR.cpp b/sapfor/experts/Sapfor_2017/_src/CFGraph/IR.cpp index a691586..164ce48 100644 --- a/sapfor/experts/Sapfor_2017/_src/CFGraph/IR.cpp +++ b/sapfor/experts/Sapfor_2017/_src/CFGraph/IR.cpp @@ -490,9 +490,9 @@ static SAPFOR::Argument* processExpression(SgExpression* ex, vector& printInternalError(convertFileName(__FILE__).c_str(), __LINE__); string callName = "_ERROR_"; - for (int z = 0; z < func->pointerDetailCallsFrom.size() && callName == "_ERROR_"; ++z) - if (func->pointerDetailCallsFrom[z].first == ex) - callName = func->detailCallsFrom[z].first; + for (int z = 0; z < func->callsFromDetailed.size() && callName == "_ERROR_"; ++z) + if (func->callsFromDetailed[z].pointerDetailCallsFrom.first == ex) + callName = func->callsFromDetailed[z].detailCallsFrom.first; SAPFOR::Argument* fArg = getFuncArg(callName); @@ -1094,9 +1094,9 @@ static SgStatement* processStatement(SgStatement* st, vector& blocks, bool hasLabelArgs = processArgs(call, call->numberOfArgs(), blocks, func, commonVars, &labelsOfArgs); string callName = "_ERROR_"; - for (int z = 0; z < func->pointerDetailCallsFrom.size() && callName == "_ERROR_"; ++z) - if (func->pointerDetailCallsFrom[z].first == st) - callName = func->detailCallsFrom[z].first; + for (int z = 0; z < func->callsFromDetailed.size() && callName == "_ERROR_"; ++z) + if (func->callsFromDetailed[z].pointerDetailCallsFrom.first == st) + callName = func->callsFromDetailed[z].detailCallsFrom.first; SAPFOR::Argument* fArg = getFuncArg(callName); diff --git a/sapfor/experts/Sapfor_2017/_src/CreateInterTree/CreateInterTree.cpp b/sapfor/experts/Sapfor_2017/_src/CreateInterTree/CreateInterTree.cpp index 66549c3..2699766 100644 --- a/sapfor/experts/Sapfor_2017/_src/CreateInterTree/CreateInterTree.cpp +++ b/sapfor/experts/Sapfor_2017/_src/CreateInterTree/CreateInterTree.cpp @@ -846,8 +846,9 @@ void uniteIntervalsBetweenProcCalls(map> &intervals { if (SgFile::switchToFile(callsTo->fileName) == -1) printInternalError(convertFileName(__FILE__).c_str(), __LINE__); - for (auto &callsFrom : callsTo->pointerDetailCallsFrom) + for (auto &callsInfo: callsTo->callsFromDetailed) { + auto& callsFrom = callsInfo.pointerDetailCallsFrom; SgStatement *base = NULL; if (callsFrom.second == PROC_STAT) { diff --git a/sapfor/experts/Sapfor_2017/_src/DirectiveProcessing/shadow.cpp b/sapfor/experts/Sapfor_2017/_src/DirectiveProcessing/shadow.cpp index 6be8896..aa895da 100644 --- a/sapfor/experts/Sapfor_2017/_src/DirectiveProcessing/shadow.cpp +++ b/sapfor/experts/Sapfor_2017/_src/DirectiveProcessing/shadow.cpp @@ -1631,8 +1631,11 @@ void GroupShadow(const map>& allFuncs, for (auto& elem : byFile.second) { mapF[elem->funcName] = elem; - for (auto& call : elem->detailCallsFrom) + for (auto& callInfo : elem->callsFromDetailed) + { + auto& call = callInfo.detailCallsFrom; mapCallsF[elem->fileName][call.second].insert(call.first); + } } map> callDeps; diff --git a/sapfor/experts/Sapfor_2017/_src/DvmhRegions/DvmhRegionInserter.cpp b/sapfor/experts/Sapfor_2017/_src/DvmhRegions/DvmhRegionInserter.cpp index dce7b0e..42c6d60 100644 --- a/sapfor/experts/Sapfor_2017/_src/DvmhRegions/DvmhRegionInserter.cpp +++ b/sapfor/experts/Sapfor_2017/_src/DvmhRegions/DvmhRegionInserter.cpp @@ -877,6 +877,34 @@ ArraySet DvmhRegionInserter::get_used_arrs_for_block(SgStatement* st, int usage_ return usages; } +static bool filterFromList(SgStatement* st, const set& idents, bool exclude = false) +{ + bool empty = false; + SgExpression* list = st->expr(0); + vector newList; + while (list) + { + if (exclude) + { + if (idents.find(list->lhs()->symbol()->identifier()) == idents.end()) + newList.push_back(list->lhs()); + } + else + { + if (idents.find(list->lhs()->symbol()->identifier()) != idents.end()) + newList.push_back(list->lhs()); + } + list = list->rhs(); + } + + if (newList.size() == 0) + empty = true; + else + st->setExpression(0, makeExprList(newList)); + + return empty; +} + static string getInterfaceBlock(SgStatement* func, const FuncParam& pars) { string oldFile = current_file->filename(); @@ -884,8 +912,7 @@ static string getInterfaceBlock(SgStatement* func, const FuncParam& pars) printInternalError(convertFileName(__FILE__).c_str(), __LINE__); auto copy = duplicateProcedure(func, NULL, false, false, false, true); - - const set ident(pars.identificators.begin(), pars.identificators.end()); + const set idents(pars.identificators.begin(), pars.identificators.end()); //remove all exec SgStatement* st = copy->lexNext(); @@ -925,26 +952,16 @@ static string getInterfaceBlock(SgStatement* func, const FuncParam& pars) || st->variant() == DIM_STAT || st->variant() == INTENT_STMT) { - SgExpression* list = st->expr(0); - vector newList; - while (list) - { - if (ident.find(list->lhs()->symbol()->identifier()) != ident.end()) - newList.push_back(list->lhs()); - list = list->rhs(); - } - - if (newList.size() == 0) + bool empty = filterFromList(st, idents); + if (empty) { SgStatement* next = st->lexNext(); toExtract.push_back(st); st = next; continue; } - else - st->setExpression(0, makeExprList(newList)); } - else + else if (!isDVM_stat(st) && !isSPF_stat(st)) toExtract.push_back(st); if (st->variant() == CONTAINS_STMT) @@ -963,7 +980,7 @@ static string getInterfaceBlock(SgStatement* func, const FuncParam& pars) return retVal; } -static void insertInterface(SgStatement* func, const string& iface) +static void insertInterface(SgStatement* func, const string& iface, const string& fName) { string oldFile = current_file->filename(); if (!func->switchToFile()) @@ -973,6 +990,18 @@ static void insertInterface(SgStatement* func, const string& iface) SgStatement* last = func->lastNodeOfStmt(); while (st != last) { + if (st->variant() == VAR_DECL || st->variant() == VAR_DECL_90) + { + bool empty = filterFromList(st, { fName }, true); + if (empty) + { + SgStatement* next = st->lexNext(); + st->extractStmt(); + st = next; + continue; + } + } + if (isSgExecutableStatement(st)) break; st = st->lexNext(); @@ -1033,21 +1062,57 @@ static bool isPure(SgStatement* func) return retVal; } -void DvmhRegionInserter::createInterfaceBlock() +void DvmhRegionInserter::createInterfaceBlockForParallelFunctions() { for (auto& parF : parallel_functions) { for (auto& callTo : parF->callsTo) { - if (callTo->fileName != parF->fileName) + if (callTo->fileName != parF->fileName && isPure(parF->funcPointer->GetOriginal())) { - if (callTo->interfaceBlocks.find(parF->funcName) == callTo->interfaceBlocks.end() - && parF->funcParams.countOfPars > 0 - && isPure(parF->funcPointer->GetOriginal())) + insertRoutine(parF->funcPointer->GetOriginal()); + auto it = callTo->interfaceBlocks.find(parF->funcName); + if (it == callTo->interfaceBlocks.end()) { - insertRoutine(parF->funcPointer->GetOriginal()); - callTo->interfaceBlocks[parF->funcName] = parF; - insertInterface(callTo->funcPointer, getInterfaceBlock(parF->funcPointer->GetOriginal(), parF->funcParams)); + callTo->interfaceBlocks[parF->funcName] = NULL; + insertInterface(callTo->funcPointer, getInterfaceBlock(parF->funcPointer->GetOriginal(), parF->funcParams), parF->funcName); + } + else if (it->second) // interface not inserted as comment + { + SgStatement* st = callTo->funcPointer->GetOriginal(); + + string oldFile = current_file->filename(); + if (!st->switchToFile()) + printInternalError(convertFileName(__FILE__).c_str(), __LINE__); + + SgStatement* last = st->lastNodeOfStmt(); + SgStatement* iface = NULL; + + st = st->lexNext(); + while (st != last) + { + if (st->variant() == FUNC_HEDR || st->variant() == PROC_HEDR) + { + if (st->controlParent()->variant() == INTERFACE_STMT && + st->symbol()->identifier() == parF->funcName) + { + iface = st; + insertRoutine(iface); + break; + } + } + + if (st->variant() == CONTAINS_STMT) + break; + if (isSgExecutableStatement(st)) + break; + st = st->lexNext(); + } + + checkNull(iface, convertFileName(__FILE__).c_str(), __LINE__); + + if (SgFile::switchToFile(oldFile) == -1) + printInternalError(convertFileName(__FILE__).c_str(), __LINE__); } } } @@ -1059,14 +1124,13 @@ void DvmhRegionInserter::createInterfaceBlockForOutCalls(FuncInfo* func) for (auto& callFrom : func->callsFromV) { if (func->interfaceBlocks.find(callFrom->funcName) == func->interfaceBlocks.end() - && callFrom->funcParams.countOfPars > 0 && isPure(callFrom->funcPointer->GetOriginal())) { if (callFrom->fileName != func->fileName) insertRoutine(func->funcPointer->GetOriginal()); func->interfaceBlocks[callFrom->funcName] = callFrom; - insertInterface(func->funcPointer, getInterfaceBlock(callFrom->funcPointer->GetOriginal(), callFrom->funcParams)); + insertInterface(func->funcPointer, getInterfaceBlock(callFrom->funcPointer->GetOriginal(), callFrom->funcParams), callFrom->funcName); } } } diff --git a/sapfor/experts/Sapfor_2017/_src/DvmhRegions/DvmhRegionInserter.h b/sapfor/experts/Sapfor_2017/_src/DvmhRegions/DvmhRegionInserter.h index d6abf3e..bbc60b9 100644 --- a/sapfor/experts/Sapfor_2017/_src/DvmhRegions/DvmhRegionInserter.h +++ b/sapfor/experts/Sapfor_2017/_src/DvmhRegions/DvmhRegionInserter.h @@ -76,7 +76,7 @@ public: void insertActualDirectives(const std::vector* regs); void updateParallelFunctions(const std::map>& loopGraphs); - void createInterfaceBlock(); + void createInterfaceBlockForParallelFunctions(); void removePrivatesFromParallelLoops(); void addPrivatesToParallelLoops(); void addUsedArrays(std::set& arrays); diff --git a/sapfor/experts/Sapfor_2017/_src/GraphCall/graph_calls.cpp b/sapfor/experts/Sapfor_2017/_src/GraphCall/graph_calls.cpp index 000eb77..a9690cb 100644 --- a/sapfor/experts/Sapfor_2017/_src/GraphCall/graph_calls.cpp +++ b/sapfor/experts/Sapfor_2017/_src/GraphCall/graph_calls.cpp @@ -357,12 +357,15 @@ static void findFuncCalls(SgStatement *parent, SgExpression *curr, vectorcallsFrom.insert(nameOfCallFunc.begin(), nameOfCallFunc.end()); - proc->detailCallsFrom.push_back(make_pair(nameOfCallFunc[1], line)); // original name of call - proc->pointerDetailCallsFrom.push_back(make_pair(curr, FUNC_CALL)); - proc->parentForPointer.push_back(parent); - proc->actualParams.push_back(FuncParam()); - processActualParams(curr->lhs(), commonBlocks, proc->actualParams.back(), proc->externalCalls); + FuncInfoCallFrom newCall; + newCall.detailCallsFrom = make_pair(nameOfCallFunc[1], line); // original name of call + newCall.pointerDetailCallsFrom = make_pair(curr, FUNC_CALL); + newCall.parentForPointer = parent; + newCall.actualParams = FuncParam(); + + processActualParams(curr->lhs(), commonBlocks, newCall.actualParams, proc->externalCalls); + proc->callsFromDetailed.push_back(newCall); } } @@ -1115,13 +1118,15 @@ void functionAnalyzer(SgFile *file, map> &allFuncInfo, continue; proc->callsFrom.insert(pureNameOfCallFunc.begin(), pureNameOfCallFunc.end()); - proc->detailCallsFrom.push_back(make_pair(pureNameOfCallFunc[1], st->lineNumber())); // original name of call - proc->pointerDetailCallsFrom.push_back(make_pair(st, PROC_STAT)); - proc->parentForPointer.push_back(st); - proc->actualParams.push_back(FuncParam()); + FuncInfoCallFrom newCall; + newCall.detailCallsFrom = make_pair(pureNameOfCallFunc[1], st->lineNumber()); // original name of call + newCall.pointerDetailCallsFrom = make_pair(st, PROC_STAT); + newCall.parentForPointer = st; + newCall.actualParams = FuncParam(); - processActualParams(st->expr(0), commonBlocks, proc->actualParams.back(), proc->externalCalls); + processActualParams(st->expr(0), commonBlocks, newCall.actualParams, proc->externalCalls); + proc->callsFromDetailed.push_back(newCall); // Add func call which we've just found NestedFuncCall funcCall(pureNameOfCallFunc[1]); @@ -1150,11 +1155,14 @@ void functionAnalyzer(SgFile *file, map> &allFuncInfo, correctNameIfContains(NULL, curr, elem, containsFunctions, prefix); proc->callsFrom.insert(nameOfCallFunc.begin(), nameOfCallFunc.end()); - proc->detailCallsFrom.push_back(make_pair(nameOfCallFunc[1], st->lineNumber())); // original name of call - proc->pointerDetailCallsFrom.push_back(make_pair(curr, VAR_REF)); - proc->parentForPointer.push_back(st); - proc->actualParams.push_back(FuncParam()); + FuncInfoCallFrom newCall; + newCall.detailCallsFrom = make_pair(nameOfCallFunc[1], st->lineNumber()); // original name of call + newCall.pointerDetailCallsFrom = make_pair(curr, VAR_REF); + newCall.parentForPointer = st; + newCall.actualParams = FuncParam(); + + proc->callsFromDetailed.push_back(newCall); } } } @@ -1371,11 +1379,11 @@ static bool matchCallAndDefinition(SgProject* proj, const map& file for (auto& callsTo : currF->callsTo) { - for (int cf = 0; cf < callsTo->detailCallsFrom.size(); ++cf) + for (int cf = 0; cf < callsTo->callsFromDetailed.size(); ++cf) { - if (callsTo->detailCallsFrom[cf].first == currF->funcName) + if (callsTo->callsFromDetailed[cf].detailCallsFrom.first == currF->funcName) { - auto callInfo = callsTo->pointerDetailCallsFrom[cf]; + auto callInfo = callsTo->callsFromDetailed[cf].pointerDetailCallsFrom; if (callInfo.second == VAR_REF) // external call through proc parameter continue; @@ -1383,8 +1391,8 @@ static bool matchCallAndDefinition(SgProject* proj, const map& file if (itF == files.end()) printInternalError(convertFileName(__FILE__).c_str(), __LINE__); - bool localR = matchCallAndDefinition(currF->funcParams, callsTo->actualParams[cf], currF->funcName, - callsTo->fileName, callsTo->detailCallsFrom[cf].second, messages); + bool localR = matchCallAndDefinition(currF->funcParams, callsTo->callsFromDetailed[cf].actualParams, currF->funcName, + callsTo->fileName, callsTo->callsFromDetailed[cf].detailCallsFrom.second, messages); if (!localR) count++; } @@ -2256,8 +2264,9 @@ void propagateWritesToArrays(map> &allFuncInfo) if (!ok) printInternalError(convertFileName(__FILE__).c_str(), __LINE__); - for (auto &callFrom : callsTo->pointerDetailCallsFrom) + for (auto &callFromInfo : callsTo->callsFromDetailed) { + auto& callFrom = callFromInfo.pointerDetailCallsFrom; if (callFrom.second == VAR_REF) // pass procedure through parameter continue; @@ -2429,8 +2438,9 @@ int getLvlCall(FuncInfo* currF, int lvl, const string& func, const string& file, if (currF->funcName == func) return 0; - for (auto& callsFrom : currF->detailCallsFrom) + for (auto& callsFromInfo : currF->callsFromDetailed) { + auto& callsFrom = callsFromInfo.detailCallsFrom; if (callsFrom.first == func && callsFrom.second == line && currF->fileName == file) return lvl; } @@ -2465,12 +2475,12 @@ void setInlineAttributeToCalls(const map& allFunctions, if (itNeed != inDataChains.end()) needToInline = itNeed->second; - for (int k = 0; k < curr->detailCallsFrom.size(); ++k) + for (int k = 0; k < curr->callsFromDetailed.size(); ++k) { - if (needToInline.find(curr->detailCallsFrom[k]) == needToInline.end() && - !isIntrinsicFunctionName(curr->detailCallsFrom[k].first.c_str())) + if (needToInline.find(curr->callsFromDetailed[k].detailCallsFrom) == needToInline.end() && + !isIntrinsicFunctionName(curr->callsFromDetailed[k].detailCallsFrom.first.c_str())) { - pair detail = curr->pointerDetailCallsFrom[k]; + pair detail = curr->callsFromDetailed[k].pointerDetailCallsFrom; if (SgFile::switchToFile(curr->fileName) == -1) printInternalError(convertFileName(__FILE__).c_str(), __LINE__); @@ -2480,7 +2490,7 @@ void setInlineAttributeToCalls(const map& allFunctions, else if (detail.second == FUNC_CALL) { //TODO: many functions in same statement - SgStatement* callSt = SgStatement::getStatementByFileAndLine(curr->fileName, curr->detailCallsFrom[k].second); + SgStatement* callSt = SgStatement::getStatementByFileAndLine(curr->fileName, curr->callsFromDetailed[k].detailCallsFrom.second); if (!callSt) printInternalError(convertFileName(__FILE__).c_str(), __LINE__); //((SgExpression*)detail.first)->addAttribute(BOOL_VAL); @@ -2489,8 +2499,8 @@ void setInlineAttributeToCalls(const map& allFunctions, else printInternalError(convertFileName(__FILE__).c_str(), __LINE__); - pointsForShadowCopies.insert(make_pair(curr->fileName, curr->detailCallsFrom[k].second)); - __spf_print(1, " added attribute to '%s' <%s, %d>\n", curr->detailCallsFrom[k].first.c_str(), curr->fileName.c_str(), curr->detailCallsFrom[k].second); + pointsForShadowCopies.insert(make_pair(curr->fileName, curr->callsFromDetailed[k].detailCallsFrom.second)); + __spf_print(1, " added attribute to '%s' <%s, %d>\n", curr->callsFromDetailed[k].detailCallsFrom.first.c_str(), curr->fileName.c_str(), curr->callsFromDetailed[k].detailCallsFrom.second); } } } diff --git a/sapfor/experts/Sapfor_2017/_src/GraphCall/graph_calls.h b/sapfor/experts/Sapfor_2017/_src/GraphCall/graph_calls.h index 6181f2a..462e2b4 100644 --- a/sapfor/experts/Sapfor_2017/_src/GraphCall/graph_calls.h +++ b/sapfor/experts/Sapfor_2017/_src/GraphCall/graph_calls.h @@ -96,6 +96,16 @@ struct NestedFuncCall { } }; +struct FuncInfoCallFrom { + // + std::pair detailCallsFrom; + // SgStatement for PROC_STAT, SgExpression for FUNC_CALL, VAR_REF for external calls + std::pair pointerDetailCallsFrom; + // parent SgStatement* of FUNC_CALL + void* parentForPointer; + FuncParam actualParams; +}; + struct FuncInfo { std::string funcName; @@ -107,13 +117,14 @@ struct FuncInfo std::set callsFrom; //calls from this function std::set callsFromV; + std::vector callsFromDetailed; //TODO: create new object for grouping this info // grouped info of calls from - std::vector> detailCallsFrom; // + /*std::vector> detailCallsFrom; // std::vector> pointerDetailCallsFrom; // SgStatement for PROC_STAT, SgExpression for FUNC_CALL, VAR_REF for external calls std::vector parentForPointer; // parent SgStatement* of FUNC_CALL - std::vector actualParams; + std::vector actualParams;*/ // end/ std::map> commonBlocks; @@ -176,10 +187,10 @@ struct FuncInfo std::vector> GetDetailedCallInfo(const std::string &funcName) { std::vector> result; - for (int i = 0; i < pointerDetailCallsFrom.size(); ++i) + for (int i = 0; i < callsFromDetailed.size(); ++i) { - if (detailCallsFrom[i].first == funcName) - result.push_back(pointerDetailCallsFrom[i]); + if (callsFromDetailed[i].detailCallsFrom.first == funcName) + result.push_back(callsFromDetailed[i].pointerDetailCallsFrom); } return result; } diff --git a/sapfor/experts/Sapfor_2017/_src/GraphCall/graph_calls_base.cpp b/sapfor/experts/Sapfor_2017/_src/GraphCall/graph_calls_base.cpp index 7e350cb..f2c835a 100644 --- a/sapfor/experts/Sapfor_2017/_src/GraphCall/graph_calls_base.cpp +++ b/sapfor/experts/Sapfor_2017/_src/GraphCall/graph_calls_base.cpp @@ -154,8 +154,9 @@ void updateFuncInfo(const map> &allFuncInfo) // const for (auto &it : mapFuncInfo) { FuncInfo *currInfo = it.second; - for (auto &funcCall : currInfo->detailCallsFrom) + for (auto &callInfo : currInfo->callsFromDetailed) { + auto& funcCall = callInfo.detailCallsFrom; auto itCalledFunc = mapFuncInfo.find(funcCall.first); if (itCalledFunc != mapFuncInfo.end()) { @@ -375,7 +376,7 @@ string convertToString(const FuncInfo *currFunc) { result += "|" + currFunc->funcName + "|" + to_string(currFunc->linesNum.first) + "#" + to_string(currFunc->linesNum.second) + - "#" + to_string(currFunc->detailCallsFrom.size()) + + "#" + to_string(currFunc->callsFromDetailed.size()) + "#" + to_string(currFunc->needToInline) + "#" + to_string(currFunc->doNotInline) + "#" + to_string(currFunc->doNotAnalyze) + "#" + to_string((int)currFunc->isMain); @@ -389,8 +390,8 @@ string convertToString(const FuncInfo *currFunc) } } - for (int i = 0; i < currFunc->detailCallsFrom.size(); ++i) - result += "|" + currFunc->detailCallsFrom[i].first + "|" + to_string(currFunc->detailCallsFrom[i].second); + for (int i = 0; i < currFunc->callsFromDetailed.size(); ++i) + result += "|" + currFunc->callsFromDetailed[i].detailCallsFrom.first + "|" + to_string(currFunc->callsFromDetailed[i].detailCallsFrom.second); } return result; } @@ -721,9 +722,9 @@ void createLinksBetweenFormalAndActualParams(map> &all //printf("func %s :\n", func->funcName.c_str()); const string &name = func->funcName; for (auto &caller : func->callsTo) - for (int i = 0; i < caller->detailCallsFrom.size(); ++i) - if (caller->detailCallsFrom[i].first == name) - addLinks(caller->actualParams[i], func->funcParams, arrayLinksByFuncCalls); + for (int i = 0; i < caller->callsFromDetailed.size(); ++i) + if (caller->callsFromDetailed[i].detailCallsFrom.first == name) + addLinks(caller->callsFromDetailed[i].actualParams, func->funcParams, arrayLinksByFuncCalls); } } @@ -822,8 +823,9 @@ bool detectMpiCalls(const map>& allFuncInfo, mapdetailCallsFrom) + for (auto& callInfo: func->callsFromDetailed) { + auto& callsFromThis = callInfo.detailCallsFrom; if (isMpiFunction(callsFromThis.first) && funcByName.find(callsFromThis.first) == funcByName.end()) { retVal = true; diff --git a/sapfor/experts/Sapfor_2017/_src/Inliner/inliner.cpp b/sapfor/experts/Sapfor_2017/_src/Inliner/inliner.cpp index 9c22fd3..b4f34f3 100644 --- a/sapfor/experts/Sapfor_2017/_src/Inliner/inliner.cpp +++ b/sapfor/experts/Sapfor_2017/_src/Inliner/inliner.cpp @@ -1613,8 +1613,9 @@ bool inliner(const string& fileName_in, const string& funcName, const int lineNu { for (auto& callTo : func->callsTo) { - for (auto& callFrom : callTo->detailCallsFrom) + for (auto& callInfo : callTo->callsFromDetailed) { + auto& callFrom = callInfo.detailCallsFrom; if (callFrom.first == funcName) { SgStatement* callSt = SgStatement::getStatementByFileAndLine(fileName, callFrom.second); @@ -1719,8 +1720,9 @@ bool inliner(const string& allInFunc, const map>& allF if (SgFile::switchToFile(func->fileName) == -1) printInternalError(convertFileName(__FILE__).c_str(), __LINE__); - for (auto& callFrom : func->detailCallsFrom) + for (auto& callInfo : func->callsFromDetailed) { + auto& callFrom = callInfo.detailCallsFrom; bool res = inliner(func->fileName, callFrom.first, callFrom.second, allFuncInfo, SPF_messages, newSymbsToDeclare, commonBlocks, deepLvl); result = result && res; } diff --git a/sapfor/experts/Sapfor_2017/_src/LoopAnalyzer/loop_analyzer.cpp b/sapfor/experts/Sapfor_2017/_src/LoopAnalyzer/loop_analyzer.cpp index 8449a75..20064c1 100644 --- a/sapfor/experts/Sapfor_2017/_src/LoopAnalyzer/loop_analyzer.cpp +++ b/sapfor/experts/Sapfor_2017/_src/LoopAnalyzer/loop_analyzer.cpp @@ -927,20 +927,20 @@ static SgExpression* replaceConstatantProcedurePars(SgExpression *dimList, SgSta for (int z = 0; z < currF->callsTo.size(); ++z) { FuncInfo* callOfThis = currF->callsTo[z]; - for (int p = 0; p < callOfThis->detailCallsFrom.size(); ++p) + for (int p = 0; p < callOfThis->callsFromDetailed.size(); ++p) { - if (callOfThis->detailCallsFrom[p].first == procN) + if (callOfThis->callsFromDetailed[p].detailCallsFrom.first == procN) { for (auto& par : idxFound) { - auto parType = callOfThis->actualParams[p].parametersT[par]; + auto parType = callOfThis->callsFromDetailed[p].actualParams.parametersT[par]; if (parType != SCALAR_INT_T) return dimList; else { - if (callOfThis->actualParams[p].parameters[par] == NULL) + if (callOfThis->callsFromDetailed[p].actualParams.parameters[par] == NULL) return dimList; - values[par].insert(((int*)(callOfThis->actualParams[p].parameters[par]))[0]); + values[par].insert(((int*)(callOfThis->callsFromDetailed[p].actualParams.parameters[par]))[0]); } } } diff --git a/sapfor/experts/Sapfor_2017/_src/ParallelizationRegions/resolve_par_reg_conflicts.cpp b/sapfor/experts/Sapfor_2017/_src/ParallelizationRegions/resolve_par_reg_conflicts.cpp index 8f8cb90..91c3458 100644 --- a/sapfor/experts/Sapfor_2017/_src/ParallelizationRegions/resolve_par_reg_conflicts.cpp +++ b/sapfor/experts/Sapfor_2017/_src/ParallelizationRegions/resolve_par_reg_conflicts.cpp @@ -348,10 +348,12 @@ void fillRegionFunctions(vector ®ions, const mapisIndirect()) { - for (auto &elem : func->detailCallsFrom) + for (auto &callInfo : func->callsFromDetailed) { - auto line = elem.second; - auto call = elem.first; + auto& callFrom = callInfo.detailCallsFrom; + + auto line = callFrom.second; + auto call = callFrom.first; auto callF = getFuncInfo(funcMap, call); auto regs = getAllRegionsByLine(regions, func->fileName, line).size(); if (callF && !getAllRegionsByLine(regions, func->fileName, line).size()) diff --git a/sapfor/experts/Sapfor_2017/_src/Sapfor.cpp b/sapfor/experts/Sapfor_2017/_src/Sapfor.cpp index 3d27c54..6b35f73 100644 --- a/sapfor/experts/Sapfor_2017/_src/Sapfor.cpp +++ b/sapfor/experts/Sapfor_2017/_src/Sapfor.cpp @@ -2101,7 +2101,6 @@ static bool runAnalysis(SgProject &project, const int curr_regime, const bool ne set usedArraysInRegions; set usedWriteArraysInRegions; - set forPure; for (int i = n - 1; i >= 0; --i) { SgFile* file = &(project.file(i)); @@ -2134,16 +2133,15 @@ static bool runAnalysis(SgProject &project, const int curr_regime, const bool ne //add privates to parallel loops with manual parallelization in DVMH regions regionInserter->addPrivatesToParallelLoops(); - //create interface for 'parallel' functions - regionInserter->createInterfaceBlock(); - regionInserter->addUsedArrays(usedArraysInRegions); regionInserter->addUsedWriteArrays(usedWriteArraysInRegions); - auto parallelFuncs = regionInserter->getParallelFunctions(); - forPure.insert(parallelFuncs.begin(), parallelFuncs.end()); + setPureStatus(regionInserter->getParallelFunctions()); + + //create interface for 'parallel' functions and + // insert ROUTINE directive if needed + regionInserter->createInterfaceBlockForParallelFunctions(); } - setPureStatus(forPure); for (auto& regionInserter : inserters) { diff --git a/sapfor/experts/Sapfor_2017/_src/Transformations/checkpoints.cpp b/sapfor/experts/Sapfor_2017/_src/Transformations/checkpoints.cpp index dd3f166..468d224 100644 --- a/sapfor/experts/Sapfor_2017/_src/Transformations/checkpoints.cpp +++ b/sapfor/experts/Sapfor_2017/_src/Transformations/checkpoints.cpp @@ -1011,8 +1011,9 @@ void createCheckpoints(SgFile *file, const map& commonBloc } - for (auto& call : (j->second)->pointerDetailCallsFrom) + for (auto& callInfo : j->second->callsFromDetailed) { + auto& call = callInfo.pointerDetailCallsFrom; SgStatement* st = NULL; if (isSgFuncHedrStmt(hedrTo) && call.second == FUNC_CALL) diff --git a/sapfor/experts/Sapfor_2017/_src/Transformations/function_purifying.cpp b/sapfor/experts/Sapfor_2017/_src/Transformations/function_purifying.cpp index 53ef348..99b3c8a 100644 --- a/sapfor/experts/Sapfor_2017/_src/Transformations/function_purifying.cpp +++ b/sapfor/experts/Sapfor_2017/_src/Transformations/function_purifying.cpp @@ -429,8 +429,9 @@ static void transferCommons(set& allForChange, map fileName) == -1) printInternalError(convertFileName(__FILE__).c_str(), __LINE__); - for (auto& call : curFunc->pointerDetailCallsFrom) + for (auto& callInfo : curFunc->callsFromDetailed) { + auto& call = callInfo.pointerDetailCallsFrom; if (isSgFuncHedrStmt(precFunc->funcPointer->GetOriginal()) && call.second == FUNC_CALL) { SgFunctionCallExp* callExp = (SgFunctionCallExp*)call.first; @@ -792,8 +793,9 @@ static void transferSave(map>& funcAddedVarsFuncs, vec if (SgFile::switchToFile(curFunc->fileName) == -1) printInternalError(convertFileName(__FILE__).c_str(), __LINE__); - for (auto& call : curFunc->pointerDetailCallsFrom) + for (auto& callInfo : curFunc->callsFromDetailed) { + auto& call = callInfo.pointerDetailCallsFrom; if (isSgFuncHedrStmt(precFunc->funcPointer->GetOriginal()) && call.second == FUNC_CALL) { SgFunctionCallExp* callExp = (SgFunctionCallExp*)call.first; @@ -1251,8 +1253,9 @@ static void transferModule(map>& funcAddedVarsMods, se } } - for (auto& call : curFunc->pointerDetailCallsFrom) + for (auto& callInfo : curFunc->callsFromDetailed) { + auto& call = callInfo.pointerDetailCallsFrom; if (isSgFuncHedrStmt(precFunc->funcPointer->GetOriginal()) && call.second == FUNC_CALL) { SgFunctionCallExp* callExp = (SgFunctionCallExp*)call.first; diff --git a/sapfor/experts/Sapfor_2017/_src/Transformations/uniq_call_chain_dup.cpp b/sapfor/experts/Sapfor_2017/_src/Transformations/uniq_call_chain_dup.cpp index f6e1a21..838df37 100644 --- a/sapfor/experts/Sapfor_2017/_src/Transformations/uniq_call_chain_dup.cpp +++ b/sapfor/experts/Sapfor_2017/_src/Transformations/uniq_call_chain_dup.cpp @@ -118,15 +118,16 @@ static map countOfCalls(const map for (auto& elem : fromFile.second) { int p = 0; - for (auto& detailed : elem->detailCallsFrom) + for (auto& callInfo : elem->callsFromDetailed) { + auto& detailed = callInfo.detailCallsFrom; auto it = mapOfFunc.find(detailed.first); if (it != mapOfFunc.end()) { auto var = variantCall.find(it->second); - auto createPackCall = createParamCalls(elem->pointerDetailCallsFrom[p], elem->fileName); + auto createPackCall = createParamCalls(elem->callsFromDetailed[p].pointerDetailCallsFrom, elem->fileName); - if (checkUniqAndAdd(var->second, createPackCall, elem->pointerDetailCallsFrom[p], elem->parentForPointer[p])) + if (checkUniqAndAdd(var->second, createPackCall, elem->callsFromDetailed[p].pointerDetailCallsFrom, elem->callsFromDetailed[p].parentForPointer)) count[it->second]++; } ++p; @@ -554,9 +555,9 @@ static void copyGroup(const map &mapOfFunc, const vectorfuncPointer->GetOriginal(), origName, newName, varOfCall); // fill additional places to next replaces - for (int z = 0; z < currFunc->pointerDetailCallsFrom.size(); ++z) + for (int z = 0; z < currFunc->callsFromDetailed.size(); ++z) { - pair place = currFunc->pointerDetailCallsFrom[z]; + pair place = currFunc->callsFromDetailed[z].pointerDetailCallsFrom; if (place.second == PROC_STAT) { SgStatement* proc = (SgStatement*)place.first; @@ -575,12 +576,12 @@ static void copyGroup(const map &mapOfFunc, const vector tmp; - infoAdd->second.variantCall.push_back(callVars(make_pair(copyPoint, PROC_STAT), tmp, currFunc->parentForPointer[z])); + infoAdd->second.variantCall.push_back(callVars(make_pair(copyPoint, PROC_STAT), tmp, currFunc->callsFromDetailed[z].parentForPointer)); } else if (place.second == FUNC_CALL) { SgExpression* proc = (SgExpression*)place.first; - SgStatement* parent = (SgStatement*)currFunc->parentForPointer[z]; + SgStatement* parent = (SgStatement*)currFunc->callsFromDetailed[z].parentForPointer; checkNull(parent, convertFileName(__FILE__).c_str(), __LINE__); if (SgFile::switchToFile(parent->fileName()) == -1) printInternalError(convertFileName(__FILE__).c_str(), __LINE__); @@ -597,7 +598,7 @@ static void copyGroup(const map &mapOfFunc, const vector tmp; - infoAdd->second.variantCall.push_back(callVars(make_pair(copyPoint, FUNC_CALL), tmp, currFunc->parentForPointer[z])); + infoAdd->second.variantCall.push_back(callVars(make_pair(copyPoint, FUNC_CALL), tmp, currFunc->callsFromDetailed[z].parentForPointer)); } else printInternalError(convertFileName(__FILE__).c_str(), __LINE__); diff --git a/sapfor/experts/Sapfor_2017/_src/Utils/SgUtils.cpp b/sapfor/experts/Sapfor_2017/_src/Utils/SgUtils.cpp index b6be2cd..3ff6596 100644 --- a/sapfor/experts/Sapfor_2017/_src/Utils/SgUtils.cpp +++ b/sapfor/experts/Sapfor_2017/_src/Utils/SgUtils.cpp @@ -1153,7 +1153,8 @@ bool isDVM_stat(SgStatement *st) (var == DVM_DISTRIBUTE_DIR) || (var >= HPF_TEMPLATE_STAT && var <= DVM_REDISTRIBUTE_DIR) || (var >= BLOCK_OP && var <= STAGE_OP) || - (var >= INDIRECT_OP && var <= SHADOW_NAMES_OP)) + (var >= INDIRECT_OP && var <= SHADOW_NAMES_OP) || + (var >= ACC_REGION_DIR && var <= ACC_ASYNC_OP)) ret = true; return ret; } diff --git a/sapfor/experts/Sapfor_2017/_src/Utils/version.h b/sapfor/experts/Sapfor_2017/_src/Utils/version.h index 1861ff9..4f79ab5 100644 --- a/sapfor/experts/Sapfor_2017/_src/Utils/version.h +++ b/sapfor/experts/Sapfor_2017/_src/Utils/version.h @@ -1,3 +1,3 @@ #pragma once -#define VERSION_SPF "2231" +#define VERSION_SPF "2232" diff --git a/sapfor/experts/Sapfor_2017/_src/VisualizerCalls/BuildGraph.cpp b/sapfor/experts/Sapfor_2017/_src/VisualizerCalls/BuildGraph.cpp index 304a024..8519016 100644 --- a/sapfor/experts/Sapfor_2017/_src/VisualizerCalls/BuildGraph.cpp +++ b/sapfor/experts/Sapfor_2017/_src/VisualizerCalls/BuildGraph.cpp @@ -64,8 +64,11 @@ buildLocationOfGraph(const map>& allFuncInfo, const in for (auto& elem : mapOfFuncs) { set callsFrom; - for (auto& callFrom_ : elem.second->detailCallsFrom) + for (auto& callFromInfo : elem.second->callsFromDetailed) + { + auto& callFrom_ = callFromInfo.detailCallsFrom; callsFrom.insert(callFrom_.first); + } callsFrom.insert(elem.second->externalCalls.begin(), elem.second->externalCalls.end()); for (auto& call : callsFrom) @@ -90,8 +93,11 @@ buildLocationOfGraph(const map>& allFuncInfo, const in continue; set callsFrom; - for (auto& callFrom_ : elem.second->detailCallsFrom) + for (auto& callFromInfo : elem.second->callsFromDetailed) + { + auto& callFrom_ = callFromInfo.detailCallsFrom; callsFrom.insert(callFrom_.first); + } callsFrom.insert(elem.second->externalCalls.begin(), elem.second->externalCalls.end()); for (auto& call : callsFrom)