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