clang  7.0.0svn
Nios2.h
Go to the documentation of this file.
1 //===--- Nios2.h - Declare Nios2 target feature support ---------*- C++ -*-===//
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 declares Nios2 TargetInfo objects.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_CLANG_LIB_BASIC_TARGETS_NIOS2_H
15 #define LLVM_CLANG_LIB_BASIC_TARGETS_NIOS2_H
16 
17 #include "clang/Basic/TargetInfo.h"
19 #include "llvm/ADT/Triple.h"
20 #include "llvm/Support/Compiler.h"
21 
22 namespace clang {
23 namespace targets {
24 
25 class LLVM_LIBRARY_VISIBILITY Nios2TargetInfo : public TargetInfo {
26  void setDataLayout() {
27  if (BigEndian)
28  resetDataLayout("E-p:32:32:32-i8:8:32-i16:16:32-n32");
29  else
30  resetDataLayout("e-p:32:32:32-i8:8:32-i16:16:32-n32");
31  }
32 
33  static const Builtin::Info BuiltinInfo[];
34  std::string CPU;
35  std::string ABI;
36 
37 public:
38  Nios2TargetInfo(const llvm::Triple &triple, const TargetOptions &opts)
39  : TargetInfo(triple), CPU(opts.CPU), ABI(opts.ABI) {
40  SizeType = UnsignedInt;
41  PtrDiffType = SignedInt;
42  MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 32;
43  setDataLayout();
44  }
45 
46  StringRef getABI() const override { return ABI; }
47  bool setABI(const std::string &Name) override {
48  if (Name == "o32" || Name == "eabi") {
49  ABI = Name;
50  return true;
51  }
52  return false;
53  }
54 
55  bool isValidCPUName(StringRef Name) const override {
56  return Name == "nios2r1" || Name == "nios2r2";
57  }
58 
59  void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const override {
60  Values.append({"nios2r1", "nios2r2"});
61  }
62 
63  bool setCPU(const std::string &Name) override {
64  if (isValidCPUName(Name)) {
65  CPU = Name;
66  return true;
67  }
68  return false;
69  }
70 
71  void getTargetDefines(const LangOptions &Opts,
72  MacroBuilder &Builder) const override;
73 
74  ArrayRef<Builtin::Info> getTargetBuiltins() const override;
75 
76  bool isFeatureSupportedByCPU(StringRef Feature, StringRef CPU) const;
77 
78  bool
79  initFeatureMap(llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags,
80  StringRef CPU,
81  const std::vector<std::string> &FeatureVec) const override {
82  static const char *allFeatures[] = {"nios2r2mandatory", "nios2r2bmx",
83  "nios2r2mpx", "nios2r2cdx"
84  };
85  for (const char *feature : allFeatures) {
86  Features[feature] = isFeatureSupportedByCPU(feature, CPU);
87  }
88  return true;
89  }
90 
91  bool hasFeature(StringRef Feature) const override {
92  return isFeatureSupportedByCPU(Feature, CPU);
93  }
94 
97  }
98 
100  static const char *const GCCRegNames[] = {
101  // CPU register names
102  // Must match second column of GCCRegAliases
103  "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", "r8", "r9", "r10",
104  "r11", "r12", "r13", "r14", "r15", "r16", "r17", "r18", "r19", "r20",
105  "r21", "r22", "r23", "r24", "r25", "r26", "r27", "r28", "r29", "r30",
106  "r31",
107  // Floating point register names
108  "ctl0", "ctl1", "ctl2", "ctl3", "ctl4", "ctl5", "ctl6", "ctl7", "ctl8",
109  "ctl9", "ctl10", "ctl11", "ctl12", "ctl13", "ctl14", "ctl15"
110  };
111  return llvm::makeArrayRef(GCCRegNames);
112  }
113 
114  bool validateAsmConstraint(const char *&Name,
115  TargetInfo::ConstraintInfo &Info) const override {
116  switch (*Name) {
117  default:
118  return false;
119 
120  case 'r': // CPU registers.
121  case 'd': // Equivalent to "r" unless generating MIPS16 code.
122  case 'y': // Equivalent to "r", backwards compatibility only.
123  case 'f': // floating-point registers.
124  case 'c': // $25 for indirect jumps
125  case 'l': // lo register
126  case 'x': // hilo register pair
127  Info.setAllowsRegister();
128  return true;
129  }
130  }
131 
132  const char *getClobbers() const override { return ""; }
133 
135  static const TargetInfo::GCCRegAlias aliases[] = {
136  {{"zero"}, "r0"}, {{"at"}, "r1"}, {{"et"}, "r24"},
137  {{"bt"}, "r25"}, {{"gp"}, "r26"}, {{"sp"}, "r27"},
138  {{"fp"}, "r28"}, {{"ea"}, "r29"}, {{"ba"}, "r30"},
139  {{"ra"}, "r31"}, {{"status"}, "ctl0"}, {{"estatus"}, "ctl1"},
140  {{"bstatus"}, "ctl2"}, {{"ienable"}, "ctl3"}, {{"ipending"}, "ctl4"},
141  {{"cpuid"}, "ctl5"}, {{"exception"}, "ctl7"}, {{"pteaddr"}, "ctl8"},
142  {{"tlbacc"}, "ctl9"}, {{"tlbmisc"}, "ctl10"}, {{"badaddr"}, "ctl12"},
143  {{"config"}, "ctl13"}, {{"mpubase"}, "ctl14"}, {{"mpuacc"}, "ctl15"},
144  };
145  return llvm::makeArrayRef(aliases);
146  }
147 };
148 
149 } // namespace targets
150 } // namespace clang
151 #endif // LLVM_CLANG_LIB_BASIC_TARGETS_NIOS2_H
bool isValidCPUName(StringRef Name) const override
brief Determine whether this TargetInfo supports the given CPU name.
Definition: Nios2.h:55
static const Builtin::Info BuiltinInfo[]
Definition: Builtins.cpp:21
Options for controlling the target.
Definition: TargetOptions.h:26
bool initFeatureMap(llvm::StringMap< bool > &Features, DiagnosticsEngine &Diags, StringRef CPU, const std::vector< std::string > &FeatureVec) const override
Initialize the map with the default set of target features for the CPU this should include all legal ...
Definition: Nios2.h:79
Nios2TargetInfo(const llvm::Triple &triple, const TargetOptions &opts)
Definition: Nios2.h:38
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:50
Concrete class used by the front-end to report problems and issues.
Definition: Diagnostic.h:149
static const char *const GCCRegNames[]
Definition: X86.cpp:44
ArrayRef< TargetInfo::GCCRegAlias > getGCCRegAliases() const override
Definition: Nios2.h:134
typedef void* __builtin_va_list;
Definition: TargetInfo.h:165
Exposes information about the current target.
Definition: TargetInfo.h:54
StringRef getABI() const override
Get the ABI currently in use.
Definition: Nios2.h:46
const char * getClobbers() const override
Returns a string of target-specific clobbers, in LLVM format.
Definition: Nios2.h:132
bool hasFeature(StringRef Feature) const override
Determine whether the given target has the given feature.
Definition: Nios2.h:91
Defines the clang::TargetOptions class.
bool setABI(const std::string &Name) override
Use the specified ABI.
Definition: Nios2.h:47
bool setCPU(const std::string &Name) override
Target the specified CPU.
Definition: Nios2.h:63
Dataflow Directional Tag Classes.
ArrayRef< const char * > getGCCRegNames() const override
Definition: Nios2.h:99
BuiltinVaListKind
The different kinds of __builtin_va_list types defined by the target implementation.
Definition: TargetInfo.h:160
void fillValidCPUList(SmallVectorImpl< StringRef > &Values) const override
Fill a SmallVectorImpl with the valid values to setCPU.
Definition: Nios2.h:59
Defines the clang::TargetInfo interface.
BuiltinVaListKind getBuiltinVaListKind() const override
Returns the kind of __builtin_va_list type that should be used with this target.
Definition: Nios2.h:95
bool validateAsmConstraint(const char *&Name, TargetInfo::ConstraintInfo &Info) const override
Definition: Nios2.h:114