Coverage Report

Created: 2020-09-19 12:23

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