@@ -274,6 +274,101 @@ class FileNullabilityMap {
274
274
}
275
275
};
276
276
277
+ // TODO SYCL Integration header approach relies on an assumption that kernel
278
+ // lambda objects created by the host compiler and any of the device compilers
279
+ // will be identical wrt to field types, order and offsets. Some verification
280
+ // mechanism should be developed to enforce that.
281
+
282
+ // TODO FIXME SYCL Support for SYCL in FE should be refactored:
283
+ // - kernel indentification and generation should be made a separate pass over
284
+ // AST. RecursiveASTVisitor + VisitFunctionTemplateDecl +
285
+ // FunctionTemplateDecl::getSpecializations() mechanism could be used for that.
286
+ // - All SYCL stuff on Sema level should be encapsulated into a single Sema
287
+ // field
288
+ // - Move SYCL stuff into a separate header
289
+
290
+ // Represents contents of a SYCL integration header file produced by a SYCL
291
+ // device compiler and used by SYCL host compiler (via forced inclusion into
292
+ // compiled SYCL source):
293
+ // - SYCL kernel names
294
+ // - SYCL kernel parameters and offsets of corresponding actual arguments
295
+ class SYCLIntegrationHeader {
296
+ public:
297
+ // Kind of kernel's lambda parameters as captured by the compiler in the
298
+ // kernel lambda object
299
+ enum kernel_param_kind_t {
300
+ kind_first,
301
+ kind_none = kind_first,
302
+ kind_accessor,
303
+ kind_scalar,
304
+ kind_struct,
305
+ kind_sampler,
306
+ kind_struct_padding, // can be added by the compiler to enforce alignment
307
+ kind_last = kind_struct_padding
308
+ };
309
+
310
+ public:
311
+ SYCLIntegrationHeader ();
312
+
313
+ // / Emits contents of the header into given stream.
314
+ void emit (raw_ostream &Out);
315
+
316
+ // / Emits contents of the header into a file with given name.
317
+ // / Returns true/false on success/failure.
318
+ bool emit (const StringRef &MainSrc);
319
+
320
+ // / Signals that subsequent parameter descriptor additions will go to
321
+ // / the kernel with given name. Starts new kernel invocation descriptor.
322
+ void startKernel (StringRef KernelName);
323
+
324
+ // / Adds a kernel parameter descriptor to current kernel invocation
325
+ // / descriptor.
326
+ void addParamDesc (kernel_param_kind_t Kind, int Info, unsigned Offset);
327
+
328
+ // / Signals that addition of parameter descriptors to current kernel
329
+ // / invocation descriptor has finished.
330
+ void endKernel ();
331
+
332
+ private:
333
+ // Kernel actual parameter descriptor.
334
+ struct KernelParamDesc {
335
+ // Represents a parameter kind.
336
+ kernel_param_kind_t Kind;
337
+ // If Kind is kind_scalar or kind_struct, then
338
+ // denotes parameter size in bytes (includes padding for structs)
339
+ // If Kind is kind_accessor
340
+ // denotes access target; possible access targets are defined in
341
+ // access/access.hpp
342
+ int Info;
343
+ // Offset of the captured parameter value in the lambda or function object.
344
+ unsigned Offset;
345
+
346
+ KernelParamDesc () = default ;
347
+ };
348
+
349
+ // Kernel invocation descriptor
350
+ struct KernelDesc {
351
+ // / Kernel name.
352
+ std::string Name;
353
+ // / Descriptor of kernel actual parameters.
354
+ SmallVector<KernelParamDesc, 8 > Params;
355
+
356
+ KernelDesc () = default ;
357
+ };
358
+
359
+ // / Returns the latest invocation descriptor started by
360
+ // / SYCLIntegrationHeader::startKernel
361
+ KernelDesc *getCurKernelDesc () {
362
+ return KernelDescs.size () > 0 ? &KernelDescs[KernelDescs.size () - 1 ]
363
+ : nullptr ;
364
+ }
365
+
366
+ private:
367
+ // / Keeps invocation descriptors for each kernel invocation started by
368
+ // / SYCLIntegrationHeader::startKernel
369
+ SmallVector<KernelDesc, 4 > KernelDescs;
370
+ };
371
+
277
372
// / Sema - This implements semantic analysis and AST building for C.
278
373
class Sema {
279
374
Sema (const Sema &) = delete ;
@@ -10847,12 +10942,22 @@ class Sema {
10847
10942
// We store SYCL Kernels here and handle separately -- which is a hack.
10848
10943
// FIXME: It would be best to refactor this.
10849
10944
SmallVector<Decl*, 4 > SyclKernel;
10945
+ // SYCL integratrion header instance for current compilation unit this Sema
10946
+ // is associated with.
10947
+ std::unique_ptr<SYCLIntegrationHeader> SyclIntHeader;
10850
10948
10851
10949
public:
10852
10950
void AddSyclKernel (Decl * d) { SyclKernel.push_back (d); }
10853
10951
SmallVector<Decl*, 4 > &SyclKernels () { return SyclKernel; }
10854
10952
10855
- void ConstructSYCLKernel (FunctionDecl* KernelHelper);
10953
+ // / Lazily creates and returns SYCL integratrion header instance.
10954
+ SYCLIntegrationHeader &getSyclIntegrationHeader () {
10955
+ if (SyclIntHeader == nullptr )
10956
+ SyclIntHeader = llvm::make_unique<SYCLIntegrationHeader>();
10957
+ return *SyclIntHeader.get ();
10958
+ }
10959
+
10960
+ void ConstructSYCLKernel (FunctionDecl *KernelCallerFunc);
10856
10961
};
10857
10962
10858
10963
// / RAII object that enters a new expression evaluation context.
0 commit comments