1 //===-- LoongArch.h - Declare LoongArch target feature support --*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 // This file declares LoongArch TargetInfo objects.
11 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_CLANG_LIB_BASIC_TARGETS_LOONGARCH_H
14 #define LLVM_CLANG_LIB_BASIC_TARGETS_LOONGARCH_H
16 #include "clang/Basic/TargetInfo.h"
17 #include "clang/Basic/TargetOptions.h"
18 #include "llvm/Support/Compiler.h"
19 #include "llvm/TargetParser/Triple.h"
24 class LLVM_LIBRARY_VISIBILITY LoongArchTargetInfo
: public TargetInfo
{
32 bool HasFeatureFrecipe
;
33 bool HasFeatureLAM_BH
;
34 bool HasFeatureLAMCAS
;
35 bool HasFeatureLD_SEQ_SA
;
39 LoongArchTargetInfo(const llvm::Triple
&Triple
, const TargetOptions
&)
40 : TargetInfo(Triple
) {
43 HasFeatureLSX
= false;
44 HasFeatureLASX
= false;
45 HasFeatureFrecipe
= false;
46 HasFeatureLAM_BH
= false;
47 HasFeatureLAMCAS
= false;
48 HasFeatureLD_SEQ_SA
= false;
49 HasFeatureDiv32
= false;
50 LongDoubleWidth
= 128;
51 LongDoubleAlign
= 128;
52 LongDoubleFormat
= &llvm::APFloat::IEEEquad();
53 MCountName
= "_mcount";
55 WCharType
= SignedInt
;
56 WIntType
= UnsignedInt
;
59 bool setCPU(const std::string
&Name
) override
{
60 if (!isValidCPUName(Name
))
66 StringRef
getCPU() const { return CPU
; }
68 StringRef
getABI() const override
{ return ABI
; }
70 void getTargetDefines(const LangOptions
&Opts
,
71 MacroBuilder
&Builder
) const override
;
73 ArrayRef
<Builtin::Info
> getTargetBuiltins() const override
;
75 BuiltinVaListKind
getBuiltinVaListKind() const override
{
76 return TargetInfo::VoidPtrBuiltinVaList
;
79 std::string_view
getClobbers() const override
{ return ""; }
81 ArrayRef
<const char *> getGCCRegNames() const override
;
83 int getEHDataRegisterNumber(unsigned RegNo
) const override
{
91 ArrayRef
<TargetInfo::GCCRegAlias
> getGCCRegAliases() const override
;
93 bool validateAsmConstraint(const char *&Name
,
94 TargetInfo::ConstraintInfo
&Info
) const override
;
95 std::string
convertConstraint(const char *&Constraint
) const override
;
97 bool hasBitIntType() const override
{ return true; }
99 bool handleTargetFeatures(std::vector
<std::string
> &Features
,
100 DiagnosticsEngine
&Diags
) override
;
103 initFeatureMap(llvm::StringMap
<bool> &Features
, DiagnosticsEngine
&Diags
,
105 const std::vector
<std::string
> &FeaturesVec
) const override
;
107 bool hasFeature(StringRef Feature
) const override
;
109 bool isValidCPUName(StringRef Name
) const override
;
110 void fillValidCPUList(SmallVectorImpl
<StringRef
> &Values
) const override
;
113 class LLVM_LIBRARY_VISIBILITY LoongArch32TargetInfo
114 : public LoongArchTargetInfo
{
116 LoongArch32TargetInfo(const llvm::Triple
&Triple
, const TargetOptions
&Opts
)
117 : LoongArchTargetInfo(Triple
, Opts
) {
118 IntPtrType
= SignedInt
;
119 PtrDiffType
= SignedInt
;
120 SizeType
= UnsignedInt
;
121 resetDataLayout("e-m:e-p:32:32-i64:64-n32-S128");
122 // TODO: select appropriate ABI.
126 bool setABI(const std::string
&Name
) override
{
127 if (Name
== "ilp32d" || Name
== "ilp32f" || Name
== "ilp32s") {
133 void setMaxAtomicWidth() override
{
134 MaxAtomicPromoteWidth
= MaxAtomicInlineWidth
= 32;
138 class LLVM_LIBRARY_VISIBILITY LoongArch64TargetInfo
139 : public LoongArchTargetInfo
{
141 LoongArch64TargetInfo(const llvm::Triple
&Triple
, const TargetOptions
&Opts
)
142 : LoongArchTargetInfo(Triple
, Opts
) {
143 LongWidth
= LongAlign
= PointerWidth
= PointerAlign
= 64;
144 IntMaxType
= Int64Type
= SignedLong
;
145 HasUnalignedAccess
= true;
146 resetDataLayout("e-m:e-p:64:64-i64:64-i128:128-n32:64-S128");
147 // TODO: select appropriate ABI.
151 bool setABI(const std::string
&Name
) override
{
152 if (Name
== "lp64d" || Name
== "lp64f" || Name
== "lp64s") {
158 void setMaxAtomicWidth() override
{
159 MaxAtomicPromoteWidth
= MaxAtomicInlineWidth
= 64;
162 } // end namespace targets
163 } // end namespace clang
165 #endif // LLVM_CLANG_LIB_BASIC_TARGETS_LOONGARCH_H