forked from OSchip/llvm-project
[clang] Cache OpenCL types
If we call CGOpenCLRuntime::convertOpenCLSpecificType() multiple times we should get the same type back. Reviewed By: svenvh Differential Revision: https://reviews.llvm.org/D119011
This commit is contained in:
parent
e8bff9ae54
commit
2724c153f9
|
@ -34,41 +34,46 @@ llvm::Type *CGOpenCLRuntime::convertOpenCLSpecificType(const Type *T) {
|
|||
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 getPointerType(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 getPointerType(T, "opencl.event_t");
|
||||
case BuiltinType::OCLClkEvent:
|
||||
return llvm::PointerType::get(
|
||||
llvm::StructType::create(Ctx, "opencl.clk_event_t"), AddrSpc);
|
||||
return getPointerType(T, "opencl.clk_event_t");
|
||||
case BuiltinType::OCLQueue:
|
||||
return llvm::PointerType::get(
|
||||
llvm::StructType::create(Ctx, "opencl.queue_t"), AddrSpc);
|
||||
return getPointerType(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 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;
|
||||
|
||||
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);
|
||||
CachedTys[Name] = PTy;
|
||||
return PTy;
|
||||
}
|
||||
|
||||
llvm::Type *CGOpenCLRuntime::getPipeType(const PipeType *T) {
|
||||
if (T->isReadOnly())
|
||||
return getPipeType(T, "opencl.pipe_ro_t", PipeROTy);
|
||||
|
|
|
@ -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 @@ protected:
|
|||
llvm::Type *PipeROTy;
|
||||
llvm::Type *PipeWOTy;
|
||||
llvm::PointerType *SamplerTy;
|
||||
llvm::StringMap<llvm::PointerType *> CachedTys;
|
||||
|
||||
/// Structure for enqueued block information.
|
||||
struct EnqueuedBlockInfo {
|
||||
|
@ -50,6 +52,7 @@ protected:
|
|||
|
||||
virtual llvm::Type *getPipeType(const PipeType *T, StringRef Name,
|
||||
llvm::Type *&PipeTy);
|
||||
llvm::PointerType *getPointerType(const Type *T, StringRef Name);
|
||||
|
||||
public:
|
||||
CGOpenCLRuntime(CodeGenModule &CGM) : CGM(CGM),
|
||||
|
|
Loading…
Reference in New Issue