Coverage Report

Created: 2021-01-26 06:56

/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
public:
51
  RISCVTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
52
157
      : TargetInfo(Triple) {
53
157
    LongDoubleWidth = 128;
54
157
    LongDoubleAlign = 128;
55
157
    LongDoubleFormat = &llvm::APFloat::IEEEquad();
56
157
    SuitableAlign = 128;
57
157
    WCharType = SignedInt;
58
157
    WIntType = UnsignedInt;
59
157
  }
60
61
2
  bool setCPU(const std::string &Name) override {
62
2
    if (!isValidCPUName(Name))
63
2
      return false;
64
0
    CPU = Name;
65
0
    return true;
66
0
  }
67
68
545
  StringRef getABI() const override { return ABI; }
69
  void getTargetDefines(const LangOptions &Opts,
70
                        MacroBuilder &Builder) const override;
71
72
151
  ArrayRef<Builtin::Info> getTargetBuiltins() const override { return None; }
73
74
85
  BuiltinVaListKind getBuiltinVaListKind() const override {
75
85
    return TargetInfo::VoidPtrBuiltinVaList;
76
85
  }
77
78
16
  const char *getClobbers() const override { return ""; }
79
80
  ArrayRef<const char *> getGCCRegNames() const override;
81
82
8
  int getEHDataRegisterNumber(unsigned RegNo) const override {
83
8
    if (RegNo == 0)
84
4
      return 10;
85
4
    else if (RegNo == 1)
86
4
      return 11;
87
0
    else
88
0
      return -1;
89
8
  }
90
91
  ArrayRef<TargetInfo::GCCRegAlias> getGCCRegAliases() const override;
92
93
  bool validateAsmConstraint(const char *&Name,
94
                             TargetInfo::ConstraintInfo &Info) const override;
95
96
  bool hasFeature(StringRef Feature) const override;
97
98
  bool handleTargetFeatures(std::vector<std::string> &Features,
99
                            DiagnosticsEngine &Diags) override;
100
101
30
  bool hasExtIntType() const override { return true; }
102
};
103
class LLVM_LIBRARY_VISIBILITY RISCV32TargetInfo : public RISCVTargetInfo {
104
public:
105
  RISCV32TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
106
83
      : RISCVTargetInfo(Triple, Opts) {
107
83
    IntPtrType = SignedInt;
108
83
    PtrDiffType = SignedInt;
109
83
    SizeType = UnsignedInt;
110
83
    resetDataLayout("e-m:e-p:32:32-i64:64-n32-S128");
111
83
  }
clang::targets::RISCV32TargetInfo::RISCV32TargetInfo(llvm::Triple const&, clang::TargetOptions const&)
Line
Count
Source
106
43
      : RISCVTargetInfo(Triple, Opts) {
107
43
    IntPtrType = SignedInt;
108
43
    PtrDiffType = SignedInt;
109
43
    SizeType = UnsignedInt;
110
43
    resetDataLayout("e-m:e-p:32:32-i64:64-n32-S128");
111
43
  }
clang::targets::RISCV32TargetInfo::RISCV32TargetInfo(llvm::Triple const&, clang::TargetOptions const&)
Line
Count
Source
106
40
      : RISCVTargetInfo(Triple, Opts) {
107
40
    IntPtrType = SignedInt;
108
40
    PtrDiffType = SignedInt;
109
40
    SizeType = UnsignedInt;
110
40
    resetDataLayout("e-m:e-p:32:32-i64:64-n32-S128");
111
40
  }
112
113
56
  bool setABI(const std::string &Name) override {
114
56
    if (Name == "ilp32" || 
Name == "ilp32f"19
||
Name == "ilp32d"13
) {
115
55
      ABI = Name;
116
55
      return true;
117
55
    }
118
1
    return false;
119
1
  }
120
121
  bool isValidCPUName(StringRef Name) const override;
122
  void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const override;
123
  bool isValidTuneCPUName(StringRef Name) const override;
124
  void fillValidTuneCPUList(SmallVectorImpl<StringRef> &Values) const override;
125
126
80
  void setMaxAtomicWidth() override {
127
80
    MaxAtomicPromoteWidth = 128;
128
129
80
    if (HasA)
130
13
      MaxAtomicInlineWidth = 32;
131
80
  }
132
};
133
class LLVM_LIBRARY_VISIBILITY RISCV64TargetInfo : public RISCVTargetInfo {
134
public:
135
  RISCV64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
136
74
      : RISCVTargetInfo(Triple, Opts) {
137
74
    LongWidth = LongAlign = PointerWidth = PointerAlign = 64;
138
74
    IntMaxType = Int64Type = SignedLong;
139
74
    resetDataLayout("e-m:e-p:64:64-i64:64-i128:128-n64-S128");
140
74
  }
clang::targets::RISCV64TargetInfo::RISCV64TargetInfo(llvm::Triple const&, clang::TargetOptions const&)
Line
Count
Source
136
41
      : RISCVTargetInfo(Triple, Opts) {
137
41
    LongWidth = LongAlign = PointerWidth = PointerAlign = 64;
138
41
    IntMaxType = Int64Type = SignedLong;
139
41
    resetDataLayout("e-m:e-p:64:64-i64:64-i128:128-n64-S128");
140
41
  }
clang::targets::RISCV64TargetInfo::RISCV64TargetInfo(llvm::Triple const&, clang::TargetOptions const&)
Line
Count
Source
136
33
      : RISCVTargetInfo(Triple, Opts) {
137
33
    LongWidth = LongAlign = PointerWidth = PointerAlign = 64;
138
33
    IntMaxType = Int64Type = SignedLong;
139
33
    resetDataLayout("e-m:e-p:64:64-i64:64-i128:128-n64-S128");
140
33
  }
141
142
47
  bool setABI(const std::string &Name) override {
143
47
    if (Name == "lp64" || 
Name == "lp64f"12
||
Name == "lp64d"7
) {
144
46
      ABI = Name;
145
46
      return true;
146
46
    }
147
1
    return false;
148
1
  }
149
150
  bool isValidCPUName(StringRef Name) const override;
151
  void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const override;
152
  bool isValidTuneCPUName(StringRef Name) const override;
153
  void fillValidTuneCPUList(SmallVectorImpl<StringRef> &Values) const override;
154
155
71
  void setMaxAtomicWidth() override {
156
71
    MaxAtomicPromoteWidth = 128;
157
158
71
    if (HasA)
159
12
      MaxAtomicInlineWidth = 64;
160
71
  }
161
};
162
} // namespace targets
163
} // namespace clang
164
165
#endif // LLVM_CLANG_LIB_BASIC_TARGETS_RISCV_H