llvm-project

Форк
0
/
OpenMPKinds.cpp 
835 строк · 30.1 Кб
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
                                          const LangOptions &LangOpts) {
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
    unsigned Type = llvm::StringSwitch<unsigned>(Str)
46
#define OPENMP_DEPEND_KIND(Name) .Case(#Name, OMPC_DEPEND_##Name)
47
#include "clang/Basic/OpenMPKinds.def"
48
                        .Default(OMPC_DEPEND_unknown);
49
    if (LangOpts.OpenMP < 51 && Type == OMPC_DEPEND_inoutset)
50
      return OMPC_DEPEND_unknown;
51
    return Type;
52
  }
53
  case OMPC_doacross:
54
    return llvm::StringSwitch<OpenMPDoacrossClauseModifier>(Str)
55
#define OPENMP_DOACROSS_MODIFIER(Name) .Case(#Name, OMPC_DOACROSS_##Name)
56
#include "clang/Basic/OpenMPKinds.def"
57
        .Default(OMPC_DOACROSS_unknown);
58
  case OMPC_linear:
59
    return llvm::StringSwitch<OpenMPLinearClauseKind>(Str)
60
#define OPENMP_LINEAR_KIND(Name) .Case(#Name, OMPC_LINEAR_##Name)
61
#include "clang/Basic/OpenMPKinds.def"
62
        .Default(OMPC_LINEAR_unknown);
