FLANG
intrinsics.h
1//===-- include/flang/Evaluate/intrinsics.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_H_
10#define FORTRAN_EVALUATE_INTRINSICS_H_
11
12#include "call.h"
13#include "characteristics.h"
14#include "flang/Parser/char-block.h"
15#include "flang/Parser/message.h"
16#include "flang/Support/default-kinds.h"
17#include <memory>
18#include <optional>
19#include <string>
20
21namespace llvm {
22class raw_ostream;
23}
24
25namespace Fortran::semantics {
26class Scope;
27}
28
29namespace Fortran::evaluate {
30
31class FoldingContext;
32
33// Utility for checking for missing, excess, and duplicated arguments,
34// and rearranging the actual arguments into dummy argument order.
35bool CheckAndRearrangeArguments(ActualArguments &, parser::ContextualMessages &,
36 const char *const dummyKeywords[] /* null terminated */,
37 std::size_t trailingOptionals = 0);
38
40 std::string name;
41 bool isSubroutineCall{false};
42};
43
44struct SpecificCall {
45 SpecificCall(SpecificIntrinsic &&si, ActualArguments &&as)
46 : specificIntrinsic{std::move(si)}, arguments{std::move(as)} {}
47 SpecificIntrinsic specificIntrinsic;
48 ActualArguments arguments;
49};
50
51struct SpecificIntrinsicFunctionInterface : public characteristics::Procedure {
52 SpecificIntrinsicFunctionInterface(
53 characteristics::Procedure &&p, std::string n, bool isRestrictedSpecific)
54 : characteristics::Procedure{std::move(p)}, genericName{n},
55 isRestrictedSpecific{isRestrictedSpecific} {}
56 std::string genericName;
57 bool isRestrictedSpecific;
58 // N.B. If there are multiple arguments, they all have the same type.
59 // All argument and result types are intrinsic types with default kinds.
60};
61
62// Generic intrinsic classes from table 16.1
63ENUM_CLASS(IntrinsicClass, atomicSubroutine, collectiveSubroutine,
64 elementalFunction, elementalSubroutine, inquiryFunction, pureSubroutine,
65 simpleSubroutine, simpleElementalSubroutine, impureFunction,
66 impureSubroutine, transformationalFunction, noClass)
67
68class IntrinsicProcTable {
69private:
70 class Implementation;
71
72 IntrinsicProcTable() = default;
73
74public:
75 ~IntrinsicProcTable();
76 IntrinsicProcTable(IntrinsicProcTable &&) = default;
77
78 static IntrinsicProcTable Configure(
80
81 // Make *this aware of the __Fortran_builtins module to expose TEAM_TYPE &c.
82 void SupplyBuiltins(const semantics::Scope &) const;
83
84 // Check whether a name should be allowed to appear on an INTRINSIC
85 // statement.
86 bool IsIntrinsic(const std::string &) const;
87 bool IsIntrinsicFunction(const std::string &) const;
88 bool IsIntrinsicSubroutine(const std::string &) const;
89 bool IsDualIntrinsic(const std::string &) const;
90
91 // Inquiry intrinsics are defined in section 16.7, table 16.1
92 IntrinsicClass GetIntrinsicClass(const std::string &) const;
93
94 // Return the generic name of a specific intrinsic name.
95 // The name provided is returned if it is a generic intrinsic name or is
96 // not known to be an intrinsic.
97 std::string GetGenericIntrinsicName(const std::string &) const;
98
99 // Probe the intrinsics for a match against a specific call.
100 // On success, the actual arguments are transferred to the result
101 // in dummy argument order; on failure, the actual arguments remain
102 // untouched.
103 // For MIN and MAX, only a1 and a2 actual arguments are transferred in dummy
104 // order on success and the other arguments are transferred afterwards
105 // without being sorted.
106 std::optional<SpecificCall> Probe(
107 const CallCharacteristics &, ActualArguments &, FoldingContext &) const;
108
109 // Probe the intrinsics with the name of a potential specific intrinsic.
110 std::optional<SpecificIntrinsicFunctionInterface> IsSpecificIntrinsicFunction(
111 const std::string &) const;
112
113 // Illegal name for an intrinsic used to avoid cascading error messages when
114 // constant folding.
115 static const inline std::string InvalidName{
116 "(invalid intrinsic function call)"};
117
118 // Name of intrinsics used in various locations.
119 static inline const char *const BuiltinIntName{"__builtin_int"};
120
121 llvm::raw_ostream &Dump(llvm::raw_ostream &) const;
122
123private:
124 std::unique_ptr<Implementation> impl_;
125};
126
127// Check if an intrinsic explicitly allows its INTENT(OUT) arguments to be
128// allocatable coarrays.
129bool AcceptsIntentOutAllocatableCoarray(const std::string &);
130} // namespace Fortran::evaluate
131#endif // FORTRAN_EVALUATE_INTRINSICS_H_
Definition default-kinds.h:26
Definition common.h:217
Definition scope.h:68
Definition call.h:34
Definition intrinsics.h:39
Definition characteristics.h:367