|
|
|
@@ -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,17 @@ 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 +311,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 +322,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());
|
|
|
|
@@ -659,6 +642,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,
|
|
|
|
@@ -765,12 +753,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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@@ -781,19 +784,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)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
@@ -824,7 +814,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);
|
|
|
|
@@ -868,8 +858,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);
|
|
|
|
@@ -892,6 +881,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();
|
|
|
|
@@ -928,7 +918,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:
|
|
|
|
@@ -995,15 +984,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
|
|
|
|
@@ -1225,26 +1206,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;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (regularExpr.coefA == 0)
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool isIterationVar = false;
|
|
|
|
|
|
|
|
for (SgSymbol* iterationVar : iterationVars)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (iterationVar->identifier() == regularExpr.var)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
isIterationVar = true;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!isIterationVar)
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: possibly can be removed:
|
|
|
|
|
|
|
|
if (st->variant() == ASSIGN_STAT && isEqSymbols(st->expr(0)->symbol(), ctx->arraySymbol))
|
|
|
|
|
|
|
|
for (auto iterationVar : iterationVars)
|
|
|
|
|
|
|
|
if (isSymbolInExpression(iterationVar, st->expr(1)))
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
iterationVars.resize(indexExprList->length());
|
|
|
|
|
|
|
|
ctx->arrayRefToIterationVarsMap.insert(make_pair(arrayRef, iterationVars));
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@@ -1522,7 +1511,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;
|
|
|
|
|
|
|
|
|
|
|
|
@@ -1623,9 +1613,11 @@ static ReducedArrayVarsMap getReducedArrayVars(Context* ctx)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
string name = getReducedArrayVarName(arrayRef->symbol(), subscripts);
|
|
|
|
string name = getReducedArrayVarName(arrayRef->symbol(), subscripts);
|
|
|
|
|
|
|
|
|
|
|
|
int nameNumber = checkSymbNameAndCorrect(name + "__", 0);
|
|
|
|
if (checkSymbNameAndCorrect(name, "_") != name)
|
|
|
|
if (nameNumber != 0)
|
|
|
|
{
|
|
|
|
|
|
|
|
int nameNumber = checkSymbNameAndCorrect(name + "__", 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);
|
|
|
|
@@ -1700,8 +1692,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;
|
|
|
|
|
|
|
|
|
|
|
|
@@ -1774,7 +1765,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)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
@@ -1787,66 +1778,38 @@ 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
|
|
|
|
|
|
|
|
|
|
|
|
// try to find definition not from RD_defArgs, by search in the block instructions:
|
|
|
|
|
|
|
|
string defVarName = useInsertedStmt.insertedStmt->expr(1)->symbol()->identifier();
|
|
|
|
|
|
|
|
const auto& blockInstructionsVector = useInsAndBlock.second->getInstructions();
|
|
|
|
|
|
|
|
for (auto& instruction : blockInstructionsVector)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (defArg == SAPFOR::CFG_VAL::UNINIT)
|
|
|
|
SgStatement* stmt = instruction->getInstruction()->getOperator();
|
|
|
|
continue;
|
|
|
|
if (stmt == useInsertedStmt.insertedStmt)
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
auto defInsAndBlock = getInstructionAndBlockByNumber(CFGraph, defArg);
|
|
|
|
if (stmt->variant() == ASSIGN_STAT
|
|
|
|
if (defInsAndBlock.first == nullptr)
|
|
|
|
&& stmt->expr(0)->symbol()->identifier() == defVarName
|
|
|
|
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
|
|
|
&& !isVarChangedBetween(defVarName, stmt, useInsertedStmt.insertedStmt))
|
|
|
|
|
|
|
|
|
|
|
|
auto defInsertedStmt = findInsertedStmt(insertedStmts, defInsAndBlock.first->getOperator());
|
|
|
|
|
|
|
|
if (defInsertedStmt->relatedToStmt->lineNumber() < useLineNum &&
|
|
|
|
|
|
|
|
useInsAndBlock.second->getNumber() == defInsAndBlock.second->getNumber())
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
defIsFound = true;
|
|
|
|
defIsFound = true;
|
|
|
|
auto defInsAndBlock = getInstructionAndBlockByNumber(CFGraph, defArg);
|
|
|
|
defStmt = stmt;
|
|
|
|
defStmt = defInsAndBlock.first->getOperator();
|
|
|
|
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!defIsFound)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// try to find definition not from RD_defArgs, by search in the block instructions:
|
|
|
|
|
|
|
|
string defVarName = useInsertedStmt.insertedStmt->expr(1)->symbol()->identifier();
|
|
|
|
|
|
|
|
const auto& blockInstructionsVector = useInsAndBlock.second->getInstructions();
|
|
|
|
|
|
|
|
for (auto& instruction : blockInstructionsVector)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
SgStatement* stmt = instruction->getInstruction()->getOperator();
|
|
|
|
|
|
|
|
if (stmt == useInsertedStmt.insertedStmt)
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (stmt->variant() == ASSIGN_STAT
|
|
|
|
|
|
|
|
&& stmt->expr(0)->symbol()->identifier() == defVarName
|
|
|
|
|
|
|
|
&& !isVarChangedBetween(defVarName, stmt, useInsertedStmt.insertedStmt))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
defIsFound = true;
|
|
|
|
|
|
|
|
defStmt = stmt;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!defIsFound)
|
|
|
|
if (!defIsFound)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
addMessageCannotFindRD(ctx->messages, arrayName, useLineNum);
|
|
|
|
addMessageCannotFindRD(ctx->messages, arrayName, useLineNum);
|
|
|
|
@@ -1884,15 +1847,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)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
@@ -2063,7 +2017,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)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
@@ -2093,7 +2048,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);
|
|
|
|
|
|
|
|
|
|
|
|
@@ -2282,7 +2239,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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@@ -2349,6 +2305,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);
|
|
|
|
|
|
|
|
|
|
|
|
@@ -2358,8 +2316,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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@@ -2374,14 +2331,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);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|