[flang-commits] [flang] [flang] Add ETIME runtime and lowering intrinsics implementation (PR #90578)

jiajie zhang via flang-commits flang-commits at lists.llvm.org
Tue May 7 07:20:01 PDT 2024


JumpMasterJJ wrote:

> > `etime` needs to be both a function and a subroutine.
> 
> Yes. Any recommendation how this can be achieved? I was trying to add `etime` to the function definitions and the subroutine definitions, but then code-gen handler is not being picked up.

I am trying to declare a `DualGenerator` to solve all intrinsics with both function and subroutine forms.
```C++
// in IntrinsicCall.h

/// Define the different FIR generators that can be mapped to intrinsic to
/// generate the related code.
using ElementalGenerator = decltype(&IntrinsicLibrary::genAbs);
using ExtendedGenerator = decltype(&IntrinsicLibrary::genLenTrim);
using SubroutineGenerator = decltype(&IntrinsicLibrary::genDateAndTime);
// TODO: etime
/// The generator for intrinsic that has both function and subroutine form.
using DualGenerator = decltype(&IntrinsicLibrary::genEtime);
using Generator =
    std::variant<ElementalGenerator, ExtendedGenerator, SubroutineGenerator, DualGenerator>;
```
```C++
// in IntrinsicCall.cpp

// TODO: etime
static fir::ExtendedValue
invokeHandler(IntrinsicLibrary::DualGenerator generator,
              const IntrinsicHandler &handler,
              std::optional<mlir::Type> resultType,
              llvm::ArrayRef<fir::ExtendedValue> args, bool outline,
              IntrinsicLibrary &lib) {
  if (handler.isElemental)
    return lib.genElementalCall(generator, handler.name, mlir::Type{}, args,
                                outline);
  if (outline)
    return lib.outlineInExtendedWrapper(generator, handler.name, resultType,
                                        args);

  if (resultType.has_value()) {
    // function form
    return std::invoke(generator, lib, *resultType, args);
  } else {
    // subroutine form
    std::invoke(generator, lib, args);
  }
  return mlir::Value{};
}
```

How about this plan? Do you have any comments

https://github.com/llvm/llvm-project/pull/90578


More information about the flang-commits mailing list