fixed and improved private array resizing pass
This commit is contained in:
@@ -1061,11 +1061,7 @@ static bool runAnalysis(SgProject &project, const int curr_regime, const bool ne
|
|||||||
{
|
{
|
||||||
auto founded = loopGraph.find(file->filename());
|
auto founded = loopGraph.find(file->filename());
|
||||||
if (founded != loopGraph.end())
|
if (founded != loopGraph.end())
|
||||||
{
|
privateArraysResizing(file, founded->second, getObjectForFileFromMap(file_name, SPF_messages), countOfTransform, usersDirectives, true);
|
||||||
int err = privateArraysResizing(file, founded->second, getObjectForFileFromMap(file_name, SPF_messages), usersDirectives, true);
|
|
||||||
if (err != 0)
|
|
||||||
internalExit = -1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if (curr_regime == PRIVATE_ARRAYS_SHRINKING_ANALYSIS)
|
else if (curr_regime == PRIVATE_ARRAYS_SHRINKING_ANALYSIS)
|
||||||
{
|
{
|
||||||
@@ -1077,11 +1073,7 @@ static bool runAnalysis(SgProject &project, const int curr_regime, const bool ne
|
|||||||
{
|
{
|
||||||
auto founded = loopGraph.find(file->filename());
|
auto founded = loopGraph.find(file->filename());
|
||||||
if (founded != loopGraph.end())
|
if (founded != loopGraph.end())
|
||||||
{
|
privateArraysResizing(file, founded->second, getObjectForFileFromMap(file_name, SPF_messages), countOfTransform, usersDirectives, false);
|
||||||
int err = privateArraysResizing(file, founded->second, getObjectForFileFromMap(file_name, SPF_messages), usersDirectives, false);
|
|
||||||
if (err != 0)
|
|
||||||
internalExit = -1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if(curr_regime == LOOPS_SPLITTER)
|
else if(curr_regime == LOOPS_SPLITTER)
|
||||||
{
|
{
|
||||||
@@ -1195,7 +1187,8 @@ static bool runAnalysis(SgProject &project, const int curr_regime, const bool ne
|
|||||||
if (internalExit < 0)
|
if (internalExit < 0)
|
||||||
throw -1;
|
throw -1;
|
||||||
|
|
||||||
bool applyFor = (curr_regime == LOOPS_SPLITTER || curr_regime == LOOPS_COMBINER || curr_regime == PRIVATE_REMOVING);
|
bool applyFor = (curr_regime == LOOPS_SPLITTER || curr_regime == LOOPS_COMBINER || curr_regime == PRIVATE_REMOVING ||
|
||||||
|
curr_regime == PRIVATE_ARRAYS_EXPANSION || curr_regime == PRIVATE_ARRAYS_SHRINKING);
|
||||||
if ((countOfTransform == 0 || internalExit > 0) && applyFor)
|
if ((countOfTransform == 0 || internalExit > 0) && applyFor)
|
||||||
{
|
{
|
||||||
SgStatement* mainUnit = findMainUnit(&project, SPF_messages);
|
SgStatement* mainUnit = findMainUnit(&project, SPF_messages);
|
||||||
|
|||||||
@@ -135,13 +135,17 @@ static const string constructNewBoundName(const char *oldName, int loopLineNumbe
|
|||||||
return newName;
|
return newName;
|
||||||
}
|
}
|
||||||
|
|
||||||
static SgSymbol* createNewArrayNameSymbol(SgExpression* declaration, bool isExpansion)
|
static SgSymbol* createNewArrayNameSymbol(SgExpression* declaration, bool isExpansion, bool canBeStatic)
|
||||||
{
|
{
|
||||||
SgType* type = new SgType(T_ARRAY);
|
SgType* type = new SgType(T_ARRAY);
|
||||||
char* newNameStr = constructNewArrayName(declaration->symbol()->identifier(), isExpansion);
|
char* newNameStr = constructNewArrayName(declaration->symbol()->identifier(), isExpansion);
|
||||||
SgSymbol* newName = new SgSymbol(VARIABLE_NAME, newNameStr, type, NULL);
|
SgSymbol* newName = new SgSymbol(VARIABLE_NAME, newNameStr, type, NULL);
|
||||||
newName->setAttribute(declaration->symbol()->attributes());
|
|
||||||
|
|
||||||
|
auto attrs = declaration->symbol()->attributes();
|
||||||
|
if (!canBeStatic)
|
||||||
|
attrs |= ALLOCATABLE_BIT;
|
||||||
|
|
||||||
|
newName->setAttribute(attrs);
|
||||||
return newName;
|
return newName;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -155,7 +159,17 @@ static void fillLoopBoundExprs(const LoopGraph* forLoop, int depthOfResize, cons
|
|||||||
{
|
{
|
||||||
if (indexes[j] && isEqSymbols(loopStmt->doName(), indexes[j]))
|
if (indexes[j] && isEqSymbols(loopStmt->doName(), indexes[j]))
|
||||||
{
|
{
|
||||||
|
//TODO: add MIN and MAX call for bounds
|
||||||
|
if (curLoop->stepVal == 0)
|
||||||
|
{
|
||||||
|
__spf_print(1, "unknown step sign of loop on line %d\n", curLoop->lineNum);
|
||||||
|
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (curLoop->stepVal > 0)
|
||||||
bounds[j] = new SgExpression(DDOT, loopStmt->start()->copyPtr(), loopStmt->end()->copyPtr(), NULL);
|
bounds[j] = new SgExpression(DDOT, loopStmt->start()->copyPtr(), loopStmt->end()->copyPtr(), NULL);
|
||||||
|
else
|
||||||
|
bounds[j] = new SgExpression(DDOT, loopStmt->end()->copyPtr(), loopStmt->start()->copyPtr(), NULL);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -335,7 +349,7 @@ static SgSymbol* alterExtendArrayDeclaration(const LoopGraph* forLoop, SgStateme
|
|||||||
SgExpression* array = findSymbolInExprList(arraySymbol, declarationStmt->expr(0));
|
SgExpression* array = findSymbolInExprList(arraySymbol, declarationStmt->expr(0));
|
||||||
|
|
||||||
SgExpression* newArray = array->copyPtr();
|
SgExpression* newArray = array->copyPtr();
|
||||||
newArraySymbol = createNewArrayNameSymbol(newArray, true);
|
newArraySymbol = createNewArrayNameSymbol(newArray, true, canBeStatic);
|
||||||
if (newArraySymbol == NULL)
|
if (newArraySymbol == NULL)
|
||||||
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
||||||
|
|
||||||
@@ -350,13 +364,14 @@ static SgSymbol* alterExtendArrayDeclaration(const LoopGraph* forLoop, SgStateme
|
|||||||
return newArraySymbol;
|
return newArraySymbol;
|
||||||
}
|
}
|
||||||
|
|
||||||
static SgSymbol* alterShrinkArrayDeclaration(SgStatement *declarationStatement, SgSymbol *arraySymbol, vector<int> &dimensions)
|
static SgSymbol* alterShrinkArrayDeclaration(SgStatement *declarationStatement, SgSymbol *arraySymbol,
|
||||||
|
vector<int> &dimensions, bool canBeStatic)
|
||||||
{
|
{
|
||||||
SgSymbol *newArraySymbol = NULL;
|
SgSymbol *newArraySymbol = NULL;
|
||||||
SgExpression *array = findSymbolInExprList(arraySymbol, declarationStatement->expr(0));
|
SgExpression *array = findSymbolInExprList(arraySymbol, declarationStatement->expr(0));
|
||||||
|
|
||||||
SgExpression *newArray = array->copyPtr();
|
SgExpression *newArray = array->copyPtr();
|
||||||
newArraySymbol = createNewArrayNameSymbol(newArray, false);
|
newArraySymbol = createNewArrayNameSymbol(newArray, false, canBeStatic);
|
||||||
|
|
||||||
reduceArray(dimensions, newArray, newArraySymbol);
|
reduceArray(dimensions, newArray, newArraySymbol);
|
||||||
|
|
||||||
@@ -369,35 +384,25 @@ static SgSymbol* alterShrinkArrayDeclaration(SgStatement *declarationStatement,
|
|||||||
return newArraySymbol;
|
return newArraySymbol;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void extendArrayRefsInExpr(const vector<SgSymbol*>& indexes, SgExpression* expr, SgSymbol* arraySymbol,
|
static void extendArrayRefsInExpr(const vector<SgSymbol*>& indexes, SgExpression* expr,
|
||||||
SgSymbol* newArraySymbol, const vector<SgExpression*>& lowBounds)
|
SgSymbol* arraySymbol, SgSymbol* newArraySymbol,
|
||||||
|
const vector<SgExpression*>& lowBounds)
|
||||||
{
|
{
|
||||||
SgExpression *lhs = expr->lhs(), *rhs = expr->rhs();
|
if (expr)
|
||||||
|
{
|
||||||
|
extendArrayRefsInExpr(indexes, expr->lhs(), arraySymbol, newArraySymbol, lowBounds);
|
||||||
|
extendArrayRefsInExpr(indexes, expr->rhs(), arraySymbol, newArraySymbol, lowBounds);
|
||||||
|
|
||||||
if (lhs)
|
if (isArrayRef(expr) && isEqSymbols(arraySymbol, expr->symbol()))
|
||||||
|
extendArrayRef(indexes, expr, newArraySymbol, lowBounds);
|
||||||
|
else if (expr->variant() == VAR_REF && isEqSymbols(arraySymbol, expr->symbol()))
|
||||||
{
|
{
|
||||||
if (isArrayRef(lhs) && isEqSymbols(arraySymbol, lhs->symbol()))
|
SgExpression* extended = extendArrayRef(indexes, expr, newArraySymbol, lowBounds);
|
||||||
extendArrayRef(indexes, lhs, newArraySymbol, lowBounds);
|
|
||||||
else if (lhs->variant() == VAR_REF && isEqSymbols(arraySymbol, lhs->symbol()))
|
|
||||||
{
|
|
||||||
SgExpression* extended = extendArrayRef(indexes, lhs, newArraySymbol, lowBounds);
|
|
||||||
expr->setLhs(extended);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
extendArrayRefsInExpr(indexes, lhs, arraySymbol, newArraySymbol, lowBounds);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (rhs)
|
expr->setSymbol(extended->symbol());
|
||||||
{
|
expr->setLhs(extended->lhs());
|
||||||
if (isArrayRef(rhs) && isEqSymbols(arraySymbol, rhs->symbol()))
|
expr->setRhs(extended->rhs());
|
||||||
extendArrayRef(indexes, rhs, newArraySymbol, lowBounds);
|
|
||||||
else if (rhs->variant() == VAR_REF && isEqSymbols(arraySymbol, rhs->symbol()))
|
|
||||||
{
|
|
||||||
SgExpression* extended = extendArrayRef(indexes, rhs, newArraySymbol, lowBounds);
|
|
||||||
expr->setRhs(extended);
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
extendArrayRefsInExpr(indexes, rhs, arraySymbol, newArraySymbol, lowBounds);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -406,19 +411,23 @@ static void extendArrayRefs(const vector<SgSymbol*> &indexes, SgStatement *st, S
|
|||||||
{
|
{
|
||||||
for (int i = 0; i < 3; ++i)
|
for (int i = 0; i < 3; ++i)
|
||||||
{
|
{
|
||||||
|
if (st->variant() == PROC_STAT)
|
||||||
|
{
|
||||||
|
SgCallStmt* call = isSgCallStmt(st);
|
||||||
|
for (int arg = 0; arg < call->numberOfArgs(); ++arg)
|
||||||
|
{
|
||||||
|
auto argRef = call->arg(arg);
|
||||||
|
if ((isArrayRef(argRef) || argRef->variant() == VAR_REF) && isEqSymbols(argRef->symbol(), arraySymbol))
|
||||||
|
{
|
||||||
|
__spf_print(1, "unsupported private array extension under call on line %d\n", st->lineNumber());
|
||||||
|
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (st->expr(i))
|
if (st->expr(i))
|
||||||
{
|
|
||||||
if (isArrayRef(st->expr(i)) && isEqSymbols(arraySymbol, st->expr(i)->symbol()))
|
|
||||||
extendArrayRef(indexes, st->expr(i), newArraySymbol, lowBounds);
|
|
||||||
else if (st->expr(i)->variant() == VAR_REF && isEqSymbols(arraySymbol, st->expr(i)->symbol()))
|
|
||||||
{
|
|
||||||
SgExpression* extended = extendArrayRef(indexes, st->expr(i), newArraySymbol, lowBounds);
|
|
||||||
st->setExpression(i, *extended);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
extendArrayRefsInExpr(indexes, st->expr(i), arraySymbol, newArraySymbol, lowBounds);
|
extendArrayRefsInExpr(indexes, st->expr(i), arraySymbol, newArraySymbol, lowBounds);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static SgStatement* createNewDeclarationStatemnet(SgStatement *loop, SgStatement *originalDeclaration, SgSymbol *arraySymbol)
|
static SgStatement* createNewDeclarationStatemnet(SgStatement *loop, SgStatement *originalDeclaration, SgSymbol *arraySymbol)
|
||||||
@@ -428,6 +437,8 @@ static SgStatement* createNewDeclarationStatemnet(SgStatement *loop, SgStatement
|
|||||||
{
|
{
|
||||||
if (isSgExecutableStatement(lastDecl))
|
if (isSgExecutableStatement(lastDecl))
|
||||||
break;
|
break;
|
||||||
|
if (lastDecl->variant() == CONTAINS_STMT)
|
||||||
|
break;
|
||||||
lastDecl = lastDecl->lexNext();
|
lastDecl = lastDecl->lexNext();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -559,7 +570,7 @@ static SgExpression* constructArrayAllocationExp(const LoopGraph* forLoop, SgExp
|
|||||||
return new SgExpression(EXPR_LIST, arrayRef, (SgExpression*)NULL, (SgSymbol*)NULL);
|
return new SgExpression(EXPR_LIST, arrayRef, (SgExpression*)NULL, (SgSymbol*)NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void insertAllocDealloc(const LoopGraph* forLoop, SgSymbol* origArraySymbol, SgSymbol* arraySymbol,
|
static void insertAllocDealloc(const LoopGraph* forLoop, SgSymbol* origArraySymbol, SgSymbol* arraySymbol, SgSymbol* allocDone,
|
||||||
bool isExpansion, const vector<SgSymbol*>* indexes = NULL, const vector<int>* shrinkIndexes = NULL)
|
bool isExpansion, const vector<SgSymbol*>* indexes = NULL, const vector<int>* shrinkIndexes = NULL)
|
||||||
{
|
{
|
||||||
SgForStmt *loopStmt = (SgForStmt*)(forLoop->loop->GetOriginal());
|
SgForStmt *loopStmt = (SgForStmt*)(forLoop->loop->GetOriginal());
|
||||||
@@ -589,11 +600,17 @@ static void insertAllocDealloc(const LoopGraph* forLoop, SgSymbol* origArraySymb
|
|||||||
new SgExpression(ARRAY_REF, (SgExpression*)NULL, (SgExpression*)NULL, arraySymbol),
|
new SgExpression(ARRAY_REF, (SgExpression*)NULL, (SgExpression*)NULL, arraySymbol),
|
||||||
(SgExpression*)NULL, (SgSymbol*)NULL);
|
(SgExpression*)NULL, (SgSymbol*)NULL);
|
||||||
|
|
||||||
SgStatement *allocate = new SgStatement(ALLOCATE_STMT, (SgLabel*)NULL, (SgSymbol*)NULL, arrayAllocation, (SgExpression*)NULL, (SgExpression*)NULL);
|
|
||||||
SgStatement *deallocate = new SgStatement(DEALLOCATE_STMT, (SgLabel*)NULL, (SgSymbol*)NULL, arrayDeallocation, (SgExpression*)NULL, (SgExpression*)NULL);
|
|
||||||
|
|
||||||
loopStmt->insertStmtBefore(*allocate, *loopStmt->controlParent());
|
|
||||||
loopStmt->lastNodeOfStmt()->insertStmtAfter(*deallocate, *loopStmt->controlParent());
|
SgStatement *allocate = new SgStatement(ALLOCATE_STMT, (SgLabel*)NULL, (SgSymbol*)NULL, arrayAllocation, (SgExpression*)NULL, (SgExpression*)NULL);
|
||||||
|
SgIfStmt* ifSt = new SgIfStmt(SgEqOp(*new SgVarRefExp(allocDone), *new SgValueExp(0)), *allocate);
|
||||||
|
|
||||||
|
loopStmt->insertStmtBefore(*ifSt, *loopStmt->controlParent());
|
||||||
|
|
||||||
|
|
||||||
|
// insert allocates as save
|
||||||
|
//SgStatement* deallocate = new SgStatement(DEALLOCATE_STMT, (SgLabel*)NULL, (SgSymbol*)NULL, arrayDeallocation, (SgExpression*)NULL, (SgExpression*)NULL);
|
||||||
|
//loopStmt->lastNodeOfStmt()->insertStmtAfter(*deallocate, *loopStmt->controlParent());
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool containsFunctionCall(SgExpression* exp)
|
static bool containsFunctionCall(SgExpression* exp)
|
||||||
@@ -781,6 +798,61 @@ static void renamePrivateVarsInAttributes(const vector<SgStatement*>& attrs, con
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void removePrivateVarsInAttributes(const vector<SgStatement*>& attrs, const map<SgSymbol*, SgSymbol*>& symbols)
|
||||||
|
{
|
||||||
|
for (SgStatement* st : attrs)
|
||||||
|
{
|
||||||
|
if (st->variant() != SPF_ANALYSIS_DIR)
|
||||||
|
return;
|
||||||
|
|
||||||
|
SgExpression* exprList = st->expr(0);
|
||||||
|
vector<SgExpression*> newL;
|
||||||
|
bool remList = false;
|
||||||
|
while (exprList)
|
||||||
|
{
|
||||||
|
if (exprList->lhs()->variant() == ACC_PRIVATE_OP)
|
||||||
|
{
|
||||||
|
vector<SgExpression*> newL;
|
||||||
|
bool removed = false;
|
||||||
|
SgExpression* list = exprList->lhs()->lhs();
|
||||||
|
while (list)
|
||||||
|
{
|
||||||
|
bool found = false;
|
||||||
|
for (auto& pair : symbols)
|
||||||
|
{
|
||||||
|
if (isEqSymbols(pair.first, list->lhs()->symbol()))
|
||||||
|
found = true;
|
||||||
|
if (found)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (!found)
|
||||||
|
newL.push_back(list->lhs());
|
||||||
|
else
|
||||||
|
removed = true;
|
||||||
|
list = list->rhs();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (removed)
|
||||||
|
{
|
||||||
|
if (newL.size() == 0)
|
||||||
|
remList = true;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
exprList->lhs()->setLhs(makeExprList(newL));
|
||||||
|
newL.push_back(exprList->lhs());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
newL.push_back(exprList->lhs());
|
||||||
|
exprList = exprList->rhs();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (remList)
|
||||||
|
st->setExpression(0, makeExprList(newL));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static int getArrayDimensionality(SgSymbol* array)
|
static int getArrayDimensionality(SgSymbol* array)
|
||||||
{
|
{
|
||||||
if (array->type()->variant() != T_ARRAY)
|
if (array->type()->variant() != T_ARRAY)
|
||||||
@@ -975,7 +1047,7 @@ static int fillIndexesToExtend(const LoopGraph* loop, int origDim, int depthOfRe
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static SgSymbol* shrinkArray(const LoopGraph *forLoop, SgSymbol *arraySymbol, vector<int> &indexes)
|
static SgSymbol* shrinkArray(const LoopGraph *forLoop, SgSymbol *arraySymbol, vector<int> &indexes, SgSymbol *allocDone)
|
||||||
{
|
{
|
||||||
int maxDepth = forLoop->perfectLoop;
|
int maxDepth = forLoop->perfectLoop;
|
||||||
const LoopGraph *curLoop = forLoop;
|
const LoopGraph *curLoop = forLoop;
|
||||||
@@ -1005,16 +1077,17 @@ static SgSymbol* shrinkArray(const LoopGraph *forLoop, SgSymbol *arraySymbol, ve
|
|||||||
SgStatement *originalDeclaration = declaratedInStmt(arraySymbol);
|
SgStatement *originalDeclaration = declaratedInStmt(arraySymbol);
|
||||||
SgStatement *copiedDeclaration = createNewDeclarationStatemnet(forLoop->loop->GetOriginal(), originalDeclaration, arraySymbol);
|
SgStatement *copiedDeclaration = createNewDeclarationStatemnet(forLoop->loop->GetOriginal(), originalDeclaration, arraySymbol);
|
||||||
|
|
||||||
|
bool canBeStatic = !(!reduceToVariable && isAllocatable(arraySymbol));
|
||||||
SgSymbol *newSymbol = reduceToVariable
|
SgSymbol *newSymbol = reduceToVariable
|
||||||
? createReducedToVariableArray(copiedDeclaration, forLoop->lineNum, arraySymbol)
|
? createReducedToVariableArray(copiedDeclaration, forLoop->lineNum, arraySymbol)
|
||||||
: alterShrinkArrayDeclaration(copiedDeclaration, arraySymbol, indexes);
|
: alterShrinkArrayDeclaration(copiedDeclaration, arraySymbol, indexes, canBeStatic);
|
||||||
|
|
||||||
if (newSymbol)
|
if (newSymbol)
|
||||||
{
|
{
|
||||||
SgForStmt *loopStmt = (SgForStmt*)(forLoop->loop->GetOriginal());
|
SgForStmt *loopStmt = (SgForStmt*)(forLoop->loop->GetOriginal());
|
||||||
|
|
||||||
if (!reduceToVariable && isAllocatable(arraySymbol))
|
if (!reduceToVariable && isAllocatable(arraySymbol))
|
||||||
insertAllocDealloc(forLoop, arraySymbol, newSymbol, false, NULL, &indexes);
|
insertAllocDealloc(forLoop, arraySymbol, newSymbol, false, allocDone, NULL, &indexes);
|
||||||
|
|
||||||
for (SgStatement *st = loopStmt->lexNext(); st != loopStmt->lastNodeOfStmt()->lexNext(); st = st->lexNext())
|
for (SgStatement *st = loopStmt->lexNext(); st != loopStmt->lastNodeOfStmt()->lexNext(); st = st->lexNext())
|
||||||
if (st->variant() != ALLOCATE_STMT && st->variant() != DEALLOCATE_STMT)
|
if (st->variant() != ALLOCATE_STMT && st->variant() != DEALLOCATE_STMT)
|
||||||
@@ -1026,7 +1099,7 @@ static SgSymbol* shrinkArray(const LoopGraph *forLoop, SgSymbol *arraySymbol, ve
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static SgSymbol* resizeArray(const LoopGraph *forLoop, SgSymbol *arraySymbol, int depthOfResize)
|
static SgSymbol* resizeArray(const LoopGraph *forLoop, SgSymbol *arraySymbol, int depthOfResize, SgSymbol *allocDone)
|
||||||
{
|
{
|
||||||
if (depthOfResize < 0 || depthOfResize > forLoop->perfectLoop)
|
if (depthOfResize < 0 || depthOfResize > forLoop->perfectLoop)
|
||||||
depthOfResize = forLoop->perfectLoop;
|
depthOfResize = forLoop->perfectLoop;
|
||||||
@@ -1074,7 +1147,8 @@ static SgSymbol* resizeArray(const LoopGraph *forLoop, SgSymbol *arraySymbol, in
|
|||||||
{
|
{
|
||||||
SgForStmt *loopStmt = (SgForStmt*)(forLoop->loop->GetOriginal());
|
SgForStmt *loopStmt = (SgForStmt*)(forLoop->loop->GetOriginal());
|
||||||
if (!canBeStatic || isAllocatable(newArraySymbol))
|
if (!canBeStatic || isAllocatable(newArraySymbol))
|
||||||
insertAllocDealloc(forLoop, arraySymbol, newArraySymbol, true, &indexes, NULL);
|
insertAllocDealloc(forLoop, arraySymbol, newArraySymbol, allocDone, true, &indexes, NULL);
|
||||||
|
|
||||||
for (SgStatement *st = loopStmt->lexNext(); st != loopStmt->lastNodeOfStmt()->lexNext(); st = st->lexNext())
|
for (SgStatement *st = loopStmt->lexNext(); st != loopStmt->lastNodeOfStmt()->lexNext(); st = st->lexNext())
|
||||||
if (st->variant() != ALLOCATE_STMT && st->variant() != DEALLOCATE_STMT)
|
if (st->variant() != ALLOCATE_STMT && st->variant() != DEALLOCATE_STMT)
|
||||||
extendArrayRefs(indexes, st, arraySymbol, newArraySymbol, lowBounds);
|
extendArrayRefs(indexes, st, arraySymbol, newArraySymbol, lowBounds);
|
||||||
@@ -1257,13 +1331,27 @@ void analyzeShrinking(SgFile* file, const vector<LoopGraph*>& loopGraphs, vector
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void createAllocDoneSymbol(map<SgStatement*, SgSymbol*>& allocDoneByFunc, SgStatement* func)
|
||||||
|
{
|
||||||
|
if (allocDoneByFunc.find(func) == allocDoneByFunc.end())
|
||||||
|
{
|
||||||
|
auto newName = (string("spf_") + string(func->symbol()->identifier()) + "_alloc_");
|
||||||
|
allocDoneByFunc[func] = new SgSymbol(VARIABLE_NAME, newName.c_str(), SgTypeInt(), func);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//Вычислять размер массива с учётом шага цикла - //TODO
|
//Вычислять размер массива с учётом шага цикла - //TODO
|
||||||
int privateArraysResizing(SgFile *file, const vector<LoopGraph*> &loopGraphs, vector<Messages> &messages,
|
void privateArraysResizing(SgFile *file, const vector<LoopGraph*> &loopGraphs, vector<Messages> &messages, int& countOfTransform,
|
||||||
const map<pair<string, int>, set<SgStatement*>>& usersDirectives, bool isExpand)
|
const map<pair<string, int>, set<SgStatement*>>& usersDirectives, bool isExpand)
|
||||||
{
|
{
|
||||||
map<int, LoopGraph*> mapLoopGraph;
|
map<int, LoopGraph*> mapLoopGraph;
|
||||||
createMapLoopGraph(loopGraphs, mapLoopGraph);
|
createMapLoopGraph(loopGraphs, mapLoopGraph);
|
||||||
|
|
||||||
|
map<SgStatement*, SgSymbol*> allocDoneByFunc;
|
||||||
|
map<SgStatement*, SgSymbol*> usedAllocDoneByFunc;
|
||||||
|
|
||||||
|
map<SgStatement*, vector<SgExpression*>> saveDecls;
|
||||||
|
|
||||||
for (auto &loopPair : mapLoopGraph)
|
for (auto &loopPair : mapLoopGraph)
|
||||||
{
|
{
|
||||||
LoopGraph *loop = loopPair.second;
|
LoopGraph *loop = loopPair.second;
|
||||||
@@ -1275,6 +1363,9 @@ int privateArraysResizing(SgFile *file, const vector<LoopGraph*> &loopGraphs, ve
|
|||||||
auto attrPrivInCode = getAttributes<SgStatement*, SgStatement*>(loopSt, set<int>{ SPF_ANALYSIS_DIR });
|
auto attrPrivInCode = getAttributes<SgStatement*, SgStatement*>(loopSt, set<int>{ SPF_ANALYSIS_DIR });
|
||||||
|
|
||||||
auto arrayPrivates = fillPrivates(usersDirectives, loop);
|
auto arrayPrivates = fillPrivates(usersDirectives, loop);
|
||||||
|
auto func = getFuncStat(loopSt);
|
||||||
|
|
||||||
|
set<SgSymbol*> symbolsToDecl;
|
||||||
|
|
||||||
if (arrayPrivates.size() == 0)
|
if (arrayPrivates.size() == 0)
|
||||||
{
|
{
|
||||||
@@ -1284,9 +1375,7 @@ int privateArraysResizing(SgFile *file, const vector<LoopGraph*> &loopGraphs, ve
|
|||||||
else
|
else
|
||||||
__spf_printToBuf(str, "Can not do PRIVATE SHRINK for this loop - privates not found");
|
__spf_printToBuf(str, "Can not do PRIVATE SHRINK for this loop - privates not found");
|
||||||
|
|
||||||
//TODO:
|
__spf_print(0, "%s on line %d\n", str.c_str(), loop->lineNum);
|
||||||
//messages.push_back(Messages(NOTE, loop->lineNum, str, 2008));
|
|
||||||
__spf_print(1, "%s on line %d\n", str.c_str(), loop->lineNum);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -1302,6 +1391,8 @@ int privateArraysResizing(SgFile *file, const vector<LoopGraph*> &loopGraphs, ve
|
|||||||
|
|
||||||
if (list->lhs()->variant() == SPF_EXPAND_OP && isExpand)
|
if (list->lhs()->variant() == SPF_EXPAND_OP && isExpand)
|
||||||
{
|
{
|
||||||
|
createAllocDoneSymbol(allocDoneByFunc, func);
|
||||||
|
|
||||||
int deep = -1;
|
int deep = -1;
|
||||||
if (list->lhs()->lhs() != NULL)
|
if (list->lhs()->lhs() != NULL)
|
||||||
{
|
{
|
||||||
@@ -1312,14 +1403,24 @@ int privateArraysResizing(SgFile *file, const vector<LoopGraph*> &loopGraphs, ve
|
|||||||
|
|
||||||
for (SgSymbol* privArr : arrayPrivates)
|
for (SgSymbol* privArr : arrayPrivates)
|
||||||
{
|
{
|
||||||
SgSymbol* newSymbol = resizeArray(loop, privArr, deep);
|
SgSymbol* newSymbol = resizeArray(loop, privArr, deep, allocDoneByFunc[func]);
|
||||||
|
|
||||||
if (newSymbol)
|
if (newSymbol)
|
||||||
|
{
|
||||||
symbols.insert(std::make_pair(privArr, newSymbol));
|
symbols.insert(std::make_pair(privArr, newSymbol));
|
||||||
|
usedAllocDoneByFunc[func] = allocDoneByFunc[func];
|
||||||
|
countOfTransform++;
|
||||||
|
|
||||||
|
if (isAllocatable(newSymbol))
|
||||||
|
symbolsToDecl.insert(newSymbol);
|
||||||
}
|
}
|
||||||
renamePrivateVarsInAttributes(attrPrivInCode, symbols);
|
}
|
||||||
|
removePrivateVarsInAttributes(attrPrivInCode, symbols);
|
||||||
}
|
}
|
||||||
else if (list->lhs()->variant() == SPF_SHRINK_OP && !isExpand)
|
else if (list->lhs()->variant() == SPF_SHRINK_OP && !isExpand)
|
||||||
{
|
{
|
||||||
|
createAllocDoneSymbol(allocDoneByFunc, func);
|
||||||
|
|
||||||
SgExprListExp* listExp = isSgExprListExp(list->lhs()->lhs());
|
SgExprListExp* listExp = isSgExprListExp(list->lhs()->lhs());
|
||||||
checkNull(listExp, convertFileName(__FILE__).c_str(), __LINE__);
|
checkNull(listExp, convertFileName(__FILE__).c_str(), __LINE__);
|
||||||
|
|
||||||
@@ -1335,9 +1436,17 @@ int privateArraysResizing(SgFile *file, const vector<LoopGraph*> &loopGraphs, ve
|
|||||||
|
|
||||||
if (!indexes.empty() && !skip)
|
if (!indexes.empty() && !skip)
|
||||||
{
|
{
|
||||||
SgSymbol* newSymbol = shrinkArray(loop, privArr, indexes);
|
SgSymbol* newSymbol = shrinkArray(loop, privArr, indexes, allocDoneByFunc[func]);
|
||||||
|
|
||||||
if (newSymbol)
|
if (newSymbol)
|
||||||
|
{
|
||||||
symbols.insert(std::make_pair(privArr, newSymbol));
|
symbols.insert(std::make_pair(privArr, newSymbol));
|
||||||
|
usedAllocDoneByFunc[func] = allocDoneByFunc[func];
|
||||||
|
countOfTransform++;
|
||||||
|
|
||||||
|
if (isAllocatable(newSymbol))
|
||||||
|
symbolsToDecl.insert(newSymbol);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
renamePrivateVarsInAttributes(attrPrivInCode, symbols);
|
renamePrivateVarsInAttributes(attrPrivInCode, symbols);
|
||||||
@@ -1348,23 +1457,39 @@ int privateArraysResizing(SgFile *file, const vector<LoopGraph*> &loopGraphs, ve
|
|||||||
list = list->rhs();
|
list = list->rhs();
|
||||||
}
|
}
|
||||||
|
|
||||||
SgExpression *ex = NULL;
|
attr->setExpression(0, makeExprList(newL, false));
|
||||||
SgExpression *p = NULL;
|
|
||||||
for (int z = 0; z < newL.size(); ++z)
|
|
||||||
{
|
|
||||||
if (z == 0)
|
|
||||||
p = ex = newL[z];
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ex->setRhs(newL[z]);
|
|
||||||
ex = ex->rhs();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
attr->setExpression(0, p);
|
|
||||||
//__spf_print(1, "set new %d attributes to line %d\n", newL.size(), loop->lineNum);
|
//__spf_print(1, "set new %d attributes to line %d\n", newL.size(), loop->lineNum);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (auto& elem : symbolsToDecl)
|
||||||
|
saveDecls[func].push_back(new SgVarRefExp(elem));
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
for (auto& funcPair : saveDecls)
|
||||||
|
{
|
||||||
|
auto func = funcPair.first;
|
||||||
|
if (usedAllocDoneByFunc.find(func) == usedAllocDoneByFunc.end())
|
||||||
|
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
||||||
|
|
||||||
|
SgSymbol* allocVar = usedAllocDoneByFunc[func];
|
||||||
|
auto list = makeExprList(funcPair.second);
|
||||||
|
SgStatement* save = new SgStatement(SAVE_DECL, NULL, NULL, list);
|
||||||
|
|
||||||
|
SgStatement* st = func->lexNext();
|
||||||
|
while (!isSgExecutableStatement(st))
|
||||||
|
{
|
||||||
|
if (st->variant() == CONTAINS_STMT)
|
||||||
|
break;
|
||||||
|
st = st->lexNext();
|
||||||
|
}
|
||||||
|
|
||||||
|
vector<SgExpression*> init = { new SgValueExp(-1) };
|
||||||
|
makeDeclaration(func, { allocVar }, &init);
|
||||||
|
|
||||||
|
st->insertStmtBefore(*save, *func);
|
||||||
|
|
||||||
|
SgAssignStmt* assign = new SgAssignStmt(*new SgVarRefExp(allocVar), *new SgVarRefExp(allocVar) + *new SgValueExp(1));
|
||||||
|
st->insertStmtBefore(*assign, *func);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,5 +5,5 @@
|
|||||||
#include <set>
|
#include <set>
|
||||||
|
|
||||||
|
|
||||||
int privateArraysResizing(SgFile *file, const std::vector<LoopGraph*> &loopGraphs, std::vector<Messages> &messages, const std::map<std::pair<std::string, int>, std::set<SgStatement*>>& usersDirectives, bool isExpand);
|
void privateArraysResizing(SgFile *file, const std::vector<LoopGraph*> &loopGraphs, std::vector<Messages> &messages, int& countOfTransform, const std::map<std::pair<std::string, int>, std::set<SgStatement*>>& usersDirectives, bool isExpand);
|
||||||
void analyzeShrinking(SgFile* file, const std::vector<LoopGraph*>& loopGraphs, std::vector<Messages>& messages, const std::map<std::pair<std::string, int>, std::set<SgStatement*>>& usersDirectives);
|
void analyzeShrinking(SgFile* file, const std::vector<LoopGraph*>& loopGraphs, std::vector<Messages>& messages, const std::map<std::pair<std::string, int>, std::set<SgStatement*>>& usersDirectives);
|
||||||
@@ -184,6 +184,7 @@ extern int staticShadowAnalysis;
|
|||||||
extern int keepDvmDirectives;
|
extern int keepDvmDirectives;
|
||||||
extern int ignoreIO;
|
extern int ignoreIO;
|
||||||
extern int keepSpfDirs;
|
extern int keepSpfDirs;
|
||||||
|
extern int maxShadowWidth;
|
||||||
|
|
||||||
const string printVersionAsFortranComm()
|
const string printVersionAsFortranComm()
|
||||||
{
|
{
|
||||||
@@ -199,13 +200,14 @@ const string printVersionAsFortranComm()
|
|||||||
ret += "! *** shadow optimization\n";
|
ret += "! *** shadow optimization\n";
|
||||||
if (keepDvmDirectives)
|
if (keepDvmDirectives)
|
||||||
ret += "! *** consider DVMH directives\n";
|
ret += "! *** consider DVMH directives\n";
|
||||||
|
if (keepSpfDirs)
|
||||||
|
ret += "! *** save SPF directives\n";
|
||||||
if (mpiProgram)
|
if (mpiProgram)
|
||||||
ret += "! *** MPI program regime (shared memory parallelization)\n";
|
ret += "! *** MPI program regime (shared memory parallelization)\n";
|
||||||
if (ignoreIO)
|
if (ignoreIO)
|
||||||
ret += "! *** ignore I/O checker for arrays (DVM I/O limitations)\n";
|
ret += "! *** ignore I/O checker for arrays (DVM I/O limitations)\n";
|
||||||
if (keepSpfDirs)
|
if (maxShadowWidth > 0)
|
||||||
ret += "! *** save SPF directives\n";
|
ret += "! *** maximum shadow width is " + std::to_string(maxShadowWidth) + " percent\n";
|
||||||
|
|
||||||
ret += "! *** generated by SAPFOR\n";
|
ret += "! *** generated by SAPFOR\n";
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#define VERSION_SPF "2291"
|
#define VERSION_SPF "2292"
|
||||||
|
|||||||
@@ -1911,6 +1911,14 @@ int SPF_RemoveDeadCode(void*& context, int winHandler, short* options, short* pr
|
|||||||
return simpleTransformPass(REMOVE_DEAD_CODE_AND_UNPARSE, options, projName, folderName, output, outputSize, outputMessage, outputMessageSize);
|
return simpleTransformPass(REMOVE_DEAD_CODE_AND_UNPARSE, options, projName, folderName, output, outputSize, outputMessage, outputMessageSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int SPF_InsertImplicitNone(void*& context, int winHandler, short* options, short* projName, short* folderName, short*& output,
|
||||||
|
int*& outputSize, short*& outputMessage, int*& outputMessageSize)
|
||||||
|
{
|
||||||
|
MessageManager::clearCache();
|
||||||
|
MessageManager::setWinHandler(winHandler);
|
||||||
|
return simpleTransformPass(SET_IMPLICIT_NONE, options, projName, folderName, output, outputSize, outputMessage, outputMessageSize);
|
||||||
|
}
|
||||||
|
|
||||||
static inline void convertBackSlash(char *str, int strL)
|
static inline void convertBackSlash(char *str, int strL)
|
||||||
{
|
{
|
||||||
for (int z = 0; z < strL; ++z)
|
for (int z = 0; z < strL; ++z)
|
||||||
@@ -2625,6 +2633,8 @@ const wstring Sapfor_RunTransformation(const char* transformName_c, const char*
|
|||||||
retCode = SPF_InsertPrivateFromGUI(context, winHandler, optSh, projSh, fold, output, outputSize, outputMessage, outputMessageSize);
|
retCode = SPF_InsertPrivateFromGUI(context, winHandler, optSh, projSh, fold, output, outputSize, outputMessage, outputMessageSize);
|
||||||
else if (whichRun == "SPF_RemoveDeadCode")
|
else if (whichRun == "SPF_RemoveDeadCode")
|
||||||
retCode = SPF_RemoveDeadCode(context, winHandler, optSh, projSh, fold, output, outputSize, outputMessage, outputMessageSize);
|
retCode = SPF_RemoveDeadCode(context, winHandler, optSh, projSh, fold, output, outputSize, outputMessage, outputMessageSize);
|
||||||
|
else if (whichRun == "SPF_InsertImplicitNone")
|
||||||
|
retCode = SPF_InsertImplicitNone(context, winHandler, optSh, projSh, fold, output, outputSize, outputMessage, outputMessageSize);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (showDebug)
|
if (showDebug)
|
||||||
|
|||||||
Reference in New Issue
Block a user