finalyze first version of private arrays search

This commit is contained in:
ALEXks
2025-12-11 12:26:39 +03:00
parent 678c2cf351
commit 3de06d9261
8 changed files with 32 additions and 16 deletions

View File

@@ -12,6 +12,7 @@
#include "SgUtils.h"
#include "graph_loops.h"
#include "CFGraph/CFGraph.h"
#include "utils.h"
using namespace std;
@@ -136,11 +137,11 @@ unsigned long long CalculateLength(const AccessingSet& array)
return result;
}
void AddPrivateArraysToLoop(LoopGraph* loop, ArrayAccessingIndexes privates)
void AddPrivateArraysToLoop(LoopGraph* loop, const ArrayAccessingIndexes& privates, set<SgStatement*>& insertedPrivates)
{
SgStatement* spfStat = new SgStatement(SPF_ANALYSIS_DIR);
spfStat->setlineNumber(loop->lineNum);
spfStat->setFileName((char*)loop->loop->fileName());
spfStat->setlineNumber(loop->loop->lineNumber());
spfStat->setFileName(loop->loop->fileName());
SgExpression* toAdd = new SgExpression(EXPR_LIST, new SgExpression(ACC_PRIVATE_OP), NULL, NULL);
set<SgSymbol*> arraysToInsert;
for (const auto& [_, accessingSet] : privates)
@@ -171,11 +172,15 @@ void AddPrivateArraysToLoop(LoopGraph* loop, ArrayAccessingIndexes privates)
}
toAdd->setLhs(new SgVarRefExp(elem));
}
if (arraysToInsert.size() == 0)
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
loop->loop->addAttribute(SPF_ANALYSIS_DIR, spfStat, sizeof(SgStatement));
loop->loop->insertStmtBefore(*spfStat, *loop->loop->controlParent());
insertedPrivates.insert(spfStat);
}
map<LoopGraph*, ArrayAccessingIndexes> FindPrivateArrays(map<string, vector<LoopGraph*>> &loopGraph, map<FuncInfo*, vector<SAPFOR::BasicBlock*>>& FullIR)
void FindPrivateArrays(map<string, vector<LoopGraph*>> &loopGraph, map<FuncInfo*, vector<SAPFOR::BasicBlock*>>& FullIR, set<SgStatement*> &insertedPrivates)
{
map<LoopGraph*, ArrayAccessingIndexes> result;
for (const auto& [fileName, loops] : loopGraph)
@@ -203,11 +208,9 @@ map<LoopGraph*, ArrayAccessingIndexes> FindPrivateArrays(map<string, vector<Loo
delete(loopRegion);
}
}
if (result.find(loop) != result.end() && !result[loop].empty())
{
AddPrivateArraysToLoop(loop, result[loop]);
}
AddPrivateArraysToLoop(loop, result[loop], insertedPrivates);
}
}
return result;
}

View File

@@ -2,11 +2,12 @@
#include <vector>
#include <map>
#include <set>
#include <unordered_set>
#include "range_structures.h"
#include "graph_loops.h"
#include "CFGraph/CFGraph.h"
std::map<LoopGraph*, ArrayAccessingIndexes> FindPrivateArrays(std::map<std::string, std::vector<LoopGraph*>>& loopGraph, std::map<FuncInfo*, std::vector<SAPFOR::BasicBlock*>>& FullIR);
void FindPrivateArrays(std::map<std::string, std::vector<LoopGraph*>>& loopGraph, std::map<FuncInfo*, std::vector<SAPFOR::BasicBlock*>>& FullIR, std::set<SgStatement*>& insertedPrivates);
std::pair<SAPFOR::BasicBlock*, std::unordered_set<SAPFOR::BasicBlock*>> GetBasicBlocksForLoop(const LoopGraph* loop, const std::vector<SAPFOR::BasicBlock*> blocks);

View File

