aeubanks created this revision. Herald added subscribers: Naghasan, ldrumm, Anastasia, yaxunl. aeubanks requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
If we call CGOpenCLRuntime::convertOpenCLSpecificType() multiple times we should get the same type back. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D119011 Files: clang/lib/CodeGen/CGOpenCLRuntime.cpp clang/lib/CodeGen/CGOpenCLRuntime.h Index: clang/lib/CodeGen/CGOpenCLRuntime.h =================================================================== --- clang/lib/CodeGen/CGOpenCLRuntime.h +++ clang/lib/CodeGen/CGOpenCLRuntime.h @@ -18,6 +18,7 @@ #include "clang/AST/Expr.h" #include "clang/AST/Type.h" #include "llvm/ADT/DenseMap.h" +#include "llvm/ADT/StringMap.h" #include "llvm/IR/Type.h" #include "llvm/IR/Value.h" @@ -38,6 +39,7 @@ llvm::Type *PipeROTy; llvm::Type *PipeWOTy; llvm::PointerType *SamplerTy; + llvm::StringMap<llvm::PointerType *> Tys; /// Structure for enqueued block information. struct EnqueuedBlockInfo { @@ -50,6 +52,7 @@ virtual llvm::Type *getPipeType(const PipeType *T, StringRef Name, llvm::Type *&PipeTy); + llvm::PointerType *getType(const Type *T, StringRef Name); public: CGOpenCLRuntime(CodeGenModule &CGM) : CGM(CGM), Index: clang/lib/CodeGen/CGOpenCLRuntime.cpp =================================================================== --- clang/lib/CodeGen/CGOpenCLRuntime.cpp +++ clang/lib/CodeGen/CGOpenCLRuntime.cpp @@ -34,41 +34,45 @@ assert(T->isOpenCLSpecificType() && "Not an OpenCL specific type!"); - llvm::LLVMContext& Ctx = CGM.getLLVMContext(); - uint32_t AddrSpc = CGM.getContext().getTargetAddressSpace( - CGM.getContext().getOpenCLTypeAddrSpace(T)); 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 llvm::PointerType::get( \ - llvm::StructType::create(Ctx, "opencl." #ImgType "_" #Suffix "_t"), \ - AddrSpc); +#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \ + case BuiltinType::Id: \ + return getType(T, "opencl." #ImgType "_" #Suffix "_t"); #include "clang/Basic/OpenCLImageTypes.def" case BuiltinType::OCLSampler: return getSamplerType(T); case BuiltinType::OCLEvent: - return llvm::PointerType::get( - llvm::StructType::create(Ctx, "opencl.event_t"), AddrSpc); + return getType(T, "opencl.event_t"); case BuiltinType::OCLClkEvent: - return llvm::PointerType::get( - llvm::StructType::create(Ctx, "opencl.clk_event_t"), AddrSpc); + return getType(T, "opencl.clk_event_t"); case BuiltinType::OCLQueue: - return llvm::PointerType::get( - llvm::StructType::create(Ctx, "opencl.queue_t"), AddrSpc); + return getType(T, "opencl.queue_t"); case BuiltinType::OCLReserveID: - return llvm::PointerType::get( - llvm::StructType::create(Ctx, "opencl.reserve_id_t"), AddrSpc); -#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \ - case BuiltinType::Id: \ - return llvm::PointerType::get( \ - llvm::StructType::create(Ctx, "opencl." #ExtType), AddrSpc); + return getType(T, "opencl.reserve_id_t"); +#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \ + case BuiltinType::Id: \ + return getType(T, "opencl." #ExtType); #include "clang/Basic/OpenCLExtensionTypes.def" } } +llvm::PointerType *CGOpenCLRuntime::getType(const Type *T, StringRef Name) { + auto I = Tys.find(Name); + if (I != Tys.end()) + return I->second; + + llvm::LLVMContext &Ctx = CGM.getLLVMContext(); + uint32_t AddrSpc = CGM.getContext().getTargetAddressSpace( + CGM.getContext().getOpenCLTypeAddrSpace(T)); + auto *PTy = + llvm::PointerType::get(llvm::StructType::create(Ctx, Name), AddrSpc); + Tys[Name] = PTy; + return PTy; +} + llvm::Type *CGOpenCLRuntime::getPipeType(const PipeType *T) { if (T->isReadOnly()) return getPipeType(T, "opencl.pipe_ro_t", PipeROTy);
Index: clang/lib/CodeGen/CGOpenCLRuntime.h =================================================================== --- clang/lib/CodeGen/CGOpenCLRuntime.h +++ clang/lib/CodeGen/CGOpenCLRuntime.h @@ -18,6 +18,7 @@ #include "clang/AST/Expr.h" #include "clang/AST/Type.h" #include "llvm/ADT/DenseMap.h" +#include "llvm/ADT/StringMap.h" #include "llvm/IR/Type.h" #include "llvm/IR/Value.h" @@ -38,6 +39,7 @@ llvm::Type *PipeROTy; llvm::Type *PipeWOTy; llvm::PointerType *SamplerTy; + llvm::StringMap<llvm::PointerType *> Tys; /// Structure for enqueued block information. struct EnqueuedBlockInfo { @@ -50,6 +52,7 @@ virtual llvm::Type *getPipeType(const PipeType *T, StringRef Name, llvm::Type *&PipeTy); + llvm::PointerType *getType(const Type *T, StringRef Name); public: CGOpenCLRuntime(CodeGenModule &CGM) : CGM(CGM), Index: clang/lib/CodeGen/CGOpenCLRuntime.cpp =================================================================== --- clang/lib/CodeGen/CGOpenCLRuntime.cpp +++ clang/lib/CodeGen/CGOpenCLRuntime.cpp @@ -34,41 +34,45 @@ assert(T->isOpenCLSpecificType() && "Not an OpenCL specific type!"); - llvm::LLVMContext& Ctx = CGM.getLLVMContext(); - uint32_t AddrSpc = CGM.getContext().getTargetAddressSpace( - CGM.getContext().getOpenCLTypeAddrSpace(T)); 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 llvm::PointerType::get( \ - llvm::StructType::create(Ctx, "opencl." #ImgType "_" #Suffix "_t"), \ - AddrSpc); +#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \ + case BuiltinType::Id: \ + return getType(T, "opencl." #ImgType "_" #Suffix "_t"); #include "clang/Basic/OpenCLImageTypes.def" case BuiltinType::OCLSampler: return getSamplerType(T); case BuiltinType::OCLEvent: - return llvm::PointerType::get( - llvm::StructType::create(Ctx, "opencl.event_t"), AddrSpc); + return getType(T, "opencl.event_t"); case BuiltinType::OCLClkEvent: - return llvm::PointerType::get( - llvm::StructType::create(Ctx, "opencl.clk_event_t"), AddrSpc); + return getType(T, "opencl.clk_event_t"); case BuiltinType::OCLQueue: - return llvm::PointerType::get( - llvm::StructType::create(Ctx, "opencl.queue_t"), AddrSpc); + return getType(T, "opencl.queue_t"); case BuiltinType::OCLReserveID: - return llvm::PointerType::get( - llvm::StructType::create(Ctx, "opencl.reserve_id_t"), AddrSpc); -#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \ - case BuiltinType::Id: \ - return llvm::PointerType::get( \ - llvm::StructType::create(Ctx, "opencl." #ExtType), AddrSpc); + return getType(T, "opencl.reserve_id_t"); +#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \ + case BuiltinType::Id: \ + return getType(T, "opencl." #ExtType); #include "clang/Basic/OpenCLExtensionTypes.def" } } +llvm::PointerType *CGOpenCLRuntime::getType(const Type *T, StringRef Name) { + auto I = Tys.find(Name); + if (I != Tys.end()) + return I->second; + + llvm::LLVMContext &Ctx = CGM.getLLVMContext(); + uint32_t AddrSpc = CGM.getContext().getTargetAddressSpace( + CGM.getContext().getOpenCLTypeAddrSpace(T)); + auto *PTy = + llvm::PointerType::get(llvm::StructType::create(Ctx, Name), AddrSpc); + Tys[Name] = PTy; + return PTy; +} + llvm::Type *CGOpenCLRuntime::getPipeType(const PipeType *T) { if (T->isReadOnly()) return getPipeType(T, "opencl.pipe_ro_t", PipeROTy);
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits