#include #include #include #include #include #include "../Utils/errors.h" #include "../Utils/SgUtils.h" #include "../GraphCall/graph_calls.h" #include "../GraphCall/graph_calls_func.h" #include "../CFGraph/CFGraph.h" #include "../CFGraph/IR.h" #include "../GraphLoop/graph_loops.h" #include "swapOperators.h" using namespace std; unordered_set loop_tags = {FOR_NODE/*, FORALL_NODE, WHILE_NODE, DO_WHILE_NODE*/}; vector findInstructionsFromOperator(SgStatement* st, vector Blocks) { vector result; string filename = st -> fileName(); for (auto& block: Blocks) { vector instructionsInBlock = block -> getInstructions(); for (auto& instruction: instructionsInBlock) { SgStatement* curOperator = instruction -> getInstruction() -> getOperator(); if (curOperator -> lineNumber() == st -> lineNumber()) result.push_back(instruction); } } return result; } vector findFuncBlocksByFuncStatement(SgStatement *st, std::map>& FullIR) { vector 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> findAndAnalyzeLoops(SgStatement *st, vector blocks) { map> 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> AnalyzeLoop(SgForStmt* forStatement, vector loopBlocks) { vector> 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>& loopGraph, std::map>& 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 blocks = findFuncBlocksByFuncStatement(st, FullIR); map> loopsMapping = findAndAnalyzeLoops(st, blocks); for (pair> loopForAnalyze: loopsMapping) { vector> moveRules = AnalyzeLoop(loopForAnalyze.first, loopForAnalyze.second); } } return; };