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