Go to the documentation of this file.
23 #define DEBUG_TYPE "openmp-ir-builder"
32 ? TraitProperty::device_kind_nohost
33 : TraitProperty::device_kind_host));
34 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) == StringRef("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!");
104 if (C0.
size() >
C1.size())
106 auto It0 = C0.
begin(), End0 = C0.
end();
107 auto It1 =
C1.begin(), End1 =
C1.end();
108 while (It0 != End0) {
123 template <
typename T>
125 if (C0.
size() >=
C1.size())
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)))
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);
217 if (Result.hasValue())
218 return Result.getValue();
221 if (!DeviceSetOnly) {
224 unsigned ConstructIdx = 0, NoConstructTraits = Ctx.
ConstructTraits.size();
227 TraitSet::construct &&
228 "Variant context is ill-formed!");
231 bool FoundInOrder =
false;
232 while (!FoundInOrder && ConstructIdx != NoConstructTraits)
234 if (ConstructMatches)
235 ConstructMatches->push_back(ConstructIdx - 1);
238 if (Result.hasValue())
239 return Result.getValue();
244 <<
" was not nested properly.\n");
252 "Broken invariant!");
257 <<
"] None of the properties was in the OpenMP context "
258 "but match kind is any.\n");
267 bool DeviceSetOnly) {
269 VMI, Ctx,
nullptr, DeviceSetOnly);
283 assert(UserScore.
uge(0) &&
"Expect non-negative user scores!");
289 case TraitSet::construct:
293 case TraitSet::implementation:
299 case TraitSet::device:
302 case TraitSet::invalid:
307 if (Property == TraitProperty::device_kind_any)
311 case TraitSelector::device_kind:
312 Score += (1ULL << (NoConstructTraits + 0));
314 case TraitSelector::device_arch:
315 Score += (1ULL << (NoConstructTraits + 1));
317 case TraitSelector::device_isa:
318 Score += (1ULL << (NoConstructTraits + 2));
325 unsigned ConstructIdx = 0;
326 assert(NoConstructTraits == ConstructMatches.size() &&
327 "Mismatch in the construct traits!");
330 TraitSet::construct &&
331 "Ill-formed variant match info!");
334 Score += (1ULL << ConstructMatches[ConstructIdx++]);
345 APInt BestScore(64, 0);
349 for (
unsigned u = 0,
e = VMIs.size(); u <
e; ++u) {
359 if (Score.
ult(BestScore))
362 if (Score.
eq(BestScore)) {
381 #define OMP_TRAIT_SET(Enum, Str) .Case(Str, TraitSet::Enum)
382 #include "llvm/Frontend/OpenMP/OMPKinds.def"
389 #define OMP_TRAIT_SELECTOR(Enum, TraitSetEnum, Str, ReqProp) \
390 case TraitSelector::Enum: \
391 return TraitSet::TraitSetEnum;
392 #include "llvm/Frontend/OpenMP/OMPKinds.def"
399 #define OMP_TRAIT_PROPERTY(Enum, TraitSetEnum, TraitSelectorEnum, Str) \
400 case TraitProperty::Enum: \
401 return TraitSet::TraitSetEnum;
402 #include "llvm/Frontend/OpenMP/OMPKinds.def"
408 #define OMP_TRAIT_SET(Enum, Str) \
409 case TraitSet::Enum: \
411 #include "llvm/Frontend/OpenMP/OMPKinds.def"
418 #define OMP_TRAIT_SELECTOR(Enum, TraitSetEnum, Str, ReqProp) \
419 .Case(Str, TraitSelector::Enum)
420 #include "llvm/Frontend/OpenMP/OMPKinds.def"
421 .
Default(TraitSelector::invalid);
426 #define OMP_TRAIT_PROPERTY(Enum, TraitSetEnum, TraitSelectorEnum, Str) \
427 case TraitProperty::Enum: \
428 return TraitSelector::TraitSelectorEnum;
429 #include "llvm/Frontend/OpenMP/OMPKinds.def"
435 #define OMP_TRAIT_SELECTOR(Enum, TraitSetEnum, Str, ReqProp) \
436 case TraitSelector::Enum: \
438 #include "llvm/Frontend/OpenMP/OMPKinds.def"
447 if (Set == TraitSet::device && Selector == TraitSelector::device_isa)
448 return TraitProperty::device_isa___ANY;
449 #define OMP_TRAIT_PROPERTY(Enum, TraitSetEnum, TraitSelectorEnum, Str) \
450 if (Set == TraitSet::TraitSetEnum && Str == S) \
451 return TraitProperty::Enum;
452 #include "llvm/Frontend/OpenMP/OMPKinds.def"
453 return TraitProperty::invalid;
459 #define OMP_TRAIT_PROPERTY(Enum, TraitSetEnum, TraitSelectorEnum, Str) \
460 .Case(Str, Selector == TraitSelector::TraitSelectorEnum \
461 ? TraitProperty::Enum \
462 : TraitProperty::invalid)
463 #include "llvm/Frontend/OpenMP/OMPKinds.def"
464 .
Default(TraitProperty::invalid);
468 if (
Kind == TraitProperty::device_isa___ANY)
471 #define OMP_TRAIT_PROPERTY(Enum, TraitSetEnum, TraitSelectorEnum, Str) \
472 case TraitProperty::Enum: \
474 #include "llvm/Frontend/OpenMP/OMPKinds.def"
480 #define OMP_TRAIT_PROPERTY(Enum, TraitSetEnum, TraitSelectorEnum, Str) \
481 case TraitProperty::Enum: \
482 return "(" #TraitSetEnum "," #TraitSelectorEnum "," Str ")";
483 #include "llvm/Frontend/OpenMP/OMPKinds.def"
490 bool &AllowsTraitScore,
491 bool &RequiresProperty) {
492 AllowsTraitScore = Set != TraitSet::construct && Set != TraitSet::device;
494 #define OMP_TRAIT_SELECTOR(Enum, TraitSetEnum, Str, ReqProp) \
495 case TraitSelector::Enum: \
496 RequiresProperty = ReqProp; \
497 return Set == TraitSet::TraitSetEnum;
498 #include "llvm/Frontend/OpenMP/OMPKinds.def"
506 #define OMP_TRAIT_PROPERTY(Enum, TraitSetEnum, TraitSelectorEnum, Str) \
507 case TraitProperty::Enum: \
508 return Set == TraitSet::TraitSetEnum && \
509 Selector == TraitSelector::TraitSelectorEnum;
510 #include "llvm/Frontend/OpenMP/OMPKinds.def"
517 #define OMP_TRAIT_SET(Enum, Str) \
518 if (StringRef(Str) != "invalid") \
519 S.append("'").append(Str).append("'").append(" ");
520 #include "llvm/Frontend/OpenMP/OMPKinds.def"
527 #define OMP_TRAIT_SELECTOR(Enum, TraitSetEnum, Str, ReqProp) \
528 if (TraitSet::TraitSetEnum == Set && StringRef(Str) != "Invalid") \
529 S.append("'").append(Str).append("'").append(" ");
530 #include "llvm/Frontend/OpenMP/OMPKinds.def"
539 #define OMP_TRAIT_PROPERTY(Enum, TraitSetEnum, TraitSelectorEnum, Str) \
540 if (TraitSet::TraitSetEnum == Set && \
541 TraitSelector::TraitSelectorEnum == Selector && \
542 StringRef(Str) != "invalid") \
543 S.append("'").append(Str).append("'").append(" ");
544 #include "llvm/Frontend/OpenMP/OMPKinds.def"
This class represents lattice values for constants.
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
getArch - 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