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