From e5572d9dff1c6f75262bb5b374f898a4a3265fa8 Mon Sep 17 00:00:00 2001 From: Anton Date: Thu, 14 Dec 2023 23:57:39 +0300 Subject: [PATCH] remove intent(in) --- .../_src/Transformations/checkpoints.cpp | 309 ++++++++++++++---- 1 file changed, 241 insertions(+), 68 deletions(-) diff --git a/sapfor/experts/Sapfor_2017/_src/Transformations/checkpoints.cpp b/sapfor/experts/Sapfor_2017/_src/Transformations/checkpoints.cpp index 8ea0504..87f9511 100644 --- a/sapfor/experts/Sapfor_2017/_src/Transformations/checkpoints.cpp +++ b/sapfor/experts/Sapfor_2017/_src/Transformations/checkpoints.cpp @@ -3,6 +3,8 @@ #include #include #include +#include +#include #include "../Utils/SgUtils.h" #include "../Utils/utils.h" @@ -34,11 +36,11 @@ static SgType* createArrayCharType(int len, int dim) auto lenght = new SgValueExp(len); arrayType->baseType()->thetype->entry.Template.kind_len = lenght->thellnd; return arrayType; - } + } } -static void findDecls(SgExpression* ex, vector& local, const map& localParams, - set& added) +static void findDecls(SgExpression* ex, vector& local, const map& localParams, + set& added) { if (ex) { @@ -57,7 +59,7 @@ static void findDecls(SgExpression* ex, vector& local, const map< 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.insert(ex->symbol()->identifier()); @@ -70,8 +72,8 @@ static void findDecls(SgExpression* ex, vector& local, const map< } } -static void findLocalData(SgStatement* start, SgStatement* end, vector& local, - map& localParams, set& added) +static void findLocalData(SgStatement* start, SgStatement* end, vector& local, + map& localParams, set& added) { for (SgStatement* st = start; st != end; st = st->lexNext()) { @@ -84,16 +86,16 @@ static void findLocalData(SgStatement* start, SgStatement* end, vectorvariant() == EXTERN_STAT) for (SgExpression* ex = st->expr(0); ex; ex = ex->rhs()) - added.insert(ex->lhs()->symbol()->identifier()); + added.insert(ex->lhs()->symbol()->identifier()); } - + for (SgStatement* st = start; st != end; st = st->lexNext()) { //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); - } + } } static vector findUseOfModules(SgStatement* start, SgStatement* end) @@ -140,7 +142,7 @@ static SgExpression* getAttribute(SgExpression* spec, const string& type) if (val->value() == type) return spec->lhs()->rhs(); } - } + } spec = spec->rhs(); } return NULL; @@ -149,7 +151,7 @@ static SgExpression* getAttribute(SgExpression* spec, const string& type) static SgSymbol* makeVar(const string& name) { return new SgSymbol(VARIABLE_NAME, name.c_str()); } static void insertToOpenClose(const map& needToSave, const vector& names, const vector& closedStatus, - const string& iosModule) + const string& iosModule) { int z = 0; map>> useOnlyByFileAndFunc; @@ -190,7 +192,7 @@ static void insertToOpenClose(const map& needToSave, const vecto printInternalError(convertFileName(__FILE__).c_str(), __LINE__); currClose->insertStmtAfter(*new SgAssignStmt(*new SgVarRefExp(makeVar(closedStatus[z])), *new SgValueExp(0)), *currClose->controlParent()); - + auto fStat = getFuncStat(currClose, { MODULE_STMT }); checkNull(fStat, convertFileName(__FILE__).c_str(), __LINE__); useOnlyByFileAndFunc[currClose->fileName()][fStat].insert(closedStatus[z]); @@ -286,7 +288,7 @@ static bool createForIOs(const map& filesInfo, SgStatement* func close->insertStmtAfter(*ifstat, *close); ++z; } - + z = 0; auto sSTR = new SgSymbol(FUNCTION_NAME, "TO_STR", createArrayCharType(32, 0), moduleF); @@ -296,7 +298,7 @@ static bool createForIOs(const map& filesInfo, SgStatement* func vector listSpec; /*listSpec.push_back(&SgAssignOp(*new SgKeywordValExp("iostat"), *iostat)); listSpec.push_back(&SgAssignOp(*new SgKeywordValExp("status"), *new SgValueExp("old")));*/ - + auto fCall = new SgFunctionCallExp(*trim, *new SgVarRefExp(names[z])); auto fCall2 = new SgFunctionCallExp(*trim, *new SgFunctionCallExp(*sSTR, *new SgVarRefExp(counter))); @@ -307,7 +309,7 @@ static bool createForIOs(const map& filesInfo, SgStatement* func ifstat->insertStmtAfter(*new SgAssignStmt(*new SgVarRefExp(closedStatus[z]), *new SgValueExp(1)), *ifstat); open->insertStmtAfter(*ifstat, *open); ++z; - } + } auto k_par = new SgSymbol(VARIABLE_NAME, "k"); SgFuncHedrStmt* str_func = new SgFuncHedrStmt(*sSTR); @@ -316,8 +318,8 @@ static bool createForIOs(const map& filesInfo, SgStatement* func str_func->AddArg(*new SgVarRefExp(k_par)); str_func->setExpression(0, NULL); //bad solution! str_func->insertStmtAfter(*makeDeclaration(NULL, { sSTR }), *str_func); - - str_func->lastNodeOfStmt()->insertStmtBefore(*new SgInputOutputStmt(WRITE_STAT, *makeExprList({ new SgKeywordValExp("*"), new SgVarRefExp(sSTR)}, false), *new SgVarRefExp(k_par)), *str_func); + + str_func->lastNodeOfStmt()->insertStmtBefore(*new SgInputOutputStmt(WRITE_STAT, *makeExprList({ new SgKeywordValExp("*"), new SgVarRefExp(sSTR) }, false), *new SgVarRefExp(k_par)), *str_func); SgAssignStmt* adjustl = new SgAssignStmt(*new SgVarRefExp(sSTR), *new SgFunctionCallExp(*new SgSymbol(FUNCTION_NAME, "ADJUSTL"), *new SgVarRefExp(sSTR))); str_func->lastNodeOfStmt()->insertStmtBefore(*adjustl, *str_func); @@ -408,10 +410,10 @@ static bool findSpfCpDir(SgFile* file, map& info) return found; } -static void fillToProcess(FuncInfo* funcI, set>& toProcess) +static void fillToProcess(FuncInfo* funcI, set>& toProcess) { int oldSize = toProcess.size(); - for (int k = 0; k < funcI->callsTo.size(); k++) + for (int k = 0; k < funcI->callsTo.size(); k++) { pair n(funcI, funcI->callsTo[k]); toProcess.insert(n); @@ -425,7 +427,7 @@ static void fillToProcess(FuncInfo* funcI, set>& toPr //TODO: reverse if 'before' == false static int insertInitNamesOfFiles(const int numOfFiles, const string& additional, SgSymbol* files, SgArrayRefExp* journal, - SgStatement* insert, bool before = true) + SgStatement* insert, bool before = true) { int maxFileLen = -1; string tmp; @@ -498,9 +500,86 @@ static void replaceExprByExprInSt(SgStatement* st, SgExpression* from, SgExpress } -void createCheckpoints(SgFile *file, const map& commonBlocks, const map& filesInfo, - const vector& allFuncInfo) -{ +void deleteIntentIn(SgStatement* start, SgStatement* end) +{ + for (SgStatement* st = start; st != end; st = st->lexNext()) + { + if (st->expr(2)) { + int var = st->expr(2)->lhs()->variant(); + if (var == 468) + st->setExpression(2, NULL); + } + } +} + +void replaceIntentInWithIntentinOut(SgStatement* start, SgStatement* end) +{ + for (SgStatement* st = start; st != end; st = st->lexNext()) + { + if (st->expr(2)) { + int var = st->expr(2)->lhs()->variant(); + if (var == 468) + st->expr(2)->lhs()->setVariant(470); + } + } +} + +static void findLocalDataNoIntentIn(SgStatement* start, SgStatement* end, vector& local, + map& localParams, set& added) +{ + for (SgStatement* st = start; st != end; st = st->lexNext()) + { + if (st->variant() == PARAM_DECL) + { + auto decl = (SgParameterStmt*)st; + for (int z = 0; z < decl->numberOfConstants(); ++z) + localParams[decl->constant(z)->identifier()] = st; + } + + if (st->variant() == EXTERN_STAT) + for (SgExpression* ex = st->expr(0); ex; ex = ex->rhs()) + added.insert(ex->lhs()->symbol()->identifier()); + } + + for (SgStatement* st = start; st != end; st = st->lexNext()) + if (st->variant() == VAR_DECL || st->variant() == VAR_DECL_90) + if (st->expr(2) && st->expr(2)->lhs()->variant() == 468) { + SgExpression* ex = st->expr(0); + while (ex) + { + if (ex->lhs()) + if (ex->lhs()->variant() == VAR_REF) + added.insert(ex->lhs()->symbol()->identifier()); + + ex = ex->rhs(); + } + } + + for (SgStatement* st = start; st != end; st = st->lexNext()) + { + //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); + } + + for (SgStatement* st = start; st != end; st = st->lexNext()) + if (st->variant() == VAR_DECL || st->variant() == VAR_DECL_90) + if (st->expr(2) && st->expr(2)->lhs()->variant() == 468) { + SgExpression* ex = st->expr(0); + while (ex) + { + if (ex->lhs()) + if (ex->lhs()->variant() == VAR_REF) + added.erase(ex->lhs()->symbol()->identifier()); + + ex = ex->rhs(); + } + } +} + +void createCheckpoints(SgFile* file, const map& commonBlocks, const map& filesInfo, + const vector& allFuncInfo) +{ map inFileCp; bool inFile = findSpfCpDir(file, inFileCp); @@ -566,14 +645,18 @@ void createCheckpoints(SgFile *file, const map& commonBloc checkNull(lastDecl, convertFileName(__FILE__).c_str(), __LINE__); SgStatement* firstExec = lastDecl->lexNext(); + //deleteIntentIn(func->lexNext(), firstExec); + //replaceIntentInWithIntentinOut(func->lexNext(), firstExec); + vector local; map localParams; set addedToList; - findLocalData(func->lexNext(), lastDecl, local, localParams, addedToList); - const vector useOfMods = findUseOfModules(func->lexNext(), lastDecl); + findLocalDataNoIntentIn(func->lexNext(), firstExec, local, localParams, addedToList); + const vector useOfMods = findUseOfModules(func->lexNext(), firstExec); SgStatement* loadBlock = new SgStatement(IF_NODE); SgStatement* storeBlock = new SgStatement(IF_NODE); + //std::cout << "##############################################################################" << std::endl; point->insertStmtBefore(*loadBlock, *point->controlParent()); point->insertStmtBefore(*storeBlock, *point->controlParent()); @@ -583,26 +666,41 @@ void createCheckpoints(SgFile *file, const map& commonBloc loadBlock->setLabel(*loadblockLab); string filesS = "spf_cp_files" + additional; - SgSymbol* files = new SgSymbol(VARIABLE_NAME, filesS.c_str(), createArrayCharType(32, numOfFiles + 1), func); + SgSymbol* files = new SgSymbol(VARIABLE_NAME, filesS.c_str(), createArrayCharType(32, numOfFiles + 1), func); SgArrayRefExp* journal = new SgArrayRefExp(*files, *new SgValueExp(numOfFiles + 1)); //give max len, dont insert + /* after store-block in func with cp: + spf_cp_files_0_26(1) = 'spf_cp_file_1_0_26' + spf_cp_files_0_26(2) = 'spf_cp_file_2_0_26' + spf_cp_files_0_26(3) = 'spf_cp_journal_0_26' + */ int maxFileLen = insertInitNamesOfFiles(numOfFiles, additional, files, journal, NULL); vector everyS; vector profS; vector initS; - string profSs = "spf_cp_prof_s" + additional; - string profEs = "spf_cp_prof_e" + additional; + string + profSs = "spf_cp_prof_s" + additional, + profEs = "spf_cp_prof_e" + additional; + profS.push_back(new SgSymbol(VARIABLE_NAME, profSs.c_str(), SgTypeFloat(), func)); profS.push_back(new SgSymbol(VARIABLE_NAME, profEs.c_str(), SgTypeFloat(), func)); - SgSymbol* timeF = new SgSymbol(FUNCTION_NAME, "omp_get_wtime", SgTypeDouble(),func); // OR dvtime + SgSymbol* timeF = new SgSymbol(FUNCTION_NAME, "omp_get_wtime", SgTypeDouble(), func); // OR dvtime + //spf_cp_prof_s(e)_0_26 = omp_get_wtime() SgStatement* profCallS = new SgAssignStmt(*new SgVarRefExp(profS[0]), *new SgFunctionCallExp(*timeF)); SgStatement* profCallE = new SgAssignStmt(*new SgVarRefExp(profS[1]), *new SgFunctionCallExp(*timeF)); + /* beginning of store block : + * ! STORE CHECKPOINT + spf_cp_interval_0_26 = spf_cp_interval_0_26 + 1 + if (spf_cp_interval_0_26 .ge. 1) then + spf_cp_interval_0_26 = 0 + endif + */ if (type == typeEvery::TIME) { string everySs = "spf_cp_start" + additional; @@ -633,14 +731,31 @@ void createCheckpoints(SgFile *file, const map& commonBloc everyS.push_back(new SgSymbol(VARIABLE_NAME, everyIs.c_str(), SgTypeInt(), func)); initS.push_back(new SgValueExp(0)); SgAssignStmt* init = new SgAssignStmt(*new SgVarRefExp(everyS[0]), *new SgValueExp(0)); + //std::cout << "INIT::" << std::endl; + //init->unparsestdout(); + //std::cout << "storeBlock before::" << std::endl; + //storeBlock->unparsestdout(); storeBlock->insertStmtAfter(*init, *storeBlock); + //std::cout << "storeBlock after init::" << std::endl; + //storeBlock->unparsestdout(); SgAssignStmt* inc = new SgAssignStmt(*new SgVarRefExp(everyS[0]), *new SgVarRefExp(everyS[0]) + *new SgValueExp(1)); + //std::cout << "INC::" << std::endl; + //init->unparsestdout(); + //std::cout << "storeBlock->controlParent()::" << std::endl; + //storeBlock->controlParent()->unparsestdout(); storeBlock->insertStmtBefore(*inc, *storeBlock->controlParent()); inc->addComment("! STORE CHECKPOINT\n"); + //std::cout << "storeBlock after inc::" << std::endl; + //storeBlock->unparsestdout(); storeBlock->setExpression(0, *new SgVarRefExp(everyS[0]) >= *new SgValueExp(every)); + //std::cout << "storeBlock after setexpr::" << std::endl; + //storeBlock->unparsestdout(); + //std::cout << "storeBlock->controlParent()::" << std::endl; + //storeBlock->controlParent()->unparsestdout(); } + //std::cout << "##############################################################################" << std::endl; vector loadS; vector initLoadS; @@ -658,9 +773,9 @@ void createCheckpoints(SgFile *file, const map& commonBloc loadS.push_back(new SgSymbol(VARIABLE_NAME, iostatS.c_str(), SgTypeInt(), func)); initLoadS.push_back(NULL); - /*string loadSaveS = "spf_cp_load_save" + additional; - loadS.push_back(new SgSymbol(VARIABLE_NAME, loadSaveS.c_str(), SgTypeInt(), func)); - initLoadS.push_back(new SgValueExp(0));*/ + /*string loadSaveS = "spf_cp_load_save" + additional; + loadS.push_back(new SgSymbol(VARIABLE_NAME, loadSaveS.c_str(), SgTypeInt(), func)); + initLoadS.push_back(new SgValueExp(0));*/ string loadLabelS = "spf_cp_load_label" + additional; loadS.push_back(new SgSymbol(VARIABLE_NAME, loadLabelS.c_str(), SgTypeInt(), func)); @@ -670,10 +785,18 @@ void createCheckpoints(SgFile *file, const map& commonBloc loadS.push_back(new SgSymbol(VARIABLE_NAME, saveFS.c_str(), SgTypeInt(), func)); initLoadS.push_back(new SgValueExp(0)); + //std::cout << "loadBlock->controlParent()::" << std::endl; + //loadBlock->controlParent()->unparsestdout(); loadBlock->setExpression(0, *new SgVarRefExp(loadS[0]) == *new SgValueExp(0)); SgAssignStmt* init = new SgAssignStmt(*new SgVarRefExp(loadS[0]), *new SgValueExp(1)); + //std::cout << "INIT::" << std::endl; + //init->unparsestdout(); insertToLoadS.push_back(init); + //std::cout << "loadBlock->controlParent()::" << std::endl; + //loadBlock->controlParent()->unparsestdout(); + //std::cout << "##############################################################################" << std::endl; + vector listSpec; SgExpression& unitNull = SgAssignOp(*new SgKeywordValExp("unit"), *new SgKeywordValExp("*")); @@ -684,6 +807,7 @@ void createCheckpoints(SgFile *file, const map& commonBloc SgExpression* iostat = new SgVarRefExp(loadS[2]); SgExpression* fileIdx = new SgVarRefExp(loadS[1]); + // for first open journal file in load block listSpec.push_back(&SgAssignOp(*new SgKeywordValExp("iostat"), *iostat)); listSpec.push_back(&SgAssignOp(*new SgKeywordValExp("status"), *new SgValueExp("old"))); listSpec.push_back(&SgAssignOp(*new SgKeywordValExp("file"), *journal)); @@ -711,9 +835,17 @@ void createCheckpoints(SgFile *file, const map& commonBloc insertToifLoadOk.push_back(open); SgIfStmt* ifLoadOk1 = new SgIfStmt(*iostat == *new SgValueExp(0), *new SgIOControlStmt(CLOSE_STAT, unit)); - + //std::cout << "ifLoadOk1::" << std::endl; + //ifLoadOk1->unparsestdout(); + insertToifLoadOk.push_back(ifLoadOk1); + /* from "! LOAD DATA FROM CHECKPOINT" + spf_cp_file_n_0_26 = spf_cp_file_n_0_26 + 1 + if (spf_cp_file_n_0_26 .eq. 3) then + spf_cp_file_n_0_26 = 1 + endif + */ ifLoadOk1->insertStmtAfter(*new SgIfStmt(*fileIdx == *new SgValueExp(numOfFiles + 1), *new SgAssignStmt(*fileIdx, *new SgValueExp(1))), *ifLoadOk1); ifLoadOk1->insertStmtAfter(*new SgAssignStmt(*fileIdx, *fileIdx + *new SgValueExp(1)), *ifLoadOk1); ifLoadOk1->addComment("! LOAD DATA FROM CHECKPOINT\n"); @@ -730,6 +862,7 @@ void createCheckpoints(SgFile *file, const map& commonBloc //open all files if (createdModuleForIO) { + //std::cout << "createdModuleForIO" << std::endl; SgCallStmt* call = new SgCallStmt(*new SgSymbol(FUNCTION_NAME, iosNames[1].c_str())); ifLoadOk1->insertStmtAfter(*call, *ifLoadOk1); } @@ -737,6 +870,7 @@ void createCheckpoints(SgFile *file, const map& commonBloc //READ from modules for (auto& mod : moduleNames) { + //std::cout << "READ from modules" << std::endl; SgCallStmt* call = new SgCallStmt(*new SgSymbol(FUNCTION_NAME, ("SPF_CP_" + mod).c_str())); call->addArg(*new SgValueExp(unitNum)); call->addArg(*new SgValueExp(0)); @@ -746,11 +880,16 @@ void createCheckpoints(SgFile *file, const map& commonBloc //READ DATA if (local.size()) { + //std::cout << "READ DATA" << std::endl; auto dataRead = new SgInputOutputStmt(READ_STAT, unit, *makeExprList(local, false)); ifLoadOk1->insertStmtAfter(*dataRead, *ifLoadOk1); } ifLoadOk1->insertStmtAfter(profCallS->copy(), *ifLoadOk1); + //std::cout << "loadBlock->controlParent()::" << std::endl; + //loadBlock->controlParent()->unparsestdout(); + + // loadblock done (need to upload) listSpec.clear(); listSpec.push_back(&SgAssignOp(*new SgKeywordValExp("form"), *new SgValueExp("unformatted"))); @@ -822,26 +961,51 @@ void createCheckpoints(SgFile *file, const map& commonBloc assign->insertStmtBefore(*new SgIOControlStmt(CLOSE_STAT, unit), *ifStoreOk); ifStoreOk->insertStmtAfter(profCallS->copy(), *ifStoreOk); + // store-block done + // block after name of files and before first executable operator SgStatement* copyForGoto = loadBlock->copyPtr(); + //std::cout << "copyForGoto::" << std::endl; + //copyForGoto->unparsestdout(); copyForGoto->deleteLabel(); + //std::cout << "copyForGoto after delete label::" << std::endl; + //copyForGoto->unparsestdout(); + //std::cout << "firstExec::" << std::endl; + //firstExec->unparsestdout(); firstExec->insertStmtBefore(*copyForGoto, *func); + //std::cout << "firstExec parent after insert::" << std::endl; + //firstExec->controlParent()->unparsestdout(); + //loadBlock->controlParent()->unparsestdout(); insertInitNamesOfFiles(numOfFiles, additional, files, journal, copyForGoto, true); + //std::cout << "insert names of files::" << std::endl; copyForGoto->insertStmtAfter(insertToLoadS[insertToLoadS.size() - 1]->copy(), *copyForGoto); + //std::cout << "copyForGoto::" << std::endl; + //copyForGoto->controlParent()->unparsestdout(); copyForGoto->insertStmtAfter(insertToLoadS[insertToLoadS.size() - 2]->copy(), *copyForGoto); + //std::cout << "copyForGoto::" << std::endl; + //copyForGoto->controlParent()->unparsestdout(); copyForGoto = copyForGoto->lexNext()->lexNext(); + //std::cout << "copyForGoto after double lexnext::" << std::endl; + //copyForGoto->unparsestdout(); copyForGoto->insertStmtAfter(*new SgGotoStmt(*loadblockLab), *copyForGoto); + //std::cout << "copyForGoto::" << std::endl; + //copyForGoto->controlParent()->unparsestdout(); copyForGoto->insertStmtAfter(*new SgIOControlStmt(CLOSE_STAT, unit), *copyForGoto); + //std::cout << "copyForGoto::" << std::endl; + //copyForGoto->controlParent()->unparsestdout(); for (int z = insertToLoadS.size() - 1; z >= 0; --z) loadBlock->insertStmtAfter(*insertToLoadS[z], *loadBlock); for (int z = insertToifLoadOk.size() - 1; z >= 0; --z) ifLoadOk->insertStmtAfter(*insertToifLoadOk[z], *ifLoadOk); - + + // load block added + + //std::cout << "##############################################################################" << std::endl; //TODO: /*set elemNotDeclHere; @@ -915,7 +1079,7 @@ void createCheckpoints(SgFile *file, const map& commonBloc FuncInfo* funcI = NULL; for (auto& funcs : allFuncInfo) - if (funcs->funcName == func->symbol()->identifier()) + if (funcs->funcName == func->symbol()->identifier()) funcI = funcs; if (funcI == NULL) @@ -927,6 +1091,7 @@ void createCheckpoints(SgFile *file, const map& commonBloc map processedFrom; for (auto j = toProcess.begin(); j != toProcess.end(); j++) { + std::cout << "( " << (j->first)->funcName << " , " << (j->second)->funcName << " ) " << std::endl; int callNum = 1; SgStatement* hedrTo = (j->first)->funcPointer->GetOriginal(); SgStatement* hedrFrom = (j->second)->funcPointer->GetOriginal(); @@ -935,10 +1100,13 @@ void createCheckpoints(SgFile *file, const map& commonBloc lastDecl = lastDecl->lexNext(); SgStatement* firstExec = lastDecl->lexNext(); + + deleteIntentIn(hedrFrom->lexNext(), firstExec); + vector local; map localParams; set addedToList; - findLocalData(hedrFrom->lexNext(), lastDecl, local, localParams, addedToList); + findLocalData(hedrFrom->lexNext(), firstExec, local, localParams, addedToList); if (!processedFrom.count(j->second)) { SgSymbol* modS = moduleF->symbol(); @@ -951,8 +1119,8 @@ void createCheckpoints(SgFile *file, const map& commonBloc gotoBlock->addComment("!GOTO LOAD BLOCK \n"); gotoBlock->setExpression(0, *new SgVarRefExp(loadS[0]) == *new SgValueExp(0)); - - if (j->second->isMain) + + if (j->second->isMain) { SgAssignStmt* loadOne = new SgAssignStmt(*new SgVarRefExp(loadS[0]), *new SgValueExp(1)); insertToGotoBlock.push_back(loadOne); @@ -990,7 +1158,7 @@ void createCheckpoints(SgFile *file, const map& commonBloc ifLoadOk1->insertStmtAfter(*loadZero, *ifLoadOk1); insertToifLoadOk.push_back(ifLoadOk1); - + firstExec->insertStmtBefore(*gotoBlock, *hedrFrom); for (int z = insertToGotoBlock.size() - 1; z >= 0; --z) @@ -1000,32 +1168,37 @@ void createCheckpoints(SgFile *file, const map& commonBloc ifLoadOk->insertStmtAfter(*insertToifLoadOk[z], *ifLoadOk); processedFrom[j->second] = ifLoadOk1->lexNext(); - processedFrom[j->second]->unparsestdout(); + //processedFrom[j->second]->unparsestdout(); } - else + else { - SgStatement * read = new SgInputOutputStmt(READ_STAT, *makeExprList({ &frmt, &unit }, false), *new SgVarRefExp(loadS[3])); + SgStatement* read = new SgInputOutputStmt(READ_STAT, *makeExprList({ &frmt, &unit }, false), *new SgVarRefExp(loadS[3])); gotoBlock->insertStmtAfter(*read, *gotoBlock); processedFrom[j->second] = gotoBlock->lexNext(); + firstExec->insertStmtBefore(*gotoBlock, *hedrFrom); } - + processedFrom[j->second]->unparsestdout(); + //std::cout << "gotoblock: " << std::endl; + //gotoBlock->unparsestdout(); } for (auto& callInfo : j->second->callsFromDetailed) { + //std::cout << "callinfo name: " << callInfo.detailCallsFrom.first << std::endl; auto& call = callInfo.pointerDetailCallsFrom; + //std::cout << "callinfo var: " << call.second << std::endl; SgStatement* st = NULL; - + if (isSgFuncHedrStmt(hedrTo) && call.second == FUNC_CALL) { SgFunctionCallExp* callExp = (SgFunctionCallExp*)call.first; - if (!strcmp(callExp->funName()->identifier(), (j->first)->funcName.c_str())) + if (!strcmp(callExp->funName()->identifier(), (j->first)->funcName.c_str())) { st = SgStatement::getStatmentByExpression(callExp); - SgSymbol * buf = new SgSymbol(VARIABLE_NAME, ("SPF_CALL_"+ (j->first)->funcName + "_" + to_string(callNum)).c_str(), callExp->type(), (j->second)->funcPointer->GetOriginal()); + SgSymbol* buf = new SgSymbol(VARIABLE_NAME, ("SPF_CALL_" + (j->first)->funcName + "_" + to_string(callNum)).c_str(), callExp->type(), (j->second)->funcPointer->GetOriginal()); SgExpression* bufRef = new SgVarRefExp(buf); SgStatement* bufAssign = new SgAssignStmt(*bufRef, *callExp); - st->insertStmtBefore(*bufAssign,* (st->controlParent())); + st->insertStmtBefore(*bufAssign, *(st->controlParent())); replaceExprByExprInSt(st, callExp, bufRef); makeDeclaration(hedrFrom, { buf }); for (int i = 0; i < callExp->numberOfArgs(); i++) @@ -1041,15 +1214,15 @@ void createCheckpoints(SgFile *file, const map& commonBloc { break; } - + } - SgSymbol* argBuf = new SgSymbol(VARIABLE_NAME, ("SPF_ARG_" + (j->first)->funcName+"_" + to_string(callNum) + "_" + to_string(i)).c_str(), s->type(), (j->second)->funcPointer->GetOriginal()); + SgSymbol* argBuf = new SgSymbol(VARIABLE_NAME, ("SPF_ARG_" + (j->first)->funcName + "_" + to_string(callNum) + "_" + to_string(i)).c_str(), s->type(), (j->second)->funcPointer->GetOriginal()); SgExpression* argBufRef = new SgVarRefExp(argBuf); SgStatement* argBufAssign = new SgAssignStmt(*argBufRef, *(callExp->arg(i))); bufAssign->insertStmtBefore(*argBufAssign, *(st->controlParent())); - SgStatement* decl = makeDeclaration(hedrFrom, {argBuf}); - + SgStatement* decl = makeDeclaration(hedrFrom, { argBuf }); + for (int i = 0; i < 3; i++) { SgExpression* e; @@ -1058,7 +1231,7 @@ void createCheckpoints(SgFile *file, const map& commonBloc } } - + } st = bufAssign; callNum++; @@ -1096,13 +1269,13 @@ void createCheckpoints(SgFile *file, const map& commonBloc loadBlock->setLabel(*loadblockLab); SgIfStmt* gotoIf = new SgIfStmt(*new SgVarRefExp(loadS[3]) == *new SgValueExp(labNum), *new SgGotoStmt(*loadblockLab)); - processedFrom[j->second]->insertStmtAfter(*gotoIf,*(processedFrom[j->second]->controlParent())); - + processedFrom[j->second]->insertStmtAfter(*gotoIf, *(processedFrom[j->second]->controlParent())); + storeBlock->addComment("! STORE CHECKPOINT\n"); storeBlock->setExpression(0, *new SgVarRefExp(everyS[0]) >= *new SgValueExp(every)); - vector insertToLoadS; + vector insertToLoadS; loadBlock->setExpression(0, *new SgVarRefExp(loadS[0]) == *new SgValueExp(0)); loadBlock->addComment("! LOAD DATA FROM CHECKPOINT\n"); @@ -1120,7 +1293,7 @@ void createCheckpoints(SgFile *file, const map& commonBloc } } } - + //process modules vector modules; findModulesInFile(file, modules); @@ -1149,7 +1322,7 @@ void createCheckpoints(SgFile *file, const map& commonBloc newF->AddArg("unit_f", *SgTypeInt()); newF->AddArg("type_of_op", *SgTypeInt()); - + if (local.size()) { SgExpression& unit = SgAssignOp(*new SgKeywordValExp("unit"), *new SgVarRefExp(*newF->parameter(0))); @@ -1161,7 +1334,7 @@ void createCheckpoints(SgFile *file, const map& commonBloc ifBlock->addComment(("!STORE OR LOAD " + to_string(local.size()) + " ITEMS\n").c_str()); } - } + } } static string cuttingType(const string& all_decl_with_init) @@ -1185,8 +1358,8 @@ static void createModule(SgStatement*& module, const string& name, bool withFile } } -static SgExpression* moveSaveAssignToMod(SgExpression* ex, SgStatement*& saveModule, - map& declLists, const string& procName, bool withInit) +static SgExpression* moveSaveAssignToMod(SgExpression* ex, SgStatement*& saveModule, + map& declLists, const string& procName, bool withInit) { if (saveModule == NULL) createModule(saveModule, "spf_module_save_"); @@ -1201,7 +1374,7 @@ static SgExpression* moveSaveAssignToMod(SgExpression* ex, SgStatement*& saveMod if (ex->variant() != VAR_REF && ex->variant() != ARRAY_REF) printInternalError(convertFileName(__FILE__).c_str(), __LINE__); } - + SgSymbol* copy = (withInit) ? &ex->lhs()->symbol()->copy() : &ex->symbol()->copy(); copy->changeName((string(copy->identifier()) + "_" + procName).c_str()); @@ -1213,8 +1386,8 @@ static SgExpression* moveSaveAssignToMod(SgExpression* ex, SgStatement*& saveMod } else decl = makeDeclaration(NULL, { ex->symbol() }, NULL); - - const string typeKey = cuttingType(decl->unparse()); + + const string typeKey = cuttingType(decl->unparse()); if (withInit) { decl->expr(0)->lhs()->setLhs(withInit ? ex->lhs()->copyPtr() : ex->copyPtr()); @@ -1246,7 +1419,7 @@ void convertSaveToModule(SgFile* file) vector renames; SgStatement* func = file->functions(ff); - + string procName = file->functions(ff)->symbol()->identifier(); set toRem; vector dataValues; @@ -1347,7 +1520,7 @@ void convertSaveToModule(SgFile* file) SgSymbol* modS = new SgSymbol(VARIABLE_NAME, saveModule->symbol()->identifier()); SgStatement* use = new SgStatement(USE_STMT, NULL, modS, makeExprList(renames), NULL, NULL); func->insertStmtAfter(*use, *func); - + for (auto& dataV : dataValues) { char* value = dataV->thellnd->entry.string_val; @@ -1358,7 +1531,7 @@ void convertSaveToModule(SgFile* file) for (auto& elem : dataRenames) { auto it = dataS.find(elem.first); - if (it != string::npos && + if (it != string::npos && (dataS[it + elem.first.size()] == ' ' || dataS[it + elem.first.size()] == '/') && (dataS[it - 1] == ',' || dataS[it - 1] == ' ' || dataS[it - 1] == '/')) { @@ -1380,13 +1553,13 @@ void convertSaveToModule(SgFile* file) static int getUnit(SgExpression* spec) { - int unit = -1; + int unit = -1; while (spec) { if (spec->lhs() && spec->lhs()->variant() == SPEC_PAIR) { if (spec->lhs()->lhs()->variant() == KEYWORD_VAL) - { + { SgKeywordValExp* val = (SgKeywordValExp*)(spec->lhs()->lhs()); if (spec->lhs()->rhs()->variant() == INT_VAL) {