@@ -279,7 +279,8 @@ static string unparseProjectIfNeed(SgFile* file, const int curr_regime, const bo
for (SgStatement* st = file->firstStatement(); st; st = st->lexNext())
if (isSPF_stat(st)) // except sapfor parallel regions and if attributes dont move
if (st->variant() != SPF_PARALLEL_REG_DIR && st->variant() != SPF_END_PARALLEL_REG_DIR)
toDel.push_back(st);
if (insertedPrivates.find(st) == insertedPrivates.end())
toDel.push_back(st);
for (auto& elem : toDel)
elem->deleteStmt();
@@ -1914,8 +1915,8 @@ static bool runAnalysis(SgProject &project, const int curr_regime, const bool ne
}
else if (curr_regime == TRANSFORM_ASSUMED_SIZE_PARAMETERS)
transformAssumedSizeParameters(allFuncInfo);
else if (curr_regime == FIND_PRIVATE_ARRAYS)
auto result = FindPrivateArrays(loopGraph, fullIR);
else if (curr_regime == FIND_PRIVATE_ARRAYS_ANALYSIS)
FindPrivateArrays(loopGraph, fullIR, insertedPrivates);
const float elapsed = duration_cast<milliseconds>(high_resolution_clock::now() - timeForPass).count() / 1000.;
const float elapsedGlobal = duration_cast<milliseconds>(high_resolution_clock::now() - globalTime).count() / 1000.;
@@ -2373,6 +2374,7 @@ void runPass(const int curr_regime, const char *proj_name, const char *folderNam
case SUBST_EXPR_RD_AND_UNPARSE:
case SUBST_EXPR_AND_UNPARSE:
case REMOVE_DEAD_CODE_AND_UNPARSE:
case FIND_PRIVATE_ARRAYS:
if (folderName)
runAnalysis(*project, UNPARSE_FILE, true, "", folderName);
else
@@ -2634,7 +2636,7 @@ int main(int argc, char **argv)
}
}
if (curr_regime == INSERT_PARALLEL_DIRS_NODIST)
if (curr_regime == INSERT_PARALLEL_DIRS_NODIST || curr_regime == FIND_PRIVATE_ARRAYS)
{
ignoreArrayDistributeState = true;
sharedMemoryParallelization = 1;

View File

@@ -183,6 +183,7 @@ enum passes {
SET_IMPLICIT_NONE,
RENAME_INLCUDES,
FIND_PRIVATE_ARRAYS_ANALYSIS,
FIND_PRIVATE_ARRAYS,
TRANSFORM_ASSUMED_SIZE_PARAMETERS,
@@ -371,6 +372,7 @@ static void setPassValues()
passNames[SET_IMPLICIT_NONE] = "SET_IMPLICIT_NONE";
passNames[RENAME_INLCUDES] = "RENAME_INLCUDES";
passNames[INSERT_NO_DISTR_FLAGS_FROM_GUI] = "INSERT_NO_DISTR_FLAGS_FROM_GUI";
passNames[FIND_PRIVATE_ARRAYS_ANALYSIS] = "FIND_PRIVATE_ARRAYS_ANALYSIS";
passNames[FIND_PRIVATE_ARRAYS] = "FIND_PRIVATE_ARRAYS";
passNames[TRANSFORM_ASSUMED_SIZE_PARAMETERS] = "TRANSFORM_ASSUMED_SIZE_PARAMETERS";

View File

@@ -175,6 +175,11 @@ std::set<std::tuple<std::string, int, std::string>> parametersOfProject; // [fil
//for GET_MIN_MAX_BLOCK_DIST
std::pair<int, int> min_max_block = std::make_pair(-1, -1);
//
//for FIND_PRIVATE_ARRAYS
std::set<SgStatement*> insertedPrivates;
//
const char* passNames[EMPTY_PASS + 1];
const char* optionNames[EMPTY_OPTION + 1];
bool passNamesWasInit = false;

View File

@@ -316,7 +316,8 @@ void InitPassesDependencies(map<passes, vector<passes>> &passDepsIn, set<passes>
list({ VERIFY_INCLUDES, CORRECT_VAR_DECL }) <= Pass(SET_IMPLICIT_NONE);
list({ CALL_GRAPH2, CALL_GRAPH, BUILD_IR, LOOP_GRAPH, LOOP_ANALYZER_DATA_DIST_S2 }) <= Pass(FIND_PRIVATE_ARRAYS);
list({ CALL_GRAPH2, CALL_GRAPH, BUILD_IR, LOOP_GRAPH, LOOP_ANALYZER_DATA_DIST_S2 }) <= Pass(FIND_PRIVATE_ARRAYS_ANALYSIS);
list({ FIND_PRIVATE_ARRAYS_ANALYSIS, CONVERT_LOOP_TO_ASSIGN, RESTORE_LOOP_FROM_ASSIGN, REVERT_SUBST_EXPR_RD }) <= Pass(FIND_PRIVATE_ARRAYS);
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,

View File

@@ -1,3 +1,3 @@
#pragma once
#define VERSION_SPF "2447"
#define VERSION_SPF "2448"

View File

@@ -1797,6 +1797,8 @@ int SPF_InsertPrivateArrayDirectives(void*& context, int winHandler, short* opti
{
MessageManager::clearCache();
MessageManager::setWinHandler(winHandler);
ignoreArrayDistributeState = true;
sharedMemoryParallelization = 1;
return simpleTransformPass(FIND_PRIVATE_ARRAYS, options, projName, folderName, output, outputMessage);
}