Go to the documentation of this file.
22 #define DEBUG_TYPE "openmp-ir-builder"
31 ? TraitProperty::device_kind_nohost
32 : TraitProperty::device_kind_host));
33 switch (TargetTriple.
getArch()) {
61 #define OMP_TRAIT_PROPERTY(Enum, TraitSetEnum, TraitSelectorEnum, Str) \
62 if (TraitSelector::TraitSelectorEnum == TraitSelector::device_arch) { \
63 if (TargetTriple.getArch() == TargetTriple.getArchTypeForLLVMName(Str)) \
64 ActiveTraits.set(unsigned(TraitProperty::Enum)); \
65 if (StringRef(Str) == StringRef("x86_64") && \
66 TargetTriple.getArch() == Triple::x86_64) \
67 ActiveTraits.set(unsigned(TraitProperty::Enum)); \
69 #include "llvm/Frontend/OpenMP/OMPKinds.def"
87 <<
"] New OpenMP context with the following properties:\n";
99 #ifdef EXPENSIVE_CHECKS
101 "Expected sorted arrays!");
103 if (C0.
size() >
C1.size())
105 auto It0 = C0.
begin(), End0 = C0.
end();
106 auto It1 =
C1.begin(), End1 =
C1.end();
107 while (It0 != End0) {
122 template <
typename T>
124 if (C0.
size() >=
C1.size())
126 return isSubset<T>(C0,
C1);
150 enum MatchKind { MK_ALL, MK_ANY, MK_NONE };
152 MatchKind MK = MK_ALL;
156 unsigned(TraitProperty::implementation_extension_match_any)))
159 unsigned(TraitProperty::implementation_extension_match_none)))
177 if ((WasFound && MK == MK_ALL) || (!WasFound && MK == MK_NONE))
185 <<
" was not in the OpenMP context but match kind is all.\n";
189 <<
" was in the OpenMP context but match kind is none.\n";
203 TraitSelector::implementation_extension)
210 if (Property == TraitProperty::device_isa___ANY)
212 return Ctx.matchesISATrait(RawString);
216 if (Result.hasValue())
217 return Result.getValue();
220 if (!DeviceSetOnly) {
223 unsigned ConstructIdx = 0, NoConstructTraits = Ctx.
ConstructTraits.size();
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);
237 if (Result.hasValue())
238 return Result.getValue();
243 <<
" was not nested properly.\n");
251 "Broken invariant!");
256 <<
"] None of the properties was in the OpenMP context "
257 "but match kind is any.\n");
266 bool DeviceSetOnly) {
268 VMI, Ctx,
nullptr, DeviceSetOnly);
282 assert(UserScore.
uge(0) &&
"Expect non-negative user scores!");
288 case TraitSet::construct:
292 case TraitSet::implementation:
298 case TraitSet::device:
301 case TraitSet::invalid:
306 if (Property == TraitProperty::device_kind_any)
310 case TraitSelector::device_kind:
311 Score += (1ULL << (NoConstructTraits + 0));
313 case TraitSelector::device_arch:
314 Score += (1ULL << (NoConstructTraits + 1));
316 case TraitSelector::device_isa:
317 Score += (1ULL << (NoConstructTraits + 2));
324 unsigned ConstructIdx = 0;
325 assert(NoConstructTraits == ConstructMatches.size() &&
326 "Mismatch in the construct traits!");
329 TraitSet::construct &&
330 "Ill-formed variant match info!");
333 Score += (1ULL << ConstructMatches[ConstructIdx++]);
344 APInt BestScore(64, 0);
348 for (
unsigned u = 0,
e = VMIs.size(); u <
e; ++u) {
358 if (Score.
ult(BestScore))
361 if (Score.
eq(BestScore)) {
380 #define OMP_TRAIT_SET(Enum, Str) .Case(Str, TraitSet::Enum)
381 #include "llvm/Frontend/OpenMP/OMPKinds.def"
388 #define OMP_TRAIT_SELECTOR(Enum, TraitSetEnum, Str, ReqProp) \
389 case TraitSelector::Enum: \
390 return TraitSet::TraitSetEnum;
391 #include "llvm/Frontend/OpenMP/OMPKinds.def"
398 #define OMP_TRAIT_PROPERTY(Enum, TraitSetEnum, TraitSelectorEnum, Str) \
399 case TraitProperty::Enum: \
400 return TraitSet::TraitSetEnum;
401 #include "llvm/Frontend/OpenMP/OMPKinds.def"
407 #define OMP_TRAIT_SET(Enum, Str) \
408 case TraitSet::Enum: \
410 #include "llvm/Frontend/OpenMP/OMPKinds.def"
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);
425 #define OMP_TRAIT_PROPERTY(Enum, TraitSetEnum, TraitSelectorEnum, Str) \
426 case TraitProperty::Enum: \
427 return TraitSelector::TraitSelectorEnum;
428 #include "llvm/Frontend/OpenMP/OMPKinds.def"
434 #define OMP_TRAIT_SELECTOR(Enum, TraitSetEnum, Str, ReqProp) \
435 case TraitSelector::Enum: \
437 #include "llvm/Frontend/OpenMP/OMPKinds.def"
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;
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);
467 if (
Kind == TraitProperty::device_isa___ANY)
470 #define OMP_TRAIT_PROPERTY(Enum, TraitSetEnum, TraitSelectorEnum, Str) \
471 case TraitProperty::Enum: \
473 #include "llvm/Frontend/OpenMP/OMPKinds.def"
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"
489 bool &AllowsTraitScore,
490 bool &RequiresProperty) {
491 AllowsTraitScore = Set != TraitSet::construct && Set != TraitSet::device;
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"
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"
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"
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"
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"
This is an optimization pass for GlobalISel generic memory operations.
LLVM_NODISCARD R Default(T Value)
Variant match information describes the required traits and how they are scored (via the ScoresMap).
instcombine should handle this C2 when C1
TraitProperty getOpenMPContextTraitPropertyForSelector(TraitSelector Selector)
Return the trait property for a singleton selector Selector.
SmallDenseMap< TraitProperty, APInt > ScoreMap
iterator_range< const_set_bits_iterator > set_bits() const
Triple - Helper class for working with autoconf configuration names.
TraitSelector getOpenMPContextTraitSelectorKind(StringRef Str)
Parse Str and return the trait set it matches or TraitSelector::invalid.
TraitSet
OpenMP Context related IDs and helpers.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
bool uge(const APInt &RHS) const
Unsigned greater or equal comparison.
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
bool eq(const APInt &RHS) const
Equality comparison.
size_type count() const
count - Returns the number of bits which are set.
StringRef getOpenMPContextTraitSetName(TraitSet Kind)
Return a textual representation of the trait set Kind.
uint64_t getZExtValue() const
Get zero extended value.
static bool isStrictSubset(ArrayRef< T > C0, ArrayRef< T > C1)
Return true if C0 is a strict subset of C1.
ArchType getArch() const
Get the parsed architecture type of this triple.
SmallVector< TraitProperty, 8 > ConstructTraits
OMPContext(bool IsDeviceCompilation, Triple TargetTriple)
std::string listOpenMPContextTraitProperties(TraitSet Set, TraitSelector Selector)
Return a string listing all trait properties for Set and Selector.
static APInt getVariantMatchScore(const VariantMatchInfo &VMI, const OMPContext &Ctx, SmallVectorImpl< unsigned > &ConstructMatches)
StringRef getOpenMPContextTraitSelectorName(TraitSelector Kind)
Return a textual representation of the trait selector Kind.
std::string listOpenMPContextTraitSelectors(TraitSet Set)
Return a string listing all trait selectors for Set.
TraitSet getOpenMPContextTraitSetForSelector(TraitSelector Selector)
Return the trait set for which Selector is a selector.
std::string listOpenMPContextTraitSets()
Return a string listing all trait sets.
static int isVariantApplicableInContextHelper(const VariantMatchInfo &VMI, const OMPContext &Ctx, SmallVectorImpl< unsigned > *ConstructMatches, bool DeviceSetOnly)
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...
SmallVector< TraitProperty, 8 > ConstructTraits
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
TraitProperty
IDs for all OpenMP context trait properties (host/gpu/bsc/llvm/...)
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...
Class for arbitrary precision integers.
The context for a source location is made up of active property traits, e.g., device={kind(host)},...
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
StringRef - Represent a constant reference to a string, i.e.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
TraitSet getOpenMPContextTraitSetForProperty(TraitProperty Property)
Return the trait set for which Property is a property.
add sub stmia L5 ldr r0 bl L_printf $stub Instead of a and a wouldn t it be better to do three moves *Return an aggregate type is even return S
bool ult(const APInt &RHS) const
Unsigned less than comparison.
bool isValidTraitPropertyForTraitSetAndSelector(TraitProperty Property, TraitSelector Selector, TraitSet Set)
Return true if Property can be nested in Selector and Set.
static bool isSubset(ArrayRef< T > C0, ArrayRef< T > C1)
Return true if C0 is a subset of C1.
bool test(unsigned Idx) const
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...
TraitSelector getOpenMPContextTraitSelectorForProperty(TraitProperty Property)
Return the trait selector for which Property is a property.
TraitSelector
IDs for all OpenMP context selector trait (device={kind/isa...}/...).
size_t size() const
size - Get the array size.
StringRef getOpenMPContextTraitPropertyName(TraitProperty Kind, StringRef RawString)
Return a textual representation of the trait property Kind, which might be the raw string we parsed (...
A switch()-like statement whose cases are string literals.
bool isValidTraitSelectorForTraitSet(TraitSelector Selector, TraitSet Set, bool &AllowsTraitScore, bool &RequiresProperty)
}
TraitSet getOpenMPContextTraitSetKind(StringRef Str)
Parse Str and return the trait set it matches or TraitSet::invalid.
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 getOpenMPContextTraitPropertyFullName(TraitProperty Kind)
Return a textual representation of the trait property Kind with selector and set name included.
SmallVector< StringRef, 8 > ISATraits