clang  5.0.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 "TargetInfo.h"
19 #include "llvm/IR/DerivedTypes.h"
20 #include "llvm/IR/GlobalValue.h"
21 #include <assert.h>
22 
23 using namespace clang;
24 using namespace CodeGen;
25 
27 
29  const VarDecl &D) {
31 }
32 
34  assert(T->isOpenCLSpecificType() &&
35  "Not an OpenCL specific type!");
36 
37  llvm::LLVMContext& Ctx = CGM.getLLVMContext();
38  uint32_t ImgAddrSpc = CGM.getContext().getTargetAddressSpace(
40  switch (cast<BuiltinType>(T)->getKind()) {
41  default:
42  llvm_unreachable("Unexpected opencl builtin type!");
43  return nullptr;
44 #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
45  case BuiltinType::Id: \
46  return llvm::PointerType::get( \
47  llvm::StructType::create(Ctx, "opencl." #ImgType "_" #Suffix "_t"), \
48  ImgAddrSpc);
49 #include "clang/Basic/OpenCLImageTypes.def"
50  case BuiltinType::OCLSampler:
51  return getSamplerType();
52  case BuiltinType::OCLEvent:
53  return llvm::PointerType::get(llvm::StructType::create(
54  Ctx, "opencl.event_t"), 0);
55  case BuiltinType::OCLClkEvent:
56  return llvm::PointerType::get(
57  llvm::StructType::create(Ctx, "opencl.clk_event_t"), 0);
58  case BuiltinType::OCLQueue:
59  return llvm::PointerType::get(
60  llvm::StructType::create(Ctx, "opencl.queue_t"), 0);
61  case BuiltinType::OCLReserveID:
62  return llvm::PointerType::get(
63  llvm::StructType::create(Ctx, "opencl.reserve_id_t"), 0);
64  }
65 }
66 
68  if (!PipeTy){
69  uint32_t PipeAddrSpc =
71  PipeTy = llvm::PointerType::get(llvm::StructType::create(
72  CGM.getLLVMContext(), "opencl.pipe_t"), PipeAddrSpc);
73  }
74 
75  return PipeTy;
76 }
77 
78 llvm::PointerType *CGOpenCLRuntime::getSamplerType() {
79  if (!SamplerTy)
80  SamplerTy = llvm::PointerType::get(llvm::StructType::create(
81  CGM.getLLVMContext(), "opencl.sampler_t"),
84  return SamplerTy;
85 }
86 
88  const PipeType *PipeTy = PipeArg->getType()->getAs<PipeType>();
89  // The type of the last (implicit) argument to be passed.
90  llvm::Type *Int32Ty = llvm::IntegerType::getInt32Ty(CGM.getLLVMContext());
91  unsigned TypeSize = CGM.getContext()
93  .getQuantity();
94  return llvm::ConstantInt::get(Int32Ty, TypeSize, false);
95 }
96 
98  const PipeType *PipeTy = PipeArg->getType()->getAs<PipeType>();
99  // The type of the last (implicit) argument to be passed.
100  llvm::Type *Int32Ty = llvm::IntegerType::getInt32Ty(CGM.getLLVMContext());
101  unsigned TypeSize = CGM.getContext()
103  .getQuantity();
104  return llvm::ConstantInt::get(Int32Ty, TypeSize, false);
105 }
void EmitStaticVarDecl(const VarDecl &D, llvm::GlobalValue::LinkageTypes Linkage)
Definition: CGDecl.cpp:368
llvm::LLVMContext & getLLVMContext()
The base class of the type hierarchy.
Definition: Type.h:1303
virtual llvm::Value * getPipeElemAlign(const Expr *PipeArg)
VarDecl - An instance of this class is created to represent a variable declaration or definition...
Definition: Decl.h:758
PipeType - OpenCL20.
Definition: Type.h:5419
bool isOpenCLSpecificType() const
Definition: Type.h:5864
CodeGenFunction - This class organizes the per-function state that is used while generating LLVM code...
CharUnits getTypeSizeInChars(QualType T) const
Return the size of the specified (complete) type T, in characters.
virtual llvm::Type * convertOpenCLSpecificType(const Type *T)
const TargetInfo & getTarget() const
Expr - This represents one expression.
Definition: Expr.h:105
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
virtual llvm::Value * getPipeElemSize(const Expr *PipeArg)
The l-value was considered opaque, so the alignment was determined from a type.
CharUnits getTypeAlignInChars(QualType T) const
Return the ABI-specified alignment of a (complete) type T, in characters.
virtual LangAS::ID getOpenCLImageAddrSpace() const
Get OpenCL image type address space.
Definition: TargetInfo.h:1055
QualType getType() const
Definition: Expr.h:127
std::unique_ptr< DiagnosticConsumer > create(StringRef OutputFile, DiagnosticOptions *Diags, bool MergeChildRecords=false)
Returns a DiagnosticConsumer that serializes diagnostics to a bitcode file.
const T * getAs() const
Member-template getAs<specific type>'.
Definition: Type.h:6042
llvm::PointerType * getSamplerType()
Internal linkage, which indicates that the entity can be referred to from within the translation unit...
Definition: Linkage.h:33
virtual llvm::Type * getPipeType()
unsigned getTargetAddressSpace(QualType T) const
Definition: ASTContext.h:2321
QualType getElementType() const
Definition: Type.h:5432