Skip to content

Commit 26d254f

Browse files
committed
Sink more Attr.h inline methods, NFC
This has very little impact on build time, but is a mechanical pre-req to removing the OpenMPClause.h include, which matters. Most of these pretty print methods require Expr to be complete.
1 parent 1ef0d66 commit 26d254f

File tree

5 files changed

+158
-128
lines changed

5 files changed

+158
-128
lines changed

clang/include/clang/AST/Attr.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,9 @@
1313
#ifndef LLVM_CLANG_AST_ATTR_H
1414
#define LLVM_CLANG_AST_ATTR_H
1515

16-
#include "clang/AST/ASTContextAllocate.h" // For Attrs.inc
16+
#include "clang/AST/ASTFwd.h"
1717
#include "clang/AST/AttrIterator.h"
1818
#include "clang/AST/Decl.h"
19-
#include "clang/AST/Expr.h"
2019
#include "clang/AST/OpenMPClause.h"
2120
#include "clang/AST/Type.h"
2221
#include "clang/Basic/AttrKinds.h"

clang/include/clang/Basic/Attr.td

Lines changed: 8 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -3130,57 +3130,14 @@ def LoopHint : Attr {
31303130
llvm_unreachable("Unhandled LoopHint option.");
31313131
}
31323132

3133-
void printPrettyPragma(raw_ostream &OS, const PrintingPolicy &Policy) const {
3134-
unsigned SpellingIndex = getAttributeSpellingListIndex();
3135-
// For "#pragma unroll" and "#pragma nounroll" the string "unroll" or
3136-
// "nounroll" is already emitted as the pragma name.
3137-
if (SpellingIndex == Pragma_nounroll || SpellingIndex == Pragma_nounroll_and_jam)
3138-
return;
3139-
else if (SpellingIndex == Pragma_unroll || SpellingIndex == Pragma_unroll_and_jam) {
3140-
OS << ' ' << getValueString(Policy);
3141-
return;
3142-
}
3143-
3144-
assert(SpellingIndex == Pragma_clang_loop && "Unexpected spelling");
3145-
OS << ' ' << getOptionName(option) << getValueString(Policy);
3146-
}
3133+
void printPrettyPragma(raw_ostream &OS, const PrintingPolicy &Policy) const;
31473134

31483135
// Return a string containing the loop hint argument including the
31493136
// enclosing parentheses.
3150-
std::string getValueString(const PrintingPolicy &Policy) const {
3151-
std::string ValueName;
3152-
llvm::raw_string_ostream OS(ValueName);
3153-
OS << "(";
3154-
if (state == Numeric)
3155-
value->printPretty(OS, nullptr, Policy);
3156-
else if (state == Enable)
3157-
OS << "enable";
3158-
else if (state == Full)
3159-
OS << "full";
3160-
else if (state == AssumeSafety)
3161-
OS << "assume_safety";
3162-
else
3163-
OS << "disable";
3164-
OS << ")";
3165-
return OS.str();
3166-
}
3137+
std::string getValueString(const PrintingPolicy &Policy) const;
31673138

31683139
// Return a string suitable for identifying this attribute in diagnostics.
3169-
std::string getDiagnosticName(const PrintingPolicy &Policy) const {
3170-
unsigned SpellingIndex = getAttributeSpellingListIndex();
3171-
if (SpellingIndex == Pragma_nounroll)
3172-
return "#pragma nounroll";
3173-
else if (SpellingIndex == Pragma_unroll)
3174-
return "#pragma unroll" + (option == UnrollCount ? getValueString(Policy) : "");
3175-
else if (SpellingIndex == Pragma_nounroll_and_jam)
3176-
return "#pragma nounroll_and_jam";
3177-
else if (SpellingIndex == Pragma_unroll_and_jam)
3178-
return "#pragma unroll_and_jam" +
3179-
(option == UnrollAndJamCount ? getValueString(Policy) : "");
3180-
3181-
assert(SpellingIndex == Pragma_clang_loop && "Unexpected spelling");
3182-
return getOptionName(option) + getValueString(Policy);
3183-
}
3140+
std::string getDiagnosticName(const PrintingPolicy &Policy) const;
31843141
}];
31853142

