CGOpenCLRuntime.cpp 2.7 KB

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