Skip to content

Commit

Permalink
Split full timer name into 64 character chunks
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
zbeekman committed Dec 14, 2024
1 parent 7854547 commit ce2f564
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
8 changes: 4 additions & 4 deletions config_files/tau_fortran_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand All @@ -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:
Expand Down
19 changes: 17 additions & 2 deletions src/salt_instrument_flang_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit ce2f564

Please sign in to comment.