1 //===--- RISCV.h - Declare RISC-V 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 RISC-V 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/Support/Compiler.h"
19 #include "llvm/Support/RISCVISAInfo.h"
20 #include "llvm/TargetParser/Triple.h"
27 class RISCVTargetInfo
: public TargetInfo
{
30 std::unique_ptr
<llvm::RISCVISAInfo
> ISAInfo
;
33 bool FastUnalignedAccess
;
36 RISCVTargetInfo(const llvm::Triple
&Triple
, const TargetOptions
&)
37 : TargetInfo(Triple
) {
40 BFloat16Format
= &llvm::APFloat::BFloat();
41 LongDoubleWidth
= 128;
42 LongDoubleAlign
= 128;
43 LongDoubleFormat
= &llvm::APFloat::IEEEquad();
45 WCharType
= SignedInt
;
46 WIntType
= UnsignedInt
;
47 HasRISCVVTypes
= true;
48 MCountName
= "_mcount";
53 bool setCPU(const std::string
&Name
) override
{
54 if (!isValidCPUName(Name
))
60 StringRef
getABI() const override
{ return ABI
; }
61 void getTargetDefines(const LangOptions
&Opts
,
62 MacroBuilder
&Builder
) const override
;
64 ArrayRef
<Builtin::Info
> getTargetBuiltins() const override
;
66 BuiltinVaListKind
getBuiltinVaListKind() const override
{
67 return TargetInfo::VoidPtrBuiltinVaList
;
70 std::string_view
getClobbers() const override
{ return ""; }
72 StringRef
getConstraintRegister(StringRef Constraint
,
73 StringRef Expression
) const override
{
77 ArrayRef
<const char *> getGCCRegNames() const override
;
79 int getEHDataRegisterNumber(unsigned RegNo
) const override
{
88 ArrayRef
<TargetInfo::GCCRegAlias
> getGCCRegAliases() const override
;
90 bool validateAsmConstraint(const char *&Name
,
91 TargetInfo::ConstraintInfo
&Info
) const override
;
93 std::string
convertConstraint(const char *&Constraint
) const override
;
96 initFeatureMap(llvm::StringMap
<bool> &Features
, DiagnosticsEngine
&Diags
,
98 const std::vector
<std::string
> &FeaturesVec
) const override
;
100 std::optional
<std::pair
<unsigned, unsigned>>
101 getVScaleRange(const LangOptions
&LangOpts
) const override
;
103 bool hasFeature(StringRef Feature
) const override
;
105 bool handleTargetFeatures(std::vector
<std::string
> &Features
,
106 DiagnosticsEngine
&Diags
) override
;
108 bool hasBitIntType() const override
{ return true; }
110 bool hasBFloat16Type() const override
{ return true; }
112 bool useFP16ConversionIntrinsics() const override
{
116 bool isValidCPUName(StringRef Name
) const override
;
117 void fillValidCPUList(SmallVectorImpl
<StringRef
> &Values
) const override
;
118 bool isValidTuneCPUName(StringRef Name
) const override
;
119 void fillValidTuneCPUList(SmallVectorImpl
<StringRef
> &Values
) const override
;
121 class LLVM_LIBRARY_VISIBILITY RISCV32TargetInfo
: public RISCVTargetInfo
{
123 RISCV32TargetInfo(const llvm::Triple
&Triple
, const TargetOptions
&Opts
)
124 : RISCVTargetInfo(Triple
, Opts
) {
125 IntPtrType
= SignedInt
;
126 PtrDiffType
= SignedInt
;
127 SizeType
= UnsignedInt
;
128 resetDataLayout("e-m:e-p:32:32-i64:64-n32-S128");
131 bool setABI(const std::string
&Name
) override
{
132 if (Name
== "ilp32" || Name
== "ilp32f" || Name
== "ilp32d") {
139 void setMaxAtomicWidth() override
{
140 MaxAtomicPromoteWidth
= 128;
142 if (ISAInfo
->hasExtension("a"))
143 MaxAtomicInlineWidth
= 32;
146 class LLVM_LIBRARY_VISIBILITY RISCV64TargetInfo
: public RISCVTargetInfo
{
148 RISCV64TargetInfo(const llvm::Triple
&Triple
, const TargetOptions
&Opts
)
149 : RISCVTargetInfo(Triple
, Opts
) {
150 LongWidth
= LongAlign
= PointerWidth
= PointerAlign
= 64;
151 IntMaxType
= Int64Type
= SignedLong
;
152 resetDataLayout("e-m:e-p:64:64-i64:64-i128:128-n32:64-S128");
155 bool setABI(const std::string
&Name
) override
{
156 if (Name
== "lp64" || Name
== "lp64f" || Name
== "lp64d") {
163 void setMaxAtomicWidth() override
{
164 MaxAtomicPromoteWidth
= 128;
166 if (ISAInfo
->hasExtension("a"))
167 MaxAtomicInlineWidth
= 64;
170 } // namespace targets
173 #endif // LLVM_CLANG_LIB_BASIC_TARGETS_RISCV_H