clang  3.9.0
CGOpenCLRuntime.cpp
Go to the documentation of this file.
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 
26 
28  const VarDecl &D) {
30 }
31 
33  assert(T->isOpenCLSpecificType() &&
34  "Not an OpenCL specific type!");
35 
36  llvm::LLVMContext& Ctx = CGM.getLLVMContext();
37  uint32_t ImgAddrSpc =
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 
70  if (!PipeTy){
71  uint32_t PipeAddrSpc =
73  PipeTy = llvm::PointerType::get(llvm::StructType::create(
74  CGM.getLLVMContext(), "opencl.pipe_t"), PipeAddrSpc);
75  }
76 
77  return PipeTy;
78 }
void EmitStaticVarDecl(const VarDecl &D, llvm::GlobalValue::LinkageTypes Linkage)
Definition: CGDecl.cpp:352
llvm::LLVMContext & getLLVMContext()
The base class of the type hierarchy.
Definition: Type.h:1281
VarDecl - An instance of this class is created to represent a variable declaration or definition...
Definition: Decl.h:768
bool isOpenCLSpecificType() const
Definition: Type.h:5638
CodeGenFunction - This class organizes the per-function state that is used while generating LLVM code...
virtual llvm::Type * convertOpenCLSpecificType(const Type *T)
virtual void EmitWorkGroupLocalVarDecl(CodeGenFunction &CGF, const VarDecl &D)
Emit the IR required for a work-group-local variable declaration, and add an entry to CGF's LocalDecl...
ASTContext & getContext() const
The l-value was considered opaque, so the alignment was determined from a type.
std::unique_ptr< DiagnosticConsumer > create(StringRef OutputFile, DiagnosticOptions *Diags, bool MergeChildRecords=false)
Returns a DiagnosticConsumer that serializes diagnostics to a bitcode file.
Internal linkage, which indicates that the entity can be referred to from within the translation unit...
Definition: Linkage.h:33
virtual llvm::Type * getPipeType()
static Decl::Kind getKind(const Decl *D)
Definition: DeclBase.cpp:810
unsigned getTargetAddressSpace(QualType T) const
Definition: ASTContext.h:2200