| 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/Support/Compiler.h" | 
|---|
| 19 | #include "llvm/TargetParser/Triple.h" | 
|---|
| 20 |  | 
|---|
| 21 | namespace clang { | 
|---|
| 22 | namespace targets { | 
|---|
| 23 |  | 
|---|
| 24 | class LLVM_LIBRARY_VISIBILITY LoongArchTargetInfo : public TargetInfo { | 
|---|
| 25 | protected: | 
|---|
| 26 | std::string ABI; | 
|---|
| 27 | std::string CPU; | 
|---|
| 28 | bool HasFeatureD; | 
|---|
| 29 | bool HasFeatureF; | 
|---|
| 30 | bool HasFeatureLSX; | 
|---|
| 31 | bool HasFeatureLASX; | 
|---|
| 32 | bool HasFeatureFrecipe; | 
|---|
| 33 | bool HasFeatureLAM_BH; | 
|---|
| 34 | bool HasFeatureLAMCAS; | 
|---|
| 35 | bool HasFeatureLD_SEQ_SA; | 
|---|
| 36 | bool HasFeatureDiv32; | 
|---|
| 37 | bool HasFeatureSCQ; | 
|---|
| 38 |  | 
|---|
| 39 | public: | 
|---|
| 40 | LoongArchTargetInfo(const llvm::Triple &Triple, const TargetOptions &) | 
|---|
| 41 | : TargetInfo(Triple) { | 
|---|
| 42 | HasFeatureD = false; | 
|---|
| 43 | HasFeatureF = false; | 
|---|
| 44 | HasFeatureLSX = false; | 
|---|
| 45 | HasFeatureLASX = false; | 
|---|
| 46 | HasFeatureFrecipe = false; | 
|---|
| 47 | HasFeatureLAM_BH = false; | 
|---|
| 48 | HasFeatureLAMCAS = false; | 
|---|
| 49 | HasFeatureLD_SEQ_SA = false; | 
|---|
| 50 | HasFeatureDiv32 = false; | 
|---|
| 51 | HasFeatureSCQ = false; | 
|---|
| 52 | BFloat16Width = 16; | 
|---|
| 53 | BFloat16Align = 16; | 
|---|
| 54 | BFloat16Format = &llvm::APFloat::BFloat(); | 
|---|
| 55 | LongDoubleWidth = 128; | 
|---|
| 56 | LongDoubleAlign = 128; | 
|---|
| 57 | LongDoubleFormat = &llvm::APFloat::IEEEquad(); | 
|---|
| 58 | MCountName = "_mcount"; | 
|---|
| 59 | HasFloat16 = true; | 
|---|
| 60 | SuitableAlign = 128; | 
|---|
| 61 | WCharType = SignedInt; | 
|---|
| 62 | WIntType = UnsignedInt; | 
|---|
| 63 | BitIntMaxAlign = 128; | 
|---|
| 64 | } | 
|---|
| 65 |  | 
|---|
| 66 | bool setCPU(const std::string &Name) override { | 
|---|
| 67 | if (!isValidCPUName(Name)) | 
|---|
| 68 | return false; | 
|---|
| 69 | CPU = Name; | 
|---|
| 70 | return true; | 
|---|
| 71 | } | 
|---|
| 72 |  | 
|---|
| 73 | StringRef getCPU() const { return CPU; } | 
|---|
| 74 |  | 
|---|
| 75 | StringRef getABI() const override { return ABI; } | 
|---|
| 76 |  | 
|---|
| 77 | void getTargetDefines(const LangOptions &Opts, | 
|---|
| 78 | MacroBuilder &Builder) const override; | 
|---|
| 79 |  | 
|---|
| 80 | llvm::SmallVector<Builtin::InfosShard> getTargetBuiltins() const override; | 
|---|
| 81 |  | 
|---|
| 82 | BuiltinVaListKind getBuiltinVaListKind() const override { | 
|---|
| 83 | return TargetInfo::VoidPtrBuiltinVaList; | 
|---|
| 84 | } | 
|---|
| 85 |  | 
|---|
| 86 | std::string_view getClobbers() const override { return ""; } | 
|---|
| 87 |  | 
|---|
| 88 | ArrayRef<const char *> getGCCRegNames() const override; | 
|---|
| 89 |  | 
|---|
| 90 | int getEHDataRegisterNumber(unsigned RegNo) const override { | 
|---|
| 91 | if (RegNo == 0) | 
|---|
| 92 | return 4; | 
|---|
| 93 | if (RegNo == 1) | 
|---|
| 94 | return 5; | 
|---|
| 95 | return -1; | 
|---|
| 96 | } | 
|---|
| 97 |  | 
|---|
| 98 | ArrayRef<TargetInfo::GCCRegAlias> getGCCRegAliases() const override; | 
|---|
| 99 |  | 
|---|
| 100 | bool validateAsmConstraint(const char *&Name, | 
|---|
| 101 | TargetInfo::ConstraintInfo &Info) const override; | 
|---|
| 102 | std::string convertConstraint(const char *&Constraint) const override; | 
|---|
| 103 |  | 
|---|
| 104 | bool hasBitIntType() const override { return true; } | 
|---|
| 105 |  | 
|---|
| 106 | bool hasBFloat16Type() const override { return true; } | 
|---|
| 107 |  | 
|---|
| 108 | bool useFP16ConversionIntrinsics() const override { return false; } | 
|---|
| 109 |  | 
|---|
| 110 | bool handleTargetFeatures(std::vector<std::string> &Features, | 
|---|
| 111 | DiagnosticsEngine &Diags) override; | 
|---|
| 112 |  | 
|---|
| 113 | ParsedTargetAttr parseTargetAttr(StringRef Str) const override; | 
|---|
| 114 | bool supportsTargetAttributeTune() const override { return true; } | 
|---|
| 115 |  | 
|---|
| 116 | bool | 
|---|
| 117 | initFeatureMap(llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags, | 
|---|
| 118 | StringRef CPU, | 
|---|
| 119 | const std::vector<std::string> &FeaturesVec) const override; | 
|---|
| 120 |  | 
|---|
| 121 | bool hasFeature(StringRef Feature) const override; | 
|---|
| 122 |  | 
|---|
| 123 | bool isValidCPUName(StringRef Name) const override; | 
|---|
| 124 | void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const override; | 
|---|
| 125 | bool isValidFeatureName(StringRef Name) const override; | 
|---|
| 126 | }; | 
|---|
| 127 |  | 
|---|
| 128 | class LLVM_LIBRARY_VISIBILITY LoongArch32TargetInfo | 
|---|
| 129 | : public LoongArchTargetInfo { | 
|---|
| 130 | public: | 
|---|
| 131 | LoongArch32TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts) | 
|---|
| 132 | : LoongArchTargetInfo(Triple, Opts) { | 
|---|
| 133 | IntPtrType = SignedInt; | 
|---|
| 134 | PtrDiffType = SignedInt; | 
|---|
| 135 | SizeType = UnsignedInt; | 
|---|
| 136 | resetDataLayout(DL: "e-m:e-p:32:32-i64:64-n32-S128"); | 
|---|
| 137 | // TODO: select appropriate ABI. | 
|---|
| 138 | setABI( "ilp32d"); | 
|---|
| 139 | } | 
|---|
| 140 |  | 
|---|
| 141 | bool setABI(const std::string &Name) override { | 
|---|
| 142 | if (Name == "ilp32d"|| Name == "ilp32f"|| Name == "ilp32s") { | 
|---|
| 143 | ABI = Name; | 
|---|
| 144 | return true; | 
|---|
| 145 | } | 
|---|
| 146 | return false; | 
|---|
| 147 | } | 
|---|
| 148 | void setMaxAtomicWidth() override { | 
|---|
| 149 | MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 32; | 
|---|
| 150 | } | 
|---|
| 151 | }; | 
|---|
| 152 |  | 
|---|
| 153 | class LLVM_LIBRARY_VISIBILITY LoongArch64TargetInfo | 
|---|
| 154 | : public LoongArchTargetInfo { | 
|---|
| 155 | public: | 
|---|
| 156 | LoongArch64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts) | 
|---|
| 157 | : LoongArchTargetInfo(Triple, Opts) { | 
|---|
| 158 | LongWidth = LongAlign = PointerWidth = PointerAlign = 64; | 
|---|
| 159 | IntMaxType = Int64Type = SignedLong; | 
|---|
| 160 | HasUnalignedAccess = true; | 
|---|
| 161 | resetDataLayout(DL: "e-m:e-p:64:64-i64:64-i128:128-n32:64-S128"); | 
|---|
| 162 | // TODO: select appropriate ABI. | 
|---|
| 163 | setABI( "lp64d"); | 
|---|
| 164 | } | 
|---|
| 165 |  | 
|---|
| 166 | bool setABI(const std::string &Name) override { | 
|---|
| 167 | if (Name == "lp64d"|| Name == "lp64f"|| Name == "lp64s") { | 
|---|
| 168 | ABI = Name; | 
|---|
| 169 | return true; | 
|---|
| 170 | } | 
|---|
| 171 | return false; | 
|---|
| 172 | } | 
|---|
| 173 | void setMaxAtomicWidth() override { | 
|---|
| 174 | MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 64; | 
|---|
| 175 | } | 
|---|
| 176 | }; | 
|---|
| 177 | } // end namespace targets | 
|---|
| 178 | } // end namespace clang | 
|---|
| 179 |  | 
|---|
| 180 | #endif // LLVM_CLANG_LIB_BASIC_TARGETS_LOONGARCH_H | 
|---|
| 181 |  | 
|---|