replacing kernel and handler names to avoid conflicts with C language keywords and intrinsic function names
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user