Support APPLY_FRAGMENT(WEIGHT(double)) clause: add weights to fragments of parallel regions (and use it in at loopAnalyzer)

This commit is contained in:
2025-05-10 15:27:03 +03:00
parent 29a8c30370
commit 738f2c5d12
5 changed files with 246 additions and 44 deletions

View File

@@ -17,7 +17,7 @@
struct ParallelRegionLines
{
ParallelRegionLines()
ParallelRegionLines(double weight = 1.0) : weight(weight)
{
lines = std::make_pair(-1, -1);
stats = std::make_pair<Statement*, Statement*>(NULL, NULL);
@@ -25,14 +25,15 @@ struct ParallelRegionLines
intervalAfter = std::make_pair<Statement*, Statement*>(NULL, NULL);
}
ParallelRegionLines(const std::pair<int, int> &lines) : lines(lines)
ParallelRegionLines(const std::pair<int, int> &lines, double weight = 1.0) : lines(lines), weight(weight)
{
stats = std::make_pair<Statement*, Statement*>(NULL, NULL);
intervalBefore = 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) : lines(lines), stats(stats)
ParallelRegionLines(const std::pair<int, int> &lines, const std::pair<Statement*, Statement*> stats, double weight = 1.0)
: lines(lines), stats(stats), weight(weight)
{
intervalBefore = std::make_pair<Statement*, Statement*>(NULL, NULL);
intervalAfter = std::make_pair<Statement*, Statement*>(NULL, NULL);
@@ -60,6 +61,8 @@ struct ParallelRegionLines
// <start, end> interval
std::pair<Statement*, Statement*> intervalBefore;
std::pair<Statement*, Statement*> intervalAfter;
double weight; // weight of the fragment among all fragments of this region
};
#if __SPF
@@ -114,7 +117,7 @@ public:
currentVariant = copy.currentVariant;
}
int AddLines(const std::pair<int, int> &linesToAdd, const std::string &file, const std::pair<Statement*, Statement*> *startEnd = NULL)
int AddLines(const std::pair<int, int> &linesToAdd, const std::string &file, const std::pair<Statement*, Statement*> *startEnd = NULL, double weight = 1.0)
{
if (linesToAdd.first > linesToAdd.second)
return -1;
@@ -124,17 +127,29 @@ public:
it = lines.insert(it, make_pair(file, std::vector<ParallelRegionLines>()));
if (startEnd)
it->second.push_back(ParallelRegionLines(linesToAdd, *startEnd));
it->second.push_back(ParallelRegionLines(linesToAdd, *startEnd, weight));
else
it->second.push_back(ParallelRegionLines(linesToAdd));
it->second.push_back(ParallelRegionLines(linesToAdd, weight));
return 0;
}
void AddFuncCalls(const std::string &func) { functionsCall.insert(func); }
void AddFuncCalls(const std::string &func, const std::string &file, const int line)
{
auto *found_lines = GetLinesByLine(file, line);
if (found_lines)
functionsCall[func].insert(found_lines);
}
#if __SPF
void AddFuncCallsToAllCalls(FuncInfo *func) { allFunctionsCall.insert(func); }
void AddFuncCallsToAllCalls(FuncInfo *func, const std::string &file, const int line)
{
auto *found_lines = GetLinesByLine(file, line);
if (found_lines)
allFunctionsCall[func].insert(found_lines);
}
#endif
uint64_t GetId() const { return regionId; }
@@ -174,10 +189,10 @@ public:
const DataDirective& GetDataDir() const { return dataDirectives; }
DataDirective& GetDataDirToModify() { return dataDirectives; }
const std::set<std::string>& GetFuncCalls() const { return functionsCall; }
const std::map<std::string, std::set<const ParallelRegionLines*>>& GetFuncCalls() const { return functionsCall; }
#if __SPF
const std::set<FuncInfo*>& GetAllFuncCalls() const { return allFunctionsCall; }
const std::map<FuncInfo*, std::set<const ParallelRegionLines*>>& 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>>>& GetUsedCommonArrays() const { return usedCommonArrays; }
@@ -216,7 +231,7 @@ public:
}
#endif
bool HasThisLine(const int line, const std::string &file) const
bool HasThisLine(const int line, const std::string &file, const ParallelRegionLines** found = nullptr) const
{
bool retVal = false;
auto it = lines.find(file);
@@ -227,6 +242,9 @@ public:
if (it->second[i].lines.first <= line && it->second[i].lines.second >= line)
{
retVal = true;
if (found)
*found = &(it->second[i]);
break;
}
}
@@ -283,7 +301,7 @@ public:
fprintf(fileOut, " originalName '%s'\n", originalName.c_str());
fprintf(fileOut, " functions call from %d:\n", (int)functionsCall.size());
for (auto &func : functionsCall)
fprintf(fileOut, " '%s'\n", func.c_str());
fprintf(fileOut, " '%s'\n", func.first.c_str());
fprintf(fileOut, " total lines %d:\n", (int)lines.size());
for (auto &line : lines)
{
@@ -353,11 +371,11 @@ private:
std::string originalName;
// file -> lines info
std::map<std::string, std::vector<ParallelRegionLines>> lines;
std::set<std::string> functionsCall;
std::map<std::string, std::set<const ParallelRegionLines*>> functionsCall; // func name -> fragments with calls
#if __SPF
// for RESOLVE_PAR_REGIONS
std::set<FuncInfo*> allFunctionsCall;
std::map<FuncInfo*, std::set<const ParallelRegionLines*>> allFunctionsCall; // function -> fragments with calls
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
//
@@ -399,4 +417,5 @@ private:
ParallelRegion* getRegionById(const std::vector<ParallelRegion*>& regions, const uint64_t regionId);
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);
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);