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<Constant *, Constant *>;
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 begin and end of the
24/// `__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 device images into the module \p M as global symbols and
34/// registers the images with the OpenACC Offloading runtime libacctarget.
35/// \param EntryArray Optional pair pointing to the begin and end of the
36/// `__tgt_offload_entry` array.
37/// \param Relocatable Indicate if we need to change the offloading section to
38/// create a relocatable object.
39LLVM_ABI llvm::Error
40wrapOpenACCBinaries(llvm::Module &M,
41 llvm::ArrayRef<llvm::ArrayRef<char>> Images,
42 EntryArrayTy EntryArray, bool Relocatable = false);
43
44/// Wraps the input fatbinary image into the module \p M as global symbols and
45/// registers the images with the CUDA runtime.
46/// \param EntryArray Optional pair pointing to the begin and end of the
47/// `__tgt_offload_entry` array.
48/// \param Suffix An optional suffix appended to the emitted symbols.
49/// \param EmitSurfacesAndTextures Whether to emit surface and textures
50/// registration code. It defaults to false.
51LLVM_ABI llvm::Error wrapCudaBinary(llvm::Module &M,
52 llvm::ArrayRef<char> Images,
53 EntryArrayTy EntryArray,
54 llvm::StringRef Suffix = "",
55 bool EmitSurfacesAndTextures = true);
56
57/// Wraps the input bundled image into the module \p M as global symbols and
58/// registers the images with the HIP runtime.
59/// \param EntryArray Optional pair pointing to the begin and end of the
60/// `__tgt_offload_entry` array.
61/// \param Suffix An optional suffix appended to the emitted symbols.
62/// \param EmitSurfacesAndTextures Whether to emit surface and textures
63/// registration code. It defaults to false.
64LLVM_ABI llvm::Error wrapHIPBinary(llvm::Module &M, llvm::ArrayRef<char> Images,
65 EntryArrayTy EntryArray,
66 llvm::StringRef Suffix = "",
67 bool EmitSurfacesAndTextures = true);
68
69struct SYCLJITOptions {
70 // Target/compiler specific options that are passed to the device compiler at
71 // runtime.
72 std::string CompileOptions;
73 // Target/compiler specific options that are passed to the device linker at
74 // runtime.
75 std::string LinkOptions;
76};
77
78/// Wraps OffloadBinaries in the given \p Buffers into the module \p M
79/// as global symbols and registers the images with the SYCL Runtime.
80/// \param Options Compiler and linker options to be encoded for the later
81/// use by a runtime for JIT compilation. Not used for AOT.
82/// \param IsFinalizedImage True when \p Buffer holds a device image that must
83/// not be device-linked again, e.g. from -fno-gpu-rdc or a relocatable link.
84/// It is put in .sycl_fatbin instead of .llvm.offloading, so
85/// clang-linker-wrapper does not extract it for linking.
86/// \param RegistrationFunc When given, receives the function that registers the
87/// binary with the runtime instead of it being appended to llvm.global_ctors.
88/// A caller has to add it to that list itself.
89LLVM_ABI llvm::Error
90wrapSYCLBinaries(llvm::Module &M, llvm::ArrayRef<char> Buffer,
91 SYCLJITOptions Options = SYCLJITOptions(),
92 bool IsFinalizedImage = false,
93 llvm::Function **RegistrationFunc = nullptr);
94
95} // namespace offloading
96} // namespace llvm
97
98#endif // LLVM_FRONTEND_OFFLOADING_OFFLOADWRAPPER_H
99