insert param stsmts & load block fixed

This commit is contained in:
2024-05-07 18:02:49 +03:00
parent b4f8f223eb
commit bcd3f49a72

View File

@@ -594,30 +594,35 @@ static void renameEx(SgExpression* sizeEx, const char* funcName) {
renameEx(sizeEx->rhs(), funcName);
}
static void findSizeEx(SgExpression* sizeEx, const map<string, SgStatement*>& moduleStmts, const map<string, SgStatement*>& moduleParamStmts, SgStatement* proc_moduleF, set<string>& addedModuleParams) {
static void findSizeEx(SgExpression* sizeEx, const map<string, SgStatement*>& moduleStmts,
const map<string, SgStatement*>& moduleParamStmts, SgStatement* proc_moduleF,
set<string>& addedModuleParams, SgStatement* borderStmt) {
if (sizeEx->variant() == CONST_REF) {
if (moduleParamStmts.count(sizeEx->symbol()->identifier()) == 1 && addedModuleParams.count(sizeEx->symbol()->identifier()) == 0) {
auto decl = (SgParameterStmt*)moduleParamStmts.at(sizeEx->symbol()->identifier());
SgStatement* copyParamStmt = moduleParamStmts.at(sizeEx->symbol()->identifier())->copyPtr();
proc_moduleF->insertStmtAfter(*copyParamStmt, *proc_moduleF);
borderStmt->insertStmtBefore(*copyParamStmt, *proc_moduleF);
if (moduleStmts.count(sizeEx->symbol()->identifier())) {
SgStatement* copyStmt = moduleStmts.at(sizeEx->symbol()->identifier())->copyPtr();
proc_moduleF->insertStmtAfter(*copyStmt, *proc_moduleF);
copyParamStmt->insertStmtBefore(*copyStmt, *proc_moduleF);
borderStmt = copyStmt;
}
else
borderStmt = copyParamStmt;
addedModuleParams.insert(sizeEx->symbol()->identifier());
findSizeEx(decl->value(0), moduleStmts, moduleParamStmts, proc_moduleF, addedModuleParams);
findSizeEx(decl->value(0), moduleStmts, moduleParamStmts, proc_moduleF, addedModuleParams, borderStmt);
}
}
if (sizeEx->lhs())
findSizeEx(sizeEx->lhs(), moduleStmts, moduleParamStmts, proc_moduleF, addedModuleParams);
findSizeEx(sizeEx->lhs(), moduleStmts, moduleParamStmts, proc_moduleF, addedModuleParams, borderStmt);
if (sizeEx->rhs())
findSizeEx(sizeEx->rhs(), moduleStmts, moduleParamStmts, proc_moduleF, addedModuleParams);
findSizeEx(sizeEx->rhs(), moduleStmts, moduleParamStmts, proc_moduleF, addedModuleParams, borderStmt);
}
static void processCommonStmt(SgStatement* st, set<string>& commonVariables)
@@ -763,6 +768,9 @@ static void insertStmtToModule(const map<string, SgStatement*>& moduleStmts, con
{
SgStatement* endProcModuleF = proc_moduleF->lastNodeOfStmt();
SgStatement* borderStmt = new SgStatement(VAR_DECL);
proc_moduleF->insertStmtAfter(*borderStmt, *proc_moduleF);
for (const auto& [varName, varStmt] : moduleStmts) {
string varNameNoPref = varName;
@@ -784,13 +792,15 @@ static void insertStmtToModule(const map<string, SgStatement*>& moduleStmts, con
while (sizeEx && sizeEx->lhs()) {
sizeLhs = sizeEx->lhs();
findSizeEx(sizeLhs, moduleStmts, moduleParamStmts, proc_moduleF, addedModuleParams);
findSizeEx(sizeLhs, moduleStmts, moduleParamStmts, proc_moduleF, addedModuleParams, borderStmt);
sizeEx = sizeEx->rhs();
}
}
}
}
borderStmt->deleteStmt();
}
static SgStatement* createLoadBlock(const vector<SgSymbol*>& loadS, FuncInfo*& funcI, SgExpression* iostat, SgArrayRefExp* journal,
@@ -873,10 +883,10 @@ static SgStatement* createLoadBlock(const vector<SgSymbol*>& loadS, FuncInfo*& f
}
//READ LOCAL DATA
vector<string> varNames;
if (moduleStmts.size())
{
vector<SgExpression*> variablesVec;
vector<string> varNames;
for (auto localVar : localVarNoParams)
{
const char* varName = localVar.c_str();
@@ -890,8 +900,8 @@ static SgStatement* createLoadBlock(const vector<SgSymbol*>& loadS, FuncInfo*& f
auto dataRead = new SgInputOutputStmt(READ_STAT, unit, *makeExprList(variablesVec, false));
ifLoadOk1->insertStmtAfter(*dataRead, *ifLoadOk1);
chainLocalVarNoParams.push_back(varNames);
}
chainLocalVarNoParams.push_back(varNames);
if (!isBaseFunc)
{
@@ -1159,16 +1169,29 @@ static void processFunctionCallChain(SgStatement* func, const vector<FuncInfo*>&
SgStatement* hedrTo = funcTo->funcPointer->GetOriginal();
SgStatement* hedrFrom = funcFrom->funcPointer->GetOriginal();
SgStatement* lastDecl = hedrFrom->lexNext();
while (lastDecl && !isSgExecutableStatement(lastDecl->lexNext()))
lastDecl = lastDecl->lexNext();
SgStatement* firstExec;
if (isSgExecutableStatement(lastDecl))
{
firstExec = lastDecl;
lastDecl = NULL;
}
else
{
while (lastDecl && !isSgExecutableStatement(lastDecl->lexNext()))
lastDecl = lastDecl->lexNext();
firstExec = lastDecl->lexNext();
}
SgStatement* firstExec = lastDecl->lexNext();
vector<SgExpression*> local;
map<string, SgStatement*> localParams;
set<string> addedToList;
if (!processedFrom.count(funcFrom))
{
if (funcFrom->isMain)
insertInitNamesOfFiles(numOfFiles, additional, files, journal, firstExec);
SgSymbol* timeF = new SgSymbol(FUNCTION_NAME, "omp_get_wtime", SgTypeDouble(), func); // OR dvtime
SgStatement* profCallS = new SgAssignStmt(*new SgVarRefExp(profS[0]), *new SgFunctionCallExp(*timeF));
@@ -1219,13 +1242,11 @@ static void processFunctionCallChain(SgStatement* func, const vector<FuncInfo*>&
moduleNames, unitNum, funcI->funcName, chainLocalVarNoParams, false, procLabelSymb);
firstExec->insertStmtBefore(*loadBlock, *firstExec->controlParent());
if (funcFrom->isMain)
insertInitNamesOfFiles(numOfFiles, additional, files, journal, lastDecl, false);
SgStatement* gotoBlock = new SgStatement(IF_NODE);
gotoBlock->addComment("! goto next program unit\n");
gotoBlock->setExpression(0, *new SgVarRefExp(loadS[0]) == *new SgValueExp(1));
firstExec->insertStmtBefore(*gotoBlock, *firstExec->controlParent());
loadBlock->insertStmtAfter(*gotoBlock, *loadBlock->controlParent());
// insert gotoBlock and save to module
processAllCalls(firstExec, funcTo->funcName, funcFrom->funcName, gotoBlock, localVarNoParams, procLabelSymb);