[clang] 129904d - [OpenMP][NFC] Use OMPInteropInfo in the OMPDeclareVariantAttr attribute
Mike Rice via cfe-commits
cfe-commits at lists.llvm.org
Mon Aug 22 10:49:22 PDT 2022
Author: Mike Rice
Date: 2022-08-22T10:41:16-07:00
New Revision: 129904d5041ffad13747fd0ad77e44050d6c6aaa
URL: https://github.com/llvm/llvm-project/commit/129904d5041ffad13747fd0ad77e44050d6c6aaa
DIFF: https://github.com/llvm/llvm-project/commit/129904d5041ffad13747fd0ad77e44050d6c6aaa.diff
LOG: [OpenMP][NFC] Use OMPInteropInfo in the OMPDeclareVariantAttr attribute
In preparation for allowing the prefer_type list in the append_args clause,
use the OMPInteropInfo in the attribute for 'declare variant'.
This requires adding a new Argument kind to the attribute code. This change
adds a specific attribute to pass an array of OMPInteropInfo. It implements
new tablegen needed to handle the interop-type part of the structure. When
prefer_type is added, more work will be needed to dump, instantiate, and
serialize the PreferTypes field in OMPInteropInfo.
Differential Revision: https://reviews.llvm.org/D132270
Added:
Modified:
clang/include/clang/AST/OpenMPClause.h
clang/include/clang/Basic/Attr.td
clang/include/clang/Basic/OpenMPKinds.h
clang/include/clang/Parse/Parser.h
clang/include/clang/Sema/Sema.h
clang/lib/AST/AttrImpl.cpp
clang/lib/Parse/ParseOpenMP.cpp
clang/lib/Sema/SemaOpenMP.cpp
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
clang/lib/Sema/TreeTransform.h
clang/lib/Serialization/ASTReaderDecl.cpp
clang/utils/TableGen/ClangAttrEmitter.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/AST/OpenMPClause.h b/clang/include/clang/AST/OpenMPClause.h
index a3982d7ba0aeb..fd6f50e31bfe1 100644
--- a/clang/include/clang/AST/OpenMPClause.h
+++ b/clang/include/clang/AST/OpenMPClause.h
@@ -7709,13 +7709,6 @@ class OMPOrderClause final : public OMPClause {
}
};
-/// Contains 'interop' data for 'append_args' and 'init' clauses.
-struct OMPInteropInfo final {
- bool IsTarget = false;
- bool IsTargetSync = false;
- llvm::SmallVector<Expr *, 4> PreferTypes;
-};
-
/// This represents the 'init' clause in '#pragma omp ...' directives.
///
/// \code
diff --git a/clang/include/clang/Basic/Attr.td b/clang/include/clang/Basic/Attr.td
index 670af57c3def5..e504596a2067c 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -221,6 +221,7 @@ class DeclArgument<DeclNode kind, string name, bit opt = 0, bit fake = 0>
// OMPTraitProperty := {Kind}
//
class OMPTraitInfoArgument<string name> : Argument<name, 0>;
+class VariadicOMPInteropInfoArgument<string name> : Argument<name, 0>;
class TypeArgument<string name, bit opt = 0> : Argument<name, opt>;
class UnsignedArgument<string name, bit opt = 0> : Argument<name, opt>;
@@ -3827,14 +3828,19 @@ def OMPDeclareVariant : InheritableAttr {
OMPTraitInfoArgument<"TraitInfos">,
VariadicExprArgument<"AdjustArgsNothing">,
VariadicExprArgument<"AdjustArgsNeedDevicePtr">,
- VariadicEnumArgument<"AppendArgs", "InteropType",
- ["target", "targetsync", "target,targetsync"],
- ["Target", "TargetSync", "Target_TargetSync"]>
+ VariadicOMPInteropInfoArgument<"AppendArgs">,
];
let AdditionalMembers = [{
OMPTraitInfo &getTraitInfo() { return *traitInfos; }
void printPrettyPragma(raw_ostream & OS, const PrintingPolicy &Policy)
const;
+ static StringRef getInteropTypeString(const OMPInteropInfo *I) {
+ if (I->IsTarget && I->IsTargetSync)
+ return "target,targetsync";
+ if (I->IsTarget)
+ return "target";
+ return "targetsync";
+ }
}];
}
diff --git a/clang/include/clang/Basic/OpenMPKinds.h b/clang/include/clang/Basic/OpenMPKinds.h
index e95a717f268df..82875aa0fafa6 100644
--- a/clang/include/clang/Basic/OpenMPKinds.h
+++ b/clang/include/clang/Basic/OpenMPKinds.h
@@ -181,6 +181,16 @@ enum OpenMPBindClauseKind {
OMPC_BIND_unknown
};
+/// Contains 'interop' data for 'append_args' and 'init' clauses.
+class Expr;
+struct OMPInteropInfo final {
+ OMPInteropInfo(bool IsTarget = false, bool IsTargetSync = false)
+ : IsTarget(IsTarget), IsTargetSync(IsTargetSync) {}
+ bool IsTarget;
+ bool IsTargetSync;
+ llvm::SmallVector<Expr *, 4> PreferTypes;
+};
+
unsigned getOpenMPSimpleClauseType(OpenMPClauseKind Kind, llvm::StringRef Str,
const LangOptions &LangOpts);
const char *getOpenMPSimpleClauseTypeName(OpenMPClauseKind Kind, unsigned Type);
diff --git a/clang/include/clang/Parse/Parser.h b/clang/include/clang/Parse/Parser.h
index 3dd92f08bff1f..690a56bf66142 100644
--- a/clang/include/clang/Parse/Parser.h
+++ b/clang/include/clang/Parse/Parser.h
@@ -3180,8 +3180,7 @@ class Parser : public CodeCompletionHandler {
bool parseOMPContextSelectors(SourceLocation Loc, OMPTraitInfo &TI);
/// Parse an 'append_args' clause for '#pragma omp declare variant'.
- bool parseOpenMPAppendArgs(
- SmallVectorImpl<OMPDeclareVariantAttr::InteropType> &InterOpTypes);
+ bool parseOpenMPAppendArgs(SmallVectorImpl<OMPInteropInfo> &InteropInfos);
/// Parse a `match` clause for an '#pragma omp declare variant'. Return true
/// if there was an error.
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index c6c298eca9c18..3e9a748346250 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -11393,9 +11393,8 @@ class Sema final {
FunctionDecl *FD, Expr *VariantRef, OMPTraitInfo &TI,
ArrayRef<Expr *> AdjustArgsNothing,
ArrayRef<Expr *> AdjustArgsNeedDevicePtr,
- ArrayRef<OMPDeclareVariantAttr::InteropType> AppendArgs,
- SourceLocation AdjustArgsLoc, SourceLocation AppendArgsLoc,
- SourceRange SR);
+ ArrayRef<OMPInteropInfo> AppendArgs, SourceLocation AdjustArgsLoc,
+ SourceLocation AppendArgsLoc, SourceRange SR);
OMPClause *ActOnOpenMPSingleExprClause(OpenMPClauseKind Kind,
Expr *Expr,
diff --git a/clang/lib/AST/AttrImpl.cpp b/clang/lib/AST/AttrImpl.cpp
index deb28bee5ed8c..cecbd703ac61e 100644
--- a/clang/lib/AST/AttrImpl.cpp
+++ b/clang/lib/AST/AttrImpl.cpp
@@ -222,18 +222,18 @@ void OMPDeclareVariantAttr::printPrettyPragma(
OS << ")";
}
- auto PrintInteropTypes = [&OS](InteropType *Begin, InteropType *End) {
- for (InteropType *I = Begin; I != End; ++I) {
+ auto PrintInteropInfo = [&OS](OMPInteropInfo *Begin, OMPInteropInfo *End) {
+ for (OMPInteropInfo *I = Begin; I != End; ++I) {
if (I != Begin)
OS << ", ";
OS << "interop(";
- OS << ConvertInteropTypeToStr(*I);
+ OS << getInteropTypeString(I);
OS << ")";
}
};
if (appendArgs_size()) {
OS << " append_args(";
- PrintInteropTypes(appendArgs_begin(), appendArgs_end());
+ PrintInteropInfo(appendArgs_begin(), appendArgs_end());
OS << ")";
}
}
diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp
index e0707c63a9c96..6f8a467b9a657 100644
--- a/clang/lib/Parse/ParseOpenMP.cpp
+++ b/clang/lib/Parse/ParseOpenMP.cpp
@@ -1419,7 +1419,7 @@ void Parser::ParseOMPDeclareVariantClauses(Parser::DeclGroupPtrTy Ptr,
OMPTraitInfo &TI = ASTCtx.getNewOMPTraitInfo();
SmallVector<Expr *, 6> AdjustNothing;
SmallVector<Expr *, 6> AdjustNeedDevicePtr;
- SmallVector<OMPDeclareVariantAttr::InteropType, 3> AppendArgs;
+ SmallVector<OMPInteropInfo, 3> AppendArgs;
SourceLocation AdjustArgsLoc, AppendArgsLoc;
// At least one clause is required.
@@ -1503,7 +1503,7 @@ void Parser::ParseOMPDeclareVariantClauses(Parser::DeclGroupPtrTy Ptr,
}
bool Parser::parseOpenMPAppendArgs(
- SmallVectorImpl<OMPDeclareVariantAttr::InteropType> &InterOpTypes) {
+ SmallVectorImpl<OMPInteropInfo> &InteropInfos) {
bool HasError = false;
// Parse '('.
BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end);
@@ -1521,26 +1521,16 @@ bool Parser::parseOpenMPAppendArgs(
return true;
OMPInteropInfo InteropInfo;
- if (ParseOMPInteropInfo(InteropInfo, OMPC_append_args)) {
+ if (ParseOMPInteropInfo(InteropInfo, OMPC_append_args))
HasError = true;
- } else {
- OMPDeclareVariantAttr::InteropType IT;
- // As of OpenMP 5.1, there are two interop-types, "target" and
- // "targetsync". Either or both are allowed for a single interop.
- if (InteropInfo.IsTarget && InteropInfo.IsTargetSync)
- IT = OMPDeclareVariantAttr::Target_TargetSync;
- else if (InteropInfo.IsTarget)
- IT = OMPDeclareVariantAttr::Target;
- else
- IT = OMPDeclareVariantAttr::TargetSync;
- InterOpTypes.push_back(IT);
- }
+ else
+ InteropInfos.push_back(InteropInfo);
IT.consumeClose();
if (Tok.is(tok::comma))
ConsumeToken();
}
- if (!HasError && InterOpTypes.empty()) {
+ if (!HasError && InteropInfos.empty()) {
HasError = true;
Diag(Tok.getLocation(), diag::err_omp_unexpected_append_op);
SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end,
diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index 4f1f690093276..a8de8c2f2c829 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -7585,9 +7585,8 @@ void Sema::ActOnOpenMPDeclareVariantDirective(
FunctionDecl *FD, Expr *VariantRef, OMPTraitInfo &TI,
ArrayRef<Expr *> AdjustArgsNothing,
ArrayRef<Expr *> AdjustArgsNeedDevicePtr,
- ArrayRef<OMPDeclareVariantAttr::InteropType> AppendArgs,
- SourceLocation AdjustArgsLoc, SourceLocation AppendArgsLoc,
- SourceRange SR) {
+ ArrayRef<OMPInteropInfo> AppendArgs, SourceLocation AdjustArgsLoc,
+ SourceLocation AppendArgsLoc, SourceRange SR) {
// OpenMP 5.1 [2.3.5, declare variant directive, Restrictions]
// An adjust_args clause or append_args clause can only be specified if the
@@ -7647,8 +7646,7 @@ void Sema::ActOnOpenMPDeclareVariantDirective(
AdjustArgsNothing.size(),
const_cast<Expr **>(AdjustArgsNeedDevicePtr.data()),
AdjustArgsNeedDevicePtr.size(),
- const_cast<OMPDeclareVariantAttr::InteropType *>(AppendArgs.data()),
- AppendArgs.size(), SR);
+ const_cast<OMPInteropInfo *>(AppendArgs.data()), AppendArgs.size(), SR);
FD->addAttr(NewAttr);
}
diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index 140844ca4e811..cce054d11dc8b 100644
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -506,7 +506,7 @@ static void instantiateOMPDeclareVariantAttr(
SmallVector<Expr *, 8> NothingExprs;
SmallVector<Expr *, 8> NeedDevicePtrExprs;
- SmallVector<OMPDeclareVariantAttr::InteropType, 8> AppendArgs;
+ SmallVector<OMPInteropInfo, 4> AppendArgs;
for (Expr *E : Attr.adjustArgsNothing()) {
ExprResult ER = Subst(E);
@@ -520,7 +520,10 @@ static void instantiateOMPDeclareVariantAttr(
continue;
NeedDevicePtrExprs.push_back(ER.get());
}
- llvm::append_range(AppendArgs, Attr.appendArgs());
+ for (OMPInteropInfo &II : Attr.appendArgs()) {
+ // When prefer_type is implemented for append_args handle them here too.
+ AppendArgs.emplace_back(II.IsTarget, II.IsTargetSync);
+ }
S.ActOnOpenMPDeclareVariantDirective(
FD, E, TI, NothingExprs, NeedDevicePtrExprs, AppendArgs, SourceLocation(),
diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index c5337deed7ad9..9fde9ce8582d1 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -9671,9 +9671,7 @@ OMPClause *TreeTransform<Derived>::TransformOMPInitClause(OMPInitClause *C) {
if (IVR.isInvalid())
return nullptr;
- OMPInteropInfo InteropInfo;
- InteropInfo.IsTarget = C->getIsTarget();
- InteropInfo.IsTargetSync = C->getIsTargetSync();
+ OMPInteropInfo InteropInfo(C->getIsTarget(), C->getIsTargetSync());
InteropInfo.PreferTypes.reserve(C->varlist_size() - 1);
for (Expr *E : llvm::drop_begin(C->varlists())) {
ExprResult ER = getDerived().TransformExpr(cast<Expr>(E));
diff --git a/clang/lib/Serialization/ASTReaderDecl.cpp b/clang/lib/Serialization/ASTReaderDecl.cpp
index 73800191dfc1b..674b524a00e38 100644
--- a/clang/lib/Serialization/ASTReaderDecl.cpp
+++ b/clang/lib/Serialization/ASTReaderDecl.cpp
@@ -2859,6 +2859,8 @@ class AttrReader {
return Reader.readInt();
}
+ bool readBool() { return Reader.readBool(); }
+
SourceRange readSourceRange() {
return Reader.readSourceRange();
}
diff --git a/clang/utils/TableGen/ClangAttrEmitter.cpp b/clang/utils/TableGen/ClangAttrEmitter.cpp
index e5ab1129d1790..374e18ec823cd 100644
--- a/clang/utils/TableGen/ClangAttrEmitter.cpp
+++ b/clang/utils/TableGen/ClangAttrEmitter.cpp
@@ -806,6 +806,49 @@ namespace {
}
};
+ class VariadicOMPInteropInfoArgument : public VariadicArgument {
+ public:
+ VariadicOMPInteropInfoArgument(const Record &Arg, StringRef Attr)
+ : VariadicArgument(Arg, Attr, "OMPInteropInfo") {}
+
+ void writeDump(raw_ostream &OS) const override {
+ OS << " for (" << getAttrName() << "Attr::" << getLowerName()
+ << "_iterator I = SA->" << getLowerName() << "_begin(), E = SA->"
+ << getLowerName() << "_end(); I != E; ++I) {\n";
+ OS << " if (I->IsTarget && I->IsTargetSync)\n";
+ OS << " OS << \" Target_TargetSync\";\n";
+ OS << " else if (I->IsTarget)\n";
+ OS << " OS << \" Target\";\n";
+ OS << " else\n";
+ OS << " OS << \" TargetSync\";\n";
+ OS << " }\n";
+ }
+
+ void writePCHReadDecls(raw_ostream &OS) const override {
+ OS << " unsigned " << getLowerName() << "Size = Record.readInt();\n";
+ OS << " SmallVector<OMPInteropInfo, 4> " << getLowerName() << ";\n";
+ OS << " " << getLowerName() << ".reserve(" << getLowerName()
+ << "Size);\n";
+ OS << " for (unsigned I = 0, E = " << getLowerName() << "Size; ";
+ OS << "I != E; ++I) {\n";
+ OS << " bool IsTarget = Record.readBool();\n";
+ OS << " bool IsTargetSync = Record.readBool();\n";
+ OS << " " << getLowerName()
+ << ".emplace_back(IsTarget, IsTargetSync);\n";
+ OS << " }\n";
+ }
+
+ void writePCHWrite(raw_ostream &OS) const override {
+ OS << " Record.push_back(SA->" << getLowerName() << "_size());\n";
+ OS << " for (" << getAttrName() << "Attr::" << getLowerName()
+ << "_iterator I = SA->" << getLowerName() << "_begin(), E = SA->"
+ << getLowerName() << "_end(); I != E; ++I) {\n";
+ OS << " Record.writeBool(I->IsTarget);\n";
+ OS << " Record.writeBool(I->IsTargetSync);\n";
+ OS << " }\n";
+ }
+ };
+
class VariadicParamIdxArgument : public VariadicArgument {
public:
VariadicParamIdxArgument(const Record &Arg, StringRef Attr)
@@ -1374,6 +1417,8 @@ createArgument(const Record &Arg, StringRef Attr,
Ptr = std::make_unique<VersionArgument>(Arg, Attr);
else if (ArgName == "OMPTraitInfoArgument")
Ptr = std::make_unique<SimpleArgument>(Arg, Attr, "OMPTraitInfo *");
+ else if (ArgName == "VariadicOMPInteropInfoArgument")
+ Ptr = std::make_unique<VariadicOMPInteropInfoArgument>(Arg, Attr);
if (!Ptr) {
// Search in reverse order so that the most-derived type is handled first.
More information about the cfe-commits
mailing list