Compare commits
5 Commits
672f03a81f
...
b98ae6f81b
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b98ae6f81b | ||
|
|
d2b1eed326 | ||
|
|
c2bc541ef6 | ||
|
|
3d457b3b02 | ||
|
|
f3f7368bdc |
@@ -1787,6 +1787,8 @@ public:
|
||||
inline SgSymbol *construct_name();
|
||||
inline void replaceTrueBody(SgStatement &s);// new body=s and lex successors.
|
||||
inline void replaceFalseBody(SgStatement &s);//new body=s and lex successors.
|
||||
// added by A.S. Kolganov 12.12.2024
|
||||
inline void setConditional(SgExpression* cond) { BIF_LL1(thebif) = cond->thellnd; }
|
||||
inline ~SgIfStmt();
|
||||
};
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ static int has_region, in_arg_list, analyzing, has_max_minloc, for_shadow_comput
|
||||
|
||||
static SgStatement *cur_in_block, *cur_in_source, *mod_gpu_end;
|
||||
static SgStatement *call_kernel;
|
||||
static SgExpression *dvm_array_list, *do_st_list, *indexing_info_list;
|
||||
static SgExpression *dvm_array_list, *do_st_list, *indexing_info_list, *acc_declared_list;
|
||||
static SgExpression *argument_list, *base_mem_list, *coeff_list, *gpu_coeff_list, *registered_uses_list;
|
||||
static SgExpression *red_var_list, *formal_red_offset_list, *red_offset_list, *copy_uses_list;
|
||||
static SgConstantSymb *device_const[Ndev], *const_LONG, *intent_const[Nintent], *handler_const[Nhandler];
|
||||
@@ -288,6 +288,7 @@ void InitializeInFuncACC()
|
||||
acc_return_list = NULL; /*ACC*/
|
||||
acc_registered_list = NULL; /*ACC*/
|
||||
registered_uses_list = NULL; /*ACC*/
|
||||
acc_declared_list = NULL; /*ACC*/
|
||||
}
|
||||
|
||||
int GeneratedForCuda()
|
||||
@@ -977,6 +978,8 @@ void DeclareVarGPU(SgStatement *lstat, SgType *tlen)
|
||||
/************************************************************************************/
|
||||
void EnterDataRegionForAllocated(SgStatement *stmt)
|
||||
{SgExpression *al;
|
||||
if(!ACC_program)
|
||||
return;
|
||||
for(al=stmt->expr(0); al; al=al->rhs())
|
||||
EnterDataRegion(al->lhs(),stmt);
|
||||
|
||||
@@ -1044,7 +1047,7 @@ void UnregisterVariables(int begin_block)
|
||||
{
|
||||
stmt_list *stl;
|
||||
int is;
|
||||
if (IN_MAIN_PROGRAM)
|
||||
if (!ACC_program || IN_MAIN_PROGRAM)
|
||||
return;
|
||||
for (stl = acc_return_list; stl; stl = stl->next)
|
||||
{
|
||||
@@ -1101,6 +1104,15 @@ void DeclareDataRegionSaveVariables(SgStatement *lstat, SgType *tlen)
|
||||
if (attr)
|
||||
DeclareVariableWithInitialization (*attr, tlen, lstat);
|
||||
}
|
||||
for (el = acc_declared_list; el; el = el->rhs())
|
||||
{
|
||||
symb = el->lhs()->symbol();
|
||||
if (!(IS_ARRAY(symb)) || isInExprList(el->lhs(), registered_uses_list) || isInSymbList(symb, acc_registered_list))
|
||||
continue;
|
||||
SgSymbol **attr = (SgSymbol **)(symb)->attributeValue(0,DATA_REGION_SYMB);
|
||||
if (attr)
|
||||
DeclareVariableWithInitialization (*attr, tlen, lstat);
|
||||
}
|
||||
}
|
||||
|
||||
SgSymbol *DataRegionVar(SgSymbol *symb)
|
||||
@@ -1124,9 +1136,9 @@ void EnterDataRegionForLocalVariables(SgStatement *st, SgStatement *first_exec,
|
||||
{
|
||||
if (!el->lhs()) continue;
|
||||
SgSymbol *sym = el->lhs()->symbol();
|
||||
if (sym->variant() != CONST_NAME && IS_LOCAL_VAR(sym) && !IS_ALLOCATABLE(sym) && !IS_POINTER_F90(sym) && !(sym->attributes() & HEAP_BIT)) // //!(el->lhs()->symbol()->attributes() & PARAMETER_BIT) )
|
||||
if (IS_ARRAY(sym) && sym->variant() != CONST_NAME && IS_LOCAL_VAR(sym) && !IS_ALLOCATABLE(sym) && !IS_POINTER_F90(sym) && !(sym->attributes() & HEAP_BIT)) // //!(el->lhs()->symbol()->attributes() & PARAMETER_BIT) )
|
||||
{
|
||||
if ((HAS_SAVE_ATTR(sym) || IN_DATA(sym)) && IS_ARRAY(sym))
|
||||
if (HAS_SAVE_ATTR(sym) || IN_DATA(sym))
|
||||
newst = doIfThenForDataRegion(DataRegionVar(sym), st, DataEnter(new SgVarRefExp(sym),ConstRef(0)));
|
||||
else
|
||||
st->insertStmtAfter(*(newst=DataEnter(new SgVarRefExp(sym),ConstRef(0))),*st->controlParent());
|
||||
@@ -1134,14 +1146,30 @@ void EnterDataRegionForLocalVariables(SgStatement *st, SgStatement *first_exec,
|
||||
}
|
||||
for (sl = acc_registered_list; sl; sl = sl->next)
|
||||
{
|
||||
if (sl->symb->variant() != CONST_NAME && IS_LOCAL_VAR(sl->symb) && !IS_ALLOCATABLE(sl->symb) && !IS_POINTER_F90(sl->symb) && !HEADER(sl->symb)) //!(sl->symb->attributes() & PARAMETER_BIT))
|
||||
if (IS_ARRAY(sl->symb) && sl->symb->variant() != CONST_NAME && IS_LOCAL_VAR(sl->symb) && !IS_ALLOCATABLE(sl->symb) && !IS_POINTER_F90(sl->symb) && !HEADER(sl->symb)) //!(sl->symb->attributes() & PARAMETER_BIT))
|
||||
{
|
||||
if ((HAS_SAVE_ATTR(sl->symb) || IN_DATA(sl->symb)) && IS_ARRAY(sl->symb))
|
||||
if (HAS_SAVE_ATTR(sl->symb) || IN_DATA(sl->symb))
|
||||
newst = doIfThenForDataRegion(DataRegionVar(sl->symb), st, DataEnter(new SgVarRefExp(sl->symb),ConstRef(0)));
|
||||
else
|
||||
st->insertStmtAfter(*(newst=DataEnter(new SgVarRefExp(sl->symb),ConstRef(0))),*st->controlParent());
|
||||
}
|
||||
}
|
||||
|
||||
for (el = acc_declared_list; el; el = el->rhs())
|
||||
{
|
||||
SgSymbol *sym = el->lhs()->symbol();
|
||||
if (!IS_ARRAY(sym) || isInExprList(el->lhs(), registered_uses_list) || isInSymbList(sym, acc_registered_list))
|
||||
continue;
|
||||
|
||||
if (sym->variant() != CONST_NAME && IS_LOCAL_VAR(sym) && !IS_ALLOCATABLE(sym) && !IS_POINTER_F90(sym) && !(sym->attributes() & HEAP_BIT) && !HEADER(sym))
|
||||
{
|
||||
if (HAS_SAVE_ATTR(sym) || IN_DATA(sym))
|
||||
newst = doIfThenForDataRegion(DataRegionVar(sym), st, DataEnter(new SgVarRefExp(sym),ConstRef(0)));
|
||||
else
|
||||
st->insertStmtAfter(*(newst=DataEnter(new SgVarRefExp(sym),ConstRef(0))),*st->controlParent());
|
||||
}
|
||||
}
|
||||
|
||||
if (newst && !begin_block)
|
||||
LINE_NUMBER_AFTER(first_exec,st);
|
||||
}
|
||||
@@ -1155,9 +1183,9 @@ void ExitDataRegionForLocalVariables(SgStatement *st, int is)
|
||||
{
|
||||
if (!el->lhs()) continue;
|
||||
SgSymbol *sym = el->lhs()->symbol();
|
||||
if (sym->variant() != CONST_NAME && IS_LOCAL_VAR(sym) && !IS_ALLOCATABLE(sym) && !IS_POINTER_F90(sym) && !(sym->attributes() & HEAP_BIT)) // //!(el->lhs()->symbol()->attributes() & PARAMETER_BIT) )
|
||||
if (IS_ARRAY(sym) && sym->variant() != CONST_NAME && IS_LOCAL_VAR(sym) && !IS_ALLOCATABLE(sym) && !IS_POINTER_F90(sym) && !(sym->attributes() & HEAP_BIT)) // //!(el->lhs()->symbol()->attributes() & PARAMETER_BIT) )
|
||||
{
|
||||
if ((HAS_SAVE_ATTR(sym) || IN_DATA(sym)) && IS_ARRAY(sym))
|
||||
if (HAS_SAVE_ATTR(sym) || IN_DATA(sym))
|
||||
continue;
|
||||
if (!is++)
|
||||
LINE_NUMBER_BEFORE(st,st);
|
||||
@@ -1166,18 +1194,71 @@ void ExitDataRegionForLocalVariables(SgStatement *st, int is)
|
||||
}
|
||||
for (sl = acc_registered_list; sl; sl = sl->next)
|
||||
{
|
||||
if (sl->symb->variant() != CONST_NAME && IS_LOCAL_VAR(sl->symb) && !IS_ALLOCATABLE(sl->symb) && !IS_POINTER_F90(sl->symb) && !HEADER(sl->symb)) //!(sl->symb->attributes() & PARAMETER_BIT))
|
||||
if (IS_ARRAY(sl->symb) && sl->symb->variant() != CONST_NAME && IS_LOCAL_VAR(sl->symb) && !IS_ALLOCATABLE(sl->symb) && !IS_POINTER_F90(sl->symb) && !HEADER(sl->symb)) //!(sl->symb->attributes() & PARAMETER_BIT))
|
||||
{
|
||||
if ((HAS_SAVE_ATTR(sl->symb) || IN_DATA(sl->symb)) && IS_ARRAY(sl->symb))
|
||||
if (HAS_SAVE_ATTR(sl->symb) || IN_DATA(sl->symb))
|
||||
continue;
|
||||
if (!is++)
|
||||
LINE_NUMBER_BEFORE(st,st);
|
||||
InsertNewStatementBefore(DataExit(new SgVarRefExp(sl->symb),0),st);
|
||||
}
|
||||
}
|
||||
for (el = acc_declared_list; el; el = el->rhs())
|
||||
{
|
||||
if (!el->lhs()) continue;
|
||||
SgSymbol *sym = el->lhs()->symbol();
|
||||
if (!IS_ARRAY(sym) || isInExprList(el->lhs(), registered_uses_list) || isInSymbList(sym, acc_registered_list))
|
||||
continue;
|
||||
if (sym->variant() != CONST_NAME && IS_LOCAL_VAR(sym) && !IS_ALLOCATABLE(sym) && !IS_POINTER_F90(sym) && !(sym->attributes() & HEAP_BIT) && !HEADER(sym))
|
||||
{
|
||||
if (HAS_SAVE_ATTR(sym) || IN_DATA(sym))
|
||||
continue;
|
||||
if (!is++)
|
||||
LINE_NUMBER_BEFORE(st,st);
|
||||
InsertNewStatementBefore(DataExit(new SgVarRefExp(sym),0),st);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void testScopeOfDeclaredVariables(SgStatement *stmt)
|
||||
{
|
||||
SgExpression *el;
|
||||
for (el = stmt->expr(0); el; el = el->rhs())
|
||||
{
|
||||
SgSymbol *sym = el->lhs()->symbol();
|
||||
if (!IS_LOCAL_VAR(sym))
|
||||
Error("Non-local data object in DECLARE directive: %s", sym->identifier(), 668, stmt);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
void testDeclareDirectives(SgStatement *first_dvm_exec)
|
||||
{
|
||||
SgStatement *stmt;
|
||||
for (stmt = cur_func->lexNext(); stmt && (stmt != first_dvm_exec); stmt = stmt->lastNodeOfStmt()->lexNext())
|
||||
{
|
||||
if (stmt->variant()==ACC_DECLARE_DIR)
|
||||
{
|
||||
if (IN_MODULE)
|
||||
err("Illegal directive in module", 632, stmt);
|
||||
else if (!IN_MAIN_PROGRAM)
|
||||
testScopeOfDeclaredVariables(stmt);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
// eliminating duplicate objects from the acc_declared_list
|
||||
SgExpression *el, *el2, *prev;
|
||||
for (el = acc_declared_list; el; el = el->rhs())
|
||||
{
|
||||
for (el2 = el->rhs(), prev = el; el2; )
|
||||
if (ORIGINAL_SYMBOL(el->lhs()->symbol()) == ORIGINAL_SYMBOL(el2->lhs()->symbol()))
|
||||
{ prev->setRhs(el2->rhs()); el2 = el2->rhs(); }
|
||||
else
|
||||
{ prev = el2; el2 = el2->rhs(); }
|
||||
}
|
||||
}
|
||||
|
||||
void ExtractCopy(SgExpression *elist)
|
||||
{
|
||||
SgExpression *el;
|
||||
@@ -1204,6 +1285,8 @@ void CleanAllocatedList()
|
||||
int ExitDataRegionForAllocated(SgStatement *st,int begin_block)
|
||||
{
|
||||
SgExpression *el;
|
||||
if (!ACC_program)
|
||||
return(0);
|
||||
|
||||
if (TestLocal(allocated_list))
|
||||
{
|
||||
@@ -1251,6 +1334,7 @@ int hasSameOriginalName(SgSymbol *s)
|
||||
|
||||
void EnterDataRegionForVariablesInMainProgram(SgStatement *st)
|
||||
{
|
||||
/*
|
||||
symb_list *sl;
|
||||
SgSymbol *s;
|
||||
for(sl=registration; sl; sl=sl->next)
|
||||
@@ -1266,10 +1350,34 @@ void EnterDataRegionForVariablesInMainProgram(SgStatement *st)
|
||||
st->insertStmtAfter(*DataEnter(new SgVarRefExp(s),ConstRef(0)),*st->controlParent());
|
||||
s = s->next();
|
||||
}
|
||||
*/
|
||||
SgExpression *el;
|
||||
symb_list *sl;
|
||||
for (el = registered_uses_list; el; el = el->rhs())
|
||||
{
|
||||
SgSymbol *sym = el->lhs()->symbol();
|
||||
if (IS_ARRAY(sym) && sym->variant() != CONST_NAME && !IS_ALLOCATABLE(sym) && !IS_POINTER_F90(sym) && !(sym->attributes() & HEAP_BIT))
|
||||
st->insertStmtAfter(*DataEnter(new SgVarRefExp(sym),ConstRef(0)),*st->controlParent());
|
||||
}
|
||||
for (sl = acc_registered_list; sl; sl = sl->next)
|
||||
{
|
||||
if (sl->symb->variant() != CONST_NAME && !IS_ALLOCATABLE(sl->symb) && !IS_POINTER_F90(sl->symb) && !HEADER(sl->symb))
|
||||
st->insertStmtAfter(*DataEnter(new SgVarRefExp(sl->symb),ConstRef(0)),*st->controlParent());
|
||||
}
|
||||
for (el = acc_declared_list; el; el = el->rhs())
|
||||
{
|
||||
SgSymbol *sym = el->lhs()->symbol();
|
||||
if (!IS_ARRAY(sym) || isInExprList(el->lhs(), registered_uses_list) || isInSymbList(sym, acc_registered_list))
|
||||
continue;
|
||||
|
||||
if (sym->variant() == VARIABLE_NAME && !IS_ALLOCATABLE(sym) && !IS_POINTER_F90(sym) && !HEADER(sym) && !(sym->attributes() & HEAP_BIT))
|
||||
st->insertStmtAfter(*DataEnter(new SgVarRefExp(sym),ConstRef(0)),*st->controlParent());
|
||||
}
|
||||
}
|
||||
|
||||
void ExitDataRegionForVariablesInMainProgram(SgStatement *st)
|
||||
{
|
||||
/*
|
||||
symb_list *sl;
|
||||
SgSymbol *s;
|
||||
for(sl=registration; sl; sl=sl->next)
|
||||
@@ -1286,6 +1394,37 @@ void ExitDataRegionForVariablesInMainProgram(SgStatement *st)
|
||||
InsertNewStatementBefore(DataExit(new SgVarRefExp(s),0),st);
|
||||
s = s->next();
|
||||
}
|
||||
SgSymbol *s;
|
||||
SgExpression *el;
|
||||
for (el = acc_declared_list; el; el = el->rhs())
|
||||
{
|
||||
s = el->lhs()->symbol();
|
||||
if (IS_ARRAY(s) && s->variant() == VARIABLE_NAME && !IS_ALLOCATABLE(s) && !IS_POINTER_F90(s) && !HEADER(s) && !(s->attributes() & HEAP_BIT))
|
||||
InsertNewStatementBefore(DataExit(new SgVarRefExp(s),0),st);
|
||||
}
|
||||
*/
|
||||
SgExpression *el;
|
||||
symb_list *sl;
|
||||
for (el = registered_uses_list; el; el = el->rhs())
|
||||
{
|
||||
SgSymbol *sym = el->lhs()->symbol();
|
||||
if (IS_ARRAY(sym) && sym->variant() != CONST_NAME && !IS_ALLOCATABLE(sym) && !IS_POINTER_F90(sym) && !(sym->attributes() & HEAP_BIT))
|
||||
InsertNewStatementBefore(DataExit(new SgVarRefExp(sym),0),st);
|
||||
}
|
||||
for (sl = acc_registered_list; sl; sl = sl->next)
|
||||
{
|
||||
if (sl->symb->variant() != CONST_NAME && !IS_ALLOCATABLE(sl->symb) && !IS_POINTER_F90(sl->symb) && !HEADER(sl->symb))
|
||||
InsertNewStatementBefore(DataExit(new SgVarRefExp(sl->symb),0),st);
|
||||
}
|
||||
for (el = acc_declared_list; el; el = el->rhs())
|
||||
{
|
||||
SgSymbol *sym = el->lhs()->symbol();
|
||||
if (!IS_ARRAY(sym) || isInExprList(el->lhs(), registered_uses_list) || isInSymbList(sym, acc_registered_list))
|
||||
continue;
|
||||
|
||||
if (sym->variant() == VARIABLE_NAME && !IS_ALLOCATABLE(sym) && !IS_POINTER_F90(sym) && !HEADER(sym) && !(sym->attributes() & HEAP_BIT))
|
||||
InsertNewStatementBefore(DataExit(new SgVarRefExp(sym),0),st);
|
||||
}
|
||||
}
|
||||
|
||||
/**********************************************************************************/
|
||||
@@ -1345,9 +1484,15 @@ SgStatement *ACC_Directive(SgStatement *stmt)
|
||||
|
||||
}
|
||||
|
||||
void ACC_DECLARE_Directive(SgStatement *stmt)
|
||||
{
|
||||
if (ACC_program)
|
||||
acc_declared_list = ExpressionListsUnion(acc_declared_list, &(stmt->expr(0)->copy()));
|
||||
}
|
||||
|
||||
void ACC_ROUTINE_Directive(SgStatement *stmt)
|
||||
{
|
||||
if( options.isOn(NO_CUDA) )
|
||||
if(!ACC_program || options.isOn(NO_CUDA) )
|
||||
return;
|
||||
int control_variant = stmt->controlParent()->controlParent()->variant();
|
||||
if (control_variant == INTERFACE_STMT || control_variant == INTERFACE_OPERATOR || control_variant == INTERFACE_ASSIGNMENT)
|
||||
@@ -1658,11 +1803,8 @@ SgStatement *ACC_REGION_Directive(SgStatement *stmt)
|
||||
|
||||
|
||||
// creating lists of registered variables in procedure
|
||||
if (!IN_MAIN_PROGRAM)
|
||||
{
|
||||
acc_registered_list = SymbolListsUnion(acc_registered_list, acc_array_list);
|
||||
registered_uses_list = ExpressionListsUnion(registered_uses_list, uses_list);
|
||||
}
|
||||
|
||||
return(cur_st);
|
||||
}
|
||||
@@ -10664,7 +10806,18 @@ void ReductionBlockInKernel_On_C_Cuda(SgStatement *stat, SgSymbol *i_var, SgExpr
|
||||
|
||||
stat->insertStmtBefore(*new SgCExpStmt(*fun_ref), *stat->controlParent());
|
||||
|
||||
if (across)
|
||||
{
|
||||
newst = AssignStatement(new SgArrayRefExp(*rsl->red_grid, *ex), new SgVarRefExp(rsl->redvar));
|
||||
|
||||
SgExpression* cond = if_st->conditional();
|
||||
int redVar = RedFuncNumber(ered->lhs());
|
||||
if (redVar == 9) // maxloc
|
||||
cond = &(*cond && (*new SgVarRefExp(rsl->redvar) > *new SgArrayRefExp(*rsl->red_grid, *ex)));
|
||||
else if (redVar == 10) // minloc
|
||||
cond = &(*cond && (*new SgVarRefExp(rsl->redvar) < *new SgArrayRefExp(*rsl->red_grid, *ex)));
|
||||
|
||||
if_st->setConditional(cond);
|
||||
}
|
||||
else
|
||||
newst = AssignStatement(new SgArrayRefExp(*rsl->red_grid, *BlockIdxRefExpr("x") * *ex1 + *ex), new SgVarRefExp(rsl->redvar));
|
||||
|
||||
@@ -5923,7 +5923,11 @@ SgStatement *CreateLoopKernelAcross(SgSymbol *skernel, ArgsForKernel* argsKer, i
|
||||
else if (num == 9 || num == 10)
|
||||
{
|
||||
st = AssignStatement(*new SgArrayRefExp(*redGrid, *e1), red_expr_ref->copy());
|
||||
ifSt = new SgIfStmt(red_expr_ref->copy() > *new SgArrayRefExp(*redGrid, *e1), *st);
|
||||
if (num == 9)
|
||||
ifSt = new SgIfStmt(red_expr_ref->copy() > *new SgArrayRefExp(*redGrid, *e1), *st);
|
||||
else
|
||||
ifSt = new SgIfStmt(red_expr_ref->copy() < *new SgArrayRefExp(*redGrid, *e1), *st);
|
||||
|
||||
for (int i = loc_el_num - 1; i >= 0; i--)
|
||||
{
|
||||
SgSymbol *locGrid = new SgSymbol(VARIABLE_NAME, tmp_list->loc_grid->identifier());
|
||||
|
||||
@@ -2191,6 +2191,9 @@ void TransFunc(SgStatement *func,SgStatement* &end_of_unit) {
|
||||
case(ACC_ROUTINE_DIR):
|
||||
ACC_ROUTINE_Directive(stmt);
|
||||
continue;
|
||||
case(ACC_DECLARE_DIR):
|
||||
ACC_DECLARE_Directive(stmt);
|
||||
continue;
|
||||
case(HPF_TEMPLATE_STAT):
|
||||
if(IN_MODULE && stmt->expr(1))
|
||||
err("Illegal directive in module",632,stmt);
|
||||
@@ -2679,6 +2682,8 @@ void TransFunc(SgStatement *func,SgStatement* &end_of_unit) {
|
||||
|
||||
break;
|
||||
}
|
||||
// checking semantics of DECLARE directives
|
||||
testDeclareDirectives(stmt);
|
||||
|
||||
if(pstmt && (stmt != last))
|
||||
pstmt = pstmt->next; //deleting first executable statement from
|
||||
@@ -4239,7 +4244,6 @@ END_: // end of program unit
|
||||
if(last_dvm_entry)
|
||||
lentry = last_dvm_entry->lexNext(); // lentry - statement following first_dvm_exec or last generated dvm-initialization statement(before first_exec)
|
||||
// before first_exec may be new statements generated for first_exec
|
||||
|
||||
if(!IN_MODULE) {
|
||||
if(has_contains)
|
||||
MarkCoeffsAsUsed();
|
||||
@@ -5294,7 +5298,8 @@ void DEALLOCATEf90_arrays(SgStatement *stmt)
|
||||
|
||||
} else
|
||||
{ apr = al;
|
||||
InsertNewStatementAfter(DataExit(&al->lhs()->copy(),0),cur_st,stmt->controlParent()); /*26.10.17*/
|
||||
if(ACC_program) /*ACC*/
|
||||
InsertNewStatementAfter(DataExit(&al->lhs()->copy(),0),cur_st,stmt->controlParent()); /*26.10.17*/
|
||||
//if(ACC_program) /*ACC*/
|
||||
// InsertNewStatementAfter(DestroyScalar(&al->lhs()->copy()),cur_st,stmt->controlParent());
|
||||
//doCallAfter(DataExit(&al->lhs()->copy(),0)); /*ACC*/
|
||||
@@ -10600,6 +10605,7 @@ void InsertDebugStat(SgStatement *func, SgStatement* &end_of_unit)
|
||||
pstmt = addToStmtList(pstmt, stmt);
|
||||
continue;
|
||||
case(ACC_ROUTINE_DIR):
|
||||
case(ACC_DECLARE_DIR):
|
||||
case(HPF_PROCESSORS_STAT):
|
||||
case(HPF_TEMPLATE_STAT):
|
||||
case(DVM_DYNAMIC_DIR):
|
||||
@@ -13760,6 +13766,7 @@ SgStatement *InterfaceBody(SgStatement *hedr)
|
||||
case (DVM_POINTER_DIR):
|
||||
case (DVM_HEAP_DIR):
|
||||
case (DVM_ASYNCID_DIR):
|
||||
case (ACC_DECLARE_DIR):
|
||||
dvm_pred = stmt;
|
||||
default:
|
||||
continue;
|
||||
|
||||
@@ -1453,6 +1453,8 @@ SgExpression *CreatePrivateDummyList();
|
||||
SgExpression *CreatePrivateDummyList();
|
||||
char *PointerNameForPrivateArray(SgSymbol *symb);
|
||||
void GetMemoryForPrivateArrays(SgSymbol *private_first, SgSymbol *s_loop_ref, int nump, SgStatement *st_end, SgStatement *st_hedr, SgExpression *e_totalThreads);
|
||||
SgSymbol *LocRedVariableSymbolInKernel(reduction_operation_list *rsl);
|
||||
void testDeclareDirectives(SgStatement *first_dvm_exec);
|
||||
void ACC_DECLARE_Directive(SgStatement *stmt);
|
||||
|
||||
/* acc_analyzer.cpp */
|
||||
|
||||
@@ -1345,11 +1345,16 @@ body:/* if(newname) {
|
||||
{ prefix[5]=BLANKC; *endcd++ = '\0';}
|
||||
else
|
||||
*endcd++ = '\0'; /* put NULL char in buffer as end marker */
|
||||
if((c==';') && (char_cntx==0)) {
|
||||
stmt_end: if((c==';') && (char_cntx==0)) {
|
||||
restcd = bend - endcd;
|
||||
while( ((c = getc(infile)) == ';') || (c == ' '))
|
||||
restcd--;
|
||||
(void) ungetc(c,infile);
|
||||
if(c == '!') { /* delimiter ';' is ignored before comment */
|
||||
restcd = 0;
|
||||
goto stmt_end;
|
||||
}
|
||||
else
|
||||
(void) ungetc(c,infile);
|
||||
}
|
||||
else if((c=='!') && (char_cntx==0)) {
|
||||
cmt = tempbuf;
|
||||
@@ -1615,11 +1620,16 @@ body: /* Read body of line */
|
||||
/*('\r\n' is end line marker in Windows) */
|
||||
else
|
||||
*endcd++ = '\0'; /* put NULL char in buffer as end marker */
|
||||
if((c==';') && (char_cntx==0)) {
|
||||
stmt_end: if((c==';') && (char_cntx==0)) {
|
||||
restcd = 1;
|
||||
while( ((c = getc(infile)) == ';') || (c == ' '))
|
||||
;
|
||||
(void) ungetc(c,infile);
|
||||
if(c == '!') { /* delimiter ';' is ignored before comment */
|
||||
restcd = 0;
|
||||
goto stmt_end;
|
||||
}
|
||||
else
|
||||
(void) ungetc(c,infile);
|
||||
}
|
||||
else if((c=='!') && (char_cntx==0)) {
|
||||
cmt = tempbuf;
|
||||
|
||||
@@ -10,24 +10,241 @@
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include <tuple>
|
||||
#include <unordered_set>
|
||||
|
||||
#include "dvm.h"
|
||||
#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 "projectParameters.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
map< pair<string, int>, set<string>>
|
||||
set goodArgTypes = {SAPFOR::CFG_ARG_TYPE::REG, SAPFOR::CFG_ARG_TYPE::VAR};
|
||||
set funcOperatrions = {SAPFOR::CFG_OP::PARAM, SAPFOR::CFG_OP::F_CALL};
|
||||
set instructionsToLook = {SAPFOR::CFG_OP::LOAD, SAPFOR::CFG_OP::STORE, SAPFOR::CFG_OP::REC_REF_LOAD, SAPFOR::CFG_OP::REC_REF_STORE,
|
||||
SAPFOR::CFG_OP::ADD, SAPFOR::CFG_OP::MULT, SAPFOR::CFG_OP::DIV, SAPFOR::CFG_OP::SUBT, SAPFOR::CFG_OP::UN_ADD,
|
||||
SAPFOR::CFG_OP::UN_MINUS, SAPFOR::CFG_OP::POW, SAPFOR::CFG_OP::CONCAT, SAPFOR::CFG_OP::ASSIGN};
|
||||
|
||||
static bool isParentStmt(SgStatement* stmt, const SgStatement* parent)
|
||||
{
|
||||
for (; stmt; stmt = stmt->controlParent())
|
||||
if (stmt == parent)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/*returns head block and loop*/
|
||||
SAPFOR::BasicBlock* GetBasicBlocksForLoop(const LoopGraph* loop, const 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))
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
/*returns FuncInfo vetcor by filename*/
|
||||
vector<FuncInfo*> FindFuncInfoVec(string funcname, const map<string, vector<FuncInfo*>>& allFuncInfo){
|
||||
for(pair<string, vector<FuncInfo*>> p: allFuncInfo) {
|
||||
if(p.first == funcname){
|
||||
return p.second;
|
||||
}
|
||||
}
|
||||
vector<FuncInfo*> a;
|
||||
return a;
|
||||
}
|
||||
|
||||
/*returns BasicBlock vector for function by FuncInfo*/
|
||||
vector<SAPFOR::BasicBlock*> FindBlocksVec(const FuncInfo* func, const map<FuncInfo*, vector<SAPFOR::BasicBlock*>>& fullIR){
|
||||
for(const pair<FuncInfo*, vector<SAPFOR::BasicBlock*>>& p: fullIR) {
|
||||
if(p.first == func){
|
||||
return p.second;
|
||||
}
|
||||
}
|
||||
vector<SAPFOR::BasicBlock*> a;
|
||||
return a;
|
||||
}
|
||||
|
||||
/*returns LoopGraph vector by filename*/
|
||||
vector<LoopGraph*> FindLoopsWithFilename(string filename, const map<string, vector<LoopGraph*>>& loopGraph){
|
||||
for(pair<string, vector<LoopGraph*>> p: loopGraph) {
|
||||
if(p.first == filename){
|
||||
return p.second;
|
||||
}
|
||||
}
|
||||
vector<LoopGraph*> a;
|
||||
return a;
|
||||
}
|
||||
|
||||
/*checks if instruction is found for result*/
|
||||
bool CheckIfInstructionIsFound(const vector<pair<int, SAPFOR::Instruction*>> found, int block_num, const SAPFOR::Instruction* instr){
|
||||
for(pair<int, SAPFOR::Instruction*> p: found){
|
||||
if(p.first == block_num && p.second == instr){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/*main pass function*/
|
||||
map<pair<string, int>, set<string>>
|
||||
findParameters(const map<string, vector<DefUseList>> &defUseByFunctions,
|
||||
const map<string, CommonBlock*> &commonBlocks,
|
||||
const map<string, vector<FuncInfo*>> &allFuncInfo)
|
||||
const map<string, vector<FuncInfo*>> &allFuncInfo,
|
||||
const map<FuncInfo*, vector<SAPFOR::BasicBlock*>> &fullIR,
|
||||
const map<string, vector<LoopGraph*>>& loopGraph)
|
||||
{
|
||||
map< pair<string, int>, set<string>> foundParameters;
|
||||
|
||||
/*find blocks with loops start for each function*/
|
||||
map<FuncInfo*, vector<SAPFOR::BasicBlock*>> mapFuncLoops;
|
||||
for(const pair<FuncInfo*, vector<SAPFOR::BasicBlock*>>& partIR: fullIR) {
|
||||
vector<LoopGraph*> loopsForFile = FindLoopsWithFilename(partIR.first->fileName, loopGraph);
|
||||
SAPFOR::BasicBlock* head = nullptr;
|
||||
for(auto vec: loopsForFile){
|
||||
head = nullptr;
|
||||
head = GetBasicBlocksForLoop(vec, partIR.second);
|
||||
if(head != nullptr){
|
||||
mapFuncLoops[partIR.first].push_back(head);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return foundParameters;
|
||||
/*find instructions with read operaton which affects on number iterations for loops*/
|
||||
map<pair<string, int>, set<string>> finalInstructions;
|
||||
/*for each function*/
|
||||
for(const auto lookedFunc: mapFuncLoops){
|
||||
/*for each loop in function*/
|
||||
for(const auto& vectElem: lookedFunc.second){
|
||||
SAPFOR::Instruction* instr = vectElem->getInstructions().front()->getInstruction();
|
||||
vector<SAPFOR::BasicBlock*> blocks = vectElem->getPrev();
|
||||
vector<SAPFOR::Argument*> argumentsForLook;
|
||||
argumentsForLook.push_back(instr->getArg2());
|
||||
int blockInd = 0;
|
||||
/*run through blocks from first found to first in program taking previous blocks on each step*/
|
||||
while(blockInd < blocks.size()){
|
||||
if(argumentsForLook.empty()){
|
||||
break;
|
||||
}
|
||||
vector<SAPFOR::IR_Block*> blockInstructions = blocks[blockInd]->getInstructions();
|
||||
int numberOfInstructions = blockInstructions.size();
|
||||
/*run through all instructions of block from bottom to up*/
|
||||
for(int i=numberOfInstructions-1; i>=0; i--){
|
||||
SAPFOR::Instruction* cur = blockInstructions[i]->getInstruction();
|
||||
/*if instuction type is CALL*/
|
||||
if(cur->getOperation() == SAPFOR::CFG_OP::F_CALL){
|
||||
/*if it is CALL of READ function*/
|
||||
if(cur->getArg1()->getValue() == "_READ"){
|
||||
int numParams = std::stoi(cur->getArg2()->getValue());
|
||||
bool flag = false;
|
||||
/*drop all found arguments from argumentsForLook and add them to answer*/
|
||||
for(int j=i-1; j>i-numParams-1; j--){
|
||||
auto iter = find(argumentsForLook.begin(), argumentsForLook.end(), blockInstructions[j]->getInstruction()->getArg1());
|
||||
if(iter != argumentsForLook.end()){
|
||||
int delimeterPosition = (*iter)->getValue().find("%");
|
||||
finalInstructions[{blockInstructions[j]->getInstruction()->getOperator()->fileName(),
|
||||
blockInstructions[j]->getInstruction()->getLine()}].insert((*iter)->getValue().substr(delimeterPosition+1));
|
||||
argumentsForLook.erase(iter);
|
||||
flag = true;
|
||||
}
|
||||
}
|
||||
i = i-numParams;
|
||||
continue;
|
||||
}
|
||||
/*if it is CALL of another function than find it's arguments and result to change argumentsForLook vector if needed*/
|
||||
auto it = find(argumentsForLook.begin(), argumentsForLook.end(), cur->getResult());
|
||||
if(cur->getResult() && it != argumentsForLook.end()){
|
||||
int dist = distance(argumentsForLook.begin(), it);
|
||||
int numParams = std::stoi(cur->getArg2()->getValue());
|
||||
for(int j=i-1; j>i-numParams-1; j--){
|
||||
if(find(argumentsForLook.begin(), argumentsForLook.end(), blockInstructions[j]->getInstruction()->getArg1()) == argumentsForLook.end()){
|
||||
argumentsForLook.push_back(blockInstructions[j]->getInstruction()->getArg1());
|
||||
}
|
||||
}
|
||||
i = i-numParams;
|
||||
argumentsForLook.erase(argumentsForLook.begin()+dist);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
/*check only some operation types because other types are useless for this task*/
|
||||
if(instructionsToLook.find(cur->getOperation()) == instructionsToLook.end()){
|
||||
continue;
|
||||
}
|
||||
/*check if result of operation in argumentsForLook*/
|
||||
auto it = find(argumentsForLook.begin(), argumentsForLook.end(), cur->getResult());
|
||||
if(*it != NULL && it != argumentsForLook.end()){
|
||||
int dist = distance(argumentsForLook.begin(), it);
|
||||
/*add arguments of operation to argumentsForLook vector if they are not there*/
|
||||
if(cur->getArg1() != NULL && find(argumentsForLook.begin(), argumentsForLook.end(), cur->getArg1()) == argumentsForLook.end()){
|
||||
/*add argument only if it's type is register or variable because constants are not needed here*/
|
||||
if(goodArgTypes.find(cur->getArg1()->getType()) != goodArgTypes.end()){
|
||||
argumentsForLook.push_back(cur->getArg1());
|
||||
}
|
||||
}
|
||||
if(cur->getArg2() != NULL && find(argumentsForLook.begin(), argumentsForLook.end(), cur->getArg2()) == argumentsForLook.end()){
|
||||
/*add argument only if it's type is register or variable because constants are not needed here*/
|
||||
if(goodArgTypes.find(cur->getArg2()->getType()) != goodArgTypes.end()){
|
||||
argumentsForLook.push_back(cur->getArg2());
|
||||
}
|
||||
}
|
||||
/*drop found result of operation from argumentsForLook vector*/
|
||||
argumentsForLook.erase(argumentsForLook.begin()+dist);
|
||||
};
|
||||
}
|
||||
/*add prev blocks to run through*/
|
||||
for(auto b: blocks[blockInd]->getPrev()){
|
||||
if(find(blocks.begin(), blocks.end(), b) == blocks.end()){
|
||||
blocks.push_back(b);
|
||||
}
|
||||
}
|
||||
blockInd++;
|
||||
}
|
||||
/*next step is next function that means next structures are not needed -> clear them*/
|
||||
argumentsForLook.clear();
|
||||
blocks.clear();
|
||||
/*In the argumentsForLook vector may be arguments of instructions that could not be found in the blocks of current program or function.
|
||||
Perhaps I need to look for them in the arguments of the current function, they should be there.
|
||||
That means that I will need more complex processing of function calls*/
|
||||
}
|
||||
}
|
||||
|
||||
/*here should be part of founding istructions for allocates!!*/
|
||||
|
||||
/*print found instructions for each function or program*/
|
||||
cout << "\n\nFINAL INSTRUCTIONS" << endl;
|
||||
for(auto m: finalInstructions){
|
||||
cout << "file: " << m.first.first << endl;
|
||||
cout << "line: " << m.first.second << endl;
|
||||
for(auto v: m.second){
|
||||
cout << "\tvar: " << v << endl;
|
||||
}
|
||||
cout << "\n";
|
||||
}
|
||||
|
||||
return finalInstructions;
|
||||
}
|
||||
@@ -1,3 +1,29 @@
|
||||
#pragma once
|
||||
|
||||
std::map< std::pair<std::string, int>, std::set<std::string>> findParameters(const std::map<std::string, std::vector<DefUseList>> &defUseByFunctions, const std::map<std::string, CommonBlock*> &commonBlocks, const std::map<std::string, std::vector<FuncInfo*>> &allFuncInfo);
|
||||
#include "../Utils/leak_detector.h"
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <cstring>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <cstdlib>
|
||||
#include <set>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include <tuple>
|
||||
|
||||
#include "dvm.h"
|
||||
#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"
|
||||
|
||||
std::map<std::pair<std::string, int>, std::set<std::string>>
|
||||
findParameters(const std::map<std::string, std::vector<DefUseList>> &defUseByFunctions,
|
||||
const std::map<std::string, CommonBlock*> &commonBlocks,
|
||||
const std::map<std::string, std::vector<FuncInfo*>> &allFuncInfo,
|
||||
const std::map<FuncInfo*, std::vector<SAPFOR::BasicBlock*>> &fullIR,
|
||||
const std::map<std::string, std::vector<LoopGraph*>>& loopGraph);
|
||||
@@ -1874,7 +1874,7 @@ static bool runAnalysis(SgProject &project, const int curr_regime, const bool ne
|
||||
else if (curr_regime == RENAME_SYMBOLS)
|
||||
runRenameSymbols(&project, commonBlocks);
|
||||
else if (curr_regime == FIND_PARAMETERS)
|
||||
parametersOfProject = findParameters(defUseByFunctions, commonBlocks, allFuncInfo);
|
||||
parametersOfProject = findParameters(defUseByFunctions, commonBlocks, allFuncInfo, fullIR, loopGraph);
|
||||
else if (curr_regime == BUILD_IR)
|
||||
{
|
||||
auto CFG_forFile = buildCFG(commonBlocks, allFuncInfo_IR, SAPFOR::CFG_Settings(0));
|
||||
|
||||
@@ -168,7 +168,7 @@ std::map<int, UserFiles> filesInfo; // information about open,close,write and re
|
||||
//
|
||||
|
||||
//for FIND_PARAMETERS
|
||||
std::map< std::pair<std::string, int>, std::set<std::string>> parametersOfProject; // [file, line] -> set[vars]
|
||||
std::map<std::pair<std::string, int>, std::set<std::string>> parametersOfProject; // [file, line] -> set[vars]
|
||||
//
|
||||
|
||||
//for GET_MIN_MAX_BLOCK_DIST
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
#pragma once
|
||||
|
||||
#define VERSION_SPF "2374"
|
||||
#define VERSION_SPF "2375"
|
||||
|
||||
Reference in New Issue
Block a user