diff --git a/sapfor/experts/Sapfor_2017/_src/DirectiveProcessing/directive_omp_parser.cpp b/sapfor/experts/Sapfor_2017/_src/DirectiveProcessing/directive_omp_parser.cpp index 581886d..da472d8 100644 --- a/sapfor/experts/Sapfor_2017/_src/DirectiveProcessing/directive_omp_parser.cpp +++ b/sapfor/experts/Sapfor_2017/_src/DirectiveProcessing/directive_omp_parser.cpp @@ -47,7 +47,7 @@ static inline void addToAttribute(SgStatement* st, int var, vectorsetLhs(new SgExpression(var, makeExprList(list), NULL)); SgStatement* toAdd = new SgStatement(SPF_ANALYSIS_DIR, NULL, NULL, ex, NULL, NULL); toAdd->setlineNumber(st->lineNumber()); - toAdd->setLocalLineNumber(888); + toAdd->setLocalLineNumber(SPF_OMP_DIR); //filter if (var == ACC_PRIVATE_OP) diff --git a/sapfor/experts/Sapfor_2017/_src/DirectiveProcessing/directive_omp_parser.h b/sapfor/experts/Sapfor_2017/_src/DirectiveProcessing/directive_omp_parser.h index e241f38..8895289 100644 --- a/sapfor/experts/Sapfor_2017/_src/DirectiveProcessing/directive_omp_parser.h +++ b/sapfor/experts/Sapfor_2017/_src/DirectiveProcessing/directive_omp_parser.h @@ -6,6 +6,10 @@ #include "../Utils/errors.h" +#define SPF_USER_DIR 777 +#define SPF_USER_DIR_COPY 999 +#define SPF_OMP_DIR 888 + struct OmpDir { std::set privVars; diff --git a/sapfor/experts/Sapfor_2017/_src/DirectiveProcessing/spf_directive_preproc.cpp b/sapfor/experts/Sapfor_2017/_src/DirectiveProcessing/spf_directive_preproc.cpp index ee9bb12..da7ddee 100644 --- a/sapfor/experts/Sapfor_2017/_src/DirectiveProcessing/spf_directive_preproc.cpp +++ b/sapfor/experts/Sapfor_2017/_src/DirectiveProcessing/spf_directive_preproc.cpp @@ -20,6 +20,7 @@ #include "directive_parser.h" #include "../ExpressionTransform/expr_transform.h" #include "../LoopAnalyzer/loop_analyzer.h" +#include "../DirectiveProcessing/directive_omp_parser.h" using std::string; using std::wstring; @@ -34,7 +35,7 @@ static void addToattribute(SgStatement *toAttr, SgStatement *curr, const int var // move SgStatement to attribute SgStatement *toAdd = new SgStatement(toAttr->variant(), NULL, toAttr->symbol(), toAttr->expr(0), toAttr->expr(1), toAttr->expr(2)); toAdd->setlineNumber(toAttr->lineNumber()); - toAdd->setLocalLineNumber(777); + toAdd->setLocalLineNumber(SPF_USER_DIR); curr->addAttribute(variant, toAdd, sizeof(SgStatement)); //copy comments to st @@ -257,7 +258,7 @@ static bool checkPrivate(SgStatement *st, if (!defCond && !useCond) { - if (attributeStatement->localLineNumber() != 888) + if (attributeStatement->localLineNumber() != SPF_OMP_DIR) { __spf_print(1, "variable '%s' is not used in loop on line %d\n", privElem.c_str(), attributeStatement->lineNumber()); wstring messageE, messageR; @@ -272,7 +273,7 @@ static bool checkPrivate(SgStatement *st, } else if (!defCond && useCond) { - if (attributeStatement->localLineNumber() != 888) + if (attributeStatement->localLineNumber() != SPF_OMP_DIR) { __spf_print(1, "variable '%s' is not changed in loop on line %d\n", privElem.c_str(), attributeStatement->lineNumber()); wstring messageE, messageR; @@ -2042,6 +2043,69 @@ bool check_par_reg_dirs(SgFile *file, vector &messagesForFile) return noError; } +static void distributeAnalysisWithCover(SgFile* file) +{ + int funcNum = file->numberOfFunctions(); + const string currFile = file->filename(); + + for (int i = 0; i < funcNum; ++i) + { + SgStatement* st = file->functions(i); + SgStatement* lastNode = st->lastNodeOfStmt(); + + map, int>> spfAnalysis; + do + { + st = st->lexNext(); + if (st == NULL) + { + __spf_print(1, "internal error in analysis, parallel directives will not be generated for this file!\n"); + break; + } + + if (st->variant() == CONTAINS_STMT) + break; + + if (st->variant() == FOR_NODE) + { + pair, int> newData = { set(), 0 }; + for (auto& data : getAttributes(st, set{ SPF_ANALYSIS_DIR })) + { + newData.first.insert(data); + int cover = getCoverPropertyFromComment(new Statement(data)); + if (cover != 0) + newData.second = cover; + } + if (newData.first.size()) + spfAnalysis[st] = newData; + } + } while (st != lastNode); + + for (auto& data : spfAnalysis) + { + SgForStmt* st = isSgForStmt(data.first); + checkNull(st, convertFileName(__FILE__).c_str(), __LINE__); + + int level = st->isPerfectLoopNest(); + if (data.second.second < level && data.second.second != 0) + level = data.second.second; + + for (int z = 0; z < level - 1; ++z) + { + st = isSgForStmt(st->lexNext()); + checkNull(st, convertFileName(__FILE__).c_str(), __LINE__); + + for (auto& dirs : data.second.first) + { + auto copy = dirs->copyPtr(); + copy->setLocalLineNumber(SPF_USER_DIR_COPY); + st->addAttribute(copy->variant(), copy, sizeof(SgStatement)); + } + } + } + } +} + bool preprocess_spf_dirs(SgFile *file, const map &commonBlocks, vector &messagesForFile, const set& allFileNames, map, set>& usersDirectives) { @@ -2084,6 +2148,10 @@ bool preprocess_spf_dirs(SgFile *file, const map &commonBl findModulesInFile(file, modules); bool result = processModules(modules, currFile, &commonBlocks, messagesForFile, allFileNames, usersDirectives); noError = noError && result; + + if (noError) + distributeAnalysisWithCover(file); + return noError; } @@ -2184,7 +2252,7 @@ vector filterUserSpf(const vector &toFilter, bool wi { vector ret; for (auto &elem : toFilter) - if (elem->localLineNumber() == 777 || (elem->localLineNumber() == 888 && with_omp)) // user and omp + if (elem->localLineNumber() == SPF_USER_DIR || (elem->localLineNumber() == SPF_OMP_DIR && with_omp)) // user and omp ret.push_back(elem); return ret; diff --git a/sapfor/experts/Sapfor_2017/_src/Transformations/loops_splitter.cpp b/sapfor/experts/Sapfor_2017/_src/Transformations/loops_splitter.cpp index 071999f..65f7eca 100644 --- a/sapfor/experts/Sapfor_2017/_src/Transformations/loops_splitter.cpp +++ b/sapfor/experts/Sapfor_2017/_src/Transformations/loops_splitter.cpp @@ -9,6 +9,7 @@ #include "../CFGraph/CFGraph.h" #include "../SageAnalysisTool/OmegaForSage/include/lang-interf.h" #include "../DirectiveProcessing/directive_parser.h" +#include "../DirectiveProcessing/directive_omp_parser.h" using std::string; using std::vector; @@ -766,7 +767,7 @@ static void filterSpfAttributes(SgStatement* stat) if (attr->getAttributeType() == SPF_ANALYSIS_DIR) { SgStatement* data = (SgStatement*)attr->getAttributeData(); - if (data->localLineNumber() != 777) + if (data->localLineNumber() != SPF_USER_DIR) continue; //__spf_print(1, "%s", data->unparse()); diff --git a/sapfor/experts/Sapfor_2017/_src/Utils/version.h b/sapfor/experts/Sapfor_2017/_src/Utils/version.h index 573c892..9492715 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 "2315" +#define VERSION_SPF "2316"