1//===- OffloadWrapper.h --r-------------------------------------*- 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#ifndef LLVM_FRONTEND_OFFLOADING_OFFLOADWRAPPER_H
10#define LLVM_FRONTEND_OFFLOADING_OFFLOADWRAPPER_H
11
12#include "llvm/ADT/ArrayRef.h"
13#include "llvm/IR/Module.h"
14#include "llvm/Support/Compiler.h"
15
16#include <string>
17
18namespace llvm {
19namespace offloading {
20using EntryArrayTy = std::pair<GlobalVariable *, GlobalVariable *>;
21/// Wraps the input device images into the module \p M as global symbols and
22/// registers the images with the OpenMP Offloading runtime libomptarget.
23/// \param EntryArray Optional pair pointing to the `__start` and `__stop`
24/// symbols holding the `__tgt_offload_entry` array.
25/// \param Suffix An optional suffix appended to the emitted symbols.
26/// \param Relocatable Indicate if we need to change the offloading section to
27/// create a relocatable object.
28LLVM_ABI llvm::Error
29wrapOpenMPBinaries(llvm::Module &M, llvm::ArrayRef<llvm::ArrayRef<char>> Images,
30 EntryArrayTy EntryArray, llvm::StringRef Suffix = "",
31 bool Relocatable = false);
32
33/// Wraps the input fatbinary image into the module \p M as global symbols and
34/// registers the images with the CUDA runtime.
35/// \param EntryArray Optional pair pointing to the `__start` and `__stop`
36/// symbols holding the `__tgt_offload_entry` array.
37/// \param Suffix An optional suffix appended to the emitted symbols.
38/// \param EmitSurfacesAndTextures Whether to emit surface and textures
39/// registration code. It defaults to false.
40LLVM_ABI llvm::Error wrapCudaBinary(llvm::Module &M,
41 llvm::ArrayRef<char> Images,
42 EntryArrayTy EntryArray,
43 llvm::StringRef Suffix = "",
44 bool EmitSurfacesAndTextures = true);
45
46/// Wraps the input bundled image into the module \p M as global symbols and
47/// registers the images with the HIP runtime.
48/// \param EntryArray Optional pair pointing to the `__start` and `__stop`
49/// symbols holding the `__tgt_offload_entry` array.
50/// \param Suffix An optional suffix appended to the emitted symbols.
51/// \param EmitSurfacesAndTextures Whether to emit surface and textures
52/// registration code. It defaults to false.
53LLVM_ABI llvm::Error wrapHIPBinary(llvm::Module &M, llvm::ArrayRef<char> Images,
54 EntryArrayTy EntryArray,
55 llvm::StringRef Suffix = "",
56 bool EmitSurfacesAndTextures = true);
57
58struct SYCLJITOptions {
59 // Target/compiler specific options that are passed to the device compiler at
60 // runtime.
61 std::string CompileOptions;
62 // Target/compiler specific options that are passed to the device linker at
63 // runtime.
64 std::string LinkOptions;
65};
66
67/// Wraps OffloadBinaries in the given \p Buffers into the module \p M
68/// as global symbols and registers the images with the SYCL Runtime.
69/// \param Options Compiler and linker options to be encoded for the later
70/// use by a runtime for JIT compilation. Not used for AOT.
71LLVM_ABI llvm::Error
72wrapSYCLBinaries(llvm::Module &M, llvm::ArrayRef<char> Buffer,
73 SYCLJITOptions Options = SYCLJITOptions());
74
75} // namespace offloading
76} // namespace llvm
77
78#endif // LLVM_FRONTEND_OFFLOADING_OFFLOADWRAPPER_H
79