Skip to content

Commit b4a1195

Browse files
committed
initial commit
1 parent 7793bae commit b4a1195

File tree

8 files changed

+447
-620
lines changed

8 files changed

+447
-620
lines changed

flang-rt/lib/runtime/extensions.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,5 +268,8 @@ void FORTRAN_PROCEDURE_NAME(qsort)(int *array, int *len, int *isize,
268268
qsort(array, *len, *isize, compar);
269269
}
270270

271+
// GNU extension function TIME()
272+
std::int64_t RTNAME(time)() { return time(nullptr); }
273+
271274
} // namespace Fortran::runtime
272275
} // extern "C"

flang/docs/Intrinsics.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,6 +1085,27 @@ end program rename_proc
10851085
This intrinsic is an alias for `CPU_TIME`: supporting both a subroutine and a
10861086
function form.
10871087

1088+
### Non-Standard Intrinsics: TIME
1089+
1090+
#### Description
1091+
`TIME()` returns the current time of the system as a INTEGER(8).
1092+
1093+
#### Usage and Info
1094+
1095+
- **Standard:** GNU extension
1096+
- **Class:** function
1097+
- **Syntax:** `RESULT = TIME()`
1098+
1099+
#### Example
1100+
```Fortran
1101+
PROGRAM example_time
1102+
print *, TIME()
1103+
print *, TIME()
1104+
call SLEEP(10)
1105+
print *, TIME()
1106+
END PROGRAM
1107+
```
1108+
10881109
### Non-standard Intrinsics: LNBLNK
10891110
This intrinsic is an alias for `LEN_TRIM`, without the optional KIND argument.
10901111

flang/include/flang/Optimizer/Builder/IntrinsicCall.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,7 @@ struct IntrinsicLibrary {
428428
mlir::ArrayRef<fir::ExtendedValue> args);
429429
void genSystemClock(llvm::ArrayRef<fir::ExtendedValue>);
430430
mlir::Value genTand(mlir::Type, llvm::ArrayRef<mlir::Value>);
431+
mlir::Value genTime(mlir::Type, llvm::ArrayRef<mlir::Value>);
431432
mlir::Value genTrailz(mlir::Type, llvm::ArrayRef<mlir::Value>);
432433
fir::ExtendedValue genTransfer(mlir::Type,
433434
llvm::ArrayRef<fir::ExtendedValue>);

flang/include/flang/Optimizer/Builder/Runtime/Intrinsics.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ void genRandomSeed(fir::FirOpBuilder &, mlir::Location, mlir::Value size,
6565
void genRename(fir::FirOpBuilder &builder, mlir::Location loc,
6666
mlir::Value path1, mlir::Value path2, mlir::Value status);
6767

68+
/// generate time runtime call
69+
mlir::Value genTime(fir::FirOpBuilder &builder, mlir::Location loc);
70+
6871
/// generate runtime call to transfer intrinsic with no size argument
6972
void genTransfer(fir::FirOpBuilder &builder, mlir::Location loc,
7073
mlir::Value resultBox, mlir::Value sourceBox,

flang/include/flang/Runtime/extensions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ std::int64_t RTNAME(Signal)(std::int64_t number, void (*handler)(int));
6565
// GNU extension subroutine SLEEP(SECONDS)
6666
void RTNAME(Sleep)(std::int64_t seconds);
6767

68+
// GNU extension function TIME()
69+
std::int64_t RTNAME(time)();
70+
6871
// GNU extension function ACCESS(NAME, MODE)
6972
// TODO: not supported on Windows
7073
#ifndef _WIN32

flang/lib/Evaluate/intrinsics.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -975,6 +975,8 @@ static const IntrinsicInterface genericIntrinsicFunction[]{
975975
DefaultInt, Rank::vector, IntrinsicClass::transformationalFunction},
976976
{"this_image", {OptionalTEAM}, DefaultInt, Rank::scalar,
977977
IntrinsicClass::transformationalFunction},
978+
{"time", {}, TypePattern{IntType, KindCode::exactKind, 8}, Rank::scalar,
979+
IntrinsicClass::transformationalFunction},
978980
{"tiny",
979981
{{"x", SameReal, Rank::anyOrAssumedRank, Optionality::required,
980982
common::Intent::In, {ArgFlag::canBeMoldNull}}},

0 commit comments

Comments
 (0)