Skip to content

[AST] Perf: Avoid reg spills on the fast path of getCanonicalType() #13661

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions include/swift/AST/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -400,17 +400,17 @@ class alignas(1 << TypeAlignInBits) TypeBase {
bool hasCanonicalTypeComputed() const { return !CanonicalType.isNull(); }

private:
void computeCanonicalType();
CanType computeCanonicalType();

public:
/// getCanonicalType - Return the canonical version of this type, which has
/// sugar from all levels stripped off.
CanType getCanonicalType() {
if (isCanonical())
return CanType(this);
if (!hasCanonicalTypeComputed())
computeCanonicalType();
return CanType(CanonicalType.get<TypeBase*>());
if (hasCanonicalTypeComputed())
return CanType(CanonicalType.get<TypeBase*>());
return computeCanonicalType();
}

/// getCanonicalType - Stronger canonicalization which folds away equivalent
Expand Down
3 changes: 2 additions & 1 deletion lib/AST/Type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1045,7 +1045,7 @@ getCanonicalInputType(AnyFunctionType *funcType,
return inputType;
}

void TypeBase::computeCanonicalType() {
CanType TypeBase::computeCanonicalType() {
assert(!hasCanonicalTypeComputed() && "called unnecessarily");

TypeBase *Result = nullptr;
Expand Down Expand Up @@ -1223,6 +1223,7 @@ void TypeBase::computeCanonicalType() {
// Cache the canonical type for future queries.
assert(Result && "Case not implemented!");
CanonicalType = Result;
return CanType(Result);
}

CanType TypeBase::getCanonicalType(GenericSignature *sig) {
Expand Down