diff options
author | Yaxun Liu <Yaxun.Liu@amd.com> | 2016-08-03 20:38:06 +0000 |
---|---|---|
committer | Yaxun Liu <Yaxun.Liu@amd.com> | 2016-08-03 20:38:06 +0000 |
commit | 99444cb86099d3bf60145d8fc1ddfa43522ea63e (patch) | |
tree | 20e70e29031d0fcf65d4d64f9dffa433c6be64d3 /clang | |
parent | 803568866c9e0d9049d731628ac0233591e7c8f6 (diff) | |
download | bcm5719-llvm-99444cb86099d3bf60145d8fc1ddfa43522ea63e.tar.gz bcm5719-llvm-99444cb86099d3bf60145d8fc1ddfa43522ea63e.zip |
[OpenCL] Fix size of image type
The size of image type is reported incorrectly as size of a pointer to address space 0, which causes error when casting image type to pointers by __builtin_astype.
The fix is to get image address space from TargetInfo then report the size accordingly.
Differential Revision: https://reviews.llvm.org/D22927
llvm-svn: 277647
Diffstat (limited to 'clang')
-rw-r--r-- | clang/include/clang/Basic/TargetInfo.h | 5 | ||||
-rw-r--r-- | clang/lib/AST/ASTContext.cpp | 12 | ||||
-rw-r--r-- | clang/lib/Basic/Targets.cpp | 4 | ||||
-rw-r--r-- | clang/lib/CodeGen/CGOpenCLRuntime.cpp | 4 | ||||
-rw-r--r-- | clang/lib/CodeGen/TargetInfo.cpp | 9 | ||||
-rw-r--r-- | clang/lib/CodeGen/TargetInfo.h | 3 |
6 files changed, 19 insertions, 18 deletions
diff --git a/clang/include/clang/Basic/TargetInfo.h b/clang/include/clang/Basic/TargetInfo.h index cd79df32a1b..958c28ecfec 100644 --- a/clang/include/clang/Basic/TargetInfo.h +++ b/clang/include/clang/Basic/TargetInfo.h @@ -986,6 +986,11 @@ public: return getTargetOpts().SupportedOpenCLOptions; } + /// \brief Get OpenCL image type address space. + virtual LangAS::ID getOpenCLImageAddrSpace() const { + return LangAS::opencl_global; + } + /// \brief Check the target is valid after it is fully initialized. virtual bool validateTarget(DiagnosticsEngine &Diags) const { return true; diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp index 2aa6a148e3e..4b42141452f 100644 --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/lib/AST/ASTContext.cpp @@ -1750,14 +1750,18 @@ TypeInfo ASTContext::getTypeInfoImpl(const Type *T) const { case BuiltinType::OCLQueue: case BuiltinType::OCLNDRange: case BuiltinType::OCLReserveID: -#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \ - case BuiltinType::Id: -#include "clang/Basic/OpenCLImageTypes.def" - // 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); + } } break; case Type::ObjCObjectPointer: diff --git a/clang/lib/Basic/Targets.cpp b/clang/lib/Basic/Targets.cpp index e6f3e382607..a5e1d6f49e8 100644 --- a/clang/lib/Basic/Targets.cpp +++ b/clang/lib/Basic/Targets.cpp @@ -2131,6 +2131,10 @@ public: } } + LangAS::ID getOpenCLImageAddrSpace() const override { + return LangAS::opencl_constant; + } + CallingConvCheckResult checkCallingConvention(CallingConv CC) const override { switch (CC) { default: diff --git a/clang/lib/CodeGen/CGOpenCLRuntime.cpp b/clang/lib/CodeGen/CGOpenCLRuntime.cpp index e4541d59c25..8983fdeafbc 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.getTargetCodeGenInfo().getOpenCLImageAddrSpace(CGM); + uint32_t ImgAddrSpc = CGM.getContext().getTargetAddressSpace( + CGM.getTarget().getOpenCLImageAddrSpace()); switch (cast<BuiltinType>(T)->getKind()) { default: llvm_unreachable("Unexpected opencl builtin type!"); diff --git a/clang/lib/CodeGen/TargetInfo.cpp b/clang/lib/CodeGen/TargetInfo.cpp index 2d1fa65c476..fa1b58ddd52 100644 --- a/clang/lib/CodeGen/TargetInfo.cpp +++ b/clang/lib/CodeGen/TargetInfo.cpp @@ -401,10 +401,6 @@ unsigned TargetCodeGenInfo::getOpenCLKernelCallingConv() const { return llvm::CallingConv::C; } -unsigned TargetCodeGenInfo::getOpenCLImageAddrSpace(CodeGen::CodeGenModule &CGM) const { - return CGM.getContext().getTargetAddressSpace(LangAS::opencl_global); -} - static bool isEmptyRecord(ASTContext &Context, QualType T, bool AllowArrays); /// isEmptyField - Return true iff a the field is "empty", that is it @@ -6883,7 +6879,6 @@ public: void setTargetAttributes(const Decl *D, llvm::GlobalValue *GV, CodeGen::CodeGenModule &M) const override; unsigned getOpenCLKernelCallingConv() const override; - unsigned getOpenCLImageAddrSpace(CodeGen::CodeGenModule &CGM) const override; }; } @@ -6920,10 +6915,6 @@ unsigned AMDGPUTargetCodeGenInfo::getOpenCLKernelCallingConv() const { return llvm::CallingConv::AMDGPU_KERNEL; } -unsigned AMDGPUTargetCodeGenInfo::getOpenCLImageAddrSpace(CodeGen::CodeGenModule &CGM) const { - return CGM.getContext().getTargetAddressSpace(LangAS::opencl_constant); -} - //===----------------------------------------------------------------------===// // SPARC v8 ABI Implementation. // Based on the SPARC Compliance Definition version 2.4.1. diff --git a/clang/lib/CodeGen/TargetInfo.h b/clang/lib/CodeGen/TargetInfo.h index 64a082b4bbf..e46382596af 100644 --- a/clang/lib/CodeGen/TargetInfo.h +++ b/clang/lib/CodeGen/TargetInfo.h @@ -220,9 +220,6 @@ public: /// Get LLVM calling convention for OpenCL kernel. virtual unsigned getOpenCLKernelCallingConv() const; - - /// Get LLVM Image Address Space for OpenCL kernel. - virtual unsigned getOpenCLImageAddrSpace(CodeGen::CodeGenModule &CGM) const; }; } // namespace CodeGen |