added convertation to sapfor

This commit is contained in:
ALEXks
2024-02-28 17:38:02 +03:00
parent 4386eb7041
commit 8a92f305f4
7 changed files with 637 additions and 146 deletions

View File

@@ -1793,6 +1793,7 @@ bool SgStatement::consistentCheckIsActivated = false;
bool SgStatement::deprecatedCheck = false;
std::string SgStatement::currProcessFile = "";
int SgStatement::currProcessLine = -1;
bool SgStatement::sapfor_regime = false;
void SgStatement::checkConsistence()
{
@@ -4497,7 +4498,8 @@ SgExecutableStatement* isSgExecutableStatement(SgStatement *pt)
return NULL;
if (!isADeclBif(BIF_CODE(pt->thebif)))
{
#if __SPF
if (SgStatement::isSapforRegime())
{
const int var = pt->variant();
if (var == CONTROL_END)
{
@@ -4524,13 +4526,14 @@ SgExecutableStatement* isSgExecutableStatement(SgStatement *pt)
return isSgExecutableStatement(pt->lexNext());
else
return (SgExecutableStatement*)pt;
#else
}
else
return (SgExecutableStatement*)pt;
#endif
}
else
{
#if __SPF
if (SgStatement::isSapforRegime())
{
const int var = pt->variant();
if (var == SPF_PARALLEL_DIR)
return (SgExecutableStatement*)pt;
@@ -4566,7 +4569,7 @@ SgExecutableStatement* isSgExecutableStatement(SgStatement *pt)
var == DVM_DISTRIBUTE_DIR || var == DVM_VAR_DECL || var == DVM_SHADOW_DIR ||
var == DVM_HEAP_DIR || var == DVM_CONSISTENT_DIR || var == DVM_POINTER_DIR)
return NULL;
#endif
}
return NULL;
}
}

View File

@@ -126,6 +126,7 @@ private:
SgProject *project;
bool unparseIgnore;
static bool sapfor_regime;
static std::string currProcessFile;
static int currProcessLine;
static bool deprecatedCheck;
@@ -335,6 +336,9 @@ public:
static void setCurrProcessLine(const int line) { currProcessLine = line; }
static std::string getCurrProcessFile() { return currProcessFile; }
static int getCurrProcessLine() { return currProcessLine; }
static void setSapforRegime() { sapfor_regime = true; }
static bool isSapforRegime() { return sapfor_regime; }
};
class SgExpression

View File

