22void LoopHintAttr::printPrettyPragma(raw_ostream &OS,
24 unsigned SpellingIndex = getAttributeSpellingListIndex();
27 if (SpellingIndex == Pragma_nounroll ||
28 SpellingIndex == Pragma_nounroll_and_jam)
30 else if (SpellingIndex == Pragma_unroll ||
31 SpellingIndex == Pragma_unroll_and_jam) {
32 OS <<
' ' << getValueString(Policy);
36 assert(SpellingIndex == Pragma_clang_loop &&
"Unexpected spelling");
42std::string LoopHintAttr::getValueString(
const PrintingPolicy &Policy)
const {
43 std::string ValueName;
44 llvm::raw_string_ostream
OS(ValueName);
47 value->printPretty(OS,
nullptr, Policy);
48 else if (state == FixedWidth || state == ScalableWidth) {
50 value->printPretty(OS,
nullptr, Policy);
51 if (state == ScalableWidth)
53 }
else if (state == ScalableWidth)
57 }
else if (state == Enable)
59 else if (state ==
Full)
61 else if (state == AssumeSafety)
62 OS <<
"assume_safety";
71LoopHintAttr::getDiagnosticName(
const PrintingPolicy &Policy)
const {
72 unsigned SpellingIndex = getAttributeSpellingListIndex();
73 if (SpellingIndex == Pragma_nounroll)
74 return "#pragma nounroll";
75 else if (SpellingIndex == Pragma_unroll)
76 return "#pragma unroll" +
77 (option == UnrollCount ? getValueString(Policy) :
"");
78 else if (SpellingIndex == Pragma_nounroll_and_jam)
79 return "#pragma nounroll_and_jam";
80 else if (SpellingIndex == Pragma_unroll_and_jam)
81 return "#pragma unroll_and_jam" +
82 (option == UnrollAndJamCount ? getValueString(Policy) :
"");
84 assert(SpellingIndex == Pragma_clang_loop &&
"Unexpected spelling");
88void OMPDeclareSimdDeclAttr::printPrettyPragma(
90 if (getBranchState() != BS_Undefined)
91 OS <<
' ' << ConvertBranchStateTyToStr(getBranchState());
92 if (
auto *E = getSimdlen()) {
94 E->printPretty(OS,
nullptr, Policy);
97 if (uniforms_size() > 0) {
100 for (
auto *E : uniforms()) {
102 E->printPretty(OS,
nullptr, Policy);
107 alignments_iterator NI = alignments_begin();
108 for (
auto *E : aligneds()) {
110 E->printPretty(OS,
nullptr, Policy);
113 (*NI)->printPretty(OS,
nullptr, Policy);
118 steps_iterator I = steps_begin();
119 modifiers_iterator MI = modifiers_begin();
120 for (
auto *E : linears()) {
125 E->printPretty(OS,
nullptr, Policy);
130 (*I)->printPretty(OS,
nullptr, Policy);
138void OMPDeclareTargetDeclAttr::printPrettyPragma(
141 if (getDevType() != DT_Any)
142 OS <<
" device_type(" << ConvertDevTypeTyToStr(getDevType()) <<
")";
143 if (getMapType() != MT_To && getMapType() != MT_Enter)
144 OS <<
' ' << ConvertMapTypeTyToStr(getMapType());
145 if (
Expr *E = getIndirectExpr()) {
147 E->printPretty(OS,
nullptr, Policy);
149 }
else if (getIndirect()) {
154std::optional<OMPDeclareTargetDeclAttr *>
155OMPDeclareTargetDeclAttr::getActiveAttr(
const ValueDecl *VD) {
156 if (llvm::all_of(VD->
redecls(), [](
const Decl *D) { return !D->hasAttrs(); }))
159 OMPDeclareTargetDeclAttr *FoundAttr =
nullptr;
163 Level =
Attr->getLevel();
173std::optional<OMPDeclareTargetDeclAttr::MapTypeTy>
174OMPDeclareTargetDeclAttr::isDeclareTargetDeclaration(
const ValueDecl *VD) {
175 std::optional<OMPDeclareTargetDeclAttr *> ActiveAttr = getActiveAttr(VD);
177 return (*ActiveAttr)->getMapType();
181std::optional<OMPDeclareTargetDeclAttr::DevTypeTy>
182OMPDeclareTargetDeclAttr::getDeviceType(
const ValueDecl *VD) {
183 std::optional<OMPDeclareTargetDeclAttr *> ActiveAttr = getActiveAttr(VD);
185 return (*ActiveAttr)->getDevType();
189std::optional<SourceLocation>
190OMPDeclareTargetDeclAttr::getLocation(
const ValueDecl *VD) {
191 std::optional<OMPDeclareTargetDeclAttr *> ActiveAttr = getActiveAttr(VD);
193 return (*ActiveAttr)->getRange().getBegin();
198llvm::raw_ostream &
operator<<(llvm::raw_ostream &OS,
const OMPTraitInfo &TI);
199llvm::raw_ostream &
operator<<(llvm::raw_ostream &OS,
const OMPTraitInfo *TI);
202void OMPDeclareVariantAttr::printPrettyPragma(
204 if (
const Expr *E = getVariantFuncRef()) {
206 E->printPretty(OS,
nullptr, Policy);
209 OS <<
" match(" << traitInfos <<
")";
211 auto PrintExprs = [&
OS, &Policy](
Expr **Begin,
Expr **End) {
212 for (
Expr **I = Begin; I != End; ++I) {
213 assert(*I &&
"Expected non-null Stmt");
216 (*I)->printPretty(OS,
nullptr, Policy);
219 if (adjustArgsNothing_size()) {
220 OS <<
" adjust_args(nothing:";
221 PrintExprs(adjustArgsNothing_begin(), adjustArgsNothing_end());
224 if (adjustArgsNeedDevicePtr_size()) {
225 OS <<
" adjust_args(need_device_ptr:";
226 PrintExprs(adjustArgsNeedDevicePtr_begin(), adjustArgsNeedDevicePtr_end());
229 if (adjustArgsNeedDeviceAddr_size()) {
230 OS <<
" adjust_args(need_device_addr:";
231 PrintExprs(adjustArgsNeedDeviceAddr_begin(),
232 adjustArgsNeedDeviceAddr_end());
242 if (!I->Prefs.empty()) {
243 OS <<
"prefer_type(";
244 if (I->HasPreferAttrs) {
246 for (
const auto &P : I->Prefs) {
250 P.Fr->printPretty(OS,
nullptr, Policy);
253 bool NeedSep = P.Fr !=
nullptr;
254 for (
Expr *A : P.Attrs) {
267 for (
const auto &P : I->Prefs) {
270 P.Fr->printPretty(OS,
nullptr, Policy);
276 OS << getInteropTypeString(I);
280 if (appendArgs_size()) {
281 OS <<
" append_args(";
282 PrintInteropInfo(appendArgs_begin(), appendArgs_end());
287unsigned AlignedAttr::getAlignment(
ASTContext &Ctx)
const {
288 assert(!isAlignmentDependent());
289 if (getCachedAlignmentValue())
290 return *getCachedAlignmentValue();
293 if (!isAlignmentExpr()) {
294 QualType T = getAlignmentType()->getType();
299 T =
T.getNonReferenceType();
301 if (
T.getQualifiers().hasUnaligned())
310 return alignmentExpr->EvaluateKnownConstInt(Ctx).getZExtValue() *
327#define USE_DEFAULT_EQUALITY \
328 (std::is_same_v<T, StringRef> || std::is_same_v<T, VersionTuple> || \
329 std::is_same_v<T, IdentifierInfo *> || std::is_same_v<T, char *> || \
330 std::is_enum_v<T> || std::is_integral_v<T>)
333typename std::enable_if_t<!USE_DEFAULT_EQUALITY, bool>
339typename std::enable_if_t<USE_DEFAULT_EQUALITY, bool>
359bool equalAttrArgs(
T *A1_B,
T *A1_E,
T *A2_B,
T *A2_E,
361 if (A1_E - A1_B != A2_E - A2_B)
364 for (; A1_B != A1_E; ++A1_B, ++A2_B)
365 if (!equalAttrArgs(*A1_B, *A2_B, Context))
372bool equalAttrArgs<Attr *>(
Attr *A1,
Attr *A2,
380bool equalAttrArgs<Expr *>(
Expr *A1,
Expr *A2,
392bool equalAttrArgs<const IdentifierInfo *>(
398bool areAlignedAttrsEqual(
const AlignedAttr &A1,
const AlignedAttr &A2,
400 if (A1.getSpelling() != A2.getSpelling())
403 if (A1.isAlignmentExpr() != A2.isAlignmentExpr())
406 if (A1.isAlignmentExpr())
407 return equalAttrArgs(A1.getAlignmentExpr(), A2.getAlignmentExpr(), Context);
409 return equalAttrArgs(A1.getAlignmentType()->getType(),
410 A2.getAlignmentType()->getType(), Context);
421#define USE_DEFAULT_PROFILE \
422 (std::is_same_v<T, StringRef> || std::is_same_v<T, VersionTuple> || \
423 std::is_same_v<T, IdentifierInfo *> || \
424 std::is_same_v<T, const IdentifierInfo *> || std::is_enum_v<T> || \
425 std::is_integral_v<T>)
428typename std::enable_if_t<!USE_DEFAULT_PROFILE>
429profileAttrArg(llvm::FoldingSetNodeID &,
const ASTContext &,
T) {
430 llvm_unreachable(
"profile not implemented for this type");
434typename std::enable_if_t<USE_DEFAULT_PROFILE>
435profileAttrArg(llvm::FoldingSetNodeID &ID,
const ASTContext &,
T V) {
436 if constexpr (std::is_same_v<T, StringRef>)
438 else if constexpr (std::is_same_v<T, VersionTuple>) {
439 ID.AddInteger(
V.getMajor());
440 ID.AddInteger(
V.getMinor().value_or(0));
441 ID.AddInteger(
V.getSubminor().value_or(0));
442 ID.AddInteger(
V.getBuild().value_or(0));
443 }
else if constexpr (std::is_same_v<T, IdentifierInfo *> ||
444 std::is_same_v<T, const IdentifierInfo *>)
447 ID.AddInteger(
static_cast<long long>(
V));
451inline void profileAttrArg<ParamIdx>(llvm::FoldingSetNodeID &ID,
459inline void profileAttrArg(llvm::FoldingSetNodeID &ID,
const ASTContext &Ctx,
461 ID.AddInteger(End - Begin);
462 for (; Begin != End; ++Begin)
463 profileAttrArg(ID, Ctx, *Begin);
467inline void profileAttrArg<Attr *>(llvm::FoldingSetNodeID &ID,
470 ID.AddPointer(
nullptr);
478inline void profileAttrArg<Expr *>(llvm::FoldingSetNodeID &ID,
484inline void profileAttrArg<QualType>(llvm::FoldingSetNodeID &ID,
486 ID.AddPointer(
T.getCanonicalType().getAsOpaquePtr());
489void profileAlignedAttr(
const AlignedAttr &A, llvm::FoldingSetNodeID &ID,
491 ID.AddInteger(A.getSpellingListIndex());
492 ID.AddBoolean(A.isAlignmentExpr());
493 if (A.isAlignmentExpr())
494 profileAttrArg(ID, Ctx, A.getAlignmentExpr());
496 profileAttrArg(ID, Ctx, A.getAlignmentType()->getType());
500#include "clang/AST/AttrImpl.inc"
Defines the clang::ASTContext interface.
static StringRef getOptionName(StringRef Option, const char Delimiter='=')
C Language Family Type Representation.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
CharUnits getTypeAlignInChars(QualType T) const
Return the ABI-specified alignment of a (complete) type T, in characters.
unsigned getTargetDefaultAlignForAttributeAligned() const
Return the default alignment for attribute((aligned)) on this target, to be used if no alignment valu...
uint64_t getCharWidth() const
Return the size of the character type, in bits.
Attr - This represents one attribute.
bool isEquivalent(const Attr &Other, StructuralEquivalenceContext &Context) const
attr::Kind getKind() const
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Ctx) const
QuantityType getQuantity() const
getQuantity - Get the raw integer representation of this quantity.
Decl - This represents one declaration (or definition), e.g.
llvm::iterator_range< specific_attr_iterator< T > > specific_attrs() const
redecl_range redecls() const
Returns an iterator range for all the redeclarations of the same decl.
This represents one expression.
One of these records is kept for each identifier that is lexed.
A single parameter index whose accessors require each use to make explicit the parameter index encodi...
bool isValid() const
Is this parameter index valid?
unsigned getASTIndex() const
Get the parameter index as it would normally be encoded at the AST level of representation: zero-orig...
A (possibly-)qualified type.
void printPretty(raw_ostream &OS, PrinterHelper *Helper, const PrintingPolicy &Policy, unsigned Indentation=0, StringRef NewlineSymbol="\n", const ASTContext *Context=nullptr) const
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context, bool Canonical, bool ProfileLambdaExpr=false) const
Produce a unique representation of the given statement.
StringLiteral - This represents a string literal expression, e.g.
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
bool isEquivalent(StructuralEquivalenceContext &Context, QualType T1, QualType T2)
Determine structural equivalence of two types.
@ OS
Indicates that the tracking object is a descendant of a referenced-counted OSObject,...
Top level wrappers for InstallAPI frontend operations.
const char * getOpenMPSimpleClauseTypeName(OpenMPClauseKind Kind, unsigned Type)
const FunctionProtoType * T
@ Full
Match, but we didn't check for full match.
const StreamingDiagnostic & operator<<(const StreamingDiagnostic &DB, const ConceptReference *C)
Insertion operator for diagnostics.
U cast(CodeGen::Address addr)
Describes how types, statements, expressions, and declarations should be printed.