From bcd3f49a72ac8027f7ab0d56257a4cc4ab1d5224 Mon Sep 17 00:00:00 2001 From: AntonMilienkov Date: Tue, 7 May 2024 18:02:49 +0300 Subject: [PATCH] insert param stsmts & load block fixed --- .../_src/Transformations/checkpoints.cpp | 51 +++++++++++++------ 1 file changed, 36 insertions(+), 15 deletions(-) diff --git a/sapfor/experts/Sapfor_2017/_src/Transformations/checkpoints.cpp b/sapfor/experts/Sapfor_2017/_src/Transformations/checkpoints.cpp index b2189e6..f6906c2 100644 --- a/sapfor/experts/Sapfor_2017/_src/Transformations/checkpoints.cpp +++ b/sapfor/experts/Sapfor_2017/_src/Transformations/checkpoints.cpp @@ -594,30 +594,35 @@ static void renameEx(SgExpression* sizeEx, const char* funcName) { renameEx(sizeEx->rhs(), funcName); } -static void findSizeEx(SgExpression* sizeEx, const map& moduleStmts, const map& moduleParamStmts, SgStatement* proc_moduleF, set& addedModuleParams) { +static void findSizeEx(SgExpression* sizeEx, const map& moduleStmts, + const map& moduleParamStmts, SgStatement* proc_moduleF, + set& 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& commonVariables) @@ -763,6 +768,9 @@ static void insertStmtToModule(const map& 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& 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& loadS, FuncInfo*& funcI, SgExpression* iostat, SgArrayRefExp* journal, @@ -873,10 +883,10 @@ static SgStatement* createLoadBlock(const vector& loadS, FuncInfo*& f } //READ LOCAL DATA + vector varNames; if (moduleStmts.size()) { vector variablesVec; - vector varNames; for (auto localVar : localVarNoParams) { const char* varName = localVar.c_str(); @@ -890,8 +900,8 @@ static SgStatement* createLoadBlock(const vector& 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& 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 local; map localParams; set 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& 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);