From e8cdf0e3f0cf16b764cd68cc6baa9c5cabcb3f11 Mon Sep 17 00:00:00 2001 From: ALEXks Date: Mon, 30 Sep 2024 20:24:34 +0300 Subject: [PATCH] added statistics, fixed shadow, fixed inliner, and etc. --- dvm/fdvm/trunk/fdvm/acc.cpp | 8 ++-- .../_src/DirectiveProcessing/shadow.cpp | 2 +- .../Sapfor_2017/_src/GraphCall/graph_calls.h | 38 +++++++++++++++++++ .../Sapfor_2017/_src/Inliner/inliner.cpp | 18 ++++++++- .../_src/Predictor/PredictScheme.cpp | 38 ++++++++++++++++--- sapfor/experts/Sapfor_2017/_src/Sapfor.cpp | 2 +- .../Transformations/function_purifying.cpp | 14 ++++++- .../experts/Sapfor_2017/_src/Utils/errors.h | 10 ++--- .../_src/Utils/russian_errors_text.txt | 2 +- .../experts/Sapfor_2017/_src/Utils/version.h | 2 +- .../VerificationCode/StructureChecker.cpp | 4 +- 11 files changed, 115 insertions(+), 23 deletions(-) diff --git a/dvm/fdvm/trunk/fdvm/acc.cpp b/dvm/fdvm/trunk/fdvm/acc.cpp index 93b35a7..502b1ee 100644 --- a/dvm/fdvm/trunk/fdvm/acc.cpp +++ b/dvm/fdvm/trunk/fdvm/acc.cpp @@ -1118,7 +1118,7 @@ void EnterDataRegionForLocalVariables(SgStatement *st, SgStatement *first_exec, { if (!el->lhs()) continue; SgSymbol *sym = el->lhs()->symbol(); - if (sym->variant() != CONST_NAME && IS_LOCAL_VAR(sym) && !IS_ALLOCATABLE(sym) && !(sym->attributes() & HEAP_BIT)) // //!(el->lhs()->symbol()->attributes() & PARAMETER_BIT) ) + if (sym->variant() != CONST_NAME && IS_LOCAL_VAR(sym) && !IS_ALLOCATABLE(sym) && !IS_POINTER_F90(sym) && !(sym->attributes() & HEAP_BIT)) // //!(el->lhs()->symbol()->attributes() & PARAMETER_BIT) ) { if ((HAS_SAVE_ATTR(sym) || IN_DATA(sym)) && IS_ARRAY(sym)) newst = doIfThenForDataRegion(DataRegionVar(sym), st, DataEnter(new SgVarRefExp(sym),ConstRef(0))); @@ -1128,7 +1128,7 @@ void EnterDataRegionForLocalVariables(SgStatement *st, SgStatement *first_exec, } for (sl = acc_registered_list; sl; sl = sl->next) { - if (sl->symb->variant() != CONST_NAME && IS_LOCAL_VAR(sl->symb) && !IS_ALLOCATABLE(sl->symb) && !HEADER(sl->symb)) //!(sl->symb->attributes() & PARAMETER_BIT)) + if (sl->symb->variant() != CONST_NAME && IS_LOCAL_VAR(sl->symb) && !IS_ALLOCATABLE(sl->symb) && !IS_POINTER_F90(sl->symb) && !HEADER(sl->symb)) //!(sl->symb->attributes() & PARAMETER_BIT)) { if ((HAS_SAVE_ATTR(sl->symb) || IN_DATA(sl->symb)) && IS_ARRAY(sl->symb)) newst = doIfThenForDataRegion(DataRegionVar(sl->symb), st, DataEnter(new SgVarRefExp(sl->symb),ConstRef(0))); @@ -1149,7 +1149,7 @@ void ExitDataRegionForLocalVariables(SgStatement *st, int is) { if (!el->lhs()) continue; SgSymbol *sym = el->lhs()->symbol(); - if (sym->variant() != CONST_NAME && IS_LOCAL_VAR(sym) && !IS_ALLOCATABLE(sym) && !(sym->attributes() & HEAP_BIT)) // //!(el->lhs()->symbol()->attributes() & PARAMETER_BIT) ) + if (sym->variant() != CONST_NAME && IS_LOCAL_VAR(sym) && !IS_ALLOCATABLE(sym) && !IS_POINTER_F90(sym) && !(sym->attributes() & HEAP_BIT)) // //!(el->lhs()->symbol()->attributes() & PARAMETER_BIT) ) { if ((HAS_SAVE_ATTR(sym) || IN_DATA(sym)) && IS_ARRAY(sym)) continue; @@ -1160,7 +1160,7 @@ void ExitDataRegionForLocalVariables(SgStatement *st, int is) } for (sl = acc_registered_list; sl; sl = sl->next) { - if (sl->symb->variant() != CONST_NAME && IS_LOCAL_VAR(sl->symb) && !IS_ALLOCATABLE(sl->symb) && !HEADER(sl->symb)) //!(sl->symb->attributes() & PARAMETER_BIT)) + if (sl->symb->variant() != CONST_NAME && IS_LOCAL_VAR(sl->symb) && !IS_ALLOCATABLE(sl->symb) && !IS_POINTER_F90(sl->symb) && !HEADER(sl->symb)) //!(sl->symb->attributes() & PARAMETER_BIT)) { if ((HAS_SAVE_ATTR(sl->symb) || IN_DATA(sl->symb)) && IS_ARRAY(sl->symb)) continue; diff --git a/sapfor/experts/Sapfor_2017/_src/DirectiveProcessing/shadow.cpp b/sapfor/experts/Sapfor_2017/_src/DirectiveProcessing/shadow.cpp index aa895da..a8bccba 100644 --- a/sapfor/experts/Sapfor_2017/_src/DirectiveProcessing/shadow.cpp +++ b/sapfor/experts/Sapfor_2017/_src/DirectiveProcessing/shadow.cpp @@ -309,7 +309,7 @@ static void replaceShadowByRemote(SgExpression *specInDir, SgStatement *stat, void devourShadowByRemote(void *file_, const map& funcMap, const vector& loops, const map> &arrayLinksByFuncCalls) -{ +{ SgFile* file = static_cast(file_); map loopByLine; createMapLoopGraph(loops, loopByLine); diff --git a/sapfor/experts/Sapfor_2017/_src/GraphCall/graph_calls.h b/sapfor/experts/Sapfor_2017/_src/GraphCall/graph_calls.h index c4597f0..17fc462 100644 --- a/sapfor/experts/Sapfor_2017/_src/GraphCall/graph_calls.h +++ b/sapfor/experts/Sapfor_2017/_src/GraphCall/graph_calls.h @@ -242,6 +242,44 @@ struct FuncInfo if (names.size() == 1) return *names.begin(); + //try to find in next lvl calls + for (auto& call : callsFromDetailed) + { + if (call.detailCallsFrom.second == line) + { + std::string name_next = call.detailCallsFrom.first; + std::set next, done; + + for (auto& callFrom : callsFromV) + if (callFrom->funcName == name_next) + next.insert(callFrom); + + done = next; + while (next.size()) + { + auto curr = next; + next.clear(); + + for (auto& callFrom : curr) + { + for (auto& call : callFrom->callsFromDetailed) + { + if (call.detailCallsFrom.first == name) + return call.detailCallsFrom.first; + } + + for (auto& callFromNext : callFrom->callsFromV) + { + if (done.find(callFromNext) == done.end()) + { + next.insert(callFromNext); + done.insert(callFromNext); + } + } + } + } + } + } return ""; } }; diff --git a/sapfor/experts/Sapfor_2017/_src/Inliner/inliner.cpp b/sapfor/experts/Sapfor_2017/_src/Inliner/inliner.cpp index 38b384c..ad87c5a 100644 --- a/sapfor/experts/Sapfor_2017/_src/Inliner/inliner.cpp +++ b/sapfor/experts/Sapfor_2017/_src/Inliner/inliner.cpp @@ -1483,9 +1483,8 @@ static bool run_inliner(const map& funcMap, set { wstring messageE, messageR; __spf_printToLongBuf(messageE, L"It is allowed to inline function only at execution code section."); -#ifdef _WIN32 __spf_printToLongBuf(messageR, R177); -#endif + getObjectForFileFromMap(fileName.c_str(), SPF_messages).push_back(Messages(ERROR, insertPlace->lineNumber(), messageR, messageE, 2011)); printInternalError(convertFileName(__FILE__).c_str(), __LINE__); } @@ -1689,6 +1688,18 @@ static map> fillNextDeep(const set& i return nextInfo; } +static void addMessage(bool status, map>& SPF_messages, const string& fileName, const int line) +{ + if (status == true) + return; + + wstring messageE, messageR; + __spf_printToLongBuf(messageE, L"Function inlining failed with an error."); + __spf_printToLongBuf(messageR, R193); + + getObjectForFileFromMap(fileName.c_str(), SPF_messages).push_back(Messages(ERROR, line, messageR, messageE, 2020)); +} + static bool inliner(const string& fileName_in, const string& funcName, const int lineNumber, const map>& allFuncInfo, map>& SPF_messages, map>& newSymbsToDeclare, const map& commonBlocks, @@ -1773,6 +1784,7 @@ static bool inliner(const string& fileName_in, const string& funcName, const int //1 level bool isInlined = run_inliner(funcMap, toInsert, SPF_messages, fileName, func, newSymbsToDeclare, point, commonBlocks); __spf_print(1, "%s\n", isInlined ? "done" : "fault"); + addMessage(isInlined, SPF_messages, fileName, lineNumber); if (isInlined == false) { @@ -1807,6 +1819,8 @@ static bool inliner(const string& fileName_in, const string& funcName, const int __spf_print(1, " INLINE %s - ", next.first->funcName.c_str()); bool isInlined = run_inliner(funcMap, next.second, SPF_messages, fileName, next.first, newSymbsToDeclare, point, commonBlocks); __spf_print(1, "%s\n", isInlined ? "done" : "fault"); + addMessage(isInlined, SPF_messages, fileName, lineNumber); + changed |= isInlined; } } diff --git a/sapfor/experts/Sapfor_2017/_src/Predictor/PredictScheme.cpp b/sapfor/experts/Sapfor_2017/_src/Predictor/PredictScheme.cpp index 371dfd5..5844fad 100644 --- a/sapfor/experts/Sapfor_2017/_src/Predictor/PredictScheme.cpp +++ b/sapfor/experts/Sapfor_2017/_src/Predictor/PredictScheme.cpp @@ -152,7 +152,8 @@ static void calculate_for_parallel_loop(SgStatement* loop, const map>& allFuncInfo, const map>& gCovInfo) { - uint64_t paralle_exec_count = 0; + uint64_t total_exec_count = 0; + uint64_t parallel_exec_count = 0; uint64_t count_of_parallel_lines = 0; for (auto& byFile : allFuncInfo) { @@ -170,7 +171,8 @@ void calculate_stats_for_predictor(const map>& allFunc for (auto& func : byFile.second) { SgStatement* stat = func->funcPointer->GetOriginal(); - for (auto st = stat->lexNext(); st != stat->lastNodeOfStmt(); st = st->lexNext()) { + for (auto st = stat->lexNext(); st != stat->lastNodeOfStmt(); st = st->lexNext()) + { uint64_t paralle_exec = 0; uint64_t lines_count = 0; @@ -183,18 +185,44 @@ void calculate_stats_for_predictor(const map>& allFunc calculate_for_parallel_loop(loop, gcov, paralle_exec, lines_count); st = loop->lastNodeOfStmt(); - paralle_exec_count += paralle_exec; + parallel_exec_count += paralle_exec; count_of_parallel_lines += lines_count; __spf_print(1, " PAR LOOP [%d %s] total exec %llu, total exec lines %llu, avg %.16e\n", loop->lineNumber(), byFile.first.c_str(), paralle_exec, lines_count, paralle_exec / (double)lines_count); } } + + for (auto st = stat->lexNext(); st != stat->lastNodeOfStmt(); st = st->lexNext()) + { + if (!isSgExecutableStatement(st) || isDVM_stat(st) || isSPF_stat(st)) + continue; + + int line = st->lineNumber(); + if (line <= 0) + continue; + + auto it = gcov.find(line); + if (it == gcov.end()) + continue; + + auto& info = it->second; + + if (info.getNumLine() != line) { + __spf_print(1, "bad gcov info\n"); + printInternalError(convertFileName(__FILE__).c_str(), __LINE__); + } + + total_exec_count += info.getExecutedCount(); + } } } - __spf_print(1, " coverage_average %.16e\n", paralle_exec_count / (double)count_of_parallel_lines); + __spf_print(1, " average_parallel_exec %.16e\n", parallel_exec_count / (double)count_of_parallel_lines); + __spf_print(1, " parallel_rate %.16e\n", parallel_exec_count / (double)total_exec_count); + ofstream stats("stats.csv"); - stats << "coverage_average;" << paralle_exec_count / (double)count_of_parallel_lines << std::endl; + stats << "average_parallel_exec;" << parallel_exec_count / (double)count_of_parallel_lines << std::endl; + stats << "parallel_rate;" << parallel_exec_count / (double)total_exec_count << std::endl; stats.close(); } \ No newline at end of file diff --git a/sapfor/experts/Sapfor_2017/_src/Sapfor.cpp b/sapfor/experts/Sapfor_2017/_src/Sapfor.cpp index 48a657d..ca5a72d 100644 --- a/sapfor/experts/Sapfor_2017/_src/Sapfor.cpp +++ b/sapfor/experts/Sapfor_2017/_src/Sapfor.cpp @@ -1908,7 +1908,7 @@ static bool runAnalysis(SgProject &project, const int curr_regime, const bool ne } static int countMaxValuesForParallelVariants(int &maxDims, int &maxDimsIdx, int &maxDimsIdxReg, vector> ¤tVariants) -{ +{ int lastI; if (consoleMode) { diff --git a/sapfor/experts/Sapfor_2017/_src/Transformations/function_purifying.cpp b/sapfor/experts/Sapfor_2017/_src/Transformations/function_purifying.cpp index c338c1a..32a3771 100644 --- a/sapfor/experts/Sapfor_2017/_src/Transformations/function_purifying.cpp +++ b/sapfor/experts/Sapfor_2017/_src/Transformations/function_purifying.cpp @@ -92,8 +92,18 @@ void insertIntrinsicStat(const vector& allFuncInfo) SgStatement* intr = new SgStatement(INTRIN_STAT); intr->setExpression(0, makeExprList(list)); - intr->setlineNumber(st->lineNumber()); + auto prev = (st->variant() == FOR_NODE) ? st->lexPrev() : st; + int line = prev->lineNumber(); + while (line <= 0 && !isSgProgHedrStmt(prev)) { + prev = prev->lexPrev(); + line = prev->lineNumber(); + } + + if (line <= 0) + printInternalError(convertFileName(__FILE__).c_str(), __LINE__); + + intr->setlineNumber(line); st->insertStmtBefore(*intr, *func->funcPointer); } else @@ -449,6 +459,8 @@ static void insertIntents(set& identificators, SgStatement* header, cons if (args.size()) { SgIntentStmt* intent = new SgIntentStmt(*makeExprList(args), *attr); + intent->setlineNumber(lastDecl->lineNumber()); + lastDecl->insertStmtAfter(*intent, (header == lastDecl) ? *header : *lastDecl->controlParent()); } } diff --git a/sapfor/experts/Sapfor_2017/_src/Utils/errors.h b/sapfor/experts/Sapfor_2017/_src/Utils/errors.h index 179621f..565d4b6 100644 --- a/sapfor/experts/Sapfor_2017/_src/Utils/errors.h +++ b/sapfor/experts/Sapfor_2017/_src/Utils/errors.h @@ -86,8 +86,8 @@ enum typeMessage { WARR, ERROR, NOTE }; // 07 "Internal error during unparsing process has occurred" // 08 "Can not do PRIVATE EXPANSION for this loop - privates not found" // 09 "Can not split this loop because of dependecy: %s" -// 10 "This loop has indirect child loops and can not be splitted\n" -// 11 +// 10 "This loop has indirect child loops and can not be splitted" +// 11 "It is allowed to inline function only at execution code section" // 12 "for function duplication" // 13 "for function duplication" // 14 inlining errors - dims mismatch @@ -96,7 +96,7 @@ enum typeMessage { WARR, ERROR, NOTE }; // 17 cannot remove private var '%s' - it has recursive dependency or it depends on non-invariant var '%s' // 18 "private variable '%s' was removed" or "private variable '%s' was partially removed" // 19 "Removing of private var '%s' was made with assumption that references '%s' and '%s' are different" -// 20 --- FREE POSITION +// 20 "Function inlining failed with an error" // 21 "cannot remove private var '%s' - cannot find reaching definition for the statement" // 22 "cannot transform ..." // 23 "cannot transform ..." @@ -276,7 +276,7 @@ static void printStackTrace() { }; } \ } while (0) -// Свободный - R193 и далее R205 +// Свободный - R205 // Гайд по русификации сообщений: При добавлении нового сообщения, меняется последний сводобный идентификатор. // В этом файле остаются только спецификаторы, для которых будет заполнен текст. Полный текст пишется в файле // russian_errors_text.txt. Спецификаторы там тоже сохраняются, по ним в визуализаторе будет восстановлен @@ -523,7 +523,7 @@ static const wchar_t *R201 = L"R201:%s"; //2019 static const wchar_t *R192 = L"R192:%s#%s#%s"; //2020 -// static const wchar_t *R193 = L"R193:%s"; +static const wchar_t *R193 = L"R193:"; //2021 static const wchar_t *R194 = L"R194:%s"; //2022 diff --git a/sapfor/experts/Sapfor_2017/_src/Utils/russian_errors_text.txt b/sapfor/experts/Sapfor_2017/_src/Utils/russian_errors_text.txt index ed08dd6..0d254e3 100644 --- a/sapfor/experts/Sapfor_2017/_src/Utils/russian_errors_text.txt +++ b/sapfor/experts/Sapfor_2017/_src/Utils/russian_errors_text.txt @@ -233,7 +233,7 @@ R201 = "Приватная переменная '%s' была частично //2019 R192 = "Удаление приватной переменной '%s' было выполнено в предположении, что выражения '%s' и '%s' различны" //2020 -R193 = "--FREE POSITION" +R193 = "Подстановка функций выполнилась с ошибкой" //2021 R194 = "Нельзя удалить приватную переменную '%s' - не удалось найти достигающее определение для оператора" //2022 diff --git a/sapfor/experts/Sapfor_2017/_src/Utils/version.h b/sapfor/experts/Sapfor_2017/_src/Utils/version.h index 974f2b9..383d187 100644 --- a/sapfor/experts/Sapfor_2017/_src/Utils/version.h +++ b/sapfor/experts/Sapfor_2017/_src/Utils/version.h @@ -1,3 +1,3 @@ #pragma once -#define VERSION_SPF "2362" +#define VERSION_SPF "2364" diff --git a/sapfor/experts/Sapfor_2017/_src/VerificationCode/StructureChecker.cpp b/sapfor/experts/Sapfor_2017/_src/VerificationCode/StructureChecker.cpp index 62bf14e..407510b 100644 --- a/sapfor/experts/Sapfor_2017/_src/VerificationCode/StructureChecker.cpp +++ b/sapfor/experts/Sapfor_2017/_src/VerificationCode/StructureChecker.cpp @@ -555,6 +555,7 @@ bool OperatorChecker(SgFile* file, map>& currMessages) SgStatement* st = file->firstStatement(); string currF = file->filename(); + const set cpOnSameLine = { ARITHIF_NODE, LOGIF_NODE, GOTO_NODE , IF_NODE, FORALL_STAT }; while (st) { int line = st->lineNumber(); @@ -562,9 +563,8 @@ bool OperatorChecker(SgFile* file, map>& currMessages) ; // skip else if (line > 0 && st->fileName() == currF) { - ; int var = st->controlParent()->variant(); - bool cpWasAdded = (var == ARITHIF_NODE || var == LOGIF_NODE || var == GOTO_NODE || var == IF_NODE) && (usedLines.find(line) != usedLines.end()); + bool cpWasAdded = cpOnSameLine.find(var) != cpOnSameLine.end() && (usedLines.find(line) != usedLines.end()); if (usedLines.find(line) != usedLines.end() && !cpWasAdded) {