================
@@ -6905,6 +6905,37 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
     auto Str = CGM.GetAddrOfConstantCString(Name, "");
     return RValue::get(Str.getPointer());
   }
+  case Builtin::BI__builtin_sycl_dynamic_local_memory: {
+    llvm::Type *RetTy = ConvertType(E->getType());
+    // Dynamic local memory only exists on the device; host code never reaches
+    // a kernel's reification, so return a null pointer.
+    if (!getLangOpts().SYCLIsDevice)
+      return RValue::get(
+          llvm::ConstantPointerNull::get(cast<llvm::PointerType>(RetTy)));
+
+    StringRef Name = "__sycl_dynamic_local_memory";
+    llvm::GlobalVariable *GV = CGM.getModule().getNamedGlobal(Name);
+    if (!GV) {
+      unsigned AS = getContext().getTargetAddressSpace(LangAS::sycl_local);
+      GV = new llvm::GlobalVariable(
+          CGM.getModule(), llvm::ArrayType::get(Int8Ty, 0),
+          /*isConstant=*/false, llvm::GlobalValue::ExternalLinkage,
+          /*Initializer=*/nullptr, Name, /*InsertBefore=*/nullptr,
+          llvm::GlobalValue::NotThreadLocal, AS);
+      // This global has default alignment. For SPIR-V with Level Zero, the
+      // SPIRVLowerDynamicLocalMemory pass adds a local pointer parameter to
+      // each kernel. It replaces uses of __sycl_dynamic_local_memory (looks
+      // for unsized arrays in local memory) with the value of the parameter,
+      // so the global's alignment has no effect. Other targets (e.g. AMDGPU,
+      // NVPTX) would align the start of the dynamic local memory block based
+      // on this global. This however may not be what the local accessors
+      // require. The SYCL runtime does not currently support these targets. If
+      // support is added, it should handle any alignment the local accessors
+      // require.
+      // FIXME: Should the builtin guarantee some alignment instead?
----------------
tahonermann wrote:

I think it suffices to state that the driver/backend will perform the 
allocation and therefore choose the alignment; I don't think any guarantees can 
be offered here. I would avoid mentioning what the SYCL runtime currently 
supports since such comments tend to become stale; just state requirements and 
behavior.

https://github.com/llvm/llvm-project/pull/244373
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to