diff options
| author | Sven van Haastregt <sven.vanhaastregt@arm.com> | 2017-08-15 09:38:18 +0000 |
|---|---|---|
| committer | Sven van Haastregt <sven.vanhaastregt@arm.com> | 2017-08-15 09:38:18 +0000 |
| commit | efb4d4c78c647c9a0fd94b4de238ea2d386fc2d2 (patch) | |
| tree | 8659d5f2b37b53a3b4532cac8f134c1aaf72a76a /clang/lib | |
| parent | 25e2800e206af4e703c6d5ddbf81aa146cea1ec4 (diff) | |
| download | bcm5719-llvm-efb4d4c78c647c9a0fd94b4de238ea2d386fc2d2.tar.gz bcm5719-llvm-efb4d4c78c647c9a0fd94b4de238ea2d386fc2d2.zip | |
[OpenCL] Allow targets to select address space per type
Generalize getOpenCLImageAddrSpace into getOpenCLTypeAddrSpace, such
that targets can select the address space per type.
No functional changes intended.
Initial patch by Simon Perretta.
Differential Revision: https://reviews.llvm.org/D33989
llvm-svn: 310911
Diffstat (limited to 'clang/lib')
| -rw-r--r-- | clang/lib/AST/ASTContext.cpp | 29 | ||||
| -rw-r--r-- | clang/lib/Basic/TargetInfo.cpp | 25 | ||||
| -rw-r--r-- | clang/lib/Basic/Targets/AMDGPU.h | 16 | ||||
| -rw-r--r-- | clang/lib/CodeGen/CGOpenCLRuntime.cpp | 28 | ||||
| -rw-r--r-- | clang/lib/CodeGen/CGOpenCLRuntime.h | 4 | ||||
| -rw-r--r-- | clang/lib/CodeGen/CodeGenModule.cpp | 2 | ||||
| -rw-r--r-- | clang/lib/CodeGen/CodeGenTypes.cpp | 2 |
7 files changed, 67 insertions, 39 deletions
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp index 34a78c6a0c6..1fb146e839b 100644 --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/lib/AST/ASTContext.cpp @@ -1631,6 +1631,7 @@ TypeInfo ASTContext::getTypeInfoImpl(const Type *T) const { uint64_t Width = 0; unsigned Align = 8; bool AlignIsRequired = false; + unsigned AS = 0; switch (T->getTypeClass()) { #define TYPE(Class, Base) #define ABSTRACT_TYPE(Class, Base) @@ -1777,28 +1778,18 @@ TypeInfo ASTContext::getTypeInfoImpl(const Type *T) const { Width = Target->getPointerWidth(0); Align = Target->getPointerAlign(0); break; - case BuiltinType::OCLSampler: { - auto AS = getTargetAddressSpace(LangAS::opencl_constant); - Width = Target->getPointerWidth(AS); - Align = Target->getPointerAlign(AS); - break; - } + case BuiltinType::OCLSampler: case BuiltinType::OCLEvent: case BuiltinType::OCLClkEvent: case BuiltinType::OCLQueue: case BuiltinType::OCLReserveID: - // Currently these types are pointers to opaque types. - Width = Target->getPointerWidth(0); - Align = Target->getPointerAlign(0); - break; #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \ case BuiltinType::Id: #include "clang/Basic/OpenCLImageTypes.def" - { - auto AS = getTargetAddressSpace(Target->getOpenCLImageAddrSpace()); - Width = Target->getPointerWidth(AS); - Align = Target->getPointerAlign(AS); - } + AS = getTargetAddressSpace(Target->getOpenCLTypeAddrSpace(T)); + Width = Target->getPointerWidth(AS); + Align = Target->getPointerAlign(AS); + break; } break; case Type::ObjCObjectPointer: @@ -1806,8 +1797,7 @@ TypeInfo ASTContext::getTypeInfoImpl(const Type *T) const { Align = Target->getPointerAlign(0); break; case Type::BlockPointer: { - unsigned AS = getTargetAddressSpace( - cast<BlockPointerType>(T)->getPointeeType()); + AS = getTargetAddressSpace(cast<BlockPointerType>(T)->getPointeeType()); Width = Target->getPointerWidth(AS); Align = Target->getPointerAlign(AS); break; @@ -1816,14 +1806,13 @@ TypeInfo ASTContext::getTypeInfoImpl(const Type *T) const { case Type::RValueReference: { // alignof and sizeof should never enter this code path here, so we go // the pointer route. - unsigned AS = getTargetAddressSpace( - cast<ReferenceType>(T)->getPointeeType()); + AS = getTargetAddressSpace(cast<ReferenceType>(T)->getPointeeType()); Width = Target->getPointerWidth(AS); Align = Target->getPointerAlign(AS); break; } case Type::Pointer: { - unsigned AS = getTargetAddressSpace(cast<PointerType>(T)->getPointeeType()); + AS = getTargetAddressSpace(cast<PointerType>(T)->getPointeeType()); Width = Target->getPointerWidth(AS); Align = Target->getPointerAlign(AS); break; diff --git a/clang/lib/Basic/TargetInfo.cpp b/clang/lib/Basic/TargetInfo.cpp index 4bcebadf458..de26a67eac3 100644 --- a/clang/lib/Basic/TargetInfo.cpp +++ b/clang/lib/Basic/TargetInfo.cpp @@ -12,6 +12,7 @@ //===----------------------------------------------------------------------===// #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" @@ -347,6 +348,30 @@ bool TargetInfo::initFeatureMap( return true; } +LangAS::ID TargetInfo::getOpenCLTypeAddrSpace(const Type *T) const { + auto BT = dyn_cast<BuiltinType>(T); + + if (!BT) { + if (isa<PipeType>(T)) + return LangAS::opencl_global; + + return LangAS::Default; + } + + switch (BT->getKind()) { +#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \ + case BuiltinType::Id: \ + return LangAS::opencl_global; +#include "clang/Basic/OpenCLImageTypes.def" + + case BuiltinType::OCLSampler: + return LangAS::opencl_constant; + + default: + return LangAS::Default; + } +} + //===----------------------------------------------------------------------===// diff --git a/clang/lib/Basic/Targets/AMDGPU.h b/clang/lib/Basic/Targets/AMDGPU.h index 8d753f5a176..d9e290bad09 100644 --- a/clang/lib/Basic/Targets/AMDGPU.h +++ b/clang/lib/Basic/Targets/AMDGPU.h @@ -14,6 +14,7 @@ #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/Triple.h" @@ -190,8 +191,21 @@ public: } } - LangAS::ID getOpenCLImageAddrSpace() const override { + LangAS::ID getOpenCLTypeAddrSpace(const Type *T) const override { + auto BT = dyn_cast<BuiltinType>(T); + + 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" + + default: + return TargetInfo::getOpenCLTypeAddrSpace(T); + } } llvm::Optional<unsigned> getConstantAddressSpace() const override { diff --git a/clang/lib/CodeGen/CGOpenCLRuntime.cpp b/clang/lib/CodeGen/CGOpenCLRuntime.cpp index db02c631c9e..01617436d62 100644 --- a/clang/lib/CodeGen/CGOpenCLRuntime.cpp +++ b/clang/lib/CodeGen/CGOpenCLRuntime.cpp @@ -35,8 +35,8 @@ llvm::Type *CGOpenCLRuntime::convertOpenCLSpecificType(const Type *T) { "Not an OpenCL specific type!"); llvm::LLVMContext& Ctx = CGM.getLLVMContext(); - uint32_t ImgAddrSpc = CGM.getContext().getTargetAddressSpace( - CGM.getTarget().getOpenCLImageAddrSpace()); + uint32_t AddrSpc = CGM.getContext().getTargetAddressSpace( + CGM.getTarget().getOpenCLTypeAddrSpace(T)); switch (cast<BuiltinType>(T)->getKind()) { default: llvm_unreachable("Unexpected opencl builtin type!"); @@ -45,29 +45,29 @@ llvm::Type *CGOpenCLRuntime::convertOpenCLSpecificType(const Type *T) { case BuiltinType::Id: \ return llvm::PointerType::get( \ llvm::StructType::create(Ctx, "opencl." #ImgType "_" #Suffix "_t"), \ - ImgAddrSpc); + AddrSpc); #include "clang/Basic/OpenCLImageTypes.def" case BuiltinType::OCLSampler: - return getSamplerType(); + return getSamplerType(T); case BuiltinType::OCLEvent: - return llvm::PointerType::get(llvm::StructType::create( - Ctx, "opencl.event_t"), 0); + return llvm::PointerType::get( + llvm::StructType::create(Ctx, "opencl.event_t"), AddrSpc); case BuiltinType::OCLClkEvent: return llvm::PointerType::get( - llvm::StructType::create(Ctx, "opencl.clk_event_t"), 0); + llvm::StructType::create(Ctx, "opencl.clk_event_t"), AddrSpc); case BuiltinType::OCLQueue: return llvm::PointerType::get( - llvm::StructType::create(Ctx, "opencl.queue_t"), 0); + llvm::StructType::create(Ctx, "opencl.queue_t"), AddrSpc); case BuiltinType::OCLReserveID: return llvm::PointerType::get( - llvm::StructType::create(Ctx, "opencl.reserve_id_t"), 0); + llvm::StructType::create(Ctx, "opencl.reserve_id_t"), AddrSpc); } } -llvm::Type *CGOpenCLRuntime::getPipeType() { +llvm::Type *CGOpenCLRuntime::getPipeType(const PipeType *T) { if (!PipeTy){ - uint32_t PipeAddrSpc = - CGM.getContext().getTargetAddressSpace(LangAS::opencl_global); + uint32_t PipeAddrSpc = CGM.getContext().getTargetAddressSpace( + CGM.getTarget().getOpenCLTypeAddrSpace(T)); PipeTy = llvm::PointerType::get(llvm::StructType::create( CGM.getLLVMContext(), "opencl.pipe_t"), PipeAddrSpc); } @@ -75,12 +75,12 @@ llvm::Type *CGOpenCLRuntime::getPipeType() { return PipeTy; } -llvm::PointerType *CGOpenCLRuntime::getSamplerType() { +llvm::PointerType *CGOpenCLRuntime::getSamplerType(const Type *T) { if (!SamplerTy) SamplerTy = llvm::PointerType::get(llvm::StructType::create( CGM.getLLVMContext(), "opencl.sampler_t"), CGM.getContext().getTargetAddressSpace( - LangAS::opencl_constant)); + CGM.getTarget().getOpenCLTypeAddrSpace(T))); return SamplerTy; } diff --git a/clang/lib/CodeGen/CGOpenCLRuntime.h b/clang/lib/CodeGen/CGOpenCLRuntime.h index ee3cb3dda06..f28d414cd77 100644 --- a/clang/lib/CodeGen/CGOpenCLRuntime.h +++ b/clang/lib/CodeGen/CGOpenCLRuntime.h @@ -48,9 +48,9 @@ public: virtual llvm::Type *convertOpenCLSpecificType(const Type *T); - virtual llvm::Type *getPipeType(); + virtual llvm::Type *getPipeType(const PipeType *T); - llvm::PointerType *getSamplerType(); + llvm::PointerType *getSamplerType(const Type *T); // \brief Returnes a value which indicates the size in bytes of the pipe // element. diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 5ba95c99a79..fe45d16dc2d 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -4536,7 +4536,7 @@ llvm::Value * CodeGenModule::createOpenCLIntToSamplerConversion(const Expr *E, CodeGenFunction &CGF) { llvm::Constant *C = EmitConstantExpr(E, E->getType(), &CGF); - auto SamplerT = getOpenCLRuntime().getSamplerType(); + auto SamplerT = getOpenCLRuntime().getSamplerType(E->getType().getTypePtr()); auto FTy = llvm::FunctionType::get(SamplerT, {C->getType()}, false); return CGF.Builder.CreateCall(CreateRuntimeFunction(FTy, "__translate_sampler_initializer"), diff --git a/clang/lib/CodeGen/CodeGenTypes.cpp b/clang/lib/CodeGen/CodeGenTypes.cpp index 5ed92913588..4ba0ba863c9 100644 --- a/clang/lib/CodeGen/CodeGenTypes.cpp +++ b/clang/lib/CodeGen/CodeGenTypes.cpp @@ -635,7 +635,7 @@ llvm::Type *CodeGenTypes::ConvertType(QualType T) { break; } case Type::Pipe: { - ResultType = CGM.getOpenCLRuntime().getPipeType(); + ResultType = CGM.getOpenCLRuntime().getPipeType(cast<PipeType>(Ty)); break; } } |

