Coverage Report

Created: 2021-08-24 07:12

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/Basic/Targets/RISCV.h
Line
Count
Source (jump to first uncovered line)
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
21
namespace clang {
22
namespace targets {
23
24
// RISC-V Target
25
class RISCVTargetInfo : public TargetInfo {
26
protected:
27
  std::string ABI, CPU;
28
  bool HasM = false;
29
  bool HasA = false;
30
  bool HasF = false;
31
  bool HasD = false;
32
  bool HasC = false;
33
  bool HasB = false;
34
  bool HasV = false;
35
  bool HasZba = false;
36
  bool HasZbb = false;
37
  bool HasZbc = false;
38
  bool HasZbe = false;
39
  bool HasZbf = false;
40
  bool HasZbm = false;
41
  bool HasZbp = false;
42
  bool HasZbproposedc = false;
43
  bool HasZbr = false;
44
  bool HasZbs = false;
45
  bool HasZbt = false;
46
  bool HasZfh = false;
47
  bool HasZvamo = false;
48
  bool HasZvlsseg = false;
49
50
  static const Builtin::Info BuiltinInfo[];
51
52
public:
53
  RISCVTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
54
503
      : TargetInfo(Triple) {
55
503
    LongDoubleWidth = 128;
56
503
    LongDoubleAlign = 128;
57
503
    LongDoubleFormat = &llvm::APFloat::IEEEquad();
58
503
    SuitableAlign = 128;
59
503
    WCharType = SignedInt;
60
503
    WIntType = UnsignedInt;
61
503
    HasRISCVVTypes = true;
62
503
    MCountName = "_mcount";
63
503
    HasFloat16 = true;
64
503
  }
65
66
2
  bool setCPU(const std::string &Name) override {
67
2
    if (!isValidCPUName(Name))
68
2
      return false;
69
0
    CPU = Name;
70
0
    return true;
71
2
  }
72
73
1.56k
  StringRef getABI() const override { return ABI; }
74
  void getTargetDefines(const LangOptions &Opts,
75
                        MacroBuilder &Builder) const override;
76
77
  ArrayRef<Builtin::Info> getTargetBuiltins() const override;
78
79
431
  BuiltinVaListKind getBuiltinVaListKind() const override {
80
431
    return TargetInfo::VoidPtrBuiltinVaList;
81
431
  }
82
83
24
  const char *getClobbers() const override { return ""; }
84
85
  ArrayRef<const char *> getGCCRegNames() const override;
86
87
8
  int getEHDataRegisterNumber(unsigned RegNo) const override {
88
8
    if (RegNo == 0)
89
4
      return 10;
90
4
    else if (RegNo == 1)
91
4
      return 11;
92
0
    else
93
0
      return -1;
94
8
  }
95
96
  ArrayRef<TargetInfo::GCCRegAlias> getGCCRegAliases() const override;
97
98
  bool validateAsmConstraint(const char *&Name,
99
                             TargetInfo::ConstraintInfo &Info) const override;
100
101
  std::string convertConstraint(const char *&Constraint) const override;
102
103
  bool
104
  initFeatureMap(llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags,
105
                 StringRef CPU,
106
                 const std::vector<std::string> &FeaturesVec) const override;
107
108
  bool hasFeature(StringRef Feature) const override;
109
110
  bool handleTargetFeatures(std::vector<std::string> &Features,
111
                            DiagnosticsEngine &Diags) override;
112
113
30
  bool hasExtIntType() const override { return true; }
114
};
115
class LLVM_LIBRARY_VISIBILITY RISCV32TargetInfo : public RISCVTargetInfo {
116
public:
117
  RISCV32TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
118
97
      : RISCVTargetInfo(Triple, Opts) {
119
97
    IntPtrType = SignedInt;
120
97
    PtrDiffType = SignedInt;
121
97
    SizeType = UnsignedInt;
122
97
    resetDataLayout("e-m:e-p:32:32-i64:64-n32-S128");
123
97
  }
clang::targets::RISCV32TargetInfo::RISCV32TargetInfo(llvm::Triple const&, clang::TargetOptions const&)
Line
Count
Source
118
56
      : RISCVTargetInfo(Triple, Opts) {
119
56
    IntPtrType = SignedInt;
120
56
    PtrDiffType = SignedInt;
121
56
    SizeType = UnsignedInt;
122
56
    resetDataLayout("e-m:e-p:32:32-i64:64-n32-S128");
123
56
  }
clang::targets::RISCV32TargetInfo::RISCV32TargetInfo(llvm::Triple const&, clang::TargetOptions const&)
Line
Count
Source
118
41
      : RISCVTargetInfo(Triple, Opts) {
119
41
    IntPtrType = SignedInt;
120
41
    PtrDiffType = SignedInt;
121
41
    SizeType = UnsignedInt;
122
41
    resetDataLayout("e-m:e-p:32:32-i64:64-n32-S128");
123
41
  }
124
125
56
  bool setABI(const std::string &Name) override {
126
56
    if (Name == "ilp32" || 
Name == "ilp32f"19
||
Name == "ilp32d"13
) {
127
55
      ABI = Name;
128
55
      return true;
129
55
    }
130
1
    return false;
131
56
  }
132
133
  bool isValidCPUName(StringRef Name) const override;
134
  void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const override;
135
  bool isValidTuneCPUName(StringRef Name) const override;
136
  void fillValidTuneCPUList(SmallVectorImpl<StringRef> &Values) const override;
137
138
94
  void setMaxAtomicWidth() override {
139
94
    MaxAtomicPromoteWidth = 128;
140
141
94
    if (HasA)
142
13
      MaxAtomicInlineWidth = 32;
143
94
  }
144
};
145
class LLVM_LIBRARY_VISIBILITY RISCV64TargetInfo : public RISCVTargetInfo {
146
public:
147
  RISCV64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
148
406
      : RISCVTargetInfo(Triple, Opts) {
149
406
    LongWidth = LongAlign = PointerWidth = PointerAlign = 64;
150
406
    IntMaxType = Int64Type = SignedLong;
151
406
    resetDataLayout("e-m:e-p:64:64-i64:64-i128:128-n64-S128");
152
406
  }
clang::targets::RISCV64TargetInfo::RISCV64TargetInfo(llvm::Triple const&, clang::TargetOptions const&)
Line
Count
Source
148
369
      : RISCVTargetInfo(Triple, Opts) {
149
369
    LongWidth = LongAlign = PointerWidth = PointerAlign = 64;
150
369
    IntMaxType = Int64Type = SignedLong;
151
369
    resetDataLayout("e-m:e-p:64:64-i64:64-i128:128-n64-S128");
152
369
  }
clang::targets::RISCV64TargetInfo::RISCV64TargetInfo(llvm::Triple const&, clang::TargetOptions const&)
Line
Count
Source
148
37
      : RISCVTargetInfo(Triple, Opts) {
149
37
    LongWidth = LongAlign = PointerWidth = PointerAlign = 64;
150
37
    IntMaxType = Int64Type = SignedLong;
151
37
    resetDataLayout("e-m:e-p:64:64-i64:64-i128:128-n64-S128");
152
37
  }
153
154
47
  bool setABI(const std::string &Name) override {
155
47
    if (Name == "lp64" || 
Name == "lp64f"12
||
Name == "lp64d"7
) {
156
46
      ABI = Name;
157
46
      return true;
158
46
    }
159
1
    return false;
160
47
  }
161
162
  bool isValidCPUName(StringRef Name) const override;
163
  void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const override;
164
  bool isValidTuneCPUName(StringRef Name) const override;
165
  void fillValidTuneCPUList(SmallVectorImpl<StringRef> &Values) const override;
166
167
403
  void setMaxAtomicWidth() override {
168
403
    MaxAtomicPromoteWidth = 128;
169
170
403
    if (HasA)
171
13
      MaxAtomicInlineWidth = 64;
172
403
  }
173
};
174
} // namespace targets
175
} // namespace clang
176
177
#endif // LLVM_CLANG_LIB_BASIC_TARGETS_RISCV_H