4 Commits

Author SHA1 Message Date
591679397b Merge pull request 'fix for pass manager and new pass improvements' (#7) from select_array_dim_conf_pass_xnp into master
Reviewed-on: Alexander_KS/SAPFOR/pulls/7
2023-09-27 12:58:50 +00:00
mkoch
bd17dde9b0 added error if no directives were inserted 2023-09-26 22:45:09 +03:00
mkoch
377e60df78 code style improvements 2023-09-26 22:13:21 +03:00
mkoch
c50bb82a48 fix applyRemovals for pass manager 2023-09-26 20:48:41 +03:00
4 changed files with 138 additions and 13 deletions

View File

@@ -1,10 +1,12 @@
#include "select_array_conf.h"
#include "../Utils/utils.h"
using std::map;
using std::string;
using std::vector;
using std::set;
using std::pair;
using std::wstring;
using std::inserter;
using std::copy;
@@ -229,3 +231,77 @@ 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__);
}

View File

@@ -15,3 +15,8 @@ void SelectArrayConfForParallelization(SgProject* proj, std::map<std::string, st
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);

View File

@@ -2179,6 +2179,7 @@ static bool runAnalysis(SgProject &project, const int curr_regime, const bool ne
map<string, vector<Messages>> localMessages;
SelectArrayConfForParallelization(&project, allFuncInfo, loopGraph, createdDirectives, localMessages, arrayLinksByFuncCalls, parallelRegions);
removeRegionsWithoutDirs(createdDirectives, parallelRegions, allFuncInfo, SPF_messages);
}
const float elapsed = duration_cast<milliseconds>(high_resolution_clock::now() - timeForPass).count() / 1000.;

View File

@@ -98,24 +98,67 @@ public:
list({ *this }) -= list({ right });
}
void applyRemovals() {
set<passes> to_process = { name }, processed;
void applyRemovals()
{
map<passes, set<passes>> to_process, processed;
to_process[name] = {};
while (!to_process.empty())
{
set<passes> to_process_next;
map<passes, set<passes>> to_process_next;
for (const auto& pass : to_process) {
if (processed.insert(pass).second) {
auto removals_it = passRemovals.find(pass);
auto deps_it = passDeps->find(pass);
for (const auto& pass : to_process)
{
auto processed_it = processed.find(pass.first);
auto& done_removals = processed_it != processed.end() ? processed_it->second : processed[pass.first];
if (removals_it != passRemovals.end() && deps_it != passDeps->end()) {
auto& removals = removals_it->second;
set<passes> removals_to_do;
bool process_pass = false;
if (processed_it == processed.end())
{
removals_to_do = done_removals = pass.second;
process_pass = true;
}
else
{
const auto& needed_removals = pass.second;
set_difference(needed_removals.begin(), needed_removals.end(), done_removals.begin(), done_removals.end(),
inserter(removals_to_do, removals_to_do.begin()));
process_pass = needed_removals.size() != 0;
done_removals.insert(removals_to_do.begin(), removals_to_do.end());
}
if (process_pass)
{
processed[pass.first] = pass.second;
auto removals_it = passRemovals.find(pass.first);
if (removals_it != passRemovals.end())
{
auto& removals_saved = removals_it->second;
set<passes> add;
set_difference(removals_saved.begin(), removals_saved.end(), done_removals.begin(), done_removals.end(),
inserter(add, add.begin()));
done_removals.insert(add.begin(), add.end());
removals_to_do.insert(add.begin(), add.end());
}
auto deps_it = passDeps->find(pass.first);
if (deps_it != passDeps->end())
{
auto& deps = deps_it->second;
for (auto dep_it = deps.begin(); dep_it != deps.end();) {
if (removals.find(*dep_it) == removals.end())
to_process_next.insert(*(dep_it++));
for (auto dep_it = deps.begin(); dep_it != deps.end();)
{
if (removals_to_do.find(*dep_it) == removals_to_do.end())
to_process_next[*(dep_it++)].insert(removals_to_do.begin(), removals_to_do.end());
else
dep_it = deps.erase(dep_it);
}