[flang] [llvm] [flang][runtime] MCLOCK library routine (PR #148960)
Peter Klausler via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 16 07:55:52 PDT 2025
https://github.com/klausler updated https://github.com/llvm/llvm-project/pull/148960
>From 3184421138ce98463ce82ab792929c0a3edc8917 Mon Sep 17 00:00:00 2001
From: Peter Klausler <pklausler at nvidia.com>
Date: Tue, 15 Jul 2025 13:54:58 -0700
Subject: [PATCH] [flang][runtime] MCLOCK library routine
Add MCLOCK as an interface to std::clock().
---
flang-rt/lib/runtime/extensions.cpp | 8 ++++----
flang/docs/Intrinsics.md | 3 ++-
flang/include/flang/Runtime/extensions.h | 9 +++++----
3 files changed, 11 insertions(+), 9 deletions(-)
diff --git a/flang-rt/lib/runtime/extensions.cpp b/flang-rt/lib/runtime/extensions.cpp
index e70dff3997233..f6c39468d5655 100644
--- a/flang-rt/lib/runtime/extensions.cpp
+++ b/flang-rt/lib/runtime/extensions.cpp
@@ -27,10 +27,7 @@
#include <thread>
#ifdef _WIN32
-#define WIN32_LEAN_AND_MEAN
-#define NOMINMAX
-#include <windows.h>
-
+#include "flang/Common/windows-include.h"
#include <synchapi.h>
inline void CtimeBuffer(char *buffer, size_t bufsize, const time_t cur_time,
@@ -309,6 +306,9 @@ void RTNAME(Perror)(const char *str) { perror(str); }
// GNU extension function TIME()
std::int64_t RTNAME(time)() { return time(nullptr); }
+// MCLOCK: returns accumulated CPU time in ticks
+std::int32_t FORTRAN_PROCEDURE_NAME(mclock)() { return std::clock(); }
+
// Extension procedures related to I/O
namespace io {
diff --git a/flang/docs/Intrinsics.md b/flang/docs/Intrinsics.md
index 0118f8eb7d913..f7da6c889d413 100644
--- a/flang/docs/Intrinsics.md
+++ b/flang/docs/Intrinsics.md
@@ -709,8 +709,9 @@ CACHESIZE, EOF, FP_CLASS, INT_PTR_KIND, ISNAN, LOC
MALLOC, FREE
```
-### Library subroutine
+### Library subroutines and functions
```
+ticks = MCLOCK()
CALL BACKTRACE()
CALL FDATE(TIME)
CALL GETLOG(USRNAME)
diff --git a/flang/include/flang/Runtime/extensions.h b/flang/include/flang/Runtime/extensions.h
index 06ae7f35d9b5b..b350204714431 100644
--- a/flang/include/flang/Runtime/extensions.h
+++ b/flang/include/flang/Runtime/extensions.h
@@ -12,14 +12,12 @@
#ifndef FORTRAN_RUNTIME_EXTENSIONS_H_
#define FORTRAN_RUNTIME_EXTENSIONS_H_
-#include "flang/Runtime/entry-names.h"
-
-#define FORTRAN_PROCEDURE_NAME(name) name##_
-
#include "flang/Runtime/entry-names.h"
#include <cstddef>
#include <cstdint>
+#define FORTRAN_PROCEDURE_NAME(name) name##_
+
#ifdef _WIN32
// UID and GID don't exist on Windows, these exist to avoid errors.
typedef std::uint32_t uid_t;
@@ -89,5 +87,8 @@ int FORTRAN_PROCEDURE_NAME(ierrno)();
// GNU extension subroutine PERROR(STRING)
void RTNAME(Perror)(const char *str);
+// MCLOCK -- returns accumulated time in ticks
+int FORTRAN_PROCEDURE_NAME(mclock)();
+
} // extern "C"
#endif // FORTRAN_RUNTIME_EXTENSIONS_H_
More information about the llvm-commits
mailing list