Skip to content

Commit ede5e8c

Browse files
committed
[offload][SYCL] Add SYCL Module splitting.
This patch adds SYCL Module splitting - the necessary step in the SYCL compilation pipeline. Only 2 splitting modes are being added in this patch: by kernel and by source. The previous attempt was at llvm#119713. In this patch there is no dependency in `TransformUtils` on "IPO" and on "Printing Passes". In this patch a module splitting is self-contained and it doesn't introduce linking issues.
1 parent 19b25a4 commit ede5e8c

File tree

13 files changed

+1047
-0
lines changed

13 files changed

+1047
-0
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
//===-------- SYCLSplitModule.h - module split ------------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
// Functionality to split a module into callgraphs. A callgraph here is a set
9+
// of entry points with all functions reachable from them via a call. The result
10+
// of the split is new modules containing corresponding callgraph.
11+
//===----------------------------------------------------------------------===//
12+
13+
#ifndef LLVM_TRANSFORMS_UTILS_SYCLSPLITMODULE_H
14+
#define LLVM_TRANSFORMS_UTILS_SYCLSPLITMODULE_H
15+
16+
#include "llvm/ADT/STLFunctionalExtras.h"
17+
#include "llvm/ADT/StringRef.h"
18+
19+
#include <memory>
20+
#include <optional>
21+
#include <string>
22+
23+
namespace llvm {
24+
25+
class Module;
26+
27+
enum class IRSplitMode {
28+
IRSM_PER_TU, // one module per translation unit
29+
IRSM_PER_KERNEL, // one module per kernel
30+
IRSM_NONE // no splitting
31+
};
32+
33+
/// \returns IRSplitMode value if \p S is recognized. Otherwise, std::nullopt is
34+
/// returned.
35+
std::optional<IRSplitMode> convertStringToSplitMode(StringRef S);
36+
37+
/// The structure represents a split LLVM Module accompanied by additional
38+
/// information. Split Modules are being stored at disk due to the high RAM
39+
/// consumption during the whole splitting process.
40+
struct ModuleAndSYCLMetadata {
41+
std::string ModuleFilePath;
42+
std::string Symbols;
43+
44+
ModuleAndSYCLMetadata() = default;
45+
ModuleAndSYCLMetadata(const ModuleAndSYCLMetadata &) = default;
46+
ModuleAndSYCLMetadata &operator=(const ModuleAndSYCLMetadata &) = default;
47+
ModuleAndSYCLMetadata(ModuleAndSYCLMetadata &&) = default;
48+
ModuleAndSYCLMetadata &operator=(ModuleAndSYCLMetadata &&) = default;
49+
50+
ModuleAndSYCLMetadata(std::string_view File, std::string Symbols)
51+
: ModuleFilePath(File), Symbols(std::move(Symbols)) {}
52+
};
53+
54+
using PostSYCLSplitCallbackType =
55+
function_ref<void(std::unique_ptr<Module> Part, std::string Symbols)>;
56+
57+
/// Splits the given module \p M according to the given \p Settings.
58+
/// Every split image is being passed to \p Callback.
59+
void SYCLSplitModule(std::unique_ptr<Module> M, IRSplitMode Mode,
60+
PostSYCLSplitCallbackType Callback);
61+
62+
} // namespace llvm
63+
64+
#endif // LLVM_TRANSFORMS_UTILS_SYCLSPLITMODULE_H
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//===------------ SYCLUtils.h - SYCL utility functions --------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
// Utility functions for SYCL.
9+
//===----------------------------------------------------------------------===//
10+
#ifndef LLVM_TRANSFORMS_UTILS_SYCLUTILS_H
11+
#define LLVM_TRANSFORMS_UTILS_SYCLUTILS_H
12+
13+
#include <llvm/ADT/SmallString.h>
14+
#include <llvm/ADT/SmallVector.h>
15+
16+
namespace llvm {
17+
18+
class raw_ostream;
19+
20+
using SYCLStringTable = SmallVector<SmallVector<SmallString<64>>>;
21+
22+
void writeSYCLStringTable(const SYCLStringTable &Table, raw_ostream &OS);
23+
24+
} // namespace llvm
25+
26+
#endif // LLVM_TRANSFORMS_UTILS_SYCLUTILS_H

llvm/lib/Transforms/Utils/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ add_llvm_component_library(LLVMTransformUtils
8383
SizeOpts.cpp
8484
SplitModule.cpp
8585
StripNonLineTableDebugInfo.cpp
86+
SYCLSplitModule.cpp
87+
SYCLUtils.cpp
8688
SymbolRewriter.cpp
8789
UnifyFunctionExitNodes.cpp
8890
UnifyLoopExits.cpp

0 commit comments

Comments
 (0)