4 Commits

34 changed files with 906 additions and 1034 deletions

View File

@@ -166,6 +166,8 @@ set(PARALLEL_REG src/ParallelizationRegions/ParRegions.cpp
set(ARRAY_PROP src/ArrayConstantPropagation/propagation.cpp set(ARRAY_PROP src/ArrayConstantPropagation/propagation.cpp
src/ArrayConstantPropagation/propagation.h src/ArrayConstantPropagation/propagation.h
) )
set(MERGE_COPY_ARRAYS src/ParallelizationRegions/parse_merge_dirs.cpp
src/ParallelizationRegions/parse_merge_dirs.h)
set(TR_DEAD_CODE src/Transformations/DeadCodeRemoving/dead_code.cpp set(TR_DEAD_CODE src/Transformations/DeadCodeRemoving/dead_code.cpp
src/Transformations/DeadCodeRemoving/dead_code.h) src/Transformations/DeadCodeRemoving/dead_code.h)
@@ -338,9 +340,7 @@ set(MAIN src/Sapfor.cpp
src/Utils/PassManager.h) src/Utils/PassManager.h)
set(PREDICTOR src/Predictor/PredictScheme.cpp set(PREDICTOR src/Predictor/PredictScheme.cpp
src/Predictor/PredictScheme.h src/Predictor/PredictScheme.h)
src/Predictor/PredictSchemeWithLibrary.cpp
src/Predictor/PredictSchemeWithLibrary.h)
set(LIBPREDICTOR ${libpred_sources}/cluster.cpp set(LIBPREDICTOR ${libpred_sources}/cluster.cpp
${libpred_sources}/predictor.cpp ${libpred_sources}/predictor.cpp
@@ -428,6 +428,7 @@ set(SOURCE_EXE
${LOOP_ANALYZER} ${LOOP_ANALYZER}
${TRANSFORMS} ${TRANSFORMS}
${PARALLEL_REG} ${PARALLEL_REG}
${MERGE_COPY_ARRAYS}
${PRIV} ${PRIV}
${ARRAY_PROP} ${ARRAY_PROP}
${FDVM} ${FDVM}
@@ -481,6 +482,7 @@ source_group (GraphCall FILES ${GR_CALL})
source_group (GraphLoop FILES ${GR_LOOP}) source_group (GraphLoop FILES ${GR_LOOP})
source_group (LoopAnalyzer FILES ${LOOP_ANALYZER}) source_group (LoopAnalyzer FILES ${LOOP_ANALYZER})
source_group (ParallelizationRegions FILES ${PARALLEL_REG}) source_group (ParallelizationRegions FILES ${PARALLEL_REG})
source_group (MergeCopyArrays FILES ${MERGE_COPY_ARRAYS})
source_group (PrivateAnalyzer FILES ${PRIV}) source_group (PrivateAnalyzer FILES ${PRIV})
source_group (ArrayConstantPropagation FILES ${ARRAY_PROP}) source_group (ArrayConstantPropagation FILES ${ARRAY_PROP})
source_group (FDVM_Compiler FILES ${FDVM}) source_group (FDVM_Compiler FILES ${FDVM})

View File

@@ -1162,9 +1162,8 @@ map<FuncInfo*, vector<BBlock*>> buildCFG(const map<string, CommonBlock*>& common
if (SgFile::switchToFile(oldFile) == -1) if (SgFile::switchToFile(oldFile) == -1)
printInternalError(convertFileName(__FILE__).c_str(), __LINE__); printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
if (!settings.withUnreachable) for (auto& [func, blocks] : result)
for (auto& [func, blocks] : result) removedUnreachableBlocks(blocks);
removedUnreachableBlocks(blocks);
return result; return result;
} }

View File

@@ -105,52 +105,23 @@ namespace SAPFOR
struct CFG_Settings struct CFG_Settings
{ {
enum setting { CFG_atLeastOneIterInLoop = 1,
CFG_withRD = 2,
CFG_withRegisters = 3,
CFG_withSPF = 4,
CFG_withDVM = 5,
CFG_withCallsInBlocks = 6,
CFG_withCallFrom = 7,
CFG_withDominators = 8,
CFG_withUnreachable = 9 };
bool atLeastOneIterInLoop = false; bool atLeastOneIterInLoop = false;
bool withRD = false; bool withRD = true;
bool withRegisters = false; bool withRegisters = false;
bool withSPF = false; bool withSPF = false;
bool withDVM = false; bool withDVM = false;
bool withCallsInBlocks = false; // separate each F_CALL to own BasicBlock bool withCallsInBlocks = false; // separate each F_CALL to own BasicBlock
bool withCallFrom = false; bool withCallFrom = true;
bool withDominators = false; bool withDominators = true;
bool withUnreachable = false;
explicit CFG_Settings(const std::set<setting> &settings = { CFG_withRD, CFG_withCallFrom, CFG_withDominators }) explicit CFG_Settings(int) { }
{
for (auto& set : settings) explicit CFG_Settings(bool atLeastOneIterInLoop = false, bool withRD = true, bool withRegisters = false,
{ bool withDVM = false, bool withSPF = false, bool withCallsInBlocks = false,
if (set == CFG_atLeastOneIterInLoop) bool withCallFrom = true, bool withDominators = true) :
atLeastOneIterInLoop = true; atLeastOneIterInLoop(atLeastOneIterInLoop), withRD(withRD), withRegisters(withRegisters), withDVM(withDVM), withSPF(withSPF),
else if (set == CFG_withRD) withCallsInBlocks(withCallsInBlocks), withCallFrom(withCallFrom), withDominators(withDominators)
withRD = true; { }
else if (set == CFG_withRegisters)
withRegisters = true;
else if (set == CFG_withSPF)
withSPF = true;
else if (set == CFG_withDVM)
withDVM = true;
else if (set == CFG_withCallsInBlocks)
withCallsInBlocks = true;
else if (set == CFG_withCallFrom)
withCallFrom = true;
else if (set == CFG_withDominators)
withDominators = true;
else if (set == CFG_withUnreachable)
withUnreachable = true;
else
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
}
}
}; };
} }

View File

@@ -321,12 +321,6 @@ static set<SAPFOR::BasicBlock*> analyzeLoop(LoopGraph* loop, const set<SAPFOR::B
} }
} }
if (currentLoop.empty()) // can't find loop IR - loop unreachable!
{
__spf_print(1, "Unreachable loop on %s:%d\n", current_file->filename(), loop_operator->lineNumber());
return currentLoop;
}
if (!head_block) if (!head_block)
printInternalError(convertFileName(__FILE__).c_str(), __LINE__); printInternalError(convertFileName(__FILE__).c_str(), __LINE__);

View File

