clang 24.0.0git
Sparc.cpp
Go to the documentation of this file.
1//===--- Sparc.cpp - Implement Sparc target feature support ---------------===//
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// This file implements Sparc TargetInfo objects.
10//
11//===----------------------------------------------------------------------===//
12
13#include "Sparc.h"
14#include "Targets.h"
16#include "llvm/ADT/StringSwitch.h"
17
18using namespace clang;
19using namespace clang::targets;
20
21const char *const SparcTargetInfo::GCCRegNames[] = {
22 // clang-format off
23 // Integer registers
24 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", "r8", "r9", "r10",
25 "r11", "r12", "r13", "r14", "r15", "r16", "r17", "r18", "r19", "r20", "r21",
26 "r22", "r23", "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31",
27
28 // Floating-point registers
29 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", "f8", "f9", "f10",
30 "f11", "f12", "f13", "f14", "f15", "f16", "f17", "f18", "f19", "f20", "f21",
31 "f22", "f23", "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31", "f32",
32 "f34", "f36", "f38", "f40", "f42", "f44", "f46", "f48", "f50", "f52", "f54",
33 "f56", "f58", "f60", "f62",
34
35 // Condition code registers
36 "icc", "fcc0", "fcc1", "fcc2", "fcc3",
37 // clang-format on
38};
39
43
44const TargetInfo::GCCRegAlias SparcTargetInfo::GCCRegAliases[] = {
45 {{"g0"}, "r0"}, {{"g1"}, "r1"}, {{"g2"}, "r2"}, {{"g3"}, "r3"},
46 {{"g4"}, "r4"}, {{"g5"}, "r5"}, {{"g6"}, "r6"}, {{"g7"}, "r7"},
47 {{"o0"}, "r8"}, {{"o1"}, "r9"}, {{"o2"}, "r10"}, {{"o3"}, "r11"},
48 {{"o4"}, "r12"}, {{"o5"}, "r13"}, {{"o6", "sp"}, "r14"}, {{"o7"}, "r15"},
49 {{"l0"}, "r16"}, {{"l1"}, "r17"}, {{"l2"}, "r18"}, {{"l3"}, "r19"},
50 {{"l4"}, "r20"}, {{"l5"}, "r21"}, {{"l6"}, "r22"}, {{"l7"}, "r23"},
51 {{"i0"}, "r24"}, {{"i1"}, "r25"}, {{"i2"}, "r26"}, {{"i3"}, "r27"},
52 {{"i4"}, "r28"}, {{"i5"}, "r29"}, {{"i6", "fp"}, "r30"}, {{"i7"}, "r31"},
53};
54
58
59bool SparcTargetInfo::hasFeature(StringRef Feature) const {
60 return llvm::StringSwitch<bool>(Feature)
61 .Case("softfloat", SoftFloat)
62 .Case("sparc", true)
63 .Default(false);
64}
65
67 llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags, StringRef CPU,
68 const std::vector<std::string> &FeaturesVec) const {
69 if (std::optional<llvm::StringMap<bool>> CPUFeatures =
70 llvm::Sparc::getSparcDefaultTargetFeatures(CPU))
71 Features = std::move(*CPUFeatures);
72 return TargetInfo::initFeatureMap(Features, Diags, CPU, FeaturesVec);
73}
74
75bool SparcTargetInfo::handleTargetFeatures(std::vector<std::string> &Features,
76 DiagnosticsEngine &Diags) {
77 for (const std::string &Feature : Features) {
78 if (Feature == "+soft-float")
79 SoftFloat = true;
80 else if (Feature == "+v9")
81 IsV9 = true;
82 else if (Feature == "+leon")
83 IsLeon = true;
84 else if (Feature == "+hasleoncasa")
85 HasLeonCASA = true;
86 else if (Feature == "+soft-mul-div")
87 SoftMulDiv = true;
88 }
89 return true;
90}
91
92bool SparcTargetInfo::isValidCPUName(StringRef Name) const {
93 return llvm::Sparc::isValidCPU(Name);
94}
95
97 SmallVectorImpl<StringRef> &Values) const {
98 llvm::Sparc::fillValidCPUList(Values);
99}
100
102 MacroBuilder &Builder) const {
103 DefineStd(Builder, "sparc", Opts);
104 Builder.defineMacro("__REGISTER_PREFIX__", "");
105
106 if (SoftFloat)
107 Builder.defineMacro("_SOFT_FLOAT");
108}
109
111 MacroBuilder &Builder) const {
113 // As with GCC, V7 gets none of the V8 macros, since it lacks the integer
114 // multiply and divide instructions.
115 if (getTriple().isOSSolaris()) {
116 if (!SoftMulDiv)
117 Builder.defineMacro("__sparcv8");
118 } else if (IsV9) {
119 Builder.defineMacro("__sparc_v9__");
120 } else if (!SoftMulDiv) {
121 Builder.defineMacro("__sparcv8");
122 Builder.defineMacro("__sparcv8__");
123 Builder.defineMacro("__sparc_v8__");
124 }
125 // As with GCC, name some of the CPUs.
126 StringRef CPUMacro = llvm::StringSwitch<StringRef>(CPU)
127 .Cases({"sparclite", "f934"}, "__sparclite__")
128 .Case("sparclite86x", "__sparclite86x__")
129 .Cases({"sparclet", "tsc701"}, "__sparclet__")
130 .Case("supersparc", "__supersparc__")
131 .Case("hypersparc", "__hypersparc__")
132 .Default("");
133 if (!CPUMacro.empty())
134 Builder.defineMacro(CPUMacro);
135 if (IsLeon)
136 Builder.defineMacro("__leon__");
137 if (IsV9 || HasLeonCASA) {
138 Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1");
139 Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2");
140 Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4");
141 // As with GCC, 64-bit compare-and-swap is only inlined in V8+ mode.
142 if (IsV9 && V8Plus)
143 Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8");
144 }
145 if (LongDoubleWidth == 128)
146 Builder.defineMacro("__LONG_DOUBLE_128__");
147}
148
150 MacroBuilder &Builder) const {
152 Builder.defineMacro("__sparcv9");
153 Builder.defineMacro("__arch64__");
154 // Solaris doesn't need these variants, but the BSDs do.
155 if (!getTriple().isOSSolaris()) {
156 Builder.defineMacro("__sparc64__");
157 Builder.defineMacro("__sparc_v9__");
158 Builder.defineMacro("__sparcv9__");
159 }
160
161 Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1");
162 Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2");
163 Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4");
164 Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8");
165}
166
167bool SparcV9TargetInfo::isValidCPUName(StringRef Name) const {
168 std::optional<llvm::StringMap<bool>> Features =
169 llvm::Sparc::getSparcDefaultTargetFeatures(Name);
170 return Features && Features->lookup("v9");
171}
172
174 SmallVectorImpl<StringRef> &Values) const {
176 llvm::Sparc::fillValidCPUList(CPUs);
177 llvm::copy_if(CPUs, std::back_inserter(Values),
178 [this](StringRef CPU) { return isValidCPUName(CPU); });
179}
Defines the clang::MacroBuilder utility class.
Concrete class used by the front-end to report problems and issues.
Definition Diagnostic.h:240
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
const llvm::Triple & getTriple() const
Returns the target triple of the primary target.
virtual bool initFeatureMap(llvm::StringMap< bool > &Features, DiagnosticsEngine &Diags, StringRef CPU, const std::vector< std::string > &FeatureVec) const
Initialize the map with the default set of target features for the CPU this should include all legal ...
bool handleTargetFeatures(std::vector< std::string > &Features, DiagnosticsEngine &Diags) override
Perform initialization based on the user configured set of features (e.g., +sse4).
Definition Sparc.cpp:75
bool isValidCPUName(StringRef Name) const override
Determine whether this TargetInfo supports the given CPU name.
Definition Sparc.cpp:92
bool hasFeature(StringRef Feature) const override
Determine whether the given target has the given feature.
Definition Sparc.cpp:59
ArrayRef< const char * > getGCCRegNames() const override
Definition Sparc.cpp:40
bool initFeatureMap(llvm::StringMap< bool > &Features, DiagnosticsEngine &Diags, StringRef CPU, const std::vector< std::string > &FeaturesVec) const override
Initialize the map with the default set of target features for the CPU this should include all legal ...
Definition Sparc.cpp:66
ArrayRef< TargetInfo::GCCRegAlias > getGCCRegAliases() const override
Definition Sparc.cpp:55
void fillValidCPUList(SmallVectorImpl< StringRef > &Values) const override
Fill a SmallVectorImpl with the valid values to setCPU.
Definition Sparc.cpp:96
void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder) const override
===-— Other target property query methods -----------------------—===//
Definition Sparc.cpp:101
void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder) const override
===-— Other target property query methods -----------------------—===//
Definition Sparc.cpp:110
void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder) const override
===-— Other target property query methods -----------------------—===//
Definition Sparc.cpp:149
void fillValidCPUList(SmallVectorImpl< StringRef > &Values) const override
Fill a SmallVectorImpl with the valid values to setCPU.
Definition Sparc.cpp:173
bool isValidCPUName(StringRef Name) const override
Determine whether this TargetInfo supports the given CPU name.
Definition Sparc.cpp:167
LLVM_LIBRARY_VISIBILITY void DefineStd(clang::MacroBuilder &Builder, llvm::StringRef MacroName, const clang::LangOptions &Opts)
Define a macro name and standard variants.
Top level wrappers for InstallAPI frontend operations.