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