|
| 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 |
0 commit comments