get def use for array
This commit is contained in:
@@ -195,6 +195,9 @@ set(TR_IMPLICIT_NONE _src/Transformations/set_implicit_none.cpp
|
|||||||
_src/Transformations/set_implicit_none.h)
|
_src/Transformations/set_implicit_none.h)
|
||||||
set(TR_REPLACE_ARRAYS_IN_IO _src/Transformations/replace_dist_arrays_in_io.cpp
|
set(TR_REPLACE_ARRAYS_IN_IO _src/Transformations/replace_dist_arrays_in_io.cpp
|
||||||
_src/Transformations/replace_dist_arrays_in_io.h)
|
_src/Transformations/replace_dist_arrays_in_io.h)
|
||||||
|
set(FIND_PRIVATE_ARRAYS _src/PrivateArrays/private_arrays_search.cpp
|
||||||
|
_src/PrivateArrays/private_arrays_search.h)
|
||||||
|
|
||||||
|
|
||||||
set(TRANSFORMS
|
set(TRANSFORMS
|
||||||
${TR_DEAD_CODE}
|
${TR_DEAD_CODE}
|
||||||
@@ -423,7 +426,8 @@ set(SOURCE_EXE
|
|||||||
${ZLIB}
|
${ZLIB}
|
||||||
${GR_LAYOUT}
|
${GR_LAYOUT}
|
||||||
${PR_PARAM}
|
${PR_PARAM}
|
||||||
${PROJ_MAN})
|
${PROJ_MAN}
|
||||||
|
${FIND_PRIVATE_ARRAYS})
|
||||||
|
|
||||||
add_executable(Sapfor_F ${SOURCE_EXE})
|
add_executable(Sapfor_F ${SOURCE_EXE})
|
||||||
source_group (CFGraph FILES ${CFG})
|
source_group (CFGraph FILES ${CFG})
|
||||||
@@ -477,6 +481,8 @@ source_group (Parser FILES ${PARSER})
|
|||||||
source_group (PPPA\\PPPA FILES ${PPPA})
|
source_group (PPPA\\PPPA FILES ${PPPA})
|
||||||
source_group (PPPA\\ZLib FILES ${ZLIB})
|
source_group (PPPA\\ZLib FILES ${ZLIB})
|
||||||
|
|
||||||
|
source_group (PrivateArrays FILES ${FIND_PRIVATE_ARRAYS})
|
||||||
|
|
||||||
if (MSVC_IDE)
|
if (MSVC_IDE)
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP /Zc:__cplusplus")
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP /Zc:__cplusplus")
|
||||||
else()
|
else()
|
||||||
|
|||||||
@@ -0,0 +1,195 @@
|
|||||||
|
#include <map>
|
||||||
|
#include <unordered_set>
|
||||||
|
#include <vector>
|
||||||
|
#include <queue>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
#include "private_arrays_search.h"
|
||||||
|
|
||||||
|
void print_info(LoopGraph* loop)
|
||||||
|
{
|
||||||
|
std::cout << "loopSymbol: " << loop->loopSymbol << std::endl;
|
||||||
|
for (const auto ops : loop->writeOpsForLoop)
|
||||||
|
{
|
||||||
|
std::cout << "Array name: " << ops.first->GetShortName() << std::endl;
|
||||||
|
for (const auto i : ops.second)
|
||||||
|
{
|
||||||
|
i.printInfo();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!loop->children.empty())
|
||||||
|
{
|
||||||
|
for (const auto child : loop->children)
|
||||||
|
{
|
||||||
|
print_info(child);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool isParentStmt(SgStatement* stmt, SgStatement* parent)
|
||||||
|
{
|
||||||
|
for (; stmt; stmt = stmt->controlParent())
|
||||||
|
if (stmt == parent)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*returns head block and loop*/
|
||||||
|
std::pair<SAPFOR::BasicBlock*, std::unordered_set<SAPFOR::BasicBlock*>> GetBasicBlocksForLoop(LoopGraph* loop, std::vector<SAPFOR::BasicBlock*> blocks)
|
||||||
|
{
|
||||||
|
std::unordered_set<SAPFOR::BasicBlock*> block_loop;
|
||||||
|
SAPFOR::BasicBlock* head_block = nullptr;
|
||||||
|
auto loop_operator = loop->loop->GetOriginal();
|
||||||
|
for (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 };
|
||||||
|
}
|
||||||
|
|
||||||
|
LoopGraph* FindLoopForIndex(std::string var_name, LoopGraph* loop)
|
||||||
|
{
|
||||||
|
if (loop->loopSymbol == var_name)
|
||||||
|
return loop;
|
||||||
|
else if (loop->children.empty()) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (auto& child : loop->children)
|
||||||
|
{
|
||||||
|
LoopGraph* res = FindLoopForIndex(var_name, child);
|
||||||
|
if (res)
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void GetDefUseArray(SAPFOR::BasicBlock* block, LoopGraph* loop, ArrayAccessingIndexes& def, ArrayAccessingIndexes& use) {
|
||||||
|
|
||||||
|
auto instructions = block->getInstructions();
|
||||||
|
for(int i = 0; i < instructions.size(); i++)
|
||||||
|
{
|
||||||
|
auto instruction = instructions[i];
|
||||||
|
if ((instruction->getInstruction()->getOperation() == SAPFOR::CFG_OP::STORE && instruction->getInstruction()->getArg1()->getType() == SAPFOR::CFG_ARG_TYPE::ARRAY) ||
|
||||||
|
(instruction->getInstruction()->getOperation() == SAPFOR::CFG_OP::LOAD && instruction->getInstruction()->getArg2()->getType() == SAPFOR::CFG_ARG_TYPE::ARRAY))
|
||||||
|
{
|
||||||
|
SAPFOR::CFG_OP operation = instruction->getInstruction()->getOperation();
|
||||||
|
std::queue<SAPFOR::Argument*> index_vars;
|
||||||
|
std::string array_name;
|
||||||
|
if(operation == SAPFOR::CFG_OP::STORE)
|
||||||
|
array_name = instruction->getInstruction()->getArg1()->getValue();
|
||||||
|
else
|
||||||
|
array_name = instruction->getInstruction()->getArg2()->getValue();
|
||||||
|
int j = i - 1;
|
||||||
|
while (j >= 0 && instructions[j]->getInstruction()->getOperation() == SAPFOR::CFG_OP::REF)
|
||||||
|
{
|
||||||
|
index_vars.push(instructions[j]->getInstruction()->getArg1());
|
||||||
|
}
|
||||||
|
/*to choose correct dimension*/
|
||||||
|
int n = index_vars.size();
|
||||||
|
if (operation == SAPFOR::CFG_OP::STORE)
|
||||||
|
{
|
||||||
|
if (def[array_name].empty())
|
||||||
|
def[array_name].resize(n);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (use[array_name].empty())
|
||||||
|
use[array_name].resize(n);
|
||||||
|
}
|
||||||
|
while (!index_vars.empty())
|
||||||
|
{
|
||||||
|
auto var = index_vars.front();
|
||||||
|
ArrayDimension current_dim;
|
||||||
|
if (var->getType() == SAPFOR::CFG_ARG_TYPE::CONST) {
|
||||||
|
current_dim = { stol(var->getValue()), 0, 1 };
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::string full_name = var->getValue();
|
||||||
|
int pos = full_name.find('%');
|
||||||
|
LoopGraph* current_loop = FindLoopForIndex(full_name.substr(pos), loop);
|
||||||
|
current_dim = { loop->startVal, loop->stepVal, loop->calculatedCountOfIters };
|
||||||
|
}
|
||||||
|
if (operation == SAPFOR::CFG_OP::STORE)
|
||||||
|
def[array_name][n - index_vars.size()].push_back(current_dim);
|
||||||
|
else
|
||||||
|
use[array_name][n - index_vars.size()].push_back(current_dim);
|
||||||
|
index_vars.pop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void FindPrivateArrays(std::map<std::string, std::vector<LoopGraph*>> &loopGraph, std::map<FuncInfo*, std::vector<SAPFOR::BasicBlock*>>& FullIR)
|
||||||
|
{
|
||||||
|
for (const auto& curr_graph_pair: loopGraph)
|
||||||
|
{
|
||||||
|
for (const auto& curr_loop : curr_graph_pair.second)
|
||||||
|
{
|
||||||
|
ArrayAccessingIndexes loopDimensionsInfo;
|
||||||
|
//GetDimensionInfo(curr_loop, loopDimensionsInfo, 0);
|
||||||
|
//print_info(curr_loop);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void GetDimensionInfo(LoopGraph* loop, std::map<DIST::Array*, std::vector<std::vector<ArrayDimension>>>& loopDimensionsInfo, int level)
|
||||||
|
{
|
||||||
|
std::cout << "line_num: " << loop->lineNum << std::endl;
|
||||||
|
for (const auto& writeOpPairs : loop->writeOpsForLoop)
|
||||||
|
{
|
||||||
|
std::vector<std::vector<ArrayDimension>> arrayDimensions(writeOpPairs.first->GetDimSize());
|
||||||
|
loopDimensionsInfo[writeOpPairs.first] = arrayDimensions;
|
||||||
|
for (const auto& writeOp : writeOpPairs.second)
|
||||||
|
{
|
||||||
|
for (const auto& coeficient_pair : writeOp.coefficients)
|
||||||
|
{
|
||||||
|
int64_t start, step, tripCount;
|
||||||
|
start = loop->startVal * coeficient_pair.first.first + coeficient_pair.first.second;
|
||||||
|
step = loop->stepVal * coeficient_pair.first.first;
|
||||||
|
tripCount = (loop->endVal - coeficient_pair.first.second) / step;
|
||||||
|
if (start <= loop->endVal)
|
||||||
|
{
|
||||||
|
loopDimensionsInfo[writeOpPairs.first][level].push_back({start, step, tripCount});
|
||||||
|
std::cout << "level: " << level << std::endl;
|
||||||
|
std::cout << "start: " << start << std::endl;
|
||||||
|
std::cout << "step: " << step << std::endl;
|
||||||
|
std::cout << "trip_count: " << tripCount << std::endl;
|
||||||
|
std::cout << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
std::cout << "line_num_after: " << loop->lineNumAfterLoop << std::endl;
|
||||||
|
if (!loop->children.empty())
|
||||||
|
{
|
||||||
|
for (const auto& childLoop : loop->children)
|
||||||
|
{
|
||||||
|
GetDimensionInfo(childLoop, loopDimensionsInfo, level+1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "../GraphLoop/graph_loops.h"
|
||||||
|
#include "../CFGraph/CFGraph.h"
|
||||||
|
|
||||||
|
struct ArrayDimension
|
||||||
|
{
|
||||||
|
int64_t start, step, tripCount;
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef std::map<std::string, std::vector<std::vector<ArrayDimension>>> ArrayAccessingIndexes;
|
||||||
|
|
||||||
|
void FindPrivateArrays(std::map<std::string, std::vector<LoopGraph*>>& loopGraph, std::map<FuncInfo*, std::vector<SAPFOR::BasicBlock*>>& FullIR);
|
||||||
|
void GetDimensionInfo(LoopGraph* loop, std::map<DIST::Array*, std::vector<std::vector<ArrayDimension>>>& loopDimensionsInfo, int level);
|
||||||
|
std::set<SAPFOR::BasicBlock> GetBasicBlocksForLoop(LoopGraph* loop, std::vector<SAPFOR::BasicBlock>);
|
||||||
@@ -98,6 +98,8 @@
|
|||||||
|
|
||||||
#include "Inliner/inliner.h"
|
#include "Inliner/inliner.h"
|
||||||
|
|
||||||
|
#include "PrivateArrays/private_arrays_search.h"
|
||||||
|
|
||||||
#include "dvm.h"
|
#include "dvm.h"
|
||||||
#include "Sapfor.h"
|
#include "Sapfor.h"
|
||||||
#include "Utils/PassManager.h"
|
#include "Utils/PassManager.h"
|
||||||
@@ -1902,7 +1904,9 @@ static bool runAnalysis(SgProject &project, const int curr_regime, const bool ne
|
|||||||
calculateStatsForPredictor(allFuncInfo, gCovInfo);
|
calculateStatsForPredictor(allFuncInfo, gCovInfo);
|
||||||
parseDvmDirForPredictor(declaredArrays, commonBlocks, allFuncInfo, gCovInfo);
|
parseDvmDirForPredictor(declaredArrays, commonBlocks, allFuncInfo, gCovInfo);
|
||||||
}
|
}
|
||||||
|
else if (curr_regime == FIND_PRIVATE_ARRAYS) {
|
||||||
|
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.;
|
||||||
__spf_print(1, "PROFILE: time for this pass = %f sec (total %f sec)\n", elapsed, elapsedGlobal);
|
__spf_print(1, "PROFILE: time for this pass = %f sec (total %f sec)\n", elapsed, elapsedGlobal);
|
||||||
|
|||||||
@@ -182,6 +182,8 @@ enum passes {
|
|||||||
SET_IMPLICIT_NONE,
|
SET_IMPLICIT_NONE,
|
||||||
RENAME_INLCUDES,
|
RENAME_INLCUDES,
|
||||||
|
|
||||||
|
FIND_PRIVATE_ARRAYS,
|
||||||
|
|
||||||
TEST_PASS,
|
TEST_PASS,
|
||||||
EMPTY_PASS
|
EMPTY_PASS
|
||||||
};
|
};
|
||||||
@@ -366,6 +368,8 @@ static void setPassValues()
|
|||||||
passNames[RENAME_INLCUDES] = "RENAME_INLCUDES";
|
passNames[RENAME_INLCUDES] = "RENAME_INLCUDES";
|
||||||
passNames[INSERT_NO_DISTR_FLAGS_FROM_GUI] = "INSERT_NO_DISTR_FLAGS_FROM_GUI";
|
passNames[INSERT_NO_DISTR_FLAGS_FROM_GUI] = "INSERT_NO_DISTR_FLAGS_FROM_GUI";
|
||||||
|
|
||||||
|
passNames[FIND_PRIVATE_ARRAYS] = "FIND_PRIVATE_ARRAYS";
|
||||||
|
|
||||||
passNames[TEST_PASS] = "TEST_PASS";
|
passNames[TEST_PASS] = "TEST_PASS";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -314,6 +314,8 @@ void InitPassesDependencies(map<passes, vector<passes>> &passDepsIn, set<passes>
|
|||||||
|
|
||||||
list({ VERIFY_INCLUDES, CORRECT_VAR_DECL }) <= Pass(SET_IMPLICIT_NONE);
|
list({ VERIFY_INCLUDES, CORRECT_VAR_DECL }) <= Pass(SET_IMPLICIT_NONE);
|
||||||
|
|
||||||
|
list({ CALL_GRAPH2, LOOP_ANALYZER_DATA_DIST_S1 }) <= Pass(FIND_PRIVATE_ARRAYS);
|
||||||
|
|
||||||
passesIgnoreStateDone.insert({ CREATE_PARALLEL_DIRS, INSERT_PARALLEL_DIRS, INSERT_SHADOW_DIRS, EXTRACT_PARALLEL_DIRS,
|
passesIgnoreStateDone.insert({ CREATE_PARALLEL_DIRS, INSERT_PARALLEL_DIRS, INSERT_SHADOW_DIRS, EXTRACT_PARALLEL_DIRS,
|
||||||
EXTRACT_SHADOW_DIRS, CREATE_REMOTES, UNPARSE_FILE, REMOVE_AND_CALC_SHADOW,
|
EXTRACT_SHADOW_DIRS, CREATE_REMOTES, UNPARSE_FILE, REMOVE_AND_CALC_SHADOW,
|
||||||
REVERSE_CREATED_NESTED_LOOPS, PREDICT_SCHEME, CALCULATE_STATS_SCHEME, REVERT_SPF_DIRS, CLEAR_SPF_DIRS, TRANSFORM_SHADOW_IF_FULL,
|
REVERSE_CREATED_NESTED_LOOPS, PREDICT_SCHEME, CALCULATE_STATS_SCHEME, REVERT_SPF_DIRS, CLEAR_SPF_DIRS, TRANSFORM_SHADOW_IF_FULL,
|
||||||
|
|||||||
Reference in New Issue
Block a user