Index: include/clang/AST/ASTContext.h =================================================================== --- include/clang/AST/ASTContext.h +++ include/clang/AST/ASTContext.h @@ -1224,6 +1224,12 @@ /// pointer to blocks. QualType getBlockDescriptorExtendedType() const; + /// Map an AST Type to an OpenCLTypeKind enum value. + TargetInfo::OpenCLTypeKind getOpenCLTypeKind(const Type *T) const; + + /// Get address space for OpenCL type. + LangAS getOpenCLTypeAddrSpace(const Type *T) const; + void setcudaConfigureCallDecl(FunctionDecl *FD) { cudaConfigureCallDecl = FD; } Index: include/clang/Basic/TargetInfo.h =================================================================== --- include/clang/Basic/TargetInfo.h +++ include/clang/Basic/TargetInfo.h @@ -46,7 +46,6 @@ class QualType; class SourceLocation; class SourceManager; -class Type; namespace Builtin { struct Info; } @@ -1057,8 +1056,19 @@ return getTargetOpts().SupportedOpenCLOptions; } + enum OpenCLTypeKind { + OCLTK_Default, + OCLTK_ClkEvent, + OCLTK_Event, + OCLTK_Image, + OCLTK_Pipe, + OCLTK_Queue, + OCLTK_ReserveID, + OCLTK_Sampler, + }; + /// \brief Get address space for OpenCL type. - virtual LangAS getOpenCLTypeAddrSpace(const Type *T) const; + virtual LangAS getOpenCLTypeAddrSpace(OpenCLTypeKind TK) const; /// \returns Target specific vtbl ptr address space. virtual unsigned getVtblPtrAddressSpace() const { Index: lib/AST/ASTContext.cpp =================================================================== --- lib/AST/ASTContext.cpp +++ lib/AST/ASTContext.cpp @@ -1826,7 +1826,8 @@ #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \ case BuiltinType::Id: #include "clang/Basic/OpenCLImageTypes.def" - AS = getTargetAddressSpace(Target->getOpenCLTypeAddrSpace(T)); + AS = getTargetAddressSpace( + Target->getOpenCLTypeAddrSpace(getOpenCLTypeKind(T))); Width = Target->getPointerWidth(AS); Align = Target->getPointerAlign(AS); break; @@ -5720,6 +5721,46 @@ return getTagDeclType(BlockDescriptorExtendedType); } +TargetInfo::OpenCLTypeKind ASTContext::getOpenCLTypeKind(const Type *T) const { + auto BT = dyn_cast(T); + + if (!BT) { + if (isa(T)) + return TargetInfo::OCLTK_Pipe; + + return TargetInfo::OCLTK_Default; + } + + switch (BT->getKind()) { +#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \ + case BuiltinType::Id: \ + return TargetInfo::OCLTK_Image; +#include "clang/Basic/OpenCLImageTypes.def" + + case BuiltinType::OCLClkEvent: + return TargetInfo::OCLTK_ClkEvent; + + case BuiltinType::OCLEvent: + return TargetInfo::OCLTK_Event; + + case BuiltinType::OCLQueue: + return TargetInfo::OCLTK_Queue; + + case BuiltinType::OCLReserveID: + return TargetInfo::OCLTK_ReserveID; + + case BuiltinType::OCLSampler: + return TargetInfo::OCLTK_Sampler; + + default: + return TargetInfo::OCLTK_Default; + } +} + +LangAS ASTContext::getOpenCLTypeAddrSpace(const Type *T) const { + return Target->getOpenCLTypeAddrSpace(getOpenCLTypeKind(T)); +} + /// BlockRequiresCopying - Returns true if byref variable "D" of type "Ty" /// requires copy/dispose. Note that this must match the logic /// in buildByrefHelpers. Index: lib/Basic/TargetInfo.cpp =================================================================== --- lib/Basic/TargetInfo.cpp +++ lib/Basic/TargetInfo.cpp @@ -12,7 +12,6 @@ //===----------------------------------------------------------------------===// #include "clang/Basic/TargetInfo.h" -#include "clang/AST/Type.h" #include "clang/Basic/AddressSpaces.h" #include "clang/Basic/CharInfo.h" #include "clang/Basic/LangOptions.h" @@ -357,23 +356,13 @@ return true; } -LangAS TargetInfo::getOpenCLTypeAddrSpace(const Type *T) const { - auto BT = dyn_cast(T); - - if (!BT) { - if (isa(T)) - return LangAS::opencl_global; - - return LangAS::Default; - } - - switch (BT->getKind()) { -#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \ - case BuiltinType::Id: \ +LangAS TargetInfo::getOpenCLTypeAddrSpace(OpenCLTypeKind TK) const { + switch (TK) { + case OCLTK_Image: + case OCLTK_Pipe: return LangAS::opencl_global; -#include "clang/Basic/OpenCLImageTypes.def" - case BuiltinType::OCLSampler: + case OCLTK_Sampler: return LangAS::opencl_constant; default: Index: lib/Basic/Targets/AMDGPU.h =================================================================== --- lib/Basic/Targets/AMDGPU.h +++ lib/Basic/Targets/AMDGPU.h @@ -14,7 +14,6 @@ #ifndef LLVM_CLANG_LIB_BASIC_TARGETS_AMDGPU_H #define LLVM_CLANG_LIB_BASIC_TARGETS_AMDGPU_H -#include "clang/AST/Type.h" #include "clang/Basic/TargetInfo.h" #include "clang/Basic/TargetOptions.h" #include "llvm/ADT/StringSet.h" @@ -258,24 +257,18 @@ } } - LangAS getOpenCLTypeAddrSpace(const Type *T) const override { - auto BT = dyn_cast(T); + LangAS getOpenCLTypeAddrSpace(OpenCLTypeKind TK) const override { + switch (TK) { + case OCLTK_Image: + return LangAS::opencl_constant; - if (!BT) - return TargetInfo::getOpenCLTypeAddrSpace(T); - - switch (BT->getKind()) { -#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \ - case BuiltinType::Id: \ - return LangAS::opencl_constant; -#include "clang/Basic/OpenCLImageTypes.def" - case BuiltinType::OCLClkEvent: - case BuiltinType::OCLQueue: - case BuiltinType::OCLReserveID: + case OCLTK_ClkEvent: + case OCLTK_Queue: + case OCLTK_ReserveID: return LangAS::opencl_global; default: - return TargetInfo::getOpenCLTypeAddrSpace(T); + return TargetInfo::getOpenCLTypeAddrSpace(TK); } } Index: lib/CodeGen/CGOpenCLRuntime.cpp =================================================================== --- lib/CodeGen/CGOpenCLRuntime.cpp +++ lib/CodeGen/CGOpenCLRuntime.cpp @@ -37,7 +37,7 @@ llvm::LLVMContext& Ctx = CGM.getLLVMContext(); uint32_t AddrSpc = CGM.getContext().getTargetAddressSpace( - CGM.getTarget().getOpenCLTypeAddrSpace(T)); + CGM.getContext().getOpenCLTypeAddrSpace(T)); switch (cast(T)->getKind()) { default: llvm_unreachable("Unexpected opencl builtin type!"); @@ -68,7 +68,7 @@ llvm::Type *CGOpenCLRuntime::getPipeType(const PipeType *T) { if (!PipeTy){ uint32_t PipeAddrSpc = CGM.getContext().getTargetAddressSpace( - CGM.getTarget().getOpenCLTypeAddrSpace(T)); + CGM.getContext().getOpenCLTypeAddrSpace(T)); PipeTy = llvm::PointerType::get(llvm::StructType::create( CGM.getLLVMContext(), "opencl.pipe_t"), PipeAddrSpc); } @@ -81,7 +81,7 @@ SamplerTy = llvm::PointerType::get(llvm::StructType::create( CGM.getLLVMContext(), "opencl.sampler_t"), CGM.getContext().getTargetAddressSpace( - CGM.getTarget().getOpenCLTypeAddrSpace(T))); + CGM.getContext().getOpenCLTypeAddrSpace(T))); return SamplerTy; }