LLVM 20.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 // Add the appropriate device kind trait based on the triple and the
29 // IsDeviceCompilation flag.
30 ActiveTraits.set(unsigned(IsDeviceCompilation
31 ? TraitProperty::device_kind_nohost
32 : TraitProperty::device_kind_host));
33 switch (TargetTriple.getArch()) {
34 case Triple::arm:
35 case Triple::armeb:
36 case Triple::aarch64:
40 case Triple::mips:
41 case Triple::mipsel:
42 case Triple::mips64:
44 case Triple::ppc:
45 case Triple::ppcle:
46 case Triple::ppc64:
47 case Triple::ppc64le:
48 case Triple::systemz:
49 case Triple::x86:
50 case Triple::x86_64:
51 ActiveTraits.set(unsigned(TraitProperty::device_kind_cpu));
52 break;
53 case Triple::amdgcn:
54 case Triple::nvptx:
55 case Triple::nvptx64:
56 ActiveTraits.set(unsigned(TraitProperty::device_kind_gpu));
57 break;
58 default:
59 break;
60 }
61
62 // Add the appropriate device architecture trait based on the triple.
63#define OMP_TRAIT_PROPERTY(Enum, TraitSetEnum, TraitSelectorEnum, Str) \
64 if (TraitSelector::TraitSelectorEnum == TraitSelector::device_arch) { \
65 if (TargetTriple.getArch() == TargetTriple.getArchTypeForLLVMName(Str)) \
66 ActiveTraits.set(unsigned(TraitProperty::Enum)); \
67 if (StringRef(Str) == "x86_64" && \
68 TargetTriple.getArch() == Triple::x86_64) \
69 ActiveTraits.set(unsigned(TraitProperty::Enum)); \
70 }
71#include "llvm/Frontend/OpenMP/OMPKinds.def"
72
73 // TODO: What exactly do we want to see as device ISA trait?
74 // The discussion on the list did not seem to have come to an agreed
75 // upon solution.
76
77 // LLVM is the "OpenMP vendor" but we could also interpret vendor as the
78 // target vendor.
79 ActiveTraits.set(unsigned(TraitProperty::implementation_vendor_llvm));
80
81 // The user condition true is accepted but not false.
82 ActiveTraits.set(unsigned(TraitProperty::user_condition_true));
83
84 // This is for sure some device.
85 ActiveTraits.set(unsigned(TraitProperty::device_kind_any));
86
88 dbgs() << "[" << DEBUG_TYPE
89 << "] New OpenMP context with the following properties:\n";
90 for (unsigned Bit : ActiveTraits.set_bits()) {
91 TraitProperty Property = TraitProperty(Bit);
92 dbgs() << "\t " << getOpenMPContextTraitPropertyFullName(Property)
93 << "\n";
94 }
95 });
96}
97
98/// Return true if \p C0 is a subset of \p C1. Note that both arrays are
99/// expected to be sorted.
100template <typename T> static bool isSubset(ArrayRef<T> C0, ArrayRef<T> C1) {
101#ifdef EXPENSIVE_CHECKS
103 "Expected sorted arrays!");
104#endif
105 if (C0.size() > C1.size())
106 return false;
107 auto It0 = C0.begin(), End0 = C0.end();
108 auto It1 = C1.begin(), End1 = C1.end();
109 while (It0 != End0) {
110 if (It1 == End1)
111 return false;
112 if (*It0 == *It1) {
113 ++It0;
114 ++It1;
115 continue;
116 }
117 ++It0;
118 }
119 return true;
120}
121
122/// Return true if \p C0 is a strict subset of \p C1. Note that both arrays are
123/// expected to be sorted.
124template <typename T>
126 if (C0.size() >= C1.size())
127 return false;
128 return isSubset<T>(C0, C1);
129}
130
131static bool isStrictSubset(const VariantMatchInfo &VMI0,
132 const VariantMatchInfo &VMI1) {
133 // If all required traits are a strict subset and the ordered vectors storing
134 // the construct traits, we say it is a strict subset. Note that the latter
135 // relation is not required to be strict.
136 if (VMI0.RequiredTraits.count() >= VMI1.RequiredTraits.count())
137 return false;
138 for (unsigned Bit : VMI0.RequiredTraits.set_bits())
139 if (!VMI1.RequiredTraits.test(Bit))
140 return false;
141 if (!isSubset<TraitProperty>(VMI0.ConstructTraits, VMI1.ConstructTraits))
142 return false;
143 return true;
144}
145
147 const VariantMatchInfo &VMI, const OMPContext &Ctx,
148 SmallVectorImpl<unsigned> *ConstructMatches, bool DeviceSetOnly) {
149
150 // The match kind determines if we need to match all traits, any of the
151 // traits, or none of the traits for it to be an applicable context.
152 enum MatchKind { MK_ALL, MK_ANY, MK_NONE };
153
154 MatchKind MK = MK_ALL;
155 // Determine the match kind the user wants, "all" is the default and provided
156 // to the user only for completeness.
157 if (VMI.RequiredTraits.test(
158 unsigned(TraitProperty::implementation_extension_match_any)))
159 MK = MK_ANY;
160 if (VMI.RequiredTraits.test(
161 unsigned(TraitProperty::implementation_extension_match_none)))
162 MK = MK_NONE;
163
164 // Helper to deal with a single property that was (not) found in the OpenMP
165 // context based on the match kind selected by the user via
166 // `implementation={extensions(match_[all,any,none])}'
167 auto HandleTrait = [MK](TraitProperty Property,
168 bool WasFound) -> std::optional<bool> /* Result */ {
169 // For kind "any" a single match is enough but we ignore non-matched
170 // properties.
171 if (MK == MK_ANY) {
172 if (WasFound)
173 return true;
174 return std::nullopt;
175 }
176
177 // In "all" or "none" mode we accept a matching or non-matching property
178 // respectively and move on. We are not done yet!
179 if ((WasFound && MK == MK_ALL) || (!WasFound && MK == MK_NONE))
180 return std::nullopt;
181
182 // We missed a property, provide some debug output and indicate failure.
183 LLVM_DEBUG({
184 if (MK == MK_ALL)
185 dbgs() << "[" << DEBUG_TYPE << "] Property "
186 << getOpenMPContextTraitPropertyName(Property, "")
187 << " was not in the OpenMP context but match kind is all.\n";
188 if (MK == MK_NONE)
189 dbgs() << "[" << DEBUG_TYPE << "] Property "
190 << getOpenMPContextTraitPropertyName(Property, "")
191 << " was in the OpenMP context but match kind is none.\n";
192 });
193 return false;
194 };
195
196 for (unsigned Bit : VMI.RequiredTraits.set_bits()) {
197 TraitProperty Property = TraitProperty(Bit);
198 if (DeviceSetOnly &&
199 getOpenMPContextTraitSetForProperty(Property) != TraitSet::device)
200 continue;
201
202 // So far all extensions are handled elsewhere, we skip them here as they
203 // are not part of the OpenMP context.
205 TraitSelector::implementation_extension)
206 continue;
207
208 bool IsActiveTrait = Ctx.ActiveTraits.test(unsigned(Property));
209
210 // We overwrite the isa trait as it is actually up to the OMPContext hook to
211 // check the raw string(s).
212 if (Property == TraitProperty::device_isa___ANY)
213 IsActiveTrait = llvm::all_of(VMI.ISATraits, [&](StringRef RawString) {
214 return Ctx.matchesISATrait(RawString);
215 });
216
217 if (std::optional<bool> Result = HandleTrait(Property, IsActiveTrait))
218 return *Result;
219 }
220
221 if (!DeviceSetOnly) {
222 // We could use isSubset here but we also want to record the match
223 // locations.
224 unsigned ConstructIdx = 0, NoConstructTraits = Ctx.ConstructTraits.size();
225 for (TraitProperty Property : VMI.ConstructTraits) {
227 TraitSet::construct &&
228 "Variant context is ill-formed!");
229
230 // Verify the nesting.
231 bool FoundInOrder = false;
232 while (!FoundInOrder && ConstructIdx != NoConstructTraits)
233 FoundInOrder = (Ctx.ConstructTraits[ConstructIdx++] == Property);
234 if (ConstructMatches)
235 ConstructMatches->push_back(ConstructIdx - 1);
236
237 if (std::optional<bool> Result = HandleTrait(Property, FoundInOrder))
238 return *Result;
239
240 if (!FoundInOrder) {
241 LLVM_DEBUG(dbgs() << "[" << DEBUG_TYPE << "] Construct property "
242 << getOpenMPContextTraitPropertyName(Property, "")
243 << " was not nested properly.\n");
244 return false;
245 }
246
247 // TODO: Verify SIMD
248 }
249
250 assert(isSubset<TraitProperty>(VMI.ConstructTraits, Ctx.ConstructTraits) &&
251 "Broken invariant!");
252 }
253
254 if (MK == MK_ANY) {
255 LLVM_DEBUG(dbgs() << "[" << DEBUG_TYPE
256 << "] None of the properties was in the OpenMP context "
257 "but match kind is any.\n");
258 return false;
259 }
260
261 return true;
262}
263
265 const OMPContext &Ctx,
266 bool DeviceSetOnly) {
268 VMI, Ctx, /* ConstructMatches */ nullptr, DeviceSetOnly);
269}
270
272 const OMPContext &Ctx,
273 SmallVectorImpl<unsigned> &ConstructMatches) {
274 APInt Score(64, 1);
275
276 unsigned NoConstructTraits = VMI.ConstructTraits.size();
277 for (unsigned Bit : VMI.RequiredTraits.set_bits()) {
278 TraitProperty Property = TraitProperty(Bit);
279 // If there is a user score attached, use it.
280 if (VMI.ScoreMap.count(Property)) {
281 const APInt &UserScore = VMI.ScoreMap.lookup(Property);
282 assert(UserScore.uge(0) && "Expect non-negative user scores!");
283 Score += UserScore.getZExtValue();
284 continue;
285 }
286
287 switch (getOpenMPContextTraitSetForProperty(Property)) {
288 case TraitSet::construct:
289 // We handle the construct traits later via the VMI.ConstructTraits
290 // container.
291 continue;
292 case TraitSet::implementation:
293 // No effect on the score (implementation defined).
294 continue;
295 case TraitSet::user:
296 // No effect on the score.
297 continue;
298 case TraitSet::device:
299 // Handled separately below.
300 break;
301 case TraitSet::invalid:
302 llvm_unreachable("Unknown trait set is not to be used!");
303 }
304
305 // device={kind(any)} is "as if" no kind selector was specified.
306 if (Property == TraitProperty::device_kind_any)
307 continue;
308
310 case TraitSelector::device_kind:
311 Score += (1ULL << (NoConstructTraits + 0));
312 continue;
313 case TraitSelector::device_arch:
314 Score += (1ULL << (NoConstructTraits + 1));
315 continue;
316 case TraitSelector::device_isa:
317 Score += (1ULL << (NoConstructTraits + 2));
318 continue;
319 default:
320 continue;
321 }
322 }
323
324 unsigned ConstructIdx = 0;
325 assert(NoConstructTraits == ConstructMatches.size() &&
326 "Mismatch in the construct traits!");
327 for (TraitProperty Property : VMI.ConstructTraits) {
329 TraitSet::construct &&
330 "Ill-formed variant match info!");
331 (void)Property;
332 // ConstructMatches is the position p - 1 and we need 2^(p-1).
333 Score += (1ULL << ConstructMatches[ConstructIdx++]);
334 }
335
336 LLVM_DEBUG(dbgs() << "[" << DEBUG_TYPE << "] Variant has a score of " << Score
337 << "\n");
338 return Score;
339}
340
342 const SmallVectorImpl<VariantMatchInfo> &VMIs, const OMPContext &Ctx) {
343
344 APInt BestScore(64, 0);
345 int BestVMIIdx = -1;
346 const VariantMatchInfo *BestVMI = nullptr;
347
348 for (unsigned u = 0, e = VMIs.size(); u < e; ++u) {
349 const VariantMatchInfo &VMI = VMIs[u];
350
351 SmallVector<unsigned, 8> ConstructMatches;
352 // If the variant is not applicable its not the best.
353 if (!isVariantApplicableInContextHelper(VMI, Ctx, &ConstructMatches,
354 /* DeviceSetOnly */ false))
355 continue;
356 // Check if its clearly not the best.
357 APInt Score = getVariantMatchScore(VMI, Ctx, ConstructMatches);
358 if (Score.ult(BestScore))
359 continue;
360 // Equal score need subset checks.
361 if (Score.eq(BestScore)) {
362 // Strict subset are never best.
363 if (isStrictSubset(VMI, *BestVMI))
364 continue;
365 // Same score and the current best is no strict subset so we keep it.
366 if (!isStrictSubset(*BestVMI, VMI))
367 continue;
368 }
369 // New best found.
370 BestVMI = &VMI;
371 BestVMIIdx = u;
372 BestScore = Score;
373 }
374
375 return BestVMIIdx;
376}
377
379 return StringSwitch<TraitSet>(S)
380#define OMP_TRAIT_SET(Enum, Str) .Case(Str, TraitSet::Enum)
381#include "llvm/Frontend/OpenMP/OMPKinds.def"
382 .Default(TraitSet::invalid);
383}
384
387 switch (Selector) {
388#define OMP_TRAIT_SELECTOR(Enum, TraitSetEnum, Str, ReqProp) \
389 case TraitSelector::Enum: \
390 return TraitSet::TraitSetEnum;
391#include "llvm/Frontend/OpenMP/OMPKinds.def"
392 }
393 llvm_unreachable("Unknown trait selector!");
394}
397 switch (Property) {
398#define OMP_TRAIT_PROPERTY(Enum, TraitSetEnum, TraitSelectorEnum, Str) \
399 case TraitProperty::Enum: \
400 return TraitSet::TraitSetEnum;
401#include "llvm/Frontend/OpenMP/OMPKinds.def"
402 }
403 llvm_unreachable("Unknown trait set!");
404}
406 switch (Kind) {
407#define OMP_TRAIT_SET(Enum, Str) \
408 case TraitSet::Enum: \
409 return Str;
410#include "llvm/Frontend/OpenMP/OMPKinds.def"
411 }
412 llvm_unreachable("Unknown trait set!");
413}
414
417#define OMP_TRAIT_SELECTOR(Enum, TraitSetEnum, Str, ReqProp) \
418 .Case(Str, TraitSelector::Enum)
419#include "llvm/Frontend/OpenMP/OMPKinds.def"
420 .Default(TraitSelector::invalid);
421}
424 switch (Property) {
425#define OMP_TRAIT_PROPERTY(Enum, TraitSetEnum, TraitSelectorEnum, Str) \
426 case TraitProperty::Enum: \
427 return TraitSelector::TraitSelectorEnum;
428#include "llvm/Frontend/OpenMP/OMPKinds.def"
429 }
430 llvm_unreachable("Unknown trait set!");
431}
433 switch (Kind) {
434#define OMP_TRAIT_SELECTOR(Enum, TraitSetEnum, Str, ReqProp) \
435 case TraitSelector::Enum: \
436 return Str;
437#include "llvm/Frontend/OpenMP/OMPKinds.def"
438 }
439 llvm_unreachable("Unknown trait selector!");
440}
441
443 TraitSet Set, TraitSelector Selector, StringRef S) {
444 // Special handling for `device={isa(...)}` as we accept anything here. It is
445 // up to the target to decide if the feature is available.
446 if (Set == TraitSet::device && Selector == TraitSelector::device_isa)
447 return TraitProperty::device_isa___ANY;
448#define OMP_TRAIT_PROPERTY(Enum, TraitSetEnum, TraitSelectorEnum, Str) \
449 if (Set == TraitSet::TraitSetEnum && Str == S) \
450 return TraitProperty::Enum;
451#include "llvm/Frontend/OpenMP/OMPKinds.def"
452 return TraitProperty::invalid;
453}
458#define OMP_TRAIT_PROPERTY(Enum, TraitSetEnum, TraitSelectorEnum, Str) \
459 .Case(Str, Selector == TraitSelector::TraitSelectorEnum \
460 ? TraitProperty::Enum \
461 : TraitProperty::invalid)
462#include "llvm/Frontend/OpenMP/OMPKinds.def"
463 .Default(TraitProperty::invalid);
464}
466 StringRef RawString) {
467 if (Kind == TraitProperty::device_isa___ANY)
468 return RawString;
469 switch (Kind) {
470#define OMP_TRAIT_PROPERTY(Enum, TraitSetEnum, TraitSelectorEnum, Str) \
471 case TraitProperty::Enum: \
472 return Str;
473#include "llvm/Frontend/OpenMP/OMPKinds.def"
474 }
475 llvm_unreachable("Unknown trait property!");
476}
478 switch (Kind) {
479#define OMP_TRAIT_PROPERTY(Enum, TraitSetEnum, TraitSelectorEnum, Str) \
480 case TraitProperty::Enum: \
481 return "(" #TraitSetEnum "," #TraitSelectorEnum "," Str ")";
482#include "llvm/Frontend/OpenMP/OMPKinds.def"
483 }
484 llvm_unreachable("Unknown trait property!");
485}
486
488 TraitSet Set,
489 bool &AllowsTraitScore,
490 bool &RequiresProperty) {
491 AllowsTraitScore = Set != TraitSet::construct && Set != TraitSet::device;
492 switch (Selector) {
493#define OMP_TRAIT_SELECTOR(Enum, TraitSetEnum, Str, ReqProp) \
494 case TraitSelector::Enum: \
495 RequiresProperty = ReqProp; \
496 return Set == TraitSet::TraitSetEnum;
497#include "llvm/Frontend/OpenMP/OMPKinds.def"
498 }
499 llvm_unreachable("Unknown trait selector!");
500}
501
503 TraitProperty Property, TraitSelector Selector, TraitSet Set) {
504 switch (Property) {
505#define OMP_TRAIT_PROPERTY(Enum, TraitSetEnum, TraitSelectorEnum, Str) \
506 case TraitProperty::Enum: \
507 return Set == TraitSet::TraitSetEnum && \
508 Selector == TraitSelector::TraitSelectorEnum;
509#include "llvm/Frontend/OpenMP/OMPKinds.def"
510 }
511 llvm_unreachable("Unknown trait property!");
512}
513
515 std::string S;
516#define OMP_TRAIT_SET(Enum, Str) \
517 if (StringRef(Str) != "invalid") \
518 S.append("'").append(Str).append("'").append(" ");
519#include "llvm/Frontend/OpenMP/OMPKinds.def"
520 S.pop_back();
521 return S;
522}
523
525 std::string S;
526#define OMP_TRAIT_SELECTOR(Enum, TraitSetEnum, Str, ReqProp) \
527 if (TraitSet::TraitSetEnum == Set && StringRef(Str) != "Invalid") \
528 S.append("'").append(Str).append("'").append(" ");
529#include "llvm/Frontend/OpenMP/OMPKinds.def"
530 S.pop_back();
531 return S;
532}
533
534std::string
536 TraitSelector Selector) {
537 std::string S;
538#define OMP_TRAIT_PROPERTY(Enum, TraitSetEnum, TraitSelectorEnum, Str) \
539 if (TraitSet::TraitSetEnum == Set && \
540 TraitSelector::TraitSelectorEnum == Selector && \
541 StringRef(Str) != "invalid") \
542 S.append("'").append(Str).append("'").append(" ");
543#include "llvm/Frontend/OpenMP/OMPKinds.def"
544 if (S.empty())
545 return "<none>";
546 S.pop_back();
547 return S;
548}
#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:125
static APInt getVariantMatchScore(const VariantMatchInfo &VMI, const OMPContext &Ctx, SmallVectorImpl< unsigned > &ConstructMatches)
Definition: OMPContext.cpp:271
static bool isSubset(ArrayRef< T > C0, ArrayRef< T > C1)
Return true if C0 is a subset of C1.
Definition: OMPContext.cpp:100
static int isVariantApplicableInContextHelper(const VariantMatchInfo &VMI, const OMPContext &Ctx, SmallVectorImpl< unsigned > *ConstructMatches, bool DeviceSetOnly)
Definition: OMPContext.cpp:146
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:44
R Default(T Value)
Definition: StringSwitch.h:182
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
@ aarch64_be
Definition: Triple.h:52
@ loongarch64
Definition: Triple.h:62
@ 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:383
#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:514
StringRef getOpenMPContextTraitPropertyFullName(TraitProperty Kind)
Return a textual representation of the trait property Kind with selector and set name included.
Definition: OMPContext.cpp:477
bool isValidTraitSelectorForTraitSet(TraitSelector Selector, TraitSet Set, bool &AllowsTraitScore, bool &RequiresProperty)
}
Definition: OMPContext.cpp:487
TraitSet getOpenMPContextTraitSetForSelector(TraitSelector Selector)
Return the trait set for which Selector is a selector.
Definition: OMPContext.cpp:386
TraitSet getOpenMPContextTraitSetForProperty(TraitProperty Property)
Return the trait set for which Property is a property.
Definition: OMPContext.cpp:396
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:341
StringRef getOpenMPContextTraitSetName(TraitSet Kind)
Return a textual representation of the trait set Kind.
Definition: OMPContext.cpp:405
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:465
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:442
StringRef getOpenMPContextTraitSelectorName(TraitSelector Kind)
Return a textual representation of the trait selector Kind.
Definition: OMPContext.cpp:432
TraitSelector getOpenMPContextTraitSelectorKind(StringRef Str)
Parse Str and return the trait set it matches or TraitSelector::invalid.
Definition: OMPContext.cpp:415
std::string listOpenMPContextTraitSelectors(TraitSet Set)
Return a string listing all trait selectors for Set.
Definition: OMPContext.cpp:524
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:423
TraitProperty getOpenMPContextTraitPropertyForSelector(TraitSelector Selector)
Return the trait property for a singleton selector Selector.
Definition: OMPContext.cpp:455
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:378
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:264
bool isValidTraitPropertyForTraitSetAndSelector(TraitProperty Property, TraitSelector Selector, TraitSet Set)
Return true if Property can be nested in Selector and Set.
Definition: OMPContext.cpp:502
std::string listOpenMPContextTraitProperties(TraitSet Set, TraitSelector Selector)
Return a string listing all trait properties for Set and Selector.
Definition: OMPContext.cpp:535
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:157
OMPContext(bool IsDeviceCompilation, Triple TargetTriple)
Definition: OMPContext.cpp:27
BitVector ActiveTraits
Definition: OMPContext.h:175
SmallVector< TraitProperty, 8 > ConstructTraits
Definition: OMPContext.h:176
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:149
SmallVector< TraitProperty, 8 > ConstructTraits
Definition: OMPContext.h:150
SmallDenseMap< TraitProperty, APInt > ScoreMap
Definition: OMPContext.h:151