================
@@ -157,24 +193,46 @@ template <typename T> static bool isSubset(ArrayRef<T>
C0, ArrayRef<T> C1) {
++It1;
continue;
}
- ++It0;
+ ++It1;
}
return true;
}
static bool isStrictSubset(const VariantMatchInfo &VMI0,
const VariantMatchInfo &VMI1) {
- // If all required traits are a strict subset and the ordered vectors storing
- // the construct traits, we say it is a strict subset. Note that the latter
- // relation is not required to be strict.
- if (VMI0.RequiredTraits.count() >= VMI1.RequiredTraits.count())
+ // kind(any) is equivalent to omitting the kind selector.
+ BitVector Traits0 = VMI0.RequiredTraits, Traits1 = VMI1.RequiredTraits;
+ for (TraitProperty Property : {TraitProperty::device_kind_any,
+ TraitProperty::target_device_kind_any}) {
+ Traits0.reset(unsigned(Property));
+ Traits1.reset(unsigned(Property));
+ }
+ size_t TraitCount0 = Traits0.count() + VMI0.UnknownTraits.size();
+ size_t TraitCount1 = Traits1.count() + VMI1.UnknownTraits.size();
+ if (TraitCount0 > TraitCount1)
return false;
- for (unsigned Bit : VMI0.RequiredTraits.set_bits())
- if (!VMI1.RequiredTraits.test(Bit))
+ for (unsigned Bit : Traits0.set_bits())
+ if (!Traits1.test(Bit))
+ return false;
+ for (const auto &Trait : VMI0.UnknownTraits)
+ if (!llvm::is_contained(VMI1.UnknownTraits, Trait))
+ return false;
+ for (const auto &Trait : VMI0.ISATraits)
+ if (!llvm::is_contained(VMI1.ISATraits, Trait))
return false;
- if (!isSubset<TraitProperty>(VMI0.ConstructTraits, VMI1.ConstructTraits))
+ bool HasAdditionalISATrait =
+ llvm::any_of(VMI1.ISATraits, [&](const auto &Trait) {
+ return !llvm::is_contained(VMI0.ISATraits, Trait);
+ });
+ if (!VMI0.UserCondition.empty() && VMI0.UserCondition != VMI1.UserCondition)
----------------
MattPD wrote:
The earlier condition-profiling changes are no longer in this PR, but the
remaining scoring changes create new ties still requiring the subset comparison
to preserve condition identity.
Compiling the following reproducer with `clang -fopenmp -fopenmp-version=52 -S
-emit-llvm repro.c -o -` emits TASKWAIT at b165f599 instead of the TASKYIELD
selected by the [parent
commit](https://github.com/llvm/llvm-project/commit/81b82b8012a2bf9a1f1822af10778922b4646fef):
```c
void distinct_conditions(void) {
#pragma omp metadirective \
when(user={condition(1)}, \
implementation={vendor(score(4): llvm, amd), extension(match_any)}:
taskyield) \
when(user={condition(2)}, device={kind(cpu)}, \
implementation={vendor(score(3): llvm, amd), extension(match_any)}:
taskwait)
}
```
Counting each vendor score once changes the totals from 9 and 8 to 5 and 5. The
conditions differ, but the subset check compares only property bits, so it
treats the first selector as a strict subset of the second.
The new device weights expose the same issue with independent runtime
conditions in Flang. Compile the following reproducer with `flang -fopenmp
-fopenmp-version=52 -S -emit-llvm repro.f90 -o -`:
```fortran
subroutine distinct_dynamic(a,b)
logical, intent(in) :: a,b
!$omp parallel num_threads(1)
!$omp parallel num_threads(1)
!$omp metadirective &
!$omp& when(user={condition(a)}, &
!$omp& implementation={vendor(score(4): llvm)}: taskyield) &
!$omp& when(user={condition(b)}, device={kind(cpu)}, &
!$omp& implementation={vendor(score(0): llvm)}: taskwait)
!$omp end parallel
!$omp end parallel
end subroutine
```
Both candidates now score 5. At b165f599, the generated code tests `b` and
selects TASKWAIT before considering `a`. The parent's code tests `a` first.
When `a` and `b` are both true, lexical order requires TASKYIELD because
neither selector is a subset of the other.
Could the subset check distinguish different conditions in these new ties while
retaining the strict-subset result for identical conditions? Giving the first
selector the higher score should also preserve its precedence.
https://github.com/llvm/llvm-project/pull/231668
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits