diff --git a/sapfor/experts/Sapfor_2017/_src/DvmhRegions/DvmhRegionInserter.cpp b/sapfor/experts/Sapfor_2017/_src/DvmhRegions/DvmhRegionInserter.cpp index ea21174..8180f55 100644 --- a/sapfor/experts/Sapfor_2017/_src/DvmhRegions/DvmhRegionInserter.cpp +++ b/sapfor/experts/Sapfor_2017/_src/DvmhRegions/DvmhRegionInserter.cpp @@ -1487,6 +1487,67 @@ void DvmhRegionInserter::addUsedWriteArrays(set& arrays) } } +static void insertDeclare(const set& usedArraysInRegions, + const set& usedWriteArraysInRegions, + const map> arrayLinksByFuncCalls) +{ + vector usedAll; + std::set_union(usedArraysInRegions.begin(), usedArraysInRegions.end(), + usedWriteArraysInRegions.begin(), usedWriteArraysInRegions.end(), + std::back_inserter(usedAll)); + + set added; + map> toDeclareByFunc; + + for (auto& array : usedAll) + { + set realRef; + getRealArrayRefs(array, array, realRef, arrayLinksByFuncCalls); + + for (auto& realArray : realRef) + { + if (std::count(usedAll.begin(), usedAll.end(), realArray) == 0 && added.count(realArray) == 0) + { + added.insert(realArray); + //TODO: for modules + if (realArray->GetLocation().first != DIST::l_MODULE) + { + auto declInfo = *realArray->GetDeclInfo().begin(); + SgStatement* declStat = SgStatement::getStatementByFileAndLine(declInfo.first, declInfo.second); + checkNull(declStat, convertFileName(__FILE__).c_str(), __LINE__); + + declStat = getFuncStat(declStat); + checkNull(declStat, convertFileName(__FILE__).c_str(), __LINE__); + + toDeclareByFunc[declStat].insert(realArray->GetDeclSymbol()); + } + } + } + } + + for (auto& declPair : toDeclareByFunc) + { + SgStatement* func = declPair.first; + const set& symbols = declPair.second; + + if (!func->switchToFile()) + printInternalError(convertFileName(__FILE__).c_str(), __LINE__); + + set added; + vector list; + for (auto& s : symbols) + { + if (added.count(s->identifier()) == 0) + { + added.insert(s->identifier()); + list.push_back(new SgVarRefExp(s)); + } + } + + func->insertStmtAfter(*new SgStatement(ACC_DECLARE_DIR, NULL, NULL, makeExprList(list)), *func); + } +} + void insertDvmhRegions(SgProject& project, int files, const vector& parallelRegions, map>& allFuncInfo, map> loopGraph, @@ -1552,6 +1613,8 @@ void insertDvmhRegions(SgProject& project, int files, const vectorcreateInterfaceBlockForParallelFunctions(false); } + insertDeclare(usedArraysInRegions, usedWriteArraysInRegions, arrayLinksByFuncCalls); + for (auto& regionInserter : inserters) { regionInserter->updateUsedArrays(usedArraysInRegions, usedWriteArraysInRegions); diff --git a/sapfor/experts/Sapfor_2017/_src/Utils/version.h b/sapfor/experts/Sapfor_2017/_src/Utils/version.h index bcf1ed3..2a5461c 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 "2379" +#define VERSION_SPF "2380"