[flang-commits] [flang] bbcdad1 - [flang][runtime] MCLOCK library routine (#148960)
via flang-commits
flang-commits at lists.llvm.org
Wed Jul 16 09:10:10 PDT 2025
Author: Peter Klausler
Date: 2025-07-16T09:10:07-07:00
New Revision: bbcdad1f8eab303a9d56c76a0bced7b17c6d2656
URL: https://github.com/llvm/llvm-project/commit/bbcdad1f8eab303a9d56c76a0bced7b17c6d2656
DIFF: https://github.com/llvm/llvm-project/commit/bbcdad1f8eab303a9d56c76a0bced7b17c6d2656.diff
LOG: [flang][runtime] MCLOCK library routine (#148960)
Add MCLOCK as an interface to std::clock().
Added:
Modified:
flang-rt/lib/runtime/extensions.cpp
flang/docs/Intrinsics.md
flang/include/flang/Runtime/extensions.h
Removed:
################################################################################
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 flang-commits
mailing list