FLANG
Fortran.h
1//===-- include/flang/Common/Fortran.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_COMMON_FORTRAN_H_
10#define FORTRAN_COMMON_FORTRAN_H_
11
12// Fortran language concepts that are used in many phases are defined
13// once here to avoid redundancy and needless translation.
14
15#include "enum-set.h"
16#include "idioms.h"
17#include "flang/Common/Fortran-consts.h"
18#include <cinttypes>
19#include <optional>
20#include <string>
21
22namespace Fortran::common {
23class LanguageFeatureControl;
24
25constexpr bool IsNumericTypeCategory(TypeCategory category) {
26 return category == TypeCategory::Integer ||
27 category == TypeCategory::Unsigned || category == TypeCategory::Real ||
28 category == TypeCategory::Complex;
29}
30
31// Kinds of IMPORT statements. Default means IMPORT or IMPORT :: names.
32ENUM_CLASS(ImportKind, Default, Only, None, All)
33
34// The attribute on a type parameter can be KIND or LEN.
35ENUM_CLASS(TypeParamAttr, Kind, Len)
36
37ENUM_CLASS(NumericOperator, Power, Multiply, Divide, Add, Subtract)
38const char *AsFortran(NumericOperator);
39
40ENUM_CLASS(LogicalOperator, And, Or, Eqv, Neqv, Not)
41const char *AsFortran(LogicalOperator);
42
43ENUM_CLASS(RelationalOperator, LT, LE, EQ, NE, GE, GT)
44const char *AsFortran(RelationalOperator);
45
46ENUM_CLASS(Intent, Default, In, Out, InOut)
47
48// Union of specifiers for all I/O statements.
49ENUM_CLASS(IoSpecKind, Access, Action, Advance, Asynchronous, Blank, Decimal,
50 Delim, Direct, Encoding, End, Eor, Err, Exist, File, Fmt, Form, Formatted,
51 Id, Iomsg, Iostat, Name, Named, Newunit, Nextrec, Nml, Number, Opened, Pad,
52 Pending, Pos, Position, Read, Readwrite, Rec, Recl, Round, Sequential, Sign,
53 Size, Status, Stream, Unformatted, Unit, Write,
54 Carriagecontrol, // nonstandard
55 Convert, // nonstandard
56 Dispose, // nonstandard
57)
58
59const char *AsFortran(DefinedIo);
60
61// Fortran label. Must be in [1..99999].
62using Label = std::uint64_t;
63
64// CUDA subprogram attribute combinations
65ENUM_CLASS(CUDASubprogramAttrs, Host, Device, HostDevice, Global, Grid_Global)
66
67// CUDA data attributes; mutually exclusive
68ENUM_CLASS(
69 CUDADataAttr, Constant, Device, Managed, Pinned, Shared, Texture, Unified)
70
71// OpenACC device types
72ENUM_CLASS(
73 OpenACCDeviceType, Star, Default, Nvidia, Radeon, Host, Multicore, None)
74
75// OpenMP atomic_default_mem_order clause allowed values
76ENUM_CLASS(OmpAtomicDefaultMemOrderType, SeqCst, AcqRel, Relaxed)
77
78// Fortran names may have up to 63 characters (See Fortran 2018 C601).
79static constexpr int maxNameLen{63};
80
81// !DIR$ IGNORE_TKR [[(letters) name] ... letters
82// "A" expands to all of TKRDM
83ENUM_CLASS(IgnoreTKR,
84 Type, // T - don't check type category
85 Kind, // K - don't check kind
86 Rank, // R - don't check ranks
87 Device, // D - don't check host/device residence
88 Managed, // M - don't check managed storage
89 Contiguous) // C - don't check for storage sequence association with a
90 // potentially non-contiguous object
91using IgnoreTKRSet = EnumSet<IgnoreTKR, 8>;
92// IGNORE_TKR(A) = IGNORE_TKR(TKRDM)
93static constexpr IgnoreTKRSet ignoreTKRAll{IgnoreTKR::Type, IgnoreTKR::Kind,
94 IgnoreTKR::Rank, IgnoreTKR::Device, IgnoreTKR::Managed};
95std::string AsFortran(IgnoreTKRSet);
96
97bool AreCompatibleCUDADataAttrs(std::optional<CUDADataAttr>,
98 std::optional<CUDADataAttr>, IgnoreTKRSet, std::optional<std::string> *,
99 bool allowUnifiedMatchingRule,
100 const LanguageFeatureControl *features = nullptr);
101
102static constexpr char blankCommonObjectName[] = "__BLNK__";
103
104// Get the assembly name for a non BIND(C) external symbol other than the blank
105// common block.
106inline std::string GetExternalAssemblyName(
107 std::string symbolName, bool underscoring) {
108 return underscoring ? std::move(symbolName) + "_" : std::move(symbolName);
109}
110
111} // namespace Fortran::common
112#endif // FORTRAN_COMMON_FORTRAN_H_
Definition: bit-population-count.h:20
bool AreCompatibleCUDADataAttrs(std::optional< CUDADataAttr >, std::optional< CUDADataAttr >, IgnoreTKRSet, std::optional< std::string > *, bool allowUnifiedMatchingRule, const LanguageFeatureControl *features=nullptr)
Definition: Fortran.cpp:104