1//===--- RISCV.h - Declare RISCV target feature support ---------*- C++ -*-===//
2//
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
6//
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;
28  bool HasM;
29  bool HasA;
30  bool HasF;
31  bool HasD;
32  bool HasC;
33
34public:
35  RISCVTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
36      : TargetInfo(Triple), HasM(false), HasA(false), HasF(false),
37        HasD(false), HasC(false) {
38    LongDoubleWidth = 128;
39    LongDoubleAlign = 128;
40    LongDoubleFormat = &llvm::APFloat::IEEEquad();
41    SuitableAlign = 128;
42    WCharType = SignedInt;
43    WIntType = UnsignedInt;
44  }
45
46  StringRef getABI() const override { return ABI; }
47  void getTargetDefines(const LangOptions &Opts,
48                        MacroBuilder &Builder) const override;
49
50  ArrayRef<Builtin::Info> getTargetBuiltins() const override { return None; }
51
52  BuiltinVaListKind getBuiltinVaListKind() const override {
53    return TargetInfo::VoidPtrBuiltinVaList;
54  }
55
56  const char *getClobbers() const override { return ""; }
57
58  ArrayRef<const char *> getGCCRegNames() const override;
59
60  int getEHDataRegisterNumber(unsigned RegNo) const override {
61    if (RegNo == 0)
62      return 10;
63    else if (RegNo == 1)
64      return 11;
65    else
66      return -1;
67  }
68
69  ArrayRef<TargetInfo::GCCRegAlias> getGCCRegAliases() const override;
70
71  bool validateAsmConstraint(const char *&Name,
72                             TargetInfo::ConstraintInfo &Info) const override;
73
74  bool hasFeature(StringRef Feature) const override;
75
76  bool handleTargetFeatures(std::vector<std::string> &Features,
77                            DiagnosticsEngine &Diags) override;
78};
79class LLVM_LIBRARY_VISIBILITY RISCV32TargetInfo : public RISCVTargetInfo {
80public:
81  RISCV32TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
82      : RISCVTargetInfo(Triple, Opts) {
83    IntPtrType = SignedInt;
84    PtrDiffType = SignedInt;
85    SizeType = UnsignedInt;
86    resetDataLayout("e-m:e-p:32:32-i64:64-n32-S128");
87  }
88
89  bool setABI(const std::string &Name) override {
90    if (Name == "ilp32" || Name == "ilp32f" || Name == "ilp32d") {
91      ABI = Name;
92      return true;
93    }
94    return false;
95  }
96
97  void setMaxAtomicWidth() override {
98    MaxAtomicPromoteWidth = 128;
99
100    if (HasA)
101      MaxAtomicInlineWidth = 32;
102  }
103};
104class LLVM_LIBRARY_VISIBILITY RISCV64TargetInfo : public RISCVTargetInfo {
105public:
106  RISCV64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
107      : RISCVTargetInfo(Triple, Opts) {
108    LongWidth = LongAlign = PointerWidth = PointerAlign = 64;
109    IntMaxType = Int64Type = SignedLong;
110    resetDataLayout("e-m:e-p:64:64-i64:64-i128:128-n64-S128");
111  }
112
113  bool setABI(const std::string &Name) override {
114    if (Name == "lp64" || Name == "lp64f" || Name == "lp64d") {
115      ABI = Name;
116      return true;
117    }
118    return false;
119  }
120
121  void setMaxAtomicWidth() override {
122    MaxAtomicPromoteWidth = 128;
123
124    if (HasA)
125      MaxAtomicInlineWidth = 64;
126  }
127};
128} // namespace targets
129} // namespace clang
130
131#endif // LLVM_CLANG_LIB_BASIC_TARGETS_RISCV_H
132