clang  3.8.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  case BuiltinType::OCLImage1d:
44  return llvm::PointerType::get(llvm::StructType::create(
45  Ctx, "opencl.image1d_t"), ImgAddrSpc);
46  case BuiltinType::OCLImage1dArray:
47  return llvm::PointerType::get(llvm::StructType::create(
48  Ctx, "opencl.image1d_array_t"), ImgAddrSpc);
49  case BuiltinType::OCLImage1dBuffer:
50  return llvm::PointerType::get(llvm::StructType::create(
51  Ctx, "opencl.image1d_buffer_t"), ImgAddrSpc);
52  case BuiltinType::OCLImage2d:
53  return llvm::PointerType::get(llvm::StructType::create(
54  Ctx, "opencl.image2d_t"), ImgAddrSpc);
55  case BuiltinType::OCLImage2dArray:
56  return llvm::PointerType::get(llvm::StructType::create(
57  Ctx, "opencl.image2d_array_t"), ImgAddrSpc);
58  case BuiltinType::OCLImage2dDepth:
59  return llvm::PointerType::get(
60  llvm::StructType::create(Ctx, "opencl.image2d_depth_t"), ImgAddrSpc);
61  case BuiltinType::OCLImage2dArrayDepth:
62  return llvm::PointerType::get(
63  llvm::StructType::create(Ctx, "opencl.image2d_array_depth_t"),
64  ImgAddrSpc);
65  case BuiltinType::OCLImage2dMSAA:
66  return llvm::PointerType::get(
67  llvm::StructType::create(Ctx, "opencl.image2d_msaa_t"), ImgAddrSpc);
68  case BuiltinType::OCLImage2dArrayMSAA:
69  return llvm::PointerType::get(
70  llvm::StructType::create(Ctx, "opencl.image2d_array_msaa_t"),
71  ImgAddrSpc);
72  case BuiltinType::OCLImage2dMSAADepth:
73  return llvm::PointerType::get(
74  llvm::StructType::create(Ctx, "opencl.image2d_msaa_depth_t"),
75  ImgAddrSpc);
76  case BuiltinType::OCLImage2dArrayMSAADepth:
77  return llvm::PointerType::get(
78  llvm::StructType::create(Ctx, "opencl.image2d_array_msaa_depth_t"),
79  ImgAddrSpc);
80  case BuiltinType::OCLImage3d:
81  return llvm::PointerType::get(llvm::StructType::create(
82  Ctx, "opencl.image3d_t"), ImgAddrSpc);
83  case BuiltinType::OCLSampler:
84  return llvm::IntegerType::get(Ctx, 32);
85  case BuiltinType::OCLEvent:
86  return llvm::PointerType::get(llvm::StructType::create(
87  Ctx, "opencl.event_t"), 0);
88  case BuiltinType::OCLClkEvent:
89  return llvm::PointerType::get(
90  llvm::StructType::create(Ctx, "opencl.clk_event_t"), 0);
91  case BuiltinType::OCLQueue:
92  return llvm::PointerType::get(
93  llvm::StructType::create(Ctx, "opencl.queue_t"), 0);
94  case BuiltinType::OCLNDRange:
95  return llvm::PointerType::get(
96  llvm::StructType::create(Ctx, "opencl.ndrange_t"), 0);
97  case BuiltinType::OCLReserveID:
98  return llvm::PointerType::get(
99  llvm::StructType::create(Ctx, "opencl.reserve_id_t"), 0);
100  }
101 }
102 
104  if (!PipeTy){
105  uint32_t PipeAddrSpc =
107  PipeTy = llvm::PointerType::get(llvm::StructType::create(
108  CGM.getLLVMContext(), "opencl.pipe_t"), PipeAddrSpc);
109  }
110 
111  return PipeTy;
112 }
void EmitStaticVarDecl(const VarDecl &D, llvm::GlobalValue::LinkageTypes Linkage)
Definition: CGDecl.cpp:343
llvm::LLVMContext & getLLVMContext()
The base class of the type hierarchy.
Definition: Type.h:1249
VarDecl - An instance of this class is created to represent a variable declaration or definition...
Definition: Decl.h:699
bool isOpenCLSpecificType() const
Definition: Type.h:5504
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:772
unsigned getTargetAddressSpace(QualType T) const
Definition: ASTContext.h:2180