Compare commits
32 Commits
aa6608e7d3
...
private_ar
| Author | SHA1 | Date | |
|---|---|---|---|
| 9ac15eec79 | |||
| 03f565f50b | |||
| 47e2b961e2 | |||
|
|
b95b336372 | ||
| f35d7cb4bd | |||
| 54615e34d4 | |||
| 8752f4a139 | |||
| 453105d273 | |||
| cad0a0b217 | |||
| 9c0fd40e7b | |||
| c7a31c8bbb | |||
|
|
9900929349 | ||
|
|
e1ba299159 | ||
|
|
8de18d1788 | ||
| 06aabdbee6 | |||
|
|
c6f290bb56 | ||
| 49d3b9b96e | |||
| 280beb13cc | |||
| 3bc9351641 | |||
| 16b2c6b42b | |||
| fe31df0ef2 | |||
|
|
4c8681bfe2 | ||
|
|
d330a6ee23 | ||
|
|
b439759e9b | ||
| b11973cb64 | |||
|
|
df9a9a30bb | ||
|
|
2cd02c295f | ||
|
|
278fc1ff9c | ||
|
|
80eac5b957 | ||
|
|
0c9eed4bb7 | ||
|
|
d3d6d0bec7 | ||
|
|
3095510826 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -78,4 +78,3 @@ Sapfor/Sapc++/x64/
|
|||||||
|
|
||||||
Sapfor/out/
|
Sapfor/out/
|
||||||
Sapfor/_bin/*
|
Sapfor/_bin/*
|
||||||
_bin/*
|
|
||||||
|
|||||||
@@ -204,8 +204,6 @@ 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}
|
||||||
@@ -228,8 +226,7 @@ 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
|
||||||
@@ -462,7 +459,6 @@ 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})
|
||||||
|
|||||||
Submodule projects/dvm updated: 4b7ef11871...4d4041a081
@@ -124,18 +124,32 @@ static void SolveDataFlow(Region* DFG)
|
|||||||
map<LoopGraph*, ArrayAccessingIndexes> FindPrivateArrays(map<string, vector<LoopGraph*>> &loopGraph, map<FuncInfo*, vector<SAPFOR::BasicBlock*>>& FullIR)
|
map<LoopGraph*, ArrayAccessingIndexes> FindPrivateArrays(map<string, vector<LoopGraph*>> &loopGraph, map<FuncInfo*, vector<SAPFOR::BasicBlock*>>& FullIR)
|
||||||
{
|
{
|
||||||
map<LoopGraph*, ArrayAccessingIndexes> result;
|
map<LoopGraph*, ArrayAccessingIndexes> result;
|
||||||
for (const auto& [loopName, loops] : loopGraph)
|
for (const auto& [fileName, loops] : loopGraph)
|
||||||
{
|
{
|
||||||
|
SgFile::switchToFile(fileName);
|
||||||
for (const auto& loop : loops)
|
for (const auto& loop : loops)
|
||||||
{
|
{
|
||||||
|
SgStatement* search_func = loop->loop->GetOriginal();
|
||||||
|
|
||||||
|
while (search_func && (!isSgProgHedrStmt(search_func)))
|
||||||
|
search_func = search_func->controlParent();
|
||||||
|
|
||||||
for (const auto& [funcInfo, blocks]: FullIR)
|
for (const auto& [funcInfo, blocks]: FullIR)
|
||||||
|
{
|
||||||
|
if (funcInfo->fileName == fileName && funcInfo->funcPointer->GetOriginal() == search_func)
|
||||||
{
|
{
|
||||||
Region* loopRegion = new Region(loop, blocks);
|
Region* loopRegion = new Region(loop, blocks);
|
||||||
|
if (loopRegion->getBasickBlocks().size() <= 1)
|
||||||
|
{
|
||||||
|
delete(loopRegion);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
SolveDataFlow(loopRegion);
|
SolveDataFlow(loopRegion);
|
||||||
result[loop] = loopRegion->array_priv;
|
result[loop] = loopRegion->array_priv;
|
||||||
delete(loopRegion);
|
delete(loopRegion);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -89,7 +89,6 @@
|
|||||||
#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"
|
||||||
|
|
||||||
@@ -940,8 +939,6 @@ 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());
|
||||||
@@ -1022,8 +1019,6 @@ static bool runAnalysis(SgProject &project, const int curr_regime, const bool ne
|
|||||||
if(func->funcPointer->variant() != ENTRY_STAT)
|
if(func->funcPointer->variant() != ENTRY_STAT)
|
||||||
countOfTransform += removeDeadCode(func->funcPointer, allFuncInfo, commonBlocks);
|
countOfTransform += removeDeadCode(func->funcPointer, allFuncInfo, commonBlocks);
|
||||||
}
|
}
|
||||||
else if (curr_regime == FIND_PRIVATE_ARRAYS)
|
|
||||||
FindPrivateArrays(loopGraph, fullIR);
|
|
||||||
else if (curr_regime == TEST_PASS)
|
else if (curr_regime == TEST_PASS)
|
||||||
{
|
{
|
||||||
//test pass
|
//test pass
|
||||||
@@ -1040,8 +1035,7 @@ 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())
|
||||||
{
|
{
|
||||||
@@ -1920,6 +1914,8 @@ static bool runAnalysis(SgProject &project, const int curr_regime, const bool ne
|
|||||||
}
|
}
|
||||||
else if (curr_regime == TRANSFORM_ASSUMED_SIZE_PARAMETERS)
|
else if (curr_regime == TRANSFORM_ASSUMED_SIZE_PARAMETERS)
|
||||||
transformAssumedSizeParameters(allFuncInfo);
|
transformAssumedSizeParameters(allFuncInfo);
|
||||||
|
else if (curr_regime == FIND_PRIVATE_ARRAYS)
|
||||||
|
auto result = FindPrivateArrays(loopGraph, fullIR);
|
||||||
|
|
||||||
const float elapsed = duration_cast<milliseconds>(high_resolution_clock::now() - timeForPass).count() / 1000.;
|
const float elapsed = duration_cast<milliseconds>(high_resolution_clock::now() - timeForPass).count() / 1000.;
|
||||||
const float elapsedGlobal = duration_cast<milliseconds>(high_resolution_clock::now() - globalTime).count() / 1000.;
|
const float elapsedGlobal = duration_cast<milliseconds>(high_resolution_clock::now() - globalTime).count() / 1000.;
|
||||||
@@ -2338,7 +2334,6 @@ 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:
|
||||||
|
|||||||
@@ -122,8 +122,6 @@ 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,
|
||||||
@@ -321,7 +319,6 @@ 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";
|
||||||
|
|||||||
@@ -1,422 +0,0 @@
|
|||||||
#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;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool buildNewAST(SgStatement* loop, vector<SgStatement*>& newBody)
|
|
||||||
{
|
|
||||||
if (!loop) {return false;}
|
|
||||||
if (newBody.empty()) {return true;}
|
|
||||||
if (loop->variant() != FOR_NODE) {return false;}
|
|
||||||
|
|
||||||
SgStatement* loopStart = loop->lexNext();
|
|
||||||
SgStatement* loopEnd = loop->lastNodeOfStmt();
|
|
||||||
if (!loopStart || !loopEnd) {return false;}
|
|
||||||
|
|
||||||
for (SgStatement* stmt : newBody) {
|
|
||||||
if (stmt && stmt != loop && stmt != loopEnd) {
|
|
||||||
SgStatement* current = loopStart;
|
|
||||||
bool found = false;
|
|
||||||
while (current && current != loopEnd->lexNext()) {
|
|
||||||
if (current == stmt) {
|
|
||||||
found = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
current = current->lexNext();
|
|
||||||
}
|
|
||||||
if (!found) {return false;}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
vector<SgStatement*> extractedStatements;
|
|
||||||
vector<char*> savedComments;
|
|
||||||
vector<int> savedLineNumbers;
|
|
||||||
|
|
||||||
for (SgStatement* stmt : newBody) {
|
|
||||||
if (stmt && stmt != loop && stmt != loopEnd) {
|
|
||||||
savedComments.push_back(stmt->comments() ? strdup(stmt->comments()) : nullptr);
|
|
||||||
savedLineNumbers.push_back(stmt->lineNumber());
|
|
||||||
SgStatement* extracted = stmt->extractStmt();
|
|
||||||
if (extracted) {extractedStatements.push_back(extracted);}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
SgStatement* currentPos = loop;
|
|
||||||
int lineCounter = loop->lineNumber() + 1;
|
|
||||||
|
|
||||||
for (size_t i = 0; i < extractedStatements.size(); i++) {
|
|
||||||
SgStatement* stmt = extractedStatements[i];
|
|
||||||
if (stmt) {
|
|
||||||
if (i < savedComments.size() && savedComments[i]) {
|
|
||||||
stmt->setComments(savedComments[i]);
|
|
||||||
}
|
|
||||||
stmt->setlineNumber(lineCounter++);
|
|
||||||
currentPos->insertStmtAfter(*stmt, *loop);
|
|
||||||
currentPos = stmt;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (char* comment : savedComments) {
|
|
||||||
if (comment) {
|
|
||||||
free(comment);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (currentPos && currentPos->lexNext() != loopEnd) {
|
|
||||||
currentPos->setLexNext(*loopEnd);
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool validateNewOrder(SgStatement* loop, const vector<SgStatement*>& newOrder)
|
|
||||||
{
|
|
||||||
if (!loop || newOrder.empty()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
unordered_set<SgStatement*> seen;
|
|
||||||
for (SgStatement* stmt : newOrder) {
|
|
||||||
if (stmt && stmt != loop && stmt != loop->lastNodeOfStmt()) {
|
|
||||||
if (seen.count(stmt)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
seen.insert(stmt);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
|
|
||||||
if (validateNewOrder(loopForAnalyze.first, new_order)) {
|
|
||||||
buildNewAST(loopForAnalyze.first, new_order);
|
|
||||||
}
|
|
||||||
st = loopForAnalyze.first -> lexNext();
|
|
||||||
while (st != loopForAnalyze.first -> lastNodeOfStmt())
|
|
||||||
{
|
|
||||||
cout << st -> lineNumber() << " " << st -> sunparse() << endl;
|
|
||||||
st = st -> lexNext();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
};
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
#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,8 +212,6 @@ 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);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user