Coverage Report

Created: 2022-07-16 07:03

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/Basic/Targets/SystemZ.h
Line
Count
Source (jump to first uncovered line)
1
//===--- SystemZ.h - Declare SystemZ 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 SystemZ TargetInfo objects.
10
//
11
//===----------------------------------------------------------------------===//
12
13
#ifndef LLVM_CLANG_LIB_BASIC_TARGETS_SYSTEMZ_H
14
#define LLVM_CLANG_LIB_BASIC_TARGETS_SYSTEMZ_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
class LLVM_LIBRARY_VISIBILITY SystemZTargetInfo : public TargetInfo {
25
26
  static const Builtin::Info BuiltinInfo[];
27
  static const char *const GCCRegNames[];
28
  std::string CPU;
29
  int ISARevision;
30
  bool HasTransactionalExecution;
31
  bool HasVector;
32
  bool SoftFloat;
33
34
public:
35
  SystemZTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
36
      : TargetInfo(Triple), CPU("z10"), ISARevision(8),
37
112
        HasTransactionalExecution(false), HasVector(false), SoftFloat(false) {
38
112
    IntMaxType = SignedLong;
39
112
    Int64Type = SignedLong;
40
112
    TLSSupported = true;
41
112
    IntWidth = IntAlign = 32;
42
112
    LongWidth = LongLongWidth = LongAlign = LongLongAlign = 64;
43
112
    PointerWidth = PointerAlign = 64;
44
112
    LongDoubleWidth = 128;
45
112
    LongDoubleAlign = 64;
46
112
    LongDoubleFormat = &llvm::APFloat::IEEEquad();
47
112
    DefaultAlignForAttributeAligned = 64;
48
112
    MinGlobalAlign = 16;
49
112
    if (Triple.isOSzOS()) {
50
      // All vector types are default aligned on an 8-byte boundary, even if the
51
      // vector facility is not available. That is different from Linux.
52
29
      MaxVectorAlign = 64;
53
      // Compared to Linux/ELF, the data layout differs only in some details:
54
      // - name mangling is GOFF
55
      // - 128 bit vector types are 64 bit aligned
56
29
      resetDataLayout(
57
29
          "E-m:l-i1:8:16-i8:8:16-i64:64-f128:64-v128:64-a:8:16-n32:64");
58
29
    } else
59
83
      resetDataLayout("E-m:e-i1:8:16-i8:8:16-i64:64-f128:64-a:8:16-n32:64");
60
112
    MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 64;
61
112
    HasStrictFP = true;
62
112
  }
clang::targets::SystemZTargetInfo::SystemZTargetInfo(llvm::Triple const&, clang::TargetOptions const&)
Line
Count
Source
37
13
        HasTransactionalExecution(false), HasVector(false), SoftFloat(false) {
38
13
    IntMaxType = SignedLong;
39
13
    Int64Type = SignedLong;
40
13
    TLSSupported = true;
41
13
    IntWidth = IntAlign = 32;
42
13
    LongWidth = LongLongWidth = LongAlign = LongLongAlign = 64;
43
13
    PointerWidth = PointerAlign = 64;
44
13
    LongDoubleWidth = 128;
45
13
    LongDoubleAlign = 64;
46
13
    LongDoubleFormat = &llvm::APFloat::IEEEquad();
47
13
    DefaultAlignForAttributeAligned = 64;
48
13
    MinGlobalAlign = 16;
49
13
    if (Triple.isOSzOS()) {
50
      // All vector types are default aligned on an 8-byte boundary, even if the
51
      // vector facility is not available. That is different from Linux.
52
0
      MaxVectorAlign = 64;
53
      // Compared to Linux/ELF, the data layout differs only in some details:
54
      // - name mangling is GOFF
55
      // - 128 bit vector types are 64 bit aligned
56
0
      resetDataLayout(
57
0
          "E-m:l-i1:8:16-i8:8:16-i64:64-f128:64-v128:64-a:8:16-n32:64");
58
0
    } else
59
13
      resetDataLayout("E-m:e-i1:8:16-i8:8:16-i64:64-f128:64-a:8:16-n32:64");
60
13
    MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 64;
61
13
    HasStrictFP = true;
62
13
  }
clang::targets::SystemZTargetInfo::SystemZTargetInfo(llvm::Triple const&, clang::TargetOptions const&)
Line
Count
Source
37
99
        HasTransactionalExecution(false), HasVector(false), SoftFloat(false) {
38
99
    IntMaxType = SignedLong;
39
99
    Int64Type = SignedLong;
40
99
    TLSSupported = true;
41
99
    IntWidth = IntAlign = 32;
42
99
    LongWidth = LongLongWidth = LongAlign = LongLongAlign = 64;
43
99
    PointerWidth = PointerAlign = 64;
44
99
    LongDoubleWidth = 128;
45
99
    LongDoubleAlign = 64;
46
99
    LongDoubleFormat = &llvm::APFloat::IEEEquad();
47
99
    DefaultAlignForAttributeAligned = 64;
48
99
    MinGlobalAlign = 16;
49
99
    if (Triple.isOSzOS()) {
50
      // All vector types are default aligned on an 8-byte boundary, even if the
51
      // vector facility is not available. That is different from Linux.
52
29
      MaxVectorAlign = 64;
53
      // Compared to Linux/ELF, the data layout differs only in some details:
54
      // - name mangling is GOFF
55
      // - 128 bit vector types are 64 bit aligned
56
29
      resetDataLayout(
57
29
          "E-m:l-i1:8:16-i8:8:16-i64:64-f128:64-v128:64-a:8:16-n32:64");
58
29
    } else
59
70
      resetDataLayout("E-m:e-i1:8:16-i8:8:16-i64:64-f128:64-a:8:16-n32:64");
60
99
    MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 64;
61
99
    HasStrictFP = true;
62
99
  }
63
64
  void getTargetDefines(const LangOptions &Opts,
65
                        MacroBuilder &Builder) const override;
66
67
  ArrayRef<Builtin::Info> getTargetBuiltins() const override;
68
69
  ArrayRef<const char *> getGCCRegNames() const override;
70
71
8
  ArrayRef<TargetInfo::GCCRegAlias> getGCCRegAliases() const override {
72
    // No aliases.
73
8
    return None;
74
8
  }
75
76
  ArrayRef<TargetInfo::AddlRegName> getGCCAddlRegNames() const override;
77
78
1
  bool isSPRegName(StringRef RegName) const override {
79
1
    return RegName.equals("r15");
80
1
  }
81
82
  bool validateAsmConstraint(const char *&Name,
83
                             TargetInfo::ConstraintInfo &info) const override;
84
85
169
  std::string convertConstraint(const char *&Constraint) const override {
86
169
    switch (Constraint[0]) {
87
2
    case 'p': // Keep 'p' constraint.
88
2
      return std::string("p");
89
0
    case 'Z':
90
0
      switch (Constraint[1]) {
91
0
      case 'Q': // Address with base and unsigned 12-bit displacement
92
0
      case 'R': // Likewise, plus an index
93
0
      case 'S': // Address with base and signed 20-bit displacement
94
0
      case 'T': // Likewise, plus an index
95
        // "^" hints llvm that this is a 2 letter constraint.
96
        // "Constraint++" is used to promote the string iterator
97
        // to the next constraint.
98
0
        return std::string("^") + std::string(Constraint++, 2);
99
0
      default:
100
0
        break;
101
0
      }
102
0
      break;
103
167
    default:
104
167
      break;
105
169
    }
106
167
    return TargetInfo::convertConstraint(Constraint);
107
169
  }
108
109
61
  const char *getClobbers() const override {
110
    // FIXME: Is this really right?
111
61
    return "";
112
61
  }
113
114
85
  BuiltinVaListKind getBuiltinVaListKind() const override {
115
85
    return TargetInfo::SystemZBuiltinVaList;
116
85
  }
117
118
  int getISARevision(StringRef Name) const;
119
120
0
  bool isValidCPUName(StringRef Name) const override {
121
0
    return getISARevision(Name) != -1;
122
0
  }
123
124
  void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const override;
125
126
0
  bool isValidTuneCPUName(StringRef Name) const override {
127
0
    return isValidCPUName(Name);
128
0
  }
129
130
0
  void fillValidTuneCPUList(SmallVectorImpl<StringRef> &Values) const override {
131
0
    fillValidCPUList(Values);
132
0
  }
133
134
63
  bool setCPU(const std::string &Name) override {
135
63
    CPU = Name;
136
63
    ISARevision = getISARevision(CPU);
137
63
    return ISARevision != -1;
138
63
  }
139
140
  bool
141
  initFeatureMap(llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags,
142
                 StringRef CPU,
143
110
                 const std::vector<std::string> &FeaturesVec) const override {
144
110
    int ISARevision = getISARevision(CPU);
145
110
    if (ISARevision >= 10)
146
38
      Features["transactional-execution"] = true;
147
110
    if (ISARevision >= 11)
148
36
      Features["vector"] = true;
149
110
    if (ISARevision >= 12)
150
22
      Features["vector-enhancements-1"] = true;
151
110
    if (ISARevision >= 13)
152
14
      Features["vector-enhancements-2"] = true;
153
110
    if (ISARevision >= 14)
154
7
      Features["nnp-assist"] = true;
155
110
    return TargetInfo::initFeatureMap(Features, Diags, CPU, FeaturesVec);
156
110
  }
157
158
  bool handleTargetFeatures(std::vector<std::string> &Features,
159
110
                            DiagnosticsEngine &Diags) override {
160
110
    HasTransactionalExecution = false;
161
110
    HasVector = false;
162
110
    SoftFloat = false;
163
123
    for (const auto &Feature : Features) {
164
123
      if (Feature == "+transactional-execution")
165
39
        HasTransactionalExecution = true;
166
84
      else if (Feature == "+vector")
167
39
        HasVector = true;
168
45
      else if (Feature == "+soft-float")
169
2
        SoftFloat = true;
170
123
    }
171
110
    HasVector &= !SoftFloat;
172
173
    // If we use the vector ABI, vector types are 64-bit aligned.
174
110
    if (HasVector && 
!getTriple().isOSzOS()37
) {
175
35
      MaxVectorAlign = 64;
176
35
      resetDataLayout("E-m:e-i1:8:16-i8:8:16-i64:64-f128:64"
177
35
                      "-v128:64-a:8:16-n32:64");
178
35
    }
179
110
    return true;
180
110
  }
181
182
  bool hasFeature(StringRef Feature) const override;
183
184
6
  CallingConvCheckResult checkCallingConvention(CallingConv CC) const override {
185
6
    switch (CC) {
186
0
    case CC_C:
187
0
    case CC_Swift:
188
0
    case CC_OpenCLKernel:
189
0
      return CCCR_OK;
190
6
    case CC_SwiftAsync:
191
6
      return CCCR_Error;
192
0
    default:
193
0
      return CCCR_Warning;
194
6
    }
195
6
  }
196
197
475
  StringRef getABI() const override {
198
475
    if (HasVector)
199
345
      return "vector";
200
130
    return "";
201
475
  }
202
203
1
  const char *getLongDoubleMangling() const override { return "g"; }
204
205
10
  bool hasBitIntType() const override { return true; }
206
207
0
  int getEHDataRegisterNumber(unsigned RegNo) const override {
208
0
    return RegNo < 4 ? 6 + RegNo : -1;
209
0
  }
210
};
211
} // namespace targets
212
} // namespace clang
213
#endif // LLVM_CLANG_LIB_BASIC_TARGETS_SYSTEMZ_H