private_removing #47

Merged
Alexander_KS merged 2 commits from private_removing into master 2024-06-10 06:14:40 +00:00
2 changed files with 95 additions and 144 deletions

View File

@@ -20,11 +20,12 @@ using UsersDirectives = map<pair<string, int>, set<SgStatement*>>;
// RegularExpr represents expressions like ( coefA * I + coefB ), // RegularExpr represents expressions like ( coefA * I + coefB ),
// where I is a variable and coefA or coefB can be equal to zero // where I is a variable and coefA or coefB can be equal to zero
struct RegularExpr { struct RegularExpr {
int coefA = 0; int coefA;
int coefB; int coefB;
string var; string var;
SgSymbol* varSymbol;
RegularExpr(): coefA(0), coefB(0), var("") {} RegularExpr(): coefA(0), coefB(0), var(""), varSymbol(nullptr) {}
string toString() const string toString() const
{ {
@@ -218,7 +219,10 @@ static bool checkAndFillRegularExpr(SgExpression* expr, RegularExpr& regularExpr
regularExpr.coefA = retCoefs.first; regularExpr.coefA = retCoefs.first;
regularExpr.coefB = retCoefs.second; regularExpr.coefB = retCoefs.second;
if (!deleteTmpVar) if (!deleteTmpVar)
{
regularExpr.var = iterationVar->identifier(); regularExpr.var = iterationVar->identifier();
regularExpr.varSymbol = iterationVar;
}
if (deleteTmpVar) if (deleteTmpVar)
delete iterationVar; delete iterationVar;
@@ -236,7 +240,7 @@ static bool checkAndFillRegularExpr(SgExpression* expr, RegularExpr& regularExpr
// getShortFixedSubscriptsVector returns vector of fixed INT_VAL subscripts of arrayRef // getShortFixedSubscriptsVector returns vector of fixed INT_VAL subscripts of arrayRef
static vector<int> getShortFixedSubscriptsVector(SgArrayRefExp* arrayRef, static vector<int> getShortFixedSubscriptsVector(SgArrayRefExp* arrayRef,
const vector<bool>& fixedDimensionsMask, const vector<bool>& fixedDimensionsMask,
Regime regime, vector<SgSymbol*> iterationVars) Regime regime)
{ {
if (regime == Regime::DEFLT) if (regime == Regime::DEFLT)
{ {
@@ -251,14 +255,12 @@ static vector<int> getShortFixedSubscriptsVector(SgArrayRefExp* arrayRef,
{ {
vector<int> subscriptsVector; vector<int> subscriptsVector;
SgExprListExp* indexExprList = (SgExprListExp*)arrayRef->lhs(); SgExprListExp* indexExprList = (SgExprListExp*)arrayRef->lhs();
if (iterationVars.size() < indexExprList->length())
return vector<int>{};
for (int i = 0; i < indexExprList->length(); ++i) for (int i = 0; i < indexExprList->length(); ++i)
{ {
SgExpression* indexExpr = indexExprList->elem(i); SgExpression* indexExpr = indexExprList->elem(i);
RegularExpr regularExpr; RegularExpr regularExpr;
if (!checkAndFillRegularExpr(indexExpr, regularExpr, iterationVars[i])) if (!checkAndFillRegularExpr(indexExpr, regularExpr, nullptr))
return vector<int>{}; return vector<int>{};
subscriptsVector.push_back(regularExpr.coefA); subscriptsVector.push_back(regularExpr.coefA);
@@ -271,38 +273,15 @@ static vector<int> getShortFixedSubscriptsVector(SgArrayRefExp* arrayRef,
return vector<int>{}; return vector<int>{};
} }
static vector<int> getShortFixedSubscriptsVector(SgArrayRefExp* arrayRef, const PrivateToRemove& varToRemove)
{
vector<SgSymbol*> iterationVars;
if (varToRemove.regime == Regime::REGULAR_INDEXES)
{
auto vars = varToRemove.arrayRefToIterationVarsMap.find(arrayRef);
if (vars != varToRemove.arrayRefToIterationVarsMap.end())
iterationVars = vars->second;
}
return getShortFixedSubscriptsVector(arrayRef, varToRemove.fixedDimensions,
varToRemove.regime, iterationVars);
}
// removeDuplicateArrayRefs returns unique array refereces in fixed dimensions // removeDuplicateArrayRefs returns unique array refereces in fixed dimensions
static vector<SgArrayRefExp*> removeDuplicateArrayRefs(const vector<SgArrayRefExp*>& arrayRefs, static vector<SgArrayRefExp*> removeDuplicateArrayRefs(const vector<SgArrayRefExp*>& arrayRefs,
const vector<bool>& fixedDimensionsMask, const vector<bool>& fixedDimensionsMask,
Regime regime, Regime regime)
const map<SgArrayRefExp*, vector<SgSymbol*>>& arrayRefToIterVarsMap)
{ {
map<vector<int>, SgArrayRefExp*> uniqueRefs; map<vector<int>, SgArrayRefExp*> uniqueRefs;
for (SgArrayRefExp* arrayRef : arrayRefs) for (SgArrayRefExp* arrayRef : arrayRefs)
{ {
vector<SgSymbol*> iterationVars; vector<int> subscripts = getShortFixedSubscriptsVector(arrayRef, fixedDimensionsMask, regime);
if (regime == Regime::REGULAR_INDEXES)
{
auto vars = arrayRefToIterVarsMap.find(arrayRef);
if (vars != arrayRefToIterVarsMap.end())
iterationVars = vars->second;
}
vector<int> subscripts = getShortFixedSubscriptsVector(arrayRef, fixedDimensionsMask, regime, iterationVars);
if (uniqueRefs.find(subscripts) == uniqueRefs.end()) if (uniqueRefs.find(subscripts) == uniqueRefs.end())
uniqueRefs.insert(make_pair(subscripts, arrayRef)); uniqueRefs.insert(make_pair(subscripts, arrayRef));
} }
@@ -330,6 +309,7 @@ static bool isSymbolInExpression(SgSymbol* symbol, SgExpression* exp)
isSymbolInExpression(symbol, exp->rhs()); isSymbolInExpression(symbol, exp->rhs());
} }
// findFuncByName searches function by its name among all functions (and subroutines) in program
static FuncInfo* findFuncByName(string funcName, const map<string, vector<FuncInfo*>>& allFuncInfo) static FuncInfo* findFuncByName(string funcName, const map<string, vector<FuncInfo*>>& allFuncInfo)
{ {
for (const auto& fileFuncs : allFuncInfo) for (const auto& fileFuncs : allFuncInfo)
@@ -340,6 +320,7 @@ static FuncInfo* findFuncByName(string funcName, const map<string, vector<FuncIn
return nullptr; return nullptr;
} }
// getCurrentFunc return FuncInfo about current function for stmt
static FuncInfo* getCurrentFunc(SgStatement* stmt, const map<string, vector<FuncInfo*>>& allFuncInfo) static FuncInfo* getCurrentFunc(SgStatement* stmt, const map<string, vector<FuncInfo*>>& allFuncInfo)
{ {
auto fileInfo = allFuncInfo.find(stmt->fileName()); auto fileInfo = allFuncInfo.find(stmt->fileName());
@@ -354,8 +335,9 @@ static FuncInfo* getCurrentFunc(SgStatement* stmt, const map<string, vector<Func
return nullptr; return nullptr;
} }
// fillIterationVariables fill vars set with iteration variables of all loops // fillIterationVariables fills SgSymbol* set with iteration variables of all loops
// from stmt to outerLoopStmt // from stmt to outerLoopStmt. If outerLoopStmt is nullptr, it fill with iteration variables
// from all outer loops
static void fillIterationVars(SgStatement* stmt, SgStatement* outerLoopStmt, vector<SgSymbol*>& vars) static void fillIterationVars(SgStatement* stmt, SgStatement* outerLoopStmt, vector<SgSymbol*>& vars)
{ {
if (stmt == nullptr) if (stmt == nullptr)
@@ -364,7 +346,7 @@ static void fillIterationVars(SgStatement* stmt, SgStatement* outerLoopStmt, vec
if (stmt->variant() == FOR_NODE) if (stmt->variant() == FOR_NODE)
vars.push_back(((SgForStmt*)stmt)->doName()); vars.push_back(((SgForStmt*)stmt)->doName());
if (stmt->id() != outerLoopStmt->id()) if (stmt != outerLoopStmt)
fillIterationVars(stmt->controlParent(), outerLoopStmt, vars); fillIterationVars(stmt->controlParent(), outerLoopStmt, vars);
} }
@@ -658,6 +640,11 @@ static bool isVarChangedBetween(string var, SgStatement* first, SgStatement* sec
return false; return false;
} }
static vector<int> getShortFixedSubscriptsVector(SgArrayRefExp* arrayRef, const PrivateToRemove& varToRemove)
{
return getShortFixedSubscriptsVector(arrayRef, varToRemove.fixedDimensions, varToRemove.regime);
}
// fillReadShortFixedSumscripts fills all short fixed subscripts vectors of array var, // fillReadShortFixedSumscripts fills all short fixed subscripts vectors of array var,
// which are used for reading from array var in exp // which are used for reading from array var in exp
static void fillReadShortFixedSubscripts(SgExpression* exp, const PrivateToRemove& var, static void fillReadShortFixedSubscripts(SgExpression* exp, const PrivateToRemove& var,
@@ -764,12 +751,27 @@ static void removeVarFromPrivateAttributes(SgSymbol* var, LoopGraph* loop)
// getVarToExpMap returns map SgSymbol* from defRef -> SgExpression* from useRef // getVarToExpMap returns map SgSymbol* from defRef -> SgExpression* from useRef
static map<SgSymbol*, SgExpression*> getVarToExpMap(SgArrayRefExp* defRef, SgArrayRefExp* useRef, static map<SgSymbol*, SgExpression*> getVarToExpMap(SgArrayRefExp* defRef, SgArrayRefExp* useRef,
const vector<bool>& fixedDimensions) const vector<bool>& fixedDimensions, Regime regime)
{ {
map<SgSymbol*, SgExpression*> varToExpMap; map<SgSymbol*, SgExpression*> varToExpMap;
for (int i = 0; i < fixedDimensions.size(); ++i) for (int i = 0; i < fixedDimensions.size(); ++i)
if (!fixedDimensions[i]) {
if (fixedDimensions[i])
continue;
// check not fixed dimension:
if (regime == Regime::REGULAR_INDEXES)
{
RegularExpr useExpr;
checkAndFillRegularExpr(useRef->subscript(i), useExpr, nullptr);
RegularExpr defExpr;
checkAndFillRegularExpr(defRef->subscript(i), defExpr, nullptr);
varToExpMap.insert(make_pair(defExpr.varSymbol, new SgVarRefExp(useExpr.varSymbol)));
}
else
varToExpMap.insert(make_pair(defRef->subscript(i)->symbol(), useRef->subscript(i))); varToExpMap.insert(make_pair(defRef->subscript(i)->symbol(), useRef->subscript(i)));
}
return varToExpMap; return varToExpMap;
} }
@@ -780,19 +782,6 @@ static set<vector<int>> removeArray(string filename, PrivateToRemove& arrayToRem
{ {
set<vector<int>> removedFixedSubscripts; set<vector<int>> removedFixedSubscripts;
// again fill itaration vars:
arrayToRemove.arrayRefToIterationVarsMap.clear();
SgStatement* loopStmt = arrayToRemove.loop->loop->GetOriginal();
for (SgStatement* st = loopStmt->lexNext(); st != loopStmt->lastNodeOfStmt(); st = st->lexNext())
{
vector<SgSymbol*> iterationVars;
fillIterationVars(st, loopStmt, iterationVars);
vector<SgArrayRefExp*> arrayRefs = getDirectArrayRefsFromSingleStmt(st, arrayToRemove.varSymbol);
for (SgArrayRefExp* arrayRef : arrayRefs)
arrayToRemove.arrayRefToIterationVarsMap.insert(make_pair(arrayRef, iterationVars));
}
auto& fixedDimensions = arrayToRemove.fixedDimensions; auto& fixedDimensions = arrayToRemove.fixedDimensions;
for (auto& defUsePair : arrayToRemove.defUseStmtsPairs) for (auto& defUsePair : arrayToRemove.defUseStmtsPairs)
{ {
@@ -823,7 +812,7 @@ static set<vector<int>> removeArray(string filename, PrivateToRemove& arrayToRem
removedFixedSubscripts.insert(useFixedSubscripts); removedFixedSubscripts.insert(useFixedSubscripts);
auto varToExpMap = getVarToExpMap(defRef, useRef, fixedDimensions); auto varToExpMap = getVarToExpMap(defRef, useRef, fixedDimensions, arrayToRemove.regime);
SgExpression* expToSubst = defStmt->rhs()->copyPtr(); SgExpression* expToSubst = defStmt->rhs()->copyPtr();
expToSubst = replaceVarsWithExps(expToSubst, varToExpMap); expToSubst = replaceVarsWithExps(expToSubst, varToExpMap);
@@ -867,8 +856,7 @@ void removePrivates(string filename, vector<Messages>& messages,
} }
else else
{ {
varRefs = removeDuplicateArrayRefs(varRefs, fixedDimensions, varToRemove.regime, varRefs = removeDuplicateArrayRefs(varRefs, fixedDimensions, varToRemove.regime);
varToRemove.arrayRefToIterationVarsMap);
for (auto& varRef : varRefs) for (auto& varRef : varRefs)
{ {
vector<int> subscripts = getShortFixedSubscriptsVector(varRef, varToRemove); vector<int> subscripts = getShortFixedSubscriptsVector(varRef, varToRemove);
@@ -891,6 +879,7 @@ void removePrivates(string filename, vector<Messages>& messages,
} }
} }
// remove dead code from loop:
for (auto& dcLoopRem : removeDC) for (auto& dcLoopRem : removeDC)
{ {
auto loopStmt = dcLoopRem->loop->GetOriginal(); auto loopStmt = dcLoopRem->loop->GetOriginal();
@@ -927,7 +916,6 @@ struct Context {
int dimensionsNum; int dimensionsNum;
vector<SgArrayRefExp*> explicitArrayRefs; vector<SgArrayRefExp*> explicitArrayRefs;
vector<bool> fixedDimensionsMask; vector<bool> fixedDimensionsMask;
map<SgArrayRefExp*, vector<SgSymbol*>> arrayRefToIterationVarsMap;
}; };
// ReducedArrayVars represents mapping of array reference to reduced scalar var: // ReducedArrayVars represents mapping of array reference to reduced scalar var:
@@ -994,15 +982,7 @@ static vector<InsertedStatement>::const_iterator findInsertedStmt(const vector<I
static vector<int> getShortFixedSubscriptsVector(Context* ctx, SgArrayRefExp* arrayRef) static vector<int> getShortFixedSubscriptsVector(Context* ctx, SgArrayRefExp* arrayRef)
{ {
vector<SgSymbol*> iterationVars; return getShortFixedSubscriptsVector(arrayRef, ctx->fixedDimensionsMask, ctx->regime);
if (ctx->regime == Regime::REGULAR_INDEXES)
{
auto vars = ctx->arrayRefToIterationVarsMap.find(arrayRef);
if (vars != ctx->arrayRefToIterationVarsMap.end())
iterationVars = vars->second;
}
return getShortFixedSubscriptsVector(arrayRef, ctx->fixedDimensionsMask, ctx->regime, iterationVars);
} }
// getLoopsInfo return vector of pair (string, int) - doName and level for each loop // getLoopsInfo return vector of pair (string, int) - doName and level for each loop
@@ -1224,26 +1204,34 @@ static bool checkRegularIndexRefs(Context* ctx)
if (!isArrayRefInVector(arrayRef, ctx->explicitArrayRefs)) if (!isArrayRefInVector(arrayRef, ctx->explicitArrayRefs))
continue; continue;
// check if unfixed dimension index contains iteration var:
SgExprListExp* indexExprList = (SgExprListExp*)arrayRef->lhs(); SgExprListExp* indexExprList = (SgExprListExp*)arrayRef->lhs();
if (iterationVars.size() < indexExprList->length())
return false;
for (int i = 0; i < indexExprList->length(); ++i) for (int i = 0; i < indexExprList->length(); ++i)
{ {
if (ctx->fixedDimensionsMask[i])
continue;
SgExpression* indexExpr = indexExprList->elem(i); SgExpression* indexExpr = indexExprList->elem(i);
RegularExpr regularExpr; RegularExpr regularExpr;
if (!checkAndFillRegularExpr(indexExpr, regularExpr, iterationVars[i])) if (!checkAndFillRegularExpr(indexExpr, regularExpr, nullptr))
return false; return false;
if (regularExpr.coefA == 0)
return false;
bool isIterationVar = false;
for (SgSymbol* iterationVar : iterationVars)
{
if (iterationVar->identifier() == regularExpr.var)
{
isIterationVar = true;
break;
}
} }
// TODO: possibly can be removed: if (!isIterationVar)
if (st->variant() == ASSIGN_STAT && isEqSymbols(st->expr(0)->symbol(), ctx->arraySymbol))
for (auto iterationVar : iterationVars)
if (isSymbolInExpression(iterationVar, st->expr(1)))
return false; return false;
}
iterationVars.resize(indexExprList->length());
ctx->arrayRefToIterationVarsMap.insert(make_pair(arrayRef, iterationVars));
} }
} }
@@ -1521,7 +1509,8 @@ static vector<vector<ArraySubscript>> checkIndirectUsage(Context* ctx)
if (currentFunc == nullptr) if (currentFunc == nullptr)
printInternalError(convertFileName(__FILE__).c_str(), __LINE__); printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
vector<Variable*> commonBlockGroupedVar = getCommonBlockGroupedVar(currentFunc, ctx->arraySymbol, ctx->commonBlocks); const auto& blocks = ctx->commonBlocks;
vector<Variable*> commonBlockGroupedVar = getCommonBlockGroupedVar(currentFunc, ctx->arraySymbol, blocks);
if (commonBlockGroupedVar.empty()) if (commonBlockGroupedVar.empty())
return indirectUsageMasks; return indirectUsageMasks;
@@ -1622,9 +1611,11 @@ static ReducedArrayVarsMap getReducedArrayVars(Context* ctx)
{ {
string name = getReducedArrayVarName(arrayRef->symbol(), subscripts); string name = getReducedArrayVarName(arrayRef->symbol(), subscripts);
if (checkSymbNameAndCorrect(name, "_") != name)
{
int nameNumber = checkSymbNameAndCorrect(name + "__", 0); int nameNumber = checkSymbNameAndCorrect(name + "__", 0);
if (nameNumber != 0)
name = name + "__" + std::to_string(nameNumber); name = name + "__" + std::to_string(nameNumber);
}
SgSymbol* newSymbol = new SgSymbol(VARIABLE_NAME, name.c_str(), type, scope); SgSymbol* newSymbol = new SgSymbol(VARIABLE_NAME, name.c_str(), type, scope);
reducedArrayVars.insert(subscripts, newSymbol); reducedArrayVars.insert(subscripts, newSymbol);
@@ -1699,8 +1690,7 @@ static vector<InsertedStatement> insertReducedArrayVarStmts(Context* ctx,
{ {
vector<SgArrayRefExp*> arrayRefs; vector<SgArrayRefExp*> arrayRefs;
fillDirectArrayRefs(st->expr(i), ctx->arraySymbol, arrayRefs); fillDirectArrayRefs(st->expr(i), ctx->arraySymbol, arrayRefs);
arrayRefs = removeDuplicateArrayRefs(arrayRefs, ctx->fixedDimensionsMask, ctx->regime, arrayRefs = removeDuplicateArrayRefs(arrayRefs, ctx->fixedDimensionsMask, ctx->regime);
ctx->arrayRefToIterationVarsMap);
if (!arrayRefs.empty()) if (!arrayRefs.empty())
isUseStmt = true; isUseStmt = true;
@@ -1773,7 +1763,7 @@ static vector<DefUseStmtsPair> buildDefUsePairs(Context* ctx, const CFG_Type& CF
set<int> RD_defArgs = RD_forUseArg->second; // make copy set<int> RD_defArgs = RD_forUseArg->second; // make copy
// delete recursive and uninit definition from RD def args: // delete recursive, uninit and definitions that cannot reach use stmt from RD def args:
set<int> tmpRD_defArgs; set<int> tmpRD_defArgs;
for (int defArgNum : RD_defArgs) for (int defArgNum : RD_defArgs)
{ {
@@ -1786,46 +1776,19 @@ static vector<DefUseStmtsPair> buildDefUsePairs(Context* ctx, const CFG_Type& CF
SgStatement* defStmt = defInsAndBlock.first->getOperator(); SgStatement* defStmt = defInsAndBlock.first->getOperator();
auto defInsertedStmt = findInsertedStmt(insertedStmts, defStmt); auto defInsertedStmt = findInsertedStmt(insertedStmts, defStmt);
if (useInsertedStmt.relatedToStmt == defInsertedStmt->relatedToStmt) if (useLineNum <= defInsertedStmt->relatedToStmt->lineNumber())
continue; continue;
tmpRD_defArgs.insert(defArgNum); tmpRD_defArgs.insert(defArgNum);
} }
RD_defArgs.swap(tmpRD_defArgs); RD_defArgs.swap(tmpRD_defArgs);
if (RD_defArgs.size() == 0) // argument is not initialized
{
addMessageCannotFindRD(ctx->messages, arrayName, useLineNum);
continue;
}
SgStatement* defStmt = nullptr; SgStatement* defStmt = nullptr;
if (RD_defArgs.size() > 1) if (RD_defArgs.size() != 1)
{ {
bool defIsFound = false; bool defIsFound = false;
for (int defArg : RD_defArgs) // try to find the real definition from RD_defArgs
{
if (defArg == SAPFOR::CFG_VAL::UNINIT)
continue;
auto defInsAndBlock = getInstructionAndBlockByNumber(CFGraph, defArg);
if (defInsAndBlock.first == nullptr)
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
auto defInsertedStmt = findInsertedStmt(insertedStmts, defInsAndBlock.first->getOperator());
if (defInsertedStmt->relatedToStmt->lineNumber() < useLineNum &&
useInsAndBlock.second->getNumber() == defInsAndBlock.second->getNumber())
{
defIsFound = true;
auto defInsAndBlock = getInstructionAndBlockByNumber(CFGraph, defArg);
defStmt = defInsAndBlock.first->getOperator();
break;
}
}
if (!defIsFound)
{
// try to find definition not from RD_defArgs, by search in the block instructions: // try to find definition not from RD_defArgs, by search in the block instructions:
string defVarName = useInsertedStmt.insertedStmt->expr(1)->symbol()->identifier(); string defVarName = useInsertedStmt.insertedStmt->expr(1)->symbol()->identifier();
const auto& blockInstructionsVector = useInsAndBlock.second->getInstructions(); const auto& blockInstructionsVector = useInsAndBlock.second->getInstructions();
@@ -1844,7 +1807,6 @@ static vector<DefUseStmtsPair> buildDefUsePairs(Context* ctx, const CFG_Type& CF
break; break;
} }
} }
}
if (!defIsFound) if (!defIsFound)
{ {
@@ -1883,15 +1845,6 @@ static vector<DefUseStmtsPair> buildDefUsePairs(Context* ctx, const CFG_Type& CF
return defUsePairs; return defUsePairs;
} }
//// getScopeLoopStmt returns least outer scope loop statement
//static SgForStmt* getScopeLoopStmt(SgStatement* stmt)
//{
// while (stmt != nullptr && stmt->variant() != FOR_NODE)
// stmt = stmt->controlParent();
//
// return (SgForStmt*)stmt;
//}
// findChildLoop returns LoopGraph for provided loop statement // findChildLoop returns LoopGraph for provided loop statement
static LoopGraph* findLoop(LoopGraph* outerLoop, SgForStmt* loopStmt) static LoopGraph* findLoop(LoopGraph* outerLoop, SgForStmt* loopStmt)
{ {
@@ -2062,7 +2015,8 @@ static bool areDifferentRefs(Context* ctx, SgExpression* exp, const pair<string,
return false; return false;
} }
static pair<SAPFOR::Argument*, set<int>> findVarInRDSet(const map<SAPFOR::Argument*, set<int>>& RD_In, const 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) for (auto& RD_InElem : RD_In)
{ {
@@ -2092,7 +2046,9 @@ static bool checkDefUsePair(Context* ctx, const DefUseStmtsPair& defUse, const C
vector<SgArrayRefExp*> arrayUseRefs = getDirectArrayRefsFromSingleStmt(defUse.second, ctx->arraySymbol); vector<SgArrayRefExp*> arrayUseRefs = getDirectArrayRefsFromSingleStmt(defUse.second, ctx->arraySymbol);
for (auto useRef : arrayUseRefs) for (auto useRef : arrayUseRefs)
{ {
map<SgSymbol*, SgExpression*> varToExpMap = getVarToExpMap(defRef, useRef, ctx->fixedDimensionsMask); map<SgSymbol*, SgExpression*> varToExpMap;
varToExpMap = getVarToExpMap(defRef, useRef, ctx->fixedDimensionsMask, ctx->regime);
SgExpression* expToSubst = defUse.first->rhs()->copyPtr(); SgExpression* expToSubst = defUse.first->rhs()->copyPtr();
expToSubst = replaceVarsWithExps(expToSubst, varToExpMap); expToSubst = replaceVarsWithExps(expToSubst, varToExpMap);
@@ -2100,7 +2056,7 @@ static bool checkDefUsePair(Context* ctx, const DefUseStmtsPair& defUse, const C
} }
vector<SgSymbol*> iterationVars{}; vector<SgSymbol*> iterationVars{};
fillIterationVars(defUse.second, ctx->loopStmt, iterationVars); fillIterationVars(defUse.second, nullptr, iterationVars);
auto defInsAndBlock = getInstructionAndBlockByStatement(CFGraph, defUse.first); auto defInsAndBlock = getInstructionAndBlockByStatement(CFGraph, defUse.first);
const auto& defRD_In = defInsAndBlock.second->getRD_In(); const auto& defRD_In = defInsAndBlock.second->getRD_In();
@@ -2281,7 +2237,6 @@ void removePrivateAnalyze(Context *ctx)
newPrivateToRemove.regime = ctx->regime; newPrivateToRemove.regime = ctx->regime;
newPrivateToRemove.defUseStmtsPairs.swap(resultDefUsePairs); newPrivateToRemove.defUseStmtsPairs.swap(resultDefUsePairs);
newPrivateToRemove.fixedDimensions.swap(ctx->fixedDimensionsMask); newPrivateToRemove.fixedDimensions.swap(ctx->fixedDimensionsMask);
newPrivateToRemove.arrayRefToIterationVarsMap = ctx->arrayRefToIterationVarsMap;
privatesToRemoveGlobal.push_back(newPrivateToRemove); privatesToRemoveGlobal.push_back(newPrivateToRemove);
} }
@@ -2348,6 +2303,8 @@ void removePrivatesAnalysis(string filename,
context.dimensionsNum = ((SgArrayType*)arrayToRemove->type())->dimension(); context.dimensionsNum = ((SgArrayType*)arrayToRemove->type())->dimension();
context.arraySymbol = arrayToRemove; context.arraySymbol = arrayToRemove;
string arrayName = arrayToRemove->identifier();
auto filterMasks = checkImplicitAndIndirectUsage(&context); auto filterMasks = checkImplicitAndIndirectUsage(&context);
filterArrayRefs(&context, arrayRefs, filterMasks); filterArrayRefs(&context, arrayRefs, filterMasks);
@@ -2357,8 +2314,7 @@ void removePrivatesAnalysis(string filename,
if (!checkLoopAlignmentMatching(&context)) if (!checkLoopAlignmentMatching(&context))
{ {
addMessageVarNotAlignedWithLoop(messages, context.arraySymbol->identifier(), addMessageVarNotAlignedWithLoop(messages, arrayName, context.loop->lineNum);
context.loop->lineNum);
continue; continue;
} }
@@ -2373,14 +2329,10 @@ void removePrivatesAnalysis(string filename,
else if (checkRegularIndexRefs(&context)) else if (checkRegularIndexRefs(&context))
{ {
context.regime = Regime::REGULAR_INDEXES; context.regime = Regime::REGULAR_INDEXES;
context.fixedDimensionsMask = vector<bool>{};
removePrivateAnalyze(&context); removePrivateAnalyze(&context);
} }
else else
{ addMessageDoesNotMatchMask(messages, arrayName, context.loop->lineNum);
addMessageDoesNotMatchMask(messages, context.arraySymbol->identifier(),
context.loop->lineNum);
}
} }
} }

View File

@@ -17,7 +17,6 @@ struct PrivateToRemove {
Regime regime; Regime regime;
std::vector<std::pair<SgAssignStmt*, SgStatement*>> defUseStmtsPairs; std::vector<std::pair<SgAssignStmt*, SgStatement*>> defUseStmtsPairs;
std::vector<bool> fixedDimensions; std::vector<bool> fixedDimensions;
std::map<SgArrayRefExp*, std::vector<SgSymbol*>> arrayRefToIterationVarsMap;
}; };
// removePrivates removes all privates from vector privatesToRemoveGloval // removePrivates removes all privates from vector privatesToRemoveGloval