FLANG
target.h
1//===-- include/flang/Evaluate/target.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// Represents the minimal amount of target architecture information required by
10// semantics.
11
12#ifndef FORTRAN_EVALUATE_TARGET_H_
13#define FORTRAN_EVALUATE_TARGET_H_
14
15#include "flang/Common/enum-class.h"
16#include "flang/Common/enum-set.h"
17#include "flang/Common/target-rounding.h"
18#include "flang/Common/type-kinds.h"
19#include "flang/Evaluate/common.h"
20#include "flang/Support/Fortran.h"
21#include <cstdint>
22
23namespace Fortran::evaluate {
24
25using common::Rounding;
26
27ENUM_CLASS(IeeeFeature, Denormal, Divide, Flags, Halting, Inf, Io, NaN,
28 Rounding, Sqrt, Standard, Subnormal, UnderflowControl)
29
30using IeeeFeatures = common::EnumSet<IeeeFeature, 16>;
31
32class TargetCharacteristics {
33public:
34 TargetCharacteristics();
35 TargetCharacteristics &operator=(const TargetCharacteristics &) = default;
36
37 bool isBigEndian() const { return isBigEndian_; }
38 void set_isBigEndian(bool isBig = true);
39
40 bool haltingSupportIsUnknownAtCompileTime() const {
41 return haltingSupportIsUnknownAtCompileTime_;
42 }
43 void set_haltingSupportIsUnknownAtCompileTime(bool yes = true) {
44 haltingSupportIsUnknownAtCompileTime_ = yes;
45 }
46
47 bool areSubnormalsFlushedToZero() const {
48 return areSubnormalsFlushedToZero_;
49 }
50 void set_areSubnormalsFlushedToZero(bool yes = true);
51
52 // Check if a given real kind has flushing control.
53 bool hasSubnormalFlushingControl(int kind) const;
54 // Check if any or all real kinds have flushing control.
55 bool hasSubnormalFlushingControl(bool any = false) const;
56 void set_hasSubnormalFlushingControl(int kind, bool yes = true);
57
58 // Check if a given real kind has support for raising a nonstandard
59 // ieee_denorm exception.
60 bool hasSubnormalExceptionSupport(int kind) const;
61 // Check if all real kinds have support for the ieee_denorm exception.
62 bool hasSubnormalExceptionSupport() const;
63 void set_hasSubnormalExceptionSupport(int kind, bool yes = true);
64
65 Rounding roundingMode() const { return roundingMode_; }
66 void set_roundingMode(Rounding);
67
68 void set_ieeeFeature(IeeeFeature ieeeFeature, bool yes = true) {
69 if (yes) {
70 ieeeFeatures_.set(ieeeFeature);
71 } else {
72 ieeeFeatures_.reset(ieeeFeature);
73 }
74 }
75
76 std::size_t procedurePointerByteSize() const {
77 return procedurePointerByteSize_;
78 }
79 std::size_t procedurePointerAlignment() const {
80 return procedurePointerAlignment_;
81 }
82 std::size_t descriptorAlignment() const { return descriptorAlignment_; }
83 std::size_t maxByteSize() const { return maxByteSize_; }
84 std::size_t maxAlignment() const { return maxAlignment_; }
85
86 static bool CanSupportType(common::TypeCategory, std::int64_t kind);
87 bool EnableType(common::TypeCategory category, std::int64_t kind,
88 std::size_t byteSize, std::size_t align);
89 void DisableType(common::TypeCategory category, std::int64_t kind);
90
91 std::size_t GetByteSize(
92 common::TypeCategory category, std::int64_t kind) const;
93 std::size_t GetAlignment(
94 common::TypeCategory category, std::int64_t kind) const;
95 bool IsTypeEnabled(common::TypeCategory category, std::int64_t kind) const;
96
97 int SelectedIntKind(std::int64_t precision = 0) const;
98 int SelectedLogicalKind(std::int64_t bits = 1) const;
99 int SelectedRealKind(std::int64_t precision = 0, std::int64_t range = 0,
100 std::int64_t radix = 2) const;
101
102 static Rounding defaultRounding;
103
104 const std::string &compilerOptionsString() const {
105 return compilerOptionsString_;
106 };
107 TargetCharacteristics &set_compilerOptionsString(std::string x) {
108 compilerOptionsString_ = x;
109 return *this;
110 }
111
112 const std::string &compilerVersionString() const {
113 return compilerVersionString_;
114 };
115 TargetCharacteristics &set_compilerVersionString(std::string x) {
116 compilerVersionString_ = x;
117 return *this;
118 }
119
120 bool isPPC() const { return isPPC_; }
121 void set_isPPC(bool isPPC = false);
122
123 bool isSPARC() const { return isSPARC_; }
124 void set_isSPARC(bool isSPARC = false);
125
126 bool isOSWindows() const { return isOSWindows_; }
127 void set_isOSWindows(bool isOSWindows = false) {
128 isOSWindows_ = isOSWindows;
129 };
130
131 IeeeFeatures &ieeeFeatures() { return ieeeFeatures_; }
132 const IeeeFeatures &ieeeFeatures() const { return ieeeFeatures_; }
133
134 std::size_t integerKindForPointer() { return integerKindForPointer_; }
135 void set_integerKindForPointer(std::size_t newKind) {
136 integerKindForPointer_ = newKind;
137 }
138
139private:
140 static constexpr int maxKind{common::maxKind};
141 std::uint8_t byteSize_[common::TypeCategory_enumSize][maxKind + 1]{};
142 std::uint8_t align_[common::TypeCategory_enumSize][maxKind + 1]{};
143 bool isBigEndian_{false};
144 bool isPPC_{false};
145 bool isSPARC_{false};
146 bool isOSWindows_{false};
147 bool haltingSupportIsUnknownAtCompileTime_{false};
148 bool areSubnormalsFlushedToZero_{false};
149 bool hasSubnormalFlushingControl_[maxKind + 1]{};
150 bool hasSubnormalExceptionSupport_[maxKind + 1]{};
151 Rounding roundingMode_{defaultRounding};
152 std::size_t procedurePointerByteSize_{8};
153 std::size_t procedurePointerAlignment_{8};
154 std::size_t descriptorAlignment_{8};
155 std::size_t maxByteSize_{8 /*at least*/};
156 std::size_t maxAlignment_{8 /*at least*/};
157 std::string compilerOptionsString_;
158 std::string compilerVersionString_;
159 IeeeFeatures ieeeFeatures_{IeeeFeature::Denormal, IeeeFeature::Divide,
160 IeeeFeature::Flags, IeeeFeature::Halting, IeeeFeature::Inf,
161 IeeeFeature::Io, IeeeFeature::NaN, IeeeFeature::Rounding,
162 IeeeFeature::Sqrt, IeeeFeature::Standard, IeeeFeature::Subnormal,
163 IeeeFeature::UnderflowControl};
164 std::size_t integerKindForPointer_{8}; /* For 64 bit pointer */
165};
166
167} // namespace Fortran::evaluate
168#endif // FORTRAN_EVALUATE_TARGET_H_
Definition call.h:34
Definition target-rounding.h:18
Definition expression.h:317