From 405a0423b169532c5f5357b054e8a8012c924cea Mon Sep 17 00:00:00 2001 From: ALEXks Date: Thu, 2 May 2024 11:00:12 +0300 Subject: [PATCH] fixed module added minor improvements --- .../_src/Transformations/checkpoints.cpp | 81 ++++++++----------- 1 file changed, 33 insertions(+), 48 deletions(-) diff --git a/sapfor/experts/Sapfor_2017/_src/Transformations/checkpoints.cpp b/sapfor/experts/Sapfor_2017/_src/Transformations/checkpoints.cpp index 96c382f..8ee6a6a 100644 --- a/sapfor/experts/Sapfor_2017/_src/Transformations/checkpoints.cpp +++ b/sapfor/experts/Sapfor_2017/_src/Transformations/checkpoints.cpp @@ -16,6 +16,22 @@ enum class typeEvery { TIME, ITER }; static const vector iosNames = { "spf_close_all", "spf_open_all", "spf_inc_num_part" }; +static void createModule(SgStatement*& module, const string& name, bool withFile = true) +{ + if (module == NULL) + { + string full_name = name; + if (withFile) + full_name += "_" + to_string(current_file_id); + + module = new SgStatement(MODULE_STMT, NULL, new SgSymbol(MODULE_NAME, full_name.c_str())); + addControlEndToStmt(module->thebif); + + SgStatement* global = current_file->firstStatement(); + global->insertStmtAfter(*module, *global); + } +} + static SgType* createArrayCharType(int len, int dim) { if (dim == 0) @@ -246,7 +262,6 @@ static void insertToOpenClose(const map& needToSave, const vecto printInternalError(convertFileName(__FILE__).c_str(), __LINE__); } -static void createModule(SgStatement*& module, const string& name, bool withFile = true); static bool createForIOs(const map& filesInfo, SgStatement* func) { SgStatement* moduleF = NULL; @@ -790,11 +805,9 @@ static SgStatement* createLoadBlock(const vector& loadS, FuncInfo*& f const char* funcName = funcI->funcName.c_str(); vector insertToLoadS; - SgStatement* loadBlock = new SgStatement(IF_NODE); + SgStatement* loadBlock = new SgIfStmt(*new SgVarRefExp(loadS[4]) == *new SgValueExp(1)); //*new SgVarRefExp(loadS[0]) loadBlock->addComment("! LOAD CHECKPOINT\n"); - loadBlock->setExpression(0, *new SgVarRefExp(loadS[4]) == *new SgValueExp(1)); //*new SgVarRefExp(loadS[0]) - if (funcI->isMain) { SgAssignStmt* init = new SgAssignStmt(*new SgVarRefExp(loadS[4]), *new SgValueExp(0)); @@ -941,8 +954,7 @@ static SgStatement* createSaveBlock(const vector& loadS, FuncInfo*& f const vector& moduleNames, const int unitNum, const vector>& chainLocalVarNoParams, const vector& chainLabel) { - SgStatement* storeBlock = new SgStatement(IF_NODE); - + SgStatement* storeBlock = new SgIfStmt(IF_NODE); vector listSpec; listSpec.push_back(&SgAssignOp(*new SgKeywordValExp("form"), *new SgValueExp("unformatted"))); @@ -1074,7 +1086,7 @@ static SgStatement* createSaveBlock(const vector& loadS, FuncInfo*& f return storeBlock; } -static void saveVarToModule(const set& localVarNoParams, SgStatement* callPE, const char* funcName, +static void saveVarToModule(const set& localVarNoParams, SgStatement* callPU, const char* funcName, SgSymbol* procLabelSymb, const int labNum) { for (auto localVar : localVarNoParams) @@ -1083,12 +1095,12 @@ static void saveVarToModule(const set& localVarNoParams, SgStatement* ca SgExpression* rightEx = new SgVarRefExp(rightSymb); SgSymbol* leftSymb = renamedNewSymb(rightSymb, funcName); SgExpression* leftEx = new SgVarRefExp(leftSymb); - callPE->insertStmtBefore(*new SgAssignStmt(*leftEx, *rightEx), *callPE->controlParent()); + callPU->insertStmtBefore(*new SgAssignStmt(*leftEx, *rightEx), *callPU->controlParent()); } SgExpression* procLabelExpr = new SgVarRefExp(procLabelSymb); SgExpression* labNumExpr = new SgValueExp(labNum); - callPE->insertStmtBefore(*new SgAssignStmt(*procLabelExpr, *labNumExpr), *callPE->controlParent()); + callPU->insertStmtBefore(*new SgAssignStmt(*procLabelExpr, *labNumExpr), *callPU->controlParent()); } static void processAllCalls(SgStatement* firstExec, const string funcToName, const string funcFromName, @@ -1099,15 +1111,13 @@ static void processAllCalls(SgStatement* firstExec, const string funcToName, con { if (execStmt->variant() == PROC_STAT && execStmt->symbol()->identifier() == funcToName) { const int labNum = getNextFreeLabel(); - auto nextPELabel = new SgLabel(labNum); - execStmt->setLabel(*nextPELabel); + auto nextPULabel = new SgLabel(labNum); + execStmt->setLabel(*nextPULabel); - SgStatement* gotoNextPE = new SgStatement(IF_NODE); - gotoNextPE->setExpression(0, *new SgVarRefExp(procLabelSymb) == *new SgValueExp(labNum)); - gotoNextPE->insertStmtAfter(*new SgGotoStmt(*nextPELabel), *gotoNextPE); - - gotoBlock->insertStmtBefore(*gotoNextPE, *gotoBlock); + SgStatement* gotoNextPU = new SgIfStmt(*new SgVarRefExp(procLabelSymb) == *new SgValueExp(labNum)); + gotoNextPU->insertStmtAfter(*new SgGotoStmt(*nextPULabel), *gotoNextPU); + gotoBlock->insertStmtBefore(*gotoNextPU, *gotoBlock); saveVarToModule(localVarNoParams, execStmt, funcFromName.c_str(), procLabelSymb, labNum); } @@ -1513,12 +1523,9 @@ void createCheckpoints(SgFile* file, const map& commonBloc const vector moduleNames = findAllModules(); SgStatement* moduleF = NULL; - const string cpModule = "spf_module_checkpoint"; - SgSymbol* mainModuleCpS = new SgSymbol(MODULE_NAME, cpModule.c_str()); - moduleF = new SgStatement(MODULE_STMT, NULL, mainModuleCpS); - SgStatement* global = current_file->firstStatement(); - global->insertStmtAfter(*moduleF, *global); - + createModule(moduleF, "spf_module_checkpoint"); + SgSymbol* mainModuleCpS = moduleF->symbol(); + for (auto& checkps : inFileCp) { const int cpLine = checkps.first; @@ -1610,9 +1617,7 @@ void createCheckpoints(SgFile* file, const map& commonBloc SgStatement* profCallS = new SgAssignStmt(*new SgVarRefExp(profS[0]), *new SgFunctionCallExp(*timeF)); SgStatement* profCallE = new SgAssignStmt(*new SgVarRefExp(profS[1]), *new SgFunctionCallExp(*timeF)); - /* - - */ + vector loadS; vector initLoadS; @@ -1660,14 +1665,8 @@ void createCheckpoints(SgFile* file, const map& commonBloc commonVariables, createdModuleForIO, moduleNames, unitNum, funcName, chainLocalVarNoParamsa); lastDecl->insertStmtAfter(*loadBlock, *lastDecl->controlParent()); - - - if (funcI->isMain) { + if (funcI->isMain) insertInitNamesOfFiles(numOfFiles, additional, files, journal, lastDecl, false); - } - - - //TODO: /*set elemNotDeclHere; @@ -1679,7 +1678,7 @@ void createCheckpoints(SgFile* file, const map& commonBloc for (auto& elem : elemNotDeclHere) printf("%s\n", elem.c_str());*/ - // make all new declarations + // make all new declarations //makeDeclaration(moduleF, everyS, &initS); makeDeclaration(moduleF, loadS, &initLoadS); makeDeclaration(moduleF, profS); @@ -1687,7 +1686,6 @@ void createCheckpoints(SgFile* file, const map& commonBloc makeDeclaration(func, { timeF }); func->insertStmtAfter(*new SgStatement(USE_STMT, NULL, mainModuleCpS), *func); - func->insertStmtAfter(*new SgStatement(USE_STMT, NULL, proc_mainModuleCpS), *func); //check use @@ -1799,9 +1797,8 @@ void createCheckpoints(SgFile* file, const map& commonBloc auto nextStLab = new SgLabel(labNum); point->setLabel(*nextStLab); - SgStatement* gotoBlock = new SgStatement(IF_NODE); + SgStatement* gotoBlock = new SgIfStmt(*new SgVarRefExp(loadS[4]) == *new SgValueExp(labNum)); gotoBlock->addComment("! goto CP\n"); - gotoBlock->setExpression(0, *new SgVarRefExp(loadS[4]) == *new SgValueExp(labNum)); gotoBlock->insertStmtAfter(*new SgGotoStmt(*nextStLab), *gotoBlock); SgAssignStmt* init = new SgAssignStmt(*new SgVarRefExp(loadS[4]), *new SgValueExp(0)); @@ -1821,18 +1818,6 @@ static string cuttingType(const string& all_decl_with_init) return all_decl_with_init.substr(0, iter); } -static void createModule(SgStatement*& module, const string& name, bool withFile) -{ - if (module == NULL) - { - module = new SgStatement(MODULE_STMT, NULL, new SgSymbol(MODULE_NAME, (name + (withFile ? to_string(current_file_id) : "")).c_str()), NULL, NULL, NULL); - addControlEndToStmt(module->thebif); - - SgStatement* global = current_file->firstStatement(); - global->insertStmtAfter(*module, *global); - } -} - static SgExpression* moveSaveAssignToMod(SgExpression* ex, SgStatement*& saveModule, map& declLists, const string& procName, bool withInit) {