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