From 551b1774524428aae5692ed3d41f969288ecd5a2 Mon Sep 17 00:00:00 2001 From: Joseph Huber Date: Fri, 3 Dec 2021 15:48:36 -0500 Subject: [PATCH] [OpenMP] Add a flag for embedding a file into the module This patch adds support for a flag `-fembed-offload-binary` to embed a file as an ELF section in the output by placing it in a global variable. This can be used to bundle offloading files with the host binary so it can be accessed by the linker. The section is named using the `-fembed-offload-section` option. Depends on D116541 Reviewed By: JonChesterfield Differential Revision: https://reviews.llvm.org/D116542 --- clang/include/clang/Basic/CodeGenOptions.h | 5 +++++ clang/include/clang/CodeGen/BackendUtil.h | 3 +++ clang/include/clang/Driver/Options.td | 4 ++++ clang/lib/CodeGen/BackendUtil.cpp | 28 ++++++++++++++++++++++++++++ clang/lib/CodeGen/CodeGenAction.cpp | 1 + clang/test/Frontend/embed-object.ll | 15 +++++++++++++++ llvm/include/llvm/Bitcode/BitcodeWriter.h | 5 +++++ llvm/lib/Bitcode/Writer/BitcodeWriter.cpp | 17 +++++++++++++++++ llvm/lib/Bitcode/Writer/CMakeLists.txt | 1 + 9 files changed, 79 insertions(+) create mode 100644 clang/test/Frontend/embed-object.ll diff --git a/clang/include/clang/Basic/CodeGenOptions.h b/clang/include/clang/Basic/CodeGenOptions.h index 5a5c268..128ca2f 100644 --- a/clang/include/clang/Basic/CodeGenOptions.h +++ b/clang/include/clang/Basic/CodeGenOptions.h @@ -276,6 +276,11 @@ public: /// CUDA runtime back-end for incorporating them into host-side object file. std::string CudaGpuBinaryFileName; + /// List of filenames and section name pairs passed in using the + /// -fembed-offload-object option to embed device-side offloading objects into + /// the host as a named section. Input passed in as ',
' + std::vector OffloadObjects; + /// The name of the file to which the backend should save YAML optimization /// records. std::string OptRecordFile; diff --git a/clang/include/clang/CodeGen/BackendUtil.h b/clang/include/clang/CodeGen/BackendUtil.h index 77d5000..d97af65 100644 --- a/clang/include/clang/CodeGen/BackendUtil.h +++ b/clang/include/clang/CodeGen/BackendUtil.h @@ -44,6 +44,9 @@ namespace clang { void EmbedBitcode(llvm::Module *M, const CodeGenOptions &CGOpts, llvm::MemoryBufferRef Buf); + + void EmbedObject(llvm::Module *M, const CodeGenOptions &CGOpts, + DiagnosticsEngine &Diags); } #endif diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 9e8fdd2..53e68ed 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -1151,6 +1151,10 @@ defm coroutines_ts : BoolFOption<"coroutines-ts", PosFlag, NegFlag>; +def fembed_offload_object_EQ : Joined<["-"], "fembed-offload-object=">, + Group, Flags<[NoXarchOption, CC1Option]>, + HelpText<"Embed Offloading device-side binary into host object file as a section.">, + MarshallingInfoStringVector>; def fembed_bitcode_EQ : Joined<["-"], "fembed-bitcode=">, Group, Flags<[NoXarchOption, CC1Option, CC1AsOption]>, MetaVarName<"