This patch adds the basic JIT support for OpenMP. Currently it only works on Nvidia GPUs.
The support for AMDGPU can be extended easily by just implementing three interface functions. However, the infrastructure requires a small extra extension (add a pre process hook) to support portability for AMDGPU because the AMDGPU backend reads target features of functions. 02bc7effcc (diff-321c2038035972ad4994ff9d85b29950ba72c08a79891db5048b8f5d46915314R432) shows how it roughly works.
As for the test, even though I added the corresponding code in CMake files, the test still cannot be triggered because some code is missing in the new plugin CMake file, which has nothing to do with this patch. It will be fixed later.
In order to enable JIT mode, when compiling, `-foffload-lto` is needed, and when linking, `-foffload-lto -Wl,--embed-bitcode` is needed. That implies that, LTO is required to enable JIT mode.
Reviewed By: jdoerfert
Differential Revision: https://reviews.llvm.org/D139287
51 lines
1.8 KiB
C++
51 lines
1.8 KiB
C++
//===- JIT.h - Target independent JIT infrastructure ----------------------===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef OPENMP_LIBOMPTARGET_PLUGINS_NEXTGEN_COMMON_JIT_H
|
|
#define OPENMP_LIBOMPTARGET_PLUGINS_NEXTGEN_COMMON_JIT_H
|
|
|
|
#include "llvm/ADT/StringRef.h"
|
|
#include "llvm/ADT/Triple.h"
|
|
#include "llvm/Support/Error.h"
|
|
|
|
#include <functional>
|
|
#include <memory>
|
|
#include <string>
|
|
|
|
struct __tgt_device_image;
|
|
|
|
namespace llvm {
|
|
class MemoryBuffer;
|
|
|
|
namespace omp {
|
|
namespace jit {
|
|
|
|
/// Function type for a callback that will be called after the backend is
|
|
/// called.
|
|
using PostProcessingFn = std::function<Expected<std::unique_ptr<MemoryBuffer>>(
|
|
std::unique_ptr<MemoryBuffer>)>;
|
|
|
|
/// Check if \p Image contains bitcode with triple \p Triple.
|
|
bool checkBitcodeImage(__tgt_device_image *Image, Triple::ArchType TA);
|
|
|
|
/// Compile the bitcode image \p Image and generate the binary image that can be
|
|
/// loaded to the target device of the triple \p Triple architecture \p MCpu. \p
|
|
/// PostProcessing will be called after codegen to handle cases such as assember
|
|
/// as an external tool.
|
|
Expected<__tgt_device_image *> compile(__tgt_device_image *Image,
|
|
Triple::ArchType TA, std::string MCpu,
|
|
unsigned OptLevel,
|
|
PostProcessingFn PostProcessing);
|
|
} // namespace jit
|
|
} // namespace omp
|
|
} // namespace llvm
|
|
|
|
#endif // OPENMP_LIBOMPTARGET_PLUGINS_NEXTGEN_COMMON_JIT_H
|