clang API Documentation

CGOpenCLRuntime.cpp
Go to the documentation of this file.
00001 //===----- CGOpenCLRuntime.cpp - Interface to OpenCL Runtimes -------------===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This provides an abstract class for OpenCL code generation.  Concrete
00011 // subclasses of this implement code generation for specific OpenCL
00012 // runtime libraries.
00013 //
00014 //===----------------------------------------------------------------------===//
00015 
00016 #include "CGOpenCLRuntime.h"
00017 #include "CodeGenFunction.h"
00018 #include "llvm/IR/DerivedTypes.h"
00019 #include "llvm/IR/GlobalValue.h"
00020 #include <assert.h>
00021 
00022 using namespace clang;
00023 using namespace CodeGen;
00024 
00025 CGOpenCLRuntime::~CGOpenCLRuntime() {}
00026 
00027 void CGOpenCLRuntime::EmitWorkGroupLocalVarDecl(CodeGenFunction &CGF,
00028                                                 const VarDecl &D) {
00029   return CGF.EmitStaticVarDecl(D, llvm::GlobalValue::InternalLinkage);
00030 }
00031 
00032 llvm::Type *CGOpenCLRuntime::convertOpenCLSpecificType(const Type *T) {
00033   assert(T->isOpenCLSpecificType() &&
00034          "Not an OpenCL specific type!");
00035 
00036   llvm::LLVMContext& Ctx = CGM.getLLVMContext();
00037   uint32_t ImgAddrSpc =
00038     CGM.getContext().getTargetAddressSpace(LangAS::opencl_global);
00039   switch (cast<BuiltinType>(T)->getKind()) {
00040   default: 
00041     llvm_unreachable("Unexpected opencl builtin type!");
00042     return nullptr;
00043   case BuiltinType::OCLImage1d:
00044     return llvm::PointerType::get(llvm::StructType::create(
00045                            Ctx, "opencl.image1d_t"), ImgAddrSpc);
00046   case BuiltinType::OCLImage1dArray:
00047     return llvm::PointerType::get(llvm::StructType::create(
00048                            Ctx, "opencl.image1d_array_t"), ImgAddrSpc);
00049   case BuiltinType::OCLImage1dBuffer:
00050     return llvm::PointerType::get(llvm::StructType::create(
00051                            Ctx, "opencl.image1d_buffer_t"), ImgAddrSpc);
00052   case BuiltinType::OCLImage2d:
00053     return llvm::PointerType::get(llvm::StructType::create(
00054                            Ctx, "opencl.image2d_t"), ImgAddrSpc);
00055   case BuiltinType::OCLImage2dArray:
00056     return llvm::PointerType::get(llvm::StructType::create(
00057                            Ctx, "opencl.image2d_array_t"), ImgAddrSpc);
00058   case BuiltinType::OCLImage3d:
00059     return llvm::PointerType::get(llvm::StructType::create(
00060                            Ctx, "opencl.image3d_t"), ImgAddrSpc);
00061   case BuiltinType::OCLSampler:
00062     return llvm::IntegerType::get(Ctx, 32);
00063   case BuiltinType::OCLEvent:
00064     return llvm::PointerType::get(llvm::StructType::create(
00065                            Ctx, "opencl.event_t"), 0);
00066   }
00067 }