Warning: This file is not a C or C++ file. It does not have highlighting.
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/Evaluate/common.h" |
17 | #include <cstdint> |
18 | |
19 | namespace Fortran::evaluate { |
20 | |
21 | // Floating-point rounding control |
22 | struct Rounding { |
23 | common::RoundingMode mode{common::RoundingMode::TiesToEven}; |
24 | // When set, emulate status flag behavior peculiar to x86 |
25 | // (viz., fail to set the Underflow flag when an inexact product of a |
26 | // multiplication is rounded up to a normal number from a subnormal |
27 | // in some rounding modes) |
28 | #if __x86_64__ || __riscv || __loongarch__ |
29 | bool x86CompatibleBehavior{true}; |
30 | #else |
31 | bool x86CompatibleBehavior{false}; |
32 | #endif |
33 | }; |
34 | |
35 | class TargetCharacteristics { |
36 | public: |
37 | TargetCharacteristics(); |
38 | TargetCharacteristics &operator=(const TargetCharacteristics &) = default; |
39 | |
40 | bool isBigEndian() const { return isBigEndian_; } |
41 | void set_isBigEndian(bool isBig = true); |
42 | |
43 | bool areSubnormalsFlushedToZero() const { |
44 | return areSubnormalsFlushedToZero_; |
45 | } |
46 | void set_areSubnormalsFlushedToZero(bool yes = true); |
47 | |
48 | Rounding roundingMode() const { return roundingMode_; } |
49 | void set_roundingMode(Rounding); |
50 | |
51 | std::size_t procedurePointerByteSize() const { |
52 | return procedurePointerByteSize_; |
53 | } |
54 | std::size_t procedurePointerAlignment() const { |
55 | return procedurePointerAlignment_; |
56 | } |
57 | std::size_t descriptorAlignment() const { return descriptorAlignment_; } |
58 | std::size_t maxByteSize() const { return maxByteSize_; } |
59 | std::size_t maxAlignment() const { return maxAlignment_; } |
60 | |
61 | static bool CanSupportType(common::TypeCategory, std::int64_t kind); |
62 | bool EnableType(common::TypeCategory category, std::int64_t kind, |
63 | std::size_t byteSize, std::size_t align); |
64 | void DisableType(common::TypeCategory category, std::int64_t kind); |
65 | |
66 | std::size_t GetByteSize( |
67 | common::TypeCategory category, std::int64_t kind) const; |
68 | std::size_t GetAlignment( |
69 | common::TypeCategory category, std::int64_t kind) const; |
70 | bool IsTypeEnabled(common::TypeCategory category, std::int64_t kind) const; |
71 | |
72 | int SelectedIntKind(std::int64_t precision = 0) const; |
73 | int SelectedLogicalKind(std::int64_t bits = 1) const; |
74 | int SelectedRealKind(std::int64_t precision = 0, std::int64_t range = 0, |
75 | std::int64_t radix = 2) const; |
76 | |
77 | static Rounding defaultRounding; |
78 | |
79 | const std::string &compilerOptionsString() const { |
80 | return compilerOptionsString_; |
81 | }; |
82 | TargetCharacteristics &set_compilerOptionsString(std::string x) { |
83 | compilerOptionsString_ = x; |
84 | return *this; |
85 | } |
86 | |
87 | const std::string &compilerVersionString() const { |
88 | return compilerVersionString_; |
89 | }; |
90 | TargetCharacteristics &set_compilerVersionString(std::string x) { |
91 | compilerVersionString_ = x; |
92 | return *this; |
93 | } |
94 | |
95 | bool isPPC() const { return isPPC_; } |
96 | void set_isPPC(bool isPPC = false); |
97 | |
98 | private: |
99 | static constexpr int maxKind{32}; |
100 | std::uint8_t byteSize_[common::TypeCategory_enumSize][maxKind]{}; |
101 | std::uint8_t align_[common::TypeCategory_enumSize][maxKind]{}; |
102 | bool isBigEndian_{false}; |
103 | bool isPPC_{false}; |
104 | bool areSubnormalsFlushedToZero_{false}; |
105 | Rounding roundingMode_{defaultRounding}; |
106 | std::size_t procedurePointerByteSize_{8}; |
107 | std::size_t procedurePointerAlignment_{8}; |
108 | std::size_t descriptorAlignment_{8}; |
109 | std::size_t maxByteSize_{8 /*at least*/}; |
110 | std::size_t maxAlignment_{8 /*at least*/}; |
111 | std::string compilerOptionsString_; |
112 | std::string compilerVersionString_; |
113 | }; |
114 | |
115 | } // namespace Fortran::evaluate |
116 | #endif // FORTRAN_EVALUATE_TARGET_H_ |
117 |
Warning: This file is not a C or C++ file. It does not have highlighting.