Compare commits
13 Commits
42f64531b8
...
02baed087f
| Author | SHA1 | Date | |
|---|---|---|---|
| 02baed087f | |||
|
|
92d4c54eaf | ||
| 92bb44560c | |||
| 5f3da5d708 | |||
| e5b4d6cc50 | |||
| f5012508d1 | |||
| 95079e29e5 | |||
| 2cc9cf3254 | |||
| 5f4bb71dcf | |||
|
|
841eb0314d | ||
| af194134ba | |||
| e2ac45f48d | |||
| 1ac7fcca2a |
@@ -2561,7 +2561,7 @@ void ACC_ParallelLoopEnd(SgStatement *pardo)
|
||||
if (!WithAcrossClause())
|
||||
Create_Host_Loop_Subroutine_Main(hostproc_symb);
|
||||
else
|
||||
{
|
||||
{
|
||||
Create_Host_Across_Loop_Subroutine(hostproc_symb);
|
||||
first_do_par->extractStmt();
|
||||
}
|
||||
@@ -4572,6 +4572,15 @@ symb_list *isInSymbList(SgSymbol *s, symb_list *slist)
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
symb_list *isInSymbListByChar(SgSymbol *s, symb_list *slist)
|
||||
{
|
||||
symb_list *sl;
|
||||
for (sl = slist; sl; sl = sl->next)
|
||||
if (!strcmp(sl->symb->identifier(), s->identifier()))
|
||||
return(sl);
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
int ListElemNumber(SgExpression *list)
|
||||
{
|
||||
SgExpression *l;
|
||||
@@ -5208,7 +5217,6 @@ int Create_New_File(char *file_name, SgFile *file, char *fout_name)
|
||||
char *new_file_name, *dep_file_name;
|
||||
int ll;
|
||||
// old file
|
||||
printf(" in 0 Create_New_File\n");
|
||||
mod_gpu->extractStmt();
|
||||
ll = strlen(file_name) + 1;
|
||||
dep_file_name = (char *)malloc((unsigned)ll);
|
||||
@@ -5219,13 +5227,10 @@ int Create_New_File(char *file_name, SgFile *file, char *fout_name)
|
||||
file->saveDepFile(dep_file_name);
|
||||
|
||||
// new file
|
||||
printf(" in 1 Create_New_File\n");
|
||||
fcuf = new SgFile(0, "dvm_gpu");
|
||||
|
||||
fcuf->firstStatement()->insertStmtAfter(*mod_gpu);
|
||||
fcuf->saveDepFile("dvm_gpu.dep");
|
||||
printf(" in 2 Create_New_File\n");
|
||||
//fcuf->unparsestdout();
|
||||
|
||||
new_file_name = (char *)malloc((unsigned)(strlen(file_name) + 10));
|
||||
sprintf(new_file_name, "dvm_gpu_%s", fout_name);
|
||||
@@ -5236,7 +5241,7 @@ int Create_New_File(char *file_name, SgFile *file, char *fout_name)
|
||||
}
|
||||
fcuf->unparse(fout);
|
||||
fclose(fout);
|
||||
printf(" in 3 Create_New_File \n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -6106,7 +6111,7 @@ SgStatement *Create_Host_Loop_Subroutine(SgSymbol *sHostProc, int dependency)
|
||||
SgExpression *ev, *ered, *er, *red;
|
||||
SgSymbol *loc_var;
|
||||
reduction_operation_list *rl;
|
||||
|
||||
|
||||
red = TranslateReductionToOpenmp(&red_list->copy()); /* OpenMP */
|
||||
if (red != NULL) parallellist->append(*red); /* OpenMP */
|
||||
else addopenmp = 0; /* OpenMP */
|
||||
@@ -8090,7 +8095,6 @@ void CreateGPUModule()
|
||||
KernelWorkSymbols();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------------
|
||||
// create CUDA kernel
|
||||
@@ -8212,7 +8216,8 @@ SgStatement *CreateLoopKernel(SgSymbol *skernel, SgType *indexTypeInKernel)
|
||||
|
||||
// inserting IMPLICIT NONE
|
||||
if (!options.isOn(C_CUDA)) // Fortran-Cuda
|
||||
kernel_st->insertStmtAfter(*new SgStatement(IMPL_DECL), *kernel_st);
|
||||
kernel_st->insertStmtAfter(*new SgStatement(IMPL_DECL), *kernel_st);
|
||||
if (options.isOn(C_CUDA))
|
||||
RenamingCudaFunctionVariables(kernel_st, skernel, 1);
|
||||
for_kernel = 0;
|
||||
|
||||
@@ -8600,6 +8605,9 @@ SgStatement *CreateLoopKernel(SgSymbol *skernel, AnalyzeReturnGpuO1 &infoGpuO1,
|
||||
// inserting IMPLICIT NONE
|
||||
if (!options.isOn(C_CUDA)) // Fortran-Cuda
|
||||
kernel_st->insertStmtAfter(*new SgStatement(IMPL_DECL), *kernel_st);
|
||||
|
||||
if (options.isOn(C_CUDA))
|
||||
RenamingCudaFunctionVariables(kernel_st, skernel, 1);
|
||||
|
||||
for_kernel = 0;
|
||||
|
||||
@@ -8802,7 +8810,7 @@ SgStatement * CreateKernel_ForSequence(SgSymbol *kernel_symb, SgStatement *first
|
||||
|
||||
if (options.isOn(C_CUDA))
|
||||
{
|
||||
swapDimentionsInprivateList();
|
||||
swapDimentionsInprivateList();
|
||||
std::vector < std::stack < SgStatement*> > zero = std::vector < std::stack < SgStatement*> >(0);
|
||||
Translate_Fortran_To_C(kernel_st, kernel_st->lastNodeOfStmt(), zero, 0);
|
||||
}
|
||||
@@ -8823,7 +8831,8 @@ SgStatement * CreateKernel_ForSequence(SgSymbol *kernel_symb, SgStatement *first
|
||||
|
||||
if (!options.isOn(C_CUDA)) // Fortran-Cuda
|
||||
// inserting IMPLICIT NONE
|
||||
kernel_st->insertStmtAfter(*new SgStatement(IMPL_DECL), *kernel_st);
|
||||
kernel_st->insertStmtAfter(*new SgStatement(IMPL_DECL), *kernel_st);
|
||||
if (options.isOn(C_CUDA))
|
||||
RenamingCudaFunctionVariables(kernel_st, kernel_symb, 1);
|
||||
return(kernel_st);
|
||||
}
|
||||
@@ -13401,9 +13410,9 @@ SgStatement *Create_C_Adapter_Function(SgSymbol *sadapter)
|
||||
SgFunctionCallExp *sizeofL = new SgFunctionCallExp(*createNewFunctionSymbol("sizeof"));
|
||||
SgFunctionCallExp *sizeofLL = new SgFunctionCallExp(*createNewFunctionSymbol("sizeof"));
|
||||
SgFunctionCallExp *sizeofI = new SgFunctionCallExp(*createNewFunctionSymbol("sizeof"));
|
||||
|
||||
sizeofL->addArg(*new SgVarRefExp(new SgSymbol(VARIABLE_NAME, "long")));
|
||||
sizeofLL->addArg(*new SgVarRefExp(new SgSymbol(VARIABLE_NAME, "long long")));
|
||||
|
||||
sizeofL->addArg(*new SgKeywordValExp("long")); //addArg(*new SgVarRefExp(new SgSymbol(VARIABLE_NAME, "long")));
|
||||
sizeofLL->addArg(*new SgKeywordValExp("long long")); //addArg(*new SgVarRefExp(new SgSymbol(VARIABLE_NAME, "long long")));
|
||||
sizeofI->addArg(*new SgKeywordValExp("int")); //addArg(*new SgVarRefExp(new SgSymbol(VARIABLE_NAME, "int")));
|
||||
|
||||
stmt = new SgIfStmt(SgEqOp(*new SgVarRefExp(s_idxTypeInKernel), *new SgVarRefExp(*new SgSymbol(VARIABLE_NAME, "rt_LONG")))
|
||||
@@ -13698,6 +13707,9 @@ SgStatement *Create_C_Adapter_Function(SgSymbol *sadapter)
|
||||
if (red_list)
|
||||
InsertFinishReductionCalls(st_end, s_loop_ref, s_red_num);
|
||||
}
|
||||
|
||||
if (options.isOn(C_CUDA))
|
||||
RenamingCudaFunctionVariables(st_hedr, s_loop_ref, 0);
|
||||
|
||||
return(st_hedr);
|
||||
}
|
||||
@@ -13887,9 +13899,9 @@ SgStatement *Create_C_Adapter_Function_For_Sequence(SgSymbol *sadapter, SgStatem
|
||||
SgFunctionCallExp *sizeofL = new SgFunctionCallExp(*createNewFunctionSymbol("sizeof"));
|
||||
SgFunctionCallExp *sizeofLL = new SgFunctionCallExp(*createNewFunctionSymbol("sizeof"));
|
||||
SgFunctionCallExp *sizeofI = new SgFunctionCallExp(*createNewFunctionSymbol("sizeof"));
|
||||
|
||||
sizeofL->addArg(*new SgVarRefExp(new SgSymbol(VARIABLE_NAME, "long")));
|
||||
sizeofLL->addArg(*new SgVarRefExp(new SgSymbol(VARIABLE_NAME, "long long")));
|
||||
|
||||
sizeofL->addArg(*new SgKeywordValExp("long")); //addArg(*new SgVarRefExp(new SgSymbol(VARIABLE_NAME, "long")));
|
||||
sizeofLL->addArg(*new SgKeywordValExp("long long")); //addArg(*new SgVarRefExp(new SgSymbol(VARIABLE_NAME, "long long")));
|
||||
sizeofI->addArg(*new SgKeywordValExp("int")); //addArg(*new SgVarRefExp(new SgSymbol(VARIABLE_NAME, "int")));
|
||||
|
||||
stmt = new SgIfStmt(SgEqOp(*new SgVarRefExp(s_idxTypeInKernel), *new SgVarRefExp(*new SgSymbol(VARIABLE_NAME, "rt_LONG")))
|
||||
|
||||
@@ -637,7 +637,7 @@ ArgsForKernel *Create_C_Adapter_Function_Across(SgSymbol *sadapter)
|
||||
vector<SgStatement*> cuda_kernel;
|
||||
SgExpression *fe, *ae, *el, *arg_list;
|
||||
SgType *typ;
|
||||
SgSymbol *s_loop_ref, *sarg, *s;
|
||||
SgSymbol *s_loop_ref, *sarg, *s, *current_symbol;
|
||||
symb_list *sl;
|
||||
vector<SgSymbol *> argsForVariantFunction;
|
||||
|
||||
@@ -650,6 +650,7 @@ ArgsForKernel *Create_C_Adapter_Function_Across(SgSymbol *sadapter)
|
||||
mywarn(" end: getAllVars");
|
||||
|
||||
cuda_kernel.resize(countKernels);
|
||||
current_symbol = SymbMapping(current_file->filept->cur_symb); //CUR_FILE_CUR_SYMB();
|
||||
|
||||
if (options.isOn(ONE_THREAD))
|
||||
{
|
||||
@@ -1111,7 +1112,9 @@ ArgsForKernel *Create_C_Adapter_Function_Across(SgSymbol *sadapter)
|
||||
|
||||
mywarn(" end: create IF BLOCK ");
|
||||
}
|
||||
|
||||
if (options.isOn(C_CUDA))
|
||||
RenamingCudaFunctionVariables(st_hedr, s_loop_ref, 0); //(st_hedr, current_symbol->next(), 0);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -1464,9 +1467,9 @@ vector<ArgsForKernel> Create_C_Adapter_Function_Across_OneThread(SgSymbol *sadap
|
||||
SgFunctionCallExp *sizeofLL = new SgFunctionCallExp(*createNewFunctionSymbol("sizeof"));
|
||||
SgFunctionCallExp *sizeofI = new SgFunctionCallExp(*createNewFunctionSymbol("sizeof"));
|
||||
|
||||
sizeofL->addArg(*new SgVarRefExp(new SgSymbol(VARIABLE_NAME, "long")));
|
||||
sizeofLL->addArg(*new SgVarRefExp(new SgSymbol(VARIABLE_NAME, "long long")));
|
||||
sizeofI->addArg(*new SgVarRefExp(new SgSymbol(VARIABLE_NAME, "int")));
|
||||
sizeofL->addArg(*new SgKeywordValExp("long")); //addArg(*new SgVarRefExp(new SgSymbol(VARIABLE_NAME, "long")));
|
||||
sizeofLL->addArg(*new SgKeywordValExp("long long")); //addArg(*new SgVarRefExp(new SgSymbol(VARIABLE_NAME, "long long")));
|
||||
sizeofI->addArg(*new SgKeywordValExp("int")); //addArg(*new SgVarRefExp(new SgSymbol(VARIABLE_NAME, "int")));
|
||||
|
||||
stmt = new SgIfStmt(SgEqOp(*new SgVarRefExp(idxTypeInKernel), *new SgVarRefExp(*new SgSymbol(VARIABLE_NAME, "rt_LONG")))
|
||||
&&
|
||||
@@ -1589,6 +1592,8 @@ vector<ArgsForKernel> Create_C_Adapter_Function_Across_OneThread(SgSymbol *sadap
|
||||
|
||||
delete[]reduction_ptr;
|
||||
mywarn(" end Adapter Function");
|
||||
if (options.isOn(C_CUDA))
|
||||
RenamingCudaFunctionVariables(st_hedr, s_loop_ref, 0);
|
||||
return argsKernel;
|
||||
}
|
||||
|
||||
@@ -1638,8 +1643,8 @@ static inline void insertReductionArgs(SgSymbol **reduction_ptr, SgSymbol **redu
|
||||
//TODO!!
|
||||
if (rsl->locvar) //MAXLOC,MINLOC
|
||||
{
|
||||
for (int i = 0; i < rsl->number; ++i)
|
||||
funcCallKernel->addArg(*new SgArrayRefExp(*s, *new SgValueExp(i)));
|
||||
for (int k = 0; k < rsl->number; ++k)
|
||||
funcCallKernel->addArg(*new SgArrayRefExp(*reduction_loc_symb[i], *new SgValueExp(k)));
|
||||
s = s->next();
|
||||
e = new SgCastExp(*C_PointerType(options.isOn(C_CUDA) ? C_Type(rsl->locvar->type()) : new SgDescriptType(*SgTypeChar(), BIT_SIGNED)), *new SgVarRefExp(s));
|
||||
funcCallKernel->addArg(*e);
|
||||
@@ -1943,6 +1948,7 @@ vector<ArgsForKernel> Create_C_Adapter_Function_Across_variants(SgSymbol *sadapt
|
||||
SYMB_SCOPE(s->thesymb) = st_hedr->thebif;
|
||||
stmt = makeSymbolDeclaration(s);
|
||||
st_hedr->insertStmtAfter(*stmt, *st_hedr);
|
||||
reduction_loc_symb[ln] = s_loc_var;
|
||||
|
||||
s = sgrid_loc = GridSymbolForRedInAdapter(s, st_hedr);
|
||||
stmt = makeSymbolDeclaration(s);
|
||||
@@ -2395,9 +2401,9 @@ vector<ArgsForKernel> Create_C_Adapter_Function_Across_variants(SgSymbol *sadapt
|
||||
SgFunctionCallExp *sizeofLL = new SgFunctionCallExp(*createNewFunctionSymbol("sizeof"));
|
||||
SgFunctionCallExp *sizeofI = new SgFunctionCallExp(*createNewFunctionSymbol("sizeof"));
|
||||
|
||||
sizeofL->addArg(*new SgVarRefExp(new SgSymbol(VARIABLE_NAME, "long")));
|
||||
sizeofLL->addArg(*new SgVarRefExp(new SgSymbol(VARIABLE_NAME, "long long")));
|
||||
sizeofI->addArg(*new SgVarRefExp(new SgSymbol(VARIABLE_NAME, "int")));
|
||||
sizeofL->addArg(*new SgKeywordValExp("long")); //addArg(*new SgVarRefExp(new SgSymbol(VARIABLE_NAME, "long")));
|
||||
sizeofLL->addArg(*new SgKeywordValExp("long long")); //addArg(*new SgVarRefExp(new SgSymbol(VARIABLE_NAME, "long long")));
|
||||
sizeofI->addArg(*new SgKeywordValExp("int")); //addArg(*new SgVarRefExp(new SgSymbol(VARIABLE_NAME, "int")));
|
||||
|
||||
stmt = new SgIfStmt(SgEqOp(*new SgVarRefExp(idxTypeInKernel), *new SgVarRefExp(*new SgSymbol(VARIABLE_NAME, "rt_LONG")))
|
||||
&&
|
||||
@@ -3885,6 +3891,8 @@ vector<ArgsForKernel> Create_C_Adapter_Function_Across_variants(SgSymbol *sadapt
|
||||
delete[]reduction_symb;
|
||||
delete[]num_elems;
|
||||
mywarn(" end Adapter Function");
|
||||
if (options.isOn(C_CUDA))
|
||||
RenamingCudaFunctionVariables(st_hedr, s_loop_ref, 0);
|
||||
return argsKernel;
|
||||
}
|
||||
|
||||
@@ -4197,7 +4205,7 @@ SgStatement *CreateLoopKernelAcross(SgSymbol *skernel, ArgsForKernel* argsKer, S
|
||||
SgSymbol *redGrid = new SgSymbol(VARIABLE_NAME, tmp_list->red_grid->identifier());
|
||||
redGrid->setType(*new SgArrayType(*tmp_list->red_grid->type()));
|
||||
|
||||
st = AssignStatement(*new SgArrayRefExp(*redGrid, *new SgValueExp(0)), *red_expr_ref);
|
||||
st = AssignStatement(*new SgArrayRefExp(*redGrid, *new SgValueExp(0)), red_expr_ref->copy());
|
||||
if_st->lastExecutable()->insertStmtAfter(*st);
|
||||
tmp_list = tmp_list->next;
|
||||
}
|
||||
@@ -4227,7 +4235,8 @@ SgStatement *CreateLoopKernelAcross(SgSymbol *skernel, ArgsForKernel* argsKer, S
|
||||
#if debugMode
|
||||
mywarn(" end: CreateLoopKernelAcross");
|
||||
#endif
|
||||
|
||||
if (options.isOn(C_CUDA))
|
||||
RenamingCudaFunctionVariables(kernel_st, skernel, 1);
|
||||
ACROSS_MOD_IN_KERNEL = 0;
|
||||
return kernel_st;
|
||||
}
|
||||
@@ -5353,7 +5362,7 @@ SgStatement *CreateLoopKernelAcross(SgSymbol *skernel, ArgsForKernel* argsKer, i
|
||||
//get info of arrays in private and locvar lists
|
||||
swapDimentionsInprivateList();
|
||||
if (argsKer->symb.size() == 1 && options.isOn(GPU_O0))
|
||||
{
|
||||
{
|
||||
Translate_Fortran_To_C(mainFor->lexPrev()->controlParent());
|
||||
Translate_Fortran_To_C(mainFor, mainFor->lastNodeOfStmt(), copyOfBody, 0); //countOfCopies
|
||||
}
|
||||
@@ -5515,7 +5524,7 @@ SgStatement *CreateLoopKernelAcross(SgSymbol *skernel, ArgsForKernel* argsKer, i
|
||||
if (tmp_list->redvar_size == 0)
|
||||
{
|
||||
funcCall->addArg(*new SgArrayRefExp(*redGrid, *new SgVarRefExp(*tid)));
|
||||
funcCall->addArg(*red_expr_ref);
|
||||
funcCall->addArg(*new SgVarRefExp(*red_expr_ref->symbol()));
|
||||
st = AssignStatement(*new SgArrayRefExp(*redGrid, *new SgVarRefExp(*tid)), *funcCall);
|
||||
}
|
||||
else if (tmp_list->redvar_size > 0 && options.isOn(C_CUDA)) //TODO for Fortran
|
||||
@@ -5541,7 +5550,7 @@ SgStatement *CreateLoopKernelAcross(SgSymbol *skernel, ArgsForKernel* argsKer, i
|
||||
|
||||
SgSymbol *emin = argsKer->sizeVars[6];
|
||||
funcCall->addArg(*new SgArrayRefExp(*redGrid, *new SgVarRefExp(*tid) + *new SgVarRefExp(*tid1) * *new SgVarRefExp(*emin)));
|
||||
funcCall->addArg(*red_expr_ref);
|
||||
funcCall->addArg(*new SgVarRefExp(red_expr_ref->symbol()));
|
||||
st = AssignStatement(*new SgArrayRefExp(*redGrid, *new SgVarRefExp(*tid) + *new SgVarRefExp(*tid1) * *new SgVarRefExp(*emin)), *funcCall);
|
||||
}
|
||||
}
|
||||
@@ -5572,7 +5581,7 @@ SgStatement *CreateLoopKernelAcross(SgSymbol *skernel, ArgsForKernel* argsKer, i
|
||||
SgExpression* red_ref = NULL;
|
||||
|
||||
if (tmp_list->redvar_size == 0)
|
||||
red_ref = red_expr_ref;
|
||||
red_ref = &red_expr_ref->copy();
|
||||
else // TODO
|
||||
red_ref = new SgArrayRefExp(*red_expr_ref->symbol(), *new SgVarRefExp(freeS));
|
||||
|
||||
@@ -5590,12 +5599,12 @@ SgStatement *CreateLoopKernelAcross(SgSymbol *skernel, ArgsForKernel* argsKer, i
|
||||
e = &SgEqOp(*new SgArrayRefExp(*redGrid, *e1), *red_ref);
|
||||
else if (num == 9 || num == 10)
|
||||
{
|
||||
st = AssignStatement(*new SgArrayRefExp(*redGrid, *e1), *red_expr_ref);
|
||||
ifSt = new SgIfStmt(*red_expr_ref > *new SgArrayRefExp(*redGrid, *e1), *st);
|
||||
st = AssignStatement(*new SgArrayRefExp(*redGrid, *e1), red_expr_ref->copy());
|
||||
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());
|
||||
redGrid->setType(*new SgArrayType(*tmp_list->loc_grid->type()));
|
||||
locGrid->setType(*new SgArrayType(*tmp_list->loc_grid->type()));
|
||||
|
||||
if (options.isOn(C_CUDA))
|
||||
st = AssignStatement(*new SgArrayRefExp(*locGrid, *new SgValueExp(i), *e1), *new SgArrayRefExp(*loc_var_ref->symbol(), *new SgValueExp(i)));
|
||||
@@ -5745,6 +5754,8 @@ SgStatement *CreateLoopKernelAcross(SgSymbol *skernel, ArgsForKernel* argsKer, i
|
||||
// inserting IMPLICIT NONE
|
||||
if (!options.isOn(C_CUDA)) // Fortran-Cuda
|
||||
kernel_st->insertStmtAfter(*new SgStatement(IMPL_DECL), *kernel_st);
|
||||
if (options.isOn(C_CUDA))
|
||||
RenamingCudaFunctionVariables(kernel_st, skernel, 1);
|
||||
|
||||
ACROSS_MOD_IN_KERNEL = 0;
|
||||
return kernel_st;
|
||||
|
||||
@@ -172,7 +172,7 @@ static char* getNewCycleVar(const char *oldVar)
|
||||
{
|
||||
char *str = new char[strlen(oldVar) + 2];
|
||||
str[0] = '\0';
|
||||
strcat(str, "_");
|
||||
strcat(str, "__");
|
||||
strcat(str, oldVar);
|
||||
return str;
|
||||
}
|
||||
@@ -3179,7 +3179,7 @@ void initF2C_FunctionCalls()
|
||||
handlersOfFunction[string("sinh")] = FunctionParam("sinh", 1, &createNewFCall);
|
||||
handlersOfFunction[string("shifta")] = FunctionParam("shifta", 2, &createNewFCall);
|
||||
handlersOfFunction[string("shiftl")] = FunctionParam("lshft", 2, &createNewFCall);
|
||||
handlersOfFunction[string("shiftr")] = FunctionParam("rshft", 2, &createNewFCall);
|
||||
handlersOfFunction[string("shiftr")] = FunctionParam("shiftr", 2, &createNewFCall);
|
||||
handlersOfFunction[string("tan")] = FunctionParam("tan", 1, &createNewFCall);
|
||||
handlersOfFunction[string("tand")] = FunctionParam("tan", 0, &__sindcosdtand_handler);
|
||||
handlersOfFunction[string("tanh")] = FunctionParam("tanh", 1, &createNewFCall);
|
||||
@@ -3391,3 +3391,185 @@ void Translate_Fortran_To_C(SgStatement *firstStmt, SgStatement *lastStmt, vecto
|
||||
printf("END: CONVERTION OF BODY ON LINE %d\n", number_of_loop_line);
|
||||
#endif
|
||||
}
|
||||
|
||||
void ChangeSymbolName(SgSymbol *symb)
|
||||
{
|
||||
char *name = new char[strlen(symb->identifier())+2];
|
||||
sprintf(name, "_%s", symb->identifier());
|
||||
SYMB_IDENT(symb->thesymb) = name;
|
||||
}
|
||||
|
||||
void RenamingNewProcedureVariables(SgSymbol *proc_name)
|
||||
{
|
||||
// replacing new procedure names to avoid conflicts with C language keywords and intrinsic function names
|
||||
SgSymbol *sl;
|
||||
for(sl = proc_name; sl; sl = sl->next())
|
||||
switch(sl->variant())
|
||||
{
|
||||
case VARIABLE_NAME:
|
||||
case CONST_NAME:
|
||||
case FIELD_NAME:
|
||||
case TYPE_NAME:
|
||||
case LABEL_VAR:
|
||||
case COMMON_NAME:
|
||||
case NAMELIST_NAME:
|
||||
ChangeSymbolName(sl);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
SgSymbol *hasSameNameAsSource(SgSymbol *symb)
|
||||
{
|
||||
symb_list *sl;
|
||||
if (!symb)
|
||||
return NULL;
|
||||
if (sl=isInSymbListByChar(symb, acc_array_list))
|
||||
return sl->symb;
|
||||
SgExpression *el;
|
||||
if (newVars.size() != 0)
|
||||
{
|
||||
correctPrivateList(RESTORE);
|
||||
newVars.clear();
|
||||
}
|
||||
for (el = private_list; el; el = el->rhs())
|
||||
if (!strcmp(el->lhs()->symbol()->identifier(), symb->identifier()))
|
||||
return el->lhs()->symbol();
|
||||
if (el=isInUsesListByChar(symb->identifier()))
|
||||
return el->lhs()->symbol();
|
||||
for (el = dvm_parallel_dir->expr(2); el; el = el->rhs())
|
||||
if (!strcmp(el->lhs()->symbol()->identifier(), symb->identifier()))
|
||||
return el->lhs()->symbol();
|
||||
reduction_operation_list *rl;
|
||||
for (rl = red_struct_list; rl; rl = rl->next)
|
||||
{
|
||||
if(rl->redvar && !strcmp(rl->redvar->identifier(), symb->identifier()))
|
||||
return rl->redvar;
|
||||
if(rl->locvar && !strcmp(rl->locvar->identifier(), symb->identifier()))
|
||||
return rl->locvar;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
/*
|
||||
void RenamingCudaFunctionVariables(SgStatement *first, SgStatement *last, SgSymbol *k_symb)
|
||||
{ // replacing kernel names to avoid conflicts with C language keywords and intrinsic function names
|
||||
SgSymbol *sl;
|
||||
for (sl=k_symb->next(); sl; sl=sl->next())
|
||||
{
|
||||
SgSymbol *s_symb = hasSameNameAsSource(sl);
|
||||
if (s_symb)
|
||||
{
|
||||
replaceSymbInStmts(first->thebif, last->thebif, s_symb->thesymb, sl->thesymb);
|
||||
ChangeSymbolName(sl);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ReplacingVariablesInTranslatedCode(SgStatement *first, SgSymbol *k_symb)
|
||||
{ // replacing source symbols by kernel symbols of the same name
|
||||
SgSymbol *sl;
|
||||
|
||||
for (sl=k_symb->next(); sl; sl=sl->next())
|
||||
{
|
||||
if (sl->scope() != kernel_st || sl->variant() != VARIABLE_NAME)
|
||||
continue;
|
||||
SgSymbol *s_symb = hasSameNameAsSource(sl);
|
||||
if (s_symb)
|
||||
{ //printf("::: %s id:%d variant:%d\n",sl->identifier(), sl->id(), sl->variant());
|
||||
//replaceSymbInStmtsSameName(first->thebif, last->thebif, s_symb->thesymb, sl->thesymb);
|
||||
first->replaceSymbBySymbSameName(s_symb,sl);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void RenamingCudaFunctionVariables(SgStatement *first, SgStatement *first_body, SgSymbol *k_symb, int replace_flag)
|
||||
{ // replacing kernel names to avoid conflicts with C language keywords and intrinsic function names
|
||||
if (first_body)
|
||||
ReplacingVariablesInTranslatedCode(first_body, k_symb);
|
||||
for (sl=k_symb->next(); sl; sl=sl->next())
|
||||
{
|
||||
if (sl->scope() != kernel_st || sl->variant() != VARIABLE_NAME)
|
||||
continue;
|
||||
|
||||
SgSymbol *s_symb = hasSameNameAsSource(sl);
|
||||
if (s_symb)
|
||||
{
|
||||
if (replace_flag)
|
||||
first->replaceSymbBySymb(s_symb,sl);
|
||||
//replaceSymbInStmts(first->thebif, last->thebif, s_symb->thesymb, sl->thesymb);
|
||||
ChangeSymbolName(sl);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int isCudaVariable(SgSymbol *symb)
|
||||
{
|
||||
if(!strcmp(symb->identifier(), "blocks")) return 1;
|
||||
if(!strcmp(symb->identifier(), "threads")) return 1;
|
||||
if(!strcmp(symb->identifier(), "threadIdx")) return 1;
|
||||
if(!strcmp(symb->identifier(), "blockIdx")) return 1;
|
||||
if(!strcmp(symb->identifier(), "blockDim")) return 1;
|
||||
if(!strcmp(symb->identifier(), "gridDim")) return 1;
|
||||
return 0;
|
||||
}
|
||||
*/
|
||||
|
||||
int sameVariableName(SgSymbol *symb1, SgSymbol *symb2)
|
||||
{
|
||||
if (!symb1 || !symb2 || (symb1->variant() != VARIABLE_NAME && symb1->variant() != CONST_NAME) || symb2->variant() != VARIABLE_NAME && symb2->variant() != CONST_NAME)
|
||||
return 0;
|
||||
if (!strcmp (symb1->identifier(), symb2->identifier()))
|
||||
return 1;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
void replaceSymbolSameNameInExpr(SgExpression *expr, SgSymbol *symb, SgSymbol *s_new)
|
||||
{
|
||||
//SgRecordRefExp *re;
|
||||
if (!expr || !symb || !s_new)
|
||||
return;
|
||||
//if (isSgRecordRefExp(expr)) //&& isCudaVariable(re->recordName()))
|
||||
// replaceSymbolSameNameInExpr(expr->lhs(), symb, s_new);
|
||||
if (expr->symbol())
|
||||
if (sameVariableName(expr->symbol(), symb))
|
||||
expr->setSymbol(s_new);
|
||||
replaceSymbolSameNameInExpr(expr->lhs(), symb, s_new);
|
||||
replaceSymbolSameNameInExpr(expr->rhs(), symb, s_new);
|
||||
}
|
||||
|
||||
void replaceVariableSymbSameNameInStatements(SgStatement *first, SgStatement *last, SgSymbol *symb, SgSymbol *s_new, int replace_flag)
|
||||
{
|
||||
SgStatement *stmt;
|
||||
for (stmt=first; stmt; stmt = stmt->lexNext())
|
||||
{
|
||||
if (sameVariableName (stmt->symbol(), symb))
|
||||
stmt->setSymbol(*s_new);
|
||||
replaceSymbolSameNameInExpr(stmt->expr(0), symb, s_new);
|
||||
replaceSymbolSameNameInExpr(stmt->expr(1), symb, s_new);
|
||||
replaceSymbolSameNameInExpr(stmt->expr(2), symb, s_new);
|
||||
if (last && stmt == last)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void RenamingCudaFunctionVariables(SgStatement *first, SgSymbol *k_symb, int replace_flag)
|
||||
{ // replacing kernel names to avoid conflicts with C language keywords and intrinsic function names
|
||||
SgSymbol *sl;
|
||||
for (sl=k_symb->next(); sl; sl=sl->next())
|
||||
{
|
||||
if (sl->scope() != first || sl->variant() != VARIABLE_NAME)
|
||||
continue;
|
||||
|
||||
SgSymbol *s_symb = hasSameNameAsSource(sl);
|
||||
if (s_symb)
|
||||
{
|
||||
if (replace_flag)
|
||||
replaceVariableSymbSameNameInStatements(first,first->lastNodeOfStmt(), s_symb, sl, replace_flag);
|
||||
// first->replaceSymbBySymb(s_symb,sl);
|
||||
//replaceSymbInStmts(first->thebif, last->thebif, s_symb->thesymb, sl->thesymb);
|
||||
ChangeSymbolName(sl);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -357,6 +357,7 @@ SgStatement *InsertProcedureCopy(SgStatement *st_header, SgSymbol *sproc, int is
|
||||
|
||||
if (options.isOn(C_CUDA))
|
||||
{
|
||||
RenamingNewProcedureVariables(new_sproc); // to avoid conflicts with C language keywords
|
||||
int flagHasDerivedTypeVariables = HasDerivedTypeVariables(new_header);
|
||||
|
||||
end_st = new_header->lastNodeOfStmt();
|
||||
|
||||
@@ -1219,6 +1219,7 @@ void AddRemoteAccessBufferList_ToArrayList();
|
||||
void AddRemoteAccessBufferList_ToArrayList();
|
||||
SgExpression * ExpressionListsUnion(SgExpression *list, SgExpression *alist);
|
||||
SgExpression *isInExprList(SgExpression *e,SgExpression *list);
|
||||
symb_list *isInSymbList(SgSymbol *s, symb_list *slist);
|
||||
symb_list *isInSymbListByChar(SgSymbol *s, symb_list *slist);
|
||||
symb_list *SymbolListsUnion(symb_list *slist1, symb_list *slist2);
|
||||
void UnregisterVariables(int begin_block);
|
||||
@@ -2097,7 +2098,11 @@ void convertExpr(SgExpression*, SgExpression*&);
|
||||
void convertExpr(SgExpression*, SgExpression*&);
|
||||
void initSupportedVars(void);
|
||||
void initF2C_FunctionCalls(void);
|
||||
void initIntrinsicFunctionNames();
|
||||
void initIntrinsicFunctionNames();
|
||||
void ChangeSymbolName(SgSymbol *symb);
|
||||
void RenamingNewProcedureVariables(SgSymbol *proc_name);
|
||||
SgSymbol *hasSameNameAsSource(SgSymbol *symb);
|
||||
void RenamingCudaFunctionVariables(SgStatement *first, SgSymbol *k_symb, int replace_flag);
|
||||
void replaceVariableSymbSameNameInStatements(SgStatement *first, SgStatement *last, SgSymbol *symb, SgSymbol *s_new, int replace_flag);
|
||||
/* acc_across.cpp */
|
||||
ArgsForKernel *Create_C_Adapter_Function_Across(SgSymbol *sadapter);
|
||||
|
||||
@@ -10,7 +10,8 @@
|
||||
#include "../IR.h"
|
||||
|
||||
template <class NodeType>
|
||||
class BackwardDataFlowAnalysis : public DataFlowAnalysis<NodeType> {
|
||||
class BackwardDataFlowAnalysis : public DataFlowAnalysis<NodeType>
|
||||
{
|
||||
std::vector<SAPFOR::BasicBlock*> reorderSequence(const std::vector<SAPFOR::BasicBlock*>& blocks,
|
||||
const std::set<SAPFOR::BasicBlock*> back_edge_sources);
|
||||
public:
|
||||
|
||||
@@ -29,6 +29,7 @@ public:
|
||||
virtual bool addIn(const DataType& data) = 0;
|
||||
virtual bool addOut(const DataType& data) = 0;
|
||||
|
||||
virtual bool updateState() { return false; }
|
||||
virtual bool forwardData(const DataType& data) = 0;
|
||||
|
||||
bool newerThan(const DataFlowAnalysisNode<DataType>* block) const { return out_cnt > block->in_cnt; }
|
||||
|
||||
@@ -27,6 +27,8 @@ template <class DataType>
|
||||
void DataFlowAnalysisNode<DataType>::doStep()
|
||||
{
|
||||
int in_max_cnt = CNT_NOTINIT, out_max_cnt = CNT_NOTINIT;
|
||||
|
||||
bool uniq_change = updateState();
|
||||
for (auto next : prev_blocks)
|
||||
{
|
||||
if (in_cnt < next->out_cnt)
|
||||
@@ -49,7 +51,7 @@ void DataFlowAnalysisNode<DataType>::doStep()
|
||||
}
|
||||
}
|
||||
|
||||
bool was_notinit = (out_cnt == CNT_NOTINIT);
|
||||
uniq_change |= (out_cnt == CNT_NOTINIT);
|
||||
|
||||
if (out_max_cnt != CNT_NOTINIT)
|
||||
out_cnt = out_max_cnt;
|
||||
@@ -58,7 +60,7 @@ void DataFlowAnalysisNode<DataType>::doStep()
|
||||
in_cnt = in_max_cnt;
|
||||
|
||||
// TODO: fix counter overflow
|
||||
if (was_notinit)
|
||||
if (uniq_change)
|
||||
{
|
||||
out_cnt++;
|
||||
in_cnt++;
|
||||
@@ -68,7 +70,8 @@ void DataFlowAnalysisNode<DataType>::doStep()
|
||||
/* definitions for DataFlowAnalysis class */
|
||||
|
||||
template <class NodeType>
|
||||
void DataFlowAnalysis<NodeType>::analyze() {
|
||||
void DataFlowAnalysis<NodeType>::analyze()
|
||||
{
|
||||
auto curr = 0;
|
||||
auto stop = nodes.size();
|
||||
|
||||
|
||||
@@ -14,6 +14,40 @@ using std::set;
|
||||
using std::remove_if;
|
||||
|
||||
#define PRINT_USELESS_STATEMENTS 1
|
||||
#define DEBUG_IR 0
|
||||
|
||||
// detect wich registers are used at more than one block
|
||||
// such registers should participate in live analysis to spread information about useful instructions
|
||||
// such registers appears at loops
|
||||
static void fillSharedRegs(const map<FuncInfo*, vector<SAPFOR::BasicBlock*>>& cfg, set<SAPFOR::Argument*>& shared_regs)
|
||||
{
|
||||
map<SAPFOR::Argument*, SAPFOR::BasicBlock*> used_at;
|
||||
|
||||
for (const auto& byFunc : cfg)
|
||||
{
|
||||
for (const auto& byBlock : byFunc.second)
|
||||
{
|
||||
for (const auto& byIrBlock : byBlock->getInstructions())
|
||||
{
|
||||
auto instr = byIrBlock->getInstruction();
|
||||
|
||||
set<SAPFOR::Argument*> used = { instr->getResult(), instr->getArg1(), instr->getArg2() };
|
||||
for (auto arg : used)
|
||||
{
|
||||
if(arg && arg->getType() == SAPFOR::CFG_ARG_TYPE::REG)
|
||||
{
|
||||
auto it = used_at.find(arg);
|
||||
|
||||
if (it == used_at.end())
|
||||
used_at[arg] = byBlock;
|
||||
else if(it->second != byBlock)
|
||||
shared_regs.insert(arg);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void updateUseDefForInstruction(SAPFOR::BasicBlock* block, SAPFOR::Instruction* instr,
|
||||
set<SAPFOR::Argument*>& use, set<SAPFOR::Argument*>& def,
|
||||
@@ -39,7 +73,9 @@ static void updateUseDefForInstruction(SAPFOR::BasicBlock* block, SAPFOR::Instru
|
||||
{
|
||||
for (SAPFOR::Argument* r : res)
|
||||
{
|
||||
if (use.find(r) != use.end() || r->getMemType() != SAPFOR::CFG_MEM_TYPE::LOCAL_)
|
||||
if (use.find(r) != use.end() ||
|
||||
r->getMemType() != SAPFOR::CFG_MEM_TYPE::LOCAL_ ||
|
||||
!(r->getType() == SAPFOR::CFG_ARG_TYPE::VAR || r->getType() == SAPFOR::CFG_ARG_TYPE::REG))
|
||||
{
|
||||
useful = true;
|
||||
break;
|
||||
@@ -88,8 +124,8 @@ static void updateUseDefForInstruction(SAPFOR::BasicBlock* block, SAPFOR::Instru
|
||||
use.insert(e);
|
||||
def.erase(e);
|
||||
}
|
||||
|
||||
insertIfVar(args.begin(), args.end(), usedByThisBlock);
|
||||
|
||||
usedByThisBlock.insert(args.begin(), args.end());
|
||||
}
|
||||
|
||||
if ((instr->getOperation() == SAPFOR::CFG_OP::F_CALL || instr->getOperation() == SAPFOR::CFG_OP::PARAM) && fName == "")
|
||||
@@ -128,12 +164,13 @@ static void buildUseDef(SAPFOR::BasicBlock* block, set<SAPFOR::Argument*>& use,
|
||||
useful[i] = u;
|
||||
}
|
||||
|
||||
insertIfVar(use_with_regs.begin(), use_with_regs.end(), use);
|
||||
insertIfVar(def_with_regs.begin(), def_with_regs.end(), def);
|
||||
use.insert(use_with_regs.begin(), use_with_regs.end());
|
||||
def.insert(def_with_regs.begin(), def_with_regs.end());
|
||||
}
|
||||
|
||||
|
||||
class DeadCodeAnalysisNode : public DataFlowAnalysisNode<map<SAPFOR::Argument*, vector<SAPFOR::BasicBlock*>>> {
|
||||
class DeadCodeAnalysisNode : public DataFlowAnalysisNode<map<SAPFOR::Argument*, vector<SAPFOR::BasicBlock*>>>
|
||||
{
|
||||
private:
|
||||
vector<bool> useful;
|
||||
bool useful_block = false;
|
||||
@@ -142,6 +179,7 @@ private:
|
||||
|
||||
vector<SAPFOR::Argument*>& formal_parameters;
|
||||
const map<string, FuncInfo*>& funcByName;
|
||||
const set<SAPFOR::Argument*>& shared_regs;
|
||||
public:
|
||||
bool updateJumpStatus()
|
||||
{
|
||||
@@ -196,30 +234,41 @@ public:
|
||||
return updated;
|
||||
}
|
||||
|
||||
map<SAPFOR::Argument*, vector<SAPFOR::BasicBlock*>> getIn() {
|
||||
map<SAPFOR::Argument*, vector<SAPFOR::BasicBlock*>> getIn()
|
||||
{
|
||||
return getBlock()->getLiveOut();
|
||||
}
|
||||
|
||||
map<SAPFOR::Argument*, vector<SAPFOR::BasicBlock*>> getOut() {
|
||||
map<SAPFOR::Argument*, vector<SAPFOR::BasicBlock*>> getOut()
|
||||
{
|
||||
return getBlock()->getLiveIn();
|
||||
}
|
||||
|
||||
bool addIn(const map<SAPFOR::Argument*, vector<SAPFOR::BasicBlock*>>& data) {
|
||||
bool inserted = getBlock()->addLiveOut(data);
|
||||
|
||||
if (!useful_block)
|
||||
inserted |= updateNextNotEmpty();
|
||||
|
||||
inserted |= updateJumpStatus();
|
||||
|
||||
return inserted;
|
||||
bool addIn(const map<SAPFOR::Argument*, vector<SAPFOR::BasicBlock*>>& data)
|
||||
{
|
||||
return getBlock()->addLiveOut(data);
|
||||
}
|
||||
|
||||
bool addOut(const map<SAPFOR::Argument*, vector<SAPFOR::BasicBlock*>>& data) {
|
||||
bool addOut(const map<SAPFOR::Argument*, vector<SAPFOR::BasicBlock*>>& data)
|
||||
{
|
||||
return getBlock()->addLiveIn(data);
|
||||
}
|
||||
|
||||
bool forwardData(const map<SAPFOR::Argument*, vector<SAPFOR::BasicBlock*>>& data) {
|
||||
bool updateState()
|
||||
{
|
||||
bool updated = false;
|
||||
|
||||
if (!useful_block)
|
||||
updated |= updateNextNotEmpty();
|
||||
|
||||
updated |= updateJumpStatus();
|
||||
updated |= this->forwardData({ });
|
||||
|
||||
return updated;
|
||||
}
|
||||
|
||||
bool forwardData(const map<SAPFOR::Argument*, vector<SAPFOR::BasicBlock*>>& data)
|
||||
{
|
||||
bool inserted = false;
|
||||
SAPFOR::BasicBlock* bb= getBlock();
|
||||
|
||||
@@ -235,30 +284,34 @@ public:
|
||||
|
||||
for (SAPFOR::Argument* arg : use)
|
||||
{
|
||||
bool this_block = usedByThisBlock.find(arg) != usedByThisBlock.end();
|
||||
|
||||
if (!this_block)
|
||||
if(arg && (arg->getType() == SAPFOR::CFG_ARG_TYPE::VAR ||
|
||||
(arg->getType() == SAPFOR::CFG_ARG_TYPE::REG && shared_regs.find(arg) != shared_regs.end())))
|
||||
{
|
||||
auto data_it = data.find(arg);
|
||||
bool this_block = usedByThisBlock.find(arg) != usedByThisBlock.end();
|
||||
|
||||
if (data_it == data.end())
|
||||
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
||||
|
||||
inserted |= bb->addLiveIn({ *data_it });
|
||||
}
|
||||
else
|
||||
{
|
||||
auto in_it = in.find(arg);
|
||||
bool skip = false;
|
||||
if (in_it != in.end())
|
||||
if (!this_block)
|
||||
{
|
||||
if (in_it->second.size() == 1 && *(in_it->second.begin()) == bb)
|
||||
skip = true; // nothing to do, inserted = false
|
||||
else
|
||||
bb->removeLiveIn(arg);
|
||||
auto data_it = data.find(arg);
|
||||
|
||||
if (data_it == data.end())
|
||||
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
||||
|
||||
inserted |= bb->addLiveIn({ *data_it });
|
||||
}
|
||||
else
|
||||
{
|
||||
auto in_it = in.find(arg);
|
||||
bool skip = false;
|
||||
if (in_it != in.end())
|
||||
{
|
||||
if (in_it->second.size() == 1 && *(in_it->second.begin()) == bb)
|
||||
skip = true; // nothing to do, inserted = false
|
||||
else
|
||||
bb->removeLiveIn(arg);
|
||||
}
|
||||
if(!skip)
|
||||
inserted |= bb->addLiveIn({ { arg, { bb } } });
|
||||
}
|
||||
if(!skip)
|
||||
inserted |= bb->addLiveIn({ { arg, { bb } } });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -291,38 +344,39 @@ public:
|
||||
|
||||
DeadCodeAnalysisNode(SAPFOR::BasicBlock* block,
|
||||
vector<SAPFOR::Argument*>& formal_parameters,
|
||||
const map<string, FuncInfo*>& funcByName)
|
||||
const map<string, FuncInfo*>& funcByName,
|
||||
const set<SAPFOR::Argument*>& shared_regs)
|
||||
:
|
||||
formal_parameters(formal_parameters),
|
||||
funcByName(funcByName)
|
||||
funcByName(funcByName),
|
||||
shared_regs(shared_regs)
|
||||
{
|
||||
setBlock(block);
|
||||
useful.resize(block->getInstructions().size(), false);
|
||||
set<SAPFOR::Argument*> use, def;
|
||||
set<SAPFOR::Argument*> usedByThisBlock;
|
||||
|
||||
buildUseDef(getBlock(), use, def, this->formal_parameters, useful, usedByThisBlock, funcByName);
|
||||
|
||||
for (SAPFOR::Argument* arg : use)
|
||||
getBlock()->addLiveIn({ { arg, { getBlock() } } });
|
||||
}
|
||||
|
||||
const vector<bool>& getResult() { return useful; }
|
||||
};
|
||||
|
||||
class DeadCodeAnalysis : public BackwardDataFlowAnalysis<DeadCodeAnalysisNode> {
|
||||
class DeadCodeAnalysis : public BackwardDataFlowAnalysis<DeadCodeAnalysisNode>
|
||||
{
|
||||
protected:
|
||||
vector<SAPFOR::Argument*>& formal_parameters;
|
||||
const map<string, FuncInfo*>& funcByName;
|
||||
const set<SAPFOR::Argument*>& shared_regs;
|
||||
|
||||
DeadCodeAnalysisNode* createNode(SAPFOR::BasicBlock* block) override {
|
||||
return new DeadCodeAnalysisNode(block, formal_parameters, funcByName);
|
||||
DeadCodeAnalysisNode* createNode(SAPFOR::BasicBlock* block) override
|
||||
{
|
||||
return new DeadCodeAnalysisNode(block, formal_parameters, funcByName, shared_regs);
|
||||
}
|
||||
public:
|
||||
DeadCodeAnalysis(vector<SAPFOR::Argument*>& formal_parameters, const map<string, FuncInfo*>& funcByName)
|
||||
DeadCodeAnalysis(vector<SAPFOR::Argument*>& formal_parameters,
|
||||
const map<string, FuncInfo*>& funcByName,
|
||||
const set<SAPFOR::Argument*>& shared_regs)
|
||||
:
|
||||
formal_parameters(formal_parameters),
|
||||
funcByName(funcByName)
|
||||
funcByName(funcByName),
|
||||
shared_regs(shared_regs)
|
||||
{ }
|
||||
};
|
||||
|
||||
@@ -394,8 +448,10 @@ void removeDeadCode(SgStatement* func,
|
||||
|
||||
cfg_pair.second.erase(remove_unreachable_it, cfg_pair.second.end());
|
||||
|
||||
#if DEBUG_IR
|
||||
dumpCFG({ cfg_pair }, false);
|
||||
#endif
|
||||
// detect useless code
|
||||
|
||||
vector<SAPFOR::Argument*> func_parameters(cfg_pair.first->funcParams.countOfPars, NULL);
|
||||
|
||||
map<string, FuncInfo*> funcByName;
|
||||
@@ -403,8 +459,11 @@ void removeDeadCode(SgStatement* func,
|
||||
for (auto& byFile : allFuncs)
|
||||
for (auto byFunc : byFile.second)
|
||||
funcByName[byFunc->funcName] = byFunc;
|
||||
|
||||
set<SAPFOR::Argument*> shared_regs;
|
||||
fillSharedRegs({ cfg_pair }, shared_regs);
|
||||
|
||||
DeadCodeAnalysis analysis_object(func_parameters, funcByName);
|
||||
DeadCodeAnalysis analysis_object(func_parameters, funcByName, shared_regs);
|
||||
|
||||
analysis_object.fit(cfg_pair.second);
|
||||
analysis_object.analyze();
|
||||
@@ -462,38 +521,45 @@ void removeDeadCode(SgStatement* func,
|
||||
__spf_print(PRINT_USELESS_STATEMENTS, "[Useless statement on line %d and file %s]\n", rem->lineNumber(), rem->fileName());
|
||||
rem->deleteStmt();
|
||||
}
|
||||
|
||||
remove.clear();
|
||||
//remove empty blocks
|
||||
for (auto st = start; st != end; st = st->lexNext())
|
||||
|
||||
//remove empty blocks
|
||||
do
|
||||
{
|
||||
const int var = st->variant();
|
||||
if ((var == FOR_NODE || var == WHILE_NODE || var == IF_NODE || var == SWITCH_NODE) &&
|
||||
st->lexNext()->variant() == CONTROL_END)
|
||||
remove.clear();
|
||||
for (auto st = start; st != end; st = st->lexNext())
|
||||
{
|
||||
remove.push_back(st);
|
||||
continue;
|
||||
}
|
||||
const int var = st->variant();
|
||||
if ((var == FOR_NODE || var == WHILE_NODE || var == SWITCH_NODE) &&
|
||||
st->lexNext()->variant() == CONTROL_END)
|
||||
{
|
||||
remove.push_back(st);
|
||||
}
|
||||
else if (var == IF_NODE)
|
||||
{
|
||||
SgStatement* ifS = st;
|
||||
while (ifS->lexNext()->variant() == ELSEIF_NODE)
|
||||
ifS = ifS->lexNext();
|
||||
|
||||
if (var == IF_NODE)
|
||||
{
|
||||
SgStatement* ifS = st;
|
||||
while (ifS->lexNext()->variant() == ELSEIF_NODE)
|
||||
SgStatement* lastNode = ifS->lastNodeOfStmt();
|
||||
ifS = ifS->lexNext();
|
||||
|
||||
if (ifS->lexNext()->variant() == CONTROL_END)
|
||||
remove.push_back(st);
|
||||
while (ifS->variant() == CONTROL_END && ifS != lastNode)
|
||||
ifS = ifS->lexNext();
|
||||
|
||||
if (ifS == lastNode)
|
||||
remove.push_back(st);
|
||||
}
|
||||
|
||||
//TODO: SWITCH and other block statements
|
||||
}
|
||||
|
||||
//TODO: SWITCH and other block statements
|
||||
}
|
||||
|
||||
|
||||
for (auto& rem : remove)
|
||||
{
|
||||
__spf_print(PRINT_USELESS_STATEMENTS, "[Useless block statement on line %d and file %s]\n", rem->lineNumber(), rem->fileName());
|
||||
rem->deleteStmt();
|
||||
}
|
||||
for (auto& rem : remove)
|
||||
{
|
||||
__spf_print(PRINT_USELESS_STATEMENTS, "[Useless block statement on line %d and file %s]\n", rem->lineNumber(), rem->fileName());
|
||||
rem->deleteStmt();
|
||||
}
|
||||
} while (remove.size());
|
||||
|
||||
deleteCFG(cfg);
|
||||
}
|
||||
@@ -290,20 +290,17 @@ static bool isSymbolInExpression(SgSymbol* symbol, SgExpression* exp)
|
||||
isSymbolInExpression(symbol, exp->rhs());
|
||||
}
|
||||
|
||||
static FuncInfo* findFunc(string fileName, string funcName, const map<string, vector<FuncInfo*>>& allFuncInfo)
|
||||
static FuncInfo* findFuncByName(string funcName, const map<string, vector<FuncInfo*>>& allFuncInfo)
|
||||
{
|
||||
auto fileInfo = allFuncInfo.find(fileName);
|
||||
if (fileInfo == allFuncInfo.end())
|
||||
return nullptr;
|
||||
|
||||
for (auto funcInfo : fileInfo->second)
|
||||
if (funcInfo->funcName == funcName)
|
||||
return funcInfo;
|
||||
for (const auto& fileFuncs : allFuncInfo)
|
||||
for (auto funcInfo : fileFuncs.second)
|
||||
if (funcInfo->funcName == funcName)
|
||||
return funcInfo;
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static FuncInfo* getCurrectFunc(SgStatement* stmt, const map<string, vector<FuncInfo*>>& allFuncInfo)
|
||||
static FuncInfo* getCurrentFunc(SgStatement* stmt, const map<string, vector<FuncInfo*>>& allFuncInfo)
|
||||
{
|
||||
auto fileInfo = allFuncInfo.find(stmt->fileName());
|
||||
if (fileInfo == allFuncInfo.end())
|
||||
@@ -855,7 +852,7 @@ void removePrivates(string filename, vector<Messages>& messages,
|
||||
for (auto& dcLoopRem : removeDC)
|
||||
{
|
||||
auto loopStmt = dcLoopRem->loop->GetOriginal();
|
||||
FuncInfo* currFunc = getCurrectFunc(loopStmt, allFuncInfo);
|
||||
FuncInfo* currFunc = getCurrentFunc(loopStmt, allFuncInfo);
|
||||
|
||||
if (currFunc == nullptr)
|
||||
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
||||
@@ -1140,7 +1137,7 @@ static SgForStmt* getLoopStmtForVar(SgStatement* stmt, string loopVar)
|
||||
static vector<ArraySubscript> getFixedSubscriptsVector(SgArrayRefExp* arrayRef, int dimensionsNum = 0,
|
||||
SgStatement* stmt = nullptr)
|
||||
{
|
||||
if (arrayRef->numberOfSubscripts() == 0)
|
||||
if (arrayRef == nullptr || arrayRef->numberOfSubscripts() == 0)
|
||||
return vector<ArraySubscript>(dimensionsNum);
|
||||
|
||||
vector<ArraySubscript> subscriptsVector;
|
||||
@@ -1202,7 +1199,7 @@ static void checkImplicitDirectUsage(Context* ctx, SgExpression* exp, int stmtLi
|
||||
{
|
||||
SgFunctionCallExp* funcCallExp = (SgFunctionCallExp*)exp;
|
||||
string funcName = funcCallExp->funName()->identifier();
|
||||
FuncInfo* funcInfo = findFunc(ctx->loopStmt->fileName(), funcName, ctx->allFuncInfo);
|
||||
FuncInfo* funcInfo = findFuncByName(funcName, ctx->allFuncInfo);
|
||||
if (funcInfo != nullptr)
|
||||
{
|
||||
for (int i = 0; i < funcCallExp->numberOfArgs(); ++i)
|
||||
@@ -1244,8 +1241,8 @@ static vector<vector<ArraySubscript>> checkImplicitDirectUsage(Context* ctx)
|
||||
// st->variant() == PROC_STAT:
|
||||
SgCallStmt* callStmt = (SgCallStmt*)st;
|
||||
string procName = callStmt->name()->identifier();
|
||||
FuncInfo* funcInfo = findFunc(callStmt->fileName(), procName, ctx->allFuncInfo);
|
||||
|
||||
FuncInfo* funcInfo = findFuncByName(procName, ctx->allFuncInfo);
|
||||
|
||||
for (int i = 0; i < callStmt->numberOfArgs(); ++i)
|
||||
{
|
||||
SgExpression* callArg = callStmt->arg(i);
|
||||
@@ -1295,34 +1292,37 @@ static vector<Variable*> getCommonBlockGroupedVar(FuncInfo* curFunc, SgSymbol* v
|
||||
|
||||
// checkIndirectUsage returns masks of array indirect usage in function
|
||||
// (indirect usage is usage through common blocks) and writes messages about it
|
||||
static void checkIndirectUsage(Context* ctx, FuncInfo* curFunc, vector<Variable*> commonBlockGroupedVar,
|
||||
static void checkIndirectUsage(Context* ctx, FuncInfo* calledFunc, vector<Variable*> commonBlockGroupedVar,
|
||||
set<string>& visitedFuncs, vector<vector<ArraySubscript>>& indirectUsageMasks)
|
||||
{
|
||||
if (visitedFuncs.find(curFunc->funcName) != visitedFuncs.end())
|
||||
if (visitedFuncs.find(calledFunc->funcName) != visitedFuncs.end())
|
||||
return;
|
||||
|
||||
visitedFuncs.insert(curFunc->funcName);
|
||||
visitedFuncs.insert(calledFunc->funcName);
|
||||
|
||||
for (Variable* commonBlockVar : commonBlockGroupedVar)
|
||||
{
|
||||
for (const CommonVariableUse& varUse : commonBlockVar->getAllUse())
|
||||
{
|
||||
if (varUse.getFileName() != curFunc->fileName || varUse.getFunctionName() != curFunc->funcName)
|
||||
if (varUse.getFileName() != calledFunc->fileName || varUse.getFunctionName() != calledFunc->funcName)
|
||||
continue;
|
||||
|
||||
vector<SgArrayRefExp*> directArrayRefs = getDirectArrayRefs(varUse.getFunction(), varUse.getUseS());
|
||||
SgStatement* calledFuncStmt = varUse.getFunction();
|
||||
calledFuncStmt->switchToFile();
|
||||
vector<SgArrayRefExp*> directArrayRefs = getDirectArrayRefs(calledFuncStmt, varUse.getUseS());
|
||||
for (auto arrayRef : directArrayRefs)
|
||||
{
|
||||
auto mask = getFixedSubscriptsVector(arrayRef, ctx->dimensionsNum);
|
||||
indirectUsageMasks.push_back(mask);
|
||||
addMessageUsageInFunctionCall(ctx->messages, getDimensionVarName(ctx->arraySymbol, mask),
|
||||
curFunc->funcName, ctx->loop->lineNum, ctx->loop->lineNum);
|
||||
calledFunc->funcName, ctx->loop->lineNum, ctx->loop->lineNum);
|
||||
}
|
||||
ctx->loopStmt->switchToFile();
|
||||
}
|
||||
}
|
||||
|
||||
for (FuncInfo* calledFunc : curFunc->callsFromV)
|
||||
checkIndirectUsage(ctx, calledFunc, commonBlockGroupedVar, visitedFuncs, indirectUsageMasks);
|
||||
for (FuncInfo* subCalledFunc : calledFunc->callsFromV)
|
||||
checkIndirectUsage(ctx, subCalledFunc, commonBlockGroupedVar, visitedFuncs, indirectUsageMasks);
|
||||
}
|
||||
|
||||
// checkIndirectUsage returns masks of array indirect usage in any function call in loop
|
||||
@@ -1330,7 +1330,7 @@ static void checkIndirectUsage(Context* ctx, FuncInfo* curFunc, vector<Variable*
|
||||
static vector<vector<ArraySubscript>> checkIndirectUsage(Context* ctx)
|
||||
{
|
||||
vector<vector<ArraySubscript>> indirectUsageMasks;
|
||||
FuncInfo* currentFunc = getCurrectFunc(ctx->loopStmt, ctx->allFuncInfo);
|
||||
FuncInfo* currentFunc = getCurrentFunc(ctx->loopStmt, ctx->allFuncInfo);
|
||||
if (currentFunc == nullptr)
|
||||
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
||||
|
||||
@@ -1338,10 +1338,17 @@ static vector<vector<ArraySubscript>> checkIndirectUsage(Context* ctx)
|
||||
if (commonBlockGroupedVar.empty())
|
||||
return indirectUsageMasks;
|
||||
|
||||
|
||||
set<string> visitedFunctions = { currentFunc->funcName };
|
||||
for (FuncInfo* calledFunc : currentFunc->callsFromV)
|
||||
checkIndirectUsage(ctx, calledFunc, commonBlockGroupedVar, visitedFunctions, indirectUsageMasks);
|
||||
for (SgStatement* st = ctx->loopStmt->lexNext(); st != ctx->loopStmt->lastNodeOfStmt(); st = st->lexNext())
|
||||
{
|
||||
if (st->variant() == PROC_STAT)
|
||||
{
|
||||
SgCallStmt* callStmt = (SgCallStmt*)st;
|
||||
string procName = callStmt->name()->identifier();
|
||||
FuncInfo* calledFunc = findFuncByName(procName, ctx->allFuncInfo);
|
||||
checkIndirectUsage(ctx, calledFunc, commonBlockGroupedVar, visitedFunctions, indirectUsageMasks);
|
||||
}
|
||||
}
|
||||
|
||||
return indirectUsageMasks;
|
||||
}
|
||||
@@ -2136,8 +2143,8 @@ void removePrivatesAnalysis(string filename,
|
||||
|
||||
auto filterMasks = checkImplicitAndIndirectUsage(&context);
|
||||
filterArrayRefs(&context, arrayRefs, filterMasks);
|
||||
context.explicitArrayRefs.swap(arrayRefs);
|
||||
|
||||
context.explicitArrayRefs.swap(arrayRefs);
|
||||
if (context.explicitArrayRefs.empty())
|
||||
continue;
|
||||
|
||||
|
||||
@@ -291,7 +291,7 @@ void InitPassesDependencies(map<passes, vector<passes>> &passDepsIn, set<passes>
|
||||
|
||||
list({ CALL_GRAPH2, REVERT_SUBST_EXPR_RD, CONVERT_LOOP_TO_ASSIGN, RESTORE_LOOP_FROM_ASSIGN }) <= list({ DUPLICATE_FUNCTIONS, REMOVE_UNUSED_FUNCTIONS });
|
||||
|
||||
list({ CONVERT_LOOP_TO_ASSIGN, RESTORE_LOOP_FROM_ASSIGN }) <= list({ LOOPS_SPLITTER, LOOPS_COMBINER, PRIVATE_ARRAYS_EXPANSION, PRIVATE_ARRAYS_SHRINKING, CREATE_PARALLEL_REGIONS, PURE_SAVE_TO_PARAMS, PURE_MODULE_TO_PARAMS, PURE_COMMON_TO_PARAMS, PURE_INTENT_INSERT });
|
||||
list({ CONVERT_LOOP_TO_ASSIGN, RESTORE_LOOP_FROM_ASSIGN }) <= list({ LOOPS_SPLITTER, LOOPS_COMBINER, PRIVATE_ARRAYS_EXPANSION, PRIVATE_ARRAYS_SHRINKING, CREATE_PARALLEL_REGIONS, PURE_SAVE_TO_PARAMS, PURE_MODULE_TO_PARAMS, PURE_COMMON_TO_PARAMS, PURE_INTENT_INSERT, PRIVATE_REMOVING });
|
||||
|
||||
list({ GET_ALL_ARRAY_DECL, FILL_PARALLEL_REG_IR }) <= Pass(CONVERT_ASSIGN_TO_LOOP);
|
||||
|
||||
@@ -307,8 +307,8 @@ void InitPassesDependencies(map<passes, vector<passes>> &passDepsIn, set<passes>
|
||||
|
||||
Pass(REMOVE_OMP_DIRS) <= Pass(REMOVE_OMP_DIRS_TRANSFORM);
|
||||
|
||||
Pass(CALL_GRAPH2) <= Pass(REMOVE_DEAD_CODE);
|
||||
list({ REMOVE_DEAD_CODE, REVERT_SUBST_EXPR_RD, CONVERT_LOOP_TO_ASSIGN, RESTORE_LOOP_FROM_ASSIGN }) <= Pass(REMOVE_DEAD_CODE_AND_UNPARSE);
|
||||
list({ CALL_GRAPH2, REVERT_SUBST_EXPR_RD }) <= Pass(REMOVE_DEAD_CODE);
|
||||
list({ REMOVE_DEAD_CODE, CONVERT_LOOP_TO_ASSIGN, RESTORE_LOOP_FROM_ASSIGN }) <= Pass(REMOVE_DEAD_CODE_AND_UNPARSE);
|
||||
|
||||
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,
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
#pragma once
|
||||
|
||||
#define VERSION_SPF "2303"
|
||||
#define VERSION_SPF "2305"
|
||||
|
||||
Reference in New Issue
Block a user