From 50c050f9e71ecfc39a0e40b55aabca1a4b654719 Mon Sep 17 00:00:00 2001 From: Alexander Date: Thu, 29 May 2025 09:05:15 +0300 Subject: [PATCH] cleanup and replaced parseFortranDouble to strtod --- projects/libpredictor | 2 +- src/LoopAnalyzer/loop_analyzer.cpp | 8 +-- src/ParallelizationRegions/ParRegions.cpp | 81 ++--------------------- src/Utils/utils.cpp | 14 ++-- 4 files changed, 17 insertions(+), 88 deletions(-) diff --git a/projects/libpredictor b/projects/libpredictor index 840f9d9..d0772cd 160000 --- a/projects/libpredictor +++ b/projects/libpredictor @@ -1 +1 @@ -Subproject commit 840f9d9c1ad579825d81c46cdf70877c497fecca +Subproject commit d0772cdb57432b8c96ce634687641b1c8c76d21c diff --git a/src/LoopAnalyzer/loop_analyzer.cpp b/src/LoopAnalyzer/loop_analyzer.cpp index 4568c85..a544fca 100644 --- a/src/LoopAnalyzer/loop_analyzer.cpp +++ b/src/LoopAnalyzer/loop_analyzer.cpp @@ -1635,9 +1635,9 @@ void loopAnalyzer(SgFile *file, vector ®ions, mapfunctions(i)->symbol()->identifier(); #if _WIN32 if (file->functions(i)->variant() != MODULE_STMT) - sendMessage_2lvl(wstring(L"��������� ������� '") + wstring(fName.begin(), fName.end()) + L"'"); + sendMessage_2lvl(wstring(L"обработка функции '") + wstring(fName.begin(), fName.end()) + L"'"); else - sendMessage_2lvl(wstring(L"��������� ������ '") + wstring(fName.begin(), fName.end()) + L"'"); + sendMessage_2lvl(wstring(L"обработка модуля '") + wstring(fName.begin(), fName.end()) + L"'"); #else if (file->functions(i)->variant() != MODULE_STMT) sendMessage_2lvl(wstring(L"processing function '") + wstring(fName.begin(), fName.end()) + L"'"); @@ -1712,8 +1712,8 @@ void loopAnalyzer(SgFile *file, vector ®ions, map ®ions, mapfunctions(i)->symbol()->identifier(); #ifdef _WIN32 - sendMessage_2lvl(wstring(L"��������� ����� ") + std::to_wstring(idx) + L"/" + std::to_wstring(convertedLoopInfo.size())); + sendMessage_2lvl(wstring(L"обработка цикла ") + std::to_wstring(idx) + L"/" + std::to_wstring(convertedLoopInfo.size())); #else sendMessage_2lvl(wstring(L"processing loop ") + std::to_wstring(idx) + L"/" + std::to_wstring(convertedLoopInfo.size())); #endif diff --git a/src/ParallelizationRegions/ParRegions.cpp b/src/ParallelizationRegions/ParRegions.cpp index d185ea9..f01be39 100644 --- a/src/ParallelizationRegions/ParRegions.cpp +++ b/src/ParallelizationRegions/ParRegions.cpp @@ -106,7 +106,7 @@ static void updateRegionInfo(SgStatement *st, map calls_from_statement; + set callsFromStatement; if (st->variant() == PROC_STAT) { @@ -114,16 +114,16 @@ static void updateRegionInfo(SgStatement *st, mapexpr(z), calls_from_statement, containsPrefix, mapFuncs); + findFuncCalls(st->expr(z), callsFromStatement, containsPrefix, mapFuncs); string filename = st->fileName(); int line = st->lineNumber(); - for (const auto &func_name : calls_from_statement) + for (const auto &func_name : callsFromStatement) funcCallFromReg[func_name][filename].insert(line); } @@ -294,71 +294,6 @@ static void checkForEmpty(SgStatement *start, SgStatement *end, vector } } -static bool parseFortranDouble(const char* str, double &val) -{ - int base_sign = 1, exp_sign = 1; - - int integer_part = 0, power = 0; - double decimal_part = 0; - while (*str && *str != '.' && *str != 'd' && *str != 'D') - { - if (*str >= '0' && *str <= '9') - integer_part = integer_part * 10 + (*str - '0'); - else if (*str == '-') - base_sign = -1; - else if (*str == '+') - base_sign = 1; - - str++; - } - - if (*str == '.') - { - str++; - - int base = 10; - while (*str >= '0' && *str <= '9') - { - decimal_part += double(*str - '0') / base; - str++; - base *= 10; - } - } - - if (*str == 'd' || *str == 'D') - { - str++; - - while (*str == '+' || *str == '-' || *str >= '0' && *str <= '9') - { - if (*str >= '0' && *str <= '9') - power = power * 10 + (*str - '0'); - else if (*str == '-') - exp_sign = -1; - else if (*str == '+') - exp_sign = 1; - - str++; - } - } - - double result = integer_part + decimal_part; - - for(int i = 0; i < power; i++) - { - if (exp_sign > 0) - result *= 10; - else - result /= 10; - } - - if (base_sign < 0) - result = -result; - - val = result; - return true; -} - void fillRegionLines(SgFile *file, vector ®ions, vector& messagesForFile, vector *loops, vector *funcs) { map mapFuncs; @@ -453,7 +388,6 @@ void fillRegionLines(SgFile *file, vector ®ions, vectorlhs(); - if (curr) { __spf_print(1, "%s %d\n", curr->unparse(), curr->variant()); @@ -462,18 +396,15 @@ void fillRegionLines(SgFile *file, vector ®ions, vectorlhs() && isSgValueExp(curr->lhs()) && - isSgValueExp(curr->lhs())->doubleValue() && - parseFortranDouble(isSgValueExp(curr->lhs())->doubleValue(), fragmentWeight)) + isSgValueExp(curr->lhs())->doubleValue()) { + fragmentWeight = strtod(isSgValueExp(curr->lhs())->doubleValue(), NULL); __spf_print(1, "->> %lf\n", fragmentWeight); } else - { __spf_print(1, "WEIGHT clause without double argument\n"); - } } } - apply_fragment = apply_fragment->rhs(); } } diff --git a/src/Utils/utils.cpp b/src/Utils/utils.cpp index 7d99610..2ee26d1 100644 --- a/src/Utils/utils.cpp +++ b/src/Utils/utils.cpp @@ -1418,32 +1418,30 @@ ParallelRegion* getRegionByLine(const vector& regions, const st std::pair getRegionAndLinesByLine(const vector& regions, const string& file, const int line) { if (regions.size() == 1 && regions[0]->GetName() == "DEFAULT") // only default - return {regions[0], NULL}; - + return { regions[0], NULL }; else if (regions.size() > 0) { map regFound; - - const ParallelRegionLines* foundLines = nullptr; + const ParallelRegionLines* foundLines = NULL; for (int i = 0; i < regions.size(); ++i) if (regions[i]->HasThisLine(line, file, &foundLines)) regFound[regions[i]] = foundLines; if (regFound.size() == 0) - return {NULL, NULL}; + return { NULL, NULL }; else if (regFound.size() == 1) return *regFound.begin(); else { __spf_print(1, "WARN: this lines included in more than one region!!\n"); - return {NULL, NULL}; + return { NULL, NULL }; } } else - return {NULL, NULL}; + return { NULL, NULL }; - return {NULL, NULL}; + return { NULL, NULL }; } set getAllRegionsByLine(const vector& regions, const string& file, const int line)