private_removing: some small fixes
This commit is contained in:
@@ -44,7 +44,7 @@ static bool operator<(const RegularExpr& left, const RegularExpr& right)
|
||||
}
|
||||
|
||||
// FixedSubscript represents subscript of array. Subscript is fixed if it is INT_VAL value
|
||||
struct FixedSubscript {
|
||||
struct ArraySubscript {
|
||||
bool isFixed;
|
||||
int value;
|
||||
|
||||
@@ -52,7 +52,7 @@ struct FixedSubscript {
|
||||
RegularExpr regExprStart;
|
||||
RegularExpr regExprEnd;
|
||||
|
||||
FixedSubscript() {
|
||||
ArraySubscript() {
|
||||
isFixed = false;
|
||||
value = 0;
|
||||
isRegIndex = false;
|
||||
@@ -240,6 +240,7 @@ static vector<int> getShortFixedSubscriptsVector(SgArrayRefExp* arrayRef, const
|
||||
if (vars != varToRemove.arrayRefToIterationVarsMap.end())
|
||||
iterationVars = vars->second;
|
||||
}
|
||||
|
||||
return getShortFixedSubscriptsVector(arrayRef, varToRemove.fixedDimensions,
|
||||
varToRemove.regime, iterationVars);
|
||||
}
|
||||
@@ -278,8 +279,12 @@ static bool isSymbolInExpression(SgSymbol* symbol, SgExpression* exp)
|
||||
if (exp == nullptr)
|
||||
return false;
|
||||
|
||||
if (exp->symbol() != nullptr && isEqSymbols(exp->symbol(), symbol))
|
||||
if (exp->symbol() != nullptr &&
|
||||
(exp->variant() == VAR_REF || exp->variant() == ARRAY_REF) &&
|
||||
isEqSymbols(exp->symbol(), symbol))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return isSymbolInExpression(symbol, exp->lhs()) ||
|
||||
isSymbolInExpression(symbol, exp->rhs());
|
||||
@@ -312,6 +317,20 @@ static FuncInfo* getCurrectFunc(SgStatement* stmt, const map<string, vector<Func
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// fillIterationVariables fill vars set with iteration variables of all loops
|
||||
// from stmt to outerLoopStmt
|
||||
static void fillIterationVars(SgStatement* stmt, SgStatement* outerLoopStmt, vector<SgSymbol*>& vars)
|
||||
{
|
||||
if (stmt == nullptr)
|
||||
return;
|
||||
|
||||
if (stmt->variant() == FOR_NODE)
|
||||
vars.push_back(((SgForStmt*)stmt)->doName());
|
||||
|
||||
if (stmt->id() != outerLoopStmt->id())
|
||||
fillIterationVars(stmt->controlParent(), outerLoopStmt, vars);
|
||||
}
|
||||
|
||||
/* ************************************** *
|
||||
* End of block of common used functions: *
|
||||
* ************************************** */
|
||||
@@ -369,18 +388,19 @@ static void addMessageCannotFindRD(vector<Messages>& messages, string varName, i
|
||||
messages.push_back(Messages(typeMessage::WARR, loopLineNum, messageR, messageE, 2021));
|
||||
}
|
||||
|
||||
static void addMessageMoreThanOneRD(vector<Messages>& messages, string varName, int loopLineNum)
|
||||
{
|
||||
__spf_print(1, "WARR: cannot remove private var '%s' - more than one definition reaches the statement in line %d\n",
|
||||
varName.c_str(), loopLineNum);
|
||||
|
||||
wstring messageE, messageR;
|
||||
__spf_printToLongBuf(messageE, L"Cannot remove private var '%s' - more than one definition reaches the statement",
|
||||
to_wstring(varName).c_str());
|
||||
__spf_printToLongBuf(messageR, R193, to_wstring(varName).c_str());
|
||||
|
||||
messages.push_back(Messages(typeMessage::WARR, loopLineNum, messageR, messageE, 2020));
|
||||
}
|
||||
// TODO: unused:
|
||||
//static void addMessageMoreThanOneRD(vector<Messages>& messages, string varName, int loopLineNum)
|
||||
//{
|
||||
// __spf_print(1, "WARR: cannot remove private var '%s' - more than one definition reaches the statement in line %d\n",
|
||||
// varName.c_str(), loopLineNum);
|
||||
//
|
||||
// wstring messageE, messageR;
|
||||
// __spf_printToLongBuf(messageE, L"Cannot remove private var '%s' - more than one definition reaches the statement",
|
||||
// to_wstring(varName).c_str());
|
||||
// __spf_printToLongBuf(messageR, R193, to_wstring(varName).c_str());
|
||||
//
|
||||
// messages.push_back(Messages(typeMessage::WARR, loopLineNum, messageR, messageE, 2020));
|
||||
//}
|
||||
|
||||
static void addMessageRecursiveDependency(vector<Messages>& messages, string varName, int lineNum)
|
||||
{
|
||||
@@ -499,7 +519,7 @@ static string getDimensionVarName(SgSymbol* var, const vector<int>& subscripts,
|
||||
}
|
||||
|
||||
// getDimensionVarName returns var name in style A(1, 2, *)
|
||||
static string getDimensionVarName(SgSymbol* var, const vector<FixedSubscript>& fixedSubscripts)
|
||||
static string getDimensionVarName(SgSymbol* var, const vector<ArraySubscript>& fixedSubscripts)
|
||||
{
|
||||
string result = var->identifier();
|
||||
|
||||
@@ -607,14 +627,13 @@ static void fillReadShortFixedSubscripts(SgExpression* exp, const PrivateToRemov
|
||||
if (exp == nullptr)
|
||||
return;
|
||||
|
||||
if (exp->symbol() != nullptr)
|
||||
if (exp->symbol() != nullptr &&
|
||||
(exp->symbol()->variant() == ARRAY_REF || exp->symbol()->variant() == VARIABLE_NAME) &&
|
||||
isEqSymbols(exp->symbol(), var.varSymbol))
|
||||
{
|
||||
if (isEqSymbols(exp->symbol(), var.varSymbol))
|
||||
{
|
||||
auto subscripts = getShortFixedSubscriptsVector((SgArrayRefExp*)exp, var);
|
||||
fixedSubscripts.insert(subscripts);
|
||||
return;
|
||||
}
|
||||
auto subscripts = getShortFixedSubscriptsVector((SgArrayRefExp*)exp, var);
|
||||
fixedSubscripts.insert(subscripts);
|
||||
return;
|
||||
}
|
||||
|
||||
fillReadShortFixedSubscripts(exp->lhs(), var, fixedSubscripts);
|
||||
@@ -718,10 +737,23 @@ static map<SgSymbol*, SgExpression*> getVarToExpMap(SgArrayRefExp* defRef, SgArr
|
||||
|
||||
// removeArray removes array by substituting it in DEF-USE pairs.
|
||||
// Returns set of removed fixed subscripts
|
||||
static set<vector<int>> removeArray(string filename, const PrivateToRemove& arrayToRemove)
|
||||
static set<vector<int>> removeArray(string filename, PrivateToRemove& arrayToRemove)
|
||||
{
|
||||
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;
|
||||
for (auto& defUsePair : arrayToRemove.defUseStmtsPairs)
|
||||
{
|
||||
@@ -934,19 +966,6 @@ static vector<int> getShortFixedSubscriptsVector(Context* ctx, SgArrayRefExp* ar
|
||||
return getShortFixedSubscriptsVector(arrayRef, ctx->fixedDimensionsMask, ctx->regime, iterationVars);
|
||||
}
|
||||
|
||||
// fillIterationVariables fill vars set with iteration variables of all loops
|
||||
// from stmt to outerLoopStmt
|
||||
static void fillIterationVars(SgStatement* stmt, SgStatement* outerLoopStmt, vector<SgSymbol*>& vars)
|
||||
{
|
||||
if (stmt == nullptr)
|
||||
return;
|
||||
|
||||
if (stmt->variant() == FOR_NODE)
|
||||
vars.push_back(((SgForStmt*)stmt)->doName());
|
||||
|
||||
if (stmt->id() != outerLoopStmt->id())
|
||||
fillIterationVars(stmt->controlParent(), outerLoopStmt, vars);
|
||||
}
|
||||
|
||||
// matchesFixedDimensionsMask checks if all array references have INT_VAL value in fixed dimension
|
||||
static bool checkFixedDimensionsMaskMatching(Context* ctx)
|
||||
@@ -1058,6 +1077,7 @@ static bool checkRegularIndexRefs(Context* ctx)
|
||||
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)))
|
||||
@@ -1117,17 +1137,17 @@ static SgForStmt* getLoopStmtForVar(SgStatement* stmt, string loopVar)
|
||||
|
||||
// getFixedSubscriptsVector returns vector of fixed INT_VAL subscripts of arrayRef
|
||||
// true - subscript is fixed, false - it isn't
|
||||
static vector<FixedSubscript> getFixedSubscriptsVector(SgArrayRefExp* arrayRef, int dimensionsNum = 0,
|
||||
static vector<ArraySubscript> getFixedSubscriptsVector(SgArrayRefExp* arrayRef, int dimensionsNum = 0,
|
||||
SgStatement* stmt = nullptr)
|
||||
{
|
||||
if (arrayRef->numberOfSubscripts() == 0)
|
||||
return vector<FixedSubscript>(dimensionsNum);
|
||||
return vector<ArraySubscript>(dimensionsNum);
|
||||
|
||||
vector<FixedSubscript> subscriptsVector;
|
||||
vector<ArraySubscript> subscriptsVector;
|
||||
for (int i = 0; i < arrayRef->numberOfSubscripts(); ++i)
|
||||
{
|
||||
SgExpression* subscriptExpr = arrayRef->subscript(i);
|
||||
FixedSubscript sub;
|
||||
ArraySubscript sub;
|
||||
|
||||
if (subscriptExpr->variant() == INT_VAL)
|
||||
{
|
||||
@@ -1173,7 +1193,7 @@ static vector<FixedSubscript> getFixedSubscriptsVector(SgArrayRefExp* arrayRef,
|
||||
// checkImplicitDirectUsage returns masks of array implicit usage (as out argument)
|
||||
// in any function call in exp and writes message about each usage
|
||||
static void checkImplicitDirectUsage(Context* ctx, SgExpression* exp, int stmtLineNum,
|
||||
vector<vector<FixedSubscript>>& fixedSubscripts)
|
||||
vector<vector<ArraySubscript>>& fixedSubscripts)
|
||||
{
|
||||
if (exp == nullptr)
|
||||
return;
|
||||
@@ -1208,9 +1228,9 @@ static void checkImplicitDirectUsage(Context* ctx, SgExpression* exp, int stmtLi
|
||||
// checkImplicitDirectUsage returns masks of array implicit usage (as out argument)
|
||||
// and reference to whole array (like fcall(A, 1)) in any function call in loop
|
||||
// and writes message about each usage
|
||||
static vector<vector<FixedSubscript>> checkImplicitDirectUsage(Context* ctx)
|
||||
static vector<vector<ArraySubscript>> checkImplicitDirectUsage(Context* ctx)
|
||||
{
|
||||
vector<vector<FixedSubscript>> fixedSubscripts;
|
||||
vector<vector<ArraySubscript>> fixedSubscripts;
|
||||
for (SgStatement* st = ctx->loopStmt->lexNext(); st != ctx->loopStmt->lastNodeOfStmt(); st = st->lexNext())
|
||||
{
|
||||
if (st->variant() != PROC_STAT)
|
||||
@@ -1276,7 +1296,7 @@ static vector<Variable*> getCommonBlockGroupedVar(FuncInfo* curFunc, SgSymbol* v
|
||||
// checkIndirectUsage returns masks of array indirect usage in function
|
||||
// (indirect usage is usage through common blocks) and writes messages about it
|
||||
static void checkIndirectUsage(Context* ctx, FuncInfo* curFunc, vector<Variable*> commonBlockGroupedVar,
|
||||
set<string>& visitedFuncs, vector<vector<FixedSubscript>>& indirectUsageMasks)
|
||||
set<string>& visitedFuncs, vector<vector<ArraySubscript>>& indirectUsageMasks)
|
||||
{
|
||||
if (visitedFuncs.find(curFunc->funcName) != visitedFuncs.end())
|
||||
return;
|
||||
@@ -1307,9 +1327,9 @@ static void checkIndirectUsage(Context* ctx, FuncInfo* curFunc, vector<Variable*
|
||||
|
||||
// checkIndirectUsage returns masks of array indirect usage in any function call in loop
|
||||
// (indirect usage is usage through common blocks) and writes messages about it
|
||||
static vector<vector<FixedSubscript>> checkIndirectUsage(Context* ctx)
|
||||
static vector<vector<ArraySubscript>> checkIndirectUsage(Context* ctx)
|
||||
{
|
||||
vector<vector<FixedSubscript>> indirectUsageMasks;
|
||||
vector<vector<ArraySubscript>> indirectUsageMasks;
|
||||
FuncInfo* currentFunc = getCurrectFunc(ctx->loopStmt, ctx->allFuncInfo);
|
||||
if (currentFunc == nullptr)
|
||||
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
||||
@@ -1327,10 +1347,10 @@ static vector<vector<FixedSubscript>> checkIndirectUsage(Context* ctx)
|
||||
}
|
||||
|
||||
// checkImplicitAndIndirectUsage returns masks of implicit or indirect array usage in loop
|
||||
static vector<vector<FixedSubscript>> checkImplicitAndIndirectUsage(Context* ctx)
|
||||
static vector<vector<ArraySubscript>> checkImplicitAndIndirectUsage(Context* ctx)
|
||||
{
|
||||
vector<vector<FixedSubscript>> implicitMasks = checkImplicitDirectUsage(ctx);
|
||||
vector<vector<FixedSubscript>> indirectMasks = checkIndirectUsage(ctx);
|
||||
vector<vector<ArraySubscript>> implicitMasks = checkImplicitDirectUsage(ctx);
|
||||
vector<vector<ArraySubscript>> indirectMasks = checkIndirectUsage(ctx);
|
||||
|
||||
implicitMasks.insert(implicitMasks.end(), indirectMasks.begin(), indirectMasks.end());
|
||||
return implicitMasks;
|
||||
@@ -1338,7 +1358,7 @@ static vector<vector<FixedSubscript>> checkImplicitAndIndirectUsage(Context* ctx
|
||||
|
||||
// filterArrayRefs removes from arrayRefs all refs that are not different from fixedVectors
|
||||
static void filterArrayRefs(Context* ctx, vector<SgArrayRefExp*>& arrayRefs,
|
||||
const vector<vector<FixedSubscript>>& masks)
|
||||
const vector<vector<ArraySubscript>>& masks)
|
||||
{
|
||||
if (masks.empty())
|
||||
return;
|
||||
@@ -1346,7 +1366,7 @@ static void filterArrayRefs(Context* ctx, vector<SgArrayRefExp*>& arrayRefs,
|
||||
vector<SgArrayRefExp*> filteredArrayRefs;
|
||||
for (auto arrayRef : arrayRefs)
|
||||
{
|
||||
vector<FixedSubscript> arrayRefVec = getFixedSubscriptsVector(arrayRef, ctx->dimensionsNum);
|
||||
vector<ArraySubscript> arrayRefVec = getFixedSubscriptsVector(arrayRef, ctx->dimensionsNum);
|
||||
|
||||
bool isDifferent = false;
|
||||
for (auto& mask : masks)
|
||||
@@ -1609,17 +1629,18 @@ static vector<DefUseStmtsPair> buildDefUsePairs(Context* ctx, const CFG_Type& CF
|
||||
|
||||
if (!defIsFound)
|
||||
{
|
||||
// try to find definition not 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();
|
||||
SgStatement* blockStart = useInsAndBlock.second->getInstructions().front()->getInstruction()->getOperator();
|
||||
SgStatement* blockEnd = useInsAndBlock.second->getInstructions().back()->getInstruction()->getOperator();
|
||||
for (SgStatement* st = blockStart; st != blockEnd; st = st->lexNext())
|
||||
const auto& blockInstructionsVector = useInsAndBlock.second->getInstructions();
|
||||
for (auto& instruction : blockInstructionsVector)
|
||||
{
|
||||
if (st->variant() == ASSIGN_STAT && st->expr(0)->symbol()->identifier() == defVarName &&
|
||||
!isVarChangedBetween(defVarName, st, useInsertedStmt.insertedStmt))
|
||||
SgStatement* stmt = instruction->getInstruction()->getOperator();
|
||||
if (stmt->variant() == ASSIGN_STAT
|
||||
&& stmt->expr(0)->symbol()->identifier() == defVarName
|
||||
&& !isVarChangedBetween(defVarName, stmt, useInsertedStmt.insertedStmt))
|
||||
{
|
||||
defIsFound = true;
|
||||
defStmt = st;
|
||||
defStmt = stmt;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -1735,7 +1756,7 @@ static LoopGraph* leastCommonAncestor(LoopGraph* a, LoopGraph* b, LoopGraph* par
|
||||
// fillFullFixedSubscriptsVectorsOfAllVars return vector of pairs (name of var, its fixed subscripts vector)
|
||||
// of all VAR_REF and ARRAY_REF vars in exp
|
||||
static void fillFixedSubscriptsVectorsOfAllVars(SgExpression* exp,
|
||||
vector<pair<string, vector<FixedSubscript>>>& vec,
|
||||
vector<pair<string, vector<ArraySubscript>>>& vec,
|
||||
SgStatement* stmt = nullptr)
|
||||
{
|
||||
if (exp == nullptr)
|
||||
@@ -1749,7 +1770,7 @@ static void fillFixedSubscriptsVectorsOfAllVars(SgExpression* exp,
|
||||
if (elem.first == exp->symbol()->identifier())
|
||||
return;
|
||||
|
||||
vec.push_back(make_pair(exp->symbol()->identifier(), vector<FixedSubscript>{}));
|
||||
vec.push_back(make_pair(exp->symbol()->identifier(), vector<ArraySubscript>{}));
|
||||
}
|
||||
else if (exp->variant() == ARRAY_REF)
|
||||
{
|
||||
@@ -1768,7 +1789,7 @@ static void fillFixedSubscriptsVectorsOfAllVars(SgExpression* exp,
|
||||
}
|
||||
|
||||
// fixedSubscriptLess checks if left FixedSubscript is less than right
|
||||
static bool fixedSubscriptLess(const FixedSubscript& left, const FixedSubscript& right)
|
||||
static bool fixedSubscriptLess(const ArraySubscript& left, const ArraySubscript& right)
|
||||
{
|
||||
if (left.isFixed && right.isFixed && left.value < right.value)
|
||||
return true;
|
||||
@@ -1789,7 +1810,7 @@ static bool fixedSubscriptLess(const FixedSubscript& left, const FixedSubscript&
|
||||
|
||||
// fixedSubscriptLess checks if left and right FixedSubscripts are different,
|
||||
// using empirical methods
|
||||
static bool possibleDifferent(FixedSubscript left, FixedSubscript right)
|
||||
static bool possibleDifferent(ArraySubscript left, ArraySubscript right)
|
||||
{
|
||||
// TODO: add warning?
|
||||
if (left.isFixed && right.isRegIndex && right.regExprStart == right.regExprEnd) {
|
||||
@@ -1801,7 +1822,7 @@ static bool possibleDifferent(FixedSubscript left, FixedSubscript right)
|
||||
|
||||
// isDifferentRefs checks if exp (var reference) is different from var. Refs are different
|
||||
// if they has at least one different fixed subscript: arr(i, 1) is different from arr(j, 2)
|
||||
static bool isDifferentRefs(SgExpression* exp, const pair<string, vector<FixedSubscript>>& var, SgStatement* stmt)
|
||||
static bool isDifferentRefs(SgExpression* exp, const pair<string, vector<ArraySubscript>>& var, SgStatement* stmt)
|
||||
{
|
||||
if (exp->symbol()->identifier() != var.first)
|
||||
return true;
|
||||
@@ -1809,7 +1830,7 @@ static bool isDifferentRefs(SgExpression* exp, const pair<string, vector<FixedSu
|
||||
if (exp->variant() == VAR_REF)
|
||||
return false;
|
||||
|
||||
vector<FixedSubscript> leftVec = getFixedSubscriptsVector((SgArrayRefExp*)exp, 0, stmt);
|
||||
vector<ArraySubscript> leftVec = getFixedSubscriptsVector((SgArrayRefExp*)exp, 0, stmt);
|
||||
|
||||
if (leftVec.size() != var.second.size())
|
||||
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
||||
@@ -1852,7 +1873,7 @@ static bool checkDefUsePair(Context* ctx, const DefUseStmtsPair& defUse, const C
|
||||
|
||||
string arrayName = ctx->arraySymbol->identifier();
|
||||
|
||||
vector<pair<string, vector<FixedSubscript>>> dependOnVars;
|
||||
vector<pair<string, vector<ArraySubscript>>> dependOnVars;
|
||||
SgArrayRefExp* defRef = (SgArrayRefExp*)defUse.first->expr(0);
|
||||
vector<SgArrayRefExp*> arrayUseRefs = getDirectArrayRefsFromSingleStmt(defUse.second, ctx->arraySymbol);
|
||||
for (auto useRef : arrayUseRefs)
|
||||
|
||||
Reference in New Issue
Block a user