Merge pull request 'private_removing: update interprocedure analysis' (#38) from private_removing into master
This commit was merged in pull request #38.
This commit is contained in:
@@ -290,20 +290,17 @@ static bool isSymbolInExpression(SgSymbol* symbol, SgExpression* exp)
|
|||||||
isSymbolInExpression(symbol, exp->rhs());
|
isSymbolInExpression(symbol, exp->rhs());
|
||||||
}
|
}
|
||||||
|
|
||||||
static FuncInfo* findFunc(string fileName, string funcName, const map<string, vector<FuncInfo*>>& allFuncInfo)
|
static FuncInfo* findFuncByName(string funcName, const map<string, vector<FuncInfo*>>& allFuncInfo)
|
||||||
{
|
{
|
||||||
auto fileInfo = allFuncInfo.find(fileName);
|
for (const auto& fileFuncs : allFuncInfo)
|
||||||
if (fileInfo == allFuncInfo.end())
|
for (auto funcInfo : fileFuncs.second)
|
||||||
return nullptr;
|
if (funcInfo->funcName == funcName)
|
||||||
|
return funcInfo;
|
||||||
for (auto funcInfo : fileInfo->second)
|
|
||||||
if (funcInfo->funcName == funcName)
|
|
||||||
return funcInfo;
|
|
||||||
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
static FuncInfo* getCurrectFunc(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());
|
||||||
if (fileInfo == allFuncInfo.end())
|
if (fileInfo == allFuncInfo.end())
|
||||||
@@ -855,7 +852,7 @@ void removePrivates(string filename, vector<Messages>& messages,
|
|||||||
for (auto& dcLoopRem : removeDC)
|
for (auto& dcLoopRem : removeDC)
|
||||||
{
|
{
|
||||||
auto loopStmt = dcLoopRem->loop->GetOriginal();
|
auto loopStmt = dcLoopRem->loop->GetOriginal();
|
||||||
FuncInfo* currFunc = getCurrectFunc(loopStmt, allFuncInfo);
|
FuncInfo* currFunc = getCurrentFunc(loopStmt, allFuncInfo);
|
||||||
|
|
||||||
if (currFunc == nullptr)
|
if (currFunc == nullptr)
|
||||||
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
||||||
@@ -1140,7 +1137,7 @@ static SgForStmt* getLoopStmtForVar(SgStatement* stmt, string loopVar)
|
|||||||
static vector<ArraySubscript> getFixedSubscriptsVector(SgArrayRefExp* arrayRef, int dimensionsNum = 0,
|
static vector<ArraySubscript> getFixedSubscriptsVector(SgArrayRefExp* arrayRef, int dimensionsNum = 0,
|
||||||
SgStatement* stmt = nullptr)
|
SgStatement* stmt = nullptr)
|
||||||
{
|
{
|
||||||
if (arrayRef->numberOfSubscripts() == 0)
|
if (arrayRef == nullptr || arrayRef->numberOfSubscripts() == 0)
|
||||||
return vector<ArraySubscript>(dimensionsNum);
|
return vector<ArraySubscript>(dimensionsNum);
|
||||||
|
|
||||||
vector<ArraySubscript> subscriptsVector;
|
vector<ArraySubscript> subscriptsVector;
|
||||||
@@ -1202,7 +1199,7 @@ static void checkImplicitDirectUsage(Context* ctx, SgExpression* exp, int stmtLi
|
|||||||
{
|
{
|
||||||
SgFunctionCallExp* funcCallExp = (SgFunctionCallExp*)exp;
|
SgFunctionCallExp* funcCallExp = (SgFunctionCallExp*)exp;
|
||||||
string funcName = funcCallExp->funName()->identifier();
|
string funcName = funcCallExp->funName()->identifier();
|
||||||
FuncInfo* funcInfo = findFunc(ctx->loopStmt->fileName(), funcName, ctx->allFuncInfo);
|
FuncInfo* funcInfo = findFuncByName(funcName, ctx->allFuncInfo);
|
||||||
if (funcInfo != nullptr)
|
if (funcInfo != nullptr)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < funcCallExp->numberOfArgs(); ++i)
|
for (int i = 0; i < funcCallExp->numberOfArgs(); ++i)
|
||||||
@@ -1244,7 +1241,7 @@ static vector<vector<ArraySubscript>> checkImplicitDirectUsage(Context* ctx)
|
|||||||
// st->variant() == PROC_STAT:
|
// st->variant() == PROC_STAT:
|
||||||
SgCallStmt* callStmt = (SgCallStmt*)st;
|
SgCallStmt* callStmt = (SgCallStmt*)st;
|
||||||
string procName = callStmt->name()->identifier();
|
string procName = callStmt->name()->identifier();
|
||||||
FuncInfo* funcInfo = findFunc(callStmt->fileName(), procName, ctx->allFuncInfo);
|
FuncInfo* funcInfo = findFuncByName(procName, ctx->allFuncInfo);
|
||||||
|
|
||||||
for (int i = 0; i < callStmt->numberOfArgs(); ++i)
|
for (int i = 0; i < callStmt->numberOfArgs(); ++i)
|
||||||
{
|
{
|
||||||
@@ -1295,34 +1292,37 @@ static vector<Variable*> getCommonBlockGroupedVar(FuncInfo* curFunc, SgSymbol* v
|
|||||||
|
|
||||||
// checkIndirectUsage returns masks of array indirect usage in function
|
// checkIndirectUsage returns masks of array indirect usage in function
|
||||||
// (indirect usage is usage through common blocks) and writes messages about it
|
// (indirect usage is usage through common blocks) and writes messages about it
|
||||||
static void checkIndirectUsage(Context* ctx, FuncInfo* curFunc, vector<Variable*> commonBlockGroupedVar,
|
static void checkIndirectUsage(Context* ctx, FuncInfo* calledFunc, vector<Variable*> commonBlockGroupedVar,
|
||||||
set<string>& visitedFuncs, vector<vector<ArraySubscript>>& indirectUsageMasks)
|
set<string>& visitedFuncs, vector<vector<ArraySubscript>>& indirectUsageMasks)
|
||||||
{
|
{
|
||||||
if (visitedFuncs.find(curFunc->funcName) != visitedFuncs.end())
|
if (visitedFuncs.find(calledFunc->funcName) != visitedFuncs.end())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
visitedFuncs.insert(curFunc->funcName);
|
visitedFuncs.insert(calledFunc->funcName);
|
||||||
|
|
||||||
for (Variable* commonBlockVar : commonBlockGroupedVar)
|
for (Variable* commonBlockVar : commonBlockGroupedVar)
|
||||||
{
|
{
|
||||||
for (const CommonVariableUse& varUse : commonBlockVar->getAllUse())
|
for (const CommonVariableUse& varUse : commonBlockVar->getAllUse())
|
||||||
{
|
{
|
||||||
if (varUse.getFileName() != curFunc->fileName || varUse.getFunctionName() != curFunc->funcName)
|
if (varUse.getFileName() != calledFunc->fileName || varUse.getFunctionName() != calledFunc->funcName)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
vector<SgArrayRefExp*> directArrayRefs = getDirectArrayRefs(varUse.getFunction(), varUse.getUseS());
|
SgStatement* calledFuncStmt = varUse.getFunction();
|
||||||
|
calledFuncStmt->switchToFile();
|
||||||
|
vector<SgArrayRefExp*> directArrayRefs = getDirectArrayRefs(calledFuncStmt, varUse.getUseS());
|
||||||
for (auto arrayRef : directArrayRefs)
|
for (auto arrayRef : directArrayRefs)
|
||||||
{
|
{
|
||||||
auto mask = getFixedSubscriptsVector(arrayRef, ctx->dimensionsNum);
|
auto mask = getFixedSubscriptsVector(arrayRef, ctx->dimensionsNum);
|
||||||
indirectUsageMasks.push_back(mask);
|
indirectUsageMasks.push_back(mask);
|
||||||
addMessageUsageInFunctionCall(ctx->messages, getDimensionVarName(ctx->arraySymbol, mask),
|
addMessageUsageInFunctionCall(ctx->messages, getDimensionVarName(ctx->arraySymbol, mask),
|
||||||
curFunc->funcName, ctx->loop->lineNum, ctx->loop->lineNum);
|
calledFunc->funcName, ctx->loop->lineNum, ctx->loop->lineNum);
|
||||||
}
|
}
|
||||||
|
ctx->loopStmt->switchToFile();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (FuncInfo* calledFunc : curFunc->callsFromV)
|
for (FuncInfo* subCalledFunc : calledFunc->callsFromV)
|
||||||
checkIndirectUsage(ctx, calledFunc, commonBlockGroupedVar, visitedFuncs, indirectUsageMasks);
|
checkIndirectUsage(ctx, subCalledFunc, commonBlockGroupedVar, visitedFuncs, indirectUsageMasks);
|
||||||
}
|
}
|
||||||
|
|
||||||
// checkIndirectUsage returns masks of array indirect usage in any function call in loop
|
// checkIndirectUsage returns masks of array indirect usage in any function call in loop
|
||||||
@@ -1330,7 +1330,7 @@ static void checkIndirectUsage(Context* ctx, FuncInfo* curFunc, vector<Variable*
|
|||||||
static vector<vector<ArraySubscript>> checkIndirectUsage(Context* ctx)
|
static vector<vector<ArraySubscript>> checkIndirectUsage(Context* ctx)
|
||||||
{
|
{
|
||||||
vector<vector<ArraySubscript>> indirectUsageMasks;
|
vector<vector<ArraySubscript>> indirectUsageMasks;
|
||||||
FuncInfo* currentFunc = getCurrectFunc(ctx->loopStmt, ctx->allFuncInfo);
|
FuncInfo* currentFunc = getCurrentFunc(ctx->loopStmt, ctx->allFuncInfo);
|
||||||
if (currentFunc == nullptr)
|
if (currentFunc == nullptr)
|
||||||
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
||||||
|
|
||||||
@@ -1338,10 +1338,17 @@ static vector<vector<ArraySubscript>> checkIndirectUsage(Context* ctx)
|
|||||||
if (commonBlockGroupedVar.empty())
|
if (commonBlockGroupedVar.empty())
|
||||||
return indirectUsageMasks;
|
return indirectUsageMasks;
|
||||||
|
|
||||||
|
|
||||||
set<string> visitedFunctions = { currentFunc->funcName };
|
set<string> visitedFunctions = { currentFunc->funcName };
|
||||||
for (FuncInfo* calledFunc : currentFunc->callsFromV)
|
for (SgStatement* st = ctx->loopStmt->lexNext(); st != ctx->loopStmt->lastNodeOfStmt(); st = st->lexNext())
|
||||||
checkIndirectUsage(ctx, calledFunc, commonBlockGroupedVar, visitedFunctions, indirectUsageMasks);
|
{
|
||||||
|
if (st->variant() == PROC_STAT)
|
||||||
|
{
|
||||||
|
SgCallStmt* callStmt = (SgCallStmt*)st;
|
||||||
|
string procName = callStmt->name()->identifier();
|
||||||
|
FuncInfo* calledFunc = findFuncByName(procName, ctx->allFuncInfo);
|
||||||
|
checkIndirectUsage(ctx, calledFunc, commonBlockGroupedVar, visitedFunctions, indirectUsageMasks);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return indirectUsageMasks;
|
return indirectUsageMasks;
|
||||||
}
|
}
|
||||||
@@ -2136,8 +2143,8 @@ void removePrivatesAnalysis(string filename,
|
|||||||
|
|
||||||
auto filterMasks = checkImplicitAndIndirectUsage(&context);
|
auto filterMasks = checkImplicitAndIndirectUsage(&context);
|
||||||
filterArrayRefs(&context, arrayRefs, filterMasks);
|
filterArrayRefs(&context, arrayRefs, filterMasks);
|
||||||
context.explicitArrayRefs.swap(arrayRefs);
|
|
||||||
|
|
||||||
|
context.explicitArrayRefs.swap(arrayRefs);
|
||||||
if (context.explicitArrayRefs.empty())
|
if (context.explicitArrayRefs.empty())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user