Skip to content

Commit 6706aeb

Browse files
authored
Revert "[flang] Add ETIME runtime and lowering intrinsics implementation" (#92354)
Reverts #90578 This broke the premerge linux buildbot.
1 parent 5c35b63 commit 6706aeb

File tree

13 files changed

+5
-382
lines changed

13 files changed

+5
-382
lines changed

etime-function.mlir

Lines changed: 0 additions & 25 deletions
This file was deleted.

flang/docs/Intrinsics.md

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -916,55 +916,3 @@ used in constant expressions have currently no folding support at all.
916916
- If a condition occurs that would assign a nonzero value to `CMDSTAT` but the `CMDSTAT` variable is not present, error termination is initiated.
917917
- On POSIX-compatible systems, the child process (async process) will be terminated with no effect on the parent process (continues).
918918
- On Windows, error termination is not initiated.
919-
920-
### Non-Standard Intrinsics: ETIME
921-
922-
#### Description
923-
`ETIME(VALUES, TIME)` returns the number of seconds of runtime since the start of the process’s execution in *TIME*. *VALUES* returns the user and system components of this time in `VALUES(1)` and `VALUES(2)` respectively. *TIME* is equal to `VALUES(1) + VALUES(2)`.
924-
925-
On some systems, the underlying timings are represented using types with sufficiently small limits that overflows (wrap around) are possible, such as 32-bit types. Therefore, the values returned by this intrinsic might be, or become, negative, or numerically less than previous values, during a single run of the compiled program.
926-
927-
This intrinsic is provided in both subroutine and function forms; however, only one form can be used in any given program unit.
928-
929-
*VALUES* and *TIME* are `INTENT(OUT)` and provide the following:
930-
931-
932-
| | |
933-
|---------------|-----------------------------------|
934-
| `VALUES(1)` | User time in seconds. |
935-
| `VALUES(2)` | System time in seconds. |
936-
| `TIME` | Run time since start in seconds. |
937-
938-
#### Usage and Info
939-
940-
- **Standard:** GNU extension
941-
- **Class:** Subroutine, function
942-
- **Syntax:** `CALL ETIME(VALUES, TIME)`
943-
- **Arguments:**
944-
- **Return value** Elapsed time in seconds since the start of program execution.
945-
946-
| Argument | Description |
947-
|------------|-----------------------------------------------------------------------|
948-
| `VALUES` | The type shall be REAL(4), DIMENSION(2). |
949-
| `TIME` | The type shall be REAL(4). |
950-
951-
#### Example
952-
Here is an example usage from [Gfortran ETIME](https://gcc.gnu.org/onlinedocs/gfortran/ETIME.html)
953-
```Fortran
954-
program test_etime
955-
integer(8) :: i, j
956-
real, dimension(2) :: tarray
957-
real :: result
958-
call ETIME(tarray, result)
959-
print *, result
960-
print *, tarray(1)
961-
print *, tarray(2)
962-
do i=1,100000000 ! Just a delay
963-
j = i * i - i
964-
end do
965-
call ETIME(tarray, result)
966-
print *, result
967-
print *, tarray(1)
968-
print *, tarray(2)
969-
end program test_etime
970-
```

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

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,6 @@ struct IntrinsicLibrary {
222222
fir::ExtendedValue genEoshift(mlir::Type, llvm::ArrayRef<fir::ExtendedValue>);
223223
void genExit(llvm::ArrayRef<fir::ExtendedValue>);
224224
void genExecuteCommandLine(mlir::ArrayRef<fir::ExtendedValue> args);
225-
fir::ExtendedValue genEtime(std::optional<mlir::Type>,
226-
mlir::ArrayRef<fir::ExtendedValue> args);
227225
mlir::Value genExponent(mlir::Type, llvm::ArrayRef<mlir::Value>);
228226
fir::ExtendedValue genExtendsTypeOf(mlir::Type,
229227
llvm::ArrayRef<fir::ExtendedValue>);
@@ -402,10 +400,8 @@ struct IntrinsicLibrary {
402400
using ElementalGenerator = decltype(&IntrinsicLibrary::genAbs);
403401
using ExtendedGenerator = decltype(&IntrinsicLibrary::genLenTrim);
404402
using SubroutineGenerator = decltype(&IntrinsicLibrary::genDateAndTime);
405-
/// The generator for intrinsic that has both function and subroutine form.
406-
using DualGenerator = decltype(&IntrinsicLibrary::genEtime);
407-
using Generator = std::variant<ElementalGenerator, ExtendedGenerator,
408-
SubroutineGenerator, DualGenerator>;
403+
using Generator =
404+
std::variant<ElementalGenerator, ExtendedGenerator, SubroutineGenerator>;
409405

410406
/// All generators can be outlined. This will build a function named
411407
/// "fir."+ <generic name> + "." + <result type code> and generate the
@@ -446,10 +442,6 @@ struct IntrinsicLibrary {
446442
llvm::ArrayRef<mlir::Value> args);
447443
mlir::Value invokeGenerator(SubroutineGenerator generator,
448444
llvm::ArrayRef<mlir::Value> args);
449-
mlir::Value invokeGenerator(DualGenerator generator,
450-
llvm::ArrayRef<mlir::Value> args);
451-
mlir::Value invokeGenerator(DualGenerator generator, mlir::Type resultType,
452-
llvm::ArrayRef<mlir::Value> args);
453445

454446
/// Get pointer to unrestricted intrinsic. Generate the related unrestricted
455447
/// intrinsic if it is not defined yet.

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@ void genDateAndTime(fir::FirOpBuilder &, mlir::Location,
4444
std::optional<fir::CharBoxValue> date,
4545
std::optional<fir::CharBoxValue> time,
4646
std::optional<fir::CharBoxValue> zone, mlir::Value values);
47-
void genEtime(fir::FirOpBuilder &builder, mlir::Location loc,
48-
mlir::Value values, mlir::Value time);
4947

5048
void genRandomInit(fir::FirOpBuilder &, mlir::Location, mlir::Value repeatable,
5149
mlir::Value imageDistinct);

flang/include/flang/Runtime/time-intrinsic.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,6 @@ void RTNAME(DateAndTime)(char *date, std::size_t dateChars, char *time,
4343
const char *source = nullptr, int line = 0,
4444
const Descriptor *values = nullptr);
4545

46-
void RTNAME(Etime)(const Descriptor *values, const Descriptor *time,
47-
const char *sourceFile, int line);
48-
4946
} // extern "C"
5047
} // namespace Fortran::runtime
5148
#endif // FORTRAN_RUNTIME_TIME_INTRINSIC_H_

flang/lib/Evaluate/intrinsics.cpp

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -454,10 +454,6 @@ static const IntrinsicInterface genericIntrinsicFunction[]{
454454
{"erf", {{"x", SameReal}}, SameReal},
455455
{"erfc", {{"x", SameReal}}, SameReal},
456456
{"erfc_scaled", {{"x", SameReal}}, SameReal},
457-
{"etime",
458-
{{"values", TypePattern{RealType, KindCode::exactKind, 4}, Rank::vector,
459-
Optionality::required, common::Intent::Out}},
460-
TypePattern{RealType, KindCode::exactKind, 4}},
461457
{"exp", {{"x", SameFloating}}, SameFloating},
462458
{"exp", {{"x", SameFloating}}, SameFloating},
463459
{"exponent", {{"x", AnyReal}}, DefaultInt},
@@ -1346,12 +1342,6 @@ static const IntrinsicInterface intrinsicSubroutine[]{
13461342
{"values", AnyInt, Rank::vector, Optionality::optional,
13471343
common::Intent::Out}},
13481344
{}, Rank::elemental, IntrinsicClass::impureSubroutine},
1349-
{"etime",
1350-
{{"values", TypePattern{RealType, KindCode::exactKind, 4}, Rank::vector,
1351-
Optionality::required, common::Intent::Out},
1352-
{"time", TypePattern{RealType, KindCode::exactKind, 4},
1353-
Rank::scalar, Optionality::required, common::Intent::Out}},
1354-
{}, Rank::elemental, IntrinsicClass::impureSubroutine},
13551345
{"execute_command_line",
13561346
{{"command", DefaultChar, Rank::scalar},
13571347
{"wait", AnyLogical, Rank::scalar, Optionality::optional},
@@ -2494,7 +2484,6 @@ class IntrinsicProcTable::Implementation {
24942484
bool IsIntrinsic(const std::string &) const;
24952485
bool IsIntrinsicFunction(const std::string &) const;
24962486
bool IsIntrinsicSubroutine(const std::string &) const;
2497-
bool IsDualIntrinsic(const std::string &) const;
24982487

24992488
IntrinsicClass GetIntrinsicClass(const std::string &) const;
25002489
std::string GetGenericIntrinsicName(const std::string &) const;
@@ -2556,17 +2545,6 @@ bool IntrinsicProcTable::Implementation::IsIntrinsic(
25562545
const std::string &name) const {
25572546
return IsIntrinsicFunction(name) || IsIntrinsicSubroutine(name);
25582547
}
2559-
bool IntrinsicProcTable::Implementation::IsDualIntrinsic(
2560-
const std::string &name) const {
2561-
// Collection for some intrinsics with function and subroutine form,
2562-
// in order to pass the semantic check.
2563-
static const std::string dualIntrinsic[]{{"etime"}};
2564-
2565-
return std::find_if(std::begin(dualIntrinsic), std::end(dualIntrinsic),
2566-
[&name](const std::string &dualName) {
2567-
return dualName == name;
2568-
}) != std::end(dualIntrinsic);
2569-
}
25702548

25712549
IntrinsicClass IntrinsicProcTable::Implementation::GetIntrinsicClass(
25722550
const std::string &name) const {
@@ -3105,7 +3083,7 @@ std::optional<SpecificCall> IntrinsicProcTable::Implementation::Probe(
31053083
return specificCall;
31063084
}
31073085
}
3108-
if (IsIntrinsicFunction(call.name) && !IsDualIntrinsic(call.name)) {
3086+
if (IsIntrinsicFunction(call.name)) {
31093087
context.messages().Say(
31103088
"Cannot use intrinsic function '%s' as a subroutine"_err_en_US,
31113089
call.name);
@@ -3240,7 +3218,7 @@ std::optional<SpecificCall> IntrinsicProcTable::Implementation::Probe(
32403218
}
32413219

32423220
if (specificBuffer.empty() && genericBuffer.empty() &&
3243-
IsIntrinsicSubroutine(call.name) && !IsDualIntrinsic(call.name)) {
3221+
IsIntrinsicSubroutine(call.name)) {
32443222
context.messages().Say(
32453223
"Cannot use intrinsic subroutine '%s' as a function"_err_en_US,
32463224
call.name);

flang/lib/Optimizer/Builder/IntrinsicCall.cpp

Lines changed: 0 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
#include "flang/Optimizer/Builder/Runtime/Stop.h"
3636
#include "flang/Optimizer/Builder/Runtime/Transformational.h"
3737
#include "flang/Optimizer/Builder/Todo.h"
38-
#include "flang/Optimizer/Dialect/FIROps.h"
3938
#include "flang/Optimizer/Dialect/FIROpsSupport.h"
4039
#include "flang/Optimizer/Dialect/Support/FIRContext.h"
4140
#include "flang/Optimizer/Support/FatalError.h"
@@ -50,7 +49,6 @@
5049
#include "llvm/Support/Debug.h"
5150
#include "llvm/Support/MathExtras.h"
5251
#include "llvm/Support/raw_ostream.h"
53-
#include <mlir/IR/Value.h>
5452
#include <optional>
5553

5654
#define DEBUG_TYPE "flang-lower-intrinsic"
@@ -224,10 +222,6 @@ static constexpr IntrinsicHandler handlers[]{
224222
{"boundary", asBox, handleDynamicOptional},
225223
{"dim", asValue}}},
226224
/*isElemental=*/false},
227-
{"etime",
228-
&I::genEtime,
229-
{{{"values", asBox}, {"time", asBox}}},
230-
/*isElemental=*/false},
231225
{"execute_command_line",
232226
&I::genExecuteCommandLine,
233227
{{{"command", asBox},
@@ -1688,24 +1682,6 @@ IntrinsicLibrary::genElementalCall<IntrinsicLibrary::SubroutineGenerator>(
16881682
return mlir::Value();
16891683
}
16901684

1691-
template <>
1692-
fir::ExtendedValue
1693-
IntrinsicLibrary::genElementalCall<IntrinsicLibrary::DualGenerator>(
1694-
DualGenerator generator, llvm::StringRef name, mlir::Type resultType,
1695-
llvm::ArrayRef<fir::ExtendedValue> args, bool outline) {
1696-
assert(resultType.getImpl() && "expect elemental intrinsic to be functions");
1697-
1698-
for (const fir::ExtendedValue &arg : args)
1699-
if (!arg.getUnboxed() && !arg.getCharBox())
1700-
// fir::emitFatalError(loc, "nonscalar intrinsic argument");
1701-
crashOnMissingIntrinsic(loc, name);
1702-
if (outline)
1703-
return outlineInExtendedWrapper(generator, name, resultType, args);
1704-
1705-
return std::invoke(generator, *this, std::optional<mlir::Type>{resultType},
1706-
args);
1707-
}
1708-
17091685
static fir::ExtendedValue
17101686
invokeHandler(IntrinsicLibrary::ElementalGenerator generator,
17111687
const IntrinsicHandler &handler,
@@ -1749,22 +1725,6 @@ invokeHandler(IntrinsicLibrary::SubroutineGenerator generator,
17491725
return mlir::Value{};
17501726
}
17511727

1752-
static fir::ExtendedValue
1753-
invokeHandler(IntrinsicLibrary::DualGenerator generator,
1754-
const IntrinsicHandler &handler,
1755-
std::optional<mlir::Type> resultType,
1756-
llvm::ArrayRef<fir::ExtendedValue> args, bool outline,
1757-
IntrinsicLibrary &lib) {
1758-
if (handler.isElemental)
1759-
return lib.genElementalCall(generator, handler.name, mlir::Type{}, args,
1760-
outline);
1761-
if (outline)
1762-
return lib.outlineInExtendedWrapper(generator, handler.name, resultType,
1763-
args);
1764-
1765-
return std::invoke(generator, lib, resultType, args);
1766-
}
1767-
17681728
std::pair<fir::ExtendedValue, bool>
17691729
IntrinsicLibrary::genIntrinsicCall(llvm::StringRef specificName,
17701730
std::optional<mlir::Type> resultType,
@@ -1860,34 +1820,6 @@ IntrinsicLibrary::invokeGenerator(SubroutineGenerator generator,
18601820
return {};
18611821
}
18621822

1863-
mlir::Value
1864-
IntrinsicLibrary::invokeGenerator(DualGenerator generator,
1865-
llvm::ArrayRef<mlir::Value> args) {
1866-
llvm::SmallVector<fir::ExtendedValue> extendedArgs;
1867-
for (mlir::Value arg : args)
1868-
extendedArgs.emplace_back(toExtendedValue(arg, builder, loc));
1869-
std::invoke(generator, *this, std::optional<mlir::Type>{}, extendedArgs);
1870-
return {};
1871-
}
1872-
1873-
mlir::Value
1874-
IntrinsicLibrary::invokeGenerator(DualGenerator generator,
1875-
mlir::Type resultType,
1876-
llvm::ArrayRef<mlir::Value> args) {
1877-
llvm::SmallVector<fir::ExtendedValue> extendedArgs;
1878-
for (mlir::Value arg : args)
1879-
extendedArgs.emplace_back(toExtendedValue(arg, builder, loc));
1880-
1881-
if (resultType.getImpl() == nullptr) {
1882-
// TODO:
1883-
assert(false && "result type is null");
1884-
}
1885-
1886-
auto extendedResult = std::invoke(
1887-
generator, *this, std::optional<mlir::Type>{resultType}, extendedArgs);
1888-
return toValue(extendedResult, builder, loc);
1889-
}
1890-
18911823
//===----------------------------------------------------------------------===//
18921824
// Intrinsic Procedure Mangling
18931825
//===----------------------------------------------------------------------===//
@@ -3303,37 +3235,6 @@ void IntrinsicLibrary::genExecuteCommandLine(
33033235
exitstatBox, cmdstatBox, cmdmsgBox);
33043236
}
33053237

3306-
// ETIME
3307-
fir::ExtendedValue
3308-
IntrinsicLibrary::genEtime(std::optional<mlir::Type> resultType,
3309-
llvm::ArrayRef<fir::ExtendedValue> args) {
3310-
assert((args.size() == 2 && !resultType.has_value()) ||
3311-
(args.size() == 1 && resultType.has_value()));
3312-
3313-
mlir::Value values = fir::getBase(args[0]);
3314-
if (resultType.has_value()) {
3315-
// function form
3316-
if (!values)
3317-
fir::emitFatalError(loc, "expected VALUES parameter");
3318-
3319-
auto timeAddr = builder.createTemporary(loc, *resultType);
3320-
auto timeBox = builder.createBox(loc, timeAddr);
3321-
fir::runtime::genEtime(builder, loc, values, timeBox);
3322-
return builder.create<fir::LoadOp>(loc, timeAddr);
3323-
} else {
3324-
// subroutine form
3325-
mlir::Value time = fir::getBase(args[1]);
3326-
if (!values)
3327-
fir::emitFatalError(loc, "expected VALUES parameter");
3328-
if (!time)
3329-
fir::emitFatalError(loc, "expected TIME parameter");
3330-
3331-
fir::runtime::genEtime(builder, loc, values, time);
3332-
return {};
3333-
}
3334-
return {};
3335-
}
3336-
33373238
// EXIT
33383239
void IntrinsicLibrary::genExit(llvm::ArrayRef<fir::ExtendedValue> args) {
33393240
assert(args.size() == 1);

flang/lib/Optimizer/Builder/Runtime/Intrinsics.cpp

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -106,20 +106,6 @@ void fir::runtime::genDateAndTime(fir::FirOpBuilder &builder,
106106
builder.create<fir::CallOp>(loc, callee, args);
107107
}
108108

109-
void fir::runtime::genEtime(fir::FirOpBuilder &builder, mlir::Location loc,
110-
mlir::Value values, mlir::Value time) {
111-
auto runtimeFunc = fir::runtime::getRuntimeFunc<mkRTKey(Etime)>(loc, builder);
112-
mlir::FunctionType runtimeFuncTy = runtimeFunc.getFunctionType();
113-
114-
mlir::Value sourceFile = fir::factory::locationToFilename(builder, loc);
115-
mlir::Value sourceLine =
116-
fir::factory::locationToLineNo(builder, loc, runtimeFuncTy.getInput(3));
117-
118-
llvm::SmallVector<mlir::Value> args = fir::runtime::createArguments(
119-
builder, loc, runtimeFuncTy, values, time, sourceFile, sourceLine);
120-
builder.create<fir::CallOp>(loc, runtimeFunc, args);
121-
}
122-
123109
void fir::runtime::genRandomInit(fir::FirOpBuilder &builder, mlir::Location loc,
124110
mlir::Value repeatable,
125111
mlir::Value imageDistinct) {

0 commit comments

Comments
 (0)