refactored transformation: added folders for each transformation

This commit is contained in:
ALEXks
2025-06-02 19:08:09 +03:00
parent 8161609173
commit a0a401c42a
102 changed files with 189 additions and 188 deletions

View File

@@ -1,4 +1,4 @@
#include "../Utils/leak_detector.h"
#include "leak_detector.h"
#include <vector>
#include <string>
@@ -6,7 +6,7 @@
#include "../Utils/SgUtils.h"
#include "../Utils/utils.h"
#include "../ExpressionTransform/expr_transform.h"
#include "expr_transform.h"
#include "checkpoints.h"

View File

@@ -1,4 +1,4 @@
#include "../Utils/leak_detector.h"
#include "leak_detector.h"
#include <cstdio>
#include <cstring>

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,128 @@
#pragma once
#include <map>
#include <set>
#include <string>
#include "dvm.h"
#include "../Distribution/Distribution.h"
#include "../GraphLoop/graph_loops.h"
#include "../ParallelizationRegions/ParRegions.h"
#include "graph_calls.h"
#include "../Utils/SgUtils.h"
#include "acc_analyzer.h"
struct VariableItem;
class VarsKeeper;
class DataFlowItem;
SgExpression* ReplaceParameter_(SgExpression* e);
SgExpression* ReplaceArrayBoundSizes(SgExpression *edim);
SgExpression* ReplaceConstant(SgExpression *e);
void getCoefsOfSubscript(std::pair<int, int> &retCoefs, SgExpression *exp, SgSymbol *doName);
void createLinksToCopy(SgExpression* exOrig, SgExpression* exCopy);
int CalculateInteger(SgExpression *expr, int &result);
SgExpression* CalculateInteger(SgExpression *expr);
void expressionAnalyzer(SgFile *file,
const std::map<std::string, std::vector<DefUseList>> &defUseByFunctions,
const std::map<std::string, CommonBlock*> &commonBlocks,
const std::map<std::string, std::vector<FuncInfo*>> &allFuncInfo,
const std::vector<ParallelRegion*> &regions);
bool calculate(SgExpression *&exp);
bool replaceConstantRec(SgExpression *&exp);
enum REPLACE_PTR_TYPE { SG_EXPRESSION, SG_STATEMENT };
void revertReplacements(const std::string &filename, bool back = false);
struct GraphItem {
GraphItem(): CGraph(NULL), file_id(-1), calls(CallData()), commons(CommonData()), dldl(DoLoopDataList()), privateDone(false) {}
int file_id;
ControlFlowGraph* CGraph;
CallData calls;
CommonData commons;
DoLoopDataList dldl;
bool privateDone;
~GraphItem() { if(CGraph) delete CGraph; }
};
class GraphsKeeper {
private:
std::map<SgStatement*, GraphItem*> graphs;
GraphsKeeper(): graphs(std::map<SgStatement*, GraphItem*>()) {}
public:
static GraphsKeeper* getGraphsKeeper();
static void deleteGraphsKeeper();
~GraphsKeeper()
{
for (auto &it : graphs)
if (it.second)
{
delete it.second;
it.second = NULL;
}
graphs.clear();
}
GraphItem* buildGraph(SgStatement* st);
GraphItem* getGraph(SgStatement *header);
CBasicBlock* findBlock(SgStatement* stmt);
};
struct FuncCallSE
{
std::string funcName;
std::set<std::string> calls;
FuncCallSE(std::string &n, std::set<std::string>& v) : funcName(n), calls(v) {}
};
class CommonVarsOverseer
{
private:
bool inited;
public:
std::map<std::string, std::set<SgSymbol*>> funcKillsVars;
CommonVarsOverseer() : inited(false), funcKillsVars(std::map<std::string, std::set<SgSymbol*>>()) {}
bool isInited() { return inited; }
void riseInited() { inited = true; }
void addKilledVar(SgSymbol* symbol, const std::string &funcName)
{
auto founded = funcKillsVars.find(funcName);
if (founded == funcKillsVars.end())
funcKillsVars.insert(founded, std::make_pair(funcName, std::set<SgSymbol*>()))->second.insert(symbol);
else
founded->second.insert(symbol);
}
std::set<SgSymbol*>* killedVars(const std::string &funcName)
{
auto founded = funcKillsVars.find(funcName);
if (founded == funcKillsVars.end())
return NULL;
return &(founded->second);
}
};
std::map<SgStatement*, std::pair<std::set<SgStatement*>, std::set<SgStatement*>>> buildRequireReachMapForLoop(SgStatement *since, SgStatement *till, std::set<std::string> &privates);
const std::map<SymbolKey, std::set<ExpressionValue*>> getReachingDefinitionsExt(SgStatement* stmt);
void FillCFGInsAndOutsDefs(ControlFlowGraph*, std::map<SymbolKey, std::set<ExpressionValue*>> *inDefs, CommonVarsOverseer *overseer_Ptr);
void CorrectInDefs(ControlFlowGraph*);
void ClearCFGInsAndOutsDefs(ControlFlowGraph*);
bool valueWithRecursion(const SymbolKey&, SgExpression*);
bool valueWithFunctionCall(SgExpression*);
bool valueWithArrayReference(SgExpression *exp, SgStatement* from);
bool argIsReplaceable(int i, AnalysedCallsList* callData);
bool argIsUsed(int i, AnalysedCallsList* callData);
bool symbolInExpression(const SymbolKey &symbol, SgExpression *exp);
void showDefs(std::map<SymbolKey, std::set<ExpressionValue>> *defs);
void showDefs(std::map<SymbolKey, SgExpression*> *defs);
void showDefsOfGraph(ControlFlowGraph *CGraph);
void debugStructure(ControlFlowGraph *CGraph, const std::string &filename);
bool findCFIsForStmt(SgStatement *st, std::vector <ControlFlowItem*> &cfis);
std::map<SymbolKey, std::set<ExpressionValue*>> createHeaderInDefs(SgStatement *header);
ControlFlowGraph* BuildUnfilteredReachingDefinitionsFor(SgStatement *header);
void runPrivateAnalysis(SgStatement *main);
SgStatement* findReplacedExpression(SgExpression* ex);

