2 Commits

Author SHA1 Message Date
025113211b omp_getwetime added 2024-05-02 14:15:48 +03:00
19ddaa0523 no comms 2024-05-02 13:17:11 +03:00

View File

@@ -805,12 +805,12 @@ static SgStatement* createLoadBlock(const vector<SgSymbol*>& loadS, FuncInfo*& f
const char* funcName = funcI->funcName.c_str(); const char* funcName = funcI->funcName.c_str();
vector<SgStatement*> insertToLoadS; vector<SgStatement*> insertToLoadS;
SgStatement* loadBlock = new SgIfStmt(*new SgVarRefExp(loadS[4]) == *new SgValueExp(1)); //*new SgVarRefExp(loadS[0]) SgStatement* loadBlock = new SgIfStmt(*new SgVarRefExp(loadS[0]) == *new SgValueExp(1)); //*new SgVarRefExp(loadS[0])
loadBlock->addComment("! LOAD CHECKPOINT\n"); loadBlock->addComment("! LOAD CHECKPOINT\n");
if (funcI->isMain) if (funcI->isMain)
{ {
SgAssignStmt* init = new SgAssignStmt(*new SgVarRefExp(loadS[4]), *new SgValueExp(0)); SgAssignStmt* init = new SgAssignStmt(*new SgVarRefExp(loadS[0]), *new SgValueExp(0));
insertToLoadS.push_back(init); insertToLoadS.push_back(init);
insertToLoadS.push_back(createOpenJ_old(iostat, journal, unit)); insertToLoadS.push_back(createOpenJ_old(iostat, journal, unit));
} }
@@ -833,7 +833,7 @@ static SgStatement* createLoadBlock(const vector<SgSymbol*>& loadS, FuncInfo*& f
if (funcI->isMain) if (funcI->isMain)
{ {
SgAssignStmt* init = new SgAssignStmt(*new SgVarRefExp(loadS[4]), *new SgValueExp(1)); SgAssignStmt* init = new SgAssignStmt(*new SgVarRefExp(loadS[0]), *new SgValueExp(1));
ifLoadOk1->insertStmtAfter(*init, *ifLoadOk1); ifLoadOk1->insertStmtAfter(*init, *ifLoadOk1);
} }
@@ -1166,7 +1166,6 @@ 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, firstExec, local, localParams, addedToList, allFuncInfo);
if (!processedFrom.count(funcFrom)) if (!processedFrom.count(funcFrom))
{ {
@@ -1194,7 +1193,6 @@ static void processFunctionCallChain(SgStatement* func, const vector<FuncInfo*>&
set<string> addedModuleParams; set<string> addedModuleParams;
set<string> localVarNoParams; set<string> localVarNoParams;
insertStmtToModule(moduleStmts, moduleParamStmts, addedModuleParams, commonVariables, proc_moduleF, localVarNoParams, externVars); insertStmtToModule(moduleStmts, moduleParamStmts, addedModuleParams, commonVariables, proc_moduleF, localVarNoParams, externVars);
//chainLocalVarNoParams.push_back(localVarNoParams);
const string namelabelSymb = funcFrom->funcName + "_label"; const string namelabelSymb = funcFrom->funcName + "_label";
SgSymbol* procLabelSymb = createLabel(namelabelSymb, proc_moduleF); SgSymbol* procLabelSymb = createLabel(namelabelSymb, proc_moduleF);
@@ -1220,235 +1218,21 @@ static void processFunctionCallChain(SgStatement* func, const vector<FuncInfo*>&
localVarNoParams, moduleStmts, commonVariables, createdModuleForIO, localVarNoParams, moduleStmts, commonVariables, createdModuleForIO,
moduleNames, unitNum, funcI->funcName, chainLocalVarNoParams, false, procLabelSymb); moduleNames, unitNum, funcI->funcName, chainLocalVarNoParams, false, procLabelSymb);
firstExec->insertStmtBefore(*loadBlock, *firstExec->controlParent()); firstExec->insertStmtBefore(*loadBlock, *firstExec->controlParent());
if (funcFrom->isMain) if (funcFrom->isMain)
{
insertInitNamesOfFiles(numOfFiles, additional, files, journal, lastDecl, false); insertInitNamesOfFiles(numOfFiles, additional, files, journal, lastDecl, false);
/*
SgAssignStmt* loadOne = new SgAssignStmt(*new SgVarRefExp(loadS[0]), *new SgValueExp(1));
vector<SgStatement*> insertToifLoadOk;
SgIfStmt* ifLoadOk = new SgIfStmt(*iostat == *new SgValueExp(0));
SgInputOutputStmt* read = new SgInputOutputStmt(READ_STAT, *makeExprList({ &frmt, &unit }, false), *fileIdx);
insertToifLoadOk.push_back(read);
insertToifLoadOk.push_back(new SgIOControlStmt(CLOSE_STAT, unit));
insertToifLoadOk.push_back(createOpen(iostat, files, fileIdx, unit));
read = new SgInputOutputStmt(READ_STAT, *makeExprList({ &frmt, &unit }, false), *new SgVarRefExp(loadS[3]));
SgIfStmt* ifLoadOk1 = new SgIfStmt(*iostat == *new SgValueExp(0), *read);
SgAssignStmt* loadZero = new SgAssignStmt(*new SgVarRefExp(loadS[0]), *new SgValueExp(0));
ifLoadOk1->insertStmtAfter(*loadZero, *ifLoadOk1);
insertToifLoadOk.push_back(ifLoadOk1);
firstExec->insertStmtBefore(*gotoBlock, *hedrFrom);
for (int z = insertToGotoBlock.size() - 1; z >= 0; --z)
gotoBlock->insertStmtAfter(*insertToGotoBlock[z], *gotoBlock);
for (int z = insertToifLoadOk.size() - 1; z >= 0; --z)
ifLoadOk->insertStmtAfter(*insertToifLoadOk[z], *ifLoadOk);
*/
//processedFrom[funcFrom] = ifLoadOk1->lexNext();
}
SgStatement* gotoBlock = new SgStatement(IF_NODE); SgStatement* gotoBlock = new SgStatement(IF_NODE);
gotoBlock->addComment("! goto next program unit\n"); gotoBlock->addComment("! goto next program unit\n");
gotoBlock->setExpression(0, *new SgVarRefExp(loadS[4]) == *new SgValueExp(1)); gotoBlock->setExpression(0, *new SgVarRefExp(loadS[0]) == *new SgValueExp(1));
firstExec->insertStmtBefore(*gotoBlock, *firstExec->controlParent()); firstExec->insertStmtBefore(*gotoBlock, *firstExec->controlParent());
// insert gotoBlock and save to module // insert gotoBlock and save to module
processAllCalls(firstExec, funcTo->funcName, funcFrom->funcName, gotoBlock, localVarNoParams, procLabelSymb); processAllCalls(firstExec, funcTo->funcName, funcFrom->funcName, gotoBlock, localVarNoParams, procLabelSymb);
makeDeclaration(hedrFrom, { timeF });
/*
std::cout << funcTo->funcName << std::endl;
std::cout << "-------------------------------------" << std::endl;
for (int k = 0; k < funcTo->callsTo.size(); k++)
{
std::cout << funcTo->callsTo[k] << std::endl;
}
std::cout << "=====================================" << std::endl;
std::cout << "-------------------------------------" << std::endl;
for (auto elem :funcTo->callsFrom)
{
std::cout << elem << std::endl;
}
std::cout << "=====================================" << std::endl;
std::cout << funcFrom->funcName << std::endl;
std::cout << "-------------------------------------" << std::endl;
for (int k = 0; k < funcFrom->callsTo.size(); k++)
{
std::cout << funcFrom->callsTo[k] << std::endl;
}
std::cout << "=====================================" << std::endl;
std::cout << "-------------------------------------" << std::endl;
for (auto elem : funcFrom->callsFrom)
{
std::cout << elem << std::endl;
}
std::cout << "=====================================" << std::endl;
*/
/*
SgStatement* gotoBlock = new SgStatement(IF_NODE);
vector<SgStatement*> insertToGotoBlock;
gotoBlock->addComment("!GOTO LOAD BLOCK \n");
gotoBlock->setExpression(0, *new SgVarRefExp(loadS[0]) == *new SgValueExp(0));
if (funcFrom->isMain)
{
SgAssignStmt* loadOne = new SgAssignStmt(*new SgVarRefExp(loadS[0]), *new SgValueExp(1));
insertToGotoBlock.push_back(loadOne);
insertToGotoBlock.push_back(createOpenJ_old(iostat, journal, unit));
vector<SgStatement*> insertToifLoadOk;
SgIfStmt* ifLoadOk = new SgIfStmt(*iostat == *new SgValueExp(0));
insertToGotoBlock.push_back(ifLoadOk);
SgInputOutputStmt* read = new SgInputOutputStmt(READ_STAT, *makeExprList({ &frmt, &unit }, false), *fileIdx);
insertToifLoadOk.push_back(read);
insertToifLoadOk.push_back(new SgIOControlStmt(CLOSE_STAT, unit));
insertToifLoadOk.push_back(createOpen(iostat, files, fileIdx, unit));
read = new SgInputOutputStmt(READ_STAT, *makeExprList({ &frmt, &unit }, false), *new SgVarRefExp(loadS[3]));
SgIfStmt* ifLoadOk1 = new SgIfStmt(*iostat == *new SgValueExp(0), *read);
SgAssignStmt* loadZero = new SgAssignStmt(*new SgVarRefExp(loadS[0]), *new SgValueExp(0));
ifLoadOk1->insertStmtAfter(*loadZero, *ifLoadOk1);
insertToifLoadOk.push_back(ifLoadOk1);
firstExec->insertStmtBefore(*gotoBlock, *hedrFrom);
for (int z = insertToGotoBlock.size() - 1; z >= 0; --z)
gotoBlock->insertStmtAfter(*insertToGotoBlock[z], *gotoBlock);
for (int z = insertToifLoadOk.size() - 1; z >= 0; --z)
ifLoadOk->insertStmtAfter(*insertToifLoadOk[z], *ifLoadOk);
processedFrom[funcFrom] = ifLoadOk1->lexNext();
}
else
{
SgStatement* read = new SgInputOutputStmt(READ_STAT, *makeExprList({ &frmt, &unit }, false), *new SgVarRefExp(loadS[3]));
gotoBlock->insertStmtAfter(*read, *gotoBlock);
processedFrom[funcFrom] = gotoBlock->lexNext();
firstExec->insertStmtBefore(*gotoBlock, *hedrFrom);
}*/
} }
/*
for (auto& callInfo : funcFrom->callsFromDetailed)
{
auto& call = callInfo.pointerDetailCallsFrom;
SgStatement* st = NULL;
if (isSgFuncHedrStmt(hedrTo) && call.second == FUNC_CALL)
{
SgFunctionCallExp* callExp = (SgFunctionCallExp*)call.first;
if (!strcmp(callExp->funName()->identifier(), funcTo->funcName.c_str()))
{
st = SgStatement::getStatmentByExpression(callExp);
SgSymbol* buf = new SgSymbol(VARIABLE_NAME, ("SPF_CALL_" + funcTo->funcName + "_" + to_string(callNum)).c_str(), callExp->type(), funcFrom->funcPointer->GetOriginal());
SgExpression* bufRef = new SgVarRefExp(buf);
SgStatement* bufAssign = new SgAssignStmt(*bufRef, *callExp);
st->insertStmtBefore(*bufAssign, *(st->controlParent()));
replaceExprByExprInSt(st, callExp, bufRef);
makeDeclaration(hedrFrom, { buf });
for (int i = 0; i < callExp->numberOfArgs(); i++)
{
if (funcTo->funcParams.isArgInOut(i) || funcTo->funcParams.isArgOut(i))
{
SgSymbol* s, * sl;
SgStatement* lst = hedrTo->lastNodeOfStmt();
sl = lst->lexNext() ? lst->lexNext()->symbol() : NULL;
for (s = hedrTo->symbol(); s != sl && s; s = s->next())
{
if (s->scope() == hedrTo && !strcmp(s->identifier(), funcTo->funcParams.identificators[i].c_str()))
{
break;
}
}
SgSymbol* argBuf = new SgSymbol(VARIABLE_NAME, ("SPF_ARG_" + funcTo->funcName + "_" + to_string(callNum) + "_" + to_string(i)).c_str(), s->type(), funcFrom->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 });
for (int i = 0; i < 3; i++)
{
SgExpression* e;
if (e = decl->expr(i))
decl->setExpression(i, CalculateInteger(ReplaceConstant(e)));
}
}
}
st = bufAssign;
callNum++;
}
}
else if (isSgProcHedrStmt(hedrTo) && call.second == PROC_STAT)
{
//TODO: need to revise!!
/*SgCallStmt* callSt = (SgCallStmt*)call.first;
if (!strcmp(callSt->name()->identifier(), funcTo->funcName.c_str())) {
st = callSt;
for (int i = 0; i < callSt->numberOfArgs(); i++)
{
if (funcTo->funcParams.isArgInOut(i) || funcTo->funcParams.isArgOut(i))
{
SgSymbol* buf1 = new SgSymbol(VARIABLE_NAME, "TEMP1", callSt->arg(i)->type(), hedrFrom);
SgExpression* buf1Ref = new SgVarRefExp(buf1);
SgStatement* buf1Assign = new SgAssignStmt(*buf1Ref, *(callSt->arg(i)));
st->insertStmtBefore(*buf1Assign, *(st->controlParent()));
}
}
}
}
if (st)
{
SgStatement* loadBlock = new SgStatement(IF_NODE);
SgStatement* loadBlockLast = NULL;
SgStatement* storeBlock = new SgStatement(IF_NODE);
st->insertStmtBefore(*loadBlock, *st->controlParent());
st->insertStmtAfter(*storeBlock, *st->controlParent());
loadBlock->addComment("! LOAD CHECKPOINT\n");
const int labNum = getNextFreeLabel();
auto loadblockLab = new SgLabel(labNum);
loadBlock->setLabel(*loadblockLab);
SgIfStmt* gotoIf = new SgIfStmt(*new SgVarRefExp(loadS[3]) == *new SgValueExp(labNum), *new SgGotoStmt(*loadblockLab));
processedFrom[funcFrom]->insertStmtAfter(*gotoIf, *(processedFrom[funcFrom]->controlParent()));
storeBlock->addComment("! STORE CHECKPOINT\n");
//TODO: this block incorrect!!
storeBlock->setExpression(0, *new SgVarRefExp(everyS[0]) >= *new SgValueExp(every));
vector<SgStatement*> insertToLoadS;
loadBlock->setExpression(0, *new SgVarRefExp(loadS[0]) == *new SgValueExp(0));
loadBlock->addComment("! LOAD DATA FROM CHECKPOINT\n");
//READ DATA
if (local.size())
{
auto dataRead = new SgInputOutputStmt(READ_STAT, unit, *makeExprList(local));
loadBlock->insertStmtAfter(*dataRead, *loadBlock);
}
}
}
*/
} }
@@ -1569,7 +1353,6 @@ void createCheckpoints(SgFile* file, const map<string, CommonBlock*>& commonBloc
findLocalData(func, firstExec, local, localParams, addedToList, allFuncInfo); findLocalData(func, firstExec, local, localParams, addedToList, allFuncInfo);
const char* funcName = func->symbol()->identifier(); const char* funcName = func->symbol()->identifier();
//int lenFuncName = strlen(funcName);
SgStatement* proc_moduleF = NULL; SgStatement* proc_moduleF = NULL;
const string proc_cpModule = "spf_module_" + string(funcName); const string proc_cpModule = "spf_module_" + string(funcName);
@@ -1604,9 +1387,7 @@ void createCheckpoints(SgFile* file, const map<string, CommonBlock*>& commonBloc
//give max len, dont insert //give max len, dont insert
int maxFileLen = insertInitNamesOfFiles(numOfFiles, additional, files, journal, NULL); int maxFileLen = insertInitNamesOfFiles(numOfFiles, additional, files, journal, NULL);
//vector<SgSymbol*> everyS;
vector<SgSymbol*> profS; vector<SgSymbol*> profS;
//vector<SgExpression*> initS;
string profSs = "spf_cp_prof_s" + additional; string profSs = "spf_cp_prof_s" + additional;
string profEs = "spf_cp_prof_e" + additional; string profEs = "spf_cp_prof_e" + additional;
@@ -1623,7 +1404,7 @@ void createCheckpoints(SgFile* file, const map<string, CommonBlock*>& commonBloc
string cpLoadS = "spf_cp_load" + additional; string cpLoadS = "spf_cp_load" + additional;
loadS.push_back(new SgSymbol(VARIABLE_NAME, cpLoadS.c_str(), SgTypeInt(), func)); loadS.push_back(new SgSymbol(VARIABLE_NAME, cpLoadS.c_str(), SgTypeInt(), func));
initLoadS.push_back(new SgValueExp(0)); initLoadS.push_back(new SgValueExp(1));
string fileNS = "spf_cp_file_n" + additional; string fileNS = "spf_cp_file_n" + additional;
loadS.push_back(new SgSymbol(VARIABLE_NAME, fileNS.c_str(), SgTypeInt(), func)); loadS.push_back(new SgSymbol(VARIABLE_NAME, fileNS.c_str(), SgTypeInt(), func));
@@ -1633,22 +1414,10 @@ void createCheckpoints(SgFile* file, const map<string, CommonBlock*>& commonBloc
loadS.push_back(new SgSymbol(VARIABLE_NAME, iostatS.c_str(), SgTypeInt(), func)); loadS.push_back(new SgSymbol(VARIABLE_NAME, iostatS.c_str(), SgTypeInt(), func));
initLoadS.push_back(NULL); 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 loadLabelS = "spf_cp_load_label" + additional; string loadLabelS = "spf_cp_load_label" + additional;
loadS.push_back(new SgSymbol(VARIABLE_NAME, loadLabelS.c_str(), SgTypeInt(), func)); loadS.push_back(new SgSymbol(VARIABLE_NAME, loadLabelS.c_str(), SgTypeInt(), func));
initLoadS.push_back(new SgValueExp(0)); initLoadS.push_back(new SgValueExp(0));
string loadFS = "spf_cp_load_flag" + additional;
loadS.push_back(new SgSymbol(VARIABLE_NAME, loadFS.c_str(), SgTypeInt(), func));
initLoadS.push_back(new SgValueExp(1));
string saveFS = "spf_cp_save_flag" + additional;
loadS.push_back(new SgSymbol(VARIABLE_NAME, saveFS.c_str(), SgTypeInt(), func));
initLoadS.push_back(new SgValueExp(0));
SgExpression& unitNull = SgAssignOp(*new SgKeywordValExp("unit"), *new SgKeywordValExp("*")); SgExpression& unitNull = SgAssignOp(*new SgKeywordValExp("unit"), *new SgKeywordValExp("*"));
SgExpression& unit = SgAssignOp(*new SgKeywordValExp("unit"), *new SgValueExp(unitNum)); SgExpression& unit = SgAssignOp(*new SgKeywordValExp("unit"), *new SgValueExp(unitNum));
@@ -1668,18 +1437,7 @@ void createCheckpoints(SgFile* file, const map<string, CommonBlock*>& commonBloc
if (funcI->isMain) if (funcI->isMain)
insertInitNamesOfFiles(numOfFiles, additional, files, journal, lastDecl, false); insertInitNamesOfFiles(numOfFiles, additional, files, journal, lastDecl, false);
//TODO:
/*set<string> elemNotDeclHere;
for (auto& elem : commonVars)
{
if (addedToList.find(elem) == addedToList.end())
elemNotDeclHere.insert(elem);
}
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, loadS, &initLoadS);
makeDeclaration(moduleF, profS); makeDeclaration(moduleF, profS);
makeDeclaration(moduleF, { files }); makeDeclaration(moduleF, { files });
@@ -1739,21 +1497,22 @@ void createCheckpoints(SgFile* file, const map<string, CommonBlock*>& commonBloc
} }
} }
vector<SgSymbol*> everyS; vector<vector<string>> chainLocalVarNoParams;
vector<SgExpression*> initS;
vector<vector<string>> chainLocalVarNoParams; //localVarNoParams
vector<string> chainLabel; vector<string> chainLabel;
//TODO: this function needs to be completely rewritten!! processFunctionCallChain(func, allFuncInfo, moduleF, loadS, iostat, journal, frmt, unit, files,
processFunctionCallChain(func, allFuncInfo, moduleF, loadS, iostat, journal, frmt, unit, files, fileIdx, every, numOfFiles, additional, fileIdx, every, numOfFiles, additional, profS, frmtProf, unitNull,
profS, frmtProf, unitNull, unitNum, createdModuleForIO, moduleNames, chainLocalVarNoParams, chainLabel); unitNum, createdModuleForIO, moduleNames, chainLocalVarNoParams, chainLabel);
SgStatement* storeBlock = createSaveBlock(loadS, funcI, iostat, journal, frmt, unit, files, fileIdx, SgStatement* storeBlock = createSaveBlock(loadS, funcI, iostat, journal, frmt, unit, files, fileIdx,
numOfFiles, profS, frmtProf, unitNull, profCallS, profCallE, localVarNoParams, moduleStmts, numOfFiles, profS, frmtProf, unitNull, profCallS, profCallE,
commonVariables, createdModuleForIO, moduleNames, unitNum, chainLocalVarNoParams, chainLabel); localVarNoParams, moduleStmts, commonVariables, createdModuleForIO,
moduleNames, unitNum, chainLocalVarNoParams, chainLabel);
point->insertStmtBefore(*storeBlock, *point->controlParent()); point->insertStmtBefore(*storeBlock, *point->controlParent());
vector<SgSymbol*> everyS;
vector<SgExpression*> initS;
if (type == typeEvery::TIME) if (type == typeEvery::TIME)
{ {
string everySs = "spf_cp_start" + additional; string everySs = "spf_cp_start" + additional;
@@ -1793,15 +1552,17 @@ void createCheckpoints(SgFile* file, const map<string, CommonBlock*>& commonBloc
storeBlock->setExpression(0, *new SgVarRefExp(everyS[0]) >= *new SgValueExp(every)); storeBlock->setExpression(0, *new SgVarRefExp(everyS[0]) >= *new SgValueExp(every));
} }
makeDeclaration(moduleF, everyS, &initS);
const int labNum = getNextFreeLabel(); const int labNum = getNextFreeLabel();
auto nextStLab = new SgLabel(labNum); auto nextStLab = new SgLabel(labNum);
point->setLabel(*nextStLab); point->setLabel(*nextStLab);
SgStatement* gotoBlock = new SgIfStmt(*new SgVarRefExp(loadS[4]) == *new SgValueExp(labNum)); SgStatement* gotoBlock = new SgIfStmt(*new SgVarRefExp(loadS[0]) == *new SgValueExp(labNum));
gotoBlock->addComment("! goto CP\n"); gotoBlock->addComment("! GOTO CP\n");
gotoBlock->insertStmtAfter(*new SgGotoStmt(*nextStLab), *gotoBlock); gotoBlock->insertStmtAfter(*new SgGotoStmt(*nextStLab), *gotoBlock);
SgAssignStmt* init = new SgAssignStmt(*new SgVarRefExp(loadS[4]), *new SgValueExp(0)); SgAssignStmt* init = new SgAssignStmt(*new SgVarRefExp(loadS[0]), *new SgValueExp(0));
gotoBlock->insertStmtAfter(*init, *gotoBlock); gotoBlock->insertStmtAfter(*init, *gotoBlock);
loadBlock->insertStmtAfter(*gotoBlock, *loadBlock->controlParent()); loadBlock->insertStmtAfter(*gotoBlock, *loadBlock->controlParent());
} }