findlocaldata

This commit is contained in:
2023-12-20 16:31:16 +03:00
parent 41fdfcf3f8
commit 36e401b5d2

View File

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