View File

@@ -1,4 +1,4 @@
#include "../Utils/leak_detector.h"
#include "leak_detector.h"
#include <cstdio>
#include <cstring>
@@ -16,9 +16,9 @@
#include "../Utils/SgUtils.h"
#include "uniq_call_chain_dup.h"
#include "../GraphCall/graph_calls.h"
#include "graph_calls.h"
#include "../GraphCall/graph_calls_func.h"
#include "../ExpressionTransform/expr_transform.h"
#include "expr_transform.h"
#include "../VerificationCode/verifications.h"
using namespace std;

View File

@@ -1,6 +1,6 @@
#pragma once
#include "../GraphCall/graph_calls.h"
#include "graph_calls.h"
#include <map>
#include <string>
#include <vector>

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,12 @@
#pragma once
#include <set>
#include <vector>
#include <map>
#include <string>
void callInliner(const std::map<std::string, std::vector<FuncInfo*>>& allFuncInfo,
std::vector<std::tuple<std::string, std::string, int>>& inDataProc,
std::map<std::string, std::set<std::pair<std::string, int>>>& inDataChains,
const std::set<std::string>& inDataChainsStart,
std::map<std::string, std::vector<Messages>>& SPF_messages,
const std::map<std::string, CommonBlock*>& commonBlocks);

View File

@@ -1,4 +1,4 @@
#include "../Utils/leak_detector.h"
#include "leak_detector.h"
#include <cstdio>
#include <cstdlib>
@@ -15,7 +15,7 @@
#include "../Utils/SgUtils.h"
#include "../Utils/CommonBlock.h"
#include "../Utils/DefUseList.h"
#include "ExpressionTransform/expr_transform.h"
#include "expr_transform.h"
#include "../VerificationCode/verifications.h"
#include "../DvmhRegions/DvmhRegionInserter.h"
#include "function_purifying.h"

View File

@@ -11,7 +11,7 @@
#include "../Utils/SgUtils.h"
#include "../LoopAnalyzer/loop_analyzer.h"
#include "../ExpressionTransform/expr_transform.h"
#include "expr_transform.h"
struct DeclInfo // for error messages

