LLVM 24.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/DenseSet.h"
17#include "llvm/ADT/StringRef.h"
19#include "llvm/Support/Debug.h"
22#include <algorithm>
23
24#define DEBUG_TYPE "openmp-ir-builder"
25
26using namespace llvm;
27using namespace omp;
28
29OMPContext::OMPContext(bool IsDeviceCompilation, Triple TargetTriple,
30 Triple TargetOffloadTriple, int DeviceNum) {
31 // Add the appropriate target device kind trait based on the target triple
32 if (!TargetOffloadTriple.getTriple().empty() && DeviceNum > -1) {
33 // If target triple is present, then target device is not a host
34 ActiveTraits.set(unsigned(TraitProperty::target_device_kind_nohost));
35 switch (TargetOffloadTriple.getArch()) {
36 case Triple::arm:
37 case Triple::armeb:
38 case Triple::aarch64:
41 case Triple::mips:
42 case Triple::mipsel:
43 case Triple::mips64:
45 case Triple::ppc:
46 case Triple::ppcle:
47 case Triple::ppc64:
48 case Triple::ppc64le:
49 case Triple::systemz:
50 case Triple::x86:
51 case Triple::x86_64:
52 ActiveTraits.set(unsigned(TraitProperty::target_device_kind_cpu));
53 break;
54 case Triple::amdgpu:
55 case Triple::nvptx:
56 case Triple::nvptx64:
57 case Triple::spirv64:
58 ActiveTraits.set(unsigned(TraitProperty::target_device_kind_gpu));
59 break;
60 default:
61 break;
62 }
63 // Add the appropriate device architecture trait based on the triple.
64#define OMP_TRAIT_PROPERTY(Enum, TraitSetEnum, TraitSelectorEnum, Str) \
65 if (TraitSelector::TraitSelectorEnum == TraitSelector::target_device_arch) { \
66 if (TargetOffloadTriple.getArch() == Triple::parseArch(Str)) \
67 ActiveTraits.set(unsigned(TraitProperty::Enum)); \
68 }
69#include "llvm/Frontend/OpenMP/OMPKinds.def"
70 } else {
71 // Add the appropriate device kind trait based on the triple and the
72 // IsDeviceCompilation flag.
73 ActiveTraits.set(unsigned(IsDeviceCompilation
74 ? TraitProperty::device_kind_nohost
75 : TraitProperty::device_kind_host));
76 ActiveTraits.set(unsigned(TraitProperty::target_device_kind_host));
77 switch (TargetTriple.getArch()) {
78 case Triple::arm:
79 case Triple::armeb:
80 case Triple::aarch64:
83 case Triple::mips:
84 case Triple::mipsel:
85 case Triple::mips64:
87 case Triple::ppc:
88 case Triple::ppcle:
89 case Triple::ppc64:
90 case Triple::ppc64le:
91 case Triple::systemz:
92 case Triple::x86:
93 case Triple::x86_64:
94 ActiveTraits.set(unsigned(TraitProperty::device_kind_cpu));
95 ActiveTraits.set(unsigned(TraitProperty::target_device_kind_cpu));
96 break;
97 case Triple::amdgpu:
98 case Triple::nvptx:
99 case Triple::nvptx64:
100 case Triple::spirv64:
101 ActiveTraits.set(unsigned(TraitProperty::device_kind_gpu));
102 ActiveTraits.set(unsigned(TraitProperty::target_device_kind_gpu));
103 break;
104 default:
105 break;
106 }
107
108 // Add the appropriate device architecture trait based on the triple.
109#define OMP_TRAIT_PROPERTY(Enum, TraitSetEnum, TraitSelectorEnum, Str) \
110 if (TraitSelector::TraitSelectorEnum == TraitSelector::device_arch || \
111 TraitSelector::TraitSelectorEnum == TraitSelector::target_device_arch) { \
112 if (TargetTriple.getArch() == Triple::parseArch(Str)) \
113 ActiveTraits.set(unsigned(TraitProperty::Enum)); \
114 }
115#include "llvm/Frontend/OpenMP/OMPKinds.def"
116
117 // TODO: What exactly do we want to see as device ISA trait?
118 // The discussion on the list did not seem to have come to an agreed
119 // upon solution.
120
121 // LLVM is the "OpenMP vendor" but we could also interpret vendor as the
122 // target vendor.
123 ActiveTraits.set(unsigned(TraitProperty::implementation_vendor_llvm));
124
125 // The user condition true is accepted but not false.
126 ActiveTraits.set(unsigned(TraitProperty::user_condition_true));
127
128 // This is for sure some device.
129 ActiveTraits.set(unsigned(TraitProperty::device_kind_any));
130
131 LLVM_DEBUG({
132 dbgs() << "[" << DEBUG_TYPE
133 << "] New OpenMP context with the following properties:\n";
134 for (unsigned Bit : ActiveTraits.set_bits()) {
137 << "\n";
138 }
139 });
140 }
141}
142
143/// Return true if \p C0 is an ordered subsequence of \p C1.
144template <typename T>
146 if (C0.size() > C1.size())
147 return false;
148 auto It0 = C0.begin(), End0 = C0.end();
149 auto It1 = C1.begin(), End1 = C1.end();
150 while (It0 != End0) {
151 if (It1 == End1)
152 return false;
153 if (*It0 == *It1) {
154 ++It0;
155 ++It1;
156 continue;
157 }
158 ++It1;
159 }
160 return true;
161}
162
163static bool isStrictSubset(const VariantMatchInfo &VMI0,
164 const VariantMatchInfo &VMI1) {
165 // VMI0 is a strict subset if its required traits are a subset of VMI1's, its
166 // construct traits are an ordered subsequence of VMI1's, and either relation
167 // is strict.
168 if (VMI0.RequiredTraits.count() > VMI1.RequiredTraits.count())
169 return false;
170 for (unsigned Bit : VMI0.RequiredTraits.set_bits())
171 if (!VMI1.RequiredTraits.test(Bit))
172 return false;
173 // Different ISA names share a trait, so compare them as well.
174 if (!llvm::all_of(VMI0.ISATraits,
175 [&](const VariantMatchInfo::ISATrait &Trait) {
176 return llvm::is_contained(VMI1.ISATraits, Trait);
177 }))
178 return false;
180 VMI1.ConstructTraits))
181 return false;
182 if (VMI0.RequiredTraits.count() < VMI1.RequiredTraits.count())
183 return true;
184 // With the same traits, only a repeated construct makes VMI0 strict.
185 if (VMI0.ConstructTraits.size() == VMI1.ConstructTraits.size())
186 return false;
187 // Different conditions share a trait, so they can't be compared.
189 {TraitProperty::user_condition_true, TraitProperty::user_condition_false,
190 TraitProperty::user_condition_unknown})
191 if (VMI0.RequiredTraits.test(unsigned(Property)))
192 return false;
193 return true;
194}
195
196static int
198 const OMPContext &Ctx,
199 SmallVectorImpl<unsigned> *ConstructMatches,
200 bool DeviceOrImplementationSetOnly) {
201
202 // The match kind determines if we need to match all traits, any of the
203 // traits, or none of the traits for it to be an applicable context.
204 enum MatchKind { MK_ALL, MK_ANY, MK_NONE };
205
206 MatchKind MK = MK_ALL;
207 // Determine the match kind the user wants, "all" is the default and provided
208 // to the user only for completeness.
209 if (VMI.RequiredTraits.test(
210 unsigned(TraitProperty::implementation_extension_match_any)))
211 MK = MK_ANY;
212 if (VMI.RequiredTraits.test(
213 unsigned(TraitProperty::implementation_extension_match_none)))
214 MK = MK_NONE;
215
216 bool AnyTraitMatched = false;
217
218 // Apply the match kind selected by implementation={extension(...)} to
219 // each property. Continue after match_any succeeds to record all construct
220 // match positions needed for scoring.
221 auto HandleTrait = [MK, &AnyTraitMatched](TraitProperty Property,
222 bool WasFound) -> bool {
223 AnyTraitMatched |= WasFound;
224 if (MK == MK_ANY)
225 return true;
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 true;
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 "
237 << " was not in the OpenMP context but match kind is all.\n";
238 if (MK == MK_NONE)
239 dbgs() << "[" << DEBUG_TYPE << "] 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()) {
248 if (DeviceOrImplementationSetOnly &&
249 getOpenMPContextTraitSetForProperty(Property) != TraitSet::device &&
251 TraitSet::implementation)
252 continue;
253
254 // So far all extensions are handled elsewhere, we skip them here as they
255 // are not part of the OpenMP context.
257 TraitSelector::implementation_extension)
258 continue;
259
260 bool IsActiveTrait = Ctx.ActiveTraits.test(unsigned(Property));
261
262 // We overwrite the isa trait as it is actually up to the OMPContext hook to
263 // check the raw string(s).
264 if (Property == TraitProperty::device_isa___ANY ||
265 Property == TraitProperty::target_device_isa___ANY)
266 IsActiveTrait = llvm::all_of(VMI.ISATraits, [&](const auto &Trait) {
267 return Trait.Property != Property || Ctx.matchesISATrait(Trait.Name);
268 });
269
270 if (!HandleTrait(Property, IsActiveTrait))
271 return false;
272 // The match_any result is known; skip ISA lookups, which can warn.
273 if (MK == MK_ANY && AnyTraitMatched)
274 break;
275 }
276
277 if (!DeviceOrImplementationSetOnly) {
278 // Scan the construct sequence in order, recording matching context
279 // positions for scoring.
280 unsigned ConstructIdx = 0, NoConstructTraits = Ctx.ConstructTraits.size();
283 TraitSet::construct &&
284 "Variant context is ill-formed!");
285
286 // Verify the nesting. A failed match in match_any or match_none must not
287 // consume the remaining context, since a later selector property can
288 // still match.
289 unsigned SearchStart = ConstructIdx;
290 bool FoundInOrder = false;
291 while (!FoundInOrder && ConstructIdx != NoConstructTraits)
292 FoundInOrder = (Ctx.ConstructTraits[ConstructIdx++] == Property);
293 if (!FoundInOrder && MK != MK_ALL)
294 ConstructIdx = SearchStart;
295 if (ConstructMatches && FoundInOrder)
296 ConstructMatches->push_back(ConstructIdx - 1);
297
298 if (!HandleTrait(Property, FoundInOrder)) {
299 LLVM_DEBUG(dbgs() << "[" << DEBUG_TYPE << "] Construct property "
301 << " was not nested properly.\n");
302 return false;
303 }
304
305 // TODO: Verify SIMD
306 }
307
308 // A complete ordered match can have several embeddings in the context.
309 // Match backwards to choose the highest-valued one for scoring. Keep the
310 // forward scan's partial matches for the match_any extension.
311 if (ConstructMatches &&
312 ConstructMatches->size() == VMI.ConstructTraits.size()) {
313 ConstructIdx = NoConstructTraits;
314 for (unsigned I = VMI.ConstructTraits.size(); I > 0; --I) {
316 while (ConstructIdx > 0 &&
317 Ctx.ConstructTraits[ConstructIdx - 1] != Property)
318 --ConstructIdx;
319 assert(ConstructIdx > 0 && "Previously matched construct not found!");
320 (*ConstructMatches)[I - 1] = --ConstructIdx;
321 }
322 }
323
324 if (MK == MK_ALL)
326 Ctx.ConstructTraits) &&
327 "Broken invariant!");
328 }
329
330 if (MK == MK_ANY && !AnyTraitMatched) {
331 LLVM_DEBUG(dbgs() << "[" << DEBUG_TYPE
332 << "] None of the properties was in the OpenMP context "
333 "but match kind is any.\n");
334 return false;
335 }
336
337 return true;
338}
339
341 const VariantMatchInfo &VMI, const OMPContext &Ctx,
342 bool DeviceOrImplementationSetOnly) {
344 VMI, Ctx, /* ConstructMatches */ nullptr, DeviceOrImplementationSetOnly);
345}
346
348 const OMPContext &Ctx,
349 SmallVectorImpl<unsigned> &ConstructMatches) {
350 APInt Score(1, 1);
351
352 // A sum of valid scores can exceed the width of any individual score.
353 // Retain all active bits and allow one more bit for each addition's carry.
354 auto AddScore = [&](const APInt &Value) {
355 unsigned Width = std::max(Score.getActiveBits(), Value.getActiveBits()) + 1;
356 Score = Score.zextOrTrunc(Width);
357 Score += Value.zextOrTrunc(Width);
358 };
359 auto AddPowerOfTwo = [&](unsigned Exponent) {
360 AddScore(APInt::getOneBitSet(Exponent + 1, Exponent));
361 };
362
363 unsigned NoConstructTraits = Ctx.ConstructTraits.size();
364 SmallDenseSet<TraitSelector, 8> ScoredSelectors;
365 auto AddSelectorScore = [&](TraitSelector Selector, const APInt *UserScore) {
366 // Scores belong to selectors, not to individual properties.
367 if (!ScoredSelectors.insert(Selector).second)
368 return;
369 if (UserScore) {
370 AddScore(*UserScore);
371 return;
372 }
373 switch (Selector) {
374 case TraitSelector::device_kind:
375 case TraitSelector::target_device_kind:
376 AddPowerOfTwo(NoConstructTraits);
377 break;
378 case TraitSelector::device_arch:
379 case TraitSelector::target_device_arch:
380 AddPowerOfTwo(NoConstructTraits + 1);
381 break;
382 case TraitSelector::device_isa:
383 case TraitSelector::target_device_isa:
384 AddPowerOfTwo(NoConstructTraits + 2);
385 break;
386 default:
387 break;
388 }
389 };
390 for (unsigned Bit : VMI.RequiredTraits.set_bits()) {
392 // Construct scores use ordered positions below, and unknown properties
393 // their UnknownTraits entries. kind(any) is treated as if no kind selector
394 // were specified.
395 if (getOpenMPContextTraitSetForProperty(Property) == TraitSet::construct ||
396 Property == TraitProperty::invalid ||
397 Property == TraitProperty::device_kind_any ||
398 Property == TraitProperty::target_device_kind_any)
399 continue;
400 auto It = VMI.ScoreMap.find(Property);
402 It == VMI.ScoreMap.end() ? nullptr : &It->second);
403 }
404 for (const VariantMatchInfo::UnknownTrait &Trait : VMI.UnknownTraits)
405 AddSelectorScore(Trait.Selector, Trait.Score ? &*Trait.Score : nullptr);
406
407 assert(VMI.ConstructTraits.size() >= ConstructMatches.size() &&
408 "Mismatch in the construct traits!");
409 for (unsigned Match : ConstructMatches) {
410 // ConstructMatches is the position p - 1 and we need 2^(p-1).
411 AddPowerOfTwo(Match);
412 }
413
414 LLVM_DEBUG({
415 dbgs() << "[" << DEBUG_TYPE << "] Variant has a score of ";
416 Score.print(dbgs(), /*isSigned=*/false);
417 dbgs() << "\n";
418 });
419 return Score;
420}
421
423 const SmallVectorImpl<VariantMatchInfo> &VMIs, const OMPContext &Ctx) {
424
425 APInt BestScore(1, 0);
426 SmallVector<unsigned, 4> BestVMIIdxs;
427
428 for (unsigned u = 0, e = VMIs.size(); u < e; ++u) {
429 const VariantMatchInfo &VMI = VMIs[u];
430
431 SmallVector<unsigned, 8> ConstructMatches;
432 // If the variant is not applicable its not the best.
434 VMI, Ctx, &ConstructMatches,
435 /* DeviceOrImplementationSetOnly */ false))
436 continue;
437 // Check if its clearly not the best.
438 APInt Score = getVariantMatchScore(VMI, Ctx, ConstructMatches);
439 unsigned Width = std::max(Score.getBitWidth(), BestScore.getBitWidth());
440 Score = Score.zextOrTrunc(Width);
441 BestScore = BestScore.zextOrTrunc(Width);
442 if (Score.ult(BestScore))
443 continue;
444 if (Score.ugt(BestScore)) {
445 BestScore = Score;
446 BestVMIIdxs.clear();
447 }
448 BestVMIIdxs.push_back(u);
449 }
450
451 // A strict subset of another tied variant is never best; otherwise the first
452 // one wins. Tied variants often share a few supersets, so try the ones found
453 // so far before scanning all of them.
455 for (unsigned Idx : BestVMIIdxs) {
456 const VariantMatchInfo &VMI = VMIs[Idx];
457 if (llvm::any_of(Supersets, [&](const VariantMatchInfo *Superset) {
458 return isStrictSubset(VMI, *Superset);
459 }))
460 continue;
461 auto *It = llvm::find_if(BestVMIIdxs, [&](unsigned OtherIdx) {
462 return isStrictSubset(VMI, VMIs[OtherIdx]);
463 });
464 if (It == BestVMIIdxs.end())
465 return Idx;
466 Supersets.push_back(&VMIs[*It]);
467 }
468 return -1;
469}
470
472 return StringSwitch<TraitSet>(S)
473#define OMP_TRAIT_SET(Enum, Str) .Case(Str, TraitSet::Enum)
474#include "llvm/Frontend/OpenMP/OMPKinds.def"
475 .Default(TraitSet::invalid);
476}
477
480 switch (Selector) {
481#define OMP_TRAIT_SELECTOR(Enum, TraitSetEnum, Str, ReqProp) \
482 case TraitSelector::Enum: \
483 return TraitSet::TraitSetEnum;
484#include "llvm/Frontend/OpenMP/OMPKinds.def"
485 }
486 llvm_unreachable("Unknown trait selector!");
487}
490 switch (Property) {
491#define OMP_TRAIT_PROPERTY(Enum, TraitSetEnum, TraitSelectorEnum, Str) \
492 case TraitProperty::Enum: \
493 return TraitSet::TraitSetEnum;
494#include "llvm/Frontend/OpenMP/OMPKinds.def"
495 }
496 llvm_unreachable("Unknown trait set!");
497}
499 switch (Kind) {
500#define OMP_TRAIT_SET(Enum, Str) \
501 case TraitSet::Enum: \
502 return Str;
503#include "llvm/Frontend/OpenMP/OMPKinds.def"
504 }
505 llvm_unreachable("Unknown trait set!");
506}
507
509 TraitSet Set) {
510 if (Set == TraitSet::target_device && S == "kind")
511 return TraitSelector::target_device_kind;
512 if (Set == TraitSet::target_device && S == "arch")
513 return TraitSelector::target_device_arch;
514 if (Set == TraitSet::target_device && S == "isa")
515 return TraitSelector::target_device_isa;
517#define OMP_TRAIT_SELECTOR(Enum, TraitSetEnum, Str, ReqProp) \
518 .Case(Str, TraitSelector::Enum)
519#include "llvm/Frontend/OpenMP/OMPKinds.def"
520 .Default(TraitSelector::invalid);
521}
524 switch (Property) {
525#define OMP_TRAIT_PROPERTY(Enum, TraitSetEnum, TraitSelectorEnum, Str) \
526 case TraitProperty::Enum: \
527 return TraitSelector::TraitSelectorEnum;
528#include "llvm/Frontend/OpenMP/OMPKinds.def"
529 }
530 llvm_unreachable("Unknown trait set!");
531}
533 switch (Kind) {
534#define OMP_TRAIT_SELECTOR(Enum, TraitSetEnum, Str, ReqProp) \
535 case TraitSelector::Enum: \
536 return Str;
537#include "llvm/Frontend/OpenMP/OMPKinds.def"
538 }
539 llvm_unreachable("Unknown trait selector!");
540}
541
543 TraitSet Set, TraitSelector Selector, StringRef S) {
544 // Special handling for `device={isa(...)}` as we accept anything here. It is
545 // up to the target to decide if the feature is available.
546 if (Set == TraitSet::device && Selector == TraitSelector::device_isa)
547 return TraitProperty::device_isa___ANY;
548 if (Set == TraitSet::target_device &&
549 Selector == TraitSelector::target_device_isa)
550 return TraitProperty::target_device_isa___ANY;
551#define OMP_TRAIT_PROPERTY(Enum, TraitSetEnum, TraitSelectorEnum, Str) \
552 if (Set == TraitSet::TraitSetEnum && Str == S) \
553 return TraitProperty::Enum;
554#include "llvm/Frontend/OpenMP/OMPKinds.def"
555 return TraitProperty::invalid;
556}
561#define OMP_TRAIT_PROPERTY(Enum, TraitSetEnum, TraitSelectorEnum, Str) \
562 .Case(Str, Selector == TraitSelector::TraitSelectorEnum \
563 ? TraitProperty::Enum \
564 : TraitProperty::invalid)
565#include "llvm/Frontend/OpenMP/OMPKinds.def"
566 .Default(TraitProperty::invalid);
567}
569 StringRef RawString) {
570 if (Kind == TraitProperty::device_isa___ANY)
571 return RawString;
572 if (Kind == TraitProperty::target_device_isa___ANY)
573 return RawString;
574 switch (Kind) {
575#define OMP_TRAIT_PROPERTY(Enum, TraitSetEnum, TraitSelectorEnum, Str) \
576 case TraitProperty::Enum: \
577 return Str;
578#include "llvm/Frontend/OpenMP/OMPKinds.def"
579 }
580 llvm_unreachable("Unknown trait property!");
581}
583 switch (Kind) {
584#define OMP_TRAIT_PROPERTY(Enum, TraitSetEnum, TraitSelectorEnum, Str) \
585 case TraitProperty::Enum: \
586 return "(" #TraitSetEnum "," #TraitSelectorEnum "," Str ")";
587#include "llvm/Frontend/OpenMP/OMPKinds.def"
588 }
589 llvm_unreachable("Unknown trait property!");
590}
591
593 TraitSet Set,
594 bool &AllowsTraitScore,
595 bool &RequiresProperty) {
596 AllowsTraitScore = Set != TraitSet::construct && Set != TraitSet::device &&
597 Set != TraitSet::target_device;
598 switch (Selector) {
599#define OMP_TRAIT_SELECTOR(Enum, TraitSetEnum, Str, ReqProp) \
600 case TraitSelector::Enum: \
601 RequiresProperty = ReqProp; \
602 return Set == TraitSet::TraitSetEnum;
603#include "llvm/Frontend/OpenMP/OMPKinds.def"
604 }
605 llvm_unreachable("Unknown trait selector!");
606}
607
610 switch (Property) {
611#define OMP_TRAIT_PROPERTY(Enum, TraitSetEnum, TraitSelectorEnum, Str) \
612 case TraitProperty::Enum: \
613 return Set == TraitSet::TraitSetEnum && \
614 Selector == TraitSelector::TraitSelectorEnum;
615#include "llvm/Frontend/OpenMP/OMPKinds.def"
616 }
617 llvm_unreachable("Unknown trait property!");
618}
619
621 std::string S;
622#define OMP_TRAIT_SET(Enum, Str) \
623 if (StringRef(Str) != "invalid") \
624 S.append("'").append(Str).append("'").append(" ");
625#include "llvm/Frontend/OpenMP/OMPKinds.def"
626 S.pop_back();
627 return S;
628}
629
631 std::string S;
632#define OMP_TRAIT_SELECTOR(Enum, TraitSetEnum, Str, ReqProp) \
633 if (TraitSet::TraitSetEnum == Set && StringRef(Str) != "Invalid") \
634 S.append("'").append(Str).append("'").append(" ");
635#include "llvm/Frontend/OpenMP/OMPKinds.def"
636 S.pop_back();
637 return S;
638}
639
640std::string
642 TraitSelector Selector) {
643 std::string S;
644#define OMP_TRAIT_PROPERTY(Enum, TraitSetEnum, TraitSelectorEnum, Str) \
645 if (TraitSet::TraitSetEnum == Set && \
646 TraitSelector::TraitSelectorEnum == Selector && \
647 StringRef(Str) != "invalid") \
648 S.append("'").append(Str).append("'").append(" ");
649#include "llvm/Frontend/OpenMP/OMPKinds.def"
650 if (S.empty())
651 return "<none>";
652 S.pop_back();
653 return S;
654}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file defines the DenseSet and SmallDenseSet classes.
#define DEBUG_TYPE
#define I(x, y, z)
Definition MD5.cpp:57
static APInt getVariantMatchScore(const VariantMatchInfo &VMI, const OMPContext &Ctx, SmallVectorImpl< unsigned > &ConstructMatches)
static bool isOrderedSubset(ArrayRef< T > C0, ArrayRef< T > C1)
Return true if C0 is an ordered subsequence of C1.
static int isVariantApplicableInContextHelper(const VariantMatchInfo &VMI, const OMPContext &Ctx, SmallVectorImpl< unsigned > *ConstructMatches, bool DeviceOrImplementationSetOnly)
static bool isStrictSubset(const VariantMatchInfo &VMI0, const VariantMatchInfo &VMI1)
This file provides helper functions and classes to deal with OpenMP contexts as used by [begin/end] d...
int64_t C1
int64_t C0
This file implements the StringSwitch template, which mimics a switch() statement whose cases are str...
#define LLVM_DEBUG(...)
Definition Debug.h:119
Class for arbitrary precision integers.
Definition APInt.h:78
LLVM_ABI APInt zextOrTrunc(unsigned width) const
Zero extend or truncate to width.
Definition APInt.cpp:1078
unsigned getActiveBits() const
Compute the number of active bits in the value.
Definition APInt.h:1532
bool ugt(const APInt &RHS) const
Unsigned greater than comparison.
Definition APInt.h:1186
LLVM_ABI void print(raw_ostream &OS, bool isSigned) const
Definition APInt.cpp:2354
unsigned getBitWidth() const
Return the number of bits in the APInt.
Definition APInt.h:1508
bool ult(const APInt &RHS) const
Unsigned less than comparison.
Definition APInt.h:1115
static APInt getOneBitSet(unsigned numBits, unsigned BitNo)
Return an APInt with exactly one bit set in the result.
Definition APInt.h:235
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
bool test(unsigned Idx) const
Returns true if bit Idx is set.
Definition BitVector.h:483
size_type count() const
Returns the number of bits which are set.
Definition BitVector.h:182
iterator_range< const_set_bits_iterator > set_bits() const
Definition BitVector.h:160
Implements a dense probed hash-table based set with some number of buckets stored inline.
Definition DenseSet.h:295
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
A switch()-like statement whose cases are string literals.
Triple - Helper class for working with autoconf configuration names.
Definition Triple.h:48
ArchType getArch() const
Get the parsed architecture type of this triple.
Definition Triple.h:517
const std::string & getTriple() const
Definition Triple.h:584
LLVM Value Representation.
Definition Value.h:75
std::pair< iterator, bool > insert(const ValueT &V)
Definition DenseSet.h:210
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
LLVM_ABI std::string listOpenMPContextTraitSets()
Return a string listing all trait sets.
LLVM_ABI StringRef getOpenMPContextTraitPropertyFullName(TraitProperty Kind)
Return a textual representation of the trait property Kind with selector and set name included.
LLVM_ABI bool isValidTraitSelectorForTraitSet(TraitSelector Selector, TraitSet Set, bool &AllowsTraitScore, bool &RequiresProperty)
}
LLVM_ABI TraitSet getOpenMPContextTraitSetForSelector(TraitSelector Selector)
Return the trait set for which Selector is a selector.
LLVM_ABI TraitSelector getOpenMPContextTraitSelectorKind(StringRef Str, TraitSet Set)
Parse Str and return the trait set it matches or TraitSelector::invalid.
LLVM_ABI TraitSet getOpenMPContextTraitSetForProperty(TraitProperty Property)
Return the trait set for which Property is a property.
LLVM_ABI int getBestVariantMatchForContext(const SmallVectorImpl< VariantMatchInfo > &VMIs, const OMPContext &Ctx)
Return the index (into VMIs) of the variant with the highest score from the ones applicable in Ctx.
LLVM_ABI StringRef getOpenMPContextTraitSetName(TraitSet Kind)
Return a textual representation of the trait set Kind.
LLVM_ABI StringRef getOpenMPContextTraitPropertyName(TraitProperty Kind, StringRef RawString)
Return a textual representation of the trait property Kind, which might be the raw string we parsed (...
LLVM_ABI 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...
LLVM_ABI StringRef getOpenMPContextTraitSelectorName(TraitSelector Kind)
Return a textual representation of the trait selector Kind.
LLVM_ABI std::string listOpenMPContextTraitSelectors(TraitSet Set)
Return a string listing all trait selectors for Set.
TraitSet
OpenMP Context related IDs and helpers.
Definition OMPContext.h:35
LLVM_ABI TraitSelector getOpenMPContextTraitSelectorForProperty(TraitProperty Property)
Return the trait selector for which Property is a property.
LLVM_ABI TraitProperty getOpenMPContextTraitPropertyForSelector(TraitSelector Selector)
Return the trait property for a singleton selector Selector.
TraitSelector
IDs for all OpenMP context selector trait (device={kind/isa...}/...).
Definition OMPContext.h:41
LLVM_ABI bool isVariantApplicableInContext(const VariantMatchInfo &VMI, const OMPContext &Ctx, bool DeviceOrImplementationSetOnly=false)
Return true if VMI is applicable in Ctx, that is, all traits required by VMI are available in the Ope...
LLVM_ABI TraitSet getOpenMPContextTraitSetKind(StringRef Str)
Parse Str and return the trait set it matches or TraitSet::invalid.
TraitProperty
IDs for all OpenMP context trait properties (host/gpu/bsc/llvm/...)
Definition OMPContext.h:47
LLVM_ABI bool isValidTraitPropertyForTraitSetAndSelector(TraitProperty Property, TraitSelector Selector, TraitSet Set)
Return true if Property can be nested in Selector and Set.
LLVM_ABI std::string listOpenMPContextTraitProperties(TraitSet Set, TraitSelector Selector)
Return a string listing all trait properties for Set and Selector.
This is an optimization pass for GlobalISel generic memory operations.
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:1755
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1762
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition Debug.cpp:209
auto find_if(R &&Range, UnaryPredicate P)
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1788
The context for a source location is made up of active property traits, e.g., device={kind(host)}...
Definition OMPContext.h:187
LLVM_ABI OMPContext(bool IsDeviceCompilation, Triple TargetTriple, Triple TargetOffloadTriple, int DeviceNum)
A device or target_device isa property and the ISA name it requires.
Definition OMPContext.h:127
Variant match information describes the required traits and how they are scored (via the ScoresMap).
Definition OMPContext.h:125
SmallVector< TraitProperty, 8 > ConstructTraits
Definition OMPContext.h:179
SmallVector< ISATrait, 8 > ISATraits
Definition OMPContext.h:178
SmallVector< UnknownTrait, 2 > UnknownTraits
Definition OMPContext.h:181
SmallDenseMap< TraitProperty, APInt > ScoreMap
Definition OMPContext.h:180