Skip to content

Commit d158cf6

Browse files
committed
[OPENMP5.0]Add basic support for declare variant directive.
Added basic support for declare variant directive and its match clause with user context selector. llvm-svn: 371892
1 parent f69c917 commit d158cf6

File tree

13 files changed

+804
-91
lines changed

13 files changed

+804
-91
lines changed

clang/include/clang/Basic/DiagnosticParseKinds.td

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ def err_invalid_token_after_declarator_suggest_equal : Error<
201201
"invalid %0 at end of declaration; did you mean '='?">;
202202
def err_expected_statement : Error<"expected statement">;
203203
def err_expected_lparen_after : Error<"expected '(' after '%0'">;
204+
def err_expected_lbrace_after : Error<"expected '{' after '%0'">;
204205
def err_expected_rparen_after : Error<"expected ')' after '%0'">;
205206
def err_expected_punc : Error<"expected ')' or ',' after '%0'">;
206207
def err_expected_less_after : Error<"expected '<' after '%0'">;
@@ -1177,8 +1178,8 @@ def err_omp_expected_identifier_for_critical : Error<
11771178
"expected identifier specifying the name of the 'omp critical' directive">;
11781179
def err_omp_expected_reduction_identifier : Error<
11791180
"expected identifier or one of the following operators: '+', '-', '*', '&', '|', '^', '&&', or '||'">;
1180-
def err_omp_decl_in_declare_simd : Error<
1181-
"function declaration is expected after 'declare simd' directive">;
1181+
def err_omp_decl_in_declare_simd_variant : Error<
1182+
"function declaration is expected after 'declare %select{simd|variant}0' directive">;
11821183
def err_omp_unknown_map_type : Error<
11831184
"incorrect map type, expected one of 'to', 'from', 'tofrom', 'alloc', 'release', or 'delete'">;
11841185
def err_omp_unknown_map_type_modifier : Error<
@@ -1199,6 +1200,12 @@ def err_omp_mapper_illegal_identifier : Error<
11991200
"illegal OpenMP user-defined mapper identifier">;
12001201
def err_omp_mapper_expected_declarator : Error<
12011202
"expected declarator on 'omp declare mapper' directive">;
1203+
def err_omp_declare_variant_wrong_clause : Error<
1204+
"expected '%0' clause on 'omp declare variant' directive">;
1205+
def err_omp_declare_variant_no_ctx_selector : Error<
1206+
"expected context selector in '%0' clause on 'omp declare variant' directive">;
1207+
def err_omp_declare_variant_equal_expected : Error<
1208+
"expected '=' after '%0' context selector set name on 'omp declare variant' directive">;
12021209
def warn_omp_more_one_device_type_clause : Warning<
12031210
"more than one 'device_type' clause is specified">,
12041211
InGroup<OpenMPClauses>;

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9213,10 +9213,10 @@ def err_omp_single_copyprivate_with_nowait : Error<
92139213
"the 'copyprivate' clause must not be used with the 'nowait' clause">;
92149214
def note_omp_nowait_clause_here : Note<
92159215
"'nowait' clause is here">;
9216-
def err_omp_single_decl_in_declare_simd : Error<
9217-
"single declaration is expected after 'declare simd' directive">;
9216+
def err_omp_single_decl_in_declare_simd_variant : Error<
9217+
"single declaration is expected after 'declare %select{simd|variant}0' directive">;
92189218
def err_omp_function_expected : Error<
9219-
"'#pragma omp declare simd' can only be applied to functions">;
9219+
"'#pragma omp declare %select{simd|variant}0' can only be applied to functions">;
92209220
def err_omp_wrong_cancel_region : Error<
92219221
"one of 'for', 'parallel', 'sections' or 'taskgroup' is expected">;
92229222
def err_omp_parent_cancel_region_nowait : Error<
@@ -9408,6 +9408,27 @@ def note_omp_marked_device_type_here : Note<"marked as 'device_type(%0)' here">;
94089408
def warn_omp_declare_target_after_first_use : Warning<
94099409
"declaration marked as declare target after first use, it may lead to incorrect results">,
94109410
InGroup<OpenMPTarget>;
9411+
def err_omp_declare_variant_incompat_attributes : Error<
9412+
"'#pragma omp declare variant' is not compatible with any target-specific attributes">;
9413+
def err_omp_declare_variant_after_used : Error<
9414+
"'#pragma omp declare variant' cannot be applied for function after first "
9415+
"usage">;
9416+
def err_omp_declare_variant_noproto : Error<
9417+
"function with '#pragma omp declare variant' must have a prototype">;
9418+
def note_omp_declare_variant_specified_here : Note<
9419+
"'#pragma omp declare variant' for function specified here">;
9420+
def err_omp_declare_variant_doesnt_support : Error<
9421+
"'#pragma omp declare variant' does not "
9422+
"support %select{function templates|virtual functions|"
9423+
"deduced return types|constructors|destructors|deleted functions|"
9424+
"defaulted functions|constexpr functions|consteval function}0">;
9425+
def err_omp_declare_variant_diff : Error<
9426+
"function with '#pragma omp declare variant' has a different %select{calling convention"
9427+
"|return type|constexpr specification|inline specification|storage class|"
9428+
"linkage}0">;
9429+
def err_omp_declare_variant_incompat_types : Error<
9430+
"variant in '#pragma omp declare variant' with type %0 is incompatible with type %1"
9431+
>;
94119432
} // end of OpenMP category
94129433

