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
{
31 LoongArchTargetInfo(const llvm::Triple
&Triple
, const TargetOptions
&)
32 : TargetInfo(Triple
) {
35 LongDoubleWidth
= 128;
36 LongDoubleAlign
= 128;
37 LongDoubleFormat
= &llvm::APFloat::IEEEquad();
39 WCharType
= SignedInt
;
40 WIntType
= UnsignedInt
;
43 StringRef
getABI() const override
{ return ABI
; }
45 void getTargetDefines(const LangOptions
&Opts
,
46 MacroBuilder
&Builder
) const override
;
48 ArrayRef
<Builtin::Info
> getTargetBuiltins() const override
;
50 BuiltinVaListKind
getBuiltinVaListKind() const override
{
51 return TargetInfo::VoidPtrBuiltinVaList
;
54 std::string_view
getClobbers() const override
{ return ""; }
56 ArrayRef
<const char *> getGCCRegNames() const override
;
58 int getEHDataRegisterNumber(unsigned RegNo
) const override
{
66 ArrayRef
<TargetInfo::GCCRegAlias
> getGCCRegAliases() const override
;
68 bool validateAsmConstraint(const char *&Name
,
69 TargetInfo::ConstraintInfo
&Info
) const override
;
70 std::string
convertConstraint(const char *&Constraint
) const override
;
72 bool hasBitIntType() const override
{ return true; }
74 bool handleTargetFeatures(std::vector
<std::string
> &Features
,
75 DiagnosticsEngine
&Diags
) override
;
78 initFeatureMap(llvm::StringMap
<bool> &Features
, DiagnosticsEngine
&Diags
,
80 const std::vector
<std::string
> &FeaturesVec
) const override
;
82 bool hasFeature(StringRef Feature
) const override
;
85 class LLVM_LIBRARY_VISIBILITY LoongArch32TargetInfo
86 : public LoongArchTargetInfo
{
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.
98 bool setABI(const std::string
&Name
) override
{
99 if (Name
== "ilp32d" || Name
== "ilp32f" || Name
== "ilp32s") {
105 void setMaxAtomicWidth() override
{
106 MaxAtomicPromoteWidth
= MaxAtomicInlineWidth
= 32;
110 class LLVM_LIBRARY_VISIBILITY LoongArch64TargetInfo
111 : public LoongArchTargetInfo
{
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.
122 bool setABI(const std::string
&Name
) override
{
123 if (Name
== "lp64d" || Name
== "lp64f" || Name
== "lp64s") {
129 void setMaxAtomicWidth() override
{
130 MaxAtomicPromoteWidth
= MaxAtomicInlineWidth
= 64;
133 } // end namespace targets
134 } // end namespace clang
136 #endif // LLVM_CLANG_LIB_BASIC_TARGETS_LOONGARCH_H