From ce2f564758c6cd72414b5a332d468e26f396133a Mon Sep 17 00:00:00 2001 From: Izaak Beekman Date: Sat, 14 Dec 2024 16:12:36 -0500 Subject: [PATCH] Split full timer name into 64 character chunks Use string litteral line continuations compatible with Fortran 77 and modern free form Fortran. This ensures old school 72 character line length limits are respected. --- config_files/tau_fortran_config.yaml | 8 ++++---- src/salt_instrument_flang_plugin.cpp | 19 +++++++++++++++++-- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/config_files/tau_fortran_config.yaml b/config_files/tau_fortran_config.yaml index 9f5414d..8e40eb9 100644 --- a/config_files/tau_fortran_config.yaml +++ b/config_files/tau_fortran_config.yaml @@ -6,8 +6,8 @@ instrumentation: tauFortran program_insert: - " integer, save :: tauProfileTimer(2) = [0, 0]" - " call TAU_PROFILE_INIT()" - - " call TAU_PROFILE_TIMER(tauProfileTimer, \"&" - - " &${full_timer_name}\")" + - " call TAU_PROFILE_TIMER(tauProfileTimer, \"${full_timer_name}&" + - " &\")" - " call TAU_PROFILE_START(tauProfileTimer)" - "#ifndef TAU_MPI" - " call TAU_PROFILE_SET_NODE(0)" @@ -16,8 +16,8 @@ program_insert: procedure_begin_insert: - " integer, save :: tauProfileTimer(2) = [0, 0]" - - " call TAU_PROFILE_TIMER(tauProfileTimer, \"&" - - " &${full_timer_name}\")" + - " call TAU_PROFILE_TIMER(tauProfileTimer, \"${full_timer_name}&" + - " &\")" - " call TAU_PROFILE_START(tauProfileTimer)" procedure_end_insert: diff --git a/src/salt_instrument_flang_plugin.cpp b/src/salt_instrument_flang_plugin.cpp index 25952a1..ad47c5c 100644 --- a/src/salt_instrument_flang_plugin.cpp +++ b/src/salt_instrument_flang_plugin.cpp @@ -54,6 +54,8 @@ limitations under the License. #define SALT_FORTRAN_PROCEDURE_END_KEY "procedure_end_insert" #define SALT_FORTRAN_TIMER_NAME_TEMPLATE R"(\$\{full_timer_name\})" +#define SALT_FORTRAN_STRING_SPLITTER "&\n &" +#define SALT_F77_LINE_LENGTH 64 using namespace Fortran::frontend; @@ -503,17 +505,30 @@ class SaltInstrumentAction final : public PluginParseTreeAction { ss << ",1}-{"; // TODO column number, first char of program/subroutine/function stmt ss << endLoc.line + 1; ss << ",1}]"; // TODO column number, last char of end stmt + const std::string timerName{ss.str()}; + + // Split the timername string so that it will fit between Fortran 77's 72 character limit, + // and use character string line continuation syntax compatible with Fortran 77 and modern + // Fortran. + std::stringstream ss2; + for (size_t i = 0; i < timerName.size(); i += SALT_F77_LINE_LENGTH) { + ss2 << SALT_FORTRAN_STRING_SPLITTER; + ss2 << timerName.substr(i, SALT_F77_LINE_LENGTH); + } + + const std::string splitTimerName{ss2.str()}; + if (isInMainProgram_) { llvm::outs() << "Program begin \"" << mainProgramName_ << "\" at " << startLoc.line << ", " << startLoc.column << "\n"; addInstrumentationPoint(SaltInstrumentationPointType::PROGRAM_BEGIN, startLoc.line, - timerName); + splitTimerName); } else { llvm::outs() << "Subprogram begin \"" << subprogramName_ << "\" at " << startLoc.line << ", " << startLoc.column << "\n"; addInstrumentationPoint(SaltInstrumentationPointType::PROCEDURE_BEGIN, startLoc.line, - timerName); + splitTimerName); } llvm::outs() << "End at " << endLoc.line << ", " << endLoc.column << "\n"; addInstrumentationPoint(SaltInstrumentationPointType::PROCEDURE_END, endLoc.line);