@@ -8,12 +8,456 @@
#include "../Utils/errors.h"
#include "../Utils/SgUtils.h"
#include "../Utils/utils.h"
#include "../VerificationCode/verifications.h"
#include "ConvertFiles.h"
#include "calls.h"
using namespace std;
extern int convert_file(int argc, char* argv[], const char* proj_name);
extern int v_print;
extern int warn_all;
extern int unparse_functions;
extern int opt_base;
extern int opt_loop_range;
extern graph_node* cur_node;
extern graph_node* node_list;
extern "C" int out_free_form;
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;
static int convertFile(int argc, char* argv[], const string& fileToConv,
const set<string>& filesInProj, const set<string>& moduleDeclsInFiles)
{
FILE* fout = NULL;
FILE* fout_cuf = NULL, * fout_C_cu = NULL, * fout_info = NULL; /*ACC*/
const char* fout_name = "out.DVMH.f";
char* fout_name_cuf; /*ACC*/
char* fout_name_C_cu; /*ACC*/
char* fout_name_info_C; /*ACC*/
char* source_name;
int level, hpf, openmp, isz, dvm_type_size;
int a_mode = 0;
initialize();
openmp = hpf = 0; dvm_type_size = 0;
argv++;
while ((argc > 1) && (*argv)[0] == '-')
{
if ((*argv)[1] == 'o' && ((*argv)[2] == '\0')) {
fout_name = argv[1];
argv++;
argc--;
}
else if (!strcmp(argv[0], "-dc"))
check_regim = 1;
else if (!strcmp(argv[0], "-dbif1"))
dbg_if_regim = 1;
else if (!strcmp(argv[0], "-dbif2"))
dbg_if_regim = 2;
else if (!strcmp(argv[0], "-speedL0")) /* for dedugging ACROSS-scheme */
options.setOn(SPEED_TEST_L0); /*ACC*/
else if (!strcmp(argv[0], "-speedL1")) /* for dedugging ACROSS-scheme */
options.setOn(SPEED_TEST_L1); /*ACC*/
else if (!strcmp(argv[0], "-dmpi"))
deb_mpi = 1;
else if (!strcmp(argv[0], "-dnoind"))
d_no_index = 1;
else if (!strcmp(argv[0], "-dperf")) {
debug_regim = 1;
omp_debug = DPERF;
}
else if (!strcmp(argv[0], "-dvmLoopAnalysisEC")) /*ACC*/
{
options.setOn(LOOP_ANALYSIS);
options.setOn(OPT_EXP_COMP);
}
else if (!strcmp(argv[0], "-dvmIrregAnalysis")) /*ACC*/
{
options.setOn(LOOP_ANALYSIS);
options.setOn(OPT_EXP_COMP);
options.setOn(GPU_IRR_ACC);
}
else if (!strcmp(argv[0], "-dvmLoopAnalysis")) /*ACC*/
options.setOn(LOOP_ANALYSIS);
else if (!strcmp(argv[0], "-dvmPrivateAnalysis")) /*ACC*/
options.setOn(PRIVATE_ANALYSIS);
else if ((*argv)[1] == 'd') {
switch ((*argv)[2]) {
case '0': level = 0; break;
case '1': level = 1; omp_debug = D1; /*OMP*/ break;
case '2': level = 2; omp_debug = D2; /*OMP*/ break;
case '3': level = 3; omp_debug = D3; /*OMP*/ break;
case '4': level = 4; omp_debug = D4; /*OMP*/ break;
case '5': level = 5; omp_debug = D5; /*OMP*/ break;
/* case '5': level = -1; many_files=1; break;*/
default: level = -1;
}
if (level > 0)
debug_regim = 1;
if ((*argv)[3] == '\0')
AddToFragmentList(0, 0, level, -1);
else if ((*argv)[3] == ':')
FragmentList(*argv + 4, level, -1);
}
else if ((*argv)[1] == 'e') {
switch ((*argv)[2]) {
case '0': level = 0; break;
case '1': level = 1; break;
case '2': level = 2; break;
case '3': level = 3; break;
case '4': level = 4; break;
case 'm': omp_perf = 1; break;
default: level = -1;
}
if ((*argv)[3] == '\0')
AddToFragmentList(0, 0, -1, level);
else if ((*argv)[3] == ':')
FragmentList(*argv + 4, -1, level);
}
else if (!strcmp(argv[0], "-spf"))
{
fprintf(stderr, "Illegal option -spf \n");
return 1;
}
else if (!strcmp(argv[0], "-p")) {
only_debug = 0; hpf = 0;
}
else if (!strcmp(argv[0], "-s")) {
only_debug = 1; hpf = 0;
}
else if (!strcmp(argv[0], "-v"))
v_print = 1;
else if (!strcmp(argv[0], "-w"))
warn_all = 1;
else if (!strcmp(argv[0], "-bind0"))
bind_ = 0;
else if (!strcmp(argv[0], "-bind1"))
bind_ = 1;
else if (!strcmp(argv[0], "-t8"))
dvm_type_size = 8;
else if (!strcmp(argv[0], "-t4"))
dvm_type_size = 4;
else if (!strcmp(argv[0], "-r8"))
default_real_size = 8;
else if (!strcmp(argv[0], "-i8"))
default_integer_size = 8;
else if (!strcmp(argv[0], "-hpf") || !strcmp(argv[0], "-hpf1") || !strcmp(argv[0], "-hpf2"))
hpf = 1;
else if (!strcmp(argv[0], "-mp")) {
OMP_program = 1; /*OMP*/
openmp = 1;
}
//else if (!strcmp(argv[0],"-ta"))
// ACC_program = 1;
else if (!strcmp(argv[0], "-noH"))
ACC_program = 0;
else if (!strcmp(argv[0], "-noCudaType")) /*ACC*/
undefined_Tcuda = 1;
else if (!strcmp(argv[0], "-noCuda"))
options.setOn(NO_CUDA); /*ACC*/
else if (!strcmp(argv[0], "-noPureFunc"))
options.setOn(NO_PURE_FUNC); /*ACC*/
else if (!strcmp(argv[0], "-C_Cuda")) /*ACC*/
options.setOn(C_CUDA);
else if (!strcmp(argv[0], "-FTN_Cuda") || !strcmp(argv[0], "-F_Cuda")) /*ACC*/
options.setOff(C_CUDA);
else if (!strcmp(argv[0], "-no_blocks_info") || !strcmp(argv[0], "-noBI"))
options.setOn(NO_BL_INFO); /*ACC*/
else if (!strcmp(argv[0], "-cacheIdx"))
options.setOff(NO_BL_INFO); /*ACC*/
else if (!strcmp(argv[0], "-Ohost")) /*ACC*/
options.setOn(O_HOST);
else if (!strcmp(argv[0], "-noOhost")) /*ACC*/
options.setOff(O_HOST);
else if (!strcmp(argv[0], "-Opl2")) /*ACC*/
{
parloop_by_handler = 2;
options.setOn(O_HOST);
options.setOn(O_PL2);
// options.setOn(NO_CUDA);
}
else if (!strcmp(argv[0], "-Opl")) /*ACC*/
{
parloop_by_handler = 1;
options.setOn(O_PL);
}
else if (!strcmp(argv[0], "-oneThread")) /*ACC*/
options.setOn(ONE_THREAD);
else if (!strcmp(argv[0], "-noTfm")) /*ACC*/
options.setOff(AUTO_TFM);
else if (!strcmp(argv[0], "-autoTfm")) /*ACC*/
options.setOn(AUTO_TFM);
else if (!strcmp(argv[0], "-gpuO0")) /*ACC*/
options.setOn(GPU_O0);
else if (!strcmp(argv[0], "-gpuO1")) /*ACC*/
options.setOn(GPU_O1);
else if (!strcmp(argv[0], "-rtc")) /*ACC*/
options.setOn(RTC); //for NVRTC compilation and execution
else if (!strcmp(argv[0], "-ffo"))
out_free_form = 1;
else if (!strcmp(argv[0], "-upcase"))
out_upper_case = 1;
else if (!strcmp(argv[0], "-noLimitLine"))
out_line_unlimit = 1;
else if (!strcmp(argv[0], "-uniForm"))
{
out_free_form = 1;
out_line_length = 72;
}
else if (!strcmp(argv[0], "-noRemote"))
options.setOn(NO_REMOTE);
else if (!strcmp(argv[0], "-lgstd"))
{
(void)fprintf(stderr, "Illegal option -lgstd \n");
return 1;
}
else if (!strcmp(argv[0], "-byFunUnparse"))
unparse_functions = 1;
else if (!strncmp(argv[0], "-bufio", 6)) {
if ((*argv)[6] != '\0' && (isz = is_integer_value(*argv + 6)))
IOBufSize = isz;
}
else if (!strncmp(argv[0], "-bufUnparser", 12)) {
if ((*argv)[12] != '\0' && (isz = is_integer_value(*argv + 12)))
UnparserBufSize = isz * 1024 * 1024;
}
else if (!strcmp(argv[0], "-ioRTS"))
options.setOn(IO_RTS);
else if (!strcmp(argv[0], "-read_all"))
options.setOn(READ_ALL);
else if (!strcmp(argv[0], "-Obase"))
opt_base = 1;
else if (!strcmp(argv[0], "-Oloop_range"))
opt_loop_range = 1;
else if ((*argv)[1] == 'H') {
if ((*argv)[2] == 's' && (*argv)[3] == 'h' && (*argv)[4] == 'w') {
if ((*argv)[5] != '\0' && (all_sh_width = is_integer_value(*argv + 5)))
;
}
else if (!strcmp(*argv + 2, "nora"))
no_rma = 1;
else if (!strcmp(*argv + 2, "oneq"))
one_inquiry = 1;
else if (!strcmp(*argv + 2, "onlyl"))
only_local = 1;
}
else if (!strncmp(argv[0], "-collapse", 9))
if ((*argv)[9] != '\0' && (collapse_loop_count = is_integer_value(*argv + 9)));
argc--;
argv++;
}
// Check options combinations
options.checkCombinations();
// definition of DvmType size: len_DvmType
// len_DvmType==0, if DvmType-size == default_integer_size == 4
if (bind_ == 1)
len_DvmType = 8; //sizeof(long) == 8
if (dvm_type_size)
len_DvmType = dvm_type_size;
if (len_DvmType == 0 && default_integer_size == 8)
len_DvmType = 4;
if (ACC_program && debug_regim && !only_debug)
{
fprintf(stderr, "Warning: -noH option is set to debug mode\n");
ACC_program = 0;
}
if (parloop_by_handler > 0 && debug_regim)
{
fprintf(stderr, "Warning: -Opl/Opl2 option is ignored in debug mode\n");
parloop_by_handler = 0;
options.setOff(O_PL);
options.setOff(O_PL2);
}
if (openmp && ACC_program)
{
fprintf(stderr, "Warning: -noH option is set to -mp mode\n");
ACC_program = 0;
}
if (parloop_by_handler == 2 && !options.isOn(O_HOST))
{
fprintf(stderr, "Warning: -Ohost option is set to -Opl2 mode\n");
options.setOn(O_HOST);
}
if (out_free_form == 1 && out_line_length == 72 && out_line_unlimit == 1)
{
fprintf(stderr, "Warning: -noLimitLine and -uniForm options are incompatible; -noLimitLine option is ignored\n");
out_line_unlimit = 0;
}
if (v_print)
(void)fprintf(stderr, "<<<<< Translating >>>>>\n");
//------------------------------------------------------------------------------
string proj_name = "fdvm__";
static int id = 0;
vector<char*> filesList;
filesList.push_back((char*)fileToConv.c_str());
SgProject project((proj_name + to_string(id++)).c_str(), filesList.data(), filesList.size());
shiftLines(&project, false);
for (int z = 0; z < project.numberOfFiles(); ++z) {
vector<SgStatement*> tmp;
removeExecutableFromModuleDeclaration(&(project.file(z)), filesInProj, tmp);
}
SgFile* file;
addNumberOfFileToAttribute(&project);
//----------------------------
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), " ");
fout_name = doOutFileName(file->filename()); //project.fileName(id);
if (fout_name && source_name && !strcmp(source_name, fout_name))
{
fprintf(stderr, "Output file has the same name as source file\n");
return 1;
}
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();
initLibNames(); //for every file
InitDVM(file); //for every file
current_file = file; // global variable (used in SgTypeComplex)
max_lab = getLastLabelId();
if (dbg_if_regim)
GetLabel();
TranslateFileDVM(file);
if (err_cnt) {
fprintf(stderr, "%d error(s)\n", err_cnt);
return 1;
}
if (!fout_name) {
file->unparsestdout();
return 0;
}
//writing result of converting into file
if ((fout = fopen(fout_name, "w")) == NULL) {
fprintf(stderr, "Can't open file %s for write\n", fout_name);
return 1;
}
if (GeneratedForCuda()) /*ACC*/
{
if ((fout_C_cu = fopen(fout_name_C_cu, "w")) == NULL) {
fprintf(stderr, "Can't open file %s for write\n", fout_name_C_cu);
return 1;
}
if (!options.isOn(C_CUDA)) {
if ((fout_cuf = fopen(fout_name_cuf, "w")) == NULL) {
fprintf(stderr, "Can't open file %s for write\n", fout_name_cuf);
return 1;
}
}
if ((fout_info = fopen(fout_name_info_C, "w")) == NULL) {
fprintf(stderr, "Can't open file %s for write\n", fout_name_info_C);
return 1;
}
}
if (v_print)
fprintf(stderr, "<<<<< Unparsing %s >>>>>\n", fout_name);
if (mod_gpu) /*ACC*/
UnparseTo_CufAndCu_Files(file, fout_cuf, fout_C_cu, fout_info);
const string fileN = file->filename();
hideUnnecessary(file, fileN, moduleDeclsInFiles, true);
if (unparse_functions)
UnparseFunctionsOfFile(file, fout);
else if (UnparserBufSize)
file->unparseS(fout, UnparserBufSize);
else
file->unparse(fout);
if ((fclose(fout)) < 0) {
fprintf(stderr, "Could not close %s\n", fout_name);
return 1;
}
if (GeneratedForCuda()) {
if ((fclose(fout_C_cu)) < 0) {
fprintf(stderr, "Could not close %s\n", fout_name_C_cu);
return 1;
}
if (!options.isOn(C_CUDA)) {
if ((fclose(fout_cuf)) < 0) {
fprintf(stderr, "Could not close %s\n", fout_name_cuf);
return 1;
}
}
if ((fclose(fout_info)) < 0) {
fprintf(stderr, "Could not close %s\n", fout_name_info_C);
return 1;
}
}
}
if (v_print)
fprintf(stderr, "\n***** Done *****\n");
return 0;
}
static void preprocess(const vector<string>& files, map<string, set<string>>& moduleUsesByFile, map<string, string>& moduleDecls)
{
vector<char*> filesList;
for (int z = 0; z < files.size(); ++z)
filesList.push_back((char*)files[z].c_str());
SgProject tmpProj("preproc", filesList.data(), files.size());
for (int z = 0; z < tmpProj.numberOfFiles(); ++z)
{
SgFile* file = &(tmpProj.file(z));
fillModuleUse(file, moduleUsesByFile, moduleDecls);
}
InitializeTable();
}
void convertFiles(int argc, char* argv[], const char* proj_name)
{
@@ -21,11 +465,32 @@ void convertFiles(int argc, char* argv[], const char* proj_name)
for (int z = 0; z < argc; ++z)
args_v.push_back(argv[z]);
args_v.push_back("-a");
args_v.push_back((char*)proj_name);
const string fileText = readFileToStr(proj_name);
vector<string> files;
set<string> filesinSet;
splitString(fileText, '\n', files);
args_v.push_back(NULL);
for (auto& file : files)
filesinSet.insert(file);
int code = convert_file(args_v.size() - 1, args_v.data(), proj_name);
exit(code);
map<string, set<string>> moduleUsesByFile;
map<string, string> moduleDecls;
set<string> moduleDeclsInFiles;
preprocess(files, moduleUsesByFile, moduleDecls);
for (auto& elem : moduleDecls)
moduleDeclsInFiles.insert(elem.second);
int codes = 0;
for (auto& file : files)
{
codes += convertFile(args_v.size() - 1, args_v.data(), file, filesinSet, moduleDeclsInFiles);
cur_node = node_list = NULL;
InitializeTable();
}
if (codes == 0)
printf("Convertation was completed successfully\n");
exit(0);
}