View File

@@ -1,7 +1,7 @@
#include "loops_combiner.h"
#include "../LoopAnalyzer/loop_analyzer.h"
#include "../ExpressionTransform/expr_transform.h"
#include "expr_transform.h"
#include "../Utils/errors.h"
#include "../Utils/SgUtils.h"
#include <string>

View File

@@ -1,4 +1,4 @@
#include "../Utils/leak_detector.h"
#include "leak_detector.h"
#include <cstdio>
#include <cstring>

View File

@@ -1,4 +1,4 @@
#include "../Utils/leak_detector.h"
#include "leak_detector.h"
#include <vector>
#include <string>

View File

@@ -4,7 +4,7 @@
#include <vector>
#include "../LoopAnalyzer/loop_analyzer.h"
#include "../ExpressionTransform/expr_transform.h"
#include "expr_transform.h"
#include "../Utils/errors.h"
#include "../CFGraph/CFGraph.h"
#include "../SageAnalysisTool/OmegaForSage/include/lang-interf.h"

View File

@@ -3,8 +3,8 @@
#include "../Utils/errors.h"
#include "../Utils/SgUtils.h"
#include "../Utils/utils.h"
#include "../ExpressionTransform/expr_transform.h"
#include "dead_code.h"
#include "expr_transform.h"
#include "../DeadCodeRemoving/dead_code.h"
using std::make_pair;
using std::map;

View File

@@ -0,0 +1,168 @@
#include <string>
#include <set>
#include <map>
#include <vector>
#include "Utils/SgUtils.h"
#include "rename_symbols.h"
using std::vector;
using std::map;
using std::multimap;
using std::set;
using std::make_pair;
using std::string;
using std::to_string;
static set<string> allNames;
static map<SgSymbol*, set<SgSymbol*>> usesByModSym;
static multimap<string, SgSymbol*> saves; //for saves
static multimap<string, SgSymbol*> params; //for params
inline static string generateUnique(const set<string> &banned, const string &old) {
static int counter = 0;
string new_name = old + "_" + to_string(++counter);
while (banned.count(new_name))
new_name = old + "_" + to_string(++counter);
return new_name;
}
inline static void renameUnique(SgSymbol* s, const set<string>& banned = allNames) {
string new_name = generateUnique(banned, s->identifier());
allNames.insert(new_name);
SgSymbol* orig = OriginalSymbol(s);
orig->changeName(new_name.c_str());
if (usesByModSym.count(orig))
for (auto& e : usesByModSym[orig])
e->changeName(new_name.c_str());
}
static void addToScope(SgSymbol* s, SgProject* project) {
if (isSgVariableSymb(s) || isSgConstantSymb(s)) {
SgSymbol* orig_mod = OriginalSymbol(s);
if (orig_mod != s) {
usesByModSym[orig_mod].insert(s);
return;
}
if (s->scope() && s->scope()->variant() == MODULE_STMT)
usesByModSym[s];
if (s->attributes() & SAVE_BIT)
saves.insert(make_pair(s->identifier(), s));
if (s->attributes() & PARAMETER_BIT)
params.insert(make_pair(s->identifier(), s));
}
}
void runRenameSymbolsByFiles(SgFile* file, SgProject* project) {
for (SgSymbol* s = file->firstSymbol(); s; s = s->next()) {
allNames.insert(s->identifier());
if (s->variant() == VARIABLE_NAME || isSgConstantSymb(s))
addToScope(s, project);
}
}
void runRenameSymbols(SgProject* project, const map<string, CommonBlock*> &commonBlocks) {
int n = project->numberOfFiles();
for (int i = 0; i < n; i++) {
SgFile* f = &(project->file(i));
for (SgSymbol* s = f->firstSymbol(); s; s = s->next()) {
if (s->variant() == VARIABLE_NAME || isSgConstantSymb(s)) {
string name = s->identifier();
SgSymbol* orig = OriginalSymbol(s);
bool is_mod_sym = (usesByModSym.find(orig) != usesByModSym.end());
auto is_mod_iter = std::find_if(usesByModSym.begin(),
usesByModSym.end(),
[&name, orig](const std::pair<SgSymbol*, set<SgSymbol*>> &p) {
return (name == p.first->identifier()) && (p.first != orig);
});
bool intersect_with_mod = (is_mod_iter != usesByModSym.end());
//fix intersects with MODULE symbols
if (intersect_with_mod) {
renameUnique(s);
continue;
}
if (is_mod_sym)
continue;
//fix intersects inside SAVE variables
if ((s->attributes() & SAVE_BIT) ? saves.count(name) > 1 : saves.count(name)) {
renameUnique(s);
name = s->identifier();
if (s->attributes() & SAVE_BIT) {
saves.erase(find_if(saves.begin(),
saves.end(),
[&s](const std::pair<string, SgSymbol*>& p) {
return p.second == s;
}));
saves.insert(make_pair(name, s));
}
continue;
}
//fix intersects inside PARAMETER variables
if ((s->attributes() & PARAMETER_BIT) ? params.count(name) > 1 : params.count(name)) {
SgConstantSymb* cSym;
bool need_to_rename = false;
if (cSym = isSgConstantSymb(s)) {
string val = cSym->constantValue()->unparse();
string const_name = cSym->identifier();
auto found = find_if(params.begin(),
params.end(),
[&const_name, &val, project, i](const std::pair<string, SgSymbol*>& p) {
SgConstantSymb* cmpSym = isSgConstantSymb(p.second);
project->file(cmpSym->getFileId());
string cmp_val = cmpSym->constantValue()->unparse();
project->file(i);
return (const_name == cmpSym->identifier()) && (cmp_val != val);
});
need_to_rename = (found != params.end());
} else
need_to_rename = true;
if (need_to_rename) {
renameUnique(s);
name = s->identifier();
if (s->attributes() & PARAMETER_BIT) {
params.erase(find_if(params.begin(),
params.end(),
[&s](const std::pair<string, SgSymbol*>& p) {
return p.second == s;
}));
params.insert(make_pair(name, s));
}
}
}
}
}
}
for (auto& e : commonBlocks) {
const CommonBlock& block = *e.second;
for (auto& grouped : block.getGroupedVars()) {
const vector<Variable*>& vars = grouped.second;
string new_name = generateUnique(allNames, vars[0]->getName());
for (auto& var : vars)
for (auto& varUse : var->getAllUse())
varUse.getUseS()->changeName(new_name.c_str());
}
}
}

