Skip to content

Commit bfeea10

Browse files
authored
[offload][SYCL] Add SYCL Module splitting (#119713)
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.
1 parent fcce308 commit bfeea10

File tree

12 files changed

+1124
-0
lines changed

12 files changed

+1124
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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/SmallVector.h"
17+
#include "llvm/ADT/StringRef.h"
18+
#include "llvm/Support/Error.h"
19+
20+
#include <memory>
21+
#include <optional>
22+
#include <string>
23+
24+
namespace llvm {
25+
26+
class Module;
27+
28+
enum class IRSplitMode {
29+
IRSM_PER_TU, // one module per translation unit
30+
IRSM_PER_KERNEL, // one module per kernel
31+
IRSM_NONE // no splitting
32+
};
33+
34+
/// \returns IRSplitMode value if \p S is recognized. Otherwise, std::nullopt is
35+
/// returned.
36+
std::optional<IRSplitMode> convertStringToSplitMode(StringRef S);
37+
38+
/// The structure represents a split LLVM Module accompanied by additional
39+
/// information. Split Modules are being stored at disk due to the high RAM
40+
/// consumption during the whole splitting process.
41+
struct ModuleAndSYCLMetadata {
42+
std::string ModuleFilePath;
43+
std::string Symbols;
44+
45+
ModuleAndSYCLMetadata() = default;
46+
ModuleAndSYCLMetadata(const ModuleAndSYCLMetadata &) = default;
47+
ModuleAndSYCLMetadata &operator=(const ModuleAndSYCLMetadata &) = default;
48+
ModuleAndSYCLMetadata(ModuleAndSYCLMetadata &&) = default;
49+
ModuleAndSYCLMetadata &operator=(ModuleAndSYCLMetadata &&) = default;
50+
51+
ModuleAndSYCLMetadata(std::string_view File, std::string Symbols)
52+
: ModuleFilePath(File), Symbols(std::move(Symbols)) {}
53+
};
54+
55+
struct ModuleSplitterSettings {
56+
IRSplitMode Mode;
57+
bool OutputAssembly = false; // Bitcode or LLVM IR.
58+
StringRef OutputPrefix;
59+
};
60+
61+
/// Parses the string table.
62+
Expected<SmallVector<ModuleAndSYCLMetadata, 0>>
63+
parseModuleAndSYCLMetadataFromFile(StringRef File);
64+
65+
/// Splits the given module \p M according to the given \p Settings.
66+
Expected<SmallVector<ModuleAndSYCLMetadata, 0>>
67+
SYCLSplitModule(std::unique_ptr<Module> M, ModuleSplitterSettings Settings);
68+
69+
} // namespace llvm
70+
71+
#endif // LLVM_TRANSFORMS_UTILS_SYCLSPLITMODULE_H
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

+2
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)