[clang] [llvm] [openmp] [OpenMP][clang] Indirect and Virtual function call mapping from host to device (PR #159857)

Jason Van Beusekom via cfe-commits cfe-commits at lists.llvm.org
Wed Feb 11 11:59:24 PST 2026


================
@@ -7360,8 +7360,14 @@ ExprResult SemaOpenMP::ActOnOpenMPCall(ExprResult Call, Scope *Scope,
     return Call;
 
   FunctionDecl *CalleeFnDecl = CE->getDirectCallee();
-  if (!CalleeFnDecl)
+
+  // Mark indirect calls inside target regions, to allow for insertion of
+  // __llvm_omp_indirect_call_lookup calls during codegen.
+  if (!CalleeFnDecl) {
+    if (isInOpenMPTargetExecutionDirective())
+      getASTContext().OMPTargetCalls.insert(CE);
----------------
Jason-Van-Beusekom wrote:

Apooliges for the delay on this, I have not had much time to work on this, I did verify that `__llvm_omp_indirect_call_lookup` is not emitted wheh using PCH when I reverted https://github.com/llvm/llvm-project/pull/159857/commits/7abe4866545d063d6478351c837d9e76f4684c1f to test my visitor solution `__llvm_omp_indirect_call_lookup` was emitted properly. 

For reference these are the commands I used:

```bash
# 1: Host IR
clang -cc1 -fopenmp -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm test.c -o host.ll

# 2: Host BC (needed by device steps)
clang -cc1 -fopenmp -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm-bc test.c -o host.bc

# 3: Device IR
clang -cc1 -fopenmp -x c++ -triple nvptx64-nvidia-cuda -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm test.c -fopenmp-is-target-device -fvisibility=protected -fopenmp-host-ir-file-path host.bc -o device.ll

# 4: Device PCH
clang -cc1 -fopenmp -x c++ -triple nvptx64-nvidia-cuda -fopenmp-targets=nvptx64-nvidia-cuda test.c -fopenmp-is-target-device -fvisibility=protected -fopenmp-host-ir-file-path host.bc -emit-pch -o device.pch

# 5: Device IR with PCH
clang -cc1 -fopenmp -x c++ -triple nvptx64-nvidia-cuda -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm test.c -fopenmp-is-target-device -fvisibility=protected -fopenmp-host-ir-file-path host.bc -include-pch device.pch -o device_pch.ll
```

Because of this I am leaning towards my original visitor solution.


https://github.com/llvm/llvm-project/pull/159857


More information about the cfe-commits mailing list