[llvm] [offload][SYCL] Add Module splitting by categories. (PR #131347)
Maksim Sabianin via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 25 05:46:44 PDT 2025
================
@@ -0,0 +1,44 @@
+//===-------- SplitModuleByCategory.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 by categories.
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_TRANSFORM_UTILS_SPLIT_MODULE_BY_CATEGORY_H
+#define LLVM_TRANSFORM_UTILS_SPLIT_MODULE_BY_CATEGORY_H
+
+#include "llvm/ADT/STLFunctionalExtras.h"
+
+#include <memory>
+#include <optional>
+#include <string>
+
+namespace llvm {
+
+class Module;
+class Function;
+
+/// Splits the given module \p M using the given \p FunctionCategorizer.
+/// \p FunctionCategorizer returns integer category for an input Function.
+/// It may return std::nullopt if a function doesn't have a category.
+/// Module's functions are being grouped by categories. Every such group
+/// populates a call graph containing group's functions themselves and all
+/// reachable functions and globals. Split outputs are populated from each call
+/// graph associated with some category.
----------------
maksimsab wrote:
> I am unsure why this uses an optional, and what that means.
In SYCL case `FunctionCategorizer` allows to define entry points and group them together by assigning group identifiers (categories). For non-entry functions we need a way to not choose them in a selection step of the algorithm. I chose `std::nullopt` as an indicator that the corresponding function shouldn't be added in any entry group. The function still can be copied in case if this is transitively used by some entry points.
We could replace `std::optional<int>` with a simple `int` and use value `-1` for not choosing functions in entry groups.
https://github.com/llvm/llvm-project/pull/131347
More information about the llvm-commits
mailing list