diff --git a/clang/lib/CIR/CodeGen/CIRGenModule.cpp b/clang/lib/CIR/CodeGen/CIRGenModule.cpp index 4a6275e07fcc..6c2c907f0573 100644 --- a/clang/lib/CIR/CodeGen/CIRGenModule.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenModule.cpp @@ -569,14 +569,11 @@ bool CIRGenModule::shouldEmitCUDAGlobalVar(const VarDecl *global) const { // size and host-side address in order to provide access to // their device-side incarnations. - if (global->getType()->isCUDADeviceBuiltinTextureType()) { - llvm_unreachable("NYI"); - } - return !langOpts.CUDAIsDevice || global->hasAttr() || global->hasAttr() || global->hasAttr() || - global->getType()->isCUDADeviceBuiltinSurfaceType(); + global->getType()->isCUDADeviceBuiltinSurfaceType() || + global->getType()->isCUDADeviceBuiltinTextureType(); } void CIRGenModule::emitGlobal(GlobalDecl gd) { @@ -1212,7 +1209,6 @@ CIRGenModule::getOrCreateCIRGlobal(StringRef mangledName, mlir::Type ty, // initializer. if (gv.isDeclaration()) { getTargetCIRGenInfo().setTargetAttributes(d, gv, *this); - // External HIP managed variables needed to be recorded for transformation // in both device and host compilations. if (getLangOpts().CUDA && d && d->hasAttr() && @@ -1493,7 +1489,8 @@ void CIRGenModule::emitGlobalVarDefinition(const clang::VarDecl *d, // because they must not be initialized. if (linkage != cir::GlobalLinkageKind::InternalLinkage && (d->hasAttr() || d->hasAttr() || - d->getType()->isCUDADeviceBuiltinSurfaceType())) { + d->getType()->isCUDADeviceBuiltinSurfaceType() || + d->getType()->isCUDADeviceBuiltinTextureType())) { gv->setAttr(CUDAExternallyInitializedAttr::getMnemonic(), CUDAExternallyInitializedAttr::get(&getMLIRContext())); } diff --git a/clang/lib/CIR/CodeGen/CIRGenTypes.cpp b/clang/lib/CIR/CodeGen/CIRGenTypes.cpp index 6000474b161d..8fba1ec12718 100644 --- a/clang/lib/CIR/CodeGen/CIRGenTypes.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenTypes.cpp @@ -357,7 +357,11 @@ mlir::Type CIRGenTypes::convertType(QualType T) { if (mlir::Type Ty = CGM.getTargetCIRGenInfo().getCUDADeviceBuiltinSurfaceDeviceType()) return Ty; + llvm_unreachable("NYI"); } else if (T->isCUDADeviceBuiltinTextureType()) { + if (mlir::Type Ty = + CGM.getTargetCIRGenInfo().getCUDADeviceBuiltinTextureDeviceType()) + return Ty; llvm_unreachable("NYI"); } } diff --git a/clang/lib/CIR/CodeGen/TargetInfo.cpp b/clang/lib/CIR/CodeGen/TargetInfo.cpp index 1727ebf3a09c..d8a3d9cc1abe 100644 --- a/clang/lib/CIR/CodeGen/TargetInfo.cpp +++ b/clang/lib/CIR/CodeGen/TargetInfo.cpp @@ -345,13 +345,16 @@ class NVPTXTargetCIRGenInfo : public TargetCIRGenInfo { public: NVPTXTargetCIRGenInfo(CIRGenTypes &cgt) : TargetCIRGenInfo(std::make_unique(cgt)) {} - mlir::Type getCUDADeviceBuiltinSurfaceDeviceType() const override { + // On the device side, surface reference is represented as an object handle + // in 64-bit integer. + return cir::IntType::get(&getABIInfo().CGT.getMLIRContext(), 64, true); + } + mlir::Type getCUDADeviceBuiltinTextureDeviceType() const override { // On the device side, texture reference is represented as an object handle // in 64-bit integer. return cir::IntType::get(&getABIInfo().CGT.getMLIRContext(), 64, true); } - void setTargetAttributes(const clang::Decl *decl, mlir::Operation *global, CIRGenModule &cgm) const override { if (const auto *vd = clang::dyn_cast_or_null(decl)) { diff --git a/clang/lib/CIR/CodeGen/TargetInfo.h b/clang/lib/CIR/CodeGen/TargetInfo.h index abbfcafbe00e..b232aa38236c 100644 --- a/clang/lib/CIR/CodeGen/TargetInfo.h +++ b/clang/lib/CIR/CodeGen/TargetInfo.h @@ -132,6 +132,9 @@ class TargetCIRGenInfo { virtual mlir::Type getCUDADeviceBuiltinSurfaceDeviceType() const { return nullptr; } + virtual mlir::Type getCUDADeviceBuiltinTextureDeviceType() const { + return nullptr; + } virtual ~TargetCIRGenInfo() {} }; diff --git a/clang/test/CIR/CodeGen/CUDA/texture.cu b/clang/test/CIR/CodeGen/CUDA/texture.cu new file mode 100644 index 000000000000..db431b658bda --- /dev/null +++ b/clang/test/CIR/CodeGen/CUDA/texture.cu @@ -0,0 +1,24 @@ +// REQUIRES: x86-registered-target +// REQUIRES: nvptx-registered-target + +// RUN: %clang_cc1 -fclangir -std=c++11 -fcuda-is-device -triple nvptx64-nvidia-cuda -emit-llvm -o - %s | FileCheck --check-prefix=DEVICE-LLVM %s +// RUN: %clang_cc1 -fclangir -std=c++11 -fcuda-is-device -triple nvptx64-nvidia-cuda -emit-cir -o - %s | FileCheck --check-prefix=DEVICE-CIR %s +// RUN: echo "GPU binary would be here" > %t + +struct textureReference { + int desc; +}; + +enum ReadMode { + ElementType = 0, + NormalizedFloat = 1 +}; + +template +struct __attribute__((device_builtin_texture_type)) texture : public textureReference { +}; + +texture tex; + +// DEVICE-LLVM: @tex = addrspace(1) externally_initialized global i64 undef, align 4 +// DEVICE-CIR: cir.global external addrspace(offload_global) @tex = #cir.undef : !s64i {alignment = 4 : i64, cu.externally_initialized = #cir.cu.externally_initialized}