Skip to content

[SYCL] Avoid redundant deep device type checks - #23062

Open
vmustya wants to merge 3 commits into
intel:syclfrom
vmustya:sycl-sema-typecheck-optimize-alloc
Open

[SYCL] Avoid redundant deep device type checks#23062
vmustya wants to merge 3 commits into
intel:syclfrom
vmustya:sycl-sema-typecheck-optimize-alloc

Conversation

@vmustya

@vmustya vmustya commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Skip types that cannot contain zero-length arrays, use an inline visited
set, and cache successfully validated complete record definitions. This
reduces temporary allocations from repeated SYCL type validation while
preserving diagnostics for invalid and incomplete records.

Assisted-by: GPT-5.6 Terra noreply@openai.com

Skip types that cannot contain zero-length arrays, use an inline visited
set, and cache successfully validated complete record definitions. This
reduces temporary allocations from repeated SYCL type validation while
preserving diagnostics for invalid and incomplete records.

Assisted-by: GPT-5.6 Terra <noreply@openai.com>
@vmustya
vmustya marked this pull request as ready for review August 31, 2026 20:39
@vmustya
vmustya requested a review from a team as a code owner August 31, 2026 20:39
@vmustya

vmustya commented Aug 31, 2026

Copy link
Copy Markdown
Contributor Author

This change reduces the number of memory allocation calls in the frontend by ~8%, when compiling a simple SYCL free function kernel test case for device.

Comment thread clang/lib/Sema/SemaSYCL.cpp Outdated
return false;
}

static bool needsDeepTypeCheck(SemaSYCL &S, QualType Ty,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: I would return a pair here and avoid having an "output" function parameter.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparently, we don't even need a pair -- the RootRecord is a pointer, that could be nullptr. I'll try to update the function.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done: ee14b63

@koparasy koparasy left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@tahonermann tahonermann left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of comments. I think the CanonicalDeclPtr change is worth making. There is another bit of code that I'm confused by.

Comment on lines +432 to +435
if (isZeroSizedArray(S, Ty))
return {nullptr, true};
if (Ty->isArrayType())
Ty = QualType{Ty->getArrayElementTypeNoTypeQual(), 0};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something seems off here. In the zero array size case, null is returned for the record type, but true is returned to indicate a deep check is needed. Meanwhile, if we fall through for the array with size case, we return null with false if the element type isn't a record type.

// special types inside. Relevant for free function kernels only.
llvm::DenseSet<const RecordDecl *> StructsWithSpecialTypes;

llvm::DenseSet<const RecordDecl *> DeepTypeCheckedRecords;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use CanonicalDeclPtr to avoid the possibility of storing pointers to non-canonical declarations.

Would it make sense to store whether an error occurred to avoid repeated analysis of types with errors? Or is repeated analysis necessary to ensure an appropriate diagnostic is issued? It could make sense to store a partial diagnostic in error cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants