Compare commits
5 Commits
par_reg_me
...
309fc575d5
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
309fc575d5 | ||
|
|
4b24d19d5b | ||
|
|
6bf8e54d78 | ||
|
|
df0a89ffd5 | ||
|
|
f66a100e68 |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -74,8 +74,6 @@ Sapfor/Sapc++/Sapc++/x64/
|
|||||||
Sapfor/Sapc++/x64/
|
Sapfor/Sapc++/x64/
|
||||||
|
|
||||||
/build
|
/build
|
||||||
/cmake-build-debug
|
|
||||||
|
|
||||||
Sapfor/out/
|
Sapfor/out/
|
||||||
Sapfor/_bin/*
|
Sapfor/_bin/*
|
||||||
_bin/*
|
|
||||||
|
|||||||
141
CMakeLists.txt
141
CMakeLists.txt
@@ -12,7 +12,6 @@ add_definitions("-D SYS5")
|
|||||||
add_definitions("-D YYDEBUG")
|
add_definitions("-D YYDEBUG")
|
||||||
|
|
||||||
set(CMAKE_CXX_STANDARD 17)
|
set(CMAKE_CXX_STANDARD 17)
|
||||||
set(CMAKE_C_STANDARD 17)
|
|
||||||
|
|
||||||
set(fdvm_include projects/dvm/fdvmh/include/fdvmh/)
|
set(fdvm_include projects/dvm/fdvmh/include/fdvmh/)
|
||||||
set(fdvm_sources projects/dvm/fdvmh/tools/fdvmh/)
|
set(fdvm_sources projects/dvm/fdvmh/tools/fdvmh/)
|
||||||
@@ -28,14 +27,6 @@ set(libpred_sources projects/libpredictor/src/)
|
|||||||
set(libpred_include projects/libpredictor/include/)
|
set(libpred_include projects/libpredictor/include/)
|
||||||
|
|
||||||
include_directories(src)
|
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)
|
|
||||||
include_directories(src/Transformations)
|
|
||||||
|
|
||||||
#Sage lib includes
|
#Sage lib includes
|
||||||
include_directories(${fdvm_include})
|
include_directories(${fdvm_include})
|
||||||
include_directories(${sage_include_1})
|
include_directories(${sage_include_1})
|
||||||
@@ -122,13 +113,7 @@ set(OMEGA src/SageAnalysisTool/OmegaForSage/add-assert.cpp
|
|||||||
src/SageAnalysisTool/set.cpp)
|
src/SageAnalysisTool/set.cpp)
|
||||||
|
|
||||||
set(PRIV src/PrivateAnalyzer/private_analyzer.cpp
|
set(PRIV src/PrivateAnalyzer/private_analyzer.cpp
|
||||||
src/PrivateAnalyzer/private_analyzer.h
|
src/PrivateAnalyzer/private_analyzer.h)
|
||||||
src/PrivateAnalyzer/private_arrays_search.cpp
|
|
||||||
src/PrivateAnalyzer/private_arrays_search.h
|
|
||||||
src/PrivateAnalyzer/range_structures.cpp
|
|
||||||
src/PrivateAnalyzer/range_structures.h
|
|
||||||
src/PrivateAnalyzer/region.cpp
|
|
||||||
src/PrivateAnalyzer/region.h)
|
|
||||||
|
|
||||||
set(FDVM ${fdvm_sources}/acc.cpp
|
set(FDVM ${fdvm_sources}/acc.cpp
|
||||||
${fdvm_sources}/acc_across.cpp
|
${fdvm_sources}/acc_across.cpp
|
||||||
@@ -161,59 +146,42 @@ set(PARALLEL_REG src/ParallelizationRegions/ParRegions.cpp
|
|||||||
src/ParallelizationRegions/expand_extract_reg.cpp
|
src/ParallelizationRegions/expand_extract_reg.cpp
|
||||||
src/ParallelizationRegions/expand_extract_reg.h
|
src/ParallelizationRegions/expand_extract_reg.h
|
||||||
src/ParallelizationRegions/resolve_par_reg_conflicts.cpp
|
src/ParallelizationRegions/resolve_par_reg_conflicts.cpp
|
||||||
src/ParallelizationRegions/resolve_par_reg_conflicts.h
|
src/ParallelizationRegions/resolve_par_reg_conflicts.h)
|
||||||
src/ParallelizationRegions/uniq_name_creator.cpp
|
|
||||||
src/ParallelizationRegions/uniq_name_creator.h)
|
|
||||||
|
|
||||||
set(ARRAY_PROP src/ArrayConstantPropagation/propagation.cpp
|
set(TR_DEAD_CODE src/Transformations/dead_code.cpp
|
||||||
src/ArrayConstantPropagation/propagation.h
|
src/Transformations/dead_code.h)
|
||||||
)
|
set(TR_CP src/Transformations/checkpoints.cpp
|
||||||
set(MERGE_REGIONS src/ParallelizationRegions/merge_regions.cpp
|
src/Transformations/checkpoints.h)
|
||||||
src/ParallelizationRegions/merge_regions.h)
|
set(TR_VECTOR src/Transformations/array_assign_to_loop.cpp
|
||||||
|
src/Transformations/array_assign_to_loop.h)
|
||||||
set(TR_DEAD_CODE src/Transformations/DeadCodeRemoving/dead_code.cpp
|
set(TR_ENDDO_LOOP src/Transformations/enddo_loop_converter.cpp
|
||||||
src/Transformations/DeadCodeRemoving/dead_code.h)
|
src/Transformations/enddo_loop_converter.h)
|
||||||
set(TR_CP src/Transformations/CheckPoints/checkpoints.cpp
|
set(TR_LOOP_NEST src/Transformations/loop_transform.cpp
|
||||||
src/Transformations/CheckPoints/checkpoints.h)
|
src/Transformations/loop_transform.h)
|
||||||
set(TR_VECTOR src/Transformations/VectorAssignToLoop/array_assign_to_loop.cpp
|
set(TR_LOOP_COMB src/Transformations/loops_combiner.cpp
|
||||||
src/Transformations/VectorAssignToLoop/array_assign_to_loop.h)
|
src/Transformations/loops_combiner.h)
|
||||||
set(TR_ENDDO_LOOP src/Transformations/LoopEndDoConverter/enddo_loop_converter.cpp
|
set(TR_LOOP_SPLIT src/Transformations/loops_splitter.cpp
|
||||||
src/Transformations/LoopEndDoConverter/enddo_loop_converter.h)
|
src/Transformations/loops_splitter.h)
|
||||||
set(TR_LOOP_NEST src/Transformations/LoopNesting/loop_transform.cpp
|
set(TR_LOOP_UNROLL src/Transformations/loops_unrolling.cpp
|
||||||
src/Transformations/LoopNesting/loop_transform.h)
|
src/Transformations/loops_unrolling.h)
|
||||||
set(TR_LOOP_COMB src/Transformations/LoopCombining/loops_combiner.cpp
|
set(TR_PRIV_BR src/Transformations/private_arrays_resizing.cpp
|
||||||
src/Transformations/LoopCombining/loops_combiner.h)
|
src/Transformations/private_arrays_resizing.h)
|
||||||
set(TR_LOOP_SPLIT src/Transformations/LoopSplitting/loops_splitter.cpp
|
set(TR_PRIV_DEL src/Transformations/private_removing.cpp
|
||||||
src/Transformations/LoopSplitting/loops_splitter.h)
|
src/Transformations/private_removing.h)
|
||||||
set(TR_LOOP_UNROLL src/Transformations/LoopUnrolling/loops_unrolling.cpp
|
set(TR_SWAP_ARR_DIMS src/Transformations/swap_array_dims.cpp
|
||||||
src/Transformations/LoopUnrolling/loops_unrolling.h)
|
src/Transformations/swap_array_dims.h)
|
||||||
set(TR_PRIV_BR src/Transformations/PrivateArrayResizing/private_arrays_resizing.cpp
|
set(TR_FUNC_DUP src/Transformations/uniq_call_chain_dup.cpp
|
||||||
src/Transformations/PrivateArrayResizing/private_arrays_resizing.h)
|
src/Transformations/uniq_call_chain_dup.h)
|
||||||
set(TR_PRIV_DEL src/Transformations/PrivateArrayRemoving/private_removing.cpp
|
set(TR_FUNC_PURE src/Transformations/function_purifying.cpp
|
||||||
src/Transformations/PrivateArrayRemoving/private_removing.h)
|
src/Transformations/function_purifying.h)
|
||||||
set(TR_SWAP_ARR_DIMS src/Transformations/ArrayDimsSwapping/swap_array_dims.cpp
|
set(TR_GV src/Transformations/fix_common_blocks.cpp
|
||||||
src/Transformations/ArrayDimsSwapping/swap_array_dims.h)
|
src/Transformations/fix_common_blocks.h)
|
||||||
set(TR_FUNC_DUP src/Transformations/FunctionDuplication/uniq_call_chain_dup.cpp
|
set(TR_CONV src/Transformations/convert_to_c.cpp
|
||||||
src/Transformations/FunctionDuplication/uniq_call_chain_dup.h)
|
src/Transformations/convert_to_c.h)
|
||||||
set(TR_FUNC_PURE src/Transformations/FunctionPurifying/function_purifying.cpp
|
set(TR_IMPLICIT_NONE src/Transformations/set_implicit_none.cpp
|
||||||
src/Transformations/FunctionPurifying/function_purifying.h)
|
src/Transformations/set_implicit_none.h)
|
||||||
set(TR_GV src/Transformations/GlobalVariables/fix_common_blocks.cpp
|
set(TR_REPLACE_ARRAYS_IN_IO src/Transformations/replace_dist_arrays_in_io.cpp
|
||||||
src/Transformations/GlobalVariables/fix_common_blocks.h)
|
src/Transformations/replace_dist_arrays_in_io.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(TR_MOVE_OPERATORS src/Transformations/MoveOperators/move_operators.cpp
|
|
||||||
src/Transformations/MoveOperators/move_operators.h)
|
|
||||||
|
|
||||||
set(TRANSFORMS
|
set(TRANSFORMS
|
||||||
${TR_DEAD_CODE}
|
${TR_DEAD_CODE}
|
||||||
@@ -233,16 +201,10 @@ set(TRANSFORMS
|
|||||||
${TR_CONV}
|
${TR_CONV}
|
||||||
${TR_PRIV_DEL}
|
${TR_PRIV_DEL}
|
||||||
${TR_IMPLICIT_NONE}
|
${TR_IMPLICIT_NONE}
|
||||||
${TR_REPLACE_ARRAYS_IN_IO}
|
${TR_REPLACE_ARRAYS_IN_IO})
|
||||||
${TR_EXPR_TRANSFORM}
|
|
||||||
${TR_INLINER}
|
|
||||||
${TR_RENAME_SYMBOLS}
|
|
||||||
${TR_MOVE_OPERATORS})
|
|
||||||
|
|
||||||
set(CFG src/CFGraph/IR.cpp
|
set(CFG src/CFGraph/IR.cpp
|
||||||
src/CFGraph/IR.h
|
src/CFGraph/IR.h
|
||||||
src/CFGraph/IR_domTree.cpp
|
|
||||||
src/CFGraph/IR_domTree.h
|
|
||||||
src/CFGraph/CFGraph.cpp
|
src/CFGraph/CFGraph.cpp
|
||||||
src/CFGraph/CFGraph.h
|
src/CFGraph/CFGraph.h
|
||||||
src/CFGraph/RD_subst.cpp
|
src/CFGraph/RD_subst.cpp
|
||||||
@@ -321,6 +283,10 @@ set(DYNA src/DynamicAnalysis/createParallelRegions.cpp
|
|||||||
src/DynamicAnalysis/gCov_parser.cpp
|
src/DynamicAnalysis/gCov_parser.cpp
|
||||||
src/DynamicAnalysis/gCov_parser_func.h)
|
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
|
set(GR_CALL src/GraphCall/graph_calls.cpp
|
||||||
src/GraphCall/graph_calls.h
|
src/GraphCall/graph_calls.h
|
||||||
src/GraphCall/graph_calls_base.cpp
|
src/GraphCall/graph_calls_base.cpp
|
||||||
@@ -331,11 +297,18 @@ set(GR_LOOP src/GraphLoop/graph_loops_base.cpp
|
|||||||
src/GraphLoop/graph_loops.h
|
src/GraphLoop/graph_loops.h
|
||||||
src/GraphLoop/graph_loops_func.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
|
set(LOOP_ANALYZER src/LoopAnalyzer/allocations_prepoc.cpp
|
||||||
src/LoopAnalyzer/dep_analyzer.cpp
|
src/LoopAnalyzer/dep_analyzer.cpp
|
||||||
src/LoopAnalyzer/loop_analyzer.cpp
|
src/LoopAnalyzer/loop_analyzer.cpp
|
||||||
src/LoopAnalyzer/loop_analyzer.h)
|
src/LoopAnalyzer/loop_analyzer.h)
|
||||||
|
|
||||||
|
set(RENAME_SYMBOLS src/RenameSymbols/rename_symbols.cpp
|
||||||
|
src/RenameSymbols/rename_symbols.h)
|
||||||
|
|
||||||
|
|
||||||
set(MAIN src/Sapfor.cpp
|
set(MAIN src/Sapfor.cpp
|
||||||
src/Sapfor.h
|
src/Sapfor.h
|
||||||
src/SapforData.h
|
src/SapforData.h
|
||||||
@@ -425,14 +398,15 @@ set(SOURCE_EXE
|
|||||||
${DISTR}
|
${DISTR}
|
||||||
${DVMH_REG}
|
${DVMH_REG}
|
||||||
${DYNA}
|
${DYNA}
|
||||||
|
${EXPR_TRANSFORM}
|
||||||
${GR_CALL}
|
${GR_CALL}
|
||||||
${GR_LOOP}
|
${GR_LOOP}
|
||||||
|
${INLINER}
|
||||||
${LOOP_ANALYZER}
|
${LOOP_ANALYZER}
|
||||||
|
${RENAME_SYMBOLS}
|
||||||
${TRANSFORMS}
|
${TRANSFORMS}
|
||||||
${PARALLEL_REG}
|
${PARALLEL_REG}
|
||||||
${MERGE_REGIONS}
|
|
||||||
${PRIV}
|
${PRIV}
|
||||||
${ARRAY_PROP}
|
|
||||||
${FDVM}
|
${FDVM}
|
||||||
${OMEGA}
|
${OMEGA}
|
||||||
${UTILS}
|
${UTILS}
|
||||||
@@ -453,7 +427,7 @@ source_group (CFGraph FILES ${CFG})
|
|||||||
source_group (CFGraph\\DataFlow FILES ${DATA_FLOW})
|
source_group (CFGraph\\DataFlow FILES ${DATA_FLOW})
|
||||||
|
|
||||||
source_group (Transformations\\DeadCodeRemoving FILES ${TR_DEAD_CODE})
|
source_group (Transformations\\DeadCodeRemoving FILES ${TR_DEAD_CODE})
|
||||||
source_group (Transformations\\ExpressionSubstitution FILES ${TR_EXPR_TRANSFORM})
|
source_group (Transformations\\ExpressionSubstitution FILES ${EXPR_TRANSFORM})
|
||||||
source_group (Transformations\\CheckPoints FILES ${TR_CP})
|
source_group (Transformations\\CheckPoints FILES ${TR_CP})
|
||||||
source_group (Transformations\\LoopEndDoConverter FILES ${TR_ENDDO_LOOP})
|
source_group (Transformations\\LoopEndDoConverter FILES ${TR_ENDDO_LOOP})
|
||||||
source_group (Transformations\\LoopNesting FILES ${TR_LOOP_NEST})
|
source_group (Transformations\\LoopNesting FILES ${TR_LOOP_NEST})
|
||||||
@@ -461,18 +435,17 @@ source_group (Transformations\\LoopCombining FILES ${TR_LOOP_COMB})
|
|||||||
source_group (Transformations\\LoopSplitting FILES ${TR_LOOP_SPLIT})
|
source_group (Transformations\\LoopSplitting FILES ${TR_LOOP_SPLIT})
|
||||||
source_group (Transformations\\LoopUnrolling FILES ${TR_LOOP_UNROLL})
|
source_group (Transformations\\LoopUnrolling FILES ${TR_LOOP_UNROLL})
|
||||||
source_group (Transformations\\FunctionDuplication FILES ${TR_FUNC_DUP})
|
source_group (Transformations\\FunctionDuplication FILES ${TR_FUNC_DUP})
|
||||||
source_group (Transformations\\FunctionInlining FILES ${TR_INLINER})
|
source_group (Transformations\\FunctionInlining FILES ${INLINER})
|
||||||
source_group (Transformations\\FunctionPurifying FILES ${TR_FUNC_PURE})
|
source_group (Transformations\\FunctionPurifying FILES ${TR_FUNC_PURE})
|
||||||
source_group (Transformations\\ArrayDimsSwapping FILES ${TR_SWAP_ARR_DIMS})
|
source_group (Transformations\\ArrayDimsSwapping FILES ${TR_SWAP_ARR_DIMS})
|
||||||
source_group (Transformations\\PrivateArrayResizing FILES ${TR_PRIV_BR})
|
source_group (Transformations\\PrivateArrayResizing FILES ${TR_PRIV_BR})
|
||||||
source_group (Transformations\\PrivateArrayRemoving FILES ${TR_PRIV_DEL})
|
source_group (Transformations\\PrivateArrayRemoving FILES ${TR_PRIV_DEL})
|
||||||
source_group (Transformations\\VectorAssignToLoop FILES ${TR_VECTOR})
|
source_group (Transformations\\VectorAssignToLoop FILES ${TR_VECTOR})
|
||||||
source_group (Transformations\\RenameSymbols FILES ${TR_RENAME_SYMBOLS})
|
source_group (Transformations\\RenameSymbols FILES ${RENAME_SYMBOLS})
|
||||||
source_group (Transformations\\GlobalVariables FILES ${TR_GV})
|
source_group (Transformations\\GlobalVariables FILES ${TR_GV})
|
||||||
source_group (Transformations\\ConvertToC FILES ${TR_CONV})
|
source_group (Transformations\\ConvertToC FILES ${TR_CONV})
|
||||||
source_group (Transformations\\SetImplicitNone FILES ${TR_IMPLICIT_NONE})
|
source_group (Transformations\\SetImplicitNone FILES ${TR_IMPLICIT_NONE})
|
||||||
source_group (Transformations\\ReplaceArraysInIO FILES ${TR_REPLACE_ARRAYS_IN_IO})
|
source_group (Transformations\\ReplaceArraysInIO FILES ${TR_REPLACE_ARRAYS_IN_IO})
|
||||||
source_group (Transformations\\MoveOperators FILES ${TR_MOVE_OPERATORS})
|
|
||||||
|
|
||||||
|
|
||||||
source_group (CreateIntervals FILES ${CREATE_INTER_T})
|
source_group (CreateIntervals FILES ${CREATE_INTER_T})
|
||||||
@@ -484,9 +457,7 @@ source_group (GraphCall FILES ${GR_CALL})
|
|||||||
source_group (GraphLoop FILES ${GR_LOOP})
|
source_group (GraphLoop FILES ${GR_LOOP})
|
||||||
source_group (LoopAnalyzer FILES ${LOOP_ANALYZER})
|
source_group (LoopAnalyzer FILES ${LOOP_ANALYZER})
|
||||||
source_group (ParallelizationRegions FILES ${PARALLEL_REG})
|
source_group (ParallelizationRegions FILES ${PARALLEL_REG})
|
||||||
source_group (MergeRegions FILES ${MERGE_REGIONS})
|
|
||||||
source_group (PrivateAnalyzer FILES ${PRIV})
|
source_group (PrivateAnalyzer FILES ${PRIV})
|
||||||
source_group (ArrayConstantPropagation FILES ${ARRAY_PROP})
|
|
||||||
source_group (FDVM_Compiler FILES ${FDVM})
|
source_group (FDVM_Compiler FILES ${FDVM})
|
||||||
source_group (SageExtension FILES ${OMEGA})
|
source_group (SageExtension FILES ${OMEGA})
|
||||||
source_group (Utils FILES ${UTILS})
|
source_group (Utils FILES ${UTILS})
|
||||||
@@ -512,9 +483,7 @@ else()
|
|||||||
else()
|
else()
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
|
||||||
endif()
|
endif()
|
||||||
if(NOT CMAKE_BUILD_TYPE)
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2")
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
|
|
||||||
endif()
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
add_subdirectory(projects/Fdvm)
|
add_subdirectory(projects/Fdvm)
|
||||||
|
|||||||
Submodule projects/dvm updated: ab99430aee...3a567d7582
Submodule projects/libpredictor updated: 7e57477dfa...d0772cdb57
@@ -1,380 +0,0 @@
|
|||||||
#include "propagation.h"
|
|
||||||
|
|
||||||
#include "../Utils/SgUtils.h"
|
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
#include <functional>
|
|
||||||
#include <unordered_map>
|
|
||||||
#include <unordered_set>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
namespace {
|
|
||||||
|
|
||||||
struct MyHash {
|
|
||||||
size_t operator()(const SgSymbol* s) const {
|
|
||||||
return std::hash<std::string_view>{}(s->identifier());
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
struct MyEq {
|
|
||||||
bool operator()(const SgSymbol* a, const SgSymbol* b) const {
|
|
||||||
return std::strcmp(a->identifier(), b->identifier()) == 0;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
SgStatement* declPlace = NULL;
|
|
||||||
unordered_set<SgStatement*> changed;
|
|
||||||
unordered_set<SgSymbol*, MyHash, MyEq> variablesToAdd;
|
|
||||||
unordered_set<SgStatement*> positionsToAdd;
|
|
||||||
unordered_set<SgStatement*> statementsToRemove;
|
|
||||||
unordered_map<string, vector<pair<SgStatement*, SgStatement*>>> expToChange;
|
|
||||||
|
|
||||||
static bool CheckConstIndexes(SgExpression* exp)
|
|
||||||
{
|
|
||||||
if (!exp)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
SgExpression* lhs = exp->lhs();
|
|
||||||
SgExpression* rhs = exp->rhs();
|
|
||||||
do
|
|
||||||
{
|
|
||||||
if (lhs->variant() != INT_VAL)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (rhs)
|
|
||||||
{
|
|
||||||
lhs = rhs->lhs();
|
|
||||||
rhs = rhs->rhs();
|
|
||||||
}
|
|
||||||
} while (rhs);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
static SgExpression* CreateVar(int& variableNumber, SgType* type)
|
|
||||||
{
|
|
||||||
string varName = "__tmp_prop_var";
|
|
||||||
string name = varName + std::to_string(variableNumber) + "__";
|
|
||||||
variableNumber++;
|
|
||||||
|
|
||||||
SgStatement* funcStart = declPlace->controlParent();
|
|
||||||
SgSymbol* varSymbol = new SgSymbol(VARIABLE_NAME, name.c_str(), *type, *funcStart);
|
|
||||||
|
|
||||||
variablesToAdd.insert(varSymbol);
|
|
||||||
positionsToAdd.insert(declPlace);
|
|
||||||
|
|
||||||
return new SgExpression(VAR_REF, NULL, NULL, varSymbol, type->copyPtr());
|
|
||||||
}
|
|
||||||
|
|
||||||
static SgStatement* FindLastDeclStatement(SgStatement* funcStart)
|
|
||||||
{
|
|
||||||
SgStatement* endSt = funcStart->lastNodeOfStmt();
|
|
||||||
SgStatement* cur = funcStart->lexNext();
|
|
||||||
SgStatement* lastDecl = funcStart;
|
|
||||||
const set<int> declVariants = { VAR_DECL, VAR_DECL_90, ALLOCATABLE_STMT, DIM_STAT,
|
|
||||||
EXTERN_STAT, COMM_STAT, HPF_TEMPLATE_STAT, DVM_VAR_DECL, STRUCT_DECL };
|
|
||||||
|
|
||||||
while (cur && cur != endSt)
|
|
||||||
{
|
|
||||||
if (cur->variant() == INTERFACE_STMT)
|
|
||||||
cur = cur->lastNodeOfStmt();
|
|
||||||
|
|
||||||
if (declVariants.find(cur->variant()) != declVariants.end())
|
|
||||||
lastDecl = cur;
|
|
||||||
else if (isSgExecutableStatement(cur))
|
|
||||||
break;
|
|
||||||
|
|
||||||
cur = cur->lexNext();
|
|
||||||
}
|
|
||||||
|
|
||||||
return lastDecl;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void InsertCommonAndDeclsForFunction(SgStatement* funcStart, const unordered_set<SgSymbol*, MyHash, MyEq>& symbols)
|
|
||||||
{
|
|
||||||
if (symbols.empty())
|
|
||||||
return;
|
|
||||||
|
|
||||||
const string commonBlockName = "__propagation_common__";
|
|
||||||
|
|
||||||
SgStatement* funcEnd = funcStart->lastNodeOfStmt();
|
|
||||||
SgStatement* commonStat = NULL;
|
|
||||||
SgExpression* commonList = NULL;
|
|
||||||
|
|
||||||
for (SgStatement* cur = funcStart->lexNext();
|
|
||||||
cur && cur != funcEnd; cur = cur->lexNext())
|
|
||||||
{
|
|
||||||
if (cur->variant() != COMM_STAT)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
for (SgExpression* exp = cur->expr(0); exp; exp = exp->rhs())
|
|
||||||
{
|
|
||||||
if (exp->variant() != COMM_LIST)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
const char* id = exp->symbol() ? exp->symbol()->identifier() : NULL;
|
|
||||||
string existingName = id ? string(id) : string("spf_unnamed");
|
|
||||||
if (existingName == commonBlockName)
|
|
||||||
{
|
|
||||||
commonStat = cur;
|
|
||||||
commonList = exp;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (commonStat)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
vector<SgExpression*> varRefs;
|
|
||||||
for (SgSymbol* sym : symbols)
|
|
||||||
{
|
|
||||||
if (!sym || sym->variant() != VARIABLE_NAME || string(sym->identifier()) == commonBlockName)
|
|
||||||
continue;
|
|
||||||
SgSymbol* symToAdd = new SgSymbol(VARIABLE_NAME, sym->identifier(), *sym->type(), *funcStart);
|
|
||||||
varRefs.push_back(new SgVarRefExp(symToAdd));
|
|
||||||
}
|
|
||||||
SgExpression* varList = makeExprList(varRefs, false);
|
|
||||||
|
|
||||||
SgStatement* insertAfter = FindLastDeclStatement(funcStart);
|
|
||||||
for (SgSymbol* sym : symbols)
|
|
||||||
{
|
|
||||||
SgStatement* declStmt = sym->makeVarDeclStmt();
|
|
||||||
if (!declStmt)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (SgVarDeclStmt* vds = isSgVarDeclStmt(declStmt))
|
|
||||||
vds->setVariant(VAR_DECL_90);
|
|
||||||
|
|
||||||
declStmt->setFileName(funcStart->fileName());
|
|
||||||
declStmt->setFileId(funcStart->getFileId());
|
|
||||||
declStmt->setProject(funcStart->getProject());
|
|
||||||
declStmt->setlineNumber(getNextNegativeLineNumber());
|
|
||||||
|
|
||||||
insertAfter->insertStmtAfter(*declStmt, *funcStart);
|
|
||||||
insertAfter = declStmt;
|
|
||||||
statementsToRemove.insert(declStmt);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!commonList)
|
|
||||||
{
|
|
||||||
SgSymbol* commonSymbol = new SgSymbol(COMMON_NAME, commonBlockName.c_str());
|
|
||||||
commonList = new SgExpression(COMM_LIST, varList, NULL, commonSymbol);
|
|
||||||
|
|
||||||
commonStat = new SgStatement(COMM_STAT);
|
|
||||||
commonStat->setFileName(funcStart->fileName());
|
|
||||||
commonStat->setFileId(funcStart->getFileId());
|
|
||||||
commonStat->setProject(funcStart->getProject());
|
|
||||||
commonStat->setlineNumber(getNextNegativeLineNumber());
|
|
||||||
commonStat->setExpression(0, commonList);
|
|
||||||
|
|
||||||
SgStatement* lastDecl = FindLastDeclStatement(funcStart);
|
|
||||||
lastDecl->insertStmtAfter(*commonStat, *funcStart);
|
|
||||||
statementsToRemove.insert(commonStat);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
commonList->setLhs(varList);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
static void TransformRightPart(SgStatement* st, SgExpression* exp, unordered_map<string, SgExpression*>& arrayToVariable, int& variableNumber)
|
|
||||||
{
|
|
||||||
if (!exp)
|
|
||||||
return;
|
|
||||||
vector<SgExpression*> subnodes = { exp->lhs(), exp->rhs() };
|
|
||||||
|
|
||||||
string expUnparsed;
|
|
||||||
SgExpression* toAdd = NULL;
|
|
||||||
if (exp->variant() == ARRAY_REF && CheckConstIndexes(exp->lhs()))
|
|
||||||
{
|
|
||||||
expUnparsed = exp->unparse();
|
|
||||||
if (arrayToVariable.find(expUnparsed) == arrayToVariable.end() && exp->symbol()->type()->baseType())
|
|
||||||
{
|
|
||||||
arrayToVariable[expUnparsed] = CreateVar(variableNumber, exp->symbol()->type()->baseType());
|
|
||||||
}
|
|
||||||
positionsToAdd.insert(declPlace);
|
|
||||||
SgSymbol* builder = arrayToVariable[expUnparsed]->symbol();
|
|
||||||
auto* sym = new SgSymbol(builder->variant(), builder->identifier(), builder->type(), st->controlParent());
|
|
||||||
auto* newVarExp = new SgVarRefExp(sym);
|
|
||||||
expToChange[st->fileName()].push_back({ st , st->copyPtr() });
|
|
||||||
st->setExpression(1, newVarExp);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
for (int i = 0; i < 2; i++)
|
|
||||||
{
|
|
||||||
if (subnodes[i] && subnodes[i]->variant() == ARRAY_REF && subnodes[i]->symbol()->type()->baseType() && CheckConstIndexes(subnodes[i]->lhs()))
|
|
||||||
{
|
|
||||||
expUnparsed = subnodes[i]->unparse();
|
|
||||||
if (arrayToVariable.find(expUnparsed) == arrayToVariable.end())
|
|
||||||
arrayToVariable[expUnparsed] = CreateVar(variableNumber, subnodes[i]->symbol()->type()->baseType());
|
|
||||||
|
|
||||||
positionsToAdd.insert(declPlace);
|
|
||||||
SgSymbol* builder = arrayToVariable[expUnparsed]->symbol();
|
|
||||||
auto* sym = new SgSymbol(builder->variant(), builder->identifier(), builder->type(), st->controlParent());
|
|
||||||
toAdd = new SgVarRefExp(sym);
|
|
||||||
if (toAdd)
|
|
||||||
{
|
|
||||||
if (i == 0)
|
|
||||||
{
|
|
||||||
expToChange[st->fileName()].push_back({ st , st->copyPtr() });;
|
|
||||||
exp->setLhs(toAdd);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
expToChange[st->fileName()].push_back({ st , st->copyPtr() });;
|
|
||||||
exp->setRhs(toAdd);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
TransformRightPart(st, subnodes[i], arrayToVariable, variableNumber);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void TransformLeftPart(SgStatement* st, SgExpression* exp, unordered_map<string, SgExpression*>& arrayToVariable, int& variableNumber)
|
|
||||||
{
|
|
||||||
if (exp->symbol()->type()->variant() == T_STRING)
|
|
||||||
return;
|
|
||||||
if (changed.find(st) != changed.end())
|
|
||||||
return;
|
|
||||||
string expUnparsed = exp->unparse();
|
|
||||||
if (arrayToVariable.find(expUnparsed) == arrayToVariable.end() && exp->symbol()->type()->baseType())
|
|
||||||
{
|
|
||||||
arrayToVariable[expUnparsed] = CreateVar(variableNumber, exp->symbol()->type()->baseType());
|
|
||||||
}
|
|
||||||
positionsToAdd.insert(declPlace);
|
|
||||||
SgStatement* newStatement = new SgStatement(ASSIGN_STAT, NULL, NULL, arrayToVariable[expUnparsed]->copyPtr(), st->expr(1)->copyPtr(), NULL);
|
|
||||||
|
|
||||||
newStatement->setFileId(st->getFileId());
|
|
||||||
newStatement->setProject(st->getProject());
|
|
||||||
|
|
||||||
newStatement->setlineNumber(getNextNegativeLineNumber());
|
|
||||||
newStatement->setLocalLineNumber(st->lineNumber());
|
|
||||||
st->insertStmtBefore(*newStatement, *st->controlParent());
|
|
||||||
changed.insert(st);
|
|
||||||
statementsToRemove.insert(newStatement);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void TransformBorder(SgStatement* st, SgExpression* exp, unordered_map<string, SgExpression*>& arrayToVariable, int& variableNumber)
|
|
||||||
{
|
|
||||||
SgStatement* firstStatement = declPlace->lexPrev();
|
|
||||||
st = st->lexPrev();
|
|
||||||
string array = exp->unparse();
|
|
||||||
if (arrayToVariable.find(array) == arrayToVariable.end())
|
|
||||||
arrayToVariable[array] = CreateVar(variableNumber, exp->symbol()->type()->baseType());
|
|
||||||
while (st != firstStatement)
|
|
||||||
{
|
|
||||||
if (st->variant() == ASSIGN_STAT && arrayToVariable.find(st->expr(0)->unparse()) != arrayToVariable.end())
|
|
||||||
{
|
|
||||||
if (st->expr(1))
|
|
||||||
{
|
|
||||||
TransformRightPart(st, st->expr(1), arrayToVariable, variableNumber);
|
|
||||||
}
|
|
||||||
if (st->expr(0) && st->expr(0)->variant() == ARRAY_REF && CheckConstIndexes(st->expr(0)->lhs()) && arrayToVariable.find(st->expr(0)->unparse()) != arrayToVariable.end())
|
|
||||||
TransformLeftPart(st, st->expr(0), arrayToVariable, variableNumber);
|
|
||||||
}
|
|
||||||
st = st->lexPrev();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void CheckVariable(SgStatement* st, SgExpression* exp, unordered_map<string, SgExpression*>& arrayToVariable, int& variableNumber)
|
|
||||||
{
|
|
||||||
SgStatement* firstStatement = declPlace->lexPrev();
|
|
||||||
st = st->lexPrev();
|
|
||||||
string varName = exp->unparse();
|
|
||||||
while (st != firstStatement)
|
|
||||||
{
|
|
||||||
if (st->variant() == ASSIGN_STAT && st->expr(0)->symbol() == exp->symbol())
|
|
||||||
{
|
|
||||||
TransformRightPart(st, st->expr(1), arrayToVariable, variableNumber);
|
|
||||||
positionsToAdd.insert(declPlace);
|
|
||||||
}
|
|
||||||
if (st->variant() == ASSIGN_STAT && arrayToVariable.find(st->expr(0)->unparse()) != arrayToVariable.end())
|
|
||||||
{
|
|
||||||
if (st->expr(1))
|
|
||||||
{
|
|
||||||
TransformRightPart(st, st->expr(1), arrayToVariable, variableNumber);
|
|
||||||
positionsToAdd.insert(declPlace);
|
|
||||||
}
|
|
||||||
if (st->expr(0) && st->expr(0)->variant() == ARRAY_REF && CheckConstIndexes(st->expr(0)->lhs()) && arrayToVariable.find(st->expr(0)->unparse()) != arrayToVariable.end())
|
|
||||||
{
|
|
||||||
TransformLeftPart(st, st->expr(0), arrayToVariable, variableNumber);
|
|
||||||
positionsToAdd.insert(declPlace);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
st = st->lexPrev();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void arrayConstantPropagation(SgProject& project)
|
|
||||||
{
|
|
||||||
unordered_map<string, SgExpression*> arrayToVariable;
|
|
||||||
int variableNumber = 0;
|
|
||||||
for (int i = 0; i < project.numberOfFiles(); i++)
|
|
||||||
{
|
|
||||||
SgFile* file = &(project.file(i));
|
|
||||||
|
|
||||||
if (!file)
|
|
||||||
continue;
|
|
||||||
SgFile::switchToFile(file->filename());
|
|
||||||
const int funcNum = file->numberOfFunctions();
|
|
||||||
for (int i = 0; i < funcNum; ++i)
|
|
||||||
{
|
|
||||||
SgStatement* st = file->functions(i);
|
|
||||||
declPlace = st->lexNext();
|
|
||||||
SgStatement* lastNode = st->lastNodeOfStmt();
|
|
||||||
|
|
||||||
for (; st != lastNode; st = st->lexNext())
|
|
||||||
{
|
|
||||||
if (st->variant() == FOR_NODE)
|
|
||||||
{
|
|
||||||
SgExpression* lowerBound = st->expr(0)->lhs();
|
|
||||||
SgExpression* upperBound = st->expr(0)->rhs();
|
|
||||||
SgStatement* boundCopy = NULL;
|
|
||||||
string lowerBoundUnparsed = lowerBound->unparse(), upperBoundUnparsed = upperBound->unparse();
|
|
||||||
if (upperBound->variant() == ARRAY_REF && upperBound->symbol()->type()->baseType() && CheckConstIndexes(upperBound->lhs()))
|
|
||||||
{
|
|
||||||
boundCopy = st->copyPtr();
|
|
||||||
TransformBorder(st, upperBound, arrayToVariable, variableNumber);
|
|
||||||
st->expr(0)->setRhs(arrayToVariable[upperBoundUnparsed]->copyPtr());
|
|
||||||
expToChange[st->fileName()].push_back({ st ,boundCopy });;
|
|
||||||
positionsToAdd.insert(declPlace);
|
|
||||||
}
|
|
||||||
else if (upperBound->variant() == VAR_REF)
|
|
||||||
CheckVariable(st, upperBound, arrayToVariable, variableNumber);
|
|
||||||
|
|
||||||
if (lowerBound->variant() == ARRAY_REF && lowerBound->symbol()->type()->baseType() && CheckConstIndexes(lowerBound->lhs()))
|
|
||||||
{
|
|
||||||
boundCopy = st->copyPtr();
|
|
||||||
TransformBorder(st, lowerBound, arrayToVariable, variableNumber);
|
|
||||||
st->expr(0)->setLhs(arrayToVariable[lowerBoundUnparsed]->copyPtr());
|
|
||||||
expToChange[st->fileName()].push_back({ st , boundCopy });;
|
|
||||||
positionsToAdd.insert(declPlace);
|
|
||||||
}
|
|
||||||
else if (lowerBound->variant() == VAR_REF)
|
|
||||||
CheckVariable(st, lowerBound, arrayToVariable, variableNumber);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
unordered_set<SgStatement*> funcStarts;
|
|
||||||
for (SgStatement* st : positionsToAdd)
|
|
||||||
{
|
|
||||||
SgFile::switchToFile(st->fileName());
|
|
||||||
SgStatement* scope = st->controlParent();
|
|
||||||
if (scope)
|
|
||||||
funcStarts.insert(scope);
|
|
||||||
}
|
|
||||||
for (const auto& st : funcStarts)
|
|
||||||
{
|
|
||||||
SgFile::switchToFile(st->fileName());
|
|
||||||
InsertCommonAndDeclsForFunction(st, variablesToAdd);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include "../Utils/SgUtils.h"
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
struct ExprRestoreEntry
|
|
||||||
{
|
|
||||||
enum Kind { kStatementExpr, kExprChild };
|
|
||||||
Kind kind;
|
|
||||||
SgStatement* stmt;
|
|
||||||
int stmtExprIndex;
|
|
||||||
SgExpression* parent;
|
|
||||||
bool childIsRhs;
|
|
||||||
SgExpression* savedCopy;
|
|
||||||
};
|
|
||||||
|
|
||||||
void arrayConstantPropagation(SgProject& project);
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
#define _LEAK_
|
#define _LEAK_
|
||||||
#include "leak_detector.h"
|
#include "../Utils/leak_detector.h"
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@@ -8,9 +8,9 @@
|
|||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
|
||||||
#include "SgUtils.h"
|
#include "../Utils/SgUtils.h"
|
||||||
#include "CommonBlock.h"
|
#include "../Utils/CommonBlock.h"
|
||||||
#include "graph_calls.h"
|
#include "../GraphCall/graph_calls.h"
|
||||||
|
|
||||||
#include "dvm.h"
|
#include "dvm.h"
|
||||||
#include "IR.h"
|
#include "IR.h"
|
||||||
@@ -1149,23 +1149,9 @@ map<FuncInfo*, vector<BBlock*>> buildCFG(const map<string, CommonBlock*>& common
|
|||||||
if (settings.withRD)
|
if (settings.withRD)
|
||||||
buildReachingDefs(result, settings);
|
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)
|
if (SgFile::switchToFile(oldFile) == -1)
|
||||||
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
||||||
|
|
||||||
if (!settings.withUnreachable)
|
|
||||||
for (auto& [func, blocks] : result)
|
|
||||||
removedUnreachableBlocks(blocks);
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1241,48 +1227,3 @@ map<FuncInfo*, vector<SAPFOR::BasicBlock*>>
|
|||||||
|
|
||||||
return buildCFG(commonBlocks, fileFuncInfoMap, settings);
|
return buildCFG(commonBlocks, fileFuncInfoMap, settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void removedUnreachableBlocks(vector<SAPFOR::BasicBlock*>& blocks)
|
|
||||||
{
|
|
||||||
set<SAPFOR::BasicBlock*> reachable;
|
|
||||||
|
|
||||||
for (auto& b : blocks)
|
|
||||||
if (b->getInstructions().front()->isHeader() ||
|
|
||||||
b->getInstructions().front()->getInstruction()->getOperation() == SAPFOR::CFG_OP::ENTRY)
|
|
||||||
reachable.insert(b);
|
|
||||||
|
|
||||||
set<SAPFOR::BasicBlock*> worklist = reachable;
|
|
||||||
while (worklist.size() != 0)
|
|
||||||
{
|
|
||||||
set<SAPFOR::BasicBlock*> to_insert;
|
|
||||||
|
|
||||||
for (auto& b : worklist)
|
|
||||||
for (auto& next : b->getNext())
|
|
||||||
if (reachable.insert(next).second)
|
|
||||||
to_insert.insert(next);
|
|
||||||
|
|
||||||
worklist = to_insert;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto remove_unreachable_it = remove_if(blocks.begin(), blocks.end(),
|
|
||||||
[&reachable](SAPFOR::BasicBlock* b)
|
|
||||||
{
|
|
||||||
if (reachable.find(b) == reachable.end())
|
|
||||||
{
|
|
||||||
for (auto& next : b->getNext())
|
|
||||||
if (reachable.find(next) != reachable.end())
|
|
||||||
next->removePrev(b);
|
|
||||||
|
|
||||||
delete b;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
reachable.clear();
|
|
||||||
|
|
||||||
blocks.erase(remove_unreachable_it, blocks.end());
|
|
||||||
}
|
|
||||||
@@ -6,7 +6,6 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "IR.h"
|
#include "IR.h"
|
||||||
#include "IR_domTree.h"
|
|
||||||
|
|
||||||
namespace SAPFOR
|
namespace SAPFOR
|
||||||
{
|
{
|
||||||
@@ -25,7 +24,7 @@ namespace SAPFOR
|
|||||||
|
|
||||||
std::vector<BasicBlock*> next;
|
std::vector<BasicBlock*> next;
|
||||||
std::vector<BasicBlock*> prev;
|
std::vector<BasicBlock*> prev;
|
||||||
BasicBlock* directDominator = NULL;
|
|
||||||
//reaching definition
|
//reaching definition
|
||||||
std::map<SAPFOR::Argument*, std::set<int>> RD_in, RD_out;
|
std::map<SAPFOR::Argument*, std::set<int>> RD_in, RD_out;
|
||||||
|
|
||||||
@@ -35,7 +34,6 @@ namespace SAPFOR
|
|||||||
bool addLive(const std::map<SAPFOR::Argument*, std::vector<SAPFOR::BasicBlock*>>& to_add, bool in);
|
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;
|
std::map<SAPFOR::Argument*, std::vector<SAPFOR::BasicBlock*>> getLive(bool in) const;
|
||||||
bool removeLive(SAPFOR::Argument* to_remove, bool in);
|
bool removeLive(SAPFOR::Argument* to_remove, bool in);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
BasicBlock() { num = lastNumBlock++; }
|
BasicBlock() { num = lastNumBlock++; }
|
||||||
BasicBlock(IR_Block* item);
|
BasicBlock(IR_Block* item);
|
||||||
@@ -44,7 +42,6 @@ namespace SAPFOR
|
|||||||
void addInstruction(IR_Block* item);
|
void addInstruction(IR_Block* item);
|
||||||
void addPrev(BasicBlock* prev_) { prev.push_back(prev_); }
|
void addPrev(BasicBlock* prev_) { prev.push_back(prev_); }
|
||||||
void addNext(BasicBlock* next_) { next.push_back(next_); }
|
void addNext(BasicBlock* next_) { next.push_back(next_); }
|
||||||
void setDom(BasicBlock* dom) { directDominator = dom; }
|
|
||||||
|
|
||||||
int removePrev(BasicBlock* removed);
|
int removePrev(BasicBlock* removed);
|
||||||
int removeNext(BasicBlock* removed);
|
int removeNext(BasicBlock* removed);
|
||||||
@@ -72,10 +69,6 @@ namespace SAPFOR
|
|||||||
const std::vector<IR_Block*>& getInstructions() const { return instructions; }
|
const std::vector<IR_Block*>& getInstructions() const { return instructions; }
|
||||||
const std::vector<BasicBlock*>& getNext() const { return next; }
|
const std::vector<BasicBlock*>& getNext() const { return next; }
|
||||||
const std::vector<BasicBlock*>& getPrev() const { return prev; }
|
const std::vector<BasicBlock*>& getPrev() const { return prev; }
|
||||||
BasicBlock* getDom() const
|
|
||||||
{
|
|
||||||
return directDominator;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* FOR LIVE ANALYSIS
|
* FOR LIVE ANALYSIS
|
||||||
@@ -105,52 +98,21 @@ namespace SAPFOR
|
|||||||
|
|
||||||
struct CFG_Settings
|
struct CFG_Settings
|
||||||
{
|
{
|
||||||
enum setting { CFG_atLeastOneIterInLoop = 1,
|
|
||||||
CFG_withRD = 2,
|
|
||||||
CFG_withRegisters = 3,
|
|
||||||
CFG_withSPF = 4,
|
|
||||||
CFG_withDVM = 5,
|
|
||||||
CFG_withCallsInBlocks = 6,
|
|
||||||
CFG_withCallFrom = 7,
|
|
||||||
CFG_withDominators = 8,
|
|
||||||
CFG_withUnreachable = 9 };
|
|
||||||
|
|
||||||
bool atLeastOneIterInLoop = false;
|
bool atLeastOneIterInLoop = false;
|
||||||
bool withRD = false;
|
bool withRD = true;
|
||||||
bool withRegisters = false;
|
bool withRegisters = false;
|
||||||
bool withSPF = false;
|
bool withSPF = false;
|
||||||
bool withDVM = false;
|
bool withDVM = false;
|
||||||
bool withCallsInBlocks = false; // separate each F_CALL to own BasicBlock
|
bool withCallsInBlocks = false; // separate each F_CALL to own BasicBlock
|
||||||
bool withCallFrom = false;
|
bool withCallFrom = true;
|
||||||
bool withDominators = false;
|
|
||||||
bool withUnreachable = false;
|
|
||||||
|
|
||||||
explicit CFG_Settings(const std::set<setting> &settings = { CFG_withRD, CFG_withCallFrom, CFG_withDominators })
|
explicit CFG_Settings(int) { }
|
||||||
{
|
|
||||||
for (auto& set : settings)
|
explicit CFG_Settings(bool atLeastOneIterInLoop = false, bool withRD = true, bool withRegisters = false,
|
||||||
{
|
bool withDVM = false, bool withSPF = false, bool withCallsInBlocks = false, bool withCallFrom = true) :
|
||||||
if (set == CFG_atLeastOneIterInLoop)
|
atLeastOneIterInLoop(atLeastOneIterInLoop), withRD(withRD), withRegisters(withRegisters), withDVM(withDVM), withSPF(withSPF),
|
||||||
atLeastOneIterInLoop = true;
|
withCallsInBlocks(withCallsInBlocks), withCallFrom(withCallFrom)
|
||||||
else if (set == CFG_withRD)
|
{ }
|
||||||
withRD = true;
|
|
||||||
else if (set == CFG_withRegisters)
|
|
||||||
withRegisters = true;
|
|
||||||
else if (set == CFG_withSPF)
|
|
||||||
withSPF = true;
|
|
||||||
else if (set == CFG_withDVM)
|
|
||||||
withDVM = true;
|
|
||||||
else if (set == CFG_withCallsInBlocks)
|
|
||||||
withCallsInBlocks = true;
|
|
||||||
else if (set == CFG_withCallFrom)
|
|
||||||
withCallFrom = true;
|
|
||||||
else if (set == CFG_withDominators)
|
|
||||||
withDominators = true;
|
|
||||||
else if (set == CFG_withUnreachable)
|
|
||||||
withUnreachable = true;
|
|
||||||
else
|
|
||||||
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -185,5 +147,3 @@ static inline void deleteCFG(std::map<FuncInfo*, std::vector<SAPFOR::BasicBlock*
|
|||||||
}
|
}
|
||||||
cfg.clear();
|
cfg.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void removedUnreachableBlocks(std::vector<SAPFOR::BasicBlock*>& blocks);
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
#include <set>
|
#include <set>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
#include "SgUtils.h"
|
#include "../../Utils/SgUtils.h"
|
||||||
#include "../CFGraph.h"
|
#include "../CFGraph.h"
|
||||||
#include "../IR.h"
|
#include "../IR.h"
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
#include <set>
|
#include <set>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
#include "SgUtils.h"
|
#include "../../Utils/SgUtils.h"
|
||||||
#include "../CFGraph.h"
|
#include "../CFGraph.h"
|
||||||
#include "../IR.h"
|
#include "../IR.h"
|
||||||
#include "../RD_subst.h"
|
#include "../RD_subst.h"
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
#include<vector>
|
#include<vector>
|
||||||
#include<set>
|
#include<set>
|
||||||
|
|
||||||
#include "SgUtils.h"
|
#include "../../Utils/SgUtils.h"
|
||||||
#include "../CFGraph.h"
|
#include "../CFGraph.h"
|
||||||
#include "../IR.h"
|
#include "../IR.h"
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
#include<vector>
|
#include<vector>
|
||||||
#include<set>
|
#include<set>
|
||||||
|
|
||||||
#include "SgUtils.h"
|
#include "../../Utils/SgUtils.h"
|
||||||
#include "../CFGraph.h"
|
#include "../CFGraph.h"
|
||||||
#include "../IR.h"
|
#include "../IR.h"
|
||||||
|
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
#include "leak_detector.h"
|
#include "../Utils/leak_detector.h"
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <set>
|
#include <set>
|
||||||
|
|
||||||
#include "SgUtils.h"
|
#include "../Utils/SgUtils.h"
|
||||||
#include "CommonBlock.h"
|
#include "../Utils/CommonBlock.h"
|
||||||
#include "graph_calls.h"
|
#include "../GraphCall/graph_calls.h"
|
||||||
#include "expr_transform.h"
|
#include "../ExpressionTransform/expr_transform.h"
|
||||||
|
|
||||||
#include "dvm.h"
|
#include "dvm.h"
|
||||||
#include "IR.h"
|
#include "IR.h"
|
||||||
@@ -395,7 +395,7 @@ static SAPFOR::Argument* processExpression(SgExpression* ex, vector<IR_Block*>&
|
|||||||
if (ex)
|
if (ex)
|
||||||
{
|
{
|
||||||
const int var = ex->variant();
|
const int var = ex->variant();
|
||||||
if ((var == VAR_REF || var == CONST_REF || var == LABEL_REF) && !ex->lhs() && !ex->rhs()) // variable reference
|
if ((var == VAR_REF || var == CONST_REF || var == LABEL_REF) && !ex->lhs() && !ex->rhs()) // îáðàùåíèå ê ïåðåìåííîé
|
||||||
{
|
{
|
||||||
if (var == CONST_REF)
|
if (var == CONST_REF)
|
||||||
{
|
{
|
||||||
@@ -450,7 +450,7 @@ static SAPFOR::Argument* processExpression(SgExpression* ex, vector<IR_Block*>&
|
|||||||
return arg1;
|
return arg1;
|
||||||
|
|
||||||
auto reg = isLeft ? NULL : createRegister();
|
auto reg = isLeft ? NULL : createRegister();
|
||||||
Instruction* instr = new Instruction(isLeft ? CFG_OP::STORE : CFG_OP::LOAD, arg1, createConstArg(numArgs), isLeft ? isLeft : reg, NULL, ex);
|
Instruction* instr = new Instruction(isLeft ? CFG_OP::STORE : CFG_OP::LOAD, arg1, createConstArg(numArgs), isLeft ? isLeft : reg);
|
||||||
blocks.push_back(new IR_Block(instr));
|
blocks.push_back(new IR_Block(instr));
|
||||||
return reg;
|
return reg;
|
||||||
}
|
}
|
||||||
@@ -485,7 +485,7 @@ static SAPFOR::Argument* processExpression(SgExpression* ex, vector<IR_Block*>&
|
|||||||
auto arg1 = arrayRef ? arrayRef : createArrayArg(ref, blocks, func, numArgs, commonVars);
|
auto arg1 = arrayRef ? arrayRef : createArrayArg(ref, blocks, func, numArgs, commonVars);
|
||||||
|
|
||||||
auto reg = isLeft ? NULL : createRegister();
|
auto reg = isLeft ? NULL : createRegister();
|
||||||
instr = new Instruction(isLeft ? CFG_OP::STORE : CFG_OP::LOAD, arg1, createConstArg(1), isLeft ? isLeft : reg, NULL, ex);
|
instr = new Instruction(isLeft ? CFG_OP::STORE : CFG_OP::LOAD, arg1, createConstArg(1), isLeft ? isLeft : reg);
|
||||||
blocks.push_back(new IR_Block(instr));
|
blocks.push_back(new IR_Block(instr));
|
||||||
return reg;
|
return reg;
|
||||||
}
|
}
|
||||||
@@ -602,7 +602,7 @@ static SAPFOR::Argument* processExpression(SgExpression* ex, vector<IR_Block*>&
|
|||||||
{
|
{
|
||||||
if (returnReg == NULL)
|
if (returnReg == NULL)
|
||||||
{
|
{
|
||||||
Instruction* instr = new Instruction(CFG_OP::LOAD, arg, NULL, reg, NULL, ex);
|
Instruction* instr = new Instruction(CFG_OP::LOAD, arg, NULL, reg);
|
||||||
blocks.push_back(new IR_Block(instr));
|
blocks.push_back(new IR_Block(instr));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -1572,7 +1572,7 @@ vector<IR_Block*> buildIR(SgStatement* function, const FuncInfo* func, const vec
|
|||||||
else
|
else
|
||||||
findReturn(0, blocks.size(), blocks, blocks.back()->getNumber());
|
findReturn(0, blocks.size(), blocks, blocks.back()->getNumber());
|
||||||
|
|
||||||
// adding links by GOTO and jumps
|
// äîáàâëåíèå ñâÿçåé ïî GOTO è ïåðåõîäàì
|
||||||
for (int z = 0; z < blocks.size(); ++z)
|
for (int z = 0; z < blocks.size(); ++z)
|
||||||
{
|
{
|
||||||
auto op = blocks[z]->getInstruction()->getOperation();
|
auto op = blocks[z]->getInstruction()->getOperation();
|
||||||
@@ -1592,7 +1592,7 @@ vector<IR_Block*> buildIR(SgStatement* function, const FuncInfo* func, const vec
|
|||||||
|
|
||||||
blocks[z]->setJump(it->second);
|
blocks[z]->setJump(it->second);
|
||||||
|
|
||||||
// replacing the label with the instruction number
|
// çàìåíèì ìåòêó íà íîìåð èíñòðóêöèè
|
||||||
arg->setValue(to_string(it->second->getNumber()));
|
arg->setValue(to_string(it->second->getNumber()));
|
||||||
arg->setType(CFG_ARG_TYPE::INSTR);
|
arg->setType(CFG_ARG_TYPE::INSTR);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
#include "CFGraph.h"
|
#include "CFGraph.h"
|
||||||
#include "CommonBlock.h"
|
#include "../Utils/CommonBlock.h"
|
||||||
|
|
||||||
namespace SAPFOR
|
namespace SAPFOR
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,102 +0,0 @@
|
|||||||
#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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
#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). — 1979. — Vol. 1, no. 1. — Pp. 121–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);
|
|
||||||
}
|
|
||||||
@@ -8,10 +8,10 @@
|
|||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <unordered_set>
|
#include <unordered_set>
|
||||||
|
|
||||||
#include "SgUtils.h"
|
#include "../Utils/SgUtils.h"
|
||||||
#include "CommonBlock.h"
|
#include "../Utils/CommonBlock.h"
|
||||||
#include "graph_calls.h"
|
#include "../GraphCall/graph_calls.h"
|
||||||
#include "expr_transform.h"
|
#include "../ExpressionTransform/expr_transform.h"
|
||||||
|
|
||||||
#define PRINT_PROF_INFO 0
|
#define PRINT_PROF_INFO 0
|
||||||
#define DEBUG_CHECKS 0
|
#define DEBUG_CHECKS 0
|
||||||
|
|||||||
@@ -2,9 +2,9 @@
|
|||||||
|
|
||||||
#include<unordered_map>
|
#include<unordered_map>
|
||||||
|
|
||||||
#include "SgUtils.h"
|
#include "../Utils/SgUtils.h"
|
||||||
#include "CommonBlock.h"
|
#include "../Utils/CommonBlock.h"
|
||||||
#include "graph_calls.h"
|
#include "../GraphCall/graph_calls.h"
|
||||||
|
|
||||||
#include "CFGraph.h"
|
#include "CFGraph.h"
|
||||||
#include "IR.h"
|
#include "IR.h"
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "SgUtils.h"
|
#include "../Utils/SgUtils.h"
|
||||||
#include "CFGraph.h"
|
#include "CFGraph.h"
|
||||||
|
|
||||||
namespace LIVE_VARIABLES
|
namespace LIVE_VARIABLES
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#include "errors.h"
|
#include "../Utils/errors.h"
|
||||||
#include "private_variables_analysis.h"
|
#include "private_variables_analysis.h"
|
||||||
#include "graph_loops.h"
|
#include "../GraphLoop/graph_loops.h"
|
||||||
#include "../LoopAnalyzer/loop_analyzer.h"
|
#include "../LoopAnalyzer/loop_analyzer.h"
|
||||||
#include "../SageAnalysisTool/depGraph.h"
|
#include "../SageAnalysisTool/depGraph.h"
|
||||||
#include "../DirectiveProcessing/directive_parser.h"
|
#include "../DirectiveProcessing/directive_parser.h"
|
||||||
@@ -200,46 +200,20 @@ static void fillOutForFunc(const FuncInfo* func, const vector<SAPFOR::BasicBlock
|
|||||||
outForFunc[func->funcName] = { defined, common_defined };
|
outForFunc[func->funcName] = { defined, common_defined };
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool isInstructionSpfParameter(SAPFOR::Instruction* instr)
|
|
||||||
{
|
|
||||||
SgStatement* st = instr->getOperator();
|
|
||||||
|
|
||||||
// check if this operator is SPF(ANALYSIS(PARAMETER( )))
|
|
||||||
if (st && st->variant() == ASSIGN_STAT)
|
|
||||||
{
|
|
||||||
if (st->lineNumber() < 0 && st->numberOfAttributes())
|
|
||||||
{
|
|
||||||
for (int i = 0; i < st->numberOfAttributes(); ++i)
|
|
||||||
{
|
|
||||||
SgAttribute* attr = st->getAttribute(i);
|
|
||||||
SgStatement* attributeStatement = (SgStatement*)(attr->getAttributeData());
|
|
||||||
int type = st->attributeType(i);
|
|
||||||
|
|
||||||
if (type == SPF_PARAMETER_OP)
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void getDefsFromBlock(SAPFOR::BasicBlock* block, set<SAPFOR::Argument*>& res,
|
static void getDefsFromBlock(SAPFOR::BasicBlock* block, set<SAPFOR::Argument*>& res,
|
||||||
const vector<pair<const Variable*, CommonBlock*>>& commonVars,
|
const vector<pair<const Variable*, CommonBlock*>>& commonVars,
|
||||||
const FuncInfo* func)
|
const FuncInfo* func)
|
||||||
{
|
{
|
||||||
vector<SAPFOR::Argument*> lastParamRef;
|
vector<SAPFOR::Argument*> lastParamRef;
|
||||||
|
|
||||||
for (const auto &ir_block : block->getInstructions())
|
for (auto ir_block : block->getInstructions())
|
||||||
{
|
{
|
||||||
SAPFOR::Instruction* instr = ir_block->getInstruction();
|
SAPFOR::Instruction* instr = ir_block->getInstruction();
|
||||||
if (isInstructionSpfParameter(instr))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
SAPFOR::CFG_OP instr_operation = instr->getOperation();
|
SAPFOR::CFG_OP instr_operation = instr->getOperation();
|
||||||
if (instr_operation == SAPFOR::CFG_OP::PARAM)
|
if (instr_operation == SAPFOR::CFG_OP::PARAM)
|
||||||
{
|
{
|
||||||
SAPFOR::Argument* arg = instr->getArg1();
|
SAPFOR::Argument* arg = instr->getArg1();
|
||||||
if (arg->getType() == SAPFOR::CFG_ARG_TYPE::VAR)
|
if(arg->getType() == SAPFOR::CFG_ARG_TYPE::VAR)
|
||||||
addPlaceWithDef(commonVars, func, arg, instr);
|
addPlaceWithDef(commonVars, func, arg, instr);
|
||||||
|
|
||||||
lastParamRef.push_back(arg);
|
lastParamRef.push_back(arg);
|
||||||
@@ -262,19 +236,11 @@ static void getDefsFromBlock(SAPFOR::BasicBlock* block, set<SAPFOR::Argument*>&
|
|||||||
int last_instr_num = block->getInstructions().back()->getNumber();
|
int last_instr_num = block->getInstructions().back()->getNumber();
|
||||||
|
|
||||||
for (const auto& def : block->getRD_Out())
|
for (const auto& def : block->getRD_Out())
|
||||||
{
|
|
||||||
for (int place : def.second)
|
for (int place : def.second)
|
||||||
{
|
|
||||||
if (place >= first_instr_num && place <= last_instr_num && def.first->getType() == SAPFOR::CFG_ARG_TYPE::VAR)
|
if (place >= first_instr_num && place <= last_instr_num && def.first->getType() == SAPFOR::CFG_ARG_TYPE::VAR)
|
||||||
{
|
{
|
||||||
SAPFOR::Instruction* instr = block->getInstructions()[place - first_instr_num]->getInstruction();
|
|
||||||
if (isInstructionSpfParameter(instr))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
res.insert(def.first);
|
res.insert(def.first);
|
||||||
addPlaceWithDef(commonVars, func, def.first, instr);
|
addPlaceWithDef(commonVars, func, def.first, block->getInstructions()[place - first_instr_num]->getInstruction());
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -284,7 +250,7 @@ static set<SAPFOR::BasicBlock*> analyzeLoop(LoopGraph* loop, const set<SAPFOR::B
|
|||||||
const map<string, SgSymbol*>& commonArgs, FuncInfo* func,
|
const map<string, SgSymbol*>& commonArgs, FuncInfo* func,
|
||||||
map<string, vector<Messages>>& messages)
|
map<string, vector<Messages>>& messages)
|
||||||
{
|
{
|
||||||
if (!loop->isFor())
|
if (!loop->isFor)
|
||||||
printInternalError(convertFileName(__FILE__).c_str(), __LINE__); //should be called only with FOR loops
|
printInternalError(convertFileName(__FILE__).c_str(), __LINE__); //should be called only with FOR loops
|
||||||
|
|
||||||
SgStatement* loop_operator = loop->loop->GetOriginal();
|
SgStatement* loop_operator = loop->loop->GetOriginal();
|
||||||
@@ -300,7 +266,7 @@ static set<SAPFOR::BasicBlock*> analyzeLoop(LoopGraph* loop, const set<SAPFOR::B
|
|||||||
SAPFOR::BasicBlock* head_block = NULL;
|
SAPFOR::BasicBlock* head_block = NULL;
|
||||||
|
|
||||||
int loop_start = loop->lineNum, loop_end = loop->lineNumAfterLoop;
|
int loop_start = loop->lineNum, loop_end = loop->lineNumAfterLoop;
|
||||||
for (const auto &bb : blocks)
|
for (auto bb : blocks)
|
||||||
{
|
{
|
||||||
if (!bb || (bb->getInstructions().size() == 0))
|
if (!bb || (bb->getInstructions().size() == 0))
|
||||||
continue;
|
continue;
|
||||||
@@ -321,12 +287,6 @@ static set<SAPFOR::BasicBlock*> analyzeLoop(LoopGraph* loop, const set<SAPFOR::B
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (currentLoop.empty()) // can't find loop IR - loop unreachable!
|
|
||||||
{
|
|
||||||
__spf_print(1, "Unreachable loop on %s:%d\n", current_file->filename(), loop_operator->lineNumber());
|
|
||||||
return currentLoop;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!head_block)
|
if (!head_block)
|
||||||
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
||||||
|
|
||||||
@@ -388,7 +348,7 @@ static set<SAPFOR::BasicBlock*> analyzeLoop(LoopGraph* loop, const set<SAPFOR::B
|
|||||||
getDefsFromBlock(*loop_it, changeValueOnExit, commonVars, func);
|
getDefsFromBlock(*loop_it, changeValueOnExit, commonVars, func);
|
||||||
|
|
||||||
|
|
||||||
for (const auto &bb : currentLoop)
|
for (auto bb : currentLoop)
|
||||||
{
|
{
|
||||||
//fill LiveWhenLoopEnds
|
//fill LiveWhenLoopEnds
|
||||||
bool has_next_outside_body = false;
|
bool has_next_outside_body = false;
|
||||||
@@ -490,7 +450,7 @@ static void recAnalyzeLoop(LoopGraph* loop, const set<SAPFOR::BasicBlock*>& bloc
|
|||||||
const map<string, SgSymbol*>& commonArgs,
|
const map<string, SgSymbol*>& commonArgs,
|
||||||
FuncInfo* func, map<string, vector<Messages>>& messages)
|
FuncInfo* func, map<string, vector<Messages>>& messages)
|
||||||
{
|
{
|
||||||
const auto& loop_body = loop->isFor() ? analyzeLoop(loop, blocks, commonVars, commonArgs, func, messages) : blocks;
|
const auto& loop_body = loop->isFor ? analyzeLoop(loop, blocks, commonVars, commonArgs, func, messages) : blocks;
|
||||||
|
|
||||||
for (const auto& inner_loop : loop->children)
|
for (const auto& inner_loop : loop->children)
|
||||||
recAnalyzeLoop(inner_loop, loop_body, commonVars, commonArgs, func, messages);
|
recAnalyzeLoop(inner_loop, loop_body, commonVars, commonArgs, func, messages);
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#include "SgUtils.h"
|
#include "../Utils/SgUtils.h"
|
||||||
#include "graph_loops.h"
|
#include "../GraphLoop/graph_loops.h"
|
||||||
#include "CFGraph.h"
|
#include "CFGraph.h"
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#include "CreateInterTree.h"
|
#include "CreateInterTree.h"
|
||||||
#include "SgUtils.h"
|
#include "../Utils/SgUtils.h"
|
||||||
#include "utils.h"
|
#include "../Utils/utils.h"
|
||||||
#include "graph_calls_func.h"
|
#include "../GraphCall/graph_calls_func.h"
|
||||||
|
|
||||||
using std::string;
|
using std::string;
|
||||||
using std::wstring;
|
using std::wstring;
|
||||||
@@ -17,7 +17,7 @@ using std::fstream;
|
|||||||
static long int getNextTag()
|
static long int getNextTag()
|
||||||
{
|
{
|
||||||
static long int INTERVAL_TAG = 0;
|
static long int INTERVAL_TAG = 0;
|
||||||
return -(INTERVAL_TAG++);
|
return INTERVAL_TAG++;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Debug funcs
|
//Debug funcs
|
||||||
@@ -413,7 +413,7 @@ static void findIntervals(SpfInterval *interval, map<int, int> &labelsRef, map<i
|
|||||||
inter->lineFile = std::make_pair(currentSt->lineNumber(), currentSt->fileName());
|
inter->lineFile = std::make_pair(currentSt->lineNumber(), currentSt->fileName());
|
||||||
inter->parent = interval;
|
inter->parent = interval;
|
||||||
inter->exit_levels.push_back(0);
|
inter->exit_levels.push_back(0);
|
||||||
inter->tag = currentSt->lineNumber();//getNextTag();
|
inter->tag = getNextTag();
|
||||||
interval->nested.push_back(inter);
|
interval->nested.push_back(inter);
|
||||||
|
|
||||||
findIntervals(inter, labelsRef, gotoStmts, currentSt);
|
findIntervals(inter, labelsRef, gotoStmts, currentSt);
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
#include "dvm.h"
|
#include "dvm.h"
|
||||||
|
|
||||||
#include "graph_loops_func.h"
|
#include "../GraphLoop/graph_loops_func.h"
|
||||||
|
|
||||||
struct SpfInterval
|
struct SpfInterval
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#include "leak_detector.h"
|
#include "../Utils/leak_detector.h"
|
||||||
|
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
@@ -16,9 +16,9 @@
|
|||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
#include "../Distribution/DvmhDirective.h"
|
#include "../Distribution/DvmhDirective.h"
|
||||||
#include "graph_loops.h"
|
#include "../GraphLoop/graph_loops.h"
|
||||||
#include "directive_analyzer.h"
|
#include "directive_analyzer.h"
|
||||||
#include "utils.h"
|
#include "../Utils/utils.h"
|
||||||
|
|
||||||
using std::vector;
|
using std::vector;
|
||||||
using std::map;
|
using std::map;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "graph_loops.h"
|
#include "../GraphLoop/graph_loops.h"
|
||||||
|
|
||||||
void UniteNestedDirectives(std::vector<LoopGraph*> &loopGraph);
|
void UniteNestedDirectives(std::vector<LoopGraph*> &loopGraph);
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#include "leak_detector.h"
|
#include "../Utils/leak_detector.h"
|
||||||
|
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
@@ -15,18 +15,18 @@
|
|||||||
#include "../Distribution/Distribution.h"
|
#include "../Distribution/Distribution.h"
|
||||||
#include "../Distribution/DvmhDirective_func.h"
|
#include "../Distribution/DvmhDirective_func.h"
|
||||||
|
|
||||||
#include "errors.h"
|
#include "../Utils/errors.h"
|
||||||
#include "../LoopAnalyzer/loop_analyzer.h"
|
#include "../LoopAnalyzer/loop_analyzer.h"
|
||||||
#include "directive_parser.h"
|
#include "directive_parser.h"
|
||||||
#include "directive_creator.h"
|
#include "directive_creator.h"
|
||||||
#include "SgUtils.h"
|
#include "../Utils/SgUtils.h"
|
||||||
#include "../Sapfor.h"
|
#include "../Sapfor.h"
|
||||||
#include "graph_loops_func.h"
|
#include "../GraphLoop/graph_loops_func.h"
|
||||||
#include "LoopNesting/loop_transform.h"
|
#include "../Transformations/loop_transform.h"
|
||||||
#include "expr_transform.h"
|
#include "../ExpressionTransform/expr_transform.h"
|
||||||
#include "graph_calls_func.h"
|
#include "../GraphCall/graph_calls_func.h"
|
||||||
|
|
||||||
#include "AstWrapper.h"
|
#include "../Utils/AstWrapper.h"
|
||||||
|
|
||||||
#define PRINT_DIR_RESULT 0
|
#define PRINT_DIR_RESULT 0
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "../Distribution/Distribution.h"
|
#include "../Distribution/Distribution.h"
|
||||||
#include "errors.h"
|
#include "../Utils/errors.h"
|
||||||
#include "graph_loops.h"
|
#include "../GraphLoop/graph_loops.h"
|
||||||
#include "types.h"
|
#include "../Utils/types.h"
|
||||||
|
|
||||||
void createParallelDirectives(const std::map<LoopGraph*, std::map<DIST::Array*, ArrayInfo*>> &loopInfo,
|
void createParallelDirectives(const std::map<LoopGraph*, std::map<DIST::Array*, ArrayInfo*>> &loopInfo,
|
||||||
const std::vector<ParallelRegion*>& regions,
|
const std::vector<ParallelRegion*>& regions,
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#include "leak_detector.h"
|
#include "../Utils/leak_detector.h"
|
||||||
|
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
@@ -10,9 +10,9 @@
|
|||||||
|
|
||||||
#include "../ParallelizationRegions/ParRegions.h"
|
#include "../ParallelizationRegions/ParRegions.h"
|
||||||
#include "../Distribution/Arrays.h"
|
#include "../Distribution/Arrays.h"
|
||||||
#include "LoopNesting/loop_transform.h"
|
#include "../Transformations/loop_transform.h"
|
||||||
|
|
||||||
#include "errors.h"
|
#include "../Utils/errors.h"
|
||||||
#include "directive_parser.h"
|
#include "directive_parser.h"
|
||||||
#include "directive_creator.h"
|
#include "directive_creator.h"
|
||||||
|
|
||||||
@@ -75,7 +75,7 @@ static LoopGraph* createDirectiveForLoop(LoopGraph *currentLoop, MapToArray &mai
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
directive->parallel.push_back(currentLoop->loopSymbol());
|
directive->parallel.push_back(currentLoop->loopSymbol);
|
||||||
directive->arrayRef = mainArray.arrayRef;
|
directive->arrayRef = mainArray.arrayRef;
|
||||||
|
|
||||||
DIST::Array *tmp = mainArray.arrayRef;
|
DIST::Array *tmp = mainArray.arrayRef;
|
||||||
@@ -84,7 +84,7 @@ static LoopGraph* createDirectiveForLoop(LoopGraph *currentLoop, MapToArray &mai
|
|||||||
for (int i = 0; i < tmp->GetDimSize(); ++i)
|
for (int i = 0; i < tmp->GetDimSize(); ++i)
|
||||||
{
|
{
|
||||||
if (i == pos)
|
if (i == pos)
|
||||||
directive->on.push_back(make_pair(currentLoop->loopSymbol(), mainAccess));
|
directive->on.push_back(make_pair(currentLoop->loopSymbol, mainAccess));
|
||||||
else
|
else
|
||||||
directive->on.push_back(make_pair("*", make_pair(0, 0)));
|
directive->on.push_back(make_pair("*", make_pair(0, 0)));
|
||||||
}
|
}
|
||||||
@@ -808,7 +808,7 @@ void createParallelDirectives(const map<LoopGraph*, map<DIST::Array*, ArrayInfo*
|
|||||||
for (int i = 0; i < mainArrayOfLoop->GetDimSize(); ++i)
|
for (int i = 0; i < mainArrayOfLoop->GetDimSize(); ++i)
|
||||||
{
|
{
|
||||||
if (i == dimPos)
|
if (i == dimPos)
|
||||||
parDir->on2.push_back(make_pair(currLoop->loopSymbol(), mainAccess));
|
parDir->on2.push_back(make_pair(currLoop->loopSymbol, mainAccess));
|
||||||
else
|
else
|
||||||
parDir->on2.push_back(make_pair("*", make_pair(0, 0)));
|
parDir->on2.push_back(make_pair("*", make_pair(0, 0)));
|
||||||
}
|
}
|
||||||
@@ -1100,7 +1100,7 @@ static bool tryToResolveUnmatchedDims(const map<DIST::Array*, vector<bool>> &dim
|
|||||||
LoopGraph* tmpL = loop;
|
LoopGraph* tmpL = loop;
|
||||||
for (int z = 0; z < nested; ++z)
|
for (int z = 0; z < nested; ++z)
|
||||||
{
|
{
|
||||||
deprecateToMatch.insert(tmpL->loopSymbol());
|
deprecateToMatch.insert(tmpL->loopSymbol);
|
||||||
if (tmpL->children.size())
|
if (tmpL->children.size())
|
||||||
tmpL = tmpL->children[0];
|
tmpL = tmpL->children[0];
|
||||||
else if (z != nested - 1)
|
else if (z != nested - 1)
|
||||||
@@ -1113,7 +1113,7 @@ static bool tryToResolveUnmatchedDims(const map<DIST::Array*, vector<bool>> &dim
|
|||||||
tmpL = loop->parent;
|
tmpL = loop->parent;
|
||||||
while (tmpL)
|
while (tmpL)
|
||||||
{
|
{
|
||||||
if (tmpL->isWhile()) // TODO: need to add all inductive variables!
|
if (!tmpL->isFor) // TODO: need to add all inductive variables!
|
||||||
{
|
{
|
||||||
SgWhileStmt* dow = isSgWhileStmt(tmpL->loop->GetOriginal());
|
SgWhileStmt* dow = isSgWhileStmt(tmpL->loop->GetOriginal());
|
||||||
if (dow->conditional())
|
if (dow->conditional())
|
||||||
@@ -1124,7 +1124,7 @@ static bool tryToResolveUnmatchedDims(const map<DIST::Array*, vector<bool>> &dim
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
deprecateToMatch.insert(tmpL->loopSymbol());
|
deprecateToMatch.insert(tmpL->loopSymbol);
|
||||||
tmpL = tmpL->parent;
|
tmpL = tmpL->parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1601,7 +1601,7 @@ static bool matchParallelAndDist(const pair<DIST::Array*, const DistrVariant*>&
|
|||||||
parallelOn = NULL;
|
parallelOn = NULL;
|
||||||
for (auto& refOn : realRefs)
|
for (auto& refOn : realRefs)
|
||||||
{
|
{
|
||||||
linkWithTempl = refOn->GetLinksWithTemplate(regionId);
|
linkWithTempl = parallelOn->GetLinksWithTemplate(regionId);
|
||||||
int z = 0;
|
int z = 0;
|
||||||
for (int k = 0; k < linkWithTempl.size(); ++k)
|
for (int k = 0; k < linkWithTempl.size(); ++k)
|
||||||
if (linkWithTempl[k] != -1)
|
if (linkWithTempl[k] != -1)
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#include "leak_detector.h"
|
#include "../Utils/leak_detector.h"
|
||||||
|
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
@@ -9,7 +9,7 @@
|
|||||||
#include "directive_omp_parser.h"
|
#include "directive_omp_parser.h"
|
||||||
#include "directive_parser.h"
|
#include "directive_parser.h"
|
||||||
|
|
||||||
#include "SgUtils.h"
|
#include "../Utils/SgUtils.h"
|
||||||
|
|
||||||
using std::vector;
|
using std::vector;
|
||||||
using std::map;
|
using std::map;
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
#include <map>
|
#include <map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "errors.h"
|
#include "../Utils/errors.h"
|
||||||
|
|
||||||
#define SPF_USER_DIR 777
|
#define SPF_USER_DIR 777
|
||||||
#define SPF_USER_DIR_COPY 999
|
#define SPF_USER_DIR_COPY 999
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#include "leak_detector.h"
|
#include "../Utils/leak_detector.h"
|
||||||
|
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
@@ -12,10 +12,10 @@
|
|||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
#include "directive_parser.h"
|
#include "directive_parser.h"
|
||||||
#include "SgUtils.h"
|
#include "../Utils/SgUtils.h"
|
||||||
#include "../LoopAnalyzer/loop_analyzer.h"
|
#include "../LoopAnalyzer/loop_analyzer.h"
|
||||||
#include "AstWrapper.h"
|
#include "../Utils/AstWrapper.h"
|
||||||
#include "errors.h"
|
#include "../Utils/errors.h"
|
||||||
|
|
||||||
using std::string;
|
using std::string;
|
||||||
using std::vector;
|
using std::vector;
|
||||||
|
|||||||
@@ -4,8 +4,8 @@
|
|||||||
#include <set>
|
#include <set>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
#include "AstWrapper.h"
|
#include "../Utils/AstWrapper.h"
|
||||||
#include "graph_loops.h"
|
#include "../GraphLoop/graph_loops.h"
|
||||||
#include "../Distribution/DvmhDirective.h"
|
#include "../Distribution/DvmhDirective.h"
|
||||||
|
|
||||||
struct DvmDirective
|
struct DvmDirective
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#include "leak_detector.h"
|
#include "../Utils/leak_detector.h"
|
||||||
|
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
@@ -16,13 +16,13 @@
|
|||||||
#include "../Distribution/Arrays.h"
|
#include "../Distribution/Arrays.h"
|
||||||
#include "../Distribution/Distribution.h"
|
#include "../Distribution/Distribution.h"
|
||||||
#include "../Distribution/DvmhDirective_func.h"
|
#include "../Distribution/DvmhDirective_func.h"
|
||||||
#include "graph_loops_func.h"
|
#include "../GraphLoop/graph_loops_func.h"
|
||||||
#include "graph_calls_func.h"
|
#include "../GraphCall/graph_calls_func.h"
|
||||||
|
|
||||||
#include "errors.h"
|
#include "../Utils/errors.h"
|
||||||
#include "../LoopAnalyzer/loop_analyzer.h"
|
#include "../LoopAnalyzer/loop_analyzer.h"
|
||||||
#include "directive_parser.h"
|
#include "directive_parser.h"
|
||||||
#include "SgUtils.h"
|
#include "../Utils/SgUtils.h"
|
||||||
#include "../Sapfor.h"
|
#include "../Sapfor.h"
|
||||||
#include "directive_creator.h"
|
#include "directive_creator.h"
|
||||||
#include "insert_directive.h"
|
#include "insert_directive.h"
|
||||||
@@ -853,21 +853,12 @@ static pair<string, string> getModuleRename(const set<SgStatement*>& allocatable
|
|||||||
return make_pair("", "");
|
return make_pair("", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void doRename(string& str, const pair<string, string>& renamePair)
|
|
||||||
{
|
|
||||||
auto it = str.find(renamePair.first);
|
|
||||||
if (it != string::npos)
|
|
||||||
if (str[it + renamePair.first.size()] == '(' && str[it - 1] == ' ')
|
|
||||||
str = str.replace(it, renamePair.first.size(), renamePair.second);
|
|
||||||
}
|
|
||||||
|
|
||||||
static pair<DIST::Array*, string>
|
static pair<DIST::Array*, string>
|
||||||
getNewDirective(const string &fullArrayName,
|
getNewDirective(const string &fullArrayName,
|
||||||
const vector<string> &distrRules,
|
const vector<string> &distrRules,
|
||||||
const vector<string> &alignRules,
|
const vector<string> &alignRules,
|
||||||
const DataDirective &dataDir,
|
const DataDirective &dataDir,
|
||||||
const set<SgStatement*>& allocatableStmts,
|
const set<SgStatement*>& allocatableStmts)
|
||||||
const pair<string, int>& position_decl)
|
|
||||||
{
|
{
|
||||||
string out = "";
|
string out = "";
|
||||||
DIST::Array* outA = NULL;
|
DIST::Array* outA = NULL;
|
||||||
@@ -886,8 +877,7 @@ getNewDirective(const string &fullArrayName,
|
|||||||
|
|
||||||
for (int i = 0; i < dataDir.alignRules.size(); ++i)
|
for (int i = 0; i < dataDir.alignRules.size(); ++i)
|
||||||
{
|
{
|
||||||
auto alignArray = dataDir.alignRules[i].alignArray;
|
if (dataDir.alignRules[i].alignArray->GetName() == fullArrayName)
|
||||||
if (alignArray->GetName() == fullArrayName)
|
|
||||||
{
|
{
|
||||||
string rule = alignRules[i];
|
string rule = alignRules[i];
|
||||||
if (allocatableStmts.size())
|
if (allocatableStmts.size())
|
||||||
@@ -899,21 +889,21 @@ getNewDirective(const string &fullArrayName,
|
|||||||
it = rule.find("ALIGN", it + 7);
|
it = rule.find("ALIGN", it + 7);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto renamePair = getModuleRename(allocatableStmts, alignArray);
|
auto renamePair = getModuleRename(allocatableStmts, dataDir.alignRules[i].alignArray);
|
||||||
doRename(rule, renamePair);
|
if (renamePair.first != "")
|
||||||
}
|
|
||||||
else if (alignArray->GetLocation().first == DIST::l_COMMON)
|
|
||||||
{
|
{
|
||||||
auto symb = alignArray->GetDeclSymbol(position_decl);
|
it = rule.find(renamePair.first);
|
||||||
if (symb->identifier() != alignArray->GetShortName())
|
if (it != string::npos)
|
||||||
doRename(rule, make_pair(alignArray->GetShortName(), symb->identifier()));
|
if (rule[it + renamePair.first.size()] == '(' && rule[it - 1] == ' ')
|
||||||
|
rule = rule.replace(it, renamePair.first.size(), renamePair.second);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
out += "!DVM$ " + rule + "\n";
|
out += "!DVM$ " + rule + "\n";
|
||||||
if (!out_free_form)
|
if (!out_free_form)
|
||||||
out = splitDirective(out);
|
out = splitDirective(out);
|
||||||
|
|
||||||
return make_pair(alignArray, out);
|
return make_pair(dataDir.alignRules[i].alignArray, out);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1753,7 +1743,7 @@ void insertDistributionToFile(SgFile *file, const char *fin_name, const DataDire
|
|||||||
if (allocatableStmtsCopy.size())
|
if (allocatableStmtsCopy.size())
|
||||||
allocatableStmts = filterAllocateStats(file, allocatableStmtsCopy, currSymb->identifier());
|
allocatableStmts = filterAllocateStats(file, allocatableStmtsCopy, currSymb->identifier());
|
||||||
|
|
||||||
pair<DIST::Array*, string> dirWithArray = getNewDirective(fullArrayName, distrRules, alignRules, dataDir, allocatableStmts, make_pair(st->fileName(), st->lineNumber()));
|
pair<DIST::Array*, string> dirWithArray = getNewDirective(fullArrayName, distrRules, alignRules, dataDir, allocatableStmts);
|
||||||
|
|
||||||
string toInsert = dirWithArray.second;
|
string toInsert = dirWithArray.second;
|
||||||
if (toInsert != "")
|
if (toInsert != "")
|
||||||
@@ -1985,27 +1975,20 @@ void insertDistributionToFile(SgFile *file, const char *fin_name, const DataDire
|
|||||||
set<string> toInsertArrays;
|
set<string> toInsertArrays;
|
||||||
for (auto &array : dynamicArraysLocal)
|
for (auto &array : dynamicArraysLocal)
|
||||||
{
|
{
|
||||||
string name = array->GetShortName();
|
|
||||||
if (array->GetLocation().first == DIST::l_COMMON)
|
|
||||||
{
|
|
||||||
auto symb = array->GetDeclSymbol(make_pair(st->fileName(), st->lineNumber()));
|
|
||||||
name = symb->identifier();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (extractDir)
|
if (extractDir)
|
||||||
{
|
{
|
||||||
if (dynamicArraysAdded.find(name) != dynamicArraysAdded.end())
|
if (dynamicArraysAdded.find(array->GetShortName()) != dynamicArraysAdded.end())
|
||||||
{
|
{
|
||||||
dynamicArraysAdded.erase(name);
|
dynamicArraysAdded.erase(array->GetShortName());
|
||||||
toInsertArrays.insert(name);
|
toInsertArrays.insert(array->GetShortName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (dynamicArraysAdded.find(name) == dynamicArraysAdded.end())
|
if (dynamicArraysAdded.find(array->GetShortName()) == dynamicArraysAdded.end())
|
||||||
{
|
{
|
||||||
dynamicArraysAdded.insert(name);
|
dynamicArraysAdded.insert(array->GetShortName());
|
||||||
toInsertArrays.insert(name);
|
toInsertArrays.insert(array->GetShortName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2162,14 +2145,7 @@ void insertShadowSpecToFile(SgFile *file, const char *fin_name, const set<string
|
|||||||
|
|
||||||
if (needToGen)
|
if (needToGen)
|
||||||
{
|
{
|
||||||
string name = array->GetShortName();
|
string shadowSpecInsert = "!DVM$ SHADOW " + array->GetShortName() + "(";
|
||||||
if (array->GetLocation().first == DIST::l_COMMON)
|
|
||||||
{
|
|
||||||
auto symb = array->GetDeclSymbol(make_pair(st->fileName(), st->lineNumber()));
|
|
||||||
name = symb->identifier();
|
|
||||||
}
|
|
||||||
|
|
||||||
string shadowSpecInsert = "!DVM$ SHADOW " + name + "(";
|
|
||||||
for (int k = 0; k < currSpec.size(); ++k)
|
for (int k = 0; k < currSpec.size(); ++k)
|
||||||
{
|
{
|
||||||
char buf[256];
|
char buf[256];
|
||||||
@@ -2181,7 +2157,7 @@ void insertShadowSpecToFile(SgFile *file, const char *fin_name, const set<string
|
|||||||
shadowSpecInsert += ")\n";
|
shadowSpecInsert += ")\n";
|
||||||
|
|
||||||
shadowsSpecsString.push_back(shadowSpecInsert);
|
shadowsSpecsString.push_back(shadowSpecInsert);
|
||||||
pair<SgExpression*, SgExpression*> newSpec = genShadowSpec(file, make_pair(name, currSpec));
|
pair<SgExpression*, SgExpression*> newSpec = genShadowSpec(file, make_pair(array->GetShortName(), currSpec));
|
||||||
if (newSpec.first == NULL || newSpec.second == NULL)
|
if (newSpec.first == NULL || newSpec.second == NULL)
|
||||||
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
||||||
shadowsSpecs.push_back(newSpec);
|
shadowsSpecs.push_back(newSpec);
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#include "leak_detector.h"
|
#include "../Utils/leak_detector.h"
|
||||||
|
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
@@ -18,13 +18,13 @@
|
|||||||
|
|
||||||
#include "dvm.h"
|
#include "dvm.h"
|
||||||
#include "../LoopAnalyzer/loop_analyzer.h"
|
#include "../LoopAnalyzer/loop_analyzer.h"
|
||||||
#include "types.h"
|
#include "../Utils/types.h"
|
||||||
#include "errors.h"
|
#include "../Utils/errors.h"
|
||||||
#include "SgUtils.h"
|
#include "../Utils/SgUtils.h"
|
||||||
#include "../Distribution/Arrays.h"
|
#include "../Distribution/Arrays.h"
|
||||||
#include "graph_calls.h"
|
#include "../GraphCall/graph_calls.h"
|
||||||
#include "graph_calls_func.h"
|
#include "../GraphCall/graph_calls_func.h"
|
||||||
#include "graph_loops_func.h"
|
#include "../GraphLoop/graph_loops_func.h"
|
||||||
#include "remote_access.h"
|
#include "remote_access.h"
|
||||||
|
|
||||||
using std::vector;
|
using std::vector;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#include "leak_detector.h"
|
#include "../Utils/leak_detector.h"
|
||||||
|
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
@@ -17,8 +17,8 @@
|
|||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
#include "../Distribution/Arrays.h"
|
#include "../Distribution/Arrays.h"
|
||||||
#include "graph_calls.h"
|
#include "../GraphCall/graph_calls.h"
|
||||||
#include "graph_loops.h"
|
#include "../GraphLoop/graph_loops.h"
|
||||||
#include "../ParallelizationRegions/ParRegions.h"
|
#include "../ParallelizationRegions/ParRegions.h"
|
||||||
#include "remote_access.h"
|
#include "remote_access.h"
|
||||||
|
|
||||||
|
|||||||
@@ -1,21 +1,21 @@
|
|||||||
#include "leak_detector.h"
|
#include "../Utils/leak_detector.h"
|
||||||
|
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "errors.h"
|
#include "../Utils/errors.h"
|
||||||
#include "utils.h"
|
#include "../Utils/utils.h"
|
||||||
#include "graph_loops_func.h"
|
#include "../GraphLoop/graph_loops_func.h"
|
||||||
#include "graph_calls.h"
|
#include "../GraphCall/graph_calls.h"
|
||||||
#include "graph_calls_func.h"
|
#include "../GraphCall/graph_calls_func.h"
|
||||||
#include "directive_parser.h"
|
#include "directive_parser.h"
|
||||||
#include "../Distribution/DvmhDirective_func.h"
|
#include "../Distribution/DvmhDirective_func.h"
|
||||||
#include "SgUtils.h"
|
#include "../Utils/SgUtils.h"
|
||||||
#include "expr_transform.h"
|
#include "../ExpressionTransform/expr_transform.h"
|
||||||
|
|
||||||
#include "CFGraph/CFGraph.h"
|
#include "../CFGraph/CFGraph.h"
|
||||||
|
|
||||||
#include "shadow.h"
|
#include "shadow.h"
|
||||||
#include "dvm.h"
|
#include "dvm.h"
|
||||||
@@ -26,7 +26,6 @@ using std::string;
|
|||||||
using std::vector;
|
using std::vector;
|
||||||
using std::pair;
|
using std::pair;
|
||||||
using std::make_pair;
|
using std::make_pair;
|
||||||
using SAPFOR::CFG_Settings;
|
|
||||||
|
|
||||||
extern int debSh;
|
extern int debSh;
|
||||||
|
|
||||||
@@ -1673,12 +1672,9 @@ void GroupShadow(const map<string, vector<FuncInfo*>>& allFuncs,
|
|||||||
|
|
||||||
SgStatement* func = currF->funcPointer->GetOriginal();
|
SgStatement* func = currF->funcPointer->GetOriginal();
|
||||||
|
|
||||||
const auto settings = CFG_Settings({ CFG_Settings::CFG_atLeastOneIterInLoop, CFG_Settings::CFG_withDVM,
|
auto cfg = buildCFGforCurrentFunc(func, SAPFOR::CFG_Settings(true, false, false, true, false, true, false), commonBlocks, allFuncs);
|
||||||
CFG_Settings::CFG_withCallsInBlocks, CFG_Settings::CFG_withUnreachable });
|
|
||||||
auto cfg = buildCFGforCurrentFunc(func, settings, commonBlocks, allFuncs);
|
|
||||||
if (cfg.size() != 1)
|
if (cfg.size() != 1)
|
||||||
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
||||||
|
|
||||||
auto& blocks = cfg.begin()->second;
|
auto& blocks = cfg.begin()->second;
|
||||||
|
|
||||||
//create reaching blocks
|
//create reaching blocks
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#include "leak_detector.h"
|
#include "../Utils/leak_detector.h"
|
||||||
|
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
@@ -12,13 +12,13 @@
|
|||||||
|
|
||||||
#include "dvm.h"
|
#include "dvm.h"
|
||||||
#include "../Sapfor.h"
|
#include "../Sapfor.h"
|
||||||
#include "graph_loops.h"
|
#include "../GraphLoop/graph_loops.h"
|
||||||
#include "graph_calls_func.h"
|
#include "../GraphCall/graph_calls_func.h"
|
||||||
#include "../SageAnalysisTool/depInterfaceExt.h"
|
#include "../SageAnalysisTool/depInterfaceExt.h"
|
||||||
#include "SgUtils.h"
|
#include "../Utils/SgUtils.h"
|
||||||
#include "errors.h"
|
#include "../Utils/errors.h"
|
||||||
#include "directive_parser.h"
|
#include "directive_parser.h"
|
||||||
#include "expr_transform.h"
|
#include "../ExpressionTransform/expr_transform.h"
|
||||||
#include "../LoopAnalyzer/loop_analyzer.h"
|
#include "../LoopAnalyzer/loop_analyzer.h"
|
||||||
#include "../DirectiveProcessing/directive_omp_parser.h"
|
#include "../DirectiveProcessing/directive_omp_parser.h"
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#include "Array.h"
|
#include "Array.h"
|
||||||
#include "errors.h"
|
#include "../Utils/errors.h"
|
||||||
#include "utils.h"
|
#include "../Utils/utils.h"
|
||||||
#include "graph_calls.h"
|
#include "../GraphCall/graph_calls.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
|||||||
@@ -7,9 +7,9 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <climits>
|
#include <climits>
|
||||||
#include "DvmhDirectiveBase.h"
|
#include "DvmhDirectiveBase.h"
|
||||||
#include "utils.h"
|
#include "../Utils/utils.h"
|
||||||
#include "errors.h"
|
#include "../Utils/errors.h"
|
||||||
#include "json.hpp"
|
#include "../Utils/json.hpp"
|
||||||
|
|
||||||
class Symbol;
|
class Symbol;
|
||||||
class Expression;
|
class Expression;
|
||||||
@@ -106,7 +106,7 @@ namespace Distribution
|
|||||||
MAP<STRING, SET<int>> usagePlaces;
|
MAP<STRING, SET<int>> usagePlaces;
|
||||||
|
|
||||||
VECTOR<bool> mappedDims;
|
VECTOR<bool> mappedDims;
|
||||||
VECTOR<bool> deprecateToDistribute;
|
VECTOR<bool> depracateToDistribute;
|
||||||
|
|
||||||
bool ompThreadPrivate;
|
bool ompThreadPrivate;
|
||||||
bool privateInLoop;
|
bool privateInLoop;
|
||||||
@@ -171,7 +171,7 @@ namespace Distribution
|
|||||||
sizes.resize(dimSize);
|
sizes.resize(dimSize);
|
||||||
sizesExpr.resize(dimSize);
|
sizesExpr.resize(dimSize);
|
||||||
mappedDims.resize(dimSize);
|
mappedDims.resize(dimSize);
|
||||||
deprecateToDistribute.resize(dimSize);
|
depracateToDistribute.resize(dimSize);
|
||||||
|
|
||||||
for (int z = 0; z < dimSize; ++z)
|
for (int z = 0; z < dimSize; ++z)
|
||||||
{
|
{
|
||||||
@@ -179,7 +179,7 @@ namespace Distribution
|
|||||||
PAIR<int, int> initVal = std::make_pair(0, 0);
|
PAIR<int, int> initVal = std::make_pair(0, 0);
|
||||||
sizesExpr[z] = std::make_pair(std::make_pair((Expression*)NULL, initVal), std::make_pair((Expression*)NULL, initVal));
|
sizesExpr[z] = std::make_pair(std::make_pair((Expression*)NULL, initVal), std::make_pair((Expression*)NULL, initVal));
|
||||||
mappedDims[z] = false;
|
mappedDims[z] = false;
|
||||||
deprecateToDistribute[z] = false;
|
depracateToDistribute[z] = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
GenUniqKey();
|
GenUniqKey();
|
||||||
@@ -214,7 +214,7 @@ namespace Distribution
|
|||||||
uniqKey = copy.uniqKey;
|
uniqKey = copy.uniqKey;
|
||||||
containsInRegions = copy.containsInRegions;
|
containsInRegions = copy.containsInRegions;
|
||||||
mappedDims = copy.mappedDims;
|
mappedDims = copy.mappedDims;
|
||||||
deprecateToDistribute = copy.deprecateToDistribute;
|
depracateToDistribute = copy.depracateToDistribute;
|
||||||
ompThreadPrivate = copy.ompThreadPrivate;
|
ompThreadPrivate = copy.ompThreadPrivate;
|
||||||
privateInLoop = copy.privateInLoop;
|
privateInLoop = copy.privateInLoop;
|
||||||
inEquivalence = copy.inEquivalence;
|
inEquivalence = copy.inEquivalence;
|
||||||
@@ -226,7 +226,7 @@ namespace Distribution
|
|||||||
int countToRem = 0;
|
int countToRem = 0;
|
||||||
for (int z = 0; z < dimSize; ++z)
|
for (int z = 0; z < dimSize; ++z)
|
||||||
{
|
{
|
||||||
if (!mappedDims[z] || deprecateToDistribute[z])
|
if (!mappedDims[z] || depracateToDistribute[z])
|
||||||
{
|
{
|
||||||
needToRemove = true;
|
needToRemove = true;
|
||||||
countToRem++;
|
countToRem++;
|
||||||
@@ -246,19 +246,19 @@ namespace Distribution
|
|||||||
|
|
||||||
for (int z = 0; z < dimSize; ++z)
|
for (int z = 0; z < dimSize; ++z)
|
||||||
{
|
{
|
||||||
if (mappedDims[z] && !deprecateToDistribute[z])
|
if (mappedDims[z] && !depracateToDistribute[z])
|
||||||
{
|
{
|
||||||
newSizes.push_back(sizes[z]);
|
newSizes.push_back(sizes[z]);
|
||||||
newSizesExpr.push_back(sizesExpr[z]);
|
newSizesExpr.push_back(sizesExpr[z]);
|
||||||
newMappedDims.push_back(mappedDims[z]);
|
newMappedDims.push_back(mappedDims[z]);
|
||||||
newDepr.push_back(deprecateToDistribute[z]);
|
newDepr.push_back(depracateToDistribute[z]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sizes = newSizes;
|
sizes = newSizes;
|
||||||
sizesExpr = newSizesExpr;
|
sizesExpr = newSizesExpr;
|
||||||
mappedDims = newMappedDims;
|
mappedDims = newMappedDims;
|
||||||
deprecateToDistribute = newDepr;
|
depracateToDistribute = newDepr;
|
||||||
dimSize = (int)sizes.size();
|
dimSize = (int)sizes.size();
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
@@ -336,24 +336,9 @@ namespace Distribution
|
|||||||
if (pos != STRING::npos)
|
if (pos != STRING::npos)
|
||||||
{
|
{
|
||||||
name.erase(pos, shortName.size());
|
name.erase(pos, shortName.size());
|
||||||
name += newName;
|
|
||||||
}
|
|
||||||
else if (locationPos.first == l_COMMON) // name of array in common may be different
|
|
||||||
{
|
|
||||||
pos = name.rfind("_");
|
|
||||||
if (pos != STRING::npos)
|
|
||||||
{
|
|
||||||
name.erase(pos + 1, shortName.size());
|
|
||||||
name += newName;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
#if __SPF
|
|
||||||
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
|
||||||
shortName = newName;
|
shortName = newName;
|
||||||
|
name += newName;
|
||||||
|
}
|
||||||
GenUniqKey();
|
GenUniqKey();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -460,9 +445,9 @@ namespace Distribution
|
|||||||
retVal["isLoopArrayFlag"] = (int)isLoopArrayFlag;
|
retVal["isLoopArrayFlag"] = (int)isLoopArrayFlag;
|
||||||
|
|
||||||
JSON deprToDist = nlohmann::json::array();
|
JSON deprToDist = nlohmann::json::array();
|
||||||
for (int i = 0; i < deprecateToDistribute.size(); ++i)
|
for (int i = 0; i < depracateToDistribute.size(); ++i)
|
||||||
deprToDist.push_back((int)deprecateToDistribute[i]);
|
deprToDist.push_back((int)depracateToDistribute[i]);
|
||||||
retVal["deprecateToDist"] = deprToDist;
|
retVal["depracateToDist"] = deprToDist;
|
||||||
|
|
||||||
JSON mappedDimsJ = nlohmann::json::array();
|
JSON mappedDimsJ = nlohmann::json::array();
|
||||||
for (int i = 0; i < mappedDims.size(); ++i)
|
for (int i = 0; i < mappedDims.size(); ++i)
|
||||||
@@ -557,44 +542,6 @@ namespace Distribution
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
Symbol* GetDeclSymbol(const PAIR<STRING, int>& position_decl) const
|
|
||||||
{
|
|
||||||
if (!IsArray() || locationPos.first != l_COMMON)
|
|
||||||
return declSymbol;
|
|
||||||
|
|
||||||
auto it = declPlacesSymbol.find(position_decl);
|
|
||||||
if (it != declPlacesSymbol.end())
|
|
||||||
return it->second;
|
|
||||||
else // find nearest
|
|
||||||
{
|
|
||||||
MAP<PAIR<STRING, int>, Symbol*> currFile;
|
|
||||||
for (auto& [position, symb] : declPlacesSymbol)
|
|
||||||
{
|
|
||||||
if (position.first == position_decl.first)
|
|
||||||
currFile[position] = symb;
|
|
||||||
}
|
|
||||||
|
|
||||||
PAIR<int, Symbol*> nearest = { (int)0, NULL };
|
|
||||||
const int needed_pos = position_decl.second;
|
|
||||||
|
|
||||||
for (auto& [position, symb] : currFile)
|
|
||||||
{
|
|
||||||
if (nearest.second == NULL)
|
|
||||||
nearest = { abs(position.second - needed_pos), symb };
|
|
||||||
|
|
||||||
if (abs(position.second - needed_pos) < nearest.first)
|
|
||||||
nearest = { abs(position.second - needed_pos), symb };
|
|
||||||
}
|
|
||||||
|
|
||||||
if (nearest.second)
|
|
||||||
return nearest.second;
|
|
||||||
#if __SPF
|
|
||||||
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
Symbol* GetDeclSymbol() const { return declSymbol; }
|
Symbol* GetDeclSymbol() const { return declSymbol; }
|
||||||
void SetDeclSymbol(Symbol *s) { declSymbol = s; }
|
void SetDeclSymbol(Symbol *s) { declSymbol = s; }
|
||||||
|
|
||||||
@@ -658,13 +605,13 @@ namespace Distribution
|
|||||||
{
|
{
|
||||||
if (dim >= dimSize)
|
if (dim >= dimSize)
|
||||||
return;
|
return;
|
||||||
deprecateToDistribute[dim] = value;
|
depracateToDistribute[dim] = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeprecateAllDims()
|
void DeprecateAllDims()
|
||||||
{
|
{
|
||||||
for (int dim = 0; dim < dimSize; ++dim)
|
for (int dim = 0; dim < dimSize; ++dim)
|
||||||
deprecateToDistribute[dim] = true;
|
depracateToDistribute[dim] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsDimDepracated(const int dim) const
|
bool IsDimDepracated(const int dim) const
|
||||||
@@ -674,9 +621,9 @@ namespace Distribution
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (templateDimsOrder.size() == 0)
|
if (templateDimsOrder.size() == 0)
|
||||||
return deprecateToDistribute[dim];
|
return depracateToDistribute[dim];
|
||||||
else
|
else
|
||||||
return deprecateToDistribute[templateDimsOrder[dim]];
|
return depracateToDistribute[templateDimsOrder[dim]];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -684,11 +631,11 @@ namespace Distribution
|
|||||||
{
|
{
|
||||||
bool ret = true;
|
bool ret = true;
|
||||||
for (int z = 0; z < dimSize; ++z)
|
for (int z = 0; z < dimSize; ++z)
|
||||||
ret = ret && deprecateToDistribute[z];
|
ret = ret && depracateToDistribute[z];
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
const VECTOR<bool>& GetDeprecetedDims() const { return deprecateToDistribute; }
|
const VECTOR<bool>& GetDeprecetedDims() const { return depracateToDistribute; }
|
||||||
|
|
||||||
int GetTypeSize() const { return typeSize; }
|
int GetTypeSize() const { return typeSize; }
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
#include "Array.h"
|
#include "Array.h"
|
||||||
#include "errors.h"
|
#include "../Utils/errors.h"
|
||||||
#include "utils.h"
|
#include "../Utils/utils.h"
|
||||||
#include "graph_calls.h"
|
#include "../GraphCall/graph_calls.h"
|
||||||
#include "SgUtils.h"
|
#include "../Utils/SgUtils.h"
|
||||||
#include "../DirectiveProcessing/directive_parser.h"
|
#include "../DirectiveProcessing/directive_parser.h"
|
||||||
#include "../DirectiveProcessing/directive_omp_parser.h"
|
#include "../DirectiveProcessing/directive_omp_parser.h"
|
||||||
#include "../LoopAnalyzer/loop_analyzer.h"
|
#include "../LoopAnalyzer/loop_analyzer.h"
|
||||||
@@ -241,15 +241,13 @@ static void findArrayRefs (SgExpression* ex, SgStatement* st, string fName, int
|
|||||||
itNew->second.first->SetRegionPlace(reg);
|
itNew->second.first->SetRegionPlace(reg);
|
||||||
|
|
||||||
const auto oldVal = itNew->second.first->GetDistributeFlagVal();
|
const auto oldVal = itNew->second.first->GetDistributeFlagVal();
|
||||||
bool isArrayInModule = (itNew->second.first->GetLocation().first == DIST::l_MODULE);
|
bool isarrayInModule = (itNew->second.first->GetLocation().first == DIST::l_MODULE);
|
||||||
|
|
||||||
if (oldVal == DIST::DISTR || oldVal == DIST::NO_DISTR)
|
if (oldVal == DIST::DISTR || oldVal == DIST::NO_DISTR)
|
||||||
{
|
{
|
||||||
if (itNew->second.first->IsOmpThreadPrivate())
|
if (itNew->second.first->IsOmpThreadPrivate())
|
||||||
itNew->second.first->SetDistributeFlag(DIST::SPF_PRIV);
|
itNew->second.first->SetDistributeFlag(DIST::SPF_PRIV);
|
||||||
else if (deprecatedByIO.find(symb->identifier()) != deprecatedByIO.end())
|
else if (privates.find(symb->identifier()) != privates.end() || isarrayInModule)
|
||||||
itNew->second.first->SetDistributeFlag(DIST::IO_PRIV);
|
|
||||||
else if (isArrayInModule || privates.find(symb->identifier()) != privates.end())
|
|
||||||
{
|
{
|
||||||
//check in module
|
//check in module
|
||||||
if (itNew->second.first->GetLocation().first == DIST::l_MODULE)
|
if (itNew->second.first->GetLocation().first == DIST::l_MODULE)
|
||||||
@@ -276,6 +274,8 @@ static void findArrayRefs (SgExpression* ex, SgStatement* st, string fName, int
|
|||||||
else
|
else
|
||||||
itNew->second.first->SetDistributeFlag(DIST::SPF_PRIV);
|
itNew->second.first->SetDistributeFlag(DIST::SPF_PRIV);
|
||||||
}
|
}
|
||||||
|
else if (deprecatedByIO.find(symb->identifier()) != deprecatedByIO.end())
|
||||||
|
itNew->second.first->SetDistributeFlag(DIST::IO_PRIV);
|
||||||
else if (isSgConstantSymb(symb) || inDataStat)
|
else if (isSgConstantSymb(symb) || inDataStat)
|
||||||
itNew->second.first->SetDistributeFlag(DIST::SPF_PRIV);
|
itNew->second.first->SetDistributeFlag(DIST::SPF_PRIV);
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#include "leak_detector.h"
|
#include "../Utils/leak_detector.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@@ -14,9 +14,9 @@
|
|||||||
#include "GraphCSR.h"
|
#include "GraphCSR.h"
|
||||||
#include "Arrays.h"
|
#include "Arrays.h"
|
||||||
|
|
||||||
#include "errors.h"
|
#include "../Utils/errors.h"
|
||||||
#include "utils.h"
|
#include "../Utils/utils.h"
|
||||||
#include "graph_loops.h"
|
#include "../GraphLoop/graph_loops.h"
|
||||||
|
|
||||||
using std::vector;
|
using std::vector;
|
||||||
using std::set;
|
using std::set;
|
||||||
@@ -274,7 +274,7 @@ static void convertTrees(const map<DIST::Array*, int> &treesIn, map<int, vector<
|
|||||||
static DIST::Array* findBestInEqual(vector<DIST::Array*> &arrays, DIST::GraphCSR<int, double, attrType> &reducedG, DIST::Arrays<int> &allArrays)
|
static DIST::Array* findBestInEqual(vector<DIST::Array*> &arrays, DIST::GraphCSR<int, double, attrType> &reducedG, DIST::Arrays<int> &allArrays)
|
||||||
{
|
{
|
||||||
DIST::Array *retVal = NULL;
|
DIST::Array *retVal = NULL;
|
||||||
vector<vector<attrType>> coeffsByDims;
|
vector<vector<attrType>> coefsByDims;
|
||||||
for (auto &array : arrays)
|
for (auto &array : arrays)
|
||||||
{
|
{
|
||||||
vector<int> verts;
|
vector<int> verts;
|
||||||
@@ -285,7 +285,7 @@ static DIST::Array* findBestInEqual(vector<DIST::Array*> &arrays, DIST::GraphCSR
|
|||||||
{
|
{
|
||||||
retVal = array;
|
retVal = array;
|
||||||
for (auto &V : verts)
|
for (auto &V : verts)
|
||||||
coeffsByDims.push_back(reducedG.GetAllAttributes(V));
|
coefsByDims.push_back(reducedG.GetAllAttributes(V));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -294,11 +294,11 @@ static DIST::Array* findBestInEqual(vector<DIST::Array*> &arrays, DIST::GraphCSR
|
|||||||
toCmp.push_back(reducedG.GetAllAttributes(V));
|
toCmp.push_back(reducedG.GetAllAttributes(V));
|
||||||
for (int z = 0; z < toCmp.size(); ++z)
|
for (int z = 0; z < toCmp.size(); ++z)
|
||||||
{
|
{
|
||||||
if (toCmp[z].size() && coeffsByDims[z].size())
|
if (toCmp[z].size() && coefsByDims[z].size())
|
||||||
{
|
{
|
||||||
if (toCmp[z].back().first.first > coeffsByDims[z].back().first.first)
|
if (toCmp[z].back().first.first > coefsByDims[z].back().first.first)
|
||||||
{
|
{
|
||||||
coeffsByDims = toCmp;
|
coefsByDims = toCmp;
|
||||||
retVal = array;
|
retVal = array;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "graph_loops.h"
|
#include "../GraphLoop/graph_loops.h"
|
||||||
#include "errors.h"
|
#include "../Utils/errors.h"
|
||||||
|
|
||||||
void createDistributionDirs(DIST::GraphCSR<int, double, attrType> &reducedG, DIST::Arrays<int> &allArrays,
|
void createDistributionDirs(DIST::GraphCSR<int, double, attrType> &reducedG, DIST::Arrays<int> &allArrays,
|
||||||
DataDirective &dataDirectives, std::map<std::string, std::vector<Messages>> &allMessages,
|
DataDirective &dataDirectives, std::map<std::string, std::vector<Messages>> &allMessages,
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#include "leak_detector.h"
|
#include "../Utils/leak_detector.h"
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
#include "types.h"
|
#include "../Utils/types.h"
|
||||||
|
|
||||||
namespace Distribution
|
namespace Distribution
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#include "leak_detector.h"
|
#include "../Utils/leak_detector.h"
|
||||||
|
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
@@ -30,9 +30,9 @@ using namespace std::chrono;
|
|||||||
#include "Arrays.h"
|
#include "Arrays.h"
|
||||||
#include "Array.h"
|
#include "Array.h"
|
||||||
#include "Distribution.h"
|
#include "Distribution.h"
|
||||||
#include "utils.h"
|
#include "../Utils/utils.h"
|
||||||
#include "errors.h"
|
#include "../Utils/errors.h"
|
||||||
#include "types.h"
|
#include "../Utils/types.h"
|
||||||
#include "../Distribution/Cycle.h"
|
#include "../Distribution/Cycle.h"
|
||||||
#include "../VisualizerCalls/get_information.h"
|
#include "../VisualizerCalls/get_information.h"
|
||||||
#include "../VisualizerCalls/SendMessage.h"
|
#include "../VisualizerCalls/SendMessage.h"
|
||||||
@@ -455,7 +455,15 @@ namespace Distribution
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (needPrint)
|
if (needPrint)
|
||||||
sendMessage_2lvl(4, k, (int)AllCycles.size());
|
{
|
||||||
|
#if _WIN32
|
||||||
|
wstring treeM = L"ðàçðåøåíèå êîíôëèêòîâ, îáðàáîòêà ãðóïïû " + 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);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
auto timeR = steady_clock::now();
|
auto timeR = steady_clock::now();
|
||||||
if (countConflicts != 0)
|
if (countConflicts != 0)
|
||||||
@@ -508,7 +516,7 @@ namespace Distribution
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (needPrint)
|
if (needPrint)
|
||||||
sendMessage_2lvl(2);
|
sendMessage_2lvl(L"");
|
||||||
|
|
||||||
return make_pair(allOnlySecondType, globalSum);
|
return make_pair(allOnlySecondType, globalSum);
|
||||||
}
|
}
|
||||||
@@ -564,7 +572,13 @@ namespace Distribution
|
|||||||
for (int z = 0; z < arraysV.size(); ++z)
|
for (int z = 0; z < arraysV.size(); ++z)
|
||||||
{
|
{
|
||||||
const DIST::Array *array = arraysV[z];
|
const DIST::Array *array = arraysV[z];
|
||||||
sendMessage_2lvl(5, z, (int)arrays.size());
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
wstring treeM = L"ðàçðåøåíèå êîíôëèêòîâ, îáðàáîòêà ìàññèâà " + 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);
|
||||||
|
|
||||||
vector<vType> verts;
|
vector<vType> verts;
|
||||||
|
|
||||||
@@ -591,7 +605,7 @@ namespace Distribution
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sendMessage_2lvl(2);
|
sendMessage_2lvl(L"");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#include "leak_detector.h"
|
#include "../Utils/leak_detector.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@@ -7,12 +7,12 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
#include "types.h"
|
#include "../Utils/types.h"
|
||||||
#include "DvmhDirective.h"
|
#include "DvmhDirective.h"
|
||||||
#include "errors.h"
|
#include "../Utils/errors.h"
|
||||||
#include "SgUtils.h"
|
#include "../Utils/SgUtils.h"
|
||||||
#include "../Sapfor.h"
|
#include "../Sapfor.h"
|
||||||
#include "graph_calls_func.h"
|
#include "../GraphCall/graph_calls_func.h"
|
||||||
|
|
||||||
#include "dvm.h"
|
#include "dvm.h"
|
||||||
|
|
||||||
@@ -45,10 +45,10 @@ static bool findArrayRefAndCheck(SgExpression *ex, const DIST::Array* currArray,
|
|||||||
int countOfShadows = 0;
|
int countOfShadows = 0;
|
||||||
for (int i = 0; i < ref->numberOfSubscripts(); ++i)
|
for (int i = 0; i < ref->numberOfSubscripts(); ++i)
|
||||||
{
|
{
|
||||||
const vector<int*> &coeffs = getAttributes<SgExpression*, int*>(ref->subscript(i), set<int>{ INT_VAL });
|
const vector<int*> &coefs = getAttributes<SgExpression*, int*>(ref->subscript(i), set<int>{ INT_VAL });
|
||||||
if (coeffs.size() == 1)
|
if (coefs.size() == 1)
|
||||||
{
|
{
|
||||||
const pair<int, int> coef(coeffs[0][0], coeffs[0][1]);
|
const pair<int, int> coef(coefs[0][0], coefs[0][1]);
|
||||||
auto it = shiftsByAccess[i].find(coef);
|
auto it = shiftsByAccess[i].find(coef);
|
||||||
if (it != shiftsByAccess[i].end())
|
if (it != shiftsByAccess[i].end())
|
||||||
if (it->second != 0)
|
if (it->second != 0)
|
||||||
@@ -346,7 +346,7 @@ static vector<SgExpression*>
|
|||||||
{
|
{
|
||||||
needToAdd = true;
|
needToAdd = true;
|
||||||
dim_found = true;
|
dim_found = true;
|
||||||
subs[i] = new SgVarRefExp(findSymbolOrCreate(file, currLoop->loopSymbol()));
|
subs[i] = new SgVarRefExp(findSymbolOrCreate(file, currLoop->loopSymbol));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,9 +7,9 @@
|
|||||||
|
|
||||||
#include "Array.h"
|
#include "Array.h"
|
||||||
#include "DvmhDirectiveBase.h"
|
#include "DvmhDirectiveBase.h"
|
||||||
#include "AstWrapper.h"
|
#include "../Utils/AstWrapper.h"
|
||||||
#include "types.h"
|
#include "../Utils/types.h"
|
||||||
#include "utils.h"
|
#include "../Utils/utils.h"
|
||||||
|
|
||||||
extern int sharedMemoryParallelization;
|
extern int sharedMemoryParallelization;
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#include "leak_detector.h"
|
#include "../Utils/leak_detector.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@@ -10,11 +10,11 @@
|
|||||||
#include "../Distribution/Array.h"
|
#include "../Distribution/Array.h"
|
||||||
#include "../Distribution/Arrays.h"
|
#include "../Distribution/Arrays.h"
|
||||||
#include "../Distribution/GraphCSR.h"
|
#include "../Distribution/GraphCSR.h"
|
||||||
#include "errors.h"
|
#include "../Utils/errors.h"
|
||||||
#include "utils.h"
|
#include "../Utils/utils.h"
|
||||||
#include "json.hpp"
|
#include "../Utils/json.hpp"
|
||||||
|
|
||||||
#include "graph_calls_func.h"
|
#include "../GraphCall/graph_calls_func.h"
|
||||||
|
|
||||||
using std::vector;
|
using std::vector;
|
||||||
using std::tuple;
|
using std::tuple;
|
||||||
@@ -364,11 +364,11 @@ static inline string calculateShifts(DIST::GraphCSR<int, double, attrType> &redu
|
|||||||
{
|
{
|
||||||
if (sharedMemoryParallelization)
|
if (sharedMemoryParallelization)
|
||||||
{
|
{
|
||||||
for (auto& coeffs : currReadOp->first[k].coefficients)
|
for (auto& coefs : currReadOp->first[k].coefficients)
|
||||||
{
|
{
|
||||||
auto currAccess = coeffs.first;
|
auto currAccess = coefs.first;
|
||||||
|
|
||||||
const int currShift = coeffs.first.second;
|
const int currShift = coefs.first.second;
|
||||||
|
|
||||||
auto itFound = shiftsByAccess[k].find(currAccess);
|
auto itFound = shiftsByAccess[k].find(currAccess);
|
||||||
if (itFound == shiftsByAccess[k].end())
|
if (itFound == shiftsByAccess[k].end())
|
||||||
@@ -393,9 +393,9 @@ static inline string calculateShifts(DIST::GraphCSR<int, double, attrType> &redu
|
|||||||
int minShift = 9999999;
|
int minShift = 9999999;
|
||||||
int maxShift = -9999999;
|
int maxShift = -9999999;
|
||||||
|
|
||||||
for (auto &coeffs : currReadOp->first[k].coefficients)
|
for (auto &coefs : currReadOp->first[k].coefficients)
|
||||||
{
|
{
|
||||||
auto currAccess = coeffs.first;
|
auto currAccess = coefs.first;
|
||||||
auto result = DIST::Fx(currAccess, currRuleShadow);
|
auto result = DIST::Fx(currAccess, currRuleShadow);
|
||||||
|
|
||||||
if (result.first == loopRule.first)
|
if (result.first == loopRule.first)
|
||||||
@@ -417,7 +417,7 @@ static inline string calculateShifts(DIST::GraphCSR<int, double, attrType> &redu
|
|||||||
auto it = remoteRegularReads.find(calcForArray);
|
auto it = remoteRegularReads.find(calcForArray);
|
||||||
if (it == remoteRegularReads.end())
|
if (it == remoteRegularReads.end())
|
||||||
it = remoteRegularReads.insert(it, make_pair(calcForArray, vector<ArrayOp>(calcForArray->GetDimSize())));
|
it = remoteRegularReads.insert(it, make_pair(calcForArray, vector<ArrayOp>(calcForArray->GetDimSize())));
|
||||||
it->second[k].coefficients.insert(coeffs);
|
it->second[k].coefficients.insert(coefs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "json.hpp"
|
#include "../Utils/json.hpp"
|
||||||
|
|
||||||
typedef enum lang : int { LANG_C, LANG_F } language;
|
typedef enum lang : int { LANG_C, LANG_F } language;
|
||||||
typedef enum dist : int { BLOCK, NONE } distType;
|
typedef enum dist : int { BLOCK, NONE } distType;
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <set>
|
#include <set>
|
||||||
#include "dvm.h"
|
#include "dvm.h"
|
||||||
#include "types.h"
|
#include "../Utils/types.h"
|
||||||
|
|
||||||
SgExpression* createAndSetNext(const int side, const int variant, SgExpression *p);
|
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);
|
std::vector<SgExpression*> genSubscripts(const std::vector<std::pair<int, int>> &shadowRenew, const std::vector<std::pair<int, int>> &shadowRenewShifts);
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#include "leak_detector.h"
|
#include "../Utils/leak_detector.h"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <string>
|
#include <string>
|
||||||
@@ -19,8 +19,8 @@ extern int passDone;
|
|||||||
#include "Cycle.h"
|
#include "Cycle.h"
|
||||||
#include "Arrays.h"
|
#include "Arrays.h"
|
||||||
#include "Array.h"
|
#include "Array.h"
|
||||||
#include "errors.h"
|
#include "../Utils/errors.h"
|
||||||
#include "utils.h"
|
#include "../Utils/utils.h"
|
||||||
#include "../VisualizerCalls/get_information.h"
|
#include "../VisualizerCalls/get_information.h"
|
||||||
#include "../VisualizerCalls/SendMessage.h"
|
#include "../VisualizerCalls/SendMessage.h"
|
||||||
|
|
||||||
@@ -830,13 +830,13 @@ namespace Distribution
|
|||||||
color[k] = WHITE;
|
color[k] = WHITE;
|
||||||
|
|
||||||
findFrom = currentV;
|
findFrom = currentV;
|
||||||
/*#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
if (needPrint)
|
if (needPrint)
|
||||||
{
|
{
|
||||||
wstring vertexM = std::to_wstring(k + 1) + L"/" + std::to_wstring(vertByTrees[t].size());
|
wstring vertexM = std::to_wstring(k + 1) + L"/" + std::to_wstring(vertByTrees[t].size());
|
||||||
sendMessage_2lvl(wstring(L"ïîèñê ïðîñòûõ öèêëîâ â ãðàôå, îáðàáîòêà äåðåâà ") + wstring(treeM.begin(), treeM.end()) + L" âåðøèíû " + wstring(vertexM.begin(), vertexM.end()));
|
sendMessage_2lvl(wstring(L"ïîèñê ïðîñòûõ öèêëîâ â ãðàôå, îáðàáîòêà äåðåâà ") + wstring(treeM.begin(), treeM.end()) + L" âåðøèíû " + 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]);
|
__spf_print(PRINT_TIMES && needPrint, "v (tree %d) = %d (with neighb %d) ", t, i, neighbors[i + 1] - neighbors[i]);
|
||||||
activeV[activeCounter++] = currentV;
|
activeV[activeCounter++] = currentV;
|
||||||
FindLoop(cyclesTmp[t], currentV, currentV, numbers);
|
FindLoop(cyclesTmp[t], currentV, currentV, numbers);
|
||||||
@@ -847,8 +847,8 @@ namespace Distribution
|
|||||||
maxLoopDim = wasMaxLoopDim;
|
maxLoopDim = wasMaxLoopDim;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*if (needPrint)
|
if (needPrint)
|
||||||
sendMessage_2lvl(2);*/
|
sendMessage_2lvl(L"");
|
||||||
}
|
}
|
||||||
catch (int code)
|
catch (int code)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
#include <set>
|
#include <set>
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
|
|
||||||
#include "RationalNum.h"
|
#include "../Utils/RationalNum.h"
|
||||||
|
|
||||||
typedef enum links { RR_link, WR_link, WW_link } LinkType;
|
typedef enum links { RR_link, WR_link, WW_link } LinkType;
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "graph_loops_func.h"
|
#include "../GraphLoop/graph_loops_func.h"
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
|||||||
@@ -11,9 +11,9 @@
|
|||||||
#include "DvmhRegionInserter.h"
|
#include "DvmhRegionInserter.h"
|
||||||
#include "DvmhRegions/RegionsMerger.h"
|
#include "DvmhRegions/RegionsMerger.h"
|
||||||
#include "../VerificationCode/verifications.h"
|
#include "../VerificationCode/verifications.h"
|
||||||
|
#include "../Transformations/function_purifying.h"
|
||||||
#include "../LoopAnalyzer/loop_analyzer.h"
|
#include "../LoopAnalyzer/loop_analyzer.h"
|
||||||
#include "../DirectiveProcessing/directive_parser.h"
|
#include "../DirectiveProcessing/directive_parser.h"
|
||||||
#include "FunctionPurifying/function_purifying.h"
|
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
@@ -794,6 +794,154 @@ ArraySet DvmhRegionInserter::get_used_arrs_for_block(SgStatement* st, int usage_
|
|||||||
return usages;
|
return usages;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool filterFromList(SgStatement* st, const set<string>& idents, bool exclude = false)
|
||||||
|
{
|
||||||
|
bool empty = false;
|
||||||
|
SgExpression* list = st->expr(0);
|
||||||
|
vector<SgExpression*> newList;
|
||||||
|
|
||||||
|
int total = 0;
|
||||||
|
while (list)
|
||||||
|
{
|
||||||
|
if (exclude)
|
||||||
|
{
|
||||||
|
if (idents.find(list->lhs()->symbol()->identifier()) == idents.end())
|
||||||
|
newList.push_back(list->lhs());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (idents.find(list->lhs()->symbol()->identifier()) != idents.end())
|
||||||
|
newList.push_back(list->lhs());
|
||||||
|
}
|
||||||
|
total++;
|
||||||
|
list = list->rhs();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (newList.size() == 0)
|
||||||
|
empty = true;
|
||||||
|
else if (total != newList.size())
|
||||||
|
st->setExpression(0, makeExprList(newList));
|
||||||
|
|
||||||
|
return empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
static string getInterfaceBlock(SgStatement* func, const FuncParam& pars)
|
||||||
|
{
|
||||||
|
string oldFile = current_file->filename();
|
||||||
|
if (!func->switchToFile())
|
||||||
|
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
||||||
|
|
||||||
|
auto copy = duplicateProcedure(func, NULL, false, false, false, true);
|
||||||
|
const set<string> idents(pars.identificators.begin(), pars.identificators.end());
|
||||||
|
|
||||||
|
bool need = (func->symbol()->identifier() == string("bl182"));
|
||||||
|
|
||||||
|
//remove all exec
|
||||||
|
SgStatement* st = copy->lexNext();
|
||||||
|
SgStatement* last = copy->lastNodeOfStmt();
|
||||||
|
vector<SgStatement*> toExtract;
|
||||||
|
|
||||||
|
while (st != last)
|
||||||
|
{
|
||||||
|
if (isDVM_stat(st) || isSPF_stat(st))
|
||||||
|
{
|
||||||
|
if (st->variant() != ACC_ROUTINE_DIR)
|
||||||
|
{
|
||||||
|
toExtract.push_back(st);
|
||||||
|
st = st->lexNext();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
st = st->lexNext();
|
||||||
|
}
|
||||||
|
else if (isSgExecutableStatement(st))
|
||||||
|
{
|
||||||
|
SgStatement* next = st->lastNodeOfStmt();
|
||||||
|
if (next != last)
|
||||||
|
next = next->lexNext();
|
||||||
|
toExtract.push_back(st);
|
||||||
|
st = next;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
st = st->lexNext();
|
||||||
|
}
|
||||||
|
|
||||||
|
//remove unused declarations
|
||||||
|
st = copy->lexNext();
|
||||||
|
while (st != last)
|
||||||
|
{
|
||||||
|
const int var = st->variant();
|
||||||
|
|
||||||
|
if (var == VAR_DECL
|
||||||
|
|| var == VAR_DECL_90
|
||||||
|
|| var == DIM_STAT
|
||||||
|
|| var == INTENT_STMT
|
||||||
|
|| var == EXTERN_STAT)
|
||||||
|
{
|
||||||
|
bool empty = filterFromList(st, idents);
|
||||||
|
if (empty)
|
||||||
|
{
|
||||||
|
toExtract.push_back(st);
|
||||||
|
st = st->lexNext();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (!isDVM_stat(st) && !isSPF_stat(st))
|
||||||
|
toExtract.push_back(st);
|
||||||
|
|
||||||
|
if (st->variant() == CONTAINS_STMT)
|
||||||
|
break;
|
||||||
|
st = st->lexNext();
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto& elem : toExtract)
|
||||||
|
elem->extractStmt();
|
||||||
|
|
||||||
|
string retVal = copy->unparse();
|
||||||
|
|
||||||
|
if (SgFile::switchToFile(oldFile) == -1)
|
||||||
|
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
||||||
|
|
||||||
|
return retVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void insertInterface(SgStatement* func, const string& iface, const string& fName)
|
||||||
|
{
|
||||||
|
string oldFile = current_file->filename();
|
||||||
|
if (!func->switchToFile())
|
||||||
|
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
||||||
|
|
||||||
|
SgStatement* st = func->lexNext();
|
||||||
|
SgStatement* last = func->lastNodeOfStmt();
|
||||||
|
while (st != last)
|
||||||
|
{
|
||||||
|
if (st->variant() == VAR_DECL || st->variant() == VAR_DECL_90)
|
||||||
|
{
|
||||||
|
bool empty = filterFromList(st, { fName }, true);
|
||||||
|
if (empty)
|
||||||
|
{
|
||||||
|
SgStatement* next = st->lexNext();
|
||||||
|
st->extractStmt();
|
||||||
|
st = next;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isSgExecutableStatement(st))
|
||||||
|
break;
|
||||||
|
st = st->lexNext();
|
||||||
|
}
|
||||||
|
SgStatement* ifaceBlock = new SgStatement(INTERFACE_STMT);
|
||||||
|
addControlEndToStmt(ifaceBlock->thebif);
|
||||||
|
|
||||||
|
ifaceBlock->setlineNumber(getNextNegativeLineNumber()); // st->lineNumber()
|
||||||
|
ifaceBlock->setFileName(st->fileName());
|
||||||
|
st->insertStmtBefore(*ifaceBlock, *st->controlParent());
|
||||||
|
ifaceBlock->lastNodeOfStmt()->addComment(iface.c_str());
|
||||||
|
|
||||||
|
if (SgFile::switchToFile(oldFile) == -1)
|
||||||
|
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
||||||
|
}
|
||||||
|
|
||||||
static LoopGraph* getParallelLoop(LoopGraph* loop)
|
static LoopGraph* getParallelLoop(LoopGraph* loop)
|
||||||
{
|
{
|
||||||
auto prev_st = loop->loop->lexPrev();
|
auto prev_st = loop->loop->lexPrev();
|
||||||
@@ -1024,7 +1172,7 @@ static bool isPure(SgStatement* func)
|
|||||||
|
|
||||||
void DvmhRegionInserter::createInterfaceBlockForOutCall(FuncInfo* func, FuncInfo* callFrom)
|
void DvmhRegionInserter::createInterfaceBlockForOutCall(FuncInfo* func, FuncInfo* callFrom)
|
||||||
{
|
{
|
||||||
insertInterface(func->funcPointer, callFrom);
|
insertInterface(func->funcPointer, getInterfaceBlock(callFrom->funcPointer->GetOriginal(), callFrom->funcParams), callFrom->funcName);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DvmhRegionInserter::createInterfaceBlockForParallelFunctions(bool onlyRoutine)
|
void DvmhRegionInserter::createInterfaceBlockForParallelFunctions(bool onlyRoutine)
|
||||||
@@ -1289,9 +1437,6 @@ static set<DIST::Array*>
|
|||||||
|
|
||||||
SgStatement* declStat = NULL;
|
SgStatement* declStat = NULL;
|
||||||
|
|
||||||
if (realArray->GetLocation().first == DIST::l_PARAMETER)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (realArray->GetLocation().first == DIST::l_COMMON)
|
if (realArray->GetLocation().first == DIST::l_COMMON)
|
||||||
{
|
{
|
||||||
commonArrays.insert(realArray);
|
commonArrays.insert(realArray);
|
||||||
@@ -1301,9 +1446,6 @@ static set<DIST::Array*>
|
|||||||
declStat = SgStatement::getStatementByFileAndLine(decl.first, decl.second);
|
declStat = SgStatement::getStatementByFileAndLine(decl.first, decl.second);
|
||||||
if (declStat == NULL) // check in inlcudes
|
if (declStat == NULL) // check in inlcudes
|
||||||
{
|
{
|
||||||
if (!main->switchToFile())
|
|
||||||
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
|
||||||
|
|
||||||
for (auto st = main; st != main->lastNodeOfStmt() && !declStat; st = st->lexNext())
|
for (auto st = main; st != main->lastNodeOfStmt() && !declStat; st = st->lexNext())
|
||||||
{
|
{
|
||||||
if (st->fileName() == decl.first && st->lineNumber() == decl.second)
|
if (st->fileName() == decl.first && st->lineNumber() == decl.second)
|
||||||
@@ -1315,7 +1457,7 @@ static set<DIST::Array*>
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
declStat = getFuncStat(declStat, { BLOCK_DATA });
|
declStat = getFuncStat(declStat);
|
||||||
if (declStat != main)
|
if (declStat != main)
|
||||||
{
|
{
|
||||||
declStat = NULL;
|
declStat = NULL;
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "graph_calls_func.h"
|
#include "../GraphCall/graph_calls_func.h"
|
||||||
#include "graph_loops_func.h"
|
#include "../GraphLoop/graph_loops_func.h"
|
||||||
#include "expr_transform.h"
|
#include "../ExpressionTransform/expr_transform.h"
|
||||||
#include "../ParallelizationRegions/ParRegions.h"
|
#include "../ParallelizationRegions/ParRegions.h"
|
||||||
#include "SgUtils.h"
|
#include "../Utils/SgUtils.h"
|
||||||
#include "ReadWriteAnalyzer.h"
|
#include "ReadWriteAnalyzer.h"
|
||||||
#include "DvmhRegion.h"
|
#include "DvmhRegion.h"
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "graph_loops_func.h"
|
#include "../GraphLoop/graph_loops_func.h"
|
||||||
#include "graph_calls_func.h"
|
#include "../GraphCall/graph_calls_func.h"
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "dvm.h"
|
#include "dvm.h"
|
||||||
#include "SgUtils.h"
|
#include "../Utils/SgUtils.h"
|
||||||
#include "VarUsages.h"
|
#include "VarUsages.h"
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "dvm.h"
|
#include "dvm.h"
|
||||||
#include "SgUtils.h"
|
#include "../Utils/SgUtils.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
enum class VAR_TYPE { VAR_ARR, VAR_DISTR_ARR, VAR_SCALAR, VAR_ANY, VAR_UNDEFINED };
|
enum class VAR_TYPE { VAR_ARR, VAR_DISTR_ARR, VAR_SCALAR, VAR_ANY, VAR_UNDEFINED };
|
||||||
|
|||||||
@@ -5,10 +5,10 @@
|
|||||||
#include "./createParallelRegions.h"
|
#include "./createParallelRegions.h"
|
||||||
|
|
||||||
#include "../CreateInterTree/CreateInterTree.h"
|
#include "../CreateInterTree/CreateInterTree.h"
|
||||||
#include "graph_calls.h"
|
#include "../GraphCall/graph_calls.h"
|
||||||
#include "./gcov_info.h"
|
#include "./gcov_info.h"
|
||||||
#include "./gCov_parser_func.h"
|
#include "./gCov_parser_func.h"
|
||||||
#include "leak_detector.h"
|
#include "../Utils/leak_detector.h"
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "utils.h"
|
#include "../Utils/utils.h"
|
||||||
|
|
||||||
#include "./gcov_info.h"
|
#include "./gcov_info.h"
|
||||||
#include "../CreateInterTree/CreateInterTree.h"
|
#include "../CreateInterTree/CreateInterTree.h"
|
||||||
#include "graph_calls.h"
|
#include "../GraphCall/graph_calls.h"
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#include "leak_detector.h"
|
#include "../Utils/leak_detector.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
@@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
#include "dvm.h"
|
#include "dvm.h"
|
||||||
#include "gCov_parser_func.h"
|
#include "gCov_parser_func.h"
|
||||||
#include "SgUtils.h"
|
#include "../Utils/SgUtils.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "dvm.h"
|
#include "dvm.h"
|
||||||
#include "errors.h"
|
#include "../Utils/errors.h"
|
||||||
#include "gcov_info.h"
|
#include "gcov_info.h"
|
||||||
#include "../CreateInterTree/CreateInterTree.h"
|
#include "../CreateInterTree/CreateInterTree.h"
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
#include "leak_detector.h"
|
#include "../Utils/leak_detector.h"
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
#include "errors.h"
|
#include "../Utils/errors.h"
|
||||||
|
|
||||||
#include "gcov_info.h"
|
#include "gcov_info.h"
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
#include <map>
|
#include <map>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#include "utils.h"
|
#include "../Utils/utils.h"
|
||||||
|
|
||||||
//make 'class' - need friend for Gcov_info
|
//make 'class' - need friend for Gcov_info
|
||||||
struct Perform
|
struct Perform
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#include "leak_detector.h"
|
#include "../Utils/leak_detector.h"
|
||||||
|
|
||||||
#include "dvm.h"
|
#include "dvm.h"
|
||||||
#include "acc_analyzer.h"
|
#include "acc_analyzer.h"
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
#include "leak_detector.h"
|
#include "../Utils/leak_detector.h"
|
||||||
|
|
||||||
#if _WIN32 && NDEBUG && __SPF && __BOOST
|
#if _WIN32 && NDEBUG && __SPF && __BOOST
|
||||||
#include <boost/thread.hpp>
|
#include <boost/thread.hpp>
|
||||||
@@ -19,11 +19,11 @@ extern int passDone;
|
|||||||
|
|
||||||
#include "../ParallelizationRegions/ParRegions.h"
|
#include "../ParallelizationRegions/ParRegions.h"
|
||||||
#include "../ParallelizationRegions/ParRegions_func.h"
|
#include "../ParallelizationRegions/ParRegions_func.h"
|
||||||
#include "graph_loops.h"
|
#include "../GraphLoop/graph_loops.h"
|
||||||
#include "graph_calls.h"
|
#include "../GraphCall/graph_calls.h"
|
||||||
#include "graph_calls_func.h"
|
#include "../GraphCall/graph_calls_func.h"
|
||||||
#include "utils.h"
|
#include "../Utils/utils.h"
|
||||||
#include "SgUtils.h"
|
#include "../Utils/SgUtils.h"
|
||||||
#include "../Distribution/Distribution.h"
|
#include "../Distribution/Distribution.h"
|
||||||
#include "../VisualizerCalls/get_information.h"
|
#include "../VisualizerCalls/get_information.h"
|
||||||
#include "expr_transform.h"
|
#include "expr_transform.h"
|
||||||
@@ -440,18 +440,15 @@ bool replaceConstantRec(SgExpression *&exp)
|
|||||||
if (exp->variant() == CONST_REF)
|
if (exp->variant() == CONST_REF)
|
||||||
{
|
{
|
||||||
SgExpression *ret = ReplaceParameter_(exp);
|
SgExpression *ret = ReplaceParameter_(exp);
|
||||||
|
|
||||||
int sign = 1;
|
int sign = 1;
|
||||||
SgExpression* toCalc = ret;
|
SgExpression* toCalc = ret;
|
||||||
if (toCalc->variant() == UNARY_ADD_OP)
|
if (ret->variant() == UNARY_ADD_OP)
|
||||||
toCalc = toCalc->lhs();
|
toCalc = ret->lhs();
|
||||||
|
if (ret->variant() == MINUS_OP)
|
||||||
if (toCalc->variant() == MINUS_OP)
|
|
||||||
{
|
{
|
||||||
toCalc = toCalc->lhs();
|
toCalc = ret->lhs();
|
||||||
sign = -1;
|
sign = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (toCalc->isInteger())
|
if (toCalc->isInteger())
|
||||||
{
|
{
|
||||||
exp = new SgValueExp(sign * toCalc->valueInteger());
|
exp = new SgValueExp(sign * toCalc->valueInteger());
|
||||||
@@ -5,10 +5,10 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include "dvm.h"
|
#include "dvm.h"
|
||||||
#include "../Distribution/Distribution.h"
|
#include "../Distribution/Distribution.h"
|
||||||
#include "graph_loops.h"
|
#include "../GraphLoop/graph_loops.h"
|
||||||
#include "../ParallelizationRegions/ParRegions.h"
|
#include "../ParallelizationRegions/ParRegions.h"
|
||||||
#include "graph_calls.h"
|
#include "../GraphCall/graph_calls.h"
|
||||||
#include "SgUtils.h"
|
#include "../Utils/SgUtils.h"
|
||||||
|
|
||||||
#include "acc_analyzer.h"
|
#include "acc_analyzer.h"
|
||||||
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
#include "leak_detector.h"
|
#include "../Utils/leak_detector.h"
|
||||||
|
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
@@ -14,14 +14,14 @@
|
|||||||
#include "dvm.h"
|
#include "dvm.h"
|
||||||
#include "graph_calls_func.h"
|
#include "graph_calls_func.h"
|
||||||
|
|
||||||
#include "CFGraph/CFGraph.h"
|
#include "../CFGraph/CFGraph.h"
|
||||||
#include "graph_loops_func.h"
|
#include "../GraphLoop/graph_loops_func.h"
|
||||||
#include "../DirectiveProcessing/directive_parser.h"
|
#include "../DirectiveProcessing/directive_parser.h"
|
||||||
#include "SgUtils.h"
|
#include "../Utils/SgUtils.h"
|
||||||
#include "json.hpp"
|
#include "../Utils/json.hpp"
|
||||||
#include "../ParallelizationRegions/ParRegions_func.h"
|
#include "../ParallelizationRegions/ParRegions_func.h"
|
||||||
#include "../DynamicAnalysis/gCov_parser_func.h"
|
#include "../DynamicAnalysis/gCov_parser_func.h"
|
||||||
#include "expr_transform.h"
|
#include "../ExpressionTransform/expr_transform.h"
|
||||||
#include "../LoopAnalyzer/loop_analyzer.h"
|
#include "../LoopAnalyzer/loop_analyzer.h"
|
||||||
#include "../VerificationCode/verifications.h"
|
#include "../VerificationCode/verifications.h"
|
||||||
|
|
||||||
@@ -723,7 +723,7 @@ static void fillIn(FuncInfo *currF, SgExpression *ex, const map<string, int> &pa
|
|||||||
{
|
{
|
||||||
if (ex)
|
if (ex)
|
||||||
{
|
{
|
||||||
if (!isInFuncPar && (ex->variant() == VAR_REF || ex->variant() == ARRAY_REF))
|
if (!isInFuncPar && (ex->variant() == VAR_REF || isArrayRef(ex)))
|
||||||
{
|
{
|
||||||
const char *name = ex->symbol()->identifier();
|
const char *name = ex->symbol()->identifier();
|
||||||
if (name && name != string(""))
|
if (name && name != string(""))
|
||||||
@@ -779,20 +779,6 @@ static void checkSpecList(SgExpression *spec, FuncInfo* currF, const map<string,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void checkInTypeDescription(SgExpression *ex, FuncInfo* currF, const map<string, int>& parNames)
|
|
||||||
{
|
|
||||||
if (ex)
|
|
||||||
{
|
|
||||||
if (ex->variant() == ARRAY_REF)
|
|
||||||
fillIn(currF, ex->lhs(), parNames, false);
|
|
||||||
else
|
|
||||||
{
|
|
||||||
checkInTypeDescription(ex->lhs(), currF, parNames);
|
|
||||||
checkInTypeDescription(ex->rhs(), currF, parNames);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void fillInOut(FuncInfo *currF, SgStatement *start, SgStatement *last, const set<SgStatement*>& activeOps)
|
static void fillInOut(FuncInfo *currF, SgStatement *start, SgStatement *last, const set<SgStatement*>& activeOps)
|
||||||
{
|
{
|
||||||
if (currF->funcParams.countOfPars == 0)
|
if (currF->funcParams.countOfPars == 0)
|
||||||
@@ -800,58 +786,24 @@ static void fillInOut(FuncInfo *currF, SgStatement *start, SgStatement *last, co
|
|||||||
|
|
||||||
static map<string, vector<int>> supportedKeyWordArg = { {"system_clock", { OUT_BIT, OUT_BIT, OUT_BIT } } };
|
static map<string, vector<int>> supportedKeyWordArg = { {"system_clock", { OUT_BIT, OUT_BIT, OUT_BIT } } };
|
||||||
|
|
||||||
map<string, int> parNamesMain;
|
map<string, int> parNames;
|
||||||
map<string, int> parNamesContains;
|
|
||||||
|
|
||||||
for (int i = 0; i < currF->funcParams.identificators.size(); ++i)
|
for (int i = 0; i < currF->funcParams.identificators.size(); ++i)
|
||||||
parNamesMain[currF->funcParams.identificators[i]] = i;
|
parNames[currF->funcParams.identificators[i]] = i;
|
||||||
|
|
||||||
map<string, int>& parNames = parNamesMain;
|
|
||||||
|
|
||||||
bool isContainsFunctions = false;
|
|
||||||
for (auto st = start; st != last; st = st->lexNext())
|
for (auto st = start; st != last; st = st->lexNext())
|
||||||
{
|
{
|
||||||
if (st->variant() == CONTAINS_STMT) {
|
if (st->variant() == CONTAINS_STMT)
|
||||||
isContainsFunctions = true;
|
break;
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isContainsFunctions) {
|
|
||||||
if (st->variant() == PROC_HEDR || st->variant() == FUNC_HEDR) {
|
|
||||||
parNamesContains = parNamesMain;
|
|
||||||
|
|
||||||
SgProgHedrStmt* hedr = (SgProgHedrStmt*)st;
|
|
||||||
|
|
||||||
int numOfParams = hedr->numberOfParameters();
|
|
||||||
if (numOfParams > 0)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < numOfParams; ++i)
|
|
||||||
{
|
|
||||||
auto it = parNamesContains.find(hedr->parameter(i)->identifier());
|
|
||||||
if (it != parNamesContains.end())
|
|
||||||
parNamesContains.erase(it);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
parNames = parNamesContains;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (st->variant() == ENTRY_STAT)
|
if (st->variant() == ENTRY_STAT)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (isSgExecutableStatement(st) == NULL) {
|
if (isSgExecutableStatement(st) == NULL || st->lineNumber() <= 0)
|
||||||
if (!isContainsFunctions)
|
|
||||||
checkInTypeDescription(st->expr(0), currF, parNames);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (st->lineNumber() <= 0)
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
//XXX: use parameters removing in block ... isContainsFunctions ...
|
if (activeOps.size() && activeOps.find(st) == activeOps.end())
|
||||||
//TODO need to use IR for parameters checking
|
continue;
|
||||||
/*if (activeOps.size() && activeOps.find(st) == activeOps.end())
|
|
||||||
continue; */
|
|
||||||
|
|
||||||
if (st->variant() == ASSIGN_STAT)
|
if (st->variant() == ASSIGN_STAT)
|
||||||
{
|
{
|
||||||
@@ -880,7 +832,7 @@ static void fillInOut(FuncInfo *currF, SgStatement *start, SgStatement *last, co
|
|||||||
for (auto ex = read->itemList(); ex; ex = ex->rhs())
|
for (auto ex = read->itemList(); ex; ex = ex->rhs())
|
||||||
{
|
{
|
||||||
SgExpression* item = ex->lhs();
|
SgExpression* item = ex->lhs();
|
||||||
if (item && (item->variant() == VAR_REF || item->variant() == ARRAY_REF))
|
if (item->variant() == VAR_REF || isArrayRef(item))
|
||||||
{
|
{
|
||||||
string symb = "";
|
string symb = "";
|
||||||
if (item->symbol())
|
if (item->symbol())
|
||||||
@@ -901,7 +853,7 @@ static void fillInOut(FuncInfo *currF, SgStatement *start, SgStatement *last, co
|
|||||||
if (item->rhs())
|
if (item->rhs())
|
||||||
queue.push(item->rhs());
|
queue.push(item->rhs());
|
||||||
|
|
||||||
if (item->variant() == VAR_REF || item->variant() == ARRAY_REF)
|
if (item->variant() == VAR_REF || isArrayRef(item))
|
||||||
{
|
{
|
||||||
string symb = "";
|
string symb = "";
|
||||||
if (item->symbol())
|
if (item->symbol())
|
||||||
|
|||||||
@@ -3,10 +3,10 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <set>
|
#include <set>
|
||||||
|
|
||||||
#include "AstWrapper.h"
|
#include "../Utils/AstWrapper.h"
|
||||||
#include "utils.h"
|
#include "../Utils/utils.h"
|
||||||
#include "../DirectiveProcessing/shadow.h"
|
#include "../DirectiveProcessing/shadow.h"
|
||||||
#include "graph_loops.h"
|
#include "../GraphLoop/graph_loops.h"
|
||||||
|
|
||||||
static const char* paramNames[] =
|
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",
|
{ "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",
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#include "leak_detector.h"
|
#include "../Utils/leak_detector.h"
|
||||||
|
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
@@ -10,10 +10,10 @@
|
|||||||
#include <set>
|
#include <set>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "errors.h"
|
#include "../Utils/errors.h"
|
||||||
#include "graph_calls.h"
|
#include "graph_calls.h"
|
||||||
#include "../Distribution/Distribution.h"
|
#include "../Distribution/Distribution.h"
|
||||||
#include "utils.h"
|
#include "../Utils/utils.h"
|
||||||
#include "../ParallelizationRegions/ParRegions.h"
|
#include "../ParallelizationRegions/ParRegions.h"
|
||||||
|
|
||||||
using std::vector;
|
using std::vector;
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
#include <set>
|
#include <set>
|
||||||
|
|
||||||
#include "graph_calls.h"
|
#include "graph_calls.h"
|
||||||
#include "graph_loops.h"
|
#include "../GraphLoop/graph_loops.h"
|
||||||
#include "../ParallelizationRegions/ParRegions.h"
|
#include "../ParallelizationRegions/ParRegions.h"
|
||||||
#include "Utils/json.hpp"
|
#include "Utils/json.hpp"
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#include "leak_detector.h"
|
#include "../Utils/leak_detector.h"
|
||||||
|
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
@@ -12,26 +12,26 @@
|
|||||||
|
|
||||||
#include "dvm.h"
|
#include "dvm.h"
|
||||||
#include "../Sapfor.h"
|
#include "../Sapfor.h"
|
||||||
#include "graph_calls_func.h"
|
#include "../GraphCall/graph_calls_func.h"
|
||||||
#include "../ParallelizationRegions/ParRegions_func.h"
|
#include "../ParallelizationRegions/ParRegions_func.h"
|
||||||
#include "expr_transform.h"
|
#include "../ExpressionTransform/expr_transform.h"
|
||||||
|
|
||||||
#include "../Distribution/GraphCSR.h"
|
#include "../Distribution/GraphCSR.h"
|
||||||
#include "../Distribution/Arrays.h"
|
#include "../Distribution/Arrays.h"
|
||||||
#include "../Distribution/Distribution.h"
|
#include "../Distribution/Distribution.h"
|
||||||
|
|
||||||
#include "graph_loops.h"
|
#include "graph_loops.h"
|
||||||
#include "utils.h"
|
#include "../Utils/utils.h"
|
||||||
#include "SgUtils.h"
|
#include "../Utils/SgUtils.h"
|
||||||
|
|
||||||
#include "errors.h"
|
#include "../Utils/errors.h"
|
||||||
#include "AstWrapper.h"
|
#include "../Utils/AstWrapper.h"
|
||||||
#include "json.hpp"
|
#include "../Utils/json.hpp"
|
||||||
|
|
||||||
#include "../DirectiveProcessing/directive_parser.h"
|
#include "../DirectiveProcessing/directive_parser.h"
|
||||||
#include "../DynamicAnalysis/gCov_parser_func.h"
|
#include "../DynamicAnalysis/gCov_parser_func.h"
|
||||||
|
|
||||||
#include "VectorAssignToLoop/array_assign_to_loop.h"
|
#include "../Transformations/array_assign_to_loop.h"
|
||||||
|
|
||||||
using std::vector;
|
using std::vector;
|
||||||
using std::map;
|
using std::map;
|
||||||
@@ -520,7 +520,7 @@ static void findArrayRef(SgExpression *exp, bool isWirte, set<DIST::Array*>& use
|
|||||||
{
|
{
|
||||||
if (exp)
|
if (exp)
|
||||||
{
|
{
|
||||||
if (isArrayRef(exp))
|
if (exp->variant() == ARRAY_REF)
|
||||||
{
|
{
|
||||||
DIST::Array *arrayRef = NULL;
|
DIST::Array *arrayRef = NULL;
|
||||||
SgSymbol *symbS = OriginalSymbol(exp->symbol());
|
SgSymbol *symbS = OriginalSymbol(exp->symbol());
|
||||||
@@ -699,12 +699,7 @@ void loopGraphAnalyzer(SgFile *file, vector<LoopGraph*> &loopGraph, const vector
|
|||||||
newLoop->hasPrints = hasThisIds(st, newLoop->linesOfIO, { WRITE_STAT, READ_STAT, OPEN_STAT, CLOSE_STAT, PRINT_STAT } ); // FORMAT_STAT
|
newLoop->hasPrints = hasThisIds(st, newLoop->linesOfIO, { WRITE_STAT, READ_STAT, OPEN_STAT, CLOSE_STAT, PRINT_STAT } ); // FORMAT_STAT
|
||||||
newLoop->hasStops = hasThisIds(st, newLoop->linesOfStop, { STOP_STAT, PAUSE_NODE });
|
newLoop->hasStops = hasThisIds(st, newLoop->linesOfStop, { STOP_STAT, PAUSE_NODE });
|
||||||
newLoop->hasDvmIntervals = hasThisIds(st, tmpLines, { DVM_INTERVAL_DIR, DVM_ENDINTERVAL_DIR, DVM_EXIT_INTERVAL_DIR });
|
newLoop->hasDvmIntervals = hasThisIds(st, tmpLines, { DVM_INTERVAL_DIR, DVM_ENDINTERVAL_DIR, DVM_EXIT_INTERVAL_DIR });
|
||||||
if (isSgForStmt(st))
|
newLoop->isFor = isSgForStmt(st) ? true : false;
|
||||||
newLoop->loopType = LoopType::FOR;
|
|
||||||
else if (isSgWhileStmt(st))
|
|
||||||
newLoop->loopType = LoopType::WHILE;
|
|
||||||
else
|
|
||||||
newLoop->loopType = LoopType::NONE;
|
|
||||||
newLoop->inCanonicalFrom = isSgForStmt(st) ? true : false;
|
newLoop->inCanonicalFrom = isSgForStmt(st) ? true : false;
|
||||||
newLoop->hasSubstringRefs = hasSubstringRef(st);
|
newLoop->hasSubstringRefs = hasSubstringRef(st);
|
||||||
|
|
||||||
@@ -782,7 +777,7 @@ void loopGraphAnalyzer(SgFile *file, vector<LoopGraph*> &loopGraph, const vector
|
|||||||
newLoop->startEndExpr = std::make_pair((Expression*)NULL, (Expression*)NULL);
|
newLoop->startEndExpr = std::make_pair((Expression*)NULL, (Expression*)NULL);
|
||||||
|
|
||||||
newLoop->loop = new Statement(st);
|
newLoop->loop = new Statement(st);
|
||||||
newLoop->loopSymbols.addMainVar(st->symbol() ? st->symbol()->identifier() : "unknown");
|
newLoop->loopSymbol = st->symbol() ? st->symbol()->identifier() : "unknown";
|
||||||
findArrayRefs(newLoop);
|
findArrayRefs(newLoop);
|
||||||
|
|
||||||
SgStatement *lexPrev = st->lexPrev();
|
SgStatement *lexPrev = st->lexPrev();
|
||||||
|
|||||||
@@ -5,8 +5,8 @@
|
|||||||
#include <map>
|
#include <map>
|
||||||
#include <set>
|
#include <set>
|
||||||
|
|
||||||
#include "errors.h"
|
#include "../Utils/errors.h"
|
||||||
#include "types.h"
|
#include "../Utils/types.h"
|
||||||
#include "../Distribution/DvmhDirective.h"
|
#include "../Distribution/DvmhDirective.h"
|
||||||
#include "../Distribution/Distribution.h"
|
#include "../Distribution/Distribution.h"
|
||||||
|
|
||||||
@@ -25,33 +25,6 @@ namespace DIST = Distribution;
|
|||||||
void getRealArrayRefs(DIST::Array* addTo, DIST::Array* curr, std::set<DIST::Array*>& realArrayRefs, const std::map<DIST::Array*, std::set<DIST::Array*>>& arrayLinksByFuncCalls);
|
void getRealArrayRefs(DIST::Array* addTo, DIST::Array* curr, std::set<DIST::Array*>& realArrayRefs, const std::map<DIST::Array*, std::set<DIST::Array*>>& arrayLinksByFuncCalls);
|
||||||
void getAllArrayRefs(DIST::Array* addTo, DIST::Array* curr, std::set<DIST::Array*>& realArrayRefs, const std::map<DIST::Array*, std::set<DIST::Array*>>& arrayLinksByFuncCalls);
|
void getAllArrayRefs(DIST::Array* addTo, DIST::Array* curr, std::set<DIST::Array*>& realArrayRefs, const std::map<DIST::Array*, std::set<DIST::Array*>>& arrayLinksByFuncCalls);
|
||||||
|
|
||||||
enum class LoopType { NONE, FOR, WHILE, IMPLICIT };
|
|
||||||
|
|
||||||
struct InductiveVariables
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
std::string mainVar;
|
|
||||||
std::set<std::string> allVars;
|
|
||||||
|
|
||||||
public:
|
|
||||||
InductiveVariables() { }
|
|
||||||
|
|
||||||
explicit InductiveVariables(const std::string& mainVar, const std::set<std::string>& allVars) : mainVar(mainVar), allVars(allVars) { };
|
|
||||||
|
|
||||||
std::string getMainVar() const { return mainVar; }
|
|
||||||
std::set<std::string> getAllVars() const { return allVars; }
|
|
||||||
|
|
||||||
void addVar(const std::string& var) { allVars.insert(var); }
|
|
||||||
void addMainVar(const std::string& var) { mainVar = var; allVars.insert(var); }
|
|
||||||
|
|
||||||
void replaceMainVar(const std::string& var)
|
|
||||||
{
|
|
||||||
allVars.erase(mainVar);
|
|
||||||
|
|
||||||
addMainVar(var);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
struct LoopGraph
|
struct LoopGraph
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
@@ -97,7 +70,7 @@ public:
|
|||||||
calculatedCountOfIters = 0;
|
calculatedCountOfIters = 0;
|
||||||
executionTimeInSec = -1.0;
|
executionTimeInSec = -1.0;
|
||||||
inDvmhRegion = 0;
|
inDvmhRegion = 0;
|
||||||
loopType = LoopType::NONE;
|
isFor = false;
|
||||||
inCanonicalFrom = false;
|
inCanonicalFrom = false;
|
||||||
hasAccessToSubArray = false;
|
hasAccessToSubArray = false;
|
||||||
hasSubstringRefs = false;
|
hasSubstringRefs = false;
|
||||||
@@ -140,24 +113,21 @@ public:
|
|||||||
{
|
{
|
||||||
return hasUnknownArrayDep || hasUnknownScalarDep || hasGoto || hasPrints || (hasConflicts.size() != 0) || hasStops || hasNonPureProcedures ||
|
return hasUnknownArrayDep || hasUnknownScalarDep || hasGoto || hasPrints || (hasConflicts.size() != 0) || hasStops || hasNonPureProcedures ||
|
||||||
hasUnknownArrayAssigns || hasNonRectangularBounds || hasIndirectAccess || hasWritesToNonDistribute || hasDifferentAlignRules || hasDvmIntervals ||
|
hasUnknownArrayAssigns || hasNonRectangularBounds || hasIndirectAccess || hasWritesToNonDistribute || hasDifferentAlignRules || hasDvmIntervals ||
|
||||||
!isFor() || lastprivateScalars.size() || hasAccessToSubArray || hasSubstringRefs;
|
!isFor || lastprivateScalars.size() || hasAccessToSubArray || hasSubstringRefs;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool hasLimitsToSplit() const
|
bool hasLimitsToSplit() const
|
||||||
{
|
{
|
||||||
return hasGoto || hasStops || !isFor() || hasPrints;
|
return hasGoto || hasStops || !isFor || hasPrints;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool hasLimitsToCombine() const
|
bool hasLimitsToCombine() const
|
||||||
{
|
{
|
||||||
return hasGoto || hasStops || !isFor() || hasPrints || linesOfCycle.size();
|
return hasGoto || hasStops || !isFor || hasPrints || linesOfCycle.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
void addConflictMessages(std::vector<Messages> *messages)
|
void addConflictMessages(std::vector<Messages> *messages)
|
||||||
{
|
{
|
||||||
if (messages == NULL)
|
|
||||||
return;
|
|
||||||
|
|
||||||
const int line = altLineNum > 0 ? altLineNum : lineNum;
|
const int line = altLineNum > 0 ? altLineNum : lineNum;
|
||||||
if (hasUnknownArrayDep)
|
if (hasUnknownArrayDep)
|
||||||
messages->push_back(Messages(NOTE, line, R113, L"unknown array dependency prevents parallelization of this loop", 3006));
|
messages->push_back(Messages(NOTE, line, R113, L"unknown array dependency prevents parallelization of this loop", 3006));
|
||||||
@@ -198,7 +168,7 @@ public:
|
|||||||
if (hasDvmIntervals)
|
if (hasDvmIntervals)
|
||||||
messages->push_back(Messages(NOTE, line, R145, L"DVM intervals prevent parallelization of this loop", 3006));
|
messages->push_back(Messages(NOTE, line, R145, L"DVM intervals prevent parallelization of this loop", 3006));
|
||||||
|
|
||||||
if (!isFor() || !inCanonicalFrom)
|
if (!isFor || !inCanonicalFrom)
|
||||||
messages->push_back(Messages(NOTE, line, R178, L"This type of loop is not supported by the system", 3006));
|
messages->push_back(Messages(NOTE, line, R178, L"This type of loop is not supported by the system", 3006));
|
||||||
|
|
||||||
if (lastprivateScalars.size())
|
if (lastprivateScalars.size())
|
||||||
@@ -423,14 +393,6 @@ public:
|
|||||||
|
|
||||||
void* getRealStat(const char* file) const;
|
void* getRealStat(const char* file) const;
|
||||||
|
|
||||||
bool isFor() const { return loopType == LoopType::FOR; }
|
|
||||||
|
|
||||||
bool isWhile() const { return loopType == LoopType::WHILE; }
|
|
||||||
|
|
||||||
bool isImplicit() const { return loopType == LoopType::IMPLICIT; }
|
|
||||||
|
|
||||||
std::string loopSymbol() const { return loopSymbols.getMainVar(); }
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
int lineNum;
|
int lineNum;
|
||||||
int altLineNum;
|
int altLineNum;
|
||||||
@@ -445,7 +407,7 @@ public:
|
|||||||
int startVal, endVal, stepVal;
|
int startVal, endVal, stepVal;
|
||||||
std::tuple<Expression*, Expression*, Expression*> startEndStepVals;
|
std::tuple<Expression*, Expression*, Expression*> startEndStepVals;
|
||||||
|
|
||||||
InductiveVariables loopSymbols;
|
std::string loopSymbol;
|
||||||
std::pair<Expression*, Expression*> startEndExpr;
|
std::pair<Expression*, Expression*> startEndExpr;
|
||||||
|
|
||||||
bool hasGoto;
|
bool hasGoto;
|
||||||
@@ -486,7 +448,7 @@ public:
|
|||||||
|
|
||||||
bool hasSubstringRefs;
|
bool hasSubstringRefs;
|
||||||
|
|
||||||
LoopType loopType;
|
bool isFor;
|
||||||
|
|
||||||
bool inCanonicalFrom;
|
bool inCanonicalFrom;
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#include "leak_detector.h"
|
#include "../Utils/leak_detector.h"
|
||||||
|
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
@@ -23,8 +23,8 @@ using std::make_pair;
|
|||||||
using std::get;
|
using std::get;
|
||||||
|
|
||||||
#include "graph_loops.h"
|
#include "graph_loops.h"
|
||||||
#include "graph_calls_func.h"
|
#include "../GraphCall/graph_calls_func.h"
|
||||||
#include "errors.h"
|
#include "../Utils/errors.h"
|
||||||
#include "../Distribution/Distribution.h"
|
#include "../Distribution/Distribution.h"
|
||||||
#include "../Distribution/CreateDistributionDirs.h"
|
#include "../Distribution/CreateDistributionDirs.h"
|
||||||
#include "../ParallelizationRegions/ParRegions.h"
|
#include "../ParallelizationRegions/ParRegions.h"
|
||||||
@@ -551,7 +551,7 @@ void addToDistributionGraph(const map<LoopGraph*, map<DIST::Array*, ArrayInfo*>>
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!loopAccess.first->isFor())
|
if (!loopAccess.first->isFor)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
DIST::GraphCSR<int, double, attrType>& G = currReg->GetGraphToModify();
|
DIST::GraphCSR<int, double, attrType>& G = currReg->GetGraphToModify();
|
||||||
@@ -775,7 +775,7 @@ static void isAllOk(const vector<LoopGraph*> &loops, vector<Messages> &currMessa
|
|||||||
{
|
{
|
||||||
if (loops[i]->region)
|
if (loops[i]->region)
|
||||||
{
|
{
|
||||||
if (loops[i]->countOfIters == 0 && loops[i]->region && loops[i]->isFor())
|
if (loops[i]->countOfIters == 0 && loops[i]->region && loops[i]->isFor)
|
||||||
{
|
{
|
||||||
wstring bufE, bufR;
|
wstring bufE, bufR;
|
||||||
__spf_printToLongBuf(bufE, L" Can not calculate count of iterations for this loop, information about iterations in all loops in parallel regions '%s' will be ignored",
|
__spf_printToLongBuf(bufE, L" Can not calculate count of iterations for this loop, information about iterations in all loops in parallel regions '%s' will be ignored",
|
||||||
@@ -1137,9 +1137,9 @@ static bool isMapped(const vector<ArrayOp> &allOps)
|
|||||||
bool mapped = false;
|
bool mapped = false;
|
||||||
for (auto &ops : allOps)
|
for (auto &ops : allOps)
|
||||||
{
|
{
|
||||||
for (auto &coeffs : ops.coefficients)
|
for (auto &coefs : ops.coefficients)
|
||||||
{
|
{
|
||||||
if (coeffs.first.first != 0)
|
if (coefs.first.first != 0)
|
||||||
{
|
{
|
||||||
mapped = true;
|
mapped = true;
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#include "leak_detector.h"
|
#include "../Utils/leak_detector.h"
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@@ -8,13 +8,13 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
#include "dvm.h"
|
#include "dvm.h"
|
||||||
#include "errors.h"
|
#include "../Utils/errors.h"
|
||||||
#include "utils.h"
|
#include "../Utils/utils.h"
|
||||||
#include "SgUtils.h"
|
#include "../Utils/SgUtils.h"
|
||||||
#include "graph_calls_func.h"
|
#include "../GraphCall/graph_calls_func.h"
|
||||||
#include "inliner.h"
|
#include "inliner.h"
|
||||||
#include "../VisualizerCalls/SendMessage.h"
|
#include "../VisualizerCalls/SendMessage.h"
|
||||||
#include "expr_transform.h"
|
#include "../ExpressionTransform/expr_transform.h"
|
||||||
|
|
||||||
using std::set;
|
using std::set;
|
||||||
using std::map;
|
using std::map;
|
||||||
@@ -1089,8 +1089,6 @@ static int clean(const string& funcName, SgStatement* funcSt, const map<string,
|
|||||||
}
|
}
|
||||||
|
|
||||||
SgGotoStmt* gotoSt = new SgGotoStmt(*contLab);
|
SgGotoStmt* gotoSt = new SgGotoStmt(*contLab);
|
||||||
if (st->label())
|
|
||||||
gotoSt->setLabel(*st->label());
|
|
||||||
st->insertStmtBefore(*gotoSt, *st->controlParent());
|
st->insertStmtBefore(*gotoSt, *st->controlParent());
|
||||||
|
|
||||||
toDelete.push_back(st);
|
toDelete.push_back(st);
|
||||||
@@ -1778,8 +1776,11 @@ static bool inliner(const string& fileName_in, const string& funcName, const int
|
|||||||
point.currCall = func->funcName;
|
point.currCall = func->funcName;
|
||||||
|
|
||||||
__spf_print(1, " INLINE %s - ", func->funcName.c_str());
|
__spf_print(1, " INLINE %s - ", func->funcName.c_str());
|
||||||
sendMessage_2lvl(6, func->funcName);
|
#ifdef _WIN32
|
||||||
|
sendMessage_2lvl(wstring(L"ïîäñòàíîâêà ôóíêöèè '") + wstring(func->funcName.begin(), func->funcName.end()) + L"'");
|
||||||
|
#else
|
||||||
|
sendMessage_2lvl(wstring(L"inlinig of function '") + wstring(func->funcName.begin(), func->funcName.end()) + L"'");
|
||||||
|
#endif
|
||||||
//1 level
|
//1 level
|
||||||
bool isInlined = run_inliner(funcMap, toInsert, SPF_messages, fileName, func, newSymbsToDeclare, point, commonBlocks);
|
bool isInlined = run_inliner(funcMap, toInsert, SPF_messages, fileName, func, newSymbsToDeclare, point, commonBlocks);
|
||||||
__spf_print(1, "%s\n", isInlined ? "done" : "fault");
|
__spf_print(1, "%s\n", isInlined ? "done" : "fault");
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
#include "leak_detector.h"
|
#include "../Utils/leak_detector.h"
|
||||||
|
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
@@ -8,8 +8,8 @@
|
|||||||
#include <set>
|
#include <set>
|
||||||
|
|
||||||
#include "dvm.h"
|
#include "dvm.h"
|
||||||
#include "SgUtils.h"
|
#include "../Utils/SgUtils.h"
|
||||||
#include "errors.h"
|
#include "../Utils/errors.h"
|
||||||
|
|
||||||
using std::set;
|
using std::set;
|
||||||
using std::pair;
|
using std::pair;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#include "leak_detector.h"
|
#include "../Utils/leak_detector.h"
|
||||||
|
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
@@ -20,8 +20,8 @@
|
|||||||
#include "dvm.h"
|
#include "dvm.h"
|
||||||
#include "loop_analyzer.h"
|
#include "loop_analyzer.h"
|
||||||
|
|
||||||
#include "utils.h"
|
#include "../Utils/utils.h"
|
||||||
#include "SgUtils.h"
|
#include "../Utils/SgUtils.h"
|
||||||
#include "../ParallelizationRegions/ParRegions_func.h"
|
#include "../ParallelizationRegions/ParRegions_func.h"
|
||||||
#include "../SageAnalysisTool/depGraph.h"
|
#include "../SageAnalysisTool/depGraph.h"
|
||||||
#include "../SageAnalysisTool/OmegaForSage/include/lang-interf.h"
|
#include "../SageAnalysisTool/OmegaForSage/include/lang-interf.h"
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
#include <tuple>
|
#include <tuple>
|
||||||
#include <stack>
|
#include <stack>
|
||||||
|
|
||||||
#include "leak_detector.h"
|
#include "../Utils/leak_detector.h"
|
||||||
|
|
||||||
#if _WIN32 && NDEBUG && __BOOST
|
#if _WIN32 && NDEBUG && __BOOST
|
||||||
#include <boost/thread.hpp>
|
#include <boost/thread.hpp>
|
||||||
@@ -30,25 +30,25 @@ extern int passDone;
|
|||||||
#include "../Distribution/Arrays.h"
|
#include "../Distribution/Arrays.h"
|
||||||
#include "../ParallelizationRegions/ParRegions.h"
|
#include "../ParallelizationRegions/ParRegions.h"
|
||||||
|
|
||||||
#include "errors.h"
|
#include "../Utils/errors.h"
|
||||||
#include "../DirectiveProcessing/directive_parser.h"
|
#include "../DirectiveProcessing/directive_parser.h"
|
||||||
#include "../DirectiveProcessing/directive_creator.h"
|
#include "../DirectiveProcessing/directive_creator.h"
|
||||||
|
|
||||||
#include "SgUtils.h"
|
#include "../Utils/SgUtils.h"
|
||||||
#include "AstWrapper.h"
|
#include "../Utils/AstWrapper.h"
|
||||||
|
|
||||||
#include "graph_calls_func.h"
|
#include "../GraphCall/graph_calls_func.h"
|
||||||
#include "graph_loops_func.h"
|
#include "../GraphLoop/graph_loops_func.h"
|
||||||
#include "../ParallelizationRegions/ParRegions_func.h"
|
#include "../ParallelizationRegions/ParRegions_func.h"
|
||||||
#include "../DynamicAnalysis/gCov_parser_func.h"
|
#include "../DynamicAnalysis/gCov_parser_func.h"
|
||||||
|
|
||||||
#include "expr_transform.h"
|
#include "../ExpressionTransform/expr_transform.h"
|
||||||
#include "../SageAnalysisTool/depInterfaceExt.h"
|
#include "../SageAnalysisTool/depInterfaceExt.h"
|
||||||
|
|
||||||
#include "../VisualizerCalls/get_information.h"
|
#include "../VisualizerCalls/get_information.h"
|
||||||
#include "../VisualizerCalls/SendMessage.h"
|
#include "../VisualizerCalls/SendMessage.h"
|
||||||
|
|
||||||
#include "LoopEndDoConverter/enddo_loop_converter.h"
|
#include "../Transformations/enddo_loop_converter.h"
|
||||||
|
|
||||||
#include "../DirectiveProcessing/remote_access.h"
|
#include "../DirectiveProcessing/remote_access.h"
|
||||||
#include "../DirectiveProcessing/directive_omp_parser.h"
|
#include "../DirectiveProcessing/directive_omp_parser.h"
|
||||||
@@ -247,7 +247,7 @@ static vector<int> matchSubscriptToLoopSymbols(const vector<SgForStmt*> &parentL
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pair<int, int> coeffs = pair<int, int>(0, 0);
|
pair<int, int> coefs = pair<int, int>(0, 0);
|
||||||
// more than one loop symbol in subscription
|
// more than one loop symbol in subscription
|
||||||
if (countOfSymbols > 1)
|
if (countOfSymbols > 1)
|
||||||
{
|
{
|
||||||
@@ -326,16 +326,16 @@ static vector<int> matchSubscriptToLoopSymbols(const vector<SgForStmt*> &parentL
|
|||||||
{
|
{
|
||||||
if (subscr->symbol()->id() == (parentLoops[position]->doName())->id())
|
if (subscr->symbol()->id() == (parentLoops[position]->doName())->id())
|
||||||
{
|
{
|
||||||
coeffs.first = 1;
|
coefs.first = 1;
|
||||||
needToCacl = false;
|
needToCacl = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (needToCacl)
|
if (needToCacl)
|
||||||
getCoefsOfSubscript(coeffs, subscr, parentLoops[position]->doName());
|
getCoefsOfSubscript(coefs, subscr, parentLoops[position]->doName());
|
||||||
__spf_print(PRINT_ARRAY_ARCS, " <%d %d> ", coeffs.first, coeffs.second);
|
__spf_print(PRINT_ARRAY_ARCS, " <%d %d> ", coefs.first, coefs.second);
|
||||||
|
|
||||||
if (coeffs.first == 0) // && coeffs.second == 0)
|
if (coefs.first == 0) // && coefs.second == 0)
|
||||||
{
|
{
|
||||||
if (currRegime == REMOTE_ACC)
|
if (currRegime == REMOTE_ACC)
|
||||||
{
|
{
|
||||||
@@ -346,7 +346,7 @@ static vector<int> matchSubscriptToLoopSymbols(const vector<SgForStmt*> &parentL
|
|||||||
{
|
{
|
||||||
const pair<bool, string> &arrayRefString = constructArrayRefForPrint(arrayRef, dimNum, origSubscr);
|
const pair<bool, string> &arrayRefString = constructArrayRefForPrint(arrayRef, dimNum, origSubscr);
|
||||||
__spf_print(1, "WARN: can not calculate index expression for array ref '%s' at line %d\n", arrayRefString.second.c_str(), currLine);
|
__spf_print(1, "WARN: can not calculate index expression for array ref '%s' at line %d\n", arrayRefString.second.c_str(), currLine);
|
||||||
addInfoToVectors(loopInfo, parentLoops[position], currOrigArrayS, dimNum, coeffs, UNREC_OP, numOfSubscriptions, currentW);
|
addInfoToVectors(loopInfo, parentLoops[position], currOrigArrayS, dimNum, coefs, UNREC_OP, numOfSubscriptions, currentW);
|
||||||
if (side == LEFT)
|
if (side == LEFT)
|
||||||
allPositions.clear();
|
allPositions.clear();
|
||||||
|
|
||||||
@@ -371,19 +371,19 @@ static vector<int> matchSubscriptToLoopSymbols(const vector<SgForStmt*> &parentL
|
|||||||
currOp.resize(numOfSubscriptions);
|
currOp.resize(numOfSubscriptions);
|
||||||
|
|
||||||
//add only uniq
|
//add only uniq
|
||||||
auto itAdd = currOp[dimNum].coefficients.find(coeffs);
|
auto itAdd = currOp[dimNum].coefficients.find(coefs);
|
||||||
if (itAdd == currOp[dimNum].coefficients.end())
|
if (itAdd == currOp[dimNum].coefficients.end())
|
||||||
itAdd = currOp[dimNum].coefficients.insert(itAdd, make_pair(coeffs, currentW));
|
itAdd = currOp[dimNum].coefficients.insert(itAdd, make_pair(coefs, currentW));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (coeffs.first < 0)
|
if (coefs.first < 0)
|
||||||
addInfoToMap(loopInfo, parentLoops[position], currOrigArrayS, arrayRef, dimNum, REMOTE_TRUE, currLine, numOfSubscriptions);
|
addInfoToMap(loopInfo, parentLoops[position], currOrigArrayS, arrayRef, dimNum, REMOTE_TRUE, currLine, numOfSubscriptions);
|
||||||
else
|
else
|
||||||
//if we found regular access to array - set it false
|
//if we found regular access to array - set it false
|
||||||
addInfoToMap(loopInfo, parentLoops[position], currOrigArrayS, arrayRef, dimNum, REMOTE_FALSE, currLine, numOfSubscriptions);
|
addInfoToMap(loopInfo, parentLoops[position], currOrigArrayS, arrayRef, dimNum, REMOTE_FALSE, currLine, numOfSubscriptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (coeffs.first < 0 && sharedMemoryParallelization == 0)
|
if (coefs.first < 0 && sharedMemoryParallelization == 0)
|
||||||
{
|
{
|
||||||
if (currRegime == DATA_DISTR)
|
if (currRegime == DATA_DISTR)
|
||||||
{
|
{
|
||||||
@@ -402,15 +402,15 @@ static vector<int> matchSubscriptToLoopSymbols(const vector<SgForStmt*> &parentL
|
|||||||
if (side == LEFT)
|
if (side == LEFT)
|
||||||
allPositions.clear();
|
allPositions.clear();
|
||||||
else
|
else
|
||||||
addInfoToVectors(loopInfo, parentLoops[position], currOrigArrayS, dimNum, coeffs, UNREC_OP, numOfSubscriptions, currentW);
|
addInfoToVectors(loopInfo, parentLoops[position], currOrigArrayS, dimNum, coefs, UNREC_OP, numOfSubscriptions, currentW);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (side == LEFT)
|
if (side == LEFT)
|
||||||
addInfoToVectors(loopInfo, parentLoops[position], currOrigArrayS, dimNum, coeffs, WRITE_OP, numOfSubscriptions, currentW);
|
addInfoToVectors(loopInfo, parentLoops[position], currOrigArrayS, dimNum, coefs, WRITE_OP, numOfSubscriptions, currentW);
|
||||||
else
|
else
|
||||||
addInfoToVectors(loopInfo, parentLoops[position], currOrigArrayS, dimNum, coeffs, READ_OP, numOfSubscriptions, currentW);
|
addInfoToVectors(loopInfo, parentLoops[position], currOrigArrayS, dimNum, coefs, READ_OP, numOfSubscriptions, currentW);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -418,13 +418,13 @@ static vector<int> matchSubscriptToLoopSymbols(const vector<SgForStmt*> &parentL
|
|||||||
if (currRegime == ARRAY_ACC_CORNER)
|
if (currRegime == ARRAY_ACC_CORNER)
|
||||||
{
|
{
|
||||||
int *valueSubs = new int[2];
|
int *valueSubs = new int[2];
|
||||||
valueSubs[0] = coeffs.first;
|
valueSubs[0] = coefs.first;
|
||||||
valueSubs[1] = coeffs.second;
|
valueSubs[1] = coefs.second;
|
||||||
#ifdef __SPF
|
#ifdef __SPF
|
||||||
addToCollection(__LINE__, __FILE__, valueSubs, 2);
|
addToCollection(__LINE__, __FILE__, valueSubs, 2);
|
||||||
#endif
|
#endif
|
||||||
const vector<int*> &coeffs = getAttributes<SgExpression*, int*>(subscr, set<int>{ INT_VAL });
|
const vector<int*> &coefs = getAttributes<SgExpression*, int*>(subscr, set<int>{ INT_VAL });
|
||||||
if (coeffs.size() == 0)
|
if (coefs.size() == 0)
|
||||||
{
|
{
|
||||||
subscr->addAttribute(INT_VAL, valueSubs, sizeof(int*));
|
subscr->addAttribute(INT_VAL, valueSubs, sizeof(int*));
|
||||||
if (position != -1 && allPositions.size() == 1 && position < parentLoops.size())
|
if (position != -1 && allPositions.size() == 1 && position < parentLoops.size())
|
||||||
@@ -1633,7 +1633,17 @@ void loopAnalyzer(SgFile *file, vector<ParallelRegion*> ®ions, map<tuple<int,
|
|||||||
createNeededException();
|
createNeededException();
|
||||||
|
|
||||||
string fName = file->functions(i)->symbol()->identifier();
|
string fName = file->functions(i)->symbol()->identifier();
|
||||||
sendMessage_2lvl(0, (file->functions(i)->variant() != MODULE_STMT), fName);
|
#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
|
||||||
|
|
||||||
set<SgSymbol*> delcsSymbViewed;
|
set<SgSymbol*> delcsSymbViewed;
|
||||||
set<SgStatement*> delcsStatViewed;
|
set<SgStatement*> delcsStatViewed;
|
||||||
@@ -1700,10 +1710,7 @@ void loopAnalyzer(SgFile *file, vector<ParallelRegion*> ®ions, map<tuple<int,
|
|||||||
map<string, pair<SgSymbol*, SgStatement*>> notMappedDistributedArrays;
|
map<string, pair<SgSymbol*, SgStatement*>> notMappedDistributedArrays;
|
||||||
set<string> mappedDistrbutedArrays;
|
set<string> mappedDistrbutedArrays;
|
||||||
|
|
||||||
const ParallelRegionLines* prevParLines = NULL;
|
|
||||||
double prevLinesWeight = 1.0;
|
|
||||||
double currentWeight = 1.0;
|
double currentWeight = 1.0;
|
||||||
|
|
||||||
while (st != lastNode)
|
while (st != lastNode)
|
||||||
{
|
{
|
||||||
createNeededException();
|
createNeededException();
|
||||||
@@ -1726,31 +1733,13 @@ void loopAnalyzer(SgFile *file, vector<ParallelRegion*> ®ions, map<tuple<int,
|
|||||||
}
|
}
|
||||||
|
|
||||||
const int currentLine = st->lineNumber() < -1 ? st->localLineNumber() : st->lineNumber();
|
const int currentLine = st->lineNumber() < -1 ? st->localLineNumber() : st->lineNumber();
|
||||||
auto regAndLines = getRegionAndLinesByLine(regions, st->fileName(), currentLine);
|
ParallelRegion *currReg = getRegionByLine(regions, st->fileName(), currentLine);
|
||||||
|
|
||||||
auto *currReg = regAndLines.first;
|
|
||||||
auto *parLines = regAndLines.second;
|
|
||||||
if (currReg == NULL)
|
if (currReg == NULL)
|
||||||
{
|
{
|
||||||
st = st->lexNext();
|
st = st->lexNext();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parLines != prevParLines)
|
|
||||||
{
|
|
||||||
prevParLines = parLines;
|
|
||||||
auto newParLinesWeight = parLines ? parLines->weight : 1.0;
|
|
||||||
|
|
||||||
if (prevParLines)
|
|
||||||
currentWeight /= prevLinesWeight;
|
|
||||||
|
|
||||||
if (parLines)
|
|
||||||
currentWeight *= newParLinesWeight;
|
|
||||||
|
|
||||||
prevLinesWeight = newParLinesWeight;
|
|
||||||
prevParLines = parLines;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isSgExecutableStatement(st) == NULL)
|
if (isSgExecutableStatement(st) == NULL)
|
||||||
delcsStatViewed.insert(st);
|
delcsStatViewed.insert(st);
|
||||||
else if (!sharedMemoryParallelization &&
|
else if (!sharedMemoryParallelization &&
|
||||||
@@ -2178,8 +2167,11 @@ void loopAnalyzer(SgFile *file, vector<ParallelRegion*> ®ions, map<tuple<int,
|
|||||||
if (!skipDeps)
|
if (!skipDeps)
|
||||||
{
|
{
|
||||||
string fName = file->functions(i)->symbol()->identifier();
|
string fName = file->functions(i)->symbol()->identifier();
|
||||||
sendMessage_2lvl(1, idx, (int)convertedLoopInfo.size());
|
#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
|
||||||
tryToFindDependencies(loop.first, allLoops, funcWasInit, file, regions, currMessages, collection, funcByName, defUseByPlace);
|
tryToFindDependencies(loop.first, allLoops, funcWasInit, file, regions, currMessages, collection, funcByName, defUseByPlace);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2199,7 +2191,7 @@ void loopAnalyzer(SgFile *file, vector<ParallelRegion*> ®ions, map<tuple<int,
|
|||||||
LoopGraph *tmpLoop = new LoopGraph();
|
LoopGraph *tmpLoop = new LoopGraph();
|
||||||
|
|
||||||
tmpLoop->region = reg;
|
tmpLoop->region = reg;
|
||||||
tmpLoop->loopType = LoopType::FOR;
|
tmpLoop->isFor = true;
|
||||||
|
|
||||||
tmpLoops.push_back(tmpLoop);
|
tmpLoops.push_back(tmpLoop);
|
||||||
|
|
||||||
@@ -2327,7 +2319,7 @@ void loopAnalyzer(SgFile *file, vector<ParallelRegion*> ®ions, map<tuple<int,
|
|||||||
if (parallizeFreeLoops)
|
if (parallizeFreeLoops)
|
||||||
selectFreeLoopsForParallelization(loopsForFunction, funcName, (regime == DATA_DISTR), regions, messagesForFile);
|
selectFreeLoopsForParallelization(loopsForFunction, funcName, (regime == DATA_DISTR), regions, messagesForFile);
|
||||||
}
|
}
|
||||||
sendMessage_2lvl(2);
|
sendMessage_2lvl(L"");
|
||||||
}
|
}
|
||||||
else if (regime == COMP_DISTR)
|
else if (regime == COMP_DISTR)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -5,12 +5,12 @@
|
|||||||
#include <tuple>
|
#include <tuple>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <set>
|
#include <set>
|
||||||
#include "graph_loops.h"
|
#include "../GraphLoop/graph_loops.h"
|
||||||
#include "graph_calls.h"
|
#include "../GraphCall/graph_calls.h"
|
||||||
#include "../ParallelizationRegions/ParRegions.h"
|
#include "../ParallelizationRegions/ParRegions.h"
|
||||||
#include "../SageAnalysisTool/depInterfaceExt.h"
|
#include "../SageAnalysisTool/depInterfaceExt.h"
|
||||||
#include "AstWrapper.h"
|
#include "../Utils/AstWrapper.h"
|
||||||
#include "SgUtils.h"
|
#include "../Utils/SgUtils.h"
|
||||||
|
|
||||||
#include "dvm.h"
|
#include "dvm.h"
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#include "leak_detector.h"
|
#include "../Utils/leak_detector.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@@ -10,12 +10,12 @@
|
|||||||
|
|
||||||
#include "dvm.h"
|
#include "dvm.h"
|
||||||
#include "ParRegions.h"
|
#include "ParRegions.h"
|
||||||
#include "utils.h"
|
#include "../Utils/utils.h"
|
||||||
#include "SgUtils.h"
|
#include "../Utils/SgUtils.h"
|
||||||
#include "graph_calls_func.h"
|
#include "../GraphCall/graph_calls_func.h"
|
||||||
#include "graph_loops.h"
|
#include "../GraphLoop/graph_loops.h"
|
||||||
#include "../Distribution/Distribution.h"
|
#include "../Distribution/Distribution.h"
|
||||||
#include "expr_transform.h"
|
#include "../ExpressionTransform/expr_transform.h"
|
||||||
|
|
||||||
using std::vector;
|
using std::vector;
|
||||||
using std::string;
|
using std::string;
|
||||||
@@ -24,7 +24,6 @@ using std::make_pair;
|
|||||||
using std::map;
|
using std::map;
|
||||||
using std::set;
|
using std::set;
|
||||||
using std::wstring;
|
using std::wstring;
|
||||||
using std::tuple;
|
|
||||||
|
|
||||||
extern void createMapLoopGraph(map<int, LoopGraph*> &sortedLoopGraph, const vector<LoopGraph*> *loopGraph);
|
extern void createMapLoopGraph(map<int, LoopGraph*> &sortedLoopGraph, const vector<LoopGraph*> *loopGraph);
|
||||||
|
|
||||||
@@ -94,10 +93,8 @@ static inline SgStatement* getParentStat(SgStatement *st)
|
|||||||
return iterator;
|
return iterator;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void updateRegionInfo(SgStatement *st, map<string, pair<Statement*, Statement*>> &startEnd,
|
static void updateRegionInfo(SgStatement *st, map<string, pair<Statement*, Statement*>> &startEnd, map<string, pair<int, int>> &lines_,
|
||||||
map<string, pair<int, int>> &lines_,
|
set<string> &funcCallFromReg, const map<string, FuncInfo*> &mapFuncs)
|
||||||
map<string, map<string, set<int>>> &funcCallFromReg,
|
|
||||||
const map<string, FuncInfo*> &mapFuncs)
|
|
||||||
{
|
{
|
||||||
string containsPrefix = "";
|
string containsPrefix = "";
|
||||||
SgStatement *st_ps = getParentStat(st);
|
SgStatement *st_ps = getParentStat(st);
|
||||||
@@ -106,26 +103,17 @@ static void updateRegionInfo(SgStatement *st, map<string, pair<Statement*, State
|
|||||||
containsPrefix = st_ps->symbol()->identifier() + string(".");
|
containsPrefix = st_ps->symbol()->identifier() + string(".");
|
||||||
|
|
||||||
extendRegionInfo(st, startEnd, lines_);
|
extendRegionInfo(st, startEnd, lines_);
|
||||||
|
|
||||||
set<string> callsFromStatement;
|
|
||||||
|
|
||||||
if (st->variant() == PROC_STAT)
|
if (st->variant() == PROC_STAT)
|
||||||
{
|
{
|
||||||
string fullName = st->symbol()->identifier();
|
string fullName = st->symbol()->identifier();
|
||||||
//check contains
|
//check contains
|
||||||
if (mapFuncs.find(containsPrefix + fullName) != mapFuncs.end())
|
if (mapFuncs.find(containsPrefix + fullName) != mapFuncs.end())
|
||||||
fullName = containsPrefix + fullName;
|
fullName = containsPrefix + fullName;
|
||||||
callsFromStatement.insert(fullName);
|
funcCallFromReg.insert(fullName);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int z = 0; z < 3; ++z)
|
for (int z = 0; z < 3; ++z)
|
||||||
findFuncCalls(st->expr(z), callsFromStatement, containsPrefix, mapFuncs);
|
findFuncCalls(st->expr(z), funcCallFromReg, containsPrefix, mapFuncs);
|
||||||
|
|
||||||
string filename = st->fileName();
|
|
||||||
int line = st->lineNumber();
|
|
||||||
|
|
||||||
for (const auto &func_name : callsFromStatement)
|
|
||||||
funcCallFromReg[func_name][filename].insert(line);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void fillArrayNamesInReg(set<string> &usedArrayInRegion, SgExpression *exp)
|
static void fillArrayNamesInReg(set<string> &usedArrayInRegion, SgExpression *exp)
|
||||||
@@ -330,9 +318,8 @@ void fillRegionLines(SgFile *file, vector<ParallelRegion*> ®ions, vector<Mess
|
|||||||
string regionName = "";
|
string regionName = "";
|
||||||
map<string, pair<Statement*, Statement*>> startEnd;
|
map<string, pair<Statement*, Statement*>> startEnd;
|
||||||
map<string, pair<int, int>> lines_;
|
map<string, pair<int, int>> lines_;
|
||||||
map<string, map<string, set<int>>> funcCallFromReg;
|
set<string> funcCallFromReg;
|
||||||
bool regionStarted = false;
|
bool regionStarted = false;
|
||||||
double fragmentWeight = 1.0;
|
|
||||||
|
|
||||||
vector<SgStatement*> toDel;
|
vector<SgStatement*> toDel;
|
||||||
for (int i = 0; i < funcNum; ++i)
|
for (int i = 0; i < funcNum; ++i)
|
||||||
@@ -381,33 +368,6 @@ void fillRegionLines(SgFile *file, vector<ParallelRegion*> ®ions, vector<Mess
|
|||||||
itFunc->second->callRegions.insert(0);
|
itFunc->second->callRegions.insert(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// parse SPF_APPLY_FRAGMENT clause
|
|
||||||
auto *apply_fragment = data->expr(1);
|
|
||||||
fragmentWeight = 1.0;
|
|
||||||
|
|
||||||
while (apply_fragment)
|
|
||||||
{
|
|
||||||
auto *curr = apply_fragment->lhs();
|
|
||||||
if (curr)
|
|
||||||
{
|
|
||||||
__spf_print(1, "%s %d\n", curr->unparse(), curr->variant());
|
|
||||||
|
|
||||||
if (curr->variant() == SPF_WEIGHT_OP)
|
|
||||||
{
|
|
||||||
if (curr->lhs() &&
|
|
||||||
isSgValueExp(curr->lhs()) &&
|
|
||||||
isSgValueExp(curr->lhs())->doubleValue())
|
|
||||||
{
|
|
||||||
fragmentWeight = strtod(isSgValueExp(curr->lhs())->doubleValue(), NULL);
|
|
||||||
__spf_print(1, "->> %lf\n", fragmentWeight);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
__spf_print(1, "WEIGHT clause without double argument\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
apply_fragment = apply_fragment->rhs();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (next && next->variant() == SPF_END_PARALLEL_REG_DIR)
|
if (next && next->variant() == SPF_END_PARALLEL_REG_DIR)
|
||||||
@@ -440,12 +400,10 @@ void fillRegionLines(SgFile *file, vector<ParallelRegion*> ®ions, vector<Mess
|
|||||||
|
|
||||||
extendRegionInfo(st, startEnd, lines_, true);
|
extendRegionInfo(st, startEnd, lines_, true);
|
||||||
for (auto itRegInfo = startEnd.begin(); itRegInfo != startEnd.end(); ++itRegInfo)
|
for (auto itRegInfo = startEnd.begin(); itRegInfo != startEnd.end(); ++itRegInfo)
|
||||||
currReg->AddLines(lines_[itRegInfo->first], itRegInfo->first, &itRegInfo->second, fragmentWeight);
|
currReg->AddLines(lines_[itRegInfo->first], itRegInfo->first, &itRegInfo->second);
|
||||||
|
|
||||||
for (auto &by_func : funcCallFromReg)
|
for (auto &func : funcCallFromReg)
|
||||||
for (auto &by_file : by_func.second)
|
currReg->AddFuncCalls(func);
|
||||||
for(auto &by_line : by_file.second)
|
|
||||||
currReg->AddFuncCalls(by_func.first, by_file.first, by_line);
|
|
||||||
|
|
||||||
filterUserDirectives(currReg, usedArrayInRegion, userDvmRedistrDirs, userDvmRealignDirs, userDvmShadowDirs);
|
filterUserDirectives(currReg, usedArrayInRegion, userDvmRedistrDirs, userDvmRealignDirs, userDvmShadowDirs);
|
||||||
currReg->AddUserDirectives(userDvmRealignDirs, DVM_REALIGN_DIR);
|
currReg->AddUserDirectives(userDvmRealignDirs, DVM_REALIGN_DIR);
|
||||||
@@ -538,48 +496,34 @@ void fillRegionLinesStep2(vector<ParallelRegion*> ®ions, const map<string, ve
|
|||||||
{
|
{
|
||||||
if (regions[i]->GetName() != "DEFAULT")
|
if (regions[i]->GetName() != "DEFAULT")
|
||||||
for (auto &func : regions[i]->GetFuncCalls())
|
for (auto &func : regions[i]->GetFuncCalls())
|
||||||
setExplicitFlag(func.first, funcMap);
|
setExplicitFlag(func, funcMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < regions.size(); ++i)
|
for (int i = 0; i < regions.size(); ++i)
|
||||||
{
|
{
|
||||||
if (regions[i]->GetName() != "DEFAULT")
|
if (regions[i]->GetName() != "DEFAULT")
|
||||||
{
|
{
|
||||||
map<string, double> uniqFuncCalls;
|
set<string> uniqFuncCalls;
|
||||||
map<string, map<string, set<int>>> callPlaces;
|
|
||||||
|
|
||||||
for (auto &elem : regions[i]->GetFuncCalls())
|
for (auto &elem : regions[i]->GetFuncCalls())
|
||||||
{
|
uniqFuncCalls.insert(elem);
|
||||||
double max_weight = 0;
|
|
||||||
for (auto* fragment : elem.second)
|
|
||||||
if (fragment->weight > max_weight)
|
|
||||||
max_weight = fragment->weight;
|
|
||||||
|
|
||||||
uniqFuncCalls[elem.first] = max_weight;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool wasChanged = true;
|
|
||||||
auto funcsBefore = uniqFuncCalls;
|
|
||||||
|
|
||||||
|
bool wasChanged = 1;
|
||||||
while (wasChanged)
|
while (wasChanged)
|
||||||
{
|
{
|
||||||
wasChanged = false;
|
wasChanged = 0;
|
||||||
auto updated = uniqFuncCalls;
|
|
||||||
|
|
||||||
for (auto &uniqF : uniqFuncCalls)
|
for (auto &uniqF : uniqFuncCalls)
|
||||||
{
|
{
|
||||||
auto func = funcMap.find(uniqF.first);
|
auto func = funcMap.find(uniqF);
|
||||||
if (func != funcMap.end())
|
if (func != funcMap.end())
|
||||||
{
|
{
|
||||||
for (auto &call : func->second->callsFromDetailed)
|
for (auto &calls : func->second->callsFrom)
|
||||||
{
|
{
|
||||||
auto it = updated.find(call.detailCallsFrom.first);
|
auto it = uniqFuncCalls.find(calls);
|
||||||
if (it == updated.end())
|
if (it == uniqFuncCalls.end())
|
||||||
updated.insert({call.detailCallsFrom.first, uniqF.second});
|
{
|
||||||
else
|
uniqFuncCalls.insert(it, calls);
|
||||||
it->second = std::max(it->second, uniqF.second);
|
wasChanged = 1;
|
||||||
|
}
|
||||||
callPlaces[call.detailCallsFrom.first][func->second->fileName].insert(call.detailCallsFrom.second);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -588,27 +532,21 @@ void fillRegionLinesStep2(vector<ParallelRegion*> ®ions, const map<string, ve
|
|||||||
string toPrint = "";
|
string toPrint = "";
|
||||||
for (auto &elem : uniqFuncCalls)
|
for (auto &elem : uniqFuncCalls)
|
||||||
{
|
{
|
||||||
auto it = funcMap.find(elem.first);
|
auto it = funcMap.find(elem);
|
||||||
if (it != funcMap.end())
|
if (it != funcMap.end())
|
||||||
{
|
{
|
||||||
regions[i]->AddLines(it->second->linesNum, it->second->fileName, NULL, elem.second);
|
regions[i]->AddLines(it->second->linesNum, it->second->fileName);
|
||||||
|
regions[i]->AddFuncCallsToAllCalls(it->second);
|
||||||
|
|
||||||
if (it->second->inRegion == 0)
|
if (it->second->inRegion == 0)
|
||||||
it->second->inRegion = 2;
|
it->second->inRegion = 2;
|
||||||
|
|
||||||
it->second->callRegions.insert(i);
|
it->second->callRegions.insert(i);
|
||||||
|
|
||||||
toPrint += elem.first + " ";
|
toPrint += elem + " ";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto &elem : callPlaces)
|
|
||||||
{
|
|
||||||
for (const auto &byFile : elem.second)
|
|
||||||
for (auto byLine : byFile.second)
|
|
||||||
regions[i]->AddFuncCalls(elem.first, byFile.first, byLine);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (toPrint != "")
|
if (toPrint != "")
|
||||||
__spf_print(1, "[%s]: funcs: %s\n", regions[i]->GetName().c_str(), toPrint.c_str());
|
__spf_print(1, "[%s]: funcs: %s\n", regions[i]->GetName().c_str(), toPrint.c_str());
|
||||||
}
|
}
|
||||||
@@ -956,64 +894,3 @@ void calculateLinesOfCode(vector<ParallelRegion*> &allRegions)
|
|||||||
__spf_print(1, " Count of lines in region '%s' = %d\n", elem->GetName().c_str(), lineCounter);
|
__spf_print(1, " Count of lines in region '%s' = %d\n", elem->GetName().c_str(), lineCounter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void propagateRegionInfo(map<tuple<int, string, string>, pair<DIST::Array*, DIST::ArrayAccessInfo*>>& declaredArrays,
|
|
||||||
const map<DIST::Array*, set<DIST::Array*>>& arrayLinksByFuncCalls,
|
|
||||||
const vector<ParallelRegion*> ¶llelRegions)
|
|
||||||
{
|
|
||||||
bool modified = true;
|
|
||||||
while (modified)
|
|
||||||
{
|
|
||||||
modified = false;
|
|
||||||
|
|
||||||
for (auto &array_pair: declaredArrays)
|
|
||||||
{
|
|
||||||
auto array = array_pair.second.first;
|
|
||||||
if (array->GetLocation().first == DIST::l_PARAMETER)
|
|
||||||
{
|
|
||||||
set<DIST::Array*> realArrayRef;
|
|
||||||
getAllArrayRefs(array, array, realArrayRef, arrayLinksByFuncCalls);
|
|
||||||
|
|
||||||
auto regs = array->GetRegionsName();
|
|
||||||
for (auto& ref : realArrayRef)
|
|
||||||
{
|
|
||||||
auto regsRef = ref->GetRegionsName();
|
|
||||||
for (auto& reg : regsRef)
|
|
||||||
{
|
|
||||||
if (regs.count(reg) == 0)
|
|
||||||
{
|
|
||||||
array->SetRegionPlace(reg);
|
|
||||||
modified = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool hasNonDefaultReg = false;
|
|
||||||
for (auto& elem : parallelRegions)
|
|
||||||
{
|
|
||||||
string regName = elem->GetName();
|
|
||||||
convertToLower(regName);
|
|
||||||
if (regName != "default")
|
|
||||||
hasNonDefaultReg = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (hasNonDefaultReg)
|
|
||||||
{
|
|
||||||
for (auto array : declaredArrays)
|
|
||||||
{
|
|
||||||
if (array.second.first->GetRegionsName().size() == 0)
|
|
||||||
array.second.first->SetDistributeFlag(DIST::NO_DISTR);
|
|
||||||
else if (array.second.first->GetRegionsName().size() == 1)
|
|
||||||
{
|
|
||||||
string regName = *array.second.first->GetRegionsName().begin();
|
|
||||||
convertToLower(regName);
|
|
||||||
if (regName == "default")
|
|
||||||
array.second.first->SetDistributeFlag(DIST::NO_DISTR);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -9,17 +9,17 @@
|
|||||||
#include "../Distribution/DvmhDirective.h"
|
#include "../Distribution/DvmhDirective.h"
|
||||||
#include "../Distribution/GraphCSR.h"
|
#include "../Distribution/GraphCSR.h"
|
||||||
#include "../Distribution/Distribution.h"
|
#include "../Distribution/Distribution.h"
|
||||||
#include "AstWrapper.h"
|
#include "../Utils/AstWrapper.h"
|
||||||
|
|
||||||
#include "json.hpp"
|
#include "../Utils/json.hpp"
|
||||||
|
|
||||||
#if __SPF
|
#if __SPF
|
||||||
#include "SgUtils.h"
|
#include "../Utils/SgUtils.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct ParallelRegionLines
|
struct ParallelRegionLines
|
||||||
{
|
{
|
||||||
ParallelRegionLines(double weight = 1.0) : weight(weight)
|
ParallelRegionLines()
|
||||||
{
|
{
|
||||||
lines = std::make_pair(-1, -1);
|
lines = std::make_pair(-1, -1);
|
||||||
stats = std::make_pair<Statement*, Statement*>(NULL, NULL);
|
stats = std::make_pair<Statement*, Statement*>(NULL, NULL);
|
||||||
@@ -27,15 +27,14 @@ struct ParallelRegionLines
|
|||||||
intervalAfter = std::make_pair<Statement*, Statement*>(NULL, NULL);
|
intervalAfter = std::make_pair<Statement*, Statement*>(NULL, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
ParallelRegionLines(const std::pair<int, int> &lines, double weight = 1.0) : lines(lines), weight(weight)
|
ParallelRegionLines(const std::pair<int, int> &lines) : lines(lines)
|
||||||
{
|
{
|
||||||
stats = std::make_pair<Statement*, Statement*>(NULL, NULL);
|
stats = std::make_pair<Statement*, Statement*>(NULL, NULL);
|
||||||
intervalBefore = std::make_pair<Statement*, Statement*>(NULL, NULL);
|
intervalBefore = std::make_pair<Statement*, Statement*>(NULL, NULL);
|
||||||
intervalAfter = std::make_pair<Statement*, Statement*>(NULL, NULL);
|
intervalAfter = std::make_pair<Statement*, Statement*>(NULL, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
ParallelRegionLines(const std::pair<int, int> &lines, const std::pair<Statement*, Statement*> stats, double weight = 1.0)
|
ParallelRegionLines(const std::pair<int, int> &lines, const std::pair<Statement*, Statement*> stats) : lines(lines), stats(stats)
|
||||||
: lines(lines), stats(stats), weight(weight)
|
|
||||||
{
|
{
|
||||||
intervalBefore = std::make_pair<Statement*, Statement*>(NULL, NULL);
|
intervalBefore = std::make_pair<Statement*, Statement*>(NULL, NULL);
|
||||||
intervalAfter = std::make_pair<Statement*, Statement*>(NULL, NULL);
|
intervalAfter = std::make_pair<Statement*, Statement*>(NULL, NULL);
|
||||||
@@ -63,8 +62,6 @@ struct ParallelRegionLines
|
|||||||
// <start, end> interval
|
// <start, end> interval
|
||||||
std::pair<Statement*, Statement*> intervalBefore;
|
std::pair<Statement*, Statement*> intervalBefore;
|
||||||
std::pair<Statement*, Statement*> intervalAfter;
|
std::pair<Statement*, Statement*> intervalAfter;
|
||||||
|
|
||||||
double weight; // weight of the fragment among all fragments of this region
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#if __SPF
|
#if __SPF
|
||||||
@@ -119,7 +116,7 @@ public:
|
|||||||
currentVariant = copy.currentVariant;
|
currentVariant = copy.currentVariant;
|
||||||
}
|
}
|
||||||
|
|
||||||
int AddLines(const std::pair<int, int> &linesToAdd, const std::string &file, const std::pair<Statement*, Statement*> *startEnd = NULL, double weight = 1.0)
|
int AddLines(const std::pair<int, int> &linesToAdd, const std::string &file, const std::pair<Statement*, Statement*> *startEnd = NULL)
|
||||||
{
|
{
|
||||||
if (linesToAdd.first > linesToAdd.second)
|
if (linesToAdd.first > linesToAdd.second)
|
||||||
return -1;
|
return -1;
|
||||||
@@ -129,29 +126,17 @@ public:
|
|||||||
it = lines.insert(it, make_pair(file, std::vector<ParallelRegionLines>()));
|
it = lines.insert(it, make_pair(file, std::vector<ParallelRegionLines>()));
|
||||||
|
|
||||||
if (startEnd)
|
if (startEnd)
|
||||||
it->second.push_back(ParallelRegionLines(linesToAdd, *startEnd, weight));
|
it->second.push_back(ParallelRegionLines(linesToAdd, *startEnd));
|
||||||
else
|
else
|
||||||
it->second.push_back(ParallelRegionLines(linesToAdd, weight));
|
it->second.push_back(ParallelRegionLines(linesToAdd));
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AddFuncCalls(const std::string &func, const std::string &file, const int line)
|
void AddFuncCalls(const std::string &func) { functionsCall.insert(func); }
|
||||||
{
|
|
||||||
auto *found_lines = GetLinesByLine(file, line);
|
|
||||||
|
|
||||||
if (found_lines)
|
|
||||||
functionsCall[func].insert(found_lines);
|
|
||||||
}
|
|
||||||
|
|
||||||
#if __SPF
|
#if __SPF
|
||||||
void AddFuncCallsToAllCalls(FuncInfo *func, const std::string &file, const int line)
|
void AddFuncCallsToAllCalls(FuncInfo *func) { allFunctionsCall.insert(func); }
|
||||||
{
|
|
||||||
auto *found_lines = GetLinesByLine(file, line);
|
|
||||||
|
|
||||||
if (found_lines)
|
|
||||||
allFunctionsCall[func].insert(found_lines);
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
uint64_t GetId() const { return regionId; }
|
uint64_t GetId() const { return regionId; }
|
||||||
@@ -191,10 +176,10 @@ public:
|
|||||||
const DataDirective& GetDataDir() const { return dataDirectives; }
|
const DataDirective& GetDataDir() const { return dataDirectives; }
|
||||||
DataDirective& GetDataDirToModify() { return dataDirectives; }
|
DataDirective& GetDataDirToModify() { return dataDirectives; }
|
||||||
|
|
||||||
const std::map<std::string, std::set<const ParallelRegionLines*>>& GetFuncCalls() const { return functionsCall; }
|
const std::set<std::string>& GetFuncCalls() const { return functionsCall; }
|
||||||
|
|
||||||
#if __SPF
|
#if __SPF
|
||||||
const std::map<FuncInfo*, std::set<const ParallelRegionLines*>>& GetAllFuncCalls() const { return allFunctionsCall; }
|
const std::set<FuncInfo*>& GetAllFuncCalls() const { return allFunctionsCall; }
|
||||||
const std::map<FuncInfo*, std::map<DIST::Array*, std::vector<ParallelRegionLines>>>& GetUsedLocalArrays() const { return usedLocalArrays; }
|
const std::map<FuncInfo*, std::map<DIST::Array*, std::vector<ParallelRegionLines>>>& GetUsedLocalArrays() const { return usedLocalArrays; }
|
||||||
const std::map<FuncInfo*, std::map<DIST::Array*, std::vector<ParallelRegionLines>>>& GetUsedCommonArrays() const { return usedCommonArrays; }
|
const std::map<FuncInfo*, std::map<DIST::Array*, std::vector<ParallelRegionLines>>>& GetUsedCommonArrays() const { return usedCommonArrays; }
|
||||||
|
|
||||||
@@ -233,7 +218,7 @@ public:
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool HasThisLine(const int line, const std::string &file, const ParallelRegionLines** found = nullptr) const
|
bool HasThisLine(const int line, const std::string &file) const
|
||||||
{
|
{
|
||||||
bool retVal = false;
|
bool retVal = false;
|
||||||
auto it = lines.find(file);
|
auto it = lines.find(file);
|
||||||
@@ -244,9 +229,6 @@ public:
|
|||||||
if (it->second[i].lines.first <= line && it->second[i].lines.second >= line)
|
if (it->second[i].lines.first <= line && it->second[i].lines.second >= line)
|
||||||
{
|
{
|
||||||
retVal = true;
|
retVal = true;
|
||||||
if (found)
|
|
||||||
*found = &(it->second[i]);
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -310,7 +292,7 @@ public:
|
|||||||
fprintf(fileOut, " originalName '%s'\n", originalName.c_str());
|
fprintf(fileOut, " originalName '%s'\n", originalName.c_str());
|
||||||
fprintf(fileOut, " functions call from %d:\n", (int)functionsCall.size());
|
fprintf(fileOut, " functions call from %d:\n", (int)functionsCall.size());
|
||||||
for (auto &func : functionsCall)
|
for (auto &func : functionsCall)
|
||||||
fprintf(fileOut, " '%s'\n", func.first.c_str());
|
fprintf(fileOut, " '%s'\n", func.c_str());
|
||||||
fprintf(fileOut, " total lines %d:\n", (int)lines.size());
|
fprintf(fileOut, " total lines %d:\n", (int)lines.size());
|
||||||
for (auto &line : lines)
|
for (auto &line : lines)
|
||||||
{
|
{
|
||||||
@@ -380,11 +362,11 @@ private:
|
|||||||
std::string originalName;
|
std::string originalName;
|
||||||
// file -> lines info
|
// file -> lines info
|
||||||
std::map<std::string, std::vector<ParallelRegionLines>> lines;
|
std::map<std::string, std::vector<ParallelRegionLines>> lines;
|
||||||
std::map<std::string, std::set<const ParallelRegionLines*>> functionsCall; // func name -> fragments with calls
|
std::set<std::string> functionsCall;
|
||||||
|
|
||||||
#if __SPF
|
#if __SPF
|
||||||
// for RESOLVE_PAR_REGIONS
|
// for RESOLVE_PAR_REGIONS
|
||||||
std::map<FuncInfo*, std::set<const ParallelRegionLines*>> allFunctionsCall; // function -> fragments with calls
|
std::set<FuncInfo*> allFunctionsCall;
|
||||||
std::map<FuncInfo*, std::map<DIST::Array*, std::vector<ParallelRegionLines>>> usedLocalArrays; // func -> array -> lines
|
std::map<FuncInfo*, std::map<DIST::Array*, std::vector<ParallelRegionLines>>> usedLocalArrays; // func -> array -> lines
|
||||||
std::map<FuncInfo*, std::map<DIST::Array*, std::vector<ParallelRegionLines>>> usedCommonArrays; // func -> array -> lines
|
std::map<FuncInfo*, std::map<DIST::Array*, std::vector<ParallelRegionLines>>> usedCommonArrays; // func -> array -> lines
|
||||||
//
|
//
|
||||||
@@ -426,5 +408,4 @@ private:
|
|||||||
ParallelRegion* getRegionById(const std::vector<ParallelRegion*>& regions, const uint64_t regionId);
|
ParallelRegion* getRegionById(const std::vector<ParallelRegion*>& regions, const uint64_t regionId);
|
||||||
ParallelRegion* getRegionByName(const std::vector<ParallelRegion*>& regions, const std::string& regionName);
|
ParallelRegion* getRegionByName(const std::vector<ParallelRegion*>& regions, const std::string& regionName);
|
||||||
ParallelRegion* getRegionByLine(const std::vector<ParallelRegion*>& regions, const std::string& file, const int line);
|
ParallelRegion* getRegionByLine(const std::vector<ParallelRegion*>& regions, const std::string& file, const int line);
|
||||||
std::pair<ParallelRegion*, const ParallelRegionLines*> getRegionAndLinesByLine(const std::vector<ParallelRegion*>& regions, const std::string& file, const int line);
|
|
||||||
std::set<ParallelRegion*> getAllRegionsByLine(const std::vector<ParallelRegion*>& regions, const std::string& file, const int line);
|
std::set<ParallelRegion*> getAllRegionsByLine(const std::vector<ParallelRegion*>& regions, const std::string& file, const int line);
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "ParRegions.h"
|
#include "ParRegions.h"
|
||||||
#include "graph_calls.h"
|
#include "../GraphCall/graph_calls.h"
|
||||||
#include "graph_loops.h"
|
#include "../GraphLoop/graph_loops.h"
|
||||||
|
|
||||||
void fillRegionLines(SgFile *file, std::vector<ParallelRegion*> ®ions, std::vector<Messages>& messagesForFile, std::vector<LoopGraph*> *loops = NULL, std::vector<FuncInfo*> *funcs = NULL);
|
void fillRegionLines(SgFile *file, std::vector<ParallelRegion*> ®ions, std::vector<Messages>& messagesForFile, std::vector<LoopGraph*> *loops = NULL, std::vector<FuncInfo*> *funcs = NULL);
|
||||||
void fillRegionLinesStep2(std::vector<ParallelRegion*> ®ions, const std::map<std::string, std::vector<FuncInfo*>> &allFuncInfo, std::map<std::string, std::vector<LoopGraph*>> *loopGraph = NULL);
|
void fillRegionLinesStep2(std::vector<ParallelRegion*> ®ions, const std::map<std::string, std::vector<FuncInfo*>> &allFuncInfo, std::map<std::string, std::vector<LoopGraph*>> *loopGraph = NULL);
|
||||||
@@ -10,7 +10,3 @@ int printParalleRegions(const char *fileName, std::vector<ParallelRegion*> ®i
|
|||||||
bool buildGraphFromUserDirectives(const std::vector<Statement*> &userDvmAlignDirs, DIST::GraphCSR<int, double, attrType> &G, DIST::Arrays<int> &allArrays, const std::map<DIST::Array*, std::set<DIST::Array*>> &arrayLinksByFuncCalls, const std::set<DIST::Array*>& alignedArrays, std::set<DIST::Array*>& addedArrays, const std::map<std::string, std::vector<FuncInfo*>>& funcsByFile);
|
bool buildGraphFromUserDirectives(const std::vector<Statement*> &userDvmAlignDirs, DIST::GraphCSR<int, double, attrType> &G, DIST::Arrays<int> &allArrays, const std::map<DIST::Array*, std::set<DIST::Array*>> &arrayLinksByFuncCalls, const std::set<DIST::Array*>& alignedArrays, std::set<DIST::Array*>& addedArrays, const std::map<std::string, std::vector<FuncInfo*>>& funcsByFile);
|
||||||
void clearRegionStaticData();
|
void clearRegionStaticData();
|
||||||
void calculateLinesOfCode(std::vector<ParallelRegion*> &allRegions);
|
void calculateLinesOfCode(std::vector<ParallelRegion*> &allRegions);
|
||||||
|
|
||||||
void propagateRegionInfo(std::map<std::tuple<int, std::string, std::string>, std::pair<DIST::Array*, DIST::ArrayAccessInfo*>>& declaredArrays,
|
|
||||||
const std::map<DIST::Array*, std::set<DIST::Array*>>& arrayLinksByFuncCall,
|
|
||||||
const std::vector<ParallelRegion*>& parallelRegions);
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#include "leak_detector.h"
|
#include "../Utils/leak_detector.h"
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "ParRegions.h"
|
#include "ParRegions.h"
|
||||||
#include "SgUtils.h"
|
#include "../Utils/SgUtils.h"
|
||||||
#include "errors.h"
|
#include "../Utils/errors.h"
|
||||||
|
|
||||||
bool expandExtractReg(const std::string &fileName, const int startLine, const int endLine, const std::vector<ParallelRegion*> ®ions, std::vector<Messages> &messagesForFile, const bool toDelete = false);
|
bool expandExtractReg(const std::string &fileName, const int startLine, const int endLine, const std::vector<ParallelRegion*> ®ions, std::vector<Messages> &messagesForFile, const bool toDelete = false);
|
||||||
|
|||||||
@@ -1,624 +0,0 @@
|
|||||||
#include "leak_detector.h"
|
|
||||||
|
|
||||||
#include <set>
|
|
||||||
#include <map>
|
|
||||||
#include "merge_regions.h"
|
|
||||||
|
|
||||||
using std::map;
|
|
||||||
using std::set;
|
|
||||||
using std::pair;
|
|
||||||
using std::string;
|
|
||||||
using std::vector;
|
|
||||||
|
|
||||||
//TODO: need to create new clause!!
|
|
||||||
static void parseMergeDirective(const char *comment,
|
|
||||||
vector<pair<string, string>> &parsed_mapping)
|
|
||||||
{
|
|
||||||
while (comment)
|
|
||||||
{
|
|
||||||
auto *line_end = strchr(comment, '\n');
|
|
||||||
|
|
||||||
static const char prefix[] = "!!spf transform(merge_arrays(";
|
|
||||||
static const auto compare_chars = sizeof(prefix) - 1;
|
|
||||||
|
|
||||||
if (strlen(comment) >= compare_chars)
|
|
||||||
{
|
|
||||||
std::string comment_cmp(comment, compare_chars);
|
|
||||||
convertToLower(comment_cmp);
|
|
||||||
|
|
||||||
if (comment_cmp == prefix)
|
|
||||||
{
|
|
||||||
auto* pair_start = comment + compare_chars;
|
|
||||||
auto* comma = strchr(pair_start, ',');
|
|
||||||
if (comma)
|
|
||||||
{
|
|
||||||
auto* close_br = strchr(comma + 1, ')');
|
|
||||||
if (close_br)
|
|
||||||
{
|
|
||||||
parsed_mapping.emplace_back(
|
|
||||||
string(pair_start, comma - pair_start),
|
|
||||||
string(comma + 1, close_br - comma - 1));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
comment = line_end;
|
|
||||||
|
|
||||||
if (comment)
|
|
||||||
comment++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static string getNonDefaultRegion(DIST::Array *a)
|
|
||||||
{
|
|
||||||
string result;
|
|
||||||
|
|
||||||
if (!a)
|
|
||||||
return result;
|
|
||||||
|
|
||||||
for (const auto ®_name : a->GetRegionsName())
|
|
||||||
{
|
|
||||||
if (reg_name != "default")
|
|
||||||
{
|
|
||||||
if (!result.empty())
|
|
||||||
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
|
||||||
|
|
||||||
result = reg_name;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool hasSameSizes(DIST::Array *a, DIST::Array *b)
|
|
||||||
{
|
|
||||||
for (auto *array : {a, b})
|
|
||||||
{
|
|
||||||
for (const auto &p : array->GetSizes())
|
|
||||||
{
|
|
||||||
if (p.first < 0 || p.second < 0)
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return a->GetSizes() == b->GetSizes() && a->GetTypeSize() == b->GetTypeSize();
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool checkSimilarTemplates(vector<ParallelRegion *> ®ions,
|
|
||||||
const map<string, string> &new_region_mapping)
|
|
||||||
{
|
|
||||||
// new region -> old regions
|
|
||||||
map<string, set<string>> new_region_inverse_mapping;
|
|
||||||
for (const auto &p : new_region_mapping)
|
|
||||||
new_region_inverse_mapping[p.second].insert(p.first);
|
|
||||||
|
|
||||||
for (const auto &new_reg : new_region_inverse_mapping)
|
|
||||||
{
|
|
||||||
DIST::Array *template_array = nullptr;
|
|
||||||
string first_reg_name;
|
|
||||||
|
|
||||||
for (const auto &old_region_name : new_reg.second)
|
|
||||||
{
|
|
||||||
auto *old_reg = getRegionByName(regions, old_region_name);
|
|
||||||
|
|
||||||
if (!old_reg)
|
|
||||||
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
|
||||||
|
|
||||||
const auto &distr_rules = old_reg->GetDataDir().GetDistrRules();
|
|
||||||
if (distr_rules.size() != 1)
|
|
||||||
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
|
||||||
|
|
||||||
auto *current_template = distr_rules.front().first;
|
|
||||||
|
|
||||||
if (template_array)
|
|
||||||
{
|
|
||||||
if (!hasSameSizes(template_array, current_template))
|
|
||||||
{
|
|
||||||
__spf_print(1, "Templates of %s and %s has different sizes\n",
|
|
||||||
first_reg_name.c_str(),
|
|
||||||
old_region_name.c_str());
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
// else everything OK
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
template_array = current_template;
|
|
||||||
first_reg_name = old_region_name;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool hasSameAlignment(const std::set<const AlignRule *> &align_a,
|
|
||||||
const std::set<const AlignRule *> &align_b)
|
|
||||||
{
|
|
||||||
if (align_a.size() != 1 || align_b.size() != 1)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
const auto *rule_a = *align_a.begin();
|
|
||||||
const auto *rule_b = *align_b.begin();
|
|
||||||
|
|
||||||
if (rule_a->alignRule != rule_b->alignRule)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void printExpr(SgExpression *e, string pad)
|
|
||||||
{
|
|
||||||
if (!e)
|
|
||||||
return;
|
|
||||||
|
|
||||||
__spf_print(1, "%s%d: %s\n", pad.c_str(), e->variant(), e->unparse());
|
|
||||||
|
|
||||||
printExpr(e->lhs(), pad + " ");
|
|
||||||
printExpr(e->rhs(), pad + " ");
|
|
||||||
}
|
|
||||||
|
|
||||||
static pair<vector<SgStatement *>, SgSymbol *> generateDeclaration(const string &array_name, const string &common_block_name,
|
|
||||||
const vector<pair<int, int>> &sizes, SgType *type, SgStatement *scope)
|
|
||||||
{
|
|
||||||
auto *array_symbol = new SgSymbol(VARIABLE_NAME, array_name.c_str(), new SgType(T_ARRAY), scope);
|
|
||||||
|
|
||||||
auto *decl = new SgDeclarationStatement(VAR_DECL);
|
|
||||||
|
|
||||||
decl->setExpression(1, new SgTypeExp(*type));
|
|
||||||
|
|
||||||
SgExpression *subs = new SgExprListExp();
|
|
||||||
|
|
||||||
auto *array_ref = new SgArrayRefExp(*array_symbol, *subs);
|
|
||||||
|
|
||||||
for (int i = 0; i < sizes.size(); i++)
|
|
||||||
{
|
|
||||||
const auto &p = sizes[i];
|
|
||||||
auto *d = new SgExpression(DDOT, new SgValueExp(p.first), new SgValueExp(p.second));
|
|
||||||
subs->setLhs(d);
|
|
||||||
|
|
||||||
if (i + 1 < sizes.size())
|
|
||||||
{
|
|
||||||
subs->setRhs(new SgExprListExp());
|
|
||||||
subs = subs->rhs();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
decl->setExpression(0, array_ref);
|
|
||||||
|
|
||||||
auto comm = new SgStatement(COMM_STAT);
|
|
||||||
|
|
||||||
comm->setExpression(0, new SgExpression(COMM_LIST,
|
|
||||||
new SgVarRefExp(array_symbol),
|
|
||||||
NULL,
|
|
||||||
new SgSymbol(COMMON_NAME, common_block_name.c_str())));
|
|
||||||
|
|
||||||
return {{decl, comm}, array_symbol};
|
|
||||||
}
|
|
||||||
|
|
||||||
static SgExpression* findExprWithVariant(SgExpression* exp, int variant)
|
|
||||||
{
|
|
||||||
if (exp)
|
|
||||||
{
|
|
||||||
if (exp->variant() == variant)
|
|
||||||
return exp;
|
|
||||||
|
|
||||||
auto *l = findExprWithVariant(exp->lhs(), variant);
|
|
||||||
if (l)
|
|
||||||
return l;
|
|
||||||
|
|
||||||
auto *r = findExprWithVariant(exp->rhs(), variant);
|
|
||||||
if (r)
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
SgType* GetArrayType(DIST::Array *array)
|
|
||||||
{
|
|
||||||
if (!array)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
for (const auto& decl_place : array->GetDeclInfo())
|
|
||||||
{
|
|
||||||
if (SgFile::switchToFile(decl_place.first) != -1)
|
|
||||||
{
|
|
||||||
auto* decl = SgStatement::getStatementByFileAndLine(decl_place.first, decl_place.second);
|
|
||||||
if (decl)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < 3; i++)
|
|
||||||
{
|
|
||||||
auto* found_type = isSgTypeExp(findExprWithVariant(decl->expr(i), TYPE_OP));
|
|
||||||
if (found_type)
|
|
||||||
return found_type->type();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
SgSymbol *insertDeclIfNeeded(const string &array_name,
|
|
||||||
const string &common_block_name,
|
|
||||||
DIST::Array *example_array,
|
|
||||||
FuncInfo *dest,
|
|
||||||
map<FuncInfo *, map<string, SgSymbol *>> &inserted_arrays)
|
|
||||||
{
|
|
||||||
auto *type = GetArrayType(example_array);
|
|
||||||
|
|
||||||
if (!type)
|
|
||||||
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
|
||||||
|
|
||||||
if (SgFile::switchToFile(dest->fileName) == -1)
|
|
||||||
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
|
||||||
|
|
||||||
auto &by_func = inserted_arrays[dest];
|
|
||||||
auto it = by_func.find(array_name);
|
|
||||||
|
|
||||||
if (it != by_func.end())
|
|
||||||
return it->second;
|
|
||||||
|
|
||||||
SgStatement *st = dest->funcPointer;
|
|
||||||
|
|
||||||
auto *end = st->lastNodeOfStmt();
|
|
||||||
|
|
||||||
st = st->lexNext();
|
|
||||||
|
|
||||||
while (st != end && !isSgExecutableStatement(st))
|
|
||||||
{
|
|
||||||
st = st->lexNext();
|
|
||||||
}
|
|
||||||
|
|
||||||
auto generated = generateDeclaration(array_name, common_block_name,
|
|
||||||
example_array->GetSizes(),
|
|
||||||
type, dest->funcPointer);
|
|
||||||
for (auto *new_stmt : generated.first)
|
|
||||||
st->insertStmtBefore(*new_stmt, *dest->funcPointer);
|
|
||||||
|
|
||||||
by_func[array_name] = generated.second;
|
|
||||||
|
|
||||||
return generated.second;
|
|
||||||
}
|
|
||||||
|
|
||||||
static pair<string, string> createNewArray(DIST::Array *example_array, const string &base_name,
|
|
||||||
const map<string, vector<FuncInfo *>> &allFuncInfo,
|
|
||||||
map<FuncInfo *, map<string, SgSymbol *>> &inserted_arrays)
|
|
||||||
{
|
|
||||||
auto common_block_name = base_name + "_merge_r";
|
|
||||||
auto array_name = base_name;
|
|
||||||
|
|
||||||
for (const auto &by_file : allFuncInfo)
|
|
||||||
{
|
|
||||||
for (auto *func_info : by_file.second)
|
|
||||||
{
|
|
||||||
if (func_info->isMain)
|
|
||||||
{
|
|
||||||
insertDeclIfNeeded(
|
|
||||||
array_name,
|
|
||||||
common_block_name,
|
|
||||||
example_array,
|
|
||||||
func_info,
|
|
||||||
inserted_arrays);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return std::make_pair(array_name, common_block_name);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void replaceArrayRec(SgExpression *e,
|
|
||||||
const set<string> &arrays_to_replace,
|
|
||||||
SgSymbol **func_symbol_hint,
|
|
||||||
const pair<string, string> &replace_by,
|
|
||||||
DIST::Array *example_array,
|
|
||||||
FuncInfo *func,
|
|
||||||
map<FuncInfo *, map<string, SgSymbol *>> &inserted_arrays)
|
|
||||||
{
|
|
||||||
if (!e)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (isArrayRef(e) && arrays_to_replace.find(e->symbol()->identifier()) != arrays_to_replace.end())
|
|
||||||
{
|
|
||||||
if (!(*func_symbol_hint))
|
|
||||||
{
|
|
||||||
*func_symbol_hint = insertDeclIfNeeded(
|
|
||||||
replace_by.first, replace_by.second,
|
|
||||||
example_array,
|
|
||||||
func,
|
|
||||||
inserted_arrays);
|
|
||||||
}
|
|
||||||
|
|
||||||
e->setSymbol(*func_symbol_hint);
|
|
||||||
}
|
|
||||||
|
|
||||||
replaceArrayRec(
|
|
||||||
e->lhs(),
|
|
||||||
arrays_to_replace,
|
|
||||||
func_symbol_hint,
|
|
||||||
replace_by,
|
|
||||||
example_array,
|
|
||||||
func,
|
|
||||||
inserted_arrays);
|
|
||||||
|
|
||||||
replaceArrayRec(
|
|
||||||
e->rhs(),
|
|
||||||
arrays_to_replace,
|
|
||||||
func_symbol_hint,
|
|
||||||
replace_by,
|
|
||||||
example_array,
|
|
||||||
func,
|
|
||||||
inserted_arrays);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void replaceRegion(SgStatement* st, const map<string, string> &new_region_mapping)
|
|
||||||
{
|
|
||||||
if (!st)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if(isSPF_stat(st) && st->variant() == SPF_PARALLEL_REG_DIR)
|
|
||||||
{
|
|
||||||
auto it = new_region_mapping.find(st->symbol()->identifier());
|
|
||||||
|
|
||||||
if (it != new_region_mapping.end())
|
|
||||||
st->setSymbol(*(new SgSymbol(CONST_NAME, it->second.c_str())));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void mergeRegions(vector<ParallelRegion *> ®ions, const map<string, vector<FuncInfo *>> &allFuncInfo)
|
|
||||||
{
|
|
||||||
for (const auto *region : regions)
|
|
||||||
{
|
|
||||||
__spf_print(1, "region %s\n", region->GetName().c_str());
|
|
||||||
|
|
||||||
const auto &dirs = region->GetDataDir();
|
|
||||||
|
|
||||||
__spf_print(1, " distr rules: %d\n", dirs.distrRules.size());
|
|
||||||
|
|
||||||
const auto ¤tVariant = region->GetCurrentVariant();
|
|
||||||
|
|
||||||
int distr_idx = 0;
|
|
||||||
for (const auto &distr : dirs.distrRules)
|
|
||||||
{
|
|
||||||
const auto &dist_rule = distr.second.back().distRule;
|
|
||||||
|
|
||||||
string sizes;
|
|
||||||
for (const auto &p : distr.first->GetSizes())
|
|
||||||
{
|
|
||||||
if (!sizes.empty())
|
|
||||||
sizes.push_back(',');
|
|
||||||
|
|
||||||
sizes += std::to_string(p.first) + ":" + std::to_string(p.second);
|
|
||||||
}
|
|
||||||
|
|
||||||
__spf_print(1, " DIST %s(%s)", distr.first->GetName().c_str(), sizes.c_str());
|
|
||||||
for (const auto &dim : dist_rule)
|
|
||||||
__spf_print(1, " %c", dim == dist::BLOCK ? 'B' : '*');
|
|
||||||
|
|
||||||
__spf_print(1, "\n");
|
|
||||||
distr_idx++;
|
|
||||||
}
|
|
||||||
|
|
||||||
__spf_print(1, " align rules: %d\n", dirs.alignRules.size());
|
|
||||||
|
|
||||||
for (const auto &align : dirs.alignRules)
|
|
||||||
{
|
|
||||||
string sub_a, sub_b;
|
|
||||||
|
|
||||||
int i = 0;
|
|
||||||
for (const auto coefs : align.alignRule)
|
|
||||||
{
|
|
||||||
if (!sub_a.empty())
|
|
||||||
sub_a.push_back(',');
|
|
||||||
|
|
||||||
sub_a += std::to_string(coefs.first) + "*i" +
|
|
||||||
std::to_string(i) + "+" + std::to_string(coefs.second);
|
|
||||||
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const auto coefs : align.alignRuleWith)
|
|
||||||
{
|
|
||||||
if (!sub_b.empty())
|
|
||||||
sub_b.push_back(',');
|
|
||||||
|
|
||||||
sub_b += std::to_string(coefs.second.first) + "*i" +
|
|
||||||
std::to_string(coefs.first) + "+" + std::to_string(coefs.second.second);
|
|
||||||
}
|
|
||||||
|
|
||||||
__spf_print(1, " ALIGN %s(%s) WITH %s(%s)\n",
|
|
||||||
align.alignArray->GetName().c_str(), sub_a.c_str(),
|
|
||||||
align.alignWith->GetName().c_str(), sub_b.c_str());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// parse directives
|
|
||||||
|
|
||||||
// new array name -> current arrays
|
|
||||||
map<string, set<DIST::Array *>> arrays_to_merge;
|
|
||||||
map<DIST::Array *, set<const AlignRule *>> array_alignment;
|
|
||||||
|
|
||||||
for (const auto &by_file : allFuncInfo)
|
|
||||||
{
|
|
||||||
const auto current_file_name = by_file.first;
|
|
||||||
|
|
||||||
if (SgFile::switchToFile(current_file_name) == -1)
|
|
||||||
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
|
||||||
|
|
||||||
for (auto *func_info : by_file.second)
|
|
||||||
{
|
|
||||||
SgStatement *curr_stmt = func_info->funcPointer;
|
|
||||||
if (!curr_stmt)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
auto *stmt_end = curr_stmt->lastDeclaration();
|
|
||||||
if (!stmt_end)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
stmt_end = stmt_end->lexNext();
|
|
||||||
|
|
||||||
for (; curr_stmt && curr_stmt != stmt_end; curr_stmt = curr_stmt->lexNext())
|
|
||||||
{
|
|
||||||
if (curr_stmt->comments())
|
|
||||||
{
|
|
||||||
vector<pair<string, string>> parsed_mapping;
|
|
||||||
parseMergeDirective(curr_stmt->comments(), parsed_mapping);
|
|
||||||
|
|
||||||
for (const auto &p : parsed_mapping)
|
|
||||||
{
|
|
||||||
auto *found_array = getArrayFromDeclarated(curr_stmt, p.first);
|
|
||||||
if (found_array)
|
|
||||||
{
|
|
||||||
arrays_to_merge[p.second].insert(found_array);
|
|
||||||
array_alignment[found_array] = {};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// find alignment rules for array
|
|
||||||
|
|
||||||
for (const auto *region : regions)
|
|
||||||
{
|
|
||||||
const auto &dirs = region->GetDataDir();
|
|
||||||
|
|
||||||
for (const auto &align : dirs.alignRules)
|
|
||||||
{
|
|
||||||
auto it = array_alignment.find(align.alignArray);
|
|
||||||
|
|
||||||
if (it != array_alignment.end())
|
|
||||||
it->second.insert(&align);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// old region -> new region
|
|
||||||
map<string, string> new_region_mapping;
|
|
||||||
|
|
||||||
// new array -> new region
|
|
||||||
map<string, string> arrays_new_region_mapping;
|
|
||||||
vector<string> created_region_names;
|
|
||||||
|
|
||||||
for (const auto &by_new_array : arrays_to_merge)
|
|
||||||
{
|
|
||||||
string new_region_name;
|
|
||||||
for (auto *current_array : by_new_array.second)
|
|
||||||
{
|
|
||||||
auto current_array_region = getNonDefaultRegion(current_array);
|
|
||||||
auto it = new_region_mapping.find(current_array_region);
|
|
||||||
if (it != new_region_mapping.end())
|
|
||||||
{
|
|
||||||
if (new_region_name.empty())
|
|
||||||
new_region_name = it->second;
|
|
||||||
else if (new_region_name != it->second)
|
|
||||||
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (new_region_name.empty())
|
|
||||||
{
|
|
||||||
new_region_name = "merged_reg_" + std::to_string(created_region_names.size());
|
|
||||||
created_region_names.push_back(new_region_name);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (auto *current_array : by_new_array.second)
|
|
||||||
{
|
|
||||||
auto current_array_region = getNonDefaultRegion(current_array);
|
|
||||||
new_region_mapping[current_array_region] = new_region_name;
|
|
||||||
}
|
|
||||||
|
|
||||||
arrays_new_region_mapping[by_new_array.first] = new_region_name;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!checkSimilarTemplates(regions, new_region_mapping))
|
|
||||||
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
|
||||||
|
|
||||||
map<FuncInfo *, map<string, SgSymbol *>> inserted_arrays;
|
|
||||||
|
|
||||||
for (const auto &by_dest_array : arrays_to_merge)
|
|
||||||
{
|
|
||||||
const auto ©_arrays = by_dest_array.second;
|
|
||||||
|
|
||||||
if (copy_arrays.empty())
|
|
||||||
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
|
||||||
|
|
||||||
auto *first_element = *copy_arrays.begin();
|
|
||||||
auto first_elem_rules_it = array_alignment.find(first_element);
|
|
||||||
|
|
||||||
if (first_elem_rules_it == array_alignment.end())
|
|
||||||
continue;
|
|
||||||
|
|
||||||
const auto &first_elem_rules = first_elem_rules_it->second;
|
|
||||||
|
|
||||||
for (auto *array_to_merge : copy_arrays)
|
|
||||||
{
|
|
||||||
auto array_rules_it = array_alignment.find(array_to_merge);
|
|
||||||
|
|
||||||
if (array_rules_it == array_alignment.end())
|
|
||||||
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
|
||||||
|
|
||||||
const auto &array_rules = array_rules_it->second;
|
|
||||||
|
|
||||||
if (!hasSameSizes(array_to_merge, first_element) || !hasSameAlignment(first_elem_rules, array_rules))
|
|
||||||
{
|
|
||||||
__spf_print(1, "Arrays %s and %s has different sizes or align rules\n",
|
|
||||||
array_to_merge->GetName().c_str(),
|
|
||||||
first_element->GetName().c_str());
|
|
||||||
|
|
||||||
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
__spf_print(1, "merge into %s (%s):\n", by_dest_array.first.c_str(), arrays_new_region_mapping[by_dest_array.first].c_str());
|
|
||||||
for (auto *array_to_merge : copy_arrays)
|
|
||||||
__spf_print(1, "%s\n", array_to_merge->GetName().c_str());
|
|
||||||
|
|
||||||
auto created_array_info = createNewArray(first_element, by_dest_array.first, allFuncInfo, inserted_arrays);
|
|
||||||
|
|
||||||
set<string> arrays_to_replace;
|
|
||||||
for (auto *array_to_merge : copy_arrays)
|
|
||||||
arrays_to_replace.insert(array_to_merge->GetShortName());
|
|
||||||
|
|
||||||
for (const auto &by_file : allFuncInfo)
|
|
||||||
{
|
|
||||||
if (SgFile::switchToFile(by_file.first) == -1)
|
|
||||||
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
|
||||||
|
|
||||||
for (auto *func_info : by_file.second)
|
|
||||||
{
|
|
||||||
SgSymbol *func_symbol_hint = nullptr;
|
|
||||||
SgStatement *st = func_info->funcPointer;
|
|
||||||
|
|
||||||
auto *func_end = st->lastNodeOfStmt();
|
|
||||||
|
|
||||||
st = st->lexNext();
|
|
||||||
|
|
||||||
while (st && !isSgExecutableStatement(st) && st != func_end)
|
|
||||||
st = st->lexNext();
|
|
||||||
|
|
||||||
while (st && st != func_end)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < 3; i++)
|
|
||||||
{
|
|
||||||
replaceArrayRec(
|
|
||||||
st->expr(i),
|
|
||||||
arrays_to_replace,
|
|
||||||
&func_symbol_hint,
|
|
||||||
created_array_info,
|
|
||||||
first_element,
|
|
||||||
func_info,
|
|
||||||
inserted_arrays);
|
|
||||||
}
|
|
||||||
|
|
||||||
replaceRegion(st, new_region_mapping);
|
|
||||||
|
|
||||||
st = st->lexNext();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
#include "../GraphCall/graph_calls.h"
|
|
||||||
#include "ParRegions.h"
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
#include <map>
|
|
||||||
|
|
||||||
void mergeRegions(std::vector<ParallelRegion*> ®ions, const std::map<std::string, std::vector<FuncInfo*>> &allFuncInfo);
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
#include "leak_detector.h"
|
#include "../Utils/leak_detector.h"
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@@ -11,15 +11,14 @@
|
|||||||
#include "ParRegions_func.h"
|
#include "ParRegions_func.h"
|
||||||
#include "resolve_par_reg_conflicts.h"
|
#include "resolve_par_reg_conflicts.h"
|
||||||
|
|
||||||
#include "graph_calls_func.h"
|
#include "../GraphCall/graph_calls_func.h"
|
||||||
#include "graph_loops_func.h"
|
#include "../GraphLoop/graph_loops_func.h"
|
||||||
#include "../LoopAnalyzer/loop_analyzer.h"
|
#include "../LoopAnalyzer/loop_analyzer.h"
|
||||||
#include "../DirectiveProcessing/directive_creator.h"
|
#include "../DirectiveProcessing/directive_creator.h"
|
||||||
#include "../DirectiveProcessing/insert_directive.h"
|
#include "../DirectiveProcessing/insert_directive.h"
|
||||||
#include "SgUtils.h"
|
#include "../Utils/SgUtils.h"
|
||||||
#include "expr_transform.h"
|
#include "../ExpressionTransform/expr_transform.h"
|
||||||
#include "FunctionPurifying/function_purifying.h"
|
#include "../Transformations/function_purifying.h"
|
||||||
#include "uniq_name_creator.h"
|
|
||||||
|
|
||||||
using std::map;
|
using std::map;
|
||||||
using std::pair;
|
using std::pair;
|
||||||
@@ -72,7 +71,7 @@ static bool isSPF_reg(SgStatement *st)
|
|||||||
return st->variant() == SPF_PARALLEL_REG_DIR || st->variant() == SPF_END_PARALLEL_REG_DIR;
|
return st->variant() == SPF_PARALLEL_REG_DIR || st->variant() == SPF_END_PARALLEL_REG_DIR;
|
||||||
}
|
}
|
||||||
|
|
||||||
const vector<const Variable*> getArraySynonyms(DIST::Array *array)
|
static const vector<const Variable*> getArraySynonyms(DIST::Array *array)
|
||||||
{
|
{
|
||||||
auto arrayBlock = allUsedCommonArrays.find(array);
|
auto arrayBlock = allUsedCommonArrays.find(array);
|
||||||
if (arrayBlock == allUsedCommonArrays.end())
|
if (arrayBlock == allUsedCommonArrays.end())
|
||||||
@@ -128,16 +127,15 @@ static string getStringDeclaration(SgSymbol *symb)
|
|||||||
return decl;
|
return decl;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void insertStringDeclarations(SgStatement *insertPlace, DIST::Array *array, UniqueNameCreator& unique_name_creator)
|
static void insertStringDeclarations(SgStatement *insertPlace, DIST::Array *array)
|
||||||
{
|
{
|
||||||
auto varsOnPos = getArraySynonyms(array);
|
auto varsOnPos = getArraySynonyms(array);
|
||||||
if (varsOnPos.size() && varsOnPos[0]->getName() == array->GetShortName())
|
if (varsOnPos.size() && varsOnPos[0]->getName() == array->GetShortName())
|
||||||
{
|
{
|
||||||
string newArrName, commName;
|
|
||||||
unique_name_creator.GetUniqueName(array, newArrName, commName);
|
|
||||||
SgSymbol *varSymb = varsOnPos[0]->getSymbol();
|
SgSymbol *varSymb = varsOnPos[0]->getSymbol();
|
||||||
string varName = varSymb->identifier();
|
string varName = varSymb->identifier();
|
||||||
varSymb->changeName(newArrName.c_str());
|
string newName = varName + "_c";
|
||||||
|
varSymb->changeName(newName.c_str());
|
||||||
string decl = getStringDeclaration(varsOnPos[0]->getSymbol());
|
string decl = getStringDeclaration(varsOnPos[0]->getSymbol());
|
||||||
varSymb->changeName(varName.c_str());
|
varSymb->changeName(varName.c_str());
|
||||||
insertPlace->addComment(decl.c_str());
|
insertPlace->addComment(decl.c_str());
|
||||||
@@ -664,11 +662,12 @@ static void replaceFuncCalls(const ParallelRegionLines &lines, const map<string,
|
|||||||
static map<string, map<DIST::Array*, SgStatement*>> createdCommonBlocks; // file -> array -> new common statement
|
static map<string, map<DIST::Array*, SgStatement*>> createdCommonBlocks; // file -> array -> new common statement
|
||||||
static map<string, map<DIST::Array*, pair<SgSymbol*, SgSymbol*>>> createdCommonArrays; // file -> array -> (orig, copy)
|
static map<string, map<DIST::Array*, pair<SgSymbol*, SgSymbol*>>> createdCommonArrays; // file -> array -> (orig, copy)
|
||||||
|
|
||||||
static SgStatement* createCommonBlock(SgFile *file, DIST::Array *array, UniqueNameCreator& unique_name_creator)
|
static SgStatement* createCommonBlock(SgFile *file, DIST::Array *array)
|
||||||
{
|
{
|
||||||
string newArrName, commBlockName;
|
auto varsOnPos = getArraySynonyms(array);
|
||||||
|
if (!varsOnPos.size())
|
||||||
|
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
||||||
|
|
||||||
unique_name_creator.GetUniqueName(array, newArrName, commBlockName);
|
|
||||||
string fileName = file->filename();
|
string fileName = file->filename();
|
||||||
|
|
||||||
if (SgFile::switchToFile(fileName) != -1)
|
if (SgFile::switchToFile(fileName) != -1)
|
||||||
@@ -684,6 +683,7 @@ static SgStatement* createCommonBlock(SgFile *file, DIST::Array *array, UniqueNa
|
|||||||
// creating new common-block statement
|
// creating new common-block statement
|
||||||
//TODO: consistence with declaration
|
//TODO: consistence with declaration
|
||||||
//string commBlockName = checkSymbNameAndCorrect(array->GetShortName() + "_r");
|
//string commBlockName = checkSymbNameAndCorrect(array->GetShortName() + "_r");
|
||||||
|
string commBlockName = array->GetShortName() + "_r";
|
||||||
SgStatement *commDecl = new SgStatement(COMM_STAT);
|
SgStatement *commDecl = new SgStatement(COMM_STAT);
|
||||||
|
|
||||||
SgSymbol *commSymb = new SgSymbol(VARIABLE_NAME, commBlockName.c_str());
|
SgSymbol *commSymb = new SgSymbol(VARIABLE_NAME, commBlockName.c_str());
|
||||||
@@ -705,6 +705,7 @@ static SgStatement* createCommonBlock(SgFile *file, DIST::Array *array, UniqueNa
|
|||||||
{
|
{
|
||||||
//TODO: consistence with declaration
|
//TODO: consistence with declaration
|
||||||
//string newArrName = checkSymbNameAndCorrect(varsOnPos[0]->getName() + "_c");
|
//string newArrName = checkSymbNameAndCorrect(varsOnPos[0]->getName() + "_c");
|
||||||
|
string newArrName = varsOnPos[0]->getName() + "_c";
|
||||||
|
|
||||||
newArrSymb = new SgSymbol(VARIABLE_NAME, newArrName.c_str(), file->firstStatement());
|
newArrSymb = new SgSymbol(VARIABLE_NAME, newArrName.c_str(), file->firstStatement());
|
||||||
SgType *type = new SgType(T_ARRAY);
|
SgType *type = new SgType(T_ARRAY);
|
||||||
@@ -750,7 +751,7 @@ static SgStatement* createCommonBlock(SgFile *file, DIST::Array *array, UniqueNa
|
|||||||
// func -> arrays; funcs where new common statement inserted
|
// func -> arrays; funcs where new common statement inserted
|
||||||
static map<FuncInfo*, set<DIST::Array*>> insertedCommonBlocks;
|
static map<FuncInfo*, set<DIST::Array*>> insertedCommonBlocks;
|
||||||
|
|
||||||
static void insertCommonBlock(FuncInfo *func, DIST::Array *array, UniqueNameCreator& unique_name_creator)
|
static void insertCommonBlock(FuncInfo *func, DIST::Array *array)
|
||||||
{
|
{
|
||||||
SgFile *file = func->funcPointer->GetOriginal()->getFile();
|
SgFile *file = func->funcPointer->GetOriginal()->getFile();
|
||||||
SgStatement *insertPlace = NULL;
|
SgStatement *insertPlace = NULL;
|
||||||
@@ -766,7 +767,7 @@ static void insertCommonBlock(FuncInfo *func, DIST::Array *array, UniqueNameCrea
|
|||||||
if (!insertPlace)
|
if (!insertPlace)
|
||||||
insertPlace = func->funcPointer->GetOriginal();
|
insertPlace = func->funcPointer->GetOriginal();
|
||||||
|
|
||||||
SgStatement *commDecl = createCommonBlock(file, array, unique_name_creator);
|
SgStatement *commDecl = createCommonBlock(file, array);
|
||||||
SgStatement *copyDecl = commDecl->copyPtr();
|
SgStatement *copyDecl = commDecl->copyPtr();
|
||||||
|
|
||||||
auto st = insertPlace->controlParent();
|
auto st = insertPlace->controlParent();
|
||||||
@@ -778,7 +779,7 @@ static void insertCommonBlock(FuncInfo *func, DIST::Array *array, UniqueNameCrea
|
|||||||
insertPlace->lexNext()->setlineNumber(nextLine);
|
insertPlace->lexNext()->setlineNumber(nextLine);
|
||||||
|
|
||||||
// create declaration via comment
|
// create declaration via comment
|
||||||
insertStringDeclarations(insertPlace->lexNext(), array, unique_name_creator);
|
insertStringDeclarations(insertPlace->lexNext(), array);
|
||||||
}
|
}
|
||||||
|
|
||||||
// file -> lines -> arrays; lines where arrays copying is inserted
|
// file -> lines -> arrays; lines where arrays copying is inserted
|
||||||
@@ -1096,7 +1097,6 @@ pair<SgSymbol*, SgSymbol*> copyArray(const pair<string, int> &place,
|
|||||||
static void copyFunction(ParallelRegion *region,
|
static void copyFunction(ParallelRegion *region,
|
||||||
FuncInfo *func,
|
FuncInfo *func,
|
||||||
const map<string, FuncInfo*> &funcMap,
|
const map<string, FuncInfo*> &funcMap,
|
||||||
UniqueNameCreator& unique_name_creator,
|
|
||||||
const string &suffix = "")
|
const string &suffix = "")
|
||||||
{
|
{
|
||||||
if (SgFile::switchToFile(func->fileName) != -1)
|
if (SgFile::switchToFile(func->fileName) != -1)
|
||||||
@@ -1146,14 +1146,14 @@ static void copyFunction(ParallelRegion *region,
|
|||||||
if (origStat->variant() == COMM_STAT)
|
if (origStat->variant() == COMM_STAT)
|
||||||
{
|
{
|
||||||
for (auto &arrayBlock : allUsedCommonArrays)
|
for (auto &arrayBlock : allUsedCommonArrays)
|
||||||
createCommonBlock(file, arrayBlock.first, unique_name_creator);
|
createCommonBlock(file, arrayBlock.first);
|
||||||
|
|
||||||
auto usedCommonArrays = region->GetUsedCommonArrays().find(func);
|
auto usedCommonArrays = region->GetUsedCommonArrays().find(func);
|
||||||
if (usedCommonArrays != region->GetUsedCommonArrays().end())
|
if (usedCommonArrays != region->GetUsedCommonArrays().end())
|
||||||
{
|
{
|
||||||
for (auto &arrayLines : usedCommonArrays->second)
|
for (auto &arrayLines : usedCommonArrays->second)
|
||||||
{
|
{
|
||||||
SgStatement *commDecl = createCommonBlock(file, arrayLines.first, unique_name_creator);
|
SgStatement *commDecl = createCommonBlock(file, arrayLines.first);
|
||||||
SgStatement *copyDecl = commDecl->copyPtr();
|
SgStatement *copyDecl = commDecl->copyPtr();
|
||||||
|
|
||||||
while (!isSgExecutableStatement(copyStat) || isSPF_stat(copyStat))
|
while (!isSgExecutableStatement(copyStat) || isSPF_stat(copyStat))
|
||||||
@@ -1163,7 +1163,7 @@ static void copyFunction(ParallelRegion *region,
|
|||||||
copyStat->insertStmtAfter(*copyDecl, *copyStat->controlParent());
|
copyStat->insertStmtAfter(*copyDecl, *copyStat->controlParent());
|
||||||
|
|
||||||
// making declaration of new common array symbol via comment through files
|
// making declaration of new common array symbol via comment through files
|
||||||
insertStringDeclarations(copyStat->lexNext(), arrayLines.first, unique_name_creator);
|
insertStringDeclarations(copyStat->lexNext(), arrayLines.first);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto it = createdCommonArrays.find(file->filename());
|
auto it = createdCommonArrays.find(file->filename());
|
||||||
@@ -1619,8 +1619,6 @@ int resolveParRegions(vector<ParallelRegion*> ®ions, const map<string, vector
|
|||||||
map<string, FuncInfo*> funcMap;
|
map<string, FuncInfo*> funcMap;
|
||||||
createMapOfFunc(allFuncInfo, funcMap);
|
createMapOfFunc(allFuncInfo, funcMap);
|
||||||
|
|
||||||
UniqueNameCreator unique_name_creator(allFuncInfo);
|
|
||||||
|
|
||||||
if (sharedMemoryParallelization == 0)
|
if (sharedMemoryParallelization == 0)
|
||||||
{
|
{
|
||||||
map<string, map<int, set<string>>> copied;
|
map<string, map<int, set<string>>> copied;
|
||||||
@@ -1690,7 +1688,7 @@ int resolveParRegions(vector<ParallelRegion*> ®ions, const map<string, vector
|
|||||||
if (itt == it->second.end() && arrayBlock.first->GetShortName() == varsOnPos[0]->getName())
|
if (itt == it->second.end() && arrayBlock.first->GetShortName() == varsOnPos[0]->getName())
|
||||||
{
|
{
|
||||||
// need to insert common-block
|
// need to insert common-block
|
||||||
insertCommonBlock(func, arrayBlock.first, unique_name_creator);
|
insertCommonBlock(func, arrayBlock.first);
|
||||||
it->second.insert(arrayBlock.first);
|
it->second.insert(arrayBlock.first);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1783,7 +1781,7 @@ int resolveParRegions(vector<ParallelRegion*> ®ions, const map<string, vector
|
|||||||
if (itt == it->second.end() && arrayBlock.first->GetShortName() == varsOnPos[0]->getName())
|
if (itt == it->second.end() && arrayBlock.first->GetShortName() == varsOnPos[0]->getName())
|
||||||
{
|
{
|
||||||
// need to insert common-block
|
// need to insert common-block
|
||||||
insertCommonBlock(func, arrayBlock.first, unique_name_creator);
|
insertCommonBlock(func, arrayBlock.first);
|
||||||
it->second.insert(arrayBlock.first);
|
it->second.insert(arrayBlock.first);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1815,7 +1813,7 @@ int resolveParRegions(vector<ParallelRegion*> ®ions, const map<string, vector
|
|||||||
if (usedCommonArrays != region->GetUsedCommonArrays().end())
|
if (usedCommonArrays != region->GetUsedCommonArrays().end())
|
||||||
{
|
{
|
||||||
for (auto &arrayBlock : allUsedCommonArrays)
|
for (auto &arrayBlock : allUsedCommonArrays)
|
||||||
createCommonBlock(file, arrayBlock.first, unique_name_creator);
|
createCommonBlock(file, arrayBlock.first);
|
||||||
|
|
||||||
auto it = insertedCommonBlocks.find(func);
|
auto it = insertedCommonBlocks.find(func);
|
||||||
if (it == insertedCommonBlocks.end())
|
if (it == insertedCommonBlocks.end())
|
||||||
@@ -1827,7 +1825,7 @@ int resolveParRegions(vector<ParallelRegion*> ®ions, const map<string, vector
|
|||||||
if (itt == it->second.end())
|
if (itt == it->second.end())
|
||||||
{
|
{
|
||||||
// need to insert common-block
|
// need to insert common-block
|
||||||
insertCommonBlock(func, arrayLines.first, unique_name_creator);
|
insertCommonBlock(func, arrayLines.first);
|
||||||
it->second.insert(arrayLines.first);
|
it->second.insert(arrayLines.first);
|
||||||
|
|
||||||
// replace common arrays to new common arrays in executable code section
|
// replace common arrays to new common arrays in executable code section
|
||||||
@@ -1860,7 +1858,7 @@ int resolveParRegions(vector<ParallelRegion*> ®ions, const map<string, vector
|
|||||||
// need copy function for every region, the exeption is defalut region
|
// need copy function for every region, the exeption is defalut region
|
||||||
for (auto ®ionId : func->callRegions)
|
for (auto ®ionId : func->callRegions)
|
||||||
if (regionId)
|
if (regionId)
|
||||||
copyFunction(getRegionById(regions, regionId), func, funcMap, unique_name_creator, string("_r") + to_string(regionId));
|
copyFunction(getRegionById(regions, regionId), func, funcMap, string("_r") + to_string(regionId));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "ParRegions.h"
|
#include "ParRegions.h"
|
||||||
#include "SgUtils.h"
|
#include "../Utils/SgUtils.h"
|
||||||
#include "errors.h"
|
#include "../Utils/errors.h"
|
||||||
#include "graph_calls.h"
|
#include "../GraphCall/graph_calls.h"
|
||||||
|
|
||||||
void fillRegionIntervals(std::vector<ParallelRegion*> ®ions);
|
void fillRegionIntervals(std::vector<ParallelRegion*> ®ions);
|
||||||
void fillRegionArrays(std::vector<ParallelRegion*> ®ions, const std::map<std::string, std::vector<FuncInfo*>> &allFuncInfo, const std::map<std::string, CommonBlock*> &commonBlocks);
|
void fillRegionArrays(std::vector<ParallelRegion*> ®ions, const std::map<std::string, std::vector<FuncInfo*>> &allFuncInfo, const std::map<std::string, CommonBlock*> &commonBlocks);
|
||||||
@@ -22,5 +22,3 @@ std::pair<SgSymbol*, SgSymbol*> copyArray(const std::pair<std::string, int>& pla
|
|||||||
std::string& filename,
|
std::string& filename,
|
||||||
std::map<std::string, std::map<int, std::set<std::string>>>& newDeclsToInclude,
|
std::map<std::string, std::map<int, std::set<std::string>>>& newDeclsToInclude,
|
||||||
std::map<std::string, std::map<int, std::set<std::string>>>& copied);
|
std::map<std::string, std::map<int, std::set<std::string>>>& copied);
|
||||||
|
|
||||||
const std::vector<const Variable*> getArraySynonyms(DIST::Array* array);
|
|
||||||
@@ -1,98 +0,0 @@
|
|||||||
#include "leak_detector.h"
|
|
||||||
|
|
||||||
#include <set>
|
|
||||||
#include <map>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
#include "SgUtils.h"
|
|
||||||
#include "uniq_name_creator.h"
|
|
||||||
#include "resolve_par_reg_conflicts.h"
|
|
||||||
|
|
||||||
using namespace::std;
|
|
||||||
|
|
||||||
static const string COMMON_ARRAY_SUFFIX = "_c";
|
|
||||||
static const string COMMON_BLOCK_SUFFIX = "_r";
|
|
||||||
|
|
||||||
void UniqueNameCreator::GetSymbolsRec(SgExpression* exp, set<string>& add_to)
|
|
||||||
{
|
|
||||||
if (!exp)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (isArrayRef(exp) && exp->symbol() && exp->symbol()->identifier())
|
|
||||||
add_to.emplace(exp->symbol()->identifier());
|
|
||||||
|
|
||||||
GetSymbolsRec(exp->lhs(), add_to);
|
|
||||||
GetSymbolsRec(exp->rhs(), add_to);
|
|
||||||
}
|
|
||||||
|
|
||||||
void UniqueNameCreator::FillDeclarations()
|
|
||||||
{
|
|
||||||
allDeclarations.clear();
|
|
||||||
auto* file_before = current_file;
|
|
||||||
|
|
||||||
for (const auto& by_file : funcInfo)
|
|
||||||
{
|
|
||||||
if (SgFile::switchToFile(by_file.first) != -1)
|
|
||||||
{
|
|
||||||
for (const auto* by_func : by_file.second)
|
|
||||||
{
|
|
||||||
SgStatement* st = by_func->funcPointer;
|
|
||||||
|
|
||||||
if (st)
|
|
||||||
st = st->lexNext();
|
|
||||||
|
|
||||||
while (st)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < 3; i++)
|
|
||||||
GetSymbolsRec(st->expr(i), allDeclarations);
|
|
||||||
|
|
||||||
st = st->lexNext();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
|
||||||
}
|
|
||||||
|
|
||||||
SgFile::switchToFile(file_before->filename());
|
|
||||||
declarationsAnalyzed = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void UniqueNameCreator::GetUniqueName(DIST::Array* array, string& array_name, string& common_block_name)
|
|
||||||
{
|
|
||||||
auto varsOnPos = getArraySynonyms(array);
|
|
||||||
if (!varsOnPos.size())
|
|
||||||
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
|
||||||
|
|
||||||
auto array_plain_name = varsOnPos[0]->getName();
|
|
||||||
|
|
||||||
auto it = generatedNames.find(array);
|
|
||||||
if (it != generatedNames.end())
|
|
||||||
{
|
|
||||||
array_name.assign(it->second.first);
|
|
||||||
common_block_name.assign(it->second.second);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!declarationsAnalyzed)
|
|
||||||
FillDeclarations();
|
|
||||||
|
|
||||||
int v = 1;
|
|
||||||
auto created_array_name = array_plain_name + COMMON_ARRAY_SUFFIX;
|
|
||||||
auto created_common_name = array_plain_name + COMMON_BLOCK_SUFFIX;
|
|
||||||
|
|
||||||
while (allDeclarations.find(created_array_name) != allDeclarations.end() ||
|
|
||||||
allDeclarations.find(created_common_name) != allDeclarations.end())
|
|
||||||
{
|
|
||||||
created_array_name = array_plain_name + "_v" + std::to_string(v) + COMMON_ARRAY_SUFFIX;
|
|
||||||
created_common_name = array_plain_name + "_v" + std::to_string(v) + COMMON_BLOCK_SUFFIX;
|
|
||||||
v++;
|
|
||||||
}
|
|
||||||
|
|
||||||
allDeclarations.insert(created_array_name);
|
|
||||||
allDeclarations.insert(created_common_name);
|
|
||||||
generatedNames.emplace(array, std::make_pair(created_array_name, created_common_name));
|
|
||||||
|
|
||||||
array_name.assign(created_array_name);
|
|
||||||
common_block_name.assign(created_common_name);
|
|
||||||
}
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <map>
|
|
||||||
#include <set>
|
|
||||||
#include <string>
|
|
||||||
#include "GraphCall/graph_calls.h"
|
|
||||||
|
|
||||||
class UniqueNameCreator
|
|
||||||
{
|
|
||||||
std::map<std::string, std::vector<FuncInfo*>> funcInfo;
|
|
||||||
std::set<std::string> allDeclarations;
|
|
||||||
bool declarationsAnalyzed = false;
|
|
||||||
std::map<const DIST::Array*, std::pair<std::string, std::string>> generatedNames;
|
|
||||||
|
|
||||||
static void GetSymbolsRec(SgExpression* exp, std::set<std::string>& add_to);
|
|
||||||
void FillDeclarations();
|
|
||||||
|
|
||||||
public:
|
|
||||||
UniqueNameCreator(const std::map<std::string, std::vector<FuncInfo*>>& allFuncInfo)
|
|
||||||
{
|
|
||||||
declarationsAnalyzed = false;
|
|
||||||
funcInfo = allFuncInfo;
|
|
||||||
}
|
|
||||||
|
|
||||||
void GetUniqueName(DIST::Array* array, std::string& array_name, std::string& common_block_name);
|
|
||||||
};
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
#include "leak_detector.h"
|
#include "../Utils/leak_detector.h"
|
||||||
|
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
@@ -16,13 +16,13 @@
|
|||||||
#include "../DynamicAnalysis/gcov_info.h"
|
#include "../DynamicAnalysis/gcov_info.h"
|
||||||
#include "../DynamicAnalysis/gCov_parser_func.h"
|
#include "../DynamicAnalysis/gCov_parser_func.h"
|
||||||
#include "PredictScheme.h"
|
#include "PredictScheme.h"
|
||||||
#include "SgUtils.h"
|
#include "../Utils/SgUtils.h"
|
||||||
#include "../DirectiveProcessing/directive_parser.h"
|
#include "../DirectiveProcessing/directive_parser.h"
|
||||||
#include "../Distribution/DvmhDirective.h"
|
#include "../Distribution/DvmhDirective.h"
|
||||||
#include "graph_loops_func.h"
|
#include "../GraphLoop/graph_loops_func.h"
|
||||||
#include "expr_transform.h"
|
#include "../ExpressionTransform/expr_transform.h"
|
||||||
#include "../LoopAnalyzer/loop_analyzer.h"
|
#include "../LoopAnalyzer/loop_analyzer.h"
|
||||||
#include "CFGraph/CFGraph.h"
|
#include "../CFGraph/CFGraph.h"
|
||||||
|
|
||||||
#include "json.hpp"
|
#include "json.hpp"
|
||||||
|
|
||||||
@@ -33,7 +33,6 @@ using std::set;
|
|||||||
using std::ofstream;
|
using std::ofstream;
|
||||||
using std::pair;
|
using std::pair;
|
||||||
using std::tuple;
|
using std::tuple;
|
||||||
using SAPFOR::CFG_Settings;
|
|
||||||
|
|
||||||
using json = nlohmann::json;
|
using json = nlohmann::json;
|
||||||
|
|
||||||
@@ -327,7 +326,7 @@ static json parseAlign(const map<DIST::Array*, int>& byPos, SgSymbol* srcArr, Sg
|
|||||||
list = list->rhs();
|
list = list->rhs();
|
||||||
}
|
}
|
||||||
|
|
||||||
vector<pair<int, int>> coeffs(srcSymbs.size());
|
vector<pair<int, int>> coefs(srcSymbs.size());
|
||||||
list = listTgt;
|
list = listTgt;
|
||||||
while (list)
|
while (list)
|
||||||
{
|
{
|
||||||
@@ -338,8 +337,8 @@ static json parseAlign(const map<DIST::Array*, int>& byPos, SgSymbol* srcArr, Sg
|
|||||||
has = recSymbolFind(exp, srcSymbs[z].first, VAR_REF);
|
has = recSymbolFind(exp, srcSymbs[z].first, VAR_REF);
|
||||||
if (has)
|
if (has)
|
||||||
{
|
{
|
||||||
getCoefsOfSubscript(coeffs[z], exp, srcSymbs[z].second);
|
getCoefsOfSubscript(coefs[z], exp, srcSymbs[z].second);
|
||||||
if (coeffs[z].first == 0)
|
if (coefs[z].first == 0)
|
||||||
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -347,14 +346,14 @@ static json parseAlign(const map<DIST::Array*, int>& byPos, SgSymbol* srcArr, Sg
|
|||||||
list = list->rhs();
|
list = list->rhs();
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int z = 0; z < coeffs.size(); ++z)
|
for (int z = 0; z < coefs.size(); ++z)
|
||||||
{
|
{
|
||||||
if (coeffs[z].first == 0)
|
if (coefs[z].first == 0)
|
||||||
continue;
|
continue;
|
||||||
if (coeffs[z].second)
|
if (coefs[z].second)
|
||||||
align["rules"].push_back({ z, coeffs[z].first });
|
align["rules"].push_back({ z, coefs[z].first });
|
||||||
else
|
else
|
||||||
align["rules"].push_back({ z, coeffs[z].first, coeffs[z].second });
|
align["rules"].push_back({ z, coefs[z].first, coefs[z].second });
|
||||||
}
|
}
|
||||||
return align;
|
return align;
|
||||||
}
|
}
|
||||||
@@ -508,8 +507,7 @@ static void parallelDir(const map<DIST::Array*, int>& byPos, SgExpression* spec,
|
|||||||
if (currF == NULL)
|
if (currF == NULL)
|
||||||
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
||||||
|
|
||||||
const auto settings = CFG_Settings({ CFG_Settings::CFG_atLeastOneIterInLoop, CFG_Settings::CFG_withSPF, CFG_Settings::CFG_withDominators });
|
auto cfg = buildCFGforCurrentFunc(func, SAPFOR::CFG_Settings(true, false, false, true, false, false, true), commonBlocks, allFuncInfo);
|
||||||
auto cfg = buildCFGforCurrentFunc(func, settings, commonBlocks, allFuncInfo);
|
|
||||||
//TODO IP analysis
|
//TODO IP analysis
|
||||||
|
|
||||||
unsigned countOfAccess = 0;
|
unsigned countOfAccess = 0;
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "dvm.h"
|
#include "dvm.h"
|
||||||
#include "graph_calls.h"
|
#include "../GraphCall/graph_calls.h"
|
||||||
#include "json.hpp"
|
|
||||||
|
|
||||||
class ParallelStats
|
class ParallelStats
|
||||||
{
|
{
|
||||||
@@ -12,10 +11,10 @@ public:
|
|||||||
RemoteCount = ShadowCount = ReductionCount = AcrossCount = 0;
|
RemoteCount = ShadowCount = ReductionCount = AcrossCount = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int RemoteCount = 0;
|
int RemoteCount;
|
||||||
int ShadowCount = 0;
|
int ShadowCount;
|
||||||
int ReductionCount = 0;
|
int ReductionCount;
|
||||||
int AcrossCount = 0;
|
int AcrossCount;
|
||||||
};
|
};
|
||||||
|
|
||||||
class PredictorStats
|
class PredictorStats
|
||||||
@@ -28,32 +27,28 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
ParallelStats ParallelStat;
|
ParallelStats ParallelStat;
|
||||||
int ParallelCount = 0;
|
int ParallelCount;
|
||||||
int RemoteCount = 0;
|
int RemoteCount;
|
||||||
int RedistributeCount = 0;
|
int RedistributeCount;
|
||||||
int IntervalCount = 0;
|
int IntervalCount;
|
||||||
int TotalScoreComm = 0;
|
int TotalScoreComm;
|
||||||
int TotalScorePar = 0;
|
int TotalScorePar;
|
||||||
int TotalScoreDist = 0;
|
int TotalScoreDist;
|
||||||
|
|
||||||
nlohmann::json toJson()
|
std::string to_string()
|
||||||
{
|
{
|
||||||
nlohmann::json stat;
|
std::string res = "";
|
||||||
|
res += std::to_string(ParallelCount) + "|";
|
||||||
|
res += std::to_string(RemoteCount) + "|";
|
||||||
|
res += std::to_string(RedistributeCount) + "|";
|
||||||
|
res += std::to_string(IntervalCount) + "|";
|
||||||
|
|
||||||
stat["ParallelCount"] = ParallelCount;
|
res += std::to_string(ParallelStat.RemoteCount) + "|";
|
||||||
stat["RemoteCount"] = RemoteCount;
|
res += std::to_string(ParallelStat.ShadowCount) + "|";
|
||||||
stat["RedistributeCount"] = RedistributeCount;
|
res += std::to_string(ParallelStat.ReductionCount) + "|";
|
||||||
stat["IntervalCount"] = IntervalCount;
|
res += std::to_string(ParallelStat.AcrossCount);
|
||||||
|
|
||||||
stat["PS_RemoteCount"] = ParallelStat.RemoteCount;
|
return res;
|
||||||
stat["PS_ShadowCount"] = ParallelStat.ShadowCount;
|
|
||||||
stat["PS_ReductionCount"] = ParallelStat.ReductionCount;
|
|
||||||
stat["PS_AcrossCount"] = ParallelStat.AcrossCount;
|
|
||||||
|
|
||||||
//TODO: need to improve
|
|
||||||
// (summed.TotalScoreComm != 0 ? 1.0 / summed.TotalScoreComm : 0.0) + (double)summed.TotalScorePar * 1000 + (countOfDist == 0 ? -5000 : countOfDist);
|
|
||||||
stat["TotalScore"] = -1 * (ParallelStat.RemoteCount + ParallelStat.ShadowCount + ParallelStat.ReductionCount + ParallelStat.AcrossCount);
|
|
||||||
return stat;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#define _LEAK_
|
#define _LEAK_
|
||||||
#include "leak_detector.h"
|
#include "../Utils/leak_detector.h"
|
||||||
|
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
@@ -9,10 +9,10 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
#include "graph_calls.h"
|
#include "../GraphCall/graph_calls.h"
|
||||||
#include "private_analyzer.h"
|
#include "private_analyzer.h"
|
||||||
#include "dvm.h"
|
#include "dvm.h"
|
||||||
#include "CFGraph/CFGraph.h"
|
#include "../CFGraph/CFGraph.h"
|
||||||
|
|
||||||
using std::vector;
|
using std::vector;
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "dvm.h"
|
#include "dvm.h"
|
||||||
#include "graph_calls.h"
|
#include "../GraphCall/graph_calls.h"
|
||||||
|
|
||||||
extern void Private_Vars_Analyzer(SgStatement* start);
|
extern void Private_Vars_Analyzer(SgStatement* start);
|
||||||
void PrivateAnalyzer(SgFile *file, std::vector<FuncInfo*> &funcs);
|
void PrivateAnalyzer(SgFile *file, std::vector<FuncInfo*> &funcs);
|
||||||
|
|||||||
@@ -1,481 +0,0 @@
|
|||||||
#include <algorithm>
|
|
||||||
#include <map>
|
|
||||||
#include <unordered_set>
|
|
||||||
#include <unordered_map>
|
|
||||||
#include <vector>
|
|
||||||
#include <queue>
|
|
||||||
#include <numeric>
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
#include "ArrayConstantPropagation/propagation.h"
|
|
||||||
#include "CFGraph/CFGraph.h"
|
|
||||||
#include "Distribution/Array.h"
|
|
||||||
#include "graph_loops.h"
|
|
||||||
#include "private_arrays_search.h"
|
|
||||||
#include "range_structures.h"
|
|
||||||
#include "region.h"
|
|
||||||
#include "SgUtils.h"
|
|
||||||
#include "utils.h"
|
|
||||||
#include "Utils/AstWrapper.h"
|
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
extern std::map<std::tuple<int, std::string, std::string>, std::pair<DIST::Array*, DIST::ArrayAccessInfo*>> declaredArrays;
|
|
||||||
|
|
||||||
extern unordered_set<SgStatement*> statementsToRemove;
|
|
||||||
extern unordered_map<string, vector<pair<SgStatement*, SgStatement*>>> expToChange;
|
|
||||||
|
|
||||||
static unordered_set<Region*> collapsed;
|
|
||||||
|
|
||||||
static void RemoveEmptyPoints(ArrayAccessingIndexes& container)
|
|
||||||
{
|
|
||||||
ArrayAccessingIndexes resultContainer;
|
|
||||||
unordered_set<string> toRemove;
|
|
||||||
|
|
||||||
for (auto& [arrayName, accessingSet] : container)
|
|
||||||
{
|
|
||||||
vector<vector<ArrayDimension>> points;
|
|
||||||
for (auto& arrayPoint : accessingSet.GetElements())
|
|
||||||
{
|
|
||||||
if (!arrayPoint.empty())
|
|
||||||
points.push_back(arrayPoint);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!points.empty())
|
|
||||||
resultContainer[arrayName] = points;
|
|
||||||
else
|
|
||||||
toRemove.insert(arrayName);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const string& name : toRemove)
|
|
||||||
container.erase(name);
|
|
||||||
|
|
||||||
for (auto& [arrayName, accessingSet] : resultContainer)
|
|
||||||
container[arrayName] = accessingSet;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void Collapse(Region* region)
|
|
||||||
{
|
|
||||||
if (region->getBasickBlocks().empty())
|
|
||||||
return;
|
|
||||||
|
|
||||||
bool firstRegion = true;
|
|
||||||
for (Region* basickBlock : region->getBasickBlocks())
|
|
||||||
{
|
|
||||||
if (basickBlock->getNextRegions().empty())
|
|
||||||
{
|
|
||||||
if (firstRegion)
|
|
||||||
{
|
|
||||||
region->array_def = basickBlock->array_out;
|
|
||||||
firstRegion = false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
unordered_set<string> toErease;
|
|
||||||
for (auto& [arrayName, arrayRanges] : region->array_def)
|
|
||||||
{
|
|
||||||
if (basickBlock->array_out.find(arrayName) != basickBlock->array_out.end())
|
|
||||||
arrayRanges = arrayRanges.Intersect(basickBlock->array_out[arrayName]);
|
|
||||||
else
|
|
||||||
{
|
|
||||||
arrayRanges = AccessingSet();
|
|
||||||
toErease.insert(arrayName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (string arrayName : toErease)
|
|
||||||
region->array_def.erase(arrayName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
RegionInstruction instruction;
|
|
||||||
instruction.def = move(region->array_def);
|
|
||||||
|
|
||||||
|
|
||||||
for (auto& byBlock : region->getBasickBlocks())
|
|
||||||
{
|
|
||||||
for (auto& instruction : byBlock->instructions)
|
|
||||||
{
|
|
||||||
for (auto& [arrayName, _] : instruction.use)
|
|
||||||
{
|
|
||||||
AccessingSet diff = instruction.use[arrayName].Diff(instruction.in[arrayName]);
|
|
||||||
region->array_use[arrayName] = region->array_use[arrayName].Union(diff);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ArrayAccessingIndexes useUnionB;
|
|
||||||
for (auto& byBlock : region->getBasickBlocks())
|
|
||||||
for (auto& instruction : byBlock->instructions)
|
|
||||||
for (auto& [arrayName, _] : instruction.use)
|
|
||||||
useUnionB[arrayName] = useUnionB[arrayName].Union(instruction.use[arrayName]);
|
|
||||||
|
|
||||||
for (auto& [arrayName, _] : useUnionB)
|
|
||||||
region->array_priv[arrayName] = useUnionB[arrayName].Diff(region->array_use[arrayName]);
|
|
||||||
|
|
||||||
instruction.use = move(region->array_use);
|
|
||||||
|
|
||||||
for (Region* prevBlock : region->getHeader()->getPrevRegions())
|
|
||||||
{
|
|
||||||
prevBlock->replaceInNextRegions(region, region->getHeader());
|
|
||||||
region->addPrevRegion(prevBlock);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (Region* nextBlock : region->getHeader()->getNextRegions())
|
|
||||||
{
|
|
||||||
nextBlock->replaceInPrevRegions(region, region->getHeader());
|
|
||||||
region->addNextRegion(nextBlock);
|
|
||||||
}
|
|
||||||
region->instructions.push_back(instruction);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
static void SolveDataFlowIteratively(Region* DFG)
|
|
||||||
{
|
|
||||||
auto blocks = DFG->getBasickBlocks();
|
|
||||||
std::unordered_set<Region*> worklist(blocks.begin(), blocks.end());
|
|
||||||
do
|
|
||||||
{
|
|
||||||
Region* b = *worklist.begin();
|
|
||||||
ArrayAccessingIndexes newIn;
|
|
||||||
bool flagFirst = true;
|
|
||||||
for (Region* prevBlock : b->getPrevRegions())
|
|
||||||
{
|
|
||||||
if (flagFirst)
|
|
||||||
{
|
|
||||||
newIn = prevBlock->array_out;
|
|
||||||
flagFirst = false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (prevBlock->array_out.empty())
|
|
||||||
{
|
|
||||||
newIn.clear();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const auto& [arrayName, accessSet] : prevBlock->array_out)
|
|
||||||
{
|
|
||||||
if (newIn.find(arrayName) != newIn.end())
|
|
||||||
newIn[arrayName] = newIn[arrayName].Intersect(accessSet);
|
|
||||||
else
|
|
||||||
newIn[arrayName] = AccessingSet();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
b->array_in = move(newIn);
|
|
||||||
ArrayAccessingIndexes newOut;
|
|
||||||
|
|
||||||
if (b->array_def.empty())
|
|
||||||
newOut = b->array_in;
|
|
||||||
else if (b->array_in.empty())
|
|
||||||
newOut = b->array_def;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
for (auto& [arrayName, accessSet] : b->array_def)
|
|
||||||
{
|
|
||||||
if (newOut.find(arrayName) != newOut.end())
|
|
||||||
newOut[arrayName] = b->array_def[arrayName].Union(b->array_in[arrayName]);
|
|
||||||
else
|
|
||||||
newOut[arrayName] = accessSet;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* can not differ */
|
|
||||||
if (newOut != b->array_out)
|
|
||||||
b->array_out = newOut;
|
|
||||||
else
|
|
||||||
worklist.erase(b);
|
|
||||||
} while (!worklist.empty());
|
|
||||||
}
|
|
||||||
|
|
||||||
static void SolveForBasickBlock(Region* block)
|
|
||||||
{
|
|
||||||
ArrayAccessingIndexes newIn;
|
|
||||||
bool flagFirst = true;
|
|
||||||
for (Region* prevBlock : block->getPrevRegions())
|
|
||||||
{
|
|
||||||
if (flagFirst)
|
|
||||||
{
|
|
||||||
newIn = prevBlock->array_out;
|
|
||||||
flagFirst = false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (prevBlock->array_out.empty())
|
|
||||||
{
|
|
||||||
newIn.clear();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const auto& [arrayName, accessSet] : prevBlock->array_out)
|
|
||||||
{
|
|
||||||
if (newIn.find(arrayName) != newIn.end())
|
|
||||||
newIn[arrayName] = newIn[arrayName].Intersect(accessSet);
|
|
||||||
else
|
|
||||||
newIn[arrayName] = AccessingSet();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (block->instructions.empty())
|
|
||||||
block->instructions.push_back(RegionInstruction());
|
|
||||||
|
|
||||||
block->instructions[0].in = move(newIn);
|
|
||||||
|
|
||||||
for (int i = 0; i < block->instructions.size(); i++)
|
|
||||||
{
|
|
||||||
auto& instruction = block->instructions[i];
|
|
||||||
|
|
||||||
if (i > 0)
|
|
||||||
instruction.in = block->instructions[i - 1].out;
|
|
||||||
|
|
||||||
ArrayAccessingIndexes newOut;
|
|
||||||
if (instruction.def.empty())
|
|
||||||
newOut = instruction.in;
|
|
||||||
else if (instruction.in.empty())
|
|
||||||
newOut = instruction.def;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
for (auto& [arrayName, accessSet] : instruction.def)
|
|
||||||
{
|
|
||||||
if (instruction.in.find(arrayName) != instruction.in.end())
|
|
||||||
newOut[arrayName] = instruction.def[arrayName].Union(instruction.in[arrayName]);
|
|
||||||
else
|
|
||||||
newOut[arrayName] = accessSet;
|
|
||||||
}
|
|
||||||
for (auto& [arrayName, accessSet] : instruction.in)
|
|
||||||
{
|
|
||||||
if (newOut.find(arrayName) == newOut.end())
|
|
||||||
{
|
|
||||||
newOut[arrayName] = accessSet;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
instruction.out = move(newOut);
|
|
||||||
}
|
|
||||||
if (!block->instructions.empty())
|
|
||||||
block->array_out = block->instructions.back().out;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void SolveDataFlowTopologically(Region* DFG)
|
|
||||||
{
|
|
||||||
for (Region* b : DFG->getBasickBlocks())
|
|
||||||
{
|
|
||||||
collapsed.insert(b);
|
|
||||||
SolveForBasickBlock(b);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void SolveDataFlow(Region* DFG)
|
|
||||||
{
|
|
||||||
if (!DFG)
|
|
||||||
return;
|
|
||||||
for (Region* subRegion : DFG->getSubRegions())
|
|
||||||
{
|
|
||||||
SolveDataFlow(subRegion);
|
|
||||||
DFG->addBasickBlocks(subRegion);
|
|
||||||
}
|
|
||||||
vector<Region*>& blocks = DFG->getBasickBlocks();
|
|
||||||
auto pos = remove_if(blocks.begin(), blocks.end(), [](Region* r) { return collapsed.find(r) != collapsed.end(); });
|
|
||||||
blocks.erase(pos, blocks.end());
|
|
||||||
TopologySort(DFG->getBasickBlocks(), DFG->getHeader());
|
|
||||||
SolveDataFlowTopologically(DFG);
|
|
||||||
Collapse(DFG);
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool getArrayDeclaredDimensions(SgArrayRefExp* arrayRef, vector<uint64_t>& declaredDims)
|
|
||||||
{
|
|
||||||
if (!arrayRef || !arrayRef->symbol() || !isSgArrayType(arrayRef->symbol()->type()))
|
|
||||||
return false;
|
|
||||||
SgArrayType* arrayType = (SgArrayType*)arrayRef->symbol()->type();
|
|
||||||
int dimCount = arrayType->dimension();
|
|
||||||
for (int i = 0; i < dimCount; i++)
|
|
||||||
{
|
|
||||||
SgExpression* sizeExpr = arrayType->sizeInDim(i);
|
|
||||||
SgConstantSymb* constValSymb = isSgConstantSymb(sizeExpr->symbol());
|
|
||||||
SgSubscriptExp* subscriptExpr = isSgSubscriptExp(sizeExpr);
|
|
||||||
uint64_t dimLength;
|
|
||||||
if (sizeExpr && sizeExpr->variant() == INT_VAL)
|
|
||||||
dimLength = stol(sizeExpr->unparse());
|
|
||||||
else if (constValSymb)
|
|
||||||
dimLength = stol(constValSymb->constantValue()->unparse());
|
|
||||||
else if (subscriptExpr)
|
|
||||||
{
|
|
||||||
dimLength = stol(subscriptExpr->rhs()->unparse()) - stol(subscriptExpr->lhs()->unparse());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (dimLength == 0)
|
|
||||||
return false;
|
|
||||||
declaredDims.push_back(dimLength);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
static DIST::Array* getDistArrayBySymbol(SgSymbol* arrSym)
|
|
||||||
{
|
|
||||||
if (!arrSym)
|
|
||||||
return nullptr;
|
|
||||||
for (auto& [key, val] : declaredArrays)
|
|
||||||
{
|
|
||||||
DIST::Array* distArr = val.first;
|
|
||||||
if (!distArr)
|
|
||||||
continue;
|
|
||||||
Symbol* declSym = distArr->GetDeclSymbol();
|
|
||||||
if (!declSym)
|
|
||||||
continue;
|
|
||||||
SgSymbol* sgDecl = declSym->GetOriginal();
|
|
||||||
if (sgDecl && isEqSymbols(sgDecl, arrSym))
|
|
||||||
return distArr;
|
|
||||||
}
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool CheckDimensionLength(const AccessingSet& array)
|
|
||||||
{
|
|
||||||
if (array.GetElements().empty())
|
|
||||||
return false;
|
|
||||||
size_t dimCount = array.GetElements()[0].size();
|
|
||||||
SgArrayRefExp* arrayRef = array.GetElements()[0][0].array;
|
|
||||||
if (!arrayRef || !arrayRef->symbol())
|
|
||||||
return false;
|
|
||||||
|
|
||||||
vector<uint64_t> declaredDims;
|
|
||||||
declaredDims.reserve(dimCount);
|
|
||||||
|
|
||||||
DIST::Array* distArr = getDistArrayBySymbol(arrayRef->symbol());
|
|
||||||
if (distArr && distArr->GetDimSize() == (int)dimCount)
|
|
||||||
{
|
|
||||||
const auto& sizes = distArr->GetSizes();
|
|
||||||
bool valid = true;
|
|
||||||
for (size_t i = 0; i < dimCount && valid; ++i)
|
|
||||||
{
|
|
||||||
int lo = sizes[i].first;
|
|
||||||
int hi = sizes[i].second;
|
|
||||||
if (lo > hi)
|
|
||||||
valid = false;
|
|
||||||
else
|
|
||||||
declaredDims.push_back((uint64_t)(hi - lo + 1));
|
|
||||||
}
|
|
||||||
if (valid && declaredDims.size() == dimCount)
|
|
||||||
{
|
|
||||||
vector<ArrayDimension> testArray(dimCount);
|
|
||||||
for (size_t i = 0; i < dimCount; i++)
|
|
||||||
testArray[i] = { 1, 1, declaredDims[i], nullptr };
|
|
||||||
return AccessingSet({ testArray }).Diff(array).GetElements().empty();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void AddPrivateArraysToLoop(LoopGraph* loop, const ArrayAccessingIndexes& privates, set<SgStatement*>& insertedPrivates)
|
|
||||||
{
|
|
||||||
SgStatement* spfStat = new SgStatement(SPF_ANALYSIS_DIR);
|
|
||||||
spfStat->setlineNumber(loop->loop->lineNumber());
|
|
||||||
spfStat->setFileName(loop->loop->fileName());
|
|
||||||
SgExpression* toAdd = new SgExpression(EXPR_LIST, new SgExpression(ACC_PRIVATE_OP), NULL, NULL);
|
|
||||||
set<SgSymbol*> arraysToInsert;
|
|
||||||
std::cout << "First bp\n";
|
|
||||||
for (const auto& [_, accessingSet] : privates)
|
|
||||||
{
|
|
||||||
if (!CheckDimensionLength(accessingSet))
|
|
||||||
continue;
|
|
||||||
for (const auto& arrayElement : accessingSet.GetElements())
|
|
||||||
{
|
|
||||||
if (arrayElement.empty())
|
|
||||||
continue;
|
|
||||||
arraysToInsert.insert(arrayElement[0].array->symbol());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
spfStat->setExpression(0, *toAdd);
|
|
||||||
toAdd = toAdd->lhs();
|
|
||||||
bool first = true;
|
|
||||||
for (auto& elem : arraysToInsert)
|
|
||||||
{
|
|
||||||
if (first)
|
|
||||||
{
|
|
||||||
toAdd->setLhs(new SgExpression(EXPR_LIST));
|
|
||||||
toAdd = toAdd->lhs();
|
|
||||||
first = false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
toAdd->setRhs(new SgExpression(EXPR_LIST));
|
|
||||||
toAdd = toAdd->rhs();
|
|
||||||
}
|
|
||||||
toAdd->setLhs(new SgVarRefExp(elem));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (arraysToInsert.size() != 0)
|
|
||||||
{
|
|
||||||
loop->loop->insertStmtBefore(*spfStat, *loop->loop->controlParent());
|
|
||||||
insertedPrivates.insert(spfStat);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void findPrivateArrays(map<string, vector<LoopGraph*>>& loopGraph, map<FuncInfo*, vector<SAPFOR::BasicBlock*>>& FullIR, set<SgStatement*>& insertedPrivates)
|
|
||||||
{
|
|
||||||
map<LoopGraph*, ArrayAccessingIndexes> result;
|
|
||||||
for (const auto& [fileName, loops] : loopGraph)
|
|
||||||
{
|
|
||||||
SgFile::switchToFile(fileName);
|
|
||||||
for (const auto& loop : loops)
|
|
||||||
{
|
|
||||||
if (!loop->isFor())
|
|
||||||
continue;
|
|
||||||
SgStatement* search_func = loop->loop->GetOriginal();
|
|
||||||
|
|
||||||
while (search_func && (!isSgProgHedrStmt(search_func)))
|
|
||||||
search_func = search_func->controlParent();
|
|
||||||
|
|
||||||
for (const auto& [funcInfo, blocks] : FullIR)
|
|
||||||
{
|
|
||||||
if (funcInfo->fileName == fileName && funcInfo->funcPointer->GetOriginal() == search_func)
|
|
||||||
{
|
|
||||||
Region* loopRegion;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
loopRegion = new Region(loop, blocks);
|
|
||||||
}
|
|
||||||
catch (...)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (loopRegion->getBasickBlocks().size() <= 1)
|
|
||||||
{
|
|
||||||
delete(loopRegion);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
SolveDataFlow(loopRegion);
|
|
||||||
RemoveEmptyPoints(loopRegion->array_priv);
|
|
||||||
result[loop] = loopRegion->array_priv;
|
|
||||||
delete(loopRegion);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (result.find(loop) != result.end() && !result[loop].empty())
|
|
||||||
AddPrivateArraysToLoop(loop, result[loop], insertedPrivates);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (SgStatement* st : statementsToRemove)
|
|
||||||
{
|
|
||||||
SgFile::switchToFile(st->fileName());
|
|
||||||
st->deleteStmt();
|
|
||||||
}
|
|
||||||
|
|
||||||
for (auto& [filename, statements] : expToChange)
|
|
||||||
{
|
|
||||||
SgFile::switchToFile(filename);
|
|
||||||
for (auto& [statement, statementCopy] : statements)
|
|
||||||
{
|
|
||||||
statement->insertStmtBefore(*statementCopy, *statement->controlParent());
|
|
||||||
statement->deleteStmt();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <vector>
|
|
||||||
#include <map>
|
|
||||||
#include <set>
|
|
||||||
#include <unordered_set>
|
|
||||||
|
|
||||||
#include "range_structures.h"
|
|
||||||
#include "graph_loops.h"
|
|
||||||
#include "CFGraph/CFGraph.h"
|
|
||||||
|
|
||||||
void findPrivateArrays(std::map<std::string, std::vector<LoopGraph*>>& loopGraph, std::map<FuncInfo*, std::vector<SAPFOR::BasicBlock*>>& FullIR, std::set<SgStatement*>& insertedPrivates);
|
|
||||||
@@ -1,296 +0,0 @@
|
|||||||
#include <vector>
|
|
||||||
#include <map>
|
|
||||||
#include <unordered_set>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
#include "utils.h"
|
|
||||||
#include "range_structures.h"
|
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
static vector<uint64_t> FindParticularSolution(const ArrayDimension& dim1, const ArrayDimension& dim2)
|
|
||||||
{
|
|
||||||
for (uint64_t i = 0; i < dim1.tripCount; i++)
|
|
||||||
{
|
|
||||||
uint64_t leftPart = dim1.start + i * dim1.step;
|
|
||||||
for (uint64_t j = 0; j < dim2.tripCount; j++)
|
|
||||||
{
|
|
||||||
uint64_t rightPart = dim2.start + j * dim2.step;
|
|
||||||
if (leftPart == rightPart)
|
|
||||||
return { i, j };
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
/* dim1 /\ dim2 */
|
|
||||||
static ArrayDimension* DimensionIntersection(const ArrayDimension& dim1, const ArrayDimension& dim2)
|
|
||||||
{
|
|
||||||
vector<uint64_t> partSolution = FindParticularSolution(dim1, dim2);
|
|
||||||
if (partSolution.empty())
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
int64_t x0 = partSolution[0], y0 = partSolution[1];
|
|
||||||
/* x = x_0 + c * t */
|
|
||||||
/* y = y_0 + d * t */
|
|
||||||
int64_t c = dim2.step / gcd(dim1.step, dim2.step);
|
|
||||||
int64_t d = dim1.step / gcd(dim1.step, dim2.step);
|
|
||||||
int64_t tXMin, tXMax, tYMin, tYMax;
|
|
||||||
tXMin = -x0 / c;
|
|
||||||
tXMax = (dim1.tripCount - 1 - x0) / c;
|
|
||||||
tYMin = -y0 / d;
|
|
||||||
tYMax = (dim2.tripCount - 1 - y0) / d;
|
|
||||||
int64_t tMin = max(tXMin, tYMin);
|
|
||||||
uint64_t tMax = min(tXMax, tYMax);
|
|
||||||
if (tMin > tMax)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
uint64_t start3 = dim1.start + x0 * dim1.step;
|
|
||||||
uint64_t step3 = c * dim1.step;
|
|
||||||
ArrayDimension* result = new(ArrayDimension){ start3, step3, tMax + 1 , dim1.array };
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* dim1 / dim2 */
|
|
||||||
static vector<ArrayDimension> DimensionDifference(const ArrayDimension& dim1, const ArrayDimension& dim2)
|
|
||||||
{
|
|
||||||
ArrayDimension* intersection = DimensionIntersection(dim1, dim2);
|
|
||||||
if (!intersection)
|
|
||||||
return { dim1 };
|
|
||||||
|
|
||||||
vector<ArrayDimension> result;
|
|
||||||
/* add the part before intersection */
|
|
||||||
if (dim1.start < intersection->start)
|
|
||||||
result.push_back({ dim1.start, dim1.step, (intersection->start - dim1.start) / dim1.step, dim1.array });
|
|
||||||
|
|
||||||
/* add the parts between intersection steps */
|
|
||||||
if (intersection->step > dim1.step)
|
|
||||||
{
|
|
||||||
uint64_t start = (intersection->start - dim1.start) / dim1.step;
|
|
||||||
uint64_t interValue = intersection->start;
|
|
||||||
for (int64_t i = start; interValue <= intersection->start + intersection->step * (intersection->tripCount - 1); i++)
|
|
||||||
{
|
|
||||||
result.push_back({ interValue + dim1.step, dim1.step, intersection->step / dim1.step, dim1.array });
|
|
||||||
interValue += intersection->step;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/* add the part after intersection */
|
|
||||||
if (intersection->start + intersection->step * (intersection->tripCount - 1) < dim1.start + dim1.step * (dim1.tripCount - 1))
|
|
||||||
{
|
|
||||||
/* first value after intersection */
|
|
||||||
uint64_t right_start = intersection->start + intersection->step * (intersection->tripCount - 1) + dim1.step;
|
|
||||||
uint64_t tripCount = (dim1.start + dim1.step * dim1.tripCount - right_start) / dim1.step;
|
|
||||||
result.push_back({ right_start, dim1.step, tripCount, dim1.array });
|
|
||||||
}
|
|
||||||
delete(intersection);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static vector<ArrayDimension> DimensionUnion(const ArrayDimension& dim1, const ArrayDimension& dim2)
|
|
||||||
{
|
|
||||||
vector<ArrayDimension> res;
|
|
||||||
ArrayDimension* inter = DimensionIntersection(dim1, dim2);
|
|
||||||
if (!inter)
|
|
||||||
return { dim1, dim2 };
|
|
||||||
|
|
||||||
res.push_back(*inter);
|
|
||||||
delete(inter);
|
|
||||||
|
|
||||||
vector<ArrayDimension> diff1, diff2;
|
|
||||||
diff1 = DimensionDifference(dim1, dim2);
|
|
||||||
diff2 = DimensionDifference(dim2, dim1);
|
|
||||||
res.insert(res.end(), diff1.begin(), diff1.end());
|
|
||||||
res.insert(res.end(), diff2.begin(), diff2.end());
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
static vector<ArrayDimension> ElementsIntersection(const vector<ArrayDimension>& firstElement, const vector<ArrayDimension>& secondElement)
|
|
||||||
{
|
|
||||||
if (firstElement.empty() || secondElement.empty())
|
|
||||||
return {};
|
|
||||||
|
|
||||||
size_t dimAmount = firstElement.size();
|
|
||||||
/* check if there is no intersecction */
|
|
||||||
for (size_t i = 0; i < dimAmount; i++)
|
|
||||||
if (FindParticularSolution(firstElement[i], secondElement[i]).empty())
|
|
||||||
return {};
|
|
||||||
|
|
||||||
vector<ArrayDimension> result(dimAmount);
|
|
||||||
for (size_t i = 0; i < dimAmount; i++)
|
|
||||||
{
|
|
||||||
ArrayDimension* resPtr = DimensionIntersection(firstElement[i], secondElement[i]);
|
|
||||||
if (resPtr)
|
|
||||||
result[i] = *resPtr;
|
|
||||||
else
|
|
||||||
return {};
|
|
||||||
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
static vector<vector<ArrayDimension>> ElementsDifference(const vector<ArrayDimension>& firstElement,
|
|
||||||
const vector<ArrayDimension>& secondElement)
|
|
||||||
{
|
|
||||||
if (firstElement.empty())
|
|
||||||
return {};
|
|
||||||
if (secondElement.empty())
|
|
||||||
return { firstElement };
|
|
||||||
|
|
||||||
vector<ArrayDimension> intersection = ElementsIntersection(firstElement, secondElement);
|
|
||||||
vector<vector<ArrayDimension>> result;
|
|
||||||
if (intersection.empty())
|
|
||||||
return { firstElement };
|
|
||||||
|
|
||||||
for (int i = 0; i < firstElement.size(); i++)
|
|
||||||
{
|
|
||||||
auto dimDiff = DimensionDifference(firstElement[i], secondElement[i]);
|
|
||||||
if (!dimDiff.empty())
|
|
||||||
{
|
|
||||||
vector<ArrayDimension> firstCopy = firstElement;
|
|
||||||
for (const auto& range : dimDiff)
|
|
||||||
{
|
|
||||||
firstCopy[i] = range;
|
|
||||||
result.push_back(firstCopy);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void ElementsUnion(const vector<ArrayDimension>& firstElement, const vector<ArrayDimension>& secondElement,
|
|
||||||
vector<vector<ArrayDimension>>& lc, vector<vector<ArrayDimension>>& rc,
|
|
||||||
vector<ArrayDimension>& intersection)
|
|
||||||
{
|
|
||||||
/* lc(rc) is a set of ranges, which only exist in first(second) element*/
|
|
||||||
intersection = ElementsIntersection(firstElement, secondElement);
|
|
||||||
lc = ElementsDifference(firstElement, intersection);
|
|
||||||
rc = ElementsDifference(secondElement, intersection);
|
|
||||||
}
|
|
||||||
|
|
||||||
void AccessingSet::FindUncovered(const vector<ArrayDimension>& element, vector<vector<ArrayDimension>>& result) const {
|
|
||||||
vector<vector<ArrayDimension>> newTails;
|
|
||||||
result.push_back(element);
|
|
||||||
for (const auto& currentElement : allElements)
|
|
||||||
{
|
|
||||||
for (const auto& tailLoc : result)
|
|
||||||
{
|
|
||||||
auto intersection = ElementsIntersection(tailLoc, currentElement);
|
|
||||||
auto diff = ElementsDifference(tailLoc, intersection);
|
|
||||||
if (!diff.empty()) {
|
|
||||||
newTails.insert(newTails.end(), diff.begin(), diff.end());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
result = newTails;
|
|
||||||
newTails.clear();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool AccessingSet::ContainsElement(const vector<ArrayDimension>& element) const
|
|
||||||
{
|
|
||||||
vector<vector<ArrayDimension>> tails;
|
|
||||||
FindUncovered(element, tails);
|
|
||||||
return tails.empty();
|
|
||||||
}
|
|
||||||
|
|
||||||
void AccessingSet::FindCoveredBy(const vector<ArrayDimension>& element, vector<vector<ArrayDimension>>& result) const
|
|
||||||
{
|
|
||||||
for (const auto& currentElement : allElements)
|
|
||||||
{
|
|
||||||
auto intersection = ElementsIntersection(element, currentElement);
|
|
||||||
if (!intersection.empty())
|
|
||||||
result.push_back(intersection);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
vector<vector<ArrayDimension>> AccessingSet::GetElements() const { return allElements; }
|
|
||||||
|
|
||||||
void AccessingSet::Insert(const vector<ArrayDimension>& element)
|
|
||||||
{
|
|
||||||
vector<vector<ArrayDimension>> tails;
|
|
||||||
FindUncovered(element, tails);
|
|
||||||
allElements.insert(allElements.end(), tails.begin(), tails.end());
|
|
||||||
}
|
|
||||||
|
|
||||||
AccessingSet AccessingSet::Union(const AccessingSet& source) {
|
|
||||||
if (source.GetElements().empty())
|
|
||||||
return *this;
|
|
||||||
if (allElements.empty())
|
|
||||||
return source;
|
|
||||||
AccessingSet result;
|
|
||||||
for (auto& element : source.GetElements())
|
|
||||||
result.Insert(element);
|
|
||||||
|
|
||||||
for (auto& element : allElements)
|
|
||||||
result.Insert(element);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
AccessingSet AccessingSet::Intersect(const AccessingSet& secondSet) const
|
|
||||||
{
|
|
||||||
vector<vector<ArrayDimension>> result;
|
|
||||||
if (secondSet.GetElements().empty() || this->allElements.empty())
|
|
||||||
return AccessingSet(result);
|
|
||||||
|
|
||||||
for (const auto& element : allElements)
|
|
||||||
{
|
|
||||||
if (secondSet.ContainsElement(element))
|
|
||||||
result.push_back(element);
|
|
||||||
else
|
|
||||||
{
|
|
||||||
vector<vector<ArrayDimension>> coveredBy;
|
|
||||||
secondSet.FindCoveredBy(element, coveredBy);
|
|
||||||
if (!coveredBy.empty())
|
|
||||||
result.insert(result.end(), coveredBy.begin(), coveredBy.end());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return AccessingSet(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
AccessingSet AccessingSet::Diff(const AccessingSet& secondSet) const
|
|
||||||
{
|
|
||||||
if (secondSet.GetElements().empty() || allElements.empty())
|
|
||||||
return *this;
|
|
||||||
|
|
||||||
AccessingSet intersection = this->Intersect(secondSet);
|
|
||||||
vector<vector<ArrayDimension>> uncovered;
|
|
||||||
for (const auto& element : allElements)
|
|
||||||
{
|
|
||||||
vector<vector<ArrayDimension>> current_uncovered;
|
|
||||||
intersection.FindUncovered(element, current_uncovered);
|
|
||||||
uncovered.insert(uncovered.end(),
|
|
||||||
std::move_iterator(current_uncovered.begin()),
|
|
||||||
std::move_iterator(current_uncovered.end())
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return uncovered;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool operator!=(const ArrayDimension& lhs, const ArrayDimension& rhs)
|
|
||||||
{
|
|
||||||
return !(lhs.start == rhs.start && lhs.step == rhs.step && lhs.tripCount == rhs.tripCount);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool operator!=(const AccessingSet& lhs, const AccessingSet& rhs)
|
|
||||||
{
|
|
||||||
for (size_t i = 0; i < lhs.allElements.size(); i++)
|
|
||||||
for (size_t j = 0; j < lhs.allElements[i].size(); j++)
|
|
||||||
if (lhs.allElements[i][j] != rhs.allElements[i][j])
|
|
||||||
return true;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool operator!=(const ArrayAccessingIndexes& lhs, const ArrayAccessingIndexes& rhs)
|
|
||||||
{
|
|
||||||
if (lhs.size() != rhs.size())
|
|
||||||
return true;
|
|
||||||
|
|
||||||
for (auto& [key, value] : lhs)
|
|
||||||
if (rhs.find(key) == rhs.end())
|
|
||||||
return true;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
@@ -1,40 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <vector>
|
|
||||||
#include <map>
|
|
||||||
#include <unordered_set>
|
|
||||||
#include <string>
|
|
||||||
#include <cstdint>
|
|
||||||
|
|
||||||
#include "SgUtils.h"
|
|
||||||
|
|
||||||
struct ArrayDimension
|
|
||||||
{
|
|
||||||
uint64_t start, step, tripCount;
|
|
||||||
SgArrayRefExp* array;
|
|
||||||
};
|
|
||||||
|
|
||||||
class AccessingSet {
|
|
||||||
private:
|
|
||||||
std::vector<std::vector<ArrayDimension>> allElements;
|
|
||||||
|
|
||||||
public:
|
|
||||||
AccessingSet(std::vector<std::vector<ArrayDimension>> input) : allElements(input) {};
|
|
||||||
AccessingSet() {};
|
|
||||||
AccessingSet(const AccessingSet& a) { allElements = a.GetElements(); };
|
|
||||||
std::vector<std::vector<ArrayDimension>> GetElements() const;
|
|
||||||
void Insert(const std::vector<ArrayDimension>& element);
|
|
||||||
AccessingSet Union(const AccessingSet& source);
|
|
||||||
AccessingSet Intersect(const AccessingSet& secondSet) const;
|
|
||||||
AccessingSet Diff(const AccessingSet& secondSet) const;
|
|
||||||
bool ContainsElement(const std::vector<ArrayDimension>& element) const;
|
|
||||||
void FindCoveredBy(const std::vector<ArrayDimension>& element, std::vector<std::vector<ArrayDimension>>& result) const;
|
|
||||||
void FindUncovered(const std::vector<ArrayDimension>& element, std::vector<std::vector<ArrayDimension>>& result) const;
|
|
||||||
friend bool operator!=(const AccessingSet& lhs, const AccessingSet& rhs);
|
|
||||||
};
|
|
||||||
|
|
||||||
using ArrayAccessingIndexes = std::map<std::string, AccessingSet>;
|
|
||||||
|
|
||||||
bool operator!=(const ArrayDimension& lhs, const ArrayDimension& rhs);
|
|
||||||
bool operator!=(const AccessingSet& lhs, const AccessingSet& rhs);
|
|
||||||
bool operator!=(const ArrayAccessingIndexes& lhs, const ArrayAccessingIndexes& rhs);
|
|
||||||
@@ -1,363 +0,0 @@
|
|||||||
#include <algorithm>
|
|
||||||
#include <vector>
|
|
||||||
#include <map>
|
|
||||||
#include <unordered_set>
|
|
||||||
#include <unordered_map>
|
|
||||||
#include <string>
|
|
||||||
#include <numeric>
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
#include "range_structures.h"
|
|
||||||
#include "region.h"
|
|
||||||
#include "SgUtils.h"
|
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
static bool isParentStmt(SgStatement* stmt, SgStatement* parent)
|
|
||||||
{
|
|
||||||
for (; stmt; stmt = stmt->controlParent())
|
|
||||||
if (stmt == parent)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*returns head block and loop*/
|
|
||||||
static pair<SAPFOR::BasicBlock*, unordered_set<SAPFOR::BasicBlock*>> GetBasicBlocksForLoop(const LoopGraph* loop, const vector<SAPFOR::BasicBlock*> blocks)
|
|
||||||
{
|
|
||||||
unordered_set<SAPFOR::BasicBlock*> block_loop;
|
|
||||||
SAPFOR::BasicBlock* head_block = nullptr;
|
|
||||||
auto loop_operator = loop->loop->GetOriginal();
|
|
||||||
for (const auto& block : blocks)
|
|
||||||
{
|
|
||||||
if (!block || (block->getInstructions().size() == 0))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
SgStatement* first = block->getInstructions().front()->getInstruction()->getOperator();
|
|
||||||
SgStatement* last = block->getInstructions().back()->getInstruction()->getOperator();
|
|
||||||
if (isParentStmt(first, loop_operator) && isParentStmt(last, loop_operator))
|
|
||||||
{
|
|
||||||
block_loop.insert(block);
|
|
||||||
|
|
||||||
if ((!head_block) && (first == loop_operator) && (last == loop_operator) &&
|
|
||||||
(block->getInstructions().size() == 2) &&
|
|
||||||
(block->getInstructions().back()->getInstruction()->getOperation() == SAPFOR::CFG_OP::JUMP_IF))
|
|
||||||
{
|
|
||||||
head_block = block;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return { head_block, block_loop };
|
|
||||||
}
|
|
||||||
|
|
||||||
static void BuildLoopIndex(map<string, LoopGraph*>& loopForIndex, LoopGraph* loop) {
|
|
||||||
string index = loop->loopSymbol();
|
|
||||||
loopForIndex[index] = loop;
|
|
||||||
|
|
||||||
for (const auto& childLoop : loop->children)
|
|
||||||
BuildLoopIndex(loopForIndex, childLoop);
|
|
||||||
}
|
|
||||||
|
|
||||||
static string FindIndexName(int pos, SAPFOR::BasicBlock* block, map<string, LoopGraph*>& loopForIndex) {
|
|
||||||
unordered_set<SAPFOR::Argument*> args = { block->getInstructions()[pos]->getInstruction()->getArg1() };
|
|
||||||
|
|
||||||
for (int i = pos - 1; i >= 0; i--)
|
|
||||||
{
|
|
||||||
SAPFOR::Argument* res = block->getInstructions()[i]->getInstruction()->getResult();
|
|
||||||
if (res && args.find(res) != args.end())
|
|
||||||
{
|
|
||||||
SAPFOR::Argument* arg1 = block->getInstructions()[i]->getInstruction()->getArg1();
|
|
||||||
SAPFOR::Argument* arg2 = block->getInstructions()[i]->getInstruction()->getArg2();
|
|
||||||
if (arg1)
|
|
||||||
{
|
|
||||||
string name = arg1->getValue();
|
|
||||||
int idx = name.find('%');
|
|
||||||
if (idx != -1 && loopForIndex.find(name.substr(idx + 1)) != loopForIndex.end())
|
|
||||||
return name.substr(idx + 1);
|
|
||||||
else
|
|
||||||
args.insert(arg1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (arg2)
|
|
||||||
{
|
|
||||||
string name = arg2->getValue();
|
|
||||||
int idx = name.find('%');
|
|
||||||
if (idx != -1 && loopForIndex.find(name.substr(idx + 1)) != loopForIndex.end())
|
|
||||||
return name.substr(idx + 1);
|
|
||||||
else
|
|
||||||
args.insert(arg2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
static int GetDefUseArray(SAPFOR::BasicBlock* block, LoopGraph* loop, ArrayAccessingIndexes& def, ArrayAccessingIndexes& use, Region* region) {
|
|
||||||
auto instructions = block->getInstructions();
|
|
||||||
map<string, LoopGraph*> loopForIndex;
|
|
||||||
BuildLoopIndex(loopForIndex, loop);
|
|
||||||
for (int i = 0; i < instructions.size(); i++)
|
|
||||||
{
|
|
||||||
auto instruction = instructions[i];
|
|
||||||
if (!instruction->getInstruction()->getArg1())
|
|
||||||
continue;
|
|
||||||
|
|
||||||
auto operation = instruction->getInstruction()->getOperation();
|
|
||||||
auto type = instruction->getInstruction()->getArg1()->getType();
|
|
||||||
if (operation == SAPFOR::CFG_OP::ASSIGN && instruction->getInstruction()->getResult()->getType() == SAPFOR::CFG_ARG_TYPE::ARRAY)
|
|
||||||
{
|
|
||||||
SgStatement* op = instruction->getInstruction()->getOperator();
|
|
||||||
if (op && op->expr(0) && isArrayRef(op->expr(0)) && op->expr(0)->symbol() && op->expr(0)->type())
|
|
||||||
{
|
|
||||||
if (isSgArrayType(op->expr(0)->symbol()->type()))
|
|
||||||
{
|
|
||||||
SgArrayType* arrayType = (SgArrayType*)op->expr(0)->symbol()->type();
|
|
||||||
int dimCount = ((SgArrayType*)op->expr(0)->symbol()->type())->dimension();
|
|
||||||
vector<ArrayDimension> point;
|
|
||||||
for (int i = 0; i < dimCount; i++)
|
|
||||||
{
|
|
||||||
string strDimLength = arrayType->sizeInDim(i)->unparse();
|
|
||||||
if (arrayType->sizeInDim(i)->variant() == INT_VAL && strDimLength != "0")
|
|
||||||
point.push_back({ 1ULL, 1ULL, (uint64_t)stoi(strDimLength), (SgArrayRefExp*)op->expr(0) });
|
|
||||||
}
|
|
||||||
|
|
||||||
if (point.size() == dimCount)
|
|
||||||
{
|
|
||||||
def[instruction->getInstruction()->getResult()->getValue()] = AccessingSet({ point });
|
|
||||||
RegionInstruction regionInstruction;
|
|
||||||
regionInstruction.def[instruction->getInstruction()->getResult()->getValue()] = AccessingSet({ point });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ((operation == SAPFOR::CFG_OP::STORE || operation == SAPFOR::CFG_OP::LOAD) && type == SAPFOR::CFG_ARG_TYPE::ARRAY)
|
|
||||||
{
|
|
||||||
vector<SAPFOR::Argument*> index_vars;
|
|
||||||
vector<int> refPos;
|
|
||||||
string array_name = instruction->getInstruction()->getArg1()->getValue();
|
|
||||||
|
|
||||||
int j = i - 1;
|
|
||||||
while (j >= 0 && instructions[j]->getInstruction()->getOperation() == SAPFOR::CFG_OP::REF)
|
|
||||||
{
|
|
||||||
index_vars.push_back(instructions[j]->getInstruction()->getArg1());
|
|
||||||
refPos.push_back(j);
|
|
||||||
j--;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*to choose correct dimension*/
|
|
||||||
int n = index_vars.size();
|
|
||||||
vector<ArrayDimension> accessPoint(n);
|
|
||||||
|
|
||||||
auto* ref = isSgArrayRefExp(instruction->getInstruction()->getExpression());
|
|
||||||
if (!ref)
|
|
||||||
continue;
|
|
||||||
int fillCount = 0;
|
|
||||||
|
|
||||||
vector<pair<int, int>> coeffsForDims;
|
|
||||||
int subs = ref->numberOfSubscripts();
|
|
||||||
for (int i = 0; ref && i < ref->numberOfSubscripts(); ++i)
|
|
||||||
{
|
|
||||||
const vector<int*>& coeffs = getAttributes<SgExpression*, int*>(ref->subscript(i), set<int>{ INT_VAL });
|
|
||||||
if (coeffs.size() == 1)
|
|
||||||
{
|
|
||||||
const pair<int, int> coef(coeffs[0][0], coeffs[0][1]);
|
|
||||||
coeffsForDims.push_back(coef);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
coeffsForDims = { coeffsForDims.rbegin(), coeffsForDims.rend() };
|
|
||||||
|
|
||||||
while (!index_vars.empty() && !refPos.empty() && !coeffsForDims.empty())
|
|
||||||
{
|
|
||||||
auto var = index_vars.back();
|
|
||||||
int currentVarPos = refPos.back();
|
|
||||||
ArrayDimension current_dim;
|
|
||||||
if (var->getType() == SAPFOR::CFG_ARG_TYPE::CONST)
|
|
||||||
current_dim = { stoul(var->getValue()), 1, 1, ref };
|
|
||||||
else
|
|
||||||
{
|
|
||||||
string name, full_name = var->getValue();
|
|
||||||
int pos = full_name.find('%');
|
|
||||||
LoopGraph* currentLoop;
|
|
||||||
if (pos != -1)
|
|
||||||
{
|
|
||||||
name = full_name.substr(pos + 1);
|
|
||||||
if (loopForIndex.find(name) != loopForIndex.end())
|
|
||||||
currentLoop = loopForIndex[name];
|
|
||||||
else
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
name = FindIndexName(currentVarPos, block, loopForIndex);
|
|
||||||
if (name == "")
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
if (loopForIndex.find(name) != loopForIndex.end())
|
|
||||||
currentLoop = loopForIndex[name];
|
|
||||||
else
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint64_t start = coeffsForDims.back().second * currentLoop->startVal + coeffsForDims.back().first;
|
|
||||||
uint64_t step = currentLoop->stepVal;
|
|
||||||
uint64_t iters = currentLoop->calculatedCountOfIters;
|
|
||||||
current_dim = { start, step, iters, ref };
|
|
||||||
}
|
|
||||||
|
|
||||||
if (current_dim.step != 0 && current_dim.tripCount != 0)
|
|
||||||
{
|
|
||||||
accessPoint[n - index_vars.size()] = current_dim;
|
|
||||||
fillCount++;
|
|
||||||
}
|
|
||||||
index_vars.pop_back();
|
|
||||||
refPos.pop_back();
|
|
||||||
coeffsForDims.pop_back();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fillCount == accessPoint.size())
|
|
||||||
{
|
|
||||||
RegionInstruction instruction;
|
|
||||||
if (operation == SAPFOR::CFG_OP::STORE)
|
|
||||||
{
|
|
||||||
def[array_name].Insert(accessPoint);
|
|
||||||
instruction.def[array_name] = { { accessPoint } };
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
instruction.use[array_name] = { { accessPoint } };
|
|
||||||
if (def.find(array_name) == def.end())
|
|
||||||
use[array_name].Insert(accessPoint);
|
|
||||||
else
|
|
||||||
{
|
|
||||||
AccessingSet element({ accessPoint });
|
|
||||||
use[array_name] = use[array_name].Union(element.Diff(def[array_name]));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
region->instructions.push_back(instruction);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
static void RemoveHeaderConnection(SAPFOR::BasicBlock* header, const unordered_set<SAPFOR::BasicBlock*>& blockSet, unordered_map<SAPFOR::BasicBlock*, Region*>& bbToRegion)
|
|
||||||
{
|
|
||||||
for (SAPFOR::BasicBlock* block : blockSet)
|
|
||||||
{
|
|
||||||
bool isCycleBlock = false;
|
|
||||||
for (SAPFOR::BasicBlock* prevBlock : block->getPrev())
|
|
||||||
isCycleBlock = isCycleBlock || (blockSet.find(prevBlock) != blockSet.end());
|
|
||||||
|
|
||||||
if (isCycleBlock)
|
|
||||||
{
|
|
||||||
bbToRegion[block]->removeNextRegion(bbToRegion[header]);
|
|
||||||
bbToRegion[header]->removePrevRegion(bbToRegion[block]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void DFS(Region* block, vector<Region*>& result, unordered_set<Region*> cycleBlocks)
|
|
||||||
{
|
|
||||||
for (Region* nextBlock : block->getNextRegions())
|
|
||||||
{
|
|
||||||
if (cycleBlocks.find(nextBlock) != cycleBlocks.end())
|
|
||||||
DFS(nextBlock, result, cycleBlocks);
|
|
||||||
}
|
|
||||||
result.push_back(block);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool HasCycle(Region* block, const std::unordered_set<Region*>& cycleBlocks, std::unordered_set<Region*>& visitedBlocks)
|
|
||||||
{
|
|
||||||
if (visitedBlocks.find(block) != visitedBlocks.end())
|
|
||||||
return true;
|
|
||||||
visitedBlocks.insert(block);
|
|
||||||
for (Region* nextBlock : block->getNextRegions())
|
|
||||||
{
|
|
||||||
if (cycleBlocks.find(nextBlock) != cycleBlocks.end() && HasCycle(nextBlock, cycleBlocks, visitedBlocks))
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool TopologySort(std::vector<Region*>& basikBlocks, Region* header)
|
|
||||||
{
|
|
||||||
unordered_set<Region*> cycleBlocks(basikBlocks.begin(), basikBlocks.end());
|
|
||||||
unordered_set<Region*> visitedBlocks;
|
|
||||||
if (HasCycle(header, cycleBlocks, visitedBlocks))
|
|
||||||
return false;
|
|
||||||
vector<Region*> result;
|
|
||||||
DFS(header, result, cycleBlocks);
|
|
||||||
reverse(result.begin(), result.end());
|
|
||||||
basikBlocks = move(result);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void SetConnections(unordered_map<SAPFOR::BasicBlock*, Region*>& bbToRegion, const unordered_set<SAPFOR::BasicBlock*>& blockSet)
|
|
||||||
{
|
|
||||||
for (SAPFOR::BasicBlock* block : blockSet)
|
|
||||||
{
|
|
||||||
for (SAPFOR::BasicBlock* nextBlock : block->getNext())
|
|
||||||
if (bbToRegion.find(nextBlock) != bbToRegion.end())
|
|
||||||
bbToRegion[block]->addNextRegion(bbToRegion[nextBlock]);
|
|
||||||
|
|
||||||
for (SAPFOR::BasicBlock* prevBlock : block->getPrev())
|
|
||||||
if (bbToRegion.find(prevBlock) != bbToRegion.end())
|
|
||||||
bbToRegion[block]->addPrevRegion(bbToRegion[prevBlock]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static Region* CreateSubRegion(LoopGraph* loop, const vector<SAPFOR::BasicBlock*>& Blocks, unordered_map<SAPFOR::BasicBlock*, Region*>& bbToRegion)
|
|
||||||
{
|
|
||||||
Region* region = new Region;
|
|
||||||
auto [header, blockSet] = GetBasicBlocksForLoop(loop, Blocks);
|
|
||||||
RemoveHeaderConnection(header, blockSet, bbToRegion);
|
|
||||||
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())
|
|
||||||
region->addBasickBlocks(bbToRegion.at(block));
|
|
||||||
|
|
||||||
for (LoopGraph* childLoop : loop->children)
|
|
||||||
{
|
|
||||||
if (!childLoop->isFor())
|
|
||||||
continue;
|
|
||||||
region->addSubRegions(CreateSubRegion(childLoop, Blocks, bbToRegion));
|
|
||||||
}
|
|
||||||
if (!TopologySort(region->getBasickBlocks(), region->getHeader()))
|
|
||||||
throw std::runtime_error("Unnoticed cycle");
|
|
||||||
return region;
|
|
||||||
}
|
|
||||||
|
|
||||||
Region::Region(LoopGraph* loop, const vector<SAPFOR::BasicBlock*>& Blocks)
|
|
||||||
{
|
|
||||||
auto [header, blockSet] = GetBasicBlocksForLoop(loop, Blocks);
|
|
||||||
unordered_map<SAPFOR::BasicBlock*, Region*> bbToRegion;
|
|
||||||
for (auto poiner : blockSet)
|
|
||||||
{
|
|
||||||
bbToRegion[poiner] = new Region(*poiner);
|
|
||||||
this->basickBlocks.push_back(bbToRegion[poiner]);
|
|
||||||
GetDefUseArray(poiner, loop, bbToRegion[poiner]->array_def, bbToRegion[poiner]->array_use, bbToRegion[poiner]);
|
|
||||||
|
|
||||||
}
|
|
||||||
this->header = bbToRegion[header];
|
|
||||||
SetConnections(bbToRegion, blockSet);
|
|
||||||
RemoveHeaderConnection(header, blockSet, bbToRegion);
|
|
||||||
//create subRegions
|
|
||||||
for (LoopGraph* childLoop : loop->children)
|
|
||||||
{
|
|
||||||
if (!childLoop->isFor())
|
|
||||||
continue;
|
|
||||||
subRegions.insert(CreateSubRegion(childLoop, Blocks, bbToRegion));
|
|
||||||
}
|
|
||||||
if (!TopologySort(basickBlocks, this->header))
|
|
||||||
throw std::runtime_error("Unnoticed cycle");
|
|
||||||
}
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user