1 //===--- OpenMPKinds.cpp - Token Kinds Support ----------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 /// \file 9 /// This file implements the OpenMP enum and support functions. 10 /// 11 //===----------------------------------------------------------------------===// 12 13 #include "clang/Basic/OpenMPKinds.h" 14 #include "clang/Basic/IdentifierTable.h" 15 #include "llvm/ADT/StringRef.h" 16 #include "llvm/ADT/StringSwitch.h" 17 #include "llvm/Support/ErrorHandling.h" 18 #include <cassert> 19 20 using namespace clang; 21 using namespace llvm::omp; 22 23 unsigned clang::getOpenMPSimpleClauseType(OpenMPClauseKind Kind, 24 StringRef Str) { 25 switch (Kind) { 26 case OMPC_default: 27 return llvm::StringSwitch<unsigned>(Str) 28 #define OMP_DEFAULT_KIND(Enum, Name) .Case(Name, unsigned(Enum)) 29 #include "llvm/Frontend/OpenMP/OMPKinds.def" 30 .Default(unsigned(llvm::omp::OMP_DEFAULT_unknown)); 31 case OMPC_proc_bind: 32 return llvm::StringSwitch<unsigned>(Str) 33 #define OMP_PROC_BIND_KIND(Enum, Name, Value) .Case(Name, Value) 34 #include "llvm/Frontend/OpenMP/OMPKinds.def" 35 .Default(unsigned(llvm::omp::OMP_PROC_BIND_unknown)); 36 case OMPC_schedule: 37 return llvm::StringSwitch<unsigned>(Str) 38 #define OPENMP_SCHEDULE_KIND(Name) \ 39 .Case(#Name, static_cast<unsigned>(OMPC_SCHEDULE_##Name)) 40 #define OPENMP_SCHEDULE_MODIFIER(Name) \ 41 .Case(#Name, static_cast<unsigned>(OMPC_SCHEDULE_MODIFIER_##Name)) 42 #include "clang/Basic/OpenMPKinds.def" 43 .Default(OMPC_SCHEDULE_unknown); 44 case OMPC_depend: 45 return llvm::StringSwitch<OpenMPDependClauseKind>(Str) 46 #define OPENMP_DEPEND_KIND(Name) .Case(#Name, OMPC_DEPEND_##Name) 47 #include "clang/Basic/OpenMPKinds.def" 48 .Default(OMPC_DEPEND_unknown); 49 case OMPC_linear: 50 return llvm::StringSwitch<OpenMPLinearClauseKind>(Str) 51 #define OPENMP_LINEAR_KIND(Name) .Case(#Name, OMPC_LINEAR_##Name) 52 #include "clang/Basic/OpenMPKinds.def" 53 .Default(OMPC_LINEAR_unknown); 54 case OMPC_map: 55 return llvm::StringSwitch<unsigned>(Str) 56 #define OPENMP_MAP_KIND(Name) \ 57 .Case(#Name, static_cast<unsigned>(OMPC_MAP_##Name)) 58 #define OPENMP_MAP_MODIFIER_KIND(Name) \ 59 .Case(#Name, static_cast<unsigned>(OMPC_MAP_MODIFIER_##Name)) 60 #include "clang/Basic/OpenMPKinds.def" 61 .Default(OMPC_MAP_unknown); 62 case OMPC_to: 63 return llvm::StringSwitch<unsigned>(Str) 64 #define OPENMP_TO_MODIFIER_KIND(Name) \ 65 .Case(#Name, static_cast<unsigned>(OMPC_TO_MODIFIER_##Name)) 66 #include "clang/Basic/OpenMPKinds.def" 67 .Default(OMPC_TO_MODIFIER_unknown); 68 case OMPC_from: 69 return llvm::StringSwitch<unsigned>(Str) 70 #define OPENMP_FROM_MODIFIER_KIND(Name) \ 71 .Case(#Name, static_cast<unsigned>(OMPC_FROM_MODIFIER_##Name)) 72 #include "clang/Basic/OpenMPKinds.def" 73 .Default(OMPC_FROM_MODIFIER_unknown); 74 case OMPC_dist_schedule: 75 return llvm::StringSwitch<OpenMPDistScheduleClauseKind>(Str) 76 #define OPENMP_DIST_SCHEDULE_KIND(Name) .Case(#Name, OMPC_DIST_SCHEDULE_##Name) 77 #include "clang/Basic/OpenMPKinds.def" 78 .Default(OMPC_DIST_SCHEDULE_unknown); 79 case OMPC_defaultmap: 80 return llvm::StringSwitch<unsigned>(Str) 81 #define OPENMP_DEFAULTMAP_KIND(Name) \ 82 .Case(#Name, static_cast<unsigned>(OMPC_DEFAULTMAP_##Name)) 83 #define OPENMP_DEFAULTMAP_MODIFIER(Name) \ 84 .Case(#Name, static_cast<unsigned>(OMPC_DEFAULTMAP_MODIFIER_##Name)) 85 #include "clang/Basic/OpenMPKinds.def" 86 .Default(OMPC_DEFAULTMAP_unknown); 87 case OMPC_atomic_default_mem_order: 88 return llvm::StringSwitch<OpenMPAtomicDefaultMemOrderClauseKind>(Str) 89 #define OPENMP_ATOMIC_DEFAULT_MEM_ORDER_KIND(Name) \ 90 .Case(#Name, OMPC_ATOMIC_DEFAULT_MEM_ORDER_##Name) 91 #include "clang/Basic/OpenMPKinds.def" 92 .Default(OMPC_ATOMIC_DEFAULT_MEM_ORDER_unknown); 93 case OMPC_device_type: 94 return llvm::StringSwitch<OpenMPDeviceType>(Str) 95 #define OPENMP_DEVICE_TYPE_KIND(Name) .Case(#Name, OMPC_DEVICE_TYPE_##Name) 96 #include "clang/Basic/OpenMPKinds.def" 97 .Default(OMPC_DEVICE_TYPE_unknown); 98 case OMPC_lastprivate: 99 return llvm::StringSwitch<OpenMPLastprivateModifier>(Str) 100 #define OPENMP_LASTPRIVATE_KIND(Name) .Case(#Name, OMPC_LASTPRIVATE_##Name) 101 #include "clang/Basic/OpenMPKinds.def" 102 .Default(OMPC_LASTPRIVATE_unknown); 103 case OMPC_order: 104 return llvm::StringSwitch<OpenMPOrderClauseKind>(Str) 105 #define OPENMP_ORDER_KIND(Name) .Case(#Name, OMPC_ORDER_##Name) 106 #include "clang/Basic/OpenMPKinds.def" 107 .Default(OMPC_ORDER_unknown); 108 case OMPC_update: 109 return llvm::StringSwitch<OpenMPDependClauseKind>(Str) 110 #define OPENMP_DEPEND_KIND(Name) .Case(#Name, OMPC_DEPEND_##Name) 111 #include "clang/Basic/OpenMPKinds.def" 112 .Default(OMPC_DEPEND_unknown); 113 case OMPC_device: 114 return llvm::StringSwitch<OpenMPDeviceClauseModifier>(Str) 115 #define OPENMP_DEVICE_MODIFIER(Name) .Case(#Name, OMPC_DEVICE_##Name) 116 #include "clang/Basic/OpenMPKinds.def" 117 .Default(OMPC_DEVICE_unknown); 118 case OMPC_reduction: 119 return llvm::StringSwitch<OpenMPReductionClauseModifier>(Str) 120 #define OPENMP_REDUCTION_MODIFIER(Name) .Case(#Name, OMPC_REDUCTION_##Name) 121 #include "clang/Basic/OpenMPKinds.def" 122 .Default(OMPC_REDUCTION_unknown); 123 case OMPC_unknown: 124 case OMPC_threadprivate: 125 case OMPC_if: 126 case OMPC_final: 127 case OMPC_num_threads: 128 case OMPC_safelen: 129 case OMPC_simdlen: 130 case OMPC_allocator: 131 case OMPC_allocate: 132 case OMPC_collapse: 133 case OMPC_private: 134 case OMPC_firstprivate: 135 case OMPC_shared: 136 case OMPC_task_reduction: 137 case OMPC_in_reduction: 138 case OMPC_aligned: 139 case OMPC_copyin: 140 case OMPC_copyprivate: 141 case OMPC_ordered: 142 case OMPC_nowait: 143 case OMPC_untied: 144 case OMPC_mergeable: 145 case OMPC_flush: 146 case OMPC_depobj: 147 case OMPC_read: 148 case OMPC_write: 149 case OMPC_capture: 150 case OMPC_seq_cst: 151 case OMPC_acq_rel: 152 case OMPC_acquire: 153 case OMPC_release: 154 case OMPC_relaxed: 155 case OMPC_threads: 156 case OMPC_simd: 157 case OMPC_num_teams: 158 case OMPC_thread_limit: 159 case OMPC_priority: 160 case OMPC_grainsize: 161 case OMPC_nogroup: 162 case OMPC_num_tasks: 163 case OMPC_hint: 164 case OMPC_uniform: 165 case OMPC_use_device_ptr: 166 case OMPC_use_device_addr: 167 case OMPC_is_device_ptr: 168 case OMPC_unified_address: 169 case OMPC_unified_shared_memory: 170 case OMPC_reverse_offload: 171 case OMPC_dynamic_allocators: 172 case OMPC_match: 173 case OMPC_nontemporal: 174 case OMPC_destroy: 175 case OMPC_detach: 176 case OMPC_inclusive: 177 case OMPC_exclusive: 178 case OMPC_uses_allocators: 179 case OMPC_affinity: 180 break; 181 default: 182 break; 183 } 184 llvm_unreachable("Invalid OpenMP simple clause kind"); 185 } 186 187 const char *clang::getOpenMPSimpleClauseTypeName(OpenMPClauseKind Kind, 188 unsigned Type) { 189 switch (Kind) { 190 case OMPC_default: 191 switch (llvm::omp::DefaultKind(Type)) { 192 #define OMP_DEFAULT_KIND(Enum, Name) \ 193 case Enum: \ 194 return Name; 195 #include "llvm/Frontend/OpenMP/OMPKinds.def" 196 } 197 llvm_unreachable("Invalid OpenMP 'default' clause type"); 198 case OMPC_proc_bind: 199 switch (Type) { 200 #define OMP_PROC_BIND_KIND(Enum, Name, Value) \ 201 case Value: \ 202 return Name; 203 #include "llvm/Frontend/OpenMP/OMPKinds.def" 204 } 205 llvm_unreachable("Invalid OpenMP 'proc_bind' clause type"); 206 case OMPC_schedule: 207 switch (Type) { 208 case OMPC_SCHEDULE_unknown: 209 case OMPC_SCHEDULE_MODIFIER_last: 210 return "unknown"; 211 #define OPENMP_SCHEDULE_KIND(Name) \ 212 case OMPC_SCHEDULE_##Name: \ 213 return #Name; 214 #define OPENMP_SCHEDULE_MODIFIER(Name) \ 215 case OMPC_SCHEDULE_MODIFIER_##Name: \ 216 return #Name; 217 #include "clang/Basic/OpenMPKinds.def" 218 } 219 llvm_unreachable("Invalid OpenMP 'schedule' clause type"); 220 case OMPC_depend: 221 switch (Type) { 222 case OMPC_DEPEND_unknown: 223 return "unknown"; 224 #define OPENMP_DEPEND_KIND(Name) \ 225 case OMPC_DEPEND_##Name: \ 226 return #Name; 227 #include "clang/Basic/OpenMPKinds.def" 228 } 229 llvm_unreachable("Invalid OpenMP 'depend' clause type"); 230 case OMPC_linear: 231 switch (Type) { 232 case OMPC_LINEAR_unknown: 233 return "unknown"; 234 #define OPENMP_LINEAR_KIND(Name) \ 235 case OMPC_LINEAR_##Name: \ 236 return #Name; 237 #include "clang/Basic/OpenMPKinds.def" 238 } 239 llvm_unreachable("Invalid OpenMP 'linear' clause type"); 240 case OMPC_map: 241 switch (Type) { 242 case OMPC_MAP_unknown: 243 case OMPC_MAP_MODIFIER_last: 244 return "unknown"; 245 #define OPENMP_MAP_KIND(Name) \ 246 case OMPC_MAP_##Name: \ 247 return #Name; 248 #define OPENMP_MAP_MODIFIER_KIND(Name) \ 249 case OMPC_MAP_MODIFIER_##Name: \ 250 return #Name; 251 #include "clang/Basic/OpenMPKinds.def" 252 default: 253 break; 254 } 255 llvm_unreachable("Invalid OpenMP 'map' clause type"); 256 case OMPC_to: 257 switch (Type) { 258 case OMPC_TO_MODIFIER_unknown: 259 return "unknown"; 260 #define OPENMP_TO_MODIFIER_KIND(Name) \ 261 case OMPC_TO_MODIFIER_##Name: \ 262 return #Name; 263 #include "clang/Basic/OpenMPKinds.def" 264 default: 265 break; 266 } 267 llvm_unreachable("Invalid OpenMP 'to' clause type"); 268 case OMPC_from: 269 switch (Type) { 270 case OMPC_FROM_MODIFIER_unknown: 271 return "unknown"; 272 #define OPENMP_FROM_MODIFIER_KIND(Name) \ 273 case OMPC_FROM_MODIFIER_##Name: \ 274 return #Name; 275 #include "clang/Basic/OpenMPKinds.def" 276 default: 277 break; 278 } 279 llvm_unreachable("Invalid OpenMP 'from' clause type"); 280 case OMPC_dist_schedule: 281 switch (Type) { 282 case OMPC_DIST_SCHEDULE_unknown: 283 return "unknown"; 284 #define OPENMP_DIST_SCHEDULE_KIND(Name) \ 285 case OMPC_DIST_SCHEDULE_##Name: \ 286 return #Name; 287 #include "clang/Basic/OpenMPKinds.def" 288 } 289 llvm_unreachable("Invalid OpenMP 'dist_schedule' clause type"); 290 case OMPC_defaultmap: 291 switch (Type) { 292 case OMPC_DEFAULTMAP_unknown: 293 case OMPC_DEFAULTMAP_MODIFIER_last: 294 return "unknown"; 295 #define OPENMP_DEFAULTMAP_KIND(Name) \ 296 case OMPC_DEFAULTMAP_##Name: \ 297 return #Name; 298 #define OPENMP_DEFAULTMAP_MODIFIER(Name) \ 299 case OMPC_DEFAULTMAP_MODIFIER_##Name: \ 300 return #Name; 301 #include "clang/Basic/OpenMPKinds.def" 302 } 303 llvm_unreachable("Invalid OpenMP 'schedule' clause type"); 304 case OMPC_atomic_default_mem_order: 305 switch (Type) { 306 case OMPC_ATOMIC_DEFAULT_MEM_ORDER_unknown: 307 return "unknown"; 308 #define OPENMP_ATOMIC_DEFAULT_MEM_ORDER_KIND(Name) \ 309 case OMPC_ATOMIC_DEFAULT_MEM_ORDER_##Name: \ 310 return #Name; 311 #include "clang/Basic/OpenMPKinds.def" 312 } 313 llvm_unreachable("Invalid OpenMP 'atomic_default_mem_order' clause type"); 314 case OMPC_device_type: 315 switch (Type) { 316 case OMPC_DEVICE_TYPE_unknown: 317 return "unknown"; 318 #define OPENMP_DEVICE_TYPE_KIND(Name) \ 319 case OMPC_DEVICE_TYPE_##Name: \ 320 return #Name; 321 #include "clang/Basic/OpenMPKinds.def" 322 } 323 llvm_unreachable("Invalid OpenMP 'device_type' clause type"); 324 case OMPC_lastprivate: 325 switch (Type) { 326 case OMPC_LASTPRIVATE_unknown: 327 return "unknown"; 328 #define OPENMP_LASTPRIVATE_KIND(Name) \ 329 case OMPC_LASTPRIVATE_##Name: \ 330 return #Name; 331 #include "clang/Basic/OpenMPKinds.def" 332 } 333 llvm_unreachable("Invalid OpenMP 'lastprivate' clause type"); 334 case OMPC_order: 335 switch (Type) { 336 case OMPC_ORDER_unknown: 337 return "unknown"; 338 #define OPENMP_ORDER_KIND(Name) \ 339 case OMPC_ORDER_##Name: \ 340 return #Name; 341 #include "clang/Basic/OpenMPKinds.def" 342 } 343 llvm_unreachable("Invalid OpenMP 'order' clause type"); 344 case OMPC_update: 345 switch (Type) { 346 case OMPC_DEPEND_unknown: 347 return "unknown"; 348 #define OPENMP_DEPEND_KIND(Name) \ 349 case OMPC_DEPEND_##Name: \ 350 return #Name; 351 #include "clang/Basic/OpenMPKinds.def" 352 } 353 llvm_unreachable("Invalid OpenMP 'depend' clause type"); 354 case OMPC_device: 355 switch (Type) { 356 case OMPC_DEVICE_unknown: 357 return "unknown"; 358 #define OPENMP_DEVICE_MODIFIER(Name) \ 359 case OMPC_DEVICE_##Name: \ 360 return #Name; 361 #include "clang/Basic/OpenMPKinds.def" 362 } 363 llvm_unreachable("Invalid OpenMP 'device' clause modifier"); 364 case OMPC_reduction: 365 switch (Type) { 366 case OMPC_REDUCTION_unknown: 367 return "unknown"; 368 #define OPENMP_REDUCTION_MODIFIER(Name) \ 369 case OMPC_REDUCTION_##Name: \ 370 return #Name; 371 #include "clang/Basic/OpenMPKinds.def" 372 } 373 llvm_unreachable("Invalid OpenMP 'reduction' clause modifier"); 374 case OMPC_unknown: 375 case OMPC_threadprivate: 376 case OMPC_if: 377 case OMPC_final: 378 case OMPC_num_threads: 379 case OMPC_safelen: 380 case OMPC_simdlen: 381 case OMPC_allocator: 382 case OMPC_allocate: 383 case OMPC_collapse: 384 case OMPC_private: 385 case OMPC_firstprivate: 386 case OMPC_shared: 387 case OMPC_task_reduction: 388 case OMPC_in_reduction: 389 case OMPC_aligned: 390 case OMPC_copyin: 391 case OMPC_copyprivate: 392 case OMPC_ordered: 393 case OMPC_nowait: 394 case OMPC_untied: 395 case OMPC_mergeable: 396 case OMPC_flush: 397 case OMPC_depobj: 398 case OMPC_read: 399 case OMPC_write: 400 case OMPC_capture: 401 case OMPC_seq_cst: 402 case OMPC_acq_rel: 403 case OMPC_acquire: 404 case OMPC_release: 405 case OMPC_relaxed: 406 case OMPC_threads: 407 case OMPC_simd: 408 case OMPC_num_teams: 409 case OMPC_thread_limit: 410 case OMPC_priority: 411 case OMPC_grainsize: 412 case OMPC_nogroup: 413 case OMPC_num_tasks: 414 case OMPC_hint: 415 case OMPC_uniform: 416 case OMPC_use_device_ptr: 417 case OMPC_use_device_addr: 418 case OMPC_is_device_ptr: 419 case OMPC_unified_address: 420 case OMPC_unified_shared_memory: 421 case OMPC_reverse_offload: 422 case OMPC_dynamic_allocators: 423 case OMPC_match: 424 case OMPC_nontemporal: 425 case OMPC_destroy: 426 case OMPC_detach: 427 case OMPC_inclusive: 428 case OMPC_exclusive: 429 case OMPC_uses_allocators: 430 case OMPC_affinity: 431 break; 432 default: 433 break; 434 } 435 llvm_unreachable("Invalid OpenMP simple clause kind"); 436 } 437 438 bool clang::isOpenMPLoopDirective(OpenMPDirectiveKind DKind) { 439 return DKind == OMPD_simd || DKind == OMPD_for || DKind == OMPD_for_simd || 440 DKind == OMPD_parallel_for || DKind == OMPD_parallel_for_simd || 441 DKind == OMPD_taskloop || DKind == OMPD_taskloop_simd || 442 DKind == OMPD_master_taskloop || DKind == OMPD_master_taskloop_simd || 443 DKind == OMPD_parallel_master_taskloop || 444 DKind == OMPD_parallel_master_taskloop_simd || 445 DKind == OMPD_distribute || DKind == OMPD_target_parallel_for || 446 DKind == OMPD_distribute_parallel_for || 447 DKind == OMPD_distribute_parallel_for_simd || 448 DKind == OMPD_distribute_simd || 449 DKind == OMPD_target_parallel_for_simd || DKind == OMPD_target_simd || 450 DKind == OMPD_teams_distribute || 451 DKind == OMPD_teams_distribute_simd || 452 DKind == OMPD_teams_distribute_parallel_for_simd || 453 DKind == OMPD_teams_distribute_parallel_for || 454 DKind == OMPD_target_teams_distribute || 455 DKind == OMPD_target_teams_distribute_parallel_for || 456 DKind == OMPD_target_teams_distribute_parallel_for_simd || 457 DKind == OMPD_target_teams_distribute_simd; 458 } 459 460 bool clang::isOpenMPWorksharingDirective(OpenMPDirectiveKind DKind) { 461 return DKind == OMPD_for || DKind == OMPD_for_simd || 462 DKind == OMPD_sections || DKind == OMPD_section || 463 DKind == OMPD_single || DKind == OMPD_parallel_for || 464 DKind == OMPD_parallel_for_simd || DKind == OMPD_parallel_sections || 465 DKind == OMPD_target_parallel_for || 466 DKind == OMPD_distribute_parallel_for || 467 DKind == OMPD_distribute_parallel_for_simd || 468 DKind == OMPD_target_parallel_for_simd || 469 DKind == OMPD_teams_distribute_parallel_for_simd || 470 DKind == OMPD_teams_distribute_parallel_for || 471 DKind == OMPD_target_teams_distribute_parallel_for || 472 DKind == OMPD_target_teams_distribute_parallel_for_simd; 473 } 474 475 bool clang::isOpenMPTaskLoopDirective(OpenMPDirectiveKind DKind) { 476 return DKind == OMPD_taskloop || DKind == OMPD_taskloop_simd || 477 DKind == OMPD_master_taskloop || DKind == OMPD_master_taskloop_simd || 478 DKind == OMPD_parallel_master_taskloop || 479 DKind == OMPD_parallel_master_taskloop_simd; 480 } 481 482 bool clang::isOpenMPParallelDirective(OpenMPDirectiveKind DKind) { 483 return DKind == OMPD_parallel || DKind == OMPD_parallel_for || 484 DKind == OMPD_parallel_for_simd || DKind == OMPD_parallel_sections || 485 DKind == OMPD_target_parallel || DKind == OMPD_target_parallel_for || 486 DKind == OMPD_distribute_parallel_for || 487 DKind == OMPD_distribute_parallel_for_simd || 488 DKind == OMPD_target_parallel_for_simd || 489 DKind == OMPD_teams_distribute_parallel_for || 490 DKind == OMPD_teams_distribute_parallel_for_simd || 491 DKind == OMPD_target_teams_distribute_parallel_for || 492 DKind == OMPD_target_teams_distribute_parallel_for_simd || 493 DKind == OMPD_parallel_master || 494 DKind == OMPD_parallel_master_taskloop || 495 DKind == OMPD_parallel_master_taskloop_simd; 496 } 497 498 bool clang::isOpenMPTargetExecutionDirective(OpenMPDirectiveKind DKind) { 499 return DKind == OMPD_target || DKind == OMPD_target_parallel || 500 DKind == OMPD_target_parallel_for || 501 DKind == OMPD_target_parallel_for_simd || DKind == OMPD_target_simd || 502 DKind == OMPD_target_teams || DKind == OMPD_target_teams_distribute || 503 DKind == OMPD_target_teams_distribute_parallel_for || 504 DKind == OMPD_target_teams_distribute_parallel_for_simd || 505 DKind == OMPD_target_teams_distribute_simd; 506 } 507 508 bool clang::isOpenMPTargetDataManagementDirective(OpenMPDirectiveKind DKind) { 509 return DKind == OMPD_target_data || DKind == OMPD_target_enter_data || 510 DKind == OMPD_target_exit_data || DKind == OMPD_target_update; 511 } 512 513 bool clang::isOpenMPNestingTeamsDirective(OpenMPDirectiveKind DKind) { 514 return DKind == OMPD_teams || DKind == OMPD_teams_distribute || 515 DKind == OMPD_teams_distribute_simd || 516 DKind == OMPD_teams_distribute_parallel_for_simd || 517 DKind == OMPD_teams_distribute_parallel_for; 518 } 519 520 bool clang::isOpenMPTeamsDirective(OpenMPDirectiveKind DKind) { 521 return isOpenMPNestingTeamsDirective(DKind) || 522 DKind == OMPD_target_teams || DKind == OMPD_target_teams_distribute || 523 DKind == OMPD_target_teams_distribute_parallel_for || 524 DKind == OMPD_target_teams_distribute_parallel_for_simd || 525 DKind == OMPD_target_teams_distribute_simd; 526 } 527 528 bool clang::isOpenMPSimdDirective(OpenMPDirectiveKind DKind) { 529 return DKind == OMPD_simd || DKind == OMPD_for_simd || 530 DKind == OMPD_parallel_for_simd || DKind == OMPD_taskloop_simd || 531 DKind == OMPD_master_taskloop_simd || 532 DKind == OMPD_parallel_master_taskloop_simd || 533 DKind == OMPD_distribute_parallel_for_simd || 534 DKind == OMPD_distribute_simd || DKind == OMPD_target_simd || 535 DKind == OMPD_teams_distribute_simd || 536 DKind == OMPD_teams_distribute_parallel_for_simd || 537 DKind == OMPD_target_teams_distribute_parallel_for_simd || 538 DKind == OMPD_target_teams_distribute_simd || 539 DKind == OMPD_target_parallel_for_simd; 540 } 541 542 bool clang::isOpenMPNestingDistributeDirective(OpenMPDirectiveKind Kind) { 543 return Kind == OMPD_distribute || Kind == OMPD_distribute_parallel_for || 544 Kind == OMPD_distribute_parallel_for_simd || 545 Kind == OMPD_distribute_simd; 546 // TODO add next directives. 547 } 548 549 bool clang::isOpenMPDistributeDirective(OpenMPDirectiveKind Kind) { 550 return isOpenMPNestingDistributeDirective(Kind) || 551 Kind == OMPD_teams_distribute || Kind == OMPD_teams_distribute_simd || 552 Kind == OMPD_teams_distribute_parallel_for_simd || 553 Kind == OMPD_teams_distribute_parallel_for || 554 Kind == OMPD_target_teams_distribute || 555 Kind == OMPD_target_teams_distribute_parallel_for || 556 Kind == OMPD_target_teams_distribute_parallel_for_simd || 557 Kind == OMPD_target_teams_distribute_simd; 558 } 559 560 bool clang::isOpenMPPrivate(OpenMPClauseKind Kind) { 561 return Kind == OMPC_private || Kind == OMPC_firstprivate || 562 Kind == OMPC_lastprivate || Kind == OMPC_linear || 563 Kind == OMPC_reduction || Kind == OMPC_task_reduction || 564 Kind == OMPC_in_reduction; // TODO add next clauses like 'reduction'. 565 } 566 567 bool clang::isOpenMPThreadPrivate(OpenMPClauseKind Kind) { 568 return Kind == OMPC_threadprivate || Kind == OMPC_copyin; 569 } 570 571 bool clang::isOpenMPTaskingDirective(OpenMPDirectiveKind Kind) { 572 return Kind == OMPD_task || isOpenMPTaskLoopDirective(Kind); 573 } 574 575 bool clang::isOpenMPLoopBoundSharingDirective(OpenMPDirectiveKind Kind) { 576 return Kind == OMPD_distribute_parallel_for || 577 Kind == OMPD_distribute_parallel_for_simd || 578 Kind == OMPD_teams_distribute_parallel_for_simd || 579 Kind == OMPD_teams_distribute_parallel_for || 580 Kind == OMPD_target_teams_distribute_parallel_for || 581 Kind == OMPD_target_teams_distribute_parallel_for_simd; 582 } 583 584 void clang::getOpenMPCaptureRegions( 585 SmallVectorImpl<OpenMPDirectiveKind> &CaptureRegions, 586 OpenMPDirectiveKind DKind) { 587 assert(unsigned(DKind) < llvm::omp::Directive_enumSize); 588 switch (DKind) { 589 case OMPD_parallel: 590 case OMPD_parallel_for: 591 case OMPD_parallel_for_simd: 592 case OMPD_parallel_master: 593 case OMPD_parallel_sections: 594 case OMPD_distribute_parallel_for: 595 case OMPD_distribute_parallel_for_simd: 596 CaptureRegions.push_back(OMPD_parallel); 597 break; 598 case OMPD_target_teams: 599 case OMPD_target_teams_distribute: 600 case OMPD_target_teams_distribute_simd: 601 CaptureRegions.push_back(OMPD_task); 602 CaptureRegions.push_back(OMPD_target); 603 CaptureRegions.push_back(OMPD_teams); 604 break; 605 case OMPD_teams: 606 case OMPD_teams_distribute: 607 case OMPD_teams_distribute_simd: 608 CaptureRegions.push_back(OMPD_teams); 609 break; 610 case OMPD_target: 611 case OMPD_target_simd: 612 CaptureRegions.push_back(OMPD_task); 613 CaptureRegions.push_back(OMPD_target); 614 break; 615 case OMPD_teams_distribute_parallel_for: 616 case OMPD_teams_distribute_parallel_for_simd: 617 CaptureRegions.push_back(OMPD_teams); 618 CaptureRegions.push_back(OMPD_parallel); 619 break; 620 case OMPD_target_parallel: 621 case OMPD_target_parallel_for: 622 case OMPD_target_parallel_for_simd: 623 CaptureRegions.push_back(OMPD_task); 624 CaptureRegions.push_back(OMPD_target); 625 CaptureRegions.push_back(OMPD_parallel); 626 break; 627 case OMPD_task: 628 case OMPD_target_enter_data: 629 case OMPD_target_exit_data: 630 case OMPD_target_update: 631 CaptureRegions.push_back(OMPD_task); 632 break; 633 case OMPD_taskloop: 634 case OMPD_taskloop_simd: 635 case OMPD_master_taskloop: 636 case OMPD_master_taskloop_simd: 637 CaptureRegions.push_back(OMPD_taskloop); 638 break; 639 case OMPD_parallel_master_taskloop: 640 case OMPD_parallel_master_taskloop_simd: 641 CaptureRegions.push_back(OMPD_parallel); 642 CaptureRegions.push_back(OMPD_taskloop); 643 break; 644 case OMPD_target_teams_distribute_parallel_for: 645 case OMPD_target_teams_distribute_parallel_for_simd: 646 CaptureRegions.push_back(OMPD_task); 647 CaptureRegions.push_back(OMPD_target); 648 CaptureRegions.push_back(OMPD_teams); 649 CaptureRegions.push_back(OMPD_parallel); 650 break; 651 case OMPD_simd: 652 case OMPD_for: 653 case OMPD_for_simd: 654 case OMPD_sections: 655 case OMPD_section: 656 case OMPD_single: 657 case OMPD_master: 658 case OMPD_critical: 659 case OMPD_taskgroup: 660 case OMPD_distribute: 661 case OMPD_ordered: 662 case OMPD_atomic: 663 case OMPD_target_data: 664 case OMPD_distribute_simd: 665 CaptureRegions.push_back(OMPD_unknown); 666 break; 667 case OMPD_threadprivate: 668 case OMPD_allocate: 669 case OMPD_taskyield: 670 case OMPD_barrier: 671 case OMPD_taskwait: 672 case OMPD_cancellation_point: 673 case OMPD_cancel: 674 case OMPD_flush: 675 case OMPD_depobj: 676 case OMPD_scan: 677 case OMPD_declare_reduction: 678 case OMPD_declare_mapper: 679 case OMPD_declare_simd: 680 case OMPD_declare_target: 681 case OMPD_end_declare_target: 682 case OMPD_requires: 683 case OMPD_declare_variant: 684 case OMPD_begin_declare_variant: 685 case OMPD_end_declare_variant: 686 llvm_unreachable("OpenMP Directive is not allowed"); 687 case OMPD_unknown: 688 default: 689 llvm_unreachable("Unknown OpenMP directive"); 690 } 691 } 692