Skip to content

Commit f746a55

Browse files
lbushi25sarnex
andauthored
[SYCL] Implement structs that contains special types as parameters to free function kernels (#20844)
Add support for structs containing special types as free function kernel parameters. --------- Signed-off-by: Sarnie, Nick <nick.sarnie@intel.com> Co-authored-by: Nick Sarnie <nick.sarnie@intel.com>
1 parent 32fd3bc commit f746a55

21 files changed

+551
-170
lines changed

clang/include/clang/Sema/SemaSYCL.h

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ class SYCLIntegrationHeader {
6565
kind_work_group_memory,
6666
kind_dynamic_work_group_memory,
6767
kind_dynamic_accessor,
68-
kind_last = kind_dynamic_accessor
68+
kind_struct_with_special_type, // structs that contain special types
69+
kind_last = kind_struct_with_special_type
6970
};
7071

7172
public:
@@ -118,6 +119,9 @@ class SYCLIntegrationHeader {
118119
/// integration header is required.
119120
void addHostPipeRegistration() { NeedToEmitHostPipeRegistration = true; }
120121

122+
/// Set the ParentStruct field
123+
void setParentStruct(ParmVarDecl *parent);
124+
121125
private:
122126
// Kernel actual parameter descriptor.
123127
struct KernelParamDesc {
@@ -205,6 +209,20 @@ class SYCLIntegrationHeader {
205209
/// Keeps track of whether declaration of __sycl_host_pipe_registration
206210
/// type and __sycl_host_pipe_registrar variable are required to emit.
207211
bool NeedToEmitHostPipeRegistration = false;
212+
213+
// For free function kernels, keeps track of the parameter that is currently
214+
// being analyzed if it is a struct that contains special types.
215+
ParmVarDecl *ParentStruct = nullptr;
216+
217+
// For every struct that contains a special type which is given by
218+
// the ParentStruct field above, record the offset and size of its fields
219+
// at any nesting level. Store the information in the variable below.
220+
llvm::DenseMap<ParmVarDecl *, llvm::SmallVector<std::pair<size_t, size_t>>>
221+
OffsetSizeInfo;
222+
// Likewise for the kind of a field i.e accessor, std_layout etc...
223+
llvm::DenseMap<ParmVarDecl *,
224+
llvm::SmallVector<SYCLIntegrationHeader::kernel_param_kind_t>>
225+
KindInfo;
208226
};
209227

210228
class SYCLIntegrationFooter {
@@ -267,6 +285,10 @@ class SemaSYCL : public SemaBase {
267285

268286
llvm::DenseSet<const FunctionDecl *> FreeFunctionDeclarations;
269287

288+
// A map that keeps track of all structs encountered with
289+
// special types inside. Relevant for free function kernels only.
290+
llvm::DenseSet<const RecordDecl *> StructsWithSpecialTypes;
291+
270292
public:
271293
SemaSYCL(Sema &S);
272294

@@ -317,6 +339,13 @@ class SemaSYCL : public SemaBase {
317339
SYCLKernelFunctions.insert(FD);
318340
}
319341

342+
/// Add ParentStruct to StructsWithSpecialTypes.
343+
void addStructWithSpecialType(const RecordDecl *ParentStruct) {
344+
StructsWithSpecialTypes.insert(ParentStruct);
345+
}
346+
347+
auto &getStructsWithSpecialType() const { return StructsWithSpecialTypes; }
348+
320349
/// Lazily creates and returns SYCL integration header instance.
321350
SYCLIntegrationHeader &getSyclIntegrationHeader() {
322351
if (SyclIntHeader == nullptr)

0 commit comments

Comments
 (0)