Skip to content

Commit

Permalink
[SYCL][LinkerWrapper][NFC] Align code structure to community (#12499)
Browse files Browse the repository at this point in the history
This patch moves 'clang/tools/clang-linker-wrapper/SYCLOffloadWrapper.*'
functionality to 'llvm/Frontend/Offloading' to be aligned with the
community code structure.
  • Loading branch information
maksimsab authored Mar 1, 2024
1 parent 8e987fe commit 9e155c9
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 12 deletions.
1 change: 0 additions & 1 deletion clang/tools/clang-linker-wrapper/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ endif()

add_clang_tool(clang-linker-wrapper
ClangLinkerWrapper.cpp
SYCLOffloadWrapper.cpp

DEPENDS
${tablegen_deps}
Expand Down
16 changes: 8 additions & 8 deletions clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
//
//===---------------------------------------------------------------------===//

#include "SYCLOffloadWrapper.h"
#include "clang/Basic/Version.h"
#include "llvm/BinaryFormat/Magic.h"
#include "llvm/Bitcode/BitcodeWriter.h"
#include "llvm/CodeGen/CommandFlags.h"
#include "llvm/Frontend/Offloading/OffloadWrapper.h"
#include "llvm/Frontend/Offloading/SYCLOffloadWrapper.h"
#include "llvm/Frontend/Offloading/Utility.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DiagnosticPrinter.h"
Expand Down Expand Up @@ -741,8 +741,8 @@ readPropertyRegistryFromFile(StringRef File) {
// a_n.bin|a_n.prop|a_n.sym
//
// .bin extension might be a bc, spv or other native extension.
Expected<SmallVector<SYCLImage>> readSYCLImagesFromTable(StringRef TableFile,
const ArgList &Args) {
Expected<SmallVector<offloading::SYCLImage>>
readSYCLImagesFromTable(StringRef TableFile, const ArgList &Args) {
auto TableOrErr = util::SimpleTable::read(TableFile);
if (!TableOrErr)
return TableOrErr.takeError();
Expand All @@ -756,7 +756,7 @@ Expected<SmallVector<SYCLImage>> readSYCLImagesFromTable(StringRef TableFile,
inconvertibleErrorCode(),
"expected columns in the table: Code, Properties and Symbols");

SmallVector<SYCLImage> Images;
SmallVector<offloading::SYCLImage> Images;
for (const util::SimpleTable::Row &row : Table->rows()) {
auto ImageOrErr = readBinaryFile(row.getCell("Code"));
if (!ImageOrErr)
Expand All @@ -771,7 +771,7 @@ Expected<SmallVector<SYCLImage>> readSYCLImagesFromTable(StringRef TableFile,
if (!SymbolsOrErr)
return SymbolsOrErr.takeError();

SYCLImage Image;
offloading::SYCLImage Image;
Image.Image = std::move(*ImageOrErr);
Image.PropertyRegistry = std::move(**PropertiesOrErr);
Image.Entries = std::move(*SymbolsOrErr);
Expand Down Expand Up @@ -811,7 +811,7 @@ Expected<StringRef> wrapSYCLBinariesFromFile(StringRef InputFile,
inconvertibleErrorCode(),
"can't wrap SYCL image. -triple argument is missed.");

for (SYCLImage &Image : Images)
for (offloading::SYCLImage &Image : Images)
Image.Target = Target;

LLVMContext C;
Expand All @@ -822,10 +822,10 @@ Expected<StringRef> wrapSYCLBinariesFromFile(StringRef InputFile,
StringRef CompileOptions =
Args.getLastArgValue(OPT_sycl_backend_compile_options_EQ);
StringRef LinkOptions = Args.getLastArgValue(OPT_sycl_target_link_options_EQ);
SYCLWrappingOptions WrappingOptions;
offloading::SYCLWrappingOptions WrappingOptions;
WrappingOptions.CompileOptions = CompileOptions;
WrappingOptions.LinkOptions = LinkOptions;
if (Error E = wrapSYCLBinaries(M, Images, WrappingOptions))
if (Error E = offloading::wrapSYCLBinaries(M, Images, WrappingOptions))
return E;

if (Args.hasArg(OPT_print_wrapped_module))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
#include <utility>
#include <vector>

namespace llvm {
namespace offloading {

// SYCL binary image formats supported.
enum class SYCLBinaryImageFormat {
BIF_None, // Undetermined Image kind
Expand Down Expand Up @@ -50,8 +53,14 @@ struct SYCLWrappingOptions {
std::string LinkOptions;
};

/// Wraps the input bundled images and accompanied data into the module \p M
/// as global symbols and registers the images with the SYCL Runtime.
/// \param Options Settings that allows to turn on optional data and settings.
llvm::Error
wrapSYCLBinaries(llvm::Module &M, llvm::SmallVector<SYCLImage> &Images,
SYCLWrappingOptions Options = SYCLWrappingOptions());

} // namespace offloading
} // namespace llvm

#endif
2 changes: 2 additions & 0 deletions llvm/lib/Frontend/Offloading/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
add_llvm_component_library(LLVMFrontendOffloading
Utility.cpp
OffloadWrapper.cpp
SYCLOffloadWrapper.cpp


ADDITIONAL_HEADER_DIRS
${LLVM_MAIN_INCLUDE_DIR}/llvm/Frontend
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// sycl/include/sycl/detail/pi.h
//===----------------------------------------------------------------------===//

#include "SYCLOffloadWrapper.h"
#include "llvm/Frontend/Offloading/SYCLOffloadWrapper.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
Expand All @@ -40,6 +40,7 @@
#include <utility>

using namespace llvm;
using namespace llvm::offloading;
using namespace llvm::util;

namespace {
Expand Down Expand Up @@ -727,8 +728,9 @@ struct Wrapper {

} // anonymous namespace

Error wrapSYCLBinaries(llvm::Module &M, SmallVector<SYCLImage> &Images,
SYCLWrappingOptions Options) {
Error llvm::offloading::wrapSYCLBinaries(llvm::Module &M,
SmallVector<SYCLImage> &Images,
SYCLWrappingOptions Options) {
Wrapper W(M, Options);
GlobalVariable *Desc = W.createFatbinDesc(Images);
if (!Desc)
Expand Down

0 comments on commit 9e155c9

Please sign in to comment.