diff --git a/CMakeLists.txt b/CMakeLists.txt index 724026f..02022ef 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -163,10 +163,9 @@ set(PARALLEL_REG src/ParallelizationRegions/ParRegions.cpp src/ParallelizationRegions/resolve_par_reg_conflicts.cpp src/ParallelizationRegions/resolve_par_reg_conflicts.h src/ParallelizationRegions/uniq_name_creator.cpp - src/ParallelizationRegions/uniq_name_creator.h) - -set(MERGE_REGIONS src/ParallelizationRegions/merge_regions.cpp - src/ParallelizationRegions/merge_regions.h) + src/ParallelizationRegions/uniq_name_creator.h + src/ParallelizationRegions/merge_regions.h + src/ParallelizationRegions/merge_regions.cpp) set(TR_DEAD_CODE src/Transformations/DeadCodeRemoving/dead_code.cpp src/Transformations/DeadCodeRemoving/dead_code.h) @@ -430,7 +429,6 @@ set(SOURCE_EXE ${LOOP_ANALYZER} ${TRANSFORMS} ${PARALLEL_REG} - ${MERGE_REGIONS} ${PRIV} ${FDVM} ${OMEGA} @@ -484,7 +482,6 @@ source_group (GraphCall FILES ${GR_CALL}) source_group (GraphLoop FILES ${GR_LOOP}) source_group (LoopAnalyzer FILES ${LOOP_ANALYZER}) source_group (ParallelizationRegions FILES ${PARALLEL_REG}) -source_group (MergeRegions FILES ${MERGE_REGIONS}) source_group (PrivateAnalyzer FILES ${PRIV}) source_group (FDVM_Compiler FILES ${FDVM}) source_group (SageExtension FILES ${OMEGA}) diff --git a/src/DirectiveProcessing/directive_parser.cpp b/src/DirectiveProcessing/directive_parser.cpp index e653f26..5af0f02 100644 --- a/src/DirectiveProcessing/directive_parser.cpp +++ b/src/DirectiveProcessing/directive_parser.cpp @@ -2,7 +2,6 @@ #include #include -#include #include #include #include @@ -584,6 +583,37 @@ void fillCheckpointFromComment(Statement *stIn, map &clauses, template void fillCheckpointFromComment(Statement *stIn, map &clauses, set &vars, set &expt); template void fillCheckpointFromComment(Statement *stIn, map &clauses, set &vars, set &expt); +template +void fillMergeArraysFromComment(Statement* stIn, pair& toReplace) +{ + if (stIn) + { + SgStatement* st = stIn->GetOriginal(); + if (st->variant() == SPF_TRANSFORM_DIR) + { + SgExpression* exprList = st->expr(0); + while (exprList) + { + const int var = exprList->lhs()->variant(); + if (var == SPF_MERGE_ARRAYS_OP) + { + if (!exprList->lhs()->lhs() || !exprList->lhs()->rhs()) + printInternalError(convertFileName(__FILE__).c_str(), __LINE__); + + fillType *dummy = NULL; + toReplace = std::make_pair(getData(exprList->lhs()->lhs(), dummy), + getData(exprList->lhs()->rhs(), dummy)); + break; + } + exprList = exprList->rhs(); + } + } + } +} + +template void fillMergeArraysFromComment(Statement* st, pair& toReplace); +template void fillMergeArraysFromComment(Statement* st, pair& toReplace); + void fillInfoFromDirectives(const LoopGraph *loopInfo, ParallelDirective *directive) { SgForStmt *currentLoop = (SgForStmt*)loopInfo->loop; diff --git a/src/DirectiveProcessing/directive_parser.h b/src/DirectiveProcessing/directive_parser.h index f632940..3e5d954 100644 --- a/src/DirectiveProcessing/directive_parser.h +++ b/src/DirectiveProcessing/directive_parser.h @@ -52,4 +52,7 @@ void fillShrinkFromComment(Statement *stIn, std::vector void fillCheckpointFromComment(Statement *stIn, std::map &clauses, std::set &vars, std::set &expt); +template +void fillMergeArraysFromComment(Statement* stIn, std::pair& toReplace); + int getCoverPropertyFromComment(Statement* stIn); diff --git a/src/DirectiveProcessing/spf_directive_preproc.cpp b/src/DirectiveProcessing/spf_directive_preproc.cpp index 48bb8ad..191fd8f 100644 --- a/src/DirectiveProcessing/spf_directive_preproc.cpp +++ b/src/DirectiveProcessing/spf_directive_preproc.cpp @@ -186,12 +186,13 @@ static bool checkCover(SgStatement* st, return retVal; } -static bool checkProcessPrivate(SgStatement* st, - SgStatement* attributeStatement, - const set& privates, - vector& messagesForFile) +static bool checkDeclaration(SgStatement* st, + SgStatement* attributeStatement, + const set& variables, + vector& messagesForFile) { // PROCESS_PRIVATE(VAR) + // MERGE_ARRAYS(ARR1, ARR2) const int var = st->variant(); bool retVal = true; @@ -203,12 +204,12 @@ static bool checkProcessPrivate(SgStatement* st, set varDef, varUse; fillVarsSets(iterator, end, varDef, varUse); - for (auto& privElemS : privates) + for (auto& var : variables) { - const string privElem = privElemS->GetOriginal()->identifier(); + const string varElem = var->GetOriginal()->identifier(); bool defCond = true; - if (varDef.find(privElem) == varDef.end()) + if (varDef.find(varElem) == varDef.end()) defCond = false; if (!defCond) @@ -1784,7 +1785,7 @@ static inline bool processStat(SgStatement *st, const string &currFile, fillPrivatesFromComment(new Statement(attributeStatement), privates, SPF_PROCESS_PRIVATE_OP); if (privates.size()) { - bool result = checkProcessPrivate(st, attributeStatement, privates, messagesForFile); + bool result = checkDeclaration(st, attributeStatement, privates, messagesForFile); retVal = retVal && result; } @@ -1938,11 +1939,20 @@ static inline bool processStat(SgStatement *st, const string &currFile, if (isSPF_OP(attributeStatement, SPF_MERGE_ARRAYS_OP)) { attributeStatement->setLocalLineNumber(-1); - /*if (st->variant() != FOR_NODE) + if (!isSgDeclarationStatement(st)) { - BAD_POSITION_FULL(ERROR, "", "", "before", RR1_1, "DO statement", RR1_3, attributeStatement->lineNumber()); + BAD_POSITION_FULL(ERROR, "", "", "before", RR1_1, "declataion statement", RR1_9, attributeStatement->lineNumber()); retVal = false; - }*/ + } + else + { + pair toReplacePair; + fillMergeArraysFromComment(new Statement(attributeStatement), toReplacePair); + + set toCheckDecl = { toReplacePair.first }; + bool result = checkDeclaration(st, attributeStatement, toCheckDecl, messagesForFile); + retVal = retVal && result; + } } } else if (type == SPF_CHECKPOINT_DIR) diff --git a/src/ParallelizationRegions/merge_regions.cpp b/src/ParallelizationRegions/merge_regions.cpp index 4c68fb2..ed3a5dc 100644 --- a/src/ParallelizationRegions/merge_regions.cpp +++ b/src/ParallelizationRegions/merge_regions.cpp @@ -3,6 +3,7 @@ #include #include #include "merge_regions.h" +#include "../DirectiveProcessing/directive_parser.h" using std::map; using std::set; @@ -10,46 +11,6 @@ using std::pair; using std::string; using std::vector; -//TODO: need to create new clause!! -static void parseMergeDirective(const char *comment, - vector> &parsed_mapping) -{ - while (comment) - { - auto *line_end = strchr(comment, '\n'); - - static const char prefix[] = "!!spf transform(merge_arrays("; - static const auto compare_chars = sizeof(prefix) - 1; - - if (strlen(comment) >= compare_chars) - { - std::string comment_cmp(comment, compare_chars); - convertToLower(comment_cmp); - - if (comment_cmp == prefix) - { - auto* pair_start = comment + compare_chars; - auto* comma = strchr(pair_start, ','); - if (comma) - { - auto* close_br = strchr(comma + 1, ')'); - if (close_br) - { - parsed_mapping.emplace_back( - string(pair_start, comma - pair_start), - string(comma + 1, close_br - comma - 1)); - } - } - } - } - - comment = line_end; - - if (comment) - comment++; - } -} - static string getNonDefaultRegion(DIST::Array *a) { string result; @@ -217,7 +178,7 @@ static SgExpression* findExprWithVariant(SgExpression* exp, int variant) return NULL; } -SgType* GetArrayType(DIST::Array *array) +static SgType* GetArrayType(DIST::Array *array) { if (!array) return NULL; @@ -242,11 +203,11 @@ SgType* GetArrayType(DIST::Array *array) return NULL; } -SgSymbol *insertDeclIfNeeded(const string &array_name, - const string &common_block_name, - DIST::Array *example_array, - FuncInfo *dest, - map> &inserted_arrays) +static SgSymbol *insertDeclIfNeeded(const string &array_name, + const string &common_block_name, + DIST::Array *example_array, + FuncInfo *dest, + map> &inserted_arrays) { auto *type = GetArrayType(example_array); @@ -462,17 +423,20 @@ void mergeRegions(vector ®ions, const maplexNext()) { - if (curr_stmt->comments()) + auto attributes = getAttributes(curr_stmt, set{SPF_TRANSFORM_DIR}); + + for (auto& attr : attributes) { - vector> parsed_mapping; - parseMergeDirective(curr_stmt->comments(), parsed_mapping); + pair parsed_mapping = { "", "" }; + const auto empty = parsed_mapping; + fillMergeArraysFromComment(new Statement(attr), parsed_mapping); - for (const auto &p : parsed_mapping) + if (parsed_mapping != empty) { - auto *found_array = getArrayFromDeclarated(curr_stmt, p.first); + auto* found_array = getArrayFromDeclarated(curr_stmt, parsed_mapping.first); if (found_array) { - arrays_to_merge[p.second].insert(found_array); + arrays_to_merge[parsed_mapping.second].insert(found_array); array_alignment[found_array] = {}; } } diff --git a/src/Transformations/ArrayConstantPropagation/propagation.cpp b/src/Transformations/ArrayConstantPropagation/propagation.cpp index 81c48cc..0b87937 100644 --- a/src/Transformations/ArrayConstantPropagation/propagation.cpp +++ b/src/Transformations/ArrayConstantPropagation/propagation.cpp @@ -521,7 +521,7 @@ static void processLoopBound(SgStatement* st, getBorderVars(exp, st->fileName(), borderVars); - if (containsArrayRefRecursive(exp), borderVars, st->fileName()) + if (containsArrayRefRecursive(exp)) { copyStatement(st); @@ -575,7 +575,6 @@ void arrayConstantPropagation(SgProject& project) processLoopBound(st, st->expr(0), upperBoundUnparsed, true, arrayToVariable, borderVars); processLoopBound(st, st->expr(0), lowerBoundUnparsed, false, arrayToVariable, borderVars); - } } } @@ -601,9 +600,7 @@ void arrayConstantPropagation(SgProject& project) { SgFile::switchToFile(fileName); for (SgStatement* st : statements) - { insertCommonAndDeclsForFunction(st, variablesToAdd); - } } map>>> result; diff --git a/src/Utils/errors.h b/src/Utils/errors.h index 274e779..7d8abe5 100644 --- a/src/Utils/errors.h +++ b/src/Utils/errors.h @@ -322,6 +322,7 @@ static const wchar_t *RR1_5 = L"RR1_5:"; static const wchar_t *RR1_6 = L"RR1_6:"; static const wchar_t *RR1_7 = L"RR1_7:"; static const wchar_t *RR1_8 = L"RR1_8:"; +static const wchar_t *RR1_9 = L"RR1_9:"; static const wchar_t *R2 = L"R2:"; static const wchar_t *R3 = L"R3:"; diff --git a/src/Utils/version.h b/src/Utils/version.h index 24f80ed..f83fd22 100644 --- a/src/Utils/version.h +++ b/src/Utils/version.h @@ -1,3 +1,3 @@ #pragma once -#define VERSION_SPF "2485" +#define VERSION_SPF "2486"