Skip to content

Commit bbcdad1

Browse files
authored
[flang][runtime] MCLOCK library routine (#148960)
Add MCLOCK as an interface to std::clock().
1 parent 52a46dc commit bbcdad1

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

flang-rt/lib/runtime/extensions.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,7 @@
2727
#include <thread>
2828

2929
#ifdef _WIN32
30-
#define WIN32_LEAN_AND_MEAN
31-
#define NOMINMAX
32-
#include <windows.h>
33-
30+
#include "flang/Common/windows-include.h"
3431
#include <synchapi.h>
3532

3633
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); }
309306
// GNU extension function TIME()
310307
std::int64_t RTNAME(time)() { return time(nullptr); }
311308

309+
// MCLOCK: returns accumulated CPU time in ticks
310+
std::int32_t FORTRAN_PROCEDURE_NAME(mclock)() { return std::clock(); }
311+
312312
// Extension procedures related to I/O
313313

314314
namespace io {

flang/docs/Intrinsics.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -709,8 +709,9 @@ CACHESIZE, EOF, FP_CLASS, INT_PTR_KIND, ISNAN, LOC
709709
MALLOC, FREE
710710
```
711711

712-
### Library subroutine
712+
### Library subroutines and functions
713713
```
714+
ticks = MCLOCK()
714715
CALL BACKTRACE()
715716
CALL FDATE(TIME)
716717
CALL GETLOG(USRNAME)

flang/include/flang/Runtime/extensions.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,12 @@
1212
#ifndef FORTRAN_RUNTIME_EXTENSIONS_H_
1313
#define FORTRAN_RUNTIME_EXTENSIONS_H_
1414

15-
#include "flang/Runtime/entry-names.h"
16-
17-
#define FORTRAN_PROCEDURE_NAME(name) name##_
18-
1915
#include "flang/Runtime/entry-names.h"
2016
#include <cstddef>
2117
#include <cstdint>
2218

19+
#define FORTRAN_PROCEDURE_NAME(name) name##_
20+
2321
#ifdef _WIN32
2422
// UID and GID don't exist on Windows, these exist to avoid errors.
2523
typedef std::uint32_t uid_t;
@@ -89,5 +87,8 @@ int FORTRAN_PROCEDURE_NAME(ierrno)();
8987
// GNU extension subroutine PERROR(STRING)
9088
void RTNAME(Perror)(const char *str);
9189

90+
// MCLOCK -- returns accumulated time in ticks
91+
int FORTRAN_PROCEDURE_NAME(mclock)();
92+
9293
} // extern "C"
9394
#endif // FORTRAN_RUNTIME_EXTENSIONS_H_

0 commit comments

Comments
 (0)