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 25 CGOpenCLRuntime::~CGOpenCLRuntime() {} 26 27 void CGOpenCLRuntime::EmitWorkGroupLocalVarDecl(CodeGenFunction &CGF, 28 const VarDecl &D) { 29 return CGF.EmitStaticVarDecl(D, llvm::GlobalValue::InternalLinkage); 30 } 31 32 llvm::Type *CGOpenCLRuntime::convertOpenCLSpecificType(const Type *T) { 33 assert(T->isOpenCLSpecificType() && 34 "Not an OpenCL specific type!"); 35 36 llvm::LLVMContext& Ctx = CGM.getLLVMContext(); 37 uint32_t ImgAddrSpc = 38 CGM.getContext().getTargetAddressSpace(LangAS::opencl_global); 39 switch (cast<BuiltinType>(T)->getKind()) { 40 default: 41 llvm_unreachable("Unexpected opencl builtin type!"); 42 return nullptr; 43 #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \ 44 case BuiltinType::Id: \ 45 return llvm::PointerType::get( \ 46 llvm::StructType::create(Ctx, "opencl." #ImgType "_" #Suffix "_t"), \ 47 ImgAddrSpc); 48 #include "clang/Basic/OpenCLImageTypes.def" 49 case BuiltinType::OCLSampler: 50 return llvm::IntegerType::get(Ctx, 32); 51 case BuiltinType::OCLEvent: 52 return llvm::PointerType::get(llvm::StructType::create( 53 Ctx, "opencl.event_t"), 0); 54 case BuiltinType::OCLClkEvent: 55 return llvm::PointerType::get( 56 llvm::StructType::create(Ctx, "opencl.clk_event_t"), 0); 57 case BuiltinType::OCLQueue: 58 return llvm::PointerType::get( 59 llvm::StructType::create(Ctx, "opencl.queue_t"), 0); 60 case BuiltinType::OCLNDRange: 61 return llvm::PointerType::get( 62 llvm::StructType::create(Ctx, "opencl.ndrange_t"), 0); 63 case BuiltinType::OCLReserveID: 64 return llvm::PointerType::get( 65 llvm::StructType::create(Ctx, "opencl.reserve_id_t"), 0); 66 } 67 } 68 69 llvm::Type *CGOpenCLRuntime::getPipeType() { 70 if (!PipeTy){ 71 uint32_t PipeAddrSpc = 72 CGM.getContext().getTargetAddressSpace(LangAS::opencl_global); 73 PipeTy = llvm::PointerType::get(llvm::StructType::create( 74 CGM.getLLVMContext(), "opencl.pipe_t"), PipeAddrSpc); 75 } 76 77 return PipeTy; 78 } 79