diff --git a/dvm/fdvm/trunk/fdvm/acc_f2c.cpp b/dvm/fdvm/trunk/fdvm/acc_f2c.cpp index 07cb93a..84f2971 100644 --- a/dvm/fdvm/trunk/fdvm/acc_f2c.cpp +++ b/dvm/fdvm/trunk/fdvm/acc_f2c.cpp @@ -170,7 +170,7 @@ static char* getNestCond() static char* getNewCycleVar(const char *oldVar) { - char *str = new char[strlen(oldVar) + 2]; + char *str = new char[strlen(oldVar) + 3]; str[0] = '\0'; strcat(str, "__"); strcat(str, oldVar); @@ -3468,7 +3468,7 @@ SgSymbol *hasSameNameAsSource(SgSymbol *symb) int sameVariableName(SgSymbol *symb1, SgSymbol *symb2) { - if (!symb1 || !symb2 || (symb1->variant() != VARIABLE_NAME && symb1->variant() != CONST_NAME) || symb2->variant() != VARIABLE_NAME && symb2->variant() != CONST_NAME) + if (!symb1 || !symb2 || (symb1->variant() != VARIABLE_NAME && symb1->variant() != CONST_NAME && symb1->variant() != FUNCTION_NAME) || symb2->variant() != VARIABLE_NAME && symb2->variant() != CONST_NAME && symb2->variant() != FUNCTION_NAME) return 0; if (!strcmp (symb1->identifier(), symb2->identifier())) return 1; diff --git a/dvm/fdvm/trunk/fdvm/io.cpp b/dvm/fdvm/trunk/fdvm/io.cpp index fc21dd4..bef53c4 100644 --- a/dvm/fdvm/trunk/fdvm/io.cpp +++ b/dvm/fdvm/trunk/fdvm/io.cpp @@ -661,7 +661,7 @@ void ReadWritePrint_Statement(SgStatement *stmt, int error_msg) //if(IN_COMPUTE_REGION && !in_checksection) // ChangeDistArrayRef(iol); } - if(inparloop && (send || IN_COMPUTE_REGION) && error_msg) + if(inparloop && (send || IN_COMPUTE_REGION || parloop_by_handler) && error_msg) err("Illegal I/O statement in the range of parallel loop/region", 184,stmt); } diff --git a/dvm/fdvm/trunk/fdvm/parloop.cpp b/dvm/fdvm/trunk/fdvm/parloop.cpp index fd70b5f..e859f4f 100644 --- a/dvm/fdvm/trunk/fdvm/parloop.cpp +++ b/dvm/fdvm/trunk/fdvm/parloop.cpp @@ -458,7 +458,7 @@ int WhatInterface(SgStatement *stmt) case SHADOW_COMP_OP: case ACROSS_OP: case ACC_TIE_OP: - case CONSISTENT_OP: + case CONSISTENT_OP: case STAGE_OP: case REMOTE_ACCESS_OP: if(e->symbol()) // asynchronous REMOTE_ACCESS @@ -2297,8 +2297,10 @@ void Interface_2(SgStatement *stmt,SgExpression *clause[],SgExpression *init[],S } if (clause[CONSISTENT_]) //there is CONSISTENT clause for (SgExpression *el = clause[CONSISTENT_]->lhs(); el; el=el->rhs()) - InsertNewStatementAfter(Consistent_H(ilh, HeaderForArrayInParallelDir(el->lhs()->symbol(), stmt, 0), MappingList(stmt, el->lhs())), cur_st, cur_st->controlParent()); - + { + SgExpression *head = HeaderForArrayInParallelDir(el->lhs()->symbol(), stmt, 0); + InsertNewStatementAfter(Consistent_H(ilh, head, MappingList(stmt, el->lhs())), cur_st, cur_st->controlParent()); + } if (clause[REMOTE_ACCESS_]) //there is REMOTE_ACCESS clause { int nbuf=1; //adding new element to remote_access directive/clause list @@ -2306,7 +2308,10 @@ void Interface_2(SgStatement *stmt,SgExpression *clause[],SgExpression *init[],S RemoteVariableList(clause[REMOTE_ACCESS_]->symbol(), clause[REMOTE_ACCESS_]->lhs(), stmt); for (SgExpression *el=clause[REMOTE_ACCESS_]->lhs(); el; el=el->rhs(),nbuf++) - InsertNewStatementAfter(LoopRemoteAccess_H(ilh, HeaderForArrayInParallelDir(el->lhs()->symbol(), stmt, 0), el->lhs()->symbol(), MappingList(stmt, ArrayRefAddition(el->lhs()))), cur_st, cur_st->controlParent()); + { + SgExpression *head = HeaderForArrayInParallelDir(el->lhs()->symbol(), stmt, 0); + InsertNewStatementAfter(LoopRemoteAccess_H(ilh, head, el->lhs()->symbol(), MappingList(stmt, ArrayRefAddition(el->lhs()))), cur_st, cur_st->controlParent()); + } } if (clause[SHADOW_COMPUTE_]) //there is SHADOW_COMPUTE clause diff --git a/sapfor/experts/Sapfor_2017/_src/DynamicAnalysis/gcov_info.cpp b/sapfor/experts/Sapfor_2017/_src/DynamicAnalysis/gcov_info.cpp index 87e2199..c37cf81 100644 --- a/sapfor/experts/Sapfor_2017/_src/DynamicAnalysis/gcov_info.cpp +++ b/sapfor/experts/Sapfor_2017/_src/DynamicAnalysis/gcov_info.cpp @@ -45,4 +45,4 @@ int Perform::getPercent() { return percent; } void Perform::setNumber(int a) { number = a; } void Perform::setPercent(int a) { percent = a; } void Perform::gcov_print() { __spf_print(1, "%d - %d\n", number, percent); } -ostream &operator<<(ostream &out, const Perform &a) { out << "number= " << a.number << "\npercent= " << a.percent << endl; return out; } \ No newline at end of file +ostream &operator<<(ostream &out, const Perform &a) { out << "number= " << a.number << ": percent= " << a.percent << endl; return out; } \ No newline at end of file diff --git a/sapfor/experts/Sapfor_2017/_src/Inliner/inliner.cpp b/sapfor/experts/Sapfor_2017/_src/Inliner/inliner.cpp index af8ea9d..38b384c 100644 --- a/sapfor/experts/Sapfor_2017/_src/Inliner/inliner.cpp +++ b/sapfor/experts/Sapfor_2017/_src/Inliner/inliner.cpp @@ -1019,6 +1019,10 @@ static void insert(SgStatement* callSt, SgStatement* tempHedr, SgStatement* begi st->setlineNumber(getNextNegativeLineNumber()); } + next = prev->lexNext(); + next->setlineNumber(callSt->lineNumber()); + next->setFileName(callSt->fileName()); + last->extractStmt(); if (callSt->variant() == PROC_STAT) diff --git a/sapfor/experts/Sapfor_2017/_src/Predictor/PredictScheme.cpp b/sapfor/experts/Sapfor_2017/_src/Predictor/PredictScheme.cpp index 7750c54..371dfd5 100644 --- a/sapfor/experts/Sapfor_2017/_src/Predictor/PredictScheme.cpp +++ b/sapfor/experts/Sapfor_2017/_src/Predictor/PredictScheme.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include @@ -12,9 +13,16 @@ #include #include "dvm.h" +#include "../DynamicAnalysis/gcov_info.h" #include "PredictScheme.h" #include "../Utils/SgUtils.h" +using std::map; +using std::string; +using std::vector; +using std::set; +using std::ofstream; + static void fillParallel(SgExpression *exp, ParallelStats &parStats, int &totalScoreComm) { if (exp) @@ -116,3 +124,77 @@ void processFileToPredict(SgFile *file, PredictorStats &predictorCounts) predictorCounts.TotalScorePar += predictorCounts.ParallelCount; } + +static void calculate_for_parallel_loop(SgStatement* loop, const map& gcov, + uint64_t& paralle_exec_count, uint64_t& count_of_parallel_lines) { + for (auto st = loop; st != loop->lastNodeOfStmt(); st = st->lexNext()) { + int line = st->lineNumber(); + if (line <= 0) + continue; + + auto it = gcov.find(line); + if (it == gcov.end()) { + __spf_print(1, "bad gcov info\n"); + printInternalError(convertFileName(__FILE__).c_str(), __LINE__); + } + + auto& info = it->second; + + if (info.getNumLine() != line) { + __spf_print(1, "bad gcov info\n"); + printInternalError(convertFileName(__FILE__).c_str(), __LINE__); + } + + count_of_parallel_lines++; + paralle_exec_count += info.getExecutedCount(); + } +} + +void calculate_stats_for_predictor(const map>& allFuncInfo, + const map>& gCovInfo) { + uint64_t paralle_exec_count = 0; + uint64_t count_of_parallel_lines = 0; + + for (auto& byFile : allFuncInfo) { + int ok = SgFile::switchToFile(byFile.first); + if (ok == -1) + printInternalError(convertFileName(__FILE__).c_str(), __LINE__); + + auto it = gCovInfo.find(byFile.first); + if (it == gCovInfo.end()) { + __spf_print(1, "bad gcov info\n"); + printInternalError(convertFileName(__FILE__).c_str(), __LINE__); + } + + auto& gcov = it->second; + for (auto& func : byFile.second) { + SgStatement* stat = func->funcPointer->GetOriginal(); + + for (auto st = stat->lexNext(); st != stat->lastNodeOfStmt(); st = st->lexNext()) { + uint64_t paralle_exec = 0; + uint64_t lines_count = 0; + + if (st->variant() == DVM_PARALLEL_ON_DIR) { + auto loop = st->lexNext(); + checkNull(loop, convertFileName(__FILE__).c_str(), __LINE__); + if (loop->variant() != FOR_NODE) + printInternalError(convertFileName(__FILE__).c_str(), __LINE__); + + calculate_for_parallel_loop(loop, gcov, paralle_exec, lines_count); + st = loop->lastNodeOfStmt(); + + paralle_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); + } + } + } + } + + __spf_print(1, " coverage_average %.16e\n", paralle_exec_count / (double)count_of_parallel_lines); + ofstream stats("stats.csv"); + stats << "coverage_average;" << paralle_exec_count / (double)count_of_parallel_lines << std::endl; + stats.close(); +} \ No newline at end of file diff --git a/sapfor/experts/Sapfor_2017/_src/Predictor/PredictScheme.h b/sapfor/experts/Sapfor_2017/_src/Predictor/PredictScheme.h index 2e3e236..d333fb7 100644 --- a/sapfor/experts/Sapfor_2017/_src/Predictor/PredictScheme.h +++ b/sapfor/experts/Sapfor_2017/_src/Predictor/PredictScheme.h @@ -1,6 +1,7 @@ #pragma once #include #include "dvm.h" +#include "../GraphCall/graph_calls.h" class ParallelStats { @@ -51,4 +52,6 @@ public: } }; -void processFileToPredict(SgFile *file, PredictorStats &predictorCounts); \ No newline at end of file +void processFileToPredict(SgFile *file, PredictorStats &predictorCounts); + +void calculate_stats_for_predictor(const std::map>& allFuncInfo, const std::map>& gCovInfo); \ 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 b1637f2..48a657d 100644 --- a/sapfor/experts/Sapfor_2017/_src/Sapfor.cpp +++ b/sapfor/experts/Sapfor_2017/_src/Sapfor.cpp @@ -1892,9 +1892,9 @@ static bool runAnalysis(SgProject &project, const int curr_regime, const bool ne else if (curr_regime == FIX_COMMON_BLOCKS) fixCommonBlocks(allFuncInfo, commonBlocks, &project); else if (curr_regime == GET_MIN_MAX_BLOCK_DIST) - { __spf_print(1, "GET_MIN_MAX_BLOCK_DIST: %d %d\n", min_max_block.first, min_max_block.second); - } + else if (curr_regime == GET_STATS_FOR_PREDICTOR) + calculate_stats_for_predictor(allFuncInfo, gCovInfo); const float elapsed = duration_cast(high_resolution_clock::now() - timeForPass).count() / 1000.; const float elapsedGlobal = duration_cast(high_resolution_clock::now() - globalTime).count() / 1000.; diff --git a/sapfor/experts/Sapfor_2017/_src/Sapfor.h b/sapfor/experts/Sapfor_2017/_src/Sapfor.h index 40046f8..0bfc452 100644 --- a/sapfor/experts/Sapfor_2017/_src/Sapfor.h +++ b/sapfor/experts/Sapfor_2017/_src/Sapfor.h @@ -109,6 +109,7 @@ enum passes { FILL_COMMON_BLOCKS, PREDICT_SCHEME, CALCULATE_STATS_SCHEME, + GET_STATS_FOR_PREDICTOR, DEF_USE_STAGE1, DEF_USE_STAGE2, @@ -288,6 +289,7 @@ static void setPassValues() passNames[ARRAY_ACCESS_ANALYSIS_FOR_CORNER] = "ARRAY_ACCESS_ANALYSIS_FOR_CORNER"; passNames[FILL_COMMON_BLOCKS] = "FILL_COMMON_BLOCKS"; passNames[PREDICT_SCHEME] = "PREDICT_SCHEME"; + passNames[GET_STATS_FOR_PREDICTOR] = "GET_STATS_FOR_PREDICTOR"; passNames[DEF_USE_STAGE1] = "DEF_USE_STAGE1"; passNames[DEF_USE_STAGE2] = "DEF_USE_STAGE2"; passNames[REMOVE_DVM_DIRS_TO_COMMENTS] = "REMOVE_DVM_DIRS_TO_COMMENTS"; diff --git a/sapfor/experts/Sapfor_2017/_src/Utils/PassManager.h b/sapfor/experts/Sapfor_2017/_src/Utils/PassManager.h index 5952c12..f2e596b 100644 --- a/sapfor/experts/Sapfor_2017/_src/Utils/PassManager.h +++ b/sapfor/experts/Sapfor_2017/_src/Utils/PassManager.h @@ -265,7 +265,7 @@ void InitPassesDependencies(map> &passDepsIn, set list({ LOOP_ANALYZER_COMP_DIST, REMOVE_OMP_DIRS }) <= list({ CREATE_DISTR_DIRS, CREATE_PARALLEL_DIRS, INSERT_PARALLEL_DIRS }); - Pass(CALL_GRAPH2) <= list({ ONLY_ARRAY_GRAPH, CREATE_NESTED_LOOPS, FIND_FUNC_TO_INCLUDE, CHECK_FUNC_TO_INCLUDE, FIND_PARAMETERS }); + Pass(CALL_GRAPH2) <= list({ ONLY_ARRAY_GRAPH, CREATE_NESTED_LOOPS, FIND_FUNC_TO_INCLUDE, CHECK_FUNC_TO_INCLUDE, FIND_PARAMETERS, GET_STATS_FOR_PREDICTOR }); Pass(CALL_GRAPH2) <= list({ PURE_SAVE_TO_PARAMS, PURE_MODULE_TO_PARAMS, PURE_COMMON_TO_PARAMS, PURE_INTENT_INSERT }); diff --git a/sapfor/experts/Sapfor_2017/_src/Utils/version.h b/sapfor/experts/Sapfor_2017/_src/Utils/version.h index 0c1ec5a..974f2b9 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 "2359" +#define VERSION_SPF "2362" diff --git a/sapfor/experts/Sapfor_2017/_src/VerificationCode/StructureChecker.cpp b/sapfor/experts/Sapfor_2017/_src/VerificationCode/StructureChecker.cpp index 0c6d0e9..62bf14e 100644 --- a/sapfor/experts/Sapfor_2017/_src/VerificationCode/StructureChecker.cpp +++ b/sapfor/experts/Sapfor_2017/_src/VerificationCode/StructureChecker.cpp @@ -554,11 +554,15 @@ bool OperatorChecker(SgFile* file, map>& currMessages) SgStatement* st = file->firstStatement(); string currF = file->filename(); + while (st) { int line = st->lineNumber(); - if (line > 0 && st->fileName() == currF) + if (line > 0 && st->variant() == PROG_HEDR && st->symbol()->identifier() == string("_MAIN")) + ; // 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());