From c66844d629d8317ed9bbd7d4049d52d56597adcc Mon Sep 17 00:00:00 2001 From: Benjamin Kramer Date: Wed, 15 Nov 2023 00:22:19 +0100 Subject: [PATCH] [CodeGenOpenCL] Remove pointer type caching This was important when typed LLVM pointers wanted a struct definition for every type, but that's no longer necessary with opaque pointers. NFCI. --- clang/lib/CodeGen/CGOpenCLRuntime.cpp | 46 ++++----------------------- clang/lib/CodeGen/CGOpenCLRuntime.h | 3 +- 2 files changed, 8 insertions(+), 41 deletions(-) diff --git a/clang/lib/CodeGen/CGOpenCLRuntime.cpp b/clang/lib/CodeGen/CGOpenCLRuntime.cpp index 33838a6552c8..115b618056a4 100644 --- a/clang/lib/CodeGen/CGOpenCLRuntime.cpp +++ b/clang/lib/CodeGen/CGOpenCLRuntime.cpp @@ -37,43 +37,16 @@ llvm::Type *CGOpenCLRuntime::convertOpenCLSpecificType(const Type *T) { if (llvm::Type *TransTy = CGM.getTargetCodeGenInfo().getOpenCLType(CGM, T)) return TransTy; - switch (cast(T)->getKind()) { - default: - llvm_unreachable("Unexpected opencl builtin type!"); - return nullptr; -#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \ - case BuiltinType::Id: \ - return getPointerType(T, "opencl." #ImgType "_" #Suffix "_t"); -#include "clang/Basic/OpenCLImageTypes.def" - case BuiltinType::OCLSampler: + if (T->isSamplerT()) return getSamplerType(T); - case BuiltinType::OCLEvent: - return getPointerType(T, "opencl.event_t"); - case BuiltinType::OCLClkEvent: - return getPointerType(T, "opencl.clk_event_t"); - case BuiltinType::OCLQueue: - return getPointerType(T, "opencl.queue_t"); - case BuiltinType::OCLReserveID: - return getPointerType(T, "opencl.reserve_id_t"); -#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \ - case BuiltinType::Id: \ - return getPointerType(T, "opencl." #ExtType); -#include "clang/Basic/OpenCLExtensionTypes.def" - } + + return getPointerType(T); } -llvm::PointerType *CGOpenCLRuntime::getPointerType(const Type *T, - StringRef Name) { - auto I = CachedTys.find(Name); - if (I != CachedTys.end()) - return I->second; - - llvm::LLVMContext &Ctx = CGM.getLLVMContext(); +llvm::PointerType *CGOpenCLRuntime::getPointerType(const Type *T) { uint32_t AddrSpc = CGM.getContext().getTargetAddressSpace( CGM.getContext().getOpenCLTypeAddrSpace(T)); - auto *PTy = llvm::PointerType::get(Ctx, AddrSpc); - CachedTys[Name] = PTy; - return PTy; + return llvm::PointerType::get(CGM.getLLVMContext(), AddrSpc); } llvm::Type *CGOpenCLRuntime::getPipeType(const PipeType *T) { @@ -89,9 +62,7 @@ llvm::Type *CGOpenCLRuntime::getPipeType(const PipeType *T) { llvm::Type *CGOpenCLRuntime::getPipeType(const PipeType *T, StringRef Name, llvm::Type *&PipeTy) { if (!PipeTy) - PipeTy = llvm::PointerType::get( - CGM.getLLVMContext(), CGM.getContext().getTargetAddressSpace( - CGM.getContext().getOpenCLTypeAddrSpace(T))); + PipeTy = getPointerType(T); return PipeTy; } @@ -103,10 +74,7 @@ llvm::Type *CGOpenCLRuntime::getSamplerType(const Type *T) { CGM, CGM.getContext().OCLSamplerTy.getTypePtr())) SamplerTy = TransTy; else - // struct opencl.sampler_t* - SamplerTy = llvm::PointerType::get( - CGM.getLLVMContext(), CGM.getContext().getTargetAddressSpace( - CGM.getContext().getOpenCLTypeAddrSpace(T))); + SamplerTy = getPointerType(T); return SamplerTy; } diff --git a/clang/lib/CodeGen/CGOpenCLRuntime.h b/clang/lib/CodeGen/CGOpenCLRuntime.h index df8084d6008b..34613c3516f3 100644 --- a/clang/lib/CodeGen/CGOpenCLRuntime.h +++ b/clang/lib/CodeGen/CGOpenCLRuntime.h @@ -39,7 +39,6 @@ protected: llvm::Type *PipeROTy; llvm::Type *PipeWOTy; llvm::Type *SamplerTy; - llvm::StringMap CachedTys; /// Structure for enqueued block information. struct EnqueuedBlockInfo { @@ -53,7 +52,7 @@ protected: virtual llvm::Type *getPipeType(const PipeType *T, StringRef Name, llvm::Type *&PipeTy); - llvm::PointerType *getPointerType(const Type *T, StringRef Name); + llvm::PointerType *getPointerType(const Type *T); public: CGOpenCLRuntime(CodeGenModule &CGM) : CGM(CGM),