FLANG
TargetSetup.h
1//===-- Tools/TargetSetup.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_TOOLS_TARGET_SETUP_H
10#define FORTRAN_TOOLS_TARGET_SETUP_H
11
12#include "flang/Common/float128.h"
13#include "flang/Evaluate/target.h"
15#include "llvm/TargetParser/Triple.h"
16
17namespace Fortran::tools {
18
19[[maybe_unused]] inline static void setUpTargetCharacteristics(
20 Fortran::evaluate::TargetCharacteristics &targetCharacteristics,
21 const llvm::Triple &targetTriple,
22 const Fortran::frontend::TargetOptions &targetOptions,
23 const std::string &compilerVersion, const std::string &compilerOptions) {
24
25 if (targetTriple.getArch() == llvm::Triple::ArchType::x86_64) {
26 targetCharacteristics.set_hasSubnormalFlushingControl(/*kind=*/3);
27 targetCharacteristics.set_hasSubnormalFlushingControl(/*kind=*/4);
28 targetCharacteristics.set_hasSubnormalFlushingControl(/*kind=*/8);
29 // ieee_denorm exception support is nonstandard.
30 targetCharacteristics.set_hasSubnormalExceptionSupport(/*kind=*/3);
31 targetCharacteristics.set_hasSubnormalExceptionSupport(/*kind=*/4);
32 targetCharacteristics.set_hasSubnormalExceptionSupport(/*kind=*/8);
33 }
34
35 if (targetTriple.isARM() || targetTriple.isAArch64()) {
36 targetCharacteristics.set_haltingSupportIsUnknownAtCompileTime();
37 targetCharacteristics.set_ieeeFeature(
38 evaluate::IeeeFeature::Halting, false);
39 targetCharacteristics.set_ieeeFeature(
40 evaluate::IeeeFeature::Standard, false);
41 targetCharacteristics.set_hasSubnormalFlushingControl(/*kind=*/3);
42 targetCharacteristics.set_hasSubnormalFlushingControl(/*kind=*/4);
43 targetCharacteristics.set_hasSubnormalFlushingControl(/*kind=*/8);
44 }
45
46 switch (targetTriple.getArch()) {
47 case llvm::Triple::ArchType::amdgpu:
48 case llvm::Triple::ArchType::x86_64:
49 break;
50 default:
51 targetCharacteristics.DisableType(
52 Fortran::common::TypeCategory::Real, /*kind=*/10);
53 targetCharacteristics.DisableType(
54 Fortran::common::TypeCategory::Complex, /*kind=*/10);
55 break;
56 }
57
58 // Check for kind=16 support. See flang/runtime/Float128Math/math-entries.h.
59 // TODO: Take this from TargetInfo::getLongDoubleFormat for cross compilation.
60#ifdef FLANG_RUNTIME_F128_MATH_LIB
61 constexpr bool f128Support = true; // use libquadmath wrappers
62#elif HAS_LDBL128
63 constexpr bool f128Support = true; // use libm wrappers
64#else
65 constexpr bool f128Support = false;
66#endif
67
68 if constexpr (!f128Support) {
69 targetCharacteristics.DisableType(Fortran::common::TypeCategory::Real, 16);
70 targetCharacteristics.DisableType(
71 Fortran::common::TypeCategory::Complex, 16);
72 }
73
74 for (auto realKind : targetOptions.disabledRealKinds) {
75 targetCharacteristics.DisableType(common::TypeCategory::Real, realKind);
76 targetCharacteristics.DisableType(common::TypeCategory::Complex, realKind);
77 }
78
79 for (auto intKind : targetOptions.disabledIntegerKinds)
80 targetCharacteristics.DisableType(common::TypeCategory::Integer, intKind);
81
82 targetCharacteristics.set_compilerOptionsString(compilerOptions)
83 .set_compilerVersionString(compilerVersion);
84
85 if (targetTriple.isPPC())
86 targetCharacteristics.set_isPPC(true);
87
88 if (targetTriple.isSPARC())
89 targetCharacteristics.set_isSPARC(true);
90
91 if (targetTriple.isOSWindows())
92 targetCharacteristics.set_isOSWindows(true);
93
94 // Currently the integer kind happens to be the same as the byte size
95 targetCharacteristics.set_integerKindForPointer(
96 targetTriple.getArchPointerBitWidth() / 8);
97
98 // TODO: use target machine data layout to set-up the target characteristics
99 // type size and alignment info.
100}
101
102} // namespace Fortran::tools
103
104#endif // FORTRAN_TOOLS_TARGET_SETUP_H
std::vector< int > disabledRealKinds
The real KINDs disabled for this target.
Definition TargetOptions.h:46
std::vector< int > disabledIntegerKinds
The integer KINDs disabled for this target.
Definition TargetOptions.h:49