Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
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
71 changes: 71 additions & 0 deletions llvm/include/llvm/Transforms/Utils/SYCLSplitModule.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
//===-------- 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_SYCL_SPLIT_MODULE_H
#define LLVM_SYCL_SPLIT_MODULE_H

#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/Error.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)) {}
};

struct ModuleSplitterSettings {
IRSplitMode Mode;
bool OutputAssembly = false; // Bitcode or LLVM IR.
StringRef OutputPrefix;
};

/// Parses the string table.
Expected<SmallVector<ModuleAndSYCLMetadata, 0>>
parseModuleAndSYCLMetadataFromFile(StringRef File);

/// Splits the given module \p M according to the given \p Settings.
Expected<SmallVector<ModuleAndSYCLMetadata, 0>>
SYCLSplitModule(std::unique_ptr<Module> M, ModuleSplitterSettings Settings);

} // namespace llvm

#endif // LLVM_SYCL_SPLIT_MODULE_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 <string>
#include <vector>

namespace llvm {

class raw_ostream;

using SYCLStringTable = std::vector<std::vector<std::string>>;

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