Add coefficients consideration in defuse
This commit is contained in:
@@ -126,7 +126,9 @@ set(OMEGA _src/SageAnalysisTool/OmegaForSage/add-assert.cpp
|
|||||||
_src/SageAnalysisTool/set.cpp)
|
_src/SageAnalysisTool/set.cpp)
|
||||||
|
|
||||||
set(PRIV _src/PrivateAnalyzer/private_analyzer.cpp
|
set(PRIV _src/PrivateAnalyzer/private_analyzer.cpp
|
||||||
_src/PrivateAnalyzer/private_analyzer.h)
|
_src/PrivateAnalyzer/private_analyzer.h
|
||||||
|
_src/PrivateAnalyzer/private_arrays_search.cpp
|
||||||
|
_src/PrivateAnalyzer/private_arrays_search.h)
|
||||||
|
|
||||||
set(FDVM ${fdvm_sources}/acc.cpp
|
set(FDVM ${fdvm_sources}/acc.cpp
|
||||||
${fdvm_sources}/acc_across.cpp
|
${fdvm_sources}/acc_across.cpp
|
||||||
@@ -195,8 +197,6 @@ 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
|
||||||
@@ -426,8 +426,7 @@ 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})
|
||||||
@@ -481,7 +480,6 @@ 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")
|
||||||
|
|||||||
@@ -445,12 +445,12 @@ static SAPFOR::Argument* processExpression(SgExpression* ex, vector<IR_Block*>&
|
|||||||
{
|
{
|
||||||
int numArgs = 0;
|
int numArgs = 0;
|
||||||
auto arg1 = createArrayArg(ex, blocks, func, numArgs, commonVars);
|
auto arg1 = createArrayArg(ex, blocks, func, numArgs, commonVars);
|
||||||
|
|
||||||
if (numArgs == 0)
|
if (numArgs == 0)
|
||||||
return arg1;
|
return arg1;
|
||||||
|
|
||||||
auto reg = isLeft ? NULL : createRegister();
|
auto reg = isLeft ? NULL : createRegister();
|
||||||
Instruction* instr = new Instruction(isLeft ? CFG_OP::STORE : CFG_OP::LOAD, arg1, createConstArg(numArgs), isLeft ? isLeft : reg);
|
Instruction* instr = new Instruction(isLeft ? CFG_OP::STORE : CFG_OP::LOAD, arg1, createConstArg(numArgs), isLeft ? isLeft : reg, NULL, ex);
|
||||||
blocks.push_back(new IR_Block(instr));
|
blocks.push_back(new IR_Block(instr));
|
||||||
return reg;
|
return reg;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,292 @@
|
|||||||
|
#include <map>
|
||||||
|
#include <unordered_set>
|
||||||
|
#include <unordered_map>
|
||||||
|
#include <vector>
|
||||||
|
#include <queue>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
#include "private_arrays_search.h"
|
||||||
|
#include "../Utils/SgUtils.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
void print_info(LoopGraph* loop)
|
||||||
|
{
|
||||||
|
cout << "loopSymbol: " << loop->loopSymbol << endl;
|
||||||
|
for (const auto& ops : loop->writeOpsForLoop)
|
||||||
|
{
|
||||||
|
cout << "Array name: " << ops.first->GetShortName() << 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*/
|
||||||
|
pair<SAPFOR::BasicBlock*, unordered_set<SAPFOR::BasicBlock*>> GetBasicBlocksForLoop(LoopGraph* loop, vector<SAPFOR::BasicBlock*> blocks)
|
||||||
|
{
|
||||||
|
unordered_set<SAPFOR::BasicBlock*> block_loop;
|
||||||
|
SAPFOR::BasicBlock* head_block = nullptr;
|
||||||
|
auto loop_operator = loop->loop->GetOriginal();
|
||||||
|
for (const 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 };
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void BuildLoopIndex(map<string, LoopGraph*>& loopForIndex, LoopGraph* loop) {
|
||||||
|
string index = loop->loopSymbol;
|
||||||
|
loopForIndex[index] = loop;
|
||||||
|
for (const auto& childLoop : loop->children) {
|
||||||
|
BuildLoopIndex(loopForIndex, childLoop);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
string FindIndexName(int pos, SAPFOR::BasicBlock* block, map<string, LoopGraph*>& loopForIndex) {
|
||||||
|
unordered_set<SAPFOR::Argument*> args = {block->getInstructions()[pos]->getInstruction()->getArg1()};
|
||||||
|
|
||||||
|
for (int i = pos-1; i >= 0; i--) {
|
||||||
|
SAPFOR::Argument* res = block->getInstructions()[i]->getInstruction()->getResult();
|
||||||
|
if (res && args.find(res) != args.end()) {
|
||||||
|
SAPFOR::Argument* arg1 = block->getInstructions()[i]->getInstruction()->getArg1();
|
||||||
|
SAPFOR::Argument* arg2 = block->getInstructions()[i]->getInstruction()->getArg2();
|
||||||
|
if (arg1) {
|
||||||
|
string name = arg1->getValue();
|
||||||
|
int idx = name.find('%');
|
||||||
|
if (idx != -1 && loopForIndex.find(name.substr(idx + 1)) != loopForIndex.end())
|
||||||
|
return name.substr(idx + 1);
|
||||||
|
else {
|
||||||
|
args.insert(arg1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (arg2) {
|
||||||
|
string name = arg2->getValue();
|
||||||
|
int idx = name.find('%');
|
||||||
|
if (idx != -1 && loopForIndex.find(name.substr(idx + 1)) != loopForIndex.end())
|
||||||
|
return name.substr(idx + 1);
|
||||||
|
else {
|
||||||
|
args.insert(arg2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
int GetDefUseArray(SAPFOR::BasicBlock* block, LoopGraph* loop, ArrayAccessingIndexes& def, ArrayAccessingIndexes& use) {
|
||||||
|
auto instructions = block->getInstructions();
|
||||||
|
map<string, LoopGraph*> loopForIndex;
|
||||||
|
BuildLoopIndex(loopForIndex, loop);
|
||||||
|
for(int i = 0; i < instructions.size(); i++)
|
||||||
|
{
|
||||||
|
auto instruction = instructions[i];
|
||||||
|
if(!instruction->getInstruction()->getArg1()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
auto operation = instruction->getInstruction()->getOperation();
|
||||||
|
auto type = instruction->getInstruction()->getArg1()->getType();
|
||||||
|
if ((operation == SAPFOR::CFG_OP::STORE && type == SAPFOR::CFG_ARG_TYPE::ARRAY) ||
|
||||||
|
(operation == SAPFOR::CFG_OP::LOAD && type == SAPFOR::CFG_ARG_TYPE::ARRAY))
|
||||||
|
{
|
||||||
|
|
||||||
|
vector<SAPFOR::Argument*> index_vars;
|
||||||
|
vector<int> refPos;
|
||||||
|
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_back(instructions[j]->getInstruction()->getArg1());
|
||||||
|
refPos.push_back(j);
|
||||||
|
j--;
|
||||||
|
}
|
||||||
|
/*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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SgArrayRefExp* ref = (SgArrayRefExp*)instruction->getInstruction()->getExpression();
|
||||||
|
vector<pair<int, int>> coefsForDims;
|
||||||
|
for (int i = 0; i < ref->numberOfSubscripts(); ++i)
|
||||||
|
{
|
||||||
|
const vector<int*>& coefs = getAttributes<SgExpression*, int*>(ref->subscript(i), set<int>{ INT_VAL });
|
||||||
|
if (coefs.size() == 1)
|
||||||
|
{
|
||||||
|
const pair<int, int> coef(coefs[0][0], coefs[0][1]);
|
||||||
|
coefsForDims.push_back(coef);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
while (!index_vars.empty())
|
||||||
|
{
|
||||||
|
auto var = index_vars.back();
|
||||||
|
int currentVarPos = refPos.back();
|
||||||
|
pair currentCoefs = coefsForDims.back();
|
||||||
|
ArrayDimension current_dim;
|
||||||
|
if (var->getType() == SAPFOR::CFG_ARG_TYPE::CONST) {
|
||||||
|
current_dim = { stoul(var->getValue()), 0, 1 };
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
string name, full_name = var->getValue();
|
||||||
|
int pos = full_name.find('%');
|
||||||
|
LoopGraph* currentLoop;
|
||||||
|
if (pos != -1) {
|
||||||
|
name = full_name.substr(pos+1);
|
||||||
|
if (loopForIndex.find(name) != loopForIndex.end()) {
|
||||||
|
currentLoop = loopForIndex[name];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
name = FindIndexName(currentVarPos, block, loopForIndex);
|
||||||
|
if (name == "") {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (loopForIndex.find(name) != loopForIndex.end()) {
|
||||||
|
currentLoop = loopForIndex[name];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
uint64_t start = currentLoop->startVal * currentCoefs.first + currentCoefs.second;
|
||||||
|
uint64_t step = currentCoefs.first;
|
||||||
|
current_dim = { start, step, (uint64_t)currentLoop->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_back();
|
||||||
|
refPos.pop_back();
|
||||||
|
coefsForDims.pop_back();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void FindPrivateArrays(map<string, vector<LoopGraph*>> &loopGraph, map<FuncInfo*, vector<SAPFOR::BasicBlock*>>& FullIR)
|
||||||
|
{
|
||||||
|
cout << "FindPrivateArrays\n";
|
||||||
|
for (const auto& curr_graph_pair: loopGraph)
|
||||||
|
{
|
||||||
|
for (const auto& curr_loop : curr_graph_pair.second)
|
||||||
|
{
|
||||||
|
auto block_loop = GetBasicBlocksForLoop(curr_loop, (*FullIR.begin()).second);
|
||||||
|
for (const auto& bb : block_loop.second) {
|
||||||
|
ArrayAccessingIndexes def, use;
|
||||||
|
//GetDefUseArray(bb, curr_loop, def, use);
|
||||||
|
}
|
||||||
|
ArrayAccessingIndexes loopDimensionsInfo;
|
||||||
|
//GetDimensionInfo(curr_loop, loopDimensionsInfo, 0);
|
||||||
|
//print_info(curr_loop);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void GetDimensionInfo(LoopGraph* loop, map<DIST::Array*, vector<vector<ArrayDimension>>>& loopDimensionsInfo, int level)
|
||||||
|
{
|
||||||
|
cout << "line_num: " << loop->lineNum << endl;
|
||||||
|
for (const auto& writeOpPairs : loop->writeOpsForLoop)
|
||||||
|
{
|
||||||
|
vector<vector<ArrayDimension>> arrayDimensions(writeOpPairs.first->GetDimSize());
|
||||||
|
loopDimensionsInfo[writeOpPairs.first] = arrayDimensions;
|
||||||
|
for (const auto& writeOp : writeOpPairs.second)
|
||||||
|
{
|
||||||
|
for (const auto& coeficient_pair : writeOp.coefficients)
|
||||||
|
{
|
||||||
|
uint64_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});
|
||||||
|
cout << "level: " << level << endl;
|
||||||
|
cout << "start: " << start << endl;
|
||||||
|
cout << "step: " << step << endl;
|
||||||
|
cout << "trip_count: " << tripCount << endl;
|
||||||
|
cout << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cout << "line_num_after: " << loop->lineNumAfterLoop << endl;
|
||||||
|
if (!loop->children.empty())
|
||||||
|
{
|
||||||
|
for (const auto& childLoop : loop->children)
|
||||||
|
{
|
||||||
|
GetDimensionInfo(childLoop, loopDimensionsInfo, level+1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
struct ArrayDimension
|
struct ArrayDimension
|
||||||
{
|
{
|
||||||
int64_t start, step, tripCount;
|
uint64_t start, step, tripCount;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::map<std::string, std::vector<std::vector<ArrayDimension>>> ArrayAccessingIndexes;
|
typedef std::map<std::string, std::vector<std::vector<ArrayDimension>>> ArrayAccessingIndexes;
|
||||||
@@ -1,195 +0,0 @@
|
|||||||
#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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -98,7 +98,7 @@
|
|||||||
|
|
||||||
#include "Inliner/inliner.h"
|
#include "Inliner/inliner.h"
|
||||||
|
|
||||||
#include "PrivateArrays/private_arrays_search.h"
|
#include "PrivateAnalyzer/private_arrays_search.h"
|
||||||
|
|
||||||
#include "dvm.h"
|
#include "dvm.h"
|
||||||
#include "Sapfor.h"
|
#include "Sapfor.h"
|
||||||
@@ -1894,7 +1894,10 @@ static bool runAnalysis(SgProject &project, const int curr_regime, const bool ne
|
|||||||
doDumpLive(fullIR);
|
doDumpLive(fullIR);
|
||||||
}
|
}
|
||||||
else if (curr_regime == PRIVATE_ANALYSIS_IR)
|
else if (curr_regime == PRIVATE_ANALYSIS_IR)
|
||||||
|
{
|
||||||
runPrivateVariableAnalysis(loopGraph, fullIR, commonBlocks, SPF_messages);
|
runPrivateVariableAnalysis(loopGraph, fullIR, commonBlocks, SPF_messages);
|
||||||
|
FindPrivateArrays(loopGraph, fullIR);
|
||||||
|
}
|
||||||
else if (curr_regime == FIX_COMMON_BLOCKS)
|
else if (curr_regime == FIX_COMMON_BLOCKS)
|
||||||
fixCommonBlocks(allFuncInfo, commonBlocks, &project);
|
fixCommonBlocks(allFuncInfo, commonBlocks, &project);
|
||||||
else if (curr_regime == GET_MIN_MAX_BLOCK_DIST)
|
else if (curr_regime == GET_MIN_MAX_BLOCK_DIST)
|
||||||
@@ -1904,9 +1907,6 @@ 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,8 +182,6 @@ enum passes {
|
|||||||
SET_IMPLICIT_NONE,
|
SET_IMPLICIT_NONE,
|
||||||
RENAME_INLCUDES,
|
RENAME_INLCUDES,
|
||||||
|
|
||||||
FIND_PRIVATE_ARRAYS,
|
|
||||||
|
|
||||||
TEST_PASS,
|
TEST_PASS,
|
||||||
EMPTY_PASS
|
EMPTY_PASS
|
||||||
};
|
};
|
||||||
@@ -368,7 +366,6 @@ 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";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -301,7 +301,7 @@ void InitPassesDependencies(map<passes, vector<passes>> &passDepsIn, set<passes>
|
|||||||
|
|
||||||
list({ BUILD_IR, CALL_GRAPH }) <= Pass(LIVE_ANALYSIS_IR);
|
list({ BUILD_IR, CALL_GRAPH }) <= Pass(LIVE_ANALYSIS_IR);
|
||||||
|
|
||||||
list({ BUILD_IR, LOOP_GRAPH, LIVE_ANALYSIS_IR }) <= Pass(PRIVATE_ANALYSIS_IR);
|
list({ BUILD_IR, LOOP_GRAPH, LIVE_ANALYSIS_IR, ARRAY_ACCESS_ANALYSIS_FOR_CORNER }) <= Pass(PRIVATE_ANALYSIS_IR);
|
||||||
|
|
||||||
Pass(FILE_LINE_INFO) <= Pass(GET_MIN_MAX_BLOCK_DIST);
|
Pass(FILE_LINE_INFO) <= Pass(GET_MIN_MAX_BLOCK_DIST);
|
||||||
|
|
||||||
@@ -314,7 +314,6 @@ 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,
|
||||||
|
|||||||
Reference in New Issue
Block a user