1 //===----- CGOpenCLRuntime.cpp - Interface to OpenCL Runtimes -------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This provides an abstract class for OpenCL code generation. Concrete
11 // subclasses of this implement code generation for specific OpenCL
14 //===----------------------------------------------------------------------===//
16 #include "CGOpenCLRuntime.h"
17 #include "CodeGenFunction.h"
18 #include "llvm/IR/DerivedTypes.h"
19 #include "llvm/IR/GlobalValue.h"
22 using namespace clang;
23 using namespace CodeGen;
25 CGOpenCLRuntime::~CGOpenCLRuntime() {}
27 void CGOpenCLRuntime::EmitWorkGroupLocalVarDecl(CodeGenFunction &CGF,
29 return CGF.EmitStaticVarDecl(D, llvm::GlobalValue::InternalLinkage);
32 llvm::Type *CGOpenCLRuntime::convertOpenCLSpecificType(const Type *T) {
33 assert(T->isOpenCLSpecificType() &&
34 "Not an OpenCL specific type!");
36 llvm::LLVMContext& Ctx = CGM.getLLVMContext();
38 CGM.getContext().getTargetAddressSpace(LangAS::opencl_global);
39 switch (cast<BuiltinType>(T)->getKind()) {
41 llvm_unreachable("Unexpected opencl builtin type!");
43 case BuiltinType::OCLImage1d:
44 return llvm::PointerType::get(llvm::StructType::create(
45 Ctx, "opencl.image1d_t"), ImgAddrSpc);
46 case BuiltinType::OCLImage1dArray:
47 return llvm::PointerType::get(llvm::StructType::create(
48 Ctx, "opencl.image1d_array_t"), ImgAddrSpc);
49 case BuiltinType::OCLImage1dBuffer:
50 return llvm::PointerType::get(llvm::StructType::create(
51 Ctx, "opencl.image1d_buffer_t"), ImgAddrSpc);
52 case BuiltinType::OCLImage2d:
53 return llvm::PointerType::get(llvm::StructType::create(
54 Ctx, "opencl.image2d_t"), ImgAddrSpc);
55 case BuiltinType::OCLImage2dArray:
56 return llvm::PointerType::get(llvm::StructType::create(
57 Ctx, "opencl.image2d_array_t"), ImgAddrSpc);
58 case BuiltinType::OCLImage3d:
59 return llvm::PointerType::get(llvm::StructType::create(
60 Ctx, "opencl.image3d_t"), ImgAddrSpc);
61 case BuiltinType::OCLSampler:
62 return llvm::IntegerType::get(Ctx, 32);
63 case BuiltinType::OCLEvent:
64 return llvm::PointerType::get(llvm::StructType::create(
65 Ctx, "opencl.event_t"), 0);