[PATCH] D153883: [Clang][OpenMP] Delay emission of __kmpc_alloc_shared for escaped VLAs

Alexey Bataev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Jul 3 05:39:08 PDT 2023


ABataev added inline comments.


================
Comment at: clang/lib/CodeGen/CGDecl.cpp:1606
+      CGOpenMPRuntimeGPU &RT =
+          *(static_cast<CGOpenMPRuntimeGPU *>(&CGM.getOpenMPRuntime()));
+      if (RT.isDelayedVariableLengthDecl(*this, &D)) {
----------------
1. use `static_cast<CGOpenMPRuntimeGPU &>(CGM.getOpenMPRuntime())`
2. It will crash if your device is not GPU. Better to make `getKmpcAllocShared` and `getKmpcFreeShared` virtual (just like `isDelayedVariableLengthDecl`) in base CGOpenMPRuntime, since it may be required not only for GPU-based devices.


================
Comment at: clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp:261
+      else
+        DelayedVariableLengthDecls.insert(VD);
+    } else
----------------
Yep, this is what I meant. The only question: do you really need this new parameter? CGF.CapturedStmtInfo provides the list of captures and you can try to use it.


================
Comment at: clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp:1100-1104
+    // Check if the size of the VLA is available at this point i.e. check that
+    // it has been emitted already. If not available then skip it and use
+    // delayed emission of __kmpc_alloc_shared.
+    if (llvm::is_contained(I->getSecond().DelayedVariableLengthDecls, VD))
+      continue;
----------------
Do you still need this check?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153883/new/

https://reviews.llvm.org/D153883



More information about the cfe-commits mailing list