forked from OSchip/llvm-project
[LinkerWrapper] Embed OffloadBinaries for OpenMP offloading images
The OpenMP offloading runtine currently uses an array of linked offloading images. One downside to this is that we cannot know the architecture or triple associated with the given image. In this patch, instead of embedding the image itself, we embed an offloading binary instead. This binary is simply a binary format that wraps around the original linked image to provide some additional metadata. This will allow us to support offloading to multiple architecture, or performing future JIT compilation inside of the runtime, more clearly. Additionally, these can be placed at a special section such that the supported architectures can be identified using objdump with the support from D126904. This needs to be stored in a new section name `.llvm.offloading.images` because the `.llvm.offloading` section implicitly uses the `SHF_EXCLUDE` flag and will always be stripped. This patch does not contain the necessary code to parse these in libomptarget. Depends on D127246 Reviewed By: saiislam Differential Revision: https://reviews.llvm.org/D127304
This commit is contained in:
parent
53d7bf3052
commit
080022d8ed
|
@ -11,8 +11,8 @@
|
|||
// OPENMP: @__start_omp_offloading_entries = external hidden constant %__tgt_offload_entry
|
||||
// OPENMP-NEXT: @__stop_omp_offloading_entries = external hidden constant %__tgt_offload_entry
|
||||
// OPENMP-NEXT: @__dummy.omp_offloading.entry = hidden constant [0 x %__tgt_offload_entry] zeroinitializer, section "omp_offloading_entries"
|
||||
// OPENMP-NEXT: @.omp_offloading.device_image = internal unnamed_addr constant [0 x i8] zeroinitializer
|
||||
// OPENMP-NEXT: @.omp_offloading.device_images = internal unnamed_addr constant [1 x %__tgt_device_image] [%__tgt_device_image { ptr @.omp_offloading.device_image, ptr @.omp_offloading.device_image, ptr @__start_omp_offloading_entries, ptr @__stop_omp_offloading_entries }]
|
||||
// OPENMP-NEXT: @.omp_offloading.device_image = internal unnamed_addr constant [[[SIZE:[0-9]+]] x i8] c"\10\FF\10\AD{{.*}}"
|
||||
// OPENMP-NEXT: @.omp_offloading.device_images = internal unnamed_addr constant [1 x %__tgt_device_image] [%__tgt_device_image { ptr @.omp_offloading.device_image, ptr getelementptr inbounds ([[[SIZE]] x i8], ptr @.omp_offloading.device_image, i64 1, i64 0), ptr @__start_omp_offloading_entries, ptr @__stop_omp_offloading_entries }]
|
||||
// OPENMP-NEXT: @.omp_offloading.descriptor = internal constant %__tgt_bin_desc { i32 1, ptr @.omp_offloading.device_images, ptr @__start_omp_offloading_entries, ptr @__stop_omp_offloading_entries }
|
||||
// OPENMP-NEXT: @llvm.global_ctors = appending global [1 x { i32, ptr, ptr }] [{ i32, ptr, ptr } { i32 1, ptr @.omp_offloading.descriptor_reg, ptr null }]
|
||||
// OPENMP-NEXT: @llvm.global_dtors = appending global [1 x { i32, ptr, ptr }] [{ i32, ptr, ptr } { i32 1, ptr @.omp_offloading.descriptor_unreg, ptr null }]
|
||||
|
|
|
@ -1172,8 +1172,7 @@ Expected<SmallVector<std::unique_ptr<MemoryBuffer>>>
|
|||
bundleOpenMP(ArrayRef<OffloadingImage> Images) {
|
||||
SmallVector<std::unique_ptr<MemoryBuffer>> Buffers;
|
||||
for (const OffloadingImage &Image : Images)
|
||||
Buffers.emplace_back(
|
||||
MemoryBuffer::getMemBufferCopy(Image.Image->getBuffer()));
|
||||
Buffers.emplace_back(OffloadBinary::write(Image));
|
||||
|
||||
return std::move(Buffers);
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#include "llvm/IR/IRBuilder.h"
|
||||
#include "llvm/IR/LLVMContext.h"
|
||||
#include "llvm/IR/Module.h"
|
||||
#include "llvm/Object/OffloadBinary.h"
|
||||
#include "llvm/Support/Error.h"
|
||||
#include "llvm/Transforms/Utils/ModuleUtils.h"
|
||||
|
||||
|
@ -184,6 +185,8 @@ GlobalVariable *createBinDesc(Module &M, ArrayRef<ArrayRef<char>> Bufs) {
|
|||
GlobalVariable::InternalLinkage, Data,
|
||||
".omp_offloading.device_image");
|
||||
Image->setUnnamedAddr(GlobalValue::UnnamedAddr::Global);
|
||||
Image->setSection(".llvm.offloading");
|
||||
Image->setAlignment(Align(object::OffloadBinary::getAlignment()));
|
||||
|
||||
auto *Size = ConstantInt::get(getSizeTTy(M), Buf.size());
|
||||
Constant *ZeroSize[] = {Zero, Size};
|
||||
|
|
Loading…
Reference in New Issue