63
  case OMPC_map: {
64
    unsigned Type = llvm::StringSwitch<unsigned>(Str)
65
#define OPENMP_MAP_KIND(Name)                                                  \
66
  .Case(#Name, static_cast<unsigned>(OMPC_MAP_##Name))
67
#define OPENMP_MAP_MODIFIER_KIND(Name)                                         \
68
  .Case(#Name, static_cast<unsigned>(OMPC_MAP_MODIFIER_##Name))
69
#include "clang/Basic/OpenMPKinds.def"
70
        .Default(OMPC_MAP_unknown);
71
    if (LangOpts.OpenMP < 51 && Type == OMPC_MAP_MODIFIER_present)
72
      return OMPC_MAP_MODIFIER_unknown;
73
    if (!LangOpts.OpenMPExtensions && Type == OMPC_MAP_MODIFIER_ompx_hold)
74
      return OMPC_MAP_MODIFIER_unknown;
75
    return Type;
76
  }
77
  case OMPC_to:
78
  case OMPC_from: {
79
    unsigned Type = llvm::StringSwitch<unsigned>(Str)
80
#define OPENMP_MOTION_MODIFIER_KIND(Name)                                      \
81
  .Case(#Name, static_cast<unsigned>(OMPC_MOTION_MODIFIER_##Name))
82
#include "clang/Basic/OpenMPKinds.def"
83
        .Default(OMPC_MOTION_MODIFIER_unknown);
84
    if (LangOpts.OpenMP < 51 && Type == OMPC_MOTION_MODIFIER_present)
85
      return OMPC_MOTION_MODIFIER_unknown;
86
    return Type;
87
  }
88
  case OMPC_dist_schedule:
89
    return llvm::StringSwitch<OpenMPDistScheduleClauseKind>(Str)
90
#define OPENMP_DIST_SCHEDULE_KIND(Name) .Case(#Name, OMPC_DIST_SCHEDULE_##Name)
91
#include "clang/Basic/OpenMPKinds.def"
92
        .Default(OMPC_DIST_SCHEDULE_unknown);
93
  case OMPC_defaultmap:
94
    return llvm::StringSwitch<unsigned>(Str)
95
#define OPENMP_DEFAULTMAP_KIND(Name)                                           \
96
  .Case(#Name, static_cast<unsigned>(OMPC_DEFAULTMAP_##Name))
97
#define OPENMP_DEFAULTMAP_MODIFIER(Name)                                       \
98
  .Case(#Name, static_cast<unsigned>(OMPC_DEFAULTMAP_MODIFIER_##Name))
99
#include "clang/Basic/OpenMPKinds.def"
100
        .Default(OMPC_DEFAULTMAP_unknown);
101
  case OMPC_atomic_default_mem_order:
102
     return llvm::StringSwitch<OpenMPAtomicDefaultMemOrderClauseKind>(Str)
103
#define OPENMP_ATOMIC_DEFAULT_MEM_ORDER_KIND(Name)       \
104
  .Case(#Name, OMPC_ATOMIC_DEFAULT_MEM_ORDER_##Name)
105
#include "clang/Basic/OpenMPKinds.def"
106
        .Default(OMPC_ATOMIC_DEFAULT_MEM_ORDER_unknown);
107
  case OMPC_fail:
108
    return static_cast<unsigned int>(llvm::StringSwitch<llvm::omp::Clause>(Str)
109
#define OPENMP_ATOMIC_FAIL_MODIFIER(Name) .Case(#Name, OMPC_##Name)
110
#include "clang/Basic/OpenMPKinds.def"
111
                                         .Default(OMPC_unknown));
112
  case OMPC_device_type:
113
    return llvm::StringSwitch<OpenMPDeviceType>(Str)
114
#define OPENMP_DEVICE_TYPE_KIND(Name) .Case(#Name, OMPC_DEVICE_TYPE_##Name)
115
#include "clang/Basic/OpenMPKinds.def"
116
        .Default(OMPC_DEVICE_TYPE_unknown);
117
  case OMPC_at:
118
    return llvm::StringSwitch<OpenMPAtClauseKind>(Str)
119
#define OPENMP_AT_KIND(Name) .Case(#Name, OMPC_AT_##Name)
120
#include "clang/Basic/OpenMPKinds.def"
121
        .Default(OMPC_AT_unknown);
122
  case OMPC_severity:
123
    return llvm::StringSwitch<OpenMPSeverityClauseKind>(Str)
124
#define OPENMP_SEVERITY_KIND(Name) .Case(#Name, OMPC_SEVERITY_##Name)
125
#include "clang/Basic/OpenMPKinds.def"
126
        .Default(OMPC_SEVERITY_unknown);
127
  case OMPC_lastprivate:
128
    return llvm::StringSwitch<OpenMPLastprivateModifier>(Str)
129
#define OPENMP_LASTPRIVATE_KIND(Name) .Case(#Name, OMPC_LASTPRIVATE_##Name)
130
#include "clang/Basic/OpenMPKinds.def"
131
        .Default(OMPC_LASTPRIVATE_unknown);
132
  case OMPC_order:
133
    return llvm::StringSwitch<unsigned>(Str)
134
#define OPENMP_ORDER_KIND(Name)                                                \
135
  .Case(#Name, static_cast<unsigned>(OMPC_ORDER_##Name))
136
#define OPENMP_ORDER_MODIFIER(Name)                                            \
137
  .Case(#Name, static_cast<unsigned>(OMPC_ORDER_MODIFIER_##Name))
138
#include "clang/Basic/OpenMPKinds.def"
139
        .Default(OMPC_ORDER_unknown);
140
  case OMPC_update:
141
    return llvm::StringSwitch<OpenMPDependClauseKind>(Str)
142
#define OPENMP_DEPEND_KIND(Name) .Case(#Name, OMPC_DEPEND_##Name)
143
#include "clang/Basic/OpenMPKinds.def"
144
        .Default(OMPC_DEPEND_unknown);
145
  case OMPC_device:
146
    return llvm::StringSwitch<OpenMPDeviceClauseModifier>(Str)
147
#define OPENMP_DEVICE_MODIFIER(Name) .Case(#Name, OMPC_DEVICE_##Name)
148
#include "clang/Basic/OpenMPKinds.def"
149
        .Default(OMPC_DEVICE_unknown);
150
  case OMPC_reduction:
151
    return llvm::StringSwitch<OpenMPReductionClauseModifier>(Str)
152
#define OPENMP_REDUCTION_MODIFIER(Name) .Case(#Name, OMPC_REDUCTION_##Name)
153
#include "clang/Basic/OpenMPKinds.def"
154
        .Default(OMPC_REDUCTION_unknown);
155
  case OMPC_adjust_args:
156
    return llvm::StringSwitch<OpenMPAdjustArgsOpKind>(Str)
157
#define OPENMP_ADJUST_ARGS_KIND(Name) .Case(#Name, OMPC_ADJUST_ARGS_##Name)
158
#include "clang/Basic/OpenMPKinds.def"
159
        .Default(OMPC_ADJUST_ARGS_unknown);
160
  case OMPC_bind:
161
    return llvm::StringSwitch<unsigned>(Str)
162
#define OPENMP_BIND_KIND(Name) .Case(#Name, OMPC_BIND_##Name)
163
#include "clang/Basic/OpenMPKinds.def"
164
        .Default(OMPC_BIND_unknown);
165
  case OMPC_grainsize: {
166
    unsigned Type = llvm::StringSwitch<unsigned>(Str)
167
#define OPENMP_GRAINSIZE_MODIFIER(Name) .Case(#Name, OMPC_GRAINSIZE_##Name)
168
#include "clang/Basic/OpenMPKinds.def"
169
                        .Default(OMPC_GRAINSIZE_unknown);
170
    if (LangOpts.OpenMP < 51)
171
      return OMPC_GRAINSIZE_unknown;
172
    return Type;
173
  }
174
  case OMPC_num_tasks: {
175
    unsigned Type = llvm::StringSwitch<unsigned>(Str)
176
#define OPENMP_NUMTASKS_MODIFIER(Name) .Case(#Name, OMPC_NUMTASKS_##Name)
177
#include "clang/Basic/OpenMPKinds.def"
178
                        .Default(OMPC_NUMTASKS_unknown);
179
    if (LangOpts.OpenMP < 51)
180
      return OMPC_NUMTASKS_unknown;
181
    return Type;
182
  }
183
  case OMPC_unknown:
184
  case OMPC_threadprivate:
185
  case OMPC_if:
186
  case OMPC_final:
187
  case OMPC_num_threads:
188
  case OMPC_safelen:
189
  case OMPC_simdlen:
190
  case OMPC_sizes:
191
  case OMPC_allocator:
192
  case OMPC_allocate:
193
  case OMPC_collapse:
194
  case OMPC_private:
195
  case OMPC_firstprivate:
196
  case OMPC_shared:
197
  case OMPC_task_reduction:
198
  case OMPC_in_reduction:
199
  case OMPC_aligned:
200
  case OMPC_copyin:
201
  case OMPC_copyprivate:
202
  case OMPC_ordered:
203
  case OMPC_nowait:
204
  case OMPC_untied:
205
  case OMPC_mergeable:
206
  case OMPC_flush:
207
  case OMPC_depobj:
208
  case OMPC_read:
209
  case OMPC_write:
210
  case OMPC_capture:
211
  case OMPC_compare:
212
  case OMPC_seq_cst:
213
  case OMPC_acq_rel:
214
  case OMPC_acquire:
215
  case OMPC_release:
216
  case OMPC_relaxed:
217
  case OMPC_threads:
218
  case OMPC_simd:
219
  case OMPC_num_teams:
220
  case OMPC_thread_limit:
221
  case OMPC_priority:
222
  case OMPC_nogroup:
223
  case OMPC_hint:
224
  case OMPC_uniform:
225
  case OMPC_use_device_ptr:
226
  case OMPC_use_device_addr:
227
  case OMPC_is_device_ptr:
228
  case OMPC_has_device_addr:
229
  case OMPC_unified_address:
230
  case OMPC_unified_shared_memory:
231
  case OMPC_reverse_offload:
232
  case OMPC_dynamic_allocators:
233
  case OMPC_match:
234
  case OMPC_nontemporal:
235
  case OMPC_destroy:
236
  case OMPC_novariants:
237
  case OMPC_nocontext:
238
  case OMPC_detach:
239
  case OMPC_inclusive:
240
  case OMPC_exclusive:
241
  case OMPC_uses_allocators:
242
  case OMPC_affinity:
243
  case OMPC_when:
244
  case OMPC_append_args:
245
    break;
246
  default:
247
    break;
248
  }
249
  llvm_unreachable("Invalid OpenMP simple clause kind");
250
}
251

252
const char *clang::getOpenMPSimpleClauseTypeName(OpenMPClauseKind Kind,
253
                                                 unsigned Type) {
254
  switch (Kind) {
255
  case OMPC_default:
256
    switch (llvm::omp::DefaultKind(Type)) {
257
#define OMP_DEFAULT_KIND(Enum, Name)                                           \
258
  case Enum:                                                                   \
259
    return Name;
260
#include "llvm/Frontend/OpenMP/OMPKinds.def"
261
    }
262
    llvm_unreachable("Invalid OpenMP 'default' clause type");
263
  case OMPC_proc_bind:
264
    switch (Type) {
265
#define OMP_PROC_BIND_KIND(Enum, Name, Value)                                  \
266
  case Value:                                                                  \
267
    return Name;
268
#include "llvm/Frontend/OpenMP/OMPKinds.def"
269
    }
270
    llvm_unreachable("Invalid OpenMP 'proc_bind' clause type");
271
  case OMPC_schedule:
272
    switch (Type) {
273
    case OMPC_SCHEDULE_unknown:
274
    case OMPC_SCHEDULE_MODIFIER_last:
275
      return "unknown";
276
#define OPENMP_SCHEDULE_KIND(Name)                                             \
277
    case OMPC_SCHEDULE_##Name:                                                 \
278
      return #Name;
279
#define OPENMP_SCHEDULE_MODIFIER(Name)                                         \
280
    case OMPC_SCHEDULE_MODIFIER_##Name:                                        \
281
      return #Name;
282
#include "clang/Basic/OpenMPKinds.def"
283
    }
284
    llvm_unreachable("Invalid OpenMP 'schedule' clause type");
285
  case OMPC_depend:
286
    switch (Type) {
287
    case OMPC_DEPEND_unknown:
288
      return "unknown";
289
#define OPENMP_DEPEND_KIND(Name)                                             \
290
  case OMPC_DEPEND_##Name:                                                   \
291
    return #Name;
292
#include "clang/Basic/OpenMPKinds.def"
293
    }
294
    llvm_unreachable("Invalid OpenMP 'depend' clause type");
295
  case OMPC_doacross:
296
    switch (Type) {
297
    case OMPC_DOACROSS_unknown:
298
      return "unknown";
299
#define OPENMP_DOACROSS_MODIFIER(Name)                                         \
300
  case OMPC_DOACROSS_##Name:                                                   \
301
    return #Name;
302
#include "clang/Basic/OpenMPKinds.def"
303
    }
304
    llvm_unreachable("Invalid OpenMP 'doacross' clause type");
305
  case OMPC_linear:
306
    switch (Type) {
307
    case OMPC_LINEAR_unknown:
308
      return "unknown";
309
#define OPENMP_LINEAR_KIND(Name)                                             \
310
  case OMPC_LINEAR_##Name:                                                   \
311
    return #Name;
312
#include "clang/Basic/OpenMPKinds.def"
313
    }
314
    llvm_unreachable("Invalid OpenMP 'linear' clause type");
315
  case OMPC_map:
316
    switch (Type) {
317
    case OMPC_MAP_unknown:
318
    case OMPC_MAP_MODIFIER_last:
319
      return "unknown";
320
#define OPENMP_MAP_KIND(Name)                                                \
321
  case OMPC_MAP_##Name:                                                      \
322
    return #Name;
323
#define OPENMP_MAP_MODIFIER_KIND(Name)                                       \
324
  case OMPC_MAP_MODIFIER_##Name:                                             \
325
    return #Name;
326
#include "clang/Basic/OpenMPKinds.def"
327
    default:
328
      break;
329
    }
330
    llvm_unreachable("Invalid OpenMP 'map' clause type");
331
  case OMPC_to:
332
  case OMPC_from:
333
    switch (Type) {
334
    case OMPC_MOTION_MODIFIER_unknown:
335
      return "unknown";
336
#define OPENMP_MOTION_MODIFIER_KIND(Name)                                      \
337
  case OMPC_MOTION_MODIFIER_##Name:                                            \
338
    return #Name;
339
#include "clang/Basic/OpenMPKinds.def"
340
    default:
341
      break;
342
    }
343
    llvm_unreachable("Invalid OpenMP 'to' or 'from' clause type");
344
  case OMPC_dist_schedule:
345
    switch (Type) {
346
    case OMPC_DIST_SCHEDULE_unknown:
347
      return "unknown";
348
#define OPENMP_DIST_SCHEDULE_KIND(Name)                                      \
349
  case OMPC_DIST_SCHEDULE_##Name:                                            \
350
    return #Name;
351
#include "clang/Basic/OpenMPKinds.def"
352
    }
353
    llvm_unreachable("Invalid OpenMP 'dist_schedule' clause type");
354
  case OMPC_defaultmap:
355
    switch (Type) {
356
    case OMPC_DEFAULTMAP_unknown:
357
    case OMPC_DEFAULTMAP_MODIFIER_last:
358
      return "unknown";
359
#define OPENMP_DEFAULTMAP_KIND(Name)                                         \
360
    case OMPC_DEFAULTMAP_##Name:                                             \
361
      return #Name;
362
#define OPENMP_DEFAULTMAP_MODIFIER(Name)                                     \
363
    case OMPC_DEFAULTMAP_MODIFIER_##Name:                                    \
364
      return #Name;
365
#include "clang/Basic/OpenMPKinds.def"
366
    }
367
    llvm_unreachable("Invalid OpenMP 'schedule' clause type");
368
  case OMPC_atomic_default_mem_order:
369
    switch (Type) {
370
    case OMPC_ATOMIC_DEFAULT_MEM_ORDER_unknown:
371
      return "unknown";
372
#define OPENMP_ATOMIC_DEFAULT_MEM_ORDER_KIND(Name)                           \
373
    case OMPC_ATOMIC_DEFAULT_MEM_ORDER_##Name:                               \
374
      return #Name;
375
#include "clang/Basic/OpenMPKinds.def"
376
}
377
    llvm_unreachable("Invalid OpenMP 'atomic_default_mem_order' clause type");
378
  case OMPC_device_type:
379
    switch (Type) {
380
    case OMPC_DEVICE_TYPE_unknown:
381
      return "unknown";
382
#define OPENMP_DEVICE_TYPE_KIND(Name)                                          \
383
    case OMPC_DEVICE_TYPE_##Name:                                              \
384
      return #Name;
385
#include "clang/Basic/OpenMPKinds.def"
386
    }
387
    llvm_unreachable("Invalid OpenMP 'device_type' clause type");
388
  case OMPC_at:
389
    switch (Type) {
390
    case OMPC_AT_unknown:
391
      return "unknown";
392
#define OPENMP_AT_KIND(Name)                                                   \
393
  case OMPC_AT_##Name:                                                         \
394
    return #Name;
395
#include "clang/Basic/OpenMPKinds.def"
396
    }
397
    llvm_unreachable("Invalid OpenMP 'at' clause type");
398
  case OMPC_severity:
399
    switch (Type) {
400
    case OMPC_SEVERITY_unknown:
401
      return "unknown";
402
#define OPENMP_SEVERITY_KIND(Name)                                             \
403
  case OMPC_SEVERITY_##Name:                                                   \
404
    return #Name;
405
#include "clang/Basic/OpenMPKinds.def"
406
    }
407
    llvm_unreachable("Invalid OpenMP 'severity' clause type");
408
  case OMPC_lastprivate:
409
    switch (Type) {
410
    case OMPC_LASTPRIVATE_unknown:
411
      return "unknown";
412
#define OPENMP_LASTPRIVATE_KIND(Name)                                          \
413
    case OMPC_LASTPRIVATE_##Name:                                              \
414
      return #Name;
415
#include "clang/Basic/OpenMPKinds.def"
416
    }
417
    llvm_unreachable("Invalid OpenMP 'lastprivate' clause type");
418
  case OMPC_order:
419
    switch (Type) {
420
    case OMPC_ORDER_unknown:
421
    case OMPC_ORDER_MODIFIER_last:
422
      return "unknown";
423
#define OPENMP_ORDER_KIND(Name)                                                \
424
  case OMPC_ORDER_##Name:                                                      \
425
    return #Name;
426
#define OPENMP_ORDER_MODIFIER(Name)                                            \
427
  case OMPC_ORDER_MODIFIER_##Name:                                             \
428
    return #Name;
429
#include "clang/Basic/OpenMPKinds.def"
430
    }
431
    llvm_unreachable("Invalid OpenMP 'order' clause type");
432
  case OMPC_update:
433
    switch (Type) {
434
    case OMPC_DEPEND_unknown:
435
      return "unknown";
436
#define OPENMP_DEPEND_KIND(Name)                                               \
437
  case OMPC_DEPEND_##Name:                                                     \
438
    return #Name;
439
#include "clang/Basic/OpenMPKinds.def"
440
    }
441
    llvm_unreachable("Invalid OpenMP 'depend' clause type");
442
  case OMPC_fail: {
443
    OpenMPClauseKind CK = static_cast<OpenMPClauseKind>(Type);
444
    return getOpenMPClauseName(CK).data();
445
    llvm_unreachable("Invalid OpenMP 'fail' clause modifier");
446
  }
447
  case OMPC_device:
448
    switch (Type) {
449
    case OMPC_DEVICE_unknown:
450
      return "unknown";
451
#define OPENMP_DEVICE_MODIFIER(Name)                                           \
452
  case OMPC_DEVICE_##Name:                                                     \
453
    return #Name;
454
#include "clang/Basic/OpenMPKinds.def"
455
    }
456
    llvm_unreachable("Invalid OpenMP 'device' clause modifier");
457
  case OMPC_reduction:
458
    switch (Type) {
459
    case OMPC_REDUCTION_unknown:
460
      return "unknown";
461
#define OPENMP_REDUCTION_MODIFIER(Name)                                        \
462
  case OMPC_REDUCTION_##Name:                                                  \
463
    return #Name;
464
#include "clang/Basic/OpenMPKinds.def"
465
    }
466
    llvm_unreachable("Invalid OpenMP 'reduction' clause modifier");
467
  case OMPC_adjust_args:
468
    switch (Type) {
469
    case OMPC_ADJUST_ARGS_unknown:
470
      return "unknown";
471
#define OPENMP_ADJUST_ARGS_KIND(Name)                                          \
472
  case OMPC_ADJUST_ARGS_##Name:                                                \
473
    return #Name;
474
#include "clang/Basic/OpenMPKinds.def"
475
    }
476
    llvm_unreachable("Invalid OpenMP 'adjust_args' clause kind");
477
  case OMPC_bind:
478
    switch (Type) {
479
    case OMPC_BIND_unknown:
480
      return "unknown";
481
#define OPENMP_BIND_KIND(Name)                                                 \
482
  case OMPC_BIND_##Name:                                                       \
483
    return #Name;
484
#include "clang/Basic/OpenMPKinds.def"
485
    }
486
    llvm_unreachable("Invalid OpenMP 'bind' clause type");
487
  case OMPC_grainsize:
488
    switch (Type) {
489
    case OMPC_GRAINSIZE_unknown:
490
      return "unknown";
491
#define OPENMP_GRAINSIZE_MODIFIER(Name)                                        \
492
  case OMPC_GRAINSIZE_##Name:                                                  \
493
    return #Name;
494
#include "clang/Basic/OpenMPKinds.def"
495
    }
496
    llvm_unreachable("Invalid OpenMP 'grainsize' clause modifier");
497
  case OMPC_num_tasks:
498
    switch (Type) {
499
    case OMPC_NUMTASKS_unknown:
500
      return "unknown";
501
#define OPENMP_NUMTASKS_MODIFIER(Name)                                         \
502
  case OMPC_NUMTASKS_##Name:                                                   \
503
    return #Name;
504
#include "clang/Basic/OpenMPKinds.def"
505
    }
506
    llvm_unreachable("Invalid OpenMP 'num_tasks' clause modifier");
507
  case OMPC_unknown:
508
  case OMPC_threadprivate:
509
  case OMPC_if:
510
  case OMPC_final:
511
  case OMPC_num_threads:
512
  case OMPC_safelen:
513
  case OMPC_simdlen:
514
  case OMPC_sizes:
515
  case OMPC_allocator:
516
  case OMPC_allocate:
517
  case OMPC_collapse:
518
  case OMPC_private:
519
  case OMPC_firstprivate:
520
  case OMPC_shared:
521
  case OMPC_task_reduction:
522
  case OMPC_in_reduction:
523
  case OMPC_aligned:
524
  case OMPC_copyin:
525
  case OMPC_copyprivate:
526
  case OMPC_ordered:
527
  case OMPC_nowait:
528
  case OMPC_untied:
529
  case OMPC_mergeable:
530
  case OMPC_flush:
531
  case OMPC_depobj:
532
  case OMPC_read:
533
  case OMPC_write:
534
  case OMPC_capture:
535
  case OMPC_compare:
536
  case OMPC_seq_cst:
537
  case OMPC_acq_rel:
538
  case OMPC_acquire:
539
  case OMPC_release:
540
  case OMPC_relaxed:
541
  case OMPC_threads:
542
  case OMPC_simd:
543
  case OMPC_num_teams:
544
  case OMPC_thread_limit:
545
  case OMPC_priority:
546
  case OMPC_nogroup:
547
  case OMPC_hint:
548
  case OMPC_uniform:
549
  case OMPC_use_device_ptr:
550
  case OMPC_use_device_addr:
551
  case OMPC_is_device_ptr:
552
  case OMPC_has_device_addr:
553
  case OMPC_unified_address:
554
  case OMPC_unified_shared_memory:
555
  case OMPC_reverse_offload:
556
  case OMPC_dynamic_allocators:
557
  case OMPC_match:
558
  case OMPC_nontemporal:
559
  case OMPC_destroy:
560
  case OMPC_detach:
561
  case OMPC_novariants:
562
  case OMPC_nocontext:
563
  case OMPC_inclusive:
564
  case OMPC_exclusive:
565
  case OMPC_uses_allocators:
566
  case OMPC_affinity:
567
  case OMPC_when:
568
  case OMPC_append_args:
569
    break;
570
  default:
571
    break;
572
  }
573
  llvm_unreachable("Invalid OpenMP simple clause kind");
574
}
575

576
bool clang::isOpenMPLoopDirective(OpenMPDirectiveKind DKind) {
577
  return getDirectiveAssociation(DKind) == Association::Loop;
578
}
579

580
bool clang::isOpenMPWorksharingDirective(OpenMPDirectiveKind DKind) {
581
  return DKind == OMPD_for || DKind == OMPD_for_simd ||
582
         DKind == OMPD_sections || DKind == OMPD_section ||
583
         DKind == OMPD_single || DKind == OMPD_parallel_for ||
584
         DKind == OMPD_parallel_for_simd || DKind == OMPD_parallel_sections ||
585
         DKind == OMPD_target_parallel_for ||
586
         DKind == OMPD_distribute_parallel_for ||
587
         DKind == OMPD_distribute_parallel_for_simd ||
588
         DKind == OMPD_target_parallel_for_simd ||
589
         DKind == OMPD_teams_distribute_parallel_for_simd ||
590
         DKind == OMPD_teams_distribute_parallel_for ||
591
         DKind == OMPD_target_teams_distribute_parallel_for ||
592
         DKind == OMPD_target_teams_distribute_parallel_for_simd ||
593
         DKind == OMPD_parallel_loop || DKind == OMPD_teams_loop ||
594
         DKind == OMPD_target_parallel_loop || DKind == OMPD_target_teams_loop;
595
}
596

597
bool clang::isOpenMPTaskLoopDirective(OpenMPDirectiveKind DKind) {
598
  return DKind == OMPD_taskloop ||
599
         llvm::is_contained(getLeafConstructs(DKind), OMPD_taskloop);
600
}
601

602
bool clang::isOpenMPParallelDirective(OpenMPDirectiveKind DKind) {
603
  if (DKind == OMPD_teams_loop)
604
    return true;
605
  return DKind == OMPD_parallel ||
606
         llvm::is_contained(getLeafConstructs(DKind), OMPD_parallel);
607
}
608

609
bool clang::isOpenMPTargetExecutionDirective(OpenMPDirectiveKind DKind) {
610
  return DKind == OMPD_target ||
611
         llvm::is_contained(getLeafConstructs(DKind), OMPD_target);
612
}
613

614
bool clang::isOpenMPTargetDataManagementDirective(OpenMPDirectiveKind DKind) {
615
  return DKind == OMPD_target_data || DKind == OMPD_target_enter_data ||
616
         DKind == OMPD_target_exit_data || DKind == OMPD_target_update;
617
}
618

619
bool clang::isOpenMPNestingTeamsDirective(OpenMPDirectiveKind DKind) {
620
  if (DKind == OMPD_teams)
621
    return true;
622
  ArrayRef<Directive> Leaves = getLeafConstructs(DKind);
623
  return !Leaves.empty() && Leaves.front() == OMPD_teams;
624
}
625

626
bool clang::isOpenMPTeamsDirective(OpenMPDirectiveKind DKind) {
627
  return DKind == OMPD_teams ||
628
         llvm::is_contained(getLeafConstructs(DKind), OMPD_teams);
629
}
630

631
bool clang::isOpenMPSimdDirective(OpenMPDirectiveKind DKind) {
632
  // Avoid OMPD_declare_simd
633
  if (getDirectiveAssociation(DKind) != Association::Loop)
634
    return false;
635
  // Formally, OMPD_end_do_simd also has a loop association, but
636
  // it's a Fortran-specific directive.
637

638
  return DKind == OMPD_simd ||
639
         llvm::is_contained(getLeafConstructs(DKind), OMPD_simd);
640
}
641

642
bool clang::isOpenMPNestingDistributeDirective(OpenMPDirectiveKind Kind) {
643
  if (Kind == OMPD_distribute)
644
    return true;
645
  ArrayRef<Directive> Leaves = getLeafConstructs(Kind);
646
  return !Leaves.empty() && Leaves.front() == OMPD_distribute;
647
}
648

649
bool clang::isOpenMPDistributeDirective(OpenMPDirectiveKind Kind) {
650
  return Kind == OMPD_distribute ||
651
         llvm::is_contained(getLeafConstructs(Kind), OMPD_distribute);
652
}
653

654
bool clang::isOpenMPGenericLoopDirective(OpenMPDirectiveKind Kind) {
655
  if (Kind == OMPD_loop)
656
    return true;
657
  ArrayRef<Directive> Leaves = getLeafConstructs(Kind);
658
  return !Leaves.empty() && Leaves.back() == OMPD_loop;
659
}
660

661
bool clang::isOpenMPPrivate(OpenMPClauseKind Kind) {
662
  return Kind == OMPC_private || Kind == OMPC_firstprivate ||
663
         Kind == OMPC_lastprivate || Kind == OMPC_linear ||
664
         Kind == OMPC_reduction || Kind == OMPC_task_reduction ||
665
         Kind == OMPC_in_reduction; // TODO add next clauses like 'reduction'.
666
}
667

668
bool clang::isOpenMPThreadPrivate(OpenMPClauseKind Kind) {
669
  return Kind == OMPC_threadprivate || Kind == OMPC_copyin;
670
}
671

672
bool clang::isOpenMPTaskingDirective(OpenMPDirectiveKind Kind) {
673
  return Kind == OMPD_task || isOpenMPTaskLoopDirective(Kind);
674
}
675

676
bool clang::isOpenMPLoopBoundSharingDirective(OpenMPDirectiveKind Kind) {
677
  return Kind == OMPD_distribute_parallel_for ||
678
         Kind == OMPD_distribute_parallel_for_simd ||
679
         Kind == OMPD_teams_distribute_parallel_for_simd ||
680
         Kind == OMPD_teams_distribute_parallel_for ||
681
         Kind == OMPD_target_teams_distribute_parallel_for ||
682
         Kind == OMPD_target_teams_distribute_parallel_for_simd ||
683
         Kind == OMPD_teams_loop || Kind == OMPD_target_teams_loop;
684
}
685

686
bool clang::isOpenMPLoopTransformationDirective(OpenMPDirectiveKind DKind) {
687
  return DKind == OMPD_tile || DKind == OMPD_unroll;
688
}
689

690
bool clang::isOpenMPCombinedParallelADirective(OpenMPDirectiveKind DKind) {
691
  return DKind == OMPD_parallel_for || DKind == OMPD_parallel_for_simd ||
692
         DKind == OMPD_parallel_master ||
693
         DKind == OMPD_parallel_master_taskloop ||
694
         DKind == OMPD_parallel_master_taskloop_simd ||
695
         DKind == OMPD_parallel_sections;
696
}
697

698
bool clang::needsTaskBasedThreadLimit(OpenMPDirectiveKind DKind) {
699
  return DKind == OMPD_target || DKind == OMPD_target_parallel ||
700
         DKind == OMPD_target_parallel_for ||
701
         DKind == OMPD_target_parallel_for_simd || DKind == OMPD_target_simd ||
702
         DKind == OMPD_target_parallel_loop;
703
}
704

705
bool clang::isOpenMPExecutableDirective(OpenMPDirectiveKind DKind) {
706
  if (DKind == OMPD_error)
707
    return true;
708
  Category Cat = getDirectiveCategory(DKind);
709
  return Cat == Category::Executable || Cat == Category::Subsidiary;
710
}
711

712
bool clang::isOpenMPCapturingDirective(OpenMPDirectiveKind DKind) {
713
  if (isOpenMPExecutableDirective(DKind)) {
714
    switch (DKind) {
715
    case OMPD_atomic:
716
    case OMPD_barrier:
717
    case OMPD_cancel:
718
    case OMPD_cancellation_point:
719
    case OMPD_critical:
720
    case OMPD_depobj:
721
    case OMPD_error:
722
    case OMPD_flush:
723
    case OMPD_masked:
724
    case OMPD_master:
725
    case OMPD_section:
726
    case OMPD_taskwait:
727
    case OMPD_taskyield:
728
      return false;
729
    default:
730
      return !isOpenMPLoopTransformationDirective(DKind);
731
    }
732
  }
733
  // Non-executable directives.
734
  switch (DKind) {
735
  case OMPD_metadirective:
736
  case OMPD_nothing:
737
    return true;
738
  default:
739
    break;
740
  }
741
  return false;
742
}
743

744
void clang::getOpenMPCaptureRegions(
745
    SmallVectorImpl<OpenMPDirectiveKind> &CaptureRegions,
746
    OpenMPDirectiveKind DKind) {
747
  assert(unsigned(DKind) < llvm::omp::Directive_enumSize);
748
  assert(isOpenMPCapturingDirective(DKind) && "Expecting capturing directive");
749

750
  auto GetRegionsForLeaf = [&](OpenMPDirectiveKind LKind) {
751
    assert(isLeafConstruct(LKind) && "Epecting leaf directive");
752
    // Whether a leaf would require OMPD_unknown if it occured on its own.
753
    switch (LKind) {
754
    case OMPD_metadirective:
755
      CaptureRegions.push_back(OMPD_metadirective);
756
      break;
757
    case OMPD_nothing:
758
      CaptureRegions.push_back(OMPD_nothing);
759
      break;
760
    case OMPD_parallel:
761
      CaptureRegions.push_back(OMPD_parallel);
762
      break;
763
    case OMPD_target:
764
      CaptureRegions.push_back(OMPD_task);
765
      CaptureRegions.push_back(OMPD_target);
766
      break;
767
    case OMPD_task:
768
    case OMPD_target_enter_data:
769
    case OMPD_target_exit_data:
770
    case OMPD_target_update:
771
      CaptureRegions.push_back(OMPD_task);
772
      break;
773
    case OMPD_teams:
774
      CaptureRegions.push_back(OMPD_teams);
775
      break;
776
    case OMPD_taskloop:
777
      CaptureRegions.push_back(OMPD_taskloop);
778
      break;
779
    case OMPD_loop:
780
      // TODO: 'loop' may require different capture regions depending on the
781
      // bind clause or the parent directive when there is no bind clause.
782
      // If any of the directives that push regions here are parents of 'loop',
783
      // assume 'parallel'. Otherwise do nothing.
784
      if (!CaptureRegions.empty() &&
785
          !llvm::is_contained(CaptureRegions, OMPD_parallel))
786
        CaptureRegions.push_back(OMPD_parallel);
787
      else
788
        return true;
789
      break;
790
    case OMPD_dispatch:
791
    case OMPD_distribute:
792
    case OMPD_for:
793
    case OMPD_masked:
794
    case OMPD_master:
795
    case OMPD_ordered:
796
    case OMPD_scope:
797
    case OMPD_sections:
798
    case OMPD_simd:
799
    case OMPD_single:
800
    case OMPD_target_data:
801
    case OMPD_taskgroup:
802
      // These directives (when standalone) use OMPD_unknown as the region,
803
      // but when they're constituents of a compound directive, and other
804
      // leafs from that directive have specific regions, then these directives
805
      // add no additional regions.
806
      return true;
807
    default:
808
      llvm::errs() << getOpenMPDirectiveName(LKind) << '\n';
809
      llvm_unreachable("Unexpected directive");
810
    }
811
    return false;
812
  };
813

814
  bool MayNeedUnknownRegion = false;
815
  for (OpenMPDirectiveKind L : getLeafConstructsOrSelf(DKind))
816
    MayNeedUnknownRegion |= GetRegionsForLeaf(L);
817

818
  // We need OMPD_unknown when no regions were added, and specific leaf
819
  // constructs were present. Push a single OMPD_unknown as the capture
820
  /// region.
821
  if (CaptureRegions.empty() && MayNeedUnknownRegion)
822
    CaptureRegions.push_back(OMPD_unknown);
823

824
  // OMPD_unknown is only expected as the only region. If other regions
825
  // are present OMPD_unknown should not be present.
826
  assert((CaptureRegions[0] == OMPD_unknown ||
827
          !llvm::is_contained(CaptureRegions, OMPD_unknown)) &&
828
         "Misplaced OMPD_unknown");
829
}
830

831
bool clang::checkFailClauseParameter(OpenMPClauseKind FailClauseParameter) {
832
  return FailClauseParameter == llvm::omp::OMPC_acquire ||
833
         FailClauseParameter == llvm::omp::OMPC_relaxed ||
834
         FailClauseParameter == llvm::omp::OMPC_seq_cst;
835
}
836

837

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.