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