mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Merge pull request #21231 from DougGregor/simd-operator-type-check-perf-hack
[Constraint solver] De-prioritize SIMD operators.
This commit is contained in:
@@ -1443,6 +1443,40 @@ static void tryOptimizeGenericDisjunction(ConstraintSystem &cs,
|
||||
}
|
||||
}
|
||||
|
||||
/// If there are any SIMD operators in the overload set, partition the set so
|
||||
/// that the SIMD operators come at the end.
|
||||
static ArrayRef<OverloadChoice> partitionSIMDOperators(
|
||||
ArrayRef<OverloadChoice> choices,
|
||||
SmallVectorImpl<OverloadChoice> &scratch) {
|
||||
// If the first element isn't an operator, none of them are.
|
||||
if (!choices[0].isDecl() ||
|
||||
!isa<FuncDecl>(choices[0].getDecl()) ||
|
||||
!cast<FuncDecl>(choices[0].getDecl())->isOperator() ||
|
||||
choices[0].getDecl()->getASTContext().LangOpts
|
||||
.SolverEnableOperatorDesignatedTypes)
|
||||
return choices;
|
||||
|
||||
// Check whether we have any SIMD operators.
|
||||
bool foundSIMDOperator = false;
|
||||
for (const auto &choice : choices) {
|
||||
if (isSIMDOperator(choice.getDecl())) {
|
||||
foundSIMDOperator = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!foundSIMDOperator)
|
||||
return choices;
|
||||
|
||||
scratch.assign(choices.begin(), choices.end());
|
||||
std::stable_partition(scratch.begin(), scratch.end(),
|
||||
[](const OverloadChoice &choice) {
|
||||
return !isSIMDOperator(choice.getDecl());
|
||||
});
|
||||
|
||||
return scratch;
|
||||
}
|
||||
|
||||
void ConstraintSystem::addOverloadSet(Type boundType,
|
||||
ArrayRef<OverloadChoice> choices,
|
||||
DeclContext *useDC,
|
||||
@@ -1459,6 +1493,9 @@ void ConstraintSystem::addOverloadSet(Type boundType,
|
||||
|
||||
tryOptimizeGenericDisjunction(*this, choices, favoredChoice);
|
||||
|
||||
SmallVector<OverloadChoice, 4> scratchChoices;
|
||||
choices = partitionSIMDOperators(choices, scratchChoices);
|
||||
|
||||
SmallVector<Constraint *, 4> overloads;
|
||||
|
||||
// As we do for other favored constraints, if a favored overload has been
|
||||
|
||||
Reference in New Issue
Block a user