Hexagon.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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 HasAudio = false;
  31. bool UseLongCalls = false;
  32. public:
  33. HexagonTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
  34. : TargetInfo(Triple) {
  35. // Specify the vector alignment explicitly. For v512x1, the calculated
  36. // alignment would be 512*alignment(i1), which is 512 bytes, instead of
  37. // the required minimum of 64 bytes.
  38. resetDataLayout(
  39. "e-m:e-p:32:32:32-a:0-n16:32-"
  40. "i64:64:64-i32:32:32-i16:16:16-i1:8:8-f32:32:32-f64:64:64-"
  41. "v32:32:32-v64:64:64-v512:512:512-v1024:1024:1024-v2048:2048:2048");
  42. SizeType = UnsignedInt;
  43. PtrDiffType = SignedInt;
  44. IntPtrType = SignedInt;
  45. // {} in inline assembly are packet specifiers, not assembly variant
  46. // specifiers.
  47. NoAsmVariants = true;
  48. LargeArrayMinWidth = 64;
  49. LargeArrayAlign = 64;
  50. UseBitFieldTypeAlignment = true;
  51. ZeroLengthBitfieldBoundary = 32;
  52. MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 64;
  53. // These are the default values anyway, but explicitly make sure
  54. // that the size of the boolean type is 8 bits. Bool vectors are used
  55. // for modeling predicate registers in HVX, and the bool -> byte
  56. // correspondence matches the HVX architecture.
  57. BoolWidth = BoolAlign = 8;
  58. }
  59. ArrayRef<Builtin::Info> getTargetBuiltins() const override;
  60. bool validateAsmConstraint(const char *&Name,
  61. TargetInfo::ConstraintInfo &Info) const override {
  62. switch (*Name) {
  63. case 'v':
  64. case 'q':
  65. if (HasHVX) {
  66. Info.setAllowsRegister();
  67. return true;
  68. }
  69. break;
  70. case 'a': // Modifier register m0-m1.
  71. Info.setAllowsRegister();
  72. return true;
  73. case 's':
  74. // Relocatable constant.
  75. return true;
  76. }
  77. return false;
  78. }
  79. void getTargetDefines(const LangOptions &Opts,
  80. MacroBuilder &Builder) const override;
  81. bool isCLZForZeroUndef() const override { return false; }
  82. bool hasFeature(StringRef Feature) const override;
  83. bool
  84. initFeatureMap(llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags,
  85. StringRef CPU,
  86. const std::vector<std::string> &FeaturesVec) const override;
  87. bool handleTargetFeatures(std::vector<std::string> &Features,
  88. DiagnosticsEngine &Diags) override;
  89. BuiltinVaListKind getBuiltinVaListKind() const override {
  90. if (getTriple().isMusl())
  91. return TargetInfo::HexagonBuiltinVaList;
  92. return TargetInfo::CharPtrBuiltinVaList;
  93. }
  94. ArrayRef<const char *> getGCCRegNames() const override;
  95. ArrayRef<TargetInfo::GCCRegAlias> getGCCRegAliases() const override;
  96. const char *getClobbers() const override { return ""; }
  97. static const char *getHexagonCPUSuffix(StringRef Name);
  98. bool isValidCPUName(StringRef Name) const override {
  99. return getHexagonCPUSuffix(Name);
  100. }
  101. void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const override;
  102. bool setCPU(const std::string &Name) override {
  103. if (!isValidCPUName(Name))
  104. return false;
  105. CPU = Name;
  106. return true;
  107. }
  108. int getEHDataRegisterNumber(unsigned RegNo) const override {
  109. return RegNo < 2 ? RegNo : -1;
  110. }
  111. bool isTinyCore() const {
  112. // We can write more stricter checks later.
  113. return CPU.find('t') != std::string::npos;
  114. }
  115. bool hasBitIntType() const override { return true; }
  116. };
  117. } // namespace targets
  118. } // namespace clang
  119. #endif // LLVM_CLANG_LIB_BASIC_TARGETS_HEXAGON_H