Compare commits
46 Commits
968491ee29
...
595d588726
| Author | SHA1 | Date | |
|---|---|---|---|
| 595d588726 | |||
|
|
b65437a75c | ||
|
|
1840fb7d45 | ||
|
|
d0fa88eea2 | ||
| d589a372a0 | |||
|
|
2d7fea1d7c | ||
| 9812ced8ca | |||
| b9a488c7ea | |||
| e32bdb0e07 | |||
| 1713c26547 | |||
| 66feb15714 | |||
|
|
09d0195693 | ||
| d1022f2a88 | |||
|
|
1326c5e09d | ||
| 5c83e36a62 | |||
| ebca0b4c41 | |||
| 83f4e1289c | |||
|
|
8a689b5ee3 | ||
|
|
947747962d | ||
|
|
763be1857a | ||
|
|
2d0104561e | ||
| 330b5dd653 | |||
|
|
277a1f8bef | ||
|
|
4ae313e93f | ||
|
|
bdb74c8ae7 | ||
|
|
24fe7b4bad | ||
|
|
c5866f2cf9 | ||
|
|
f345741acc | ||
|
|
d27b9d1ed3 | ||
| 35dc430243 | |||
| b80c941fec | |||
|
|
0f39f6474d | ||
|
|
093abbbd55 | ||
| c6bc19640b | |||
| fbcddeea8f | |||
| 34bc8b0219 | |||
| c00f8d6977 | |||
| f145afceef | |||
| 76d173d554 | |||
| 24f8ead2b0 | |||
| cf2bed5c9c | |||
| 02de4e83ff | |||
| a5c31c60a7 | |||
| 04f8f985c0 | |||
| 3456226e66 | |||
| a882be75e9 |
@@ -25,6 +25,7 @@ extern "C" void exit(int status);
|
||||
|
||||
#include "extcxx_low.h"
|
||||
extern "C" int number_of_ll_node;
|
||||
extern "C" PTR_SYMB last_file_symbol;
|
||||
|
||||
#undef USER
|
||||
|
||||
@@ -1641,9 +1642,11 @@ SgFile &SgProject::file(int i)
|
||||
|
||||
current_file_id = i;
|
||||
current_file = pt;
|
||||
|
||||
#ifdef __SPF
|
||||
SgStatement::setCurrProcessFile(pt->filename());
|
||||
SgStatement::setCurrProcessLine(0);
|
||||
last_file_symbol = file->cur_symb;
|
||||
#endif
|
||||
return *pt;
|
||||
}
|
||||
@@ -1774,6 +1777,7 @@ int SgFile::switchToFile(const std::string &name)
|
||||
|
||||
SgStatement::setCurrProcessFile(file->filename());
|
||||
SgStatement::setCurrProcessLine(0);
|
||||
last_file_symbol = current_file->filept->cur_symb;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -83,12 +83,6 @@ int out_upper_case;
|
||||
int out_line_unlimit;
|
||||
int out_line_length; // out_line_length = 132 for -ffo mode; out_line_length = 72 for -uniForm mode
|
||||
PTR_SYMB last_file_symbol;
|
||||
struct file_symbol {
|
||||
char *fname;
|
||||
PTR_SYMB last_symb;
|
||||
struct file_symbol *next;
|
||||
} ;
|
||||
struct file_symbol *file_last_symbol = NULL;
|
||||
|
||||
static int CountNullBifNext = 0; /* for internal debugging */
|
||||
|
||||
@@ -253,24 +247,6 @@ char* mymalloc(int size)
|
||||
return pt1;
|
||||
}
|
||||
|
||||
PTR_SYMB FileLastSymbol(char *file_name)
|
||||
{
|
||||
struct file_symbol *fsl;
|
||||
for(fsl=file_last_symbol; fsl; fsl=fsl->next)
|
||||
if(!strcmp(file_name, fsl->fname))
|
||||
return fsl->last_symb;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void addFileSymbolList(char *file_name, PTR_SYMB symb)
|
||||
{
|
||||
struct file_symbol *fsl;
|
||||
fsl = (struct file_symbol *) xmalloc(sizeof (struct file_symbol));
|
||||
fsl->last_symb = symb;
|
||||
fsl->fname = file_name;
|
||||
fsl->next = file_last_symbol;
|
||||
file_last_symbol = fsl;
|
||||
}
|
||||
/***************** Provides infos on nodes ********************************
|
||||
* *
|
||||
* based on the table info in include dir *.def *
|
||||
@@ -1228,7 +1204,6 @@ int Init_Tool_Box()
|
||||
number_of_ll_node = CUR_FILE_NUM_LLNDS() + 1;
|
||||
number_of_bif_node = CUR_FILE_NUM_BIFS() + 1;
|
||||
number_of_symb_node = CUR_FILE_NUM_SYMBS() + 1;
|
||||
addFileSymbolList(CUR_FILE_NAME(), CUR_FILE_CUR_SYMB()); /* podd 01.03.24 */
|
||||
if (CUR_FILE_NAME()) strcpy(Current_File_name, CUR_FILE_NAME());
|
||||
if (ToolBOX_INIT)
|
||||
return 0;
|
||||
|
||||
@@ -82,7 +82,6 @@ extern "C" int out_upper_case;
|
||||
extern "C" int out_line_unlimit;
|
||||
extern "C" int out_line_length;
|
||||
extern "C" PTR_SYMB last_file_symbol;
|
||||
extern "C" PTR_SYMB FileLastSymbol(...);
|
||||
|
||||
Options options;
|
||||
|
||||
@@ -418,7 +417,7 @@ int main(int argc, char *argv[])
|
||||
fout_name_info_C = ChangeFto_info_C(fout_name); /*ACC*/
|
||||
|
||||
//set the last symbol of file
|
||||
last_file_symbol = FileLastSymbol(file->filename()); //for low_level.c and not only
|
||||
last_file_symbol = file->filept->cur_symb; //for low_level.c and not only
|
||||
initLibNames(); //for every file
|
||||
InitDVM(file); //for every file
|
||||
current_file = file; // global variable (used in SgTypeComplex)
|
||||
|
||||
@@ -191,6 +191,8 @@ set(TR_GV _src/Transformations/fix_common_blocks.cpp
|
||||
_src/Transformations/fix_common_blocks.h)
|
||||
set(TR_CONV _src/Transformations/convert_to_c.cpp
|
||||
_src/Transformations/convert_to_c.h)
|
||||
set(TR_IMPLICIT_NONE _src/Transformations/set_implicit_none.cpp
|
||||
_src/Transformations/set_implicit_none.h)
|
||||
|
||||
set(TRANSFORMS
|
||||
${TR_DEAD_CODE}
|
||||
@@ -207,7 +209,9 @@ set(TRANSFORMS
|
||||
${TR_LOOP_UNROLL}
|
||||
${TR_GV}
|
||||
${TR_PRIV_DEL}
|
||||
${TR_CONV})
|
||||
${TR_CONV}
|
||||
${TR_PRIV_DEL}
|
||||
${TR_IMPLICIT_NONE})
|
||||
|
||||
set(CFG _src/CFGraph/IR.cpp
|
||||
_src/CFGraph/IR.h
|
||||
@@ -231,16 +235,17 @@ set(DATA_FLOW
|
||||
set(CREATE_INTER_T _src/CreateInterTree/CreateInterTree.cpp
|
||||
_src/CreateInterTree/CreateInterTree.h)
|
||||
|
||||
set(DIRA _src/DirectiveProcessing/DirectiveAnalyzer.cpp
|
||||
_src/DirectiveProcessing/DirectiveAnalyzer.h
|
||||
set(DIRA _src/DirectiveProcessing/directive_analyzer.cpp
|
||||
_src/DirectiveProcessing/directive_analyzer.h
|
||||
_src/DirectiveProcessing/directive_creator.cpp
|
||||
_src/DirectiveProcessing/directive_creator_base.cpp
|
||||
_src/DirectiveProcessing/directive_creator.h
|
||||
_src/DirectiveProcessing/directive_creator_base_nodist.cpp
|
||||
_src/DirectiveProcessing/directive_creator_nodist.h
|
||||
_src/DirectiveProcessing/directive_creator_internal.h
|
||||
_src/DirectiveProcessing/directive_parser.cpp
|
||||
_src/DirectiveProcessing/directive_parser.h
|
||||
_src/DirectiveProcessing/directive_omp_parser.cpp
|
||||
_src/DirectiveProcessing/directive_omp_parser.h
|
||||
_src/DirectiveProcessing/insert_directive.cpp
|
||||
_src/DirectiveProcessing/insert_directive.h
|
||||
_src/DirectiveProcessing/remote_access.cpp
|
||||
@@ -448,6 +453,7 @@ source_group (Transformations\\VectorAssignToLoop FILES ${TR_VECTOR})
|
||||
source_group (Transformations\\RenameSymbols FILES ${RENAME_SYMBOLS})
|
||||
source_group (Transformations\\GlobalVariables FILES ${TR_GV})
|
||||
source_group (Transformations\\ConvertToC FILES ${TR_CONV})
|
||||
source_group (Transformations\\SetImplicitNone FILES ${TR_IMPLICIT_NONE})
|
||||
|
||||
|
||||
source_group (CreateIntervals FILES ${CREATE_INTER_T})
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
#include "../Distribution/DvmhDirective.h"
|
||||
#include "../GraphLoop/graph_loops.h"
|
||||
#include "DirectiveAnalyzer.h"
|
||||
#include "directive_analyzer.h"
|
||||
#include "../Utils/utils.h"
|
||||
|
||||
using std::vector;
|
||||
@@ -45,6 +45,8 @@ using std::get;
|
||||
using std::string;
|
||||
using std::wstring;
|
||||
|
||||
extern int mpiProgram;
|
||||
|
||||
static vector<pair<string, vector<Expression*>>>
|
||||
groupRealignsDirs(const vector<pair<string, vector<Expression*>>>& toRealign)
|
||||
{
|
||||
@@ -423,6 +425,66 @@ bool analyzeLoopBody(LoopGraph* loopV,
|
||||
return true;
|
||||
}
|
||||
|
||||
void createParallelDirs(File *file,
|
||||
map<string, vector<Directive*>>& createdDirectives,
|
||||
vector<Messages>& messages,
|
||||
const vector<LoopGraph*>& loopsInFile,
|
||||
const map<string, vector<FuncInfo*>>& allFuncInfo,
|
||||
const vector<ParallelRegion*>& parallelRegions,
|
||||
const map<LoopGraph*, void*>& depInfoForLoopGraph,
|
||||
const map<DIST::Array*, set<DIST::Array*>>& arrayLinksByFuncCalls)
|
||||
{
|
||||
const string file_name = file->filename();
|
||||
map<int, LoopGraph*> mapLoopsInFile;
|
||||
createMapLoopGraph(loopsInFile, mapLoopsInFile);
|
||||
|
||||
map<string, FuncInfo*> mapFuncInfo;
|
||||
createMapOfFunc(allFuncInfo, mapFuncInfo);
|
||||
|
||||
for (int z = 0; z < parallelRegions.size(); ++z)
|
||||
{
|
||||
vector<Directive*> toInsert;
|
||||
|
||||
const DataDirective& dataDirectives = parallelRegions[z]->GetDataDir();
|
||||
const vector<int>& currentVariant = parallelRegions[z]->GetCurrentVariant();
|
||||
DIST::GraphCSR<int, double, attrType>& reducedG = parallelRegions[z]->GetReducedGraphToModify();
|
||||
DIST::Arrays<int>& allArrays = parallelRegions[z]->GetAllArraysToModify();
|
||||
|
||||
auto& tmp = dataDirectives.distrRules;
|
||||
vector<pair<DIST::Array*, const DistrVariant*>> currentVar;
|
||||
|
||||
if (mpiProgram == 0)
|
||||
{
|
||||
for (int z1 = 0; z1 < currentVariant.size(); ++z1)
|
||||
currentVar.push_back(make_pair(tmp[z1].first, &tmp[z1].second[currentVariant[z1]]));
|
||||
}
|
||||
else
|
||||
{
|
||||
for (auto& loop : mapLoopsInFile)
|
||||
{
|
||||
auto& rules = loop.second->getDataDir().distrRules;
|
||||
for (auto& rule : rules)
|
||||
currentVar.push_back(make_pair(rule.first, &rule.second[0]));
|
||||
}
|
||||
}
|
||||
|
||||
selectParallelDirectiveForVariant(file, parallelRegions[z], reducedG, allArrays, loopsInFile,
|
||||
mapLoopsInFile, mapFuncInfo, currentVar,
|
||||
toInsert, parallelRegions[z]->GetId(), arrayLinksByFuncCalls,
|
||||
depInfoForLoopGraph, messages);
|
||||
|
||||
if (toInsert.size() > 0)
|
||||
{
|
||||
auto it = createdDirectives.find(file_name);
|
||||
if (it == createdDirectives.end())
|
||||
createdDirectives.insert(it, make_pair(file_name, toInsert));
|
||||
else
|
||||
for (int m = 0; m < toInsert.size(); ++m)
|
||||
it->second.push_back(toInsert[m]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#undef PRINT_DIR_RESULT
|
||||
#undef FIRST
|
||||
#undef SECOND
|
||||
|
||||
@@ -44,3 +44,20 @@ DIST::Array* getRealArrayRef(DIST::Array* in, const uint64_t regId, const std::m
|
||||
void shiftAlignRulesForTemplates(const std::set<DIST::Array*>& arrays, const uint64_t regId, DataDirective& dataDirectives, const std::map<DIST::Array*, std::set<DIST::Array*>>& arrayLinksByFuncCalls);
|
||||
|
||||
void createShadowSpec(const std::map<std::string, std::vector<LoopGraph*>>& loopGraph, const std::map<DIST::Array*, std::set<DIST::Array*>>& arrayLinksByFuncCalls, const std::set<DIST::Array*>& forArrays);
|
||||
|
||||
void addShadowFromAnalysis(ParallelDirective* dir, const std::map<DIST::Array*, ArrayInfo*>& currAccesses);
|
||||
|
||||
bool checkForConflict(const std::map<DIST::Array*, ArrayInfo*>& currAccesses,
|
||||
const LoopGraph* currentLoop,
|
||||
std::map<DIST::Array*, std::pair<int, std::pair<int, int>>, DIST::ArrayComparator>& arrayWriteAcc,
|
||||
const std::vector<std::pair<std::pair<std::string, std::string>, std::vector<std::pair<int, int>>>>& acrossInfo,
|
||||
std::set<DIST::Array*>& acrossOutArrays);
|
||||
|
||||
void createParallelDirs(File* file,
|
||||
std::map<std::string, std::vector<Directive*>>& createdDirectives,
|
||||
std::vector<Messages>& messages,
|
||||
const std::vector<LoopGraph*>& loopsInFile,
|
||||
const std::map<std::string, std::vector<FuncInfo*>>& allFuncInfo,
|
||||
const std::vector<ParallelRegion*>& parallelRegions,
|
||||
const std::map<LoopGraph*, void*>& depInfoForLoopGraph,
|
||||
const std::map<DIST::Array*, std::set<DIST::Array*>>& arrayLinksByFuncCalls);
|
||||
@@ -15,7 +15,6 @@
|
||||
#include "../Utils/errors.h"
|
||||
#include "directive_parser.h"
|
||||
#include "directive_creator.h"
|
||||
#include "directive_creator_internal.h"
|
||||
|
||||
#define PRINT_PROF_INFO 1
|
||||
#define PRINT_DIR_RESULT 0
|
||||
@@ -1092,6 +1091,9 @@ static bool tryToResolveUnmatchedDims(const map<DIST::Array*, vector<bool>> &dim
|
||||
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
||||
}
|
||||
|
||||
set<string> privates;
|
||||
|
||||
#if __SPF
|
||||
tmpL = loop->parent;
|
||||
while (tmpL)
|
||||
{
|
||||
@@ -1110,11 +1112,9 @@ static bool tryToResolveUnmatchedDims(const map<DIST::Array*, vector<bool>> &dim
|
||||
tmpL = tmpL->parent;
|
||||
}
|
||||
|
||||
set<string> privates;
|
||||
#if __SPF
|
||||
tryToFindPrivateInAttributes(loop->loop->GetOriginal(), privates);
|
||||
#else
|
||||
#error 'TODO - fill privates for this loop'
|
||||
#error 'TODO - fill privates for this loop and check all inductive variables'
|
||||
#endif
|
||||
|
||||
//try to resolve from write operations
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
#include "../Utils/errors.h"
|
||||
#include "directive_parser.h"
|
||||
#include "directive_creator.h"
|
||||
#include "directive_creator_internal.h"
|
||||
#include "directive_creator_nodist.h"
|
||||
|
||||
#define PRINT_PROF_INFO 1
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <string>
|
||||
|
||||
#include "../Distribution/Distribution.h"
|
||||
#include "../Utils/errors.h"
|
||||
#include "../GraphLoop/graph_loops.h"
|
||||
#include "../Utils/types.h"
|
||||
|
||||
#define FIRST(x) get<0>(x)
|
||||
#define SECOND(x) get<1>(x)
|
||||
#define THIRD(x) get<2>(x)
|
||||
|
||||
void addShadowFromAnalysis(ParallelDirective* dir, const std::map<DIST::Array*, ArrayInfo*>& currAccesses);
|
||||
|
||||
bool checkForConflict(const std::map<DIST::Array*, ArrayInfo*>& currAccesses,
|
||||
const LoopGraph* currentLoop,
|
||||
std::map<DIST::Array*, std::pair<int, std::pair<int, int>>, DIST::ArrayComparator>& arrayWriteAcc,
|
||||
const std::vector<std::pair<std::pair<std::string, std::string>, std::vector<std::pair<int, int>>>>& acrossInfo,
|
||||
std::set<DIST::Array*>& acrossOutArrays);
|
||||
@@ -0,0 +1,524 @@
|
||||
#include "../Utils/leak_detector.h"
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <cstdint>
|
||||
|
||||
#include "dvm.h"
|
||||
#include "directive_omp_parser.h"
|
||||
#include "directive_parser.h"
|
||||
|
||||
#include "../Utils/SgUtils.h"
|
||||
|
||||
using std::vector;
|
||||
using std::map;
|
||||
using std::set;
|
||||
using std::string;
|
||||
|
||||
|
||||
void removeOmpDir(SgStatement* st)
|
||||
{
|
||||
char* lineS = st->comments();
|
||||
if (!lineS)
|
||||
return;
|
||||
|
||||
vector<string> split;
|
||||
splitString(lineS, '\n', split);
|
||||
|
||||
int idx = 0;
|
||||
for (auto& elem : split)
|
||||
{
|
||||
string line = elem;
|
||||
convertToLower(line);
|
||||
if (line.substr(0, 5) == "!$omp")
|
||||
lineS[idx + 1] = '_';
|
||||
else if (line.substr(0, 3) == "!$ ")
|
||||
lineS[idx + 1] = '_';
|
||||
idx += line.size() + 1; // with '\n'
|
||||
}
|
||||
}
|
||||
|
||||
static inline void addToAttribute(SgStatement* st, int var, vector<SgExpression*> list)
|
||||
{
|
||||
if (list.size())
|
||||
{
|
||||
SgExprListExp* ex = new SgExprListExp();
|
||||
ex->setLhs(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);
|
||||
|
||||
//filter
|
||||
if (var == ACC_PRIVATE_OP)
|
||||
{
|
||||
vector<SgExpression*> list_new;
|
||||
|
||||
auto attributes = getAttributes<SgStatement*, SgStatement*>(st, set<int>{SPF_ANALYSIS_DIR});
|
||||
set<string> privates;
|
||||
for (auto& attr : attributes)
|
||||
fillPrivatesFromComment(new Statement(attr), privates);
|
||||
|
||||
if (privates.size())
|
||||
{
|
||||
for (auto& elem : list)
|
||||
if (privates.find(elem->unparse()) == privates.end())
|
||||
list_new.push_back(elem);
|
||||
list = list_new;
|
||||
|
||||
if (!list.size())
|
||||
{
|
||||
__spf_print(1, "-- skip privates on line %d from OMP dir\n%s", st->lineNumber(), toAdd->unparse());
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (var == REDUCTION_OP)
|
||||
{
|
||||
auto attributes = getAttributes<SgStatement*, SgStatement*>(st, set<int>{SPF_ANALYSIS_DIR});
|
||||
map<string, set<string>> reduction;
|
||||
for (auto& attr : attributes)
|
||||
fillReductionsFromComment(new Statement(attr), reduction);
|
||||
|
||||
map<string, set<string>> reductionToAdd;
|
||||
fillReductionsFromComment(new Statement(toAdd), reductionToAdd);
|
||||
|
||||
vector<SgExpression*> list_new;
|
||||
if (reduction.size())
|
||||
{
|
||||
if (reduction == reductionToAdd)
|
||||
{
|
||||
__spf_print(1, "-- skip reduction on line %d from OMP dir\n%s", st->lineNumber(), toAdd->unparse());
|
||||
return;
|
||||
}
|
||||
|
||||
map<string, set<string>> reductionToAddNew;
|
||||
for (auto& redPair : reductionToAdd)
|
||||
{
|
||||
auto it = reduction.find(redPair.first);
|
||||
if (it == reduction.end())
|
||||
reductionToAddNew[redPair.first] = redPair.second;
|
||||
else
|
||||
{
|
||||
set<string> newVar;
|
||||
for (auto& var : redPair.second)
|
||||
{
|
||||
auto itVar = it->second.find(var);
|
||||
if (itVar == it->second.end())
|
||||
reductionToAddNew[redPair.first].insert(var);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!reductionToAddNew.size())
|
||||
{
|
||||
__spf_print(1, "-- skip reduction on line %d from OMP dir\n%s", st->lineNumber(), toAdd->unparse());
|
||||
return;
|
||||
}
|
||||
|
||||
if (reductionToAddNew != reductionToAdd)
|
||||
{
|
||||
list.clear();
|
||||
for (auto& redPair : reductionToAddNew)
|
||||
for (auto& var : redPair.second)
|
||||
list.push_back(new SgExpression(ARRAY_OP,
|
||||
new SgKeywordValExp(redPair.first.c_str()),
|
||||
new SgVarRefExp(findSymbolOrCreate(current_file, var, NULL, getFuncStat(st)))));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ex = new SgExprListExp();
|
||||
ex->setLhs(new SgExpression(var, makeExprList(list), NULL));
|
||||
toAdd = new SgStatement(SPF_ANALYSIS_DIR, NULL, NULL, ex, NULL, NULL);
|
||||
|
||||
st->addAttribute(SPF_ANALYSIS_DIR, toAdd, sizeof(SgStatement));
|
||||
|
||||
if (var == ACC_PRIVATE_OP)
|
||||
__spf_print(1, "-- set private attribute to line %d from OMP dir\n%s", st->lineNumber(), toAdd->unparse());
|
||||
else if (var == REDUCTION_OP)
|
||||
__spf_print(1, "-- set reduction attribute to line %d from OMP dir\n%s", st->lineNumber(), toAdd->unparse());
|
||||
}
|
||||
}
|
||||
|
||||
static bool is_write_in_do(SgStatement* st, const string& var)
|
||||
{
|
||||
checkNull(st, convertFileName(__FILE__).c_str(), __LINE__);
|
||||
|
||||
if (st->variant() != FOR_NODE)
|
||||
return false;
|
||||
|
||||
SgStatement* lastNode = st->lastNodeOfStmt();
|
||||
for (SgStatement* op = st->lexNext(); st != lastNode; st = st->lexNext())
|
||||
{
|
||||
if (st->variant() == ASSIGN_STAT)
|
||||
{
|
||||
SgExpression* ex = st->expr(0);
|
||||
if (ex->variant() == ARRAY_REF || ex->variant() == VAR_REF)
|
||||
if (var == ex->symbol()->identifier())
|
||||
return true;
|
||||
}
|
||||
else if (st->variant() == FOR_NODE)
|
||||
{
|
||||
if (var == isSgForStmt(st)->doName()->identifier())
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
vector<OmpDir> parseOmpInStatement(SgStatement* st, const set<string>& globalPriv, bool forDo)
|
||||
{
|
||||
vector<OmpDir> resultAll;
|
||||
|
||||
const char* lineS = st->comments();
|
||||
if (!lineS)
|
||||
return resultAll;
|
||||
|
||||
string comment(lineS);
|
||||
convertToLower(comment);
|
||||
|
||||
vector<string> split;
|
||||
splitString(comment, '\n', split);
|
||||
|
||||
for (int z = split.size() - 1; z >= 0; z--)
|
||||
{
|
||||
string line = split[z];
|
||||
|
||||
if (line.substr(0, 6) == "!$omp&")
|
||||
{
|
||||
if (z - 1 < 0)
|
||||
break;
|
||||
split[z - 1] += line.substr(6);
|
||||
split[z] = "";
|
||||
}
|
||||
}
|
||||
|
||||
for (auto& line : split)
|
||||
{
|
||||
if (line.substr(0, 5) == "!$omp")
|
||||
{
|
||||
OmpDir result;
|
||||
|
||||
string line1 = "";
|
||||
int space = 0;
|
||||
int brake = 0;
|
||||
for (int z = 0; z < line.size(); ++z)
|
||||
{
|
||||
if (brake < 0)
|
||||
return vector<OmpDir>(); // error
|
||||
|
||||
if (brake == 0)
|
||||
{
|
||||
if (line[z] == ' ')
|
||||
space++;
|
||||
else
|
||||
space = 0;
|
||||
if ((line[z] == ' ' && space <= 1) || line[z] != ' ')
|
||||
line1 += line[z];
|
||||
}
|
||||
else
|
||||
{
|
||||
if (line[z] != ' ')
|
||||
line1 += line[z];
|
||||
}
|
||||
|
||||
if (line[z] == '(')
|
||||
{
|
||||
while (line1.size() > 2 && line1[line1.size() - 2] == ' ')
|
||||
line1 = line1.erase(line1.size() - 2, 1);
|
||||
brake++;
|
||||
space = 0;
|
||||
}
|
||||
else if (line[z] == ')')
|
||||
brake--;
|
||||
}
|
||||
vector<string> lexems;
|
||||
splitString(line1, ' ', lexems);
|
||||
bool doLexem = false;
|
||||
bool end = false;
|
||||
bool parallel = false;
|
||||
bool privat = false;
|
||||
|
||||
for (auto& lexem : lexems)
|
||||
{
|
||||
if (lexem == "do")
|
||||
{
|
||||
doLexem = true;
|
||||
result.keys.insert(lexem);
|
||||
}
|
||||
if (lexem == "end")
|
||||
{
|
||||
end = true;
|
||||
result.keys.insert(lexem);
|
||||
}
|
||||
if (lexem == "parallel")
|
||||
{
|
||||
parallel = true;
|
||||
result.keys.insert(lexem);
|
||||
}
|
||||
if (lexem == "private")
|
||||
{
|
||||
privat = true;
|
||||
result.keys.insert(lexem);
|
||||
}
|
||||
}
|
||||
|
||||
if (privat == false)
|
||||
{
|
||||
if (forDo && doLexem)
|
||||
{
|
||||
vector<SgExpression*> list;
|
||||
for (auto& var : globalPriv)
|
||||
if (is_write_in_do(st, var))
|
||||
list.push_back(new SgVarRefExp(findSymbolOrCreate(current_file, var, NULL, getFuncStat(st))));
|
||||
|
||||
if (list.size())
|
||||
addToAttribute(st, ACC_PRIVATE_OP, list);
|
||||
}
|
||||
}
|
||||
|
||||
for (auto& lexem : lexems)
|
||||
{
|
||||
bool priv = lexem.substr(0, strlen("private(")) == "private(";
|
||||
bool threadpriv = lexem.substr(0, strlen("threadprivate(")) == "threadprivate(";
|
||||
bool red = lexem.substr(0, strlen("reduction(")) == "reduction(";
|
||||
if (priv || threadpriv)
|
||||
{
|
||||
vector<string> sublex;
|
||||
splitString(lexem, '(', sublex);
|
||||
if (sublex.size() == 2 && lexem.back() == ')')
|
||||
{
|
||||
splitString(sublex[1].erase(sublex[1].size() - 1), ',', sublex);
|
||||
|
||||
vector<SgExpression*> list;
|
||||
set<string> uniqList;
|
||||
for (auto& varG : globalPriv)
|
||||
uniqList.insert(varG);
|
||||
|
||||
for (auto& var : sublex)
|
||||
uniqList.insert(var);
|
||||
|
||||
for (auto& var : uniqList)
|
||||
{
|
||||
if (priv)
|
||||
{
|
||||
result.privVars.insert(var);
|
||||
list.push_back(new SgVarRefExp(findSymbolOrCreate(current_file, var, NULL, getFuncStat(st))));
|
||||
}
|
||||
else
|
||||
result.threadPrivVars.insert(var);
|
||||
}
|
||||
|
||||
if (forDo && doLexem && priv)
|
||||
addToAttribute(st, ACC_PRIVATE_OP, list);
|
||||
}
|
||||
}
|
||||
else if (red)
|
||||
{
|
||||
vector<string> sublex;
|
||||
splitString(lexem, '(', sublex);
|
||||
if (sublex.size() == 2 && lexem.back() == ')')
|
||||
{
|
||||
splitString(sublex[1].erase(sublex[1].size() - 1), ':', sublex);
|
||||
|
||||
vector<string> vars;
|
||||
vector<SgExpression*> list;
|
||||
splitString(sublex[1], ',', vars);
|
||||
string op = "";
|
||||
|
||||
if (sublex[0] == "+")
|
||||
op = "sum";
|
||||
else if (sublex[0] == "*")
|
||||
op = "prod";
|
||||
else if (sublex[0] == "max")
|
||||
op = "max";
|
||||
else if (sublex[0] == "min")
|
||||
op = "min";
|
||||
else if (sublex[0] == ".or." || sublex[0] == "or")
|
||||
op = "or";
|
||||
else if (sublex[0] == ".and." || sublex[0] == "and")
|
||||
op = "and";
|
||||
else if (sublex[0] == ".eqv." || sublex[0] == "eqv")
|
||||
op = "eqv";
|
||||
else if (sublex[0] == ".neqv." || sublex[0] == "neqv")
|
||||
op = "neqv";
|
||||
|
||||
if (op != "")
|
||||
{
|
||||
for (auto& var : vars)
|
||||
{
|
||||
result.redVars[sublex[0]].insert(var);
|
||||
list.push_back(new SgExpression(ARRAY_OP, new SgKeywordValExp(op.c_str()), new SgVarRefExp(findSymbolOrCreate(current_file, var, NULL, getFuncStat(st)))));
|
||||
}
|
||||
}
|
||||
|
||||
if (forDo && doLexem && op != "")
|
||||
addToAttribute(st, REDUCTION_OP, list);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
resultAll.push_back(result);
|
||||
}
|
||||
}
|
||||
|
||||
return resultAll;
|
||||
}
|
||||
|
||||
//TODO: need to use IR and RD for checking
|
||||
static void filterPrivates(OmpDir& dir)
|
||||
{
|
||||
if (dir.privVars.size() == 0)
|
||||
return;
|
||||
|
||||
for (auto st = dir.start; st != dir.end; st = st->lexNext())
|
||||
{
|
||||
vector<OmpDir> res;
|
||||
if (st != dir.start)
|
||||
{
|
||||
set<string> dummy;
|
||||
res = parseOmpInStatement(st, dummy);
|
||||
}
|
||||
|
||||
bool hasParallelDo = false;
|
||||
for (auto& dir : res)
|
||||
{
|
||||
if (dir.keys.find("parallel") != dir.keys.end() ||
|
||||
dir.keys.find("do") != dir.keys.end())
|
||||
{
|
||||
hasParallelDo = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (res.size() == 0 || !hasParallelDo)
|
||||
{
|
||||
if (st->variant() == ASSIGN_STAT)
|
||||
{
|
||||
if (st->expr(0))
|
||||
{
|
||||
string ref = st->expr(0)->symbol()->identifier();
|
||||
dir.privVars.erase(ref);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static vector<OmpDir> findAllGlobalParallelRegions(SgStatement* stFunc)
|
||||
{
|
||||
vector<OmpDir> sections;
|
||||
|
||||
SgStatement* lastNode = stFunc->lastNodeOfStmt();
|
||||
for (auto st = stFunc; st != lastNode; 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;
|
||||
|
||||
set<string> dummy;
|
||||
auto res = parseOmpInStatement(st, dummy);
|
||||
|
||||
for (auto& dir : res)
|
||||
{
|
||||
auto end = dir.keys.end();
|
||||
if (dir.keys.find("parallel") != end
|
||||
&& dir.keys.find("do") == end
|
||||
&& dir.keys.find("end") == end)
|
||||
{
|
||||
if (sections.size() && sections.back().end == NULL) // has open parallel region
|
||||
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
||||
sections.push_back(dir);
|
||||
sections.back().start = st;
|
||||
}
|
||||
else if (dir.keys.find("parallel") != end
|
||||
&& dir.keys.find("do") == end
|
||||
&& dir.keys.find("end") != end)
|
||||
{
|
||||
sections.back().end = st;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (auto& dir : sections)
|
||||
filterPrivates(dir);
|
||||
|
||||
return sections;
|
||||
}
|
||||
|
||||
static set<string> getGlobalPrivate(SgStatement* st, const vector<OmpDir>& globalParallelRegions)
|
||||
{
|
||||
set<string> globalPrivates;
|
||||
const int line = st->lineNumber();
|
||||
if (line > 0)
|
||||
{
|
||||
for (auto& reg : globalParallelRegions)
|
||||
{
|
||||
if (reg.start->lineNumber() <= line && line < reg.end->lineNumber())
|
||||
{
|
||||
if (reg.privVars.size())
|
||||
return reg.privVars;
|
||||
else
|
||||
return globalPrivates;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (auto& reg : globalParallelRegions)
|
||||
{
|
||||
for (auto stF = reg.start; stF != reg.end; stF = stF->lexNext())
|
||||
{
|
||||
if (st == stF)
|
||||
{
|
||||
if (reg.privVars.size())
|
||||
return reg.privVars;
|
||||
else
|
||||
return globalPrivates;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return globalPrivates;
|
||||
}
|
||||
|
||||
void parseOmpDirectives(SgFile* file, vector<Messages>& currMessages)
|
||||
{
|
||||
int funcNum = file->numberOfFunctions();
|
||||
|
||||
for (int i = 0; i < funcNum; ++i)
|
||||
{
|
||||
SgStatement* st = file->functions(i);
|
||||
SgStatement* lastNode = st->lastNodeOfStmt();
|
||||
|
||||
vector<OmpDir> globalParallelRegions = findAllGlobalParallelRegions(st);
|
||||
|
||||
while (st != lastNode)
|
||||
{
|
||||
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)
|
||||
{
|
||||
SgForStmt* currSt = (SgForStmt*)st;
|
||||
if (currSt->isEnddoLoop() == 0)
|
||||
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
||||
else
|
||||
parseOmpInStatement(st, getGlobalPrivate(st, globalParallelRegions), true);
|
||||
}
|
||||
st = st->lexNext();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include <set>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
#include "../Utils/errors.h"
|
||||
|
||||
struct OmpDir
|
||||
{
|
||||
std::set<std::string> privVars;
|
||||
std::set<std::string> threadPrivVars;
|
||||
std::map<std::string, std::set<std::string>> redVars;
|
||||
std::set<std::string> keys;
|
||||
|
||||
SgStatement* start = NULL;
|
||||
SgStatement* end = NULL;
|
||||
};
|
||||
|
||||
void removeOmpDir(SgStatement* st);
|
||||
std::vector<OmpDir> parseOmpInStatement(SgStatement* st, const std::set<std::string>& globalPriv, bool forDo = false);
|
||||
void parseOmpDirectives(SgFile* file, std::vector<Messages>& currMessages);
|
||||
@@ -594,350 +594,3 @@ void fillInfoFromDirectives(const LoopGraph *loopInfo, ParallelDirective *direct
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void removeOmpDir(void* stIn)
|
||||
{
|
||||
SgStatement* st = (SgStatement*)stIn;
|
||||
|
||||
char* lineS = st->comments();
|
||||
if (!lineS)
|
||||
return;
|
||||
|
||||
vector<string> split;
|
||||
splitString(lineS, '\n', split);
|
||||
|
||||
int idx = 0;
|
||||
for (auto& elem : split)
|
||||
{
|
||||
string line = elem;
|
||||
convertToLower(line);
|
||||
if (line.substr(0, 5) == "!$omp")
|
||||
lineS[idx + 1] = '_';
|
||||
else if (line.substr(0, 3) == "!$ ")
|
||||
lineS[idx + 1] = '_';
|
||||
idx += line.size() + 1; // with '\n'
|
||||
}
|
||||
}
|
||||
|
||||
static inline void addToAttribute(SgStatement* st, int var, vector<SgExpression*> list)
|
||||
{
|
||||
if (list.size())
|
||||
{
|
||||
SgExprListExp* ex = new SgExprListExp();
|
||||
ex->setLhs(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);
|
||||
|
||||
//filter
|
||||
if (var == ACC_PRIVATE_OP)
|
||||
{
|
||||
vector<SgExpression*> list_new;
|
||||
|
||||
auto attributes = getAttributes<SgStatement*, SgStatement*>(st, set<int>{SPF_ANALYSIS_DIR});
|
||||
set<string> privates;
|
||||
for (auto& attr : attributes)
|
||||
fillPrivatesFromComment(new Statement(attr), privates);
|
||||
|
||||
if (privates.size())
|
||||
{
|
||||
for (auto& elem : list)
|
||||
if (privates.find(elem->unparse()) == privates.end())
|
||||
list_new.push_back(elem);
|
||||
list = list_new;
|
||||
|
||||
if (!list.size())
|
||||
{
|
||||
__spf_print(1, "-- skip privates on line %d from OMP dir\n%s", st->lineNumber(), toAdd->unparse());
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (var == REDUCTION_OP)
|
||||
{
|
||||
auto attributes = getAttributes<SgStatement*, SgStatement*>(st, set<int>{SPF_ANALYSIS_DIR});
|
||||
map<string, set<string>> reduction;
|
||||
for (auto& attr : attributes)
|
||||
fillReductionsFromComment(new Statement(attr), reduction);
|
||||
|
||||
map<string, set<string>> reductionToAdd;
|
||||
fillReductionsFromComment(new Statement(st), reductionToAdd);
|
||||
|
||||
vector<SgExpression*> list_new;
|
||||
if (reduction.size())
|
||||
{
|
||||
if (reduction == reductionToAdd)
|
||||
{
|
||||
__spf_print(1, "-- skip reduction on line %d from OMP dir\n%s", st->lineNumber(), toAdd->unparse());
|
||||
return;
|
||||
}
|
||||
|
||||
map<string, set<string>> reductionToAddNew;
|
||||
for (auto& redPair : reductionToAdd)
|
||||
{
|
||||
auto it = reduction.find(redPair.first);
|
||||
if (it == reduction.end())
|
||||
reductionToAddNew[redPair.first] = redPair.second;
|
||||
else
|
||||
{
|
||||
set<string> newVar;
|
||||
for (auto& var : redPair.second)
|
||||
{
|
||||
auto itVar = it->second.find(var);
|
||||
if (itVar == it->second.end())
|
||||
reductionToAddNew[redPair.first].insert(var);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!reductionToAddNew.size())
|
||||
{
|
||||
__spf_print(1, "-- skip reduction on line %d from OMP dir\n%s", st->lineNumber(), toAdd->unparse());
|
||||
return;
|
||||
}
|
||||
|
||||
if (reductionToAddNew != reductionToAdd)
|
||||
{
|
||||
list.clear();
|
||||
for (auto& redPair : reductionToAddNew)
|
||||
for (auto& var : redPair.second)
|
||||
list.push_back(new SgExpression(ARRAY_OP,
|
||||
new SgKeywordValExp(redPair.first.c_str()),
|
||||
new SgVarRefExp(findSymbolOrCreate(current_file, var, NULL, getFuncStat(st)))));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ex = new SgExprListExp();
|
||||
ex->setLhs(new SgExpression(var, makeExprList(list), NULL));
|
||||
toAdd = new SgStatement(SPF_ANALYSIS_DIR, NULL, NULL, ex, NULL, NULL);
|
||||
|
||||
st->addAttribute(SPF_ANALYSIS_DIR, toAdd, sizeof(SgStatement));
|
||||
|
||||
if (var == ACC_PRIVATE_OP)
|
||||
__spf_print(1, "-- set private attribute to line %d from OMP dir\n%s", st->lineNumber(), toAdd->unparse());
|
||||
else if (var == REDUCTION_OP)
|
||||
__spf_print(1, "-- set reduction attribute to line %d from OMP dir\n%s", st->lineNumber(), toAdd->unparse());
|
||||
}
|
||||
}
|
||||
|
||||
static bool is_private_in_do(SgStatement* st, const string& var)
|
||||
{
|
||||
checkNull(st, convertFileName(__FILE__).c_str(), __LINE__);
|
||||
|
||||
if (st->variant() != FOR_NODE)
|
||||
return false;
|
||||
|
||||
SgStatement* lastNode = st->lastNodeOfStmt();
|
||||
for (SgStatement* op = st->lexNext(); st != lastNode; st = st->lexNext())
|
||||
{
|
||||
if (st->variant() == ASSIGN_STAT)
|
||||
{
|
||||
SgExpression* ex = st->expr(0);
|
||||
if (ex->variant() == ARRAY_REF || ex->variant() == VAR_REF)
|
||||
if (var == ex->symbol()->identifier())
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
vector<OmpDir> parseOmpDirs(void* stIn, const set<string> &globalPriv, bool forDo)
|
||||
{
|
||||
SgStatement* st = (SgStatement*)stIn;
|
||||
vector<OmpDir> resultAll;
|
||||
|
||||
const char* lineS = st->comments();
|
||||
if (!lineS)
|
||||
return resultAll;
|
||||
|
||||
string comment(lineS);
|
||||
convertToLower(comment);
|
||||
|
||||
vector<string> split;
|
||||
splitString(comment, '\n', split);
|
||||
|
||||
for (int z = split.size() - 1; z >= 0; z--)
|
||||
{
|
||||
string line = split[z];
|
||||
|
||||
if (line.substr(0, 6) == "!$omp&")
|
||||
{
|
||||
if (z - 1 < 0)
|
||||
break;
|
||||
split[z - 1] += line.substr(6);
|
||||
split[z] = "";
|
||||
}
|
||||
}
|
||||
|
||||
for (auto& line : split)
|
||||
{
|
||||
if (line.substr(0, 5) == "!$omp")
|
||||
{
|
||||
OmpDir result;
|
||||
|
||||
string line1 = "";
|
||||
int space = 0;
|
||||
int brake = 0;
|
||||
for (int z = 0; z < line.size(); ++z)
|
||||
{
|
||||
if (brake < 0)
|
||||
return vector<OmpDir>(); // error
|
||||
|
||||
if (brake == 0)
|
||||
{
|
||||
if (line[z] == ' ')
|
||||
space++;
|
||||
else
|
||||
space = 0;
|
||||
if ((line[z] == ' ' && space <= 1) || line[z] != ' ')
|
||||
line1 += line[z];
|
||||
}
|
||||
else
|
||||
{
|
||||
if (line[z] != ' ')
|
||||
line1 += line[z];
|
||||
}
|
||||
|
||||
if (line[z] == '(')
|
||||
{
|
||||
while (line1.size() > 2 && line1[line1.size() - 2] == ' ')
|
||||
line1 = line1.erase(line1.size() - 2, 1);
|
||||
brake++;
|
||||
space = 0;
|
||||
}
|
||||
else if (line[z] == ')')
|
||||
brake--;
|
||||
}
|
||||
vector<string> lexems;
|
||||
splitString(line1, ' ', lexems);
|
||||
bool doLexem = false;
|
||||
bool end = false;
|
||||
bool parallel = false;
|
||||
bool privat = false;
|
||||
|
||||
for (auto& lexem : lexems)
|
||||
{
|
||||
if (lexem == "do")
|
||||
{
|
||||
doLexem = true;
|
||||
result.keys.insert(lexem);
|
||||
}
|
||||
if (lexem == "end")
|
||||
{
|
||||
end = true;
|
||||
result.keys.insert(lexem);
|
||||
}
|
||||
if (lexem == "parallel")
|
||||
{
|
||||
parallel = true;
|
||||
result.keys.insert(lexem);
|
||||
}
|
||||
if (lexem == "private")
|
||||
{
|
||||
privat = true;
|
||||
result.keys.insert(lexem);
|
||||
}
|
||||
}
|
||||
|
||||
if (privat == false)
|
||||
{
|
||||
if (forDo && doLexem)
|
||||
{
|
||||
vector<SgExpression*> list;
|
||||
for (auto& var : globalPriv)
|
||||
if (is_private_in_do(st, var))
|
||||
list.push_back(new SgVarRefExp(findSymbolOrCreate(current_file, var, NULL, getFuncStat(st))));
|
||||
|
||||
if (list.size())
|
||||
addToAttribute(st, ACC_PRIVATE_OP, list);
|
||||
}
|
||||
}
|
||||
|
||||
for (auto& lexem : lexems)
|
||||
{
|
||||
bool priv = lexem.substr(0, strlen("private(")) == "private(";
|
||||
bool threadpriv = lexem.substr(0, strlen("threadprivate(")) == "threadprivate(";
|
||||
bool red = lexem.substr(0, strlen("reduction(")) == "reduction(";
|
||||
if (priv || threadpriv)
|
||||
{
|
||||
vector<string> sublex;
|
||||
splitString(lexem, '(', sublex);
|
||||
if (sublex.size() == 2 && lexem.back() == ')')
|
||||
{
|
||||
splitString(sublex[1].erase(sublex[1].size() - 1), ',', sublex);
|
||||
|
||||
vector<SgExpression*> list;
|
||||
set<string> uniqList;
|
||||
for (auto& varG : globalPriv)
|
||||
uniqList.insert(varG);
|
||||
|
||||
for (auto& var : sublex)
|
||||
uniqList.insert(var);
|
||||
|
||||
for (auto& var : uniqList)
|
||||
{
|
||||
if (priv)
|
||||
{
|
||||
result.privVars.insert(var);
|
||||
list.push_back(new SgVarRefExp(findSymbolOrCreate(current_file, var, NULL, getFuncStat(st))));
|
||||
}
|
||||
else
|
||||
result.threadPrivVars.insert(var);
|
||||
}
|
||||
|
||||
if (forDo && doLexem && priv)
|
||||
addToAttribute(st, ACC_PRIVATE_OP, list);
|
||||
}
|
||||
}
|
||||
else if (red)
|
||||
{
|
||||
vector<string> sublex;
|
||||
splitString(lexem, '(', sublex);
|
||||
if (sublex.size() == 2 && lexem.back() == ')')
|
||||
{
|
||||
splitString(sublex[1].erase(sublex[1].size() - 1), ':', sublex);
|
||||
|
||||
vector<string> vars;
|
||||
vector<SgExpression*> list;
|
||||
splitString(sublex[1], ',', vars);
|
||||
string op = "";
|
||||
|
||||
if (sublex[0] == "+")
|
||||
op = "sum";
|
||||
else if (sublex[0] == "*")
|
||||
op = "prod";
|
||||
else if (sublex[0] == "max")
|
||||
op = "max";
|
||||
else if (sublex[0] == "min")
|
||||
op = "min";
|
||||
else if (sublex[0] == ".or." || sublex[0] == "or")
|
||||
op = "or";
|
||||
else if (sublex[0] == ".and." || sublex[0] == "and")
|
||||
op = "and";
|
||||
else if (sublex[0] == ".eqv." || sublex[0] == "eqv")
|
||||
op = "eqv";
|
||||
else if (sublex[0] == ".neqv." || sublex[0] == "neqv")
|
||||
op = "neqv";
|
||||
|
||||
if (op != "")
|
||||
{
|
||||
for (auto& var : vars)
|
||||
{
|
||||
result.redVars[sublex[0]].insert(var);
|
||||
list.push_back(new SgExpression(ARRAY_OP, new SgKeywordValExp(op.c_str()), new SgVarRefExp(findSymbolOrCreate(current_file, var, NULL, getFuncStat(st)))));
|
||||
}
|
||||
}
|
||||
|
||||
if (forDo && doLexem && op != "")
|
||||
addToAttribute(st, REDUCTION_OP, list);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
resultAll.push_back(result);
|
||||
}
|
||||
}
|
||||
|
||||
return resultAll;
|
||||
}
|
||||
@@ -40,14 +40,3 @@ void fillShrinkFromComment(Statement *stIn, std::vector<std::pair<fillType, std:
|
||||
|
||||
template<typename fillType>
|
||||
void fillCheckpointFromComment(Statement *stIn, std::map<int, Expression*> &clauses, std::set<fillType> &vars, std::set<fillType> &expt);
|
||||
|
||||
struct OmpDir
|
||||
{
|
||||
std::set<std::string> privVars;
|
||||
std::set<std::string> threadPrivVars;
|
||||
std::map<std::string, std::set<std::string>> redVars;
|
||||
std::set<std::string> keys;
|
||||
};
|
||||
|
||||
void removeOmpDir(void* stIn);
|
||||
std::vector<OmpDir> parseOmpDirs(void* st, const std::set<std::string>& globalPriv, bool forDo = false);
|
||||
@@ -39,6 +39,8 @@ using std::make_tuple;
|
||||
|
||||
static const string dvmhModuleName = "dvmh_template_mod";
|
||||
|
||||
extern int mpiProgram;
|
||||
|
||||
//the size of vector indiceates type of DVM_DIR
|
||||
SgStatement* createStatFromExprs(const vector<Expression*> &exprs)
|
||||
{
|
||||
@@ -2365,3 +2367,64 @@ void insertDistributeDirsToParallelRegions(const vector<ParallelRegionLines> *cu
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void insertParallelDirs(SgFile *file, bool extract,
|
||||
vector<Directive*>& createdDirectives,
|
||||
vector<Messages>& messages,
|
||||
map<string, string>& templateDeclInIncludes,
|
||||
map<string, map<int, set<string>>>& commentsToInclude,
|
||||
const vector<FuncInfo*>& callGraph,
|
||||
const vector<ParallelRegion*>& parallelRegions,
|
||||
const map<string, vector<LoopGraph*>>& loopGraph,
|
||||
const set<string>& allFileNames,
|
||||
const map<DIST::Array*, set<DIST::Array*>>& arrayLinksByFuncCalls,
|
||||
const map<tuple<int, string, string>, pair<DIST::Array*, DIST::ArrayAccessInfo*>>& declaredArrays,
|
||||
const map<DIST::Array*, tuple<int, string, string>>& tableOfUniqNamesByArray)
|
||||
{
|
||||
const char* file_name = file->filename();
|
||||
insertDirectiveToFile(file, file_name, createdDirectives, extract, messages);
|
||||
|
||||
if (mpiProgram == 0)
|
||||
{
|
||||
map<string, FuncInfo*> mapFuncInfo;
|
||||
createMapOfFunc(callGraph, mapFuncInfo);
|
||||
|
||||
for (int z = 0; z < parallelRegions.size(); ++z)
|
||||
{
|
||||
ParallelRegion* currReg = parallelRegions[z];
|
||||
|
||||
const DataDirective& dataDirectives = currReg->GetDataDir();
|
||||
const vector<int>& currentVariant = currReg->GetCurrentVariant();
|
||||
const DIST::Arrays<int>& allArrays = currReg->GetAllArrays();
|
||||
DIST::GraphCSR<int, double, attrType>& reducedG = currReg->GetReducedGraphToModify();
|
||||
|
||||
const set<string> distrArrays = fillDistributedArrays(dataDirectives, tableOfUniqNamesByArray, arrayLinksByFuncCalls);
|
||||
const vector<string> distrRules = dataDirectives.GenRule(currentVariant);
|
||||
const vector<vector<dist>> distrRulesSt = dataDirectives.GenRule(currentVariant, 0);
|
||||
const vector<string> alignRules = dataDirectives.GenAlignsRules();
|
||||
|
||||
|
||||
insertDistributionToFile(file, file_name, dataDirectives, distrArrays, distrRules, distrRulesSt, alignRules, loopGraph,
|
||||
allArrays, reducedG, commentsToInclude, templateDeclInIncludes, extract, messages,
|
||||
arrayLinksByFuncCalls, mapFuncInfo, currReg->GetId(), allFileNames);
|
||||
|
||||
insertLoopTempalteDeclaration(file, dataDirectives, distrRules, distrRulesSt, allArrays, extract, currReg->GetId());
|
||||
}
|
||||
}
|
||||
|
||||
if (extract)
|
||||
{
|
||||
createdDirectives.clear();
|
||||
|
||||
//clear shadow specs
|
||||
for (auto& array : declaredArrays)
|
||||
array.second.first->ClearShadowSpecs();
|
||||
}
|
||||
else if (mpiProgram == 0)
|
||||
{
|
||||
set<uint64_t> regNum;
|
||||
for (int z = 0; z < parallelRegions.size(); ++z)
|
||||
regNum.insert(parallelRegions[z]->GetId());
|
||||
insertTemplateModuleUse(file, regNum, arrayLinksByFuncCalls);
|
||||
}
|
||||
}
|
||||
@@ -48,3 +48,16 @@ void insertDistributeDirsToParallelRegions(const std::vector<ParallelRegionLines
|
||||
void insertTemplateModuleUse(SgFile* file, const std::set<uint64_t>& regNum, const std::map<DIST::Array*, std::set<DIST::Array*>>& arrayLinksByFuncCalls);
|
||||
void removeStatementsFromAllproject(const std::set<int>& variants);
|
||||
void correctTemplateModuleDeclaration(const std::string& folderName);
|
||||
|
||||
void insertParallelDirs(SgFile* file, bool extract,
|
||||
std::vector<Directive*>& createdDirectives,
|
||||
std::vector<Messages>& messages,
|
||||
std::map<std::string, std::string>& templateDeclInIncludes,
|
||||
std::map<std::string, std::map<int, std::set<std::string>>>& commentsToInclude,
|
||||
const std::vector<FuncInfo*>& callGraph,
|
||||
const std::vector<ParallelRegion*>& parallelRegions,
|
||||
const std::map<std::string, std::vector<LoopGraph*>>& loopGraph,
|
||||
const std::set<std::string>& allFileNames,
|
||||
const std::map<DIST::Array*, std::set<DIST::Array*>>& arrayLinksByFuncCalls,
|
||||
const std::map<std::tuple<int, std::string, std::string>, std::pair<DIST::Array*, DIST::ArrayAccessInfo*>>& declaredArrays,
|
||||
const std::map<DIST::Array*, std::tuple<int, std::string, std::string>>& tableOfUniqNamesByArray);
|
||||
@@ -2121,6 +2121,23 @@ static bool moveSpfParameterForImplicitLoops(SgStatement* st, SgStatement* toAdd
|
||||
return moveNext;
|
||||
}
|
||||
|
||||
static void insertBefore(SgStatement* st, SgStatement* toAdd)
|
||||
{
|
||||
if (toAdd == NULL)
|
||||
return;
|
||||
|
||||
st->insertStmtBefore(*toAdd, *st->controlParent());
|
||||
if (st->variant() == FOR_NODE)
|
||||
{
|
||||
auto com = st->comments();
|
||||
if (com)
|
||||
{
|
||||
st->lexPrev()->addComment(com);
|
||||
st->delComments();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void revertion_spf_dirs(SgFile *file,
|
||||
map<tuple<int, string, string>, pair<DIST::Array*, DIST::ArrayAccessInfo*>> declaredArrays,
|
||||
map<SgStatement*, set<tuple<int, string, string>>> declaratedArraysSt)
|
||||
@@ -2163,7 +2180,7 @@ void revertion_spf_dirs(SgFile *file,
|
||||
toAdd = UniteAttributes(sameAtt);
|
||||
if (toAdd)
|
||||
if (!moveSpfParameterForImplicitLoops(st, toAdd))
|
||||
st->insertStmtBefore(*toAdd, *st->controlParent());
|
||||
insertBefore(st, toAdd);
|
||||
}
|
||||
|
||||
//check previosly directives SPF_PARALLEL
|
||||
@@ -2174,7 +2191,7 @@ void revertion_spf_dirs(SgFile *file,
|
||||
{
|
||||
if (toAdd)
|
||||
toAdd = UniteAttributes(sameAtt);
|
||||
st->insertStmtBefore(*toAdd, *st->controlParent());
|
||||
insertBefore(st, toAdd);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2188,7 +2205,7 @@ void revertion_spf_dirs(SgFile *file,
|
||||
SgStatement *toAdd = &(data->copy());
|
||||
|
||||
if (toAdd)
|
||||
st->insertStmtBefore(*toAdd, *st->controlParent());
|
||||
insertBefore(st, toAdd);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,26 +65,13 @@ static void findUsedArraysInParallelLoops(LoopGraph* loop, set<DIST::Array*>& re
|
||||
}
|
||||
|
||||
static void preventLoopsFromParallelizations(LoopGraph* loop, const set<DIST::Array*>& prevent,
|
||||
vector<Directive*>& createdDirectives,vector<Messages>& messagesForFile)
|
||||
vector<Messages>& messagesForFile)
|
||||
{
|
||||
if (loop->directive)
|
||||
{
|
||||
if (IsSetsIntersect(prevent, loop->usedArraysAll))
|
||||
{
|
||||
// prevent this loop
|
||||
int loopLine = loop->lineNum;
|
||||
|
||||
for (auto dir_it = createdDirectives.begin(); dir_it != createdDirectives.end(); dir_it++)
|
||||
{
|
||||
if ((*dir_it)->line == loopLine)
|
||||
{
|
||||
delete *dir_it;
|
||||
dir_it = createdDirectives.erase(dir_it);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
delete loop->directive;
|
||||
loop->directive = NULL;
|
||||
|
||||
@@ -121,11 +108,9 @@ static void preventLoopsFromParallelizations(LoopGraph* loop, const set<DIST::Ar
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
for (LoopGraph* child : loop->children)
|
||||
preventLoopsFromParallelizations(child, prevent, createdDirectives, messagesForFile);
|
||||
}
|
||||
preventLoopsFromParallelizations(child, prevent, messagesForFile);
|
||||
}
|
||||
|
||||
struct DimConf
|
||||
@@ -171,9 +156,9 @@ pickBest(const map<DimConf, map<FuncInfo*, set<DIST::Array*>>>& arrs)
|
||||
}
|
||||
|
||||
void SelectArrayConfForParallelization(SgProject* proj, map<string, vector<FuncInfo*>>& funcByFile,
|
||||
const map<string, vector<LoopGraph*>>& loopGraph, map<std::string, vector<Directive*>>& createdDirectives,
|
||||
map<string, vector<Messages>>& allMessages, const map<DIST::Array*, set<DIST::Array*>>& arrayLinksByFuncCalls,
|
||||
const vector<ParallelRegion*>& regions)
|
||||
const map<string, vector<LoopGraph*>>& loopGraph,
|
||||
map<string, vector<Messages>>& allMessages,
|
||||
const map<DIST::Array*, set<DIST::Array*>>& arrayLinksByFuncCalls)
|
||||
{
|
||||
map<string, FuncInfo*> funcByName;
|
||||
for (const auto& byFile : funcByFile)
|
||||
@@ -267,9 +252,6 @@ void SelectArrayConfForParallelization(SgProject* proj, map<string, vector<FuncI
|
||||
for (const auto& byFile : loopGraph)
|
||||
{
|
||||
vector<Messages>& fileM = getObjectForFileFromMap(byFile.first.c_str(), allMessages);
|
||||
auto dirs_it = createdDirectives.find(byFile.first);
|
||||
if (dirs_it != createdDirectives.end())
|
||||
{
|
||||
SgFile::switchToFile(byFile.first);
|
||||
|
||||
auto& loops = byFile.second;
|
||||
@@ -298,7 +280,7 @@ void SelectArrayConfForParallelization(SgProject* proj, map<string, vector<FuncI
|
||||
{
|
||||
auto prevent_it = preventFromParallelization.find(byFunc);
|
||||
if (prevent_it != preventFromParallelization.end())
|
||||
preventLoopsFromParallelizations(loop, prevent_it->second, dirs_it->second, fileM);
|
||||
preventLoopsFromParallelizations(loop, prevent_it->second, fileM);
|
||||
|
||||
loop_analyzed = true;
|
||||
break;
|
||||
@@ -310,78 +292,3 @@ void SelectArrayConfForParallelization(SgProject* proj, map<string, vector<FuncI
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void removeRegionsWithoutDirs(const map<string, vector<Directive*>>& createdDirectives,
|
||||
vector<ParallelRegion*>& parallelRegions,
|
||||
const map<string, vector<FuncInfo*>>& allFuncInfo,
|
||||
map<string, vector<Messages>>& SPF_messages)
|
||||
{
|
||||
set<ParallelRegion*> empty_regs(parallelRegions.begin(), parallelRegions.end());
|
||||
|
||||
for (const auto& byFile : createdDirectives)
|
||||
for (const auto& dir : byFile.second)
|
||||
empty_regs.erase(getRegionByLine(parallelRegions, byFile.first, dir->line));
|
||||
|
||||
set<int> idxToDel;
|
||||
for (int z = 0; z < parallelRegions.size(); ++z)
|
||||
{
|
||||
if (empty_regs.find(parallelRegions[z]) != empty_regs.end())
|
||||
{
|
||||
__spf_print(1, " no parallel directives for parallel region '%s'\n", parallelRegions[z]->GetName().c_str());
|
||||
|
||||
if (parallelRegions[z]->GetId() == 0) // DEFAULT
|
||||
{
|
||||
wstring bufE, bufR;
|
||||
__spf_printToLongBuf(bufE, L"Can not find arrays or free loops for distribution in this project");
|
||||
__spf_printToLongBuf(bufR, R130);
|
||||
|
||||
for (auto& funcByFile : allFuncInfo)
|
||||
{
|
||||
vector<Messages>& fileM = getObjectForFileFromMap(funcByFile.first.c_str(), SPF_messages);
|
||||
for (auto& func : funcByFile.second)
|
||||
{
|
||||
auto stat = func->funcPointer->GetOriginal();
|
||||
if (stat->variant() == PROG_HEDR)
|
||||
fileM.push_back(Messages(ERROR, stat->lineNumber(), bufR, bufE, 3010));
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
wstring bufE, bufR;
|
||||
__spf_printToLongBuf(bufE, L"Can not find arrays or free loops for distribution in this region");
|
||||
__spf_printToLongBuf(bufR, R131);
|
||||
|
||||
for (auto& linesByFile : parallelRegions[z]->GetAllLines())
|
||||
{
|
||||
vector<Messages>& fileM = getObjectForFileFromMap(linesByFile.first.c_str(), SPF_messages);
|
||||
for (auto& lines : linesByFile.second)
|
||||
if (!lines.isImplicit())
|
||||
fileM.push_back(Messages(ERROR, lines.lines.first, bufR, bufE, 3010));
|
||||
}
|
||||
}
|
||||
idxToDel.insert(z);
|
||||
}
|
||||
}
|
||||
|
||||
vector<ParallelRegion*> newParReg;
|
||||
for (int z = 0; z < parallelRegions.size(); ++z)
|
||||
{
|
||||
if (idxToDel.find(z) != idxToDel.end())
|
||||
{
|
||||
ParallelRegion* regToDel = parallelRegions[z];
|
||||
#ifdef _WIN32
|
||||
removeFromCollection(parallelRegions[z]);
|
||||
#endif
|
||||
delete parallelRegions[z];
|
||||
}
|
||||
else
|
||||
newParReg.push_back(parallelRegions[z]);
|
||||
}
|
||||
parallelRegions.clear();
|
||||
parallelRegions = newParReg;
|
||||
|
||||
if (parallelRegions.size() == 0)
|
||||
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
||||
}
|
||||
@@ -12,11 +12,5 @@
|
||||
|
||||
void SelectArrayConfForParallelization(SgProject* proj, std::map<std::string, std::vector<FuncInfo*>>& funcByFile,
|
||||
const std::map<std::string, std::vector<LoopGraph*>>& loopGraph,
|
||||
std::map<std::string, std::vector<Directive*>>& createdDirectives,
|
||||
std::map<std::string, std::vector<Messages>>& allMessages,
|
||||
const std::map<DIST::Array*, std::set<DIST::Array*>>& arrayLinksByFuncCalls, const std::vector<ParallelRegion*>& regions);
|
||||
|
||||
void removeRegionsWithoutDirs(const std::map<std::string, std::vector<Directive*>>& createdDirectives,
|
||||
std::vector<ParallelRegion*>& parallelRegions,
|
||||
const std::map<std::string, std::vector<FuncInfo*>>& allFuncInfo,
|
||||
std::map<std::string, std::vector<Messages>>& SPF_messages);
|
||||
const std::map<DIST::Array*, std::set<DIST::Array*>>& arrayLinksByFuncCalls);
|
||||
@@ -207,6 +207,12 @@ static inline bool hasGoto(SgStatement *begin, SgStatement *end,
|
||||
has = true;
|
||||
}
|
||||
|
||||
if (curr->variant() == RETURN_STAT)
|
||||
{
|
||||
linesOfIntGoTo.push_back(curr->lineNumber());
|
||||
has = true;
|
||||
}
|
||||
|
||||
if (curr->variant() == CYCLE_STMT)
|
||||
cycleStmts.push_back(curr->lineNumber());
|
||||
curr = curr->lexNext();
|
||||
@@ -866,6 +872,13 @@ static void printToBuffer(const LoopGraph *currLoop, const int childSize, char b
|
||||
else
|
||||
loopState = 1;
|
||||
}
|
||||
else if (PASSES_DONE[SELECT_ARRAY_DIM_CONF])
|
||||
{
|
||||
if (currLoop->hasLimitsToParallel())
|
||||
loopState = 2;
|
||||
else
|
||||
loopState = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (currLoop->hasLimitsToParallel())
|
||||
|
||||
@@ -211,7 +211,7 @@ public:
|
||||
}
|
||||
|
||||
ParallelDirective *parDirective = baseDirs[0];
|
||||
for (int z = 1; z < baseDirs.size(); ++z)
|
||||
for (int z = 1; z < baseDirs.size() && baseDirs[z]; ++z)
|
||||
{
|
||||
ParallelDirective *old = parDirective;
|
||||
parDirective = *parDirective + *baseDirs[z];
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
#include "loop_analyzer_internal.h"
|
||||
#include "loop_analyzer.h"
|
||||
#include "../DirectiveProcessing/directive_omp_parser.h"
|
||||
|
||||
using std::vector;
|
||||
using std::pair;
|
||||
@@ -125,8 +126,7 @@ static void addInfoToMap(map<SgForStmt*, map<SgSymbol*, ArrayInfo>> &loopInfo, S
|
||||
__spf_print(DEB, "RemoteAccess[%d]: true for dim %d and array %s, loop line %d\n", __LINE__, dimNum, symb->identifier(), position->lineNumber());
|
||||
}
|
||||
|
||||
enum { READ_OP, WRITE_OP, UNREC_OP };
|
||||
static void addInfoToVectors(map<SgForStmt*, map<SgSymbol*, ArrayInfo>> &loopInfo, SgForStmt *position, SgSymbol *symb,
|
||||
void addInfoToVectors(map<SgForStmt*, map<SgSymbol*, ArrayInfo>> &loopInfo, SgForStmt *position, SgSymbol *symb,
|
||||
const int dimNum, const pair<int, int> newCoef, int type, const int maxDimSize, const double currentW)
|
||||
{
|
||||
auto itLoop = loopInfo.find(position);
|
||||
@@ -159,7 +159,7 @@ static void addInfoToVectors(map<SgForStmt*, map<SgSymbol*, ArrayInfo>> &loopInf
|
||||
}
|
||||
|
||||
|
||||
static vector<int> matchSubscriptToLoopSymbols(const vector<SgForStmt*> &parentLoops, SgExpression *subscr,
|
||||
vector<int> matchSubscriptToLoopSymbols(const vector<SgForStmt*> &parentLoops, SgExpression *subscr,
|
||||
SgArrayRefExp *arrayRefIn, const int side, const int dimNum,
|
||||
map<SgForStmt*, map<SgSymbol*, ArrayInfo>> &loopInfo,
|
||||
const int currLine, const int numOfSubscriptions, const double currentW)
|
||||
@@ -557,7 +557,7 @@ static void mapArrayRef(SgStatement* currentSt, SgExpression* currExp,
|
||||
__spf_print(PRINT_ARRAY_ARCS, "\n");
|
||||
}
|
||||
|
||||
void findArrayRef(const vector<SgForStmt*> &parentLoops, SgExpression *currExp, const int lineNum, const int side,
|
||||
static void findArrayRef(const vector<SgForStmt*> &parentLoops, SgExpression *currExp, const int lineNum, const int side,
|
||||
map<SgForStmt*, map<SgSymbol*, ArrayInfo>> &loopInfo, const set<string> &privatesVars,
|
||||
vector<set<string>>& privatesVarsForLoop, map<int, LoopGraph*> &sortedLoopGraph,
|
||||
const map<string, vector<SgExpression*>> &commonBlocks,
|
||||
@@ -2599,7 +2599,7 @@ static bool findOmpThreadPrivDecl(SgStatement* st, map<SgStatement*, set<string>
|
||||
{
|
||||
st = st->lexNext();
|
||||
|
||||
auto res = parseOmpDirs(st, dummy);
|
||||
auto res = parseOmpInStatement(st, dummy);
|
||||
for (auto& dir : res)
|
||||
for (auto& var : dir.threadPrivVars)
|
||||
it->second.insert(var);
|
||||
|
||||
@@ -58,13 +58,13 @@ void changeLoopWeight(double& currentWeight, const std::map<int, LoopGraph*>& so
|
||||
|
||||
SgStatement* takeOutConditions(std::stack<SgExpression*>& conditions, std::stack<SgStatement*>& ifBlocks, SgStatement* st);
|
||||
|
||||
void findArrayRef(const std::vector<SgForStmt*>& parentLoops, SgExpression* currExp, const int lineNum, const int side,
|
||||
std::map<SgForStmt*, std::map<SgSymbol*, ArrayInfo>>& loopInfo, const std::set<std::string>& privatesVars,
|
||||
std::vector<std::set<std::string>>& privatesVarsForLoop, std::map<int, LoopGraph*>& sortedLoopGraph,
|
||||
const std::map<std::string, std::vector<SgExpression*>>& commonBlocks,
|
||||
const std::map<std::tuple<int, std::string, std::string>, std::pair<DIST::Array*, DIST::ArrayAccessInfo*>>& declaredArrays,
|
||||
bool wasDistributedArrayRef, std::map<std::string, std::pair<SgSymbol*, SgStatement*>>& notMappedDistributedArrays,
|
||||
std::set<std::string>& mappedDistrbutedArrays, SgStatement* currentSt, const ParallelRegion* reg, const double currentW,
|
||||
const std::map<DIST::Array*, std::set<DIST::Array*>>& arrayLinksByFuncCalls);
|
||||
enum { READ_OP, WRITE_OP, UNREC_OP };
|
||||
void addInfoToVectors(std::map<SgForStmt*, std::map<SgSymbol*, ArrayInfo>>& loopInfo, SgForStmt* position, SgSymbol* symb,
|
||||
const int dimNum, const std::pair<int, int> newCoef, int type, const int maxDimSize, const double currentW);
|
||||
|
||||
std::vector<int> matchSubscriptToLoopSymbols(const std::vector<SgForStmt*>& parentLoops, SgExpression* subscr,
|
||||
SgArrayRefExp* arrayRefIn, const int side, const int dimNum,
|
||||
std::map<SgForStmt*, std::map<SgSymbol*, ArrayInfo>>& loopInfo,
|
||||
const int currLine, const int numOfSubscriptions, const double currentW);
|
||||
|
||||
bool hasNonPureFunctions(SgExpression* ex, LoopGraph* loopRef, std::vector<Messages>& messagesForFile, const int line, const std::map<std::string, FuncInfo*>& funcByName);
|
||||
@@ -1,4 +1,4 @@
|
||||
#include <cstdio>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <cstdint>
|
||||
@@ -36,7 +36,6 @@ extern void createMapLoopGraph(map<int, LoopGraph*>& sortedLoopGraph, const vect
|
||||
extern map<DIST::Array*, std::tuple<int, string, string>> tableOfUniqNamesByArray;
|
||||
static void convertOneLoopNoDist(LoopGraph* currLoop, map<LoopGraph*, map<DIST::Array*, ArrayInfo*>>& outInfo,
|
||||
const map<SgSymbol*, ArrayInfo>& toConvert,
|
||||
const set<string>& privateArrays,
|
||||
const map<string, vector<SgExpression*>>& commonBlocks,
|
||||
const map<tuple<int, string, string>, pair<DIST::Array*, DIST::ArrayAccessInfo*>>& declaredArrays,
|
||||
const map<DIST::Array*, set<DIST::Array*>>& arrayLinksByFuncCalls,
|
||||
@@ -109,7 +108,6 @@ static void convertOneLoopNoDist(LoopGraph* currLoop, map<LoopGraph*, map<DIST::
|
||||
static map<LoopGraph*, map<DIST::Array*, ArrayInfo*>>
|
||||
convertLoopInfoNoDist(const map<SgForStmt*, map<SgSymbol*, ArrayInfo>>& loopInfo,
|
||||
const map<int, LoopGraph*>& sortedLoopGraph,
|
||||
const set<string>& privateArrays,
|
||||
const map<string, vector<SgExpression*>>& commonBlocks,
|
||||
const map<tuple<int, string, string>, pair<DIST::Array*, DIST::ArrayAccessInfo*>>& declaredArrays,
|
||||
const map<DIST::Array*, set<DIST::Array*>>& arrayLinksByFuncCalls,
|
||||
@@ -123,12 +121,188 @@ convertLoopInfoNoDist(const map<SgForStmt*, map<SgSymbol*, ArrayInfo>>& loopInfo
|
||||
if (itGraph == sortedLoopGraph.end())
|
||||
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
||||
|
||||
convertOneLoopNoDist(itGraph->second, outInfo, it->second, privateArrays, commonBlocks, declaredArrays, arrayLinksByFuncCalls, createdArrays);
|
||||
convertOneLoopNoDist(itGraph->second, outInfo, it->second, commonBlocks, declaredArrays, arrayLinksByFuncCalls, createdArrays);
|
||||
}
|
||||
|
||||
return outInfo;
|
||||
}
|
||||
|
||||
static vector<int> matchArrayToLoopSymbols(const vector<SgForStmt*> &parentLoops, vector<set<string>>& privatesVarsForLoop,
|
||||
SgExpression *currExp, const int side,
|
||||
map<SgForStmt*, map<SgSymbol*, ArrayInfo>> &loopInfo, const int currLine,
|
||||
map<int, LoopGraph*> &sortedLoopGraph, const ParallelRegion *reg, const double currentW,
|
||||
const map<DIST::Array*, set<DIST::Array*>> &arrayLinksByFuncCalls)
|
||||
{
|
||||
SgArrayRefExp *arrayRef = (SgArrayRefExp*)currExp;
|
||||
int numOfSubs = arrayRef->numberOfSubscripts();
|
||||
|
||||
currExp = currExp->lhs();
|
||||
vector<int> wasFoundForLoop(parentLoops.size());
|
||||
vector<int> matched(numOfSubs);
|
||||
vector<int> matchedToDim(parentLoops.size());
|
||||
std::fill(wasFoundForLoop.begin(), wasFoundForLoop.end(), 0);
|
||||
std::fill(matched.begin(), matched.end(), -1);
|
||||
std::fill(matchedToDim.begin(), matchedToDim.end(), -1);
|
||||
int maxMatched = 0;
|
||||
int sumMatched = 0;
|
||||
|
||||
for (int i = 0; i < numOfSubs; ++i)
|
||||
{
|
||||
vector<int> matchToLoops = matchSubscriptToLoopSymbols(parentLoops, currExp->lhs(), arrayRef, side, i, loopInfo, currLine, numOfSubs, currentW);
|
||||
for (int k = 0; k < matchToLoops.size(); ++k)
|
||||
{
|
||||
wasFoundForLoop[matchToLoops[k]]++;
|
||||
matchedToDim[matchToLoops[k]] = i;
|
||||
}
|
||||
|
||||
matched[i] = matchToLoops.size();
|
||||
sumMatched += matchToLoops.size();
|
||||
maxMatched = std::max(maxMatched, (int)matchToLoops.size());
|
||||
currExp = currExp->rhs();
|
||||
}
|
||||
|
||||
//full array is used, add unknown operations to all loops
|
||||
if (numOfSubs == 0)
|
||||
{
|
||||
SgSymbol *currOrigArrayS = OriginalSymbol(arrayRef->symbol());
|
||||
auto arrType = isSgArrayType(currOrigArrayS->type());
|
||||
if (arrType != NULL)
|
||||
{
|
||||
for (int d = 0; d < arrType->dimension(); ++d)
|
||||
for (int i = 0; i < parentLoops.size(); ++i)
|
||||
addInfoToVectors(loopInfo, parentLoops[i], currOrigArrayS, d, make_pair(0, 0), UNREC_OP, arrType->dimension(), currentW);
|
||||
}
|
||||
}
|
||||
|
||||
bool ifUnknownArrayAssignFound = false;
|
||||
vector<int> canNotMapToLoop;
|
||||
for (int i = 0; i < wasFoundForLoop.size(); ++i)
|
||||
{
|
||||
if (wasFoundForLoop[i] != 1 &&
|
||||
privatesVarsForLoop[i].find(string(arrayRef->symbol()->identifier())) == privatesVarsForLoop[i].end())
|
||||
{
|
||||
auto itLoop = sortedLoopGraph.find(parentLoops[i]->lineNumber());
|
||||
if (itLoop == sortedLoopGraph.end())
|
||||
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
||||
ifUnknownArrayAssignFound = true;
|
||||
if (side == LEFT)
|
||||
itLoop->second->hasUnknownArrayAssigns = true;
|
||||
|
||||
itLoop->second->hasUnknownDistributedMap = true;
|
||||
canNotMapToLoop.push_back(parentLoops[i]->lineNumber());
|
||||
}
|
||||
}
|
||||
|
||||
if (side == LEFT)
|
||||
{
|
||||
if (ifUnknownArrayAssignFound)
|
||||
{
|
||||
const string arrayRefS = arrayRef->unparse();
|
||||
for (auto &line : canNotMapToLoop)
|
||||
{
|
||||
__spf_print(1, "WARN: can not map write to array '%s' to loop on line %d\n", arrayRefS.c_str(), line);
|
||||
wstring messageE, messageR;
|
||||
__spf_printToLongBuf(messageE, L"can not map write to array '%s' to this loop", to_wstring(arrayRefS).c_str());
|
||||
|
||||
__spf_printToLongBuf(messageR, R59, to_wstring(arrayRefS).c_str());
|
||||
|
||||
if (line > 0)
|
||||
currMessages->push_back(Messages(WARR, line, messageR, messageE, 1025));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return wasFoundForLoop;
|
||||
}
|
||||
|
||||
static void mapArrayRef(SgStatement* currentSt, SgExpression* currExp,
|
||||
const vector<SgForStmt*>& parentLoops, const int side, const int lineNum,
|
||||
map<SgForStmt*, map<SgSymbol*, ArrayInfo>>& loopInfo,
|
||||
vector<set<string>>& privatesVarsForLoop,
|
||||
map<int, LoopGraph*>& sortedLoopGraph, map<string, pair<SgSymbol*, SgStatement*>>& notMappedDistributedArrays,
|
||||
set<string>& mappedDistrbutedArrays,
|
||||
const ParallelRegion* reg, const double currentW, const map<DIST::Array*, set<DIST::Array*>>& arrayLinksByFuncCalls)
|
||||
{
|
||||
const char* printSide = NULL;
|
||||
if (PRINT_ARRAY_ARCS)
|
||||
printBlanks(2, (int)parentLoops.size());
|
||||
if (side == LEFT)
|
||||
printSide = "W_OP";
|
||||
else
|
||||
printSide = "R_OP";
|
||||
|
||||
__spf_print(PRINT_ARRAY_ARCS, "%s to array <%s> on line %d: ", printSide, OriginalSymbol(currExp->symbol())->identifier(), lineNum);
|
||||
bool wasMapped = false;
|
||||
vector<int> matched = matchArrayToLoopSymbols(parentLoops, privatesVarsForLoop, currExp, side, loopInfo, lineNum, sortedLoopGraph, reg, currentW, arrayLinksByFuncCalls);
|
||||
for (int z = 0; z < matched.size(); ++z)
|
||||
wasMapped |= (matched[z] != 0);
|
||||
|
||||
if (parentLoops.size() == 0)
|
||||
{
|
||||
SgSymbol* symb = currExp->symbol();
|
||||
if (symb->type()->variant() == T_ARRAY)
|
||||
notMappedDistributedArrays[symb->identifier()] = make_pair(symb, currentSt);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (wasMapped)
|
||||
mappedDistrbutedArrays.insert(currExp->symbol()->identifier());
|
||||
else
|
||||
{
|
||||
SgSymbol* symb = currExp->symbol();
|
||||
if (symb->type()->variant() == T_ARRAY)
|
||||
notMappedDistributedArrays[symb->identifier()] = make_pair(symb, currentSt);
|
||||
}
|
||||
}
|
||||
__spf_print(PRINT_ARRAY_ARCS, "\n");
|
||||
}
|
||||
|
||||
static void findArrayRef(const vector<SgForStmt*>& parentLoops, SgExpression* currExp, const int lineNum, const int side,
|
||||
map<SgForStmt*, map<SgSymbol*, ArrayInfo>>& loopInfo,
|
||||
vector<set<string>>& privatesVarsForLoop, map<int, LoopGraph*>& sortedLoopGraph,
|
||||
map<string, pair<SgSymbol*, SgStatement*>>& notMappedDistributedArrays,
|
||||
set<string>& mappedDistrbutedArrays, SgStatement* currentSt, const ParallelRegion* reg, const double currentW,
|
||||
const map<DIST::Array*, set<DIST::Array*>>& arrayLinksByFuncCalls)
|
||||
{
|
||||
int nextSide = side;
|
||||
if (isArrayRef(currExp))
|
||||
{
|
||||
mapArrayRef(currentSt, currExp, parentLoops, side, lineNum, loopInfo, privatesVarsForLoop, sortedLoopGraph,
|
||||
notMappedDistributedArrays, mappedDistrbutedArrays, reg, currentW, arrayLinksByFuncCalls);
|
||||
nextSide = (side == LEFT) ? RIGHT : side;
|
||||
}
|
||||
|
||||
bool needToContinue = true;
|
||||
if (currExp->variant() == FUNC_CALL)
|
||||
{
|
||||
SgFunctionCallExp* funcExp = (SgFunctionCallExp*)currExp;
|
||||
auto currFunc = isUserFunctionInProject(funcExp->funName()->identifier());
|
||||
if (currFunc)
|
||||
{
|
||||
for (int z = 0; z < funcExp->numberOfArgs(); ++z)
|
||||
{
|
||||
if ((currFunc->funcParams.inout_types[z] & OUT_BIT) != 0)
|
||||
nextSide = LEFT;
|
||||
else
|
||||
nextSide = RIGHT;
|
||||
findArrayRef(parentLoops, funcExp->arg(z), lineNum, nextSide, loopInfo, privatesVarsForLoop, sortedLoopGraph,
|
||||
notMappedDistributedArrays, mappedDistrbutedArrays, currentSt, reg, currentW, arrayLinksByFuncCalls);
|
||||
}
|
||||
needToContinue = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (needToContinue)
|
||||
{
|
||||
if (currExp->lhs())
|
||||
findArrayRef(parentLoops, currExp->lhs(), lineNum, nextSide, loopInfo, privatesVarsForLoop, sortedLoopGraph,
|
||||
notMappedDistributedArrays, mappedDistrbutedArrays, currentSt, reg, currentW, arrayLinksByFuncCalls);
|
||||
if (currExp->rhs())
|
||||
findArrayRef(parentLoops, currExp->rhs(), lineNum, nextSide, loopInfo, privatesVarsForLoop, sortedLoopGraph,
|
||||
notMappedDistributedArrays, mappedDistrbutedArrays, currentSt, reg, currentW, arrayLinksByFuncCalls);
|
||||
}
|
||||
}
|
||||
|
||||
void loopAnalyzerNoDist(SgFile* file, vector<ParallelRegion*>& regions, map<tuple<int, string, string>, DIST::Array*>& createdArrays,
|
||||
vector<Messages>& messagesForFile, const map<string, vector<FuncInfo*>>& AllfuncInfo,
|
||||
const map<tuple<int, string, string>, pair<DIST::Array*, DIST::ArrayAccessInfo*>>& declaredArrays,
|
||||
@@ -187,8 +361,6 @@ void loopAnalyzerNoDist(SgFile* file, vector<ParallelRegion*>& regions, map<tupl
|
||||
map<SgForStmt*, map<SgSymbol*, ArrayInfo>> loopInfo;
|
||||
set<int> loopWithOutArrays;
|
||||
|
||||
set<string> privatesVars;
|
||||
|
||||
SgStatement* st = file->functions(i);
|
||||
string funcName = "";
|
||||
if (st->variant() == PROG_HEDR)
|
||||
@@ -269,7 +441,7 @@ void loopAnalyzerNoDist(SgFile* file, vector<ParallelRegion*>& regions, map<tupl
|
||||
const int currV = st->variant();
|
||||
if (currV == FOR_NODE)
|
||||
{
|
||||
tryToFindPrivateInAttributes(st, privatesVars);
|
||||
//tryToFindPrivateInAttributes(st, privatesVars);
|
||||
|
||||
set<string> toAdd;
|
||||
tryToFindPrivateInAttributes(st, toAdd);
|
||||
@@ -312,12 +484,12 @@ void loopAnalyzerNoDist(SgFile* file, vector<ParallelRegion*>& regions, map<tupl
|
||||
else if (currV == ASSIGN_STAT)
|
||||
{
|
||||
if (st->expr(0))
|
||||
findArrayRef(parentLoops, st->expr(0), st->lineNumber(), LEFT, loopInfo, privatesVars, privatesVarsForLoop,
|
||||
sortedLoopGraph, commonBlocks, declaredArrays, false, notMappedDistributedArrays,
|
||||
findArrayRef(parentLoops, st->expr(0), st->lineNumber(), LEFT, loopInfo, privatesVarsForLoop,
|
||||
sortedLoopGraph, notMappedDistributedArrays,
|
||||
mappedDistrbutedArrays, st, currReg, currentWeight, arrayLinksByFuncCalls);
|
||||
if (st->expr(1))
|
||||
findArrayRef(parentLoops, st->expr(1), st->lineNumber(), RIGHT, loopInfo, privatesVars, privatesVarsForLoop,
|
||||
sortedLoopGraph, commonBlocks, declaredArrays, false, notMappedDistributedArrays,
|
||||
findArrayRef(parentLoops, st->expr(1), st->lineNumber(), RIGHT, loopInfo, privatesVarsForLoop,
|
||||
sortedLoopGraph, notMappedDistributedArrays,
|
||||
mappedDistrbutedArrays, st, currReg, currentWeight, arrayLinksByFuncCalls);
|
||||
}
|
||||
else if (currV == IF_NODE || currV == ELSEIF_NODE || currV == LOGIF_NODE || currV == SWITCH_NODE)
|
||||
@@ -325,8 +497,8 @@ void loopAnalyzerNoDist(SgFile* file, vector<ParallelRegion*>& regions, map<tupl
|
||||
SgStatement* before = NULL;
|
||||
if (st->expr(0))
|
||||
{
|
||||
findArrayRef(parentLoops, st->expr(0), st->lineNumber(), RIGHT, loopInfo, privatesVars, privatesVarsForLoop,
|
||||
sortedLoopGraph, commonBlocks, declaredArrays, false, notMappedDistributedArrays,
|
||||
findArrayRef(parentLoops, st->expr(0), st->lineNumber(), RIGHT, loopInfo, privatesVarsForLoop,
|
||||
sortedLoopGraph, notMappedDistributedArrays,
|
||||
mappedDistrbutedArrays, st, currReg, currentWeight, arrayLinksByFuncCalls);
|
||||
}
|
||||
}
|
||||
@@ -344,12 +516,12 @@ void loopAnalyzerNoDist(SgFile* file, vector<ParallelRegion*>& regions, map<tupl
|
||||
{
|
||||
SgExpression* par = list->elem(z);
|
||||
if ((func->funcParams.inout_types[z] & OUT_BIT) != 0)
|
||||
findArrayRef(parentLoops, par, st->lineNumber(), LEFT, loopInfo, privatesVars, privatesVarsForLoop,
|
||||
sortedLoopGraph, commonBlocks, declaredArrays, false, notMappedDistributedArrays,
|
||||
findArrayRef(parentLoops, par, st->lineNumber(), LEFT, loopInfo, privatesVarsForLoop,
|
||||
sortedLoopGraph, notMappedDistributedArrays,
|
||||
mappedDistrbutedArrays, st, currReg, currentWeight, arrayLinksByFuncCalls);
|
||||
else
|
||||
findArrayRef(parentLoops, par, st->lineNumber(), RIGHT, loopInfo, privatesVars, privatesVarsForLoop,
|
||||
sortedLoopGraph, commonBlocks, declaredArrays, false, notMappedDistributedArrays,
|
||||
findArrayRef(parentLoops, par, st->lineNumber(), RIGHT, loopInfo, privatesVarsForLoop,
|
||||
sortedLoopGraph, notMappedDistributedArrays,
|
||||
mappedDistrbutedArrays, st, currReg, currentWeight, arrayLinksByFuncCalls);
|
||||
}
|
||||
|
||||
@@ -385,8 +557,8 @@ void loopAnalyzerNoDist(SgFile* file, vector<ParallelRegion*>& regions, map<tupl
|
||||
|
||||
for (int z = 0; z < 3; ++z)
|
||||
if (st->expr(z))
|
||||
findArrayRef(parentLoops, st->expr(z), st->lineNumber(), side, loopInfo, privatesVars, privatesVarsForLoop,
|
||||
sortedLoopGraph, commonBlocks, declaredArrays, false, notMappedDistributedArrays,
|
||||
findArrayRef(parentLoops, st->expr(z), st->lineNumber(), side, loopInfo, privatesVarsForLoop,
|
||||
sortedLoopGraph, notMappedDistributedArrays,
|
||||
mappedDistrbutedArrays, st, currReg, currentWeight, arrayLinksByFuncCalls);
|
||||
|
||||
}
|
||||
@@ -395,7 +567,7 @@ void loopAnalyzerNoDist(SgFile* file, vector<ParallelRegion*>& regions, map<tupl
|
||||
st = st->lexNext();
|
||||
}
|
||||
|
||||
auto convertedLoopInfo = convertLoopInfoNoDist(loopInfo, sortedLoopGraph, privatesVars, commonBlocks, declaredArrays, arrayLinksByFuncCalls, createdArrays);
|
||||
auto convertedLoopInfo = convertLoopInfoNoDist(loopInfo, sortedLoopGraph, commonBlocks, declaredArrays, arrayLinksByFuncCalls, createdArrays);
|
||||
|
||||
processLoopInformationForFunction(convertedLoopInfo);
|
||||
|
||||
@@ -469,8 +641,26 @@ void loopAnalyzerNoDist(SgFile* file, vector<ParallelRegion*>& regions, map<tupl
|
||||
sendMessage_2lvl(L"");
|
||||
|
||||
createParallelDirectivesNoDist(convertedLoopInfo, regions, arrayLinksByFuncCalls, messagesForFile);
|
||||
if (parallizeFreeLoops)
|
||||
selectFreeLoopsForParallelization(loopsForFunction, funcName, false, regions, messagesForFile);
|
||||
for (auto& loopLine : loopWithOutArrays)
|
||||
{
|
||||
auto loopRef = sortedLoopGraph[loopLine];
|
||||
if (loopRef->withoutDistributedArrays && loopRef->region && !loopRef->hasLimitsToParallel() && loopRef->lineNum > 0)
|
||||
{
|
||||
int nesting = 0;
|
||||
LoopGraph* it = loopRef;
|
||||
for (int z = 0; z < loopRef->perfectLoop; ++z, it->children.size() ? it = it->children[0] : it)
|
||||
if (it->withoutDistributedArrays && it->region && !it->hasLimitsToParallel() && it->lineNum > 0)
|
||||
++nesting;
|
||||
|
||||
map<LoopGraph*, map<DIST::Array*, ArrayInfo*>> convertedLoopInfo;
|
||||
|
||||
it = loopRef;
|
||||
for (int z = 0; z < nesting; ++z, it->children.size() ? it = it->children[0] : it)
|
||||
convertedLoopInfo.insert(make_pair(it, map<DIST::Array*, ArrayInfo*>()));
|
||||
|
||||
createParallelDirectivesNoDist(convertedLoopInfo, regions, map<DIST::Array*, set<DIST::Array*>>(), messagesForFile);
|
||||
}
|
||||
}
|
||||
|
||||
__spf_print(PRINT_PROF_INFO, "Function ended\n");
|
||||
}
|
||||
|
||||
@@ -31,7 +31,6 @@ extern "C" int out_upper_case;
|
||||
extern "C" int out_line_unlimit;
|
||||
extern "C" int out_line_length;
|
||||
extern "C" PTR_SYMB last_file_symbol;
|
||||
extern "C" PTR_SYMB FileLastSymbol(...);
|
||||
|
||||
static int convertFile(int argc, char* argv[], const set<string>& filesInProj, const set<string>& moduleDeclsInFiles)
|
||||
{
|
||||
@@ -353,7 +352,6 @@ static int convertFile(int argc, char* argv[], const set<string>& filesInProj, c
|
||||
fout_name_info_C = ChangeFto_info_C(fout_name); /*ACC*/
|
||||
|
||||
//set the last symbol of file
|
||||
last_file_symbol = FileLastSymbol(file->filename());
|
||||
initLibNames(); //for every file
|
||||
InitDVM(file); //for every file
|
||||
current_file = file; // global variable (used in SgTypeComplex)
|
||||
|
||||
@@ -46,10 +46,11 @@
|
||||
#include "DynamicAnalysis/gCov_parser_func.h"
|
||||
#include "DynamicAnalysis/createParallelRegions.h"
|
||||
|
||||
#include "DirectiveProcessing/DirectiveAnalyzer.h"
|
||||
#include "DirectiveProcessing/directive_analyzer.h"
|
||||
#include "DirectiveProcessing/directive_creator.h"
|
||||
#include "DirectiveProcessing/directive_creator_nodist.h"
|
||||
#include "DirectiveProcessing/insert_directive.h"
|
||||
#include "DirectiveProcessing/directive_omp_parser.h"
|
||||
#include "VerificationCode/verifications.h"
|
||||
#include "Distribution/CreateDistributionDirs.h"
|
||||
#include "PrivateAnalyzer/private_analyzer.h"
|
||||
@@ -83,6 +84,7 @@
|
||||
#include "Transformations/private_removing.h"
|
||||
#include "Transformations/fix_common_blocks.h"
|
||||
#include "Transformations/convert_to_c.h"
|
||||
#include "Transformations/set_implicit_none.h"
|
||||
#include "Transformations/dead_code.h"
|
||||
|
||||
#include "RenameSymbols/rename_symbols.h"
|
||||
@@ -377,68 +379,6 @@ string unparseProjectToString(SgFile *file, const int curr_regime)
|
||||
return unparseProjectIfNeed(file, curr_regime, true, "", NULL, allIncludeFiles, true);
|
||||
}
|
||||
|
||||
static bool isNotNullIntersection(const set<DIST::Array*> &first, const set<DIST::Array*> &second)
|
||||
{
|
||||
for (auto &elem1 : first)
|
||||
if (second.find(elem1) != second.end())
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static set<DIST::Array*> fillDistributedArraysD(const DataDirective& dataDirectives, bool onlyCommon = false)
|
||||
{
|
||||
set<DIST::Array*> distrArrays;
|
||||
set<DIST::Array*> distrArraysD;
|
||||
set<DIST::Array*> distrArraysAdded;
|
||||
|
||||
for (int z = 0; z < dataDirectives.distrRules.size(); ++z)
|
||||
distrArraysD.insert(dataDirectives.distrRules[z].first);
|
||||
for (int z = 0; z < dataDirectives.alignRules.size(); ++z)
|
||||
distrArraysD.insert(dataDirectives.alignRules[z].alignArray);
|
||||
|
||||
for (auto& elem : tableOfUniqNamesByArray)
|
||||
{
|
||||
set<DIST::Array*> realRefs;
|
||||
getRealArrayRefs(elem.first, elem.first, realRefs, arrayLinksByFuncCalls);
|
||||
if (isNotNullIntersection(realRefs, distrArraysD))
|
||||
distrArraysAdded.insert(elem.first);
|
||||
}
|
||||
|
||||
for (auto& elem : distrArraysD)
|
||||
{
|
||||
if (onlyCommon)
|
||||
{
|
||||
if (elem->GetLocation().first == DIST::l_COMMON)
|
||||
distrArrays.insert(elem);
|
||||
}
|
||||
else
|
||||
distrArrays.insert(elem);
|
||||
}
|
||||
|
||||
for (auto& elem : distrArraysAdded)
|
||||
{
|
||||
if (onlyCommon)
|
||||
{
|
||||
if (elem->GetLocation().first == DIST::l_COMMON)
|
||||
distrArrays.insert(elem);
|
||||
}
|
||||
else
|
||||
distrArrays.insert(elem);
|
||||
}
|
||||
return distrArrays;
|
||||
}
|
||||
|
||||
static set<string> fillDistributedArrays(const DataDirective &dataDirectives, bool onlyCommon = false, bool shortName = false)
|
||||
{
|
||||
set<string> distrArrays;
|
||||
set<DIST::Array*> ret = fillDistributedArraysD(dataDirectives, onlyCommon);
|
||||
|
||||
for (auto& elem : ret)
|
||||
distrArrays.insert(shortName ? elem->GetShortName() : elem->GetName());
|
||||
return distrArrays;
|
||||
}
|
||||
|
||||
static bool runAnalysis(SgProject &project, const int curr_regime, const bool need_to_unparse, const char *newVer = NULL, const char *folderName = NULL)
|
||||
{
|
||||
if (PASSES_DONE_INIT == false)
|
||||
@@ -496,6 +436,7 @@ static bool runAnalysis(SgProject &project, const int curr_regime, const bool ne
|
||||
}
|
||||
|
||||
auto rw_analyzer = ReadWriteAnalyzer(allFuncInfo); // doesn't analyze anything until first query
|
||||
int global_err = 0;
|
||||
|
||||
for (int i = n - 1; i >= 0; --i)
|
||||
{
|
||||
@@ -525,7 +466,8 @@ static bool runAnalysis(SgProject &project, const int curr_regime, const bool ne
|
||||
{
|
||||
vector<Messages> tmp;
|
||||
loopAnalyzer(file, parallelRegions, createdArrays, tmp, DATA_DISTR,
|
||||
allFuncInfo, declaredArrays, declaratedArraysSt, arrayLinksByFuncCalls, createDefUseMapByPlace(), true, &(loopGraph.find(file_name)->second));
|
||||
allFuncInfo, declaredArrays, declaratedArraysSt, arrayLinksByFuncCalls, createDefUseMapByPlace(),
|
||||
true, &(loopGraph.find(file_name)->second));
|
||||
}
|
||||
else if (curr_regime == LOOP_ANALYZER_DATA_DIST_S1 || curr_regime == ONLY_ARRAY_GRAPH)
|
||||
{
|
||||
@@ -600,108 +542,19 @@ static bool runAnalysis(SgProject &project, const int curr_regime, const bool ne
|
||||
{
|
||||
auto &loopsInFile = getObjectForFileFromMap(file_name, loopGraph);
|
||||
|
||||
map<int, LoopGraph*> mapLoopsInFile;
|
||||
createMapLoopGraph(loopsInFile, mapLoopsInFile);
|
||||
|
||||
map<string, FuncInfo*> mapFuncInfo;
|
||||
createMapOfFunc(allFuncInfo, mapFuncInfo);
|
||||
|
||||
for (int z = 0; z < parallelRegions.size(); ++z)
|
||||
{
|
||||
vector<Directive*> toInsert;
|
||||
|
||||
const DataDirective &dataDirectives = parallelRegions[z]->GetDataDir();
|
||||
const vector<int> ¤tVariant = parallelRegions[z]->GetCurrentVariant();
|
||||
DIST::GraphCSR<int, double, attrType> &reducedG = parallelRegions[z]->GetReducedGraphToModify();
|
||||
DIST::Arrays<int> &allArrays = parallelRegions[z]->GetAllArraysToModify();
|
||||
|
||||
auto& tmp = dataDirectives.distrRules;
|
||||
vector<pair<DIST::Array*, const DistrVariant*>> currentVar;
|
||||
|
||||
if (mpiProgram == 0)
|
||||
{
|
||||
for (int z1 = 0; z1 < currentVariant.size(); ++z1)
|
||||
currentVar.push_back(make_pair(tmp[z1].first, &tmp[z1].second[currentVariant[z1]]));
|
||||
}
|
||||
else
|
||||
{
|
||||
for (auto& loop : mapLoopsInFile)
|
||||
{
|
||||
auto& rules = loop.second->getDataDir().distrRules;
|
||||
for (auto& rule : rules)
|
||||
currentVar.push_back(make_pair(rule.first, &rule.second[0]));
|
||||
}
|
||||
}
|
||||
|
||||
map<LoopGraph*, void*> depInfoForLoopGraphV;
|
||||
for (auto& elem : depInfoForLoopGraph)
|
||||
depInfoForLoopGraphV[elem.first] = elem.second;
|
||||
|
||||
selectParallelDirectiveForVariant(new File(file), parallelRegions[z], reducedG, allArrays, loopsInFile, mapLoopsInFile, mapFuncInfo, currentVar,
|
||||
toInsert, parallelRegions[z]->GetId(), arrayLinksByFuncCalls,
|
||||
depInfoForLoopGraphV, getObjectForFileFromMap(file_name, SPF_messages));
|
||||
|
||||
if (toInsert.size() > 0)
|
||||
{
|
||||
auto it = createdDirectives.find(file_name);
|
||||
if (it == createdDirectives.end())
|
||||
createdDirectives.insert(it, make_pair(file_name, toInsert));
|
||||
else
|
||||
for (int m = 0; m < toInsert.size(); ++m)
|
||||
it->second.push_back(toInsert[m]);
|
||||
}
|
||||
}
|
||||
createParallelDirs(new File(file), createdDirectives, getObjectForFileFromMap(file_name, SPF_messages),
|
||||
loopsInFile, allFuncInfo, parallelRegions, depInfoForLoopGraphV, arrayLinksByFuncCalls);
|
||||
}
|
||||
else if (curr_regime == INSERT_PARALLEL_DIRS || curr_regime == EXTRACT_PARALLEL_DIRS)
|
||||
{
|
||||
const bool extract = (curr_regime == EXTRACT_PARALLEL_DIRS);
|
||||
|
||||
insertDirectiveToFile(file, file_name, createdDirectives[file_name], extract, getObjectForFileFromMap(file_name, SPF_messages));
|
||||
|
||||
if (mpiProgram == 0)
|
||||
{
|
||||
auto callGraph = getObjectForFileFromMap(file_name, allFuncInfo);
|
||||
map<string, FuncInfo*> mapFuncInfo;
|
||||
createMapOfFunc(callGraph, mapFuncInfo);
|
||||
|
||||
for (int z = 0; z < parallelRegions.size(); ++z)
|
||||
{
|
||||
ParallelRegion* currReg = parallelRegions[z];
|
||||
|
||||
const DataDirective& dataDirectives = currReg->GetDataDir();
|
||||
const vector<int>& currentVariant = currReg->GetCurrentVariant();
|
||||
const DIST::Arrays<int>& allArrays = currReg->GetAllArrays();
|
||||
DIST::GraphCSR<int, double, attrType>& reducedG = currReg->GetReducedGraphToModify();
|
||||
|
||||
const set<string> distrArrays = fillDistributedArrays(dataDirectives);
|
||||
const vector<string> distrRules = dataDirectives.GenRule(currentVariant);
|
||||
const vector<vector<dist>> distrRulesSt = dataDirectives.GenRule(currentVariant, 0);
|
||||
const vector<string> alignRules = dataDirectives.GenAlignsRules();
|
||||
|
||||
|
||||
insertDistributionToFile(file, file_name, dataDirectives, distrArrays, distrRules, distrRulesSt, alignRules, loopGraph,
|
||||
allArrays, reducedG, commentsToInclude, templateDeclInIncludes, extract, getObjectForFileFromMap(file_name, SPF_messages),
|
||||
arrayLinksByFuncCalls, mapFuncInfo, currReg->GetId(), allFileNames);
|
||||
|
||||
insertLoopTempalteDeclaration(file, dataDirectives, distrRules, distrRulesSt, allArrays, extract, currReg->GetId());
|
||||
}
|
||||
}
|
||||
|
||||
if (extract)
|
||||
{
|
||||
createdDirectives[file_name].clear();
|
||||
|
||||
//clear shadow specs
|
||||
for (auto& array : declaredArrays)
|
||||
array.second.first->ClearShadowSpecs();
|
||||
}
|
||||
else if (mpiProgram == 0)
|
||||
{
|
||||
set<uint64_t> regNum;
|
||||
for (int z = 0; z < parallelRegions.size(); ++z)
|
||||
regNum.insert(parallelRegions[z]->GetId());
|
||||
insertTemplateModuleUse(file, regNum, arrayLinksByFuncCalls);
|
||||
}
|
||||
insertParallelDirs(file, extract, createdDirectives[file_name], getObjectForFileFromMap(file_name, SPF_messages),
|
||||
templateDeclInIncludes, commentsToInclude, getObjectForFileFromMap(file_name, allFuncInfo),
|
||||
parallelRegions, loopGraph, allFileNames, arrayLinksByFuncCalls, declaredArrays, tableOfUniqNamesByArray);
|
||||
}
|
||||
else if (curr_regime == LOOP_ANALYZER_NODIST)
|
||||
{
|
||||
@@ -757,7 +610,7 @@ static bool runAnalysis(SgProject &project, const int curr_regime, const bool ne
|
||||
DataDirective &dataDirectives = currReg->GetDataDirToModify();
|
||||
DIST::GraphCSR<int, double, attrType> &reducedG = parallelRegions[z]->GetReducedGraphToModify();
|
||||
|
||||
set<string> distrArraysF = fillDistributedArrays(dataDirectives);
|
||||
set<string> distrArraysF = fillDistributedArrays(dataDirectives, tableOfUniqNamesByArray, arrayLinksByFuncCalls);
|
||||
|
||||
set<string> distrArrays;
|
||||
for (auto& elem : distrArraysF)
|
||||
@@ -774,7 +627,7 @@ static bool runAnalysis(SgProject &project, const int curr_regime, const bool ne
|
||||
{
|
||||
ParallelRegion* currReg = parallelRegions[z];
|
||||
DataDirective& dataDirectives = currReg->GetDataDirToModify();
|
||||
const set<DIST::Array*> distrCommonArrays = fillDistributedArraysD(dataDirectives, true);
|
||||
const set<DIST::Array*> distrCommonArrays = fillDistributedArraysD(dataDirectives, tableOfUniqNamesByArray, arrayLinksByFuncCalls, true);
|
||||
insertRealignsBeforeFragments(currReg, file, distrCommonArrays, arrayLinksByFuncCalls);
|
||||
}
|
||||
}
|
||||
@@ -1060,11 +913,7 @@ static bool runAnalysis(SgProject &project, const int curr_regime, const bool ne
|
||||
{
|
||||
auto founded = loopGraph.find(file->filename());
|
||||
if (founded != loopGraph.end())
|
||||
{
|
||||
int err = privateArraysResizing(file, founded->second, getObjectForFileFromMap(file_name, SPF_messages), usersDirectives, true);
|
||||
if (err != 0)
|
||||
internalExit = -1;
|
||||
}
|
||||
privateArraysResizing(file, founded->second, getObjectForFileFromMap(file_name, SPF_messages), countOfTransform, usersDirectives, true);
|
||||
}
|
||||
else if (curr_regime == PRIVATE_ARRAYS_SHRINKING_ANALYSIS)
|
||||
{
|
||||
@@ -1076,11 +925,7 @@ static bool runAnalysis(SgProject &project, const int curr_regime, const bool ne
|
||||
{
|
||||
auto founded = loopGraph.find(file->filename());
|
||||
if (founded != loopGraph.end())
|
||||
{
|
||||
int err = privateArraysResizing(file, founded->second, getObjectForFileFromMap(file_name, SPF_messages), usersDirectives, false);
|
||||
if (err != 0)
|
||||
internalExit = -1;
|
||||
}
|
||||
privateArraysResizing(file, founded->second, getObjectForFileFromMap(file_name, SPF_messages), countOfTransform, usersDirectives, false);
|
||||
}
|
||||
else if(curr_regime == LOOPS_SPLITTER)
|
||||
{
|
||||
@@ -1163,6 +1008,8 @@ static bool runAnalysis(SgProject &project, const int curr_regime, const bool ne
|
||||
for (SgStatement* st = file->firstStatement(); st; st = st->lexNext())
|
||||
removeOmpDir(st);
|
||||
}
|
||||
else if (curr_regime == PARSE_OMP_DIRS)
|
||||
parseOmpDirectives(file, getObjectForFileFromMap(file_name, SPF_messages));
|
||||
else if (curr_regime == REMOVE_COMMENTS)
|
||||
{
|
||||
for (SgStatement* st = file->firstStatement(); st; st = st->lexNext())
|
||||
@@ -1173,6 +1020,8 @@ static bool runAnalysis(SgProject &project, const int curr_regime, const bool ne
|
||||
getMaxMinBlockDistribution(file, min_max_block);
|
||||
else if (curr_regime == CONVERT_TO_C)
|
||||
covertToC(file);
|
||||
else if (curr_regime == SET_IMPLICIT_NONE)
|
||||
implicitCheck(file);
|
||||
else if (curr_regime == INSERT_NO_DISTR_FLAGS_FROM_GUI)
|
||||
addPrivatesToArraysFromGUI(file, declaredArrays, distrStateFromGUI);
|
||||
else if (curr_regime == REMOVE_DEAD_CODE)
|
||||
@@ -1192,7 +1041,8 @@ static bool runAnalysis(SgProject &project, const int curr_regime, const bool ne
|
||||
if (internalExit < 0)
|
||||
throw -1;
|
||||
|
||||
bool applyFor = (curr_regime == LOOPS_SPLITTER || curr_regime == LOOPS_COMBINER || curr_regime == PRIVATE_REMOVING);
|
||||
bool applyFor = (curr_regime == LOOPS_SPLITTER || curr_regime == LOOPS_COMBINER || curr_regime == PRIVATE_REMOVING ||
|
||||
curr_regime == PRIVATE_ARRAYS_EXPANSION || curr_regime == PRIVATE_ARRAYS_SHRINKING);
|
||||
if ((countOfTransform == 0 || internalExit > 0) && applyFor)
|
||||
{
|
||||
SgStatement* mainUnit = findMainUnit(&project, SPF_messages);
|
||||
@@ -2077,8 +1927,7 @@ 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 == SELECT_ARRAY_DIM_CONF) {
|
||||
SelectArrayConfForParallelization(&project, allFuncInfo, loopGraph, createdDirectives, SPF_messages, arrayLinksByFuncCalls, parallelRegions);
|
||||
removeRegionsWithoutDirs(createdDirectives, parallelRegions, allFuncInfo, SPF_messages);
|
||||
SelectArrayConfForParallelization(&project, allFuncInfo, loopGraph, SPF_messages, arrayLinksByFuncCalls);
|
||||
}
|
||||
else if (curr_regime == GET_MIN_MAX_BLOCK_DIST)
|
||||
{
|
||||
@@ -2308,8 +2157,6 @@ void runPass(const int curr_regime, const char *proj_name, const char *folderNam
|
||||
|
||||
runPass(CONVERT_LOOP_TO_ASSIGN, proj_name, folderName);
|
||||
|
||||
runPass(SELECT_ARRAY_DIM_CONF, proj_name, folderName);
|
||||
|
||||
runPass(REVERT_SUBST_EXPR_RD, proj_name, folderName);
|
||||
|
||||
runAnalysis(*project, INSERT_PARALLEL_DIRS, false, consoleMode ? additionalName.c_str() : NULL, folderName);
|
||||
@@ -2534,6 +2381,7 @@ void runPass(const int curr_regime, const char *proj_name, const char *folderNam
|
||||
case LOOPS_COMBINER:
|
||||
case FIX_COMMON_BLOCKS:
|
||||
case TEST_PASS:
|
||||
case SET_IMPLICIT_NONE:
|
||||
runAnalysis(*project, curr_regime, false);
|
||||
case SUBST_EXPR_RD_AND_UNPARSE:
|
||||
case SUBST_EXPR_AND_UNPARSE:
|
||||
|
||||
@@ -169,6 +169,7 @@ enum passes {
|
||||
REMOVE_DEAD_CODE_AND_UNPARSE,
|
||||
|
||||
FIX_COMMON_BLOCKS,
|
||||
PARSE_OMP_DIRS,
|
||||
REMOVE_OMP_DIRS,
|
||||
REMOVE_OMP_DIRS_TRANSFORM,
|
||||
REMOVE_COMMENTS,
|
||||
@@ -176,6 +177,8 @@ enum passes {
|
||||
CONVERT_TO_C,
|
||||
INSERT_NO_DISTR_FLAGS_FROM_GUI,
|
||||
|
||||
SET_IMPLICIT_NONE,
|
||||
|
||||
TEST_PASS,
|
||||
EMPTY_PASS
|
||||
};
|
||||
@@ -349,11 +352,13 @@ static void setPassValues()
|
||||
passNames[REMOVE_DEAD_CODE_AND_UNPARSE] = "REMOVE_DEAD_CODE_AND_UNPARSE";
|
||||
|
||||
passNames[FIX_COMMON_BLOCKS] = "FIX_COMMON_BLOCKS";
|
||||
passNames[PARSE_OMP_DIRS] = "PARSE_OMP_DIRS";
|
||||
passNames[REMOVE_OMP_DIRS] = "REMOVE_OMP_DIRS";
|
||||
passNames[REMOVE_OMP_DIRS_TRANSFORM] = "REMOVE_OMP_DIRS_TRANSFORM";
|
||||
passNames[REMOVE_COMMENTS] = "REMOVE_COMMENTS";
|
||||
passNames[GET_MIN_MAX_BLOCK_DIST] = "GET_MIN_MAX_BLOCK_DIST";
|
||||
passNames[CONVERT_TO_C] = "CONVERT_TO_C";
|
||||
passNames[SET_IMPLICIT_NONE] = "SET_IMPLICIT_NONE";
|
||||
passNames[INSERT_NO_DISTR_FLAGS_FROM_GUI] = "INSERT_NO_DISTR_FLAGS_FROM_GUI";
|
||||
|
||||
passNames[TEST_PASS] = "TEST_PASS";
|
||||
|
||||
@@ -13,7 +13,7 @@ using std::set;
|
||||
|
||||
using std::remove_if;
|
||||
|
||||
#define PRINT_USELESS_STATEMENTS 0
|
||||
#define PRINT_USELESS_STATEMENTS 1
|
||||
|
||||
static void updateUseDefForInstruction(SAPFOR::BasicBlock* block, SAPFOR::Instruction* instr,
|
||||
set<SAPFOR::Argument*>& use, set<SAPFOR::Argument*>& def,
|
||||
@@ -329,10 +329,22 @@ public:
|
||||
|
||||
void removeDeadCode(SgStatement* func,
|
||||
const map<string, vector<FuncInfo*>>& allFuncs,
|
||||
const map<string, CommonBlock*>& commonBlocks)
|
||||
const map<string, CommonBlock*>& commonBlocks,
|
||||
SgStatement* intervalDelStart, SgStatement* intervalDelEnd)
|
||||
{
|
||||
if (intervalDelStart && !intervalDelEnd || !intervalDelStart && intervalDelEnd)
|
||||
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
||||
|
||||
SgProgHedrStmt* prog = isSgProgHedrStmt(func);
|
||||
|
||||
if (intervalDelStart)
|
||||
if (intervalDelStart->lineNumber() < prog->lineNumber() || intervalDelStart->lineNumber() > prog->lastNodeOfStmt()->lineNumber())
|
||||
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
||||
|
||||
if (intervalDelEnd)
|
||||
if (intervalDelEnd->lineNumber() < prog->lineNumber() || intervalDelEnd->lineNumber() > prog->lastNodeOfStmt()->lineNumber())
|
||||
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
||||
|
||||
auto cfg = buildCFGforCurrentFunc(func, SAPFOR::CFG_Settings(true, false, false, false, false, false, false), commonBlocks, allFuncs);
|
||||
|
||||
if(cfg.size() != 1)
|
||||
@@ -424,9 +436,6 @@ void removeDeadCode(SgStatement* func,
|
||||
}
|
||||
|
||||
// remove dead statements
|
||||
|
||||
SgStatement* end = func->lastNodeOfStmt(), *st = func;
|
||||
|
||||
set<int> removable =
|
||||
{
|
||||
ASSIGN_STAT,
|
||||
@@ -435,49 +444,55 @@ void removeDeadCode(SgStatement* func,
|
||||
READ_STAT
|
||||
};
|
||||
|
||||
while (st != end)
|
||||
{
|
||||
SgStatement* next = st->lexNext();
|
||||
vector<SgStatement*> remove;
|
||||
SgStatement* start = intervalDelStart ? intervalDelStart : func;
|
||||
SgStatement* end = intervalDelEnd ? intervalDelEnd : func->lastNodeOfStmt();
|
||||
|
||||
for (auto st = start; st != end; st = st->lexNext())
|
||||
{
|
||||
if (removable.find(st->variant()) != removable.end() && useful.find(st) == useful.end())
|
||||
{
|
||||
__spf_print(PRINT_USELESS_STATEMENTS, "[Useless statement '%s' on line %d]\n", st->unparse(), st->lineNumber());
|
||||
|
||||
st->deleteStmt();
|
||||
remove.push_back(st);
|
||||
st = st->lastNodeOfStmt();
|
||||
}
|
||||
else
|
||||
}
|
||||
|
||||
for (auto& rem : remove)
|
||||
{
|
||||
if (isSgControlEndStmt(st))
|
||||
__spf_print(PRINT_USELESS_STATEMENTS, "[Useless statement on line %d and file %s]\n", rem->lineNumber(), rem->fileName());
|
||||
rem->deleteStmt();
|
||||
}
|
||||
|
||||
remove.clear();
|
||||
//remove empty blocks
|
||||
for (auto st = start; st != end; st = st->lexNext())
|
||||
{
|
||||
SgStatement* parent = st->controlParent();
|
||||
SgStatement* parent_end;
|
||||
|
||||
if (parent && (parent_end = parent->lastNodeOfStmt()) && parent_end == st)
|
||||
const int var = st->variant();
|
||||
if ((var == FOR_NODE || var == WHILE_NODE || var == IF_NODE || var == SWITCH_NODE) &&
|
||||
st->lexNext()->variant() == CONTROL_END)
|
||||
{
|
||||
bool empty_parent = false;
|
||||
remove.push_back(st);
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (parent->variant())
|
||||
if (var == IF_NODE)
|
||||
{
|
||||
case IF_NODE:
|
||||
empty_parent =
|
||||
parent->lexNext() == parent_end || // IF THEN ENDIF
|
||||
isSgControlEndStmt(parent->lexNext()) &&
|
||||
parent->lexNext()->lexNext() == parent_end; // IF THEN ELSE ENDIF
|
||||
break;
|
||||
default:
|
||||
empty_parent = parent->lexNext() == parent_end; // DO, WHILE
|
||||
break;
|
||||
SgStatement* ifS = st;
|
||||
while (ifS->lexNext()->variant() == ELSEIF_NODE)
|
||||
ifS = ifS->lexNext();
|
||||
|
||||
if (ifS->lexNext()->variant() == CONTROL_END)
|
||||
remove.push_back(st);
|
||||
}
|
||||
|
||||
if (empty_parent)
|
||||
parent->deleteStmt();
|
||||
else if(isSgIfStmt(parent) && isSgControlEndStmt(parent_end->lexPrev())) // IF with empty ELSE branch
|
||||
parent_end->deleteStmt();
|
||||
}
|
||||
}
|
||||
//TODO: SWITCH and other block statements
|
||||
}
|
||||
|
||||
st = next;
|
||||
|
||||
for (auto& rem : remove)
|
||||
{
|
||||
__spf_print(PRINT_USELESS_STATEMENTS, "[Useless block statement on line %d and file %s]\n", rem->lineNumber(), rem->fileName());
|
||||
rem->deleteStmt();
|
||||
}
|
||||
|
||||
deleteCFG(cfg);
|
||||
|
||||
@@ -11,4 +11,5 @@
|
||||
|
||||
void removeDeadCode(SgStatement* func,
|
||||
const std::map<std::string, std::vector<FuncInfo*>>&allFuncs,
|
||||
const std::map<std::string, CommonBlock*>& commonBlocks);
|
||||
const std::map<std::string, CommonBlock*>& commonBlocks,
|
||||
SgStatement* intervalDelStart = NULL, SgStatement* intervalDelEnd = NULL);
|
||||
@@ -89,19 +89,24 @@ static void fillIterationVariables(const LoopGraph* loop, set<string>& vars, int
|
||||
}
|
||||
}
|
||||
|
||||
static SgExpression* findSymbolInExprList(SgSymbol* symbol, SgExpression* list)
|
||||
static SgExpression* findSymbol(SgSymbol* symbol, SgExpression* list)
|
||||
{
|
||||
while (list)
|
||||
if (list)
|
||||
{
|
||||
if (list->variant() != EXPR_LIST || list->lhs()->symbol() == NULL)
|
||||
return NULL;
|
||||
|
||||
if (isEqSymbols(list->lhs()->symbol(), symbol))
|
||||
return list->lhs();
|
||||
|
||||
list = list->rhs();
|
||||
if (list->variant() == VAR_REF || list->variant() == ARRAY_REF)
|
||||
{
|
||||
if (isEqSymbols(list->symbol(), symbol))
|
||||
return list;
|
||||
}
|
||||
|
||||
auto left = findSymbol(symbol, list->lhs());
|
||||
if (left)
|
||||
return left;
|
||||
|
||||
auto right = findSymbol(symbol, list->rhs());
|
||||
if (right)
|
||||
return right;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -135,13 +140,17 @@ static const string constructNewBoundName(const char *oldName, int loopLineNumbe
|
||||
return newName;
|
||||
}
|
||||
|
||||
static SgSymbol* createNewArrayNameSymbol(SgExpression* declaration, bool isExpansion)
|
||||
static SgSymbol* createNewArrayNameSymbol(SgExpression* declaration, bool isExpansion, bool canBeStatic)
|
||||
{
|
||||
SgType* type = new SgType(T_ARRAY);
|
||||
char* newNameStr = constructNewArrayName(declaration->symbol()->identifier(), isExpansion);
|
||||
SgSymbol* newName = new SgSymbol(VARIABLE_NAME, newNameStr, type, NULL);
|
||||
newName->setAttribute(declaration->symbol()->attributes());
|
||||
|
||||
auto attrs = declaration->symbol()->attributes();
|
||||
if (!canBeStatic)
|
||||
attrs |= ALLOCATABLE_BIT;
|
||||
|
||||
newName->setAttribute(attrs);
|
||||
return newName;
|
||||
}
|
||||
|
||||
@@ -155,7 +164,17 @@ static void fillLoopBoundExprs(const LoopGraph* forLoop, int depthOfResize, cons
|
||||
{
|
||||
if (indexes[j] && isEqSymbols(loopStmt->doName(), indexes[j]))
|
||||
{
|
||||
//TODO: add MIN and MAX call for bounds
|
||||
if (curLoop->stepVal == 0)
|
||||
{
|
||||
__spf_print(1, "unknown step sign of loop on line %d\n", curLoop->lineNum);
|
||||
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
||||
}
|
||||
|
||||
if (curLoop->stepVal > 0)
|
||||
bounds[j] = new SgExpression(DDOT, loopStmt->start()->copyPtr(), loopStmt->end()->copyPtr(), NULL);
|
||||
else
|
||||
bounds[j] = new SgExpression(DDOT, loopStmt->end()->copyPtr(), loopStmt->start()->copyPtr(), NULL);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -257,11 +276,10 @@ static SgExpression* constructExtendedArrayRefTail(SgExpression* oldTail, const
|
||||
return newTail;
|
||||
}
|
||||
|
||||
static SgExpression* extendArrayRef(const vector<SgSymbol*>& indexes, SgExpression* expressionToExtend,
|
||||
static void extendArrayRef(const vector<SgSymbol*>& indexes, SgExpression*& expressionToExtend,
|
||||
SgSymbol* newSymbol, const vector<SgExpression*>& lowBounds)
|
||||
{
|
||||
SgExpression* newTail = constructExtendedArrayRefTail(expressionToExtend->lhs(), indexes);
|
||||
|
||||
SgExpression* oldTail = expressionToExtend->lhs();
|
||||
if (oldTail == NULL)
|
||||
{
|
||||
@@ -286,8 +304,6 @@ static SgExpression* extendArrayRef(const vector<SgSymbol*>& indexes, SgExpressi
|
||||
expressionToExtend->setLhs(newTail);
|
||||
expressionToExtend->setSymbol(newSymbol);
|
||||
}
|
||||
|
||||
return expressionToExtend;
|
||||
}
|
||||
|
||||
static bool isAllocatable(SgSymbol* symbol)
|
||||
@@ -328,14 +344,50 @@ static void setAllocatable(SgStatement *newDecl, SgSymbol *origSymbol)
|
||||
}
|
||||
}
|
||||
|
||||
static SgExpression* checkArrayDecl(SgExpression* array, SgSymbol* arraySymbol, SgStatement* checkedDecl)
|
||||
{
|
||||
if (array->lhs() == NULL)
|
||||
{
|
||||
vector<SgStatement*> allDecls;
|
||||
auto mainDecl = declaratedInStmt(arraySymbol, &allDecls);
|
||||
if (allDecls.size() == 0)
|
||||
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
||||
|
||||
if (allDecls.size() == 1)
|
||||
{
|
||||
array = findSymbol(arraySymbol, mainDecl->expr(0));
|
||||
checkNull(array, convertFileName(__FILE__).c_str(), __LINE__);
|
||||
return array;
|
||||
}
|
||||
|
||||
for (auto& decl : allDecls)
|
||||
{
|
||||
if (decl == mainDecl)
|
||||
continue;
|
||||
if (decl == checkedDecl)
|
||||
continue;
|
||||
|
||||
array = findSymbol(arraySymbol, decl->expr(0));
|
||||
if (array->lhs())
|
||||
break;
|
||||
array = NULL;
|
||||
}
|
||||
|
||||
checkNull(array, convertFileName(__FILE__).c_str(), __LINE__);
|
||||
}
|
||||
|
||||
return array;
|
||||
}
|
||||
|
||||
static SgSymbol* alterExtendArrayDeclaration(const LoopGraph* forLoop, SgStatement* declarationStmt, SgSymbol* arraySymbol,
|
||||
bool canBeStatic, const vector<SgSymbol*>& indexes)
|
||||
{
|
||||
SgSymbol* newArraySymbol = NULL;
|
||||
SgExpression* array = findSymbolInExprList(arraySymbol, declarationStmt->expr(0));
|
||||
SgExpression* array = findSymbol(arraySymbol, declarationStmt->expr(0));
|
||||
array = checkArrayDecl(array, arraySymbol, declarationStmt);
|
||||
|
||||
SgExpression* newArray = array->copyPtr();
|
||||
newArraySymbol = createNewArrayNameSymbol(newArray, true);
|
||||
newArraySymbol = createNewArrayNameSymbol(newArray, true, canBeStatic);
|
||||
if (newArraySymbol == NULL)
|
||||
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
||||
|
||||
@@ -350,13 +402,14 @@ static SgSymbol* alterExtendArrayDeclaration(const LoopGraph* forLoop, SgStateme
|
||||
return newArraySymbol;
|
||||
}
|
||||
|
||||
static SgSymbol* alterShrinkArrayDeclaration(SgStatement *declarationStatement, SgSymbol *arraySymbol, vector<int> &dimensions)
|
||||
static SgSymbol* alterShrinkArrayDeclaration(SgStatement *declarationStatement, SgSymbol *arraySymbol,
|
||||
vector<int> &dimensions, bool canBeStatic)
|
||||
{
|
||||
SgSymbol *newArraySymbol = NULL;
|
||||
SgExpression *array = findSymbolInExprList(arraySymbol, declarationStatement->expr(0));
|
||||
SgExpression *array = findSymbol(arraySymbol, declarationStatement->expr(0));
|
||||
|
||||
SgExpression *newArray = array->copyPtr();
|
||||
newArraySymbol = createNewArrayNameSymbol(newArray, false);
|
||||
newArraySymbol = createNewArrayNameSymbol(newArray, false, canBeStatic);
|
||||
|
||||
reduceArray(dimensions, newArray, newArraySymbol);
|
||||
|
||||
@@ -369,35 +422,40 @@ static SgSymbol* alterShrinkArrayDeclaration(SgStatement *declarationStatement,
|
||||
return newArraySymbol;
|
||||
}
|
||||
|
||||
static void extendArrayRefsInExpr(const vector<SgSymbol*>& indexes, SgExpression* expr, SgSymbol* arraySymbol,
|
||||
SgSymbol* newArraySymbol, const vector<SgExpression*>& lowBounds)
|
||||
static void extendArrayRefsInExpr(const vector<SgSymbol*>& indexes, SgExpression*& expr,
|
||||
SgSymbol* arraySymbol, SgSymbol* newArraySymbol,
|
||||
const vector<SgExpression*>& lowBounds, int line)
|
||||
{
|
||||
SgExpression *lhs = expr->lhs(), *rhs = expr->rhs();
|
||||
|
||||
if (lhs)
|
||||
if (expr)
|
||||
{
|
||||
if (isArrayRef(lhs) && isEqSymbols(arraySymbol, lhs->symbol()))
|
||||
extendArrayRef(indexes, lhs, newArraySymbol, lowBounds);
|
||||
else if (lhs->variant() == VAR_REF && isEqSymbols(arraySymbol, lhs->symbol()))
|
||||
if (expr->variant() == FUNC_CALL)
|
||||
{
|
||||
SgExpression* extended = extendArrayRef(indexes, lhs, newArraySymbol, lowBounds);
|
||||
expr->setLhs(extended);
|
||||
SgFunctionCallExp* call = isSgFunctionCallExp(expr);
|
||||
for (int arg = 0; arg < call->numberOfArgs(); ++arg)
|
||||
{
|
||||
auto argRef = call->arg(arg);
|
||||
if ((isArrayRef(argRef) || argRef->variant() == VAR_REF) && isEqSymbols(argRef->symbol(), arraySymbol))
|
||||
{
|
||||
__spf_print(1, "unsupported private array extension under call on line %d\n", line);
|
||||
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
||||
}
|
||||
}
|
||||
else
|
||||
extendArrayRefsInExpr(indexes, lhs, arraySymbol, newArraySymbol, lowBounds);
|
||||
}
|
||||
|
||||
if (rhs)
|
||||
{
|
||||
if (isArrayRef(rhs) && isEqSymbols(arraySymbol, rhs->symbol()))
|
||||
extendArrayRef(indexes, rhs, newArraySymbol, lowBounds);
|
||||
else if (rhs->variant() == VAR_REF && isEqSymbols(arraySymbol, rhs->symbol()))
|
||||
{
|
||||
SgExpression* extended = extendArrayRef(indexes, rhs, newArraySymbol, lowBounds);
|
||||
expr->setRhs(extended);
|
||||
}
|
||||
else
|
||||
extendArrayRefsInExpr(indexes, rhs, arraySymbol, newArraySymbol, lowBounds);
|
||||
SgExpression* left = expr->lhs();
|
||||
extendArrayRefsInExpr(indexes, left, arraySymbol, newArraySymbol, lowBounds, line);
|
||||
if (left != expr->lhs())
|
||||
expr->setLhs(left);
|
||||
|
||||
SgExpression* right = expr->rhs();
|
||||
extendArrayRefsInExpr(indexes, right, arraySymbol, newArraySymbol, lowBounds, line);
|
||||
if (right != expr->rhs())
|
||||
expr->setRhs(right);
|
||||
|
||||
if (isArrayRef(expr) && isEqSymbols(arraySymbol, expr->symbol()))
|
||||
extendArrayRef(indexes, expr, newArraySymbol, lowBounds);
|
||||
else if (expr->variant() == VAR_REF && isEqSymbols(arraySymbol, expr->symbol()))
|
||||
extendArrayRef(indexes, expr, newArraySymbol, lowBounds);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -406,17 +464,26 @@ static void extendArrayRefs(const vector<SgSymbol*> &indexes, SgStatement *st, S
|
||||
{
|
||||
for (int i = 0; i < 3; ++i)
|
||||
{
|
||||
if (st->variant() == PROC_STAT)
|
||||
{
|
||||
SgCallStmt* call = isSgCallStmt(st);
|
||||
for (int arg = 0; arg < call->numberOfArgs(); ++arg)
|
||||
{
|
||||
auto argRef = call->arg(arg);
|
||||
if ((isArrayRef(argRef) || argRef->variant() == VAR_REF) && isEqSymbols(argRef->symbol(), arraySymbol))
|
||||
{
|
||||
__spf_print(1, "unsupported private array extension under call on line %d\n", st->lineNumber());
|
||||
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (st->expr(i))
|
||||
{
|
||||
if (isArrayRef(st->expr(i)) && isEqSymbols(arraySymbol, st->expr(i)->symbol()))
|
||||
extendArrayRef(indexes, st->expr(i), newArraySymbol, lowBounds);
|
||||
else if (st->expr(i)->variant() == VAR_REF && isEqSymbols(arraySymbol, st->expr(i)->symbol()))
|
||||
{
|
||||
SgExpression* extended = extendArrayRef(indexes, st->expr(i), newArraySymbol, lowBounds);
|
||||
st->setExpression(i, *extended);
|
||||
}
|
||||
else
|
||||
extendArrayRefsInExpr(indexes, st->expr(i), arraySymbol, newArraySymbol, lowBounds);
|
||||
SgExpression* ex = st->expr(i);
|
||||
extendArrayRefsInExpr(indexes, ex, arraySymbol, newArraySymbol, lowBounds, st->lineNumber());
|
||||
if (ex != st->expr(i))
|
||||
st->setExpression(i, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -428,6 +495,8 @@ static SgStatement* createNewDeclarationStatemnet(SgStatement *loop, SgStatement
|
||||
{
|
||||
if (isSgExecutableStatement(lastDecl))
|
||||
break;
|
||||
if (lastDecl->variant() == CONTAINS_STMT)
|
||||
break;
|
||||
lastDecl = lastDecl->lexNext();
|
||||
}
|
||||
|
||||
@@ -435,7 +504,9 @@ static SgStatement* createNewDeclarationStatemnet(SgStatement *loop, SgStatement
|
||||
while (!isEqSymbols(exprList->lhs()->symbol(), arraySymbol))
|
||||
exprList = exprList->rhs();
|
||||
|
||||
SgExpression newExprList(EXPR_LIST, exprList->lhs(), NULL, NULL);
|
||||
checkNull(exprList, convertFileName(__FILE__).c_str(), __LINE__);
|
||||
|
||||
SgExpression newExprList(EXPR_LIST, exprList->lhs()->copyPtr(), NULL, NULL);
|
||||
SgStatement *newDeclaration = originalDeclaration->copyPtr();
|
||||
|
||||
newDeclaration->setExpression(0, newExprList);
|
||||
@@ -479,7 +550,7 @@ static SgStatement* getAllocationStmt(const LoopGraph* loop, SgSymbol* symbol)
|
||||
if (alloc->variant() != ALLOCATE_STMT)
|
||||
continue;
|
||||
|
||||
if (NULL == findSymbolInExprList(symbol, alloc->expr(0)))
|
||||
if (findSymbol(symbol, alloc->expr(0)) == NULL)
|
||||
continue;
|
||||
|
||||
if (allocationStmt == NULL)
|
||||
@@ -502,10 +573,10 @@ static void fillLowBounds(const LoopGraph* forLoop, SgSymbol* origArraySymbol, S
|
||||
if (isAllocatable(origArraySymbol))
|
||||
{
|
||||
SgStatement* allocationStmt = getAllocationStmt(forLoop, origArraySymbol);
|
||||
origArray = findSymbolInExprList(origArraySymbol, allocationStmt->expr(0));
|
||||
origArray = findSymbol(origArraySymbol, allocationStmt->expr(0));
|
||||
}
|
||||
else
|
||||
origArray = findSymbolInExprList(origArraySymbol, originalDecl->expr(0));
|
||||
origArray = findSymbol(origArraySymbol, originalDecl->expr(0));
|
||||
|
||||
SgExpression* arrayRef = origArray->copyPtr();
|
||||
SgExpression* oldTail = arrayRef->lhs();
|
||||
@@ -559,7 +630,7 @@ static SgExpression* constructArrayAllocationExp(const LoopGraph* forLoop, SgExp
|
||||
return new SgExpression(EXPR_LIST, arrayRef, (SgExpression*)NULL, (SgSymbol*)NULL);
|
||||
}
|
||||
|
||||
static void insertAllocDealloc(const LoopGraph* forLoop, SgSymbol* origArraySymbol, SgSymbol* arraySymbol,
|
||||
static void insertAllocDealloc(const LoopGraph* forLoop, SgSymbol* origArraySymbol, SgSymbol* arraySymbol, SgSymbol* allocDone,
|
||||
bool isExpansion, const vector<SgSymbol*>* indexes = NULL, const vector<int>* shrinkIndexes = NULL)
|
||||
{
|
||||
SgForStmt *loopStmt = (SgForStmt*)(forLoop->loop->GetOriginal());
|
||||
@@ -571,10 +642,13 @@ static void insertAllocDealloc(const LoopGraph* forLoop, SgSymbol* origArraySymb
|
||||
if (isAllocatable(origArraySymbol))
|
||||
{
|
||||
SgStatement *allocationStmt = getAllocationStmt(forLoop, origArraySymbol);
|
||||
origArray = findSymbolInExprList(origArraySymbol, allocationStmt->expr(0));
|
||||
origArray = findSymbol(origArraySymbol, allocationStmt->expr(0));
|
||||
}
|
||||
else
|
||||
origArray = findSymbolInExprList(origArraySymbol, originalDeclaration->expr(0));
|
||||
{
|
||||
origArray = findSymbol(origArraySymbol, originalDeclaration->expr(0));
|
||||
origArray = checkArrayDecl(origArray, origArraySymbol, originalDeclaration);
|
||||
}
|
||||
|
||||
int depthOfResize = 0;
|
||||
if (isExpansion)
|
||||
@@ -589,11 +663,17 @@ static void insertAllocDealloc(const LoopGraph* forLoop, SgSymbol* origArraySymb
|
||||
new SgExpression(ARRAY_REF, (SgExpression*)NULL, (SgExpression*)NULL, arraySymbol),
|
||||
(SgExpression*)NULL, (SgSymbol*)NULL);
|
||||
|
||||
SgStatement *allocate = new SgStatement(ALLOCATE_STMT, (SgLabel*)NULL, (SgSymbol*)NULL, arrayAllocation, (SgExpression*)NULL, (SgExpression*)NULL);
|
||||
SgStatement *deallocate = new SgStatement(DEALLOCATE_STMT, (SgLabel*)NULL, (SgSymbol*)NULL, arrayDeallocation, (SgExpression*)NULL, (SgExpression*)NULL);
|
||||
|
||||
loopStmt->insertStmtBefore(*allocate, *loopStmt->controlParent());
|
||||
loopStmt->lastNodeOfStmt()->insertStmtAfter(*deallocate, *loopStmt->controlParent());
|
||||
|
||||
SgStatement *allocate = new SgStatement(ALLOCATE_STMT, (SgLabel*)NULL, (SgSymbol*)NULL, arrayAllocation, (SgExpression*)NULL, (SgExpression*)NULL);
|
||||
SgIfStmt* ifSt = new SgIfStmt(SgEqOp(*new SgVarRefExp(allocDone), *new SgValueExp(0)), *allocate);
|
||||
|
||||
loopStmt->insertStmtBefore(*ifSt, *loopStmt->controlParent());
|
||||
|
||||
|
||||
// insert allocates as save
|
||||
//SgStatement* deallocate = new SgStatement(DEALLOCATE_STMT, (SgLabel*)NULL, (SgSymbol*)NULL, arrayDeallocation, (SgExpression*)NULL, (SgExpression*)NULL);
|
||||
//loopStmt->lastNodeOfStmt()->insertStmtAfter(*deallocate, *loopStmt->controlParent());
|
||||
}
|
||||
|
||||
static bool containsFunctionCall(SgExpression* exp)
|
||||
@@ -734,7 +814,7 @@ static void reduceArrayRefs(SgStatement *st, SgSymbol *arraySymbol, SgSymbol *ne
|
||||
|
||||
static void fillIndexesToShrink(SgSymbol* arr, SgExprListExp* listExp, vector<int>& indexes)
|
||||
{
|
||||
SgExpression* sym = findSymbolInExprList(arr, listExp);
|
||||
SgExpression* sym = findSymbol(arr, listExp);
|
||||
if (sym)
|
||||
{
|
||||
SgExpression* expr = sym->lhs();
|
||||
@@ -781,6 +861,61 @@ static void renamePrivateVarsInAttributes(const vector<SgStatement*>& attrs, con
|
||||
}
|
||||
}
|
||||
|
||||
static void removePrivateVarsInAttributes(const vector<SgStatement*>& attrs, const map<SgSymbol*, SgSymbol*>& symbols)
|
||||
{
|
||||
for (SgStatement* st : attrs)
|
||||
{
|
||||
if (st->variant() != SPF_ANALYSIS_DIR)
|
||||
return;
|
||||
|
||||
SgExpression* exprList = st->expr(0);
|
||||
vector<SgExpression*> newL;
|
||||
bool remList = false;
|
||||
while (exprList)
|
||||
{
|
||||
if (exprList->lhs()->variant() == ACC_PRIVATE_OP)
|
||||
{
|
||||
vector<SgExpression*> newL;
|
||||
bool removed = false;
|
||||
SgExpression* list = exprList->lhs()->lhs();
|
||||
while (list)
|
||||
{
|
||||
bool found = false;
|
||||
for (auto& pair : symbols)
|
||||
{
|
||||
if (isEqSymbols(pair.first, list->lhs()->symbol()))
|
||||
found = true;
|
||||
if (found)
|
||||
break;
|
||||
}
|
||||
if (!found)
|
||||
newL.push_back(list->lhs());
|
||||
else
|
||||
removed = true;
|
||||
list = list->rhs();
|
||||
}
|
||||
|
||||
if (removed)
|
||||
{
|
||||
if (newL.size() == 0)
|
||||
remList = true;
|
||||
else
|
||||
{
|
||||
exprList->lhs()->setLhs(makeExprList(newL));
|
||||
newL.push_back(exprList->lhs());
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
newL.push_back(exprList->lhs());
|
||||
exprList = exprList->rhs();
|
||||
}
|
||||
|
||||
if (remList)
|
||||
st->setExpression(0, makeExprList(newL));
|
||||
}
|
||||
}
|
||||
|
||||
static int getArrayDimensionality(SgSymbol* array)
|
||||
{
|
||||
if (array->type()->variant() != T_ARRAY)
|
||||
@@ -975,7 +1110,7 @@ static int fillIndexesToExtend(const LoopGraph* loop, int origDim, int depthOfRe
|
||||
return 0;
|
||||
}
|
||||
|
||||
static SgSymbol* shrinkArray(const LoopGraph *forLoop, SgSymbol *arraySymbol, vector<int> &indexes)
|
||||
static SgSymbol* shrinkArray(const LoopGraph *forLoop, SgSymbol *arraySymbol, vector<int> &indexes, SgSymbol *allocDone)
|
||||
{
|
||||
int maxDepth = forLoop->perfectLoop;
|
||||
const LoopGraph *curLoop = forLoop;
|
||||
@@ -1005,16 +1140,17 @@ static SgSymbol* shrinkArray(const LoopGraph *forLoop, SgSymbol *arraySymbol, ve
|
||||
SgStatement *originalDeclaration = declaratedInStmt(arraySymbol);
|
||||
SgStatement *copiedDeclaration = createNewDeclarationStatemnet(forLoop->loop->GetOriginal(), originalDeclaration, arraySymbol);
|
||||
|
||||
bool canBeStatic = !(!reduceToVariable && isAllocatable(arraySymbol));
|
||||
SgSymbol *newSymbol = reduceToVariable
|
||||
? createReducedToVariableArray(copiedDeclaration, forLoop->lineNum, arraySymbol)
|
||||
: alterShrinkArrayDeclaration(copiedDeclaration, arraySymbol, indexes);
|
||||
: alterShrinkArrayDeclaration(copiedDeclaration, arraySymbol, indexes, canBeStatic);
|
||||
|
||||
if (newSymbol)
|
||||
{
|
||||
SgForStmt *loopStmt = (SgForStmt*)(forLoop->loop->GetOriginal());
|
||||
|
||||
if (!reduceToVariable && isAllocatable(arraySymbol))
|
||||
insertAllocDealloc(forLoop, arraySymbol, newSymbol, false, NULL, &indexes);
|
||||
insertAllocDealloc(forLoop, arraySymbol, newSymbol, allocDone, false, NULL, &indexes);
|
||||
|
||||
for (SgStatement *st = loopStmt->lexNext(); st != loopStmt->lastNodeOfStmt()->lexNext(); st = st->lexNext())
|
||||
if (st->variant() != ALLOCATE_STMT && st->variant() != DEALLOCATE_STMT)
|
||||
@@ -1026,7 +1162,7 @@ static SgSymbol* shrinkArray(const LoopGraph *forLoop, SgSymbol *arraySymbol, ve
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static SgSymbol* resizeArray(const LoopGraph *forLoop, SgSymbol *arraySymbol, int depthOfResize)
|
||||
static SgSymbol* resizeArray(const LoopGraph *forLoop, SgSymbol *arraySymbol, int depthOfResize, SgSymbol *allocDone)
|
||||
{
|
||||
if (depthOfResize < 0 || depthOfResize > forLoop->perfectLoop)
|
||||
depthOfResize = forLoop->perfectLoop;
|
||||
@@ -1043,7 +1179,8 @@ static SgSymbol* resizeArray(const LoopGraph *forLoop, SgSymbol *arraySymbol, in
|
||||
|
||||
for (int i = 0; i < depthOfResize; ++i)
|
||||
{
|
||||
if (curLoop->calculatedCountOfIters == 0)
|
||||
//TODO: add checking for PARAMETER
|
||||
//if (curLoop->calculatedCountOfIters == 0)
|
||||
canBeStatic = false;
|
||||
|
||||
if (areIndexesFilled != 0)
|
||||
@@ -1074,7 +1211,8 @@ static SgSymbol* resizeArray(const LoopGraph *forLoop, SgSymbol *arraySymbol, in
|
||||
{
|
||||
SgForStmt *loopStmt = (SgForStmt*)(forLoop->loop->GetOriginal());
|
||||
if (!canBeStatic || isAllocatable(newArraySymbol))
|
||||
insertAllocDealloc(forLoop, arraySymbol, newArraySymbol, true, &indexes, NULL);
|
||||
insertAllocDealloc(forLoop, arraySymbol, newArraySymbol, allocDone, true, &indexes, NULL);
|
||||
|
||||
for (SgStatement *st = loopStmt->lexNext(); st != loopStmt->lastNodeOfStmt()->lexNext(); st = st->lexNext())
|
||||
if (st->variant() != ALLOCATE_STMT && st->variant() != DEALLOCATE_STMT)
|
||||
extendArrayRefs(indexes, st, arraySymbol, newArraySymbol, lowBounds);
|
||||
@@ -1257,13 +1395,27 @@ void analyzeShrinking(SgFile* file, const vector<LoopGraph*>& loopGraphs, vector
|
||||
}
|
||||
}
|
||||
|
||||
static void createAllocDoneSymbol(map<SgStatement*, SgSymbol*>& allocDoneByFunc, SgStatement* func)
|
||||
{
|
||||
if (allocDoneByFunc.find(func) == allocDoneByFunc.end())
|
||||
{
|
||||
auto newName = (string("spf_") + string(func->symbol()->identifier()) + "_alloc_");
|
||||
allocDoneByFunc[func] = new SgSymbol(VARIABLE_NAME, newName.c_str(), SgTypeInt(), func);
|
||||
}
|
||||
}
|
||||
|
||||
//Вычислять размер массива с учётом шага цикла - //TODO
|
||||
int privateArraysResizing(SgFile *file, const vector<LoopGraph*> &loopGraphs, vector<Messages> &messages,
|
||||
void privateArraysResizing(SgFile *file, const vector<LoopGraph*> &loopGraphs, vector<Messages> &messages, int& countOfTransform,
|
||||
const map<pair<string, int>, set<SgStatement*>>& usersDirectives, bool isExpand)
|
||||
{
|
||||
map<int, LoopGraph*> mapLoopGraph;
|
||||
createMapLoopGraph(loopGraphs, mapLoopGraph);
|
||||
|
||||
map<SgStatement*, SgSymbol*> allocDoneByFunc;
|
||||
map<SgStatement*, SgSymbol*> usedAllocDoneByFunc;
|
||||
|
||||
map<SgStatement*, vector<SgExpression*>> saveDecls;
|
||||
|
||||
for (auto &loopPair : mapLoopGraph)
|
||||
{
|
||||
LoopGraph *loop = loopPair.second;
|
||||
@@ -1275,6 +1427,9 @@ int privateArraysResizing(SgFile *file, const vector<LoopGraph*> &loopGraphs, ve
|
||||
auto attrPrivInCode = getAttributes<SgStatement*, SgStatement*>(loopSt, set<int>{ SPF_ANALYSIS_DIR });
|
||||
|
||||
auto arrayPrivates = fillPrivates(usersDirectives, loop);
|
||||
auto func = getFuncStat(loopSt);
|
||||
|
||||
set<SgSymbol*> symbolsToDecl;
|
||||
|
||||
if (arrayPrivates.size() == 0)
|
||||
{
|
||||
@@ -1284,9 +1439,7 @@ int privateArraysResizing(SgFile *file, const vector<LoopGraph*> &loopGraphs, ve
|
||||
else
|
||||
__spf_printToBuf(str, "Can not do PRIVATE SHRINK for this loop - privates not found");
|
||||
|
||||
//TODO:
|
||||
//messages.push_back(Messages(NOTE, loop->lineNum, str, 2008));
|
||||
__spf_print(1, "%s on line %d\n", str.c_str(), loop->lineNum);
|
||||
__spf_print(0, "%s on line %d\n", str.c_str(), loop->lineNum);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1302,6 +1455,8 @@ int privateArraysResizing(SgFile *file, const vector<LoopGraph*> &loopGraphs, ve
|
||||
|
||||
if (list->lhs()->variant() == SPF_EXPAND_OP && isExpand)
|
||||
{
|
||||
createAllocDoneSymbol(allocDoneByFunc, func);
|
||||
|
||||
int deep = -1;
|
||||
if (list->lhs()->lhs() != NULL)
|
||||
{
|
||||
@@ -1312,14 +1467,24 @@ int privateArraysResizing(SgFile *file, const vector<LoopGraph*> &loopGraphs, ve
|
||||
|
||||
for (SgSymbol* privArr : arrayPrivates)
|
||||
{
|
||||
SgSymbol* newSymbol = resizeArray(loop, privArr, deep);
|
||||
SgSymbol* newSymbol = resizeArray(loop, privArr, deep, allocDoneByFunc[func]);
|
||||
|
||||
if (newSymbol)
|
||||
{
|
||||
symbols.insert(std::make_pair(privArr, newSymbol));
|
||||
usedAllocDoneByFunc[func] = allocDoneByFunc[func];
|
||||
countOfTransform++;
|
||||
|
||||
if (isAllocatable(newSymbol))
|
||||
symbolsToDecl.insert(newSymbol);
|
||||
}
|
||||
renamePrivateVarsInAttributes(attrPrivInCode, symbols);
|
||||
}
|
||||
removePrivateVarsInAttributes(attrPrivInCode, symbols);
|
||||
}
|
||||
else if (list->lhs()->variant() == SPF_SHRINK_OP && !isExpand)
|
||||
{
|
||||
createAllocDoneSymbol(allocDoneByFunc, func);
|
||||
|
||||
SgExprListExp* listExp = isSgExprListExp(list->lhs()->lhs());
|
||||
checkNull(listExp, convertFileName(__FILE__).c_str(), __LINE__);
|
||||
|
||||
@@ -1335,9 +1500,17 @@ int privateArraysResizing(SgFile *file, const vector<LoopGraph*> &loopGraphs, ve
|
||||
|
||||
if (!indexes.empty() && !skip)
|
||||
{
|
||||
SgSymbol* newSymbol = shrinkArray(loop, privArr, indexes);
|
||||
SgSymbol* newSymbol = shrinkArray(loop, privArr, indexes, allocDoneByFunc[func]);
|
||||
|
||||
if (newSymbol)
|
||||
{
|
||||
symbols.insert(std::make_pair(privArr, newSymbol));
|
||||
usedAllocDoneByFunc[func] = allocDoneByFunc[func];
|
||||
countOfTransform++;
|
||||
|
||||
if (isAllocatable(newSymbol))
|
||||
symbolsToDecl.insert(newSymbol);
|
||||
}
|
||||
}
|
||||
}
|
||||
renamePrivateVarsInAttributes(attrPrivInCode, symbols);
|
||||
@@ -1348,23 +1521,39 @@ int privateArraysResizing(SgFile *file, const vector<LoopGraph*> &loopGraphs, ve
|
||||
list = list->rhs();
|
||||
}
|
||||
|
||||
SgExpression *ex = NULL;
|
||||
SgExpression *p = NULL;
|
||||
for (int z = 0; z < newL.size(); ++z)
|
||||
{
|
||||
if (z == 0)
|
||||
p = ex = newL[z];
|
||||
else
|
||||
{
|
||||
ex->setRhs(newL[z]);
|
||||
ex = ex->rhs();
|
||||
}
|
||||
}
|
||||
attr->setExpression(0, p);
|
||||
attr->setExpression(0, makeExprList(newL, false));
|
||||
//__spf_print(1, "set new %d attributes to line %d\n", newL.size(), loop->lineNum);
|
||||
}
|
||||
}
|
||||
|
||||
for (auto& elem : symbolsToDecl)
|
||||
saveDecls[func].push_back(new SgVarRefExp(elem));
|
||||
}
|
||||
|
||||
return 0;
|
||||
for (auto& funcPair : saveDecls)
|
||||
{
|
||||
auto func = funcPair.first;
|
||||
if (usedAllocDoneByFunc.find(func) == usedAllocDoneByFunc.end())
|
||||
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
||||
|
||||
SgSymbol* allocVar = usedAllocDoneByFunc[func];
|
||||
auto list = makeExprList(funcPair.second);
|
||||
SgStatement* save = new SgStatement(SAVE_DECL, NULL, NULL, list);
|
||||
|
||||
SgStatement* st = func->lexNext();
|
||||
while (!isSgExecutableStatement(st))
|
||||
{
|
||||
if (st->variant() == CONTAINS_STMT)
|
||||
break;
|
||||
st = st->lexNext();
|
||||
}
|
||||
|
||||
vector<SgExpression*> init = { new SgValueExp(-1) };
|
||||
makeDeclaration(func, { allocVar }, &init);
|
||||
|
||||
st->insertStmtBefore(*save, *func);
|
||||
|
||||
SgAssignStmt* assign = new SgAssignStmt(*new SgVarRefExp(allocVar), *new SgVarRefExp(allocVar) + *new SgValueExp(1));
|
||||
st->insertStmtBefore(*assign, *func);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,5 +5,5 @@
|
||||
#include <set>
|
||||
|
||||
|
||||
int privateArraysResizing(SgFile *file, const std::vector<LoopGraph*> &loopGraphs, std::vector<Messages> &messages, const std::map<std::pair<std::string, int>, std::set<SgStatement*>>& usersDirectives, bool isExpand);
|
||||
void privateArraysResizing(SgFile *file, const std::vector<LoopGraph*> &loopGraphs, std::vector<Messages> &messages, int& countOfTransform, const std::map<std::pair<std::string, int>, std::set<SgStatement*>>& usersDirectives, bool isExpand);
|
||||
void analyzeShrinking(SgFile* file, const std::vector<LoopGraph*>& loopGraphs, std::vector<Messages>& messages, const std::map<std::pair<std::string, int>, std::set<SgStatement*>>& usersDirectives);
|
||||
@@ -44,7 +44,7 @@ static bool operator<(const RegularExpr& left, const RegularExpr& right)
|
||||
}
|
||||
|
||||
// FixedSubscript represents subscript of array. Subscript is fixed if it is INT_VAL value
|
||||
struct FixedSubscript {
|
||||
struct ArraySubscript {
|
||||
bool isFixed;
|
||||
int value;
|
||||
|
||||
@@ -52,7 +52,7 @@ struct FixedSubscript {
|
||||
RegularExpr regExprStart;
|
||||
RegularExpr regExprEnd;
|
||||
|
||||
FixedSubscript() {
|
||||
ArraySubscript() {
|
||||
isFixed = false;
|
||||
value = 0;
|
||||
isRegIndex = false;
|
||||
@@ -240,6 +240,7 @@ static vector<int> getShortFixedSubscriptsVector(SgArrayRefExp* arrayRef, const
|
||||
if (vars != varToRemove.arrayRefToIterationVarsMap.end())
|
||||
iterationVars = vars->second;
|
||||
}
|
||||
|
||||
return getShortFixedSubscriptsVector(arrayRef, varToRemove.fixedDimensions,
|
||||
varToRemove.regime, iterationVars);
|
||||
}
|
||||
@@ -312,6 +313,20 @@ static FuncInfo* getCurrectFunc(SgStatement* stmt, const map<string, vector<Func
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// fillIterationVariables fill vars set with iteration variables of all loops
|
||||
// from stmt to outerLoopStmt
|
||||
static void fillIterationVars(SgStatement* stmt, SgStatement* outerLoopStmt, vector<SgSymbol*>& vars)
|
||||
{
|
||||
if (stmt == nullptr)
|
||||
return;
|
||||
|
||||
if (stmt->variant() == FOR_NODE)
|
||||
vars.push_back(((SgForStmt*)stmt)->doName());
|
||||
|
||||
if (stmt->id() != outerLoopStmt->id())
|
||||
fillIterationVars(stmt->controlParent(), outerLoopStmt, vars);
|
||||
}
|
||||
|
||||
/* ************************************** *
|
||||
* End of block of common used functions: *
|
||||
* ************************************** */
|
||||
@@ -369,18 +384,19 @@ static void addMessageCannotFindRD(vector<Messages>& messages, string varName, i
|
||||
messages.push_back(Messages(typeMessage::WARR, loopLineNum, messageR, messageE, 2021));
|
||||
}
|
||||
|
||||
static void addMessageMoreThanOneRD(vector<Messages>& messages, string varName, int loopLineNum)
|
||||
{
|
||||
__spf_print(1, "WARR: cannot remove private var '%s' - more than one definition reaches the statement in line %d\n",
|
||||
varName.c_str(), loopLineNum);
|
||||
|
||||
wstring messageE, messageR;
|
||||
__spf_printToLongBuf(messageE, L"Cannot remove private var '%s' - more than one definition reaches the statement",
|
||||
to_wstring(varName).c_str());
|
||||
__spf_printToLongBuf(messageR, R193, to_wstring(varName).c_str());
|
||||
|
||||
messages.push_back(Messages(typeMessage::WARR, loopLineNum, messageR, messageE, 2020));
|
||||
}
|
||||
// TODO: unused:
|
||||
//static void addMessageMoreThanOneRD(vector<Messages>& messages, string varName, int loopLineNum)
|
||||
//{
|
||||
// __spf_print(1, "WARR: cannot remove private var '%s' - more than one definition reaches the statement in line %d\n",
|
||||
// varName.c_str(), loopLineNum);
|
||||
//
|
||||
// wstring messageE, messageR;
|
||||
// __spf_printToLongBuf(messageE, L"Cannot remove private var '%s' - more than one definition reaches the statement",
|
||||
// to_wstring(varName).c_str());
|
||||
// __spf_printToLongBuf(messageR, R193, to_wstring(varName).c_str());
|
||||
//
|
||||
// messages.push_back(Messages(typeMessage::WARR, loopLineNum, messageR, messageE, 2020));
|
||||
//}
|
||||
|
||||
static void addMessageRecursiveDependency(vector<Messages>& messages, string varName, int lineNum)
|
||||
{
|
||||
@@ -499,7 +515,7 @@ static string getDimensionVarName(SgSymbol* var, const vector<int>& subscripts,
|
||||
}
|
||||
|
||||
// getDimensionVarName returns var name in style A(1, 2, *)
|
||||
static string getDimensionVarName(SgSymbol* var, const vector<FixedSubscript>& fixedSubscripts)
|
||||
static string getDimensionVarName(SgSymbol* var, const vector<ArraySubscript>& fixedSubscripts)
|
||||
{
|
||||
string result = var->identifier();
|
||||
|
||||
@@ -599,40 +615,6 @@ static bool isVarChangedBetween(string var, SgStatement* first, SgStatement* sec
|
||||
return false;
|
||||
}
|
||||
|
||||
// TODO: remove if needless
|
||||
// removeDeadCodeFromLoop removes assign statements to private scalar vars which are not read in loop
|
||||
//static void removeDeadCodeFromLoop(LoopGraph* loop)
|
||||
//{
|
||||
// SgForStmt* loopStmt = (SgForStmt*) loop->loop->GetOriginal();
|
||||
// set<Symbol*> privateVars;
|
||||
// for (auto data : getAttributes<SgStatement*, SgStatement*>(loopStmt, set<int>{ SPF_ANALYSIS_DIR }))
|
||||
// fillPrivatesFromComment(new Statement(data), privateVars);
|
||||
//
|
||||
// set<string> privates;
|
||||
// for (Symbol* symbol : privateVars)
|
||||
// privates.insert(OriginalSymbol((SgSymbol*)symbol)->identifier());
|
||||
//
|
||||
// vector<SgStatement*> stmtsToDelete;
|
||||
// for (SgStatement* st = loopStmt->lexNext(); st != loopStmt->lastNodeOfStmt(); st = st->lexNext())
|
||||
// {
|
||||
// if (st->variant() != ASSIGN_STAT)
|
||||
// continue;
|
||||
//
|
||||
// SgSymbol* var = st->expr(0)->symbol();
|
||||
// if (var == nullptr || var->variant() != VARIABLE_NAME)
|
||||
// continue;
|
||||
//
|
||||
// if (privates.find(var->identifier()) != privates.end() && !isVarReadInLoop(var, loopStmt))
|
||||
// stmtsToDelete.push_back(st);
|
||||
// }
|
||||
//
|
||||
// for (auto stmt : stmtsToDelete)
|
||||
// stmt->deleteStmt();
|
||||
//
|
||||
// for (auto childLoop : loop->children)
|
||||
// removeDeadCodeFromLoop(childLoop);
|
||||
//}
|
||||
|
||||
// fillReadShortFixedSumscripts fills all short fixed subscripts vectors of array var,
|
||||
// which are used for reading from array var in exp
|
||||
static void fillReadShortFixedSubscripts(SgExpression* exp, const PrivateToRemove& var,
|
||||
@@ -698,32 +680,6 @@ static void removeExcessiveDefs(const PrivateToRemove& var)
|
||||
st->deleteStmt();
|
||||
}
|
||||
|
||||
// TODO: remove is needless
|
||||
// removeEmptyLoops removes loops with empty body and create messages
|
||||
//static void removeEmptyLoops(LoopGraph* loop, vector<Messages>& messages)
|
||||
//{
|
||||
// vector<LoopGraph*> loopsToDelete;
|
||||
// vector<LoopGraph*> newChildrenVector;
|
||||
// for (auto childLoop : loop->children)
|
||||
// {
|
||||
// SgStatement* loopStmt = childLoop->loop->GetOriginal();
|
||||
// if (loopStmt->lastNodeOfStmt() == loopStmt->lexNext())
|
||||
// loopsToDelete.push_back(childLoop);
|
||||
// else
|
||||
// newChildrenVector.push_back(childLoop);
|
||||
// }
|
||||
//
|
||||
// for (auto loopToDelete : loopsToDelete)
|
||||
// {
|
||||
// addMessageRemoveLoop(messages, loopToDelete->lineNum);
|
||||
// loopToDelete->loop->extractStmt();
|
||||
// }
|
||||
//
|
||||
// loop->children.swap(newChildrenVector);
|
||||
// for (auto childLoop : loop->children)
|
||||
// removeEmptyLoops(childLoop, messages);
|
||||
//}
|
||||
|
||||
// removeVarFromPrivateAttributes removes var from SPF ANALYSIS PRIVATE attributes of loop
|
||||
static void removeVarFromPrivateAttributes(SgSymbol* var, LoopGraph* loop)
|
||||
{
|
||||
@@ -778,10 +734,23 @@ static map<SgSymbol*, SgExpression*> getVarToExpMap(SgArrayRefExp* defRef, SgArr
|
||||
|
||||
// removeArray removes array by substituting it in DEF-USE pairs.
|
||||
// Returns set of removed fixed subscripts
|
||||
static set<vector<int>> removeArray(string filename, const PrivateToRemove& arrayToRemove)
|
||||
static set<vector<int>> removeArray(string filename, PrivateToRemove& arrayToRemove)
|
||||
{
|
||||
set<vector<int>> removedFixedSubscripts;
|
||||
|
||||
SgStatement* loopStmt = arrayToRemove.loop->loop->GetOriginal();
|
||||
for (SgStatement* st = loopStmt->lexNext(); st != loopStmt->lastNodeOfStmt(); st = st->lexNext())
|
||||
{
|
||||
vector<SgSymbol*> iterationVars;
|
||||
fillIterationVars(st, loopStmt, iterationVars);
|
||||
|
||||
vector<SgArrayRefExp*> arrayRefs = getDirectArrayRefsFromSingleStmt(st, arrayToRemove.varSymbol);
|
||||
for (SgArrayRefExp* arrayRef : arrayRefs)
|
||||
{
|
||||
arrayToRemove.arrayRefToIterationVarsMap.insert(make_pair(arrayRef, iterationVars));
|
||||
}
|
||||
}
|
||||
|
||||
auto& fixedDimensions = arrayToRemove.fixedDimensions;
|
||||
for (auto& defUsePair : arrayToRemove.defUseStmtsPairs)
|
||||
{
|
||||
@@ -833,6 +802,7 @@ void removePrivates(string filename, vector<Messages>& messages,
|
||||
const map<string, vector<FuncInfo*>>& allFuncInfo,
|
||||
int& countOfTransform)
|
||||
{
|
||||
set<LoopGraph*> removeDC;
|
||||
for (auto& varToRemove : privatesToRemoveGlobal)
|
||||
{
|
||||
if (filename != varToRemove.loop->fileName)
|
||||
@@ -841,18 +811,10 @@ void removePrivates(string filename, vector<Messages>& messages,
|
||||
auto removedDimensions = removeArray(filename, varToRemove);
|
||||
countOfTransform++;
|
||||
|
||||
//removeDeadCodeFromLoop(varToRemove.loop);
|
||||
removeExcessiveDefs(varToRemove);
|
||||
//removeEmptyLoops(varToRemove.loop, messages);
|
||||
removeDC.insert(varToRemove.loop);
|
||||
|
||||
SgForStmt* loopStmt = (SgForStmt*)varToRemove.loop->loop->GetOriginal();
|
||||
FuncInfo* currFunc = getCurrectFunc(loopStmt, allFuncInfo);
|
||||
if (currFunc == nullptr)
|
||||
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
||||
|
||||
removeDeadCode(currFunc->funcPointer, allFuncInfo, commonBlocks);
|
||||
|
||||
vector<SgArrayRefExp*> varRefs = getDirectArrayRefs(loopStmt, varToRemove.varSymbol);
|
||||
vector<SgArrayRefExp*> varRefs = getDirectArrayRefs(varToRemove.loop->loop, varToRemove.varSymbol);
|
||||
int loopLineNum = varToRemove.loop->lineNum;
|
||||
string varName = varToRemove.varSymbol->identifier();
|
||||
auto& fixedDimensions = varToRemove.fixedDimensions;
|
||||
@@ -886,6 +848,18 @@ void removePrivates(string filename, vector<Messages>& messages,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (auto& dcLoopRem : removeDC)
|
||||
{
|
||||
auto loopStmt = dcLoopRem->loop->GetOriginal();
|
||||
FuncInfo* currFunc = getCurrectFunc(loopStmt, allFuncInfo);
|
||||
|
||||
if (currFunc == nullptr)
|
||||
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
||||
|
||||
removeDeadCode(currFunc->funcPointer, allFuncInfo, commonBlocks,
|
||||
loopStmt, loopStmt->lastNodeOfStmt());
|
||||
}
|
||||
}
|
||||
|
||||
/* ****************************************** *
|
||||
@@ -989,19 +963,6 @@ static vector<int> getShortFixedSubscriptsVector(Context* ctx, SgArrayRefExp* ar
|
||||
return getShortFixedSubscriptsVector(arrayRef, ctx->fixedDimensionsMask, ctx->regime, iterationVars);
|
||||
}
|
||||
|
||||
// fillIterationVariables fill vars set with iteration variables of all loops
|
||||
// from stmt to outerLoopStmt
|
||||
static void fillIterationVars(SgStatement* stmt, SgStatement* outerLoopStmt, vector<SgSymbol*>& vars)
|
||||
{
|
||||
if (stmt == nullptr)
|
||||
return;
|
||||
|
||||
if (stmt->variant() == FOR_NODE)
|
||||
vars.push_back(((SgForStmt*)stmt)->doName());
|
||||
|
||||
if (stmt->id() != outerLoopStmt->id())
|
||||
fillIterationVars(stmt->controlParent(), outerLoopStmt, vars);
|
||||
}
|
||||
|
||||
// matchesFixedDimensionsMask checks if all array references have INT_VAL value in fixed dimension
|
||||
static bool checkFixedDimensionsMaskMatching(Context* ctx)
|
||||
@@ -1113,6 +1074,7 @@ static bool checkRegularIndexRefs(Context* ctx)
|
||||
return false;
|
||||
}
|
||||
|
||||
// TODO: possibly can be removed:
|
||||
if (st->variant() == ASSIGN_STAT && isEqSymbols(st->expr(0)->symbol(), ctx->arraySymbol))
|
||||
for (auto iterationVar : iterationVars)
|
||||
if (isSymbolInExpression(iterationVar, st->expr(1)))
|
||||
@@ -1172,17 +1134,17 @@ static SgForStmt* getLoopStmtForVar(SgStatement* stmt, string loopVar)
|
||||
|
||||
// getFixedSubscriptsVector returns vector of fixed INT_VAL subscripts of arrayRef
|
||||
// true - subscript is fixed, false - it isn't
|
||||
static vector<FixedSubscript> getFixedSubscriptsVector(SgArrayRefExp* arrayRef, int dimensionsNum = 0,
|
||||
static vector<ArraySubscript> getFixedSubscriptsVector(SgArrayRefExp* arrayRef, int dimensionsNum = 0,
|
||||
SgStatement* stmt = nullptr)
|
||||
{
|
||||
if (arrayRef->numberOfSubscripts() == 0)
|
||||
return vector<FixedSubscript>(dimensionsNum);
|
||||
return vector<ArraySubscript>(dimensionsNum);
|
||||
|
||||
vector<FixedSubscript> subscriptsVector;
|
||||
vector<ArraySubscript> subscriptsVector;
|
||||
for (int i = 0; i < arrayRef->numberOfSubscripts(); ++i)
|
||||
{
|
||||
SgExpression* subscriptExpr = arrayRef->subscript(i);
|
||||
FixedSubscript sub;
|
||||
ArraySubscript sub;
|
||||
|
||||
if (subscriptExpr->variant() == INT_VAL)
|
||||
{
|
||||
@@ -1228,7 +1190,7 @@ static vector<FixedSubscript> getFixedSubscriptsVector(SgArrayRefExp* arrayRef,
|
||||
// checkImplicitDirectUsage returns masks of array implicit usage (as out argument)
|
||||
// in any function call in exp and writes message about each usage
|
||||
static void checkImplicitDirectUsage(Context* ctx, SgExpression* exp, int stmtLineNum,
|
||||
vector<vector<FixedSubscript>>& fixedSubscripts)
|
||||
vector<vector<ArraySubscript>>& fixedSubscripts)
|
||||
{
|
||||
if (exp == nullptr)
|
||||
return;
|
||||
@@ -1263,9 +1225,9 @@ static void checkImplicitDirectUsage(Context* ctx, SgExpression* exp, int stmtLi
|
||||
// checkImplicitDirectUsage returns masks of array implicit usage (as out argument)
|
||||
// and reference to whole array (like fcall(A, 1)) in any function call in loop
|
||||
// and writes message about each usage
|
||||
static vector<vector<FixedSubscript>> checkImplicitDirectUsage(Context* ctx)
|
||||
static vector<vector<ArraySubscript>> checkImplicitDirectUsage(Context* ctx)
|
||||
{
|
||||
vector<vector<FixedSubscript>> fixedSubscripts;
|
||||
vector<vector<ArraySubscript>> fixedSubscripts;
|
||||
for (SgStatement* st = ctx->loopStmt->lexNext(); st != ctx->loopStmt->lastNodeOfStmt(); st = st->lexNext())
|
||||
{
|
||||
if (st->variant() != PROC_STAT)
|
||||
@@ -1331,7 +1293,7 @@ static vector<Variable*> getCommonBlockGroupedVar(FuncInfo* curFunc, SgSymbol* v
|
||||
// checkIndirectUsage returns masks of array indirect usage in function
|
||||
// (indirect usage is usage through common blocks) and writes messages about it
|
||||
static void checkIndirectUsage(Context* ctx, FuncInfo* curFunc, vector<Variable*> commonBlockGroupedVar,
|
||||
set<string>& visitedFuncs, vector<vector<FixedSubscript>>& indirectUsageMasks)
|
||||
set<string>& visitedFuncs, vector<vector<ArraySubscript>>& indirectUsageMasks)
|
||||
{
|
||||
if (visitedFuncs.find(curFunc->funcName) != visitedFuncs.end())
|
||||
return;
|
||||
@@ -1362,9 +1324,9 @@ static void checkIndirectUsage(Context* ctx, FuncInfo* curFunc, vector<Variable*
|
||||
|
||||
// checkIndirectUsage returns masks of array indirect usage in any function call in loop
|
||||
// (indirect usage is usage through common blocks) and writes messages about it
|
||||
static vector<vector<FixedSubscript>> checkIndirectUsage(Context* ctx)
|
||||
static vector<vector<ArraySubscript>> checkIndirectUsage(Context* ctx)
|
||||
{
|
||||
vector<vector<FixedSubscript>> indirectUsageMasks;
|
||||
vector<vector<ArraySubscript>> indirectUsageMasks;
|
||||
FuncInfo* currentFunc = getCurrectFunc(ctx->loopStmt, ctx->allFuncInfo);
|
||||
if (currentFunc == nullptr)
|
||||
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
||||
@@ -1382,10 +1344,10 @@ static vector<vector<FixedSubscript>> checkIndirectUsage(Context* ctx)
|
||||
}
|
||||
|
||||
// checkImplicitAndIndirectUsage returns masks of implicit or indirect array usage in loop
|
||||
static vector<vector<FixedSubscript>> checkImplicitAndIndirectUsage(Context* ctx)
|
||||
static vector<vector<ArraySubscript>> checkImplicitAndIndirectUsage(Context* ctx)
|
||||
{
|
||||
vector<vector<FixedSubscript>> implicitMasks = checkImplicitDirectUsage(ctx);
|
||||
vector<vector<FixedSubscript>> indirectMasks = checkIndirectUsage(ctx);
|
||||
vector<vector<ArraySubscript>> implicitMasks = checkImplicitDirectUsage(ctx);
|
||||
vector<vector<ArraySubscript>> indirectMasks = checkIndirectUsage(ctx);
|
||||
|
||||
implicitMasks.insert(implicitMasks.end(), indirectMasks.begin(), indirectMasks.end());
|
||||
return implicitMasks;
|
||||
@@ -1393,7 +1355,7 @@ static vector<vector<FixedSubscript>> checkImplicitAndIndirectUsage(Context* ctx
|
||||
|
||||
// filterArrayRefs removes from arrayRefs all refs that are not different from fixedVectors
|
||||
static void filterArrayRefs(Context* ctx, vector<SgArrayRefExp*>& arrayRefs,
|
||||
const vector<vector<FixedSubscript>>& masks)
|
||||
const vector<vector<ArraySubscript>>& masks)
|
||||
{
|
||||
if (masks.empty())
|
||||
return;
|
||||
@@ -1401,7 +1363,7 @@ static void filterArrayRefs(Context* ctx, vector<SgArrayRefExp*>& arrayRefs,
|
||||
vector<SgArrayRefExp*> filteredArrayRefs;
|
||||
for (auto arrayRef : arrayRefs)
|
||||
{
|
||||
vector<FixedSubscript> arrayRefVec = getFixedSubscriptsVector(arrayRef, ctx->dimensionsNum);
|
||||
vector<ArraySubscript> arrayRefVec = getFixedSubscriptsVector(arrayRef, ctx->dimensionsNum);
|
||||
|
||||
bool isDifferent = false;
|
||||
for (auto& mask : masks)
|
||||
@@ -1664,17 +1626,18 @@ static vector<DefUseStmtsPair> buildDefUsePairs(Context* ctx, const CFG_Type& CF
|
||||
|
||||
if (!defIsFound)
|
||||
{
|
||||
// try to find definition not from RD_defArgs:
|
||||
// try to find definition not from RD_defArgs, by search in the block instructions:
|
||||
string defVarName = useInsertedStmt.insertedStmt->expr(1)->symbol()->identifier();
|
||||
SgStatement* blockStart = useInsAndBlock.second->getInstructions().front()->getInstruction()->getOperator();
|
||||
SgStatement* blockEnd = useInsAndBlock.second->getInstructions().back()->getInstruction()->getOperator();
|
||||
for (SgStatement* st = blockStart; st != blockEnd; st = st->lexNext())
|
||||
const auto& blockInstructionsVector = useInsAndBlock.second->getInstructions();
|
||||
for (auto& instruction : blockInstructionsVector)
|
||||
{
|
||||
if (st->variant() == ASSIGN_STAT && st->expr(0)->symbol()->identifier() == defVarName &&
|
||||
!isVarChangedBetween(defVarName, st, useInsertedStmt.insertedStmt))
|
||||
SgStatement* stmt = instruction->getInstruction()->getOperator();
|
||||
if (stmt->variant() == ASSIGN_STAT
|
||||
&& stmt->expr(0)->symbol()->identifier() == defVarName
|
||||
&& !isVarChangedBetween(defVarName, stmt, useInsertedStmt.insertedStmt))
|
||||
{
|
||||
defIsFound = true;
|
||||
defStmt = st;
|
||||
defStmt = stmt;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -1790,7 +1753,7 @@ static LoopGraph* leastCommonAncestor(LoopGraph* a, LoopGraph* b, LoopGraph* par
|
||||
// fillFullFixedSubscriptsVectorsOfAllVars return vector of pairs (name of var, its fixed subscripts vector)
|
||||
// of all VAR_REF and ARRAY_REF vars in exp
|
||||
static void fillFixedSubscriptsVectorsOfAllVars(SgExpression* exp,
|
||||
vector<pair<string, vector<FixedSubscript>>>& vec,
|
||||
vector<pair<string, vector<ArraySubscript>>>& vec,
|
||||
SgStatement* stmt = nullptr)
|
||||
{
|
||||
if (exp == nullptr)
|
||||
@@ -1804,7 +1767,7 @@ static void fillFixedSubscriptsVectorsOfAllVars(SgExpression* exp,
|
||||
if (elem.first == exp->symbol()->identifier())
|
||||
return;
|
||||
|
||||
vec.push_back(make_pair(exp->symbol()->identifier(), vector<FixedSubscript>{}));
|
||||
vec.push_back(make_pair(exp->symbol()->identifier(), vector<ArraySubscript>{}));
|
||||
}
|
||||
else if (exp->variant() == ARRAY_REF)
|
||||
{
|
||||
@@ -1823,7 +1786,7 @@ static void fillFixedSubscriptsVectorsOfAllVars(SgExpression* exp,
|
||||
}
|
||||
|
||||
// fixedSubscriptLess checks if left FixedSubscript is less than right
|
||||
static bool fixedSubscriptLess(const FixedSubscript& left, const FixedSubscript& right)
|
||||
static bool fixedSubscriptLess(const ArraySubscript& left, const ArraySubscript& right)
|
||||
{
|
||||
if (left.isFixed && right.isFixed && left.value < right.value)
|
||||
return true;
|
||||
@@ -1844,7 +1807,7 @@ static bool fixedSubscriptLess(const FixedSubscript& left, const FixedSubscript&
|
||||
|
||||
// fixedSubscriptLess checks if left and right FixedSubscripts are different,
|
||||
// using empirical methods
|
||||
static bool possibleDifferent(FixedSubscript left, FixedSubscript right)
|
||||
static bool possibleDifferent(ArraySubscript left, ArraySubscript right)
|
||||
{
|
||||
// TODO: add warning?
|
||||
if (left.isFixed && right.isRegIndex && right.regExprStart == right.regExprEnd) {
|
||||
@@ -1856,7 +1819,7 @@ static bool possibleDifferent(FixedSubscript left, FixedSubscript right)
|
||||
|
||||
// isDifferentRefs checks if exp (var reference) is different from var. Refs are different
|
||||
// if they has at least one different fixed subscript: arr(i, 1) is different from arr(j, 2)
|
||||
static bool isDifferentRefs(SgExpression* exp, const pair<string, vector<FixedSubscript>>& var, SgStatement* stmt)
|
||||
static bool isDifferentRefs(SgExpression* exp, const pair<string, vector<ArraySubscript>>& var, SgStatement* stmt)
|
||||
{
|
||||
if (exp->symbol()->identifier() != var.first)
|
||||
return true;
|
||||
@@ -1864,7 +1827,7 @@ static bool isDifferentRefs(SgExpression* exp, const pair<string, vector<FixedSu
|
||||
if (exp->variant() == VAR_REF)
|
||||
return false;
|
||||
|
||||
vector<FixedSubscript> leftVec = getFixedSubscriptsVector((SgArrayRefExp*)exp, 0, stmt);
|
||||
vector<ArraySubscript> leftVec = getFixedSubscriptsVector((SgArrayRefExp*)exp, 0, stmt);
|
||||
|
||||
if (leftVec.size() != var.second.size())
|
||||
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
||||
@@ -1907,7 +1870,7 @@ static bool checkDefUsePair(Context* ctx, const DefUseStmtsPair& defUse, const C
|
||||
|
||||
string arrayName = ctx->arraySymbol->identifier();
|
||||
|
||||
vector<pair<string, vector<FixedSubscript>>> dependOnVars;
|
||||
vector<pair<string, vector<ArraySubscript>>> dependOnVars;
|
||||
SgArrayRefExp* defRef = (SgArrayRefExp*)defUse.first->expr(0);
|
||||
vector<SgArrayRefExp*> arrayUseRefs = getDirectArrayRefsFromSingleStmt(defUse.second, ctx->arraySymbol);
|
||||
for (auto useRef : arrayUseRefs)
|
||||
|
||||
@@ -0,0 +1,193 @@
|
||||
#include "../Utils/leak_detector.h"
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
||||
#include "Utils/SgUtils.h"
|
||||
#include "set_implicit_none.h"
|
||||
|
||||
using std::vector;
|
||||
using std::map;
|
||||
using std::set;
|
||||
using std::string;
|
||||
|
||||
static const char commonIntLetters[6] = { 'i', 'j', 'k', 'm', 'n', 'l' };
|
||||
|
||||
static void InitTypes(map<char, SgType*>& types)
|
||||
{
|
||||
for (char letter = 'a'; letter <= 'z'; letter++)
|
||||
types[letter] = 0;
|
||||
}
|
||||
|
||||
static void FillCommonTypes(map<char, SgType*>& types)
|
||||
{
|
||||
for (char letter : commonIntLetters)
|
||||
if (types[letter] == 0)
|
||||
types[letter] = new SgType(T_INT);
|
||||
|
||||
for (auto letter : types)
|
||||
if (letter.second == NULL)
|
||||
types[letter.first] = new SgType(T_FLOAT);
|
||||
}
|
||||
|
||||
static void FindAllVars(SgExpression* expr, set<SgSymbol*>& allVars)
|
||||
{
|
||||
if (expr == NULL)
|
||||
return;
|
||||
|
||||
if (expr->variant() == VAR_REF || expr->variant() == ARRAY_REF)
|
||||
allVars.insert(expr->symbol());
|
||||
|
||||
FindAllVars(expr->lhs(), allVars);
|
||||
FindAllVars(expr->rhs(), allVars);
|
||||
}
|
||||
|
||||
static char getValue(SgExpression* ex)
|
||||
{
|
||||
char charVal = 0;
|
||||
if (ex && ex->variant() == CHAR_VAL)
|
||||
charVal = isSgValueExp(ex)->charValue();
|
||||
return charVal;
|
||||
}
|
||||
|
||||
static void AddLettersToMap(SgExpression* expr, SgType* type, map<char, SgType*>& types)
|
||||
{
|
||||
while (expr)
|
||||
{
|
||||
if (expr->variant() != EXPR_LIST)
|
||||
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
||||
|
||||
SgExpression* val = expr->lhs();
|
||||
if (val->variant() == DDOT)
|
||||
{
|
||||
char leftVal = getValue(val->lhs());
|
||||
char rightVal = getValue(val->rhs());
|
||||
|
||||
if (leftVal == 0 || rightVal == 0)
|
||||
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
||||
|
||||
for (char letter = leftVal; letter <= rightVal; letter++)
|
||||
types[letter] = type;
|
||||
}
|
||||
else
|
||||
{
|
||||
char charVal = getValue(val);
|
||||
if (charVal == 0)
|
||||
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
||||
|
||||
types[charVal] = type;
|
||||
}
|
||||
|
||||
expr = expr->rhs();
|
||||
}
|
||||
}
|
||||
|
||||
static map<char, SgType*> FunctionImplicitCheck(SgStatement* function, const map<SgStatement*, map<char, SgType*>>& typesByFunctions)
|
||||
{
|
||||
set<SgSymbol*> allVars;
|
||||
map<char, SgType*> types;
|
||||
vector<SgSymbol*> varsWithoutDecl;
|
||||
|
||||
InitTypes(types);
|
||||
FillCommonTypes(types);
|
||||
|
||||
auto cp = function->controlParent();
|
||||
if (isSgProgHedrStmt(cp))
|
||||
if (typesByFunctions.find(cp) != typesByFunctions.end())
|
||||
for (auto& parentType : typesByFunctions.at(cp))
|
||||
types[parentType.first] = parentType.second;
|
||||
|
||||
auto hasImplicitNone = false;
|
||||
auto endOfFunc = function->lastNodeOfStmt();
|
||||
for (auto st = function; st != endOfFunc; st = st->lexNext())
|
||||
{
|
||||
if (st->variant() == IMPL_DECL)
|
||||
{
|
||||
SgImplicitStmt* implicitStatement = isSgImplicitStmt(st);
|
||||
if (implicitStatement != NULL)
|
||||
{
|
||||
const int numberOfTypes = implicitStatement->numberOfImplicitTypes();
|
||||
|
||||
if (numberOfTypes > 0)
|
||||
{
|
||||
for (int j = 0; j < numberOfTypes; ++j)
|
||||
{
|
||||
SgType* type = implicitStatement->implicitType(j);
|
||||
SgExpression* lettersExpression = implicitStatement->implicitRangeList(j);
|
||||
|
||||
AddLettersToMap(lettersExpression, type, types);
|
||||
}
|
||||
}
|
||||
else
|
||||
hasImplicitNone = true;
|
||||
}
|
||||
}
|
||||
else if (st->variant() == CONTAINS_STMT || isSgExecutableStatement(st) != NULL)
|
||||
break;
|
||||
}
|
||||
|
||||
for (auto st = function; st != endOfFunc && st->variant() != CONTAINS_STMT; st = st->lexNext())
|
||||
for (int i = 0; i < 3; ++i)
|
||||
FindAllVars(st->expr(i), allVars);
|
||||
|
||||
for (auto& var : allVars)
|
||||
{
|
||||
if (string(var->identifier()) == function->symbol()->identifier())
|
||||
continue;
|
||||
|
||||
vector<SgStatement*> _;
|
||||
SgStatement* declaredInStatement = declaratedInStmt(var, &_, false);
|
||||
if (declaredInStatement == NULL)
|
||||
{
|
||||
const char c = var->identifier()[0];
|
||||
|
||||
if (types.find(c) != types.end())
|
||||
var->setType(types[c]);
|
||||
|
||||
varsWithoutDecl.push_back(var);
|
||||
}
|
||||
}
|
||||
|
||||
makeDeclaration(varsWithoutDecl, function, NULL);
|
||||
|
||||
if (!hasImplicitNone)
|
||||
{
|
||||
for (auto st = function->lexNext();
|
||||
st != endOfFunc && st->variant() != CONTAINS_STMT && isSgExecutableStatement(st) == NULL;
|
||||
)
|
||||
{
|
||||
if (st->variant() == IMPL_DECL)
|
||||
{
|
||||
auto tmpStatement = st;
|
||||
st = st->lexNext();
|
||||
tmpStatement->deleteStmt();
|
||||
}
|
||||
else
|
||||
st = st->lexNext();
|
||||
}
|
||||
|
||||
auto implNone = new SgStatement(IMPL_DECL);
|
||||
implNone->setlineNumber(function->lineNumber());
|
||||
implNone->setFileName(function->fileName());
|
||||
|
||||
function->insertStmtAfter(*implNone, *function);
|
||||
}
|
||||
|
||||
allVars.clear();
|
||||
varsWithoutDecl.clear();
|
||||
|
||||
return types;
|
||||
}
|
||||
|
||||
void implicitCheck(SgFile* file)
|
||||
{
|
||||
map<SgStatement*, map<char, SgType*>> typesByFunctions;
|
||||
|
||||
for (int func = 0; func < file->numberOfFunctions(); ++func)
|
||||
{
|
||||
SgStatement* function = file->functions(func);
|
||||
typesByFunctions[function] = FunctionImplicitCheck(function, typesByFunctions);
|
||||
}
|
||||
|
||||
typesByFunctions.clear();
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
#pragma once
|
||||
|
||||
void implicitCheck(SgFile* file);
|
||||
@@ -227,13 +227,13 @@ void InitPassesDependencies(map<passes, vector<passes>> &passDepsIn, set<passes>
|
||||
|
||||
list({ VERIFY_ENDDO, VERIFY_INCLUDE, PREPROC_SPF, PREPROC_ALLOCATES, GET_ALL_ARRAY_DECL, GCOV_PARSER }) <= list({ CALL_GRAPH, MACRO_EXPANSION, DEF_USE_STAGE1 });
|
||||
|
||||
list({ VERIFY_ENDDO, VERIFY_INCLUDE, PREPROC_ALLOCATES, FILL_PARALLEL_REG_IR }) <= list({ GET_ALL_ARRAY_DECL, FILL_COMMON_BLOCKS }) <= Pass(PREPROC_SPF);
|
||||
list({ VERIFY_ENDDO, VERIFY_INCLUDE, PREPROC_ALLOCATES, FILL_PARALLEL_REG_IR }) <= list({ GET_ALL_ARRAY_DECL, FILL_COMMON_BLOCKS, PARSE_OMP_DIRS }) <= Pass(PREPROC_SPF);
|
||||
|
||||
Pass(CHECK_PAR_REG_DIR) <= Pass(FILL_PARALLEL_REG_IR);
|
||||
|
||||
list({ GET_ALL_ARRAY_DECL, CALL_GRAPH2, CODE_CHECKER_PASSES, SUBST_EXPR_RD, ARRAY_ACCESS_ANALYSIS_FOR_CORNER }) <= list({ LOOP_ANALYZER_NODIST, LOOP_ANALYZER_DATA_DIST_S0, LOOP_ANALYZER_DATA_DIST_S1, ONLY_ARRAY_GRAPH });
|
||||
|
||||
list({ LOOP_ANALYZER_NODIST, REMOVE_OMP_DIRS }) <= Pass(INSERT_PARALLEL_DIRS_NODIST);
|
||||
list({ LOOP_ANALYZER_NODIST, REMOVE_OMP_DIRS }) <= Pass(SELECT_ARRAY_DIM_CONF) <= Pass(INSERT_PARALLEL_DIRS_NODIST);
|
||||
|
||||
Pass(CHECK_ARGS_DECL) <= Pass(CREATE_TEMPLATE_LINKS);
|
||||
|
||||
@@ -243,7 +243,7 @@ void InitPassesDependencies(map<passes, vector<passes>> &passDepsIn, set<passes>
|
||||
|
||||
Pass(MACRO_EXPANSION) <= Pass(CALL_GRAPH);
|
||||
|
||||
list({ PREPROC_SPF, PROCESS_IO, CALL_GRAPH2, CONVERT_SAVE_TO_MODULE, REVERT_SUBST_EXPR, REVERT_SUBST_EXPR_RD }) <= Pass(CREATE_CHECKPOINTS);
|
||||
list({ PREPROC_SPF, PROCESS_IO, CALL_GRAPH2, CONVERT_SAVE_TO_MODULE, REVERT_SUBST_EXPR_RD }) <= Pass(CREATE_CHECKPOINTS);
|
||||
|
||||
Pass(FILL_PAR_REGIONS_LINES) <= Pass(VERIFY_EQUIVALENCE);
|
||||
|
||||
@@ -251,13 +251,13 @@ void InitPassesDependencies(map<passes, vector<passes>> &passDepsIn, set<passes>
|
||||
|
||||
list({ CORRECT_VAR_DECL, PREPROC_SPF }) <= list({ LOOP_GRAPH, CALL_GRAPH, CALL_GRAPH2 });
|
||||
|
||||
list({ PREPROC_SPF, CALL_GRAPH2 }) <= Pass(FILL_PAR_REGIONS_LINES) <= list({ EXPAND_EXTRACT_PAR_REGION, CHECK_FUNC_TO_INCLUDE, FIND_FUNC_TO_INCLUDE, CHECK_ARGS_DECL, SELECT_ARRAY_DIM_CONF});
|
||||
list({ PREPROC_SPF, CALL_GRAPH2 }) <= Pass(FILL_PAR_REGIONS_LINES) <= list({ EXPAND_EXTRACT_PAR_REGION, CHECK_FUNC_TO_INCLUDE, FIND_FUNC_TO_INCLUDE, CHECK_ARGS_DECL });
|
||||
|
||||
list({ PREPROC_SPF, CALL_GRAPH2, FILL_PAR_REGIONS_LINES }) <= Pass(FILL_PAR_REGIONS) <= Pass(RESOLVE_PAR_REGIONS);
|
||||
|
||||
list({ REVERT_SUBST_EXPR, REVERT_SUBST_EXPR_RD, CONVERT_LOOP_TO_ASSIGN }) <= Pass(RESOLVE_PAR_REGIONS);
|
||||
list({ REVERT_SUBST_EXPR_RD, CONVERT_LOOP_TO_ASSIGN }) <= Pass(RESOLVE_PAR_REGIONS);
|
||||
|
||||
list({ REVERT_SUBST_EXPR, REVERT_SUBST_EXPR_RD }) <= Pass(EXPAND_EXTRACT_PAR_REGION);
|
||||
Pass(REVERT_SUBST_EXPR_RD) <= Pass(EXPAND_EXTRACT_PAR_REGION);
|
||||
|
||||
Pass(FILL_PAR_REGIONS) <= Pass(PRINT_PAR_REGIONS_ERRORS);
|
||||
|
||||
@@ -269,33 +269,33 @@ void InitPassesDependencies(map<passes, vector<passes>> &passDepsIn, set<passes>
|
||||
|
||||
Pass(CALL_GRAPH2) <= list({ PURE_SAVE_TO_PARAMS, PURE_MODULE_TO_PARAMS, PURE_COMMON_TO_PARAMS, PURE_INTENT_INSERT });
|
||||
|
||||
list({ REVERT_SUBST_EXPR, REVERT_SUBST_EXPR_RD }) <= list({ PURE_SAVE_TO_PARAMS, PURE_MODULE_TO_PARAMS, PURE_COMMON_TO_PARAMS, PURE_INTENT_INSERT });
|
||||
Pass(REVERT_SUBST_EXPR_RD) <= list({ PURE_SAVE_TO_PARAMS, PURE_MODULE_TO_PARAMS, PURE_COMMON_TO_PARAMS, PURE_INTENT_INSERT });
|
||||
|
||||
list({ CORRECT_VAR_DECL, REVERT_SUBST_EXPR, REVERT_SUBST_EXPR_RD, VERIFY_INCLUDE }) <= list({ CONVERT_TO_ENDDO, CORRECT_CODE_STYLE, REMOVE_DVM_DIRS, REMOVE_DVM_DIRS_TO_COMMENTS, REMOVE_DVM_INTERVALS });
|
||||
list({ CORRECT_VAR_DECL, REVERT_SUBST_EXPR_RD, VERIFY_INCLUDE }) <= list({ CONVERT_TO_ENDDO, CORRECT_CODE_STYLE, REMOVE_DVM_DIRS, REMOVE_DVM_DIRS_TO_COMMENTS, REMOVE_DVM_INTERVALS });
|
||||
|
||||
list({ CALL_GRAPH2, CONVERT_LOOP_TO_ASSIGN, REVERT_SUBST_EXPR, REVERT_SUBST_EXPR_RD, RESTORE_LOOP_FROM_ASSIGN }) <= Pass(INLINE_PROCEDURES);
|
||||
list({ CALL_GRAPH2, CONVERT_LOOP_TO_ASSIGN, REVERT_SUBST_EXPR_RD, RESTORE_LOOP_FROM_ASSIGN }) <= Pass(INLINE_PROCEDURES);
|
||||
|
||||
list({ CONVERT_LOOP_TO_ASSIGN, CORRECT_FORMAT_PLACE }) <= list({ CONVERT_TO_ENDDO, CORRECT_CODE_STYLE, INSERT_INCLUDES, REMOVE_DVM_DIRS, REMOVE_DVM_DIRS_TO_COMMENTS, REMOVE_DVM_INTERVALS });
|
||||
|
||||
list({ CORRECT_VAR_DECL, REVERT_SUBST_EXPR, REVERT_SUBST_EXPR_RD }) <= list({ INSERT_INCLUDES, UNPARSE_FILE, SET_TO_ALL_DECL_INIT_ZERO });
|
||||
list({ CORRECT_VAR_DECL, REVERT_SUBST_EXPR_RD }) <= list({ INSERT_INCLUDES, UNPARSE_FILE, SET_TO_ALL_DECL_INIT_ZERO });
|
||||
|
||||
Pass(CALL_GRAPH2) <= Pass(PRIVATE_ARRAYS_SHRINKING_ANALYSIS) <= Pass(PRIVATE_ARRAYS_SHRINKING);
|
||||
|
||||
list({ CALL_GRAPH2, LOOP_ANALYZER_ALIGNS, REVERT_SUBST_EXPR, REVERT_SUBST_EXPR_RD }) <= list({ PRIVATE_ARRAYS_EXPANSION, PRIVATE_ARRAYS_SHRINKING });
|
||||
list({ CALL_GRAPH2, LOOP_ANALYZER_ALIGNS, REVERT_SUBST_EXPR_RD }) <= list({ PRIVATE_ARRAYS_EXPANSION, PRIVATE_ARRAYS_SHRINKING });
|
||||
|
||||
list({ GCOV_PARSER, CREATE_INTER_TREE, CALL_GRAPH, CALL_GRAPH2 }) <= Pass(CREATE_PARALLEL_REGIONS);
|
||||
|
||||
list({ PRIVATE_CALL_GRAPH_STAGE1, PRIVATE_CALL_GRAPH_STAGE2, MACRO_EXPANSION, CONVERT_ASSIGN_TO_LOOP, DEF_USE_STAGE1, DEF_USE_STAGE2, LOOP_GRAPH, CALL_GRAPH, PRIVATE_ANALYSIS_IR, FIND_FUNC_TO_INCLUDE }) <= Pass(INSERT_REGIONS);
|
||||
|
||||
list({ LOOP_ANALYZER_DATA_DIST_S1, REVERT_SUBST_EXPR, REVERT_SUBST_EXPR_RD }) <= list({ LOOPS_SPLITTER, LOOPS_COMBINER, UNROLL_LOOPS, INSERT_REGIONS });
|
||||
list({ LOOP_ANALYZER_DATA_DIST_S1, REVERT_SUBST_EXPR_RD }) <= list({ LOOPS_SPLITTER, LOOPS_COMBINER, UNROLL_LOOPS, INSERT_REGIONS });
|
||||
|
||||
list({ CALL_GRAPH2, REVERT_SUBST_EXPR, REVERT_SUBST_EXPR_RD, CONVERT_LOOP_TO_ASSIGN, RESTORE_LOOP_FROM_ASSIGN }) <= list({ DUPLICATE_FUNCTIONS, REMOVE_UNUSED_FUNCTIONS });
|
||||
list({ CALL_GRAPH2, REVERT_SUBST_EXPR_RD, CONVERT_LOOP_TO_ASSIGN, RESTORE_LOOP_FROM_ASSIGN }) <= list({ DUPLICATE_FUNCTIONS, REMOVE_UNUSED_FUNCTIONS });
|
||||
|
||||
list({ CONVERT_LOOP_TO_ASSIGN, RESTORE_LOOP_FROM_ASSIGN }) <= list({ LOOPS_SPLITTER, LOOPS_COMBINER, PRIVATE_ARRAYS_EXPANSION, PRIVATE_ARRAYS_SHRINKING, CREATE_PARALLEL_REGIONS, PURE_SAVE_TO_PARAMS, PURE_MODULE_TO_PARAMS, PURE_COMMON_TO_PARAMS, PURE_INTENT_INSERT });
|
||||
|
||||
list({ GET_ALL_ARRAY_DECL, FILL_PARALLEL_REG_IR }) <= Pass(CONVERT_ASSIGN_TO_LOOP);
|
||||
|
||||
list({ CALL_GRAPH2, REVERT_SUBST_EXPR, REVERT_SUBST_EXPR_RD }) <= Pass(RENAME_SYMBOLS);
|
||||
list({ CALL_GRAPH2, REVERT_SUBST_EXPR_RD }) <= Pass(RENAME_SYMBOLS);
|
||||
|
||||
list({ BUILD_IR, CALL_GRAPH }) <= Pass(LIVE_ANALYSIS_IR);
|
||||
|
||||
@@ -308,7 +308,7 @@ void InitPassesDependencies(map<passes, vector<passes>> &passDepsIn, set<passes>
|
||||
Pass(REMOVE_OMP_DIRS) <= Pass(REMOVE_OMP_DIRS_TRANSFORM);
|
||||
|
||||
Pass(CALL_GRAPH2) <= Pass(REMOVE_DEAD_CODE);
|
||||
list({ REMOVE_DEAD_CODE, REVERT_SUBST_EXPR, REVERT_SUBST_EXPR_RD, CONVERT_LOOP_TO_ASSIGN, RESTORE_LOOP_FROM_ASSIGN }) <= Pass(REMOVE_DEAD_CODE_AND_UNPARSE);
|
||||
list({ REMOVE_DEAD_CODE, REVERT_SUBST_EXPR_RD, CONVERT_LOOP_TO_ASSIGN, RESTORE_LOOP_FROM_ASSIGN }) <= Pass(REMOVE_DEAD_CODE_AND_UNPARSE);
|
||||
|
||||
passesIgnoreStateDone.insert({ CREATE_PARALLEL_DIRS, INSERT_PARALLEL_DIRS, INSERT_SHADOW_DIRS, EXTRACT_PARALLEL_DIRS,
|
||||
EXTRACT_SHADOW_DIRS, CREATE_REMOTES, UNPARSE_FILE, REMOVE_AND_CALC_SHADOW,
|
||||
@@ -319,7 +319,7 @@ void InitPassesDependencies(map<passes, vector<passes>> &passDepsIn, set<passes>
|
||||
//only for print
|
||||
if (printTree)
|
||||
{
|
||||
list({ CREATE_PARALLEL_DIRS, PRIVATE_ANALYSIS_IR, CREATE_REMOTES, REVERT_SUBST_EXPR, REVERT_SUBST_EXPR_RD, UNPARSE_FILE, EXTRACT_PARALLEL_DIRS }) <= Pass(INSERT_PARALLEL_DIRS);
|
||||
list({ CREATE_PARALLEL_DIRS, PRIVATE_ANALYSIS_IR, CREATE_REMOTES, REVERT_SUBST_EXPR_RD, UNPARSE_FILE, EXTRACT_PARALLEL_DIRS }) <= Pass(INSERT_PARALLEL_DIRS);
|
||||
depsToGraphViz(passDepsIn);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#include <locale>
|
||||
#include <algorithm>
|
||||
#include <thread>
|
||||
#include <cstdint>
|
||||
|
||||
#include "utils.h"
|
||||
#include "errors.h"
|
||||
@@ -184,6 +185,7 @@ extern int staticShadowAnalysis;
|
||||
extern int keepDvmDirectives;
|
||||
extern int ignoreIO;
|
||||
extern int keepSpfDirs;
|
||||
extern int maxShadowWidth;
|
||||
|
||||
const string printVersionAsFortranComm()
|
||||
{
|
||||
@@ -199,13 +201,14 @@ const string printVersionAsFortranComm()
|
||||
ret += "! *** shadow optimization\n";
|
||||
if (keepDvmDirectives)
|
||||
ret += "! *** consider DVMH directives\n";
|
||||
if (keepSpfDirs)
|
||||
ret += "! *** save SPF directives\n";
|
||||
if (mpiProgram)
|
||||
ret += "! *** MPI program regime (shared memory parallelization)\n";
|
||||
if (ignoreIO)
|
||||
ret += "! *** ignore I/O checker for arrays (DVM I/O limitations)\n";
|
||||
if (keepSpfDirs)
|
||||
ret += "! *** save SPF directives\n";
|
||||
|
||||
if (maxShadowWidth > 0)
|
||||
ret += "! *** maximum shadow width is " + std::to_string(maxShadowWidth) + " percent\n";
|
||||
ret += "! *** generated by SAPFOR\n";
|
||||
|
||||
return ret;
|
||||
@@ -1159,7 +1162,9 @@ template vector<LoopGraph*>& getObjectForFileFromMap(const char *fileName, map<s
|
||||
template vector<FuncInfo*>& getObjectForFileFromMap(const char *fileName, map<string, vector<FuncInfo*>>&);
|
||||
template map<int, Gcov_info>& getObjectForFileFromMap(const char *fileName, map<string, map<int, Gcov_info>>&);
|
||||
template map<int, double>& getObjectForFileFromMap(const char *fileName, map<string, map<int, double>>&);
|
||||
#if __SPF
|
||||
template map<SgStatement*, vector<SgStatement*>>& getObjectForFileFromMap(const char* fileName, map<string, map<SgStatement*, vector<SgStatement*>>>&);
|
||||
#endif
|
||||
|
||||
static set<string> mpiFunctions;
|
||||
bool isMpiFunction(const string& func)
|
||||
@@ -1573,3 +1578,71 @@ vector<string> splitAndArgvCreate(const string& options)
|
||||
}
|
||||
return optSplited1;
|
||||
}
|
||||
|
||||
static bool isNotNullIntersection(const set<DIST::Array*>& first, const set<DIST::Array*>& second)
|
||||
{
|
||||
for (auto& elem1 : first)
|
||||
if (second.find(elem1) != second.end())
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
set<DIST::Array*> fillDistributedArraysD(const DataDirective& dataDirectives,
|
||||
const map<DIST::Array*, tuple<int, string, string>>& tableOfUniqNamesByArray,
|
||||
const map<DIST::Array*, set<DIST::Array*>>& arrayLinksByFuncCalls,
|
||||
bool onlyCommon)
|
||||
{
|
||||
set<DIST::Array*> distrArrays;
|
||||
set<DIST::Array*> distrArraysD;
|
||||
set<DIST::Array*> distrArraysAdded;
|
||||
|
||||
for (int z = 0; z < dataDirectives.distrRules.size(); ++z)
|
||||
distrArraysD.insert(dataDirectives.distrRules[z].first);
|
||||
for (int z = 0; z < dataDirectives.alignRules.size(); ++z)
|
||||
distrArraysD.insert(dataDirectives.alignRules[z].alignArray);
|
||||
|
||||
for (auto& elem : tableOfUniqNamesByArray)
|
||||
{
|
||||
set<DIST::Array*> realRefs;
|
||||
getRealArrayRefs(elem.first, elem.first, realRefs, arrayLinksByFuncCalls);
|
||||
if (isNotNullIntersection(realRefs, distrArraysD))
|
||||
distrArraysAdded.insert(elem.first);
|
||||
}
|
||||
|
||||
for (auto& elem : distrArraysD)
|
||||
{
|
||||
if (onlyCommon)
|
||||
{
|
||||
if (elem->GetLocation().first == DIST::l_COMMON)
|
||||
distrArrays.insert(elem);
|
||||
}
|
||||
else
|
||||
distrArrays.insert(elem);
|
||||
}
|
||||
|
||||
for (auto& elem : distrArraysAdded)
|
||||
{
|
||||
if (onlyCommon)
|
||||
{
|
||||
if (elem->GetLocation().first == DIST::l_COMMON)
|
||||
distrArrays.insert(elem);
|
||||
}
|
||||
else
|
||||
distrArrays.insert(elem);
|
||||
}
|
||||
return distrArrays;
|
||||
}
|
||||
|
||||
set<string> fillDistributedArrays(const DataDirective& dataDirectives,
|
||||
const map<DIST::Array*, tuple<int, string, string>>& tableOfUniqNamesByArray,
|
||||
const map<DIST::Array*, set<DIST::Array*>>& arrayLinksByFuncCalls,
|
||||
bool onlyCommon, bool shortName)
|
||||
{
|
||||
set<string> distrArrays;
|
||||
set<DIST::Array*> ret = fillDistributedArraysD(dataDirectives, tableOfUniqNamesByArray, arrayLinksByFuncCalls, onlyCommon);
|
||||
|
||||
for (auto& elem : ret)
|
||||
distrArrays.insert(shortName ? elem->GetShortName() : elem->GetName());
|
||||
return distrArrays;
|
||||
}
|
||||
@@ -3,7 +3,9 @@
|
||||
#include <vector>
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <cstdint>
|
||||
|
||||
struct DataDirective;
|
||||
namespace Distribution
|
||||
{
|
||||
class Array;
|
||||
@@ -90,3 +92,6 @@ std::wstring fixedLongFormat(const wchar_t* old);
|
||||
std::map<std::string, DIST::Array*> sortArraysByName(const std::set<DIST::Array*>& toSort);
|
||||
bool createDirectory(const std::string& name);
|
||||
std::vector<std::string> splitAndArgvCreate(const std::string& options);
|
||||
|
||||
std::set<DIST::Array*> fillDistributedArraysD(const DataDirective& dataDirectives, const std::map<DIST::Array*, std::tuple<int, std::string, std::string>>& tableOfUniqNamesByArray, const std::map<DIST::Array*, std::set<DIST::Array*>>& arrayLinksByFuncCalls, bool onlyCommon = false);
|
||||
std::set<std::string> fillDistributedArrays(const DataDirective& dataDirectives, const std::map<DIST::Array*, std::tuple<int, std::string, std::string>>& tableOfUniqNamesByArray, const std::map<DIST::Array*, std::set<DIST::Array*>>& arrayLinksByFuncCalls, bool onlyCommon = false, bool shortName = false);
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
#pragma once
|
||||
|
||||
#define VERSION_SPF "2287"
|
||||
#define VERSION_SPF "2303"
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
#include "../Utils/utils.h"
|
||||
#include "../Utils/SgUtils.h"
|
||||
#include "../Utils/errors.h"
|
||||
#include "../DirectiveProcessing/directive_parser.h"
|
||||
|
||||
using std::vector;
|
||||
using std::map;
|
||||
@@ -32,7 +31,6 @@ bool EndDoLoopChecker(SgFile *file, vector<Messages> &currMessages)
|
||||
SgStatement *st = file->functions(i);
|
||||
SgStatement *lastNode = st->lastNodeOfStmt();
|
||||
|
||||
OmpDir globalParallelSection;
|
||||
while (st != lastNode)
|
||||
{
|
||||
if (st == NULL)
|
||||
@@ -44,31 +42,6 @@ bool EndDoLoopChecker(SgFile *file, vector<Messages> &currMessages)
|
||||
if (st->variant() == CONTAINS_STMT)
|
||||
break;
|
||||
|
||||
{
|
||||
set<string> globalPriv;
|
||||
auto res = parseOmpDirs(st, globalPriv);
|
||||
|
||||
for (auto& dir : res)
|
||||
{
|
||||
auto end = dir.keys.end();
|
||||
if (dir.keys.find("parallel") != end
|
||||
&& dir.keys.find("do") == end
|
||||
&& dir.privVars.size()
|
||||
&& dir.keys.find("end") == end)
|
||||
{
|
||||
if (globalParallelSection.keys.size())
|
||||
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
||||
globalParallelSection = dir;
|
||||
}
|
||||
else if (dir.keys.find("parallel") != end
|
||||
&& dir.keys.find("do") == end
|
||||
&& dir.keys.find("end") != end)
|
||||
{
|
||||
globalParallelSection = OmpDir();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (st->variant() == FOR_NODE)
|
||||
{
|
||||
SgForStmt *currSt = (SgForStmt*)st;
|
||||
@@ -78,13 +51,6 @@ bool EndDoLoopChecker(SgFile *file, vector<Messages> &currMessages)
|
||||
currMessages.push_back(Messages(ERROR, st->lineNumber(), R51, L"This loop does not have END DO format", 1018));
|
||||
checkOK = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
set<string> globalPriv;
|
||||
if (globalParallelSection.privVars.size())
|
||||
globalPriv = globalParallelSection.privVars;
|
||||
auto res = parseOmpDirs(st, globalPriv, true);
|
||||
}
|
||||
}
|
||||
|
||||
if (st->variant() == FORALL_NODE || st->variant() == FORALL_STAT ||
|
||||
|
||||
@@ -820,7 +820,7 @@ int SPF_GetArrayDistribution(void*& context, int winHandler, short *options, sho
|
||||
else if (regime == 1)
|
||||
{
|
||||
if (mpiProgram)
|
||||
runPassesForVisualizer(projName, { LOOP_ANALYZER_NODIST });
|
||||
runPassesForVisualizer(projName, { SELECT_ARRAY_DIM_CONF });
|
||||
else
|
||||
runPassesForVisualizer(projName, { LOOP_ANALYZER_DATA_DIST_S1 });
|
||||
}
|
||||
@@ -1674,10 +1674,11 @@ int SPF_SetDistributionFlagToArrays(void*& context, const char* keys, const char
|
||||
}
|
||||
|
||||
static int simpleTransformPass(const passes PASS_NAME, short *options, short *projName, short *folderName,
|
||||
short *&output, int *&outputSize, short *&outputMessage, int *&outputMessageSize)
|
||||
short *&output, int *&outputSize, short *&outputMessage, int *&outputMessageSize,
|
||||
bool isBuildParallel = false)
|
||||
{
|
||||
clearGlobalMessagesBuffer();
|
||||
setOptions(options);
|
||||
setOptions(options, isBuildParallel);
|
||||
|
||||
int retCode = 0;
|
||||
try
|
||||
@@ -1892,7 +1893,7 @@ int SPF_SharedMemoryParallelization(void*& context, int winHandler, short* optio
|
||||
MessageManager::setWinHandler(winHandler);
|
||||
ignoreArrayDistributeState = true;
|
||||
mpiProgram = 1;
|
||||
return simpleTransformPass(INSERT_PARALLEL_DIRS_NODIST, options, projName, folderName, output, outputSize, outputMessage, outputMessageSize);
|
||||
return simpleTransformPass(INSERT_PARALLEL_DIRS_NODIST, options, projName, folderName, output, outputSize, outputMessage, outputMessageSize, true);
|
||||
}
|
||||
|
||||
int SPF_InsertPrivateFromGUI(void*& context, int winHandler, short* options, short* projName, short* folderName, short*& output,
|
||||
@@ -1911,6 +1912,14 @@ int SPF_RemoveDeadCode(void*& context, int winHandler, short* options, short* pr
|
||||
return simpleTransformPass(REMOVE_DEAD_CODE_AND_UNPARSE, options, projName, folderName, output, outputSize, outputMessage, outputMessageSize);
|
||||
}
|
||||
|
||||
int SPF_InsertImplicitNone(void*& context, int winHandler, short* options, short* projName, short* folderName, short*& output,
|
||||
int*& outputSize, short*& outputMessage, int*& outputMessageSize)
|
||||
{
|
||||
MessageManager::clearCache();
|
||||
MessageManager::setWinHandler(winHandler);
|
||||
return simpleTransformPass(SET_IMPLICIT_NONE, options, projName, folderName, output, outputSize, outputMessage, outputMessageSize);
|
||||
}
|
||||
|
||||
static inline void convertBackSlash(char *str, int strL)
|
||||
{
|
||||
for (int z = 0; z < strL; ++z)
|
||||
@@ -2625,6 +2634,8 @@ const wstring Sapfor_RunTransformation(const char* transformName_c, const char*
|
||||
retCode = SPF_InsertPrivateFromGUI(context, winHandler, optSh, projSh, fold, output, outputSize, outputMessage, outputMessageSize);
|
||||
else if (whichRun == "SPF_RemoveDeadCode")
|
||||
retCode = SPF_RemoveDeadCode(context, winHandler, optSh, projSh, fold, output, outputSize, outputMessage, outputMessageSize);
|
||||
else if (whichRun == "SPF_InsertImplicitNone")
|
||||
retCode = SPF_InsertImplicitNone(context, winHandler, optSh, projSh, fold, output, outputSize, outputMessage, outputMessageSize);
|
||||
else
|
||||
{
|
||||
if (showDebug)
|
||||
|
||||
Reference in New Issue
Block a user