Skip to content

[offload][SYCL] Add Module splitting by categories. #131347

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions llvm/include/llvm/Transforms/Utils/SYCLSplitModule.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
//===-------- SYCLSplitModule.h - module split ------------------*- C++ -*-===//
//
// 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
//
//===----------------------------------------------------------------------===//
// Functionality to split a module into callgraphs. A callgraph here is a set
// of entry points with all functions reachable from them via a call. The result
// of the split is new modules containing corresponding callgraph.
//===----------------------------------------------------------------------===//

#ifndef LLVM_TRANSFORMS_UTILS_SYCLSPLITMODULE_H
#define LLVM_TRANSFORMS_UTILS_SYCLSPLITMODULE_H

#include "llvm/ADT/STLFunctionalExtras.h"
#include "llvm/ADT/StringRef.h"

#include <memory>
#include <optional>
#include <string>

namespace llvm {

class Module;

enum class IRSplitMode {
IRSM_PER_TU, // one module per translation unit
IRSM_PER_KERNEL, // one module per kernel
IRSM_NONE // no splitting
};

/// \returns IRSplitMode value if \p S is recognized. Otherwise, std::nullopt is
/// returned.
std::optional<IRSplitMode> convertStringToSplitMode(StringRef S);

/// The structure represents a split LLVM Module accompanied by additional
/// information. Split Modules are being stored at disk due to the high RAM
/// consumption during the whole splitting process.
struct ModuleAndSYCLMetadata {
std::string ModuleFilePath;
std::string Symbols;

ModuleAndSYCLMetadata() = default;
ModuleAndSYCLMetadata(const ModuleAndSYCLMetadata &) = default;
ModuleAndSYCLMetadata &operator=(const ModuleAndSYCLMetadata &) = default;
ModuleAndSYCLMetadata(ModuleAndSYCLMetadata &&) = default;
ModuleAndSYCLMetadata &operator=(ModuleAndSYCLMetadata &&) = default;

ModuleAndSYCLMetadata(std::string_view File, std::string Symbols)
: ModuleFilePath(File), Symbols(std::move(Symbols)) {}
};

using PostSYCLSplitCallbackType =
function_ref<void(std::unique_ptr<Module> Part, std::string Symbols)>;

/// Splits the given module \p M according to the given \p Settings.
/// Every split image is being passed to \p Callback.
void SYCLSplitModule(std::unique_ptr<Module> M, IRSplitMode Mode,
PostSYCLSplitCallbackType Callback);

} // namespace llvm

#endif // LLVM_TRANSFORMS_UTILS_SYCLSPLITMODULE_H
26 changes: 26 additions & 0 deletions llvm/include/llvm/Transforms/Utils/SYCLUtils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//===------------ SYCLUtils.h - SYCL utility functions --------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
// Utility functions for SYCL.
//===----------------------------------------------------------------------===//
#ifndef LLVM_TRANSFORMS_UTILS_SYCLUTILS_H
#define LLVM_TRANSFORMS_UTILS_SYCLUTILS_H

#include <llvm/ADT/SmallString.h>
#include <llvm/ADT/SmallVector.h>

namespace llvm {

class raw_ostream;

using SYCLStringTable = SmallVector<SmallVector<SmallString<64>>>;

void writeSYCLStringTable(const SYCLStringTable &Table, raw_ostream &OS);

} // namespace llvm

#endif // LLVM_TRANSFORMS_UTILS_SYCLUTILS_H
2 changes: 2 additions & 0 deletions llvm/lib/Transforms/Utils/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ add_llvm_component_library(LLVMTransformUtils
SizeOpts.cpp
SplitModule.cpp
StripNonLineTableDebugInfo.cpp
SYCLSplitModule.cpp
SYCLUtils.cpp
SymbolRewriter.cpp
UnifyFunctionExitNodes.cpp
UnifyLoopExits.cpp
Expand Down
Loading