Coverage Report

Created: 2023-11-11 10:31

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/Basic/Targets/LoongArch.h
Line
Count
Source (jump to first uncovered line)
1
//===-- LoongArch.h - Declare LoongArch 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 LoongArch TargetInfo objects.
10
//
11
//===----------------------------------------------------------------------===//
12
13
#ifndef LLVM_CLANG_LIB_BASIC_TARGETS_LOONGARCH_H
14
#define LLVM_CLANG_LIB_BASIC_TARGETS_LOONGARCH_H
15
16
#include "clang/Basic/TargetInfo.h"
17
#include "clang/Basic/TargetOptions.h"
18
#include "llvm/Support/Compiler.h"
19
#include "llvm/TargetParser/Triple.h"
20
21
namespace clang {
22
namespace targets {
23
24
class LLVM_LIBRARY_VISIBILITY LoongArchTargetInfo : public TargetInfo {
25
protected:
26
  std::string ABI;
27
  std::string CPU;
28
  bool HasFeatureD;
29
  bool HasFeatureF;
30
  bool HasFeatureLSX;
31
  bool HasFeatureLASX;
32
33
public:
34
  LoongArchTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
35
146
      : TargetInfo(Triple) {
36
146
    HasFeatureD = false;
37
146
    HasFeatureF = false;
38
146
    HasFeatureLSX = false;
39
146
    HasFeatureLASX = false;
40
146
    LongDoubleWidth = 128;
41
146
    LongDoubleAlign = 128;
42
146
    LongDoubleFormat = &llvm::APFloat::IEEEquad();
43
146
    MCountName = "_mcount";
44
146
    SuitableAlign = 128;
45
146
    WCharType = SignedInt;
46
146
    WIntType = UnsignedInt;
47
146
  }
48
49
76
  bool setCPU(const std::string &Name) override {
50
76
    if (!isValidCPUName(Name))
51
2
      return false;
52
74
    CPU = Name;
53
74
    return true;
54
76
  }
55
56
135
  StringRef getCPU() const { return CPU; }
57
58
316
  StringRef getABI() const override { return ABI; }
59
60
  void getTargetDefines(const LangOptions &Opts,
61
                        MacroBuilder &Builder) const override;
62
63
  ArrayRef<Builtin::Info> getTargetBuiltins() const override;
64
65
83
  BuiltinVaListKind getBuiltinVaListKind() const override {
66
83
    return TargetInfo::VoidPtrBuiltinVaList;
67
83
  }
68
69
93
  std::string_view getClobbers() const override { return ""; }
70
71
  ArrayRef<const char *> getGCCRegNames() const override;
72
73
8
  int getEHDataRegisterNumber(unsigned RegNo) const override {
74
8
    if (RegNo == 0)
75
4
      return 4;
76
4
    if (RegNo == 1)
77
4
      return 5;
78
0
    return -1;
79
4
  }
80
81
  ArrayRef<TargetInfo::GCCRegAlias> getGCCRegAliases() const override;
82
83
  bool validateAsmConstraint(const char *&Name,
84
                             TargetInfo::ConstraintInfo &Info) const override;
85
  std::string convertConstraint(const char *&Constraint) const override;
86
87
20
  bool hasBitIntType() const override { return true; }
88
89
  bool handleTargetFeatures(std::vector<std::string> &Features,
90
                            DiagnosticsEngine &Diags) override;
91
92
  bool
93
  initFeatureMap(llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags,
94
                 StringRef CPU,
95
                 const std::vector<std::string> &FeaturesVec) const override;
96
97
  bool hasFeature(StringRef Feature) const override;
98
99
  bool isValidCPUName(StringRef Name) const override;
100
  void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const override;
101
};
102
103
class LLVM_LIBRARY_VISIBILITY LoongArch32TargetInfo
104
    : public LoongArchTargetInfo {
105
public:
106
  LoongArch32TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
107
33
      : LoongArchTargetInfo(Triple, Opts) {
108
33
    IntPtrType = SignedInt;
109
33
    PtrDiffType = SignedInt;
110
33
    SizeType = UnsignedInt;
111
33
    resetDataLayout("e-m:e-p:32:32-i64:64-n32-S128");
112
    // TODO: select appropriate ABI.
113
33
    setABI("ilp32d");
114
33
  }
115
116
48
  bool setABI(const std::string &Name) override {
117
48
    if (Name == "ilp32d" || 
Name == "ilp32f"11
||
Name == "ilp32s"8
) {
118
45
      ABI = Name;
119
45
      return true;
120
45
    }
121
3
    return false;
122
48
  }
123
30
  void setMaxAtomicWidth() override {
124
30
    MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 32;
125
30
  }
126
};
127
128
class LLVM_LIBRARY_VISIBILITY LoongArch64TargetInfo
129
    : public LoongArchTargetInfo {
130
public:
131
  LoongArch64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
132
113
      : LoongArchTargetInfo(Triple, Opts) {
133
113
    LongWidth = LongAlign = PointerWidth = PointerAlign = 64;
134
113
    IntMaxType = Int64Type = SignedLong;
135
113
    resetDataLayout("e-m:e-p:64:64-i64:64-i128:128-n64-S128");
136
    // TODO: select appropriate ABI.
137
113
    setABI("lp64d");
138
113
  }
139
140
190
  bool setABI(const std::string &Name) override {
141
190
    if (Name == "lp64d" || 
Name == "lp64f"16
||
Name == "lp64s"11
) {
142
187
      ABI = Name;
143
187
      return true;
144
187
    }
145
3
    return false;
146
190
  }
147
105
  void setMaxAtomicWidth() override {
148
105
    MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 64;
149
105
  }
150
};
151
} // end namespace targets
152
} // end namespace clang
153
154
#endif // LLVM_CLANG_LIB_BASIC_TARGETS_LOONGARCH_H