31863143
let Documentation = [LoopHintDocs, UnrollHintDocs];
@@ -3240,53 +3197,7 @@ def OMPDeclareSimdDecl : Attr {
32403197
];
32413198
let AdditionalMembers = [{
32423199
void printPrettyPragma(raw_ostream & OS, const PrintingPolicy &Policy)
3243-
const {
3244-
if (getBranchState() != BS_Undefined)
3245-
OS << ' ' << ConvertBranchStateTyToStr(getBranchState());
3246-
if (auto *E = getSimdlen()) {
3247-
OS << " simdlen(";
3248-
E->printPretty(OS, nullptr, Policy);
3249-
OS << ")";
3250-
}
3251-
if (uniforms_size() > 0) {
3252-
OS << " uniform";
3253-
StringRef Sep = "(";
3254-
for (auto *E : uniforms()) {
3255-
OS << Sep;
3256-
E->printPretty(OS, nullptr, Policy);
3257-
Sep = ", ";
3258-
}
3259-
OS << ")";
3260-
}
3261-
alignments_iterator NI = alignments_begin();
3262-
for (auto *E : aligneds()) {
3263-
OS << " aligned(";
3264-
E->printPretty(OS, nullptr, Policy);
3265-
if (*NI) {
3266-
OS << ": ";
3267-
(*NI)->printPretty(OS, nullptr, Policy);
3268-
}
3269-
OS << ")";
3270-
++NI;
3271-
}
3272-
steps_iterator I = steps_begin();
3273-
modifiers_iterator MI = modifiers_begin();
3274-
for (auto *E : linears()) {
3275-
OS << " linear(";
3276-
if (*MI != OMPC_LINEAR_unknown)
3277-
OS << getOpenMPSimpleClauseTypeName(OMPC_linear, *MI) << "(";
3278-
E->printPretty(OS, nullptr, Policy);
3279-
if (*MI != OMPC_LINEAR_unknown)
3280-
OS << ")";
3281-
if (*I) {
3282-
OS << ": ";
3283-
(*I)->printPretty(OS, nullptr, Policy);
3284-
}
3285-
OS << ")";
3286-
++I;
3287-
++MI;
3288-
}
3289-
}
3200+
const;
32903201
}];
32913202
}
32923203

@@ -3304,30 +3215,10 @@ def OMPDeclareTargetDecl : InheritableAttr {
33043215
[ "DT_Host", "DT_NoHost", "DT_Any" ]>
33053216
];
33063217
let AdditionalMembers = [{
3307-
void printPrettyPragma(raw_ostream &OS, const PrintingPolicy &Policy) const {
3308-
// Use fake syntax because it is for testing and debugging purpose only.
3309-
if (getDevType() != DT_Any)
3310-
OS << " device_type(" << ConvertDevTypeTyToStr(getDevType()) << ")";
3311-
if (getMapType() != MT_To)
3312-
OS << ' ' << ConvertMapTypeTyToStr(getMapType());
3313-
}
3218+
void printPrettyPragma(raw_ostream &OS, const PrintingPolicy &Policy) const;
33143219
static llvm::Optional<MapTypeTy>
3315-
isDeclareTargetDeclaration(const ValueDecl *VD) {
3316-
if (!VD->hasAttrs())
3317-
return llvm::None;
3318-
if (const auto *Attr = VD->getAttr<OMPDeclareTargetDeclAttr>())
3319-
return Attr->getMapType();
3320-
3321-
return llvm::None;
3322-
}
3323-
static llvm::Optional<DevTypeTy> getDeviceType(const ValueDecl *VD) {
3324-
if (!VD->hasAttrs())
3325-
return llvm::None;
3326-
if (const auto *Attr = VD->getAttr<OMPDeclareTargetDeclAttr>())
3327-
return Attr->getDevType();
3328-
3329-
return llvm::None;
3330-
}
3220+
isDeclareTargetDeclaration(const ValueDecl *VD);
3221+
static llvm::Optional<DevTypeTy> getDeviceType(const ValueDecl *VD);
33313222
}];
33323223
}
33333224

