WIP: merge with master

This commit is contained in:
2025-06-18 23:21:55 +03:00
158 changed files with 1739 additions and 843 deletions

View File

@@ -27,6 +27,13 @@ set(libpred_sources projects/libpredictor/src/)
set(libpred_include projects/libpredictor/include/)
include_directories(src)
include_directories(src/Utils)
include_directories(src/SgUtils)
include_directories(src/Distribution)
include_directories(src/GraphCall)
include_directories(src/GraphLoop)
include_directories(src/Transformations/ExpressionSubstitution)
#Sage lib includes
include_directories(${fdvm_include})
include_directories(${sage_include_1})
@@ -154,40 +161,47 @@ set(PARALLEL_REG src/ParallelizationRegions/ParRegions.cpp
src/ParallelizationRegions/resolve_par_reg_conflicts.cpp
src/ParallelizationRegions/resolve_par_reg_conflicts.h)
set(TR_DEAD_CODE src/Transformations/dead_code.cpp
src/Transformations/dead_code.h)
set(TR_CP src/Transformations/checkpoints.cpp
src/Transformations/checkpoints.h)
set(TR_VECTOR src/Transformations/array_assign_to_loop.cpp
src/Transformations/array_assign_to_loop.h)
set(TR_ENDDO_LOOP src/Transformations/enddo_loop_converter.cpp
src/Transformations/enddo_loop_converter.h)
set(TR_LOOP_NEST src/Transformations/loop_transform.cpp
src/Transformations/loop_transform.h)
set(TR_LOOP_COMB src/Transformations/loops_combiner.cpp
src/Transformations/loops_combiner.h)
set(TR_LOOP_SPLIT src/Transformations/loops_splitter.cpp
src/Transformations/loops_splitter.h)
set(TR_LOOP_UNROLL src/Transformations/loops_unrolling.cpp
src/Transformations/loops_unrolling.h)
set(TR_PRIV_BR src/Transformations/private_arrays_resizing.cpp
src/Transformations/private_arrays_resizing.h)
set(TR_PRIV_DEL src/Transformations/private_removing.cpp
src/Transformations/private_removing.h)
set(TR_SWAP_ARR_DIMS src/Transformations/swap_array_dims.cpp
src/Transformations/swap_array_dims.h)
set(TR_FUNC_DUP src/Transformations/uniq_call_chain_dup.cpp
src/Transformations/uniq_call_chain_dup.h)
set(TR_FUNC_PURE src/Transformations/function_purifying.cpp
src/Transformations/function_purifying.h)
set(TR_GV src/Transformations/fix_common_blocks.cpp
src/Transformations/fix_common_blocks.h)
set(TR_CONV src/Transformations/convert_to_c.cpp
src/Transformations/convert_to_c.h)
set(TR_IMPLICIT_NONE src/Transformations/set_implicit_none.cpp
src/Transformations/set_implicit_none.h)
set(TR_REPLACE_ARRAYS_IN_IO src/Transformations/replace_dist_arrays_in_io.cpp
src/Transformations/replace_dist_arrays_in_io.h)
set(TR_DEAD_CODE src/Transformations/DeadCodeRemoving/dead_code.cpp
src/Transformations/DeadCodeRemoving/dead_code.h)
set(TR_CP src/Transformations/CheckPoints/checkpoints.cpp
src/Transformations/CheckPoints/checkpoints.h)
set(TR_VECTOR src/Transformations/VectorAssignToLoop/array_assign_to_loop.cpp
src/Transformations/VectorAssignToLoop/array_assign_to_loop.h)
set(TR_ENDDO_LOOP src/Transformations/LoopEndDoConverter/enddo_loop_converter.cpp
src/Transformations/LoopEndDoConverter/enddo_loop_converter.h)
set(TR_LOOP_NEST src/Transformations/LoopNesting/loop_transform.cpp
src/Transformations/LoopNesting/loop_transform.h)
set(TR_LOOP_COMB src/Transformations/LoopCombining/loops_combiner.cpp
src/Transformations/LoopCombining/loops_combiner.h)
set(TR_LOOP_SPLIT src/Transformations/LoopSplitting/loops_splitter.cpp
src/Transformations/LoopSplitting/loops_splitter.h)
set(TR_LOOP_UNROLL src/Transformations/LoopUnrolling/loops_unrolling.cpp
src/Transformations/LoopUnrolling/loops_unrolling.h)
set(TR_PRIV_BR src/Transformations/PrivateArrayResizing/private_arrays_resizing.cpp
src/Transformations/PrivateArrayResizing/private_arrays_resizing.h)
set(TR_PRIV_DEL src/Transformations/PrivateArrayRemoving/private_removing.cpp
src/Transformations/PrivateArrayRemoving/private_removing.h)
set(TR_SWAP_ARR_DIMS src/Transformations/ArrayDimsSwapping/swap_array_dims.cpp
src/Transformations/ArrayDimsSwapping/swap_array_dims.h)
set(TR_FUNC_DUP src/Transformations/FunctionDuplication/uniq_call_chain_dup.cpp
src/Transformations/FunctionDuplication/uniq_call_chain_dup.h)
set(TR_FUNC_PURE src/Transformations/FunctionPurifying/function_purifying.cpp
src/Transformations/FunctionPurifying/function_purifying.h)
set(TR_GV src/Transformations/GlobalVariables/fix_common_blocks.cpp
src/Transformations/GlobalVariables/fix_common_blocks.h)
set(TR_CONV src/Transformations/ConvertToC/convert_to_c.cpp
src/Transformations/ConvertToC/convert_to_c.h)
set(TR_IMPLICIT_NONE src/Transformations/SetImplicitNone/set_implicit_none.cpp
src/Transformations/SetImplicitNone/set_implicit_none.h)
set(TR_REPLACE_ARRAYS_IN_IO src/Transformations/ReplaceArraysInIO/replace_dist_arrays_in_io.cpp
src/Transformations/ReplaceArraysInIO/replace_dist_arrays_in_io.h)
set(TR_EXPR_TRANSFORM src/Transformations/ExpressionSubstitution/control_flow_graph_part.cpp
src/Transformations/ExpressionSubstitution/expr_transform.cpp
src/Transformations/ExpressionSubstitution/expr_transform.h)
set(TR_INLINER src/Transformations/FunctionInlining/inliner.cpp
src/Transformations/FunctionInlining/inliner.h)
set(TR_RENAME_SYMBOLS src/Transformations/RenameSymbols/rename_symbols.cpp
src/Transformations/RenameSymbols/rename_symbols.h)
set(TRANSFORMS
${TR_DEAD_CODE}
@@ -207,10 +221,15 @@ set(TRANSFORMS
${TR_CONV}
${TR_PRIV_DEL}
${TR_IMPLICIT_NONE}
${TR_REPLACE_ARRAYS_IN_IO})
${TR_REPLACE_ARRAYS_IN_IO}
${TR_EXPR_TRANSFORM}
${TR_INLINER}
${TR_RENAME_SYMBOLS})
set(CFG src/CFGraph/IR.cpp
src/CFGraph/IR.h
src/CFGraph/IR_domTree.cpp
src/CFGraph/IR_domTree.h
src/CFGraph/CFGraph.cpp
src/CFGraph/CFGraph.h
src/CFGraph/RD_subst.cpp
@@ -288,10 +307,6 @@ set(DYNA src/DynamicAnalysis/createParallelRegions.cpp
src/DynamicAnalysis/gcov_info.h
src/DynamicAnalysis/gCov_parser.cpp
src/DynamicAnalysis/gCov_parser_func.h)
set(EXPR_TRANSFORM src/ExpressionTransform/control_flow_graph_part.cpp
src/ExpressionTransform/expr_transform.cpp
src/ExpressionTransform/expr_transform.h)
set(GR_CALL src/GraphCall/graph_calls.cpp
src/GraphCall/graph_calls.h
@@ -303,9 +318,6 @@ set(GR_LOOP src/GraphLoop/graph_loops_base.cpp
src/GraphLoop/graph_loops.h
src/GraphLoop/graph_loops_func.h)
set(INLINER src/Inliner/inliner.cpp
src/Inliner/inliner.h)
set(LOOP_ANALYZER src/LoopAnalyzer/allocations_prepoc.cpp
src/LoopAnalyzer/dep_analyzer.cpp
src/LoopAnalyzer/loop_analyzer.cpp
@@ -313,10 +325,6 @@ set(LOOP_ANALYZER src/LoopAnalyzer/allocations_prepoc.cpp
src/LoopAnalyzer/implicit_loops_analyzer.cpp
src/LoopAnalyzer/implicit_loops_analyzer.h)
set(RENAME_SYMBOLS src/RenameSymbols/rename_symbols.cpp
src/RenameSymbols/rename_symbols.h)
set(MAIN src/Sapfor.cpp
src/Sapfor.h
src/SapforData.h
@@ -406,12 +414,9 @@ set(SOURCE_EXE
${DISTR}
${DVMH_REG}
${DYNA}
${EXPR_TRANSFORM}
${GR_CALL}
${GR_LOOP}
${INLINER}
${LOOP_ANALYZER}
${RENAME_SYMBOLS}
${TRANSFORMS}
${PARALLEL_REG}
${PRIV}
@@ -435,7 +440,7 @@ source_group (CFGraph FILES ${CFG})
source_group (CFGraph\\DataFlow FILES ${DATA_FLOW})
source_group (Transformations\\DeadCodeRemoving FILES ${TR_DEAD_CODE})
source_group (Transformations\\ExpressionSubstitution FILES ${EXPR_TRANSFORM})
source_group (Transformations\\ExpressionSubstitution FILES ${TR_EXPR_TRANSFORM})
source_group (Transformations\\CheckPoints FILES ${TR_CP})
source_group (Transformations\\LoopEndDoConverter FILES ${TR_ENDDO_LOOP})
source_group (Transformations\\LoopNesting FILES ${TR_LOOP_NEST})
@@ -443,13 +448,13 @@ source_group (Transformations\\LoopCombining FILES ${TR_LOOP_COMB})
source_group (Transformations\\LoopSplitting FILES ${TR_LOOP_SPLIT})
source_group (Transformations\\LoopUnrolling FILES ${TR_LOOP_UNROLL})
source_group (Transformations\\FunctionDuplication FILES ${TR_FUNC_DUP})
source_group (Transformations\\FunctionInlining FILES ${INLINER})
source_group (Transformations\\FunctionInlining FILES ${TR_INLINER})
source_group (Transformations\\FunctionPurifying FILES ${TR_FUNC_PURE})
source_group (Transformations\\ArrayDimsSwapping FILES ${TR_SWAP_ARR_DIMS})
source_group (Transformations\\PrivateArrayResizing FILES ${TR_PRIV_BR})
source_group (Transformations\\PrivateArrayRemoving FILES ${TR_PRIV_DEL})
source_group (Transformations\\VectorAssignToLoop FILES ${TR_VECTOR})
source_group (Transformations\\RenameSymbols FILES ${RENAME_SYMBOLS})
source_group (Transformations\\RenameSymbols FILES ${TR_RENAME_SYMBOLS})
source_group (Transformations\\GlobalVariables FILES ${TR_GV})
source_group (Transformations\\ConvertToC FILES ${TR_CONV})
source_group (Transformations\\SetImplicitNone FILES ${TR_IMPLICIT_NONE})

View File

@@ -1,5 +1,5 @@
#define _LEAK_
#include "../Utils/leak_detector.h"
#include "leak_detector.h"
#include <stdlib.h>
#include <stdio.h>
@@ -8,9 +8,9 @@
#include <chrono>
#include <functional>
#include "../Utils/SgUtils.h"
#include "../Utils/CommonBlock.h"
#include "../GraphCall/graph_calls.h"
#include "SgUtils.h"
#include "CommonBlock.h"
#include "graph_calls.h"
#include "dvm.h"
#include "IR.h"
@@ -1167,6 +1167,16 @@ map<FuncInfo*, vector<BBlock*>> buildCFG(const map<string, CommonBlock*>& common
if (settings.withRD)
buildReachingDefs(result, settings);
if (settings.withDominators)
{
auto t = high_resolution_clock::now();
for (auto& [func, bblocks] : result)
SAPFOR::buildDominatorTree(bblocks);
auto msec = duration_cast<milliseconds>(high_resolution_clock::now() - t).count();
__spf_print(1, " dominator build time is %.3f sec\n", msec / 1000.);
}
if (SgFile::switchToFile(oldFile) == -1)
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);

View File

@@ -10,6 +10,7 @@
#include "../Utils/utils.h"
#include "../Utils/CommonBlock.h"
#include "../GraphCall/graph_calls.h"
#include "IR_domTree.h"
namespace SAPFOR
{
@@ -28,7 +29,7 @@ namespace SAPFOR
std::vector<BasicBlock*> next;
std::vector<BasicBlock*> prev;
BasicBlock* directDominator = NULL;
//reaching definition
std::map<SAPFOR::Argument*, std::set<int>> RD_in, RD_out;
@@ -38,6 +39,7 @@ namespace SAPFOR
bool addLive(const std::map<SAPFOR::Argument*, std::vector<SAPFOR::BasicBlock*>>& to_add, bool in);
std::map<SAPFOR::Argument*, std::vector<SAPFOR::BasicBlock*>> getLive(bool in) const;
bool removeLive(SAPFOR::Argument* to_remove, bool in);
public:
BasicBlock() { num = lastNumBlock++; }
BasicBlock(IR_Block* item);
@@ -47,6 +49,7 @@ namespace SAPFOR
void addInstruction(IR_Block* item, bool pushFront = false);
void addPrev(BasicBlock* prev_) { prev.push_back(prev_); }
void addNext(BasicBlock* next_) { next.push_back(next_); }
void setDom(BasicBlock* dom) { directDominator = dom; }
int removePrev(BasicBlock* removed);
int removeNext(BasicBlock* removed);
@@ -74,7 +77,11 @@ namespace SAPFOR
const std::vector<IR_Block*>& getInstructions() const { return instructions; }
const std::vector<BasicBlock*>& getNext() const { return next; }
const std::vector<BasicBlock*>& getPrev() const { return prev; }
BasicBlock* getDom() const
{
return directDominator;
}
/*
* FOR LIVE ANALYSIS
*/
@@ -110,13 +117,15 @@ namespace SAPFOR
bool withDVM = false;
bool withCallsInBlocks = false; // separate each F_CALL to own BasicBlock
bool withCallFrom = true;
bool withDominators = true;
explicit CFG_Settings(int) { }
explicit CFG_Settings(bool atLeastOneIterInLoop = false, bool withRD = true, bool withRegisters = false,
bool withDVM = false, bool withSPF = false, bool withCallsInBlocks = false, bool withCallFrom = true) :
bool withDVM = false, bool withSPF = false, bool withCallsInBlocks = false,
bool withCallFrom = true, bool withDominators = true) :
atLeastOneIterInLoop(atLeastOneIterInLoop), withRD(withRD), withRegisters(withRegisters), withDVM(withDVM), withSPF(withSPF),
withCallsInBlocks(withCallsInBlocks), withCallFrom(withCallFrom)
withCallsInBlocks(withCallsInBlocks), withCallFrom(withCallFrom), withDominators(withDominators)
{ }
};
}
@@ -151,4 +160,4 @@ static inline void deleteCFG(std::map<FuncInfo*, std::vector<SAPFOR::BasicBlock*
byFunc.second.clear();
}
cfg.clear();
}
}

View File

@@ -5,7 +5,7 @@
#include <set>
#include <algorithm>
#include "../../Utils/SgUtils.h"
#include "SgUtils.h"
#include "../CFGraph.h"
#include "../IR.h"

View File

@@ -5,7 +5,7 @@
#include <set>
#include <algorithm>
#include "../../Utils/SgUtils.h"
#include "SgUtils.h"
#include "../CFGraph.h"
#include "../IR.h"
#include "../RD_subst.h"

View File

@@ -2,7 +2,7 @@
#include<vector>
#include<set>
#include "../../Utils/SgUtils.h"
#include "SgUtils.h"
#include "../CFGraph.h"
#include "../IR.h"

View File

@@ -4,7 +4,7 @@
#include<vector>
#include<set>
#include "../../Utils/SgUtils.h"
#include "SgUtils.h"
#include "../CFGraph.h"
#include "../IR.h"

View File

@@ -1,14 +1,14 @@
#include "../Utils/leak_detector.h"
#include "leak_detector.h"
#include <stdlib.h>
#include <stdio.h>
#include <vector>
#include <set>
#include "../Utils/SgUtils.h"
#include "../Utils/CommonBlock.h"
#include "../GraphCall/graph_calls.h"
#include "../ExpressionTransform/expr_transform.h"
#include "SgUtils.h"
#include "CommonBlock.h"
#include "graph_calls.h"
#include "expr_transform.h"
#include "dvm.h"
#include "IR.h"

View File

@@ -6,7 +6,7 @@
#include <algorithm>
#include "CFGraph.h"
#include "../Utils/CommonBlock.h"
#include "CommonBlock.h"
namespace SAPFOR
{
@@ -347,4 +347,4 @@ std::vector<SAPFOR::IR_Block*> buildIR(SgStatement* function, const FuncInfo* fu
SAPFOR::Instruction* getInstructionByNumber(const std::vector<SAPFOR::IR_Block*>& blocks, int num);
std::pair<SAPFOR::Instruction*, SAPFOR::BasicBlock*> getInstructionAndBlockByNumber(const std::map<FuncInfo*, std::vector<SAPFOR::BasicBlock*>>& CFGraph, int num);
std::pair<SAPFOR::Instruction*, SAPFOR::BasicBlock*> getInstructionAndBlockByStatement(const std::map<FuncInfo*, std::vector<SAPFOR::BasicBlock*>>& CFGraph, SgStatement* stmt);
int getParamIndex(SAPFOR::Argument* func_param, int max_index);
int getParamIndex(SAPFOR::Argument* func_param, int max_index);

View File

@@ -225,54 +225,52 @@ static BBlock* findImmediateDominatorsDfsHelper(BBlock* block, BBlock* currentBl
return NULL;
}
bool checkoDom(vector<BBlock*> a, vector<BBlock*> b, BBlock* c) {
if (a.size() != b.size() + 1) {
return false;
}
for (auto i : a)
{
if (i != c && find(b.begin(), b.end(), i) == b.end()) {
return false;
}
}
return true;
}
static map<BBlock*, BBlock*> findImmediateDominators1(const map<BBlock*, vector<BBlock*>>& dominators, BBlock* entry)
{
map<BBlock*, BBlock*> iDom;
for (const auto& pair : dominators)
{
for (const auto& pair : dominators) {
BBlock* b = pair.first;
if (b == entry)
continue;
if (b == entry) continue;
const auto& doms = pair.second;
BBlock* candidate = NULL;
for (auto& d : doms)
{
if (d == b)
continue;
// candidates = all dominators of b except itself
bool found = false;
for (auto& d : doms) {
if (d == b) continue;
bool isImmediate = true;
for (auto& other : doms)
{
if (other == b || other == d)
continue;
const auto& domsOfOther = dominators.at(other);
if (std::find(domsOfOther.begin(), domsOfOther.end(), d) != domsOfOther.end())
{
isImmediate = false;
break;
}
}
if (isImmediate)
{
candidate = d;
if (checkoDom(doms, dominators.at(d), b)) {
iDom[b] = d;
found = true;
break;
}
}
if (candidate)
iDom[b] = candidate;
if (!found) {
cout << "ERRORERRORERROR " << b->getNumber() << endl;
}
}
return iDom;
}
static map<BBlock*, BBlock*> findImmediateDominators(map<BBlock*, vector<BBlock*>>& dominators, BBlock* fistBlock)
{
map<BBlock*, BBlock*> iDominators;
@@ -483,6 +481,8 @@ static void renameFiFunctionArgsVar(BBlock* block, map<string, stack<BArgument*>
auto size = block->getInstructions().size();
auto& instructions = block->getInstructions();
//cout << "try to insert Phi to block - " << block->getNumber() << endl;
for (size_t i = 0; i < size; ++i)
{
auto irBlock = instructions[i];
@@ -491,6 +491,7 @@ static void renameFiFunctionArgsVar(BBlock* block, map<string, stack<BArgument*>
instruction->getArg1()->getValue() == "FI_FUNCTION" && instruction->getResult() != NULL &&
instruction->getArg2() != NULL)
{
//cout << "Insert Phi to block - " << block->getNumber() << endl;
Instruction* paramInstruction;
if (stack[instruction->getResult()->getValue()].size() > 0)
@@ -527,12 +528,14 @@ static vector<BBlock*> findBlocksWithValue(map<BBlock*, BBlock*>& iDominators, B
static void renameIR(BBlock* block, map<BBlock*, BBlock*>& iDominators, map<string, int>& counter, map<string, stack<BArgument*>>& stack) {
//cout << "renameIR for block " << block->getNumber() << endl;
renameFiFunctionResultVar(block, counter, stack);
renameInstructionVars(block, counter, stack);
for (auto& successor : block->getNext())
renameFiFunctionArgsVar(successor, stack);
for (auto& child : findBlocksWithValue(iDominators, block))
renameIR(child, iDominators, counter, stack);
@@ -558,22 +561,37 @@ static void renameIR(BBlock* block, map<BBlock*, BBlock*>& iDominators, map<stri
}
}
bool isEqual1(const char* cstr, const std::string& str) {
return str == cstr;
}
void buildIRSSAForm(const map<FuncInfo*, vector<BBlock*>>& fullIR,
map<FuncInfo*, vector<BBlock*>>& result) {
for (auto& [funcinfo, funcIRConst]: fullIR) {
if (isEqual1("csol.for", funcinfo->fileName) || isEqual1("reblns.for", funcinfo->fileName) || isEqual1("adjont.for", funcinfo->fileName)
|| isEqual1("beginf.for", funcinfo->fileName) || isEqual1("dsnp1.for", funcinfo->fileName) || isEqual1("dsnpnm.for", funcinfo->fileName)
|| isEqual1("decod3.for", funcinfo->fileName))
continue;
cout << "Testing " << funcinfo->funcName << endl;
vector<BBlock*> funcIR;
/* for (auto& i : funcIRConst) {
printBlock(i);
}*/
for (auto& i : funcIRConst)
funcIR.push_back(new BBlock(*i));
restoreConnections(funcIRConst, funcIR);
for (auto& i : funcIR) {
//printBlock(i);
}
/*for (auto& i : funcIR) {
printBlock(i);
}*/
for (auto& [func, bblocks] : result)
SAPFOR::buildDominatorTree(bblocks);
auto dominators = findDominators(funcIR);
/*cout << endl << endl << endl << "DOMINATORS" << endl << endl << endl;
@@ -640,11 +658,17 @@ void buildIRSSAForm(const map<FuncInfo*, vector<BBlock*>>& fullIR,
varStack[var->getValue()] = tmp;
}
/*for (auto& i : funcIR) {
printBlock(i);
}*/
renameIR(funcIR[0], iDominators, count, varStack);
for (auto& i : funcIR) {
//printBlock(i);
}
//cout << endl << endl << "___________________" << endl << endl;
/*for (auto& i : funcIR) {
printBlock(i);
}*/
//cout << endl << endl << endl << endl << endl;
//for (auto i : funcIRConst) {
// printBlock(i);

102
src/CFGraph/IR_domTree.cpp Normal file
View File

@@ -0,0 +1,102 @@
#include "dvm.h"
#include "IR_domTree.h"
namespace SAPFOR {
void DominatorFinder::DFS(BasicBlock* v, int parent_num) {
dfs_num[v] = n;
vertex[n] = n;
semi[n] = n;
label[n] = n;
ancestor[n] = -1;
parent[n] = parent_num;
vertices[n++] = v;
for (const auto& w : v->getNext()) {
if (dfs_num[w] == -1)
DFS(w, dfs_num[v]);
}
}
void DominatorFinder::Compress(int v) {
if (ancestor[ancestor[v]] != -1) {
Compress(ancestor[v]);
if (semi[label[ancestor[v]]] < semi[label[v]])
label[v] = label[ancestor[v]];
ancestor[v] = ancestor[ancestor[v]];
}
}
int DominatorFinder::Eval(int v) {
if (ancestor[v] == -1)
return v;
Compress(v);
return label[v];
}
void DominatorFinder::Link(int v, int w) {
ancestor[w] = v;
}
DominatorFinder::DominatorFinder(std::vector<BasicBlock*>& blocks) {
if (blocks.empty())
return;
entry = blocks[0];
n = 0;
for (auto block : blocks)
dfs_num[block] = -1;
int max_size = blocks.size();
vertices.resize(max_size);
parent.assign(max_size, -1);
semi.assign(max_size, -1);
vertex.assign(max_size, -1);
ancestor.assign(max_size, -1);
label.assign(max_size, -1);
bucket.resize(max_size);
DFS(entry, -1);
for (int i = n - 1; i > 0; --i) {
int w = vertex[i];
for (BasicBlock* v : vertices[w]->getPrev()) {
if (dfs_num[v] == -1)
continue;
int u = Eval(dfs_num[v]);
if (semi[u] < semi[w])
semi[w] = semi[u];
}
bucket[vertex[semi[w]]].push_back(w);
Link(parent[w], w);
for (int v : bucket[parent[w]])
{
int u = Eval(v);
if (semi[u] < semi[v])
vertices[v]->setDom(vertices[u]);
else
vertices[v]->setDom(vertices[parent[w]]);
}
bucket[parent[w]].clear();
}
for (int i = 1; i < n; ++i) {
int w = vertex[i];
if (vertices[w]->getDom() != vertices[vertex[semi[w]]])
vertices[w]->setDom(vertices[w]->getDom()->getDom());
}
entry->setDom(nullptr);
}
void buildDominatorTree(std::vector<BasicBlock*>& blocks) {
DominatorFinder finder(blocks);
}
}

35
src/CFGraph/IR_domTree.h Normal file
View File

@@ -0,0 +1,35 @@
#pragma once
#include <vector>
#include <map>
#include <unordered_map>
#include "CFGraph.h"
// Lengauer, Thomas. A fast algorithm for finding dominators in a flowgraph / Thomas Lengauer, Robert Endre Tarjan
// ACM Transactions on Programming Languages and Systems (TOPLAS). <20> 1979. <20> Vol. 1, no. 1. <20> Pp. 121<32>141.
namespace SAPFOR {
class BasicBlock;
class DominatorFinder {
private:
BasicBlock* entry;
std::vector<BasicBlock*> vertices;
std::unordered_map<BasicBlock*, int> dfs_num;
std::vector<int> parent, semi, vertex, ancestor, label;
std::vector<std::vector<int>> bucket;
int n;
void DFS(BasicBlock* v, int parent_num);
void Compress(int v);
int Eval(int v);
void Link(int v, int w);
public:
DominatorFinder(std::vector<BasicBlock*>& blocks);
};
void buildDominatorTree(std::vector<BasicBlock*>& blocks);
}

View File

@@ -8,10 +8,10 @@
#include <unordered_map>
#include <unordered_set>
#include "../Utils/SgUtils.h"
#include "../Utils/CommonBlock.h"
#include "../GraphCall/graph_calls.h"
#include "../ExpressionTransform/expr_transform.h"
#include "SgUtils.h"
#include "CommonBlock.h"
#include "graph_calls.h"
#include "expr_transform.h"
#define PRINT_PROF_INFO 0
#define DEBUG_CHECKS 0

View File

@@ -2,9 +2,9 @@
#include<unordered_map>
#include "../Utils/SgUtils.h"
#include "../Utils/CommonBlock.h"
#include "../GraphCall/graph_calls.h"
#include "SgUtils.h"
#include "CommonBlock.h"
#include "graph_calls.h"
#include "CFGraph.h"
#include "IR.h"

View File

@@ -1,6 +1,6 @@
#pragma once
#include "../Utils/SgUtils.h"
#include "SgUtils.h"
#include "CFGraph.h"
namespace LIVE_VARIABLES

View File

@@ -1,6 +1,6 @@
#include "../Utils/errors.h"
#include "errors.h"
#include "private_variables_analysis.h"
#include "../GraphLoop/graph_loops.h"
#include "graph_loops.h"
#include "../LoopAnalyzer/loop_analyzer.h"
#include "../SageAnalysisTool/depGraph.h"
#include "../DirectiveProcessing/directive_parser.h"

View File

@@ -1,5 +1,5 @@
#include "../Utils/SgUtils.h"
#include "../GraphLoop/graph_loops.h"
#include "SgUtils.h"
#include "graph_loops.h"
#include "CFGraph.h"
#include <string>

View File

@@ -1,7 +1,7 @@
#include "CreateInterTree.h"
#include "../Utils/SgUtils.h"
#include "../Utils/utils.h"
#include "../GraphCall/graph_calls_func.h"
#include "SgUtils.h"
#include "utils.h"
#include "graph_calls_func.h"
using std::string;
using std::wstring;

View File

@@ -8,7 +8,7 @@
#include "dvm.h"
#include "../GraphLoop/graph_loops_func.h"
#include "graph_loops_func.h"
struct SpfInterval
{

View File

@@ -1,4 +1,4 @@
#include "../Utils/leak_detector.h"
#include "leak_detector.h"
#include <cstdio>
#include <cstdlib>
@@ -16,9 +16,9 @@
#include <assert.h>
#include "../Distribution/DvmhDirective.h"
#include "../GraphLoop/graph_loops.h"
#include "graph_loops.h"
#include "directive_analyzer.h"
#include "../Utils/utils.h"
#include "utils.h"
using std::vector;
using std::map;

View File

@@ -1,6 +1,6 @@
#pragma once
#include <vector>
#include "../GraphLoop/graph_loops.h"
#include "graph_loops.h"
void UniteNestedDirectives(std::vector<LoopGraph*> &loopGraph);

View File

@@ -1,4 +1,4 @@
#include "../Utils/leak_detector.h"
#include "leak_detector.h"
#include <cstdio>
#include <cstdlib>
@@ -15,18 +15,18 @@
#include "../Distribution/Distribution.h"
#include "../Distribution/DvmhDirective_func.h"
#include "../Utils/errors.h"
#include "errors.h"
#include "../LoopAnalyzer/loop_analyzer.h"
#include "directive_parser.h"
#include "directive_creator.h"
#include "../Utils/SgUtils.h"
#include "SgUtils.h"
#include "../Sapfor.h"
#include "../GraphLoop/graph_loops_func.h"
#include "../Transformations/loop_transform.h"
#include "../ExpressionTransform/expr_transform.h"
#include "../GraphCall/graph_calls_func.h"
#include "graph_loops_func.h"
#include "../Transformations/LoopNesting/loop_transform.h"
#include "expr_transform.h"
#include "graph_calls_func.h"
#include "../Utils/AstWrapper.h"
#include "AstWrapper.h"
#define PRINT_DIR_RESULT 0

View File

@@ -1,9 +1,9 @@
#pragma once
#include "../Distribution/Distribution.h"
#include "../Utils/errors.h"
#include "../GraphLoop/graph_loops.h"
#include "../Utils/types.h"
#include "errors.h"
#include "graph_loops.h"
#include "types.h"
void createParallelDirectives(const std::map<LoopGraph*, std::map<DIST::Array*, ArrayInfo*>> &loopInfo,
const std::vector<ParallelRegion*>& regions,

View File

@@ -1,4 +1,4 @@
#include "../Utils/leak_detector.h"
#include "leak_detector.h"
#include <cstdio>
#include <cstdlib>
@@ -10,9 +10,9 @@
#include "../ParallelizationRegions/ParRegions.h"
#include "../Distribution/Arrays.h"
#include "../Transformations/loop_transform.h"
#include "../Transformations/LoopNesting/loop_transform.h"
#include "../Utils/errors.h"
#include "errors.h"
#include "directive_parser.h"
#include "directive_creator.h"

View File

@@ -1,4 +1,4 @@
#include "../Utils/leak_detector.h"
#include "leak_detector.h"
#include <cstdio>
#include <cstdlib>
@@ -9,7 +9,7 @@
#include "directive_omp_parser.h"
#include "directive_parser.h"
#include "../Utils/SgUtils.h"
#include "SgUtils.h"
using std::vector;
using std::map;

View File

@@ -4,7 +4,7 @@
#include <map>
#include <vector>
#include "../Utils/errors.h"
#include "errors.h"
#define SPF_USER_DIR 777
#define SPF_USER_DIR_COPY 999

View File

@@ -1,4 +1,4 @@
#include "../Utils/leak_detector.h"
#include "leak_detector.h"
#include <cstdio>
#include <cstring>
@@ -12,10 +12,10 @@
#include <assert.h>
#include "directive_parser.h"
#include "../Utils/SgUtils.h"
#include "SgUtils.h"
#include "../LoopAnalyzer/loop_analyzer.h"
#include "../Utils/AstWrapper.h"
#include "../Utils/errors.h"
#include "AstWrapper.h"
#include "errors.h"
using std::string;
using std::vector;

View File

@@ -4,8 +4,8 @@
#include <set>
#include <map>
#include "../Utils/AstWrapper.h"
#include "../GraphLoop/graph_loops.h"
#include "AstWrapper.h"
#include "graph_loops.h"
#include "../Distribution/DvmhDirective.h"
struct DvmDirective

View File

@@ -1,4 +1,4 @@
#include "../Utils/leak_detector.h"
#include "leak_detector.h"
#include <cstdio>
#include <cstdlib>
@@ -16,13 +16,13 @@
#include "../Distribution/Arrays.h"
#include "../Distribution/Distribution.h"
#include "../Distribution/DvmhDirective_func.h"
#include "../GraphLoop/graph_loops_func.h"
#include "../GraphCall/graph_calls_func.h"
#include "graph_loops_func.h"
#include "graph_calls_func.h"
#include "../Utils/errors.h"
#include "errors.h"
#include "../LoopAnalyzer/loop_analyzer.h"
#include "directive_parser.h"
#include "../Utils/SgUtils.h"
#include "SgUtils.h"
#include "../Sapfor.h"
#include "directive_creator.h"
#include "insert_directive.h"

View File

@@ -1,4 +1,4 @@
#include "../Utils/leak_detector.h"
#include "leak_detector.h"
#include <cstdio>
#include <cstdlib>
@@ -18,13 +18,13 @@
#include "dvm.h"
#include "../LoopAnalyzer/loop_analyzer.h"
#include "../Utils/types.h"
#include "../Utils/errors.h"
#include "../Utils/SgUtils.h"
#include "types.h"
#include "errors.h"
#include "SgUtils.h"
#include "../Distribution/Arrays.h"
#include "../GraphCall/graph_calls.h"
#include "../GraphCall/graph_calls_func.h"
#include "../GraphLoop/graph_loops_func.h"
#include "graph_calls.h"
#include "graph_calls_func.h"
#include "graph_loops_func.h"
#include "remote_access.h"
using std::vector;

View File

@@ -1,4 +1,4 @@
#include "../Utils/leak_detector.h"
#include "leak_detector.h"
#include <cstdio>
#include <cstdlib>
@@ -17,8 +17,8 @@
#include <assert.h>
#include "../Distribution/Arrays.h"
#include "../GraphCall/graph_calls.h"
#include "../GraphLoop/graph_loops.h"
#include "graph_calls.h"
#include "graph_loops.h"
#include "../ParallelizationRegions/ParRegions.h"
#include "remote_access.h"

View File

@@ -1,19 +1,19 @@
#include "../Utils/leak_detector.h"
#include "leak_detector.h"
#include <set>
#include <map>
#include <string>
#include <vector>
#include "../Utils/errors.h"
#include "../Utils/utils.h"
#include "../GraphLoop/graph_loops_func.h"
#include "../GraphCall/graph_calls.h"
#include "../GraphCall/graph_calls_func.h"
#include "errors.h"
#include "utils.h"
#include "graph_loops_func.h"
#include "graph_calls.h"
#include "graph_calls_func.h"
#include "directive_parser.h"
#include "../Distribution/DvmhDirective_func.h"
#include "../Utils/SgUtils.h"
#include "../ExpressionTransform/expr_transform.h"
#include "SgUtils.h"
#include "expr_transform.h"
#include "../CFGraph/CFGraph.h"

View File

@@ -1,4 +1,4 @@
#include "../Utils/leak_detector.h"
#include "leak_detector.h"
#include <cstdio>
#include <cstdlib>
@@ -12,13 +12,13 @@
#include "dvm.h"
#include "../Sapfor.h"
#include "../GraphLoop/graph_loops.h"
#include "../GraphCall/graph_calls_func.h"
#include "graph_loops.h"
#include "graph_calls_func.h"
#include "../SageAnalysisTool/depInterfaceExt.h"
#include "../Utils/SgUtils.h"
#include "../Utils/errors.h"
#include "SgUtils.h"
#include "errors.h"
#include "directive_parser.h"
#include "../ExpressionTransform/expr_transform.h"
#include "expr_transform.h"
#include "../LoopAnalyzer/loop_analyzer.h"
#include "../DirectiveProcessing/directive_omp_parser.h"

View File

@@ -1,7 +1,7 @@
#include "Array.h"
#include "../Utils/errors.h"
#include "../Utils/utils.h"
#include "../GraphCall/graph_calls.h"
#include "errors.h"
#include "utils.h"
#include "graph_calls.h"
using namespace std;

View File

@@ -7,9 +7,9 @@
#include <algorithm>
#include <climits>
#include "DvmhDirectiveBase.h"
#include "../Utils/utils.h"
#include "../Utils/errors.h"
#include "../Utils/json.hpp"
#include "utils.h"
#include "errors.h"
#include "json.hpp"
class Symbol;
class Expression;

View File

@@ -1,8 +1,8 @@
#include "Array.h"
#include "../Utils/errors.h"
#include "../Utils/utils.h"
#include "../GraphCall/graph_calls.h"
#include "../Utils/SgUtils.h"
#include "errors.h"
#include "utils.h"
#include "graph_calls.h"
#include "SgUtils.h"
#include "../DirectiveProcessing/directive_parser.h"
#include "../DirectiveProcessing/directive_omp_parser.h"
#include "../LoopAnalyzer/loop_analyzer.h"

View File

@@ -1,4 +1,4 @@
#include "../Utils/leak_detector.h"
#include "leak_detector.h"
#include <stdio.h>
#include <stdlib.h>
@@ -14,9 +14,9 @@
#include "GraphCSR.h"
#include "Arrays.h"
#include "../Utils/errors.h"
#include "../Utils/utils.h"
#include "../GraphLoop/graph_loops.h"
#include "errors.h"
#include "utils.h"
#include "graph_loops.h"
using std::vector;
using std::set;

View File

@@ -1,7 +1,7 @@
#pragma once
#include "../GraphLoop/graph_loops.h"
#include "../Utils/errors.h"
#include "graph_loops.h"
#include "errors.h"
void createDistributionDirs(DIST::GraphCSR<int, double, attrType> &reducedG, DIST::Arrays<int> &allArrays,
DataDirective &dataDirectives, std::map<std::string, std::vector<Messages>> &allMessages,

View File

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

View File

@@ -3,7 +3,7 @@
#include <vector>
#include <algorithm>
#include "../Utils/types.h"
#include "types.h"
namespace Distribution
{

View File

@@ -1,4 +1,4 @@
#include "../Utils/leak_detector.h"
#include "leak_detector.h"
#include <cstdio>
#include <cstdlib>
@@ -30,9 +30,9 @@ using namespace std::chrono;
#include "Arrays.h"
#include "Array.h"
#include "Distribution.h"
#include "../Utils/utils.h"
#include "../Utils/errors.h"
#include "../Utils/types.h"
#include "utils.h"
#include "errors.h"
#include "types.h"
#include "../Distribution/Cycle.h"
#include "../VisualizerCalls/get_information.h"
#include "../VisualizerCalls/SendMessage.h"
@@ -455,15 +455,7 @@ namespace Distribution
}
if (needPrint)
{
#if _WIN32
wstring treeM = L"<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> " + std::to_wstring(k + 1) + L"/" + std::to_wstring(AllCycles.size());
#else
wstring treeM = L"conflict resolution, processing group " + std::to_wstring(k + 1) + L"/" + std::to_wstring(AllCycles.size());
#endif
sendMessage_2lvl(treeM);
}
sendMessage_2lvl(4, k, (int)AllCycles.size());
auto timeR = steady_clock::now();
if (countConflicts != 0)
@@ -516,7 +508,7 @@ namespace Distribution
}
if (needPrint)
sendMessage_2lvl(L"");
sendMessage_2lvl(2);
return make_pair(allOnlySecondType, globalSum);
}
@@ -572,13 +564,7 @@ namespace Distribution
for (int z = 0; z < arraysV.size(); ++z)
{
const DIST::Array *array = arraysV[z];
#ifdef _WIN32
wstring treeM = L"<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> " + std::to_wstring(z + 1) + L"/" + std::to_wstring(arrays.size());
#else
wstring treeM = L"conflict resolution, processing array " + std::to_wstring(z + 1) + L"/" + std::to_wstring(arrays.size());
#endif
sendMessage_2lvl(treeM);
sendMessage_2lvl(5, z, (int)arrays.size());
vector<vType> verts;
@@ -605,7 +591,7 @@ namespace Distribution
}
}
}
sendMessage_2lvl(L"");
sendMessage_2lvl(2);
}
else
{

View File

@@ -1,4 +1,4 @@
#include "../Utils/leak_detector.h"
#include "leak_detector.h"
#include <stdio.h>
#include <stdlib.h>
@@ -7,12 +7,12 @@
#include <string>
#include <algorithm>
#include "../Utils/types.h"
#include "types.h"
#include "DvmhDirective.h"
#include "../Utils/errors.h"
#include "../Utils/SgUtils.h"
#include "errors.h"
#include "SgUtils.h"
#include "../Sapfor.h"
#include "../GraphCall/graph_calls_func.h"
#include "graph_calls_func.h"
#include "dvm.h"

View File

@@ -7,9 +7,9 @@
#include "Array.h"
#include "DvmhDirectiveBase.h"
#include "../Utils/AstWrapper.h"
#include "../Utils/types.h"
#include "../Utils/utils.h"
#include "AstWrapper.h"
#include "types.h"
#include "utils.h"
extern int sharedMemoryParallelization;

View File

@@ -1,4 +1,4 @@
#include "../Utils/leak_detector.h"
#include "leak_detector.h"
#include <stdio.h>
#include <stdlib.h>
@@ -10,11 +10,11 @@
#include "../Distribution/Array.h"
#include "../Distribution/Arrays.h"
#include "../Distribution/GraphCSR.h"
#include "../Utils/errors.h"
#include "../Utils/utils.h"
#include "../Utils/json.hpp"
#include "errors.h"
#include "utils.h"
#include "json.hpp"
#include "../GraphCall/graph_calls_func.h"
#include "graph_calls_func.h"
using std::vector;
using std::tuple;

View File

@@ -3,7 +3,7 @@
#include <vector>
#include <string>
#include "../Utils/json.hpp"
#include "json.hpp"
typedef enum lang : int { LANG_C, LANG_F } language;
typedef enum dist : int { BLOCK, NONE } distType;

View File

@@ -4,7 +4,7 @@
#include <string>
#include <set>
#include "dvm.h"
#include "../Utils/types.h"
#include "types.h"
SgExpression* createAndSetNext(const int side, const int variant, SgExpression *p);
std::vector<SgExpression*> genSubscripts(const std::vector<std::pair<int, int>> &shadowRenew, const std::vector<std::pair<int, int>> &shadowRenewShifts);

View File

@@ -1,4 +1,4 @@
#include "../Utils/leak_detector.h"
#include "leak_detector.h"
#include <algorithm>
#include <string>
@@ -19,8 +19,8 @@ extern int passDone;
#include "Cycle.h"
#include "Arrays.h"
#include "Array.h"
#include "../Utils/errors.h"
#include "../Utils/utils.h"
#include "errors.h"
#include "utils.h"
#include "../VisualizerCalls/get_information.h"
#include "../VisualizerCalls/SendMessage.h"
@@ -830,13 +830,13 @@ namespace Distribution
color[k] = WHITE;
findFrom = currentV;
#ifdef _WIN32
/*#ifdef _WIN32
if (needPrint)
{
wstring vertexM = std::to_wstring(k + 1) + L"/" + std::to_wstring(vertByTrees[t].size());
sendMessage_2lvl(wstring(L"<22><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD>, <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ") + wstring(treeM.begin(), treeM.end()) + L" <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> " + wstring(vertexM.begin(), vertexM.end()));
}
#endif
#endif*/
__spf_print(PRINT_TIMES && needPrint, "v (tree %d) = %d (with neighb %d) ", t, i, neighbors[i + 1] - neighbors[i]);
activeV[activeCounter++] = currentV;
FindLoop(cyclesTmp[t], currentV, currentV, numbers);
@@ -847,8 +847,8 @@ namespace Distribution
maxLoopDim = wasMaxLoopDim;
}
if (needPrint)
sendMessage_2lvl(L"");
/*if (needPrint)
sendMessage_2lvl(2);*/
}
catch (int code)
{

View File

@@ -5,7 +5,7 @@
#include <set>
#include <tuple>
#include "../Utils/RationalNum.h"
#include "RationalNum.h"
typedef enum links { RR_link, WR_link, WW_link } LinkType;

View File

@@ -1,6 +1,6 @@
#pragma once
#include "../GraphLoop/graph_loops_func.h"
#include "graph_loops_func.h"
#include <string>

View File

@@ -11,7 +11,7 @@
#include "DvmhRegionInserter.h"
#include "DvmhRegions/RegionsMerger.h"
#include "../VerificationCode/verifications.h"
#include "../Transformations/function_purifying.h"
#include "../Transformations/FunctionPurifying/function_purifying.h"
#include "../LoopAnalyzer/loop_analyzer.h"
#include "../DirectiveProcessing/directive_parser.h"

View File

@@ -1,10 +1,10 @@
#pragma once
#include "../GraphCall/graph_calls_func.h"
#include "../GraphLoop/graph_loops_func.h"
#include "../ExpressionTransform/expr_transform.h"
#include "graph_calls_func.h"
#include "graph_loops_func.h"
#include "expr_transform.h"
#include "../ParallelizationRegions/ParRegions.h"
#include "../Utils/SgUtils.h"
#include "SgUtils.h"
#include "ReadWriteAnalyzer.h"
#include "DvmhRegion.h"

View File

@@ -1,7 +1,7 @@
#pragma once
#include "../GraphLoop/graph_loops_func.h"
#include "../GraphCall/graph_calls_func.h"
#include "graph_loops_func.h"
#include "graph_calls_func.h"
#include <vector>
#include <string>

View File

@@ -1,7 +1,7 @@
#pragma once
#include "dvm.h"
#include "../Utils/SgUtils.h"
#include "SgUtils.h"
#include "VarUsages.h"
#include <set>
#include <tuple>

View File

@@ -1,7 +1,7 @@
#pragma once
#include "dvm.h"
#include "../Utils/SgUtils.h"
#include "SgUtils.h"
#include <string>
enum class VAR_TYPE { VAR_ARR, VAR_DISTR_ARR, VAR_SCALAR, VAR_ANY, VAR_UNDEFINED };

View File

@@ -5,10 +5,10 @@
#include "./createParallelRegions.h"
#include "../CreateInterTree/CreateInterTree.h"
#include "../GraphCall/graph_calls.h"
#include "graph_calls.h"
#include "./gcov_info.h"
#include "./gCov_parser_func.h"
#include "../Utils/leak_detector.h"
#include "leak_detector.h"
#include <map>
#include <vector>

View File

@@ -1,10 +1,10 @@
#pragma once
#include "../Utils/utils.h"
#include "utils.h"
#include "./gcov_info.h"
#include "../CreateInterTree/CreateInterTree.h"
#include "../GraphCall/graph_calls.h"
#include "graph_calls.h"
#include <map>
#include <vector>

View File

@@ -1,4 +1,4 @@
#include "../Utils/leak_detector.h"
#include "leak_detector.h"
#include <stdio.h>
#include <fstream>
@@ -8,7 +8,7 @@
#include "dvm.h"
#include "gCov_parser_func.h"
#include "../Utils/SgUtils.h"
#include "SgUtils.h"
using namespace std;

View File

@@ -5,7 +5,7 @@
#include <vector>
#include "dvm.h"
#include "../Utils/errors.h"
#include "errors.h"
#include "gcov_info.h"
#include "../CreateInterTree/CreateInterTree.h"

View File

@@ -1,10 +1,10 @@
#include "../Utils/leak_detector.h"
#include "leak_detector.h"
#include <iostream>
#include <map>
#include <algorithm>
#include "../Utils/errors.h"
#include "errors.h"
#include "gcov_info.h"

View File

@@ -5,7 +5,7 @@
#include <map>
#include <stdint.h>
#include "../Utils/utils.h"
#include "utils.h"
//make 'class' - need friend for Gcov_info
struct Perform

View File

@@ -1,4 +1,4 @@
#include "../Utils/leak_detector.h"
#include "leak_detector.h"
#include <cstdio>
#include <cstdlib>
@@ -15,13 +15,13 @@
#include "graph_calls_func.h"
#include "../CFGraph/CFGraph.h"
#include "../GraphLoop/graph_loops_func.h"
#include "graph_loops_func.h"
#include "../DirectiveProcessing/directive_parser.h"
#include "../Utils/SgUtils.h"
#include "../Utils/json.hpp"
#include "SgUtils.h"
#include "json.hpp"
#include "../ParallelizationRegions/ParRegions_func.h"
#include "../DynamicAnalysis/gCov_parser_func.h"
#include "../ExpressionTransform/expr_transform.h"
#include "expr_transform.h"
#include "../LoopAnalyzer/loop_analyzer.h"
#include "../VerificationCode/verifications.h"

View File

@@ -3,10 +3,10 @@
#include <string>
#include <set>
#include "../Utils/AstWrapper.h"
#include "../Utils/utils.h"
#include "AstWrapper.h"
#include "utils.h"
#include "../DirectiveProcessing/shadow.h"
#include "../GraphLoop/graph_loops.h"
#include "graph_loops.h"
static const char* paramNames[] =
{ "NONE_T", "ARRAY_T", "STRING_ARRAY_T", "STRING_T", "SCALAR_CHAR_T", "SCALAR_BOOL_T", "SCALAR_SHORT_T", "SCALAR_INT_T", "SCALAR_LONG_INT_T",

View File

@@ -1,4 +1,4 @@
#include "../Utils/leak_detector.h"
#include "leak_detector.h"
#include <cstdio>
#include <cstdlib>
@@ -10,10 +10,10 @@
#include <set>
#include <string>
#include "../Utils/errors.h"
#include "errors.h"
#include "graph_calls.h"
#include "../Distribution/Distribution.h"
#include "../Utils/utils.h"
#include "utils.h"
#include "../ParallelizationRegions/ParRegions.h"
using std::vector;

View File

@@ -5,7 +5,7 @@
#include <set>
#include "graph_calls.h"
#include "../GraphLoop/graph_loops.h"
#include "graph_loops.h"
#include "../ParallelizationRegions/ParRegions.h"
#include "Utils/json.hpp"

View File

@@ -1,4 +1,4 @@
#include "../Utils/leak_detector.h"
#include "leak_detector.h"
#include <cstdio>
#include <cstdlib>
@@ -12,26 +12,26 @@
#include "dvm.h"
#include "../Sapfor.h"
#include "../GraphCall/graph_calls_func.h"
#include "graph_calls_func.h"
#include "../ParallelizationRegions/ParRegions_func.h"
#include "../ExpressionTransform/expr_transform.h"
#include "expr_transform.h"
#include "../Distribution/GraphCSR.h"
#include "../Distribution/Arrays.h"
#include "../Distribution/Distribution.h"
#include "graph_loops.h"
#include "../Utils/utils.h"
#include "../Utils/SgUtils.h"
#include "utils.h"
#include "SgUtils.h"
#include "../Utils/errors.h"
#include "../Utils/AstWrapper.h"
#include "../Utils/json.hpp"
#include "errors.h"
#include "AstWrapper.h"
#include "json.hpp"
#include "../DirectiveProcessing/directive_parser.h"
#include "../DynamicAnalysis/gCov_parser_func.h"
#include "../Transformations/array_assign_to_loop.h"
#include "../Transformations/VectorAssignToLoop/array_assign_to_loop.h"
using std::vector;
using std::map;
@@ -520,7 +520,7 @@ static void findArrayRef(SgExpression *exp, bool isWirte, set<DIST::Array*>& use
{
if (exp)
{
if (exp->variant() == ARRAY_REF)
if (isArrayRef(exp))
{
DIST::Array *arrayRef = NULL;
SgSymbol *symbS = OriginalSymbol(exp->symbol());

View File

@@ -5,8 +5,8 @@
#include <map>
#include <set>
#include "../Utils/errors.h"
#include "../Utils/types.h"
#include "errors.h"
#include "types.h"
#include "../Distribution/DvmhDirective.h"
#include "../Distribution/Distribution.h"

View File

@@ -1,4 +1,4 @@
#include "../Utils/leak_detector.h"
#include "leak_detector.h"
#include <cstdio>
#include <cstdlib>
@@ -23,8 +23,8 @@ using std::make_pair;
using std::get;
#include "graph_loops.h"
#include "../GraphCall/graph_calls_func.h"
#include "../Utils/errors.h"
#include "graph_calls_func.h"
#include "errors.h"
#include "../Distribution/Distribution.h"
#include "../Distribution/CreateDistributionDirs.h"
#include "../ParallelizationRegions/ParRegions.h"

View File

@@ -1,4 +1,4 @@
#include "../Utils/leak_detector.h"
#include "leak_detector.h"
#include <cstdio>
#include <cstdlib>
@@ -8,8 +8,8 @@
#include <set>
#include "dvm.h"
#include "../Utils/SgUtils.h"
#include "../Utils/errors.h"
#include "SgUtils.h"
#include "errors.h"
using std::set;
using std::pair;

View File

@@ -1,4 +1,4 @@
#include "../Utils/leak_detector.h"
#include "leak_detector.h"
#include <cstdio>
#include <cstdlib>
@@ -20,8 +20,8 @@
#include "dvm.h"
#include "loop_analyzer.h"
#include "../Utils/utils.h"
#include "../Utils/SgUtils.h"
#include "utils.h"
#include "SgUtils.h"
#include "../ParallelizationRegions/ParRegions_func.h"
#include "../SageAnalysisTool/depGraph.h"
#include "../SageAnalysisTool/OmegaForSage/include/lang-interf.h"

View File

@@ -9,6 +9,9 @@
#include "GraphCall/graph_calls.h"
#include "implicit_loops_analyzer.h"
using namespace std;
using namespace SAPFOR;
using std::map;
using std::set;
using std::vector;
@@ -21,38 +24,46 @@ using std::to_string;
enum VisitState { UNVISITED = 0, VISITING = 1, VISITED = 2 };
static void dfs(SAPFOR::BasicBlock* block, map<int, int>& visit, vector<pair<SAPFOR::BasicBlock*, SAPFOR::BasicBlock*>>& startAndEnd, SAPFOR::BasicBlock* prev) {
if (!block)
return;
void dfs(SAPFOR::BasicBlock* block,
std::map<int, int>& visit,
std::vector<std::pair<SAPFOR::BasicBlock*, SAPFOR::BasicBlock*>>& startAndEnd,
SAPFOR::BasicBlock* prev) {
if (!block) return;
if (visit[block->getNumber()] == VISITED)
{
cout << "error";
int id = block->getNumber();
if (visit[id] == VISITING) {
// Обратное ребро — фиксируем цикл
startAndEnd.emplace_back(prev, block);
//std::cout << "Back edge detected: " << prev->getNumber() << " -> " << id << std::endl;
return;
}
if (visit[block->getNumber()] == VISITING)
{
visit[block->getNumber()] = VISITED;
startAndEnd.push_back(make_pair(prev, block));
if (visit[id] == VISITED) {
return;
}
visit[block->getNumber()] = VISITING;
for (auto i : block->getNext())
dfs(i, visit, startAndEnd, block);
visit[id] = VISITING;
for (auto next : block->getNext()) {
dfs(next, visit, startAndEnd, block);
}
visit[id] = VISITED;
}
static void printBlock(SAPFOR::BasicBlock* block)
{
static void printBlock(SAPFOR::BasicBlock* block) {
cout << "block - " << block->getNumber() << endl;
cout << "next -";
for (auto i : block->getNext())
{
cout << " " << i->getNumber();
}
cout << endl << "prev -";
for (auto i : block->getPrev())
{
cout << " " << i->getNumber();
}
cout << endl;
for (auto i : block->getInstructions())
@@ -60,93 +71,85 @@ static void printBlock(SAPFOR::BasicBlock* block)
string resValue = "";
string arg1Value = "";
string arg2Value = "";
if (i->getInstruction()->getResult() != NULL && i->getInstruction()->getResult()->getType() == SAPFOR::CFG_ARG_TYPE::VAR)
{
if (i->getInstruction()->getResult() != nullptr && i->getInstruction()->getResult()->getType() == CFG_ARG_TYPE::VAR) {
resValue = i->getInstruction()->getResult()->getValue();
i->getInstruction()->getResult()->setValue(i->getInstruction()->getResult()->getValue() + to_string(i->getInstruction()->getResult()->getNumber()));
}
if (i->getInstruction()->getArg1() != NULL && i->getInstruction()->getArg1()->getType() == SAPFOR::CFG_ARG_TYPE::VAR)
{
if (i->getInstruction()->getArg1() != nullptr && i->getInstruction()->getArg1()->getType() == CFG_ARG_TYPE::VAR) {
arg1Value = i->getInstruction()->getArg1()->getValue();
i->getInstruction()->getArg1()->setValue(i->getInstruction()->getArg1()->getValue() + to_string(i->getInstruction()->getArg1()->getNumber()));
}
if (i->getInstruction()->getArg2() != NULL && i->getInstruction()->getArg2()->getType() == SAPFOR::CFG_ARG_TYPE::VAR)
{
if (i->getInstruction()->getArg2() != nullptr && i->getInstruction()->getArg2()->getType() == CFG_ARG_TYPE::VAR) {
arg2Value = i->getInstruction()->getArg2()->getValue();
i->getInstruction()->getArg2()->setValue(i->getInstruction()->getArg2()->getValue() + to_string(i->getInstruction()->getArg2()->getNumber()));
}
cout << i->getNumber() << " " << i->getInstruction()->dump() << endl;
if (i->getInstruction()->getResult() != NULL && i->getInstruction()->getResult()->getType() == SAPFOR::CFG_ARG_TYPE::VAR)
i->getInstruction()->getResult()->setValue(resValue);
if (i->getInstruction()->getArg1() != NULL && i->getInstruction()->getArg1()->getType() == SAPFOR::CFG_ARG_TYPE::VAR)
if (i->getInstruction()->getResult() != nullptr && i->getInstruction()->getResult()->getType() == CFG_ARG_TYPE::VAR) {
i->getInstruction()->getResult()->setValue(resValue);
}
if (i->getInstruction()->getArg1() != nullptr && i->getInstruction()->getArg1()->getType() == CFG_ARG_TYPE::VAR) {
i->getInstruction()->getArg1()->setValue(arg1Value);
if (i->getInstruction()->getArg2() != NULL && i->getInstruction()->getArg2()->getType() == SAPFOR::CFG_ARG_TYPE::VAR)
}
if (i->getInstruction()->getArg2() != nullptr && i->getInstruction()->getArg2()->getType() == CFG_ARG_TYPE::VAR) {
i->getInstruction()->getArg2()->setValue(arg2Value);
}
}
cout << endl;
}
static void getLoopBody(SAPFOR::BasicBlock* loopHeader, const set<SAPFOR::BasicBlock*>& loopExits, std::vector<SAPFOR::BasicBlock*>& loopBody)
{
set<SAPFOR::BasicBlock*> visited;
void getLoopBody(SAPFOR::BasicBlock* loopHeader, const std::set<SAPFOR::BasicBlock*>& loopExits, std::vector<SAPFOR::BasicBlock*>& loopBody) {
std::set<SAPFOR::BasicBlock*> visited;
std::stack<SAPFOR::BasicBlock*> stack;
stack.push(loopHeader);
while (!stack.empty())
{
while (!stack.empty()) {
auto block = stack.top();
stack.pop();
if (visited.count(block))
continue;
if (visited.count(block)) continue;
visited.insert(block);
for (auto& succ : block->getNext())
{
if (loopExits.count(succ))
continue;
if (!visited.count(succ))
stack.push(succ);
for (auto succ : block->getNext()) {
if (loopExits.count(succ)) continue;
if (!visited.count(succ)) {
stack.push(succ);
}
}
}
set<SAPFOR::BasicBlock*> backReachable;
std::set<SAPFOR::BasicBlock*> backReachable;
std::stack<SAPFOR::BasicBlock*> reverseStack;
reverseStack.push(loopHeader);
while (!reverseStack.empty())
{
while (!reverseStack.empty()) {
auto block = reverseStack.top();
reverseStack.pop();
if (backReachable.count(block))
continue;
if (backReachable.count(block)) continue;
backReachable.insert(block);
for (auto& pred : block->getPrev())
if (visited.count(pred) && !backReachable.count(pred))
for (auto pred : block->getPrev()) {
if (visited.count(pred) && !backReachable.count(pred)) {
reverseStack.push(pred);
}
}
}
for (auto& block : visited)
if (backReachable.count(block))
for (auto block : visited) {
if (backReachable.count(block)) {
loopBody.push_back(block);
}
}
}
static set<SAPFOR::Argument*> findRegisterSourceVariables(const std::vector<SAPFOR::BasicBlock*>& blocks, SAPFOR::Argument* var)
{
set<SAPFOR::Argument*> result;
set<SAPFOR::Argument*> visited;
set<SAPFOR::Argument*> findRegisterSourceVariables(const std::vector<SAPFOR::BasicBlock*>& blocks, SAPFOR::Argument* var) {
std::set<SAPFOR::Argument*> result;
std::set<SAPFOR::Argument*> visited;
std::stack<SAPFOR::Argument*> workStack;
workStack.push(var);
@@ -159,15 +162,14 @@ static set<SAPFOR::Argument*> findRegisterSourceVariables(const std::vector<SAPF
op == SAPFOR::CFG_OP::EQ || op == SAPFOR::CFG_OP::NEQV ||
op == SAPFOR::CFG_OP::EQV || op == SAPFOR::CFG_OP::EMPTY ||
op == SAPFOR::CFG_OP::OR || op == SAPFOR::CFG_OP::AND;
};
};
auto isUnaryOp = [](SAPFOR::CFG_OP op) {
return op == SAPFOR::CFG_OP::UN_ADD || op == SAPFOR::CFG_OP::UN_MINUS ||
op == SAPFOR::CFG_OP::NOT || op == SAPFOR::CFG_OP::ASSIGN;
};
};
while (!workStack.empty())
{
while (!workStack.empty()) {
auto variable = workStack.top();
workStack.pop();
if (!variable || visited.count(variable))
@@ -175,10 +177,8 @@ static set<SAPFOR::Argument*> findRegisterSourceVariables(const std::vector<SAPF
visited.insert(variable);
for (auto& block : blocks)
{
for (auto& instrWrapper : block->getInstructions())
{
for (auto block : blocks) {
for (auto instrWrapper : block->getInstructions()) {
auto instr = instrWrapper->getInstruction();
if (!instr || instr->getResult() != variable)
continue;
@@ -187,23 +187,21 @@ static set<SAPFOR::Argument*> findRegisterSourceVariables(const std::vector<SAPF
auto arg1 = instr->getArg1();
auto arg2 = instr->getArg2();
if (isBinaryOp(op) && arg1 && arg2)
{
if (arg1->getType() == SAPFOR::CFG_ARG_TYPE::VAR)
if (isBinaryOp(op) && arg1 && arg2) {
if (arg1->getType() == CFG_ARG_TYPE::VAR)
result.insert(arg1);
else if (arg1->getType() == SAPFOR::CFG_ARG_TYPE::REG)
else if (arg1->getType() == CFG_ARG_TYPE::REG)
workStack.push(arg1);
if (arg2->getType() == SAPFOR::CFG_ARG_TYPE::VAR)
if (arg2->getType() == CFG_ARG_TYPE::VAR)
result.insert(arg2);
else if (arg2->getType() == SAPFOR::CFG_ARG_TYPE::REG)
else if (arg2->getType() == CFG_ARG_TYPE::REG)
workStack.push(arg2);
}
else if (isUnaryOp(op) && arg1)
{
if (arg1->getType() == SAPFOR::CFG_ARG_TYPE::VAR)
else if (isUnaryOp(op) && arg1) {
if (arg1->getType() == CFG_ARG_TYPE::VAR)
result.insert(arg1);
else if (arg1->getType() == SAPFOR::CFG_ARG_TYPE::REG)
else if (arg1->getType() == CFG_ARG_TYPE::REG)
workStack.push(arg1);
}
}
@@ -213,8 +211,7 @@ static set<SAPFOR::Argument*> findRegisterSourceVariables(const std::vector<SAPF
return result;
}
static std::vector<SAPFOR::Instruction*> getPhiArguments(SAPFOR::BasicBlock* block, SAPFOR::Instruction* phiInstr)
{
std::vector<SAPFOR::Instruction*> getPhiArguments(SAPFOR::BasicBlock* block, SAPFOR::Instruction* phiInstr) {
std::vector<SAPFOR::Instruction*> result;
auto& instructions = block->getInstructions();
@@ -222,23 +219,21 @@ static std::vector<SAPFOR::Instruction*> getPhiArguments(SAPFOR::BasicBlock* blo
for (int i = instructions.size() - 1; i >= 0; --i) {
auto instr = instructions[i]->getInstruction();
if (collecting)
{
if (instr->getOperation() == SAPFOR::CFG_OP::PARAM)
{
if (collecting) {
if (instr->getOperation() == SAPFOR::CFG_OP::PARAM) {
auto arg = instr->getArg1();
if (arg)
result.push_back(instr);
if (arg) {
result.push_back(instr);
}
}
else {
break;
}
else
break;
}
if (!instr)
continue;
if (!instr) continue;
if (instr == phiInstr)
{
if (instr == phiInstr) {
collecting = true;
continue;
}
@@ -248,215 +243,346 @@ static std::vector<SAPFOR::Instruction*> getPhiArguments(SAPFOR::BasicBlock* blo
return result;
}
SAPFOR::BasicBlock* findInstructionBlock(SAPFOR::Instruction* targetInstr, const std::vector<SAPFOR::BasicBlock*>& blocks)
{
for (auto& block : blocks)
{
for (auto& instrWrapper : block->getInstructions())
{
SAPFOR::BasicBlock* findInstructionBlock(SAPFOR::Instruction* targetInstr, const std::vector<SAPFOR::BasicBlock*>& blocks) {
for (auto block : blocks) {
for (auto instrWrapper : block->getInstructions()) {
auto instr = instrWrapper->getInstruction();
if (instr == targetInstr)
if (instr == targetInstr) {
return block;
}
}
}
return NULL;
return nullptr;
}
static SAPFOR::BasicBlock* findInstructionBlockByNumber(int number, const std::vector<SAPFOR::BasicBlock*>& blocks)
{
for (auto& block : blocks)
{
for (auto& instrWrapper : block->getInstructions())
{
SAPFOR::BasicBlock* findInstructionBlockByNumber(int number, const std::vector<SAPFOR::BasicBlock*>& blocks) {
for (auto block : blocks) {
for (auto instrWrapper : block->getInstructions()) {
auto instr = instrWrapper->getInstruction();
if (instr->getNumber() == number)
if (instr->getNumber() == number) {
return block;
}
}
}
return NULL;
return nullptr;
}
static void findInductiveVars(const std::vector<SAPFOR::BasicBlock*>& blocks,
const std::vector<SAPFOR::BasicBlock*>& Loopblocks, SAPFOR::BasicBlock* loopHeader,
const set<SAPFOR::BasicBlock*>& loopExits)
{
set<string> inductiveVars;
set<SAPFOR::BasicBlock*> relevantBlocks = { loopHeader };
set<SAPFOR::Argument*> findSourceVariablesRecursive(const std::vector<SAPFOR::BasicBlock*>& blocks, SAPFOR::Argument* var) {
std::set<SAPFOR::Argument*> result;
std::set<SAPFOR::Argument*> visited;
std::stack<SAPFOR::Argument*> workStack;
workStack.push(var);
for (auto& block : relevantBlocks)
{
for (auto& instrWrapper : block->getInstructions())
{
while (!workStack.empty()) {
auto variable = workStack.top(); workStack.pop();
if (!variable || visited.count(variable)) continue;
visited.insert(variable);
bool foundDefinition = false;
for (auto block : blocks) {
for (auto instrWrapper : block->getInstructions()) {
auto instr = instrWrapper->getInstruction();
if (!instr || instr->getResult() != variable) continue;
foundDefinition = true;
auto arg1 = instr->getArg1();
auto arg2 = instr->getArg2();
if (arg1 && arg1->getType() == CFG_ARG_TYPE::VAR) result.insert(arg1);
if (arg1 && arg1->getType() == CFG_ARG_TYPE::REG) workStack.push(arg1);
if (arg2 && arg2->getType() == CFG_ARG_TYPE::VAR) result.insert(arg2);
if (arg2 && arg2->getType() == CFG_ARG_TYPE::REG) workStack.push(arg2);
}
}
if (!foundDefinition) result.insert(variable); // параметр
}
return result;
}
// Версия findInductiveVars без логов, только финальная статистика
// Версия findInductiveVars с расширенной поддержкой и анализом цепочек зависимостей через регистры и другие операции
std::set<std::string> traceRecursiveSources(const std::vector<SAPFOR::BasicBlock*>& blocks, SAPFOR::Argument* arg) {
std::set<std::string> result;
std::set<SAPFOR::Argument*> visited;
std::stack<SAPFOR::Argument*> stack;
stack.push(arg);
while (!stack.empty()) {
auto curr = stack.top(); stack.pop();
if (!curr || visited.count(curr)) continue;
visited.insert(curr);
if (curr->getType() == CFG_ARG_TYPE::VAR) {
result.insert(curr->getValue());
continue;
}
for (auto block : blocks) {
for (auto instrWrapper : block->getInstructions()) {
auto instr = instrWrapper->getInstruction();
if (!instr) continue;
if (instr->getResult() != curr) continue;
auto a1 = instr->getArg1();
auto a2 = instr->getArg2();
if (a1) stack.push(a1);
if (a2) stack.push(a2);
}
}
}
return result;
}
// Улучшенная версия с трассировкой цепочек регистров до phi-переменных
std::set<std::string> traceSourcesDeepToPhi(const std::vector<SAPFOR::BasicBlock*>& blocks, SAPFOR::Argument* arg, const std::set<std::string>& phiNames) {
std::set<std::string> reachedPhi;
std::set<SAPFOR::Argument*> visited;
std::stack<SAPFOR::Argument*> stack;
stack.push(arg);
while (!stack.empty()) {
auto curr = stack.top(); stack.pop();
if (!curr || visited.count(curr)) continue;
visited.insert(curr);
//std::cout << "[DEBUG] visiting "
// << (curr->getType() == CFG_ARG_TYPE::VAR ? "VAR" :
// curr->getType() == CFG_ARG_TYPE::REG ? "REG" : "OTHER")
// << ": ." << curr->getValue() << "." << std::endl;
if (phiNames.count(curr->getValue())) {
//std::cout << "[DEBUG] REACHED phi: ." << curr->getValue() << "." << std::endl;
reachedPhi.insert(curr->getValue());
continue;
}
for (auto block : blocks) {
for (auto instrWrapper : block->getInstructions()) {
auto instr = instrWrapper->getInstruction();
if (!instr) continue;
if (instr->getResult() != curr) continue;
auto a1 = instr->getArg1();
auto a2 = instr->getArg2();
if (a1) stack.push(a1);
if (a2) stack.push(a2);
}
}
}
return reachedPhi;
}
void findInductiveVars(const std::vector<SAPFOR::BasicBlock*>& blocks,
const std::vector<SAPFOR::BasicBlock*>& Loopblocks,
SAPFOR::BasicBlock* loopHeader,
const std::set<SAPFOR::BasicBlock*>& loopExits) {
std::set<std::string> inductiveVars;
std::set<SAPFOR::BasicBlock*> relevantBlocks = { loopHeader };
for (auto block : relevantBlocks) {
for (auto instrWrapper : block->getInstructions()) {
auto instr = instrWrapper->getInstruction();
if (!instr)
continue;
if (!instr) continue;
auto op = instr->getOperation();
auto res = instr->getResult();
auto arg1 = instr->getArg1();
auto arg2 = instr->getArg2();
if (op == SAPFOR::CFG_OP::JUMP_IF)
{
if (arg1 && arg1->getType() == SAPFOR::CFG_ARG_TYPE::VAR)
if (op == CFG_OP::JUMP_IF) {
if (arg1 && arg1->getType() == CFG_ARG_TYPE::VAR) {
inductiveVars.insert(arg1->getValue());
if (arg1 && arg1->getType() == SAPFOR::CFG_ARG_TYPE::REG)
{
}
if (arg1 && arg1->getType() == CFG_ARG_TYPE::REG) {
auto foundVariables = findRegisterSourceVariables(blocks, arg1);
for (auto& var : foundVariables)
for (auto var : foundVariables) {
inductiveVars.insert(var->getValue());
}
}
}
}
}
set<string> finalInductiveVars;
std::set<std::string> finalInductiveVars;
for (auto& instrWrapper : loopHeader->getInstructions())
{
for (auto instrWrapper : loopHeader->getInstructions()) {
auto instr = instrWrapper->getInstruction();
if (!instr || instr->getOperation() != SAPFOR::CFG_OP::F_CALL || !instr->getArg1() || instr->getArg1()->getValue() != "FI_FUNCTION")
continue;
if (!instr || instr->getOperation() != SAPFOR::CFG_OP::F_CALL || !instr->getArg1() || instr->getArg1()->getValue() != "FI_FUNCTION") continue;
auto phiRes = instr->getResult();
if (!phiRes || !inductiveVars.count(phiRes->getValue()))
continue;
if (!phiRes || !inductiveVars.count(phiRes->getValue())) continue;
auto currentBlock = findInstructionBlock(instr, blocks);
if (!currentBlock)
continue;
if (!currentBlock) continue;
auto phiArgs = getPhiArguments(currentBlock, instr);
bool hasInLoopDefinition = false;
for (const auto& argInstr : phiArgs)
{
if (!argInstr)
continue;
for (const auto& argInstr : phiArgs) {
if (!argInstr) continue;
int definitionInstrNumber = stoi(argInstr->getArg1()->getValue());
if (definitionInstrNumber == -1)
continue;
int definitionInstrNumber = std::stoi(argInstr->getArg1()->getValue());
if (definitionInstrNumber == -1) continue;
auto phiBlock = findInstructionBlockByNumber(definitionInstrNumber, blocks);
if (!phiBlock)
continue;
if (!phiBlock) continue;
if (std::find(Loopblocks.begin(), Loopblocks.end(), phiBlock) != Loopblocks.end())
if (std::find(Loopblocks.begin(), Loopblocks.end(), phiBlock) != Loopblocks.end()) {
hasInLoopDefinition = true;
}
}
if (hasInLoopDefinition)
if (hasInLoopDefinition) {
finalInductiveVars.insert(phiRes->getValue());
}
}
for (auto& i : finalInductiveVars)
cout << "Confirmed inductive variable: " << i << endl;
for (const auto& var : finalInductiveVars) {
std::cout << "Confirmed inductive variable: " << var << std::endl;
}
if (finalInductiveVars.empty())
cout << "No confirmed inductive variables found." << endl;
if (finalInductiveVars.empty()) {
std::cout << "No confirmed inductive variables found." << std::endl;
}
}
static SAPFOR::Instruction* findInstructionAfterLoop(const std::vector<SAPFOR::BasicBlock*>& loopBody)
{
set<SAPFOR::BasicBlock*> loopSet(loopBody.begin(), loopBody.end());
for (auto& block : loopBody)
{
for (auto& succ : block->getNext())
{
if (!loopSet.count(succ))
{
// <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
Instruction* findInstructionAfterLoop(const std::vector<SAPFOR::BasicBlock*>& loopBody) {
std::set<SAPFOR::BasicBlock*> loopSet(loopBody.begin(), loopBody.end());
for (auto block : loopBody) {
for (auto succ : block->getNext()) {
if (!loopSet.count(succ)) {
// Нашли выход из цикла — возьмём первую инструкцию
auto instructions = succ->getInstructions();
for (auto& wrapper : instructions)
if (auto instr = wrapper->getInstruction())
if (instructions.empty()) {
std::cout << "Exit block has no instructions." << std::endl;
}
for (auto wrapper : instructions) {
if (auto instr = wrapper->getInstruction()) {
return instr;
}
}
}
}
}
return NULL; // <EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>
return nullptr; // не нашли
}
void findImplicitLoops(const map<FuncInfo*, vector<SAPFOR::BasicBlock*>>& fullIR_SSA, const char* fileName)
{
bool isEqual(const char* cstr, const std::string& str) {
return str == cstr;
}
void findImplicitLoops(const std::map<FuncInfo*, std::vector<SAPFOR::BasicBlock*>>& fullIR_SSA, const char* fileName) {
for (auto& i : fullIR_SSA)
{
//for (auto& j : i.second)
//for (auto j : i.second)
// printblock(j);
if (fileName != i.first->fileName)
if (!isEqual(fileName, i.first->fileName))
continue;
if (isEqual("csol.for", i.first->fileName) || isEqual("reblns.for", i.first->fileName) || isEqual("adjont.for", i.first->fileName)
|| isEqual("beginf.for", i.first->fileName) || isEqual("dsnp1.for", i.first->fileName) || isEqual("dsnpnm.for", i.first->fileName)
|| isEqual("decod3.for", i.first->fileName))
continue;
/*if (!isEqual("ddst2.for", i.first->fileName))
continue;*/
map<int, int> visited;
for (auto& i : i.second)
for (auto i : i.second)
visited[i->getNumber()] = UNVISITED;
//vector<int> visited(i.second.size(), UNVISITED);
//for (auto j : i.second)
// printBlock(j);
//vector<int> visited(i.second.size(), UNVISITED);
vector<pair<SAPFOR::BasicBlock*, SAPFOR::BasicBlock*>> startAndEnd;
dfs(i.second[0], visited, startAndEnd, NULL);
//continue;
vector<LoopGraph*> loops;
for (auto& [tail, header] : startAndEnd) {
set<SAPFOR::BasicBlock*> loopExits;
for (auto& succ : tail->getNext())
if (succ != header)
for (auto succ : tail->getNext()) {
if (succ != header) {
loopExits.insert(succ);
}
}
vector<SAPFOR::BasicBlock*> loopBody;
getLoopBody(header, loopExits, loopBody);
cout << "LOOP DETECTED:" << endl;
cout << " Header: " << header->getNumber() << endl;
cout << " Tail: " << tail->getNumber() << endl;
cout << " Body blocks: ";
for (auto& block : loopBody)
cout << block->getNumber() << " ";
cout << endl;
//cout << "LOOP DETECTED:" << endl;
//cout << " Header: " << header->getNumber() << endl;
//cout << " Tail: " << tail->getNumber() << endl;
//cout << " Body blocks: ";
//for (auto block : loopBody) {
// cout << block->getNumber() << " ";
//}
//cout << endl;
findInductiveVars(i.second, loopBody, header, loopExits);
SAPFOR::Instruction* instructionAfterLoop = findInstructionAfterLoop(loopBody);
if (instructionAfterLoop == NULL)
{
continue;
Instruction* instructionAfterLoop = findInstructionAfterLoop(loopBody);
if (instructionAfterLoop == NULL) {
cout << "Warning: instruction after loop not found!" << endl;
cout << i.first->fileName << endl;
continue;
}
auto firstInstruction = header->getInstructions()[0]->getInstruction();
auto lastInstruction = tail->getInstructions().back()->getInstruction();
cout << "first - " << firstInstruction->getNumber() << " last - " << lastInstruction->getNumber() << " after - " << instructionAfterLoop->getNumber() << endl;
auto x = firstInstruction->getOperator();
//cout << "first - " << firstInstruction->getNumber() << " last - " << lastInstruction->getNumber() << " after - " << instructionAfterLoop->getNumber() << endl;
//auto x = firstInstruction->getOperator();
auto tmpLoop = new LoopGraph();
tmpLoop->isFor = true;
tmpLoop->lineNum = firstInstruction->getOperator()->lineNumber();
tmpLoop->lineNumAfterLoop = instructionAfterLoop->getOperator()->lineNumber();
if (firstInstruction->getOperator()->variant() == FOR_NODE)
{
//continue;
if (firstInstruction->getOperator()->variant() == FOR_NODE) {
SgForStmt* stmt = isSgForStmt(firstInstruction->getOperator());
cout << "for loop" << endl;// << stmt->sunparse() << endl;
}
else if (firstInstruction->getOperator()->variant() == WHILE_NODE)
{
else if (firstInstruction->getOperator()->variant() == WHILE_NODE) {
SgWhileStmt* stmt = isSgWhileStmt(firstInstruction->getOperator());
cout << (stmt->conditional() == NULL ? "infinit" : "") << "while loop" << endl;//<< stmt->sunparse() << endl;
}
else if (firstInstruction->getOperator()->variant() == DO_WHILE_NODE)
{
else if (firstInstruction->getOperator()->variant() == DO_WHILE_NODE) {
SgWhileStmt* stmt = isSgDoWhileStmt(firstInstruction->getOperator());
cout << "do while loop" << endl;// << stmt->sunparse() << endl;
}
else if (firstInstruction->getOperator()->variant() == LOOP_NODE)
else if (firstInstruction->getOperator()->variant() == LOOP_NODE) {
cout << "not known loop" << endl;// << firstInstruction->getOperator()->sunparse() << endl;
else
}
else {
cout << "goto loop" << endl;// firstInstruction->getOperator()->sunparse() << endl;
}
cout << "loop start line " << tmpLoop->lineNum << endl;
cout << "after loop line " << tmpLoop->lineNumAfterLoop << endl << endl;
@@ -464,4 +590,4 @@ void findImplicitLoops(const map<FuncInfo*, vector<SAPFOR::BasicBlock*>>& fullIR
loops.push_back(tmpLoop);
}
}
}
}

View File

@@ -18,7 +18,7 @@
#include <tuple>
#include <stack>
#include "../Utils/leak_detector.h"
#include "leak_detector.h"
#if _WIN32 && NDEBUG && __BOOST
#include <boost/thread.hpp>
@@ -30,25 +30,25 @@ extern int passDone;
#include "../Distribution/Arrays.h"
#include "../ParallelizationRegions/ParRegions.h"
#include "../Utils/errors.h"
#include "errors.h"
#include "../DirectiveProcessing/directive_parser.h"
#include "../DirectiveProcessing/directive_creator.h"
#include "../Utils/SgUtils.h"
#include "../Utils/AstWrapper.h"
#include "SgUtils.h"
#include "AstWrapper.h"
#include "../GraphCall/graph_calls_func.h"
#include "../GraphLoop/graph_loops_func.h"
#include "graph_calls_func.h"
#include "graph_loops_func.h"
#include "../ParallelizationRegions/ParRegions_func.h"
#include "../DynamicAnalysis/gCov_parser_func.h"
#include "../ExpressionTransform/expr_transform.h"
#include "expr_transform.h"
#include "../SageAnalysisTool/depInterfaceExt.h"
#include "../VisualizerCalls/get_information.h"
#include "../VisualizerCalls/SendMessage.h"
#include "../Transformations/enddo_loop_converter.h"
#include "../Transformations/LoopEndDoConverter/enddo_loop_converter.h"
#include "../DirectiveProcessing/remote_access.h"
#include "../DirectiveProcessing/directive_omp_parser.h"
@@ -1633,17 +1633,7 @@ void loopAnalyzer(SgFile *file, vector<ParallelRegion*> &regions, map<tuple<int,
createNeededException();
string fName = file->functions(i)->symbol()->identifier();
#if _WIN32
if (file->functions(i)->variant() != MODULE_STMT)
sendMessage_2lvl(wstring(L"обработка функции '") + wstring(fName.begin(), fName.end()) + L"'");
else
sendMessage_2lvl(wstring(L"обработка модуля '") + wstring(fName.begin(), fName.end()) + L"'");
#else
if (file->functions(i)->variant() != MODULE_STMT)
sendMessage_2lvl(wstring(L"processing function '") + wstring(fName.begin(), fName.end()) + L"'");
else
sendMessage_2lvl(wstring(L"processing module '") + wstring(fName.begin(), fName.end()) + L"'");
#endif
sendMessage_2lvl(0, (file->functions(i)->variant() != MODULE_STMT), fName);
set<SgSymbol*> delcsSymbViewed;
set<SgStatement*> delcsStatViewed;
@@ -2188,11 +2178,8 @@ void loopAnalyzer(SgFile *file, vector<ParallelRegion*> &regions, map<tuple<int,
if (!skipDeps)
{
string fName = file->functions(i)->symbol()->identifier();
#ifdef _WIN32
sendMessage_2lvl(wstring(L"обработка цикла ") + std::to_wstring(idx) + L"/" + std::to_wstring(convertedLoopInfo.size()));
#else
sendMessage_2lvl(wstring(L"processing loop ") + std::to_wstring(idx) + L"/" + std::to_wstring(convertedLoopInfo.size()));
#endif
sendMessage_2lvl(1, idx, (int)convertedLoopInfo.size());
tryToFindDependencies(loop.first, allLoops, funcWasInit, file, regions, currMessages, collection, funcByName, defUseByPlace);
}
}
@@ -2340,7 +2327,7 @@ void loopAnalyzer(SgFile *file, vector<ParallelRegion*> &regions, map<tuple<int,
if (parallizeFreeLoops)
selectFreeLoopsForParallelization(loopsForFunction, funcName, (regime == DATA_DISTR), regions, messagesForFile);
}
sendMessage_2lvl(L"");
sendMessage_2lvl(2);
}
else if (regime == COMP_DISTR)
{

View File

@@ -5,12 +5,12 @@
#include <tuple>
#include <vector>
#include <set>
#include "../GraphLoop/graph_loops.h"
#include "../GraphCall/graph_calls.h"
#include "graph_loops.h"
#include "graph_calls.h"
#include "../ParallelizationRegions/ParRegions.h"
#include "../SageAnalysisTool/depInterfaceExt.h"
#include "../Utils/AstWrapper.h"
#include "../Utils/SgUtils.h"
#include "AstWrapper.h"
#include "SgUtils.h"
#include "dvm.h"

View File

@@ -1,4 +1,4 @@
#include "../Utils/leak_detector.h"
#include "leak_detector.h"
#include <stdio.h>
#include <stdlib.h>
@@ -10,12 +10,12 @@
#include "dvm.h"
#include "ParRegions.h"
#include "../Utils/utils.h"
#include "../Utils/SgUtils.h"
#include "../GraphCall/graph_calls_func.h"
#include "../GraphLoop/graph_loops.h"
#include "utils.h"
#include "SgUtils.h"
#include "graph_calls_func.h"
#include "graph_loops.h"
#include "../Distribution/Distribution.h"
#include "../ExpressionTransform/expr_transform.h"
#include "expr_transform.h"
using std::vector;
using std::string;

View File

@@ -9,12 +9,12 @@
#include "../Distribution/DvmhDirective.h"
#include "../Distribution/GraphCSR.h"
#include "../Distribution/Distribution.h"
#include "../Utils/AstWrapper.h"
#include "AstWrapper.h"
#include "../Utils/json.hpp"
#include "json.hpp"
#if __SPF
#include "../Utils/SgUtils.h"
#include "SgUtils.h"
#endif
struct ParallelRegionLines

View File

@@ -1,8 +1,8 @@
#pragma once
#include "ParRegions.h"
#include "../GraphCall/graph_calls.h"
#include "../GraphLoop/graph_loops.h"
#include "graph_calls.h"
#include "graph_loops.h"
void fillRegionLines(SgFile *file, std::vector<ParallelRegion*> &regions, std::vector<Messages>& messagesForFile, std::vector<LoopGraph*> *loops = NULL, std::vector<FuncInfo*> *funcs = NULL);
void fillRegionLinesStep2(std::vector<ParallelRegion*> &regions, const std::map<std::string, std::vector<FuncInfo*>> &allFuncInfo, std::map<std::string, std::vector<LoopGraph*>> *loopGraph = NULL);

View File

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

View File

@@ -1,7 +1,7 @@
#pragma once
#include "ParRegions.h"
#include "../Utils/SgUtils.h"
#include "../Utils/errors.h"
#include "SgUtils.h"
#include "errors.h"
bool expandExtractReg(const std::string &fileName, const int startLine, const int endLine, const std::vector<ParallelRegion*> &regions, std::vector<Messages> &messagesForFile, const bool toDelete = false);

View File

@@ -1,4 +1,4 @@
#include "../Utils/leak_detector.h"
#include "leak_detector.h"
#include <string>
#include <vector>
@@ -11,14 +11,14 @@
#include "ParRegions_func.h"
#include "resolve_par_reg_conflicts.h"
#include "../GraphCall/graph_calls_func.h"
#include "../GraphLoop/graph_loops_func.h"
#include "graph_calls_func.h"
#include "graph_loops_func.h"
#include "../LoopAnalyzer/loop_analyzer.h"
#include "../DirectiveProcessing/directive_creator.h"
#include "../DirectiveProcessing/insert_directive.h"
#include "../Utils/SgUtils.h"
#include "../ExpressionTransform/expr_transform.h"
#include "../Transformations/function_purifying.h"
#include "SgUtils.h"
#include "expr_transform.h"
#include "../Transformations/FunctionPurifying/function_purifying.h"
using std::map;
using std::pair;

View File

@@ -1,9 +1,9 @@
#pragma once
#include "ParRegions.h"
#include "../Utils/SgUtils.h"
#include "../Utils/errors.h"
#include "../GraphCall/graph_calls.h"
#include "SgUtils.h"
#include "errors.h"
#include "graph_calls.h"
void fillRegionIntervals(std::vector<ParallelRegion*> &regions);
void fillRegionArrays(std::vector<ParallelRegion*> &regions, const std::map<std::string, std::vector<FuncInfo*>> &allFuncInfo, 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>
@@ -16,11 +16,11 @@
#include "../DynamicAnalysis/gcov_info.h"
#include "../DynamicAnalysis/gCov_parser_func.h"
#include "PredictScheme.h"
#include "../Utils/SgUtils.h"
#include "SgUtils.h"
#include "../DirectiveProcessing/directive_parser.h"
#include "../Distribution/DvmhDirective.h"
#include "../GraphLoop/graph_loops_func.h"
#include "../ExpressionTransform/expr_transform.h"
#include "graph_loops_func.h"
#include "expr_transform.h"
#include "../LoopAnalyzer/loop_analyzer.h"
#include "../CFGraph/CFGraph.h"

View File

@@ -1,8 +1,8 @@
#pragma once
#include <vector>
#include "dvm.h"
#include "../GraphCall/graph_calls.h"
#include "../Utils/json.hpp"
#include "graph_calls.h"
#include "json.hpp"
class ParallelStats
{

View File

@@ -1,5 +1,5 @@
#define _LEAK_
#include "../Utils/leak_detector.h"
#include "leak_detector.h"
#include <cstdio>
#include <cstring>
@@ -9,7 +9,7 @@
#include <vector>
#include <fstream>
#include "../GraphCall/graph_calls.h"
#include "graph_calls.h"
#include "private_analyzer.h"
#include "dvm.h"
#include "../CFGraph/CFGraph.h"

View File

@@ -3,7 +3,7 @@
#include <vector>
#include "dvm.h"
#include "../GraphCall/graph_calls.h"
#include "graph_calls.h"
extern void Private_Vars_Analyzer(SgStatement* start);
void PrivateAnalyzer(SgFile *file, std::vector<FuncInfo*> &funcs);

View File

@@ -9,8 +9,8 @@
#include "private_arrays_search.h"
#include "range_structures.h"
#include "region.h"
#include "../Utils/SgUtils.h"
#include "../GraphLoop/graph_loops.h"
#include "SgUtils.h"
#include "graph_loops.h"
#include "../CFGraph/CFGraph.h"
using namespace std;

View File

@@ -6,7 +6,7 @@
#include "range_structures.h"
#include "region.h"
#include "../GraphLoop/graph_loops.h"
#include "graph_loops.h"
#include "../CFGraph/CFGraph.h"
void Collapse(Region* region);

View File

@@ -2,8 +2,8 @@
#include <map>
#include <unordered_set>
#include <string>
#include <numeric>
#include "utils.h"
#include "range_structures.h"
using namespace std;
@@ -184,7 +184,8 @@ void AccessingSet::FindUncovered(const vector<ArrayDimension>& element, vector<v
newTails.insert(newTails.end(), diff.begin(), diff.end());
}
}
result = move(newTails);
result = newTails;
newTails.clear();
}
}

View File

@@ -8,7 +8,7 @@
#include "range_structures.h"
#include "region.h"
#include "../Utils/SgUtils.h"
#include "SgUtils.h"
using namespace std;
@@ -139,11 +139,14 @@ static int GetDefUseArray(SAPFOR::BasicBlock* block, LoopGraph* loop, ArrayAcces
}
if(coefsForDims.empty())
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
while (!index_vars.empty())
{
auto var = index_vars.back();
int currentVarPos = refPos.back();
pair currentCoefs = coefsForDims.back();
pair<int, int> currentCoefs = coefsForDims.back();
ArrayDimension current_dim;
if (var->getType() == SAPFOR::CFG_ARG_TYPE::CONST)
current_dim = { stoul(var->getValue()), 1, 1 };
@@ -214,7 +217,10 @@ static Region* CreateSubRegion(LoopGraph* loop, const vector<SAPFOR::BasicBlock*
if (bbToRegion.find(header) != bbToRegion.end())
region->setHeader(bbToRegion.at(header));
else
{
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
return NULL;
}
for (SAPFOR::BasicBlock* block : blockSet)
if (bbToRegion.find(block) != bbToRegion.end())
@@ -223,7 +229,6 @@ static Region* CreateSubRegion(LoopGraph* loop, const vector<SAPFOR::BasicBlock*
for (LoopGraph* childLoop : loop->children)
region->addSubRegions(CreateSubRegion(childLoop, Blocks, bbToRegion));
cout << header << endl;
return region;
}

View File

@@ -5,7 +5,7 @@
#include <unordered_set>
#include <string>
#include "../GraphLoop/graph_loops.h"
#include "graph_loops.h"
#include "../CFGraph/CFGraph.h"
class Region : public SAPFOR::BasicBlock {

View File

@@ -1,4 +1,4 @@
#include "../Utils/leak_detector.h"
#include "leak_detector.h"
#include <cstdio>
#include <cstdlib>
@@ -6,9 +6,9 @@
#include <string>
#include <vector>
#include "../Utils/errors.h"
#include "../Utils/SgUtils.h"
#include "../Utils/utils.h"
#include "errors.h"
#include "SgUtils.h"
#include "utils.h"
#include "../VerificationCode/verifications.h"

View File

@@ -1,4 +1,4 @@
#include "../Utils/leak_detector.h"
#include "leak_detector.h"
#include <cstdio>
#include <cstdlib>
@@ -7,8 +7,8 @@
#include <vector>
#include "FileInfo.h"
#include "../Utils/utils.h"
#include "../Utils/errors.h"
#include "utils.h"
#include "errors.h"
using namespace std;

View File

@@ -1,4 +1,4 @@
#include "../Utils/leak_detector.h"
#include "leak_detector.h"
#include <cstdio>
#include <cstdlib>
@@ -22,8 +22,8 @@
#include <thread>
#include <stack>
#include "../Utils/errors.h"
#include "../Utils/SgUtils.h"
#include "errors.h"
#include "SgUtils.h"
#include "../VisualizerCalls/get_information.h"
#include "../VisualizerCalls/SendMessage.h"
@@ -34,6 +34,7 @@
using namespace std;
extern "C" int parse_file(int argc, char* argv[], char* proj_name);
extern const char* VISUALIZER_DATA_PATH;
static void findModuleDeclInProject(const string& name, const vector<string>& files, map<string, string>& modDecls)
{
@@ -293,11 +294,8 @@ static vector<string> parseList(vector<FileInfo>& listOfProject,
}
}
#ifdef _WIN32
sendMessage_2lvl(L" <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> '" + to_wstring(file) + L"'");
#else
sendMessage_2lvl(L" processing file '" + to_wstring(file) + L"'");
#endif
sendMessage_2lvl(3, file);
StdCapture::Init();
string errorMessage = "";
try
@@ -443,20 +441,12 @@ static int dumpErrors(const vector<FileInfo>& listOfProject, const vector<string
if (errors[z] == "")
{
FILE* ferr = fopen(file.errPath.c_str(), "w");
if (!ferr)
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
fclose(ferr);
if (ferr)
fclose(ferr);
++z;
continue;
}
FILE* ferr = fopen(file.errPath.c_str(), "w");
FILE* fout = fopen(file.outPath.c_str(), "w");
if (!ferr)
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
if (!fout)
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
string errS = "", outS = "";
vector<string> splited;
splitString(errors[z], '\n', splited);
@@ -475,13 +465,22 @@ static int dumpErrors(const vector<FileInfo>& listOfProject, const vector<string
}
}
fprintf(fout, "%s", outS.c_str());
fprintf(ferr, "%s", errS.c_str());
FILE* ferr = fopen(file.errPath.c_str(), "w");
FILE* fout = fopen(file.outPath.c_str(), "w");
if (ferr)
{
fprintf(ferr, "%s", errS.c_str());
fclose(ferr);
}
if (fout)
{
fprintf(fout, "%s", outS.c_str());
fclose(fout);
}
fflush(NULL);
fclose(fout);
fclose(ferr);
++z;
}
@@ -576,11 +575,8 @@ static void parseFiles(int& iters, vector<string>& errors, vector<FileInfo>& lis
do
{
#ifdef _WIN32
sendMessage_1lvl(L"<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> " + std::to_wstring((iters + 1)) + L" <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
#else
sendMessage_1lvl(L"running " + std::to_wstring((iters + 1)) + L" iteration of syntax analisys");
#endif
sendMessage_1lvl(0, iters + 1);
errors = parseList(listOfProject, iters != 0, parseForInlining, mapModuleDeps, moduleDelc, modDirectOrder, isFromConsole);
changed = createMapOfUse(errors, listOfProject, mapModuleDeps);
if (iters != 0)
@@ -713,7 +709,7 @@ int parseFiles(const char* proj, vector<string>& filesCompilationOrder, int pars
if (pathSplit.size() < 2)
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
if (pathSplit[pathSplit.size() - 2] != "visualiser_data")
if (pathSplit[pathSplit.size() - 2] != VISUALIZER_DATA_PATH)
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
string fullPath = "";
for (int z = 0; z < pathSplit.size() - 2; ++z)
@@ -745,9 +741,9 @@ int parseFiles(const char* proj, vector<string>& filesCompilationOrder, int pars
else
fileNameFixed = (toAdd.substr(0, 2) == "./") ? toAdd.substr(2) : toAdd;
const string optPath = fullPath + "visualiser_data/options/" + fileNameFixed + ".opt";
const string errPath = fullPath + "visualiser_data/options/" + fileNameFixed + ".err";
const string outPath = fullPath + "visualiser_data/options/" + fileNameFixed + ".out";
const string optPath = fullPath + VISUALIZER_DATA_PATH + "/options/" + fileNameFixed + ".opt";
const string errPath = fullPath + VISUALIZER_DATA_PATH + "/options/" + fileNameFixed + ".err";
const string outPath = fullPath + VISUALIZER_DATA_PATH + "/options/" + fileNameFixed + ".out";
const string fileText = readFileToStr(toAdd);
@@ -809,6 +805,8 @@ void parseFiles(int argc, char** argv)
printf(" run parsing for inlining\n");
int rethrow = parseFiles(errors, listOfProject, filesCompilationOrder, isInline, true);
int errCount = dumpErrors(listOfProject, errors, messages);
if (rethrow == 0)
{
for (auto& err : errors)
@@ -838,5 +836,7 @@ void parseFiles(int argc, char** argv)
}
else
printf("Parsing was completed with errors, throw code %d, errors count %d\n", rethrow, code);
dumpMessages(false, messages, VISUALIZER_DATA_PATH);
exit(0);
}

View File

@@ -1,4 +1,4 @@
#include "../Utils/leak_detector.h"
#include "leak_detector.h"
#include <cstdio>
#include <cstdlib>
@@ -6,8 +6,8 @@
#include <string>
#include <vector>
#include "../Utils/errors.h"
#include "../Utils/SgUtils.h"
#include "errors.h"
#include "SgUtils.h"
#include "StdCapture.h"

View File

@@ -1,33 +1,443 @@
#include "../Utils/leak_detector.h"
#include "leak_detector.h"
#include <cstdio>
#include <cstring>
#include <cstring>
#include <fstream>
#include <iostream>
#include <cstdlib>
#include <set>
#include <string>
#include <vector>
#include <algorithm>
#include <tuple>
#include "CFGraph/CFGraph.h"
#include "CFGraph/IR.h"
#include "Distribution/Array.h"
#include "dvm.h"
#include "../Utils/errors.h"
#include "../Utils/SgUtils.h"
#include "../GraphCall/graph_calls.h"
#include "../GraphCall/graph_calls_func.h"
#include "errors.h"
#include "SgUtils.h"
#include "graph_calls.h"
#include "graph_calls_func.h"
#include "projectParameters.h"
using namespace std;
using std::set;
using std::map;
using std::string;
using std::vector;
using std::tuple;
using std::pair;
using std::make_tuple;
using std::find_if;
map< pair<string, int>, set<string>>
findParameters(const map<string, vector<DefUseList>> &defUseByFunctions,
const map<string, CommonBlock*> &commonBlocks,
const map<string, vector<FuncInfo*>> &allFuncInfo)
static map<FuncInfo*, vector<SAPFOR::Instruction*>> call_sites;
enum class MODE
{
map< pair<string, int>, set<string>> foundParameters;
return foundParameters;
}
BEFORE,
AFTER
};
template<typename Iterator>
static void extract_vars_from_reg(set<SAPFOR::Argument*>& worklist, SAPFOR::Argument* reg, Iterator instr, Iterator first_instr);
static tuple<FuncInfo*, SAPFOR::Instruction*, SAPFOR::BasicBlock*>
stmtToIR(const map<FuncInfo*, vector<SAPFOR::BasicBlock*>>& CFGraph, SgStatement* stmt)
{
SgStatement* cur = stmt;
cur->switchToFile();
while (cur->variant() != PROC_HEDR && cur->variant() != PROG_HEDR && cur->variant() != FUNC_HEDR)
cur = cur->controlParent();
string funcName = ((SgProcHedrStmt*)cur)->nameWithContains();
int stmtID = stmt->id();
for (const auto& [func, bblocks] : CFGraph)
{
if (func->funcName != funcName)
continue;
for (auto basicBlock : bblocks)
for (auto ins : basicBlock->getInstructions())
if (stmtID == ins->getInstruction()->getOperator()->id())
return make_tuple(func, ins->getInstruction(), basicBlock);
}
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
return { NULL, NULL, NULL };
}
static tuple<FuncInfo*, SAPFOR::Instruction*, SAPFOR::BasicBlock*>
IRByNumber(const map<FuncInfo*, vector<SAPFOR::BasicBlock*>>& CFGraph, int num)
{
if (num < 0)
return { NULL, NULL, NULL };
for (const auto& [func, bblocks] : CFGraph)
for (auto byBB : bblocks)
if (byBB->getInstructions().front()->getNumber() <= num && byBB->getInstructions().back()->getNumber() >= num)
return make_tuple(func, getInstructionByNumber(byBB->getInstructions(), num), byBB);
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
return { NULL, NULL, NULL };
}
template<typename Iterator>
static void processArgument(set<SAPFOR::Argument*>& worklist,
SAPFOR::Argument* arg,
Iterator instr, Iterator first_instr)
{
if (arg == NULL)
return;
if (arg->getType() == SAPFOR::CFG_ARG_TYPE::REG)
extract_vars_from_reg(worklist, arg, instr, first_instr);
else if (arg->getType() == SAPFOR::CFG_ARG_TYPE::VAR)
worklist.insert(arg);
}
template<typename Iterator>
static void extract_vars_from_reg(set<SAPFOR::Argument*>& worklist,
SAPFOR::Argument* reg,
Iterator instr, Iterator first_instr)
{
for (; instr >= first_instr; instr--)
{
if ((*instr)->getInstruction()->getResult() == reg)
{
processArgument(worklist, (*instr)->getInstruction()->getArg1(), instr, first_instr);
processArgument(worklist, (*instr)->getInstruction()->getArg2(), instr, first_instr);
return;
}
}
}
static void lookup_for_vars(set<tuple<SgStatement*, string, MODE>>& where_to_add,
set<SAPFOR::Argument*>& worklist,
SAPFOR::Instruction* instr,
SAPFOR::BasicBlock* bblock,
FuncInfo* cur_func,
const map<FuncInfo*, vector<SAPFOR::BasicBlock*>>& fullIR)
{
while (bblock)
{
auto first_instr = bblock->getInstructions().begin();
auto cur_instr = find_if(first_instr, bblock->getInstructions().end(), [instr](SAPFOR::IR_Block* i) {
return i->getInstruction() == instr;
});
for (; cur_instr >= bblock->getInstructions().begin(); --cur_instr)
{
auto instr = (*cur_instr)->getInstruction();
auto result_arg = instr->getResult();
auto arg1 = instr->getArg1();
auto arg2 = instr->getArg2();
if (worklist.count(result_arg))
{
worklist.erase(result_arg);
processArgument(worklist, arg1, cur_instr, first_instr);
processArgument(worklist, arg2, cur_instr, first_instr);
}
if (instr->getOperation() == SAPFOR::CFG_OP::PARAM && worklist.count(arg1))
{
// skip to F_CALL
auto f_call_instr = cur_instr;
while ((*f_call_instr)->getInstruction()->getOperation() != SAPFOR::CFG_OP::F_CALL)
f_call_instr++;
if ((*f_call_instr)->getInstruction()->getArg1()->getValue() == "_READ")
{
auto stmt_before = (*f_call_instr)->getInstruction()->getOperator();
auto filename = stmt_before->fileName();
auto line = stmt_before->lineNumber();
auto var_name = arg1->getValue().substr(arg1->getValue().find('%') + 1);
__spf_print(1, "Please specify value of variable %s on line %d of file %s\n", arg1->getValue().c_str(), line, filename);
auto toAdd = make_tuple(stmt_before, var_name, MODE::AFTER);
where_to_add.insert(toAdd);
worklist.erase(arg1);
}
}
}
const auto& RD = bblock->getRD_In();
map<SAPFOR::BasicBlock*, SAPFOR::Instruction*> group_by_block;
set<SAPFOR::Argument*> to_erase;
for (auto& arg : worklist)
{
if (RD.count(arg))
{
if (RD.at(arg).size() == 1 && *RD.at(arg).begin() == SAPFOR::CFG_VAL::UNINIT)
__spf_print(1, "variable %s has no definition\n", arg->getValue().c_str());
else if (RD.at(arg).size() > 1)
{
auto stmt_after = (*first_instr)->getInstruction()->getOperator();
auto filename = stmt_after->fileName();
auto line = stmt_after->lineNumber();
auto var_name = arg->getValue().substr(arg->getValue().find('%') + 1);
__spf_print(1, "variable %s has multiple reaching definitions, further analysis is impossible\n", arg->getValue().c_str());
__spf_print(1, "Please specify value of variable %s on line %d of file %s\n", arg->getValue().c_str(), line, filename);
auto toAdd = make_tuple(stmt_after, var_name, MODE::BEFORE);
where_to_add.insert(toAdd);
to_erase.insert(arg);
}
else
{
auto instr_num = *RD.at(arg).begin();
auto [func, instr, bblock] = IRByNumber(fullIR, instr_num);
if (cur_func == func && (group_by_block[bblock] == NULL || group_by_block[bblock]->getNumber() < instr_num))
group_by_block[bblock] = instr;
}
}
}
for (const auto& arg : to_erase)
worklist.erase(arg);
while (bblock && group_by_block.find(bblock) == group_by_block.end())
bblock = bblock->getDom();
if (bblock)
instr = group_by_block[bblock];
}
// other variables are from global scope
const auto& RD = fullIR.at(cur_func).front()->getRD_In();
for (auto& arg : worklist)
{
if (arg->isMemGlobal())
{
set<int> found_rd;
if (RD.count(arg))
found_rd = RD.at(arg);
if (found_rd.size() == 0)
{
auto call_instr = call_sites[cur_func].size() ? call_sites[cur_func].front() : NULL;
while (call_instr && found_rd.size() == 0)
{
auto [call_func, _, call_bblock] = IRByNumber(fullIR, call_instr->getNumber());
if (call_bblock->getRD_Out().count(arg))
found_rd = call_bblock->getRD_Out().at(arg);
call_instr = call_sites[call_func].size() ? call_sites[call_func].front() : NULL;
}
}
if (found_rd.size() == 1 && *found_rd.begin() == SAPFOR::CFG_VAL::UNINIT)
__spf_print(1, "variable %s has no definition\n", arg->getValue().c_str());
else if (found_rd.size() > 1)
{
auto first_instr = fullIR.at(cur_func).front()->getInstructions().begin();
auto stmt_after = (*first_instr)->getInstruction()->getOperator();
auto filename = stmt_after->fileName();
auto line = stmt_after->lineNumber();
auto var_name = arg->getValue().substr(arg->getValue().find('%') + 1);
__spf_print(1, "variable %s has multiple reaching definitions, further analysis is impossible\n", arg->getValue().c_str());
__spf_print(1, "Please specify value of variable %s on line %d of file %s\n", arg->getValue().c_str(), line, filename);
auto toAdd = make_tuple(stmt_after, var_name, MODE::BEFORE);
where_to_add.insert(toAdd);
}
else
{
auto instr_num = *found_rd.begin();
auto [func, instr, bblock] = IRByNumber(fullIR, instr_num);
set<SAPFOR::Argument*> new_worklist = { arg };
lookup_for_vars(where_to_add, new_worklist, instr, bblock, func, fullIR);
}
}
}
for (const auto& call_instr : call_sites[cur_func])
{
set<SAPFOR::Argument*> new_worklist;
auto params_num = cur_func->funcParams.countOfPars;
auto [call_func, _, call_bblock] = IRByNumber(fullIR, call_instr->getNumber());
auto first_instr = call_bblock->getInstructions().begin();
auto cur_instr = find_if(first_instr, call_bblock->getInstructions().end(), [call_instr](SAPFOR::IR_Block* i) {
return i->getInstruction() == call_instr;
});
for (auto& arg : worklist)
{
if (arg->getMemType() == SAPFOR::CFG_MEM_TYPE::FUNC_PARAM_)
{
auto param_num = stoi(arg->getValue().substr(arg->getValue().find('%', arg->getValue().find('%') + 1) + 1));
auto param_instr = (cur_instr - (params_num - param_num));
auto param_arg = (*param_instr)->getInstruction()->getArg1();
processArgument(new_worklist, param_arg, param_instr, first_instr);
}
}
lookup_for_vars(where_to_add, new_worklist, call_instr, call_bblock, call_func, fullIR);
}
}
static void handle_single_allocate(set<tuple<SgStatement*, string, MODE>>& where_to_add,
SgStatement* alloc_statement,
const map<FuncInfo*, vector<SAPFOR::BasicBlock*>>& fullIR)
{
auto [func, instr, bblock] = stmtToIR(fullIR, alloc_statement);
auto first_instr = bblock->getInstructions().begin();
auto cur_instr = find_if(first_instr, bblock->getInstructions().end(), [instr](SAPFOR::IR_Block* i) {
return i->getInstruction() == instr;
});
auto alloc_instr = cur_instr;
// skip to F_CALL _ALLOC n
while ((*alloc_instr)->getInstruction()->getOperation() != SAPFOR::CFG_OP::F_CALL ||
(*alloc_instr)->getInstruction()->getArg1()->getValue() != "_ALLOC")
alloc_instr++;
auto arrays_num = stoi((*alloc_instr)->getInstruction()->getArg2()->getValue());
set<SAPFOR::Argument*> worklist;
for (int i = 0; i < arrays_num; i++)
{
auto param_instr = --alloc_instr;
auto param_reg = (*param_instr)->getInstruction()->getArg1();
while ((*param_instr)->getInstruction()->getOperation() != SAPFOR::CFG_OP::LOAD ||
(*param_instr)->getInstruction()->getResult() != param_reg)
param_instr--;
auto dimensions_num = stoi((*param_instr)->getInstruction()->getArg2()->getValue());
for (int j = 0; j < dimensions_num; j++)
{
auto ref_instr = --param_instr;
if ((*ref_instr)->getInstruction()->getOperation() == SAPFOR::CFG_OP::RANGE)
{
vector<SAPFOR::Argument*> range_args = { (*ref_instr)->getInstruction()->getArg1(),
(*ref_instr)->getInstruction()->getArg2(),
(*ref_instr)->getInstruction()->getResult() };
for (auto& arg : range_args)
processArgument(worklist, arg, ref_instr, first_instr);
}
else
{
auto arg = (*ref_instr)->getInstruction()->getArg1();
processArgument(worklist, arg, ref_instr, first_instr);
}
}
}
lookup_for_vars(where_to_add, worklist, instr, bblock, func, fullIR);
}
static void handle_single_loop(set<tuple<SgStatement*, string, MODE>>& where_to_add,
SgStatement* loop_stmt,
const map<FuncInfo*, vector<SAPFOR::BasicBlock*>>& fullIR)
{
auto [func, instr, bblock] = stmtToIR(fullIR, loop_stmt);
auto cur_instr = bblock->getInstructions().end() - 1;
set<SAPFOR::Argument*> worklist;
extract_vars_from_reg(worklist, (*cur_instr)->getInstruction()->getResult(), cur_instr, bblock->getInstructions().begin());
lookup_for_vars(where_to_add, worklist, (*cur_instr)->getInstruction(), bblock, func, fullIR);
}
void findParameters(ResultSet& foundParameters,
map<FuncInfo*, vector<SAPFOR::BasicBlock*>>& fullIR,
const map<tuple<int, string, string>, pair<DIST::Array*, DIST::ArrayAccessInfo*>>& declaredArrays)
{
set<tuple<SgStatement*, string, MODE>> where_to_add;
map<string, FuncInfo*> name_to_func;
for (const auto& [func, _] : fullIR)
name_to_func[func->funcName] = func;
for (auto& [func, bblocks] : fullIR)
{
for (const auto& block : bblocks)
{
for (const auto& ir_block : block->getInstructions())
{
auto instr = ir_block->getInstruction();
if (instr->getOperation() == SAPFOR::CFG_OP::F_CALL)
{
auto func_name = instr->getArg1()->getValue();
auto func_info = name_to_func.find(func_name);
if (func_info != name_to_func.end())
call_sites[func_info->second].push_back(instr);
}
}
}
}
set<SgStatement*> alloc_statements;
for (const auto& [func, bblocks] : fullIR)
{
for (const auto& block : bblocks)
{
for (auto instr = block->getInstructions().begin(); instr != block->getInstructions().end(); ++instr)
{
auto op = (*instr)->getInstruction()->getOperator();
if (op && op->variant() == ALLOCATE_STMT)
alloc_statements.insert(op);
}
}
}
set<SgStatement*> for_statements;
// Find all FOR statements in the program
for (const auto& [func, bblocks] : fullIR)
{
for (const auto& block : bblocks)
{
for (auto instr = block->getInstructions().begin(); instr != block->getInstructions().end(); ++instr)
{
auto op = (*instr)->getInstruction()->getOperator();
if (op && op->variant() == FOR_NODE)
for_statements.insert(op);
}
}
}
for (const auto& alloc_statement : alloc_statements)
handle_single_allocate(where_to_add, alloc_statement, fullIR);
for (const auto& stmt : for_statements)
handle_single_loop(where_to_add, stmt, fullIR);
for (const auto& [stmt_before, var_name, mode] : where_to_add)
{
stmt_before->switchToFile();
SgVariableSymb* var_symb = new SgVariableSymb(var_name.c_str());
SgVarRefExp* var = new SgVarRefExp(var_symb);
SgExprListExp* ex = new SgExprListExp();
auto assgn_op = new SgExpression(ASSGN_OP, var, NULL);
ex->setLhs(assgn_op);
SgExpression* parameter_op = new SgExpression(SPF_PARAMETER_OP, ex);
auto dir_list = new SgExprListExp();
dir_list->setLhs(parameter_op);
SgStatement* toAdd = new SgStatement(SPF_ANALYSIS_DIR, NULL, NULL, dir_list, NULL, NULL);
toAdd->setlineNumber(stmt_before->lineNumber());
toAdd->setLocalLineNumber(stmt_before->lineNumber());
toAdd->setFileId(stmt_before->getFileId());
toAdd->setProject(stmt_before->getProject());
//NOTE: only for debbuging, results will be transferred to the visualizer
/*if (mode == MODE::AFTER)
stmt_before->insertStmtAfter(*toAdd, *stmt_before->controlParent());
else
stmt_before->insertStmtBefore(*toAdd, *stmt_before->controlParent());*/
foundParameters.insert(make_tuple(stmt_before->fileName(), stmt_before->lineNumber(), var_name));
}
}

View File

@@ -1,3 +1,14 @@
#pragma once
std::map< std::pair<std::string, int>, std::set<std::string>> findParameters(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);
#include <map>
#include <string>
#include <set>
#include <vector>
#include "../GraphCall/graph_calls.h"
using ResultSet = std::set<std::tuple<std::string, int, std::string>>;
void findParameters(ResultSet& foundParameters,
std::map<FuncInfo*, std::vector<SAPFOR::BasicBlock*>>& fullIR,
const std::map<std::tuple<int, std::string, std::string>, std::pair<DIST::Array*, DIST::ArrayAccessInfo*>>& declaredArrays);

View File

@@ -4,9 +4,9 @@
#include <map>
#include <string>
#include "../GraphCall/graph_calls.h"
#include "../Utils/errors.h"
#include "../Utils/utils.h"
#include "graph_calls.h"
#include "errors.h"
#include "utils.h"
#include "sage++user.h"
#include "definesValues.h"
#include "set.h"

View File

@@ -15,8 +15,8 @@ extern "C" void removeFromCollection(void *pointer);
#endif
extern int passDone;
#include "../GraphCall/graph_calls.h"
#include "../Utils/errors.h"
#include "graph_calls.h"
#include "errors.h"
#include "../VisualizerCalls/get_information.h"
#include "sage++user.h"

View File

@@ -24,8 +24,6 @@
#include "ParallelizationRegions/resolve_par_reg_conflicts.h"
#include "ParallelizationRegions/expand_extract_reg.h"
#include "Transformations/replace_dist_arrays_in_io.h"
#include "Distribution/Distribution.h"
#include "Distribution/GraphCSR.h"
#include "Distribution/Arrays.h"
@@ -57,7 +55,7 @@
#include "Distribution/CreateDistributionDirs.h"
#include "PrivateAnalyzer/private_analyzer.h"
#include "PrivateAnalyzer/private_arrays_search.h"
#include "ExpressionTransform/expr_transform.h"
#include "expr_transform.h"
#include "Predictor/PredictScheme.h"
#include "Predictor/PredictorModel.h"
@@ -73,24 +71,26 @@
#include "VisualizerCalls/SendMessage.h"
#include "VisualizerCalls/BuildGraph.h"
#include "Transformations/enddo_loop_converter.h"
#include "Transformations/loop_transform.h"
#include "Transformations/array_assign_to_loop.h"
#include "Transformations/private_arrays_resizing.h"
#include "Transformations/loops_splitter.h"
#include "Transformations/loops_combiner.h"
#include "Transformations/loops_unrolling.h"
#include "Transformations/uniq_call_chain_dup.h"
#include "Transformations/checkpoints.h"
#include "Transformations/swap_array_dims.h"
#include "Transformations/function_purifying.h"
#include "Transformations/private_removing.h"
#include "Transformations/fix_common_blocks.h"
#include "Transformations/convert_to_c.h"
#include "Transformations/set_implicit_none.h"
#include "Transformations/dead_code.h"
#include "Transformations/ReplaceArraysInIO/replace_dist_arrays_in_io.h"
#include "Transformations/LoopEndDoConverter/enddo_loop_converter.h"
#include "Transformations/LoopNesting/loop_transform.h"
#include "Transformations/VectorAssignToLoop/array_assign_to_loop.h"
#include "Transformations/PrivateArrayResizing/private_arrays_resizing.h"
#include "Transformations/LoopSplitting/loops_splitter.h"
#include "Transformations/LoopCombining/loops_combiner.h"
#include "Transformations/LoopUnrolling/loops_unrolling.h"
#include "Transformations/FunctionDuplication/uniq_call_chain_dup.h"
#include "Transformations/CheckPoints/checkpoints.h"
#include "Transformations/ArrayDimsSwapping/swap_array_dims.h"
#include "Transformations/FunctionPurifying/function_purifying.h"
#include "Transformations/PrivateArrayRemoving/private_removing.h"
#include "Transformations/GlobalVariables/fix_common_blocks.h"
#include "Transformations/ConvertToC/convert_to_c.h"
#include "Transformations/SetImplicitNone/set_implicit_none.h"
#include "Transformations/DeadCodeRemoving/dead_code.h"
#include "Transformations/RenameSymbols/rename_symbols.h"
#include "Transformations/FunctionInlining/inliner.h"
#include "RenameSymbols/rename_symbols.h"
#include "ProjectParameters/projectParameters.h"
#include "CFGraph/IR.h"
@@ -101,8 +101,6 @@
#include "CFGraph/live_variable_analysis.h"
#include "CFGraph/private_variables_analysis.h"
#include "Inliner/inliner.h"
#include "dvm.h"
#include "Sapfor.h"
#include "Utils/PassManager.h"
@@ -402,11 +400,7 @@ static bool runAnalysis(SgProject &project, const int curr_regime, const bool ne
__spf_print(DEBUG_LVL1, "RUN PASS with name %s\n", passNames[curr_regime]);
auto toSendStrMessage = string(passNames[curr_regime]);
#ifdef _WIN32
sendMessage_1lvl(wstring(L"выполняется проход '") + wstring(toSendStrMessage.begin(), toSendStrMessage.end()) + L"'");
#else
sendMessage_1lvl(wstring(L"running pass '") + wstring(toSendStrMessage.begin(), toSendStrMessage.end()) + L"'");
#endif
sendMessage_1lvl(1, toSendStrMessage);
const int n = project.numberOfFiles();
bool verifyOK = true;
@@ -454,11 +448,7 @@ static bool runAnalysis(SgProject &project, const int curr_regime, const bool ne
SgFile *file = &(project.file(i));
toSendStrMessage = file->filename();
#ifdef _WIN32
sendMessage_2lvl(wstring(L"обработка файла '") + wstring(toSendStrMessage.begin(), toSendStrMessage.end()) + L"'");
#else
sendMessage_2lvl(wstring(L"processing file '") + wstring(toSendStrMessage.begin(), toSendStrMessage.end()) + L"'");
#endif
sendMessage_2lvl(3, toSendStrMessage);
sendMessage_progress(std::to_wstring((int)(((double)(n - i) / n) * 100)));
const char *file_name = file->filename();
@@ -912,7 +902,7 @@ static bool runAnalysis(SgProject &project, const int curr_regime, const bool ne
else if (curr_regime == ADD_TEMPL_TO_USE_ONLY)
fixUseOnlyStmt(file, parallelRegions);
else if (curr_regime == GCOV_PARSER)
parse_gcovfile(file, consoleMode == 1 ? file_name : "./visualiser_data/gcov/" + string(file_name), getObjectForFileFromMap(file_name, gCovInfo), keepFiles);
parse_gcovfile(file, consoleMode == 1 ? file_name : string(VISUALIZER_DATA_PATH) + "/gcov/" + file_name, getObjectForFileFromMap(file_name, gCovInfo), keepFiles);
else if(curr_regime == PRIVATE_ARRAYS_EXPANSION)
{
auto founded = loopGraph.find(file->filename());
@@ -964,7 +954,7 @@ static bool runAnalysis(SgProject &project, const int curr_regime, const bool ne
vector<string> include_functions;
createInterTree(file, getObjectForFileFromMap(file_name, intervals), removeNestedIntervals, getObjectForFileFromMap(file_name, SPF_messages));
assignCallsToFile(consoleMode == 1 ? file_name : "./visualiser_data/gcov/" + string(file_name), getObjectForFileFromMap(file_name, intervals));
assignCallsToFile(consoleMode == 1 ? file_name : string(VISUALIZER_DATA_PATH) + "/gcov/" + file_name, getObjectForFileFromMap(file_name, intervals));
removeNodes(intervals_threshold, getObjectForFileFromMap(file_name, intervals), include_functions);
}
else if (curr_regime == INSERT_INTER_TREE)
@@ -1032,7 +1022,10 @@ static bool runAnalysis(SgProject &project, const int curr_regime, const bool ne
countOfTransform += removeDeadCode(func->funcPointer, allFuncInfo, commonBlocks);
}
else if (curr_regime == BUILD_IR_SSA_FORM)
buildIRSSAForm(fullIR, fullIR_SSA);
{
if (fullIR_SSA.size() == 0)
buildIRSSAForm(fullIR, fullIR_SSA);
}
else if (curr_regime == FIND_IMPLICIT_LOOPS)
findImplicitLoops(fullIR_SSA, file_name);
else if (curr_regime == FIND_PRIVATE_ARRAYS)
@@ -1065,7 +1058,7 @@ static bool runAnalysis(SgProject &project, const int curr_regime, const bool ne
throw -11;
}
sendMessage_2lvl(wstring(L""));
sendMessage_2lvl(2);
// ********************************** ///
/// SECOND AGGREGATION STEP ///
// ********************************** ///
@@ -1721,7 +1714,7 @@ static bool runAnalysis(SgProject &project, const int curr_regime, const bool ne
}
else if (curr_regime == GCOV_PARSER)
{
parseTimesDvmStatisticFile((consoleMode == 1) ? string("statistic.txt") : "./visualiser_data/statistic/" + string("statistic.txt"), intervals);
parseTimesDvmStatisticFile((consoleMode == 1) ? string("statistic.txt") : string(VISUALIZER_DATA_PATH) + "/statistic/statistic.txt", intervals);
//fixed count, devide by value from PROG_HEDR
SgStatement* mainUnit = findMainUnit(&project, SPF_messages);
@@ -1903,7 +1896,7 @@ static bool runAnalysis(SgProject &project, const int curr_regime, const bool ne
else if (curr_regime == RENAME_SYMBOLS)
runRenameSymbols(&project, commonBlocks);
else if (curr_regime == FIND_PARAMETERS)
parametersOfProject = findParameters(defUseByFunctions, commonBlocks, allFuncInfo);
findParameters(parametersOfProject, fullIR, declaredArrays);
else if (curr_regime == BUILD_IR)
{
auto CFG_forFile = buildCFG(commonBlocks, allFuncInfo_IR, SAPFOR::CFG_Settings(0));
@@ -1936,7 +1929,7 @@ static bool runAnalysis(SgProject &project, const int curr_regime, const bool ne
const float elapsedGlobal = duration_cast<milliseconds>(high_resolution_clock::now() - globalTime).count() / 1000.;
__spf_print(1, "PROFILE: time for this pass = %f sec (total %f sec)\n", elapsed, elapsedGlobal);
sendMessage_2lvl(wstring(L""));
sendMessage_2lvl(2);
if (internalExit != 0)
throw -1;
@@ -2670,32 +2663,12 @@ int main(int argc, char **argv)
printStackTrace();
printf("exception occurred\n");
json byFileArray = json::array();
for (auto& byFile : SPF_messages)
{
json inFile;
inFile["file"] = byFile.first;
json messages = json::array();
for (auto& message : byFile.second)
{
message.print(byFile.first);
messages.push_back(message.toJson());
}
inFile["messages"] = messages;
byFileArray.push_back(inFile);
}
json allMessages;
allMessages["allMessage"] = byFileArray;
FILE* outF = fopen("dump_messages.json", "w");
fprintf(outF, "%s", allMessages.dump().c_str());
fclose(outF);
dumpMessages(true, SPF_messages, VISUALIZER_DATA_PATH);
}
dumpMessages(false, SPF_messages, VISUALIZER_DATA_PATH);
deleteAllAllocatedData(withDel);
#if _WIN32 && _DEBUG
if (leakMemDump)
{

View File

@@ -49,6 +49,7 @@ bool withTemplateInfo = false;
bool inlcudeAllFiles = false; // for pass INSERT_INLCUDES
bool runAsClient = false; // run console project as client for Visualizer
bool printSymbTable = false;
const char* VISUALIZER_DATA_PATH = "visualiser_data";
uint64_t currentAvailMemory = 0;
int QUALITY; // quality of conflicts search in graph
@@ -168,7 +169,7 @@ std::map<int, UserFiles> filesInfo; // information about open,close,write and re
//
//for FIND_PARAMETERS
std::map< std::pair<std::string, int>, std::set<std::string>> parametersOfProject; // [file, line] -> set[vars]
std::set<std::tuple<std::string, int, std::string>> parametersOfProject; // [file, line, varname]
//
//for GET_MIN_MAX_BLOCK_DIST

View File

@@ -11,9 +11,9 @@
#include "../Distribution/Array.h"
#include "dvm.h"
#include "../Utils/errors.h"
#include "../Utils/utils.h"
#include "../Utils/SgUtils.h"
#include "errors.h"
#include "utils.h"
#include "SgUtils.h"
using namespace std;

Some files were not shown because too many files have changed in this diff Show More