22#define DEBUG_TYPE "openmp-ir-builder"
31 ? TraitProperty::device_kind_nohost
32 : TraitProperty::device_kind_host));
33 switch (TargetTriple.
getArch()) {
62#define OMP_TRAIT_PROPERTY(Enum, TraitSetEnum, TraitSelectorEnum, Str) \
63 if (TraitSelector::TraitSelectorEnum == TraitSelector::device_arch) { \
64 if (TargetTriple.getArch() == TargetTriple.getArchTypeForLLVMName(Str)) \
65 ActiveTraits.set(unsigned(TraitProperty::Enum)); \
66 if (StringRef(Str) == "x86_64" && \
67 TargetTriple.getArch() == Triple::x86_64) \
68 ActiveTraits.set(unsigned(TraitProperty::Enum)); \
70#include "llvm/Frontend/OpenMP/OMPKinds.def"
88 <<
"] New OpenMP context with the following properties:\n";
100#ifdef EXPENSIVE_CHECKS
102 "Expected sorted arrays!");
106 auto It0 = C0.
begin(), End0 = C0.
end();
107 auto It1 = C1.
begin(), End1 = C1.
end();
108 while (It0 != End0) {
127 return isSubset<T>(C0, C1);
151 enum MatchKind { MK_ALL, MK_ANY, MK_NONE };
153 MatchKind MK = MK_ALL;
157 unsigned(TraitProperty::implementation_extension_match_any)))
160 unsigned(TraitProperty::implementation_extension_match_none)))
167 bool WasFound) -> std::optional<bool> {
178 if ((WasFound && MK == MK_ALL) || (!WasFound && MK == MK_NONE))
186 <<
" was not in the OpenMP context but match kind is all.\n";
190 <<
" was in the OpenMP context but match kind is none.\n";
204 TraitSelector::implementation_extension)
211 if (Property == TraitProperty::device_isa___ANY)
213 return Ctx.matchesISATrait(RawString);
216 if (std::optional<bool> Result = HandleTrait(Property, IsActiveTrait))
220 if (!DeviceSetOnly) {
226 TraitSet::construct &&
227 "Variant context is ill-formed!");
230 bool FoundInOrder =
false;
231 while (!FoundInOrder && ConstructIdx != NoConstructTraits)
233 if (ConstructMatches)
234 ConstructMatches->
push_back(ConstructIdx - 1);
236 if (std::optional<bool> Result = HandleTrait(Property, FoundInOrder))
242 <<
" was not nested properly.\n");
250 "Broken invariant!");
255 <<
"] None of the properties was in the OpenMP context "
256 "but match kind is any.\n");
265 bool DeviceSetOnly) {
267 VMI, Ctx,
nullptr, DeviceSetOnly);
281 assert(UserScore.
uge(0) &&
"Expect non-negative user scores!");
287 case TraitSet::construct:
291 case TraitSet::implementation:
297 case TraitSet::device:
300 case TraitSet::invalid:
305 if (Property == TraitProperty::device_kind_any)
309 case TraitSelector::device_kind:
310 Score += (1ULL << (NoConstructTraits + 0));
312 case TraitSelector::device_arch:
313 Score += (1ULL << (NoConstructTraits + 1));
315 case TraitSelector::device_isa:
316 Score += (1ULL << (NoConstructTraits + 2));
323 unsigned ConstructIdx = 0;
324 assert(NoConstructTraits == ConstructMatches.
size() &&
325 "Mismatch in the construct traits!");
328 TraitSet::construct &&
329 "Ill-formed variant match info!");
332 Score += (1ULL << ConstructMatches[ConstructIdx++]);
343 APInt BestScore(64, 0);
347 for (
unsigned u = 0, e = VMIs.
size(); u < e; ++u) {
357 if (Score.
ult(BestScore))
360 if (Score.
eq(BestScore)) {
379#define OMP_TRAIT_SET(Enum, Str) .Case(Str, TraitSet::Enum)
380#include "llvm/Frontend/OpenMP/OMPKinds.def"
387#define OMP_TRAIT_SELECTOR(Enum, TraitSetEnum, Str, ReqProp) \
388 case TraitSelector::Enum: \
389 return TraitSet::TraitSetEnum;
390#include "llvm/Frontend/OpenMP/OMPKinds.def"
397#define OMP_TRAIT_PROPERTY(Enum, TraitSetEnum, TraitSelectorEnum, Str) \
398 case TraitProperty::Enum: \
399 return TraitSet::TraitSetEnum;
400#include "llvm/Frontend/OpenMP/OMPKinds.def"
406#define OMP_TRAIT_SET(Enum, Str) \
407 case TraitSet::Enum: \
409#include "llvm/Frontend/OpenMP/OMPKinds.def"
416#define OMP_TRAIT_SELECTOR(Enum, TraitSetEnum, Str, ReqProp) \
417 .Case(Str, TraitSelector::Enum)
418#include "llvm/Frontend/OpenMP/OMPKinds.def"
419 .
Default(TraitSelector::invalid);
424#define OMP_TRAIT_PROPERTY(Enum, TraitSetEnum, TraitSelectorEnum, Str) \
425 case TraitProperty::Enum: \
426 return TraitSelector::TraitSelectorEnum;
427#include "llvm/Frontend/OpenMP/OMPKinds.def"
433#define OMP_TRAIT_SELECTOR(Enum, TraitSetEnum, Str, ReqProp) \
434 case TraitSelector::Enum: \
436#include "llvm/Frontend/OpenMP/OMPKinds.def"
445 if (Set == TraitSet::device && Selector == TraitSelector::device_isa)
446 return TraitProperty::device_isa___ANY;
447#define OMP_TRAIT_PROPERTY(Enum, TraitSetEnum, TraitSelectorEnum, Str) \
448 if (Set == TraitSet::TraitSetEnum && Str == S) \
449 return TraitProperty::Enum;
450#include "llvm/Frontend/OpenMP/OMPKinds.def"
451 return TraitProperty::invalid;
457#define OMP_TRAIT_PROPERTY(Enum, TraitSetEnum, TraitSelectorEnum, Str) \
458 .Case(Str, Selector == TraitSelector::TraitSelectorEnum \
459 ? TraitProperty::Enum \
460 : TraitProperty::invalid)
461#include "llvm/Frontend/OpenMP/OMPKinds.def"
462 .
Default(TraitProperty::invalid);
466 if (Kind == TraitProperty::device_isa___ANY)
469#define OMP_TRAIT_PROPERTY(Enum, TraitSetEnum, TraitSelectorEnum, Str) \
470 case TraitProperty::Enum: \
472#include "llvm/Frontend/OpenMP/OMPKinds.def"
478#define OMP_TRAIT_PROPERTY(Enum, TraitSetEnum, TraitSelectorEnum, Str) \
479 case TraitProperty::Enum: \
480 return "(" #TraitSetEnum "," #TraitSelectorEnum "," Str ")";
481#include "llvm/Frontend/OpenMP/OMPKinds.def"
488 bool &AllowsTraitScore,
489 bool &RequiresProperty) {
490 AllowsTraitScore = Set != TraitSet::construct && Set != TraitSet::device;
492#define OMP_TRAIT_SELECTOR(Enum, TraitSetEnum, Str, ReqProp) \
493 case TraitSelector::Enum: \
494 RequiresProperty = ReqProp; \
495 return Set == TraitSet::TraitSetEnum;
496#include "llvm/Frontend/OpenMP/OMPKinds.def"
504#define OMP_TRAIT_PROPERTY(Enum, TraitSetEnum, TraitSelectorEnum, Str) \
505 case TraitProperty::Enum: \
506 return Set == TraitSet::TraitSetEnum && \
507 Selector == TraitSelector::TraitSelectorEnum;
508#include "llvm/Frontend/OpenMP/OMPKinds.def"
515#define OMP_TRAIT_SET(Enum, Str) \
516 if (StringRef(Str) != "invalid") \
517 S.append("'").append(Str).append("'").append(" ");
518#include "llvm/Frontend/OpenMP/OMPKinds.def"
525#define OMP_TRAIT_SELECTOR(Enum, TraitSetEnum, Str, ReqProp) \
526 if (TraitSet::TraitSetEnum == Set && StringRef(Str) != "Invalid") \
527 S.append("'").append(Str).append("'").append(" ");
528#include "llvm/Frontend/OpenMP/OMPKinds.def"
537#define OMP_TRAIT_PROPERTY(Enum, TraitSetEnum, TraitSelectorEnum, Str) \
538 if (TraitSet::TraitSetEnum == Set && \
539 TraitSelector::TraitSelectorEnum == Selector && \
540 StringRef(Str) != "invalid") \
541 S.append("'").append(Str).append("'").append(" ");
542#include "llvm/Frontend/OpenMP/OMPKinds.def"
static bool isStrictSubset(ArrayRef< T > C0, ArrayRef< T > C1)
Return true if C0 is a strict subset of C1.
static APInt getVariantMatchScore(const VariantMatchInfo &VMI, const OMPContext &Ctx, SmallVectorImpl< unsigned > &ConstructMatches)
static bool isSubset(ArrayRef< T > C0, ArrayRef< T > C1)
Return true if C0 is a subset of C1.
static int isVariantApplicableInContextHelper(const VariantMatchInfo &VMI, const OMPContext &Ctx, SmallVectorImpl< unsigned > *ConstructMatches, bool DeviceSetOnly)
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.
uint64_t getZExtValue() const
Get zero extended value.
bool ult(const APInt &RHS) const
Unsigned less than comparison.
bool eq(const APInt &RHS) const
Equality comparison.
bool uge(const APInt &RHS) const
Unsigned greater or equal comparison.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
size - Get the array size.
bool test(unsigned Idx) const
size_type count() const
count - Returns the number of bits which are set.
iterator_range< const_set_bits_iterator > set_bits() const
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.
StringRef - Represent a constant reference to a string, i.e.
A switch()-like statement whose cases are string literals.
Triple - Helper class for working with autoconf configuration names.
ArchType getArch() const
Get the parsed architecture type of this triple.
#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.
StringRef getOpenMPContextTraitPropertyFullName(TraitProperty Kind)
Return a textual representation of the trait property Kind with selector and set name included.
bool isValidTraitSelectorForTraitSet(TraitSelector Selector, TraitSet Set, bool &AllowsTraitScore, bool &RequiresProperty)
}
TraitSet getOpenMPContextTraitSetForSelector(TraitSelector Selector)
Return the trait set for which Selector is a selector.
TraitSet getOpenMPContextTraitSetForProperty(TraitProperty Property)
Return the trait set for which Property is a property.
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.
StringRef getOpenMPContextTraitSetName(TraitSet Kind)
Return a textual representation of the trait set Kind.
StringRef getOpenMPContextTraitPropertyName(TraitProperty Kind, StringRef RawString)
Return a textual representation of the trait property Kind, which might be the raw string we parsed (...
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...
StringRef getOpenMPContextTraitSelectorName(TraitSelector Kind)
Return a textual representation of the trait selector Kind.
TraitSelector getOpenMPContextTraitSelectorKind(StringRef Str)
Parse Str and return the trait set it matches or TraitSelector::invalid.
std::string listOpenMPContextTraitSelectors(TraitSet Set)
Return a string listing all trait selectors for Set.
TraitSet
OpenMP Context related IDs and helpers.
TraitSelector getOpenMPContextTraitSelectorForProperty(TraitProperty Property)
Return the trait selector for which Property is a property.
TraitProperty getOpenMPContextTraitPropertyForSelector(TraitSelector Selector)
Return the trait property for a singleton selector Selector.
TraitSelector
IDs for all OpenMP context selector trait (device={kind/isa...}/...).
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/...)
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...
bool isValidTraitPropertyForTraitSetAndSelector(TraitProperty Property, TraitSelector Selector, TraitSet Set)
Return true if Property can be nested in Selector and Set.
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.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
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...
The context for a source location is made up of active property traits, e.g., device={kind(host)},...
OMPContext(bool IsDeviceCompilation, Triple TargetTriple)
SmallVector< TraitProperty, 8 > ConstructTraits
Variant match information describes the required traits and how they are scored (via the ScoresMap).
SmallVector< StringRef, 8 > ISATraits
SmallVector< TraitProperty, 8 > ConstructTraits
SmallDenseMap< TraitProperty, APInt > ScoreMap