fixed distribution, fixed routine, fixed null program unparsing

This commit is contained in:
ALEXks
2025-01-29 10:08:13 +03:00
committed by Dudarenko
parent fd402b6ab0
commit c6b09ad285
4 changed files with 67 additions and 25 deletions

View File

@@ -29,6 +29,8 @@ using std::make_pair;
using std::min; using std::min;
using std::max; using std::max;
extern map<tuple<int, string, string>, pair<DIST::Array*, DIST::ArrayAccessInfo*>> declaredArrays;
static bool findArrayRefAndCheck(SgExpression *ex, const DIST::Array* currArray, const vector<map<pair<int, int>, int>> &shiftsByAccess) static bool findArrayRefAndCheck(SgExpression *ex, const DIST::Array* currArray, const vector<map<pair<int, int>, int>> &shiftsByAccess)
{ {
bool res = false; bool res = false;
@@ -748,13 +750,31 @@ ParallelDirective::genDirective(File* file, const vector<pair<DIST::Array*, cons
{ {
const int i1 = ordered[k]; const int i1 = ordered[k];
vector<map<pair<int, int>, int>> shiftsByAccess; vector<map<pair<int, int>, int>> shiftsByAccess;
DIST::Array* currArray = NULL; DIST::Array* acrossArray = NULL;
if (!sharedMemoryParallelization) if (!sharedMemoryParallelization)
{ {
currArray = allArrays.GetArrayByName(across[i1].first.second); acrossArray = allArrays.GetArrayByName(across[i1].first.second);
if (currArray == NULL) if (acrossArray == NULL)
printInternalError(convertFileName(__FILE__).c_str(), __LINE__); {
//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 else
{ {
@@ -763,11 +783,12 @@ ParallelDirective::genDirective(File* file, const vector<pair<DIST::Array*, cons
if (currArray_it == arrayByName.end()) if (currArray_it == arrayByName.end())
printInternalError(convertFileName(__FILE__).c_str(), __LINE__); printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
currArray = currArray_it->second; acrossArray = currArray_it->second;
} }
bool isOut = acrossOutAttribute.find(currArray) != acrossOutAttribute.end(); bool isOut = acrossOutAttribute.find(acrossArray) != acrossOutAttribute.end();
string bounds = genBounds(across[i1], acrossShifts[i1], reducedG, allArrays, currArray, remoteReads, readOps, true, regionId, distribution, arraysInAcross, shiftsByAccess, arrayLinksByFuncCalls); string bounds = genBounds(across[i1], acrossShifts[i1], reducedG, allArrays, acrossArray, remoteReads, readOps, true, regionId, distribution, arraysInAcross, shiftsByAccess, arrayLinksByFuncCalls);
if (bounds != "") if (bounds != "")
{ {
if (inserted != 0) if (inserted != 0)
@@ -808,8 +829,8 @@ ParallelDirective::genDirective(File* file, const vector<pair<DIST::Array*, cons
acrossAdd += across[i1].first.first + "(" + bounds + ")"; acrossAdd += across[i1].first.first + "(" + bounds + ")";
SgArrayRefExp* newArrayRef = new SgArrayRefExp(*getFromModule(byUseInFunc, currArray->GetDeclSymbol(filename, lineRange, allFiles)->GetOriginal())); SgArrayRefExp* newArrayRef = new SgArrayRefExp(*getFromModule(byUseInFunc, acrossArray->GetDeclSymbol(filename, lineRange, allFiles)->GetOriginal()));
newArrayRef->addAttribute(ARRAY_REF, currArray, sizeof(DIST::Array)); newArrayRef->addAttribute(ARRAY_REF, acrossArray, sizeof(DIST::Array));
for (auto& elem : genSubscripts(across[i1].second, acrossShifts[i1])) for (auto& elem : genSubscripts(across[i1].second, acrossShifts[i1]))
newArrayRef->addSubscript(*elem); newArrayRef->addSubscript(*elem);
@@ -857,10 +878,14 @@ ParallelDirective::genDirective(File* file, const vector<pair<DIST::Array*, cons
const int i1 = ordered[k]; const int i1 = ordered[k];
vector<map<pair<int, int>, int>> shiftsByAccess; vector<map<pair<int, int>, int>> shiftsByAccess;
DIST::Array* shadowArray = allArrays.GetArrayByName(shadowRenew[i1].first.second); 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); const string bounds = genBounds(shadowRenew[i1], shadowRenewShifts[i1], reducedG, allArrays, shadowArray, remoteReads, readOps, false, regionId, distribution, arraysInAcross, shiftsByAccess, arrayLinksByFuncCalls);
if (bounds != "") if (bounds != "")
{ {
DIST::Array* currArray = allArrays.GetArrayByName(shadowRenew[i1].first.second); DIST::Array* shadowArray = allArrays.GetArrayByName(shadowRenew[i1].first.second);
if (inserted != 0) if (inserted != 0)
{ {
@@ -880,13 +905,13 @@ ParallelDirective::genDirective(File* file, const vector<pair<DIST::Array*, cons
} }
shadowAdd += shadowRenew[i1].first.first + "(" + bounds + ")"; shadowAdd += shadowRenew[i1].first.first + "(" + bounds + ")";
SgArrayRefExp* newArrayRef = new SgArrayRefExp(*getFromModule(byUseInFunc, currArray->GetDeclSymbol(filename, lineRange, allFiles))); SgArrayRefExp* newArrayRef = new SgArrayRefExp(*getFromModule(byUseInFunc, shadowArray->GetDeclSymbol(filename, lineRange, allFiles)));
newArrayRef->addAttribute(ARRAY_REF, currArray, sizeof(DIST::Array)); newArrayRef->addAttribute(ARRAY_REF, shadowArray, sizeof(DIST::Array));
for (auto& elem : genSubscripts(shadowRenew[i1].second, shadowRenewShifts[i1])) for (auto& elem : genSubscripts(shadowRenew[i1].second, shadowRenewShifts[i1]))
newArrayRef->addSubscript(*elem); 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); SgExpression* tmp = new SgExpression(ARRAY_OP, newArrayRef, NULL, NULL);
p->setLhs(*tmp); p->setLhs(*tmp);

View File

@@ -1295,14 +1295,17 @@ void DvmhRegionInserter::createInterfaceBlockForParallelFunctions(bool onlyRouti
for (auto& callTo : parF->callsTo) for (auto& callTo : parF->callsTo)
{ {
if (callTo->fileName != parF->fileName && isPure(parF->funcPointer->GetOriginal())) if (!isPure(parF->funcPointer->GetOriginal()))
{ continue;
if (onlyRoutine)
{
insertRoutine(parF->funcPointer->GetOriginal(), parF, inLoops, arrayLinksByFuncCalls);
continue;
}
if (callTo->fileName != parF->fileName && onlyRoutine)
{
insertRoutine(parF->funcPointer->GetOriginal(), parF, inLoops, arrayLinksByFuncCalls);
continue;
}
if (callTo->fileName != parF->fileName || isPure(callTo->funcPointer->GetOriginal()))
{
auto it = callTo->interfaceBlocks.find(parF->funcName); auto it = callTo->interfaceBlocks.find(parF->funcName);
if (it == callTo->interfaceBlocks.end()) if (it == callTo->interfaceBlocks.end())
{ {

View File

@@ -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 = ""; string strUnparse = "";
if (toString) if (toString)
strUnparse = string(file->firstStatement()->unparse()); {
if (!isEmpty)
strUnparse = string(file->firstStatement()->unparse());
}
else else
{ {
const string tmp = file->firstStatement()->unparse(); if (!isEmpty)
if (tmp.size() > 0)
{ {
#ifdef _WIN32 #ifdef _WIN32
FILE* fOut; FILE* fOut;

View File

@@ -1,3 +1,3 @@
#pragma once #pragma once
#define VERSION_SPF "2383" #define VERSION_SPF "2384"