1 //===-- include/flang/Evaluate/intrinsics-library.h -------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef FORTRAN_EVALUATE_INTRINSICS_LIBRARY_H_
10 #define FORTRAN_EVALUATE_INTRINSICS_LIBRARY_H_
11 
12 // Defines structures to be used in F18 for folding intrinsic function with host
13 // runtime libraries.
14 
15 #include <functional>
16 #include <optional>
17 #include <string>
18 #include <vector>
19 
20 namespace Fortran::evaluate {
21 class FoldingContext;
22 class DynamicType;
23 struct SomeType;
24 template <typename> class Expr;
25 
26 // Define a callable type that is used to fold scalar intrinsic function using
27 // host runtime. These callables are responsible for the conversions between
28 // host types and Fortran abstract types (Scalar<T>). They also deal with
29 // floating point environment (To set it up to match the Fortran compiling
30 // options and to clean it up after the call). Floating point errors are
31 // reported to the FoldingContext. For 16bits float types, 32bits float host
32 // runtime plus conversions may be used to build the host wrappers if no 16bits
33 // runtime is available. IEEE 128bits float may also be used for x87 float.
34 // Potential conversion overflows are reported by the HostRuntimeWrapper in the
35 // FoldingContext.
36 using HostRuntimeWrapper = std::function<Expr<SomeType>(
37     FoldingContext &, std::vector<Expr<SomeType>> &&)>;
38 
39 // Returns the folder using host runtime given the intrinsic function name,
40 // result and argument types. Nullopt if no host runtime is available for such
41 // intrinsic function.
42 std::optional<HostRuntimeWrapper> GetHostRuntimeWrapper(const std::string &name,
43     DynamicType resultType, const std::vector<DynamicType> &argTypes);
44 } // namespace Fortran::evaluate
45 #endif // FORTRAN_EVALUATE_INTRINSICS_LIBRARY_H_
46