Skip to content

Commit

Permalink
[CodeGenOpenCL] Remove pointer type caching
Browse files Browse the repository at this point in the history
This was important when typed LLVM pointers wanted a struct definition
for every type, but that's no longer necessary with opaque pointers.
NFCI.
  • Loading branch information
d0k committed Nov 14, 2023
1 parent a89c15a commit c66844d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 41 deletions.
46 changes: 7 additions & 39 deletions clang/lib/CodeGen/CGOpenCLRuntime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
}

Expand All @@ -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;
}

Expand Down
3 changes: 1 addition & 2 deletions clang/lib/CodeGen/CGOpenCLRuntime.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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),
Expand Down

0 comments on commit c66844d

Please sign in to comment.