Coverage Report

Created: 2023-05-31 04:38

/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
  bool HasFeatureD;
28
  bool HasFeatureF;
29
30
public:
31
  LoongArchTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
32
73
      : TargetInfo(Triple) {
33
73
    HasFeatureD = false;
34
73
    HasFeatureF = false;
35
73
    LongDoubleWidth = 128;
36
73
    LongDoubleAlign = 128;
37
73
    LongDoubleFormat = &llvm::APFloat::IEEEquad();
38
73
    SuitableAlign = 128;
39
73
    WCharType = SignedInt;
40
73
    WIntType = UnsignedInt;
41
73
  }
42
43
144
  StringRef getABI() const override { return ABI; }
44
45
  void getTargetDefines(const LangOptions &Opts,
46
                        MacroBuilder &Builder) const override;
47
48
  ArrayRef<Builtin::Info> getTargetBuiltins() const override;
49
50
35
  BuiltinVaListKind getBuiltinVaListKind() const override {
51
35
    return TargetInfo::VoidPtrBuiltinVaList;
52
35
  }
53
54
83
  std::string_view getClobbers() const override { return ""; }
55
56
  ArrayRef<const char *> getGCCRegNames() const override;
57
58
8
  int getEHDataRegisterNumber(unsigned RegNo) const override {
59
8
    if (RegNo == 0)
60
4
      return 4;
61
4
    if (RegNo == 1)
62
4
      return 5;
63
0
    return -1;
64
4
  }
65
66
  ArrayRef<TargetInfo::GCCRegAlias> getGCCRegAliases() const override;
67
68
  bool validateAsmConstraint(const char *&Name,
69
                             TargetInfo::ConstraintInfo &Info) const override;
70
  std::string convertConstraint(const char *&Constraint) const override;
71
72
20
  bool hasBitIntType() const override { return true; }
73
74
  bool handleTargetFeatures(std::vector<std::string> &Features,
75
                            DiagnosticsEngine &Diags) override;
76
77
  bool
78
  initFeatureMap(llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags,
79
                 StringRef CPU,
80
                 const std::vector<std::string> &FeaturesVec) const override;
81
82
  bool hasFeature(StringRef Feature) const override;
83
};
84
85
class LLVM_LIBRARY_VISIBILITY LoongArch32TargetInfo
86
    : public LoongArchTargetInfo {
87
public:
88
  LoongArch32TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
89
31
      : LoongArchTargetInfo(Triple, Opts) {
90
31
    IntPtrType = SignedInt;
91
31
    PtrDiffType = SignedInt;
92
31
    SizeType = UnsignedInt;
93
31
    resetDataLayout("e-m:e-p:32:32-i64:64-n32-S128");
94
    // TODO: select appropriate ABI.
95
31
    setABI("ilp32d");
96
31
  }
97
98
46
  bool setABI(const std::string &Name) override {
99
46
    if (Name == "ilp32d" || 
Name == "ilp32f"11
||
Name == "ilp32s"8
) {
100
43
      ABI = Name;
101
43
      return true;
102
43
    }
103
3
    return false;
104
46
  }
105
28
  void setMaxAtomicWidth() override {
106
28
    MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 32;
107
28
  }
108
};
109
110
class LLVM_LIBRARY_VISIBILITY LoongArch64TargetInfo
111
    : public LoongArchTargetInfo {
112
public:
113
  LoongArch64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
114
42
      : LoongArchTargetInfo(Triple, Opts) {
115
42
    LongWidth = LongAlign = PointerWidth = PointerAlign = 64;
116
42
    IntMaxType = Int64Type = SignedLong;
117
42
    resetDataLayout("e-m:e-p:64:64-i64:64-i128:128-n64-S128");
118
    // TODO: select appropriate ABI.
119
42
    setABI("lp64d");
120
42
  }
121
122
68
  bool setABI(const std::string &Name) override {
123
68
    if (Name == "lp64d" || 
Name == "lp64f"16
||
Name == "lp64s"11
) {
124
65
      ABI = Name;
125
65
      return true;
126
65
    }
127
3
    return false;
128
68
  }
129
39
  void setMaxAtomicWidth() override {
130
39
    MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 64;
131
39
  }
132
};
133
} // end namespace targets
134
} // end namespace clang
135
136
#endif // LLVM_CLANG_LIB_BASIC_TARGETS_LOONGARCH_H