@@ -122,7 +122,6 @@ static LoopGraph* createDirectiveForLoop(LoopGraph *currentLoop, MapToArray &mai
if (found == false) if (found == false)
{ {
directive->shadowRenew.push_back(make_pair(key, vector<pair<int, int>>())); directive->shadowRenew.push_back(make_pair(key, vector<pair<int, int>>()));
directive->shadowRenewCorner.push_back(false);
const DIST::Array *arrayRef = read; const DIST::Array *arrayRef = read;
for (int i = 0; i < arrayRef->GetDimSize(); ++i) for (int i = 0; i < arrayRef->GetDimSize(); ++i)

View File

@@ -853,21 +853,12 @@ static pair<string, string> getModuleRename(const set<SgStatement*>& allocatable
return make_pair("", ""); return make_pair("", "");
} }
static void doRename(string& str, const pair<string, string>& renamePair)
{
auto it = str.find(renamePair.first);
if (it != string::npos)
if (str[it + renamePair.first.size()] == '(' && str[it - 1] == ' ')
str = str.replace(it, renamePair.first.size(), renamePair.second);
}
static pair<DIST::Array*, string> static pair<DIST::Array*, string>
getNewDirective(const string &fullArrayName, getNewDirective(const string &fullArrayName,
const vector<string> &distrRules, const vector<string> &distrRules,
const vector<string> &alignRules, const vector<string> &alignRules,
const DataDirective &dataDir, const DataDirective &dataDir,
const set<SgStatement*>& allocatableStmts, const set<SgStatement*>& allocatableStmts)
const pair<string, int>& position_decl)
{ {
string out = ""; string out = "";
DIST::Array* outA = NULL; DIST::Array* outA = NULL;
@@ -886,8 +877,7 @@ getNewDirective(const string &fullArrayName,
for (int i = 0; i < dataDir.alignRules.size(); ++i) for (int i = 0; i < dataDir.alignRules.size(); ++i)
{ {
auto alignArray = dataDir.alignRules[i].alignArray; if (dataDir.alignRules[i].alignArray->GetName() == fullArrayName)
if (alignArray->GetName() == fullArrayName)
{ {
string rule = alignRules[i]; string rule = alignRules[i];
if (allocatableStmts.size()) if (allocatableStmts.size())
@@ -899,21 +889,21 @@ getNewDirective(const string &fullArrayName,
it = rule.find("ALIGN", it + 7); it = rule.find("ALIGN", it + 7);
} }
auto renamePair = getModuleRename(allocatableStmts, alignArray); auto renamePair = getModuleRename(allocatableStmts, dataDir.alignRules[i].alignArray);
doRename(rule, renamePair); if (renamePair.first != "")
} {
else if (alignArray->GetLocation().first == DIST::l_COMMON) it = rule.find(renamePair.first);
{ if (it != string::npos)
auto symb = alignArray->GetDeclSymbol(position_decl); if (rule[it + renamePair.first.size()] == '(' && rule[it - 1] == ' ')
if (symb->identifier() != alignArray->GetShortName()) rule = rule.replace(it, renamePair.first.size(), renamePair.second);
doRename(rule, make_pair(alignArray->GetShortName(), symb->identifier())); }
} }
out += "!DVM$ " + rule + "\n"; out += "!DVM$ " + rule + "\n";
if (!out_free_form) if (!out_free_form)
out = splitDirective(out); out = splitDirective(out);
return make_pair(alignArray, out); return make_pair(dataDir.alignRules[i].alignArray, out);
} }
} }
@@ -1753,7 +1743,7 @@ void insertDistributionToFile(SgFile *file, const char *fin_name, const DataDire
if (allocatableStmtsCopy.size()) if (allocatableStmtsCopy.size())
allocatableStmts = filterAllocateStats(file, allocatableStmtsCopy, currSymb->identifier()); allocatableStmts = filterAllocateStats(file, allocatableStmtsCopy, currSymb->identifier());
pair<DIST::Array*, string> dirWithArray = getNewDirective(fullArrayName, distrRules, alignRules, dataDir, allocatableStmts, make_pair(st->fileName(), st->lineNumber())); pair<DIST::Array*, string> dirWithArray = getNewDirective(fullArrayName, distrRules, alignRules, dataDir, allocatableStmts);
string toInsert = dirWithArray.second; string toInsert = dirWithArray.second;
if (toInsert != "") if (toInsert != "")
@@ -1985,27 +1975,20 @@ void insertDistributionToFile(SgFile *file, const char *fin_name, const DataDire
set<string> toInsertArrays; set<string> toInsertArrays;
for (auto &array : dynamicArraysLocal) for (auto &array : dynamicArraysLocal)
{ {
string name = array->GetShortName();
if (array->GetLocation().first == DIST::l_COMMON)
{
auto symb = array->GetDeclSymbol(make_pair(st->fileName(), st->lineNumber()));
name = symb->identifier();
}
if (extractDir) if (extractDir)
{ {
if (dynamicArraysAdded.find(name) != dynamicArraysAdded.end()) if (dynamicArraysAdded.find(array->GetShortName()) != dynamicArraysAdded.end())
{ {
dynamicArraysAdded.erase(name); dynamicArraysAdded.erase(array->GetShortName());
toInsertArrays.insert(name); toInsertArrays.insert(array->GetShortName());
} }
} }
else else
{ {
if (dynamicArraysAdded.find(name) == dynamicArraysAdded.end()) if (dynamicArraysAdded.find(array->GetShortName()) == dynamicArraysAdded.end())
{ {
dynamicArraysAdded.insert(name); dynamicArraysAdded.insert(array->GetShortName());
toInsertArrays.insert(name); toInsertArrays.insert(array->GetShortName());
} }
} }
} }
@@ -2162,14 +2145,7 @@ void insertShadowSpecToFile(SgFile *file, const char *fin_name, const set<string
if (needToGen) if (needToGen)
{ {
string name = array->GetShortName(); string shadowSpecInsert = "!DVM$ SHADOW " + array->GetShortName() + "(";
if (array->GetLocation().first == DIST::l_COMMON)
{
auto symb = array->GetDeclSymbol(make_pair(st->fileName(), st->lineNumber()));
name = symb->identifier();
}
string shadowSpecInsert = "!DVM$ SHADOW " + name + "(";
for (int k = 0; k < currSpec.size(); ++k) for (int k = 0; k < currSpec.size(); ++k)
{ {
char buf[256]; char buf[256];
@@ -2181,7 +2157,7 @@ void insertShadowSpecToFile(SgFile *file, const char *fin_name, const set<string
shadowSpecInsert += ")\n"; shadowSpecInsert += ")\n";
shadowsSpecsString.push_back(shadowSpecInsert); shadowsSpecsString.push_back(shadowSpecInsert);
pair<SgExpression*, SgExpression*> newSpec = genShadowSpec(file, make_pair(name, currSpec)); pair<SgExpression*, SgExpression*> newSpec = genShadowSpec(file, make_pair(array->GetShortName(), currSpec));
if (newSpec.first == NULL || newSpec.second == NULL) if (newSpec.first == NULL || newSpec.second == NULL)
printInternalError(convertFileName(__FILE__).c_str(), __LINE__); printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
shadowsSpecs.push_back(newSpec); shadowsSpecs.push_back(newSpec);

View File

@@ -26,7 +26,6 @@ using std::string;
using std::vector; using std::vector;
using std::pair; using std::pair;
using std::make_pair; using std::make_pair;
using SAPFOR::CFG_Settings;
extern int debSh; extern int debSh;
@@ -1673,12 +1672,9 @@ void GroupShadow(const map<string, vector<FuncInfo*>>& allFuncs,
SgStatement* func = currF->funcPointer->GetOriginal(); SgStatement* func = currF->funcPointer->GetOriginal();
const auto settings = CFG_Settings({ CFG_Settings::CFG_atLeastOneIterInLoop, CFG_Settings::CFG_withDVM, auto cfg = buildCFGforCurrentFunc(func, SAPFOR::CFG_Settings(true, false, false, true, false, true, false), commonBlocks, allFuncs);
CFG_Settings::CFG_withCallsInBlocks, CFG_Settings::CFG_withUnreachable });
auto cfg = buildCFGforCurrentFunc(func, settings, commonBlocks, allFuncs);
if (cfg.size() != 1) if (cfg.size() != 1)
printInternalError(convertFileName(__FILE__).c_str(), __LINE__); printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
auto& blocks = cfg.begin()->second; auto& blocks = cfg.begin()->second;
//create reaching blocks //create reaching blocks

View File

@@ -336,24 +336,9 @@ namespace Distribution
if (pos != STRING::npos) if (pos != STRING::npos)
{ {
name.erase(pos, shortName.size()); name.erase(pos, shortName.size());
shortName = newName;
name += newName; name += newName;
} }
else if (locationPos.first == l_COMMON) // name of array in common may be different
{
pos = name.rfind("_");
if (pos != STRING::npos)
{
name.erase(pos + 1, shortName.size());
name += newName;
}
else
{
#if __SPF
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
#endif
}
}
shortName = newName;
GenUniqKey(); GenUniqKey();
} }
@@ -557,44 +542,6 @@ namespace Distribution
return NULL; return NULL;
} }
Symbol* GetDeclSymbol(const PAIR<STRING, int>& position_decl) const
{
if (!IsArray() || locationPos.first != l_COMMON)
return declSymbol;
auto it = declPlacesSymbol.find(position_decl);
if (it != declPlacesSymbol.end())
return it->second;
else // find nearest
{
MAP<PAIR<STRING, int>, Symbol*> currFile;
for (auto& [position, symb] : declPlacesSymbol)
{
if (position.first == position_decl.first)
currFile[position] = symb;
}
PAIR<int, Symbol*> nearest = { (int)0, NULL };
const int needed_pos = position_decl.second;
for (auto& [position, symb] : currFile)
{
if (nearest.second == NULL)
nearest = { abs(position.second - needed_pos), symb };
if (abs(position.second - needed_pos) < nearest.first)
nearest = { abs(position.second - needed_pos), symb };
}
if (nearest.second)
return nearest.second;
#if __SPF
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
#endif
}
return NULL;
}
Symbol* GetDeclSymbol() const { return declSymbol; } Symbol* GetDeclSymbol() const { return declSymbol; }
void SetDeclSymbol(Symbol *s) { declSymbol = s; } void SetDeclSymbol(Symbol *s) { declSymbol = s; }

View File

@@ -857,11 +857,6 @@ ParallelDirective::genDirective(File* file, const vector<pair<DIST::Array*, cons
shadowRenewShifts[i].resize(shadowRenew[i].second.size()); shadowRenewShifts[i].resize(shadowRenew[i].second.size());
} }
if (shadowRenewCorner.size() == 0)
{
shadowRenewCorner.resize(shadowRenew.size(), false);
}
string shadowAdd = ", SHADOW_RENEW("; string shadowAdd = ", SHADOW_RENEW(";
int inserted = 0; int inserted = 0;
@@ -904,10 +899,7 @@ ParallelDirective::genDirective(File* file, const vector<pair<DIST::Array*, cons
for (auto& elem : genSubscripts(shadowRenew[i1].second, shadowRenewShifts[i1])) for (auto& elem : genSubscripts(shadowRenew[i1].second, shadowRenewShifts[i1]))
newArrayRef->addSubscript(*elem); newArrayRef->addSubscript(*elem);
bool needCornerFlag = shadowRenew[i1].second.size() > 1 && needCorner(shadowArray, shiftsByAccess, loop); if (shadowRenew[i1].second.size() > 1 && needCorner(shadowArray, shiftsByAccess, loop))
shadowRenewCorner[i1] = needCornerFlag;
if (needCornerFlag)
{ {
SgExpression* tmp = new SgExpression(ARRAY_OP, newArrayRef, NULL, NULL); SgExpression* tmp = new SgExpression(ARRAY_OP, newArrayRef, NULL, NULL);
p->setLhs(*tmp); p->setLhs(*tmp);

View File

@@ -102,7 +102,6 @@ public:
// origin_Name uniqName bounds // origin_Name uniqName bounds
std::vector<std::pair<std::pair<std::string, std::string>, std::vector<std::pair<int, int>>>> shadowRenew; std::vector<std::pair<std::pair<std::string, std::string>, std::vector<std::pair<int, int>>>> shadowRenew;
std::vector<std::vector<std::pair<int, int>>> shadowRenewShifts; std::vector<std::vector<std::pair<int, int>>> shadowRenewShifts;
std::vector<bool> shadowRenewCorner;
// origin_Name uniqName bounds // origin_Name uniqName bounds
std::vector<std::pair<std::pair<std::string, std::string>, std::vector<std::pair<int, int>>>> across; std::vector<std::pair<std::pair<std::string, std::string>, std::vector<std::pair<int, int>>>> across;
@@ -126,7 +125,6 @@ public:
privates = copyFrom.privates; privates = copyFrom.privates;
shadowRenew = copyFrom.shadowRenew; shadowRenew = copyFrom.shadowRenew;
shadowRenewShifts = copyFrom.shadowRenewShifts; shadowRenewShifts = copyFrom.shadowRenewShifts;
shadowRenewCorner = copyFrom.shadowRenewCorner;
across = copyFrom.across; across = copyFrom.across;
acrossShifts = copyFrom.acrossShifts; acrossShifts = copyFrom.acrossShifts;
remoteAccess = copyFrom.remoteAccess; remoteAccess = copyFrom.remoteAccess;
@@ -153,7 +151,6 @@ public:
on.clear(); on.clear();
privates.clear(); privates.clear();
shadowRenew.clear(); shadowRenew.clear();
shadowRenewCorner.clear();
across.clear(); across.clear();
acrossShifts.clear(); acrossShifts.clear();
reduction.clear(); reduction.clear();

View File

@@ -0,0 +1,616 @@
#include "parse_merge_dirs.h"
#include <unordered_set>
using std::map;
using std::pair;
using std::string;
using std::unordered_map;
using std::unordered_set;
using std::vector;
static void parseMergeDirective(const char *comment,
vector<pair<string, string>> &parsed_mapping)
{
while (comment)
{
auto *line_end = strchr(comment, '\n');
static const char prefix[] = "!!SPF TRANSFORM(MERGE_ARRAYS(";
static const auto compare_chars = sizeof(prefix) - 1;
if (strncasecmp(comment, prefix, compare_chars) == 0)
{
auto *pair_start = comment + compare_chars;
auto *comma = strchr(pair_start, ',');
if (comma)
{
auto *close_br = strchr(comma + 1, ')');
if (close_br)
{
parsed_mapping.emplace_back(
string(pair_start, comma - pair_start),
string(comma + 1, close_br - comma - 1));
}
}
}
comment = line_end;
if (comment)
comment++;
}
}
static string getNonDefaultRegion(DIST::Array *a)
{
string result;
if (!a)
return result;
for (const auto &reg_name : a->GetRegionsName())
{
if (reg_name != "default")
{
if (!result.empty())
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
result = reg_name;
}
}
return result;
}
static bool hasSameSizes(DIST::Array *a, DIST::Array *b)
{
for (auto *array : {a, b})
{
for (const auto &p : array->GetSizes())
{
if (p.first < 0 || p.second < 0)
return false;
}
}
return a->GetSizes() == b->GetSizes() && a->GetTypeSize() == b->GetTypeSize();
}
static bool checkSimilarTemplates(vector<ParallelRegion *> &regions,
const unordered_map<string, string> &new_region_mapping)
{
// new region -> old regions
unordered_map<string, unordered_set<string>> new_region_inverse_mapping;
for (const auto &p : new_region_mapping)
new_region_inverse_mapping[p.second].insert(p.first);
for (const auto &new_reg : new_region_inverse_mapping)
{
DIST::Array *template_array = nullptr;
string first_reg_name;
for (const auto &old_region_name : new_reg.second)
{
auto *old_reg = getRegionByName(regions, old_region_name);
if (!old_reg)
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
const auto &distr_rules = old_reg->GetDataDir().GetDistrRules();
if (distr_rules.size() != 1)
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
auto *current_template = distr_rules.front().first;
if (template_array)
{
if (!hasSameSizes(template_array, current_template))
{
__spf_print(1, "Templates of %s and %s has different sizes\n",
first_reg_name.c_str(),
old_region_name.c_str());
return false;
}
// else everything OK
}
else
{
template_array = current_template;
first_reg_name = old_region_name;
}
}
}
return true;
}
static bool hasSameAlignment(const std::unordered_set<const AlignRule *> &align_a,
const std::unordered_set<const AlignRule *> &align_b)
{
if (align_a.size() != 1 || align_b.size() != 1)
return false;
const auto *rule_a = *align_a.begin();
const auto *rule_b = *align_b.begin();
if (rule_a->alignRule != rule_b->alignRule)
return false;
return true;
}
static void printExpr(SgExpression *e, string pad)
{
if (!e)
return;
__spf_print(1, "%s%d: %s\n", pad.c_str(), e->variant(), e->unparse());
printExpr(e->lhs(), pad + " ");
printExpr(e->rhs(), pad + " ");
}
static pair<vector<SgStatement *>, SgSymbol *> generateDeclaration(const string &array_name, const string &common_block_name,
const vector<pair<int, int>> &sizes, SgType *type, SgStatement *scope)
{
auto *array_symbol = new SgSymbol(VARIABLE_NAME, array_name.c_str(), new SgType(T_ARRAY), scope);
auto *decl = new SgDeclarationStatement(VAR_DECL);
decl->setExpression(1, new SgTypeExp(*type));
SgExpression *subs = new SgExprListExp();
auto *array_ref = new SgArrayRefExp(*array_symbol, *subs);
for (int i = 0; i < sizes.size(); i++)
{
const auto &p = sizes[i];
auto *d = new SgExpression(DDOT, new SgValueExp(p.first), new SgValueExp(p.second));
subs->setLhs(d);
if (i + 1 < sizes.size())
{
subs->setRhs(new SgExprListExp());
subs = subs->rhs();
}
}
decl->setExpression(0, array_ref);
auto comm = new SgStatement(COMM_STAT);
comm->setExpression(0, new SgExpression(COMM_LIST,
new SgVarRefExp(array_symbol),
NULL,
new SgSymbol(COMMON_NAME, common_block_name.c_str())));
return {{decl, comm}, array_symbol};
}
static SgExpression* findExprWithVariant(SgExpression* exp, int variant)
{
if (exp)
{
if (exp->variant() == variant)
return exp;
auto *l = findExprWithVariant(exp->lhs(), variant);
if (l)
return l;
auto *r = findExprWithVariant(exp->rhs(), variant);
if (r)
return r;
}
return NULL;
}
SgType* GetArrayType(DIST::Array *array)
{
if (!array)
return NULL;
for (const auto& decl_place : array->GetDeclInfo())
{
if (SgFile::switchToFile(decl_place.first) != -1)
{
auto* decl = SgStatement::getStatementByFileAndLine(decl_place.first, decl_place.second);
if (decl)
{
for (int i = 0; i < 3; i++)
{
auto* found_type = isSgTypeExp(findExprWithVariant(decl->expr(i), TYPE_OP));
if (found_type)
return found_type->type();
}
}
}
}
return NULL;
}
SgSymbol *insertDeclIfNeeded(const string &array_name,
const string &common_block_name,
DIST::Array *example_array,
FuncInfo *dest,
unordered_map<FuncInfo *, unordered_map<string, SgSymbol *>> &inserted_arrays)
{
auto *type = GetArrayType(example_array);
if (!type)
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
if (SgFile::switchToFile(dest->fileName) == -1)
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
auto &by_func = inserted_arrays[dest];
auto it = by_func.find(array_name);
if (it != by_func.end())
return it->second;
SgStatement *st = dest->funcPointer;
auto *end = st->lastNodeOfStmt();
st = st->lexNext();
while (st != end && !isSgExecutableStatement(st))
{
st = st->lexNext();
}
auto generated = generateDeclaration(array_name, common_block_name,
example_array->GetSizes(),
type, dest->funcPointer);
for (auto *new_stmt : generated.first)
st->insertStmtBefore(*new_stmt, *dest->funcPointer);
by_func[array_name] = generated.second;
return generated.second;
}
static pair<string, string> createNewArray(DIST::Array *example_array, const string &base_name,
const map<string, vector<FuncInfo *>> &allFuncInfo,
unordered_map<FuncInfo *, unordered_map<string, SgSymbol *>> &inserted_arrays)
{
auto common_block_name = base_name + "_merge_cb";
auto array_name = base_name;
for (const auto &by_file : allFuncInfo)
{
for (auto *func_info : by_file.second)
{
if (func_info->isMain)
{
insertDeclIfNeeded(
array_name,
common_block_name,
example_array,
func_info,
inserted_arrays);
}
}
}
return std::make_pair(array_name, common_block_name);
}
static void replaceArrayRec(SgExpression *e,
const unordered_set<string> &arrays_to_replace,
SgSymbol **func_symbol_hint,
const pair<string, string> &replace_by,
DIST::Array *example_array,
FuncInfo *func,
unordered_map<FuncInfo *, unordered_map<string, SgSymbol *>> &inserted_arrays)
{
if (!e)
return;
if (isArrayRef(e) && arrays_to_replace.find(e->symbol()->identifier()) != arrays_to_replace.end())
{
if (!(*func_symbol_hint))
{
*func_symbol_hint = insertDeclIfNeeded(
replace_by.first, replace_by.second,
example_array,
func,
inserted_arrays);
}
e->setSymbol(*func_symbol_hint);
}
replaceArrayRec(
e->lhs(),
arrays_to_replace,
func_symbol_hint,
replace_by,
example_array,
func,
inserted_arrays);
replaceArrayRec(
e->rhs(),
arrays_to_replace,
func_symbol_hint,
replace_by,
example_array,
func,
inserted_arrays);
}
static void replaceRegion(SgStatement* st, const unordered_map<string, string> &new_region_mapping)
{
if (!st)
return;
if(isSPF_stat(st) && st->variant() == SPF_PARALLEL_REG_DIR)
{
auto it = new_region_mapping.find(st->symbol()->identifier());
if (it != new_region_mapping.end())
st->setSymbol(*(new SgSymbol(CONST_NAME, it->second.c_str())));
}
}
void mergeCopyArrays(vector<ParallelRegion *> &regions, const map<string, vector<FuncInfo *>> &allFuncInfo)
{
for (const auto *region : regions)
{
__spf_print(1, "region %s\n", region->GetName().c_str());
const auto &dirs = region->GetDataDir();
__spf_print(1, " distr rules: %d\n", dirs.distrRules.size());
const auto &currentVariant = region->GetCurrentVariant();
int distr_idx = 0;
for (const auto &distr : dirs.distrRules)
{
const auto &dist_rule = distr.second.back().distRule;
string sizes;
for (const auto &p : distr.first->GetSizes())
{
if (!sizes.empty())
sizes.push_back(',');
sizes += std::to_string(p.first) + ":" + std::to_string(p.second);
}
__spf_print(1, " DIST %s(%s)", distr.first->GetName().c_str(), sizes.c_str());
for (const auto &dim : dist_rule)
__spf_print(1, " %c", dim == dist::BLOCK ? 'B' : '*');
__spf_print(1, "\n");
distr_idx++;
}
__spf_print(1, " align rules: %d\n", dirs.alignRules.size());
for (const auto &align : dirs.alignRules)
{
string sub_a, sub_b;
int i = 0;
for (const auto coefs : align.alignRule)
{
if (!sub_a.empty())
sub_a.push_back(',');
sub_a += std::to_string(coefs.first) + "*i" +
std::to_string(i) + "+" + std::to_string(coefs.second);
i++;
}
for (const auto coefs : align.alignRuleWith)
{
if (!sub_b.empty())
sub_b.push_back(',');
sub_b += std::to_string(coefs.second.first) + "*i" +
std::to_string(coefs.first) + "+" + std::to_string(coefs.second.second);
}
__spf_print(1, " ALIGN %s(%s) WITH %s(%s)\n",
align.alignArray->GetName().c_str(), sub_a.c_str(),
align.alignWith->GetName().c_str(), sub_b.c_str());
}
}
// parse directives
// new array name -> current arrays
unordered_map<string, unordered_set<DIST::Array *>> arrays_to_merge;
unordered_map<DIST::Array *, unordered_set<const AlignRule *>> array_alignment;
for (const auto &by_file : allFuncInfo)
{
const auto current_file_name = by_file.first;
if (SgFile::switchToFile(current_file_name) == -1)
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
for (auto *func_info : by_file.second)
{
SgStatement *curr_stmt = func_info->funcPointer;
if (!curr_stmt)
continue;
auto *stmt_end = curr_stmt->lastDeclaration();
if (!stmt_end)
continue;
stmt_end = stmt_end->lexNext();
for (; curr_stmt && curr_stmt != stmt_end; curr_stmt = curr_stmt->lexNext())
{
if (curr_stmt->comments())
{
vector<pair<string, string>> parsed_mapping;
parseMergeDirective(curr_stmt->comments(), parsed_mapping);
for (const auto &p : parsed_mapping)
{
auto *found_array = getArrayFromDeclarated(curr_stmt, p.first);
if (found_array)
{
arrays_to_merge[p.second].insert(found_array);
array_alignment[found_array] = {};
}
}
}
}
}
}
// find alignment rules for array
for (const auto *region : regions)
{
const auto &dirs = region->GetDataDir();
for (const auto &align : dirs.alignRules)
{
auto it = array_alignment.find(align.alignArray);
if (it != array_alignment.end())
it->second.insert(&align);
}
}
// old region -> new region
unordered_map<string, string> new_region_mapping;
// new array -> new region
unordered_map<string, string> arrays_new_region_mapping;
vector<string> created_region_names;
for (const auto &by_new_array : arrays_to_merge)
{
string new_region_name;
for (auto *current_array : by_new_array.second)
{
auto current_array_region = getNonDefaultRegion(current_array);
auto it = new_region_mapping.find(current_array_region);
if (it != new_region_mapping.end())
{
if (new_region_name.empty())
new_region_name = it->second;
else if (new_region_name != it->second)
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
}
}
if (new_region_name.empty())
{
new_region_name = "merged_reg_" + std::to_string(created_region_names.size());
created_region_names.push_back(new_region_name);
}
for (auto *current_array : by_new_array.second)
{
auto current_array_region = getNonDefaultRegion(current_array);
new_region_mapping[current_array_region] = new_region_name;
}
arrays_new_region_mapping[by_new_array.first] = new_region_name;
}
if (!checkSimilarTemplates(regions, new_region_mapping))
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
unordered_map<FuncInfo *, unordered_map<string, SgSymbol *>> inserted_arrays;
for (const auto &by_dest_array : arrays_to_merge)
{
const auto &copy_arrays = by_dest_array.second;
if (copy_arrays.empty())
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
auto *first_element = *copy_arrays.begin();
auto first_elem_rules_it = array_alignment.find(first_element);
if (first_elem_rules_it == array_alignment.end())
continue;
const auto &first_elem_rules = first_elem_rules_it->second;
for (auto *array_to_merge : copy_arrays)
{
auto array_rules_it = array_alignment.find(array_to_merge);
if (array_rules_it == array_alignment.end())
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
const auto &array_rules = array_rules_it->second;
if (!hasSameSizes(array_to_merge, first_element) || !hasSameAlignment(first_elem_rules, array_rules))
{
__spf_print(1, "Arrays %s and %s has different sizes or align rules\n",
array_to_merge->GetName().c_str(),
first_element->GetName().c_str());
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
}
}
__spf_print(1, "merge into %s (%s):\n", by_dest_array.first.c_str(), arrays_new_region_mapping[by_dest_array.first].c_str());
for (auto *array_to_merge : copy_arrays)
__spf_print(1, "%s\n", array_to_merge->GetName().c_str());
auto created_array_info = createNewArray(first_element, by_dest_array.first, allFuncInfo, inserted_arrays);
unordered_set<string> arrays_to_replace;
for (auto *array_to_merge : copy_arrays)
arrays_to_replace.insert(array_to_merge->GetShortName());
for (const auto &by_file : allFuncInfo)
{
if (SgFile::switchToFile(by_file.first) == -1)
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
for (auto *func_info : by_file.second)
{
SgSymbol *func_symbol_hint = nullptr;
SgStatement *st = func_info->funcPointer;
auto *func_end = st->lastNodeOfStmt();
st = st->lexNext();
while (st && !isSgExecutableStatement(st) && st != func_end)
st = st->lexNext();
while (st && st != func_end)
{
for (int i = 0; i < 3; i++)
{
replaceArrayRec(
st->expr(i),
arrays_to_replace,
&func_symbol_hint,
created_array_info,
first_element,
func_info,
inserted_arrays);
}
replaceRegion(st, new_region_mapping);
st = st->lexNext();
}
}
}
}
}

View File

@@ -0,0 +1,8 @@
#include "../GraphCall/graph_calls.h"
#include "ParRegions.h"
#include <string>
#include <vector>
#include <map>
void mergeCopyArrays(std::vector<ParallelRegion*> &regions, const std::map<std::string, std::vector<FuncInfo*>> &allFuncInfo);

View File

@@ -23,7 +23,6 @@
#include "expr_transform.h" #include "expr_transform.h"
#include "../LoopAnalyzer/loop_analyzer.h" #include "../LoopAnalyzer/loop_analyzer.h"
#include "CFGraph/CFGraph.h" #include "CFGraph/CFGraph.h"
#include "../Utils/utils.h"
#include "json.hpp" #include "json.hpp"
@@ -34,113 +33,9 @@ using std::set;
using std::ofstream; using std::ofstream;
using std::pair; using std::pair;
using std::tuple; using std::tuple;
using SAPFOR::CFG_Settings;
using json = nlohmann::json; using json = nlohmann::json;
void runPredictSchemeOld(SgProject &project,
vector<vector<size_t>> &topologies,
vector<ParallelRegion*> &parallelRegions,
map<string, vector<LoopGraph*>> &loopGraph,
map<string, vector<SpfInterval*>> &intervals,
map<string, vector<Messages>> &SPF_messages)
{
int maxSizeDist = 0;
for (int z = 0; z < parallelRegions.size(); ++z)
{
const DataDirective &dataDirectives = parallelRegions[z]->GetDataDir();
const vector<int> &currentVariant = parallelRegions[z]->GetCurrentVariant();
auto &tmp = dataDirectives.distrRules;
vector<pair<DIST::Array*, const DistrVariant*>> currentVar;
for (int z1 = 0; z1 < currentVariant.size(); ++z1)
currentVar.push_back(std::make_pair(tmp[z1].first, &tmp[z1].second[currentVariant[z1]]));
for (auto &elem : currentVar)
{
DIST::Array *array = elem.first;
const DistrVariant *var = elem.second;
int countBlock = 0;
for (int z = 0; z < var->distRule.size(); ++z)
if (var->distRule[z] == dist::BLOCK)
++countBlock;
maxSizeDist = std::max(maxSizeDist, countBlock);
}
}
SpfInterval *mainIterval = getMainInterval(&project, intervals, SPF_messages);
topologies.clear();
if (maxSizeDist)
{
const int procNum = 8;
//TODO:
//topologies = getTopologies(procNum, maxSizeDist);
throw -10;
const int countOfTop = topologies.size();
if (countOfTop < 0)
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
for (auto &inter : intervals)
initTimeForIntervalTree(countOfTop, inter.second);
for (int z = 0; z < parallelRegions.size(); ++z)
{
const DataDirective &dataDirectives = parallelRegions[z]->GetDataDir();
const vector<int> &currentVariant = parallelRegions[z]->GetCurrentVariant();
DIST::Arrays<int> &allArrays = parallelRegions[z]->GetAllArraysToModify();
auto &tmp = dataDirectives.distrRules;
vector<pair<DIST::Array*, const DistrVariant*>> currentVar;
for (int z1 = 0; z1 < currentVariant.size(); ++z1)
currentVar.push_back(std::make_pair(tmp[z1].first, &tmp[z1].second[currentVariant[z1]]));
map<LoopGraph*, ParallelDirective*> parallelDirs;
vector<std::tuple<DIST::Array*, vector<long>, pair<string, int>>> allSingleRemotes;
for (int i = project.numberOfFiles() - 1; i >= 0; --i)
{
SgFile *file = &(project.file(i));
auto fountInfo = findAllDirectives(file, getObjectForFileFromMap(file->filename(), loopGraph), parallelRegions[z]->GetId());
parallelDirs.insert(fountInfo.begin(), fountInfo.end());
auto fountRem = findAllSingleRemotes(file, parallelRegions[z]->GetId(), parallelRegions);
allSingleRemotes.insert(allSingleRemotes.end(), fountRem.begin(), fountRem.end());
}
//TODO!
//int err = predictScheme(parallelRegions[z], currentVar, allArrays.GetArrays(), parallelDirs, intervals, SPF_messages, allSingleRemotes, maxSizeDist, procNum);
/*if (err != 0)
internalExit = err;*/
}
vector<SpfInterval*> tmp = { mainIterval };
aggregatePredictedTimes(tmp);
int idx = 0;
int best = -1;
double bestSpeedUp = 0;
for (auto &top : topologies)
{
string outStr = "";
for (auto &elem : top)
outStr += std::to_string(elem) + " ";
double currS = mainIterval->exec_time / mainIterval->predictedTimes[idx];
__spf_print(1, "%d: speed up %f for top. %s\n", idx, currS, outStr.c_str());
if (best == -1 || bestSpeedUp < currS)
{
bestSpeedUp = currS;
best = idx;
}
++idx;
}
__spf_print(1, "best topology %d with speed up %f\n", best, bestSpeedUp);
}
else
for (auto &inter : intervals)
initTimeForIntervalTree(0, inter.second);
}
static void fillParallel(SgExpression *exp, ParallelStats &parStats, int &totalScoreComm) static void fillParallel(SgExpression *exp, ParallelStats &parStats, int &totalScoreComm)
{ {
if (exp) if (exp)
@@ -612,8 +507,7 @@ static void parallelDir(const map<DIST::Array*, int>& byPos, SgExpression* spec,
if (currF == NULL) if (currF == NULL)
printInternalError(convertFileName(__FILE__).c_str(), __LINE__); printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
const auto settings = CFG_Settings({ CFG_Settings::CFG_atLeastOneIterInLoop, CFG_Settings::CFG_withSPF, CFG_Settings::CFG_withDominators }); auto cfg = buildCFGforCurrentFunc(func, SAPFOR::CFG_Settings(true, false, false, true, false, false, true), commonBlocks, allFuncInfo);
auto cfg = buildCFGforCurrentFunc(func, settings, commonBlocks, allFuncInfo);
//TODO IP analysis //TODO IP analysis
unsigned countOfAccess = 0; unsigned countOfAccess = 0;

View File

@@ -61,5 +61,3 @@ void processFileToPredict(SgFile *file, PredictorStats &predictorCounts);
void calculateStatsForPredictor(const std::map<std::string, std::vector<FuncInfo*>>& allFuncInfo, const std::map<std::string, std::map<int, Gcov_info>>& gCovInfo); void calculateStatsForPredictor(const std::map<std::string, std::vector<FuncInfo*>>& allFuncInfo, const std::map<std::string, std::map<int, Gcov_info>>& gCovInfo);
void parseDvmDirForPredictor(const std::map<std::tuple<int, std::string, std::string>, std::pair<DIST::Array*, DIST::ArrayAccessInfo*>>& declaredArrays, const std::map<std::string, CommonBlock*>& commonBlocks, const std::map<std::string, std::vector<FuncInfo*>>& allFuncInfo, const std::map<std::string, std::map<int, Gcov_info>>& gCovInfo); void parseDvmDirForPredictor(const std::map<std::tuple<int, std::string, std::string>, std::pair<DIST::Array*, DIST::ArrayAccessInfo*>>& declaredArrays, const std::map<std::string, CommonBlock*>& commonBlocks, const std::map<std::string, std::vector<FuncInfo*>>& allFuncInfo, const std::map<std::string, std::map<int, Gcov_info>>& gCovInfo);
void runPredictSchemeOld(SgProject &project, std::vector<std::vector<size_t>> &topologies, std::vector<ParallelRegion*> &parallelRegions, std::map<std::string, std::vector<LoopGraph*>> &loopGraph, std::map<std::string, std::vector<SpfInterval*>> &intervals, std::map<std::string, std::vector<Messages>> &SPF_messages);

View File

@@ -1,470 +0,0 @@
#include "leak_detector.h"
#include <limits>
#include <map>
#include <vector>
#include <string>
#include <tuple>
#include "dvm.h"
#include "PredictSchemeWithLibrary.h"
#include "../../projects/libpredictor/include/libpredict/predictor.h"
#include "../DirectiveProcessing/directive_parser.h"
#include "../Distribution/DvmhDirective.h"
#include "../ParallelizationRegions/ParRegions.h"
#include "../GraphLoop/graph_loops_func.h"
#include "../Utils/errors.h"
#include "../Utils/utils.h"
using std::map;
using std::pair;
using std::string;
using std::tuple;
using std::vector;
map<size_t, size_t> createTemplateIdMapping(const vector<ParallelRegion*>& parallelRegions)
{
size_t maxArrayId = 0;
for (int z = 0; z < parallelRegions.size(); ++z) {
const DataDirective& dataDirectives = parallelRegions[z]->GetDataDir();
for (const auto& distrRule : dataDirectives.distrRules) {
if (distrRule.first && !distrRule.first->IsTemplate()) {
maxArrayId = std::max(maxArrayId, (size_t)distrRule.first->GetId());
}
}
for (const auto& alignRule : dataDirectives.alignRules) {
if (alignRule.alignArray && !alignRule.alignArray->IsTemplate()) {
maxArrayId = std::max(maxArrayId, (size_t)alignRule.alignArray->GetId());
}
}
}
map<size_t, size_t> templateIdMapping;
size_t nextTemplateId = maxArrayId + 1;
for (int z = 0; z < parallelRegions.size(); ++z) {
const DataDirective& dataDirectives = parallelRegions[z]->GetDataDir();
for (const auto& distrRule : dataDirectives.distrRules) {
if (distrRule.first && distrRule.first->IsTemplate()) {
size_t originalId = distrRule.first->GetId();
if (templateIdMapping.find(originalId) == templateIdMapping.end()) {
templateIdMapping[originalId] = nextTemplateId++;
}
}
}
for (const auto& alignRule : dataDirectives.alignRules) {
if (alignRule.alignWith && alignRule.alignWith->IsTemplate()) {
size_t originalId = alignRule.alignWith->GetId();
if (templateIdMapping.find(originalId) == templateIdMapping.end()) {
templateIdMapping[originalId] = nextTemplateId++;
}
}
}
}
return templateIdMapping;
}
PrecomputedLibpredictParams precomputeLibpredictParams(
SgProject& project,
const vector<ParallelRegion*>& parallelRegions,
const map<string, vector<LoopGraph*>>& loopGraph,
const map<size_t, size_t>& templateIdMapping)
{
PrecomputedLibpredictParams result;
// distribute and align from parallelRegions
for (int z = 0; z < parallelRegions.size(); ++z) {
const DataDirective& dataDirectives = parallelRegions[z]->GetDataDir();
const vector<int>& currentVariant = parallelRegions[z]->GetCurrentVariant();
const DIST::Arrays<int>& allArrays = parallelRegions[z]->GetAllArrays();
auto& tmp = dataDirectives.distrRules;
vector<pair<DIST::Array*, const DistrVariant*>> currentVar;
for (int z1 = 0; z1 < currentVariant.size(); ++z1) {
currentVar.push_back(std::make_pair(tmp[z1].first, &tmp[z1].second[currentVariant[z1]]));
}
// distribute
for (const auto& distrRule : currentVar) {
DIST::Array* array = distrRule.first;
const DistrVariant* variant = distrRule.second;
if (array && variant && !array->IsNotDistribute()) {
PrecomputedDistributeParams params;
size_t originalId = array->GetId();
params.arrayId = originalId;
if (array->IsTemplate()) {
auto it = templateIdMapping.find(originalId);
if (it != templateIdMapping.end()) {
params.arrayId = it->second;
}
}
params.elemSize = array->GetTypeSize();
params.array = array;
const auto& arraySizes = array->GetSizes();
for (int dim = 0; dim < array->GetDimSize(); ++dim) {
size_t dimSize = arraySizes[dim].second - arraySizes[dim].first + 1;
if (dim < variant->distRule.size() && variant->distRule[dim] == dist::BLOCK) {
params.axisDistributions.emplace_back(dimSize, libpredict::TypeDistribute::BLOCK);
} else {
params.axisDistributions.emplace_back(dimSize, libpredict::TypeDistribute::NONE);
}
}
const auto& shadowSpec = array->GetShadowSpec();
for (int dim = 0; dim < shadowSpec.size() && dim < array->GetDimSize(); ++dim) {
if (dim < variant->distRule.size() && variant->distRule[dim] == dist::BLOCK) {
params.shadowEdges.emplace_back(shadowSpec[dim].first, shadowSpec[dim].second);
}
}
result.distributeParams.push_back(params);
}
}
// align
for (const auto& alignRule : dataDirectives.alignRules) {
DIST::Array* alignArray = alignRule.alignArray;
DIST::Array* alignWithArray = alignRule.alignWith;
if (alignArray && alignWithArray && !alignArray->IsNotDistribute()) {
PrecomputedAlignParams params;
params.arrayId = alignArray->GetId();
size_t originalDistributedArrayId = alignWithArray->GetId();
params.distributedArrayId = originalDistributedArrayId;
if (alignWithArray->IsTemplate()) {
auto it = templateIdMapping.find(originalDistributedArrayId);
if (it != templateIdMapping.end()) {
params.distributedArrayId = it->second;
}
}
params.elemSize = alignArray->GetTypeSize();
params.alignArray = alignArray;
params.alignWithArray = alignWithArray;
const auto& arraySizes = alignArray->GetSizes();
for (int dim = 0; dim < alignArray->GetDimSize(); ++dim) {
size_t dimSize = arraySizes[dim].second - arraySizes[dim].first + 1;
params.dimensions.push_back(dimSize);
}
for (int dim = 0; dim < alignWithArray->GetDimSize(); ++dim) {
bool found = false;
for (int i = 0; i < alignRule.alignRuleWith.size(); ++i) {
const auto& ruleWith = alignRule.alignRuleWith[i];
if (ruleWith.first == dim) {
const auto& rule = ruleWith.second;
if (rule.first == 0) {
// constant
params.distributionExpressions.emplace_back(rule.second);
} else {
// linear expression a * I + b
params.distributionExpressions.emplace_back(i, rule.first, rule.second);
}
found = true;
break;
}
}
if (!found) {
// There is no rule for this measurement
params.distributionExpressions.emplace_back();
}
}
const auto& shadowSpec = alignArray->GetShadowSpec();
for (int dim = 0; dim < shadowSpec.size() && dim < alignArray->GetDimSize(); ++dim) {
params.shadowEdges.emplace_back(shadowSpec[dim].first, shadowSpec[dim].second);
}
result.alignParams.push_back(params);
}
}
// shadow_renew
map<LoopGraph*, ParallelDirective*> parallelDirs;
for (int i = project.numberOfFiles() - 1; i >= 0; --i) {
SgFile* file = &(project.file(i));
auto fountInfo = findAllDirectives(
file,
getObjectForFileFromMap(file->filename(), const_cast<map<string, vector<LoopGraph*>>&>(loopGraph)),
parallelRegions[z]->GetId());
parallelDirs.insert(fountInfo.begin(), fountInfo.end());
}
for (auto& dirPair : parallelDirs) {
LoopGraph* loopPtr = dirPair.first;
ParallelDirective* directive = dirPair.second;
if (directive && !directive->shadowRenew.empty()) {
for (size_t shadowIdx = 0; shadowIdx < directive->shadowRenew.size(); ++shadowIdx) {
const auto& shadowRenewItem = directive->shadowRenew[shadowIdx];
const string& arrayName = shadowRenewItem.first.second; // uniqName
const vector<pair<int, int>>& bounds = shadowRenewItem.second;
DIST::Array* shadowArray = allArrays.GetArrayByName(arrayName);
if (shadowArray == NULL) {
continue;
}
if (shadowArray && !shadowArray->IsNotDistribute()) {
PrecomputedShadowRenewParams params;
params.arrayId = shadowArray->GetId();
params.shadowArray = shadowArray;
for (const auto& bound : bounds) {
params.shadow_renew.emplace_back(static_cast<size_t>(bound.first),
static_cast<size_t>(bound.second));
}
params.corner = directive->shadowRenewCorner[shadowIdx];
params.number_loop_iterations = loopPtr ? static_cast<size_t>(loopPtr->countOfIters) : 1;
result.shadowRenewParams.push_back(params);
}
}
}
}
}
return result;
}
double runLibpredictCalc(const vector<size_t>& topology,
const string& clusterConfStr,
const PrecomputedLibpredictParams& precomputedParams,
map<string, vector<Messages>>& SPF_messages)
{
libpredict::RetInitGrid retInitGrid = libpredict::InitGrid(topology[0], topology[1], topology[2], topology[3]);
if (retInitGrid != libpredict::INIT_GRID_SUCCESS) {
__spf_print(1, "ERROR: Failed to initialize libpredict grid with topology: %zu %zu %zu %zu, return code: %d\n",
topology[0], topology[1], topology[2], topology[3], (int)retInitGrid);
std::wstring messageR, messageE;
__spf_printToLongBuf(messageE, L"Failed to initialize libpredict grid with topology: %zu %zu %zu %zu, return code: %d",
topology[0], topology[1], topology[2], topology[3], (int)retInitGrid);
__spf_printToLongBuf(messageR, R207);
getObjectForFileFromMap(clusterConfStr.c_str(), SPF_messages).push_back(Messages(ERROR, 1, messageR, messageE, 1064));
return -1;
}
// distribute
for (const auto& params : precomputedParams.distributeParams) {
libpredict::RetDistribute retDistribute = libpredict::Distribute(
params.arrayId, params.elemSize, params.axisDistributions, params.shadowEdges);
if (retDistribute != libpredict::DISTRIBUTE_SUCCESS) {
__spf_print(1, "ERROR: Failed to distribute array '%s' (id=%zu) with libpredict, return code: %d\n",
params.array->GetShortName().c_str(), params.arrayId, (int)retDistribute);
std::wstring messageR, messageE;
__spf_printToLongBuf(messageE, L"Failed to distribute array '%s' with libpredict, return code: %d",
to_wstring(params.array->GetShortName()).c_str(), (int)retDistribute);
__spf_printToLongBuf(messageR, R208);
getObjectForFileFromMap(params.array->GetDeclInfo().begin()->first.c_str(), SPF_messages).push_back(Messages(ERROR, params.array->GetDeclInfo().begin()->second, messageR, messageE, 1065));
}
}
// align
for (const auto& params : precomputedParams.alignParams) {
libpredict::RetAlign retAlign = libpredict::Align(
params.arrayId, params.distributedArrayId, params.elemSize,
params.dimensions, params.distributionExpressions, params.shadowEdges);
if (retAlign != libpredict::ALIGN_SUCCESS) {
__spf_print(1, "ERROR: Failed to align array '%s' (id=%zu) with array '%s' (id=%zu), return code: %d\n",
params.alignArray->GetShortName().c_str(), params.arrayId,
params.alignWithArray->GetShortName().c_str(), params.distributedArrayId, (int)retAlign);
std::wstring messageR, messageE;
__spf_printToLongBuf(messageE, L"Failed to align array '%s' with array '%s' using libpredict, return code: %d",
to_wstring(params.alignArray->GetShortName()).c_str(),
to_wstring(params.alignWithArray->GetShortName()).c_str(), (int)retAlign);
__spf_printToLongBuf(messageR, R209);
getObjectForFileFromMap(params.alignArray->GetDeclInfo().begin()->first.c_str(), SPF_messages).push_back(Messages(ERROR, params.alignArray->GetDeclInfo().begin()->second, messageR, messageE, 1066));
}
}
// shadow_renew
for (const auto& params : precomputedParams.shadowRenewParams) {
libpredict::RetShadowRenew retShadowRenew = libpredict::ShadowRenew(
params.arrayId, params.shadow_renew, params.corner, params.number_loop_iterations);
if (retShadowRenew != libpredict::SHADOW_RENEW_SUCCESS) {
__spf_print(1, "ERROR: Failed to process shadow_renew for array '%s' (id=%zu), return code: %d\n",
params.shadowArray->GetShortName().c_str(), params.arrayId, (int)retShadowRenew);
std::wstring messageR, messageE;
__spf_printToLongBuf(messageE, L"Failed to process shadow_renew for array '%s' with libpredict, return code: %d",
to_wstring(params.shadowArray->GetShortName()).c_str(), (int)retShadowRenew);
__spf_printToLongBuf(messageR, R210);
getObjectForFileFromMap(params.shadowArray->GetDeclInfo().begin()->first.c_str(), SPF_messages).push_back(Messages(ERROR, params.shadowArray->GetDeclInfo().begin()->second, messageR, messageE, 1067));
}
}
return libpredict::GetTime();
}
void runPredictScheme(SgProject& project,
const vector<ParallelRegion*>& parallelRegions,
map<string, vector<LoopGraph*>>& loopGraph,
map<string, vector<Messages>>& SPF_messages)
{
// calculating maximum dimension of distribution
int maxSizeDist = 0;
for (int z = 0; z < parallelRegions.size(); ++z) {
const DataDirective& dataDirectives = parallelRegions[z]->GetDataDir();
const vector<int>& currentVariant = parallelRegions[z]->GetCurrentVariant();
auto& tmp = dataDirectives.distrRules;
vector<const DistrVariant*> currentVar;
for (int z1 = 0; z1 < currentVariant.size(); ++z1) {
currentVar.push_back(&tmp[z1].second[currentVariant[z1]]);
}
for (auto var : currentVar) {
int countBlock = 0;
for (int z = 0; z < var->distRule.size(); ++z) {
if (var->distRule[z] == dist::BLOCK) {
++countBlock;
}
}
maxSizeDist = std::max(maxSizeDist, countBlock);
}
}
// calculating name of a cluster configuration file
string clusterConfStr;
if (project.numberOfFiles() > 0) {
string firstFilePath = project.fileName(0);
size_t lastSlash = firstFilePath.find_last_of("/\\");
clusterConfStr = firstFilePath.substr(0, lastSlash + 1) + "cluster.conf";
}
// creating template ID display to avoid conflicts
map<size_t, size_t> templateIdMapping = createTemplateIdMapping(parallelRegions);
// Precomputing parameters of directive functions from libpredict
PrecomputedLibpredictParams precomputedParams = precomputeLibpredictParams(
project, parallelRegions, loopGraph, templateIdMapping);
// iterating through topologies and processes_per_processor to find most optimal one
if (maxSizeDist) {
if (maxSizeDist > 4) {
maxSizeDist = 4;
}
// Initialize cluster
int maxCoresCount = 0;
libpredict::RetInitCluster retInitCluster = libpredict::InitCluster(clusterConfStr, maxCoresCount);
if (retInitCluster != libpredict::INIT_CLUSTER_SUCCESS) {
__spf_print(1, "ERROR: Failed to initialize libpredict cluster with config: %s, return code: %d\n", clusterConfStr.c_str(), (int)retInitCluster);
std::wstring messageR, messageE;
__spf_printToLongBuf(messageE, L"Failed to initialize libpredict cluster with config: %s, return code: %d",
to_wstring(clusterConfStr).c_str(), (int)retInitCluster);
__spf_printToLongBuf(messageR, R206);
getObjectForFileFromMap(clusterConfStr.c_str(), SPF_messages).push_back(Messages(ERROR, 1, messageR, messageE, 1063));
return;
}
vector<size_t> bestTopology;
double bestTime = std::numeric_limits<double>::max();
size_t bestProcessesPerProcessor = 0;
int prevProcCount = -1;
for (size_t processes_per_processor = 1; processes_per_processor <= maxCoresCount; ++processes_per_processor) {
int procCount = 0;
libpredict::RetInitMapping retInitMapping = libpredict::InitMapping(processes_per_processor, procCount);
if (retInitMapping != libpredict::INIT_MAPPING_SUCCESS) {
__spf_print(1, "ERROR: Failed to initialize libpredict mapping with processes_per_processor: %zu, return code: %d\n",
processes_per_processor, (int)retInitMapping);
std::wstring messageR, messageE;
__spf_printToLongBuf(messageE, L"Failed to initialize libpredict mapping with processes_per_processor: %zu, return code: %d",
processes_per_processor, (int)retInitMapping);
__spf_printToLongBuf(messageR, R211);
getObjectForFileFromMap(clusterConfStr.c_str(), SPF_messages).push_back(Messages(ERROR, 1, messageR, messageE, 1068));
continue;
}
if (procCount == 0) {
break; // No more processors available
}
if (procCount == prevProcCount) {
continue; // Skip with procCount value unchanged for different processes_per_processor
}
prevProcCount = procCount;
__spf_print(1, "Calculate with processes_per_processor=%zu, procCount=%d\n", processes_per_processor, procCount);
for (size_t n1 = 2; n1 <= procCount; ++n1) {
for (size_t n2 = 1; n2 <= n1 && n1 * n2 <= procCount; ++n2) {
if (n2 != 1 && maxSizeDist < 2 || n2 == 1 && maxSizeDist == 2) {
continue;
}
for (size_t n3 = 1; n3 <= n2 && n1 * n2 * n3 <= procCount; ++n3) {
if (n3 != 1 && maxSizeDist < 3 || n3 == 1 && maxSizeDist == 3) {
continue;
}
for (size_t n4 = 1; n4 <= n3 && n1 * n2 * n3 * n4 <= procCount; ++n4) {
if (n4 != 1 && maxSizeDist < 4 || n4 == 1 && maxSizeDist == 4) {
continue;
}
vector<size_t> topology = {n1, n2, n3, n4};
double currTime = runLibpredictCalc(topology, clusterConfStr, precomputedParams, SPF_messages);
string outStr = "";
for (const auto& elem : topology) {
outStr += std::to_string(elem) + " ";
}
__spf_print(1, "topology %s has time %f\n", outStr.c_str(), currTime);
if (currTime == -1) {
continue;
}
if (currTime < bestTime) {
bestTime = currTime;
bestTopology = topology;
bestProcessesPerProcessor = processes_per_processor;
}
}
}
}
}
}
if (!bestTopology.empty()) {
string outStr;
for (const auto& elem : bestTopology) {
outStr += std::to_string(elem) + " ";
}
__spf_print(1, "best topology %s with time %f (processes_per_processor=%zu)\n",
outStr.c_str(), bestTime, bestProcessesPerProcessor);
}
} else {
__spf_print(1, "impossible to calculate best topology: project does not contain distribution directives\n");
}
}

View File

@@ -1,56 +0,0 @@
#pragma once
#include <vector>
#include <map>
#include <string>
#include "dvm.h"
#include "graph_calls.h"
#include "../../projects/libpredictor/include/libpredict/predictor.h"
struct PrecomputedDistributeParams {
size_t arrayId;
size_t elemSize;
std::vector<libpredict::DistributeAxisRule> axisDistributions;
std::vector<std::pair<size_t, size_t>> shadowEdges;
DIST::Array* array;
};
struct PrecomputedAlignParams {
size_t arrayId;
size_t distributedArrayId;
size_t elemSize;
std::vector<size_t> dimensions;
std::vector<libpredict::AlignDisplay> distributionExpressions;
std::vector<std::pair<size_t, size_t>> shadowEdges;
DIST::Array* alignArray;
DIST::Array* alignWithArray;
};
struct PrecomputedShadowRenewParams {
size_t arrayId;
std::vector<std::pair<size_t, size_t>> shadow_renew;
bool corner;
size_t number_loop_iterations;
DIST::Array* shadowArray;
};
struct PrecomputedLibpredictParams {
std::vector<PrecomputedDistributeParams> distributeParams;
std::vector<PrecomputedAlignParams> alignParams;
std::vector<PrecomputedShadowRenewParams> shadowRenewParams;
};
PrecomputedLibpredictParams precomputeLibpredictParams(
SgProject& project,
const std::vector<ParallelRegion*>& parallelRegions,
const std::map<std::string, std::vector<LoopGraph*>>& loopGraph,
const std::map<size_t, size_t>& templateIdMapping);
void runPredictScheme(SgProject& project,
const std::vector<ParallelRegion*>& parallelRegions,
std::map<std::string, std::vector<LoopGraph*>>& loopGraph,
std::map<std::string, std::vector<Messages>>& SPF_messages);
double runLibpredictCalc(const std::vector<size_t>& topology,
const std::string& clusterConfStr,
const PrecomputedLibpredictParams& precomputedParams,
std::map<std::string, std::vector<Messages>>& SPF_messages);

View File

@@ -23,6 +23,7 @@
#include "ParallelizationRegions/ParRegions_func.h" #include "ParallelizationRegions/ParRegions_func.h"
#include "ParallelizationRegions/resolve_par_reg_conflicts.h" #include "ParallelizationRegions/resolve_par_reg_conflicts.h"
#include "ParallelizationRegions/expand_extract_reg.h" #include "ParallelizationRegions/expand_extract_reg.h"
#include "ParallelizationRegions/parse_merge_dirs.h"
#include "Distribution/Distribution.h" #include "Distribution/Distribution.h"
#include "Distribution/GraphCSR.h" #include "Distribution/GraphCSR.h"
@@ -58,7 +59,6 @@
#include "expr_transform.h" #include "expr_transform.h"
#include "Predictor/PredictScheme.h" #include "Predictor/PredictScheme.h"
#include "Predictor/PredictSchemeWithLibrary.h"
#include "Predictor/PredictorModel.h" #include "Predictor/PredictorModel.h"
#include "SageAnalysisTool/depInterfaceExt.h" #include "SageAnalysisTool/depInterfaceExt.h"
#include "DvmhRegions/DvmhRegionInserter.h" #include "DvmhRegions/DvmhRegionInserter.h"
@@ -1733,7 +1733,103 @@ static bool runAnalysis(SgProject &project, const int curr_regime, const bool ne
} }
} }
else if (curr_regime == PREDICT_SCHEME) else if (curr_regime == PREDICT_SCHEME)
runPredictScheme(project, parallelRegions, loopGraph, SPF_messages); {
int maxSizeDist = 0;
for (int z = 0; z < parallelRegions.size(); ++z)
{
const DataDirective &dataDirectives = parallelRegions[z]->GetDataDir();
const vector<int> &currentVariant = parallelRegions[z]->GetCurrentVariant();
auto &tmp = dataDirectives.distrRules;
vector<pair<DIST::Array*, const DistrVariant*>> currentVar;
for (int z1 = 0; z1 < currentVariant.size(); ++z1)
currentVar.push_back(make_pair(tmp[z1].first, &tmp[z1].second[currentVariant[z1]]));
for (auto &elem : currentVar)
{
DIST::Array *array = elem.first;
const DistrVariant *var = elem.second;
int countBlock = 0;
for (int z = 0; z < var->distRule.size(); ++z)
if (var->distRule[z] == dist::BLOCK)
++countBlock;
maxSizeDist = std::max(maxSizeDist, countBlock);
}
}
SpfInterval *mainIterval = getMainInterval(&project, intervals, SPF_messages);
topologies.clear();
if (maxSizeDist)
{
const int procNum = 8;
//TODO:
//topologies = getTopologies(procNum, maxSizeDist);
throw -10;
const int countOfTop = topologies.size();
if (countOfTop < 0)
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
for (auto &inter : intervals)
initTimeForIntervalTree(countOfTop, inter.second);
for (int z = 0; z < parallelRegions.size(); ++z)
{
const DataDirective &dataDirectives = parallelRegions[z]->GetDataDir();
const vector<int> &currentVariant = parallelRegions[z]->GetCurrentVariant();
DIST::Arrays<int> &allArrays = parallelRegions[z]->GetAllArraysToModify();
auto &tmp = dataDirectives.distrRules;
vector<pair<DIST::Array*, const DistrVariant*>> currentVar;
for (int z1 = 0; z1 < currentVariant.size(); ++z1)
currentVar.push_back(make_pair(tmp[z1].first, &tmp[z1].second[currentVariant[z1]]));
map<LoopGraph*, ParallelDirective*> parallelDirs;
vector<std::tuple<DIST::Array*, vector<long>, pair<string, int>>> allSingleRemotes;
for (int i = n - 1; i >= 0; --i)
{
SgFile *file = &(project.file(i));
auto fountInfo = findAllDirectives(file, getObjectForFileFromMap(file->filename(), loopGraph), parallelRegions[z]->GetId());
parallelDirs.insert(fountInfo.begin(), fountInfo.end());
auto fountRem = findAllSingleRemotes(file, parallelRegions[z]->GetId(), parallelRegions);
allSingleRemotes.insert(allSingleRemotes.end(), fountRem.begin(), fountRem.end());
}
//TODO!
//int err = predictScheme(parallelRegions[z], currentVar, allArrays.GetArrays(), parallelDirs, intervals, SPF_messages, allSingleRemotes, maxSizeDist, procNum);
/*if (err != 0)
internalExit = err;*/
}
vector<SpfInterval*> tmp = { mainIterval };
aggregatePredictedTimes(tmp);
int idx = 0;
int best = -1;
double bestSpeedUp = 0;
for (auto &top : topologies)
{
string outStr = "";
for (auto &elem : top)
outStr += std::to_string(elem) + " ";
double currS = mainIterval->exec_time / mainIterval->predictedTimes[idx];
__spf_print(1, "%d: speed up %f for top. %s\n", idx, currS, outStr.c_str());
if (best == -1 || bestSpeedUp < currS)
{
bestSpeedUp = currS;
best = idx;
}
++idx;
}
__spf_print(1, "best topology %d with speed up %f\n", best, bestSpeedUp);
}
else
for (auto &inter : intervals)
initTimeForIntervalTree(0, inter.second);
}
else if (curr_regime == CREATE_INTER_TREE) else if (curr_regime == CREATE_INTER_TREE)
{ {
if (keepFiles) if (keepFiles)
@@ -1798,7 +1894,7 @@ static bool runAnalysis(SgProject &project, const int curr_regime, const bool ne
findParameters(parametersOfProject, fullIR, declaredArrays); findParameters(parametersOfProject, fullIR, declaredArrays);
else if (curr_regime == BUILD_IR) else if (curr_regime == BUILD_IR)
{ {
auto CFG_forFile = buildCFG(commonBlocks, allFuncInfo_IR, SAPFOR::CFG_Settings()); auto CFG_forFile = buildCFG(commonBlocks, allFuncInfo_IR, SAPFOR::CFG_Settings(0));
for (auto& byFunc : CFG_forFile) for (auto& byFunc : CFG_forFile)
fullIR[byFunc.first].insert(fullIR[byFunc.first].end(), byFunc.second.begin(), byFunc.second.end()); fullIR[byFunc.first].insert(fullIR[byFunc.first].end(), byFunc.second.begin(), byFunc.second.end());
@@ -1827,6 +1923,10 @@ static bool runAnalysis(SgProject &project, const int curr_regime, const bool ne
transformAssumedSizeParameters(allFuncInfo); transformAssumedSizeParameters(allFuncInfo);
else if (curr_regime == FIND_PRIVATE_ARRAYS_ANALYSIS) else if (curr_regime == FIND_PRIVATE_ARRAYS_ANALYSIS)
FindPrivateArrays(loopGraph, fullIR, insertedPrivates); FindPrivateArrays(loopGraph, fullIR, insertedPrivates);
else if (curr_regime == MERGE_COPY_ARRAYS)
{
mergeCopyArrays(parallelRegions, allFuncInfo);
}
else if (curr_regime == ARRAY_PROPAGATION) else if (curr_regime == ARRAY_PROPAGATION)
ArrayConstantPropagation(project); ArrayConstantPropagation(project);
@@ -2134,8 +2234,9 @@ void runPass(const int curr_regime, const char *proj_name, const char *folderNam
runAnalysis(*project, CALCULATE_STATS_SCHEME, false); runAnalysis(*project, CALCULATE_STATS_SCHEME, false);
if (!folderName && !consoleMode || predictOn) //TODO: need to rewrite this to new algo
runAnalysis(*project, PREDICT_SCHEME, false); /*if (!folderName && !consoleMode || predictOn)
runAnalysis(*project, PREDICT_SCHEME, false); */
runAnalysis(*project, REMOVE_COPIES, false); runAnalysis(*project, REMOVE_COPIES, false);
runAnalysis(*project, SWAP_LOOPS, false); runAnalysis(*project, SWAP_LOOPS, false);
@@ -2283,6 +2384,7 @@ void runPass(const int curr_regime, const char *proj_name, const char *folderNam
case FIX_COMMON_BLOCKS: case FIX_COMMON_BLOCKS:
case TEST_PASS: case TEST_PASS:
case SET_IMPLICIT_NONE: case SET_IMPLICIT_NONE:
case MERGE_COPY_ARRAYS:
runAnalysis(*project, curr_regime, false); runAnalysis(*project, curr_regime, false);
case SUBST_EXPR_RD_AND_UNPARSE: case SUBST_EXPR_RD_AND_UNPARSE:
case SUBST_EXPR_AND_UNPARSE: case SUBST_EXPR_AND_UNPARSE:
@@ -2428,8 +2530,8 @@ int main(int argc, char **argv)
out_free_form = 1; out_free_form = 1;
out_line_unlimit = 1; out_line_unlimit = 1;
} }
/*else if (string(curr_arg) == "-sh") else if (string(curr_arg) == "-sh")
staticShadowAnalysis = 1;*/ staticShadowAnalysis = 1;
else if (string(curr_arg) == "-shWidth") else if (string(curr_arg) == "-shWidth")
{ {
i++; i++;

View File

@@ -88,6 +88,8 @@ enum passes {
REMOVE_DVM_INTERVALS, REMOVE_DVM_INTERVALS,
VERIFY_DVM_DIRS, VERIFY_DVM_DIRS,
MERGE_COPY_ARRAYS,
REMOVE_DIST_ARRAYS_FROM_IO, REMOVE_DIST_ARRAYS_FROM_IO,
SUBST_EXPR, SUBST_EXPR,
@@ -273,6 +275,7 @@ static void setPassValues()
passNames[VERIFY_DVM_DIRS] = "VERIFY_DVM_DIRS"; passNames[VERIFY_DVM_DIRS] = "VERIFY_DVM_DIRS";
passNames[REMOVE_DVM_DIRS_TO_COMMENTS] = "REMOVE_DVM_DIRS_TO_COMMENTS"; passNames[REMOVE_DVM_DIRS_TO_COMMENTS] = "REMOVE_DVM_DIRS_TO_COMMENTS";
passNames[REMOVE_SPF_DIRS] = "REMOVE_SPF_DIRS"; passNames[REMOVE_SPF_DIRS] = "REMOVE_SPF_DIRS";
passNames[MERGE_COPY_ARRAYS] = "MERGE_COPY_ARRAYS";
passNames[REMOVE_DIST_ARRAYS_FROM_IO] = "REMOVE_DIST_ARRAYS_FROM_IO"; passNames[REMOVE_DIST_ARRAYS_FROM_IO] = "REMOVE_DIST_ARRAYS_FROM_IO";
passNames[SUBST_EXPR] = "SUBST_EXPR"; passNames[SUBST_EXPR] = "SUBST_EXPR";
passNames[SUBST_EXPR_RD] = "SUBST_EXPR_RD"; passNames[SUBST_EXPR_RD] = "SUBST_EXPR_RD";

View File

@@ -19,7 +19,7 @@
extern std::map<std::string, std::string> shortFileNames; extern std::map<std::string, std::string> shortFileNames;
static int activeState = 0; static int activeState = 0;
int staticShadowAnalysis = 1; int staticShadowAnalysis = 0;
int staticPrivateAnalysis = 0; int staticPrivateAnalysis = 0;
int keepDvmDirectives = 0; int keepDvmDirectives = 0;
int keepFiles = 0; int keepFiles = 0;
@@ -132,7 +132,7 @@ std::map<std::string, PredictorStats> allPredictorStats;
//for DVM INTERVALS //for DVM INTERVALS
std::map<std::string, std::vector<SpfInterval*>> intervals; // file -> intervals std::map<std::string, std::vector<SpfInterval*>> intervals; // file -> intervals
std::vector<std::vector<size_t>> topologies; // current topologies std::vector<std::vector<long>> topologies; // current topologies
// //
//for GCOV_PARSER //for GCOV_PARSER

View File

@@ -12,7 +12,6 @@ using std::map;
using std::string; using std::string;
using std::vector; using std::vector;
using std::set; using std::set;
using SAPFOR::CFG_Settings;
using std::remove_if; using std::remove_if;
@@ -425,8 +424,7 @@ int removeDeadCode(SgStatement* func,
if (intervalDelEnd->lineNumber() < prog->lineNumber() || intervalDelEnd->lineNumber() > prog->lastNodeOfStmt()->lineNumber()) if (intervalDelEnd->lineNumber() < prog->lineNumber() || intervalDelEnd->lineNumber() > prog->lastNodeOfStmt()->lineNumber())
printInternalError(convertFileName(__FILE__).c_str(), __LINE__); printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
const auto settings = CFG_Settings({ CFG_Settings::CFG_atLeastOneIterInLoop }); auto cfg = buildCFGforCurrentFunc(func, SAPFOR::CFG_Settings(true, false, false, false, false, false, false), commonBlocks, allFuncs);
auto cfg = buildCFGforCurrentFunc(func, settings, commonBlocks, allFuncs);
if(cfg.size() != 1) if(cfg.size() != 1)
printInternalError(convertFileName(__FILE__).c_str(), __LINE__); printInternalError(convertFileName(__FILE__).c_str(), __LINE__);

View File

@@ -18,66 +18,69 @@ using std::tuple;
/// main function: /// main function:
// renew unions for all common blocks in the file // renew unions for all common blocks in the file
//void BuildNewCommDecls static void BuildNewCommDecls(SgFile* file, const map<string, CommonBlock*> allCommonBlocks,
map<string, deque<CommConstraint>>& newCommonDecls, map<string, map<string, deque<CommConstraint>>>& commDecls,
set<string>& badCommon, map<string, set<string>>& notUsedVars, vector<SgStatement*>& programUnits);
// get names of variables and array elements, which were referenced in programm unit // get names of variables and array elements, which were referenced in programm unit
//set<string> getUses static set<string> getUses(SgStatement* firstSt, const set<string>& commonVarNames);
//void getUsesFromExpr static void getUsesFromExpr(SgExpression* expr, const set<string>& commonVarNames, set<string>& used);
// splits arrays into elements and replaces not used vars with empty constraints // splits arrays into elements and replaces not used vars with empty constraints
//bool splitType static bool splitType(deque<CommConstraint>& d, bool check_use, const set<string>& namesOfUsedVars);
// create constraits set // create constraits set
//deque<CommConstraint> makeConstraints static deque<CommConstraint> makeConstraints(deque<CommConstraint>& constraints, const set<string>& namesOfUsedVars, set<string>& notUsedVars);
// build union // build union
//bool buildConstraintsUnion static bool buildConstraintsUnion(deque<CommConstraint>& U, deque<CommConstraint> B, const set<string>& namesOfUsedVars, pair<CommConstraint, CommConstraint>& problemConstraints);
//bool docheckUnequalConstraints static bool docheckUnequalConstraints(deque<CommConstraint>& U, deque<CommConstraint>& B, deque<CommConstraint>& newU, pair<CommConstraint, CommConstraint>& problemConstraints);
//bool check static bool check(deque<CommConstraint>& A, deque<CommConstraint>& B, pair<CommConstraint, CommConstraint>& problemConstraints);
/// small help functions: /// small help functions:
//string getParentName static string getParentName(const string& name);
//bool equalDims static bool equalDims(const CommConstraint& a, const CommConstraint& b);
//bool equalConstraints static bool equalConstraints(const CommConstraint& a, const CommConstraint& b);
//void addElem static void addElem(deque<CommConstraint>& comm, const CommConstraint& elem);
//////
// change names of variables in 'constraints' // change names of variables in 'constraints'
//void fixNames static void fixNames(deque<CommConstraint>& constraints, const string& commName);
////// step2: transformation ////// step2: transformation
/// main function /// main function
// peform transformation on every program unit in the file // peform transformation on every program unit in the file
//void fixFunctions static void fixFunctions(SgFile* file, vector<SgStatement*> programUnits, map<string, deque<CommConstraint>>& newCommonDecls,
map<string, map<string, deque<CommConstraint>>>& commDecls, const set<string>& badCommon, map<string, set<string>>& notUsedVars);
// get pairs of names (namesOldToNew) for renaming // get pairs of names (namesOldToNew) for renaming
//bool getNamesOldToNew static bool getNamesOldToNew(deque<CommConstraint> newDecl, deque<CommConstraint> oldDecl, map<string, string>& namesOldToNew);
// create new symbols for new variables in new common declaration (constraints) // create new symbols for new variables in new common declaration (constraints)
//void makeCommVarSymbs static void makeCommVarSymbs(const deque<CommConstraint>& constraints, SgFile* file, SgStatement* func, string commName,
map<string, SgSymbol*>& symbs, vector<SgSymbol*>& needNewDecl);
// delete from program unit all references to names in commVarNames // delete from program unit all references to names in commVarNames
//void deleteOldVars static void deleteOldVars(SgStatement* firstSt, const set<string>& commVarNames);
// calls fixExpression for each statement, replaces names in data statement // calls fixExpression for each statement, replaces names in data statement
//void renameVariables static void renameVariables(SgStatement* firstSt, const map<string, SgSymbol*>& newVarSymbs, const map<string, string>& namesOldToNew);
// replacing variables or array elements in expression expr if their names are in namesOldToNew // replacing variables or array elements in expression expr if their names are in namesOldToNew
//SgExpression* fixExpression static SgExpression* fixExpression(SgExpression* expr, const map<string, SgSymbol*>& newSymbs, const map<string, string>& namesOldToNew);
// make new exprList exprssion for new declaration decl with symbols from newSymbs // make new exprList exprssion for new declaration decl with symbols from newSymbs
//SgExpression* makeExprListForCommon static SgExpression* makeExprListForCommon(const deque<CommConstraint>& decl, const map<string, SgSymbol*>& newSymbs,
SgFile* file, SgStatement* firstSt);
// replace old common declarations with new ones // replace old common declarations with new ones
//void rewriteCommon static void rewriteCommon(SgStatement* firstSt, map<string, SgExpression*>& commListExprs);
/// help functions: /// help functions:
//SgExpression* makeIdxFromStr(const string& str); static SgExpression* makeIdxFromStr(const string& str);
// make new expression of array element // make new expression of array element
//SgExpression* newArrElemExpr static SgExpression* newArrElemExpr(const string& newName, const map<string, SgSymbol*>& newSymbs);
//bool variablePositionComp static bool variablePositionComp(const Variable* lhs, const Variable* rhs);
////// //////
CommConstraint::CommConstraint(const Variable* var, bool u, const string& funcName, const string& fileName) CommConstraint::CommConstraint(const Variable* var, bool u, const string& funcName, const string& fileName)
{ {
used = u; used = u;
@@ -122,6 +125,7 @@ CommConstraint::CommConstraint(const Variable* var, bool u, const string& funcNa
} }
} }
CommConstraint::CommConstraint(const string& name, SgType* t, bool u) : used(u), type(t), identifier(name) CommConstraint::CommConstraint(const string& name, SgType* t, bool u) : used(u), type(t), identifier(name)
{ {
typeVariant = type->variant(); typeVariant = type->variant();
@@ -135,7 +139,8 @@ CommConstraint::CommConstraint(const string& name, SgType* t, bool u, vector<Dec
size = getSizeOfType(type); size = getSizeOfType(type);
} }
static string getParentName(const string& name)
string getParentName(const string& name)
{ {
size_t len = name.find("%"); size_t len = name.find("%");
size_t posB = name.find("("); size_t posB = name.find("(");
@@ -149,7 +154,8 @@ static string getParentName(const string& name)
return name.substr(0, len); return name.substr(0, len);
} }
static void getUsesFromExpr(SgExpression* expr, const set<string>& commonVarNames, set<string>& used)
void getUsesFromExpr(SgExpression* expr, const set<string>& commonVarNames, set<string>& used)
{ {
if (expr == NULL) if (expr == NULL)
return; return;
@@ -188,7 +194,8 @@ static void getUsesFromExpr(SgExpression* expr, const set<string>& commonVarName
getUsesFromExpr(expr->rhs(), commonVarNames, used); getUsesFromExpr(expr->rhs(), commonVarNames, used);
} }
static set<string> getUses(SgStatement* firstSt, const set<string>& commonVarNames)
set<string> getUses(SgStatement* firstSt, const set<string>& commonVarNames)
{ {
set<string> used; set<string> used;
SgStatement* lastSt = firstSt->lastNodeOfStmt(); SgStatement* lastSt = firstSt->lastNodeOfStmt();
@@ -205,7 +212,8 @@ static set<string> getUses(SgStatement* firstSt, const set<string>& commonVarNam
return used; return used;
} }
static bool equalDims(const CommConstraint& a, const CommConstraint& b)
bool equalDims(const CommConstraint& a, const CommConstraint& b)
{ {
const vector<pair<int, int>>& adim = a.arrayInfo->GetSizes(); const vector<pair<int, int>>& adim = a.arrayInfo->GetSizes();
const vector<pair<int, int>>& bdim = b.arrayInfo->GetSizes(); const vector<pair<int, int>>& bdim = b.arrayInfo->GetSizes();
@@ -216,12 +224,11 @@ static bool equalDims(const CommConstraint& a, const CommConstraint& b)
if (adim[i].second - adim[i].first != bdim[i].second - bdim[i].first) if (adim[i].second - adim[i].first != bdim[i].second - bdim[i].first)
return false; return false;
} }
return true;
} }
// TODO: add attributes to CommConstraints, check if a and b have equal attributes // TODO: add attributes to CommConstraints, check if a and b have equal attributes
static bool equalConstraints(const CommConstraint& a, const CommConstraint& b) bool equalConstraints(const CommConstraint& a, const CommConstraint& b)
{ {
if ((a.arrayInfo != NULL && b.arrayInfo == NULL) || ((a.arrayInfo == NULL && b.arrayInfo != NULL))) if ((a.arrayInfo != NULL && b.arrayInfo == NULL) || ((a.arrayInfo == NULL && b.arrayInfo != NULL)))
return false; return false;
@@ -232,7 +239,8 @@ static bool equalConstraints(const CommConstraint& a, const CommConstraint& b)
return true; return true;
} }
static void addElem(deque<CommConstraint>& comm, const CommConstraint& elem)
void addElem(deque<CommConstraint>& comm, const CommConstraint& elem)
{ {
if (elem.typeVariant == 0 && !comm.empty() && comm.back().typeVariant == 0) if (elem.typeVariant == 0 && !comm.empty() && comm.back().typeVariant == 0)
comm.back().size += elem.size; comm.back().size += elem.size;
@@ -240,8 +248,9 @@ static void addElem(deque<CommConstraint>& comm, const CommConstraint& elem)
comm.push_back(elem); comm.push_back(elem);
} }
// TODO: check attributes: do not split arrays with pointer or target attributes if check_use == true // TODO: check attributes: do not split arrays with pointer or target attributes if check_use == true
static bool splitType(deque<CommConstraint>& d, bool check_use, const set<string>& namesOfUsedVars = {}) bool splitType(deque<CommConstraint>& d, bool check_use, const set<string>& namesOfUsedVars = {})
{ {
CommConstraint var = d.front(); CommConstraint var = d.front();
string name = var.identifier; string name = var.identifier;
@@ -289,7 +298,8 @@ static bool splitType(deque<CommConstraint>& d, bool check_use, const set<string
} }
} }
static deque<CommConstraint> makeConstraints(deque<CommConstraint>& constraints, const set<string>& namesOfUsedVars, set<string>& notUsedVars)
deque<CommConstraint> makeConstraints(deque<CommConstraint>& constraints, const set<string>& namesOfUsedVars, set<string>& notUsedVars)
{ {
deque<CommConstraint> res; deque<CommConstraint> res;
while (!constraints.empty()) while (!constraints.empty())
@@ -306,7 +316,8 @@ static deque<CommConstraint> makeConstraints(deque<CommConstraint>& constraints,
return res; return res;
} }
static bool check(deque<CommConstraint>& A, deque<CommConstraint>& B, pair<CommConstraint, CommConstraint>& problemConstraints)
bool check(deque<CommConstraint>& A, deque<CommConstraint>& B, pair<CommConstraint, CommConstraint>& problemConstraints)
{ {
while (!A.empty() && !B.empty()) while (!A.empty() && !B.empty())
{ {
@@ -345,8 +356,8 @@ static bool check(deque<CommConstraint>& A, deque<CommConstraint>& B, pair<CommC
return true; return true;
} }
static bool docheckUnequalConstraints(deque<CommConstraint>& U, deque<CommConstraint>& B, deque<CommConstraint>& newU,
pair<CommConstraint, CommConstraint>& problemConstraints) bool docheckUnequalConstraints(deque<CommConstraint>& U, deque<CommConstraint>& B, deque<CommConstraint>& newU, pair<CommConstraint, CommConstraint>& problemConstraints)
{ {
if (U.front().typeVariant == 0) if (U.front().typeVariant == 0)
{ {
@@ -369,8 +380,8 @@ static bool docheckUnequalConstraints(deque<CommConstraint>& U, deque<CommConstr
return true; return true;
} }
static bool buildConstraintsUnion(deque<CommConstraint>& U, deque<CommConstraint> B,
const set<string>& namesOfUsedVars, pair<CommConstraint, CommConstraint>& problemConstraints) bool buildConstraintsUnion(deque<CommConstraint>& U, deque<CommConstraint> B, const set<string>& namesOfUsedVars, pair<CommConstraint, CommConstraint>& problemConstraints)
{ {
deque<CommConstraint> newU; deque<CommConstraint> newU;
while (!U.empty() && !B.empty()) while (!U.empty() && !B.empty())
@@ -425,8 +436,8 @@ static bool buildConstraintsUnion(deque<CommConstraint>& U, deque<CommConstraint
return true; return true;
} }
//TODO: check this: newDecl and oldDecl => do these variables need references?
static bool getNamesOldToNew(deque<CommConstraint> newDecl, deque<CommConstraint> oldDecl, map<string, string>& namesOldToNew) bool getNamesOldToNew(deque<CommConstraint> newDecl, deque<CommConstraint> oldDecl, map<string, string>& namesOldToNew)
{ {
bool needChange = false; bool needChange = false;
map<string, string> rename; map<string, string> rename;
@@ -491,18 +502,16 @@ static bool getNamesOldToNew(deque<CommConstraint> newDecl, deque<CommConstraint
newDecl.pop_front(); newDecl.pop_front();
} }
} }
if (!oldDecl.empty() || !newDecl.empty()) if (!oldDecl.empty() || !newDecl.empty())
needChange = true; needChange = true;
if (needChange) if (needChange)
namesOldToNew.insert(rename.begin(), rename.end()); namesOldToNew.insert(rename.begin(), rename.end());
return needChange; return needChange;
} }
static void makeCommVarSymbs(const deque<CommConstraint>& constraints, SgFile* file, SgStatement* func, const string& commName,
map<string, SgSymbol*>& symbs, vector<SgSymbol*>& needNewDecl) void makeCommVarSymbs(const deque<CommConstraint>& constraints, SgFile* file, SgStatement* func, string commName,
map<string, SgSymbol*>& symbs, vector<SgSymbol*>& needNewDecl)
{ {
for (const CommConstraint& var : constraints) for (const CommConstraint& var : constraints)
{ {
@@ -515,7 +524,8 @@ static void makeCommVarSymbs(const deque<CommConstraint>& constraints, SgFile* f
} }
} }
static void deleteOldVars(SgStatement* firstSt, const set<string>& commVarNames)
void deleteOldVars(SgStatement* firstSt, const set<string>& commVarNames)
{ {
SgStatement* lastSt = firstSt->lastNodeOfStmt(); SgStatement* lastSt = firstSt->lastNodeOfStmt();
vector<SgStatement*> stmtsToDelete; vector<SgStatement*> stmtsToDelete;
@@ -561,12 +571,12 @@ static void deleteOldVars(SgStatement* firstSt, const set<string>& commVarNames)
} }
// TODO: delete common variables form attributes statements (like DIM_STAT) // TODO: delete common variables form attributes statements (like DIM_STAT)
} }
for (SgStatement* st : stmtsToDelete) for (SgStatement* st : stmtsToDelete)
st->deleteStmt(); st->deleteStmt();
} }
static SgExpression* makeIdxFromStr(const string& str)
SgExpression* makeIdxFromStr(const string& str)
{ {
vector<SgExpression*> items; vector<SgExpression*> items;
int num = 0; int num = 0;
@@ -581,13 +591,13 @@ static SgExpression* makeIdxFromStr(const string& str)
num = 0; num = 0;
} }
} }
reverse(items.begin(), items.end()); reverse(items.begin(), items.end());
SgExpression* exprList = makeExprList(items, false); SgExpression* exprList = makeExprList(items, false);
return exprList; return exprList;
} }
static SgExpression* newArrElemExpr(const string& newName, const map<string, SgSymbol*>& newSymbs)
SgExpression* newArrElemExpr(const string& newName, const map<string, SgSymbol*>& newSymbs)
{ {
size_t pos = newName.find('('); size_t pos = newName.find('(');
SgExpression* newExpr = new SgArrayRefExp(*newSymbs.at(newName.substr(0, pos))); SgExpression* newExpr = new SgArrayRefExp(*newSymbs.at(newName.substr(0, pos)));
@@ -595,11 +605,11 @@ static SgExpression* newArrElemExpr(const string& newName, const map<string, SgS
return newExpr; return newExpr;
} }
static SgExpression* fixExpression(SgExpression* expr, const map<string, SgSymbol*>& newSymbs, const map<string, string>& namesOldToNew)
SgExpression* fixExpression(SgExpression* expr, const map<string, SgSymbol*>& newSymbs, const map<string, string>& namesOldToNew)
{ {
if (expr == NULL) if (expr == NULL)
return NULL; return NULL;
if (expr->variant() == VAR_REF || expr->variant() == ARRAY_REF) if (expr->variant() == VAR_REF || expr->variant() == ARRAY_REF)
{ {
string name = expr->symbol()->identifier(); string name = expr->symbol()->identifier();
@@ -635,18 +645,17 @@ static SgExpression* fixExpression(SgExpression* expr, const map<string, SgSymbo
} }
} }
} }
SgExpression* lhs = fixExpression(expr->lhs(), newSymbs, namesOldToNew); SgExpression* lhs = fixExpression(expr->lhs(), newSymbs, namesOldToNew);
if (lhs != NULL) if (lhs != NULL)
expr->setLhs(lhs); expr->setLhs(lhs);
SgExpression* rhs = fixExpression(expr->rhs(), newSymbs, namesOldToNew); SgExpression* rhs = fixExpression(expr->rhs(), newSymbs, namesOldToNew);
if (rhs != NULL) if (rhs != NULL)
expr->setRhs(rhs); expr->setRhs(rhs);
return NULL; return NULL;
} }
static void renameVariables(SgStatement* firstSt, const map<string, SgSymbol*>& newVarSymbs, const map<string, string>& namesOldToNew)
void renameVariables(SgStatement* firstSt, const map<string, SgSymbol*>& newVarSymbs, const map<string, string>& namesOldToNew)
{ {
SgStatement* lastSt = firstSt->lastNodeOfStmt(); SgStatement* lastSt = firstSt->lastNodeOfStmt();
for (SgStatement* curSt = firstSt; curSt != NULL && curSt != lastSt; curSt = curSt->lexNext()) for (SgStatement* curSt = firstSt; curSt != NULL && curSt != lastSt; curSt = curSt->lexNext())
@@ -694,7 +703,8 @@ static void renameVariables(SgStatement* firstSt, const map<string, SgSymbol*>&
} }
} }
static SgExpression* makeExprListForCommon(const deque<CommConstraint>& decl, const map<string, SgSymbol*>& newSymbs,
SgExpression* makeExprListForCommon(const deque<CommConstraint>& decl, const map<string, SgSymbol*>& newSymbs,
SgFile* file, SgStatement* firstSt) SgFile* file, SgStatement* firstSt)
{ {
vector<SgExpression*> items; vector<SgExpression*> items;
@@ -728,7 +738,8 @@ static SgExpression* makeExprListForCommon(const deque<CommConstraint>& decl, co
return exprList; return exprList;
} }
static void rewriteCommon(SgStatement* firstSt, map<string, SgExpression*>& commListExprs)
void rewriteCommon(SgStatement* firstSt, map<string, SgExpression*>& commListExprs)
{ {
vector<SgStatement*> commonStmtsToDelete; vector<SgStatement*> commonStmtsToDelete;
for (SgStatement* st = firstSt; st != firstSt->lastDeclaration()->lexNext(); st = st->lexNext()) for (SgStatement* st = firstSt; st != firstSt->lastDeclaration()->lexNext(); st = st->lexNext())
@@ -779,12 +790,12 @@ static void rewriteCommon(SgStatement* firstSt, map<string, SgExpression*>& comm
commonStmtsToDelete.push_back(st); commonStmtsToDelete.push_back(st);
} }
} }
for (SgStatement* st : commonStmtsToDelete) for (SgStatement* st : commonStmtsToDelete)
st->deleteStmt(); st->deleteStmt();
} }
static void fixNames(deque<CommConstraint>& constraints, const string& commName)
void fixNames(deque<CommConstraint>& constraints, const string& commName)
{ {
for (auto& var : constraints) for (auto& var : constraints)
{ {
@@ -799,26 +810,26 @@ static void fixNames(deque<CommConstraint>& constraints, const string& commName)
} }
} }
static bool variablePositionComp(const Variable* lhs, const Variable* rhs)
bool variablePositionComp(const Variable* lhs, const Variable* rhs)
{ {
return lhs->getPosition() < rhs->getPosition(); return lhs->getPosition() < rhs->getPosition();
} }
static void fixFunctions(SgFile* file, const vector<SgStatement*>& programUnits, map<string, deque<CommConstraint>>& newCommonDecls,
map<string, map<string, deque<CommConstraint>>>& commDecls, const set<string>& badCommon, map<string, set<string>>& notUsedVars) void fixFunctions(SgFile* file, vector<SgStatement*> programUnits, map<string, deque<CommConstraint>>& newCommonDecls,
map<string, map<string, deque<CommConstraint>>>& commDecls, const set<string>& badCommon, map<string, set<string>>& notUsedVars)
{ {
for (SgStatement* unitSt : programUnits) for (SgStatement* unitSt : programUnits)
{ {
string funcName = unitSt->symbol()->identifier(); string funcName = unitSt->symbol()->identifier();
if (commDecls.find(funcName) == commDecls.end()) if (commDecls.find(funcName) == commDecls.end())
continue; continue;
SgStatement* firstSt = unitSt; SgStatement* firstSt = unitSt;
map<string, SgExpression*> commListExprs; map<string, SgExpression*> commListExprs;
map<string, SgSymbol*> newVarSymbs; // new symbols for new variables map<string, SgSymbol*> newVarSymbs; // new symbols for new variables
map<string, string> namesOldToNew; // for ranaming: old name -> new name map<string, string> namesOldToNew; // for ranaming: old name -> new name
vector<SgSymbol*> needNewDecl; vector<SgSymbol*> needNewDecl;
for (auto& common : commDecls[funcName]) for (auto& common : commDecls[funcName])
{ {
string commName = common.first; string commName = common.first;
@@ -829,11 +840,9 @@ static void fixFunctions(SgFile* file, const vector<SgStatement*>& programUnits,
bool needChange = getNamesOldToNew(newDecl, common.second, namesOldToNew); bool needChange = getNamesOldToNew(newDecl, common.second, namesOldToNew);
if (!needChange) if (!needChange)
continue; continue;
makeCommVarSymbs(newDecl, file, firstSt, commName, newVarSymbs, needNewDecl); makeCommVarSymbs(newDecl, file, firstSt, commName, newVarSymbs, needNewDecl);
commListExprs[commName] = makeExprListForCommon(newDecl, newVarSymbs, file, firstSt); commListExprs[commName] = makeExprListForCommon(newDecl, newVarSymbs, file, firstSt);
} }
if (!commListExprs.empty()) if (!commListExprs.empty())
{ {
for (const auto& item : commListExprs) for (const auto& item : commListExprs)
@@ -847,9 +856,10 @@ static void fixFunctions(SgFile* file, const vector<SgStatement*>& programUnits,
} }
} }
static void buildNewCommDecls(SgFile* file, const map<string, CommonBlock*>& allCommonBlocks,
map<string, deque<CommConstraint>>& newCommonDecls, map<string, map<string, deque<CommConstraint>>>& commDecls, void BuildNewCommDecls(SgFile* file, const map<string, CommonBlock*> allCommonBlocks,
set<string>& badCommon, map<string, set<string>>& notUsedVars, vector<SgStatement*>& programUnits) map<string, deque<CommConstraint>>& newCommonDecls, map<string, map<string, deque<CommConstraint>>>& commDecls,
set<string>& badCommon, map<string, set<string>>& notUsedVars, vector<SgStatement*>& programUnits)
{ {
string fileName = file->filename(); string fileName = file->filename();
SgStatement* curSt = file->firstStatement(); SgStatement* curSt = file->firstStatement();
@@ -888,8 +898,7 @@ static void buildNewCommDecls(SgFile* file, const map<string, CommonBlock*>& all
constraints.push_back(newConstr); constraints.push_back(newConstr);
} }
if (hasChar && hasNotChar) // TDOO: make proper warning message or separate such common blocks if (hasChar && hasNotChar) // TDOO: make proper warning message or separate such common blocks
__spf_print(1, "common block '%s' ('%s':%d) contains variables of symbolic and numeric types. It is required to divide\n", __spf_print(1, "common block '%s' ('%s':%d) contains variables of symbolic and numeric types. It is required to divide\n", commName.c_str(), fileName.c_str(), constraints.back().uses.back().lineNum);
commName.c_str(), fileName.c_str(), constraints.back().uses.back().getLineNum());
if (hasChar) if (hasChar)
{ {
badCommon.insert(commName); badCommon.insert(commName);
@@ -906,7 +915,7 @@ static void buildNewCommDecls(SgFile* file, const map<string, CommonBlock*>& all
for (auto x : problemConstraints.first.uses) // TODO: make proper warning message for (auto x : problemConstraints.first.uses) // TODO: make proper warning message
for (auto y : problemConstraints.second.uses) for (auto y : problemConstraints.second.uses)
__spf_print(1, "variables '%s' and '%s' in one storage association (common block '%s') have different types (files - %s:%d and %s:%d)\n", __spf_print(1, "variables '%s' and '%s' in one storage association (common block '%s') have different types (files - %s:%d and %s:%d)\n",
x.getVarName(), y.getVarName(), commName.c_str(), x.getFileName(), x.getLineNum(), y.getFileName(), y.getLineNum()); x.varName.c_str(), y.varName.c_str(), commName.c_str(), x.fileName.c_str(), x.lineNum, y.fileName.c_str(), y.lineNum);
} }
} }
curSt = curSt->lastNodeOfStmt(); curSt = curSt->lastNodeOfStmt();
@@ -918,7 +927,7 @@ static void buildNewCommDecls(SgFile* file, const map<string, CommonBlock*>& all
// main function // main function
void fixCommonBlocks(const map<string, vector<FuncInfo*>>& allFuncInfo, const map<string, CommonBlock*>& allCommonBlocks, SgProject* project) // TODO: separate into 2 steps? void fixCommonBlocks(const map<string, vector<FuncInfo*>> allFuncInfo, const map<string, CommonBlock*> allCommonBlocks, SgProject* project) // TODO: separate into 2 steps?
{ {
int filesNum = project->numberOfFiles(); int filesNum = project->numberOfFiles();
map<string, map<string, map<string, deque<CommConstraint>>>> commDecls; // file_name -> function_name -> common block name -> old declaration of common block map<string, map<string, map<string, deque<CommConstraint>>>> commDecls; // file_name -> function_name -> common block name -> old declaration of common block
@@ -932,12 +941,10 @@ void fixCommonBlocks(const map<string, vector<FuncInfo*>>& allFuncInfo, const ma
SgFile* file = &project->file(i); SgFile* file = &project->file(i);
string fileName = file->filename(); string fileName = file->filename();
file->switchToFile(fileName); file->switchToFile(fileName);
buildNewCommDecls(file, allCommonBlocks, newCommonDecls, commDecls[fileName], badCommon, notUsedVars, programUnitsInFile[fileName]); BuildNewCommDecls(file, allCommonBlocks, newCommonDecls, commDecls[fileName], badCommon, notUsedVars, programUnitsInFile[fileName]);
} }
for (auto& elem : newCommonDecls) for (auto& elem : newCommonDecls)
fixNames(elem.second, elem.first); fixNames(elem.second, elem.first);
for (int i = 0; i < filesNum; i++) // second step for (int i = 0; i < filesNum; i++) // second step
{ {
SgFile* file = &project->file(i); SgFile* file = &project->file(i);

View File

@@ -16,18 +16,12 @@
struct DeclInfo // for error messages struct DeclInfo // for error messages
{ {
private:
std::string varName; std::string varName;
std::string fileName; std::string fileName;
int lineNum; int lineNum;
public:
DeclInfo() : varName(""), fileName(""), lineNum(0) {}; DeclInfo() : varName(""), fileName(""), lineNum(0) {};
DeclInfo(const std::string& vn, const std::string& fn, int ln) : varName(vn), fileName(fn), lineNum(ln) {}; DeclInfo(const std::string& vn, const std::string& fn, int ln) : varName(vn), fileName(fn), lineNum(ln) {};
const char* getVarName() const { return varName.c_str(); }
const char* getFileName() const { return fileName.c_str(); }
int getLineNum() const { return lineNum; }
}; };
struct CommConstraint // TODO: add variable attributes struct CommConstraint // TODO: add variable attributes
@@ -48,4 +42,4 @@ struct CommConstraint // TODO: add variable attributes
}; };
void fixCommonBlocks(const std::map<std::string, std::vector<FuncInfo*>>& allFuncInfo, const std::map<std::string, CommonBlock*>& allCommonBlocks, SgProject* project); void fixCommonBlocks(const std::map<std::string, std::vector<FuncInfo*>> allFuncInfo, const std::map<std::string, CommonBlock*> allCommonBlocks, SgProject* project);

View File

@@ -19,7 +19,6 @@ using std::pair;
using std::make_pair; using std::make_pair;
using std::wstring; using std::wstring;
using std::stack; using std::stack;
using SAPFOR::CFG_Settings;
#define PRINT_SPLITTED_FRAGMENTS 0 #define PRINT_SPLITTED_FRAGMENTS 0
@@ -316,7 +315,7 @@ static map<SgStatement*, pair<set<SgStatement*>, set<SgStatement*>>>
printInternalError(convertFileName(__FILE__).c_str(), __LINE__); printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
map<SAPFOR::Argument*, set<int>> outForCurr; map<SAPFOR::Argument*, set<int>> outForCurr;
buildGenKillForCFG(itCFG->second, funcByName, outForFunc, gen, kill, &genForIR, &killForIR, notInitedGlobals, SAPFOR::CFG_Settings()); buildGenKillForCFG(itCFG->second, funcByName, outForFunc, gen, kill, &genForIR, &killForIR, notInitedGlobals, SAPFOR::CFG_Settings(0));
if (outForFunc.count(byFunc)) if (outForFunc.count(byFunc))
printInternalError(convertFileName(__FILE__).c_str(), __LINE__); printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
@@ -1052,8 +1051,7 @@ int splitLoops(SgFile *file, vector<LoopGraph*> &loopGraphs, vector<Messages> &m
checkNull(listExp, convertFileName(__FILE__).c_str(), __LINE__); checkNull(listExp, convertFileName(__FILE__).c_str(), __LINE__);
int deep = listExp->length(); int deep = listExp->length();
const auto settings = CFG_Settings({ CFG_Settings::CFG_atLeastOneIterInLoop, CFG_Settings::CFG_withRD, CFG_Settings::CFG_withCallFrom, CFG_Settings::CFG_withDominators }); currIR = buildCFGforCurrentFunc(loop->loop, SAPFOR::CFG_Settings(true, true), commonBlocks, allFuncInfo);
currIR = buildCFGforCurrentFunc(loop->loop, settings, commonBlocks, allFuncInfo);
totalErr = splitLoop(loop, messages, deep, depInfoForLoopGraph); totalErr = splitLoop(loop, messages, deep, depInfoForLoopGraph);
if (totalErr > 0) if (totalErr > 0)

View File

@@ -13,7 +13,6 @@ using std::set;
using std::string; using std::string;
using std::vector; using std::vector;
using std::wstring; using std::wstring;
using SAPFOR::CFG_Settings;
using CFG_Type = map<FuncInfo*, vector<SAPFOR::BasicBlock*>>; using CFG_Type = map<FuncInfo*, vector<SAPFOR::BasicBlock*>>;
using UsersDirectives = map<pair<string, int>, set<SgStatement*>>; using UsersDirectives = map<pair<string, int>, set<SgStatement*>>;
@@ -2208,8 +2207,8 @@ static void removePrivateAnalyze(Context *ctx)
makeDeclaration(ctx->loopStmt, vector<SgSymbol*> {receiverVar}, nullptr) makeDeclaration(ctx->loopStmt, vector<SgSymbol*> {receiverVar}, nullptr)
)); ));
const auto settings = CFG_Settings({ CFG_Settings::CFG_atLeastOneIterInLoop, CFG_Settings::CFG_withRD, CFG_Settings::CFG_withCallFrom, CFG_Settings::CFG_withDominators }); CFG_Type CFG_ForFunc = buildCFGforCurrentFunc(ctx->loopStmt,
CFG_Type CFG_ForFunc = buildCFGforCurrentFunc(ctx->loopStmt, settings, SAPFOR::CFG_Settings(true, true),
ctx->commonBlocks, ctx->allFuncInfo); ctx->commonBlocks, ctx->allFuncInfo);
if (CFG_ForFunc.empty()) if (CFG_ForFunc.empty())
printInternalError(convertFileName(__FILE__).c_str(), __LINE__); printInternalError(convertFileName(__FILE__).c_str(), __LINE__);

View File

@@ -206,9 +206,7 @@ void InitPassesDependencies(map<passes, vector<passes>> &passDepsIn, set<passes>
Pass(DEF_USE_STAGE1) <= Pass(DEF_USE_STAGE2); Pass(DEF_USE_STAGE1) <= Pass(DEF_USE_STAGE2);
list({ VERIFY_DVM_DIRS, VERIFY_COMMON, FILL_COMMON_BLOCKS, PRIVATE_CALL_GRAPH_STAGE1, PRIVATE_CALL_GRAPH_STAGE2, MACRO_EXPANSION, CONVERT_ASSIGN_TO_LOOP, DEF_USE_STAGE1, DEF_USE_STAGE2, FILL_PARALLEL_REG_IR, CALL_GRAPH_IR }) <= list({ SUBST_EXPR, SUBST_EXPR_RD, BUILD_IR }); list({ VERIFY_DVM_DIRS, PRIVATE_CALL_GRAPH_STAGE1, PRIVATE_CALL_GRAPH_STAGE2, MACRO_EXPANSION, CONVERT_ASSIGN_TO_LOOP, DEF_USE_STAGE1, DEF_USE_STAGE2, FILL_PARALLEL_REG_IR, VERIFY_COMMON, FILL_COMMON_BLOCKS, CALL_GRAPH_IR }) <= list({ SUBST_EXPR, SUBST_EXPR_RD, BUILD_IR });
Pass(VERIFY_COMMON) <= Pass(FILL_COMMON_BLOCKS);
Pass(BUILD_IR) <= Pass(SUBST_EXPR) <= Pass(SUBST_EXPR_AND_UNPARSE); Pass(BUILD_IR) <= Pass(SUBST_EXPR) <= Pass(SUBST_EXPR_AND_UNPARSE);
@@ -219,7 +217,7 @@ void InitPassesDependencies(map<passes, vector<passes>> &passDepsIn, set<passes>
Pass(RESTORE_LOOP_FROM_ASSIGN) <= list({ SUBST_EXPR_AND_UNPARSE, SUBST_EXPR_RD_AND_UNPARSE }); Pass(RESTORE_LOOP_FROM_ASSIGN) <= list({ SUBST_EXPR_AND_UNPARSE, SUBST_EXPR_RD_AND_UNPARSE });
Pass(FILL_COMMON_BLOCKS) <= Pass(GET_ALL_ARRAY_DECL) <= list({ CALL_GRAPH_IR, INSERT_NO_DISTR_FLAGS_FROM_GUI }); Pass(GET_ALL_ARRAY_DECL) <= list({ CALL_GRAPH_IR, INSERT_NO_DISTR_FLAGS_FROM_GUI });
Pass(LOOP_GRAPH) <= Pass(PRIVATE_CALL_GRAPH_STAGE3) <= list(FIND_FUNC_TO_INCLUDE, PRIVATE_ANALYSIS_IR) <= list({ LOOP_ANALYZER_DATA_DIST_S0, LOOP_ANALYZER_DATA_DIST_S1, ONLY_ARRAY_GRAPH, LOOP_ANALYZER_ALIGNS }); Pass(LOOP_GRAPH) <= Pass(PRIVATE_CALL_GRAPH_STAGE3) <= list(FIND_FUNC_TO_INCLUDE, PRIVATE_ANALYSIS_IR) <= list({ LOOP_ANALYZER_DATA_DIST_S0, LOOP_ANALYZER_DATA_DIST_S1, ONLY_ARRAY_GRAPH, LOOP_ANALYZER_ALIGNS });
@@ -229,7 +227,7 @@ void InitPassesDependencies(map<passes, vector<passes>> &passDepsIn, set<passes>
list({ VERIFY_OPERATORS, VERIFY_ENDDO, VERIFY_INCLUDES, PREPROC_SPF, PREPROC_ALLOCATES, GET_ALL_ARRAY_DECL, GCOV_PARSER }) <= list({ CALL_GRAPH, MACRO_EXPANSION, DEF_USE_STAGE1 }); list({ VERIFY_OPERATORS, VERIFY_ENDDO, VERIFY_INCLUDES, PREPROC_SPF, PREPROC_ALLOCATES, GET_ALL_ARRAY_DECL, GCOV_PARSER }) <= list({ CALL_GRAPH, MACRO_EXPANSION, DEF_USE_STAGE1 });
list({ VERIFY_OPERATORS, VERIFY_ENDDO, VERIFY_INCLUDES, PREPROC_ALLOCATES, FILL_PARALLEL_REG_IR }) <= list({ FILL_COMMON_BLOCKS, GET_ALL_ARRAY_DECL, PARSE_OMP_DIRS }) <= Pass(PREPROC_SPF); list({ VERIFY_OPERATORS, VERIFY_ENDDO, VERIFY_INCLUDES, 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); Pass(CHECK_PAR_REG_DIR) <= Pass(FILL_PARALLEL_REG_IR);
@@ -321,6 +319,7 @@ void InitPassesDependencies(map<passes, vector<passes>> &passDepsIn, set<passes>
list({ CALL_GRAPH2, CALL_GRAPH, BUILD_IR, LOOP_GRAPH, LOOP_ANALYZER_DATA_DIST_S2 }) <= Pass(FIND_PRIVATE_ARRAYS_ANALYSIS); 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); list({ FIND_PRIVATE_ARRAYS_ANALYSIS, CONVERT_LOOP_TO_ASSIGN, RESTORE_LOOP_FROM_ASSIGN, REVERT_SUBST_EXPR_RD }) <= Pass(FIND_PRIVATE_ARRAYS);
Pass(CREATE_TEMPLATE_LINKS) <= Pass(MERGE_COPY_ARRAYS);
list({ BUILD_IR, CALL_GRAPH2, RESTORE_LOOP_FROM_ASSIGN, REVERT_SUBST_EXPR_RD }) <= Pass(MOVE_OPERATORS); list({ BUILD_IR, CALL_GRAPH2, RESTORE_LOOP_FROM_ASSIGN, REVERT_SUBST_EXPR_RD }) <= Pass(MOVE_OPERATORS);
passesIgnoreStateDone.insert({ CREATE_PARALLEL_DIRS, INSERT_PARALLEL_DIRS, INSERT_SHADOW_DIRS, EXTRACT_PARALLEL_DIRS, passesIgnoreStateDone.insert({ CREATE_PARALLEL_DIRS, INSERT_PARALLEL_DIRS, INSERT_SHADOW_DIRS, EXTRACT_PARALLEL_DIRS,

View File

@@ -934,14 +934,8 @@ void fillNonDistrArraysAsPrivate(SgStatement *st,
{ {
auto itD = declaredArrays.find(*itSet); auto itD = declaredArrays.find(*itSet);
if (itD != declaredArrays.end()) if (itD != declaredArrays.end())
{ if (itD->second.first->IsNotDistribute())
const auto array = itD->second.first; privatesVars.insert(itD->second.first->GetShortName());
if (array->IsNotDistribute())
{
auto symb = array->GetDeclSymbol(make_pair(st->fileName(), st->lineNumber()));
privatesVars.insert(symb->identifier());
}
}
} }
} }
} }
@@ -960,20 +954,8 @@ DIST::Array* getArrayFromDeclarated(SgStatement *st, const string &arrayName)
{ {
auto itD = declaredArrays.find(*itSet); auto itD = declaredArrays.find(*itSet);
if (itD != declaredArrays.end()) if (itD != declaredArrays.end())
{ if (itD->second.first->GetShortName() == arrayName)
DIST::Array* array = itD->second.first; found = itD->second.first;
if (array->GetLocation().first == DIST::l_COMMON)
{
auto symb = array->GetDeclSymbol(make_pair(st->fileName(), st->lineNumber()));
if (symb && symb->identifier() == arrayName)
found = array;
}
else
{
if (array->GetShortName() == arrayName)
found = array;
}
}
} }
} }
return found; return found;
@@ -1282,32 +1264,6 @@ static SgExpression* isInCommon(const vector<SgExpression*> &commonBlocks, const
return NULL; return NULL;
} }
//all common block in project
extern map<string, CommonBlock*> commonBlocks;
static string getCommonNameOnPos(const string& name, const int commonPos)
{
if (commonBlocks.size() == 0)
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
auto it = commonBlocks.find(name);
if (it == commonBlocks.end())
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
auto inPos = it->second->getGroupedVars().find(commonPos);
if (inPos == it->second->getGroupedVars().end())
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
set<string> namesOnPos;
for (auto& var : inPos->second)
namesOnPos.insert(var->getName());
if (namesOnPos.size() == 0)
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
return *namesOnPos.begin();
}
static map<tuple<string, string, int>, tuple<int, string, string>> tableOfUniqNames; static map<tuple<string, string, int>, tuple<int, string, string>> tableOfUniqNames;
tuple<int, string, string> getUniqName(const map<string, vector<SgExpression*>> &commonBlocks, SgStatement *decl, SgSymbol *symb) tuple<int, string, string> getUniqName(const map<string, vector<SgExpression*>> &commonBlocks, SgStatement *decl, SgSymbol *symb)
{ {
@@ -1316,7 +1272,6 @@ tuple<int, string, string> getUniqName(const map<string, vector<SgExpression*>>
int commonPos = 0; int commonPos = 0;
SgExpression *foundCommon = NULL; SgExpression *foundCommon = NULL;
string symbCommn = "";
SgStatement *declCP = decl->controlParent(); SgStatement *declCP = decl->controlParent();
// find symbol in parameter list of functions // find symbol in parameter list of functions
@@ -1352,7 +1307,6 @@ tuple<int, string, string> getUniqName(const map<string, vector<SgExpression*>>
if (foundCommon) if (foundCommon)
{ {
inCommon = true; inCommon = true;
symbCommn = getCommonNameOnPos(common.first, commonPos);
break; break;
} }
} }
@@ -1360,7 +1314,7 @@ tuple<int, string, string> getUniqName(const map<string, vector<SgExpression*>>
tuple<int, string, string> retVal; tuple<int, string, string> retVal;
if (inCommon) if (inCommon)
retVal = make_tuple(commonPos, string("common_") + getCommonName(foundCommon), symbCommn); retVal = make_tuple(commonPos, string("common_") + getCommonName(foundCommon), string(symb->identifier()));
else else
retVal = make_tuple(decl->lineNumber(), string(decl->fileName()), string(symb->identifier())); retVal = make_tuple(decl->lineNumber(), string(decl->fileName()), string(symb->identifier()));

View File

@@ -78,11 +78,6 @@ enum typeMessage { WARR, ERROR, NOTE };
// 60 "Format misplaced" // 60 "Format misplaced"
// 61 "Array has declaration area conflict" // 61 "Array has declaration area conflict"
// 62 "need to move common declaration to main for DECLATE" // 62 "need to move common declaration to main for DECLATE"
// 63 "Failed to initialize libpredict cluster"
// 64 "Failed to initialize libpredict grid"
// 65 "Failed to distribute array with libpredict"
// 66 "Failed to align array with libpredict"
// 67 "Failed to process shadow_renew with libpredict"
// //
// 20xx TRANSFORM GROUP // 20xx TRANSFORM GROUP
// 01 "can not convert array assign to loop" // 01 "can not convert array assign to loop"
@@ -310,7 +305,7 @@ static void printStackTrace() { };
} \ } \
} while (0) } while (0)
// Свободный - R210 // Свободный - R206
// Гайд по русификации сообщений: При добавлении нового сообщения, меняется последний сводобный идентификатор. // Гайд по русификации сообщений: При добавлении нового сообщения, меняется последний сводобный идентификатор.
// В этом файле остаются только спецификаторы, для которых будет заполнен текст. Полный текст пишется в файле // В этом файле остаются только спецификаторы, для которых будет заполнен текст. Полный текст пишется в файле
// russian_errors_text.txt. Спецификаторы там тоже сохраняются, по ним в визуализаторе будет восстановлен // russian_errors_text.txt. Спецификаторы там тоже сохраняются, по ним в визуализаторе будет восстановлен
@@ -509,18 +504,6 @@ static const wchar_t *R183 = L"R183:";
static const wchar_t *R184 = L"R184:%s"; static const wchar_t *R184 = L"R184:%s";
//1062 //1062
static const wchar_t* R205 = L"R205:%s#%s"; static const wchar_t* R205 = L"R205:%s#%s";
//1063
static const wchar_t* R206 = L"R206:";
//1064
static const wchar_t* R207 = L"R207:";
//1065
static const wchar_t* R208 = L"R208:";
//1066
static const wchar_t* R209 = L"R209:";
//1067
static const wchar_t* R210 = L"R210:";
//1068
static const wchar_t* R211 = L"R211:";
//2001 //2001
static const wchar_t *R94 = L"R94:"; static const wchar_t *R94 = L"R94:";

View File

@@ -337,15 +337,10 @@ const set<SgSymbol*>& getModuleSymbols(SgStatement *func)
//if function or module in contains //if function or module in contains
auto cp = func->controlParent(); auto cp = func->controlParent();
if (isSgProgHedrStmt(cp) || cp->variant() == MODULE_STMT) if (isSgProgHedrStmt(cp) || cp->variant() == MODULE_STMT)
{
getModuleSymbols(cp, symbs); getModuleSymbols(cp, symbs);
if (func->variant() == FUNC_HEDR)
symbs.insert(func->symbol());
}
symbolsForFunc[func->symbol()->identifier()] = symbs; symbolsForFunc[func->symbol()->identifier()] = symbs;
return symbolsForFunc[func->symbol()->identifier()]; return symbs;
} }
static void findSymbol(SgStatement* func, const string& varName, const string& locName, static void findSymbol(SgStatement* func, const string& varName, const string& locName,
@@ -354,19 +349,9 @@ static void findSymbol(SgStatement* func, const string& varName, const string& l
for (const auto& s : getModuleSymbols(func)) for (const auto& s : getModuleSymbols(func))
{ {
SgSymbol* orig = OriginalSymbol(s); SgSymbol* orig = OriginalSymbol(s);
printf("%s == %s\n", orig->identifier(), s->identifier());
//any suitable symbol can be used //any suitable symbol can be used
if (orig->identifier() == varName && orig->scope()->symbol()->identifier() == locName)
if (orig->variant() == FUNCTION_NAME) altNames[s->identifier()] = s;
{
if (orig->identifier() == varName)
altNames[s->identifier()] = s;
}
else
{
if (orig->identifier() == varName && orig->scope()->symbol()->identifier() == locName)
altNames[s->identifier()] = s;
}
} }
} }
@@ -384,7 +369,6 @@ SgSymbol* getNameInLocation(SgStatement* func, const string& varName, const stri
return altNames.begin()->second; return altNames.begin()->second;
else { else {
__spf_print(1, "%s (%s %s) %s\n", func->symbol()->identifier(), clearName.c_str(), varName.c_str(), locName.c_str()); __spf_print(1, "%s (%s %s) %s\n", func->symbol()->identifier(), clearName.c_str(), varName.c_str(), locName.c_str());
findSymbol(func, varName, locName, altNames);
printInternalError(convertFileName(__FILE__).c_str(), __LINE__); printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
} }

View File

@@ -184,20 +184,8 @@ R182 = "Редукционная операция по элементу масс
R183 = "Расположение операторов FORMAT не поддерживается, попробуйте применить проход Коррекция стиля кода". R183 = "Расположение операторов FORMAT не поддерживается, попробуйте применить проход Коррекция стиля кода".
//1061 //1061
R184 = "Область объявления массива '%s' конфликтует с предыдущей областью. Возможно, это вызвано использованием include-файлов. Попробуйте применить проход 'Подстановка заголовочных файлов'". R184 = "Область объявления массива '%s' конфликтует с предыдущей областью. Возможно, это вызвано использованием include-файлов. Попробуйте применить проход 'Подстановка заголовочных файлов'".
//1062 //1042
R205 = "Массив '%s' состоящий в common блоке '%s' должен иметь описание в главной программной единице для объявления в директиве DECLARE" R205 = "Массив '%s' состоящий в common блоке '%s' должен иметь описание в главной программной единице для объявления в директиве DECLARE"
//1063
R206 = "Ошибка инициализации библиотеки libpredict с конфигурацией кластера: %s, код возврата: %d"
//1064
R207 = "Ошибка инициализации сетки libpredict с топологией: %zu %zu %zu %zu, код возврата: %d"
//1065
R208 = "Ошибка распределения массива '%s' с помощью libpredict, код возврата: %d"
//1066
R209 = "Ошибка выравнивания массива '%s' с массивом '%s' с помощью libpredict, код возврата: %d"
//1067
R210 = "Ошибка обработки shadow_renew для массива '%s' с помощью libpredict, код возврата: %d"
//1068
R211 = "Ошибка инициализации отображения libpredict с processes_per_processor: %zu, код возврата: %d"
//2001 //2001
R94 = "Невозможно автоматически преобразовать данное присваивание к циклу" R94 = "Невозможно автоматически преобразовать данное присваивание к циклу"

View File

@@ -569,8 +569,8 @@ void copyIncludes(const set<string> &allIncludeFiles, const map<string, map<int,
while (!feof(oldFile)) while (!feof(oldFile))
{ {
char buf[16384]; char buf[8192];
char *res = fgets(buf, sizeof(buf), oldFile); char *res = fgets(buf, 16384, oldFile);
if (res == NULL) if (res == NULL)
break; break;

View File

@@ -1,3 +1,3 @@
#pragma once #pragma once
#define VERSION_SPF "2465" #define VERSION_SPF "2453"

View File

@@ -152,7 +152,7 @@ static void setOptions(const short* options, bool isBuildParallel = false, const
intOptions[z] = -1; intOptions[z] = -1;
} }
//staticShadowAnalysis = intOptions[STATIC_SHADOW_ANALYSIS]; staticShadowAnalysis = intOptions[STATIC_SHADOW_ANALYSIS];
staticPrivateAnalysis = intOptions[STATIC_PRIVATE_ANALYSIS]; staticPrivateAnalysis = intOptions[STATIC_PRIVATE_ANALYSIS];
out_free_form = intOptions[FREE_FORM]; out_free_form = intOptions[FREE_FORM];
if (out_free_form == 1) if (out_free_form == 1)
@@ -950,7 +950,7 @@ int SPF_ModifyArrayDistribution(void*& context, int winHandler, short *options,
extern map<string, PredictorStats> allPredictorStats; extern map<string, PredictorStats> allPredictorStats;
extern map<string, vector<SpfInterval*>> intervals; extern map<string, vector<SpfInterval*>> intervals;
extern vector<vector<size_t>> topologies; extern vector<vector<long>> topologies;
int SPF_CreateParallelVariant(void*& context, int winHandler, short *options, short *projName, short *folderName, int64_t *variants, int *varLen, int SPF_CreateParallelVariant(void*& context, int winHandler, short *options, short *projName, short *folderName, int64_t *variants, int *varLen,
string &output, string &outputMessage, string &predictorStats) string &output, string &outputMessage, string &predictorStats)
@@ -1823,7 +1823,7 @@ static int inline runModificationPass(passes passName, short* projName, short* f
runPassesForVisualizer(projName, { passName }, folderName); runPassesForVisualizer(projName, { passName }, folderName);
//fill data //fill data
// newFiles: <<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD>, <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>> // newFiles: <èìåíà ôàéëîâ äëÿ ìîä, ñîäåðæèìîå ôàéëà>
string newFile; string newFile;
if (SgFile::switchToFile(outFileName.c_str()) == -1) if (SgFile::switchToFile(outFileName.c_str()) == -1)
@@ -2392,7 +2392,7 @@ const wstring Sapfor_RunAnalysis(const char* analysisName_c, const char* options
retCode = SPF_GetArrayLinks(context, winHandler, optSh, projSh, result, output, outputMessage); retCode = SPF_GetArrayLinks(context, winHandler, optSh, projSh, result, output, outputMessage);
else if (whichRun == "SPF_GetMaxMinBlockDistribution") else if (whichRun == "SPF_GetMaxMinBlockDistribution")
retCode = SPF_GetMaxMinBlockDistribution(context, winHandler, optSh, projSh, result, output, outputMessage); retCode = SPF_GetMaxMinBlockDistribution(context, winHandler, optSh, projSh, result, output, outputMessage);
else if (whichRun == "SPF_<EFBFBD>hangeDirectory") // russian C else if (whichRun == "SPF_ÑhangeDirectory") // russian C
{ {
if (options_c == NULL) if (options_c == NULL)
printInternalError(convertFileName(__FILE__).c_str(), __LINE__); printInternalError(convertFileName(__FILE__).c_str(), __LINE__);