diff --git a/sapfor/experts/Sapfor_2017/_src/DirectiveProcessing/directive_creator.cpp b/sapfor/experts/Sapfor_2017/_src/DirectiveProcessing/directive_creator.cpp index e9e804d..2bd6d86 100644 --- a/sapfor/experts/Sapfor_2017/_src/DirectiveProcessing/directive_creator.cpp +++ b/sapfor/experts/Sapfor_2017/_src/DirectiveProcessing/directive_creator.cpp @@ -90,8 +90,7 @@ pair, vector> const pair linesBeforeAfter) { vector>>> optimizedRules(2); - auto byUse = moduleRefsByUseInFunction(st->GetOriginal()); - + for (int num = 0; num < 2; ++num) { for (auto &elemPair : sortArraysByName(usedArrays)) @@ -108,7 +107,7 @@ pair, vector> printInternalError(convertFileName(__FILE__).c_str(), __LINE__); vector realign = { NULL, NULL, NULL, NULL, NULL }; - SgVarRefExp *ref = new SgVarRefExp(getFromModule(byUse, findSymbolOrCreate(file, elem->GetShortName()))); + SgVarRefExp *ref = new SgVarRefExp((SgSymbol*)elem->GetNameInLocationS(st)); realign[0] = new Expression(ref); SgExprListExp *list = new SgExprListExp(); diff --git a/sapfor/experts/Sapfor_2017/_src/DirectiveProcessing/insert_directive.cpp b/sapfor/experts/Sapfor_2017/_src/DirectiveProcessing/insert_directive.cpp index 642a5b7..68c20ac 100644 --- a/sapfor/experts/Sapfor_2017/_src/DirectiveProcessing/insert_directive.cpp +++ b/sapfor/experts/Sapfor_2017/_src/DirectiveProcessing/insert_directive.cpp @@ -839,7 +839,7 @@ static pair getModuleRename(const set& allocatable set arrayNames; for (auto& alloc : allocatableStmts) if (alloc->variant() == ALLOCATE_STMT) - arrayNames.insert(getNameByUse(alloc, array->GetShortName(), array->GetLocation().second)); + arrayNames.insert(array->GetNameInLocation(alloc)); if (arrayNames.size() > 1 || arrayNames.size() == 0) printInternalError(convertFileName(__FILE__).c_str(), __LINE__); @@ -1397,15 +1397,24 @@ static set filterAllocateStats(SgFile* file, const vectorswitchToFile()) printInternalError(convertFileName(__FILE__).c_str(), __LINE__); - auto byUse = moduleRefsByUseInFunction(stat); - for (auto &elem : byUse) - if (elem.first == array) - for (auto &newElem : elem.second) - arraySyns.insert(newElem->identifier()); + SgExpression* list = stat->expr(0); + bool find = false; + while (list) + { + if (list->lhs() && list->lhs()->symbol()) + { + if (OriginalSymbol(list->lhs()->symbol())->identifier() == array) + { + find = true; + break; + } + } - for (auto &syns : arraySyns) - if (recSymbolFind(stat->expr(0), syns, ARRAY_REF)) - filtered.insert(stat); + list = list->rhs(); + } + + if (find) + filtered.insert(stat); SgFile::switchToFile(fileName); } diff --git a/sapfor/experts/Sapfor_2017/_src/DirectiveProcessing/remote_access.cpp b/sapfor/experts/Sapfor_2017/_src/DirectiveProcessing/remote_access.cpp index 67e35a1..5e3ae08 100644 --- a/sapfor/experts/Sapfor_2017/_src/DirectiveProcessing/remote_access.cpp +++ b/sapfor/experts/Sapfor_2017/_src/DirectiveProcessing/remote_access.cpp @@ -780,6 +780,8 @@ void addRemoteLink(const LoopGraph* loop, const map& funcMap, while (withDir && withDir->loop->GetOriginal()->lexPrev()->variant() != DVM_PARALLEL_ON_DIR) withDir = withDir->parent; + checkNull(withDir, convertFileName(__FILE__).c_str(), __LINE__); + set loopVars; for (auto& elem : withDir->directive->parallel) if (elem != "*") @@ -871,8 +873,6 @@ ArrayRefExp* createRemoteLink(const LoopGraph* currLoop, const DIST::Array* forA const set allFiles = getAllFilesInProject(); SgStatement* realStat = (SgStatement*)currLoop->getRealStat(file->filename()); const map> byUseInFunc = moduleRefsByUseInFunction(realStat); - SgStatement* parentFunc = getFuncStat(realStat); - const pair lineRange = make_pair(parentFunc->lineNumber(), parentFunc->lastNodeOfStmt()->lineNumber()); SgExpression* ex = new SgExpression(EXPR_LIST); SgExpression* p = ex; @@ -885,21 +885,7 @@ ArrayRefExp* createRemoteLink(const LoopGraph* currLoop, const DIST::Array* forA p = p->rhs(); } } - SgArrayRefExp* newRem = NULL; - - auto decls = forArray->GetDeclInfoWithSymb(); - const string fName = current_file->filename(); - /*for (auto& decl : decls) - { - if (decl.first.first == fName) - { - newRem = new SgArrayRefExp(*decl.second->GetOriginal(), *ex); - break; - } - }*/ - - if (!newRem) - newRem = new SgArrayRefExp(*getFromModule(byUseInFunc, forArray->GetDeclSymbol(fName, lineRange, allFiles)->GetOriginal()), *ex); + SgArrayRefExp* newRem = new SgArrayRefExp(*((SgSymbol*)forArray->GetNameInLocationS(realStat)), *ex); return new ArrayRefExp(newRem); } diff --git a/sapfor/experts/Sapfor_2017/_src/DirectiveProcessing/shadow.cpp b/sapfor/experts/Sapfor_2017/_src/DirectiveProcessing/shadow.cpp index aa895da..95f3a0e 100644 --- a/sapfor/experts/Sapfor_2017/_src/DirectiveProcessing/shadow.cpp +++ b/sapfor/experts/Sapfor_2017/_src/DirectiveProcessing/shadow.cpp @@ -782,12 +782,7 @@ static void replacingShadowNodes(FuncInfo* currF) const ShadowElement& currElement = currSh.second[0]; - SgSymbol* s = currArray->GetDeclSymbol()->GetOriginal(); - if (currArray->IsModuleSymbol()) - { - const map> byUseInFunc = moduleRefsByUseInFunction(currF->funcPointer->GetOriginal()); - s = getFromModule(byUseInFunc, s); - } + SgSymbol* s = (SgSymbol*)currArray->GetNameInLocationS(currF->funcPointer); //TODO: if moved from other file /*auto itTmp = currElement.origNameByProc.find(currF); diff --git a/sapfor/experts/Sapfor_2017/_src/Distribution/Array.h b/sapfor/experts/Sapfor_2017/_src/Distribution/Array.h index 8380a6b..4d56db1 100644 --- a/sapfor/experts/Sapfor_2017/_src/Distribution/Array.h +++ b/sapfor/experts/Sapfor_2017/_src/Distribution/Array.h @@ -265,6 +265,9 @@ namespace Distribution int GetDimSize() const { return dimSize; } const STRING GetName() const { return name; } const STRING GetShortName() const { return shortName; } + const STRING GetNameInLocation(void* location) const; + void* GetNameInLocationS(void* location) const; + unsigned GetId() const { return id; } void SetSizes(VECTOR> &_sizes, bool notCopyToExpr = false) { diff --git a/sapfor/experts/Sapfor_2017/_src/Distribution/DvmhDirective.cpp b/sapfor/experts/Sapfor_2017/_src/Distribution/DvmhDirective.cpp index 98be8c9..f2c6973 100644 --- a/sapfor/experts/Sapfor_2017/_src/Distribution/DvmhDirective.cpp +++ b/sapfor/experts/Sapfor_2017/_src/Distribution/DvmhDirective.cpp @@ -227,7 +227,7 @@ static vector compliteTieList(const LoopGraph* currLoop, const vector& loops, const map>& arrayLinksByFuncCalls, const map>& byUseInFunc, - File* file, const pair& lineRange, + File* file, SgStatement *location, const set& onlyFor, const set& privates) { @@ -257,9 +257,8 @@ static vector { if (privates.find(pairs.second->GetShortName()) != privates.end()) continue; - - auto type = pairs.second->GetDeclSymbol(currLoop->fileName, lineRange, getAllFilesInProject())->GetOriginal()->type(); - SgSymbol* arrayS = getFromModule(byUseInFunc, findSymbolOrCreate(file, pairs.second->GetShortName(), type)); + + SgSymbol* arrayS = (SgSymbol*)pairs.second->GetNameInLocationS(location); SgArrayRefExp* array = new SgArrayRefExp(*arrayS); bool needToAdd = false; @@ -509,8 +508,6 @@ ParallelDirective::genDirective(File* file, const vector> byUseInFunc = moduleRefsByUseInFunction(realStat); const int nested = countPerfectLoopNest(loopG); - const pair lineRange = make_pair(parentFunc->lineNumber(), parentFunc->lastNodeOfStmt()->lineNumber()); - const string& filename = currLoop->fileName; vector loopSymbs; vector loops; @@ -595,12 +592,14 @@ ParallelDirective::genDirective(File* file, const vectorIsTemplate()) { if (mapTo->IsLoopArray()) - symbForPar = getFromModule(byUseInFunc, findSymbolOrCreate(file, mapTo->GetShortName(), new SgArrayType(*SgTypeInt()), file->GetOriginal()->firstStatement())); + symbForPar = findSymbolOrCreate(file, mapTo->GetShortName(), new SgArrayType(*SgTypeInt()), file->GetOriginal()->firstStatement()); else - symbForPar = getFromModule(byUseInFunc, mapTo->GetDeclSymbol(filename, lineRange, allFiles)->GetOriginal()); + { + symbForPar = (SgSymbol*)mapTo->GetNameInLocationS(parentFunc); + } } else - symbForPar = getFromModule(byUseInFunc, arrayRef->GetDeclSymbol(filename, lineRange, allFiles)->GetOriginal()); + symbForPar = (SgSymbol*)arrayRef->GetNameInLocationS(parentFunc); arrayExpr = new SgArrayRefExp(*symbForPar); arrayExprS = ""; @@ -695,9 +694,9 @@ ParallelDirective::genDirective(File* file, const vector tieList; if (sharedMemoryParallelization) - tieList = compliteTieList(currLoop, loopsTie, arrayLinksByFuncCalls, byUseInFunc, file, lineRange, onlyFor, uniqNamesOfPrivates); + tieList = compliteTieList(currLoop, loopsTie, arrayLinksByFuncCalls, byUseInFunc, file, parentFunc, onlyFor, uniqNamesOfPrivates); else if (onlyFor.size()) // not MPI regime - tieList = compliteTieList(currLoop, loopsTie, arrayLinksByFuncCalls, byUseInFunc, file, lineRange, onlyFor, uniqNamesOfPrivates); + tieList = compliteTieList(currLoop, loopsTie, arrayLinksByFuncCalls, byUseInFunc, file, parentFunc, onlyFor, uniqNamesOfPrivates); if (tieList.size()) { @@ -829,7 +828,7 @@ ParallelDirective::genDirective(File* file, const vectorGetDeclSymbol(filename, lineRange, allFiles)->GetOriginal())); + SgArrayRefExp* newArrayRef = new SgArrayRefExp(*((SgSymbol*)acrossArray->GetNameInLocationS(parentFunc))); newArrayRef->addAttribute(ARRAY_REF, acrossArray, sizeof(DIST::Array)); for (auto& elem : genSubscripts(across[i1].second, acrossShifts[i1])) @@ -905,7 +904,7 @@ ParallelDirective::genDirective(File* file, const vectorGetDeclSymbol(filename, lineRange, allFiles))); + SgArrayRefExp* newArrayRef = new SgArrayRefExp(*((SgSymbol*)shadowArray->GetNameInLocationS(parentFunc))); newArrayRef->addAttribute(ARRAY_REF, shadowArray, sizeof(DIST::Array)); for (auto& elem : genSubscripts(shadowRenew[i1].second, shadowRenewShifts[i1])) @@ -1053,7 +1052,7 @@ ParallelDirective::genDirective(File* file, const vectorfirst.second + ")"; DIST::Array* currArray = allArrays.GetArrayByName(it->first.first.second); - SgArrayRefExp* tmp = new SgArrayRefExp(*getFromModule(byUseInFunc, currArray->GetDeclSymbol(filename, lineRange, allFiles)->GetOriginal()), *it->second); + SgArrayRefExp* tmp = new SgArrayRefExp(*((SgSymbol*)currArray->GetNameInLocationS(parentFunc)), *it->second); tmp->addAttribute(ARRAY_REF, currArray, sizeof(DIST::Array)); p->setLhs(tmp); diff --git a/sapfor/experts/Sapfor_2017/_src/DvmhRegions/DvmhRegionInserter.cpp b/sapfor/experts/Sapfor_2017/_src/DvmhRegions/DvmhRegionInserter.cpp index 9b760c7..53c668c 100644 --- a/sapfor/experts/Sapfor_2017/_src/DvmhRegions/DvmhRegionInserter.cpp +++ b/sapfor/experts/Sapfor_2017/_src/DvmhRegions/DvmhRegionInserter.cpp @@ -654,9 +654,7 @@ void DvmhRegionInserter::insertActualDirective(SgStatement *st, const ArraySet & vector list; for (auto &arr : arraySet) { - string arrayName = arr->GetShortName(); - if (arr->GetLocation().first == DIST::l_MODULE) - arrayName = getNameByUse(st, arrayName, arr->GetLocation().second); + string arrayName = arr->GetNameInLocation(st); if (exceptSymbs) if (exceptSymbs->find(arrayName) != exceptSymbs->end()) diff --git a/sapfor/experts/Sapfor_2017/_src/Utils/module_utils.cpp b/sapfor/experts/Sapfor_2017/_src/Utils/module_utils.cpp index 99df6ba..76bc0fb 100644 --- a/sapfor/experts/Sapfor_2017/_src/Utils/module_utils.cpp +++ b/sapfor/experts/Sapfor_2017/_src/Utils/module_utils.cpp @@ -314,126 +314,98 @@ static SgStatement* findModWithName(const vector& modules, const s return NULL; } -string getNameByUse(SgStatement* place, const string& varName, const string& locName) +static map> symbolsForFunc; +static set allFiles; + +static const set& getModeulSymbols(SgStatement *func) { - int old_id = -1; - string oldFileName = ""; - if (place->getFileId() != current_file_id) + if (symbolsForFunc.find(func) != symbolsForFunc.end()) + return symbolsForFunc[func]; + + set symbs; + SgSymbol* s = func->symbol()->next(); + while (s) { - old_id = current_file_id; - oldFileName = current_file->filename(); - if (!place->switchToFile()) - printInternalError(convertFileName(__FILE__).c_str(), __LINE__); + if (s->scope() == func && IS_BY_USE(s)) + symbs.insert(s); + s = s->next(); } - SgStatement* func = getFuncStat(place, { MODULE_STMT }); - string returnVal = varName; - if (func != NULL) + symbolsForFunc[func] = symbs; + return symbolsForFunc[func]; +} + + +namespace Distribution +{ + const string Array::GetNameInLocation(void* location_p) const { - map> graphUse; + return ((SgSymbol*)GetNameInLocationS(location_p))->identifier(); + } - set useMod; - map>> modByUse; - map>> modByUseOnly; + void* Array::GetNameInLocationS(void* location_p) const + { + SgStatement* location = (SgStatement*)location_p; - fillInfo(func, useMod, modByUse, modByUseOnly); - SgStatement* cp = func->controlParent(); - if (isSgProgHedrStmt(cp) || cp->variant() == MODULE_STMT) // if function in contains region - fillInfo(cp, useMod, modByUse, modByUseOnly); - - set useModDone; - bool needRepeat = true; - - vector modules; - findModulesInFile(func->getFile(), modules); - - while (needRepeat) + int old_id = -1; + string oldFileName = ""; + if (location->getFileId() != current_file_id) { - needRepeat = false; - set newUseMod; - for (auto& useM : useMod) - { - if (useModDone.find(useM) == useModDone.end()) - { - auto modSt = findModWithName(modules, useM); - if (modSt == NULL || useM == "dvmh_template_mod") - continue; - - checkNull(modSt, convertFileName(__FILE__).c_str(), __LINE__); - - set tmpUse; - fillInfo(modSt, tmpUse, modByUse, modByUseOnly); - useModDone.insert(useM); - - for (auto& use : tmpUse) - { - newUseMod.insert(use); - - if (use != "dvmh_template_mod") - graphUse[use].insert(useM); - } - } - } - - for (auto& newU : newUseMod) - { - if (useModDone.find(newU) == useModDone.end()) - { - useModDone.insert(newU); - needRepeat = true; - } - } + old_id = current_file_id; + oldFileName = current_file->filename(); + if (!location->switchToFile()) + printInternalError(convertFileName(__FILE__).c_str(), __LINE__); } - vector altNames; - findByUse(modByUse, varName, { locName }, altNames); - findByUse(modByUseOnly, varName, { locName }, altNames); + SgStatement* func = getFuncStat(location, { MODULE_STMT }); + if (func == NULL) + printInternalError(convertFileName(__FILE__).c_str(), __LINE__); - if (altNames.size() == 0) + if (allFiles.size() == 0) + allFiles = getAllFilesInProject(); + + const pair lineRange = make_pair(func->lineNumber(), func->lastNodeOfStmt()->lineNumber()); + const string& filename = func->fileName(); + + SgSymbol* returnVal = NULL; + + if (locationPos.first == l_MODULE) { - set locations = { locName }; - bool changed = true; - while (changed) + const string& varName = shortName; + const string& locName = locationPos.second; + + + map altNames; + for (const auto& s : getModeulSymbols(func)) { - changed = false; - for (auto& loc : locations) + SgSymbol* orig = OriginalSymbol(s); + if (orig->identifier() == varName && orig->scope()->symbol()->identifier() == locName) { - if (graphUse.find(loc) != graphUse.end()) - { - for (auto& use : graphUse[loc]) - { - if (locations.find(use) == locations.end()) - { - locations.insert(use); - changed = true; - } - } - } + if (altNames.count(s->identifier())) + printInternalError(convertFileName(__FILE__).c_str(), __LINE__); + + altNames[s->identifier()] = s; } } - findByUse(modByUse, varName, locations, altNames); - findByUse(modByUseOnly, varName, locations, altNames); - } - - if (altNames.size() == 0) - returnVal = varName; - else if (altNames.size() >= 1) - { - set setAlt(altNames.begin(), altNames.end()); - returnVal = *setAlt.begin(); + if (altNames.size() > 0) + returnVal = altNames.begin()->second; + else + printInternalError(convertFileName(__FILE__).c_str(), __LINE__); } else - printInternalError(convertFileName(__FILE__).c_str(), __LINE__); - } + returnVal = GetDeclSymbol(filename, lineRange, allFiles); - if (old_id != -1) - { - if (SgFile::switchToFile(oldFileName) == -1) - printInternalError(convertFileName(__FILE__).c_str(), __LINE__); - } + checkNull(returnVal, convertFileName(__FILE__).c_str(), __LINE__); - return returnVal; + if (old_id != -1) + { + if (SgFile::switchToFile(oldFileName) == -1) + printInternalError(convertFileName(__FILE__).c_str(), __LINE__); + } + + return returnVal; + } } void fixUseOnlyStmt(SgFile *file, const vector ®s) diff --git a/sapfor/experts/Sapfor_2017/_src/Utils/module_utils.h b/sapfor/experts/Sapfor_2017/_src/Utils/module_utils.h index e0e14a5..82216b2 100644 --- a/sapfor/experts/Sapfor_2017/_src/Utils/module_utils.h +++ b/sapfor/experts/Sapfor_2017/_src/Utils/module_utils.h @@ -7,7 +7,6 @@ std::map> createMapOfModuleUses(SgFile* file) void fillModuleUse(SgFile* file, std::map>& moduleUses, std::map& moduleDecls); void filterModuleUse(std::map>& moduleUses, std::map& moduleDecls); void fillUsedModulesInFunction(SgStatement* st, std::vector& useStats); -std::string getNameByUse(SgStatement* place, const std::string& varName, const std::string& locName); void fillUseStatement(SgStatement* st, std::set& useMod, std::map>>& modByUse, std::map>>& modByUseOnly); void fixUseOnlyStmt(SgFile* file, const std::vector& regs); std::map> moduleRefsByUseInFunction(SgStatement* stIn); diff --git a/sapfor/experts/Sapfor_2017/_src/Utils/version.h b/sapfor/experts/Sapfor_2017/_src/Utils/version.h index a6610ad..c5b1c0d 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 "2390" +#define VERSION_SPF "2391"