diff --git a/dvm/fdvm/trunk/Sage/lib/newsrc/low_level.c b/dvm/fdvm/trunk/Sage/lib/newsrc/low_level.c index 92326cf..3b95b45 100644 --- a/dvm/fdvm/trunk/Sage/lib/newsrc/low_level.c +++ b/dvm/fdvm/trunk/Sage/lib/newsrc/low_level.c @@ -54,6 +54,7 @@ int getLastLabelId(); int isItInSection(); int Init_Tool_Box(); void Message(); + PTR_BFND rec_num_near_search(); PTR_BFND Redo_Bif_Next_Chain_Internal(); PTR_SYMB duplicateSymbol(); @@ -82,6 +83,12 @@ int out_upper_case; int out_line_unlimit; int out_line_length; // out_line_length = 132 for -ffo mode; out_line_length = 72 for -uniForm mode PTR_SYMB last_file_symbol; +struct file_symbol { + char *fname; + PTR_SYMB last_symb; + struct file_symbol *next; +} ; +struct file_symbol *file_last_symbol = NULL; static int CountNullBifNext = 0; /* for internal debugging */ @@ -94,7 +101,6 @@ enum typenode node_code_kind[LAST_CODE]; char info_type[LAST_CODE][MAXFIELDTYPE]; char info_symb[LAST_CODE][MAXFIELDSYMB]; char general_info[LAST_CODE][MAXFIELDSYMB]; - /*static struct bif_stack_level *stack_level = NULL;*/ /*static struct bif_stack_level *current_level = NULL;*/ @@ -247,6 +253,24 @@ char* mymalloc(int size) return pt1; } +PTR_SYMB FileLastSymbol(char *file_name) +{ + struct file_symbol *fsl; + for(fsl=file_last_symbol; fsl; fsl=fsl->next) + if(!strcmp(file_name, fsl->fname)) + return fsl->last_symb; + return NULL; +} + +void addFileSymbolList(char *file_name, PTR_SYMB symb) +{ + struct file_symbol *fsl; + fsl = (struct file_symbol *) xmalloc(sizeof (struct file_symbol)); + fsl->last_symb = symb; + fsl->fname = file_name; + fsl->next = file_last_symbol; + file_last_symbol = fsl; +} /***************** Provides infos on nodes ******************************** * * * based on the table info in include dir *.def * @@ -549,6 +573,7 @@ void Message(char *s, int l) #endif } + /***************************************************************************/ /* A set of functions for dealing with a free list for low_level node */ /***************************************************************************/ @@ -1203,14 +1228,13 @@ int Init_Tool_Box() number_of_ll_node = CUR_FILE_NUM_LLNDS() + 1; number_of_bif_node = CUR_FILE_NUM_BIFS() + 1; number_of_symb_node = CUR_FILE_NUM_SYMBS() + 1; - last_file_symbol = CUR_FILE_CUR_SYMB(); /* podd 23.06.15 */ - + addFileSymbolList(CUR_FILE_NAME(), CUR_FILE_CUR_SYMB()); /* podd 01.03.24 */ if (CUR_FILE_NAME()) strcpy(Current_File_name, CUR_FILE_NAME()); if (ToolBOX_INIT) return 0; ToolBOX_INIT = 1; - + make_a_malloc_stack(); /* initialisation des noeuds */ diff --git a/dvm/fdvm/trunk/Sage/lib/newsrc/unparse.c b/dvm/fdvm/trunk/Sage/lib/newsrc/unparse.c index eb5e47c..cc70fb9 100644 --- a/dvm/fdvm/trunk/Sage/lib/newsrc/unparse.c +++ b/dvm/fdvm/trunk/Sage/lib/newsrc/unparse.c @@ -736,10 +736,11 @@ void Init_Unparser() /* set the first tabulation */ TabNumber = 1; } - } else - { - if (Parser_Initiated != C_Initialized) - { + } + else + { + if (Parser_Initiated != C_Initialized) + { #define DEFNODECODE(SYM, NAME, TYPE, LENGTH, NT) Unparse_Def[SYM].str = create_unp_str( NAME); #include"unparseC++.def" #undef DEFNODECODE @@ -747,12 +748,15 @@ void Init_Unparser() #define DEFNODECODE(SYM, NAME, TYPE, LENGTH, NT) Unparse_Def[SYM].fct = NULL; #include"unparseC++.def" #undef DEFNODECODE - Parser_Initiated = C_Initialized; - /* init precedence table of operators for C++ */ - for(i=BIT_COMPLEMENT_OP - EQ_OP; i<=RSHIFT_ASSGN_OP-EQ_OP;i++) - precedence_C[i] = precedence2_C[i-BIT_COMPLEMENT_OP+EQ_OP]; - } - } + Parser_Initiated = C_Initialized; + /* set the first tabulation */ + TabNumber = 0; + + /* init precedence table of operators for C++ */ + for(i=BIT_COMPLEMENT_OP - EQ_OP; i<=RSHIFT_ASSGN_OP-EQ_OP;i++) + precedence_C[i] = precedence2_C[i-BIT_COMPLEMENT_OP+EQ_OP]; + } + } /* initialize the number of flag */ diff --git a/dvm/fdvm/trunk/fdvm/acc.cpp b/dvm/fdvm/trunk/fdvm/acc.cpp index 995a215..44cef68 100644 --- a/dvm/fdvm/trunk/fdvm/acc.cpp +++ b/dvm/fdvm/trunk/fdvm/acc.cpp @@ -83,11 +83,14 @@ void InitializeACC() type_CudaIndexType = NULL; type_with_len_DvmType = NULL; declaration_cmnt = NULL; + indexType_int = indexType_long = indexType_llong = NULL; dvmh_targets = options.isOn(NO_CUDA) ? HOST_DEVICE : HOST_DEVICE | CUDA_DEVICE; SpecialSymbols.insert(std::pair('\n', "\\n\"\n\"")); SpecialSymbols.insert(std::pair('"', "\\\"")); SpecialSymbols.insert(std::pair('\\', "\\\\")); + + InitializeAcrossACC(); } char *filenameACC() diff --git a/dvm/fdvm/trunk/fdvm/acc_across.cpp b/dvm/fdvm/trunk/fdvm/acc_across.cpp index 76af6ff..82aee5e 100644 --- a/dvm/fdvm/trunk/fdvm/acc_across.cpp +++ b/dvm/fdvm/trunk/fdvm/acc_across.cpp @@ -40,15 +40,13 @@ void DeclarationCreateReductionBlocksAcross(int, SgExpression*); AnalyzeReturnGpuO1 analyzeLoopBody(int type); // local static variables -static SgSymbol *red_first; -static bool declaration_include = true; +static SgSymbol *red_first = NULL; static bool createBodyKernel = false; static bool createConvert_XY = true; static const int numLoopVars = 16; static bool ifReadLvlMode = false; static vector > copyOfBody; static vector allRegNames; -static unsigned countOfCopies; static vector allVariants; static const char *funcDvmhConvXYfortVer = " attributes(device) subroutine dvmh_convert_XY_int(x,y,Rx,Ry,slash,idx)\n implicit none\n integer ,value:: x\n integer ,value:: y\n integer ,value:: Rx\n integer ,value:: Ry\n integer ,value:: slash\n integer ,device:: idx \n \n if(slash .eq. 0) then\n if(Rx .eq. Ry) then\n if(x + y .lt. Rx) then\n idx = y + (1+x+y)*(x+y)/2\n else\n idx = Rx*(Rx-1)+x-(2*Rx-x-y-1)*(2*Rx-x-y-2)/2\n endif \n elseif(Rx .lt. Ry) then\n if(x + y .lt. Rx) then\n idx = y + ((1+x+y)*(x+y)) / 2\n elseif(x + y .lt. Ry) then\n idx = ((1+Rx)*Rx) / 2 + Rx - x - 1 + Rx * (x+y-Rx)\n else\n idx = Rx*Ry-Ry+y-(((Rx+Ry-y-x-1)*(Rx+Ry-y-x-2))/2)\n endif\n else\n if(x + y .lt. Ry) then\n idx = x + (1+x+y)*(x+y) / 2\n elseif(x + y .lt. Rx) then\n idx = (1+Ry)*Ry/2 + (Ry-y-1) + Ry * (x+y-Ry)\n else\n idx = Rx*Ry-Rx+x-((Rx+Ry-y-x-1)*(Rx+Ry-y-x-2)/2)\n endif\n endif\n else\n if(Rx .eq. Ry) then\n if(x + Rx-1-y .lt. Rx) then\n idx = Rx-1-y + (x+Rx-y)*(x+Rx-1-y)/2\n else\n idx = Rx*(Rx-1) + x - (Rx-x+y)*(Rx-x+y-1)/2\n endif\n elseif(Rx .lt. Ry) then\n if(x + Ry-1-y .lt. Rx) then \n idx = Ry-1-y + ((x+Ry-y)*(x+Ry-1-y)) / 2\n elseif(x + Ry-1-y .lt. Ry) then\n idx = ((1+Rx)*Rx)/2+Rx-x-1+Rx*(x+Ry-1-y-Rx)\n else\n idx = Rx*Ry-1-y-(((Rx+y-x)*(Rx+y-x-1))/2)\n endif\n else\n if(x + Ry-1-y .lt. Ry) then\n idx = x + (1+x+Ry-1-y)*(x+Ry-1-y)/2\n elseif(x + Ry-1-y .lt. Rx) then\n idx = (1+Ry)*Ry/2 + y + Ry * (x-y-1)\n else\n idx = Rx*Ry-Rx+x-((Rx+y-x)*(Rx+y-x-1)/2)\n endif\n endif\n endif\n end subroutine\n"; @@ -58,6 +56,17 @@ static const char* fermiPreprocDir = "CUDA_FERMI_ARCH"; // local variables SgStatement *kernelScope, *block; +void InitializeAcrossACC() +{ + red_first = NULL; + createBodyKernel = false; + createConvert_XY = true; + ifReadLvlMode = false; + copyOfBody.clear(); + allRegNames.clear(); + allVariants.clear(); +} + static inline int pow(int n) { int tmp = 1; @@ -716,9 +725,6 @@ ArgsForKernel *Create_C_Adapter_Function_Across(SgSymbol *sadapter) { if (allVariants[i].acrossV != 1) ifOne = false; - - if ((unsigned)allVariants[i].acrossV == countOfCopies + 1) - countOfCopies++; } // set global if true if (ifOne) @@ -1787,11 +1793,8 @@ vector Create_C_Adapter_Function_Across_variants(SgSymbol *sadapt st_end = st_hedr->lexNext(); fe = st_hedr->expr(0); first_exec = st_end; - if (declaration_include) - { + if (declaration_cmnt == NULL) declaration_cmnt = "#include \n#define MIN(X,Y) ((X) < (Y) ? (X) : (Y))\n#define MAX(X,Y) ((X) > (Y) ? (X) : (Y))"; - declaration_include = false; - } mywarn(" end: create fuction header "); mywarn("start: create dummy argument list "); diff --git a/dvm/fdvm/trunk/fdvm/dvm.cpp b/dvm/fdvm/trunk/fdvm/dvm.cpp index 97a838d..58d9b7b 100644 --- a/dvm/fdvm/trunk/fdvm/dvm.cpp +++ b/dvm/fdvm/trunk/fdvm/dvm.cpp @@ -82,6 +82,7 @@ extern "C" int out_upper_case; extern "C" int out_line_unlimit; extern "C" int out_line_length; extern "C" PTR_SYMB last_file_symbol; +extern "C" PTR_SYMB FileLastSymbol(...); Options options; @@ -99,7 +100,7 @@ int main(int argc, char *argv[]) { FILE *fout = NULL; FILE *fout_cuf = NULL, *fout_C_cu = NULL, *fout_info = NULL; /*ACC*/ - const char *fout_name = "out.DVMH.f"; + const char *fout_name = NULL; char *fout_name_cuf; /*ACC*/ char *fout_name_C_cu; /*ACC*/ char *fout_name_info_C; /*ACC*/ @@ -389,22 +390,22 @@ int main(int argc, char *argv[]) ProjectStructure(project); Private_Vars_Project_Analyzer(); //---------------------------- - + initVariantNames(); //for project initIntrinsicFunctionNames(); //for project initSupportedVars(); // for project, acc_f2c.cpp initF2C_FunctionCalls(); // for project, acc_f2c.cpp for(int id=project.numberOfFiles()-1; id >= 0; id--) - { + { file = &(project.file(id)); //file->unparsestdout(); fin_name = new char[strlen(project.fileName(id))+2]; - sprintf(fin_name, "%s%s", project.fileName(id), " "); + sprintf(fin_name, "%s%s", project.fileName(id), " "); //fin_name = strcat(project.fileName(0)," "); // for call of function 'tpoint' //added one symbol to input-file name //printf("%s",fin_name); //!!! debug - if(a_mode || project.numberOfFiles()>1) - fout_name = doOutFileName(file->filename()); //project.fileName(id); + if(!fout_name) + fout_name = doOutFileName(file->filename()); else if (fout_name && source_name && !strcmp(source_name, fout_name)) { (void)fprintf(stderr, "Output file has the same name as source file\n"); @@ -417,7 +418,7 @@ int main(int argc, char *argv[]) fout_name_info_C = ChangeFto_info_C(fout_name); /*ACC*/ //set the last symbol of file - last_file_symbol = CUR_FILE_CUR_SYMB(); //LastSymbolOfFile(file)->thesymb; //for low_level.c + last_file_symbol = FileLastSymbol(file->filename()); //for low_level.c and not only initLibNames(); //for every file InitDVM(file); //for every file current_file = file; // global variable (used in SgTypeComplex) @@ -542,6 +543,7 @@ int main(int argc, char *argv[]) } } + fout_name = NULL; } if (v_print) diff --git a/dvm/fdvm/trunk/include/dvm.h b/dvm/fdvm/trunk/include/dvm.h index 785de47..b43f09f 100644 --- a/dvm/fdvm/trunk/include/dvm.h +++ b/dvm/fdvm/trunk/include/dvm.h @@ -1004,6 +1004,7 @@ SgStatement *doIfThenConstrForLoop_GPU(SgExpression *ref,SgStatement *endhost,Sg SgSymbol *KernelSymbol(SgStatement *st_do); void Blocks_Off_Symbol(); void InitializeACC(); +void InitializeAcrossACC(); void InitializeInFuncACC(); SgSymbol *GPUModuleSymb(SgStatement *global_st); void CreateGPUModule(); diff --git a/sapfor/experts/Sapfor_2017/_src/ProjectManipulation/ConvertFiles.cpp b/sapfor/experts/Sapfor_2017/_src/ProjectManipulation/ConvertFiles.cpp index aa52cef..db7a1ce 100644 --- a/sapfor/experts/Sapfor_2017/_src/ProjectManipulation/ConvertFiles.cpp +++ b/sapfor/experts/Sapfor_2017/_src/ProjectManipulation/ConvertFiles.cpp @@ -31,13 +31,13 @@ extern "C" int out_upper_case; extern "C" int out_line_unlimit; extern "C" int out_line_length; extern "C" PTR_SYMB last_file_symbol; +extern "C" PTR_SYMB FileLastSymbol(...); -static int convertFile(int argc, char* argv[], const string& fileToConv, - const set& filesInProj, const set& moduleDeclsInFiles) +static int convertFile(int argc, char* argv[], const set& filesInProj, const set& moduleDeclsInFiles) { FILE* fout = NULL; FILE* fout_cuf = NULL, * fout_C_cu = NULL, * fout_info = NULL; /*ACC*/ - const char* fout_name = "out.DVMH.f"; + const char* fout_name = NULL; char* fout_name_cuf; /*ACC*/ char* fout_name_C_cu; /*ACC*/ char* fout_name_info_C; /*ACC*/ @@ -54,7 +54,8 @@ static int convertFile(int argc, char* argv[], const string& fileToConv, while ((argc > 1) && (*argv)[0] == '-') { if ((*argv)[1] == 'o' && ((*argv)[2] == '\0')) { - fout_name = argv[1]; + if (filesInProj.size() == 1) + fout_name = argv[1]; argv++; argc--; } @@ -307,7 +308,8 @@ static int convertFile(int argc, char* argv[], const string& fileToConv, static int id = 0; vector filesList; - filesList.push_back((char*)fileToConv.c_str()); + for (auto& file : filesInProj) + filesList.push_back((char*)file.c_str()); SgProject project((proj_name + to_string(id++)).c_str(), filesList.data(), filesList.size()); @@ -317,7 +319,7 @@ static int convertFile(int argc, char* argv[], const string& fileToConv, removeExecutableFromModuleDeclaration(&(project.file(z)), filesInProj, tmp); } - SgFile* file; + SgFile* file = NULL; addNumberOfFileToAttribute(&project); //---------------------------- @@ -331,23 +333,27 @@ static int convertFile(int argc, char* argv[], const string& fileToConv, initF2C_FunctionCalls(); // for project, acc_f2c.cpp for (int id = project.numberOfFiles() - 1; id >= 0; id--) { - file = &(project.file(id)); //file->unparsestdout(); + file = &(project.file(id)); fin_name = new char[strlen(project.fileName(id)) + 2]; sprintf(fin_name, "%s%s", project.fileName(id), " "); - fout_name = doOutFileName(file->filename()); //project.fileName(id); + + if (fout_name == NULL) + fout_name = doOutFileName(file->filename()); if (fout_name && source_name && !strcmp(source_name, fout_name)) { fprintf(stderr, "Output file has the same name as source file\n"); return 1; } - + + printf("convert %d to %s\n", id, fout_name); + fout_name_cuf = ChangeFtoCuf(fout_name); /*ACC*/ fout_name_C_cu = ChangeFto_C_Cu(fout_name); /*ACC*/ fout_name_info_C = ChangeFto_info_C(fout_name); /*ACC*/ //set the last symbol of file - last_file_symbol = CUR_FILE_CUR_SYMB(); + last_file_symbol = FileLastSymbol(file->filename()); initLibNames(); //for every file InitDVM(file); //for every file current_file = file; // global variable (used in SgTypeComplex) @@ -402,7 +408,22 @@ static int convertFile(int argc, char* argv[], const string& fileToConv, UnparseTo_CufAndCu_Files(file, fout_cuf, fout_C_cu, fout_info); const string fileN = file->filename(); - hideUnnecessary(file, fileN, moduleDeclsInFiles, true); + set toRemove; + + for (SgStatement* st = file->firstStatement(); st; st = st->lexNext()) + { + if (st->fileName() != fileN) + { + if (st->variant() == MODULE_STMT && moduleDeclsInFiles.find(st->fileName()) != moduleDeclsInFiles.end()) + { + toRemove.insert(st); + st = st->lastNodeOfStmt(); + } + } + } + + for (auto& toRem : toRemove) + toRem->extractStmt(); if (unparse_functions) UnparseFunctionsOfFile(file, fout); @@ -434,7 +455,7 @@ static int convertFile(int argc, char* argv[], const string& fileToConv, return 1; } } - + fout_name = NULL; } if (v_print) @@ -467,11 +488,11 @@ void convertFiles(int argc, char* argv[], const char* proj_name) const string fileText = readFileToStr(proj_name); vector files; - set filesinSet; + set filesInSet; splitString(fileText, '\n', files); for (auto& file : files) - filesinSet.insert(file); + filesInSet.insert(file); map> moduleUsesByFile; map moduleDecls; @@ -482,9 +503,9 @@ void convertFiles(int argc, char* argv[], const char* proj_name) moduleDeclsInFiles.insert(elem.second); int codes = 0; - for (auto& file : files) - { - codes += convertFile(args_v.size() - 1, args_v.data(), file, filesinSet, moduleDeclsInFiles); + //for (auto& file : files) + { + codes += convertFile(args_v.size(), args_v.data(), filesInSet, moduleDeclsInFiles); cur_node = node_list = NULL; InitializeTable(); diff --git a/sapfor/experts/Sapfor_2017/_src/Utils/SgUtils.cpp b/sapfor/experts/Sapfor_2017/_src/Utils/SgUtils.cpp index 2adeab4..b9113d1 100644 --- a/sapfor/experts/Sapfor_2017/_src/Utils/SgUtils.cpp +++ b/sapfor/experts/Sapfor_2017/_src/Utils/SgUtils.cpp @@ -271,7 +271,7 @@ static int reverseVar(SgStatement* st) static map>> insertedIncludes; static set genVersionDone; -set hideUnnecessary(SgFile* file, const string& fileN, const set& moduleDeclsInFiles, bool dontReplaceIncludes) +static set hideUnnecessary(SgFile* file, const string& fileN, const set& moduleDeclsInFiles, bool dontReplaceIncludes) { set changedVars; for (SgStatement* st = file->firstStatement(); st; st = st->lexNext()) diff --git a/sapfor/experts/Sapfor_2017/_src/Utils/SgUtils.h b/sapfor/experts/Sapfor_2017/_src/Utils/SgUtils.h index 176a5cf..fcf0be8 100644 --- a/sapfor/experts/Sapfor_2017/_src/Utils/SgUtils.h +++ b/sapfor/experts/Sapfor_2017/_src/Utils/SgUtils.h @@ -11,7 +11,6 @@ SgStatement* declaratedInStmt(SgSymbol *toFind, std::vector *allDe #include "DefUseList.h" #include "CommonBlock.h" -std::set hideUnnecessary(SgFile* file, const std::string& fileN, const std::set& moduleDeclsInFiles, const bool dontReplaceIncludes); std::string removeIncludeStatsAndUnparse(SgFile *file, const char *fileName, const char *fout, std::set &allIncludeFiles, bool outFree, const std::map> &moduleUsesByFile, const std::map& moduleDelcs, const std::map>& exctactedModuleStats, bool toString, bool dontReplaceIncls = false); SgSymbol* findSymbolOrCreate(SgFile *file, const std::string toFind, SgType *type = NULL, SgStatement *scope = NULL); void recExpressionPrint(SgExpression *exp); diff --git a/sapfor/experts/Sapfor_2017/_src/Utils/version.h b/sapfor/experts/Sapfor_2017/_src/Utils/version.h index 98963f6..94bf617 100644 --- a/sapfor/experts/Sapfor_2017/_src/Utils/version.h +++ b/sapfor/experts/Sapfor_2017/_src/Utils/version.h @@ -1,3 +1,3 @@ #pragma once -#define VERSION_SPF "2286" +#define VERSION_SPF "2287"