|
|
|
|
@@ -599,38 +599,39 @@ static bool isVarChangedBetween(string var, SgStatement* first, SgStatement* sec
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO: remove if needless
|
|
|
|
|
// removeDeadCodeFromLoop removes assign statements to private scalar vars which are not read in loop
|
|
|
|
|
static void removeDeadCodeFromLoop(LoopGraph* loop)
|
|
|
|
|
{
|
|
|
|
|
SgForStmt* loopStmt = (SgForStmt*) loop->loop->GetOriginal();
|
|
|
|
|
set<Symbol*> privateVars;
|
|
|
|
|
for (auto data : getAttributes<SgStatement*, SgStatement*>(loopStmt, set<int>{ SPF_ANALYSIS_DIR }))
|
|
|
|
|
fillPrivatesFromComment(new Statement(data), privateVars);
|
|
|
|
|
|
|
|
|
|
set<string> privates;
|
|
|
|
|
for (Symbol* symbol : privateVars)
|
|
|
|
|
privates.insert(OriginalSymbol((SgSymbol*)symbol)->identifier());
|
|
|
|
|
|
|
|
|
|
vector<SgStatement*> stmtsToDelete;
|
|
|
|
|
for (SgStatement* st = loopStmt->lexNext(); st != loopStmt->lastNodeOfStmt(); st = st->lexNext())
|
|
|
|
|
{
|
|
|
|
|
if (st->variant() != ASSIGN_STAT)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
SgSymbol* var = st->expr(0)->symbol();
|
|
|
|
|
if (var == nullptr || var->variant() != VARIABLE_NAME)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (privates.find(var->identifier()) != privates.end() && !isVarReadInLoop(var, loopStmt))
|
|
|
|
|
stmtsToDelete.push_back(st);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (auto stmt : stmtsToDelete)
|
|
|
|
|
stmt->deleteStmt();
|
|
|
|
|
|
|
|
|
|
for (auto childLoop : loop->children)
|
|
|
|
|
removeDeadCodeFromLoop(childLoop);
|
|
|
|
|
}
|
|
|
|
|
//static void removeDeadCodeFromLoop(LoopGraph* loop)
|
|
|
|
|
//{
|
|
|
|
|
// SgForStmt* loopStmt = (SgForStmt*) loop->loop->GetOriginal();
|
|
|
|
|
// set<Symbol*> privateVars;
|
|
|
|
|
// for (auto data : getAttributes<SgStatement*, SgStatement*>(loopStmt, set<int>{ SPF_ANALYSIS_DIR }))
|
|
|
|
|
// fillPrivatesFromComment(new Statement(data), privateVars);
|
|
|
|
|
//
|
|
|
|
|
// set<string> privates;
|
|
|
|
|
// for (Symbol* symbol : privateVars)
|
|
|
|
|
// privates.insert(OriginalSymbol((SgSymbol*)symbol)->identifier());
|
|
|
|
|
//
|
|
|
|
|
// vector<SgStatement*> stmtsToDelete;
|
|
|
|
|
// for (SgStatement* st = loopStmt->lexNext(); st != loopStmt->lastNodeOfStmt(); st = st->lexNext())
|
|
|
|
|
// {
|
|
|
|
|
// if (st->variant() != ASSIGN_STAT)
|
|
|
|
|
// continue;
|
|
|
|
|
//
|
|
|
|
|
// SgSymbol* var = st->expr(0)->symbol();
|
|
|
|
|
// if (var == nullptr || var->variant() != VARIABLE_NAME)
|
|
|
|
|
// continue;
|
|
|
|
|
//
|
|
|
|
|
// if (privates.find(var->identifier()) != privates.end() && !isVarReadInLoop(var, loopStmt))
|
|
|
|
|
// stmtsToDelete.push_back(st);
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// for (auto stmt : stmtsToDelete)
|
|
|
|
|
// stmt->deleteStmt();
|
|
|
|
|
//
|
|
|
|
|
// for (auto childLoop : loop->children)
|
|
|
|
|
// removeDeadCodeFromLoop(childLoop);
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
// fillReadShortFixedSumscripts fills all short fixed subscripts vectors of array var,
|
|
|
|
|
// which are used for reading from array var in exp
|
|
|
|
|
@@ -697,30 +698,31 @@ static void removeExcessiveDefs(const PrivateToRemove& var)
|
|
|
|
|
st->deleteStmt();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO: remove is needless
|
|
|
|
|
// removeEmptyLoops removes loops with empty body and create messages
|
|
|
|
|
static void removeEmptyLoops(LoopGraph* loop, vector<Messages>& messages)
|
|
|
|
|
{
|
|
|
|
|
vector<LoopGraph*> loopsToDelete;
|
|
|
|
|
vector<LoopGraph*> newChildrenVector;
|
|
|
|
|
for (auto childLoop : loop->children)
|
|
|
|
|
{
|
|
|
|
|
SgStatement* loopStmt = childLoop->loop->GetOriginal();
|
|
|
|
|
if (loopStmt->lastNodeOfStmt() == loopStmt->lexNext())
|
|
|
|
|
loopsToDelete.push_back(childLoop);
|
|
|
|
|
else
|
|
|
|
|
newChildrenVector.push_back(childLoop);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (auto loopToDelete : loopsToDelete)
|
|
|
|
|
{
|
|
|
|
|
addMessageRemoveLoop(messages, loopToDelete->lineNum);
|
|
|
|
|
loopToDelete->loop->extractStmt();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
loop->children.swap(newChildrenVector);
|
|
|
|
|
for (auto childLoop : loop->children)
|
|
|
|
|
removeEmptyLoops(childLoop, messages);
|
|
|
|
|
}
|
|
|
|
|
//static void removeEmptyLoops(LoopGraph* loop, vector<Messages>& messages)
|
|
|
|
|
//{
|
|
|
|
|
// vector<LoopGraph*> loopsToDelete;
|
|
|
|
|
// vector<LoopGraph*> newChildrenVector;
|
|
|
|
|
// for (auto childLoop : loop->children)
|
|
|
|
|
// {
|
|
|
|
|
// SgStatement* loopStmt = childLoop->loop->GetOriginal();
|
|
|
|
|
// if (loopStmt->lastNodeOfStmt() == loopStmt->lexNext())
|
|
|
|
|
// loopsToDelete.push_back(childLoop);
|
|
|
|
|
// else
|
|
|
|
|
// newChildrenVector.push_back(childLoop);
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// for (auto loopToDelete : loopsToDelete)
|
|
|
|
|
// {
|
|
|
|
|
// addMessageRemoveLoop(messages, loopToDelete->lineNum);
|
|
|
|
|
// loopToDelete->loop->extractStmt();
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// loop->children.swap(newChildrenVector);
|
|
|
|
|
// for (auto childLoop : loop->children)
|
|
|
|
|
// removeEmptyLoops(childLoop, messages);
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
// removeVarFromPrivateAttributes removes var from SPF ANALYSIS PRIVATE attributes of loop
|
|
|
|
|
static void removeVarFromPrivateAttributes(SgSymbol* var, LoopGraph* loop)
|
|
|
|
|
@@ -820,39 +822,35 @@ static set<vector<int>> removeArray(string filename, const PrivateToRemove& arra
|
|
|
|
|
|
|
|
|
|
SgExpression* substExp = substituteExpressions(useStmt->expr(i), refToExpMap);
|
|
|
|
|
useStmt->setExpression(i, *substExp);
|
|
|
|
|
|
|
|
|
|
// don't revert substitutions in useStmt:
|
|
|
|
|
cancelRevertionForStatement(filename, useStmt, i);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return removedFixedSubscripts;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void removePrivates(SgFile* file, vector<Messages>& messages,
|
|
|
|
|
void removePrivates(string filename, vector<Messages>& messages,
|
|
|
|
|
const map<string, CommonBlock*>& commonBlocks,
|
|
|
|
|
const map<string, vector<FuncInfo*>>& allFuncInfo,
|
|
|
|
|
int& countOfTransform)
|
|
|
|
|
{
|
|
|
|
|
for (auto& varToRemove : privatesToRemoveGlobal)
|
|
|
|
|
{
|
|
|
|
|
if (string(file->filename()) != varToRemove.loop->fileName)
|
|
|
|
|
if (filename != varToRemove.loop->fileName)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
auto removedDimensions = removeArray(file->filename(), varToRemove);
|
|
|
|
|
auto removedDimensions = removeArray(filename, varToRemove);
|
|
|
|
|
countOfTransform++;
|
|
|
|
|
|
|
|
|
|
//removeDeadCodeFromLoop(varToRemove.loop); // TODO: problem with reverting substitution
|
|
|
|
|
//removeDeadCodeFromLoop(varToRemove.loop);
|
|
|
|
|
removeExcessiveDefs(varToRemove);
|
|
|
|
|
removeEmptyLoops(varToRemove.loop, messages); // removing is made by REMOVE_DEAD_CODE pass
|
|
|
|
|
//removeEmptyLoops(varToRemove.loop, messages);
|
|
|
|
|
|
|
|
|
|
SgForStmt* loopStmt = (SgForStmt*)varToRemove.loop->loop->GetOriginal();
|
|
|
|
|
FuncInfo* currFunc = getCurrectFunc(loopStmt, allFuncInfo);
|
|
|
|
|
if (currFunc == nullptr)
|
|
|
|
|
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
|
|
|
|
|
|
|
|
|
// TODO: problem with removing dead code before reverting substitution
|
|
|
|
|
//removeDeadCode(currFunc->funcPointer, allFuncInfo, commonBlocks);
|
|
|
|
|
removeDeadCode(currFunc->funcPointer, allFuncInfo, commonBlocks);
|
|
|
|
|
|
|
|
|
|
vector<SgArrayRefExp*> varRefs = getDirectArrayRefs(loopStmt, varToRemove.varSymbol);
|
|
|
|
|
int loopLineNum = varToRemove.loop->lineNum;
|
|
|
|
|
@@ -904,6 +902,7 @@ struct Context {
|
|
|
|
|
const map<string, vector<FuncInfo*>>& allFuncInfo;
|
|
|
|
|
const map<string, CommonBlock*>& commonBlocks;
|
|
|
|
|
vector<Messages>& messages;
|
|
|
|
|
string filename;
|
|
|
|
|
|
|
|
|
|
Regime regime;
|
|
|
|
|
LoopGraph* loop;
|
|
|
|
|
@@ -1883,7 +1882,7 @@ static bool isDifferentRefs(SgExpression* exp, const pair<string, vector<FixedSu
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static pair<SAPFOR::Argument*, set<int>> findVarInRDSet(const map<SAPFOR::Argument*, set<int>> RD_In, string var)
|
|
|
|
|
static pair<SAPFOR::Argument*, set<int>> findVarInRDSet(const map<SAPFOR::Argument*, set<int>>& RD_In, const string& var)
|
|
|
|
|
{
|
|
|
|
|
for (auto& RD_InElem : RD_In)
|
|
|
|
|
{
|
|
|
|
|
@@ -2083,9 +2082,19 @@ void removePrivateAnalyze(Context *ctx)
|
|
|
|
|
{
|
|
|
|
|
vector<DefUseStmtsPair> resultDefUsePairs;
|
|
|
|
|
for (auto& pair : defUseStmtsPairs)
|
|
|
|
|
{
|
|
|
|
|
if (checkDefUsePair(ctx, pair, CFG_ForFunc))
|
|
|
|
|
{
|
|
|
|
|
resultDefUsePairs.push_back(pair);
|
|
|
|
|
|
|
|
|
|
// don't revert substitutions in use and def stmts:
|
|
|
|
|
cancelRevertionForStatement(ctx->filename, pair.first, 1);
|
|
|
|
|
cancelRevertionForStatement(ctx->filename, pair.second, 0);
|
|
|
|
|
cancelRevertionForStatement(ctx->filename, pair.second, 1);
|
|
|
|
|
cancelRevertionForStatement(ctx->filename, pair.second, 2);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PrivateToRemove newPrivateToRemove;
|
|
|
|
|
newPrivateToRemove.loop = ctx->loop;
|
|
|
|
|
newPrivateToRemove.varSymbol = ctx->arraySymbol;
|
|
|
|
|
@@ -2104,7 +2113,8 @@ void removePrivateAnalyze(Context *ctx)
|
|
|
|
|
deleteCFG(CFG_ForFunc);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void removePrivatesAnalysis(vector<LoopGraph*>& loopGraphs,
|
|
|
|
|
void removePrivatesAnalysis(string filename,
|
|
|
|
|
vector<LoopGraph*>& loopGraphs,
|
|
|
|
|
vector<Messages>& messages,
|
|
|
|
|
const UsersDirectives& usersDirectives,
|
|
|
|
|
const map<string, CommonBlock*>& commonBlocks,
|
|
|
|
|
@@ -2151,7 +2161,7 @@ void removePrivatesAnalysis(vector<LoopGraph*>& loopGraphs,
|
|
|
|
|
if (arrayToRemove == nullptr) // no array to remove
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
Context context = Context{allFuncInfo, commonBlocks, messages};
|
|
|
|
|
Context context = Context{allFuncInfo, commonBlocks, messages, filename};
|
|
|
|
|
context.regime = Regime::DEFLT;
|
|
|
|
|
context.loop = loop;
|
|
|
|
|
context.loopStmt = loopStmt;
|
|
|
|
|
@@ -2173,9 +2183,7 @@ void removePrivatesAnalysis(vector<LoopGraph*>& loopGraphs,
|
|
|
|
|
{
|
|
|
|
|
removePrivateAnalyze(&context);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (checkRegularIndexRefs(&context))
|
|
|
|
|
else if (checkRegularIndexRefs(&context))
|
|
|
|
|
{
|
|
|
|
|
context.regime = Regime::REGULAR_INDEXES;
|
|
|
|
|
context.fixedDimensionsMask = vector<bool>{};
|
|
|
|
|
@@ -2185,8 +2193,7 @@ void removePrivatesAnalysis(vector<LoopGraph*>& loopGraphs,
|
|
|
|
|
addMessageDoesNotMatchMask(messages, context.arraySymbol->identifier(), context.loop->lineNum);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (LoopGraph* loop : loopGraphs)
|
|
|
|
|
removePrivatesAnalysis(loop->children, messages, usersDirectives, commonBlocks, allFuncInfo);
|
|
|
|
|
removePrivatesAnalysis(filename, loop->children, messages, usersDirectives, commonBlocks, allFuncInfo);
|
|
|
|
|
}
|
|
|
|
|
|