diff options
author | Pekka Jaaskelainen <pekka.jaaskelainen@tut.fi> | 2014-01-09 13:37:30 +0000 |
---|---|---|
committer | Pekka Jaaskelainen <pekka.jaaskelainen@tut.fi> | 2014-01-09 13:37:30 +0000 |
commit | 3587b32e1cc978d997602d4c0784cdcedda7de3f (patch) | |
tree | 22a2c896daeee817f54ffce2fafc8719256b71a3 /clang/lib/CodeGen | |
parent | af4480a121473f7218081a38a92562c742b47dc1 (diff) | |
download | bcm5719-llvm-3587b32e1cc978d997602d4c0784cdcedda7de3f.tar.gz bcm5719-llvm-3587b32e1cc978d997602d4c0784cdcedda7de3f.zip |
The OpenCL specification states that images are allocated
from the global address space (6.5.1 of the OpenCL 1.2 specification).
This makes clang construct the image arguments in the global address
space and generate the argument metadata with the correct address space
descriptor.
Patch by Pedro Ferreira!
llvm-svn: 198868
Diffstat (limited to 'clang/lib/CodeGen')
-rw-r--r-- | clang/lib/CodeGen/CGOpenCLRuntime.cpp | 19 | ||||
-rw-r--r-- | clang/lib/CodeGen/CodeGenFunction.cpp | 7 |
2 files changed, 17 insertions, 9 deletions
diff --git a/clang/lib/CodeGen/CGOpenCLRuntime.cpp b/clang/lib/CodeGen/CGOpenCLRuntime.cpp index 7c454ac7c69..6e1a3c975d0 100644 --- a/clang/lib/CodeGen/CGOpenCLRuntime.cpp +++ b/clang/lib/CodeGen/CGOpenCLRuntime.cpp @@ -33,32 +33,35 @@ llvm::Type *CGOpenCLRuntime::convertOpenCLSpecificType(const Type *T) { assert(T->isOpenCLSpecificType() && "Not an OpenCL specific type!"); + llvm::LLVMContext& Ctx = CGM.getLLVMContext(); + uint32_t ImgAddrSpc = + CGM.getContext().getTargetAddressSpace(LangAS::opencl_global); switch (cast<BuiltinType>(T)->getKind()) { default: llvm_unreachable("Unexpected opencl builtin type!"); return 0; case BuiltinType::OCLImage1d: return llvm::PointerType::get(llvm::StructType::create( - CGM.getLLVMContext(), "opencl.image1d_t"), 0); + Ctx, "opencl.image1d_t"), ImgAddrSpc); case BuiltinType::OCLImage1dArray: return llvm::PointerType::get(llvm::StructType::create( - CGM.getLLVMContext(), "opencl.image1d_array_t"), 0); + Ctx, "opencl.image1d_array_t"), ImgAddrSpc); case BuiltinType::OCLImage1dBuffer: return llvm::PointerType::get(llvm::StructType::create( - CGM.getLLVMContext(), "opencl.image1d_buffer_t"), 0); + Ctx, "opencl.image1d_buffer_t"), ImgAddrSpc); case BuiltinType::OCLImage2d: return llvm::PointerType::get(llvm::StructType::create( - CGM.getLLVMContext(), "opencl.image2d_t"), 0); + Ctx, "opencl.image2d_t"), ImgAddrSpc); case BuiltinType::OCLImage2dArray: return llvm::PointerType::get(llvm::StructType::create( - CGM.getLLVMContext(), "opencl.image2d_array_t"), 0); + Ctx, "opencl.image2d_array_t"), ImgAddrSpc); case BuiltinType::OCLImage3d: return llvm::PointerType::get(llvm::StructType::create( - CGM.getLLVMContext(), "opencl.image3d_t"), 0); + Ctx, "opencl.image3d_t"), ImgAddrSpc); case BuiltinType::OCLSampler: - return llvm::IntegerType::get(CGM.getLLVMContext(),32); + return llvm::IntegerType::get(Ctx, 32); case BuiltinType::OCLEvent: return llvm::PointerType::get(llvm::StructType::create( - CGM.getLLVMContext(), "opencl.event_t"), 0); + Ctx, "opencl.event_t"), 0); } } diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp index c1e522d0d74..564ea11a8f8 100644 --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -383,7 +383,12 @@ static void GenOpenCLArgMetadata(const FunctionDecl *FD, llvm::Function *Fn, if (pointeeTy.isVolatileQualified()) typeQuals += typeQuals.empty() ? "volatile" : " volatile"; } else { - addressQuals.push_back(Builder.getInt32(0)); + uint32_t AddrSpc = 0; + if (ty->isImageType()) + AddrSpc = + CGM.getContext().getTargetAddressSpace(LangAS::opencl_global); + + addressQuals.push_back(Builder.getInt32(AddrSpc)); // Get argument type name. std::string typeName = ty.getUnqualifiedType().getAsString(); |