clang  6.0.0svn
Sparc.cpp
Go to the documentation of this file.
1 //===--- Sparc.cpp - Implement Sparc target feature support ---------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements Sparc TargetInfo objects.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "Sparc.h"
15 #include "Targets.h"
17 #include "llvm/ADT/StringSwitch.h"
18 
19 using namespace clang;
20 using namespace clang::targets;
21 
22 const char *const SparcTargetInfo::GCCRegNames[] = {
23  "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", "r8", "r9", "r10",
24  "r11", "r12", "r13", "r14", "r15", "r16", "r17", "r18", "r19", "r20", "r21",
25  "r22", "r23", "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31"
26 };
27 
29  return llvm::makeArrayRef(GCCRegNames);
30 }
31 
32 const TargetInfo::GCCRegAlias SparcTargetInfo::GCCRegAliases[] = {
33  {{"g0"}, "r0"}, {{"g1"}, "r1"}, {{"g2"}, "r2"}, {{"g3"}, "r3"},
34  {{"g4"}, "r4"}, {{"g5"}, "r5"}, {{"g6"}, "r6"}, {{"g7"}, "r7"},
35  {{"o0"}, "r8"}, {{"o1"}, "r9"}, {{"o2"}, "r10"}, {{"o3"}, "r11"},
36  {{"o4"}, "r12"}, {{"o5"}, "r13"}, {{"o6", "sp"}, "r14"}, {{"o7"}, "r15"},
37  {{"l0"}, "r16"}, {{"l1"}, "r17"}, {{"l2"}, "r18"}, {{"l3"}, "r19"},
38  {{"l4"}, "r20"}, {{"l5"}, "r21"}, {{"l6"}, "r22"}, {{"l7"}, "r23"},
39  {{"i0"}, "r24"}, {{"i1"}, "r25"}, {{"i2"}, "r26"}, {{"i3"}, "r27"},
40  {{"i4"}, "r28"}, {{"i5"}, "r29"}, {{"i6", "fp"}, "r30"}, {{"i7"}, "r31"},
41 };
42 
44  return llvm::makeArrayRef(GCCRegAliases);
45 }
46 
47 bool SparcTargetInfo::hasFeature(StringRef Feature) const {
48  return llvm::StringSwitch<bool>(Feature)
49  .Case("softfloat", SoftFloat)
50  .Case("sparc", true)
51  .Default(false);
52 }
53 
55  return llvm::StringSwitch<CPUKind>(Name)
56  .Case("v8", CK_V8)
57  .Case("supersparc", CK_SUPERSPARC)
58  .Case("sparclite", CK_SPARCLITE)
59  .Case("f934", CK_F934)
60  .Case("hypersparc", CK_HYPERSPARC)
61  .Case("sparclite86x", CK_SPARCLITE86X)
62  .Case("sparclet", CK_SPARCLET)
63  .Case("tsc701", CK_TSC701)
64  .Case("v9", CK_V9)
65  .Case("ultrasparc", CK_ULTRASPARC)
66  .Case("ultrasparc3", CK_ULTRASPARC3)
67  .Case("niagara", CK_NIAGARA)
68  .Case("niagara2", CK_NIAGARA2)
69  .Case("niagara3", CK_NIAGARA3)
70  .Case("niagara4", CK_NIAGARA4)
71  .Case("ma2100", CK_MYRIAD2100)
72  .Case("ma2150", CK_MYRIAD2150)
73  .Case("ma2155", CK_MYRIAD2155)
74  .Case("ma2450", CK_MYRIAD2450)
75  .Case("ma2455", CK_MYRIAD2455)
76  .Case("ma2x5x", CK_MYRIAD2x5x)
77  .Case("ma2080", CK_MYRIAD2080)
78  .Case("ma2085", CK_MYRIAD2085)
79  .Case("ma2480", CK_MYRIAD2480)
80  .Case("ma2485", CK_MYRIAD2485)
81  .Case("ma2x8x", CK_MYRIAD2x8x)
82  // FIXME: the myriad2[.n] spellings are obsolete,
83  // but a grace period is needed to allow updating dependent builds.
84  .Case("myriad2", CK_MYRIAD2x5x)
85  .Case("myriad2.1", CK_MYRIAD2100)
86  .Case("myriad2.2", CK_MYRIAD2x5x)
87  .Case("myriad2.3", CK_MYRIAD2x8x)
88  .Case("leon2", CK_LEON2)
89  .Case("at697e", CK_LEON2_AT697E)
90  .Case("at697f", CK_LEON2_AT697F)
91  .Case("leon3", CK_LEON3)
92  .Case("ut699", CK_LEON3_UT699)
93  .Case("gr712rc", CK_LEON3_GR712RC)
94  .Case("leon4", CK_LEON4)
95  .Case("gr740", CK_LEON4_GR740)
96  .Default(CK_GENERIC);
97 }
98 
100  MacroBuilder &Builder) const {
101  DefineStd(Builder, "sparc", Opts);
102  Builder.defineMacro("__REGISTER_PREFIX__", "");
103 
104  if (SoftFloat)
105  Builder.defineMacro("SOFT_FLOAT", "1");
106 }
107 
109  MacroBuilder &Builder) const {
110  SparcTargetInfo::getTargetDefines(Opts, Builder);
111  switch (getCPUGeneration(CPU)) {
112  case CG_V8:
113  Builder.defineMacro("__sparcv8");
114  if (getTriple().getOS() != llvm::Triple::Solaris)
115  Builder.defineMacro("__sparcv8__");
116  break;
117  case CG_V9:
118  Builder.defineMacro("__sparcv9");
119  if (getTriple().getOS() != llvm::Triple::Solaris) {
120  Builder.defineMacro("__sparcv9__");
121  Builder.defineMacro("__sparc_v9__");
122  }
123  break;
124  }
125  if (getTriple().getVendor() == llvm::Triple::Myriad) {
126  std::string MyriadArchValue, Myriad2Value;
127  Builder.defineMacro("__sparc_v8__");
128  Builder.defineMacro("__leon__");
129  switch (CPU) {
130  case CK_MYRIAD2100:
131  MyriadArchValue = "__ma2100";
132  Myriad2Value = "1";
133  break;
134  case CK_MYRIAD2150:
135  MyriadArchValue = "__ma2150";
136  Myriad2Value = "2";
137  break;
138  case CK_MYRIAD2155:
139  MyriadArchValue = "__ma2155";
140  Myriad2Value = "2";
141  break;
142  case CK_MYRIAD2450:
143  MyriadArchValue = "__ma2450";
144  Myriad2Value = "2";
145  break;
146  case CK_MYRIAD2455:
147  MyriadArchValue = "__ma2455";
148  Myriad2Value = "2";
149  break;
150  case CK_MYRIAD2x5x:
151  Myriad2Value = "2";
152  break;
153  case CK_MYRIAD2080:
154  MyriadArchValue = "__ma2080";
155  Myriad2Value = "3";
156  break;
157  case CK_MYRIAD2085:
158  MyriadArchValue = "__ma2085";
159  Myriad2Value = "3";
160  break;
161  case CK_MYRIAD2480:
162  MyriadArchValue = "__ma2480";
163  Myriad2Value = "3";
164  break;
165  case CK_MYRIAD2485:
166  MyriadArchValue = "__ma2485";
167  Myriad2Value = "3";
168  break;
169  case CK_MYRIAD2x8x:
170  Myriad2Value = "3";
171  break;
172  default:
173  MyriadArchValue = "__ma2100";
174  Myriad2Value = "1";
175  break;
176  }
177  if (!MyriadArchValue.empty()) {
178  Builder.defineMacro(MyriadArchValue, "1");
179  Builder.defineMacro(MyriadArchValue + "__", "1");
180  }
181  Builder.defineMacro("__myriad2__", Myriad2Value);
182  Builder.defineMacro("__myriad2", Myriad2Value);
183  }
184 }
185 
187  MacroBuilder &Builder) const {
188  SparcTargetInfo::getTargetDefines(Opts, Builder);
189  Builder.defineMacro("__sparcv9");
190  Builder.defineMacro("__arch64__");
191  // Solaris doesn't need these variants, but the BSDs do.
192  if (getTriple().getOS() != llvm::Triple::Solaris) {
193  Builder.defineMacro("__sparc64__");
194  Builder.defineMacro("__sparc_v9__");
195  Builder.defineMacro("__sparcv9__");
196  }
197 }
void DefineStd(MacroBuilder &Builder, StringRef MacroName, const LangOptions &Opts)
DefineStd - Define a macro name and standard variants.
Definition: Targets.cpp:53
Defines the clang::MacroBuilder utility class.
const llvm::Triple & getTriple() const
Returns the target triple of the primary target.
Definition: TargetInfo.h:790
void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder) const override
===-— Other target property query methods --------------------——===//
Definition: Sparc.cpp:99
ArrayRef< TargetInfo::GCCRegAlias > getGCCRegAliases() const override
Definition: Sparc.cpp:43
void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder) const override
===-— Other target property query methods --------------------——===//
Definition: Sparc.cpp:186
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:48
void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder) const override
===-— Other target property query methods --------------------——===//
Definition: Sparc.cpp:108
Dataflow Directional Tag Classes.
enum clang::targets::SparcTargetInfo::CPUKind CPU
bool hasFeature(StringRef Feature) const override
Determine whether the given target has the given feature.
Definition: Sparc.cpp:47
CPUGeneration getCPUGeneration(CPUKind Kind) const
Definition: Sparc.h:134
ArrayRef< const char * > getGCCRegNames() const override
Definition: Sparc.cpp:28
void defineMacro(const Twine &Name, const Twine &Value="1")
Append a #define line for macro of the form "\#define Name Value\n".
Definition: MacroBuilder.h:30
CPUKind getCPUKind(StringRef Name) const
Definition: Sparc.cpp:54