94139434
let CategoryName = "Related Result Type Issue" in {

clang/include/clang/Basic/OpenMPKinds.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ OPENMP_DIRECTIVE_EXT(target_teams_distribute_parallel_for, "target teams distrib
251251
OPENMP_DIRECTIVE_EXT(target_teams_distribute_parallel_for_simd, "target teams distribute parallel for simd")
252252
OPENMP_DIRECTIVE_EXT(target_teams_distribute_simd, "target teams distribute simd")
253253
OPENMP_DIRECTIVE(allocate)
254+
OPENMP_DIRECTIVE_EXT(declare_variant, "declare variant")
254255

255256
// OpenMP clauses.
256257
OPENMP_CLAUSE(allocator, OMPAllocatorClause)

clang/include/clang/Parse/Parser.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2834,6 +2834,10 @@ class Parser : public CodeCompletionHandler {
28342834
DeclGroupPtrTy ParseOMPDeclareSimdClauses(DeclGroupPtrTy Ptr,
28352835
CachedTokens &Toks,
28362836
SourceLocation Loc);
2837+
/// Parse clauses for '#pragma omp declare variant'.
2838+
DeclGroupPtrTy ParseOMPDeclareVariantClauses(DeclGroupPtrTy Ptr,
2839+
CachedTokens &Toks,
2840+
SourceLocation Loc);
28372841
/// Parse clauses for '#pragma omp declare target'.
28382842
DeclGroupPtrTy ParseOMPDeclareTargetClauses();
28392843
/// Parse '#pragma omp end declare target'.
@@ -2927,7 +2931,8 @@ class Parser : public CodeCompletionHandler {
29272931
/// Parses simple expression in parens for single-expression clauses of OpenMP
29282932
/// constructs.
29292933
/// \param RLoc Returned location of right paren.
2930-
ExprResult ParseOpenMPParensExpr(StringRef ClauseName, SourceLocation &RLoc);
2934+
ExprResult ParseOpenMPParensExpr(StringRef ClauseName, SourceLocation &RLoc,
2935+
bool IsAddressOfOperand = false);
29312936

29322937
/// Data used for parsing list of variables in OpenMP clauses.
29332938
struct OpenMPVarListDataTy {

clang/include/clang/Sema/Sema.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9090,6 +9090,15 @@ class Sema {
90909090
SourceRange SrcRange = SourceRange());
90919091

90929092
public:
9093+
/// Checks if the variant/multiversion functions are compatible.
9094+
bool areMultiversionVariantFunctionsCompatible(
9095+
const FunctionDecl *OldFD, const FunctionDecl *NewFD,
9096+
const PartialDiagnostic &NoProtoDiagID,
9097+
const PartialDiagnosticAt &NoteCausedDiagIDAt,
9098+
const PartialDiagnosticAt &NoSupportDiagIDAt,
9099+
const PartialDiagnosticAt &DiffDiagIDAt, bool TemplatesSupported,
9100+
bool ConstexprSupported);
9101+
90939102
/// Function tries to capture lambda's captured variables in the OpenMP region
90949103
/// before the original lambda is captured.
90959104
void tryCaptureOpenMPLambdas(ValueDecl *V);
@@ -9514,6 +9523,16 @@ class Sema {
95149523
ArrayRef<Expr *> Alignments, ArrayRef<Expr *> Linears,
95159524
ArrayRef<unsigned> LinModifiers, ArrayRef<Expr *> Steps, SourceRange SR);
95169525

9526+
/// Called on well-formed '\#pragma omp declare variant' after parsing of
9527+
/// the associated method/function.
9528+
/// \param DG Function declaration to which declare variant directive is
9529+
/// applied to.
9530+
/// \param VariantRef Expression that references the variant function, which
9531+
/// must be used instead of the original one, specified in \p DG.
9532+
DeclGroupPtrTy ActOnOpenMPDeclareVariantDirective(DeclGroupPtrTy DG,
9533+
Expr *VariantRef,
9534+
SourceRange SR);
9535+
95179536
OMPClause *ActOnOpenMPSingleExprClause(OpenMPClauseKind Kind,
95189537
Expr *Expr,
95199538
SourceLocation StartLoc,

clang/lib/Basic/OpenMPKinds.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -606,8 +606,6 @@ bool clang::isAllowedClauseForDirective(OpenMPDirectiveKind DKind,
606606
break;
607607
}
608608
break;
609-
case OMPD_declare_simd:
610-
break;
611609
case OMPD_cancel:
612610
switch (CKind) {
613611
#define OPENMP_CANCEL_CLAUSE(Name) \
@@ -849,6 +847,8 @@ bool clang::isAllowedClauseForDirective(OpenMPDirectiveKind DKind,
849847
case OMPD_taskwait:
850848
case OMPD_cancellation_point:
851849
case OMPD_declare_reduction:
850+
case OMPD_declare_simd:
851+
case OMPD_declare_variant:
852852
break;
853853
}
854854
return false;
@@ -1078,6 +1078,7 @@ void clang::getOpenMPCaptureRegions(
10781078
case OMPD_declare_target:
10791079
case OMPD_end_declare_target:
10801080
case OMPD_requires:
1081+
case OMPD_declare_variant:
10811082
llvm_unreachable("OpenMP Directive is not allowed");
10821083
case OMPD_unknown:
10831084
llvm_unreachable("Unknown OpenMP directive");

clang/lib/CodeGen/CGOpenMPRuntime.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6770,6 +6770,7 @@ emitNumTeamsForTargetDirective(CodeGenFunction &CGF,
67706770
case OMPD_teams_distribute_parallel_for_simd:
67716771
case OMPD_target_update:
67726772
case OMPD_declare_simd:
6773+
case OMPD_declare_variant:
67736774
case OMPD_declare_target:
67746775
case OMPD_end_declare_target:
67756776
case OMPD_declare_reduction:
@@ -7075,6 +7076,7 @@ emitNumThreadsForTargetDirective(CodeGenFunction &CGF,
70757076
case OMPD_teams_distribute_parallel_for_simd:
70767077
case OMPD_target_update:
70777078
case OMPD_declare_simd:
7079+
case OMPD_declare_variant:
70787080
case OMPD_declare_target:
70797081
case OMPD_end_declare_target:
70807082
case OMPD_declare_reduction:
@@ -8826,6 +8828,7 @@ getNestedDistributeDirective(ASTContext &Ctx, const OMPExecutableDirective &D) {
88268828
case OMPD_teams_distribute_parallel_for_simd:
88278829
case OMPD_target_update:
88288830
case OMPD_declare_simd:
8831+
case OMPD_declare_variant:
88298832
case OMPD_declare_target:
88308833
case OMPD_end_declare_target:
88318834
case OMPD_declare_reduction:
@@ -9583,6 +9586,7 @@ void CGOpenMPRuntime::scanForTargetRegionsFunctions(const Stmt *S,
95839586
case OMPD_teams_distribute_parallel_for_simd:
95849587
case OMPD_target_update:
95859588
case OMPD_declare_simd:
9589+
case OMPD_declare_variant:
95869590
case OMPD_declare_target:
95879591
case OMPD_end_declare_target:
95889592
case OMPD_declare_reduction:
@@ -10205,6 +10209,7 @@ void CGOpenMPRuntime::emitTargetDataStandAloneCall(
1020510209
case OMPD_teams_distribute_parallel_for:
1020610210
case OMPD_teams_distribute_parallel_for_simd:
1020710211
case OMPD_declare_simd:
10212+
case OMPD_declare_variant:
1020810213
case OMPD_declare_target:
1020910214
case OMPD_end_declare_target:
1021010215
case OMPD_declare_reduction:

clang/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -795,6 +795,7 @@ static bool hasNestedSPMDDirective(ASTContext &Ctx,
795795
case OMPD_teams_distribute_parallel_for_simd:
796796
case OMPD_target_update:
797797
case OMPD_declare_simd:
798+
case OMPD_declare_variant:
798799
case OMPD_declare_target:
799800
case OMPD_end_declare_target:
800801
case OMPD_declare_reduction:
@@ -865,6 +866,7 @@ static bool supportsSPMDExecutionMode(ASTContext &Ctx,
865866
case OMPD_teams_distribute_parallel_for_simd:
866867
case OMPD_target_update:
867868
case OMPD_declare_simd:
869+
case OMPD_declare_variant:
868870
case OMPD_declare_target:
869871
case OMPD_end_declare_target:
870872
case OMPD_declare_reduction:
@@ -1028,6 +1030,7 @@ static bool hasNestedLightweightDirective(ASTContext &Ctx,
10281030
case OMPD_teams_distribute_parallel_for_simd:
10291031
case OMPD_target_update:
10301032
case OMPD_declare_simd:
1033+
case OMPD_declare_variant:
10311034
case OMPD_declare_target:
10321035
case OMPD_end_declare_target:
10331036
case OMPD_declare_reduction:
@@ -1104,6 +1107,7 @@ static bool supportsLightweightRuntime(ASTContext &Ctx,
11041107
case OMPD_teams_distribute_parallel_for_simd:
11051108
case OMPD_target_update:
11061109
case OMPD_declare_simd:
1110+
case OMPD_declare_variant:
11071111
case OMPD_declare_target:
11081112
case OMPD_end_declare_target:
11091113
case OMPD_declare_reduction:

0 commit comments

Comments
 (0)