Hexagon.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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 char *const GCCRegNames[];
  23. static const TargetInfo::GCCRegAlias GCCRegAliases[];
  24. std::string CPU;
  25. std::string HVXVersion;
  26. bool HasHVX = false;
  27. bool HasHVX64B = false;
  28. bool HasHVX128B = false;
  29. bool HasAudio = 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. MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 64;
  52. // These are the default values anyway, but explicitly make sure
  53. // that the size of the boolean type is 8 bits. Bool vectors are used
  54. // for modeling predicate registers in HVX, and the bool -> byte
  55. // correspondence matches the HVX architecture.
  56. BoolWidth = BoolAlign = 8;
  57. }
  58. ArrayRef<Builtin::Info> getTargetBuiltins() const override;
  59. bool validateAsmConstraint(const char *&Name,
  60. TargetInfo::ConstraintInfo &Info) const override {
  61. switch (*Name) {
  62. case 'v':
  63. case 'q':
  64. if (HasHVX) {
  65. Info.setAllowsRegister();
  66. return true;
  67. }
  68. break;
  69. case 'a': // Modifier register m0-m1.
  70. Info.setAllowsRegister();
  71. return true;
  72. case 's':
  73. // Relocatable constant.
  74. return true;
  75. }
  76. return false;
  77. }
  78. void getTargetDefines(const LangOptions &Opts,
  79. MacroBuilder &Builder) const override;
  80. bool isCLZForZeroUndef() const override { return false; }
  81. bool hasFeature(StringRef Feature) const override;
  82. bool
  83. initFeatureMap(llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags,
  84. StringRef CPU,
  85. const std::vector<std::string> &FeaturesVec) const override;
  86. bool handleTargetFeatures(std::vector<std::string> &Features,
  87. DiagnosticsEngine &Diags) override;
  88. BuiltinVaListKind getBuiltinVaListKind() const override {
  89. if (getTriple().isMusl())
  90. return TargetInfo::HexagonBuiltinVaList;
  91. return TargetInfo::CharPtrBuiltinVaList;
  92. }
  93. ArrayRef<const char *> getGCCRegNames() const override;
  94. ArrayRef<TargetInfo::GCCRegAlias> getGCCRegAliases() const override;
  95. const char *getClobbers() const override { return ""; }
  96. static const char *getHexagonCPUSuffix(StringRef Name);
  97. bool isValidCPUName(StringRef Name) const override {
  98. return getHexagonCPUSuffix(Name);
  99. }
  100. void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const override;
  101. bool setCPU(const std::string &Name) override {
  102. if (!isValidCPUName(Name))
  103. return false;
  104. CPU = Name;
  105. return true;
  106. }
  107. int getEHDataRegisterNumber(unsigned RegNo) const override {
  108. return RegNo < 2 ? RegNo : -1;
  109. }
  110. bool isTinyCore() const {
  111. // We can write more stricter checks later.
  112. return CPU.find('t') != std::string::npos;
  113. }
  114. bool hasBitIntType() const override { return true; }
  115. };
  116. } // namespace targets
  117. } // namespace clang
  118. #endif // LLVM_CLANG_LIB_BASIC_TARGETS_HEXAGON_H