blob: 6db526da4c59fc5bd7ad87bd9c8bfe9f75acda3e [file] [log] [blame]
Alex Bradbury71f45452018-01-11 13:36:56 +00001//===--- RISCV.h - Declare RISCV target feature support ---------*- C++ -*-===//
2//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// 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
Alex Bradbury71f45452018-01-11 13:36:56 +00006//
7//===----------------------------------------------------------------------===//
8//
9// This file declares RISCV TargetInfo objects.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_CLANG_LIB_BASIC_TARGETS_RISCV_H
14#define LLVM_CLANG_LIB_BASIC_TARGETS_RISCV_H
15
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
21namespace clang {
22namespace targets {
23
24// RISC-V Target
25class RISCVTargetInfo : public TargetInfo {
26protected:
Zakk Chen294d1ea2020-07-16 10:32:01 -070027 std::string ABI, CPU;
Shiva Chen4891dbf2018-04-05 12:54:00 +000028 bool HasM;
29 bool HasA;
30 bool HasF;
31 bool HasD;
32 bool HasC;
Scott Egerton61ff296372020-04-09 17:51:26 +010033 bool HasB;
Alex Bradbury71f45452018-01-11 13:36:56 +000034
35public:
36 RISCVTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
Shiva Chen4891dbf2018-04-05 12:54:00 +000037 : TargetInfo(Triple), HasM(false), HasA(false), HasF(false),
Scott Egerton61ff296372020-04-09 17:51:26 +010038 HasD(false), HasC(false), HasB(false) {
Alex Bradbury71f45452018-01-11 13:36:56 +000039 LongDoubleWidth = 128;
40 LongDoubleAlign = 128;
41 LongDoubleFormat = &llvm::APFloat::IEEEquad();
42 SuitableAlign = 128;
43 WCharType = SignedInt;
44 WIntType = UnsignedInt;
45 }
46
Zakk Chen294d1ea2020-07-16 10:32:01 -070047 bool setCPU(const std::string &Name) override {
48 if (!isValidCPUName(Name))
49 return false;
50 CPU = Name;
51 return true;
52 }
53
Alex Bradbury71f45452018-01-11 13:36:56 +000054 StringRef getABI() const override { return ABI; }
55 void getTargetDefines(const LangOptions &Opts,
56 MacroBuilder &Builder) const override;
57
58 ArrayRef<Builtin::Info> getTargetBuiltins() const override { return None; }
59
60 BuiltinVaListKind getBuiltinVaListKind() const override {
61 return TargetInfo::VoidPtrBuiltinVaList;
62 }
63
64 const char *getClobbers() const override { return ""; }
65
66 ArrayRef<const char *> getGCCRegNames() const override;
67
Alex Bradbury77d4a8f2019-07-08 09:38:06 +000068 int getEHDataRegisterNumber(unsigned RegNo) const override {
69 if (RegNo == 0)
70 return 10;
71 else if (RegNo == 1)
72 return 11;
73 else
74 return -1;
75 }
76
Alex Bradbury71f45452018-01-11 13:36:56 +000077 ArrayRef<TargetInfo::GCCRegAlias> getGCCRegAliases() const override;
78
79 bool validateAsmConstraint(const char *&Name,
Lewis Revill5665ef32019-06-11 12:44:01 +000080 TargetInfo::ConstraintInfo &Info) const override;
Shiva Chen4891dbf2018-04-05 12:54:00 +000081
82 bool hasFeature(StringRef Feature) const override;
83
84 bool handleTargetFeatures(std::vector<std::string> &Features,
85 DiagnosticsEngine &Diags) override;
Erich Keane8a1c9992020-04-29 12:48:07 -070086
87 bool hasExtIntType() const override { return true; }
Alex Bradbury71f45452018-01-11 13:36:56 +000088};
89class LLVM_LIBRARY_VISIBILITY RISCV32TargetInfo : public RISCVTargetInfo {
90public:
91 RISCV32TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
92 : RISCVTargetInfo(Triple, Opts) {
93 IntPtrType = SignedInt;
94 PtrDiffType = SignedInt;
95 SizeType = UnsignedInt;
96 resetDataLayout("e-m:e-p:32:32-i64:64-n32-S128");
97 }
98
99 bool setABI(const std::string &Name) override {
Alex Bradburye078967a2019-07-18 18:29:59 +0000100 if (Name == "ilp32" || Name == "ilp32f" || Name == "ilp32d") {
Alex Bradbury71f45452018-01-11 13:36:56 +0000101 ABI = Name;
102 return true;
103 }
104 return false;
105 }
Sam Elliottf2606302019-08-27 15:41:16 +0000106
Zakk Chen294d1ea2020-07-16 10:32:01 -0700107 bool isValidCPUName(StringRef Name) const override;
108 void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const override;
109
Sam Elliottf2606302019-08-27 15:41:16 +0000110 void setMaxAtomicWidth() override {
111 MaxAtomicPromoteWidth = 128;
112
113 if (HasA)
114 MaxAtomicInlineWidth = 32;
115 }
Alex Bradbury71f45452018-01-11 13:36:56 +0000116};
117class LLVM_LIBRARY_VISIBILITY RISCV64TargetInfo : public RISCVTargetInfo {
118public:
119 RISCV64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
120 : RISCVTargetInfo(Triple, Opts) {
121 LongWidth = LongAlign = PointerWidth = PointerAlign = 64;
122 IntMaxType = Int64Type = SignedLong;
123 resetDataLayout("e-m:e-p:64:64-i64:64-i128:128-n64-S128");
124 }
125
126 bool setABI(const std::string &Name) override {
Alex Bradburye078967a2019-07-18 18:29:59 +0000127 if (Name == "lp64" || Name == "lp64f" || Name == "lp64d") {
Alex Bradbury71f45452018-01-11 13:36:56 +0000128 ABI = Name;
129 return true;
130 }
131 return false;
132 }
Sam Elliottf2606302019-08-27 15:41:16 +0000133
Zakk Chen294d1ea2020-07-16 10:32:01 -0700134 bool isValidCPUName(StringRef Name) const override;
135 void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const override;
136
Sam Elliottf2606302019-08-27 15:41:16 +0000137 void setMaxAtomicWidth() override {
138 MaxAtomicPromoteWidth = 128;
139
140 if (HasA)
141 MaxAtomicInlineWidth = 64;
142 }
Alex Bradbury71f45452018-01-11 13:36:56 +0000143};
144} // namespace targets
145} // namespace clang
146
147#endif // LLVM_CLANG_LIB_BASIC_TARGETS_RISCV_H