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
{
34 LoongArchTargetInfo(const llvm::Triple
&Triple
, const TargetOptions
&)
35 : TargetInfo(Triple
) {
38 HasFeatureLSX
= false;
39 HasFeatureLASX
= false;
40 LongDoubleWidth
= 128;
41 LongDoubleAlign
= 128;
42 LongDoubleFormat
= &llvm::APFloat::IEEEquad();
43 MCountName
= "_mcount";
45 WCharType
= SignedInt
;
46 WIntType
= UnsignedInt
;
49 bool setCPU(const std::string
&Name
) override
{
50 if (!isValidCPUName(Name
))
56 StringRef
getCPU() const { return CPU
; }
58 StringRef
getABI() const override
{ return ABI
; }
60 void getTargetDefines(const LangOptions
&Opts
,
61 MacroBuilder
&Builder
) const override
;
63 ArrayRef
<Builtin::Info
> getTargetBuiltins() const override
;
65 BuiltinVaListKind
getBuiltinVaListKind() const override
{
66 return TargetInfo::VoidPtrBuiltinVaList
;
69 std::string_view
getClobbers() const override
{ return ""; }
71 ArrayRef
<const char *> getGCCRegNames() const override
;
73 int getEHDataRegisterNumber(unsigned RegNo
) const override
{
81 ArrayRef
<TargetInfo::GCCRegAlias
> getGCCRegAliases() const override
;
83 bool validateAsmConstraint(const char *&Name
,
84 TargetInfo::ConstraintInfo
&Info
) const override
;
85 std::string
convertConstraint(const char *&Constraint
) const override
;
87 bool hasBitIntType() const override
{ return true; }
89 bool handleTargetFeatures(std::vector
<std::string
> &Features
,
90 DiagnosticsEngine
&Diags
) override
;
93 initFeatureMap(llvm::StringMap
<bool> &Features
, DiagnosticsEngine
&Diags
,
95 const std::vector
<std::string
> &FeaturesVec
) const override
;
97 bool hasFeature(StringRef Feature
) const override
;
99 bool isValidCPUName(StringRef Name
) const override
;
100 void fillValidCPUList(SmallVectorImpl
<StringRef
> &Values
) const override
;
103 class LLVM_LIBRARY_VISIBILITY LoongArch32TargetInfo
104 : public LoongArchTargetInfo
{
106 LoongArch32TargetInfo(const llvm::Triple
&Triple
, const TargetOptions
&Opts
)
107 : LoongArchTargetInfo(Triple
, Opts
) {
108 IntPtrType
= SignedInt
;
109 PtrDiffType
= SignedInt
;
110 SizeType
= UnsignedInt
;
111 resetDataLayout("e-m:e-p:32:32-i64:64-n32-S128");
112 // TODO: select appropriate ABI.
116 bool setABI(const std::string
&Name
) override
{
117 if (Name
== "ilp32d" || Name
== "ilp32f" || Name
== "ilp32s") {
123 void setMaxAtomicWidth() override
{
124 MaxAtomicPromoteWidth
= MaxAtomicInlineWidth
= 32;
128 class LLVM_LIBRARY_VISIBILITY LoongArch64TargetInfo
129 : public LoongArchTargetInfo
{
131 LoongArch64TargetInfo(const llvm::Triple
&Triple
, const TargetOptions
&Opts
)
132 : LoongArchTargetInfo(Triple
, Opts
) {
133 LongWidth
= LongAlign
= PointerWidth
= PointerAlign
= 64;
134 IntMaxType
= Int64Type
= SignedLong
;
135 resetDataLayout("e-m:e-p:64:64-i64:64-i128:128-n64-S128");
136 // TODO: select appropriate ABI.
140 bool setABI(const std::string
&Name
) override
{
141 if (Name
== "lp64d" || Name
== "lp64f" || Name
== "lp64s") {
147 void setMaxAtomicWidth() override
{
148 MaxAtomicPromoteWidth
= MaxAtomicInlineWidth
= 64;
151 } // end namespace targets
152 } // end namespace clang
154 #endif // LLVM_CLANG_LIB_BASIC_TARGETS_LOONGARCH_H