-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[clang][OpenMP] Make getOpenMPCaptureRegionForClause
more generic
#98180
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[clang][OpenMP] Make getOpenMPCaptureRegionForClause
more generic
#98180
Conversation
Rewrite `getOpenMPCaptureRegionForClause` with more generic code, relying on directive composition instead of listing individual directives.
@llvm/pr-subscribers-clang Author: Krzysztof Parzyszek (kparzysz) ChangesRewrite Patch is 32.06 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/98180.diff 1 Files Affected:
diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index 12cd75e7102ba..bc5c172f1390e 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -14815,948 +14815,116 @@ OMPClause *SemaOpenMP::ActOnOpenMPSingleExprClause(OpenMPClauseKind Kind,
static OpenMPDirectiveKind getOpenMPCaptureRegionForClause(
OpenMPDirectiveKind DKind, OpenMPClauseKind CKind, unsigned OpenMPVersion,
OpenMPDirectiveKind NameModifier = OMPD_unknown) {
- OpenMPDirectiveKind CaptureRegion = OMPD_unknown;
+ assert(isAllowedClauseForDirective(DKind, CKind, OpenMPVersion) &&
+ "Invalid directive with CKind-clause");
+
+ // Invalid modifier will be diagnosed separately, just return OMPD_unknown.
+ if (NameModifier != OMPD_unknown &&
+ !isAllowedClauseForDirective(NameModifier, CKind, OpenMPVersion))
+ return OMPD_unknown;
+
+ ArrayRef<OpenMPDirectiveKind> Leafs = getLeafConstructsOrSelf(DKind);
+
+ // [5.2:341:24-30]
+ // If the clauses have expressions on them, such as for various clauses where
+ // the argument of the clause is an expression, or lower-bound, length, or
+ // stride expressions inside array sections (or subscript and stride
+ // expressions in subscript-triplet for Fortran), or linear-step or alignment
+ // expressions, the expressions are evaluated immediately before the construct
+ // to which the clause has been split or duplicated per the above rules
+ // (therefore inside of the outer leaf constructs). However, the expressions
+ // inside the num_teams and thread_limit clauses are always evaluated before
+ // the outermost leaf construct.
+
+ // Process special cases first.
switch (CKind) {
case OMPC_if:
switch (DKind) {
- case OMPD_target_parallel_for_simd:
- if (OpenMPVersion >= 50 &&
- (NameModifier == OMPD_unknown || NameModifier == OMPD_simd)) {
- CaptureRegion = OMPD_parallel;
- break;
- }
- [[fallthrough]];
- case OMPD_target_parallel:
- case OMPD_target_parallel_for:
- case OMPD_target_parallel_loop:
- // If this clause applies to the nested 'parallel' region, capture within
- // the 'target' region, otherwise do not capture.
- if (NameModifier == OMPD_unknown || NameModifier == OMPD_parallel)
- CaptureRegion = OMPD_target;
- break;
case OMPD_teams_loop:
case OMPD_target_teams_loop:
// For [target] teams loop, assume capture region is 'teams' so it's
// available for codegen later to use if/when necessary.
- CaptureRegion = OMPD_teams;
- break;
- case OMPD_target_teams_distribute_parallel_for_simd:
- if (OpenMPVersion >= 50 &&
- (NameModifier == OMPD_unknown || NameModifier == OMPD_simd)) {
- CaptureRegion = OMPD_parallel;
- break;
- }
- [[fallthrough]];
- case OMPD_target_teams_distribute_parallel_for:
- // If this clause applies to the nested 'parallel' region, capture within
- // the 'teams' region, otherwise do not capture.
- if (NameModifier == OMPD_unknown || NameModifier == OMPD_parallel)
- CaptureRegion = OMPD_teams;
- break;
- case OMPD_teams_distribute_parallel_for_simd:
- if (OpenMPVersion >= 50 &&
- (NameModifier == OMPD_unknown || NameModifier == OMPD_simd)) {
- CaptureRegion = OMPD_parallel;
- break;
- }
- [[fallthrough]];
- case OMPD_teams_distribute_parallel_for:
- CaptureRegion = OMPD_teams;
- break;
+ return OMPD_teams;
case OMPD_target_update:
case OMPD_target_enter_data:
case OMPD_target_exit_data:
- CaptureRegion = OMPD_task;
- break;
- case OMPD_parallel_masked_taskloop:
- if (NameModifier == OMPD_unknown || NameModifier == OMPD_taskloop)
- CaptureRegion = OMPD_parallel;
- break;
- case OMPD_parallel_master_taskloop:
- if (NameModifier == OMPD_unknown || NameModifier == OMPD_taskloop)
- CaptureRegion = OMPD_parallel;
- break;
- case OMPD_parallel_masked_taskloop_simd:
- if ((OpenMPVersion <= 45 && NameModifier == OMPD_unknown) ||
- NameModifier == OMPD_taskloop) {
- CaptureRegion = OMPD_parallel;
- break;
- }
- if (OpenMPVersion <= 45)
- break;
- if (NameModifier == OMPD_unknown || NameModifier == OMPD_simd)
- CaptureRegion = OMPD_taskloop;
- break;
- case OMPD_parallel_master_taskloop_simd:
- if ((OpenMPVersion <= 45 && NameModifier == OMPD_unknown) ||
- NameModifier == OMPD_taskloop) {
- CaptureRegion = OMPD_parallel;
- break;
- }
- if (OpenMPVersion <= 45)
- break;
- if (NameModifier == OMPD_unknown || NameModifier == OMPD_simd)
- CaptureRegion = OMPD_taskloop;
- break;
- case OMPD_parallel_for_simd:
- if (OpenMPVersion <= 45)
- break;
- if (NameModifier == OMPD_unknown || NameModifier == OMPD_simd)
- CaptureRegion = OMPD_parallel;
- break;
- case OMPD_taskloop_simd:
- case OMPD_master_taskloop_simd:
- case OMPD_masked_taskloop_simd:
- if (OpenMPVersion <= 45)
- break;
- if (NameModifier == OMPD_unknown || NameModifier == OMPD_simd)
- CaptureRegion = OMPD_taskloop;
- break;
- case OMPD_distribute_parallel_for_simd:
- if (OpenMPVersion <= 45)
- break;
- if (NameModifier == OMPD_unknown || NameModifier == OMPD_simd)
- CaptureRegion = OMPD_parallel;
- break;
- case OMPD_target_simd:
- if (OpenMPVersion >= 50 &&
- (NameModifier == OMPD_unknown || NameModifier == OMPD_simd))
- CaptureRegion = OMPD_target;
- break;
- case OMPD_teams_distribute_simd:
- case OMPD_target_teams_distribute_simd:
- if (OpenMPVersion >= 50 &&
- (NameModifier == OMPD_unknown || NameModifier == OMPD_simd))
- CaptureRegion = OMPD_teams;
- break;
- case OMPD_cancel:
- case OMPD_parallel:
- case OMPD_parallel_master:
- case OMPD_parallel_masked:
- case OMPD_parallel_sections:
- case OMPD_parallel_for:
- case OMPD_parallel_loop:
- case OMPD_target:
- case OMPD_target_teams:
- case OMPD_target_teams_distribute:
- case OMPD_distribute_parallel_for:
- case OMPD_task:
- case OMPD_taskloop:
- case OMPD_master_taskloop:
- case OMPD_masked_taskloop:
- case OMPD_target_data:
- case OMPD_simd:
- case OMPD_for_simd:
- case OMPD_distribute_simd:
- // Do not capture if-clause expressions.
- break;
- case OMPD_threadprivate:
- case OMPD_allocate:
- case OMPD_taskyield:
- case OMPD_error:
- case OMPD_barrier:
- case OMPD_taskwait:
- case OMPD_cancellation_point:
- case OMPD_flush:
- case OMPD_depobj:
- case OMPD_scan:
- case OMPD_declare_reduction:
- case OMPD_declare_mapper:
- case OMPD_declare_simd:
- case OMPD_declare_variant:
- case OMPD_begin_declare_variant:
- case OMPD_end_declare_variant:
- case OMPD_declare_target:
- case OMPD_end_declare_target:
- case OMPD_loop:
- case OMPD_teams:
- case OMPD_tile:
- case OMPD_unroll:
- case OMPD_for:
- case OMPD_sections:
- case OMPD_section:
- case OMPD_single:
- case OMPD_master:
- case OMPD_masked:
- case OMPD_critical:
- case OMPD_taskgroup:
- case OMPD_distribute:
- case OMPD_ordered:
- case OMPD_atomic:
- case OMPD_teams_distribute:
- case OMPD_requires:
- case OMPD_metadirective:
- llvm_unreachable("Unexpected OpenMP directive with if-clause");
- case OMPD_unknown:
+ return OMPD_task;
default:
- llvm_unreachable("Unknown OpenMP directive");
- }
- break;
- case OMPC_num_threads:
- switch (DKind) {
- case OMPD_target_parallel:
- case OMPD_target_parallel_for:
- case OMPD_target_parallel_for_simd:
- case OMPD_target_parallel_loop:
- CaptureRegion = OMPD_target;
- break;
- case OMPD_teams_distribute_parallel_for:
- case OMPD_teams_distribute_parallel_for_simd:
- case OMPD_target_teams_distribute_parallel_for:
- case OMPD_target_teams_distribute_parallel_for_simd:
- CaptureRegion = OMPD_teams;
- break;
- case OMPD_parallel:
- case OMPD_parallel_master:
- case OMPD_parallel_masked:
- case OMPD_parallel_sections:
- case OMPD_parallel_for:
- case OMPD_parallel_for_simd:
- case OMPD_parallel_loop:
- case OMPD_distribute_parallel_for:
- case OMPD_distribute_parallel_for_simd:
- case OMPD_parallel_master_taskloop:
- case OMPD_parallel_masked_taskloop:
- case OMPD_parallel_master_taskloop_simd:
- case OMPD_parallel_masked_taskloop_simd:
- // Do not capture num_threads-clause expressions.
break;
- case OMPD_target_data:
- case OMPD_target_enter_data:
- case OMPD_target_exit_data:
- case OMPD_target_update:
- case OMPD_target:
- case OMPD_target_simd:
- case OMPD_target_teams:
- case OMPD_target_teams_distribute:
- case OMPD_target_teams_distribute_simd:
- case OMPD_cancel:
- case OMPD_task:
- case OMPD_taskloop:
- case OMPD_taskloop_simd:
- case OMPD_master_taskloop:
- case OMPD_masked_taskloop:
- case OMPD_master_taskloop_simd:
- case OMPD_masked_taskloop_simd:
- case OMPD_threadprivate:
- case OMPD_allocate:
- case OMPD_taskyield:
- case OMPD_error:
- case OMPD_barrier:
- case OMPD_taskwait:
- case OMPD_cancellation_point:
- case OMPD_flush:
- case OMPD_depobj:
- case OMPD_scan:
- case OMPD_declare_reduction:
- case OMPD_declare_mapper:
- case OMPD_declare_simd:
- case OMPD_declare_variant:
- case OMPD_begin_declare_variant:
- case OMPD_end_declare_variant:
- case OMPD_declare_target:
- case OMPD_end_declare_target:
- case OMPD_loop:
- case OMPD_teams_loop:
- case OMPD_target_teams_loop:
- case OMPD_teams:
- case OMPD_simd:
- case OMPD_tile:
- case OMPD_unroll:
- case OMPD_for:
- case OMPD_for_simd:
- case OMPD_sections:
- case OMPD_section:
- case OMPD_single:
- case OMPD_master:
- case OMPD_masked:
- case OMPD_critical:
- case OMPD_taskgroup:
- case OMPD_distribute:
- case OMPD_ordered:
- case OMPD_atomic:
- case OMPD_distribute_simd:
- case OMPD_teams_distribute:
- case OMPD_teams_distribute_simd:
- case OMPD_requires:
- case OMPD_metadirective:
- llvm_unreachable("Unexpected OpenMP directive with num_threads-clause");
- case OMPD_unknown:
- default:
- llvm_unreachable("Unknown OpenMP directive");
}
break;
case OMPC_num_teams:
- switch (DKind) {
- case OMPD_target_teams:
- case OMPD_target_teams_distribute:
- case OMPD_target_teams_distribute_simd:
- case OMPD_target_teams_distribute_parallel_for:
- case OMPD_target_teams_distribute_parallel_for_simd:
- case OMPD_target_teams_loop:
- CaptureRegion = OMPD_target;
- break;
- case OMPD_teams_distribute_parallel_for:
- case OMPD_teams_distribute_parallel_for_simd:
- case OMPD_teams:
- case OMPD_teams_distribute:
- case OMPD_teams_distribute_simd:
- case OMPD_teams_loop:
- // Do not capture num_teams-clause expressions.
- break;
- case OMPD_distribute_parallel_for:
- case OMPD_distribute_parallel_for_simd:
- case OMPD_task:
- case OMPD_taskloop:
- case OMPD_taskloop_simd:
- case OMPD_master_taskloop:
- case OMPD_masked_taskloop:
- case OMPD_master_taskloop_simd:
- case OMPD_masked_taskloop_simd:
- case OMPD_parallel_master_taskloop:
- case OMPD_parallel_masked_taskloop:
- case OMPD_parallel_master_taskloop_simd:
- case OMPD_parallel_masked_taskloop_simd:
- case OMPD_target_data:
- case OMPD_target_enter_data:
- case OMPD_target_exit_data:
- case OMPD_target_update:
- case OMPD_cancel:
- case OMPD_parallel:
- case OMPD_parallel_master:
- case OMPD_parallel_masked:
- case OMPD_parallel_sections:
- case OMPD_parallel_for:
- case OMPD_parallel_for_simd:
- case OMPD_parallel_loop:
- case OMPD_target:
- case OMPD_target_simd:
- case OMPD_target_parallel:
- case OMPD_target_parallel_for:
- case OMPD_target_parallel_for_simd:
- case OMPD_target_parallel_loop:
- case OMPD_threadprivate:
- case OMPD_allocate:
- case OMPD_taskyield:
- case OMPD_error:
- case OMPD_barrier:
- case OMPD_taskwait:
- case OMPD_cancellation_point:
- case OMPD_flush:
- case OMPD_depobj:
- case OMPD_scan:
- case OMPD_declare_reduction:
- case OMPD_declare_mapper:
- case OMPD_declare_simd:
- case OMPD_declare_variant:
- case OMPD_begin_declare_variant:
- case OMPD_end_declare_variant:
- case OMPD_declare_target:
- case OMPD_end_declare_target:
- case OMPD_loop:
- case OMPD_simd:
- case OMPD_tile:
- case OMPD_unroll:
- case OMPD_for:
- case OMPD_for_simd:
- case OMPD_sections:
- case OMPD_section:
- case OMPD_single:
- case OMPD_master:
- case OMPD_masked:
- case OMPD_critical:
- case OMPD_taskgroup:
- case OMPD_distribute:
- case OMPD_ordered:
- case OMPD_atomic:
- case OMPD_distribute_simd:
- case OMPD_requires:
- case OMPD_metadirective:
- llvm_unreachable("Unexpected OpenMP directive with num_teams-clause");
- case OMPD_unknown:
- default:
- llvm_unreachable("Unknown OpenMP directive");
- }
- break;
case OMPC_thread_limit:
- switch (DKind) {
- case OMPD_target:
- case OMPD_target_teams:
- case OMPD_target_teams_distribute:
- case OMPD_target_teams_distribute_simd:
- case OMPD_target_teams_distribute_parallel_for:
- case OMPD_target_teams_distribute_parallel_for_simd:
- case OMPD_target_teams_loop:
- case OMPD_target_simd:
- case OMPD_target_parallel:
- case OMPD_target_parallel_for:
- case OMPD_target_parallel_for_simd:
- case OMPD_target_parallel_loop:
- CaptureRegion = OMPD_target;
- break;
- case OMPD_teams_distribute_parallel_for:
- case OMPD_teams_distribute_parallel_for_simd:
- case OMPD_teams:
- case OMPD_teams_distribute:
- case OMPD_teams_distribute_simd:
- case OMPD_teams_loop:
- // Do not capture thread_limit-clause expressions.
- break;
- case OMPD_distribute_parallel_for:
- case OMPD_distribute_parallel_for_simd:
- case OMPD_task:
- case OMPD_taskloop:
- case OMPD_taskloop_simd:
- case OMPD_master_taskloop:
- case OMPD_masked_taskloop:
- case OMPD_master_taskloop_simd:
- case OMPD_masked_taskloop_simd:
- case OMPD_parallel_master_taskloop:
- case OMPD_parallel_masked_taskloop:
- case OMPD_parallel_master_taskloop_simd:
- case OMPD_parallel_masked_taskloop_simd:
- case OMPD_target_data:
- case OMPD_target_enter_data:
- case OMPD_target_exit_data:
- case OMPD_target_update:
- case OMPD_cancel:
- case OMPD_parallel:
- case OMPD_parallel_master:
- case OMPD_parallel_masked:
- case OMPD_parallel_sections:
- case OMPD_parallel_for:
- case OMPD_parallel_for_simd:
- case OMPD_parallel_loop:
- case OMPD_threadprivate:
- case OMPD_allocate:
- case OMPD_taskyield:
- case OMPD_error:
- case OMPD_barrier:
- case OMPD_taskwait:
- case OMPD_cancellation_point:
- case OMPD_flush:
- case OMPD_depobj:
- case OMPD_scan:
- case OMPD_declare_reduction:
- case OMPD_declare_mapper:
- case OMPD_declare_simd:
- case OMPD_declare_variant:
- case OMPD_begin_declare_variant:
- case OMPD_end_declare_variant:
- case OMPD_declare_target:
- case OMPD_end_declare_target:
- case OMPD_loop:
- case OMPD_simd:
- case OMPD_tile:
- case OMPD_unroll:
- case OMPD_for:
- case OMPD_for_simd:
- case OMPD_sections:
- case OMPD_section:
- case OMPD_single:
- case OMPD_master:
- case OMPD_masked:
- case OMPD_critical:
- case OMPD_taskgroup:
- case OMPD_distribute:
- case OMPD_ordered:
- case OMPD_atomic:
- case OMPD_distribute_simd:
- case OMPD_requires:
- case OMPD_metadirective:
- llvm_unreachable("Unexpected OpenMP directive with thread_limit-clause");
- case OMPD_unknown:
- default:
- llvm_unreachable("Unknown OpenMP directive");
- }
- break;
- case OMPC_schedule:
- switch (DKind) {
- case OMPD_parallel_for:
- case OMPD_parallel_for_simd:
- case OMPD_distribute_parallel_for:
- case OMPD_distribute_parallel_for_simd:
- case OMPD_teams_distribute_parallel_for:
- case OMPD_teams_distribute_parallel_for_simd:
- case OMPD_target_parallel_for:
- case OMPD_target_parallel_for_simd:
- case OMPD_target_teams_distribute_parallel_for:
- case OMPD_target_teams_distribute_parallel_for_simd:
- CaptureRegion = OMPD_parallel;
- break;
- case OMPD_for:
- case OMPD_for_simd:
- // Do not capture schedule-clause expressions.
- break;
- case OMPD_task:
- case OMPD_taskloop:
- case OMPD_taskloop_simd:
- case OMPD_master_taskloop:
- case OMPD_masked_taskloop:
- case OMPD_master_taskloop_simd:
- case OMPD_masked_taskloop_simd:
- case OMPD_parallel_master_taskloop:
- case OMPD_parallel_masked_taskloop:
- case OMPD_parallel_master_taskloop_simd:
- case OMPD_parallel_masked_taskloop_simd:
- case OMPD_target_data:
- case OMPD_target_enter_data:
- case OMPD_target_exit_data:
- case OMPD_target_update:
- case OMPD_teams:
- case OMPD_teams_distribute:
- case OMPD_teams_distribute_simd:
- case OMPD_target_teams_distribute:
- case OMPD_target_teams_distribute_simd:
- case OMPD_target:
- case OMPD_target_simd:
- case OMPD_target_parallel:
- case OMPD_cancel:
- case OMPD_parallel:
- case OMPD_parallel_master:
- case OMPD_parallel_masked:
- case OMPD_parallel_sections:
- case OMPD_threadprivate:
- case OMPD_allocate:
- case OMPD_taskyield:
- case OMPD_error:
- case OMPD_barrier:
- case OMPD_taskwait:
- case OMPD_cancellation_point:
- case OMPD_flush:
- case OMPD_depobj:
- case OMPD_scan:
- case OMPD_declare_reduction:
- case OMPD_declare_mapper:
- case OMPD_declare_simd:
- case OMPD_declare_variant:
- case OMPD_begin_declare_variant:
- case OMPD_end_declare_variant:
- case OMPD_declare_target:
- case OMPD_end_declare_target:
- case OMPD_loop:
- case OMPD_teams_loop:
- case OMPD_target_teams_loop:
- case OMPD_parallel_loop:
- case OMPD_target_parallel_loop:
- case OMPD_simd:
- case OMPD_tile:
- case OMPD_unroll:
- case OMPD_sections:
- case OMPD_section:
- case OMPD_single:
- case OMPD_master:
- case OMPD_masked:
- case OMPD_critical:
- case OMPD_taskgroup:
- case OMPD_distribute:
- case OMPD_ordered:
- case OMPD_atomic:
- case OMPD_distribute_simd:
- case OMPD_target_teams:
- case OMPD_requires:
- case OMPD_metadirective:
- llvm_unreachable("Unexpected OpenMP directive with schedule clause");
- case OMPD_unknown:
- default:
- llvm_unreachable("Unknown OpenMP directive");
- }
- break;
- case OMPC_dist_schedule:
- switch (DKind) {
- case OMPD_teams_distribute_parallel_for:
- case OMPD_teams_distribute_parallel_for_simd:
- case OMPD_teams_distribute:
- case OMPD_teams_distribute_simd:
- case OMPD_target_teams_distribute_parallel_for:
- case OMPD_target_teams_distribute_parallel_for_simd:
- case OMPD_target_teams_distribute:
- case OMPD_target_teams_distribute_simd:
- CaptureRegion = OMPD_teams;
- break;
- case OMPD_distribute_parallel_for:
- case OMPD_distribute_parallel_for_simd:
- case OMPD_distribute:
- case OMPD_distribute_simd:
- // Do not capture dist_schedule-clause expressions.
- break;
- case OMPD_parallel_for:
- case OMPD_parallel_for_simd:
- case OMPD_target_parallel_for_simd:
- case OMPD_target_parallel_for:
- case OMPD_task:
- case OMPD_taskloop:
- case OMPD_taskloop_simd:
- case OMPD_master_taskloop:
- case OMPD_masked_taskloop:
- case OMPD_master_taskloop_simd:
- case OMPD_masked_taskloop_simd:
- case OMPD_parallel_master_taskloop:
- case OMPD_parallel_masked_taskloop:
- case OMPD_parallel_master_taskloop_simd:
- case OMPD_parallel_masked_taskloop_simd:
- case OMPD_target_data:
- case OMPD_target_enter_data:
- case OMPD_target_exit_data:
- case OMPD_target_update:
...
[truncated]
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LG
…lvm#98180) Rewrite `getOpenMPCaptureRegionForClause` with more generic code, relying on directive composition instead of listing individual directives.
Rewrite
getOpenMPCaptureRegionForClause
with more generic code, relying on directive composition instead of listing individual directives.