Compare commits
2 Commits
libpredict
...
3682f7aa59
| Author | SHA1 | Date | |
|---|---|---|---|
| 3682f7aa59 | |||
| 400c378691 |
@@ -126,7 +126,9 @@ set(OMEGA _src/SageAnalysisTool/OmegaForSage/add-assert.cpp
|
||||
_src/SageAnalysisTool/set.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
|
||||
${fdvm_sources}/acc_across.cpp
|
||||
@@ -196,6 +198,7 @@ set(TR_IMPLICIT_NONE _src/Transformations/set_implicit_none.cpp
|
||||
set(TR_REPLACE_ARRAYS_IN_IO _src/Transformations/replace_dist_arrays_in_io.cpp
|
||||
_src/Transformations/replace_dist_arrays_in_io.h)
|
||||
|
||||
|
||||
set(TRANSFORMS
|
||||
${TR_DEAD_CODE}
|
||||
${TR_CP}
|
||||
@@ -477,6 +480,7 @@ source_group (Parser FILES ${PARSER})
|
||||
source_group (PPPA\\PPPA FILES ${PPPA})
|
||||
source_group (PPPA\\ZLib FILES ${ZLIB})
|
||||
|
||||
|
||||
if (MSVC_IDE)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP /Zc:__cplusplus")
|
||||
else()
|
||||
|
||||
@@ -450,7 +450,7 @@ static SAPFOR::Argument* processExpression(SgExpression* ex, vector<IR_Block*>&
|
||||
return arg1;
|
||||
|
||||
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));
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include "../GraphLoop/graph_loops.h"
|
||||
#include "../CFGraph/CFGraph.h"
|
||||
|
||||
struct ArrayDimension
|
||||
{
|
||||
uint64_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 "PrivateAnalyzer/private_arrays_search.h"
|
||||
|
||||
#include "dvm.h"
|
||||
#include "Sapfor.h"
|
||||
#include "Utils/PassManager.h"
|
||||
@@ -1892,7 +1894,10 @@ static bool runAnalysis(SgProject &project, const int curr_regime, const bool ne
|
||||
doDumpLive(fullIR);
|
||||
}
|
||||
else if (curr_regime == PRIVATE_ANALYSIS_IR)
|
||||
{
|
||||
runPrivateVariableAnalysis(loopGraph, fullIR, commonBlocks, SPF_messages);
|
||||
FindPrivateArrays(loopGraph, fullIR);
|
||||
}
|
||||
else if (curr_regime == FIX_COMMON_BLOCKS)
|
||||
fixCommonBlocks(allFuncInfo, commonBlocks, &project);
|
||||
else if (curr_regime == GET_MIN_MAX_BLOCK_DIST)
|
||||
@@ -1902,7 +1907,6 @@ static bool runAnalysis(SgProject &project, const int curr_regime, const bool ne
|
||||
calculateStatsForPredictor(allFuncInfo, gCovInfo);
|
||||
parseDvmDirForPredictor(declaredArrays, commonBlocks, allFuncInfo, gCovInfo);
|
||||
}
|
||||
|
||||
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.;
|
||||
__spf_print(1, "PROFILE: time for this pass = %f sec (total %f sec)\n", elapsed, elapsedGlobal);
|
||||
|
||||
@@ -366,6 +366,7 @@ static void setPassValues()
|
||||
passNames[RENAME_INLCUDES] = "RENAME_INLCUDES";
|
||||
passNames[INSERT_NO_DISTR_FLAGS_FROM_GUI] = "INSERT_NO_DISTR_FLAGS_FROM_GUI";
|
||||
|
||||
|
||||
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, 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);
|
||||
|
||||
@@ -314,6 +314,7 @@ void InitPassesDependencies(map<passes, vector<passes>> &passDepsIn, set<passes>
|
||||
|
||||
list({ VERIFY_INCLUDES, CORRECT_VAR_DECL }) <= Pass(SET_IMPLICIT_NONE);
|
||||
|
||||
|
||||
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,
|
||||
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