@@ -3368,16 +3259,7 @@ def OMPDeclareVariant : InheritableAttr {
33683259
let AdditionalMembers = [{
33693260
OMPTraitInfo &getTraitInfo() { return traitInfos; }
33703261
void printPrettyPragma(raw_ostream & OS, const PrintingPolicy &Policy)
3371-
const {
3372-
if (const Expr *E = getVariantFuncRef()) {
3373-
OS << "(";
3374-
E->printPretty(OS, nullptr, Policy);
3375-
OS << ")";
3376-
}
3377-
OS << " match(";
3378-
traitInfos.print(OS, Policy);
3379-
OS << ")";
3380-
}
3262+
const;
33813263
}];
33823264
}
33833265

clang/lib/AST/AttrImpl.cpp

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,151 @@
1616
#include "clang/AST/Type.h"
1717
using namespace clang;
1818

19+
void LoopHintAttr::printPrettyPragma(raw_ostream &OS,
20+
const PrintingPolicy &Policy) const {
21+
unsigned SpellingIndex = getAttributeSpellingListIndex();
22+
// For "#pragma unroll" and "#pragma nounroll" the string "unroll" or
23+
// "nounroll" is already emitted as the pragma name.
24+
if (SpellingIndex == Pragma_nounroll ||
25+
SpellingIndex == Pragma_nounroll_and_jam)
26+
return;
27+
else if (SpellingIndex == Pragma_unroll ||
28+
SpellingIndex == Pragma_unroll_and_jam) {
29+
OS << ' ' << getValueString(Policy);
30+
return;
31+
}
32+
33+
assert(SpellingIndex == Pragma_clang_loop && "Unexpected spelling");
34+
OS << ' ' << getOptionName(option) << getValueString(Policy);
35+
}
36+
37+
// Return a string containing the loop hint argument including the
38+
// enclosing parentheses.
39+
std::string LoopHintAttr::getValueString(const PrintingPolicy &Policy) const {
40+
std::string ValueName;
41+
llvm::raw_string_ostream OS(ValueName);
42+
OS << "(";
43+
if (state == Numeric)
44+
value->printPretty(OS, nullptr, Policy);
45+
else if (state == Enable)
46+
OS << "enable";
47+
else if (state == Full)
48+
OS << "full";
49+
else if (state == AssumeSafety)
50+
OS << "assume_safety";
51+
else
52+
OS << "disable";
53+
OS << ")";
54+
return OS.str();
55+
}
56+
57+
// Return a string suitable for identifying this attribute in diagnostics.
58+
std::string
59+
LoopHintAttr::getDiagnosticName(const PrintingPolicy &Policy) const {
60+
unsigned SpellingIndex = getAttributeSpellingListIndex();
61+
if (SpellingIndex == Pragma_nounroll)
62+
return "#pragma nounroll";
63+
else if (SpellingIndex == Pragma_unroll)
64+
return "#pragma unroll" +
65+
(option == UnrollCount ? getValueString(Policy) : "");
66+
else if (SpellingIndex == Pragma_nounroll_and_jam)
67+
return "#pragma nounroll_and_jam";
68+
else if (SpellingIndex == Pragma_unroll_and_jam)
69+
return "#pragma unroll_and_jam" +
70+
(option == UnrollAndJamCount ? getValueString(Policy) : "");
71+
72+
assert(SpellingIndex == Pragma_clang_loop && "Unexpected spelling");
73+
return getOptionName(option) + getValueString(Policy);
74+
}
75+
76+
void OMPDeclareSimdDeclAttr::printPrettyPragma(
77+
raw_ostream &OS, const PrintingPolicy &Policy) const {
78+
if (getBranchState() != BS_Undefined)
79+
OS << ' ' << ConvertBranchStateTyToStr(getBranchState());
80+
if (auto *E = getSimdlen()) {
81+
OS << " simdlen(";
82+
E->printPretty(OS, nullptr, Policy);
83+
OS << ")";
84+
}
85+
if (uniforms_size() > 0) {
86+
OS << " uniform";
87+
StringRef Sep = "(";
88+
for (auto *E : uniforms()) {
89+
OS << Sep;
90+
E->printPretty(OS, nullptr, Policy);
91+
Sep = ", ";
92+
}
93+
OS << ")";
94+
}
95+
alignments_iterator NI = alignments_begin();
96+
for (auto *E : aligneds()) {
97+
OS << " aligned(";
98+
E->printPretty(OS, nullptr, Policy);
99+
if (*NI) {
100+
OS << ": ";
101+
(*NI)->printPretty(OS, nullptr, Policy);
102+
}
103+
OS << ")";
104+
++NI;
105+
}
106+
steps_iterator I = steps_begin();
107+
modifiers_iterator MI = modifiers_begin();
108+
for (auto *E : linears()) {
109+
OS << " linear(";
110+
if (*MI != OMPC_LINEAR_unknown)
111+
OS << getOpenMPSimpleClauseTypeName(OMPC_linear, *MI) << "(";
112+
E->printPretty(OS, nullptr, Policy);
113+
if (*MI != OMPC_LINEAR_unknown)
114+
OS << ")";
115+
if (*I) {
116+
OS << ": ";
117+
(*I)->printPretty(OS, nullptr, Policy);
118+
}
119+
OS << ")";
120+
++I;
121+
++MI;
122+
}
123+
}
124+
125+
void OMPDeclareTargetDeclAttr::printPrettyPragma(
126+
raw_ostream &OS, const PrintingPolicy &Policy) const {
127+
// Use fake syntax because it is for testing and debugging purpose only.
128+
if (getDevType() != DT_Any)
129+
OS << " device_type(" << ConvertDevTypeTyToStr(getDevType()) << ")";
130+
if (getMapType() != MT_To)
131+
OS << ' ' << ConvertMapTypeTyToStr(getMapType());
132+
}
133+
134+
llvm::Optional<OMPDeclareTargetDeclAttr::MapTypeTy>
135+
OMPDeclareTargetDeclAttr::isDeclareTargetDeclaration(const ValueDecl *VD) {
136+
if (!VD->hasAttrs())
137+
return llvm::None;
138+
if (const auto *Attr = VD->getAttr<OMPDeclareTargetDeclAttr>())
139+
return Attr->getMapType();
140+
141+
return llvm::None;
142+
}
143+
144+
llvm::Optional<OMPDeclareTargetDeclAttr::DevTypeTy>
145+
OMPDeclareTargetDeclAttr::getDeviceType(const ValueDecl *VD) {
146+
if (!VD->hasAttrs())
147+
return llvm::None;
148+
if (const auto *Attr = VD->getAttr<OMPDeclareTargetDeclAttr>())
149+
return Attr->getDevType();
150+
151+
return llvm::None;
152+
}
153+
154+
void OMPDeclareVariantAttr::printPrettyPragma(
155+
raw_ostream &OS, const PrintingPolicy &Policy) const {
156+
if (const Expr *E = getVariantFuncRef()) {
157+
OS << "(";
158+
E->printPretty(OS, nullptr, Policy);
159+
OS << ")";
160+
}
161+
OS << " match(";
162+
traitInfos.print(OS, Policy);
163+
OS << ")";
164+
}
165+
19166
#include "clang/AST/AttrImpl.inc"

clang/lib/AST/OpenMPClause.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#include "clang/AST/OpenMPClause.h"
1414
#include "clang/AST/ASTContext.h"
15+
#include "clang/AST/Attr.h"
1516
#include "clang/AST/Decl.h"
1617
#include "clang/AST/DeclOpenMP.h"
1718
#include "clang/Basic/LLVM.h"

clang/lib/CodeGen/CGLoopInfo.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "CGLoopInfo.h"
1010
#include "clang/AST/ASTContext.h"
1111
#include "clang/AST/Attr.h"
12+
#include "clang/AST/Expr.h"
1213
#include "llvm/IR/BasicBlock.h"
1314
#include "llvm/IR/CFG.h"
1415
#include "llvm/IR/Constants.h"

0 commit comments

Comments
 (0)