1 //===--- RISCV.h - Declare RISCV 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 RISCV TargetInfo objects.
11 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_CLANG_LIB_BASIC_TARGETS_RISCV_H
14 #define LLVM_CLANG_LIB_BASIC_TARGETS_RISCV_H
16 #include "clang/Basic/TargetInfo.h"
17 #include "clang/Basic/TargetOptions.h"
18 #include "llvm/ADT/Triple.h"
19 #include "llvm/Support/Compiler.h"
20 #include "llvm/Support/RISCVISAInfo.h"
26 class RISCVTargetInfo
: public TargetInfo
{
29 std::unique_ptr
<llvm::RISCVISAInfo
> ISAInfo
;
30 static const Builtin::Info BuiltinInfo
[];
33 RISCVTargetInfo(const llvm::Triple
&Triple
, const TargetOptions
&)
34 : TargetInfo(Triple
) {
35 LongDoubleWidth
= 128;
36 LongDoubleAlign
= 128;
37 LongDoubleFormat
= &llvm::APFloat::IEEEquad();
39 WCharType
= SignedInt
;
40 WIntType
= UnsignedInt
;
41 HasRISCVVTypes
= true;
42 MCountName
= "_mcount";
46 bool setCPU(const std::string
&Name
) override
{
47 if (!isValidCPUName(Name
))
53 StringRef
getABI() const override
{ return ABI
; }
54 void getTargetDefines(const LangOptions
&Opts
,
55 MacroBuilder
&Builder
) const override
;
57 ArrayRef
<Builtin::Info
> getTargetBuiltins() const override
;
59 BuiltinVaListKind
getBuiltinVaListKind() const override
{
60 return TargetInfo::VoidPtrBuiltinVaList
;
63 const char *getClobbers() const override
{ return ""; }
65 StringRef
getConstraintRegister(StringRef Constraint
,
66 StringRef Expression
) const override
{
70 ArrayRef
<const char *> getGCCRegNames() const override
;
72 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
;
86 std::string
convertConstraint(const char *&Constraint
) const override
;
89 initFeatureMap(llvm::StringMap
<bool> &Features
, DiagnosticsEngine
&Diags
,
91 const std::vector
<std::string
> &FeaturesVec
) const override
;
93 bool hasFeature(StringRef Feature
) const override
;
95 bool handleTargetFeatures(std::vector
<std::string
> &Features
,
96 DiagnosticsEngine
&Diags
) override
;
98 bool hasBitIntType() const override
{ return true; }
100 bool useFP16ConversionIntrinsics() const override
{
104 bool isValidCPUName(StringRef Name
) const override
;
105 void fillValidCPUList(SmallVectorImpl
<StringRef
> &Values
) const override
;
106 bool isValidTuneCPUName(StringRef Name
) const override
;
107 void fillValidTuneCPUList(SmallVectorImpl
<StringRef
> &Values
) const override
;
109 class LLVM_LIBRARY_VISIBILITY RISCV32TargetInfo
: public RISCVTargetInfo
{
111 RISCV32TargetInfo(const llvm::Triple
&Triple
, const TargetOptions
&Opts
)
112 : RISCVTargetInfo(Triple
, Opts
) {
113 IntPtrType
= SignedInt
;
114 PtrDiffType
= SignedInt
;
115 SizeType
= UnsignedInt
;
116 resetDataLayout("e-m:e-p:32:32-i64:64-n32-S128");
119 bool setABI(const std::string
&Name
) override
{
120 if (Name
== "ilp32" || Name
== "ilp32f" || Name
== "ilp32d") {
127 void setMaxAtomicWidth() override
{
128 MaxAtomicPromoteWidth
= 128;
130 if (ISAInfo
->hasExtension("a"))
131 MaxAtomicInlineWidth
= 32;
134 class LLVM_LIBRARY_VISIBILITY RISCV64TargetInfo
: public RISCVTargetInfo
{
136 RISCV64TargetInfo(const llvm::Triple
&Triple
, const TargetOptions
&Opts
)
137 : RISCVTargetInfo(Triple
, Opts
) {
138 LongWidth
= LongAlign
= PointerWidth
= PointerAlign
= 64;
139 IntMaxType
= Int64Type
= SignedLong
;
140 resetDataLayout("e-m:e-p:64:64-i64:64-i128:128-n64-S128");
143 bool setABI(const std::string
&Name
) override
{
144 if (Name
== "lp64" || Name
== "lp64f" || Name
== "lp64d") {
151 void setMaxAtomicWidth() override
{
152 MaxAtomicPromoteWidth
= 128;
154 if (ISAInfo
->hasExtension("a"))
155 MaxAtomicInlineWidth
= 64;
158 } // namespace targets
161 #endif // LLVM_CLANG_LIB_BASIC_TARGETS_RISCV_H