Hexagon.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. //===--- Hexagon.h - Declare Hexagon 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 Hexagon TargetInfo objects.
  10. //
  11. //===----------------------------------------------------------------------===//
  12. #ifndef LLVM_CLANG_LIB_BASIC_TARGETS_HEXAGON_H
  13. #define LLVM_CLANG_LIB_BASIC_TARGETS_HEXAGON_H
  14. #include "clang/Basic/TargetInfo.h"
  15. #include "clang/Basic/TargetOptions.h"
  16. #include "llvm/ADT/Triple.h"
  17. #include "llvm/Support/Compiler.h"
  18. namespace clang {
  19. namespace targets {
  20. // Hexagon abstract base class
  21. class LLVM_LIBRARY_VISIBILITY HexagonTargetInfo : public TargetInfo {
  22. static const Builtin::Info BuiltinInfo[];
  23. static const char *const GCCRegNames[];
  24. static const TargetInfo::GCCRegAlias GCCRegAliases[];
  25. std::string CPU;
  26. std::string HVXVersion;
  27. bool HasHVX = false;
  28. bool HasHVX64B = false;
  29. bool HasHVX128B = false;
  30. bool UseLongCalls = false;
  31. public:
  32. HexagonTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
  33. : TargetInfo(Triple) {
  34. // Specify the vector alignment explicitly. For v512x1, the calculated
  35. // alignment would be 512*alignment(i1), which is 512 bytes, instead of
  36. // the required minimum of 64 bytes.
  37. resetDataLayout(
  38. "e-m:e-p:32:32:32-a:0-n16:32-"
  39. "i64:64:64-i32:32:32-i16:16:16-i1:8:8-f32:32:32-f64:64:64-"
  40. "v32:32:32-v64:64:64-v512:512:512-v1024:1024:1024-v2048:2048:2048");
  41. SizeType = UnsignedInt;
  42. PtrDiffType = SignedInt;
  43. IntPtrType = SignedInt;
  44. // {} in inline assembly are packet specifiers, not assembly variant
  45. // specifiers.
  46. NoAsmVariants = true;
  47. LargeArrayMinWidth = 64;
  48. LargeArrayAlign = 64;
  49. UseBitFieldTypeAlignment = true;
  50. ZeroLengthBitfieldBoundary = 32;
  51. }
  52. ArrayRef<Builtin::Info> getTargetBuiltins() const override;
  53. bool validateAsmConstraint(const char *&Name,
  54. TargetInfo::ConstraintInfo &Info) const override {
  55. switch (*Name) {
  56. case 'v':
  57. case 'q':
  58. if (HasHVX) {
  59. Info.setAllowsRegister();
  60. return true;
  61. }
  62. break;
  63. case 'a': // Modifier register m0-m1.
  64. Info.setAllowsRegister();
  65. return true;
  66. case 's':
  67. // Relocatable constant.
  68. return true;
  69. }
  70. return false;
  71. }
  72. void getTargetDefines(const LangOptions &Opts,
  73. MacroBuilder &Builder) const override;
  74. bool isCLZForZeroUndef() const override { return false; }
  75. bool hasFeature(StringRef Feature) const override;
  76. bool
  77. initFeatureMap(llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags,
  78. StringRef CPU,
  79. const std::vector<std::string> &FeaturesVec) const override;
  80. bool handleTargetFeatures(std::vector<std::string> &Features,
  81. DiagnosticsEngine &Diags) override;
  82. BuiltinVaListKind getBuiltinVaListKind() const override {
  83. return TargetInfo::CharPtrBuiltinVaList;
  84. }
  85. ArrayRef<const char *> getGCCRegNames() const override;
  86. ArrayRef<TargetInfo::GCCRegAlias> getGCCRegAliases() const override;
  87. const char *getClobbers() const override { return ""; }
  88. static const char *getHexagonCPUSuffix(StringRef Name);
  89. bool isValidCPUName(StringRef Name) const override {
  90. return getHexagonCPUSuffix(Name);
  91. }
  92. void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const override;
  93. bool setCPU(const std::string &Name) override {
  94. if (!isValidCPUName(Name))
  95. return false;
  96. CPU = Name;
  97. return true;
  98. }
  99. int getEHDataRegisterNumber(unsigned RegNo) const override {
  100. return RegNo < 2 ? RegNo : -1;
  101. }
  102. };
  103. } // namespace targets
  104. } // namespace clang
  105. #endif // LLVM_CLANG_LIB_BASIC_TARGETS_HEXAGON_H