From c6b09ad285f66be7f99256a2c247d802c4c8f92f Mon Sep 17 00:00:00 2001 From: ALEXks Date: Wed, 29 Jan 2025 10:08:13 +0300 Subject: [PATCH] fixed distribution, fixed routine, fixed null program unparsing --- .../_src/Distribution/DvmhDirective.cpp | 51 ++++++++++++++----- .../_src/DvmhRegions/DvmhRegionInserter.cpp | 17 ++++--- .../Sapfor_2017/_src/Utils/SgUtils.cpp | 22 ++++++-- .../experts/Sapfor_2017/_src/Utils/version.h | 2 +- 4 files changed, 67 insertions(+), 25 deletions(-) diff --git a/sapfor/experts/Sapfor_2017/_src/Distribution/DvmhDirective.cpp b/sapfor/experts/Sapfor_2017/_src/Distribution/DvmhDirective.cpp index 8d75eab..98be8c9 100644 --- a/sapfor/experts/Sapfor_2017/_src/Distribution/DvmhDirective.cpp +++ b/sapfor/experts/Sapfor_2017/_src/Distribution/DvmhDirective.cpp @@ -29,6 +29,8 @@ using std::make_pair; using std::min; using std::max; +extern map, pair> declaredArrays; + static bool findArrayRefAndCheck(SgExpression *ex, const DIST::Array* currArray, const vector, int>> &shiftsByAccess) { bool res = false; @@ -748,13 +750,31 @@ ParallelDirective::genDirective(File* file, const vector, int>> shiftsByAccess; - DIST::Array* currArray = NULL; + DIST::Array* acrossArray = NULL; if (!sharedMemoryParallelization) { - currArray = allArrays.GetArrayByName(across[i1].first.second); - if (currArray == NULL) - printInternalError(convertFileName(__FILE__).c_str(), __LINE__); + acrossArray = allArrays.GetArrayByName(across[i1].first.second); + if (acrossArray == NULL) + { + //TODO: need to fix SageDep analysis or use IR + bool notPrivate = true; + for (auto& arrayPair : declaredArrays) + { + auto array = arrayPair.second.first; + if (array->GetName() == across[i1].first.second) + { + if (array->IsNotDistribute()) + notPrivate = false; + break; + } + } + + if (notPrivate) + printInternalError(convertFileName(__FILE__).c_str(), __LINE__); + else + continue; + } } else { @@ -763,11 +783,12 @@ ParallelDirective::genDirective(File* file, const vectorsecond; + acrossArray = currArray_it->second; } - bool isOut = acrossOutAttribute.find(currArray) != acrossOutAttribute.end(); - string bounds = genBounds(across[i1], acrossShifts[i1], reducedG, allArrays, currArray, remoteReads, readOps, true, regionId, distribution, arraysInAcross, shiftsByAccess, arrayLinksByFuncCalls); + bool isOut = acrossOutAttribute.find(acrossArray) != acrossOutAttribute.end(); + string bounds = genBounds(across[i1], acrossShifts[i1], reducedG, allArrays, acrossArray, remoteReads, readOps, true, regionId, distribution, arraysInAcross, shiftsByAccess, arrayLinksByFuncCalls); + if (bounds != "") { if (inserted != 0) @@ -808,8 +829,8 @@ ParallelDirective::genDirective(File* file, const vectorGetDeclSymbol(filename, lineRange, allFiles)->GetOriginal())); - newArrayRef->addAttribute(ARRAY_REF, currArray, sizeof(DIST::Array)); + SgArrayRefExp* newArrayRef = new SgArrayRefExp(*getFromModule(byUseInFunc, acrossArray->GetDeclSymbol(filename, lineRange, allFiles)->GetOriginal())); + newArrayRef->addAttribute(ARRAY_REF, acrossArray, sizeof(DIST::Array)); for (auto& elem : genSubscripts(across[i1].second, acrossShifts[i1])) newArrayRef->addSubscript(*elem); @@ -857,10 +878,14 @@ ParallelDirective::genDirective(File* file, const vector, int>> shiftsByAccess; DIST::Array* shadowArray = allArrays.GetArrayByName(shadowRenew[i1].first.second); + if (shadowArray == NULL) + printInternalError(convertFileName(__FILE__).c_str(), __LINE__); + const string bounds = genBounds(shadowRenew[i1], shadowRenewShifts[i1], reducedG, allArrays, shadowArray, remoteReads, readOps, false, regionId, distribution, arraysInAcross, shiftsByAccess, arrayLinksByFuncCalls); + if (bounds != "") { - DIST::Array* currArray = allArrays.GetArrayByName(shadowRenew[i1].first.second); + DIST::Array* shadowArray = allArrays.GetArrayByName(shadowRenew[i1].first.second); if (inserted != 0) { @@ -880,13 +905,13 @@ ParallelDirective::genDirective(File* file, const vectorGetDeclSymbol(filename, lineRange, allFiles))); - newArrayRef->addAttribute(ARRAY_REF, currArray, sizeof(DIST::Array)); + SgArrayRefExp* newArrayRef = new SgArrayRefExp(*getFromModule(byUseInFunc, shadowArray->GetDeclSymbol(filename, lineRange, allFiles))); + newArrayRef->addAttribute(ARRAY_REF, shadowArray, sizeof(DIST::Array)); for (auto& elem : genSubscripts(shadowRenew[i1].second, shadowRenewShifts[i1])) newArrayRef->addSubscript(*elem); - if (shadowRenew[i1].second.size() > 1 && needCorner(currArray, shiftsByAccess, loop)) + if (shadowRenew[i1].second.size() > 1 && needCorner(shadowArray, shiftsByAccess, loop)) { SgExpression* tmp = new SgExpression(ARRAY_OP, newArrayRef, NULL, NULL); p->setLhs(*tmp); diff --git a/sapfor/experts/Sapfor_2017/_src/DvmhRegions/DvmhRegionInserter.cpp b/sapfor/experts/Sapfor_2017/_src/DvmhRegions/DvmhRegionInserter.cpp index 5adc9a5..6096dbf 100644 --- a/sapfor/experts/Sapfor_2017/_src/DvmhRegions/DvmhRegionInserter.cpp +++ b/sapfor/experts/Sapfor_2017/_src/DvmhRegions/DvmhRegionInserter.cpp @@ -1295,14 +1295,17 @@ void DvmhRegionInserter::createInterfaceBlockForParallelFunctions(bool onlyRouti for (auto& callTo : parF->callsTo) { - if (callTo->fileName != parF->fileName && isPure(parF->funcPointer->GetOriginal())) + if (!isPure(parF->funcPointer->GetOriginal())) + continue; + + if (callTo->fileName != parF->fileName && onlyRoutine) + { + insertRoutine(parF->funcPointer->GetOriginal(), parF, inLoops, arrayLinksByFuncCalls); + continue; + } + + if (callTo->fileName != parF->fileName || isPure(callTo->funcPointer->GetOriginal())) { - if (onlyRoutine) - { - insertRoutine(parF->funcPointer->GetOriginal(), parF, inLoops, arrayLinksByFuncCalls); - continue; - } - auto it = callTo->interfaceBlocks.find(parF->funcName); if (it == callTo->interfaceBlocks.end()) { diff --git a/sapfor/experts/Sapfor_2017/_src/Utils/SgUtils.cpp b/sapfor/experts/Sapfor_2017/_src/Utils/SgUtils.cpp index 39f5c7d..eb9b0e2 100644 --- a/sapfor/experts/Sapfor_2017/_src/Utils/SgUtils.cpp +++ b/sapfor/experts/Sapfor_2017/_src/Utils/SgUtils.cpp @@ -656,13 +656,27 @@ string removeIncludeStatsAndUnparse(SgFile *file, const char *fileName, const ch } } + //check for empty + string comm = ""; + if (file->firstStatement()->comments()) + { + comm = file->firstStatement()->comments(); + file->firstStatement()->delComments(); + } + const string tmp = file->firstStatement()->unparse(); + bool isEmpty = (tmp.size() == 0); + if (comm.size()) + file->firstStatement()->addComment(comm.c_str()); + string strUnparse = ""; if (toString) - strUnparse = string(file->firstStatement()->unparse()); - else { - const string tmp = file->firstStatement()->unparse(); - if (tmp.size() > 0) + if (!isEmpty) + strUnparse = string(file->firstStatement()->unparse()); + } + else + { + if (!isEmpty) { #ifdef _WIN32 FILE* fOut; diff --git a/sapfor/experts/Sapfor_2017/_src/Utils/version.h b/sapfor/experts/Sapfor_2017/_src/Utils/version.h index 2268af7..9bc5377 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 "2383" +#define VERSION_SPF "2384"