Coverage Report

Created: 2020-10-24 06:27

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/AST/AttrImpl.cpp
Line
Count
Source (jump to first uncovered line)
1
//===--- AttrImpl.cpp - Classes for representing attributes -----*- 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 contains out-of-line methods for Attr classes.
10
//
11
//===----------------------------------------------------------------------===//
12
13
#include "clang/AST/ASTContext.h"
14
#include "clang/AST/Attr.h"
15
#include "clang/AST/Expr.h"
16
#include "clang/AST/Type.h"
17
using namespace clang;
18
19
void LoopHintAttr::printPrettyPragma(raw_ostream &OS,
20
46
                                     const PrintingPolicy &Policy) const {
21
46
  unsigned SpellingIndex = getAttributeSpellingListIndex();
22
  // For "#pragma unroll" and "#pragma nounroll" the string "unroll" or
23
  // "nounroll" is already emitted as the pragma name.
24
46
  if (SpellingIndex == Pragma_nounroll ||
25
45
      SpellingIndex == Pragma_nounroll_and_jam)
26
1
    return;
27
45
  else if (SpellingIndex == Pragma_unroll ||
28
43
           SpellingIndex == Pragma_unroll_and_jam) {
29
2
    OS << ' ' << getValueString(Policy);
30
2
    return;
31
2
  }
32
33
43
  assert(SpellingIndex == Pragma_clang_loop && "Unexpected spelling");
34
43
  OS << ' ' << getOptionName(option) << getValueString(Policy);
35
43
}
36
37
// Return a string containing the loop hint argument including the
38
// enclosing parentheses.
39
93
std::string LoopHintAttr::getValueString(const PrintingPolicy &Policy) const {
40
93
  std::string ValueName;
41
93
  llvm::raw_string_ostream OS(ValueName);
42
93
  OS << "(";
43
93
  if (state == Numeric)
44
42
    value->printPretty(OS, nullptr, Policy);
45
51
  else if (state == Enable)
46
19
    OS << "enable";
47
32
  else if (state == Full)
48
5
    OS << "full";
49
27
  else if (state == AssumeSafety)
50
2
    OS << "assume_safety";
51
25
  else
52
25
    OS << "disable";
53
93
  OS << ")";
54
93
  return OS.str();
55
93
}
56
57
// Return a string suitable for identifying this attribute in diagnostics.
58
std::string
59
56
LoopHintAttr::getDiagnosticName(const PrintingPolicy &Policy) const {
60
56
  unsigned SpellingIndex = getAttributeSpellingListIndex();
61
56
  if (SpellingIndex == Pragma_nounroll)
62
3
    return "#pragma nounroll";
63
53
  else if (SpellingIndex == Pragma_unroll)
64
10
    return "#pragma unroll" +
65
6
           (option == UnrollCount ? getValueString(Policy) : 
""4
);
66
43
  else if (SpellingIndex == Pragma_nounroll_and_jam)
67
1
    return "#pragma nounroll_and_jam";
68
42
  else if (SpellingIndex == Pragma_unroll_and_jam)
69
1
    return "#pragma unroll_and_jam" +
70
1
           (option == UnrollAndJamCount ? getValueString(Policy) : 
""0
);
71
72
41
  assert(SpellingIndex == Pragma_clang_loop && "Unexpected spelling");
73
41
  return getOptionName(option) + getValueString(Policy);
74
41
}
75
76
void OMPDeclareSimdDeclAttr::printPrettyPragma(
77
100
    raw_ostream &OS, const PrintingPolicy &Policy) const {
78
100
  if (getBranchState() != BS_Undefined)
79
16
    OS << ' ' << ConvertBranchStateTyToStr(getBranchState());
80
100
  if (auto *E = getSimdlen()) {
81
28
    OS << " simdlen(";
82
28
    E->printPretty(OS, nullptr, Policy);
83
28
    OS << ")";
84
28
  }
85
100
  if (uniforms_size() > 0) {
86
20
    OS << " uniform";
87
20
    StringRef Sep = "(";
88
36
    for (auto *E : uniforms()) {
89
36
      OS << Sep;
90
36
      E->printPretty(OS, nullptr, Policy);
91
36
      Sep = ", ";
92
36
    }
93
20
    OS << ")";
94
20
  }
95
100
  alignments_iterator NI = alignments_begin();
96
80
  for (auto *E : aligneds()) {
97
80
    OS << " aligned(";
98
80
    E->printPretty(OS, nullptr, Policy);
99
80
    if (*NI) {
100
44
      OS << ": ";
101
44
      (*NI)->printPretty(OS, nullptr, Policy);
102
44
    }
103
80
    OS << ")";
104
80
    ++NI;
105
80
  }
106
100
  steps_iterator I = steps_begin();
107
100
  modifiers_iterator MI = modifiers_begin();
108
52
  for (auto *E : linears()) {
109
52
    OS << " linear(";
110
52
    if (*MI != OMPC_LINEAR_unknown)
111
52
      OS << getOpenMPSimpleClauseTypeName(llvm::omp::Clause::OMPC_linear, *MI)
112
52
         << "(";
113
52
    E->printPretty(OS, nullptr, Policy);
114
52
    if (*MI != OMPC_LINEAR_unknown)
115
52
      OS << ")";
116
52
    if (*I) {
117
44
      OS << ": ";
118
44
      (*I)->printPretty(OS, nullptr, Policy);
119
44
    }
120
52
    OS << ")";
121
52
    ++I;
122
52
    ++MI;
123
52
  }
124
100
}
125
126
void OMPDeclareTargetDeclAttr::printPrettyPragma(
127
230
    raw_ostream &OS, const PrintingPolicy &Policy) const {
128
  // Use fake syntax because it is for testing and debugging purpose only.
129
230
  if (getDevType() != DT_Any)
130
14
    OS << " device_type(" << ConvertDevTypeTyToStr(getDevType()) << ")";
131
230
  if (getMapType() != MT_To)
132
28
    OS << ' ' << ConvertMapTypeTyToStr(getMapType());
133
230
}
134
135
llvm::Optional<OMPDeclareTargetDeclAttr::MapTypeTy>
136
539k
OMPDeclareTargetDeclAttr::isDeclareTargetDeclaration(const ValueDecl *VD) {
137
539k
  if (!VD->hasAttrs())
138
480k
    return llvm::None;
139
58.8k
  unsigned Level = 0;
140
58.8k
  const OMPDeclareTargetDeclAttr *FoundAttr = nullptr;
141
12.3k
  for (const auto *Attr : VD->specific_attrs<OMPDeclareTargetDeclAttr>()) {
142
12.3k
    if (Level < Attr->getLevel()) {
143
12.3k
      Level = Attr->getLevel();
144
12.3k
      FoundAttr = Attr;
145
12.3k
    }
146
12.3k
  }
147
58.8k
  if (FoundAttr)
148
12.2k
    return FoundAttr->getMapType();
149
150
46.6k
  return llvm::None;
151
46.6k
}
152
153
llvm::Optional<OMPDeclareTargetDeclAttr::DevTypeTy>
154
351k
OMPDeclareTargetDeclAttr::getDeviceType(const ValueDecl *VD) {
155
351k
  if (!VD->hasAttrs())
156
283k
    return llvm::None;
157
67.9k
  unsigned Level = 0;
158
67.9k
  const OMPDeclareTargetDeclAttr *FoundAttr = nullptr;
159
9.57k
  for (const auto *Attr : VD->specific_attrs<OMPDeclareTargetDeclAttr>()) {
160
9.57k
    if (Level < Attr->getLevel()) {
161
9.57k
      Level = Attr->getLevel();
162
9.57k
      FoundAttr = Attr;
163
9.57k
    }
164
9.57k
  }
165
67.9k
  if (FoundAttr)
166
9.56k
    return FoundAttr->getDevType();
167
168
58.4k
  return llvm::None;
169
58.4k
}
170
171
llvm::Optional<SourceLocation>
172
381
OMPDeclareTargetDeclAttr::getLocation(const ValueDecl *VD) {
173
381
  if (!VD->hasAttrs())
174
297
    return llvm::None;
175
84
  unsigned Level = 0;
176
84
  const OMPDeclareTargetDeclAttr *FoundAttr = nullptr;
177
84
  for (const auto *Attr : VD->specific_attrs<OMPDeclareTargetDeclAttr>()) {
178
84
    if (Level < Attr->getLevel()) {
179
84
      Level = Attr->getLevel();
180
84
      FoundAttr = Attr;
181
84
    }
182
84
  }
183
84
  if (FoundAttr)
184
84
    return FoundAttr->getRange().getBegin();
185
186
0
  return llvm::None;
187
0
}
188
189
namespace clang {
190
llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const OMPTraitInfo &TI);
191
llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const OMPTraitInfo *TI);
192
}
193
194
void OMPDeclareVariantAttr::printPrettyPragma(
195
80
    raw_ostream &OS, const PrintingPolicy &Policy) const {
196
80
  if (const Expr *E = getVariantFuncRef()) {
197
80
    OS << "(";
198
80
    E->printPretty(OS, nullptr, Policy);
199
80
    OS << ")";
200
80
  }
201
80
  OS << " match(" << traitInfos << ")";
202
80
}
203
204
#include "clang/AST/AttrImpl.inc"