Skip to content

Commit ba1ffd2

Browse files
committed
[OpenMP][NFC] Remove the need to include OpenMPClause.h
See rational here: https://reviews.llvm.org/D76173#1922916 Time to compile Attr.h in isolation goes from 2.6s to 1.8s. Original patch by Johannes, plus some additions from Reid to fix some clang tooling targets. Effect on transitive includes is marginal, though: $ diff -u <(sort thedeps-before.txt) <(sort thedeps-after.txt) \ | grep '^[-+] ' | sort | uniq -c | sort -nr 104 - /usr/local/google/home/rnk/llvm-project/clang/include/clang/AST/OpenMPClause.h 87 - /usr/local/google/home/rnk/llvm-project/llvm/include/llvm/Frontend/OpenMP/OMPContext.h 19 - /usr/local/google/home/rnk/llvm-project/llvm/include/llvm/ADT/SmallSet.h 19 - /usr/local/google/home/rnk/llvm-project/llvm/include/llvm/ADT/SetVector.h 14 - /usr/include/c++/9/set ... Differential Revision: https://reviews.llvm.org/D76184
1 parent e33a636 commit ba1ffd2

File tree

13 files changed

+77
-63
lines changed

13 files changed

+77
-63
lines changed

clang-tools-extra/clangd/XRefs.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#include "llvm/ADT/ArrayRef.h"
4444
#include "llvm/ADT/None.h"
4545
#include "llvm/ADT/STLExtras.h"
46+
#include "llvm/ADT/SmallSet.h"
4647
#include "llvm/ADT/StringExtras.h"
4748
#include "llvm/ADT/StringRef.h"
4849
#include "llvm/Support/Casting.h"

clang/include/clang/AST/Attr.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616
#include "clang/AST/ASTFwd.h"
1717
#include "clang/AST/AttrIterator.h"
1818
#include "clang/AST/Decl.h"
19-
#include "clang/AST/OpenMPClause.h"
2019
#include "clang/AST/Type.h"
2120
#include "clang/Basic/AttrKinds.h"
2221
#include "clang/Basic/AttributeCommonInfo.h"
22+
#include "clang/Basic/LangOptions.h"
2323
#include "clang/Basic/LLVM.h"
2424
#include "clang/Basic/OpenMPKinds.h"
2525
#include "clang/Basic/Sanitizers.h"
@@ -40,6 +40,7 @@ class Expr;
4040
class QualType;
4141
class FunctionDecl;
4242
class TypeSourceInfo;
43+
class OMPTraitInfo;
4344

4445
/// Attr - This represents one attribute.
4546
class Attr : public AttributeCommonInfo {

clang/include/clang/AST/OpenMPClause.h

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5249,19 +5249,14 @@ class OMPMapClause final : public OMPMappableExprListClause<OMPMapClause>,
52495249
return getUniqueDeclarationsNum() + getTotalComponentListNum();
52505250
}
52515251

