6 Commits

7 changed files with 45 additions and 176 deletions

1
.gitignore vendored
View File

@@ -74,7 +74,6 @@ Sapfor/Sapc++/Sapc++/x64/
Sapfor/Sapc++/x64/ Sapfor/Sapc++/x64/
/build /build
/cmake-build-debug
Sapfor/out/ Sapfor/out/
Sapfor/_bin/* Sapfor/_bin/*

View File

@@ -1635,9 +1635,9 @@ void loopAnalyzer(SgFile *file, vector<ParallelRegion*> &regions, map<tuple<int,
string fName = file->functions(i)->symbol()->identifier(); string fName = file->functions(i)->symbol()->identifier();
#if _WIN32 #if _WIN32
if (file->functions(i)->variant() != MODULE_STMT) if (file->functions(i)->variant() != MODULE_STMT)
sendMessage_2lvl(wstring(L"обработка функции '") + wstring(fName.begin(), fName.end()) + L"'"); sendMessage_2lvl(wstring(L"îáðàáîòêà ôóíêöèè '") + wstring(fName.begin(), fName.end()) + L"'");
else else
sendMessage_2lvl(wstring(L"обработка модуля '") + wstring(fName.begin(), fName.end()) + L"'"); sendMessage_2lvl(wstring(L"îáðàáîòêà ìîäóëÿ '") + wstring(fName.begin(), fName.end()) + L"'");
#else #else
if (file->functions(i)->variant() != MODULE_STMT) if (file->functions(i)->variant() != MODULE_STMT)
sendMessage_2lvl(wstring(L"processing function '") + wstring(fName.begin(), fName.end()) + L"'"); sendMessage_2lvl(wstring(L"processing function '") + wstring(fName.begin(), fName.end()) + L"'");
@@ -1710,10 +1710,7 @@ void loopAnalyzer(SgFile *file, vector<ParallelRegion*> &regions, map<tuple<int,
map<string, pair<SgSymbol*, SgStatement*>> notMappedDistributedArrays; map<string, pair<SgSymbol*, SgStatement*>> notMappedDistributedArrays;
set<string> mappedDistrbutedArrays; set<string> mappedDistrbutedArrays;
const ParallelRegionLines* prevParLines = NULL;
double prevLinesWeight = 1.0;
double currentWeight = 1.0; double currentWeight = 1.0;
while (st != lastNode) while (st != lastNode)
{ {
createNeededException(); createNeededException();
@@ -1736,31 +1733,13 @@ void loopAnalyzer(SgFile *file, vector<ParallelRegion*> &regions, map<tuple<int,
} }
const int currentLine = st->lineNumber() < -1 ? st->localLineNumber() : st->lineNumber(); const int currentLine = st->lineNumber() < -1 ? st->localLineNumber() : st->lineNumber();
auto regAndLines = getRegionAndLinesByLine(regions, st->fileName(), currentLine); ParallelRegion *currReg = getRegionByLine(regions, st->fileName(), currentLine);
auto *currReg = regAndLines.first;
auto *parLines = regAndLines.second;
if (currReg == NULL) if (currReg == NULL)
{ {
st = st->lexNext(); st = st->lexNext();
continue; continue;
} }
if (parLines != prevParLines)
{
prevParLines = parLines;
auto newParLinesWeight = parLines ? parLines->weight : 1.0;
if (prevParLines)
currentWeight /= prevLinesWeight;
if (parLines)
currentWeight *= newParLinesWeight;
prevLinesWeight = newParLinesWeight;
prevParLines = parLines;
}
if (isSgExecutableStatement(st) == NULL) if (isSgExecutableStatement(st) == NULL)
delcsStatViewed.insert(st); delcsStatViewed.insert(st);
else if (!sharedMemoryParallelization && else if (!sharedMemoryParallelization &&
@@ -2189,7 +2168,7 @@ void loopAnalyzer(SgFile *file, vector<ParallelRegion*> &regions, map<tuple<int,
{ {
string fName = file->functions(i)->symbol()->identifier(); string fName = file->functions(i)->symbol()->identifier();
#ifdef _WIN32 #ifdef _WIN32
sendMessage_2lvl(wstring(L"обработка цикла ") + std::to_wstring(idx) + L"/" + std::to_wstring(convertedLoopInfo.size())); sendMessage_2lvl(wstring(L"îáðàáîòêà öèêëà ") + std::to_wstring(idx) + L"/" + std::to_wstring(convertedLoopInfo.size()));
#else #else
sendMessage_2lvl(wstring(L"processing loop ") + std::to_wstring(idx) + L"/" + std::to_wstring(convertedLoopInfo.size())); sendMessage_2lvl(wstring(L"processing loop ") + std::to_wstring(idx) + L"/" + std::to_wstring(convertedLoopInfo.size()));
#endif #endif

View File

@@ -93,10 +93,8 @@ static inline SgStatement* getParentStat(SgStatement *st)
return iterator; return iterator;
} }
static void updateRegionInfo(SgStatement *st, map<string, pair<Statement*, Statement*>> &startEnd, static void updateRegionInfo(SgStatement *st, map<string, pair<Statement*, Statement*>> &startEnd, map<string, pair<int, int>> &lines_,
map<string, pair<int, int>> &lines_, set<string> &funcCallFromReg, const map<string, FuncInfo*> &mapFuncs)
map<string, map<string, set<int>>> &funcCallFromReg,
const map<string, FuncInfo*> &mapFuncs)
{ {
string containsPrefix = ""; string containsPrefix = "";
SgStatement *st_ps = getParentStat(st); SgStatement *st_ps = getParentStat(st);
@@ -105,26 +103,17 @@ static void updateRegionInfo(SgStatement *st, map<string, pair<Statement*, State
containsPrefix = st_ps->symbol()->identifier() + string("."); containsPrefix = st_ps->symbol()->identifier() + string(".");
extendRegionInfo(st, startEnd, lines_); extendRegionInfo(st, startEnd, lines_);
set<string> callsFromStatement;
if (st->variant() == PROC_STAT) if (st->variant() == PROC_STAT)
{ {
string fullName = st->symbol()->identifier(); string fullName = st->symbol()->identifier();
//check contains //check contains
if (mapFuncs.find(containsPrefix + fullName) != mapFuncs.end()) if (mapFuncs.find(containsPrefix + fullName) != mapFuncs.end())
fullName = containsPrefix + fullName; fullName = containsPrefix + fullName;
callsFromStatement.insert(fullName); funcCallFromReg.insert(fullName);
} }
for (int z = 0; z < 3; ++z) for (int z = 0; z < 3; ++z)
findFuncCalls(st->expr(z), callsFromStatement, containsPrefix, mapFuncs); findFuncCalls(st->expr(z), funcCallFromReg, containsPrefix, mapFuncs);
string filename = st->fileName();
int line = st->lineNumber();
for (const auto &func_name : callsFromStatement)
funcCallFromReg[func_name][filename].insert(line);
} }
static void fillArrayNamesInReg(set<string> &usedArrayInRegion, SgExpression *exp) static void fillArrayNamesInReg(set<string> &usedArrayInRegion, SgExpression *exp)
@@ -329,9 +318,8 @@ void fillRegionLines(SgFile *file, vector<ParallelRegion*> &regions, vector<Mess
string regionName = ""; string regionName = "";
map<string, pair<Statement*, Statement*>> startEnd; map<string, pair<Statement*, Statement*>> startEnd;
map<string, pair<int, int>> lines_; map<string, pair<int, int>> lines_;
map<string, map<string, set<int>>> funcCallFromReg; set<string> funcCallFromReg;
bool regionStarted = false; bool regionStarted = false;
double fragmentWeight = 1.0;
vector<SgStatement*> toDel; vector<SgStatement*> toDel;
for (int i = 0; i < funcNum; ++i) for (int i = 0; i < funcNum; ++i)
@@ -380,33 +368,6 @@ void fillRegionLines(SgFile *file, vector<ParallelRegion*> &regions, vector<Mess
itFunc->second->callRegions.insert(0); itFunc->second->callRegions.insert(0);
} }
} }
// parse SPF_APPLY_FRAGMENT clause
auto *apply_fragment = data->expr(1);
fragmentWeight = 1.0;
while (apply_fragment)
{
auto *curr = apply_fragment->lhs();
if (curr)
{
__spf_print(1, "%s %d\n", curr->unparse(), curr->variant());
if (curr->variant() == SPF_WEIGHT_OP)
{
if (curr->lhs() &&
isSgValueExp(curr->lhs()) &&
isSgValueExp(curr->lhs())->doubleValue())
{
fragmentWeight = strtod(isSgValueExp(curr->lhs())->doubleValue(), NULL);
__spf_print(1, "->> %lf\n", fragmentWeight);
}
else
__spf_print(1, "WEIGHT clause without double argument\n");
}
}
apply_fragment = apply_fragment->rhs();
}
} }
if (next && next->variant() == SPF_END_PARALLEL_REG_DIR) if (next && next->variant() == SPF_END_PARALLEL_REG_DIR)
@@ -439,12 +400,10 @@ void fillRegionLines(SgFile *file, vector<ParallelRegion*> &regions, vector<Mess
extendRegionInfo(st, startEnd, lines_, true); extendRegionInfo(st, startEnd, lines_, true);
for (auto itRegInfo = startEnd.begin(); itRegInfo != startEnd.end(); ++itRegInfo) for (auto itRegInfo = startEnd.begin(); itRegInfo != startEnd.end(); ++itRegInfo)
currReg->AddLines(lines_[itRegInfo->first], itRegInfo->first, &itRegInfo->second, fragmentWeight); currReg->AddLines(lines_[itRegInfo->first], itRegInfo->first, &itRegInfo->second);
for (auto &by_func : funcCallFromReg) for (auto &func : funcCallFromReg)
for (auto &by_file : by_func.second) currReg->AddFuncCalls(func);
for(auto &by_line : by_file.second)
currReg->AddFuncCalls(by_func.first, by_file.first, by_line);
filterUserDirectives(currReg, usedArrayInRegion, userDvmRedistrDirs, userDvmRealignDirs, userDvmShadowDirs); filterUserDirectives(currReg, usedArrayInRegion, userDvmRedistrDirs, userDvmRealignDirs, userDvmShadowDirs);
currReg->AddUserDirectives(userDvmRealignDirs, DVM_REALIGN_DIR); currReg->AddUserDirectives(userDvmRealignDirs, DVM_REALIGN_DIR);
@@ -537,48 +496,34 @@ void fillRegionLinesStep2(vector<ParallelRegion*> &regions, const map<string, ve
{ {
if (regions[i]->GetName() != "DEFAULT") if (regions[i]->GetName() != "DEFAULT")
for (auto &func : regions[i]->GetFuncCalls()) for (auto &func : regions[i]->GetFuncCalls())
setExplicitFlag(func.first, funcMap); setExplicitFlag(func, funcMap);
} }
for (int i = 0; i < regions.size(); ++i) for (int i = 0; i < regions.size(); ++i)
{ {
if (regions[i]->GetName() != "DEFAULT") if (regions[i]->GetName() != "DEFAULT")
{ {
map<string, double> uniqFuncCalls; set<string> uniqFuncCalls;
map<string, map<string, set<int>>> callPlaces;
for (auto &elem : regions[i]->GetFuncCalls()) for (auto &elem : regions[i]->GetFuncCalls())
{ uniqFuncCalls.insert(elem);
double max_weight = 0;
for (auto* fragment : elem.second)
if (fragment->weight > max_weight)
max_weight = fragment->weight;
uniqFuncCalls[elem.first] = max_weight;
}
bool wasChanged = true;
auto funcsBefore = uniqFuncCalls;
bool wasChanged = 1;
while (wasChanged) while (wasChanged)
{ {
wasChanged = false; wasChanged = 0;
auto updated = uniqFuncCalls;
for (auto &uniqF : uniqFuncCalls) for (auto &uniqF : uniqFuncCalls)
{ {
auto func = funcMap.find(uniqF.first); auto func = funcMap.find(uniqF);
if (func != funcMap.end()) if (func != funcMap.end())
{ {
for (auto &call : func->second->callsFromDetailed) for (auto &calls : func->second->callsFrom)
{ {
auto it = updated.find(call.detailCallsFrom.first); auto it = uniqFuncCalls.find(calls);
if (it == updated.end()) if (it == uniqFuncCalls.end())
updated.insert({call.detailCallsFrom.first, uniqF.second}); {
else uniqFuncCalls.insert(it, calls);
it->second = std::max(it->second, uniqF.second); wasChanged = 1;
}
callPlaces[call.detailCallsFrom.first][func->second->fileName].insert(call.detailCallsFrom.second);
} }
} }
} }
@@ -587,27 +532,21 @@ void fillRegionLinesStep2(vector<ParallelRegion*> &regions, const map<string, ve
string toPrint = ""; string toPrint = "";
for (auto &elem : uniqFuncCalls) for (auto &elem : uniqFuncCalls)
{ {
auto it = funcMap.find(elem.first); auto it = funcMap.find(elem);
if (it != funcMap.end()) if (it != funcMap.end())
{ {
regions[i]->AddLines(it->second->linesNum, it->second->fileName, NULL, elem.second); regions[i]->AddLines(it->second->linesNum, it->second->fileName);
regions[i]->AddFuncCallsToAllCalls(it->second);
if (it->second->inRegion == 0) if (it->second->inRegion == 0)
it->second->inRegion = 2; it->second->inRegion = 2;
it->second->callRegions.insert(i); it->second->callRegions.insert(i);
toPrint += elem.first + " "; toPrint += elem + " ";
} }
} }
for (auto &elem : callPlaces)
{
for (const auto &byFile : elem.second)
for (auto byLine : byFile.second)
regions[i]->AddFuncCalls(elem.first, byFile.first, byLine);
}
if (toPrint != "") if (toPrint != "")
__spf_print(1, "[%s]: funcs: %s\n", regions[i]->GetName().c_str(), toPrint.c_str()); __spf_print(1, "[%s]: funcs: %s\n", regions[i]->GetName().c_str(), toPrint.c_str());
} }

View File

@@ -19,7 +19,7 @@
struct ParallelRegionLines struct ParallelRegionLines
{ {
ParallelRegionLines(double weight = 1.0) : weight(weight) ParallelRegionLines()
{ {
lines = std::make_pair(-1, -1); lines = std::make_pair(-1, -1);
stats = std::make_pair<Statement*, Statement*>(NULL, NULL); stats = std::make_pair<Statement*, Statement*>(NULL, NULL);
@@ -27,15 +27,14 @@ struct ParallelRegionLines
intervalAfter = std::make_pair<Statement*, Statement*>(NULL, NULL); intervalAfter = std::make_pair<Statement*, Statement*>(NULL, NULL);
} }
ParallelRegionLines(const std::pair<int, int> &lines, double weight = 1.0) : lines(lines), weight(weight) ParallelRegionLines(const std::pair<int, int> &lines) : lines(lines)
{ {
stats = std::make_pair<Statement*, Statement*>(NULL, NULL); stats = std::make_pair<Statement*, Statement*>(NULL, NULL);
intervalBefore = std::make_pair<Statement*, Statement*>(NULL, NULL); intervalBefore = std::make_pair<Statement*, Statement*>(NULL, NULL);
intervalAfter = std::make_pair<Statement*, Statement*>(NULL, NULL); intervalAfter = std::make_pair<Statement*, Statement*>(NULL, NULL);
} }
ParallelRegionLines(const std::pair<int, int> &lines, const std::pair<Statement*, Statement*> stats, double weight = 1.0) ParallelRegionLines(const std::pair<int, int> &lines, const std::pair<Statement*, Statement*> stats) : lines(lines), stats(stats)
: lines(lines), stats(stats), weight(weight)
{ {
intervalBefore = std::make_pair<Statement*, Statement*>(NULL, NULL); intervalBefore = std::make_pair<Statement*, Statement*>(NULL, NULL);
intervalAfter = std::make_pair<Statement*, Statement*>(NULL, NULL); intervalAfter = std::make_pair<Statement*, Statement*>(NULL, NULL);
@@ -63,8 +62,6 @@ struct ParallelRegionLines
// <start, end> interval // <start, end> interval
std::pair<Statement*, Statement*> intervalBefore; std::pair<Statement*, Statement*> intervalBefore;
std::pair<Statement*, Statement*> intervalAfter; std::pair<Statement*, Statement*> intervalAfter;
double weight; // weight of the fragment among all fragments of this region
}; };
#if __SPF #if __SPF
@@ -119,7 +116,7 @@ public:
currentVariant = copy.currentVariant; currentVariant = copy.currentVariant;
} }
int AddLines(const std::pair<int, int> &linesToAdd, const std::string &file, const std::pair<Statement*, Statement*> *startEnd = NULL, double weight = 1.0) int AddLines(const std::pair<int, int> &linesToAdd, const std::string &file, const std::pair<Statement*, Statement*> *startEnd = NULL)
{ {
if (linesToAdd.first > linesToAdd.second) if (linesToAdd.first > linesToAdd.second)
return -1; return -1;
@@ -129,29 +126,17 @@ public:
it = lines.insert(it, make_pair(file, std::vector<ParallelRegionLines>())); it = lines.insert(it, make_pair(file, std::vector<ParallelRegionLines>()));
if (startEnd) if (startEnd)
it->second.push_back(ParallelRegionLines(linesToAdd, *startEnd, weight)); it->second.push_back(ParallelRegionLines(linesToAdd, *startEnd));
else else
it->second.push_back(ParallelRegionLines(linesToAdd, weight)); it->second.push_back(ParallelRegionLines(linesToAdd));
return 0; return 0;
} }
void AddFuncCalls(const std::string &func, const std::string &file, const int line) void AddFuncCalls(const std::string &func) { functionsCall.insert(func); }
{
auto *found_lines = GetLinesByLine(file, line);
if (found_lines)
functionsCall[func].insert(found_lines);
}
#if __SPF #if __SPF
void AddFuncCallsToAllCalls(FuncInfo *func, const std::string &file, const int line) void AddFuncCallsToAllCalls(FuncInfo *func) { allFunctionsCall.insert(func); }
{
auto *found_lines = GetLinesByLine(file, line);
if (found_lines)
allFunctionsCall[func].insert(found_lines);
}
#endif #endif
uint64_t GetId() const { return regionId; } uint64_t GetId() const { return regionId; }
@@ -191,10 +176,10 @@ public:
const DataDirective& GetDataDir() const { return dataDirectives; } const DataDirective& GetDataDir() const { return dataDirectives; }
DataDirective& GetDataDirToModify() { return dataDirectives; } DataDirective& GetDataDirToModify() { return dataDirectives; }
const std::map<std::string, std::set<const ParallelRegionLines*>>& GetFuncCalls() const { return functionsCall; } const std::set<std::string>& GetFuncCalls() const { return functionsCall; }
#if __SPF #if __SPF
const std::map<FuncInfo*, std::set<const ParallelRegionLines*>>& GetAllFuncCalls() const { return allFunctionsCall; } const std::set<FuncInfo*>& GetAllFuncCalls() const { return allFunctionsCall; }
const std::map<FuncInfo*, std::map<DIST::Array*, std::vector<ParallelRegionLines>>>& GetUsedLocalArrays() const { return usedLocalArrays; } const std::map<FuncInfo*, std::map<DIST::Array*, std::vector<ParallelRegionLines>>>& GetUsedLocalArrays() const { return usedLocalArrays; }
const std::map<FuncInfo*, std::map<DIST::Array*, std::vector<ParallelRegionLines>>>& GetUsedCommonArrays() const { return usedCommonArrays; } const std::map<FuncInfo*, std::map<DIST::Array*, std::vector<ParallelRegionLines>>>& GetUsedCommonArrays() const { return usedCommonArrays; }
@@ -233,7 +218,7 @@ public:
} }
#endif #endif
bool HasThisLine(const int line, const std::string &file, const ParallelRegionLines** found = nullptr) const bool HasThisLine(const int line, const std::string &file) const
{ {
bool retVal = false; bool retVal = false;
auto it = lines.find(file); auto it = lines.find(file);
@@ -244,9 +229,6 @@ public:
if (it->second[i].lines.first <= line && it->second[i].lines.second >= line) if (it->second[i].lines.first <= line && it->second[i].lines.second >= line)
{ {
retVal = true; retVal = true;
if (found)
*found = &(it->second[i]);
break; break;
} }
} }
@@ -310,7 +292,7 @@ public:
fprintf(fileOut, " originalName '%s'\n", originalName.c_str()); fprintf(fileOut, " originalName '%s'\n", originalName.c_str());
fprintf(fileOut, " functions call from %d:\n", (int)functionsCall.size()); fprintf(fileOut, " functions call from %d:\n", (int)functionsCall.size());
for (auto &func : functionsCall) for (auto &func : functionsCall)
fprintf(fileOut, " '%s'\n", func.first.c_str()); fprintf(fileOut, " '%s'\n", func.c_str());
fprintf(fileOut, " total lines %d:\n", (int)lines.size()); fprintf(fileOut, " total lines %d:\n", (int)lines.size());
for (auto &line : lines) for (auto &line : lines)
{ {
@@ -380,11 +362,11 @@ private:
std::string originalName; std::string originalName;
// file -> lines info // file -> lines info
std::map<std::string, std::vector<ParallelRegionLines>> lines; std::map<std::string, std::vector<ParallelRegionLines>> lines;
std::map<std::string, std::set<const ParallelRegionLines*>> functionsCall; // func name -> fragments with calls std::set<std::string> functionsCall;
#if __SPF #if __SPF
// for RESOLVE_PAR_REGIONS // for RESOLVE_PAR_REGIONS
std::map<FuncInfo*, std::set<const ParallelRegionLines*>> allFunctionsCall; // function -> fragments with calls std::set<FuncInfo*> allFunctionsCall;
std::map<FuncInfo*, std::map<DIST::Array*, std::vector<ParallelRegionLines>>> usedLocalArrays; // func -> array -> lines std::map<FuncInfo*, std::map<DIST::Array*, std::vector<ParallelRegionLines>>> usedLocalArrays; // func -> array -> lines
std::map<FuncInfo*, std::map<DIST::Array*, std::vector<ParallelRegionLines>>> usedCommonArrays; // func -> array -> lines std::map<FuncInfo*, std::map<DIST::Array*, std::vector<ParallelRegionLines>>> usedCommonArrays; // func -> array -> lines
// //
@@ -426,5 +408,4 @@ private:
ParallelRegion* getRegionById(const std::vector<ParallelRegion*>& regions, const uint64_t regionId); ParallelRegion* getRegionById(const std::vector<ParallelRegion*>& regions, const uint64_t regionId);
ParallelRegion* getRegionByName(const std::vector<ParallelRegion*>& regions, const std::string& regionName); ParallelRegion* getRegionByName(const std::vector<ParallelRegion*>& regions, const std::string& regionName);
ParallelRegion* getRegionByLine(const std::vector<ParallelRegion*>& regions, const std::string& file, const int line); ParallelRegion* getRegionByLine(const std::vector<ParallelRegion*>& regions, const std::string& file, const int line);
std::pair<ParallelRegion*, const ParallelRegionLines*> getRegionAndLinesByLine(const std::vector<ParallelRegion*>& regions, const std::string& file, const int line);
std::set<ParallelRegion*> getAllRegionsByLine(const std::vector<ParallelRegion*>& regions, const std::string& file, const int line); std::set<ParallelRegion*> getAllRegionsByLine(const std::vector<ParallelRegion*>& regions, const std::string& file, const int line);

View File

@@ -1415,35 +1415,6 @@ ParallelRegion* getRegionByLine(const vector<ParallelRegion*>& regions, const st
return NULL; return NULL;
} }
std::pair<ParallelRegion*, const ParallelRegionLines*> getRegionAndLinesByLine(const vector<ParallelRegion*>& regions, const string& file, const int line)
{
if (regions.size() == 1 && regions[0]->GetName() == "DEFAULT") // only default
return { regions[0], NULL };
else if (regions.size() > 0)
{
map<ParallelRegion*, const ParallelRegionLines*> regFound;
const ParallelRegionLines* foundLines = NULL;
for (int i = 0; i < regions.size(); ++i)
if (regions[i]->HasThisLine(line, file, &foundLines))
regFound[regions[i]] = foundLines;
if (regFound.size() == 0)
return { NULL, NULL };
else if (regFound.size() == 1)
return *regFound.begin();
else
{
__spf_print(1, "WARN: this lines included in more than one region!!\n");
return { NULL, NULL };
}
}
else
return { NULL, NULL };
return { NULL, NULL };
}
set<ParallelRegion*> getAllRegionsByLine(const vector<ParallelRegion*>& regions, const string& file, const int line) set<ParallelRegion*> getAllRegionsByLine(const vector<ParallelRegion*>& regions, const string& file, const int line)
{ {
set<ParallelRegion*> regFound; set<ParallelRegion*> regFound;