4 Commits

Author SHA1 Message Date
Egor Mayorov
600094f13a Some actions simplify analyzing IR 2025-05-13 00:47:25 +03:00
Egor Mayorov
5052e7e218 Pass with output file added 2025-04-15 18:10:13 +03:00
Egor Mayorov
d78c86a7dc change pass deps 2025-03-29 15:41:58 +03:00
Egor Mayorov
83c07da3cc New pass 2025-03-25 15:20:13 +03:00
6 changed files with 128 additions and 2 deletions

View File

@@ -177,6 +177,8 @@ set(TR_IMPLICIT_NONE src/Transformations/set_implicit_none.cpp
src/Transformations/set_implicit_none.h) src/Transformations/set_implicit_none.h)
set(TR_REPLACE_ARRAYS_IN_IO src/Transformations/replace_dist_arrays_in_io.cpp set(TR_REPLACE_ARRAYS_IN_IO src/Transformations/replace_dist_arrays_in_io.cpp
src/Transformations/replace_dist_arrays_in_io.h) src/Transformations/replace_dist_arrays_in_io.h)
SET(SWAP_OPERATORS src/SwapOperators/swapOperators.cpp
src/SwapOperators/swapOperators.h)
set(TRANSFORMS set(TRANSFORMS
${TR_DEAD_CODE} ${TR_DEAD_CODE}
@@ -405,7 +407,8 @@ set(SOURCE_EXE
${ZLIB} ${ZLIB}
${GR_LAYOUT} ${GR_LAYOUT}
${PR_PARAM} ${PR_PARAM}
${PROJ_MAN}) ${PROJ_MAN}
${SWAP_OPERATORS})
add_executable(Sapfor_F ${SOURCE_EXE}) add_executable(Sapfor_F ${SOURCE_EXE})
source_group (CFGraph FILES ${CFG}) source_group (CFGraph FILES ${CFG})
@@ -449,6 +452,7 @@ source_group (Utils FILES ${UTILS})
source_group (VerificationCode FILES ${VERIF}) source_group (VerificationCode FILES ${VERIF})
source_group (ProjectParameters FILES ${PR_PARAM}) source_group (ProjectParameters FILES ${PR_PARAM})
source_group (ProjectManipulation FILES ${PROJ_MAN}) source_group (ProjectManipulation FILES ${PROJ_MAN})
source_group (SwapOperators FILES ${SWAP_OPERATORS})
source_group (VisualizerCalls FILES ${VS_CALLS}) source_group (VisualizerCalls FILES ${VS_CALLS})
source_group (VisualizerCalls\\GraphLayout FILES ${GR_LAYOUT}) source_group (VisualizerCalls\\GraphLayout FILES ${GR_LAYOUT})

View File

@@ -70,6 +70,8 @@
#include "VisualizerCalls/SendMessage.h" #include "VisualizerCalls/SendMessage.h"
#include "VisualizerCalls/BuildGraph.h" #include "VisualizerCalls/BuildGraph.h"
#include "SwapOperators/swapOperators.h"
#include "Transformations/enddo_loop_converter.h" #include "Transformations/enddo_loop_converter.h"
#include "Transformations/loop_transform.h" #include "Transformations/loop_transform.h"
#include "Transformations/array_assign_to_loop.h" #include "Transformations/array_assign_to_loop.h"
@@ -938,6 +940,10 @@ static bool runAnalysis(SgProject &project, const int curr_regime, const bool ne
internalExit = err; internalExit = err;
} }
} }
else if (curr_regime == SWAP_OPERATORS)
{
runSwapOperators(file, loopGraph, fullIR, countOfTransform);
}
else if (curr_regime == PRIVATE_REMOVING_ANALYSIS) else if (curr_regime == PRIVATE_REMOVING_ANALYSIS)
{ {
auto itFound = loopGraph.find(file->filename()); auto itFound = loopGraph.find(file->filename());
@@ -1034,7 +1040,8 @@ static bool runAnalysis(SgProject &project, const int curr_regime, const bool ne
PRIVATE_REMOVING, PRIVATE_REMOVING,
PRIVATE_ARRAYS_EXPANSION, PRIVATE_ARRAYS_EXPANSION,
PRIVATE_ARRAYS_SHRINKING, PRIVATE_ARRAYS_SHRINKING,
REMOVE_DEAD_CODE }; REMOVE_DEAD_CODE,
SWAP_OPERATORS };
if ((countOfTransform == 0 || internalExit > 0) && applyFor.find(curr_regime) != applyFor.end()) if ((countOfTransform == 0 || internalExit > 0) && applyFor.find(curr_regime) != applyFor.end())
{ {
@@ -2325,6 +2332,7 @@ void runPass(const int curr_regime, const char *proj_name, const char *folderNam
case INSERT_NO_DISTR_FLAGS_FROM_GUI: case INSERT_NO_DISTR_FLAGS_FROM_GUI:
case PRIVATE_REMOVING: case PRIVATE_REMOVING:
case RENAME_INLCUDES: case RENAME_INLCUDES:
case SWAP_OPERATORS:
runAnalysis(*project, curr_regime, true, "", folderName); runAnalysis(*project, curr_regime, true, "", folderName);
break; break;
case INLINE_PROCEDURES: case INLINE_PROCEDURES:

View File

@@ -122,6 +122,8 @@ enum passes {
CREATE_INTER_TREE, CREATE_INTER_TREE,
INSERT_INTER_TREE, INSERT_INTER_TREE,
SWAP_OPERATORS,
SHADOW_GROUPING, SHADOW_GROUPING,
INLINE_PROCEDURES, INLINE_PROCEDURES,
FILL_PARALLEL_REG_IR, FILL_PARALLEL_REG_IR,
@@ -315,6 +317,7 @@ static void setPassValues()
passNames[CHECK_PAR_REG_DIR] = "CHECK_PAR_REG_DIR"; passNames[CHECK_PAR_REG_DIR] = "CHECK_PAR_REG_DIR";
passNames[CREATE_INTER_TREE] = "CREATE_INTER_TREE"; passNames[CREATE_INTER_TREE] = "CREATE_INTER_TREE";
passNames[INSERT_INTER_TREE] = "INSERT_INTER_TREE"; passNames[INSERT_INTER_TREE] = "INSERT_INTER_TREE";
passNames[SWAP_OPERATORS] = "SWAP_OPERATORS";
passNames[CREATE_PARALLEL_REGIONS] = "CREATE_PARALLEL_REGIONS"; passNames[CREATE_PARALLEL_REGIONS] = "CREATE_PARALLEL_REGIONS";
passNames[PRIVATE_REMOVING_ANALYSIS] = "PRIVATE_REMOVING_ANALYSIS"; passNames[PRIVATE_REMOVING_ANALYSIS] = "PRIVATE_REMOVING_ANALYSIS";
passNames[PRIVATE_REMOVING] = "PRIVATE_REMOVING"; passNames[PRIVATE_REMOVING] = "PRIVATE_REMOVING";

View File

@@ -0,0 +1,103 @@
#include <map>
#include <unordered_set>
#include <vector>
#include <queue>
#include <iostream>
#include "../Utils/errors.h"
#include "../Utils/SgUtils.h"
#include "../GraphCall/graph_calls.h"
#include "../GraphCall/graph_calls_func.h"
#include "../CFGraph/CFGraph.h"
#include "../CFGraph/IR.h"
#include "../GraphLoop/graph_loops.h"
#include "swapOperators.h"
using namespace std;
unordered_set<int> loop_tags = {FOR_NODE/*, FORALL_NODE, WHILE_NODE, DO_WHILE_NODE*/};
vector<SAPFOR::IR_Block*> findInstructionsFromOperator(SgStatement* st, vector<SAPFOR::BasicBlock*> Blocks)
{
vector<SAPFOR::IR_Block*> result;
string filename = st -> fileName();
for (auto& block: Blocks)
{
vector<SAPFOR::IR_Block*> instructionsInBlock = block -> getInstructions();
for (auto& instruction: instructionsInBlock)
{
SgStatement* curOperator = instruction -> getInstruction() -> getOperator();
if (curOperator -> lineNumber() == st -> lineNumber())
result.push_back(instruction);
}
}
return result;
}
vector<SAPFOR::BasicBlock*> findFuncBlocksByFuncStatement(SgStatement *st, std::map<FuncInfo*, std::vector<SAPFOR::BasicBlock*>>& FullIR)
{
vector<SAPFOR::BasicBlock*> result;
Statement* forSt = (Statement*)st;
for (auto& func : FullIR)
{
if (func.first -> funcPointer -> getCurrProcessFile() == forSt -> getCurrProcessFile()
&& func.first -> funcPointer -> lineNumber() == forSt -> lineNumber())
result = func.second;
}
return result;
}
map<SgForStmt*, vector<SAPFOR::BasicBlock*>> findAndAnalyzeLoops(SgStatement *st, vector<SAPFOR::BasicBlock*> blocks)
{
map<SgForStmt*, vector<SAPFOR::BasicBlock*>> result;
SgStatement *lastNode = st->lastNodeOfStmt();
while (st && st != lastNode)
{
if (loop_tags.find(st -> variant()) != loop_tags.end())
{
// part with find statements of loop
SgForStmt *forSt = (SgForStmt*)st;
SgStatement *loopBody = forSt -> body();
SgStatement *lastLoopNode = st->lastNodeOfStmt();
// part with find blocks and instructions of loops
while (loopBody && loopBody != lastLoopNode)
{
SAPFOR::IR_Block* IR = findInstructionsFromOperator(loopBody, blocks).front();
result[forSt].push_back(IR -> getBasicBlock()); // change this part for taking only unique blocks to vector
loopBody = loopBody -> lexNext();
}
}
st = st -> lexNext();
}
return result;
}
vector<pair<int, int>> AnalyzeLoop(SgForStmt* forStatement, vector<SAPFOR::BasicBlock*> loopBlocks)
{
vector<pair<int, int>> result;
// Analyze loop and create rules for moving operators in loops
// Return vector with moving rules (from line to line for operators)
return result;
}
void runSwapOperators(SgFile *file, std::map<std::string, std::vector<LoopGraph*>>& loopGraph, std::map<FuncInfo*, std::vector<SAPFOR::BasicBlock*>>& FullIR, int& countOfTransform)
{
std::cout << "SWAP_OPERATORS Pass" << std::endl; // to remove
countOfTransform += 1; // to remove
const int funcNum = file->numberOfFunctions();
for (int i = 0; i < funcNum; ++i)
{
SgStatement *st = file->functions(i);
vector<SAPFOR::BasicBlock*> blocks = findFuncBlocksByFuncStatement(st, FullIR);
map<SgForStmt*, vector<SAPFOR::BasicBlock*>> loopsMapping = findAndAnalyzeLoops(st, blocks);
for (pair<SgForStmt*, vector<SAPFOR::BasicBlock*>> loopForAnalyze: loopsMapping)
{
vector<pair<int, int>> moveRules = AnalyzeLoop(loopForAnalyze.first, loopForAnalyze.second);
}
}
return;
};

View File

@@ -0,0 +1,6 @@
#pragma once
#include "../GraphLoop/graph_loops.h"
#include "../CFGraph/CFGraph.h"
void runSwapOperators(SgFile *file, std::map<std::string, std::vector<LoopGraph*>>& loopGraph, std::map<FuncInfo*, std::vector<SAPFOR::BasicBlock*>>& FullIR, int& countOfTransform);

View File

@@ -212,6 +212,8 @@ void InitPassesDependencies(map<passes, vector<passes>> &passDepsIn, set<passes>
Pass(BUILD_IR) <= Pass(SUBST_EXPR_RD) <= Pass(SUBST_EXPR_RD_AND_UNPARSE); Pass(BUILD_IR) <= Pass(SUBST_EXPR_RD) <= Pass(SUBST_EXPR_RD_AND_UNPARSE);
list({BUILD_IR, CALL_GRAPH2}) <= Pass(SWAP_OPERATORS);
list({ LOOP_ANALYZER_DATA_DIST_S1, SUBST_EXPR_RD } ) <= Pass(PRIVATE_REMOVING_ANALYSIS); list({ LOOP_ANALYZER_DATA_DIST_S1, SUBST_EXPR_RD } ) <= Pass(PRIVATE_REMOVING_ANALYSIS);
list({ PRIVATE_REMOVING_ANALYSIS, REVERT_SUBST_EXPR_RD }) <= Pass(PRIVATE_REMOVING); list({ PRIVATE_REMOVING_ANALYSIS, REVERT_SUBST_EXPR_RD }) <= Pass(PRIVATE_REMOVING);