| 1 | //===------ CIRGenCUDARuntime.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 | |
| 15 | #ifndef LLVM_CLANG_LIB_CIR_CIRGENCUDARUNTIME_H |
| 16 | #define LLVM_CLANG_LIB_CIR_CIRGENCUDARUNTIME_H |
| 17 | |
| 18 | #include "clang/CIR/Dialect/IR/CIRDialect.h" |
| 19 | |
| 20 | namespace clang { |
| 21 | class CUDAKernelCallExpr; |
| 22 | } |
| 23 | |
| 24 | namespace clang::CIRGen { |
| 25 | |
| 26 | class CIRGenFunction; |
| 27 | class CIRGenModule; |
| 28 | class FunctionArgList; |
| 29 | class RValue; |
| 30 | class ReturnValueSlot; |
| 31 | |
| 32 | class CIRGenCUDARuntime { |
| 33 | protected: |
| 34 | CIRGenModule &cgm; |
| 35 | |
| 36 | public: |
| 37 | CIRGenCUDARuntime(CIRGenModule &cgm) : cgm(cgm) {} |
| 38 | virtual ~CIRGenCUDARuntime(); |
| 39 | |
| 40 | virtual void emitDeviceStub(CIRGenFunction &cgf, cir::FuncOp fn, |
| 41 | FunctionArgList &args) = 0; |
| 42 | |
| 43 | virtual RValue emitCUDAKernelCallExpr(CIRGenFunction &cgf, |
| 44 | const CUDAKernelCallExpr *expr, |
| 45 | ReturnValueSlot retValue); |
| 46 | |
| 47 | virtual mlir::Operation *getKernelHandle(cir::FuncOp fn, GlobalDecl gd) = 0; |
| 48 | |
| 49 | virtual mlir::Operation *getKernelStub(mlir::Operation *handle) = 0; |
| 50 | |
| 51 | /// Adjust linkage of shadow variables in host compilation |
| 52 | virtual void internalizeDeviceSideVar(const VarDecl *d, |
| 53 | cir::GlobalLinkageKind &linkage) = 0; |
| 54 | |
| 55 | /// Check whether a variable is a device variable and register it if true. |
| 56 | virtual void handleVarRegistration(const VarDecl *vd, cir::GlobalOp var) = 0; |
| 57 | |
| 58 | /// Perform module finalization: on device side, mark ODR-used device |
| 59 | /// variables as compiler-used. Mirrors OG's CGCUDARuntime::finalizeModule. |
| 60 | virtual void finalizeModule() {} |
| 61 | |
| 62 | /// Returns function or variable name on device side even if the current |
| 63 | /// compilation is for host. |
| 64 | virtual std::string getDeviceSideName(const NamedDecl *nd) = 0; |
| 65 | |
| 66 | virtual void handleGlobalReplace(cir::GlobalOp oldGV, cir::GlobalOp newGV) {} |
| 67 | }; |
| 68 | |
| 69 | CIRGenCUDARuntime *createNVCUDARuntime(CIRGenModule &cgm); |
| 70 | |
| 71 | } // namespace clang::CIRGen |
| 72 | |
| 73 | #endif // LLVM_CLANG_LIB_CIR_CIRGENCUDARUNTIME_H |
| 74 | |