improved privated removing
This commit is contained in:
@@ -434,7 +434,7 @@ void removeDeadCode(SgStatement* func,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//TODO: need to add [intervalDelStart; intervalDelEnd]
|
|
||||||
// remove dead statements
|
// remove dead statements
|
||||||
set<int> removable =
|
set<int> removable =
|
||||||
{
|
{
|
||||||
@@ -445,7 +445,10 @@ void removeDeadCode(SgStatement* func,
|
|||||||
};
|
};
|
||||||
|
|
||||||
vector<SgStatement*> remove;
|
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())
|
if (removable.find(st->variant()) != removable.end() && useful.find(st) == useful.end())
|
||||||
{
|
{
|
||||||
@@ -462,7 +465,7 @@ void removeDeadCode(SgStatement* func,
|
|||||||
|
|
||||||
remove.clear();
|
remove.clear();
|
||||||
//remove empty blocks
|
//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();
|
const int var = st->variant();
|
||||||
if ((var == FOR_NODE || var == WHILE_NODE || var == IF_NODE || var == SWITCH_NODE) &&
|
if ((var == FOR_NODE || var == WHILE_NODE || var == IF_NODE || var == SWITCH_NODE) &&
|
||||||
|
|||||||
@@ -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)
|
if (list->variant() == VAR_REF || list->variant() == ARRAY_REF)
|
||||||
return NULL;
|
{
|
||||||
|
if (isEqSymbols(list->symbol(), symbol))
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
if (isEqSymbols(list->lhs()->symbol(), symbol))
|
auto left = findSymbol(symbol, list->lhs());
|
||||||
return list->lhs();
|
if (left)
|
||||||
|
return left;
|
||||||
|
|
||||||
list = list->rhs();
|
auto right = findSymbol(symbol, list->rhs());
|
||||||
|
if (right)
|
||||||
|
return right;
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
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,
|
static SgSymbol* alterExtendArrayDeclaration(const LoopGraph* forLoop, SgStatement* declarationStmt, SgSymbol* arraySymbol,
|
||||||
bool canBeStatic, const vector<SgSymbol*>& indexes)
|
bool canBeStatic, const vector<SgSymbol*>& indexes)
|
||||||
{
|
{
|
||||||
SgSymbol* newArraySymbol = NULL;
|
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();
|
SgExpression* newArray = array->copyPtr();
|
||||||
newArraySymbol = createNewArrayNameSymbol(newArray, true, canBeStatic);
|
newArraySymbol = createNewArrayNameSymbol(newArray, true, canBeStatic);
|
||||||
@@ -368,7 +402,7 @@ static SgSymbol* alterShrinkArrayDeclaration(SgStatement *declarationStatement,
|
|||||||
vector<int> &dimensions, bool canBeStatic)
|
vector<int> &dimensions, bool canBeStatic)
|
||||||
{
|
{
|
||||||
SgSymbol *newArraySymbol = NULL;
|
SgSymbol *newArraySymbol = NULL;
|
||||||
SgExpression *array = findSymbolInExprList(arraySymbol, declarationStatement->expr(0));
|
SgExpression *array = findSymbol(arraySymbol, declarationStatement->expr(0));
|
||||||
|
|
||||||
SgExpression *newArray = array->copyPtr();
|
SgExpression *newArray = array->copyPtr();
|
||||||
newArraySymbol = createNewArrayNameSymbol(newArray, false, canBeStatic);
|
newArraySymbol = createNewArrayNameSymbol(newArray, false, canBeStatic);
|
||||||
@@ -460,7 +494,9 @@ static SgStatement* createNewDeclarationStatemnet(SgStatement *loop, SgStatement
|
|||||||
while (!isEqSymbols(exprList->lhs()->symbol(), arraySymbol))
|
while (!isEqSymbols(exprList->lhs()->symbol(), arraySymbol))
|
||||||
exprList = exprList->rhs();
|
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();
|
SgStatement *newDeclaration = originalDeclaration->copyPtr();
|
||||||
|
|
||||||
newDeclaration->setExpression(0, newExprList);
|
newDeclaration->setExpression(0, newExprList);
|
||||||
@@ -504,7 +540,7 @@ static SgStatement* getAllocationStmt(const LoopGraph* loop, SgSymbol* symbol)
|
|||||||
if (alloc->variant() != ALLOCATE_STMT)
|
if (alloc->variant() != ALLOCATE_STMT)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (NULL == findSymbolInExprList(symbol, alloc->expr(0)))
|
if (findSymbol(symbol, alloc->expr(0)) == NULL)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (allocationStmt == NULL)
|
if (allocationStmt == NULL)
|
||||||
@@ -527,10 +563,10 @@ static void fillLowBounds(const LoopGraph* forLoop, SgSymbol* origArraySymbol, S
|
|||||||
if (isAllocatable(origArraySymbol))
|
if (isAllocatable(origArraySymbol))
|
||||||
{
|
{
|
||||||
SgStatement* allocationStmt = getAllocationStmt(forLoop, origArraySymbol);
|
SgStatement* allocationStmt = getAllocationStmt(forLoop, origArraySymbol);
|
||||||
origArray = findSymbolInExprList(origArraySymbol, allocationStmt->expr(0));
|
origArray = findSymbol(origArraySymbol, allocationStmt->expr(0));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
origArray = findSymbolInExprList(origArraySymbol, originalDecl->expr(0));
|
origArray = findSymbol(origArraySymbol, originalDecl->expr(0));
|
||||||
|
|
||||||
SgExpression* arrayRef = origArray->copyPtr();
|
SgExpression* arrayRef = origArray->copyPtr();
|
||||||
SgExpression* oldTail = arrayRef->lhs();
|
SgExpression* oldTail = arrayRef->lhs();
|
||||||
@@ -596,10 +632,13 @@ static void insertAllocDealloc(const LoopGraph* forLoop, SgSymbol* origArraySymb
|
|||||||
if (isAllocatable(origArraySymbol))
|
if (isAllocatable(origArraySymbol))
|
||||||
{
|
{
|
||||||
SgStatement *allocationStmt = getAllocationStmt(forLoop, origArraySymbol);
|
SgStatement *allocationStmt = getAllocationStmt(forLoop, origArraySymbol);
|
||||||
origArray = findSymbolInExprList(origArraySymbol, allocationStmt->expr(0));
|
origArray = findSymbol(origArraySymbol, allocationStmt->expr(0));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
origArray = findSymbolInExprList(origArraySymbol, originalDeclaration->expr(0));
|
{
|
||||||
|
origArray = findSymbol(origArraySymbol, originalDeclaration->expr(0));
|
||||||
|
origArray = checkArrayDecl(origArray, origArraySymbol, originalDeclaration);
|
||||||
|
}
|
||||||
|
|
||||||
int depthOfResize = 0;
|
int depthOfResize = 0;
|
||||||
if (isExpansion)
|
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)
|
static void fillIndexesToShrink(SgSymbol* arr, SgExprListExp* listExp, vector<int>& indexes)
|
||||||
{
|
{
|
||||||
SgExpression* sym = findSymbolInExprList(arr, listExp);
|
SgExpression* sym = findSymbol(arr, listExp);
|
||||||
if (sym)
|
if (sym)
|
||||||
{
|
{
|
||||||
SgExpression* expr = sym->lhs();
|
SgExpression* expr = sym->lhs();
|
||||||
@@ -1130,7 +1169,8 @@ static SgSymbol* resizeArray(const LoopGraph *forLoop, SgSymbol *arraySymbol, in
|
|||||||
|
|
||||||
for (int i = 0; i < depthOfResize; ++i)
|
for (int i = 0; i < depthOfResize; ++i)
|
||||||
{
|
{
|
||||||
if (curLoop->calculatedCountOfIters == 0)
|
//TODO: add checking for PARAMETER
|
||||||
|
//if (curLoop->calculatedCountOfIters == 0)
|
||||||
canBeStatic = false;
|
canBeStatic = false;
|
||||||
|
|
||||||
if (areIndexesFilled != 0)
|
if (areIndexesFilled != 0)
|
||||||
|
|||||||
@@ -833,6 +833,7 @@ void removePrivates(string filename, vector<Messages>& messages,
|
|||||||
const map<string, vector<FuncInfo*>>& allFuncInfo,
|
const map<string, vector<FuncInfo*>>& allFuncInfo,
|
||||||
int& countOfTransform)
|
int& countOfTransform)
|
||||||
{
|
{
|
||||||
|
set<LoopGraph*> removedDC;
|
||||||
for (auto& varToRemove : privatesToRemoveGlobal)
|
for (auto& varToRemove : privatesToRemoveGlobal)
|
||||||
{
|
{
|
||||||
if (filename != varToRemove.loop->fileName)
|
if (filename != varToRemove.loop->fileName)
|
||||||
@@ -850,7 +851,12 @@ void removePrivates(string filename, vector<Messages>& messages,
|
|||||||
if (currFunc == nullptr)
|
if (currFunc == nullptr)
|
||||||
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
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);
|
vector<SgArrayRefExp*> varRefs = getDirectArrayRefs(loopStmt, varToRemove.varSymbol);
|
||||||
int loopLineNum = varToRemove.loop->lineNum;
|
int loopLineNum = varToRemove.loop->lineNum;
|
||||||
@@ -863,7 +869,7 @@ void removePrivates(string filename, vector<Messages>& messages,
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
varRefs = removeDuplicateArrayRefs(varRefs, fixedDimensions, varToRemove.regime,
|
varRefs = removeDuplicateArrayRefs(varRefs, fixedDimensions, varToRemove.regime,
|
||||||
varToRemove.arrayRefToIterationVarsMap);
|
varToRemove.arrayRefToIterationVarsMap);
|
||||||
for (auto& varRef : varRefs)
|
for (auto& varRef : varRefs)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#define VERSION_SPF "2294"
|
#define VERSION_SPF "2296"
|
||||||
|
|||||||
Reference in New Issue
Block a user