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 "type.h"
15#include "flang/Parser/char-block.h"
16#include "flang/Parser/message.h"
17#include "flang/Support/default-kinds.h"
18#include <memory>
19#include <optional>
20#include <string>
21
22namespace llvm {
23class raw_ostream;
24}
25
26namespace Fortran::semantics {
27class Scope;
28}
29
30namespace Fortran::evaluate {
31
32class FoldingContext;
33
34// Utility for checking for missing, excess, and duplicated arguments,
35// and rearranging the actual arguments into dummy argument order.
36bool CheckAndRearrangeArguments(ActualArguments &, parser::ContextualMessages &,
37 const char *const dummyKeywords[] /* null terminated */,
38 std::size_t trailingOptionals = 0);
39
41 std::string name;
42 bool isSubroutineCall{false};
43};
44
45struct SpecificCall {
46 SpecificCall(SpecificIntrinsic &&si, ActualArguments &&as)
47 : specificIntrinsic{std::move(si)}, arguments{std::move(as)} {}
48 SpecificIntrinsic specificIntrinsic;
49 ActualArguments arguments;
50};
51
52struct SpecificIntrinsicFunctionInterface : public characteristics::Procedure {
53 SpecificIntrinsicFunctionInterface(
54 characteristics::Procedure &&p, std::string n, bool isRestrictedSpecific)
55 : characteristics::Procedure{std::move(p)}, genericName{n},
56 isRestrictedSpecific{isRestrictedSpecific} {}
57 std::string genericName;
58 bool isRestrictedSpecific;
59 // N.B. If there are multiple arguments, they all have the same type.
60 // All argument and result types are intrinsic types with default kinds.
61};
62
63// Generic intrinsic classes from table 16.1
64ENUM_CLASS(IntrinsicClass, atomicSubroutine, collectiveSubroutine,
65 elementalFunction, elementalSubroutine, inquiryFunction, pureSubroutine,
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 llvm::raw_ostream &Dump(llvm::raw_ostream &) const;
119
120private:
121 std::unique_ptr<Implementation> impl_;
122};
123
124// Check if an intrinsic explicitly allows its INTENT(OUT) arguments to be
125// allocatable coarrays.
126bool AcceptsIntentOutAllocatableCoarray(const std::string &);
127} // namespace Fortran::evaluate
128#endif // FORTRAN_EVALUATE_INTRINSICS_H_
Definition default-kinds.h:26
Definition common.h:216
Definition scope.h:58
Definition call.h:34
Definition intrinsics.h:40
Definition characteristics.h:365