Coverage Report

Created: 2021-09-21 08:58

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/Basic/Targets/AVR.h
Line
Count
Source (jump to first uncovered line)
1
//===--- AVR.h - Declare AVR 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 AVR TargetInfo objects.
10
//
11
//===----------------------------------------------------------------------===//
12
13
#ifndef LLVM_CLANG_LIB_BASIC_TARGETS_AVR_H
14
#define LLVM_CLANG_LIB_BASIC_TARGETS_AVR_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
// AVR Target
25
class LLVM_LIBRARY_VISIBILITY AVRTargetInfo : public TargetInfo {
26
public:
27
  AVRTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
28
22
      : TargetInfo(Triple) {
29
22
    TLSSupported = false;
30
22
    PointerWidth = 16;
31
22
    PointerAlign = 8;
32
22
    IntWidth = 16;
33
22
    IntAlign = 8;
34
22
    LongWidth = 32;
35
22
    LongAlign = 8;
36
22
    LongLongWidth = 64;
37
22
    LongLongAlign = 8;
38
22
    SuitableAlign = 8;
39
22
    DefaultAlignForAttributeAligned = 8;
40
22
    HalfWidth = 16;
41
22
    HalfAlign = 8;
42
22
    FloatWidth = 32;
43
22
    FloatAlign = 8;
44
22
    DoubleWidth = 32;
45
22
    DoubleAlign = 8;
46
22
    DoubleFormat = &llvm::APFloat::IEEEsingle();
47
22
    LongDoubleWidth = 32;
48
22
    LongDoubleAlign = 8;
49
22
    LongDoubleFormat = &llvm::APFloat::IEEEsingle();
50
22
    SizeType = UnsignedInt;
51
22
    PtrDiffType = SignedInt;
52
22
    IntPtrType = SignedInt;
53
22
    Char16Type = UnsignedInt;
54
22
    WIntType = SignedInt;
55
22
    Int16Type = SignedInt;
56
22
    Char32Type = UnsignedLong;
57
22
    SigAtomicType = SignedChar;
58
22
    resetDataLayout("e-P1-p:16:8-i8:8-i16:8-i32:8-i64:8-f32:8-f64:8-n8-a:8");
59
22
  }
clang::targets::AVRTargetInfo::AVRTargetInfo(llvm::Triple const&, clang::TargetOptions const&)
Line
Count
Source
28
22
      : TargetInfo(Triple) {
29
22
    TLSSupported = false;
30
22
    PointerWidth = 16;
31
22
    PointerAlign = 8;
32
22
    IntWidth = 16;
33
22
    IntAlign = 8;
34
22
    LongWidth = 32;
35
22
    LongAlign = 8;
36
22
    LongLongWidth = 64;
37
22
    LongLongAlign = 8;
38
22
    SuitableAlign = 8;
39
22
    DefaultAlignForAttributeAligned = 8;
40
22
    HalfWidth = 16;
41
22
    HalfAlign = 8;
42
22
    FloatWidth = 32;
43
22
    FloatAlign = 8;
44
22
    DoubleWidth = 32;
45
22
    DoubleAlign = 8;
46
22
    DoubleFormat = &llvm::APFloat::IEEEsingle();
47
22
    LongDoubleWidth = 32;
48
22
    LongDoubleAlign = 8;
49
22
    LongDoubleFormat = &llvm::APFloat::IEEEsingle();
50
22
    SizeType = UnsignedInt;
51
22
    PtrDiffType = SignedInt;
52
22
    IntPtrType = SignedInt;
53
22
    Char16Type = UnsignedInt;
54
22
    WIntType = SignedInt;
55
22
    Int16Type = SignedInt;
56
22
    Char32Type = UnsignedLong;
57
22
    SigAtomicType = SignedChar;
58
22
    resetDataLayout("e-P1-p:16:8-i8:8-i16:8-i32:8-i64:8-f32:8-f64:8-n8-a:8");
59
22
  }
Unexecuted instantiation: clang::targets::AVRTargetInfo::AVRTargetInfo(llvm::Triple const&, clang::TargetOptions const&)
60
61
  void getTargetDefines(const LangOptions &Opts,
62
                        MacroBuilder &Builder) const override;
63
64
21
  ArrayRef<Builtin::Info> getTargetBuiltins() const override { return None; }
65
66
16
  BuiltinVaListKind getBuiltinVaListKind() const override {
67
16
    return TargetInfo::VoidPtrBuiltinVaList;
68
16
  }
69
70
24
  const char *getClobbers() const override { return ""; }
71
72
0
  ArrayRef<const char *> getGCCRegNames() const override {
73
0
    static const char *const GCCRegNames[] = {
74
0
        "r0",  "r1",  "r2",  "r3",  "r4",  "r5",  "r6",  "r7",  "r8",  "r9",
75
0
        "r10", "r11", "r12", "r13", "r14", "r15", "r16", "r17", "r18", "r19",
76
0
        "r20", "r21", "r22", "r23", "r24", "r25", "X",   "Y",   "Z",   "SP"
77
0
    };
78
0
    return llvm::makeArrayRef(GCCRegNames);
79
0
  }
80
81
0
  ArrayRef<TargetInfo::GCCRegAlias> getGCCRegAliases() const override {
82
0
    return None;
83
0
  }
84
85
0
  ArrayRef<TargetInfo::AddlRegName> getGCCAddlRegNames() const override {
86
0
    static const TargetInfo::AddlRegName AddlRegNames[] = {
87
0
        {{"r26", "r27"}, 26},
88
0
        {{"r28", "r29"}, 27},
89
0
        {{"r30", "r31"}, 28},
90
0
        {{"SPL", "SPH"}, 29},
91
0
    };
92
0
    return llvm::makeArrayRef(AddlRegNames);
93
0
  }
94
95
  bool validateAsmConstraint(const char *&Name,
96
48
                             TargetInfo::ConstraintInfo &Info) const override {
97
    // There aren't any multi-character AVR specific constraints.
98
48
    if (StringRef(Name).size() > 1)
99
2
      return false;
100
101
46
    switch (*Name) {
102
0
    default:
103
0
      return false;
104
6
    case 'a': // Simple upper registers
105
8
    case 'b': // Base pointer registers pairs
106
10
    case 'd': // Upper register
107
12
    case 'l': // Lower registers
108
14
    case 'e': // Pointer register pairs
109
16
    case 'q': // Stack pointer register
110
16
    case 'r': // Any register
111
18
    case 'w': // Special upper register pairs
112
20
    case 't': // Temporary register
113
22
    case 'x':
114
22
    case 'X': // Pointer register pair X
115
24
    case 'y':
116
24
    case 'Y': // Pointer register pair Y
117
26
    case 'z':
118
26
    case 'Z': // Pointer register pair Z
119
26
      Info.setAllowsRegister();
120
26
      return true;
121
2
    case 'I': // 6-bit positive integer constant
122
2
      Info.setRequiresImmediate(0, 63);
123
2
      return true;
124
2
    case 'J': // 6-bit negative integer constant
125
2
      Info.setRequiresImmediate(-63, 0);
126
2
      return true;
127
2
    case 'K': // Integer constant (Range: 2)
128
2
      Info.setRequiresImmediate(2);
129
2
      return true;
130
2
    case 'L': // Integer constant (Range: 0)
131
2
      Info.setRequiresImmediate(0);
132
2
      return true;
133
2
    case 'M': // 8-bit integer constant
134
2
      Info.setRequiresImmediate(0, 0xff);
135
2
      return true;
136
0
    case 'N': // Integer constant (Range: -1)
137
0
      Info.setRequiresImmediate(-1);
138
0
      return true;
139
2
    case 'O': // Integer constant (Range: 8, 16, 24)
140
2
      Info.setRequiresImmediate({8, 16, 24});
141
2
      return true;
142
2
    case 'P': // Integer constant (Range: 1)
143
2
      Info.setRequiresImmediate(1);
144
2
      return true;
145
2
    case 'R': // Integer constant (Range: -6 to 5)
146
2
      Info.setRequiresImmediate(-6, 5);
147
2
      return true;
148
2
    case 'G': // Floating point constant
149
4
    case 'Q': // A memory address based on Y or Z pointer with displacement.
150
4
      return true;
151
46
    }
152
153
0
    return false;
154
46
  }
155
156
40
  IntType getIntTypeByWidth(unsigned BitWidth, bool IsSigned) const final {
157
    // AVR prefers int for 16-bit integers.
158
40
    return BitWidth == 16 ? 
(0
IsSigned0
?
SignedInt0
:
UnsignedInt0
)
159
40
                          : TargetInfo::getIntTypeByWidth(BitWidth, IsSigned);
160
40
  }
161
162
336
  IntType getLeastIntTypeByWidth(unsigned BitWidth, bool IsSigned) const final {
163
    // AVR uses int for int_least16_t and int_fast16_t.
164
336
    return BitWidth == 16
165
336
               ? 
(84
IsSigned84
?
SignedInt42
:
UnsignedInt42
)
166
336
               : 
TargetInfo::getLeastIntTypeByWidth(BitWidth, IsSigned)252
;
167
336
  }
168
169
  bool isValidCPUName(StringRef Name) const override;
170
  void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const override;
171
3
  bool setCPU(const std::string &Name) override {
172
3
    bool isValid = isValidCPUName(Name);
173
3
    if (isValid)
174
2
      CPU = Name;
175
3
    return isValid;
176
3
  }
177
178
protected:
179
  std::string CPU;
180
};
181
182
} // namespace targets
183
} // namespace clang
184
185
#endif // LLVM_CLANG_LIB_BASIC_TARGETS_AVR_H