blob: c2d0f73b1af060a22d48903234e363318d2e1a62 [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:
27 std::string ABI;
Shiva Chen4891dbf2018-04-05 12:54:00 +000028 bool HasM;
29 bool HasA;
30 bool HasF;
31 bool HasD;
32 bool HasC;
Alex Bradbury71f45452018-01-11 13:36:56 +000033
34public:
35 RISCVTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
Shiva Chen4891dbf2018-04-05 12:54:00 +000036 : TargetInfo(Triple), HasM(false), HasA(false), HasF(false),
37 HasD(false), HasC(false) {
Alex Bradbury71f45452018-01-11 13:36:56 +000038 TLSSupported = false;
39 LongDoubleWidth = 128;
40 LongDoubleAlign = 128;
41 LongDoubleFormat = &llvm::APFloat::IEEEquad();
42 SuitableAlign = 128;
43 WCharType = SignedInt;
44 WIntType = UnsignedInt;
45 }
46
47 StringRef getABI() const override { return ABI; }
48 void getTargetDefines(const LangOptions &Opts,
49 MacroBuilder &Builder) const override;
50
51 ArrayRef<Builtin::Info> getTargetBuiltins() const override { return None; }
52
53 BuiltinVaListKind getBuiltinVaListKind() const override {
54 return TargetInfo::VoidPtrBuiltinVaList;
55 }
56
57 const char *getClobbers() const override { return ""; }
58
59 ArrayRef<const char *> getGCCRegNames() const override;
60
61 ArrayRef<TargetInfo::GCCRegAlias> getGCCRegAliases() const override;
62
63 bool validateAsmConstraint(const char *&Name,
Lewis Revill5665ef32019-06-11 12:44:01 +000064 TargetInfo::ConstraintInfo &Info) const override;
Shiva Chen4891dbf2018-04-05 12:54:00 +000065
66 bool hasFeature(StringRef Feature) const override;
67
68 bool handleTargetFeatures(std::vector<std::string> &Features,
69 DiagnosticsEngine &Diags) override;
Alex Bradbury71f45452018-01-11 13:36:56 +000070};
71class LLVM_LIBRARY_VISIBILITY RISCV32TargetInfo : public RISCVTargetInfo {
72public:
73 RISCV32TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
74 : RISCVTargetInfo(Triple, Opts) {
75 IntPtrType = SignedInt;
76 PtrDiffType = SignedInt;
77 SizeType = UnsignedInt;
78 resetDataLayout("e-m:e-p:32:32-i64:64-n32-S128");
79 }
80
81 bool setABI(const std::string &Name) override {
82 // TODO: support ilp32f and ilp32d ABIs.
83 if (Name == "ilp32") {
84 ABI = Name;
85 return true;
86 }
87 return false;
88 }
89};
90class LLVM_LIBRARY_VISIBILITY RISCV64TargetInfo : public RISCVTargetInfo {
91public:
92 RISCV64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
93 : RISCVTargetInfo(Triple, Opts) {
94 LongWidth = LongAlign = PointerWidth = PointerAlign = 64;
95 IntMaxType = Int64Type = SignedLong;
96 resetDataLayout("e-m:e-p:64:64-i64:64-i128:128-n64-S128");
97 }
98
99 bool setABI(const std::string &Name) override {
100 // TODO: support lp64f and lp64d ABIs.
101 if (Name == "lp64") {
102 ABI = Name;
103 return true;
104 }
105 return false;
106 }
107};
108} // namespace targets
109} // namespace clang
110
111#endif // LLVM_CLANG_LIB_BASIC_TARGETS_RISCV_H