Merge pull request 'findlocaldata' (#20) from CP into master

This commit was merged in pull request #20.
This commit is contained in:
2023-12-22 07:50:30 +00:00

View File

@@ -38,7 +38,7 @@ static SgType* createArrayCharType(int len, int dim)
}
static void findDecls(SgExpression* ex, vector<SgExpression*>& local, const map<string, SgStatement*>& localParams,
set<string>& added)
set<string>& added, set<string>& IntentInParams)
{
if (ex)
{
@@ -47,7 +47,8 @@ static void findDecls(SgExpression* ex, vector<SgExpression*>& local, const map<
if (ex->symbol()->variant() == VARIABLE_NAME &&
localParams.find(ex->symbol()->identifier()) == localParams.end())
{
if (added.find(ex->symbol()->identifier()) == added.end())
if (added.find(ex->symbol()->identifier()) == added.end() &&
IntentInadded.find(ex->symbol()->identifier()) == IntentInadded.end())
{
added.insert(ex->symbol()->identifier());
local.push_back(ex);
@@ -58,21 +59,42 @@ static void findDecls(SgExpression* ex, vector<SgExpression*>& local, const map<
if (ex->variant() == ARRAY_REF)
{
if (ex->symbol()->variant() == VARIABLE_NAME &&
added.find(ex->symbol()->identifier()) == added.end())
added.find(ex->symbol()->identifier()) == added.end() &&
IntentInadded.find(ex->symbol()->identifier()) == IntentInadded.end())
{
added.insert(ex->symbol()->identifier());
local.push_back(new SgArrayRefExp(*ex->symbol()));
}
}
findDecls(ex->lhs(), local, localParams, added);
findDecls(ex->rhs(), local, localParams, added);
findDecls(ex->lhs(), local, localParams, added, IntentInParams);
findDecls(ex->rhs(), local, localParams, added, IntentInParams);
}
}
static void findLocalData(SgStatement* start, SgStatement* end, vector<SgExpression*>& local,
map<string, SgStatement*>& localParams, set<string>& added)
static FuncInfo* findFileInfoByName(SgStatement* func, const vector<FuncInfo*>& allFuncInfo)
{
FuncInfo* funcI = NULL;
for (auto& funcs : allFuncInfo)
if (funcs->funcName == func->symbol()->identifier())
funcI = funcs;
checkNull(funcI, convertFileName(__FILE__).c_str(), __LINE__);
return funcI;
}
static void findLocalData(SgStatement* func, SgStatement* end, vector<SgExpression*>& local,
map<string, SgStatement*>& localParams, set<string>& added, const vector<FuncInfo*>& allFuncInfo)
{
SgStatement* start = func->lexNext();
FuncInfo* funcI = findFileInfoByName(func, allFuncInfo);
set<string> IntentInParams;
for (int i = 0; i < funcI->funcParams.countOfPars; ++i)
if (funcI->funcParams.isArgIn(i) && !funcI->funcParams.isArgOut(i))
IntentInParams.insert(funcI->funcParams.identificators[i]);
for (SgStatement* st = start; st != end; st = st->lexNext())
{
if (st->variant() == PARAM_DECL)
@@ -92,7 +114,7 @@ static void findLocalData(SgStatement* start, SgStatement* end, vector<SgExpress
{
//printf("line %d %s Var %s\n", st->lineNumber(), st->fileName(), tag[st->variant()]);
if (st->variant() == VAR_DECL || st->variant() == VAR_DECL_90)
findDecls(st->expr(0), local, localParams, added);
findDecls(st->expr(0), local, localParams, added, IntentInParams);
}
}
@@ -529,11 +551,7 @@ static void processFunctionCallChain(SgStatement* func, const vector<FuncInfo*>&
const int every, const vector<SgSymbol*>& everyS)
{
//find function structure
FuncInfo* funcI = NULL;
for (auto& funcs : allFuncInfo)
if (funcs->funcName == func->symbol()->identifier())
funcI = funcs;
checkNull(funcI, convertFileName(__FILE__).c_str(), __LINE__);
FuncInfo* funcI = findFileInfoByName(func, allFuncInfo);
set<pair<FuncInfo*, FuncInfo*>> toProcess;
fillToProcess(funcI, toProcess);
@@ -555,7 +573,7 @@ static void processFunctionCallChain(SgStatement* func, const vector<FuncInfo*>&
vector<SgExpression*> local;
map<string, SgStatement*> localParams;
set<string> addedToList;
findLocalData(hedrFrom->lexNext(), firstExec, local, localParams, addedToList);
findLocalData(hedrFrom, firstExec, local, localParams, addedToList, allFuncInfo);
if (!processedFrom.count(funcFrom))
{
@@ -720,7 +738,7 @@ static void processFunctionCallChain(SgStatement* func, const vector<FuncInfo*>&
}
}
static void processModules(SgFile* file)
static void processModules(SgFile* file, const vector<FuncInfo*>& allFuncInfo)
{
vector<SgStatement*> modules;
findModulesInFile(file, modules);
@@ -740,7 +758,7 @@ static void processModules(SgFile* file)
vector<SgExpression*> local;
map<string, SgStatement*> localParams;
set<string> addedToList;
findLocalData(mod->lexNext(), hasContains ? st : mod->lastNodeOfStmt(), local, localParams, addedToList);
findLocalData(mod, hasContains ? st : mod->lastNodeOfStmt(), local, localParams, addedToList, allFuncInfo);
SgProcHedrStmt* newF = new SgProcHedrStmt((string("spf_cp_") + mod->symbol()->identifier()).c_str());
if (!hasContains)
@@ -772,7 +790,7 @@ void createCheckpoints(SgFile* file, const map<string, CommonBlock*>& commonBloc
if (!inFile)
{
processModules(file);
processModules(file, allFuncInfo);
return;
}
@@ -832,7 +850,7 @@ void createCheckpoints(SgFile* file, const map<string, CommonBlock*>& commonBloc
vector<SgExpression*> local;
map<string, SgStatement*> localParams;
set<string> addedToList;
findLocalData(func->lexNext(), firstExec, local, localParams, addedToList);
findLocalData(func, firstExec, local, localParams, addedToList, allFuncInfo);
const vector<SgStatement*> useOfMods = findUseOfModules(func->lexNext(), firstExec);
SgStatement* loadBlock = new SgStatement(IF_NODE);
@@ -1165,7 +1183,7 @@ void createCheckpoints(SgFile* file, const map<string, CommonBlock*>& commonBloc
//processFunctionCallChain(func, allFuncInfo, moduleF, loadS, iostat, journal, frmt, unit, files, fileIdx, every, everyS);
}
processModules(file);
processModules(file, allFuncInfo);
}
static string cuttingType(const string& all_decl_with_init)