Compare commits
16 Commits
analyze_lo
...
b298cc03bf
| Author | SHA1 | Date | |
|---|---|---|---|
| b298cc03bf | |||
|
|
8c6a55463c | ||
|
|
32a4a7fd0a | ||
|
|
507305ac3a | ||
|
|
a3939ed274 | ||
|
|
95ef954b6e | ||
|
|
243b1f5bdb | ||
|
|
5fb2bd79df | ||
|
|
d33659290e | ||
|
|
b8a6c92ca8 | ||
|
|
1028e20177 | ||
|
|
85e2a60183 | ||
|
|
68bd21b7b0 | ||
|
|
177433a95b | ||
|
|
29ece9072e | ||
|
|
feafa43f32 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -78,3 +78,4 @@ Sapfor/Sapc++/x64/
|
|||||||
|
|
||||||
Sapfor/out/
|
Sapfor/out/
|
||||||
Sapfor/_bin/*
|
Sapfor/_bin/*
|
||||||
|
_bin/*
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ include_directories(src/Distribution)
|
|||||||
include_directories(src/GraphCall)
|
include_directories(src/GraphCall)
|
||||||
include_directories(src/GraphLoop)
|
include_directories(src/GraphLoop)
|
||||||
include_directories(src/Transformations/ExpressionSubstitution)
|
include_directories(src/Transformations/ExpressionSubstitution)
|
||||||
|
include_directories(src/Transformations)
|
||||||
|
|
||||||
#Sage lib includes
|
#Sage lib includes
|
||||||
include_directories(${fdvm_include})
|
include_directories(${fdvm_include})
|
||||||
@@ -202,6 +203,8 @@ set(TR_INLINER src/Transformations/FunctionInlining/inliner.cpp
|
|||||||
src/Transformations/FunctionInlining/inliner.h)
|
src/Transformations/FunctionInlining/inliner.h)
|
||||||
set(TR_RENAME_SYMBOLS src/Transformations/RenameSymbols/rename_symbols.cpp
|
set(TR_RENAME_SYMBOLS src/Transformations/RenameSymbols/rename_symbols.cpp
|
||||||
src/Transformations/RenameSymbols/rename_symbols.h)
|
src/Transformations/RenameSymbols/rename_symbols.h)
|
||||||
|
SET(TR_SWAP_OPERATORS src/Transformations/SwapOperators/swap_operators.cpp
|
||||||
|
src/Transformations/SwapOperators/swap_operators.h)
|
||||||
|
|
||||||
set(TRANSFORMS
|
set(TRANSFORMS
|
||||||
${TR_DEAD_CODE}
|
${TR_DEAD_CODE}
|
||||||
@@ -224,7 +227,8 @@ set(TRANSFORMS
|
|||||||
${TR_REPLACE_ARRAYS_IN_IO}
|
${TR_REPLACE_ARRAYS_IN_IO}
|
||||||
${TR_EXPR_TRANSFORM}
|
${TR_EXPR_TRANSFORM}
|
||||||
${TR_INLINER}
|
${TR_INLINER}
|
||||||
${TR_RENAME_SYMBOLS})
|
${TR_RENAME_SYMBOLS}
|
||||||
|
${TR_SWAP_OPERATORS})
|
||||||
|
|
||||||
set(CFG src/CFGraph/IR.cpp
|
set(CFG src/CFGraph/IR.cpp
|
||||||
src/CFGraph/IR.h
|
src/CFGraph/IR.h
|
||||||
@@ -457,6 +461,7 @@ 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\\SwapOperators FILES ${TR_SWAP_OPERATORS})
|
||||||
|
|
||||||
|
|
||||||
source_group (CreateIntervals FILES ${CREATE_INTER_T})
|
source_group (CreateIntervals FILES ${CREATE_INTER_T})
|
||||||
|
|||||||
@@ -22,7 +22,7 @@
|
|||||||
#include "SgUtils.h"
|
#include "SgUtils.h"
|
||||||
#include "../Sapfor.h"
|
#include "../Sapfor.h"
|
||||||
#include "graph_loops_func.h"
|
#include "graph_loops_func.h"
|
||||||
#include "../Transformations/LoopNesting/loop_transform.h"
|
#include "LoopNesting/loop_transform.h"
|
||||||
#include "expr_transform.h"
|
#include "expr_transform.h"
|
||||||
#include "graph_calls_func.h"
|
#include "graph_calls_func.h"
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
#include "../ParallelizationRegions/ParRegions.h"
|
#include "../ParallelizationRegions/ParRegions.h"
|
||||||
#include "../Distribution/Arrays.h"
|
#include "../Distribution/Arrays.h"
|
||||||
#include "../Transformations/LoopNesting/loop_transform.h"
|
#include "LoopNesting/loop_transform.h"
|
||||||
|
|
||||||
#include "errors.h"
|
#include "errors.h"
|
||||||
#include "directive_parser.h"
|
#include "directive_parser.h"
|
||||||
|
|||||||
@@ -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/FunctionPurifying/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,154 +794,6 @@ 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();
|
||||||
@@ -1172,7 +1024,7 @@ static bool isPure(SgStatement* func)
|
|||||||
|
|
||||||
void DvmhRegionInserter::createInterfaceBlockForOutCall(FuncInfo* func, FuncInfo* callFrom)
|
void DvmhRegionInserter::createInterfaceBlockForOutCall(FuncInfo* func, FuncInfo* callFrom)
|
||||||
{
|
{
|
||||||
insertInterface(func->funcPointer, getInterfaceBlock(callFrom->funcPointer->GetOriginal(), callFrom->funcParams), callFrom->funcName);
|
insertInterface(func->funcPointer, callFrom);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DvmhRegionInserter::createInterfaceBlockForParallelFunctions(bool onlyRoutine)
|
void DvmhRegionInserter::createInterfaceBlockForParallelFunctions(bool onlyRoutine)
|
||||||
@@ -1457,7 +1309,7 @@ static set<DIST::Array*>
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
declStat = getFuncStat(declStat);
|
declStat = getFuncStat(declStat, { BLOCK_DATA });
|
||||||
if (declStat != main)
|
if (declStat != main)
|
||||||
{
|
{
|
||||||
declStat = NULL;
|
declStat = NULL;
|
||||||
|
|||||||
@@ -779,6 +779,20 @@ 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)
|
||||||
@@ -799,7 +813,12 @@ static void fillInOut(FuncInfo *currF, SgStatement *start, SgStatement *last, co
|
|||||||
if (st->variant() == ENTRY_STAT)
|
if (st->variant() == ENTRY_STAT)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (isSgExecutableStatement(st) == NULL || st->lineNumber() <= 0)
|
if (isSgExecutableStatement(st) == NULL) {
|
||||||
|
checkInTypeDescription(st->expr(0), currF, parNames);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (st->lineNumber() <= 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (activeOps.size() && activeOps.find(st) == activeOps.end())
|
if (activeOps.size() && activeOps.find(st) == activeOps.end())
|
||||||
|
|||||||
@@ -31,7 +31,7 @@
|
|||||||
#include "../DirectiveProcessing/directive_parser.h"
|
#include "../DirectiveProcessing/directive_parser.h"
|
||||||
#include "../DynamicAnalysis/gCov_parser_func.h"
|
#include "../DynamicAnalysis/gCov_parser_func.h"
|
||||||
|
|
||||||
#include "../Transformations/VectorAssignToLoop/array_assign_to_loop.h"
|
#include "VectorAssignToLoop/array_assign_to_loop.h"
|
||||||
|
|
||||||
using std::vector;
|
using std::vector;
|
||||||
using std::map;
|
using std::map;
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ extern int passDone;
|
|||||||
#include "../VisualizerCalls/get_information.h"
|
#include "../VisualizerCalls/get_information.h"
|
||||||
#include "../VisualizerCalls/SendMessage.h"
|
#include "../VisualizerCalls/SendMessage.h"
|
||||||
|
|
||||||
#include "../Transformations/LoopEndDoConverter/enddo_loop_converter.h"
|
#include "LoopEndDoConverter/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"
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
#include "../DirectiveProcessing/insert_directive.h"
|
#include "../DirectiveProcessing/insert_directive.h"
|
||||||
#include "SgUtils.h"
|
#include "SgUtils.h"
|
||||||
#include "expr_transform.h"
|
#include "expr_transform.h"
|
||||||
#include "../Transformations/FunctionPurifying/function_purifying.h"
|
#include "FunctionPurifying/function_purifying.h"
|
||||||
|
|
||||||
using std::map;
|
using std::map;
|
||||||
using std::pair;
|
using std::pair;
|
||||||
|
|||||||
@@ -89,6 +89,7 @@
|
|||||||
#include "Transformations/DeadCodeRemoving/dead_code.h"
|
#include "Transformations/DeadCodeRemoving/dead_code.h"
|
||||||
#include "Transformations/RenameSymbols/rename_symbols.h"
|
#include "Transformations/RenameSymbols/rename_symbols.h"
|
||||||
#include "Transformations/FunctionInlining/inliner.h"
|
#include "Transformations/FunctionInlining/inliner.h"
|
||||||
|
#include "Transformations/SwapOperators/swap_operators.h"
|
||||||
|
|
||||||
#include "ProjectParameters/projectParameters.h"
|
#include "ProjectParameters/projectParameters.h"
|
||||||
|
|
||||||
@@ -939,6 +940,8 @@ static bool runAnalysis(SgProject &project, const int curr_regime, const bool ne
|
|||||||
internalExit = err;
|
internalExit = err;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (curr_regime == SWAP_OPERATORS)
|
||||||
|
runSwapOperators(file, loopGraph, fullIR, countOfTransform);
|
||||||
else if (curr_regime == PRIVATE_REMOVING_ANALYSIS)
|
else if (curr_regime == PRIVATE_REMOVING_ANALYSIS)
|
||||||
{
|
{
|
||||||
auto itFound = loopGraph.find(file->filename());
|
auto itFound = loopGraph.find(file->filename());
|
||||||
@@ -1037,7 +1040,8 @@ static bool runAnalysis(SgProject &project, const int curr_regime, const bool ne
|
|||||||
PRIVATE_REMOVING,
|
PRIVATE_REMOVING,
|
||||||
PRIVATE_ARRAYS_EXPANSION,
|
PRIVATE_ARRAYS_EXPANSION,
|
||||||
PRIVATE_ARRAYS_SHRINKING,
|
PRIVATE_ARRAYS_SHRINKING,
|
||||||
REMOVE_DEAD_CODE };
|
REMOVE_DEAD_CODE,
|
||||||
|
SWAP_OPERATORS };
|
||||||
|
|
||||||
if ((countOfTransform == 0 || internalExit > 0) && applyFor.find(curr_regime) != applyFor.end())
|
if ((countOfTransform == 0 || internalExit > 0) && applyFor.find(curr_regime) != applyFor.end())
|
||||||
{
|
{
|
||||||
@@ -1281,7 +1285,6 @@ static bool runAnalysis(SgProject &project, const int curr_regime, const bool ne
|
|||||||
detectCopies(allFuncInfo);
|
detectCopies(allFuncInfo);
|
||||||
fillInterfaceBlock(allFuncInfo);
|
fillInterfaceBlock(allFuncInfo);
|
||||||
intentInsertToInterfaces(allFuncInfo);
|
intentInsertToInterfaces(allFuncInfo);
|
||||||
createInterfacesForAssumedSize(allFuncInfo);
|
|
||||||
|
|
||||||
//this call is only for testing
|
//this call is only for testing
|
||||||
//setPureStatus(allFuncInfo);
|
//setPureStatus(allFuncInfo);
|
||||||
@@ -2331,6 +2334,7 @@ void runPass(const int curr_regime, const char *proj_name, const char *folderNam
|
|||||||
case INSERT_NO_DISTR_FLAGS_FROM_GUI:
|
case INSERT_NO_DISTR_FLAGS_FROM_GUI:
|
||||||
case PRIVATE_REMOVING:
|
case PRIVATE_REMOVING:
|
||||||
case RENAME_INLCUDES:
|
case RENAME_INLCUDES:
|
||||||
|
case SWAP_OPERATORS:
|
||||||
runAnalysis(*project, curr_regime, true, "", folderName);
|
runAnalysis(*project, curr_regime, true, "", folderName);
|
||||||
break;
|
break;
|
||||||
case INLINE_PROCEDURES:
|
case INLINE_PROCEDURES:
|
||||||
@@ -2632,7 +2636,10 @@ int main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (curr_regime == INSERT_PARALLEL_DIRS_NODIST)
|
if (curr_regime == INSERT_PARALLEL_DIRS_NODIST)
|
||||||
|
{
|
||||||
ignoreArrayDistributeState = true;
|
ignoreArrayDistributeState = true;
|
||||||
|
sharedMemoryParallelization = 1;
|
||||||
|
}
|
||||||
|
|
||||||
if (runAsClient)
|
if (runAsClient)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -122,6 +122,8 @@ enum passes {
|
|||||||
CREATE_INTER_TREE,
|
CREATE_INTER_TREE,
|
||||||
INSERT_INTER_TREE,
|
INSERT_INTER_TREE,
|
||||||
|
|
||||||
|
SWAP_OPERATORS,
|
||||||
|
|
||||||
SHADOW_GROUPING,
|
SHADOW_GROUPING,
|
||||||
INLINE_PROCEDURES,
|
INLINE_PROCEDURES,
|
||||||
FILL_PARALLEL_REG_IR,
|
FILL_PARALLEL_REG_IR,
|
||||||
@@ -317,6 +319,7 @@ static void setPassValues()
|
|||||||
passNames[CHECK_PAR_REG_DIR] = "CHECK_PAR_REG_DIR";
|
passNames[CHECK_PAR_REG_DIR] = "CHECK_PAR_REG_DIR";
|
||||||
passNames[CREATE_INTER_TREE] = "CREATE_INTER_TREE";
|
passNames[CREATE_INTER_TREE] = "CREATE_INTER_TREE";
|
||||||
passNames[INSERT_INTER_TREE] = "INSERT_INTER_TREE";
|
passNames[INSERT_INTER_TREE] = "INSERT_INTER_TREE";
|
||||||
|
passNames[SWAP_OPERATORS] = "SWAP_OPERATORS";
|
||||||
passNames[CREATE_PARALLEL_REGIONS] = "CREATE_PARALLEL_REGIONS";
|
passNames[CREATE_PARALLEL_REGIONS] = "CREATE_PARALLEL_REGIONS";
|
||||||
passNames[PRIVATE_REMOVING_ANALYSIS] = "PRIVATE_REMOVING_ANALYSIS";
|
passNames[PRIVATE_REMOVING_ANALYSIS] = "PRIVATE_REMOVING_ANALYSIS";
|
||||||
passNames[PRIVATE_REMOVING] = "PRIVATE_REMOVING";
|
passNames[PRIVATE_REMOVING] = "PRIVATE_REMOVING";
|
||||||
|
|||||||
@@ -210,7 +210,8 @@ static vector<FuncInfo*> sortByName(const T &funcs)
|
|||||||
return funcList;
|
return funcList;
|
||||||
}
|
}
|
||||||
|
|
||||||
void createInterfacesForAssumedSize(const map<string, vector<FuncInfo*>>& allFuncInfo)
|
//XXX: incorrect!!
|
||||||
|
/*void createInterfacesForAssumedSize(const map<string, vector<FuncInfo*>>& allFuncInfo)
|
||||||
{
|
{
|
||||||
set<FuncInfo*> hasAssumedSizeArrays;
|
set<FuncInfo*> hasAssumedSizeArrays;
|
||||||
|
|
||||||
@@ -295,7 +296,7 @@ void createInterfacesForAssumedSize(const map<string, vector<FuncInfo*>>& allFun
|
|||||||
removeExternalStat(prog, addedInterfaceFor);
|
removeExternalStat(prog, addedInterfaceFor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
|
||||||
static void setPureStatus(FuncInfo* func)
|
static void setPureStatus(FuncInfo* func)
|
||||||
{
|
{
|
||||||
@@ -1388,6 +1389,37 @@ static string makeName(SgSymbol* var, map<SgSymbol*, set< SgSymbol*>>& modVarsTo
|
|||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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)
|
static string getInterfaceBlock(SgStatement* func, const FuncParam& pars)
|
||||||
{
|
{
|
||||||
string oldFile = current_file->filename();
|
string oldFile = current_file->filename();
|
||||||
@@ -1395,22 +1427,21 @@ static string getInterfaceBlock(SgStatement* func, const FuncParam& pars)
|
|||||||
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
||||||
|
|
||||||
auto copy = duplicateProcedure(func, NULL, false, false, false, true);
|
auto copy = duplicateProcedure(func, NULL, false, false, false, true);
|
||||||
|
const set<string> idents(pars.identificators.begin(), pars.identificators.end());
|
||||||
const set<string> ident(pars.identificators.begin(), pars.identificators.end());
|
|
||||||
|
|
||||||
//remove all exec
|
//remove all exec
|
||||||
SgStatement* st = copy->lexNext();
|
SgStatement* st = copy->lexNext();
|
||||||
SgStatement* last = copy->lastNodeOfStmt();
|
SgStatement* last = copy->lastNodeOfStmt();
|
||||||
vector<SgStatement*> toExtract;
|
vector<SgStatement*> toExtract;
|
||||||
|
|
||||||
while (st != last)
|
while (st != last)
|
||||||
{
|
{
|
||||||
if (isDVM_stat(st) || isSPF_stat(st))
|
if (isDVM_stat(st) || isSPF_stat(st))
|
||||||
{
|
{
|
||||||
if (st->variant() != ACC_ROUTINE_DIR)
|
if (st->variant() != ACC_ROUTINE_DIR)
|
||||||
{
|
{
|
||||||
SgStatement* next = st->lexNext();
|
toExtract.push_back(st);
|
||||||
st->extractStmt();
|
st = st->lexNext();
|
||||||
st = next;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
st = st->lexNext();
|
st = st->lexNext();
|
||||||
@@ -1431,31 +1462,20 @@ static string getInterfaceBlock(SgStatement* func, const FuncParam& pars)
|
|||||||
st = copy->lexNext();
|
st = copy->lexNext();
|
||||||
while (st != last)
|
while (st != last)
|
||||||
{
|
{
|
||||||
if (st->variant() == VAR_DECL
|
const int var = st->variant();
|
||||||
|| st->variant() == VAR_DECL_90
|
|
||||||
|| st->variant() == DIM_STAT
|
|
||||||
|| st->variant() == INTENT_STMT)
|
|
||||||
{
|
|
||||||
SgExpression* list = st->expr(0);
|
|
||||||
vector<SgExpression*> newList;
|
|
||||||
while (list)
|
|
||||||
{
|
|
||||||
if (ident.find(list->lhs()->symbol()->identifier()) != ident.end())
|
|
||||||
newList.push_back(list->lhs());
|
|
||||||
list = list->rhs();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (newList.size() == 0)
|
if (var == VAR_DECL || var == VAR_DECL_90 || var == DIM_STAT ||
|
||||||
|
var == INTENT_STMT || var == EXTERN_STAT)
|
||||||
|
{
|
||||||
|
bool empty = filterFromList(st, idents);
|
||||||
|
if (empty)
|
||||||
{
|
{
|
||||||
SgStatement* next = st->lexNext();
|
|
||||||
toExtract.push_back(st);
|
toExtract.push_back(st);
|
||||||
st = next;
|
st = st->lexNext();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
st->setExpression(0, makeExprList(newList));
|
|
||||||
}
|
}
|
||||||
else
|
else if (!isDVM_stat(st) && !isSPF_stat(st))
|
||||||
toExtract.push_back(st);
|
toExtract.push_back(st);
|
||||||
|
|
||||||
if (st->variant() == CONTAINS_STMT)
|
if (st->variant() == CONTAINS_STMT)
|
||||||
@@ -1466,16 +1486,56 @@ static string getInterfaceBlock(SgStatement* func, const FuncParam& pars)
|
|||||||
for (auto& elem : toExtract)
|
for (auto& elem : toExtract)
|
||||||
elem->extractStmt();
|
elem->extractStmt();
|
||||||
|
|
||||||
string retVal = copy->unparse();
|
string codeString = copy->unparse();
|
||||||
|
|
||||||
if (SgFile::switchToFile(oldFile) == -1)
|
if (SgFile::switchToFile(oldFile) == -1)
|
||||||
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
||||||
|
|
||||||
|
//insert tabs
|
||||||
|
const string tab = " ";
|
||||||
|
const int countEnds = std::count(codeString.begin(), codeString.end(), '\n');
|
||||||
|
|
||||||
|
string retVal = " ";
|
||||||
|
retVal.reserve(retVal.size() + codeString.size() + countEnds * tab.size());
|
||||||
|
|
||||||
|
for (int z = 0, ends = 0; z < codeString.size(); ++z)
|
||||||
|
{
|
||||||
|
retVal += codeString[z];
|
||||||
|
if (codeString[z] == '\n')
|
||||||
|
{
|
||||||
|
ends++;
|
||||||
|
if (ends == countEnds)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
int p = z + 1;
|
||||||
|
while (codeString[p] == ' ' && p < codeString.size())
|
||||||
|
++p;
|
||||||
|
|
||||||
|
auto start = p;
|
||||||
|
auto end = string::npos;
|
||||||
|
auto sub = codeString.find("subroutine", p);
|
||||||
|
auto func = codeString.find("function", p);
|
||||||
|
auto end_sub = codeString.find("end subroutine", p);
|
||||||
|
auto end_func = codeString.find("end function", p);
|
||||||
|
|
||||||
|
if (sub != end && sub == start || end_sub != end && end_sub == start ||
|
||||||
|
func != end && func == start || end_func != end && end_func == start)
|
||||||
|
{
|
||||||
|
retVal += " ";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
retVal += tab;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void insertInterface(SgStatement* func, const string& iface)
|
void insertInterface(SgStatement* func, const FuncInfo *callFrom)
|
||||||
{
|
{
|
||||||
|
const string& iface = getInterfaceBlock(callFrom->funcPointer->GetOriginal(), callFrom->funcParams);
|
||||||
|
const string& fName = callFrom->funcName;
|
||||||
|
|
||||||
string oldFile = current_file->filename();
|
string oldFile = current_file->filename();
|
||||||
if (!func->switchToFile())
|
if (!func->switchToFile())
|
||||||
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
||||||
@@ -1484,6 +1544,18 @@ static void insertInterface(SgStatement* func, const string& iface)
|
|||||||
SgStatement* last = func->lastNodeOfStmt();
|
SgStatement* last = func->lastNodeOfStmt();
|
||||||
while (st != last)
|
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))
|
if (isSgExecutableStatement(st))
|
||||||
break;
|
break;
|
||||||
st = st->lexNext();
|
st = st->lexNext();
|
||||||
@@ -1491,7 +1563,7 @@ static void insertInterface(SgStatement* func, const string& iface)
|
|||||||
SgStatement* ifaceBlock = new SgStatement(INTERFACE_STMT);
|
SgStatement* ifaceBlock = new SgStatement(INTERFACE_STMT);
|
||||||
addControlEndToStmt(ifaceBlock->thebif);
|
addControlEndToStmt(ifaceBlock->thebif);
|
||||||
|
|
||||||
ifaceBlock->setlineNumber(st->lineNumber());
|
ifaceBlock->setlineNumber(getNextNegativeLineNumber());
|
||||||
ifaceBlock->setFileName(st->fileName());
|
ifaceBlock->setFileName(st->fileName());
|
||||||
st->insertStmtBefore(*ifaceBlock, *st->controlParent());
|
st->insertStmtBefore(*ifaceBlock, *st->controlParent());
|
||||||
ifaceBlock->lastNodeOfStmt()->addComment(iface.c_str());
|
ifaceBlock->lastNodeOfStmt()->addComment(iface.c_str());
|
||||||
@@ -1507,7 +1579,7 @@ static void createInterfaceBlockForToCalls(FuncInfo* func)
|
|||||||
if (callTo->interfaceBlocks.find(func->funcName) == callTo->interfaceBlocks.end())
|
if (callTo->interfaceBlocks.find(func->funcName) == callTo->interfaceBlocks.end())
|
||||||
{
|
{
|
||||||
callTo->interfaceBlocks[func->funcName] = func;
|
callTo->interfaceBlocks[func->funcName] = func;
|
||||||
insertInterface(callTo->funcPointer, getInterfaceBlock(func->funcPointer->GetOriginal(), func->funcParams));
|
insertInterface(callTo->funcPointer, func);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ bool checkOutCalls(const std::set<std::string>& outCalls);
|
|||||||
std::map<SgStatement*, std::set<std::string>> fillFromIntent(SgStatement* header);
|
std::map<SgStatement*, std::set<std::string>> fillFromIntent(SgStatement* header);
|
||||||
void intentInsert(const std::vector<FuncInfo*>& allFuncInfo);
|
void intentInsert(const std::vector<FuncInfo*>& allFuncInfo);
|
||||||
void intentInsertToInterfaces(const std::map<std::string, std::vector<FuncInfo*>>& allFuncInfo);
|
void intentInsertToInterfaces(const std::map<std::string, std::vector<FuncInfo*>>& allFuncInfo);
|
||||||
void createInterfacesForAssumedSize(const std::map<std::string, std::vector<FuncInfo*>>& allFuncInfo);
|
|
||||||
void createInterfacesForOutCalls(FuncInfo* func);
|
void createInterfacesForOutCalls(FuncInfo* func);
|
||||||
void setPureStatus(const std::set<FuncInfo*>& funcInfo);
|
void setPureStatus(const std::set<FuncInfo*>& funcInfo);
|
||||||
void setPureStatus(const std::map<std::string, std::vector<FuncInfo*>>& allFuncInfo);
|
void setPureStatus(const std::map<std::string, std::vector<FuncInfo*>>& allFuncInfo);
|
||||||
@@ -14,3 +13,5 @@ void setPureStatus(const std::map<std::string, std::vector<FuncInfo*>>& allFuncI
|
|||||||
void commonTransfer(const std::map<std::string, std::vector<FuncInfo*>>& allFuncInfo, const std::map<std::string, CommonBlock*>& commonBlocks);
|
void commonTransfer(const std::map<std::string, std::vector<FuncInfo*>>& allFuncInfo, const std::map<std::string, CommonBlock*>& commonBlocks);
|
||||||
void saveTransfer(const std::map<std::string, std::vector<FuncInfo*>>& allFuncInfo);
|
void saveTransfer(const std::map<std::string, std::vector<FuncInfo*>>& allFuncInfo);
|
||||||
void moduleTransfer(const std::map<std::string, std::vector<FuncInfo*>>& allFuncInfo);
|
void moduleTransfer(const std::map<std::string, std::vector<FuncInfo*>>& allFuncInfo);
|
||||||
|
|
||||||
|
void insertInterface(SgStatement* func, const FuncInfo* callFrom);
|
||||||
353
src/Transformations/SwapOperators/swap_operators.cpp
Normal file
353
src/Transformations/SwapOperators/swap_operators.cpp
Normal file
@@ -0,0 +1,353 @@
|
|||||||
|
#include <map>
|
||||||
|
#include <unordered_set>
|
||||||
|
#include <vector>
|
||||||
|
#include <queue>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
#include "../../Utils/errors.h"
|
||||||
|
#include "../../Utils/SgUtils.h"
|
||||||
|
#include "../../GraphCall/graph_calls.h"
|
||||||
|
#include "../../GraphCall/graph_calls_func.h"
|
||||||
|
#include "../../CFGraph/CFGraph.h"
|
||||||
|
#include "../../CFGraph/IR.h"
|
||||||
|
#include "../../GraphLoop/graph_loops.h"
|
||||||
|
#include "swap_operators.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
|
||||||
|
unordered_set<int> loop_tags = {FOR_NODE/*, FORALL_NODE, WHILE_NODE, DO_WHILE_NODE*/};
|
||||||
|
unordered_set<int> importantDepsTags = {FOR_NODE, IF_NODE};
|
||||||
|
unordered_set<int> importantUpdDepsTags = {ELSEIF_NODE};
|
||||||
|
unordered_set<int> importantEndTags = {CONTROL_END};
|
||||||
|
|
||||||
|
|
||||||
|
vector<SAPFOR::IR_Block*> findInstructionsFromOperator(SgStatement* st, vector<SAPFOR::BasicBlock*> Blocks)
|
||||||
|
{
|
||||||
|
vector<SAPFOR::IR_Block*> result;
|
||||||
|
string filename = st -> fileName();
|
||||||
|
for (auto& block: Blocks)
|
||||||
|
{
|
||||||
|
vector<SAPFOR::IR_Block*> instructionsInBlock = block -> getInstructions();
|
||||||
|
for (auto& instruction: instructionsInBlock)
|
||||||
|
{
|
||||||
|
SgStatement* curOperator = instruction -> getInstruction() -> getOperator();
|
||||||
|
if (curOperator -> lineNumber() == st -> lineNumber())
|
||||||
|
result.push_back(instruction);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
vector<SAPFOR::BasicBlock*> findFuncBlocksByFuncStatement(SgStatement *st, map<FuncInfo*, vector<SAPFOR::BasicBlock*>>& FullIR)
|
||||||
|
{
|
||||||
|
vector<SAPFOR::BasicBlock*> result;
|
||||||
|
Statement* forSt = (Statement*)st;
|
||||||
|
for (auto& func: FullIR)
|
||||||
|
{
|
||||||
|
if (func.first -> funcPointer -> getCurrProcessFile() == forSt -> getCurrProcessFile()
|
||||||
|
&& func.first -> funcPointer -> lineNumber() == forSt -> lineNumber())
|
||||||
|
result = func.second;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
map<SgForStmt*, vector<SAPFOR::BasicBlock*>> findAndAnalyzeLoops(SgStatement *st, vector<SAPFOR::BasicBlock*> blocks)
|
||||||
|
{
|
||||||
|
map<SgForStmt*, vector<SAPFOR::BasicBlock*>> result;
|
||||||
|
SgStatement *lastNode = st->lastNodeOfStmt();
|
||||||
|
while (st && st != lastNode)
|
||||||
|
{
|
||||||
|
if (loop_tags.find(st -> variant()) != loop_tags.end())
|
||||||
|
{
|
||||||
|
// part with find statements of loop
|
||||||
|
SgForStmt *forSt = (SgForStmt*)st;
|
||||||
|
SgStatement *loopBody = forSt -> body();
|
||||||
|
SgStatement *lastLoopNode = st->lastNodeOfStmt();
|
||||||
|
// part with find blocks and instructions of loops
|
||||||
|
unordered_set<int> blocks_nums;
|
||||||
|
while (loopBody && loopBody != lastLoopNode)
|
||||||
|
{
|
||||||
|
SAPFOR::IR_Block* IR = findInstructionsFromOperator(loopBody, blocks).front();
|
||||||
|
if (blocks_nums.find(IR -> getBasicBlock() -> getNumber()) == blocks_nums.end())
|
||||||
|
{
|
||||||
|
result[forSt].push_back(IR -> getBasicBlock());
|
||||||
|
blocks_nums.insert(IR -> getBasicBlock() -> getNumber());
|
||||||
|
}
|
||||||
|
loopBody = loopBody -> lexNext();
|
||||||
|
}
|
||||||
|
std::sort(result[forSt].begin(), result[forSt].end());
|
||||||
|
}
|
||||||
|
st = st -> lexNext();
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
map<SgStatement*, set<SgStatement*>> AnalyzeLoopAndFindDeps(SgForStmt* forStatement, vector<SAPFOR::BasicBlock*> loopBlocks, map<FuncInfo*, vector<SAPFOR::BasicBlock*>>& FullIR)
|
||||||
|
{
|
||||||
|
map<SgStatement*, set<SgStatement*>> result;
|
||||||
|
for (SAPFOR::BasicBlock* bb: loopBlocks)
|
||||||
|
{
|
||||||
|
map<SAPFOR::Argument*, set<int>> blockReachingDefinitions = bb -> getRD_In();
|
||||||
|
vector<SAPFOR::IR_Block*> instructions = bb -> getInstructions();
|
||||||
|
for (SAPFOR::IR_Block* irBlock: instructions)
|
||||||
|
{
|
||||||
|
// TODO: Think about what to do with function calls and array references. Because there are also dependencies there that are not reflected in RD, but they must be taken into account
|
||||||
|
SAPFOR::Instruction* instr = irBlock -> getInstruction();
|
||||||
|
result[instr -> getOperator()];
|
||||||
|
// take Argument 1 and it's RD and push operators to final set
|
||||||
|
if (instr -> getArg1() != NULL)
|
||||||
|
{
|
||||||
|
SAPFOR::Argument* arg = instr -> getArg1();
|
||||||
|
set<int> prevInstructionsNumbers = blockReachingDefinitions[arg];
|
||||||
|
for (int i: prevInstructionsNumbers)
|
||||||
|
{
|
||||||
|
SAPFOR::Instruction* foundInstruction = getInstructionAndBlockByNumber(FullIR, i).first;
|
||||||
|
if (foundInstruction != NULL)
|
||||||
|
{
|
||||||
|
SgStatement* prevOp = foundInstruction -> getOperator();
|
||||||
|
if (prevOp != forStatement && instr -> getOperator() != forStatement && instr -> getOperator() -> lineNumber() > prevOp -> lineNumber()
|
||||||
|
&& prevOp -> lineNumber() > forStatement -> lineNumber())
|
||||||
|
result[instr -> getOperator()].insert(prevOp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// take Argument 2 (if exists) and it's RD and push operators to final set
|
||||||
|
if (instr -> getArg2() != NULL)
|
||||||
|
{
|
||||||
|
SAPFOR::Argument* arg = instr -> getArg2();
|
||||||
|
set<int> prevInstructionsNumbers = blockReachingDefinitions[arg];
|
||||||
|
for (int i: prevInstructionsNumbers)
|
||||||
|
{
|
||||||
|
SAPFOR::Instruction* foundInstruction = getInstructionAndBlockByNumber(FullIR, i).first;
|
||||||
|
if (foundInstruction != NULL)
|
||||||
|
{
|
||||||
|
SgStatement* prevOp = foundInstruction -> getOperator();
|
||||||
|
if (prevOp != forStatement && instr -> getOperator() != forStatement&& instr -> getOperator() -> lineNumber() > prevOp -> lineNumber()
|
||||||
|
&& prevOp -> lineNumber() > forStatement -> lineNumber())
|
||||||
|
result[instr -> getOperator()].insert(prevOp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// update RD
|
||||||
|
if (instr -> getResult() != NULL)
|
||||||
|
blockReachingDefinitions[instr -> getResult()] = {instr -> getNumber()};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
void buildAdditionalDeps(SgForStmt* forStatement, map<SgStatement*, set<SgStatement*>>& dependencies)
|
||||||
|
{
|
||||||
|
SgStatement* lastNode = forStatement->lastNodeOfStmt();
|
||||||
|
vector<SgStatement*> importantDeps;
|
||||||
|
SgStatement* st = (SgStatement*) forStatement;
|
||||||
|
st = st -> lexNext();
|
||||||
|
SgStatement* logIfOp = NULL;
|
||||||
|
while (st && st != lastNode)
|
||||||
|
{
|
||||||
|
if(importantDeps.size() != 0)
|
||||||
|
{
|
||||||
|
if (st != importantDeps.back())
|
||||||
|
{
|
||||||
|
dependencies[st].insert(importantDeps.back());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (logIfOp != NULL)
|
||||||
|
{
|
||||||
|
dependencies[st].insert(logIfOp);
|
||||||
|
logIfOp = NULL;
|
||||||
|
}
|
||||||
|
if (st -> variant() == LOGIF_NODE)
|
||||||
|
{
|
||||||
|
logIfOp = st;
|
||||||
|
}
|
||||||
|
if (importantDepsTags.find(st -> variant()) != importantDepsTags.end())
|
||||||
|
{
|
||||||
|
importantDeps.push_back(st);
|
||||||
|
}
|
||||||
|
if (importantUpdDepsTags.find(st -> variant()) != importantUpdDepsTags.end())
|
||||||
|
{
|
||||||
|
importantDeps.pop_back();
|
||||||
|
importantDeps.push_back(st);
|
||||||
|
}
|
||||||
|
if (importantEndTags.find(st -> variant()) != importantEndTags.end())
|
||||||
|
{
|
||||||
|
if(importantDeps.size() != 0)
|
||||||
|
{
|
||||||
|
importantDeps.pop_back();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
st = st -> lexNext();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct ReadyOp {
|
||||||
|
SgStatement* stmt;
|
||||||
|
int degree;
|
||||||
|
size_t arrival;
|
||||||
|
ReadyOp(SgStatement* s, int d, size_t a): stmt(s), degree(d), arrival(a) {}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ReadyOpCompare {
|
||||||
|
bool operator()(const ReadyOp& a, const ReadyOp& b) const {
|
||||||
|
if (a.degree != b.degree)
|
||||||
|
return a.degree > b.degree;
|
||||||
|
else
|
||||||
|
return a.arrival > b.arrival;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
vector<SgStatement*> scheduleOperations(const map<SgStatement*, set<SgStatement*>>& dependencies)
|
||||||
|
{
|
||||||
|
// get all statements
|
||||||
|
unordered_set<SgStatement*> allStmtsSet;
|
||||||
|
for (const auto& pair : dependencies)
|
||||||
|
{
|
||||||
|
allStmtsSet.insert(pair.first);
|
||||||
|
for (SgStatement* dep : pair.second)
|
||||||
|
{
|
||||||
|
allStmtsSet.insert(dep);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
vector<SgStatement*> allStmts(allStmtsSet.begin(), allStmtsSet.end());
|
||||||
|
// count deps and build reversed graph
|
||||||
|
unordered_map<SgStatement*, vector<SgStatement*>> graph;
|
||||||
|
unordered_map<SgStatement*, int> inDegree;
|
||||||
|
unordered_map<SgStatement*, int> degree;
|
||||||
|
for (auto op : allStmts)
|
||||||
|
inDegree[op] = 0;
|
||||||
|
// find and remember initial dependencies
|
||||||
|
unordered_set<SgStatement*> dependentStmts;
|
||||||
|
for (const auto& pair : dependencies)
|
||||||
|
{
|
||||||
|
SgStatement* op = pair.first;
|
||||||
|
const auto& deps = pair.second;
|
||||||
|
degree[op] = deps.size();
|
||||||
|
inDegree[op] = deps.size();
|
||||||
|
if (!deps.empty())
|
||||||
|
dependentStmts.insert(op);
|
||||||
|
for (auto dep : deps)
|
||||||
|
graph[dep].push_back(op);
|
||||||
|
}
|
||||||
|
for (SgStatement* op : allStmts)
|
||||||
|
{
|
||||||
|
if (!degree.count(op))
|
||||||
|
{
|
||||||
|
degree[op] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// build queues
|
||||||
|
using PQ = priority_queue<ReadyOp, vector<ReadyOp>, ReadyOpCompare>;
|
||||||
|
PQ readyDependent;
|
||||||
|
queue<SgStatement*> readyIndependent;
|
||||||
|
size_t arrivalCounter = 0;
|
||||||
|
for (auto op : allStmts)
|
||||||
|
{
|
||||||
|
if (inDegree[op] == 0)
|
||||||
|
{
|
||||||
|
if (dependentStmts.count(op))
|
||||||
|
{
|
||||||
|
readyDependent.emplace(op, degree[op], arrivalCounter++);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
readyIndependent.push(op);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// main sort algorythm
|
||||||
|
vector<SgStatement*> executionOrder;
|
||||||
|
while (!readyDependent.empty() || !readyIndependent.empty())
|
||||||
|
{
|
||||||
|
SgStatement* current = nullptr;
|
||||||
|
if (!readyDependent.empty())
|
||||||
|
{
|
||||||
|
current = readyDependent.top().stmt;
|
||||||
|
readyDependent.pop();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
current = readyIndependent.front();
|
||||||
|
readyIndependent.pop();
|
||||||
|
}
|
||||||
|
executionOrder.push_back(current);
|
||||||
|
for (SgStatement* neighbor : graph[current])
|
||||||
|
{
|
||||||
|
inDegree[neighbor]--;
|
||||||
|
if (inDegree[neighbor] == 0) {
|
||||||
|
if (dependentStmts.count(neighbor))
|
||||||
|
{
|
||||||
|
readyDependent.emplace(neighbor, degree[neighbor], arrivalCounter++);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
readyIndependent.push(neighbor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return executionOrder;
|
||||||
|
}
|
||||||
|
|
||||||
|
void buildNewAST(SgStatement* loop, vector<SgStatement*>& newBody)
|
||||||
|
{
|
||||||
|
SgStatement* endDo = loop->lastNodeOfStmt();
|
||||||
|
SgStatement* st = loop;
|
||||||
|
int lineNum = loop -> lineNumber() + 1;
|
||||||
|
for (int i = 0; i < newBody.size(); i++)
|
||||||
|
{
|
||||||
|
st -> setLexNext(*newBody[i]);
|
||||||
|
st = st -> lexNext();
|
||||||
|
st -> setlineNumber(lineNum);
|
||||||
|
lineNum++;
|
||||||
|
}
|
||||||
|
st -> setLexNext(*endDo);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void runSwapOperators(SgFile *file, std::map<std::string, std::vector<LoopGraph*>>& loopGraph, std::map<FuncInfo*, std::vector<SAPFOR::BasicBlock*>>& FullIR, int& countOfTransform)
|
||||||
|
{
|
||||||
|
std::cout << "SWAP_OPERATORS Pass" << std::endl; // to remove
|
||||||
|
countOfTransform += 1; // to remove
|
||||||
|
|
||||||
|
const int funcNum = file -> numberOfFunctions();
|
||||||
|
for (int i = 0; i < funcNum; ++i)
|
||||||
|
{
|
||||||
|
SgStatement *st = file -> functions(i);
|
||||||
|
vector<SAPFOR::BasicBlock*> blocks = findFuncBlocksByFuncStatement(st, FullIR);
|
||||||
|
map<SgForStmt*, vector<SAPFOR::BasicBlock*>> loopsMapping = findAndAnalyzeLoops(st, blocks);
|
||||||
|
for (pair<SgForStmt*, vector<SAPFOR::BasicBlock*>> loopForAnalyze: loopsMapping)
|
||||||
|
{
|
||||||
|
map<SgStatement*, set<SgStatement*>> dependencyGraph = AnalyzeLoopAndFindDeps(loopForAnalyze.first, loopForAnalyze.second, FullIR);
|
||||||
|
// TODO: Write a function that will go through the operators and update all dependencies so that there are no mix-ups and splits inside the semantic blocks (for if, do and may be some other cases)
|
||||||
|
buildAdditionalDeps(loopForAnalyze.first, dependencyGraph);
|
||||||
|
cout << endl;
|
||||||
|
int firstLine = loopForAnalyze.first -> lineNumber();
|
||||||
|
int lastLine = loopForAnalyze.first -> lastNodeOfStmt() -> lineNumber();
|
||||||
|
cout << "LOOP ANALYZE FROM " << firstLine << " TO " << lastLine << " RES" << endl;
|
||||||
|
// for (auto &v: dependencyGraph) {
|
||||||
|
// cout << "OPERATOR: " << v.first -> lineNumber() << " " << v.first -> variant() << "\nDEPENDS ON:" << endl;
|
||||||
|
// if (v.second.size() != 0)
|
||||||
|
// for (auto vv: v.second)
|
||||||
|
// cout << vv -> lineNumber() << " ";
|
||||||
|
// cout << endl;
|
||||||
|
// }
|
||||||
|
vector<SgStatement*> new_order = scheduleOperations(dependencyGraph);
|
||||||
|
cout << "RESULT ORDER:" << endl;
|
||||||
|
for (auto v: new_order)
|
||||||
|
if (v -> lineNumber() > firstLine)
|
||||||
|
cout << v -> lineNumber() << endl;
|
||||||
|
buildNewAST(loopForAnalyze.first, new_order);
|
||||||
|
st = loopForAnalyze.first -> lexNext();
|
||||||
|
while (st != loopForAnalyze.first -> lastNodeOfStmt())
|
||||||
|
{
|
||||||
|
cout << st -> lineNumber() << " " << st -> sunparse() << endl;
|
||||||
|
st = st -> lexNext();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
};
|
||||||
6
src/Transformations/SwapOperators/swap_operators.h
Normal file
6
src/Transformations/SwapOperators/swap_operators.h
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "../../GraphLoop/graph_loops.h"
|
||||||
|
#include "../../CFGraph/CFGraph.h"
|
||||||
|
|
||||||
|
void runSwapOperators(SgFile *file, std::map<std::string, std::vector<LoopGraph*>>& loopGraph, std::map<FuncInfo*, std::vector<SAPFOR::BasicBlock*>>& FullIR, int& countOfTransform);
|
||||||
@@ -212,6 +212,8 @@ void InitPassesDependencies(map<passes, vector<passes>> &passDepsIn, set<passes>
|
|||||||
|
|
||||||
Pass(BUILD_IR) <= Pass(SUBST_EXPR_RD) <= Pass(SUBST_EXPR_RD_AND_UNPARSE);
|
Pass(BUILD_IR) <= Pass(SUBST_EXPR_RD) <= Pass(SUBST_EXPR_RD_AND_UNPARSE);
|
||||||
|
|
||||||
|
list({BUILD_IR, CALL_GRAPH2}) <= Pass(SWAP_OPERATORS);
|
||||||
|
|
||||||
list({ LOOP_ANALYZER_DATA_DIST_S1, SUBST_EXPR_RD } ) <= Pass(PRIVATE_REMOVING_ANALYSIS);
|
list({ LOOP_ANALYZER_DATA_DIST_S1, SUBST_EXPR_RD } ) <= Pass(PRIVATE_REMOVING_ANALYSIS);
|
||||||
list({ PRIVATE_REMOVING_ANALYSIS, REVERT_SUBST_EXPR_RD }) <= Pass(PRIVATE_REMOVING);
|
list({ PRIVATE_REMOVING_ANALYSIS, REVERT_SUBST_EXPR_RD }) <= Pass(PRIVATE_REMOVING);
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#define VERSION_SPF "2432"
|
#define VERSION_SPF "2436"
|
||||||
|
|||||||
Reference in New Issue
Block a user