[clang] c66844d - [CodeGenOpenCL] Remove pointer type caching

Benjamin Kramer via cfe-commits cfe-commits at lists.llvm.org
Tue Nov 14 15:37:58 PST 2023


Author: Benjamin Kramer
Date: 2023-11-15T00:37:44+01:00
New Revision: c66844d629d8317ed9bbd7d4049d52d56597adcc

URL: https://github.com/llvm/llvm-project/commit/c66844d629d8317ed9bbd7d4049d52d56597adcc
DIFF: https://github.com/llvm/llvm-project/commit/c66844d629d8317ed9bbd7d4049d52d56597adcc.diff

LOG: [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.

Added: 
    

Modified: 
    clang/lib/CodeGen/CGOpenCLRuntime.cpp
    clang/lib/CodeGen/CGOpenCLRuntime.h

Removed: 
    


################################################################################
diff  --git a/clang/lib/CodeGen/CGOpenCLRuntime.cpp b/clang/lib/CodeGen/CGOpenCLRuntime.cpp
index 33838a6552c8d70..115b618056a445e 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<BuiltinType>(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"
-  }
-}
 
-llvm::PointerType *CGOpenCLRuntime::getPointerType(const Type *T,
-                                                   StringRef Name) {
-  auto I = CachedTys.find(Name);
-  if (I != CachedTys.end())
-    return I->second;
+  return getPointerType(T);
+}
 
-  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 df8084d6008be94..34613c3516f3745 100644
--- a/clang/lib/CodeGen/CGOpenCLRuntime.h
+++ b/clang/lib/CodeGen/CGOpenCLRuntime.h
@@ -39,7 +39,6 @@ class CGOpenCLRuntime {
   llvm::Type *PipeROTy;
   llvm::Type *PipeWOTy;
   llvm::Type *SamplerTy;
-  llvm::StringMap<llvm::PointerType *> CachedTys;
 
   /// Structure for enqueued block information.
   struct EnqueuedBlockInfo {
@@ -53,7 +52,7 @@ class CGOpenCLRuntime {
 
   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),


        


More information about the cfe-commits mailing list