Coverage Report

Created: 2022-01-25 06:29

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