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