Skip to content

Commit bf48915

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: by kernel and by source.
1 parent e909c0c commit bf48915

File tree

15 files changed

+1487
-0
lines changed

15 files changed

+1487
-0
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
//===-------- SYCLModuleSplit.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_SYCL_MODULE_SPLIT_H
14+
#define LLVM_SYCL_MODULE_SPLIT_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 SYCLSplitModule {
42+
std::string ModuleFilePath;
43+
std::string Symbols;
44+
45+
SYCLSplitModule() = default;
46+
SYCLSplitModule(const SYCLSplitModule &) = default;
47+
SYCLSplitModule &operator=(const SYCLSplitModule &) = default;
48+
SYCLSplitModule(SYCLSplitModule &&) = default;
49+
SYCLSplitModule &operator=(SYCLSplitModule &&) = default;
50+
51+
SYCLSplitModule(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<SYCLSplitModule, 0>>
63+
parseSYCLSplitModulesFromFile(StringRef File);
64+
65+
/// Splits the given module \p M according to the given \p Settings.
66+
Expected<SmallVector<SYCLSplitModule, 0>>
67+
splitSYCLModule(std::unique_ptr<Module> M, ModuleSplitterSettings Settings);
68+
69+
} // namespace llvm
70+
71+
#endif // LLVM_SYCL_MODULE_SPLIT_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 <string>
14+
#include <vector>
15+
16+
namespace llvm {
17+
18+
class raw_ostream;
19+
20+
using SYCLStringTable = std::vector<std::vector<std::string>>;
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
@@ -82,6 +82,8 @@ add_llvm_component_library(LLVMTransformUtils
8282
SizeOpts.cpp
8383
SplitModule.cpp
8484
StripNonLineTableDebugInfo.cpp
85+
SYCLModuleSplit.cpp
86+
SYCLUtils.cpp
8587
SymbolRewriter.cpp
8688
UnifyFunctionExitNodes.cpp
8789
UnifyLoopExits.cpp

0 commit comments

Comments
 (0)