improved privated removing

This commit is contained in:
ALEXks
2024-03-28 21:57:06 +03:00
parent d1022f2a88
commit 09d0195693
4 changed files with 73 additions and 24 deletions

View File

@@ -434,7 +434,7 @@ void removeDeadCode(SgStatement* func,
}
}
}
//TODO: need to add [intervalDelStart; intervalDelEnd]
// remove dead statements
set<int> removable =
{
@@ -445,7 +445,10 @@ void removeDeadCode(SgStatement* func,
};
vector<SgStatement*> remove;
for (auto st = func; st != func->lastNodeOfStmt(); st = st->lexNext())
SgStatement* start = intervalDelStart ? intervalDelStart : func;
SgStatement* end = intervalDelEnd ? intervalDelEnd : func->lastNodeOfStmt();
for (auto st = start; st != end; st = st->lexNext())
{
if (removable.find(st->variant()) != removable.end() && useful.find(st) == useful.end())
{
@@ -462,7 +465,7 @@ void removeDeadCode(SgStatement* func,
remove.clear();
//remove empty blocks
for (auto st = func; st != func->lastNodeOfStmt(); st = st->lexNext())
for (auto st = start; st != end; st = st->lexNext())
{
const int var = st->variant();
if ((var == FOR_NODE || var == WHILE_NODE || var == IF_NODE || var == SWITCH_NODE) &&

View File

@@ -89,19 +89,24 @@ static void fillIterationVariables(const LoopGraph* loop, set<string>& vars, int
}
}
static SgExpression* findSymbolInExprList(SgSymbol* symbol, SgExpression* list)
static SgExpression* findSymbol(SgSymbol* symbol, SgExpression* list)
{
while (list)
if (list)
{
if (list->variant() != EXPR_LIST || list->lhs()->symbol() == NULL)
return NULL;
if (list->variant() == VAR_REF || list->variant() == ARRAY_REF)
{
if (isEqSymbols(list->symbol(), symbol))
return list;
}
if (isEqSymbols(list->lhs()->symbol(), symbol))
return list->lhs();
auto left = findSymbol(symbol, list->lhs());
if (left)
return left;
list = list->rhs();
auto right = findSymbol(symbol, list->rhs());
if (right)
return right;
}
return NULL;
}
@@ -342,11 +347,40 @@ static void setAllocatable(SgStatement *newDecl, SgSymbol *origSymbol)
}
}
static SgExpression* checkArrayDecl(SgExpression* array, SgSymbol* arraySymbol, SgStatement* checkedDecl)
{
if (array->lhs() == NULL)
{
vector<SgStatement*> allDecls;
auto mainDecl = declaratedInStmt(arraySymbol, &allDecls);
if (allDecls.size() < 2)
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
for (auto& decl : allDecls)
{
if (decl == mainDecl)
continue;
if (decl == checkedDecl)
continue;
array = findSymbol(arraySymbol, decl->expr(0));
if (array->lhs())
break;
array = NULL;
}
checkNull(array, convertFileName(__FILE__).c_str(), __LINE__);
}
return array;
}
static SgSymbol* alterExtendArrayDeclaration(const LoopGraph* forLoop, SgStatement* declarationStmt, SgSymbol* arraySymbol,
bool canBeStatic, const vector<SgSymbol*>& indexes)
{
SgSymbol* newArraySymbol = NULL;
SgExpression* array = findSymbolInExprList(arraySymbol, declarationStmt->expr(0));
SgExpression* array = findSymbol(arraySymbol, declarationStmt->expr(0));
array = checkArrayDecl(array, arraySymbol, declarationStmt);
SgExpression* newArray = array->copyPtr();
newArraySymbol = createNewArrayNameSymbol(newArray, true, canBeStatic);
@@ -368,7 +402,7 @@ static SgSymbol* alterShrinkArrayDeclaration(SgStatement *declarationStatement,
vector<int> &dimensions, bool canBeStatic)
{
SgSymbol *newArraySymbol = NULL;
SgExpression *array = findSymbolInExprList(arraySymbol, declarationStatement->expr(0));
SgExpression *array = findSymbol(arraySymbol, declarationStatement->expr(0));
SgExpression *newArray = array->copyPtr();
newArraySymbol = createNewArrayNameSymbol(newArray, false, canBeStatic);
@@ -460,7 +494,9 @@ static SgStatement* createNewDeclarationStatemnet(SgStatement *loop, SgStatement
while (!isEqSymbols(exprList->lhs()->symbol(), arraySymbol))
exprList = exprList->rhs();
SgExpression newExprList(EXPR_LIST, exprList->lhs(), NULL, NULL);
checkNull(exprList, convertFileName(__FILE__).c_str(), __LINE__);
SgExpression newExprList(EXPR_LIST, exprList->lhs()->copyPtr(), NULL, NULL);
SgStatement *newDeclaration = originalDeclaration->copyPtr();
newDeclaration->setExpression(0, newExprList);
@@ -504,7 +540,7 @@ static SgStatement* getAllocationStmt(const LoopGraph* loop, SgSymbol* symbol)
if (alloc->variant() != ALLOCATE_STMT)
continue;
if (NULL == findSymbolInExprList(symbol, alloc->expr(0)))
if (findSymbol(symbol, alloc->expr(0)) == NULL)
continue;
if (allocationStmt == NULL)
@@ -527,10 +563,10 @@ static void fillLowBounds(const LoopGraph* forLoop, SgSymbol* origArraySymbol, S
if (isAllocatable(origArraySymbol))
{
SgStatement* allocationStmt = getAllocationStmt(forLoop, origArraySymbol);
origArray = findSymbolInExprList(origArraySymbol, allocationStmt->expr(0));
origArray = findSymbol(origArraySymbol, allocationStmt->expr(0));
}
else
origArray = findSymbolInExprList(origArraySymbol, originalDecl->expr(0));
origArray = findSymbol(origArraySymbol, originalDecl->expr(0));
SgExpression* arrayRef = origArray->copyPtr();
SgExpression* oldTail = arrayRef->lhs();
@@ -596,10 +632,13 @@ static void insertAllocDealloc(const LoopGraph* forLoop, SgSymbol* origArraySymb
if (isAllocatable(origArraySymbol))
{
SgStatement *allocationStmt = getAllocationStmt(forLoop, origArraySymbol);
origArray = findSymbolInExprList(origArraySymbol, allocationStmt->expr(0));
origArray = findSymbol(origArraySymbol, allocationStmt->expr(0));
}
else
origArray = findSymbolInExprList(origArraySymbol, originalDeclaration->expr(0));
{
origArray = findSymbol(origArraySymbol, originalDeclaration->expr(0));
origArray = checkArrayDecl(origArray, origArraySymbol, originalDeclaration);
}
int depthOfResize = 0;
if (isExpansion)
@@ -765,7 +804,7 @@ static void reduceArrayRefs(SgStatement *st, SgSymbol *arraySymbol, SgSymbol *ne
static void fillIndexesToShrink(SgSymbol* arr, SgExprListExp* listExp, vector<int>& indexes)
{
SgExpression* sym = findSymbolInExprList(arr, listExp);
SgExpression* sym = findSymbol(arr, listExp);
if (sym)
{
SgExpression* expr = sym->lhs();
@@ -1130,7 +1169,8 @@ static SgSymbol* resizeArray(const LoopGraph *forLoop, SgSymbol *arraySymbol, in
for (int i = 0; i < depthOfResize; ++i)
{
if (curLoop->calculatedCountOfIters == 0)
//TODO: add checking for PARAMETER
//if (curLoop->calculatedCountOfIters == 0)
canBeStatic = false;
if (areIndexesFilled != 0)

View File

@@ -833,6 +833,7 @@ void removePrivates(string filename, vector<Messages>& messages,
const map<string, vector<FuncInfo*>>& allFuncInfo,
int& countOfTransform)
{
set<LoopGraph*> removedDC;
for (auto& varToRemove : privatesToRemoveGlobal)
{
if (filename != varToRemove.loop->fileName)
@@ -850,7 +851,12 @@ void removePrivates(string filename, vector<Messages>& messages,
if (currFunc == nullptr)
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
removeDeadCode(currFunc->funcPointer, allFuncInfo, commonBlocks);
if (removedDC.find(varToRemove.loop) == removedDC.end())
{
removeDeadCode(currFunc->funcPointer, allFuncInfo, commonBlocks,
varToRemove.loop->loop, varToRemove.loop->loop->lastNodeOfStmt());
removedDC.insert(varToRemove.loop);
}
vector<SgArrayRefExp*> varRefs = getDirectArrayRefs(loopStmt, varToRemove.varSymbol);
int loopLineNum = varToRemove.loop->lineNum;

View File

@@ -1,3 +1,3 @@
#pragma once
#define VERSION_SPF "2294"
#define VERSION_SPF "2296"