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