CGCUDARuntime.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. //===----- CGCUDARuntime.h - Interface to CUDA Runtimes ---------*- C++ -*-===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. //
  9. // This provides an abstract class for CUDA code generation. Concrete
  10. // subclasses of this implement code generation for specific CUDA
  11. // runtime libraries.
  12. //
  13. //===----------------------------------------------------------------------===//
  14. #ifndef LLVM_CLANG_LIB_CODEGEN_CGCUDARUNTIME_H
  15. #define LLVM_CLANG_LIB_CODEGEN_CGCUDARUNTIME_H
  16. #include "llvm/ADT/StringRef.h"
  17. namespace llvm {
  18. class Function;
  19. class GlobalVariable;
  20. }
  21. namespace clang {
  22. class CUDAKernelCallExpr;
  23. class VarDecl;
  24. namespace CodeGen {
  25. class CodeGenFunction;
  26. class CodeGenModule;
  27. class FunctionArgList;
  28. class ReturnValueSlot;
  29. class RValue;
  30. class CGCUDARuntime {
  31. protected:
  32. CodeGenModule &CGM;
  33. public:
  34. // Global variable properties that must be passed to CUDA runtime.
  35. enum DeviceVarFlags {
  36. ExternDeviceVar = 0x01, // extern
  37. ConstantDeviceVar = 0x02, // __constant__
  38. };
  39. CGCUDARuntime(CodeGenModule &CGM) : CGM(CGM) {}
  40. virtual ~CGCUDARuntime();
  41. virtual RValue EmitCUDAKernelCallExpr(CodeGenFunction &CGF,
  42. const CUDAKernelCallExpr *E,
  43. ReturnValueSlot ReturnValue);
  44. /// Emits a kernel launch stub.
  45. virtual void emitDeviceStub(CodeGenFunction &CGF, FunctionArgList &Args) = 0;
  46. virtual void registerDeviceVar(const VarDecl *VD, llvm::GlobalVariable &Var,
  47. unsigned Flags) = 0;
  48. /// Constructs and returns a module initialization function or nullptr if it's
  49. /// not needed. Must be called after all kernels have been emitted.
  50. virtual llvm::Function *makeModuleCtorFunction() = 0;
  51. /// Returns a module cleanup function or nullptr if it's not needed.
  52. /// Must be called after ModuleCtorFunction
  53. virtual llvm::Function *makeModuleDtorFunction() = 0;
  54. /// Construct and return the stub name of a kernel.
  55. virtual std::string getDeviceStubName(llvm::StringRef Name) const = 0;
  56. };
  57. /// Creates an instance of a CUDA runtime class.
  58. CGCUDARuntime *CreateNVCUDARuntime(CodeGenModule &CGM);
  59. }
  60. }
  61. #endif