ARM.h 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. //===--- ARM.h - Declare ARM target feature support -------------*- 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. // This file declares ARM TargetInfo objects.
  10. //
  11. //===----------------------------------------------------------------------===//
  12. #ifndef LLVM_CLANG_LIB_BASIC_TARGETS_ARM_H
  13. #define LLVM_CLANG_LIB_BASIC_TARGETS_ARM_H
  14. #include "OSTargets.h"
  15. #include "clang/Basic/TargetInfo.h"
  16. #include "clang/Basic/TargetOptions.h"
  17. #include "llvm/ADT/Triple.h"
  18. #include "llvm/Support/Compiler.h"
  19. #include "llvm/Support/ARMTargetParser.h"
  20. #include "llvm/Support/TargetParser.h"
  21. namespace clang {
  22. namespace targets {
  23. class LLVM_LIBRARY_VISIBILITY ARMTargetInfo : public TargetInfo {
  24. // Possible FPU choices.
  25. enum FPUMode {
  26. VFP2FPU = (1 << 0),
  27. VFP3FPU = (1 << 1),
  28. VFP4FPU = (1 << 2),
  29. NeonFPU = (1 << 3),
  30. FPARMV8 = (1 << 4)
  31. };
  32. enum MVEMode {
  33. MVE_INT = (1 << 0),
  34. MVE_FP = (1 << 1)
  35. };
  36. // Possible HWDiv features.
  37. enum HWDivMode { HWDivThumb = (1 << 0), HWDivARM = (1 << 1) };
  38. static bool FPUModeIsVFP(FPUMode Mode) {
  39. return Mode & (VFP2FPU | VFP3FPU | VFP4FPU | NeonFPU | FPARMV8);
  40. }
  41. static const TargetInfo::GCCRegAlias GCCRegAliases[];
  42. static const char *const GCCRegNames[];
  43. std::string ABI, CPU;
  44. StringRef CPUProfile;
  45. StringRef CPUAttr;
  46. enum { FP_Default, FP_VFP, FP_Neon } FPMath;
  47. llvm::ARM::ISAKind ArchISA;
  48. llvm::ARM::ArchKind ArchKind = llvm::ARM::ArchKind::ARMV4T;
  49. llvm::ARM::ProfileKind ArchProfile;
  50. unsigned ArchVersion;
  51. unsigned FPU : 5;
  52. unsigned MVE : 2;
  53. unsigned IsAAPCS : 1;
  54. unsigned HWDiv : 2;
  55. // Initialized via features.
  56. unsigned SoftFloat : 1;
  57. unsigned SoftFloatABI : 1;
  58. unsigned CRC : 1;
  59. unsigned Crypto : 1;
  60. unsigned SHA2 : 1;
  61. unsigned AES : 1;
  62. unsigned DSP : 1;
  63. unsigned Unaligned : 1;
  64. unsigned DotProd : 1;
  65. unsigned HasMatMul : 1;
  66. unsigned FPRegsDisabled : 1;
  67. unsigned HasPAC : 1;
  68. unsigned HasBTI : 1;
  69. enum {
  70. LDREX_B = (1 << 0), /// byte (8-bit)
  71. LDREX_H = (1 << 1), /// half (16-bit)
  72. LDREX_W = (1 << 2), /// word (32-bit)
  73. LDREX_D = (1 << 3), /// double (64-bit)
  74. };
  75. uint32_t LDREX;
  76. // ACLE 6.5.1 Hardware floating point
  77. enum {
  78. HW_FP_HP = (1 << 1), /// half (16-bit)
  79. HW_FP_SP = (1 << 2), /// single (32-bit)
  80. HW_FP_DP = (1 << 3), /// double (64-bit)
  81. };
  82. uint32_t HW_FP;
  83. static const Builtin::Info BuiltinInfo[];
  84. void setABIAAPCS();
  85. void setABIAPCS(bool IsAAPCS16);
  86. void setArchInfo();
  87. void setArchInfo(llvm::ARM::ArchKind Kind);
  88. void setAtomic();
  89. bool isThumb() const;
  90. bool supportsThumb() const;
  91. bool supportsThumb2() const;
  92. bool hasMVE() const;
  93. bool hasMVEFloat() const;
  94. bool hasCDE() const;
  95. StringRef getCPUAttr() const;
  96. StringRef getCPUProfile() const;
  97. public:
  98. ARMTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts);
  99. StringRef getABI() const override;
  100. bool setABI(const std::string &Name) override;
  101. bool isBranchProtectionSupportedArch(StringRef Arch) const override;
  102. bool validateBranchProtection(StringRef Spec, StringRef Arch,
  103. BranchProtectionInfo &BPI,
  104. StringRef &Err) const override;
  105. // FIXME: This should be based on Arch attributes, not CPU names.
  106. bool
  107. initFeatureMap(llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags,
  108. StringRef CPU,
  109. const std::vector<std::string> &FeaturesVec) const override;
  110. bool isValidFeatureName(StringRef Feature) const override {
  111. // We pass soft-float-abi in as a -target-feature, but the backend figures
  112. // this out through other means.
  113. return Feature != "soft-float-abi";
  114. }
  115. bool handleTargetFeatures(std::vector<std::string> &Features,
  116. DiagnosticsEngine &Diags) override;
  117. bool hasFeature(StringRef Feature) const override;
  118. bool hasBFloat16Type() const override;
  119. bool isValidCPUName(StringRef Name) const override;
  120. void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const override;
  121. bool setCPU(const std::string &Name) override;
  122. bool setFPMath(StringRef Name) override;
  123. bool useFP16ConversionIntrinsics() const override {
  124. return false;
  125. }
  126. void getTargetDefinesARMV81A(const LangOptions &Opts,
  127. MacroBuilder &Builder) const;
  128. void getTargetDefinesARMV82A(const LangOptions &Opts,
  129. MacroBuilder &Builder) const;
  130. void getTargetDefinesARMV83A(const LangOptions &Opts,
  131. MacroBuilder &Builder) const;
  132. void getTargetDefines(const LangOptions &Opts,
  133. MacroBuilder &Builder) const override;
  134. ArrayRef<Builtin::Info> getTargetBuiltins() const override;
  135. bool isCLZForZeroUndef() const override;
  136. BuiltinVaListKind getBuiltinVaListKind() const override;
  137. ArrayRef<const char *> getGCCRegNames() const override;
  138. ArrayRef<TargetInfo::GCCRegAlias> getGCCRegAliases() const override;
  139. bool validateAsmConstraint(const char *&Name,
  140. TargetInfo::ConstraintInfo &Info) const override;
  141. std::string convertConstraint(const char *&Constraint) const override;
  142. bool
  143. validateConstraintModifier(StringRef Constraint, char Modifier, unsigned Size,
  144. std::string &SuggestedModifier) const override;
  145. const char *getClobbers() const override;
  146. StringRef getConstraintRegister(StringRef Constraint,
  147. StringRef Expression) const override {
  148. return Expression;
  149. }
  150. CallingConvCheckResult checkCallingConvention(CallingConv CC) const override;
  151. int getEHDataRegisterNumber(unsigned RegNo) const override;
  152. bool hasSjLjLowering() const override;
  153. bool hasBitIntType() const override { return true; }
  154. const char *getBFloat16Mangling() const override { return "u6__bf16"; };
  155. };
  156. class LLVM_LIBRARY_VISIBILITY ARMleTargetInfo : public ARMTargetInfo {
  157. public:
  158. ARMleTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts);
  159. void getTargetDefines(const LangOptions &Opts,
  160. MacroBuilder &Builder) const override;
  161. };
  162. class LLVM_LIBRARY_VISIBILITY ARMbeTargetInfo : public ARMTargetInfo {
  163. public:
  164. ARMbeTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts);
  165. void getTargetDefines(const LangOptions &Opts,
  166. MacroBuilder &Builder) const override;
  167. };
  168. class LLVM_LIBRARY_VISIBILITY WindowsARMTargetInfo
  169. : public WindowsTargetInfo<ARMleTargetInfo> {
  170. const llvm::Triple Triple;
  171. public:
  172. WindowsARMTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts);
  173. void getVisualStudioDefines(const LangOptions &Opts,
  174. MacroBuilder &Builder) const;
  175. BuiltinVaListKind getBuiltinVaListKind() const override;
  176. CallingConvCheckResult checkCallingConvention(CallingConv CC) const override;
  177. };
  178. // Windows ARM + Itanium C++ ABI Target
  179. class LLVM_LIBRARY_VISIBILITY ItaniumWindowsARMleTargetInfo
  180. : public WindowsARMTargetInfo {
  181. public:
  182. ItaniumWindowsARMleTargetInfo(const llvm::Triple &Triple,
  183. const TargetOptions &Opts);
  184. void getTargetDefines(const LangOptions &Opts,
  185. MacroBuilder &Builder) const override;
  186. };
  187. // Windows ARM, MS (C++) ABI
  188. class LLVM_LIBRARY_VISIBILITY MicrosoftARMleTargetInfo
  189. : public WindowsARMTargetInfo {
  190. public:
  191. MicrosoftARMleTargetInfo(const llvm::Triple &Triple,
  192. const TargetOptions &Opts);
  193. void getTargetDefines(const LangOptions &Opts,
  194. MacroBuilder &Builder) const override;
  195. };
  196. // ARM MinGW target
  197. class LLVM_LIBRARY_VISIBILITY MinGWARMTargetInfo : public WindowsARMTargetInfo {
  198. public:
  199. MinGWARMTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts);
  200. void getTargetDefines(const LangOptions &Opts,
  201. MacroBuilder &Builder) const override;
  202. };
  203. // ARM Cygwin target
  204. class LLVM_LIBRARY_VISIBILITY CygwinARMTargetInfo : public ARMleTargetInfo {
  205. public:
  206. CygwinARMTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts);
  207. void getTargetDefines(const LangOptions &Opts,
  208. MacroBuilder &Builder) const override;
  209. };
  210. class LLVM_LIBRARY_VISIBILITY DarwinARMTargetInfo
  211. : public DarwinTargetInfo<ARMleTargetInfo> {
  212. protected:
  213. void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
  214. MacroBuilder &Builder) const override;
  215. public:
  216. DarwinARMTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts);
  217. };
  218. // 32-bit RenderScript is armv7 with width and align of 'long' set to 8-bytes
  219. class LLVM_LIBRARY_VISIBILITY RenderScript32TargetInfo
  220. : public ARMleTargetInfo {
  221. public:
  222. RenderScript32TargetInfo(const llvm::Triple &Triple,
  223. const TargetOptions &Opts);
  224. void getTargetDefines(const LangOptions &Opts,
  225. MacroBuilder &Builder) const override;
  226. };
  227. } // namespace targets
  228. } // namespace clang
  229. #endif // LLVM_CLANG_LIB_BASIC_TARGETS_ARM_H