1bdd1243dSDimitry Andric //===-- LoongArch.h - Declare LoongArch target feature support --*- C++ -*-===// 2bdd1243dSDimitry Andric // 3bdd1243dSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4bdd1243dSDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 5bdd1243dSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6bdd1243dSDimitry Andric // 7bdd1243dSDimitry Andric //===----------------------------------------------------------------------===// 8bdd1243dSDimitry Andric // 9bdd1243dSDimitry Andric // This file declares LoongArch TargetInfo objects. 10bdd1243dSDimitry Andric // 11bdd1243dSDimitry Andric //===----------------------------------------------------------------------===// 12bdd1243dSDimitry Andric 13bdd1243dSDimitry Andric #ifndef LLVM_CLANG_LIB_BASIC_TARGETS_LOONGARCH_H 14bdd1243dSDimitry Andric #define LLVM_CLANG_LIB_BASIC_TARGETS_LOONGARCH_H 15bdd1243dSDimitry Andric 16bdd1243dSDimitry Andric #include "clang/Basic/TargetInfo.h" 17bdd1243dSDimitry Andric #include "clang/Basic/TargetOptions.h" 18bdd1243dSDimitry Andric #include "llvm/Support/Compiler.h" 1906c3fb27SDimitry Andric #include "llvm/TargetParser/Triple.h" 20bdd1243dSDimitry Andric 21bdd1243dSDimitry Andric namespace clang { 22bdd1243dSDimitry Andric namespace targets { 23bdd1243dSDimitry Andric 24bdd1243dSDimitry Andric class LLVM_LIBRARY_VISIBILITY LoongArchTargetInfo : public TargetInfo { 25bdd1243dSDimitry Andric protected: 26bdd1243dSDimitry Andric std::string ABI; 278a4dda33SDimitry Andric std::string CPU; 28bdd1243dSDimitry Andric bool HasFeatureD; 29bdd1243dSDimitry Andric bool HasFeatureF; 305f757f3fSDimitry Andric bool HasFeatureLSX; 315f757f3fSDimitry Andric bool HasFeatureLASX; 32*0fca6ea1SDimitry Andric bool HasFeatureFrecipe; 33bdd1243dSDimitry Andric 34bdd1243dSDimitry Andric public: LoongArchTargetInfo(const llvm::Triple & Triple,const TargetOptions &)35bdd1243dSDimitry Andric LoongArchTargetInfo(const llvm::Triple &Triple, const TargetOptions &) 36bdd1243dSDimitry Andric : TargetInfo(Triple) { 37bdd1243dSDimitry Andric HasFeatureD = false; 38bdd1243dSDimitry Andric HasFeatureF = false; 395f757f3fSDimitry Andric HasFeatureLSX = false; 405f757f3fSDimitry Andric HasFeatureLASX = false; 41*0fca6ea1SDimitry Andric HasFeatureFrecipe = false; 42bdd1243dSDimitry Andric LongDoubleWidth = 128; 43bdd1243dSDimitry Andric LongDoubleAlign = 128; 44bdd1243dSDimitry Andric LongDoubleFormat = &llvm::APFloat::IEEEquad(); 455f757f3fSDimitry Andric MCountName = "_mcount"; 46bdd1243dSDimitry Andric SuitableAlign = 128; 47bdd1243dSDimitry Andric WCharType = SignedInt; 48bdd1243dSDimitry Andric WIntType = UnsignedInt; 49bdd1243dSDimitry Andric } 50bdd1243dSDimitry Andric setCPU(const std::string & Name)518a4dda33SDimitry Andric bool setCPU(const std::string &Name) override { 528a4dda33SDimitry Andric if (!isValidCPUName(Name)) 538a4dda33SDimitry Andric return false; 548a4dda33SDimitry Andric CPU = Name; 558a4dda33SDimitry Andric return true; 568a4dda33SDimitry Andric } 578a4dda33SDimitry Andric getCPU()588a4dda33SDimitry Andric StringRef getCPU() const { return CPU; } 598a4dda33SDimitry Andric getABI()60bdd1243dSDimitry Andric StringRef getABI() const override { return ABI; } 61bdd1243dSDimitry Andric 62bdd1243dSDimitry Andric void getTargetDefines(const LangOptions &Opts, 63bdd1243dSDimitry Andric MacroBuilder &Builder) const override; 64bdd1243dSDimitry Andric 65bdd1243dSDimitry Andric ArrayRef<Builtin::Info> getTargetBuiltins() const override; 66bdd1243dSDimitry Andric getBuiltinVaListKind()67bdd1243dSDimitry Andric BuiltinVaListKind getBuiltinVaListKind() const override { 68bdd1243dSDimitry Andric return TargetInfo::VoidPtrBuiltinVaList; 69bdd1243dSDimitry Andric } 70bdd1243dSDimitry Andric getClobbers()7106c3fb27SDimitry Andric std::string_view getClobbers() const override { return ""; } 72bdd1243dSDimitry Andric 73bdd1243dSDimitry Andric ArrayRef<const char *> getGCCRegNames() const override; 74bdd1243dSDimitry Andric getEHDataRegisterNumber(unsigned RegNo)75bdd1243dSDimitry Andric int getEHDataRegisterNumber(unsigned RegNo) const override { 76bdd1243dSDimitry Andric if (RegNo == 0) 77bdd1243dSDimitry Andric return 4; 78bdd1243dSDimitry Andric if (RegNo == 1) 79bdd1243dSDimitry Andric return 5; 80bdd1243dSDimitry Andric return -1; 81bdd1243dSDimitry Andric } 82bdd1243dSDimitry Andric 83bdd1243dSDimitry Andric ArrayRef<TargetInfo::GCCRegAlias> getGCCRegAliases() const override; 84bdd1243dSDimitry Andric 85bdd1243dSDimitry Andric bool validateAsmConstraint(const char *&Name, 86bdd1243dSDimitry Andric TargetInfo::ConstraintInfo &Info) const override; 87bdd1243dSDimitry Andric std::string convertConstraint(const char *&Constraint) const override; 88bdd1243dSDimitry Andric hasBitIntType()89bdd1243dSDimitry Andric bool hasBitIntType() const override { return true; } 90bdd1243dSDimitry Andric 91bdd1243dSDimitry Andric bool handleTargetFeatures(std::vector<std::string> &Features, 92bdd1243dSDimitry Andric DiagnosticsEngine &Diags) override; 93bdd1243dSDimitry Andric 94bdd1243dSDimitry Andric bool 95bdd1243dSDimitry Andric initFeatureMap(llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags, 96bdd1243dSDimitry Andric StringRef CPU, 97bdd1243dSDimitry Andric const std::vector<std::string> &FeaturesVec) const override; 98bdd1243dSDimitry Andric 99bdd1243dSDimitry Andric bool hasFeature(StringRef Feature) const override; 1008a4dda33SDimitry Andric 1018a4dda33SDimitry Andric bool isValidCPUName(StringRef Name) const override; 1028a4dda33SDimitry Andric void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const override; 103bdd1243dSDimitry Andric }; 104bdd1243dSDimitry Andric 105bdd1243dSDimitry Andric class LLVM_LIBRARY_VISIBILITY LoongArch32TargetInfo 106bdd1243dSDimitry Andric : public LoongArchTargetInfo { 107bdd1243dSDimitry Andric public: LoongArch32TargetInfo(const llvm::Triple & Triple,const TargetOptions & Opts)108bdd1243dSDimitry Andric LoongArch32TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts) 109bdd1243dSDimitry Andric : LoongArchTargetInfo(Triple, Opts) { 110bdd1243dSDimitry Andric IntPtrType = SignedInt; 111bdd1243dSDimitry Andric PtrDiffType = SignedInt; 112bdd1243dSDimitry Andric SizeType = UnsignedInt; 113bdd1243dSDimitry Andric resetDataLayout("e-m:e-p:32:32-i64:64-n32-S128"); 114bdd1243dSDimitry Andric // TODO: select appropriate ABI. 115bdd1243dSDimitry Andric setABI("ilp32d"); 116bdd1243dSDimitry Andric } 117bdd1243dSDimitry Andric setABI(const std::string & Name)118bdd1243dSDimitry Andric bool setABI(const std::string &Name) override { 119bdd1243dSDimitry Andric if (Name == "ilp32d" || Name == "ilp32f" || Name == "ilp32s") { 120bdd1243dSDimitry Andric ABI = Name; 121bdd1243dSDimitry Andric return true; 122bdd1243dSDimitry Andric } 123bdd1243dSDimitry Andric return false; 124bdd1243dSDimitry Andric } setMaxAtomicWidth()125bdd1243dSDimitry Andric void setMaxAtomicWidth() override { 126bdd1243dSDimitry Andric MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 32; 127bdd1243dSDimitry Andric } 128bdd1243dSDimitry Andric }; 129bdd1243dSDimitry Andric 130bdd1243dSDimitry Andric class LLVM_LIBRARY_VISIBILITY LoongArch64TargetInfo 131bdd1243dSDimitry Andric : public LoongArchTargetInfo { 132bdd1243dSDimitry Andric public: LoongArch64TargetInfo(const llvm::Triple & Triple,const TargetOptions & Opts)133bdd1243dSDimitry Andric LoongArch64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts) 134bdd1243dSDimitry Andric : LoongArchTargetInfo(Triple, Opts) { 135bdd1243dSDimitry Andric LongWidth = LongAlign = PointerWidth = PointerAlign = 64; 136bdd1243dSDimitry Andric IntMaxType = Int64Type = SignedLong; 137*0fca6ea1SDimitry Andric HasUnalignedAccess = true; 138*0fca6ea1SDimitry Andric resetDataLayout("e-m:e-p:64:64-i64:64-i128:128-n32:64-S128"); 139bdd1243dSDimitry Andric // TODO: select appropriate ABI. 140bdd1243dSDimitry Andric setABI("lp64d"); 141bdd1243dSDimitry Andric } 142bdd1243dSDimitry Andric setABI(const std::string & Name)143bdd1243dSDimitry Andric bool setABI(const std::string &Name) override { 144bdd1243dSDimitry Andric if (Name == "lp64d" || Name == "lp64f" || Name == "lp64s") { 145bdd1243dSDimitry Andric ABI = Name; 146bdd1243dSDimitry Andric return true; 147bdd1243dSDimitry Andric } 148bdd1243dSDimitry Andric return false; 149bdd1243dSDimitry Andric } setMaxAtomicWidth()150bdd1243dSDimitry Andric void setMaxAtomicWidth() override { 151bdd1243dSDimitry Andric MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 64; 152bdd1243dSDimitry Andric } 153bdd1243dSDimitry Andric }; 154bdd1243dSDimitry Andric } // end namespace targets 155bdd1243dSDimitry Andric } // end namespace clang 156bdd1243dSDimitry Andric 157bdd1243dSDimitry Andric #endif // LLVM_CLANG_LIB_BASIC_TARGETS_LOONGARCH_H 158