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 // FIXME: Handle real(3) ?
28 if (targetTriple.getArch() != llvm::Triple::ArchType::x86_64) {
29 targetCharacteristics.DisableType(
30 Fortran::common::TypeCategory::Real, /*kind=*/10);
31 }
32 if (targetTriple.getArch() == llvm::Triple::ArchType::x86_64) {
33 targetCharacteristics.set_hasSubnormalFlushingControl(/*kind=*/3);
34 targetCharacteristics.set_hasSubnormalFlushingControl(/*kind=*/4);
35 targetCharacteristics.set_hasSubnormalFlushingControl(/*kind=*/8);
36 }
37 if (targetTriple.isARM() || targetTriple.isAArch64()) {
38 targetCharacteristics.set_haltingSupportIsUnknownAtCompileTime();
39 targetCharacteristics.set_ieeeFeature(
40 evaluate::IeeeFeature::Halting, false);
41 } else {
42 targetCharacteristics.set_ieeeFeature(evaluate::IeeeFeature::Halting);
43 }
44
45 // Figure out if we can support F128: see
46 // flang/runtime/Float128Math/math-entries.h
47 // TODO: this should be taken from TargetInfo::getLongDoubleFormat to support
48 // cross-compilation
49#ifdef FLANG_RUNTIME_F128_MATH_LIB
50 // we can use libquadmath wrappers
51 constexpr bool f128Support = true;
52#elif HAS_LDBL128
53 // we can use libm wrappers
54 constexpr bool f128Support = true;
55#else
56 constexpr bool f128Support = false;
57#endif
58
59 if constexpr (!f128Support)
60 targetCharacteristics.DisableType(Fortran::common::TypeCategory::Real, 16);
61
62 for (auto realKind : targetOptions.disabledRealKinds)
63 targetCharacteristics.DisableType(common::TypeCategory::Real, realKind);
64
65 for (auto intKind : targetOptions.disabledIntegerKinds)
66 targetCharacteristics.DisableType(common::TypeCategory::Integer, intKind);
67
68 targetCharacteristics.set_compilerOptionsString(compilerOptions)
69 .set_compilerVersionString(compilerVersion);
70
71 if (targetTriple.isPPC())
72 targetCharacteristics.set_isPPC(true);
73
74 if (targetTriple.isSPARC())
75 targetCharacteristics.set_isSPARC(true);
76
77 if (targetTriple.isOSWindows())
78 targetCharacteristics.set_isOSWindows(true);
79
80 // TODO: use target machine data layout to set-up the target characteristics
81 // type size and alignment info.
82}
83
84} // namespace Fortran::tools
85
86#endif // FORTRAN_TOOLS_TARGET_SETUP_H
Options for controlling the target.
Definition: TargetOptions.h:27
std::vector< int > disabledRealKinds
The real KINDs disabled for this target.
Definition: TargetOptions.h:43
std::vector< int > disabledIntegerKinds
The integer KINDs disabled for this target.
Definition: TargetOptions.h:46