LoongArch.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. //===-- LoongArch.h - Declare LoongArch 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 LoongArch TargetInfo objects.
  10. //
  11. //===----------------------------------------------------------------------===//
  12. #ifndef LLVM_CLANG_LIB_BASIC_TARGETS_LOONGARCH_H
  13. #define LLVM_CLANG_LIB_BASIC_TARGETS_LOONGARCH_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. class LLVM_LIBRARY_VISIBILITY LoongArchTargetInfo : public TargetInfo {
  21. protected:
  22. std::string ABI;
  23. bool HasFeatureD;
  24. bool HasFeatureF;
  25. public:
  26. LoongArchTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
  27. : TargetInfo(Triple) {
  28. HasFeatureD = false;
  29. HasFeatureF = false;
  30. LongDoubleWidth = 128;
  31. LongDoubleAlign = 128;
  32. LongDoubleFormat = &llvm::APFloat::IEEEquad();
  33. SuitableAlign = 128;
  34. WCharType = SignedInt;
  35. WIntType = UnsignedInt;
  36. }
  37. StringRef getABI() const override { return ABI; }
  38. void getTargetDefines(const LangOptions &Opts,
  39. MacroBuilder &Builder) const override;
  40. ArrayRef<Builtin::Info> getTargetBuiltins() const override;
  41. BuiltinVaListKind getBuiltinVaListKind() const override {
  42. return TargetInfo::VoidPtrBuiltinVaList;
  43. }
  44. const char *getClobbers() const override { return ""; }
  45. ArrayRef<const char *> getGCCRegNames() const override;
  46. int getEHDataRegisterNumber(unsigned RegNo) const override {
  47. if (RegNo == 0)
  48. return 4;
  49. if (RegNo == 1)
  50. return 5;
  51. return -1;
  52. }
  53. ArrayRef<TargetInfo::GCCRegAlias> getGCCRegAliases() const override;
  54. bool validateAsmConstraint(const char *&Name,
  55. TargetInfo::ConstraintInfo &Info) const override;
  56. std::string convertConstraint(const char *&Constraint) const override;
  57. bool hasBitIntType() const override { return true; }
  58. bool handleTargetFeatures(std::vector<std::string> &Features,
  59. DiagnosticsEngine &Diags) override;
  60. bool
  61. initFeatureMap(llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags,
  62. StringRef CPU,
  63. const std::vector<std::string> &FeaturesVec) const override;
  64. bool hasFeature(StringRef Feature) const override;
  65. };
  66. class LLVM_LIBRARY_VISIBILITY LoongArch32TargetInfo
  67. : public LoongArchTargetInfo {
  68. public:
  69. LoongArch32TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
  70. : LoongArchTargetInfo(Triple, Opts) {
  71. IntPtrType = SignedInt;
  72. PtrDiffType = SignedInt;
  73. SizeType = UnsignedInt;
  74. resetDataLayout("e-m:e-p:32:32-i64:64-n32-S128");
  75. // TODO: select appropriate ABI.
  76. setABI("ilp32d");
  77. }
  78. bool setABI(const std::string &Name) override {
  79. if (Name == "ilp32d" || Name == "ilp32f" || Name == "ilp32s") {
  80. ABI = Name;
  81. return true;
  82. }
  83. return false;
  84. }
  85. void setMaxAtomicWidth() override {
  86. MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 32;
  87. }
  88. };
  89. class LLVM_LIBRARY_VISIBILITY LoongArch64TargetInfo
  90. : public LoongArchTargetInfo {
  91. public:
  92. LoongArch64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
  93. : LoongArchTargetInfo(Triple, Opts) {
  94. LongWidth = LongAlign = PointerWidth = PointerAlign = 64;
  95. IntMaxType = Int64Type = SignedLong;
  96. resetDataLayout("e-m:e-p:64:64-i64:64-i128:128-n64-S128");
  97. // TODO: select appropriate ABI.
  98. setABI("lp64d");
  99. }
  100. bool setABI(const std::string &Name) override {
  101. if (Name == "lp64d" || Name == "lp64f" || Name == "lp64s") {
  102. ABI = Name;
  103. return true;
  104. }
  105. return false;
  106. }
  107. void setMaxAtomicWidth() override {
  108. MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 64;
  109. }
  110. };
  111. } // end namespace targets
  112. } // end namespace clang
  113. #endif // LLVM_CLANG_LIB_BASIC_TARGETS_LOONGARCH_H