https://github.com/koparasy created https://github.com/llvm/llvm-project/pull/239817
CIR's shouldEmitRTTI only disabled RTTI for CUDA/HIP device compiles and OpenMP device compiles on NVPTX. Classic codegen disables it for any offload device compile (SYCL, OpenMP, CUDA, HIP) targeting a GPU. I use the same condition as classic codegen. CUDA and HIP behavior is unchanged. Classic CodeGen does not have a.t.m tests for SYCL or OMP on AMDGPU I could not find any OG tests. As such, I am pushing tests on the CIR test dir. >From e2f1f0b18bc99d7287480d018f17cf7b1494f2e9 Mon Sep 17 00:00:00 2001 From: Konstantinos Parasyris <[email protected]> Date: Fri, 6 Nov 2026 13:57:44 -0800 Subject: [PATCH] [CIR] Match classic codegen's shouldEmitRTTI for offload devices --- clang/lib/CIR/CodeGen/CIRGenModule.h | 5 +- clang/test/CIR/CodeGenCXX/device-rtti.cpp | 64 +++++++++++++++++++++++ 2 files changed, 66 insertions(+), 3 deletions(-) create mode 100644 clang/test/CIR/CodeGenCXX/device-rtti.cpp diff --git a/clang/lib/CIR/CodeGen/CIRGenModule.h b/clang/lib/CIR/CodeGen/CIRGenModule.h index ce53b73fb163c..a2c3b52f02335 100644 --- a/clang/lib/CIR/CodeGen/CIRGenModule.h +++ b/clang/lib/CIR/CodeGen/CIRGenModule.h @@ -667,9 +667,8 @@ class CIRGenModule : public CIRGenTypeCache { // Return whether RTTI information should be emitted for this target. bool shouldEmitRTTI(bool forEH = false) { - return (forEH || getLangOpts().RTTI) && !getLangOpts().CUDAIsDevice && - !(getLangOpts().OpenMP && getLangOpts().OpenMPIsTargetDevice && - getTriple().isNVPTX()); + return (forEH || getLangOpts().RTTI) && + (!getLangOpts().isTargetDevice() || !getTriple().isGPU()); } /// Emit type info if type of an expression is a variably modified diff --git a/clang/test/CIR/CodeGenCXX/device-rtti.cpp b/clang/test/CIR/CodeGenCXX/device-rtti.cpp new file mode 100644 index 0000000000000..deac890e1e211 --- /dev/null +++ b/clang/test/CIR/CodeGenCXX/device-rtti.cpp @@ -0,0 +1,64 @@ +// RTTI is not emitted when compiling for a GPU offload device (SYCL, OpenMP, +// CUDA or HIP), but is emitted for the host. Without RTTI, the vtable's RTTI +// slot is null and no type info (_ZTI) is emitted. + +// SYCL device on SPIR. +// RUN: %clang_cc1 -fsycl-is-device -triple spir64-unknown-unknown -aux-triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t-sycl.cir +// RUN: FileCheck --check-prefix=CIR-DEV --implicit-check-not=_ZTI --input-file=%t-sycl.cir %s +// RUN: %clang_cc1 -fsycl-is-device -triple spir64-unknown-unknown -aux-triple x86_64-unknown-linux-gnu -fclangir -emit-llvm %s -o %t-sycl-cir.ll +// RUN: FileCheck --check-prefix=LLVM-DEV --implicit-check-not=_ZTI --input-file=%t-sycl-cir.ll %s +// RUN: %clang_cc1 -fsycl-is-device -triple spir64-unknown-unknown -aux-triple x86_64-unknown-linux-gnu -emit-llvm %s -o %t-sycl.ll +// RUN: FileCheck --check-prefix=LLVM-DEV --implicit-check-not=_ZTI --input-file=%t-sycl.ll %s + +// OpenMP device on AMDGPU. +// RUN: %clang_cc1 -fopenmp -fopenmp-is-target-device -triple amdgcn-amd-amdhsa -aux-triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t-omp.cir +// RUN: FileCheck --check-prefix=CIR-DEV --implicit-check-not=_ZTI --input-file=%t-omp.cir %s +// RUN: %clang_cc1 -fopenmp -fopenmp-is-target-device -triple amdgcn-amd-amdhsa -aux-triple x86_64-unknown-linux-gnu -fclangir -emit-llvm %s -o %t-omp-cir.ll +// RUN: FileCheck --check-prefix=LLVM-DEV --implicit-check-not=_ZTI --input-file=%t-omp-cir.ll %s +// RUN: %clang_cc1 -fopenmp -fopenmp-is-target-device -triple amdgcn-amd-amdhsa -aux-triple x86_64-unknown-linux-gnu -emit-llvm %s -o %t-omp.ll +// RUN: FileCheck --check-prefix=LLVM-DEV --implicit-check-not=_ZTI --input-file=%t-omp.ll %s + +// CUDA and HIP devices (unchanged behavior). +// RUN: %clang_cc1 -x cuda -fcuda-is-device -triple nvptx64-nvidia-cuda -aux-triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t-cuda.cir +// RUN: FileCheck --check-prefix=CIR-DEV --implicit-check-not=_ZTI --input-file=%t-cuda.cir %s +// RUN: %clang_cc1 -x hip -fcuda-is-device -triple amdgcn-amd-amdhsa -aux-triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t-hip.cir +// RUN: FileCheck --check-prefix=CIR-DEV --implicit-check-not=_ZTI --input-file=%t-hip.cir %s + +// SYCL host keeps RTTI. +// RUN: %clang_cc1 -fsycl-is-host -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t-host.cir +// RUN: FileCheck --check-prefix=CIR-HOST --input-file=%t-host.cir %s +// RUN: %clang_cc1 -fsycl-is-host -triple x86_64-unknown-linux-gnu -fclangir -emit-llvm %s -o %t-host-cir.ll +// RUN: FileCheck --check-prefix=LLVM-HOST --input-file=%t-host-cir.ll %s +// RUN: %clang_cc1 -fsycl-is-host -triple x86_64-unknown-linux-gnu -emit-llvm %s -o %t-host.ll +// RUN: FileCheck --check-prefix=LLVM-HOST --input-file=%t-host.ll %s + +#if defined(__CUDA__) || defined(__HIP__) +#define DEVICE __attribute__((device)) +#else +#define DEVICE +#endif + +#ifdef _OPENMP +#pragma omp declare target +#endif + +struct Key { + DEVICE virtual void f(); +}; + +#ifdef __SYCL_DEVICE_ONLY__ +[[clang::sycl_external]] +#endif +DEVICE void Key::f() {} + +#ifdef _OPENMP +#pragma omp end declare target +#endif + +// CIR-DEV: cir.global {{.*}} @_ZTV3Key = #cir.vtable<{#cir.const_array<[#cir.ptr<null> : !cir.ptr<!u8i>, #cir.ptr<null> : !cir.ptr<!u8i>, #cir.global_view<@_ZN3Key1fEv> : !cir.ptr<!u8i>]> +// LLVM-DEV: @_ZTV3Key = {{.*}}null, ptr{{.*}} null, ptr{{.*}} @_ZN3Key1fEv + +// CIR-HOST-DAG: cir.global {{.*}} @_ZTV3Key = #cir.vtable<{#cir.const_array<[#cir.ptr<null> : !cir.ptr<!u8i>, #cir.global_view<@_ZTI3Key> : !cir.ptr<!u8i>, #cir.global_view<@_ZN3Key1fEv> : !cir.ptr<!u8i>]> +// CIR-HOST-DAG: cir.global constant external @_ZTI3Key = #cir.typeinfo< +// LLVM-HOST-DAG: @_ZTV3Key = constant { [3 x ptr] } { [3 x ptr] [ptr null, ptr @_ZTI3Key, ptr @_ZN3Key1fEv] } +// LLVM-HOST-DAG: @_ZTI3Key = constant _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
