2023-09-14 19:43:13 +03:00
|
|
|
#include "dvm.h"
|
|
|
|
|
#include "aks_structs.h"
|
2023-12-16 17:42:11 +03:00
|
|
|
#include <vector>
|
|
|
|
|
#include <map>
|
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
|
|
using std::vector;
|
|
|
|
|
using std::string;
|
|
|
|
|
using std::map;
|
2023-09-14 19:43:13 +03:00
|
|
|
|
|
|
|
|
#define DEBUG_LV1 true
|
|
|
|
|
#if 1
|
|
|
|
|
std::ostream &out = std::cout;
|
|
|
|
|
#else
|
|
|
|
|
std::ofstream out("_log_debug_info.txt");
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
extern SgStatement *dvm_parallel_dir;
|
|
|
|
|
|
|
|
|
|
SgExpression* findDirect(SgExpression *inExpr, int DIR)
|
|
|
|
|
{
|
|
|
|
|
SgExpression *temp = NULL;
|
|
|
|
|
if (inExpr)
|
|
|
|
|
{
|
|
|
|
|
if (inExpr->variant() == DIR)
|
|
|
|
|
return inExpr;
|
|
|
|
|
else
|
|
|
|
|
{
|
2023-12-16 17:42:11 +03:00
|
|
|
if (inExpr->lhs())
|
|
|
|
|
temp = findDirect(inExpr->lhs(), DIR);
|
2023-09-14 19:43:13 +03:00
|
|
|
|
2023-12-16 17:42:11 +03:00
|
|
|
if(temp == NULL && inExpr->rhs())
|
2023-09-14 19:43:13 +03:00
|
|
|
temp = findDirect(inExpr->rhs(), DIR);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return temp;
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-16 17:42:11 +03:00
|
|
|
static vector<SgSymbol*> fillDataOfArray(SgExpression* on, int& dimInPar)
|
2023-09-14 19:43:13 +03:00
|
|
|
{
|
|
|
|
|
dimInPar = 0;
|
|
|
|
|
SgExpression* temp = on;
|
|
|
|
|
while (temp)
|
|
|
|
|
{
|
|
|
|
|
dimInPar++;
|
|
|
|
|
temp = temp->rhs();
|
|
|
|
|
}
|
2023-12-16 17:42:11 +03:00
|
|
|
|
|
|
|
|
vector<SgSymbol*> symbInPar(dimInPar);
|
2023-09-14 19:43:13 +03:00
|
|
|
temp = on;
|
|
|
|
|
for (int i = 0; i < dimInPar; ++i)
|
|
|
|
|
{
|
|
|
|
|
symbInPar[i] = temp->lhs()->symbol();
|
|
|
|
|
temp = temp->rhs();
|
|
|
|
|
}
|
|
|
|
|
return symbInPar;
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-16 17:42:11 +03:00
|
|
|
static void printError()
|
|
|
|
|
{
|
|
|
|
|
err("internal error in across", 424, first_do_par);
|
|
|
|
|
exit(-1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static vector<SageArrayIdxs> GetIdxInParDir(const map<string, SgExpression*>& on, SgExpression *across, bool tie = false)
|
2023-09-14 19:43:13 +03:00
|
|
|
{
|
2023-12-16 17:42:11 +03:00
|
|
|
vector<SageArrayIdxs> ret;
|
|
|
|
|
|
2023-09-14 19:43:13 +03:00
|
|
|
int dimInPar = 0;
|
2023-12-16 17:42:11 +03:00
|
|
|
vector<SgSymbol*> symbInPar;
|
|
|
|
|
vector<SgExpression*> toAnalyze;
|
|
|
|
|
|
2023-09-14 19:43:13 +03:00
|
|
|
if (across->lhs()->variant() == EXPR_LIST)
|
|
|
|
|
toAnalyze.push_back(across->lhs());
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (across->lhs()->variant() == DDOT)
|
|
|
|
|
toAnalyze.push_back(across->lhs()->rhs());
|
|
|
|
|
if (across->rhs())
|
|
|
|
|
if (across->rhs()->variant() == DDOT)
|
|
|
|
|
toAnalyze.push_back(across->rhs()->rhs());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < toAnalyze.size(); ++i)
|
|
|
|
|
{
|
|
|
|
|
across = toAnalyze[i];
|
|
|
|
|
while (across)
|
|
|
|
|
{
|
2023-12-16 17:42:11 +03:00
|
|
|
if (symbInPar.size() == 0)
|
2023-09-14 19:43:13 +03:00
|
|
|
{
|
|
|
|
|
if (on.size() == 0)
|
2023-12-16 17:42:11 +03:00
|
|
|
printError();
|
2023-09-14 19:43:13 +03:00
|
|
|
else if (on.size() == 1)
|
2023-12-16 17:42:11 +03:00
|
|
|
symbInPar = fillDataOfArray(on.begin()->second, dimInPar);
|
2023-09-14 19:43:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SgExpression *t = across->lhs();
|
|
|
|
|
int dim = 0;
|
|
|
|
|
|
|
|
|
|
if (tie)
|
|
|
|
|
{
|
|
|
|
|
if (t->variant() == ARRAY_REF)
|
|
|
|
|
{
|
|
|
|
|
if (on.find(t->symbol()->identifier()) == on.end())
|
2023-12-16 17:42:11 +03:00
|
|
|
printError();
|
2023-09-14 19:43:13 +03:00
|
|
|
else
|
|
|
|
|
symbInPar = fillDataOfArray(on.find(t->symbol()->identifier())->second, dimInPar);
|
|
|
|
|
}
|
|
|
|
|
else if (t->variant() == ARRAY_OP)
|
|
|
|
|
{
|
|
|
|
|
if (on.find(t->lhs()->symbol()->identifier()) == on.end())
|
2023-12-16 17:42:11 +03:00
|
|
|
printError();
|
2023-09-14 19:43:13 +03:00
|
|
|
else
|
|
|
|
|
symbInPar = fillDataOfArray(on.find(t->lhs()->symbol()->identifier())->second, dimInPar);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (t->variant() == ARRAY_REF)
|
|
|
|
|
t = t->lhs();
|
|
|
|
|
else if (t->variant() == ARRAY_OP)
|
|
|
|
|
t = t->lhs()->lhs();
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (DEBUG_LV1)
|
|
|
|
|
out << "!!! unknown variant in ACROSS dir: " << t->variant() << std::endl;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SgExpression *tmp = t;
|
|
|
|
|
while (tmp)
|
|
|
|
|
{
|
|
|
|
|
dim++;
|
|
|
|
|
tmp = tmp->rhs();
|
|
|
|
|
}
|
2023-12-16 17:42:11 +03:00
|
|
|
|
|
|
|
|
SageArrayIdxs act;
|
|
|
|
|
|
|
|
|
|
act.symb.resize(dim);
|
|
|
|
|
act.dim = dim;
|
2023-09-14 19:43:13 +03:00
|
|
|
for (int i = 0; i < dim; ++i)
|
|
|
|
|
{
|
2023-12-16 17:42:11 +03:00
|
|
|
act.symb[i].across_left = t->lhs()->lhs()->valueInteger();
|
|
|
|
|
act.symb[i].across_right = t->lhs()->rhs()->valueInteger();
|
|
|
|
|
if (act.symb[i].across_left != 0 || act.symb[i].across_right != 0)
|
|
|
|
|
act.symb[i].symb = symbInPar[i];
|
2023-09-14 19:43:13 +03:00
|
|
|
else if (i < dimInPar)
|
2023-12-16 17:42:11 +03:00
|
|
|
act.symb[i].symb = symbInPar[i];
|
2023-09-14 19:43:13 +03:00
|
|
|
else
|
2023-12-16 17:42:11 +03:00
|
|
|
act.symb[i].symb = NULL;
|
2023-09-14 19:43:13 +03:00
|
|
|
t = t->rhs();
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-16 17:42:11 +03:00
|
|
|
ret.push_back(act);
|
2023-09-14 19:43:13 +03:00
|
|
|
across = across->rhs();
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-12-16 17:42:11 +03:00
|
|
|
|
2023-09-14 19:43:13 +03:00
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-16 17:42:11 +03:00
|
|
|
SageAcrossInfo GetLoopsWithParAndAcrDir()
|
2023-09-14 19:43:13 +03:00
|
|
|
{
|
2023-12-16 17:42:11 +03:00
|
|
|
SageAcrossInfo retVal;
|
2023-09-14 19:43:13 +03:00
|
|
|
SgStatement *temp = dvm_parallel_dir;
|
|
|
|
|
|
|
|
|
|
if (temp->variant() == DVM_PARALLEL_ON_DIR)
|
|
|
|
|
{
|
|
|
|
|
SgExpression *t = findDirect(temp->expr(1), ACROSS_OP);
|
|
|
|
|
SgExpression *tie = findDirect(temp->expr(1), ACC_TIE_OP);
|
2023-12-16 17:42:11 +03:00
|
|
|
|
|
|
|
|
map<string, SgExpression*> arrays;
|
2023-09-14 19:43:13 +03:00
|
|
|
if (t != NULL)
|
|
|
|
|
{
|
|
|
|
|
if (temp->expr(0) && temp->expr(0)->lhs())
|
|
|
|
|
{
|
|
|
|
|
arrays[temp->expr(0)->symbol()->identifier()] = temp->expr(0)->lhs();
|
2023-12-16 17:42:11 +03:00
|
|
|
retVal.idxs = GetIdxInParDir(arrays, t);
|
|
|
|
|
}
|
2023-09-14 19:43:13 +03:00
|
|
|
else if (tie)
|
|
|
|
|
{
|
|
|
|
|
SgExpression* list = tie->lhs();
|
|
|
|
|
while (list)
|
|
|
|
|
{
|
|
|
|
|
arrays[list->lhs()->symbol()->identifier()] = list->lhs()->lhs();
|
|
|
|
|
list = list->rhs();
|
|
|
|
|
}
|
2023-12-16 17:42:11 +03:00
|
|
|
retVal.idxs = GetIdxInParDir(arrays, t, true);
|
2023-09-14 19:43:13 +03:00
|
|
|
}
|
|
|
|
|
else
|
2023-12-16 17:42:11 +03:00
|
|
|
printError();
|
2023-09-14 19:43:13 +03:00
|
|
|
}
|
2023-12-16 17:42:11 +03:00
|
|
|
}
|
|
|
|
|
return retVal;
|
2023-09-14 19:43:13 +03:00
|
|
|
}
|
|
|
|
|
|
2023-12-16 17:42:11 +03:00
|
|
|
vector<SageSymbols> GetSymbInParalell(SgExpression *first)
|
2023-09-14 19:43:13 +03:00
|
|
|
{
|
2023-12-16 17:42:11 +03:00
|
|
|
vector<SageSymbols> retval;
|
2023-09-14 19:43:13 +03:00
|
|
|
while(first)
|
|
|
|
|
{
|
2023-12-16 17:42:11 +03:00
|
|
|
SageSymbols q(first->lhs()->symbol(), -1, 0, 0);
|
|
|
|
|
retval.push_back(q);
|
|
|
|
|
|
2023-09-14 19:43:13 +03:00
|
|
|
first = first->rhs();
|
|
|
|
|
}
|
2023-12-16 17:42:11 +03:00
|
|
|
return retval;
|
2023-09-14 19:43:13 +03:00
|
|
|
}
|