View File

@@ -0,0 +1,9 @@
#pragma once
#include "Utils/SgUtils.h"
#include "string"
#include "map"
void runRenameSymbolsByFiles(SgFile* file, SgProject* project);
void runRenameSymbols(SgProject* project, const std::map<std::string, CommonBlock*>& commonBlocks);

View File

@@ -1,11 +1,11 @@
#include "replace_dist_arrays_in_io.h"
#include "../ParallelizationRegions/resolve_par_reg_conflicts.h"
#include <string>
#include <map>
#include <set>
#include <ExpressionTransform/expr_transform.h>
#include "expr_transform.h"
#include "../ParallelizationRegions/resolve_par_reg_conflicts.h"
using std::map;
using std::set;

View File

@@ -3,7 +3,7 @@
#include "../ParallelizationRegions/ParRegions.h"
#include "../Utils/SgUtils.h"
#include "../Utils/errors.h"
#include "../GraphCall/graph_calls.h"
#include "graph_calls.h"
void replaceDistributedArraysInIO(std::vector<ParallelRegion*>& regions,
const std::map<std::string, std::vector<FuncInfo*>>& allFuncInfo,

View File

@@ -1,4 +1,4 @@
#include "../Utils/leak_detector.h"
#include "leak_detector.h"
#include <string>
#include <map>

View File

@@ -1,4 +1,4 @@
#include "../Utils/leak_detector.h"
#include "leak_detector.h"
#include <cstdio>
#include <cstring>
@@ -14,7 +14,7 @@
#include "../ParallelizationRegions/ParRegions.h"
#include "array_assign_to_loop.h"
#include "../Utils/SgUtils.h"
#include "../ExpressionTransform/expr_transform.h"
#include "expr_transform.h"
#include "../GraphCall/graph_calls_func.h"
#include "../VerificationCode/verifications.h"