5252-
public:
5253-
/// Number of allowed map-type-modifiers.
5254-
static constexpr unsigned NumberOfModifiers =
5255-
OMPC_MAP_MODIFIER_last - OMPC_MAP_MODIFIER_unknown - 1;
5256-
52575252
private:
52585253
/// Map-type-modifiers for the 'map' clause.
5259-
OpenMPMapModifierKind MapTypeModifiers[NumberOfModifiers] = {
5254+
OpenMPMapModifierKind MapTypeModifiers[NumberOfOMPMapClauseModifiers] = {
52605255
OMPC_MAP_MODIFIER_unknown, OMPC_MAP_MODIFIER_unknown,
52615256
OMPC_MAP_MODIFIER_unknown};
52625257

52635258
/// Location of map-type-modifiers for the 'map' clause.
5264-
SourceLocation MapTypeModifiersLoc[NumberOfModifiers];
5259+
SourceLocation MapTypeModifiersLoc[NumberOfOMPMapClauseModifiers];
52655260

52665261
/// Map type for the 'map' clause.
52675262
OpenMPMapClauseKind MapType = OMPC_MAP_unknown;
@@ -5330,7 +5325,7 @@ class OMPMapClause final : public OMPMappableExprListClause<OMPMapClause>,
53305325
/// \param I index for map-type-modifier.
53315326
/// \param T map-type-modifier for the clause.
53325327
void setMapTypeModifier(unsigned I, OpenMPMapModifierKind T) {
5333-
assert(I < NumberOfModifiers &&
5328+
assert(I < NumberOfOMPMapClauseModifiers &&
53345329
"Unexpected index to store map type modifier, exceeds array size.");
53355330
MapTypeModifiers[I] = T;
53365331
}
@@ -5340,7 +5335,7 @@ class OMPMapClause final : public OMPMappableExprListClause<OMPMapClause>,
53405335
/// \param I index for map-type-modifier location.
53415336
/// \param TLoc map-type-modifier location.
53425337
void setMapTypeModifierLoc(unsigned I, SourceLocation TLoc) {
5343-
assert(I < NumberOfModifiers &&
5338+
assert(I < NumberOfOMPMapClauseModifiers &&
53445339
"Index to store map type modifier location exceeds array size.");
53455340
MapTypeModifiersLoc[I] = TLoc;
53465341
}
@@ -5415,7 +5410,7 @@ class OMPMapClause final : public OMPMappableExprListClause<OMPMapClause>,
54155410
///
54165411
/// \param Cnt index for map-type-modifier.
54175412
OpenMPMapModifierKind getMapTypeModifier(unsigned Cnt) const LLVM_READONLY {
5418-
assert(Cnt < NumberOfModifiers &&
5413+
assert(Cnt < NumberOfOMPMapClauseModifiers &&
54195414
"Requested modifier exceeds the total number of modifiers.");
54205415
return MapTypeModifiers[Cnt];
54215416
}
@@ -5425,7 +5420,7 @@ class OMPMapClause final : public OMPMappableExprListClause<OMPMapClause>,
54255420
///
54265421
/// \param Cnt index for map-type-modifier location.
54275422
SourceLocation getMapTypeModifierLoc(unsigned Cnt) const LLVM_READONLY {
5428-
assert(Cnt < NumberOfModifiers &&
5423+
assert(Cnt < NumberOfOMPMapClauseModifiers &&
54295424
"Requested modifier location exceeds total number of modifiers.");
54305425
return MapTypeModifiersLoc[Cnt];
54315426
}
@@ -7144,6 +7139,19 @@ class OMPClausePrinter final : public OMPClauseVisitor<OMPClausePrinter> {
71447139
#include "clang/Basic/OpenMPKinds.def"
71457140
};
71467141

7142+
struct OMPTraitProperty {
7143+
llvm::omp::TraitProperty Kind = llvm::omp::TraitProperty::invalid;
7144+
};
7145+
struct OMPTraitSelector {
7146+
Expr *ScoreOrCondition = nullptr;
7147+
llvm::omp::TraitSelector Kind = llvm::omp::TraitSelector::invalid;
7148+
llvm::SmallVector<OMPTraitProperty, 1> Properties;
7149+
};
7150+
struct OMPTraitSet {
7151+
llvm::omp::TraitSet Kind = llvm::omp::TraitSet::invalid;
7152+
llvm::SmallVector<OMPTraitSelector, 2> Selectors;
7153+
};
7154+
71477155
/// Helper data structure representing the traits in a match clause of an
71487156
/// `declare variant` or `metadirective`. The outer level is an ordered
71497157
/// collection of selector sets, each with an associated kind and an ordered
@@ -7158,27 +7166,14 @@ class OMPTraitInfo {
71587166
/// Reconstruct a (partial) OMPTraitInfo object from a mangled name.
71597167
OMPTraitInfo(StringRef MangledName);
71607168

7161-
struct OMPTraitProperty {
7162-
llvm::omp::TraitProperty Kind = llvm::omp::TraitProperty::invalid;
7163-
};
7164-
struct OMPTraitSelector {
7165-
Expr *ScoreOrCondition = nullptr;
7166-
llvm::omp::TraitSelector Kind = llvm::omp::TraitSelector::invalid;
7167-
llvm::SmallVector<OMPTraitProperty, 1> Properties;
7168-
};
7169-
struct OMPTraitSet {
7170-
llvm::omp::TraitSet Kind = llvm::omp::TraitSet::invalid;
7171-
llvm::SmallVector<OMPTraitSelector, 2> Selectors;
7172-
};
7173-
71747169
/// The outermost level of selector sets.
71757170
llvm::SmallVector<OMPTraitSet, 2> Sets;
71767171

71777172
bool anyScoreOrCondition(
71787173
llvm::function_ref<bool(Expr *&, bool /* IsScore */)> Cond) {
7179-
return llvm::any_of(Sets, [&](OMPTraitInfo::OMPTraitSet &Set) {
7174+
return llvm::any_of(Sets, [&](OMPTraitSet &Set) {
71807175
return llvm::any_of(
7181-
Set.Selectors, [&](OMPTraitInfo::OMPTraitSelector &Selector) {
7176+
Set.Selectors, [&](OMPTraitSelector &Selector) {
71827177
return Cond(Selector.ScoreOrCondition,
71837178
/* IsScore */ Selector.Kind !=
71847179
llvm::omp::TraitSelector::user_condition);

clang/include/clang/Basic/OpenMPKinds.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ enum OpenMPMapModifierKind {
9191
OMPC_MAP_MODIFIER_last
9292
};
9393

94+
/// Number of allowed map-type-modifiers.
95+
static constexpr unsigned NumberOfOMPMapClauseModifiers =
96+
OMPC_MAP_MODIFIER_last - OMPC_MAP_MODIFIER_unknown - 1;
97+
9498
/// OpenMP modifier kind for 'to' clause.
9599
enum OpenMPToModifierKind {
96100
#define OPENMP_TO_MODIFIER_KIND(Name) \

clang/include/clang/Parse/Parser.h

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#ifndef LLVM_CLANG_PARSE_PARSER_H
1414
#define LLVM_CLANG_PARSE_PARSER_H
1515

16-
#include "clang/AST/OpenMPClause.h"
1716
#include "clang/AST/Availability.h"
1817
#include "clang/Basic/BitmaskEnum.h"
1918
#include "clang/Basic/OpenMPKinds.h"
@@ -24,6 +23,7 @@
2423
#include "clang/Sema/DeclSpec.h"
2524
#include "clang/Sema/Sema.h"
2625
#include "llvm/ADT/SmallVector.h"
26+
#include "llvm/Frontend/OpenMP/OMPContext.h"
2727
#include "llvm/Support/Compiler.h"
2828
#include "llvm/Support/PrettyStackTrace.h"
2929
#include "llvm/Support/SaveAndRestore.h"
@@ -49,6 +49,10 @@ namespace clang {
4949
class OMPClause;
5050
class ObjCTypeParamList;
5151
class ObjCTypeParameter;
52+
struct OMPTraitProperty;
53+
struct OMPTraitSelector;
54+
struct OMPTraitSet;
55+
class OMPTraitInfo;
5256

5357
/// Parser - This implements a parser for the C family of languages. After
5458
/// parsing units of the grammar, productions are invoked to handle whatever has
@@ -2936,32 +2940,32 @@ class Parser : public CodeCompletionHandler {
29362940

29372941
/// Parse a property kind into \p TIProperty for the selector set \p Set and
29382942
/// selector \p Selector.
2939-
void parseOMPTraitPropertyKind(OMPTraitInfo::OMPTraitProperty &TIProperty,
2943+
void parseOMPTraitPropertyKind(OMPTraitProperty &TIProperty,
29402944
llvm::omp::TraitSet Set,
29412945
llvm::omp::TraitSelector Selector,
29422946
llvm::StringMap<SourceLocation> &Seen);
29432947

29442948
/// Parse a selector kind into \p TISelector for the selector set \p Set.
2945-
void parseOMPTraitSelectorKind(OMPTraitInfo::OMPTraitSelector &TISelector,
2949+
void parseOMPTraitSelectorKind(OMPTraitSelector &TISelector,
29462950
llvm::omp::TraitSet Set,
29472951
llvm::StringMap<SourceLocation> &Seen);
29482952

29492953
/// Parse a selector set kind into \p TISet.
2950-
void parseOMPTraitSetKind(OMPTraitInfo::OMPTraitSet &TISet,
2954+
void parseOMPTraitSetKind(OMPTraitSet &TISet,
29512955
llvm::StringMap<SourceLocation> &Seen);
29522956

29532957
/// Parses an OpenMP context property.
2954-
void parseOMPContextProperty(OMPTraitInfo::OMPTraitSelector &TISelector,
2958+
void parseOMPContextProperty(OMPTraitSelector &TISelector,
29552959
llvm::omp::TraitSet Set,
29562960
llvm::StringMap<SourceLocation> &Seen);
29572961

29582962
/// Parses an OpenMP context selector.
2959-
void parseOMPContextSelector(OMPTraitInfo::OMPTraitSelector &TISelector,
2963+
void parseOMPContextSelector(OMPTraitSelector &TISelector,
29602964
llvm::omp::TraitSet Set,
29612965
llvm::StringMap<SourceLocation> &SeenSelectors);
29622966

29632967
/// Parses an OpenMP context selector set.
2964-
void parseOMPContextSelectorSet(OMPTraitInfo::OMPTraitSet &TISet,
2968+
void parseOMPContextSelectorSet(OMPTraitSet &TISet,
29652969
llvm::StringMap<SourceLocation> &SeenSets);
29662970

29672971
/// Parses OpenMP context selectors.
@@ -3107,9 +3111,9 @@ class Parser : public CodeCompletionHandler {
31073111
DeclarationNameInfo ReductionOrMapperId;
31083112
int ExtraModifier = -1; ///< Additional modifier for linear, map, depend or
31093113
///< lastprivate clause.
3110-
SmallVector<OpenMPMapModifierKind, OMPMapClause::NumberOfModifiers>
3114+
SmallVector<OpenMPMapModifierKind, NumberOfOMPMapClauseModifiers>
31113115
MapTypeModifiers;
3112-
SmallVector<SourceLocation, OMPMapClause::NumberOfModifiers>
3116+
SmallVector<SourceLocation, NumberOfOMPMapClauseModifiers>
31133117
MapTypeModifiersLoc;
31143118
bool IsMapTypeImplicit = false;
31153119
SourceLocation ExtraModifierLoc;

clang/include/clang/Sema/Sema.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
#include "llvm/ADT/Optional.h"
5959
#include "llvm/ADT/SetVector.h"
6060
#include "llvm/ADT/SmallBitVector.h"
61+
#include "llvm/ADT/SmallSet.h"
6162
#include "llvm/ADT/SmallPtrSet.h"
6263
#include "llvm/ADT/SmallVector.h"
6364
#include "llvm/ADT/TinyPtrVector.h"
@@ -9861,8 +9862,7 @@ class Sema final {
98619862
/// The associated OpenMP context selector mangling.
98629863
std::string NameSuffix;
98639864

9864-
OMPDeclareVariantScope(OMPTraitInfo &TI)
9865-
: TI(&TI), NameSuffix(TI.getMangledName()) {}
9865+
OMPDeclareVariantScope(OMPTraitInfo &TI);
98669866
};
98679867

98689868
/// The current `omp begin/end declare variant` scopes.

clang/lib/AST/AttrImpl.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,16 +151,19 @@ OMPDeclareTargetDeclAttr::getDeviceType(const ValueDecl *VD) {
151151
return llvm::None;
152152
}
153153

154+
namespace clang {
155+
llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const OMPTraitInfo &TI);
156+
llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const OMPTraitInfo *TI);
157+
}
158+
154159
void OMPDeclareVariantAttr::printPrettyPragma(
155160
raw_ostream &OS, const PrintingPolicy &Policy) const {
156161
if (const Expr *E = getVariantFuncRef()) {
157162
OS << "(";
158163
E->printPretty(OS, nullptr, Policy);
159164
OS << ")";
160165
}
161-
OS << " match(";
162-
traitInfos->print(OS, Policy);
163-
OS << ")";
166+
OS << " match(" << traitInfos << ")";
164167
}
165168

166169
#include "clang/AST/AttrImpl.inc"

clang/lib/AST/OpenMPClause.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1754,7 +1754,7 @@ void OMPClausePrinter::VisitOMPMapClause(OMPMapClause *Node) {
17541754
if (!Node->varlist_empty()) {
17551755
OS << "map(";
17561756
if (Node->getMapType() != OMPC_MAP_unknown) {
1757-
for (unsigned I = 0; I < OMPMapClause::NumberOfModifiers; ++I) {
1757+
for (unsigned I = 0; I < NumberOfOMPMapClauseModifiers; ++I) {
17581758
if (Node->getMapTypeModifier(I) != OMPC_MAP_MODIFIER_unknown) {
17591759
OS << getOpenMPSimpleClauseTypeName(OMPC_map,
17601760
Node->getMapTypeModifier(I));
@@ -1934,14 +1934,14 @@ void OMPTraitInfo::getAsVariantMatchInfo(ASTContext &ASTCtx,
19341934
void OMPTraitInfo::print(llvm::raw_ostream &OS,
19351935
const PrintingPolicy &Policy) const {
19361936
bool FirstSet = true;
1937-
for (const OMPTraitInfo::OMPTraitSet &Set : Sets) {
1937+
for (const OMPTraitSet &Set : Sets) {
19381938
if (!FirstSet)
19391939
OS << ", ";
19401940
FirstSet = false;
19411941
OS << getOpenMPContextTraitSetName(Set.Kind) << "={";
19421942

19431943
bool FirstSelector = true;
1944-
for (const OMPTraitInfo::OMPTraitSelector &Selector : Set.Selectors) {
1944+
for (const OMPTraitSelector &Selector : Set.Selectors) {
19451945
if (!FirstSelector)
19461946
OS << ", ";
19471947
FirstSelector = false;
@@ -1967,8 +1967,7 @@ void OMPTraitInfo::print(llvm::raw_ostream &OS,
19671967
}
19681968

19691969
bool FirstProperty = true;
1970-
for (const OMPTraitInfo::OMPTraitProperty &Property :
1971-
Selector.Properties) {
1970+
for (const OMPTraitProperty &Property : Selector.Properties) {
19721971
if (!FirstProperty)
19731972
OS << ", ";
19741973
FirstProperty = false;
@@ -1984,9 +1983,9 @@ void OMPTraitInfo::print(llvm::raw_ostream &OS,
19841983
std::string OMPTraitInfo::getMangledName() const {
19851984
std::string MangledName;
19861985
llvm::raw_string_ostream OS(MangledName);
1987-
for (const OMPTraitInfo::OMPTraitSet &Set : Sets) {
1986+
for (const OMPTraitSet &Set : Sets) {
19881987
OS << '.' << 'S' << unsigned(Set.Kind);
1989-
for (const OMPTraitInfo::OMPTraitSelector &Selector : Set.Selectors) {
1988+
for (const OMPTraitSelector &Selector : Set.Selectors) {
19901989

19911990
bool AllowsTraitScore = false;
19921991
bool RequiresProperty = false;
@@ -1998,7 +1997,7 @@ std::string OMPTraitInfo::getMangledName() const {
19981997
Selector.Kind == TraitSelector::user_condition)
19991998
continue;
20001999

2001-
for (const OMPTraitInfo::OMPTraitProperty &Property : Selector.Properties)
2000+
for (const OMPTraitProperty &Property : Selector.Properties)
20022001
OS << '.' << 'P'
20032002
<< getOpenMPContextTraitPropertyName(Property.Kind);
20042003
}

0 commit comments

Comments
 (0)