LLVM 22.0.0git
SplitModuleByCategory.h
Go to the documentation of this file.
1//===-------- SplitModuleByCategory.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 by categories.
9//===----------------------------------------------------------------------===//
10
11#ifndef LLVM_TRANSFORM_UTILS_SPLIT_MODULE_BY_CATEGORY_H
12#define LLVM_TRANSFORM_UTILS_SPLIT_MODULE_BY_CATEGORY_H
13
16
17#include <memory>
18#include <optional>
19#include <string>
20
21namespace llvm {
22
23class Module;
24class Function;
25
26/// Splits the given module \p M into parts. Each output part is passed to
27/// \p Callback for further possible processing. Each part corresponds to a
28/// subset of the module that is transitively reachable from some entry point
29/// group. Each entry point group is defined by \p EntryPointCategorizer (EPC)
30/// as follows: 1) If the function is not an entry point, then the Categorizer
31/// returns std::nullopt. Therefore, the function doesn't belong to any group.
32/// However, the function and global objects can still be associated with some
33/// output parts if they are transitively used from some entry points. 2) If the
34/// function belongs to an entry point group, then EPC returns an integer which
35/// is an identifier of the group. If two entry points belong to one group, then
36/// EPC returns the same identifier for both of them.
37///
38/// Let A and B be global objects in the module. The transitive dependency
39/// relation is defined such that: If global object A is used by global object B
40/// in any way (e.g., store, bitcast, phi node, call), then "A" -> "B".
41/// Transitivity is defined such that: If "A" -> "B" and "B" -> "C", then "A" ->
42/// "C". Examples of dependencies:
43/// - Function FA calls function FB
44/// - Function FA uses global variable GA
45/// - Global variable GA references (is initialized with) function FB
46/// - Function FA stores the address of function FB somewhere
47///
48/// The following cases are treated as dependencies between global objects:
49/// 1. Global object A is used by global object B in any way (store,
50/// bitcast, phi node, call, etc.): an "A" -> "B" edge will be added to the
51/// graph;
52/// 2. Function A performs an indirect call of a function with signature S, and
53/// there is a function B with signature S. An "A" -> "B" edge will be added
54/// to the graph;
55///
56/// FIXME: For now, the algorithm assumes no recursion in the input Module. This
57/// will be addressed in the near future.
59 std::unique_ptr<Module> M,
60 function_ref<std::optional<int>(const Function &F)> EntryPointCategorizer,
61 function_ref<void(std::unique_ptr<Module> Part)> Callback);
62
63} // namespace llvm
64
65#endif // LLVM_TRANSFORM_UTILS_SPLIT_MODULE_BY_CATEGORY_H
#define LLVM_ABI
Definition Compiler.h:213
#define F(x, y, z)
Definition MD5.cpp:55
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:67
An efficient, type-erasing, non-owning reference to a callable.
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI void splitModuleTransitiveFromEntryPoints(std::unique_ptr< Module > M, function_ref< std::optional< int >(const Function &F)> EntryPointCategorizer, function_ref< void(std::unique_ptr< Module > Part)> Callback)
Splits the given module M into parts.