[SYCL] Avoid redundant deep device type checks - #23062
Conversation
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>
|
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. |
| return false; | ||
| } | ||
|
|
||
| static bool needsDeepTypeCheck(SemaSYCL &S, QualType Ty, |
There was a problem hiding this comment.
NIT: I would return a pair here and avoid having an "output" function parameter.
There was a problem hiding this comment.
Apparently, we don't even need a pair -- the RootRecord is a pointer, that could be nullptr. I'll try to update the function.
tahonermann
left a comment
There was a problem hiding this comment.
A couple of comments. I think the CanonicalDeclPtr change is worth making. There is another bit of code that I'm confused by.
| if (isZeroSizedArray(S, Ty)) | ||
| return {nullptr, true}; | ||
| if (Ty->isArrayType()) | ||
| Ty = QualType{Ty->getArrayElementTypeNoTypeQual(), 0}; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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.
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