LLVM 21.0.0git
OMPContext.cpp
Go to the documentation of this file.
1//===- OMPContext.cpp ------ Collection of helpers for OpenMP contexts ----===//
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///
10/// This file implements helper functions and classes to deal with OpenMP
11/// contexts as used by `[begin/end] declare variant` and `metadirective`.
12///
13//===----------------------------------------------------------------------===//
14
16#include "llvm/ADT/StringRef.h"
18#include "llvm/Support/Debug.h"
21
22#define DEBUG_TYPE "openmp-ir-builder"
23
24using namespace llvm;
25using namespace omp;
26
27OMPContext::OMPContext(bool IsDeviceCompilation, Triple TargetTriple,
28 Triple TargetOffloadTriple, int DeviceNum) {
29 // Add the appropriate target device kind trait based on the target triple
30 if (!TargetOffloadTriple.getTriple().empty() && DeviceNum > -1) {
31 // If target triple is present, then target device is not a host
32 ActiveTraits.set(unsigned(TraitProperty::target_device_kind_nohost));
33 switch (TargetOffloadTriple.getArch()) {
34 case Triple::arm:
35 case Triple::armeb:
36 case Triple::aarch64:
39 case Triple::mips:
40 case Triple::mipsel:
41 case Triple::mips64:
43 case Triple::ppc:
44 case Triple::ppcle:
45 case Triple::ppc64:
46 case Triple::ppc64le:
47 case Triple::systemz:
48 case Triple::x86:
49 case Triple::x86_64:
50 ActiveTraits.set(unsigned(TraitProperty::target_device_kind_cpu));
51 break;
52 case Triple::amdgcn:
53 case Triple::nvptx:
54 case Triple::nvptx64:
55 case Triple::spirv64:
56 ActiveTraits.set(unsigned(TraitProperty::target_device_kind_gpu));
57 break;
58 default:
59 break;
60 }
61 // Add the appropriate device architecture trait based on the triple.
62#define OMP_TRAIT_PROPERTY(Enum, TraitSetEnum, TraitSelectorEnum, Str) \
63 if (TraitSelector::TraitSelectorEnum == TraitSelector::target_device_arch) { \
64 if (TargetOffloadTriple.getArch() == \
65 TargetOffloadTriple.getArchTypeForLLVMName(Str)) \
66 ActiveTraits.set(unsigned(TraitProperty::Enum)); \
67 if (StringRef(Str) == "x86_64" && \
68 TargetOffloadTriple.getArch() == Triple::x86_64) \
69 ActiveTraits.set(unsigned(TraitProperty::Enum)); \
70 }
71#include "llvm/Frontend/OpenMP/OMPKinds.def"
72 } else {
73 // Add the appropriate device kind trait based on the triple and the
74 // IsDeviceCompilation flag.
75 ActiveTraits.set(unsigned(IsDeviceCompilation
76 ? TraitProperty::device_kind_nohost
77 : TraitProperty::device_kind_host));
78 ActiveTraits.set(unsigned(TraitProperty::target_device_kind_host));
79 switch (TargetTriple.getArch()) {
80 case Triple::arm:
81 case Triple::armeb:
82 case Triple::aarch64:
85 case Triple::mips:
86 case Triple::mipsel:
87 case Triple::mips64:
89 case Triple::ppc:
90 case Triple::ppcle:
91 case Triple::ppc64:
92 case Triple::ppc64le:
93 case Triple::systemz:
94 case Triple::x86:
95 case Triple::x86_64:
96 ActiveTraits.set(unsigned(TraitProperty::device_kind_cpu));
97 ActiveTraits.set(unsigned(TraitProperty::target_device_kind_cpu));
98 break;
99 case Triple::amdgcn:
100 case Triple::nvptx:
101 case Triple::nvptx64:
102 case Triple::spirv64:
103 ActiveTraits.set(unsigned(TraitProperty::device_kind_gpu));
104 ActiveTraits.set(unsigned(TraitProperty::target_device_kind_gpu));
105 break;
106 default:
107 break;
108 }
109
110 // Add the appropriate device architecture trait based on the triple.
111#define OMP_TRAIT_PROPERTY(Enum, TraitSetEnum, TraitSelectorEnum, Str) \
112 if (TraitSelector::TraitSelectorEnum == TraitSelector::device_arch || \
113 TraitSelector::TraitSelectorEnum == TraitSelector::target_device_arch) { \
114 if (TargetTriple.getArch() == TargetTriple.getArchTypeForLLVMName(Str)) \
115 ActiveTraits.set(unsigned(TraitProperty::Enum)); \
116 if (StringRef(Str) == "x86_64" && \
117 TargetTriple.getArch() == Triple::x86_64) \
118 ActiveTraits.set(unsigned(TraitProperty::Enum)); \
119 }
120#include "llvm/Frontend/OpenMP/OMPKinds.def"
121
122 // TODO: What exactly do we want to see as device ISA trait?
123 // The discussion on the list did not seem to have come to an agreed
124 // upon solution.
125
126 // LLVM is the "OpenMP vendor" but we could also interpret vendor as the
127 // target vendor.
128 ActiveTraits.set(unsigned(TraitProperty::implementation_vendor_llvm));
129
130 // The user condition true is accepted but not false.
131 ActiveTraits.set(unsigned(TraitProperty::user_condition_true));
132
133 // This is for sure some device.
134 ActiveTraits.set(unsigned(TraitProperty::device_kind_any));
135
136 LLVM_DEBUG({
137 dbgs() << "[" << DEBUG_TYPE
138 << "] New OpenMP context with the following properties:\n";
139 for (unsigned Bit : ActiveTraits.set_bits()) {
140 TraitProperty Property = TraitProperty(Bit);
141 dbgs() << "\t " << getOpenMPContextTraitPropertyFullName(Property)
142 << "\n";
143 }
144 });
145 }
146}
147
148/// Return true if \p C0 is a subset of \p C1. Note that both arrays are
149/// expected to be sorted.
150template <typename T> static bool isSubset(ArrayRef<T> C0, ArrayRef<T> C1) {
151#ifdef EXPENSIVE_CHECKS
153 "Expected sorted arrays!");
154#endif
155 if (C0.size() > C1.size())
156 return false;
157 auto It0 = C0.begin(), End0 = C0.end();
158 auto It1 = C1.begin(), End1 = C1.end();
159 while (It0 != End0) {
160 if (It1 == End1)
161 return false;
162 if (*It0 == *It1) {
163 ++It0;
164 ++It1;
165 continue;
166 }
167 ++It0;
168 }
169 return true;
170}
171
172/// Return true if \p C0 is a strict subset of \p C1. Note that both arrays are
173/// expected to be sorted.
174template <typename T>
176 if (C0.size() >= C1.size())
177 return false;
178 return isSubset<T>(C0, C1);
179}
180
181static bool isStrictSubset(const VariantMatchInfo &VMI0,
182 const VariantMatchInfo &VMI1) {
183 // If all required traits are a strict subset and the ordered vectors storing
184 // the construct traits, we say it is a strict subset. Note that the latter
185 // relation is not required to be strict.
186 if (VMI0.RequiredTraits.count() >= VMI1.RequiredTraits.count())
187 return false;
188 for (unsigned Bit : VMI0.RequiredTraits.set_bits())
189 if (!VMI1.RequiredTraits.test(Bit))
190 return false;
191 if (!isSubset<TraitProperty>(VMI0.ConstructTraits, VMI1.ConstructTraits))
192 return false;
193 return true;
194}
195
197 const VariantMatchInfo &VMI, const OMPContext &Ctx,
198 SmallVectorImpl<unsigned> *ConstructMatches, bool DeviceSetOnly) {
199
200 // The match kind determines if we need to match all traits, any of the
201 // traits, or none of the traits for it to be an applicable context.
202 enum MatchKind { MK_ALL, MK_ANY, MK_NONE };
203
204 MatchKind MK = MK_ALL;
205 // Determine the match kind the user wants, "all" is the default and provided
206 // to the user only for completeness.
207 if (VMI.RequiredTraits.test(
208 unsigned(TraitProperty::implementation_extension_match_any)))
209 MK = MK_ANY;
210 if (VMI.RequiredTraits.test(
211 unsigned(TraitProperty::implementation_extension_match_none)))
212 MK = MK_NONE;
213
214 // Helper to deal with a single property that was (not) found in the OpenMP
215 // context based on the match kind selected by the user via
216 // `implementation={extensions(match_[all,any,none])}'
217 auto HandleTrait = [MK](TraitProperty Property,
218 bool WasFound) -> std::optional<bool> /* Result */ {
219 // For kind "any" a single match is enough but we ignore non-matched
220 // properties.
221 if (MK == MK_ANY) {
222 if (WasFound)
223 return true;
224 return std::nullopt;
225 }
226
227 // In "all" or "none" mode we accept a matching or non-matching property
228 // respectively and move on. We are not done yet!
229 if ((WasFound && MK == MK_ALL) || (!WasFound && MK == MK_NONE))
230 return std::nullopt;
231
232 // We missed a property, provide some debug output and indicate failure.
233 LLVM_DEBUG({
234 if (MK == MK_ALL)
235 dbgs() << "[" << DEBUG_TYPE << "] Property "
236 << getOpenMPContextTraitPropertyName(Property, "")
237 << " was not in the OpenMP context but match kind is all.\n";
238 if (MK == MK_NONE)
239 dbgs() << "[" << DEBUG_TYPE << "] Property "
240 << getOpenMPContextTraitPropertyName(Property, "")
241 << " was in the OpenMP context but match kind is none.\n";
242 });
243 return false;
244 };
245
246 for (unsigned Bit : VMI.RequiredTraits.set_bits()) {
247 TraitProperty Property = TraitProperty(Bit);
248 if (DeviceSetOnly &&
249 getOpenMPContextTraitSetForProperty(Property) != TraitSet::device)
250 continue;
251
252 // So far all extensions are handled elsewhere, we skip them here as they
253 // are not part of the OpenMP context.
255 TraitSelector::implementation_extension)
256 continue;
257
258 bool IsActiveTrait = Ctx.ActiveTraits.test(unsigned(Property));
259
260 // We overwrite the isa trait as it is actually up to the OMPContext hook to
261 // check the raw string(s).
262 if (Property == TraitProperty::device_isa___ANY)
263 IsActiveTrait = llvm::all_of(VMI.ISATraits, [&](StringRef RawString) {
264 return Ctx.matchesISATrait(RawString);
265 });
266 if (Property == TraitProperty::target_device_isa___ANY)
267 IsActiveTrait = llvm::all_of(VMI.ISATraits, [&](StringRef RawString) {
268 return Ctx.matchesISATrait(RawString);
269 });
270
271 if (std::optional<bool> Result = HandleTrait(Property, IsActiveTrait))
272 return *Result;
273 }
274
275 if (!DeviceSetOnly) {
276 // We could use isSubset here but we also want to record the match
277 // locations.
278 unsigned ConstructIdx = 0, NoConstructTraits = Ctx.ConstructTraits.size();
279 for (TraitProperty Property : VMI.ConstructTraits) {
281 TraitSet::construct &&
282 "Variant context is ill-formed!");
283
284 // Verify the nesting.
285 bool FoundInOrder = false;
286 while (!FoundInOrder && ConstructIdx != NoConstructTraits)
287 FoundInOrder = (Ctx.ConstructTraits[ConstructIdx++] == Property);
288 if (ConstructMatches)
289 ConstructMatches->push_back(ConstructIdx - 1);
290
291 if (std::optional<bool> Result = HandleTrait(Property, FoundInOrder))
292 return *Result;
293
294 if (!FoundInOrder) {
295 LLVM_DEBUG(dbgs() << "[" << DEBUG_TYPE << "] Construct property "
296 << getOpenMPContextTraitPropertyName(Property, "")
297 << " was not nested properly.\n");
298 return false;
299 }
300
301 // TODO: Verify SIMD
302 }
303
304 assert(isSubset<TraitProperty>(VMI.ConstructTraits, Ctx.ConstructTraits) &&
305 "Broken invariant!");
306 }
307
308 if (MK == MK_ANY) {
309 LLVM_DEBUG(dbgs() << "[" << DEBUG_TYPE
310 << "] None of the properties was in the OpenMP context "
311 "but match kind is any.\n");
312 return false;
313 }
314
315 return true;
316}
317
319 const OMPContext &Ctx,
320 bool DeviceSetOnly) {
322 VMI, Ctx, /* ConstructMatches */ nullptr, DeviceSetOnly);
323}
324
326 const OMPContext &Ctx,
327 SmallVectorImpl<unsigned> &ConstructMatches) {
328 APInt Score(64, 1);
329
330 unsigned NoConstructTraits = VMI.ConstructTraits.size();
331 for (unsigned Bit : VMI.RequiredTraits.set_bits()) {
332 TraitProperty Property = TraitProperty(Bit);
333 // If there is a user score attached, use it.
334 if (VMI.ScoreMap.count(Property)) {
335 const APInt &UserScore = VMI.ScoreMap.lookup(Property);
336 assert(UserScore.uge(0) && "Expect non-negative user scores!");
337 Score += UserScore.getZExtValue();
338 continue;
339 }
340
341 switch (getOpenMPContextTraitSetForProperty(Property)) {
342 case TraitSet::construct:
343 // We handle the construct traits later via the VMI.ConstructTraits
344 // container.
345 continue;
346 case TraitSet::implementation:
347 // No effect on the score (implementation defined).
348 continue;
349 case TraitSet::user:
350 // No effect on the score.
351 continue;
352 case TraitSet::device:
353 // Handled separately below.
354 break;
355 case TraitSet::target_device:
356 // TODO: Handling separately.
357 break;
358 case TraitSet::invalid:
359 llvm_unreachable("Unknown trait set is not to be used!");
360 }
361
362 // device={kind(any)} is "as if" no kind selector was specified.
363 if (Property == TraitProperty::device_kind_any)
364 continue;
365 if (Property == TraitProperty::target_device_kind_any)
366 continue;
367
369 case TraitSelector::device_kind:
370 Score += (1ULL << (NoConstructTraits + 0));
371 continue;
372 case TraitSelector::device_arch:
373 Score += (1ULL << (NoConstructTraits + 1));
374 continue;
375 case TraitSelector::device_isa:
376 Score += (1ULL << (NoConstructTraits + 2));
377 continue;
378 case TraitSelector::target_device_kind:
379 Score += (1ULL << (NoConstructTraits + 0));
380 continue;
381 case TraitSelector::target_device_arch:
382 Score += (1ULL << (NoConstructTraits + 1));
383 continue;
384 case TraitSelector::target_device_isa:
385 Score += (1ULL << (NoConstructTraits + 2));
386 continue;
387 default:
388 continue;
389 }
390 }
391
392 unsigned ConstructIdx = 0;
393 assert(NoConstructTraits == ConstructMatches.size() &&
394 "Mismatch in the construct traits!");
395 for (TraitProperty Property : VMI.ConstructTraits) {
397 TraitSet::construct &&
398 "Ill-formed variant match info!");
399 (void)Property;
400 // ConstructMatches is the position p - 1 and we need 2^(p-1).
401 Score += (1ULL << ConstructMatches[ConstructIdx++]);
402 }
403
404 LLVM_DEBUG(dbgs() << "[" << DEBUG_TYPE << "] Variant has a score of " << Score
405 << "\n");
406 return Score;
407}
408
410 const SmallVectorImpl<VariantMatchInfo> &VMIs, const OMPContext &Ctx) {
411
412 APInt BestScore(64, 0);
413 int BestVMIIdx = -1;
414 const VariantMatchInfo *BestVMI = nullptr;
415
416 for (unsigned u = 0, e = VMIs.size(); u < e; ++u) {
417 const VariantMatchInfo &VMI = VMIs[u];
418
419 SmallVector<unsigned, 8> ConstructMatches;
420 // If the variant is not applicable its not the best.
421 if (!isVariantApplicableInContextHelper(VMI, Ctx, &ConstructMatches,
422 /* DeviceSetOnly */ false))
423 continue;
424 // Check if its clearly not the best.
425 APInt Score = getVariantMatchScore(VMI, Ctx, ConstructMatches);
426 if (Score.ult(BestScore))
427 continue;
428 // Equal score need subset checks.
429 if (Score.eq(BestScore)) {
430 // Strict subset are never best.
431 if (isStrictSubset(VMI, *BestVMI))
432 continue;
433 // Same score and the current best is no strict subset so we keep it.
434 if (!isStrictSubset(*BestVMI, VMI))
435 continue;
436 }
437 // New best found.
438 BestVMI = &VMI;
439 BestVMIIdx = u;
440 BestScore = Score;
441 }
442
443 return BestVMIIdx;
444}
445
447 return StringSwitch<TraitSet>(S)
448#define OMP_TRAIT_SET(Enum, Str) .Case(Str, TraitSet::Enum)
449#include "llvm/Frontend/OpenMP/OMPKinds.def"
450 .Default(TraitSet::invalid);
451}
452
455 switch (Selector) {
456#define OMP_TRAIT_SELECTOR(Enum, TraitSetEnum, Str, ReqProp) \
457 case TraitSelector::Enum: \
458 return TraitSet::TraitSetEnum;
459#include "llvm/Frontend/OpenMP/OMPKinds.def"
460 }
461 llvm_unreachable("Unknown trait selector!");
462}
465 switch (Property) {
466#define OMP_TRAIT_PROPERTY(Enum, TraitSetEnum, TraitSelectorEnum, Str) \
467 case TraitProperty::Enum: \
468 return TraitSet::TraitSetEnum;
469#include "llvm/Frontend/OpenMP/OMPKinds.def"
470 }
471 llvm_unreachable("Unknown trait set!");
472}
474 switch (Kind) {
475#define OMP_TRAIT_SET(Enum, Str) \
476 case TraitSet::Enum: \
477 return Str;
478#include "llvm/Frontend/OpenMP/OMPKinds.def"
479 }
480 llvm_unreachable("Unknown trait set!");
481}
482
484 TraitSet Set) {
485 if (Set == TraitSet::target_device && S == "kind")
486 return TraitSelector::target_device_kind;
487 if (Set == TraitSet::target_device && S == "arch")
488 return TraitSelector::target_device_arch;
489 if (Set == TraitSet::target_device && S == "isa")
490 return TraitSelector::target_device_isa;
492#define OMP_TRAIT_SELECTOR(Enum, TraitSetEnum, Str, ReqProp) \
493 .Case(Str, TraitSelector::Enum)
494#include "llvm/Frontend/OpenMP/OMPKinds.def"
495 .Default(TraitSelector::invalid);
496}
499 switch (Property) {
500#define OMP_TRAIT_PROPERTY(Enum, TraitSetEnum, TraitSelectorEnum, Str) \
501 case TraitProperty::Enum: \
502 return TraitSelector::TraitSelectorEnum;
503#include "llvm/Frontend/OpenMP/OMPKinds.def"
504 }
505 llvm_unreachable("Unknown trait set!");
506}
508 switch (Kind) {
509#define OMP_TRAIT_SELECTOR(Enum, TraitSetEnum, Str, ReqProp) \
510 case TraitSelector::Enum: \
511 return Str;
512#include "llvm/Frontend/OpenMP/OMPKinds.def"
513 }
514 llvm_unreachable("Unknown trait selector!");
515}
516
518 TraitSet Set, TraitSelector Selector, StringRef S) {
519 // Special handling for `device={isa(...)}` as we accept anything here. It is
520 // up to the target to decide if the feature is available.
521 if (Set == TraitSet::device && Selector == TraitSelector::device_isa)
522 return TraitProperty::device_isa___ANY;
523 if (Set == TraitSet::target_device &&
524 Selector == TraitSelector::target_device_isa)
525 return TraitProperty::target_device_isa___ANY;
526#define OMP_TRAIT_PROPERTY(Enum, TraitSetEnum, TraitSelectorEnum, Str) \
527 if (Set == TraitSet::TraitSetEnum && Str == S) \
528 return TraitProperty::Enum;
529#include "llvm/Frontend/OpenMP/OMPKinds.def"
530 return TraitProperty::invalid;
531}
536#define OMP_TRAIT_PROPERTY(Enum, TraitSetEnum, TraitSelectorEnum, Str) \
537 .Case(Str, Selector == TraitSelector::TraitSelectorEnum \
538 ? TraitProperty::Enum \
539 : TraitProperty::invalid)
540#include "llvm/Frontend/OpenMP/OMPKinds.def"
541 .Default(TraitProperty::invalid);
542}
544 StringRef RawString) {
545 if (Kind == TraitProperty::device_isa___ANY)
546 return RawString;
547 if (Kind == TraitProperty::target_device_isa___ANY)
548 return RawString;
549 switch (Kind) {
550#define OMP_TRAIT_PROPERTY(Enum, TraitSetEnum, TraitSelectorEnum, Str) \
551 case TraitProperty::Enum: \
552 return Str;
553#include "llvm/Frontend/OpenMP/OMPKinds.def"
554 }
555 llvm_unreachable("Unknown trait property!");
556}
558 switch (Kind) {
559#define OMP_TRAIT_PROPERTY(Enum, TraitSetEnum, TraitSelectorEnum, Str) \
560 case TraitProperty::Enum: \
561 return "(" #TraitSetEnum "," #TraitSelectorEnum "," Str ")";
562#include "llvm/Frontend/OpenMP/OMPKinds.def"
563 }
564 llvm_unreachable("Unknown trait property!");
565}
566
568 TraitSet Set,
569 bool &AllowsTraitScore,
570 bool &RequiresProperty) {
571 AllowsTraitScore = Set != TraitSet::construct && Set != TraitSet::device &&
572 Set != TraitSet::target_device;
573 switch (Selector) {
574#define OMP_TRAIT_SELECTOR(Enum, TraitSetEnum, Str, ReqProp) \
575 case TraitSelector::Enum: \
576 RequiresProperty = ReqProp; \
577 return Set == TraitSet::TraitSetEnum;
578#include "llvm/Frontend/OpenMP/OMPKinds.def"
579 }
580 llvm_unreachable("Unknown trait selector!");
581}
582
584 TraitProperty Property, TraitSelector Selector, TraitSet Set) {
585 switch (Property) {
586#define OMP_TRAIT_PROPERTY(Enum, TraitSetEnum, TraitSelectorEnum, Str) \
587 case TraitProperty::Enum: \
588 return Set == TraitSet::TraitSetEnum && \
589 Selector == TraitSelector::TraitSelectorEnum;
590#include "llvm/Frontend/OpenMP/OMPKinds.def"
591 }
592 llvm_unreachable("Unknown trait property!");
593}
594
596 std::string S;
597#define OMP_TRAIT_SET(Enum, Str) \
598 if (StringRef(Str) != "invalid") \
599 S.append("'").append(Str).append("'").append(" ");
600#include "llvm/Frontend/OpenMP/OMPKinds.def"
601 S.pop_back();
602 return S;
603}
604
606 std::string S;
607#define OMP_TRAIT_SELECTOR(Enum, TraitSetEnum, Str, ReqProp) \
608 if (TraitSet::TraitSetEnum == Set && StringRef(Str) != "Invalid") \
609 S.append("'").append(Str).append("'").append(" ");
610#include "llvm/Frontend/OpenMP/OMPKinds.def"
611 S.pop_back();
612 return S;
613}
614
615std::string
617 TraitSelector Selector) {
618 std::string S;
619#define OMP_TRAIT_PROPERTY(Enum, TraitSetEnum, TraitSelectorEnum, Str) \
620 if (TraitSet::TraitSetEnum == Set && \
621 TraitSelector::TraitSelectorEnum == Selector && \
622 StringRef(Str) != "invalid") \
623 S.append("'").append(Str).append("'").append(" ");
624#include "llvm/Frontend/OpenMP/OMPKinds.def"
625 if (S.empty())
626 return "<none>";
627 S.pop_back();
628 return S;
629}
#define LLVM_DEBUG(...)
Definition: Debug.h:106
#define DEBUG_TYPE
static bool isStrictSubset(ArrayRef< T > C0, ArrayRef< T > C1)
Return true if C0 is a strict subset of C1.
Definition: OMPContext.cpp:175
static APInt getVariantMatchScore(const VariantMatchInfo &VMI, const OMPContext &Ctx, SmallVectorImpl< unsigned > &ConstructMatches)
Definition: OMPContext.cpp:325
static bool isSubset(ArrayRef< T > C0, ArrayRef< T > C1)
Return true if C0 is a subset of C1.
Definition: OMPContext.cpp:150
static int isVariantApplicableInContextHelper(const VariantMatchInfo &VMI, const OMPContext &Ctx, SmallVectorImpl< unsigned > *ConstructMatches, bool DeviceSetOnly)
Definition: OMPContext.cpp:196
This file provides helper functions and classes to deal with OpenMP contexts as used by [begin/end] d...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file implements the StringSwitch template, which mimics a switch() statement whose cases are str...
Class for arbitrary precision integers.
Definition: APInt.h:78
uint64_t getZExtValue() const
Get zero extended value.
Definition: APInt.h:1520
bool ult(const APInt &RHS) const
Unsigned less than comparison.
Definition: APInt.h:1111
bool eq(const APInt &RHS) const
Equality comparison.
Definition: APInt.h:1079
bool uge(const APInt &RHS) const
Unsigned greater or equal comparison.
Definition: APInt.h:1221
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
iterator end() const
Definition: ArrayRef.h:157
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:168
iterator begin() const
Definition: ArrayRef.h:156
bool test(unsigned Idx) const
Definition: BitVector.h:461
size_type count() const
count - Returns the number of bits which are set.
Definition: BitVector.h:162
BitVector & set()
Definition: BitVector.h:351
iterator_range< const_set_bits_iterator > set_bits() const
Definition: BitVector.h:140
size_t size() const
Definition: SmallVector.h:78
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: SmallVector.h:573
void push_back(const T &Elt)
Definition: SmallVector.h:413
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1196
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:51
A switch()-like statement whose cases are string literals.
Definition: StringSwitch.h:43
R Default(T Value)
Definition: StringSwitch.h:177
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
@ aarch64_be
Definition: Triple.h:52
@ mips64el
Definition: Triple.h:67
@ aarch64_32
Definition: Triple.h:53
ArchType getArch() const
Get the parsed architecture type of this triple.
Definition: Triple.h:395
const std::string & getTriple() const
Definition: Triple.h:464
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
std::string listOpenMPContextTraitSets()
Return a string listing all trait sets.
Definition: OMPContext.cpp:595
StringRef getOpenMPContextTraitPropertyFullName(TraitProperty Kind)
Return a textual representation of the trait property Kind with selector and set name included.
Definition: OMPContext.cpp:557
bool isValidTraitSelectorForTraitSet(TraitSelector Selector, TraitSet Set, bool &AllowsTraitScore, bool &RequiresProperty)
}
Definition: OMPContext.cpp:567
TraitSet getOpenMPContextTraitSetForSelector(TraitSelector Selector)
Return the trait set for which Selector is a selector.
Definition: OMPContext.cpp:454
TraitSelector getOpenMPContextTraitSelectorKind(StringRef Str, TraitSet Set)
Parse Str and return the trait set it matches or TraitSelector::invalid.
Definition: OMPContext.cpp:483
TraitSet getOpenMPContextTraitSetForProperty(TraitProperty Property)
Return the trait set for which Property is a property.
Definition: OMPContext.cpp:464
int getBestVariantMatchForContext(const SmallVectorImpl< VariantMatchInfo > &VMIs, const OMPContext &Ctx)
Return the index (into VMIs) of the variant with the highest score from the ones applicble in Ctx.
Definition: OMPContext.cpp:409
StringRef getOpenMPContextTraitSetName(TraitSet Kind)
Return a textual representation of the trait set Kind.
Definition: OMPContext.cpp:473
StringRef getOpenMPContextTraitPropertyName(TraitProperty Kind, StringRef RawString)
Return a textual representation of the trait property Kind, which might be the raw string we parsed (...
Definition: OMPContext.cpp:543
TraitProperty getOpenMPContextTraitPropertyKind(TraitSet Set, TraitSelector Selector, StringRef Str)
Parse Str and return the trait property it matches in the set Set and selector Selector or TraitPrope...
Definition: OMPContext.cpp:517
StringRef getOpenMPContextTraitSelectorName(TraitSelector Kind)
Return a textual representation of the trait selector Kind.
Definition: OMPContext.cpp:507
std::string listOpenMPContextTraitSelectors(TraitSet Set)
Return a string listing all trait selectors for Set.
Definition: OMPContext.cpp:605
TraitSet
OpenMP Context related IDs and helpers.
Definition: OMPContext.h:33
TraitSelector getOpenMPContextTraitSelectorForProperty(TraitProperty Property)
Return the trait selector for which Property is a property.
Definition: OMPContext.cpp:498
TraitProperty getOpenMPContextTraitPropertyForSelector(TraitSelector Selector)
Return the trait property for a singleton selector Selector.
Definition: OMPContext.cpp:533
TraitSelector
IDs for all OpenMP context selector trait (device={kind/isa...}/...).
Definition: OMPContext.h:39
TraitSet getOpenMPContextTraitSetKind(StringRef Str)
Parse Str and return the trait set it matches or TraitSet::invalid.
Definition: OMPContext.cpp:446
TraitProperty
IDs for all OpenMP context trait properties (host/gpu/bsc/llvm/...)
Definition: OMPContext.h:45
bool isVariantApplicableInContext(const VariantMatchInfo &VMI, const OMPContext &Ctx, bool DeviceSetOnly=false)
Return true if VMI is applicable in Ctx, that is, all traits required by VMI are available in the Ope...
Definition: OMPContext.cpp:318
bool isValidTraitPropertyForTraitSetAndSelector(TraitProperty Property, TraitSelector Selector, TraitSet Set)
Return true if Property can be nested in Selector and Set.
Definition: OMPContext.cpp:583
std::string listOpenMPContextTraitProperties(TraitSet Set, TraitSelector Selector)
Return a string listing all trait properties for Set and Selector.
Definition: OMPContext.cpp:616
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1739
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:163
bool is_sorted(R &&Range, Compare C)
Wrapper function around std::is_sorted to check if elements in a range R are sorted with respect to a...
Definition: STLExtras.h:1926
The context for a source location is made up of active property traits, e.g., device={kind(host)},...
Definition: OMPContext.h:159
OMPContext(bool IsDeviceCompilation, Triple TargetTriple, Triple TargetOffloadTriple, int DeviceNum)
Definition: OMPContext.cpp:27
BitVector ActiveTraits
Definition: OMPContext.h:178
SmallVector< TraitProperty, 8 > ConstructTraits
Definition: OMPContext.h:179
Variant match information describes the required traits and how they are scored (via the ScoresMap).
Definition: OMPContext.h:119
SmallVector< StringRef, 8 > ISATraits
Definition: OMPContext.h:151
SmallVector< TraitProperty, 8 > ConstructTraits
Definition: OMPContext.h:152
SmallDenseMap< TraitProperty, APInt > ScoreMap
Definition: OMPContext.h:153