Author: Arseniy Obolenskiy Date: 2026-10-02T09:49:54Z New Revision: 4dfc4f5457efc21c8bed43dca7605f119ef35d5e
URL: https://github.com/llvm/llvm-project/commit/4dfc4f5457efc21c8bed43dca7605f119ef35d5e DIFF: https://github.com/llvm/llvm-project/commit/4dfc4f5457efc21c8bed43dca7605f119ef35d5e.diff LOG: [CIR] Emit OpenCL file scope global variables (#228125) Added: clang/test/CIR/CodeGenOpenCL/global-vars.cl Modified: clang/lib/CIR/CodeGen/CIRGenModule.cpp Removed: ################################################################################ diff --git a/clang/lib/CIR/CodeGen/CIRGenModule.cpp b/clang/lib/CIR/CodeGen/CIRGenModule.cpp index e3b433d0d10c8..8bb518f91e933 100644 --- a/clang/lib/CIR/CodeGen/CIRGenModule.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenModule.cpp @@ -1524,9 +1524,14 @@ void CIRGenModule::emitLLVMUsed() { void CIRGenModule::emitGlobalVarDefinition(const clang::VarDecl *vd, bool isTentative) { - if (getLangOpts().OpenCL || getLangOpts().OpenMPIsTargetDevice) { + // OpenCL global variables of sampler type are translated to function calls, + // therefore no need to be translated. + if (getLangOpts().OpenCL && vd->getType()->isSamplerT()) + return; + + if (getLangOpts().OpenMPIsTargetDevice) { errorNYI(vd->getSourceRange(), - "emitGlobalVarDefinition: emit OpenCL/OpenMP global variable"); + "emitGlobalVarDefinition: emit OpenMP global variable"); return; } diff --git a/clang/test/CIR/CodeGenOpenCL/global-vars.cl b/clang/test/CIR/CodeGenOpenCL/global-vars.cl new file mode 100644 index 0000000000000..9d45f33d57859 --- /dev/null +++ b/clang/test/CIR/CodeGenOpenCL/global-vars.cl @@ -0,0 +1,25 @@ +// RUN: %clang_cc1 -x cl -triple spir64 -cl-std=CL2.0 -fclangir -emit-cir \ +// RUN: -Wno-deprecated-attributes -mmlir \ +// RUN: --mlir-print-ir-before=cir-target-lowering %s -o %t.cir 2> %t.pre.cir +// RUN: FileCheck %s --check-prefix=CIR --input-file=%t.pre.cir +// RUN: %clang_cc1 -x cl -triple spirv64-unknown-unknown -cl-std=CL2.0 \ +// RUN: -fclangir -emit-llvm -O0 -Wno-deprecated-attributes %s -o %t.cir.ll +// RUN: FileCheck %s --check-prefix=LLVM --input-file=%t.cir.ll +// RUN: %clang_cc1 -x cl -triple spirv64-unknown-unknown -cl-std=CL2.0 \ +// RUN: -emit-llvm -O0 -Wno-deprecated-attributes %s -o %t.ogcg.ll +// RUN: FileCheck %s --check-prefix=LLVM --input-file=%t.ogcg.ll + +constant int const_gv = 42; +global int global_gv = 7; +global int tentative_gv; +const sampler_t sampler_gv = 0; + +// CIR-DAG: cir.global constant external lang_address_space(offload_constant) @const_gv = #cir.int<42> : !s32i +// CIR-DAG: cir.global external lang_address_space(offload_global) @global_gv = #cir.int<7> : !s32i +// CIR-DAG: cir.global external lang_address_space(offload_global) @tentative_gv = #cir.int<0> : !s32i +// CIR-NOT: @sampler_gv + +// LLVM-DAG: @const_gv = addrspace(2) constant i32 42 +// LLVM-DAG: @global_gv = addrspace(1) global i32 7 +// LLVM-DAG: @tentative_gv = addrspace(1) global i32 0 +// LLVM-NOT: @sampler_gv _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
