[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
This commit is contained in:
Reid Kleckner 2020-04-03 12:35:30 -07:00
parent e33a636e26
commit ba1ffd25c1
13 changed files with 77 additions and 63 deletions

View File

@ -43,6 +43,7 @@
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/None.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallSet.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/Casting.h"

View File

@ -16,10 +16,10 @@
#include "clang/AST/ASTFwd.h"
#include "clang/AST/AttrIterator.h"
#include "clang/AST/Decl.h"
#include "clang/AST/OpenMPClause.h"
#include "clang/AST/Type.h"
#include "clang/Basic/AttrKinds.h"
#include "clang/Basic/AttributeCommonInfo.h"
#include "clang/Basic/LangOptions.h"
#include "clang/Basic/LLVM.h"
#include "clang/Basic/OpenMPKinds.h"
#include "clang/Basic/Sanitizers.h"
@ -40,6 +40,7 @@ class Expr;
class QualType;
class FunctionDecl;
class TypeSourceInfo;
class OMPTraitInfo;
/// Attr - This represents one attribute.
class Attr : public AttributeCommonInfo {

View File

@ -5249,19 +5249,14 @@ class OMPMapClause final : public OMPMappableExprListClause<OMPMapClause>,
return getUniqueDeclarationsNum() + getTotalComponentListNum();
}
public:
/// Number of allowed map-type-modifiers.
static constexpr unsigned NumberOfModifiers =
OMPC_MAP_MODIFIER_last - OMPC_MAP_MODIFIER_unknown - 1;
private:
/// Map-type-modifiers for the 'map' clause.
OpenMPMapModifierKind MapTypeModifiers[NumberOfModifiers] = {
OpenMPMapModifierKind MapTypeModifiers[NumberOfOMPMapClauseModifiers] = {
OMPC_MAP_MODIFIER_unknown, OMPC_MAP_MODIFIER_unknown,
OMPC_MAP_MODIFIER_unknown};
/// Location of map-type-modifiers for the 'map' clause.
SourceLocation MapTypeModifiersLoc[NumberOfModifiers];
SourceLocation MapTypeModifiersLoc[NumberOfOMPMapClauseModifiers];
/// Map type for the 'map' clause.
OpenMPMapClauseKind MapType = OMPC_MAP_unknown;
@ -5330,7 +5325,7 @@ private:
/// \param I index for map-type-modifier.
/// \param T map-type-modifier for the clause.
void setMapTypeModifier(unsigned I, OpenMPMapModifierKind T) {
assert(I < NumberOfModifiers &&
assert(I < NumberOfOMPMapClauseModifiers &&
"Unexpected index to store map type modifier, exceeds array size.");
MapTypeModifiers[I] = T;
}
@ -5340,7 +5335,7 @@ private:
/// \param I index for map-type-modifier location.
/// \param TLoc map-type-modifier location.
void setMapTypeModifierLoc(unsigned I, SourceLocation TLoc) {
assert(I < NumberOfModifiers &&
assert(I < NumberOfOMPMapClauseModifiers &&
"Index to store map type modifier location exceeds array size.");
MapTypeModifiersLoc[I] = TLoc;
}
@ -5415,7 +5410,7 @@ public:
///
/// \param Cnt index for map-type-modifier.
OpenMPMapModifierKind getMapTypeModifier(unsigned Cnt) const LLVM_READONLY {
assert(Cnt < NumberOfModifiers &&
assert(Cnt < NumberOfOMPMapClauseModifiers &&
"Requested modifier exceeds the total number of modifiers.");
return MapTypeModifiers[Cnt];
}
@ -5425,7 +5420,7 @@ public:
///
/// \param Cnt index for map-type-modifier location.
SourceLocation getMapTypeModifierLoc(unsigned Cnt) const LLVM_READONLY {
assert(Cnt < NumberOfModifiers &&
assert(Cnt < NumberOfOMPMapClauseModifiers &&
"Requested modifier location exceeds total number of modifiers.");
return MapTypeModifiersLoc[Cnt];
}
@ -7144,6 +7139,19 @@ public:
#include "clang/Basic/OpenMPKinds.def"
};
struct OMPTraitProperty {
llvm::omp::TraitProperty Kind = llvm::omp::TraitProperty::invalid;
};
struct OMPTraitSelector {
Expr *ScoreOrCondition = nullptr;
llvm::omp::TraitSelector Kind = llvm::omp::TraitSelector::invalid;
llvm::SmallVector<OMPTraitProperty, 1> Properties;
};
struct OMPTraitSet {
llvm::omp::TraitSet Kind = llvm::omp::TraitSet::invalid;
llvm::SmallVector<OMPTraitSelector, 2> Selectors;
};
/// Helper data structure representing the traits in a match clause of an
/// `declare variant` or `metadirective`. The outer level is an ordered
/// collection of selector sets, each with an associated kind and an ordered
@ -7158,27 +7166,14 @@ public:
/// Reconstruct a (partial) OMPTraitInfo object from a mangled name.
OMPTraitInfo(StringRef MangledName);
struct OMPTraitProperty {
llvm::omp::TraitProperty Kind = llvm::omp::TraitProperty::invalid;
};
struct OMPTraitSelector {
Expr *ScoreOrCondition = nullptr;
llvm::omp::TraitSelector Kind = llvm::omp::TraitSelector::invalid;
llvm::SmallVector<OMPTraitProperty, 1> Properties;
};
struct OMPTraitSet {
llvm::omp::TraitSet Kind = llvm::omp::TraitSet::invalid;
llvm::SmallVector<OMPTraitSelector, 2> Selectors;
};
/// The outermost level of selector sets.
llvm::SmallVector<OMPTraitSet, 2> Sets;
bool anyScoreOrCondition(
llvm::function_ref<bool(Expr *&, bool /* IsScore */)> Cond) {
return llvm::any_of(Sets, [&](OMPTraitInfo::OMPTraitSet &Set) {
return llvm::any_of(Sets, [&](OMPTraitSet &Set) {
return llvm::any_of(
Set.Selectors, [&](OMPTraitInfo::OMPTraitSelector &Selector) {
Set.Selectors, [&](OMPTraitSelector &Selector) {
return Cond(Selector.ScoreOrCondition,
/* IsScore */ Selector.Kind !=
llvm::omp::TraitSelector::user_condition);

View File

@ -91,6 +91,10 @@ enum OpenMPMapModifierKind {
OMPC_MAP_MODIFIER_last
};
/// Number of allowed map-type-modifiers.
static constexpr unsigned NumberOfOMPMapClauseModifiers =
OMPC_MAP_MODIFIER_last - OMPC_MAP_MODIFIER_unknown - 1;
/// OpenMP modifier kind for 'to' clause.
enum OpenMPToModifierKind {
#define OPENMP_TO_MODIFIER_KIND(Name) \

View File

@ -13,7 +13,6 @@
#ifndef LLVM_CLANG_PARSE_PARSER_H
#define LLVM_CLANG_PARSE_PARSER_H
#include "clang/AST/OpenMPClause.h"
#include "clang/AST/Availability.h"
#include "clang/Basic/BitmaskEnum.h"
#include "clang/Basic/OpenMPKinds.h"
@ -24,6 +23,7 @@
#include "clang/Sema/DeclSpec.h"
#include "clang/Sema/Sema.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/Frontend/OpenMP/OMPContext.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/PrettyStackTrace.h"
#include "llvm/Support/SaveAndRestore.h"
@ -49,6 +49,10 @@ namespace clang {
class OMPClause;
class ObjCTypeParamList;
class ObjCTypeParameter;
struct OMPTraitProperty;
struct OMPTraitSelector;
struct OMPTraitSet;
class OMPTraitInfo;
/// Parser - This implements a parser for the C family of languages. After
/// parsing units of the grammar, productions are invoked to handle whatever has
@ -2936,32 +2940,32 @@ private:
/// Parse a property kind into \p TIProperty for the selector set \p Set and
/// selector \p Selector.
void parseOMPTraitPropertyKind(OMPTraitInfo::OMPTraitProperty &TIProperty,
void parseOMPTraitPropertyKind(OMPTraitProperty &TIProperty,
llvm::omp::TraitSet Set,
llvm::omp::TraitSelector Selector,
llvm::StringMap<SourceLocation> &Seen);
/// Parse a selector kind into \p TISelector for the selector set \p Set.
void parseOMPTraitSelectorKind(OMPTraitInfo::OMPTraitSelector &TISelector,
void parseOMPTraitSelectorKind(OMPTraitSelector &TISelector,
llvm::omp::TraitSet Set,
llvm::StringMap<SourceLocation> &Seen);
/// Parse a selector set kind into \p TISet.
void parseOMPTraitSetKind(OMPTraitInfo::OMPTraitSet &TISet,
void parseOMPTraitSetKind(OMPTraitSet &TISet,
llvm::StringMap<SourceLocation> &Seen);
/// Parses an OpenMP context property.
void parseOMPContextProperty(OMPTraitInfo::OMPTraitSelector &TISelector,
void parseOMPContextProperty(OMPTraitSelector &TISelector,
llvm::omp::TraitSet Set,
llvm::StringMap<SourceLocation> &Seen);
/// Parses an OpenMP context selector.
void parseOMPContextSelector(OMPTraitInfo::OMPTraitSelector &TISelector,
void parseOMPContextSelector(OMPTraitSelector &TISelector,
llvm::omp::TraitSet Set,
llvm::StringMap<SourceLocation> &SeenSelectors);
/// Parses an OpenMP context selector set.
void parseOMPContextSelectorSet(OMPTraitInfo::OMPTraitSet &TISet,
void parseOMPContextSelectorSet(OMPTraitSet &TISet,
llvm::StringMap<SourceLocation> &SeenSets);
/// Parses OpenMP context selectors.
@ -3107,9 +3111,9 @@ public:
DeclarationNameInfo ReductionOrMapperId;
int ExtraModifier = -1; ///< Additional modifier for linear, map, depend or
///< lastprivate clause.
SmallVector<OpenMPMapModifierKind, OMPMapClause::NumberOfModifiers>
SmallVector<OpenMPMapModifierKind, NumberOfOMPMapClauseModifiers>
MapTypeModifiers;
SmallVector<SourceLocation, OMPMapClause::NumberOfModifiers>
SmallVector<SourceLocation, NumberOfOMPMapClauseModifiers>
MapTypeModifiersLoc;
bool IsMapTypeImplicit = false;
SourceLocation ExtraModifierLoc;

View File

@ -58,6 +58,7 @@
#include "llvm/ADT/Optional.h"
#include "llvm/ADT/SetVector.h"
#include "llvm/ADT/SmallBitVector.h"
#include "llvm/ADT/SmallSet.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/TinyPtrVector.h"
@ -9861,8 +9862,7 @@ private:
/// The associated OpenMP context selector mangling.
std::string NameSuffix;
OMPDeclareVariantScope(OMPTraitInfo &TI)
: TI(&TI), NameSuffix(TI.getMangledName()) {}
OMPDeclareVariantScope(OMPTraitInfo &TI);
};
/// The current `omp begin/end declare variant` scopes.

View File

@ -151,6 +151,11 @@ OMPDeclareTargetDeclAttr::getDeviceType(const ValueDecl *VD) {
return llvm::None;
}
namespace clang {
llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const OMPTraitInfo &TI);
llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const OMPTraitInfo *TI);
}
void OMPDeclareVariantAttr::printPrettyPragma(
raw_ostream &OS, const PrintingPolicy &Policy) const {
if (const Expr *E = getVariantFuncRef()) {
@ -158,9 +163,7 @@ void OMPDeclareVariantAttr::printPrettyPragma(
E->printPretty(OS, nullptr, Policy);
OS << ")";
}
OS << " match(";
traitInfos->print(OS, Policy);
OS << ")";
OS << " match(" << traitInfos << ")";
}
#include "clang/AST/AttrImpl.inc"

View File

@ -1754,7 +1754,7 @@ void OMPClausePrinter::VisitOMPMapClause(OMPMapClause *Node) {
if (!Node->varlist_empty()) {
OS << "map(";
if (Node->getMapType() != OMPC_MAP_unknown) {
for (unsigned I = 0; I < OMPMapClause::NumberOfModifiers; ++I) {
for (unsigned I = 0; I < NumberOfOMPMapClauseModifiers; ++I) {
if (Node->getMapTypeModifier(I) != OMPC_MAP_MODIFIER_unknown) {
OS << getOpenMPSimpleClauseTypeName(OMPC_map,
Node->getMapTypeModifier(I));
@ -1934,14 +1934,14 @@ void OMPTraitInfo::getAsVariantMatchInfo(ASTContext &ASTCtx,
void OMPTraitInfo::print(llvm::raw_ostream &OS,
const PrintingPolicy &Policy) const {
bool FirstSet = true;
for (const OMPTraitInfo::OMPTraitSet &Set : Sets) {
for (const OMPTraitSet &Set : Sets) {
if (!FirstSet)
OS << ", ";
FirstSet = false;
OS << getOpenMPContextTraitSetName(Set.Kind) << "={";
bool FirstSelector = true;
for (const OMPTraitInfo::OMPTraitSelector &Selector : Set.Selectors) {
for (const OMPTraitSelector &Selector : Set.Selectors) {
if (!FirstSelector)
OS << ", ";
FirstSelector = false;
@ -1967,8 +1967,7 @@ void OMPTraitInfo::print(llvm::raw_ostream &OS,
}
bool FirstProperty = true;
for (const OMPTraitInfo::OMPTraitProperty &Property :
Selector.Properties) {
for (const OMPTraitProperty &Property : Selector.Properties) {
if (!FirstProperty)
OS << ", ";
FirstProperty = false;
@ -1984,9 +1983,9 @@ void OMPTraitInfo::print(llvm::raw_ostream &OS,
std::string OMPTraitInfo::getMangledName() const {
std::string MangledName;
llvm::raw_string_ostream OS(MangledName);
for (const OMPTraitInfo::OMPTraitSet &Set : Sets) {
for (const OMPTraitSet &Set : Sets) {
OS << '.' << 'S' << unsigned(Set.Kind);
for (const OMPTraitInfo::OMPTraitSelector &Selector : Set.Selectors) {
for (const OMPTraitSelector &Selector : Set.Selectors) {
bool AllowsTraitScore = false;
bool RequiresProperty = false;
@ -1998,7 +1997,7 @@ std::string OMPTraitInfo::getMangledName() const {
Selector.Kind == TraitSelector::user_condition)
continue;
for (const OMPTraitInfo::OMPTraitProperty &Property : Selector.Properties)
for (const OMPTraitProperty &Property : Selector.Properties)
OS << '.' << 'P'
<< getOpenMPContextTraitPropertyName(Property.Kind);
}

View File

@ -11,6 +11,7 @@
//===----------------------------------------------------------------------===//
#include "clang/AST/ASTContext.h"
#include "clang/AST/OpenMPClause.h"
#include "clang/AST/StmtOpenMP.h"
#include "clang/Basic/OpenMPKinds.h"
#include "clang/Basic/TargetInfo.h"
@ -865,7 +866,7 @@ static bool checkForDuplicates(Parser &P, StringRef Name,
} // namespace
void Parser::parseOMPTraitPropertyKind(
OMPTraitInfo::OMPTraitProperty &TIProperty, llvm::omp::TraitSet Set,
OMPTraitProperty &TIProperty, llvm::omp::TraitSet Set,
llvm::omp::TraitSelector Selector, llvm::StringMap<SourceLocation> &Seen) {
TIProperty.Kind = TraitProperty::invalid;
@ -934,14 +935,14 @@ void Parser::parseOMPTraitPropertyKind(
<< CONTEXT_TRAIT_LVL << listOpenMPContextTraitProperties(Set, Selector);
}
void Parser::parseOMPContextProperty(OMPTraitInfo::OMPTraitSelector &TISelector,
void Parser::parseOMPContextProperty(OMPTraitSelector &TISelector,
llvm::omp::TraitSet Set,
llvm::StringMap<SourceLocation> &Seen) {
assert(TISelector.Kind != TraitSelector::user_condition &&
"User conditions are special properties not handled here!");
SourceLocation PropertyLoc = Tok.getLocation();
OMPTraitInfo::OMPTraitProperty TIProperty;
OMPTraitProperty TIProperty;
parseOMPTraitPropertyKind(TIProperty, Set, TISelector.Kind, Seen);
// If we have an invalid property here we already issued a warning.
@ -975,7 +976,7 @@ void Parser::parseOMPContextProperty(OMPTraitInfo::OMPTraitSelector &TISelector,
}
void Parser::parseOMPTraitSelectorKind(
OMPTraitInfo::OMPTraitSelector &TISelector, llvm::omp::TraitSet Set,
OMPTraitSelector &TISelector, llvm::omp::TraitSet Set,
llvm::StringMap<SourceLocation> &Seen) {
TISelector.Kind = TraitSelector::invalid;
@ -1054,7 +1055,7 @@ static ExprResult parseContextScore(Parser &P) {
///
/// <trait-selector-name> ['('[<trait-score>] <trait-property> [, <t-p>]* ')']
void Parser::parseOMPContextSelector(
OMPTraitInfo::OMPTraitSelector &TISelector, llvm::omp::TraitSet Set,
OMPTraitSelector &TISelector, llvm::omp::TraitSet Set,
llvm::StringMap<SourceLocation> &SeenSelectors) {
unsigned short OuterPC = ParenCount;
@ -1160,7 +1161,7 @@ void Parser::parseOMPContextSelector(
BDT.consumeClose();
}
void Parser::parseOMPTraitSetKind(OMPTraitInfo::OMPTraitSet &TISet,
void Parser::parseOMPTraitSetKind(OMPTraitSet &TISet,
llvm::StringMap<SourceLocation> &Seen) {
TISet.Kind = TraitSet::invalid;
@ -1224,7 +1225,7 @@ void Parser::parseOMPTraitSetKind(OMPTraitInfo::OMPTraitSet &TISet,
///
/// <trait-set-selector-name> '=' '{' <trait-selector> [, <trait-selector>]* '}'
void Parser::parseOMPContextSelectorSet(
OMPTraitInfo::OMPTraitSet &TISet,
OMPTraitSet &TISet,
llvm::StringMap<SourceLocation> &SeenSets) {
auto OuterBC = BraceCount;
@ -1279,7 +1280,7 @@ void Parser::parseOMPContextSelectorSet(
llvm::StringMap<SourceLocation> SeenSelectors;
do {
OMPTraitInfo::OMPTraitSelector TISelector;
OMPTraitSelector TISelector;
parseOMPContextSelector(TISelector, TISet.Kind, SeenSelectors);
if (TISelector.Kind != TraitSelector::invalid &&
!TISelector.Properties.empty())
@ -1301,10 +1302,10 @@ void Parser::parseOMPContextSelectorSet(
/// Parse OpenMP context selectors:
///
/// <trait-set-selector> [, <trait-set-selector>]*
bool Parser::parseOMPContextSelectors(SourceLocation Loc, OMPTraitInfo &TI) {
bool Parser::parseOMPContextSelectors(SourceLocation Loc, OMPTraitInfo& TI) {
llvm::StringMap<SourceLocation> SeenSets;
do {
OMPTraitInfo::OMPTraitSet TISet;
OMPTraitSet TISet;
parseOMPContextSelectorSet(TISet, SeenSets);
if (TISet.Kind != TraitSet::invalid && !TISet.Selectors.empty())
TI.Sets.push_back(TISet);

View File

@ -35,6 +35,8 @@
#include "llvm/ADT/PointerEmbeddedInt.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/Frontend/OpenMP/OMPConstants.h"
#include <set>
using namespace clang;
using namespace llvm::omp;
@ -5543,6 +5545,9 @@ static void setPrototype(Sema &S, FunctionDecl *FD, FunctionDecl *FDWithProto,
FD->setParams(Params);
}
Sema::OMPDeclareVariantScope::OMPDeclareVariantScope(OMPTraitInfo &TI)
: TI(&TI), NameSuffix(TI.getMangledName()) {}
FunctionDecl *
Sema::ActOnStartOfFunctionDefinitionInOpenMPDeclareVariantScope(Scope *S,
Declarator &D) {
@ -17054,7 +17059,7 @@ OMPClause *Sema::ActOnOpenMPMapClause(
OpenMPMapModifierKind Modifiers[] = {OMPC_MAP_MODIFIER_unknown,
OMPC_MAP_MODIFIER_unknown,
OMPC_MAP_MODIFIER_unknown};
SourceLocation ModifiersLoc[OMPMapClause::NumberOfModifiers];
SourceLocation ModifiersLoc[NumberOfOMPMapClauseModifiers];
// Process map-type-modifiers, flag errors for duplicate modifiers.
unsigned Count = 0;
@ -17064,7 +17069,7 @@ OMPClause *Sema::ActOnOpenMPMapClause(
Diag(MapTypeModifiersLoc[I], diag::err_omp_duplicate_map_type_modifier);
continue;
}
assert(Count < OMPMapClause::NumberOfModifiers &&
assert(Count < NumberOfOMPMapClauseModifiers &&
"Modifiers exceed the allowed number of map type modifiers");
Modifiers[Count] = MapTypeModifiers[I];
ModifiersLoc[Count] = MapTypeModifiersLoc[I];

View File

@ -12335,7 +12335,7 @@ void OMPClauseReader::VisitOMPDeviceClause(OMPDeviceClause *C) {
void OMPClauseReader::VisitOMPMapClause(OMPMapClause *C) {
C->setLParenLoc(Record.readSourceLocation());
for (unsigned I = 0; I < OMPMapClause::NumberOfModifiers; ++I) {
for (unsigned I = 0; I < NumberOfOMPMapClauseModifiers; ++I) {
C->setMapTypeModifier(
I, static_cast<OpenMPMapModifierKind>(Record.readInt()));
C->setMapTypeModifierLoc(I, Record.readSourceLocation());

View File

@ -6403,7 +6403,7 @@ void OMPClauseWriter::VisitOMPMapClause(OMPMapClause *C) {
Record.push_back(C->getTotalComponentListNum());
Record.push_back(C->getTotalComponentsNum());
Record.AddSourceLocation(C->getLParenLoc());
for (unsigned I = 0; I < OMPMapClause::NumberOfModifiers; ++I) {
for (unsigned I = 0; I < NumberOfOMPMapClauseModifiers; ++I) {
Record.push_back(C->getMapTypeModifier(I));
Record.AddSourceLocation(C->getMapTypeModifierLoc(I));
}

View File

@ -20,6 +20,7 @@
#include "clang/Basic/SourceManager.h"
#include "clang/Lex/Lexer.h"
#include "llvm/Support/Errc.h"
#include <set>
using namespace clang;