View File

@@ -186,6 +186,10 @@ static set<FileInfo*> applyModuleDeclsForFile(FileInfo *forFile, const map<strin
writeFileFromStr(forFile->fileName, data);
/*static string tmp = "tmp__";
static int id = 0;
writeFileFromStr(tmp + to_string(id++) + ".ftn", data);*/
forFile->includesAdded = included.size();
forFile->includes = included;
@@ -275,7 +279,7 @@ static vector<string> parseList(vector<FileInfo>& listOfProject,
}
FILE* depPath = fopen(elem.outDepPath.c_str(), "r");
if (depPath && !isFromConsole)
if (depPath && !isFromConsole && !needToIncludeForInline)
{
fclose(depPath);
if (elem.error <= 0)
@@ -302,7 +306,7 @@ static vector<string> parseList(vector<FileInfo>& listOfProject,
StdCapture::BeginCapture();
if (needToInclude)
filesModified = applyModuleDeclsForFile(&elem, mapFiles, moduleDelc, mapModuleDeps, modDirectOrder, optSplited, needToIncludeForInline);
else if (needToIncludeForInline) // TODO for modules
else if (needToIncludeForInline)
filesModified = applyModuleDeclsForFile(&elem, mapFiles, moduleDelc, mapModuleDeps, modDirectOrder, optSplited, needToIncludeForInline);
int retCode = parse_file(optSplited.size(), toParse, "dvm.proj");
@@ -521,7 +525,7 @@ static void parseFiles(int& iters, vector<string>& errors, vector<FileInfo>& lis
{
int changed = 0;
int lastChanged = 0;
const string projName = "tmp";
const string projName = (parseForInlining == 0) ? "tmp" : "tmp_inl";
do
{
@@ -635,12 +639,8 @@ static int parseFiles(vector<string>& errors, vector<FileInfo>& listOfProject, v
filesCompilationOrder = finalyzeParsing(listOfProject, mapModuleDeps, moduleDelc);
if (parseForInlining)
{
for (auto& file : listOfProject)
file.outDepPath = "";
parseFiles(iters, errors, listOfProject, mapModuleDeps, moduleDelc, modDirectOrder, true, isFromConsole);
}
}
catch (int err)
{
rethrow = err;
@@ -756,6 +756,9 @@ void parseFiles(int argc, char** argv)
}
vector<string> filesCompilationOrder;
if (isInline)
printf(" run parsing for inlining\n");
int rethrow = parseFiles(errors, listOfProject, filesCompilationOrder, isInline, true);
if (rethrow == 0)
{

View File

@@ -271,6 +271,41 @@ static int reverseVar(SgStatement* st)
static map<SgStatement*, map<int, set<string>>> insertedIncludes;
static set<SgFile*> genVersionDone;
set<int> hideUnnecessary(SgFile* file, const string& fileN, const set<string>& moduleDeclsInFiles, bool dontReplaceIncludes)
{
set<int> changedVars;
for (SgStatement* st = file->firstStatement(); st; st = st->lexNext())
{
if (dontReplaceIncludes == false)
{
if (st->fileName() != fileN || st->getUnparseIgnore())
if (st->variant() > 0)
changedVars.insert(reverseVar(st));
}
else
{
if (st->getUnparseIgnore())
{
if (st->variant() > 0)
changedVars.insert(reverseVar(st));
}
else if (st->fileName() != fileN)
{
if (st->variant() == MODULE_STMT && moduleDeclsInFiles.find(st->fileName()) != moduleDeclsInFiles.end())
{
for (auto mSt = st; mSt != st->lastNodeOfStmt(); mSt = mSt->lexNext())
changedVars.insert(reverseVar(mSt));
st = st->lastNodeOfStmt();
changedVars.insert(reverseVar(st));
}
}
}
}
return changedVars;
}
//TODO: read includes and find last lines, all included files
string removeIncludeStatsAndUnparse(SgFile *file, const char *fileName, const char *fout,
set<string> &allIncludeFiles, bool outFree,
@@ -573,38 +608,9 @@ string removeIncludeStatsAndUnparse(SgFile *file, const char *fileName, const ch
}
}
set<int> changedVars;
//remove unnecessary
//XXX: use Sage hack!!
for (SgStatement* st = file->firstStatement(); st; st = st->lexNext())
{
if (dontReplaceIncludes == false)
{
if (st->fileName() != fileN || st->getUnparseIgnore())
if (st->variant() > 0)
changedVars.insert(reverseVar(st));
}
else
{
if (st->getUnparseIgnore())
{
if (st->variant() > 0)
changedVars.insert(reverseVar(st));
}
else if (st->fileName() != fileN)
{
if (st->variant() == MODULE_STMT && moduleDeclsInFiles.find(st->fileName()) != moduleDeclsInFiles.end())
{
for (auto mSt = st; mSt != st->lastNodeOfStmt(); mSt = mSt->lexNext())
changedVars.insert(reverseVar(mSt));
st = st->lastNodeOfStmt();
changedVars.insert(reverseVar(st));
}
}
}
}
set<int> changedVars = hideUnnecessary(file, fileN, moduleDeclsInFiles, dontReplaceIncludes);
set<int> checkPositions;
for (auto& elem : includeFiles)
@@ -3069,6 +3075,56 @@ set<T> getAllVariables(SgStatement* stFrom, SgStatement* stTo, const set<int>& v
template set<string> getAllVariables(SgStatement* stFrom, SgStatement* stTo, const set<int>& variants);
template set<SgSymbol*> getAllVariables(SgStatement* stFrom, SgStatement* stTo, const set<int>& variants);
void shiftLines(SgProject* project, bool print)
{
map<string, int> shifts;
//shift lines if modules included
const string shiftInfo = "!SPF NUM FILES";
for (int z = 0; z < project->numberOfFiles(); ++z)
{
SgFile* file = &(project->file(z));
const string fileN = file->filename();
int shiftN = 0;
for (auto st = file->firstStatement(); st; st = st->lexNext())
{
if (st->comments())
{
string comms = st->comments();
auto it = comms.find(shiftInfo);
if (it != string::npos)
{
it += shiftInfo.size() + 1;
if (sscanf(comms.c_str() + it, "%d", &shiftN) == -1)
{
__spf_print(print, "comm %s, shifted %s\n", comms.c_str(), comms.c_str() + it);
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
}
break;
}
}
}
if (shiftN == 0)
continue;
shifts[fileN] = shiftN + 1; // with comment !SPF NUM FILES
__spf_print(print, " shift by %d for %s\n", shiftN, fileN.c_str());
}
for (int z = 0; z < project->numberOfFiles(); ++z)
{
SgFile* file = &(project->file(z));
for (SgStatement* st = file->firstStatement()->lexNext(); st; st = st->lexNext())
{
string currF = st->fileName();
auto it = shifts.find(currF);
if (it != shifts.end() && file->filename() == currF)
st->setlineNumber(st->lineNumber() - it->second);
}
}
}
SgProject* createProject(const char* proj_name,
vector<ParallelRegion*>& parallelRegions,
vector<ParallelRegion*>& subs_parallelRegions,
@@ -3078,6 +3134,7 @@ SgProject* createProject(const char* proj_name,
map<string, string>& moduleDecls,
map<string, map<SgStatement*, vector<SgStatement*>>>& exctactedModuleStats)
{
Statement::setSapforRegime();
Statement::deactiveConsistentchecker();
sortFilesBySize(proj_name);
SgProject* project = new SgProject(proj_name);
@@ -3246,52 +3303,8 @@ SgProject* createProject(const char* proj_name,
}
filterModuleUse(moduleUsesByFile, moduleDecls);
map<string, int> shifts;
//shiftLines if modules included
const string shiftInfo = "!SPF NUM FILES";
for (int z = 0; z < project->numberOfFiles(); ++z)
{
SgFile* file = &(project->file(z));
const string fileN = file->filename();
int shiftN = 0;
for (auto st = file->firstStatement(); st; st = st->lexNext())
{
if (st->comments())
{
string comms = st->comments();
auto it = comms.find(shiftInfo);
if (it != string::npos)
{
it += shiftInfo.size() + 1;
if (sscanf(comms.c_str() + it, "%d", &shiftN) == -1)
{
__spf_print(1, "comm %s, shifted %s\n", comms.c_str(), comms.c_str() + it);
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
}
break;
}
}
}
if (shiftN == 0)
continue;
shifts[fileN] = shiftN + 1; // with comment !SPF NUM FILES
__spf_print(1, " shift by %d for %s\n", shiftN, fileN.c_str());
}
for (int z = 0; z < project->numberOfFiles(); ++z)
{
SgFile* file = &(project->file(z));
for (SgStatement* st = file->firstStatement()->lexNext(); st; st = st->lexNext())
{
string currF = st->fileName();
auto it = shifts.find(currF);
if (it != shifts.end() && file->filename() == currF)
st->setlineNumber(st->lineNumber() - it->second);
}
}
//shift lines if modules included
shiftLines(project);
map<string, vector<Function>> functions;
for (int z = 0; z < project->numberOfFiles(); ++z)

View File

@@ -11,6 +11,7 @@ SgStatement* declaratedInStmt(SgSymbol *toFind, std::vector<SgStatement*> *allDe
#include "DefUseList.h"
#include "CommonBlock.h"
std::set<int> hideUnnecessary(SgFile* file, const std::string& fileN, const std::set<std::string>& moduleDeclsInFiles, const bool dontReplaceIncludes);
std::string removeIncludeStatsAndUnparse(SgFile *file, const char *fileName, const char *fout, std::set<std::string> &allIncludeFiles, bool outFree, const std::map<std::string, std::set<std::string>> &moduleUsesByFile, const std::map<std::string, std::string>& moduleDelcs, const std::map<SgStatement*, std::vector<SgStatement*>>& exctactedModuleStats, bool toString, bool dontReplaceIncls = false);
SgSymbol* findSymbolOrCreate(SgFile *file, const std::string toFind, SgType *type = NULL, SgStatement *scope = NULL);
void recExpressionPrint(SgExpression *exp);
@@ -107,3 +108,5 @@ void removeSpecialCommentsFromProject(SgFile* file);
void getMaxMinBlockDistribution(SgFile* file, std::pair<int, int>& min_max);
void addPrivatesToArraysFromGUI(SgFile* file, const std::map<std::tuple<int, std::string, std::string>, std::pair<DIST::Array*, DIST::ArrayAccessInfo*>>& declaredArrays, const std::map<std::string, int>& distrStateFromGUI);
void shiftLines(SgProject* project, bool print = true);

View File

@@ -1,3 +1,3 @@
#pragma once
#define VERSION_SPF "2282"
#define VERSION_SPF "2285"