[Mlir-commits] [mlir] [MLIR][LLVM] Remove support for synthetic profile entry counts (PR #233357)
Aiden Grossman
llvmlistbot at llvm.org
Mon Oct 19 00:28:34 PDT 2026
https://github.com/boomanaiden154 created https://github.com/llvm/llvm-project/pull/233357
These are going to be fully removed from LLVM soon (they have been partially removed for a while). Remove them from MLIR to unblock further cleanup in LLVM.
>From 21147aa82c9d4a0e2f9b74c3e03c3e375f22b8f1 Mon Sep 17 00:00:00 2001
From: Aiden Grossman <aidengrossman at google.com>
Date: Mon, 19 Oct 2026 07:27:21 +0000
Subject: [PATCH] [MLIR][LLVM] Remove support for synthetic profile entry
counts
These are going to be fully removed from LLVM soon (they have been partially
removed for a while). Remove them from MLIR to unblock further cleanup in
LLVM.
---
.../mlir/Dialect/LLVMIR/LLVMAttrDefs.td | 9 ++-----
mlir/include/mlir/Dialect/LLVMIR/LLVMEnums.td | 15 ------------
mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td | 5 ++--
mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp | 2 +-
.../LLVMIR/LLVMIRToLLVMTranslation.cpp | 13 +++-------
mlir/lib/Target/LLVMIR/ModuleTranslation.cpp | 9 ++-----
.../LLVMIR/Import/function-attributes.ll | 24 ++-----------------
mlir/test/Target/LLVMIR/llvmir.mlir | 24 -------------------
8 files changed, 12 insertions(+), 89 deletions(-)
diff --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMAttrDefs.td b/mlir/include/mlir/Dialect/LLVMIR/LLVMAttrDefs.td
index b875003a2c75c..29effed1b9ddf 100644
--- a/mlir/include/mlir/Dialect/LLVMIR/LLVMAttrDefs.td
+++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMAttrDefs.td
@@ -105,15 +105,10 @@ def LLVM_FunctionEntryCountAttr
let summary = "LLVM function entry count profile metadata";
let description = [{
Models function-level `!prof` entry-count metadata. The `entry_count` field
- stores the unsigned 64-bit counter bit pattern. The `count_type` field
- defaults to real and selects whether the metadata is emitted as
- `"function_entry_count"` or `"synthetic_function_entry_count"`. The optional
- `imports` field stores the trailing import GUID operands used by ThinLTO
- sample PGO.
+ stores the unsigned 64-bit counter bit pattern. The optional `imports` field
+ stores the trailing import GUID operands used by ThinLTO sample PGO.
}];
let parameters = (ins "uint64_t":$entry_count,
- DefaultValuedParameter<"ProfileCountType",
- "ProfileCountType::Real">:$count_type,
OptionalArrayRefParameter<"uint64_t">:$imports);
let assemblyFormat = "`<` struct(params) `>`";
}
diff --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMEnums.td b/mlir/include/mlir/Dialect/LLVMIR/LLVMEnums.td
index 803dbdaabfd91..8867e3ba84bb2 100644
--- a/mlir/include/mlir/Dialect/LLVMIR/LLVMEnums.td
+++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMEnums.td
@@ -83,21 +83,6 @@ def AsmATTOrIntel : LLVM_EnumAttr<
let cppNamespace = "::mlir::LLVM";
}
-//===----------------------------------------------------------------------===//
-// ProfileCountType
-//===----------------------------------------------------------------------===//
-
-def ProfileCountReal : I64EnumAttrCase<
- /*string sym=*/"Real", /*int val=*/0, /*string str=*/"real">;
-def ProfileCountSynthetic : I64EnumAttrCase<
- /*string sym=*/"Synthetic", /*int val=*/1, /*string str=*/"synthetic">;
-def ProfileCountTypeAttr : I64EnumAttr<
- /*string name=*/"ProfileCountType",
- /*string description=*/"real or synthetic function entry count",
- /*list<I64EnumAttrCase> cases=*/[ProfileCountReal, ProfileCountSynthetic]> {
- let cppNamespace = "::mlir::LLVM";
-}
-
//===----------------------------------------------------------------------===//
// Atomic Operations
//===----------------------------------------------------------------------===//
diff --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td b/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
index 9f658bc7a4b81..9ff3b2d75e3f6 100644
--- a/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
+++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
@@ -2121,9 +2121,8 @@ def LLVM_LLVMFuncOp : LLVM_Op<"func", [
```
The `function_entry_count` attribute models function-level `!prof`
- entry-count metadata. It stores the entry count, whether the count is real
- or synthetic, and any trailing import GUID operands in a single
- `#llvm.function_entry_count` attribute.
+ entry-count metadata. It stores the entry count and any trailing import
+ GUID operands in a single `#llvm.function_entry_count` attribute.
}];
let arguments = (ins
diff --git a/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp b/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
index 1b0cc7bdb8799..11653a288bc60 100644
--- a/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
+++ b/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
@@ -3183,7 +3183,7 @@ void LLVMFuncOp::build(OpBuilder &builder, OperationState &result,
result.addAttribute(getFunctionEntryCountAttrName(result.name),
FunctionEntryCountAttr::get(
builder.getContext(), *functionEntryCount,
- ProfileCountType::Real, ArrayRef<uint64_t>{}));
+ ArrayRef<uint64_t>{}));
#ifndef NDEBUG
std::optional<NamedAttribute> duplicate = result.attributes.findDuplicate();
if (duplicate.has_value()) {
diff --git a/mlir/lib/Target/LLVMIR/Dialect/LLVMIR/LLVMIRToLLVMTranslation.cpp b/mlir/lib/Target/LLVMIR/Dialect/LLVMIR/LLVMIRToLLVMTranslation.cpp
index de038c68596cb..f0b31a1c661b4 100644
--- a/mlir/lib/Target/LLVMIR/Dialect/LLVMIR/LLVMIRToLLVMTranslation.cpp
+++ b/mlir/lib/Target/LLVMIR/Dialect/LLVMIR/LLVMIRToLLVMTranslation.cpp
@@ -126,16 +126,10 @@ static LogicalResult setProfilingAttr(OpBuilder &builder, llvm::MDNode *node,
StringRef profName = name->getString();
// Handle function entry count metadata.
- if (profName == llvm::MDProfLabels::FunctionEntryCount ||
- profName == llvm::MDProfLabels::SyntheticFunctionEntryCount) {
+ if (profName == llvm::MDProfLabels::FunctionEntryCount) {
if (node->getNumOperands() < 2)
return failure();
- bool isSynthetic =
- profName == llvm::MDProfLabels::SyntheticFunctionEntryCount;
- ProfileCountType profileCountType =
- isSynthetic ? ProfileCountType::Synthetic : ProfileCountType::Real;
-
std::optional<uint64_t> entryCountValue =
getUInt64Metadata(node->getOperand(1));
if (!entryCountValue)
@@ -152,9 +146,8 @@ static LogicalResult setProfilingAttr(OpBuilder &builder, llvm::MDNode *node,
}
if (auto funcOp = dyn_cast<LLVMFuncOp>(op)) {
- funcOp.setFunctionEntryCountAttr(
- FunctionEntryCountAttr::get(builder.getContext(), *entryCountValue,
- profileCountType, importGUIDValues));
+ funcOp.setFunctionEntryCountAttr(FunctionEntryCountAttr::get(
+ builder.getContext(), *entryCountValue, importGUIDValues));
return success();
}
return op->emitWarning()
diff --git a/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp b/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
index 07b9d683d309d..c0019a278b4a6 100644
--- a/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
+++ b/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
@@ -2140,13 +2140,8 @@ LogicalResult ModuleTranslation::convertFunctionSignatures() {
llvm::DenseSet<llvm::GlobalValue::GUID> importGUIDs;
if (!imports.empty())
importGUIDs.insert(imports.begin(), imports.end());
- llvm::MDBuilder metadataBuilder(llvmFunc->getContext());
- llvmFunc->setMetadata(
- llvm::LLVMContext::MD_prof,
- metadataBuilder.createFunctionEntryCount(
- entryCount.getEntryCount(),
- entryCount.getCountType() == ProfileCountType::Synthetic,
- imports.empty() ? nullptr : &importGUIDs));
+ llvmFunc->setEntryCount(entryCount.getEntryCount(),
+ imports.empty() ? nullptr : &importGUIDs);
}
// Convert result attributes.
diff --git a/mlir/test/Target/LLVMIR/Import/function-attributes.ll b/mlir/test/Target/LLVMIR/Import/function-attributes.ll
index efcb7e4a6526e..86eaf58701b42 100644
--- a/mlir/test/Target/LLVMIR/Import/function-attributes.ll
+++ b/mlir/test/Target/LLVMIR/Import/function-attributes.ll
@@ -188,33 +188,13 @@ define void @entry_count() !prof !1 {
; // -----
-; CHECK-LABEL: @synthetic_entry_count
-; CHECK-SAME: attributes {function_entry_count = #llvm.function_entry_count<entry_count = 7, count_type = synthetic>}
-define void @synthetic_entry_count() !prof !2 {
- ret void
-}
-
-!2 = !{!"synthetic_function_entry_count", i64 7}
-
-; // -----
-
; CHECK-LABEL: @entry_count_imports
; CHECK-SAME: attributes {function_entry_count = #llvm.function_entry_count<entry_count = 7, imports = 1234, 18446744073709551615, 4, 1234>}
-define void @entry_count_imports() !prof !3 {
- ret void
-}
-
-!3 = !{!"function_entry_count", i64 7, i64 1234, i64 -1, i64 4, i64 1234}
-
-; // -----
-
-; CHECK-LABEL: @synthetic_entry_count_imports
-; CHECK-SAME: attributes {function_entry_count = #llvm.function_entry_count<entry_count = 7, count_type = synthetic, imports = 1234>}
-define void @synthetic_entry_count_imports() !prof !4 {
+define void @entry_count_imports() !prof !2 {
ret void
}
-!4 = !{!"synthetic_function_entry_count", i64 7, i64 1234}
+!2 = !{!"function_entry_count", i64 7, i64 1234, i64 -1, i64 4, i64 1234}
; // -----
diff --git a/mlir/test/Target/LLVMIR/llvmir.mlir b/mlir/test/Target/LLVMIR/llvmir.mlir
index 7d0fc4c520708..de23b9041d1c9 100644
--- a/mlir/test/Target/LLVMIR/llvmir.mlir
+++ b/mlir/test/Target/LLVMIR/llvmir.mlir
@@ -1958,30 +1958,6 @@ llvm.func @functionEntryCount() attributes {
// -----
-// CHECK-LABEL: @syntheticFunctionEntryCount
-// CHECK-SAME: !prof ![[SYNTH_PROF_ID:[0-9]+]]
-llvm.func @syntheticFunctionEntryCount() attributes {
- function_entry_count = #llvm.function_entry_count<entry_count = 7, count_type = synthetic>
-} {
- llvm.return
-}
-
-// CHECK-DAG: ![[SYNTH_PROF_ID]] = !{!"synthetic_function_entry_count", i64 7}
-
-// -----
-
-// CHECK-LABEL: @syntheticFunctionEntryCountWithImports
-// CHECK-SAME: !prof ![[SYNTH_IMPORTS_PROF_ID:[0-9]+]]
-llvm.func @syntheticFunctionEntryCountWithImports() attributes {
- function_entry_count = #llvm.function_entry_count<entry_count = 7, count_type = synthetic, imports = 1234, 4, 1234>
-} {
- llvm.return
-}
-
-// CHECK-DAG: ![[SYNTH_IMPORTS_PROF_ID]] = !{!"synthetic_function_entry_count", i64 7, i64 4, i64 1234}
-
-// -----
-
// CHECK-LABEL: @functionEntryCountWithImports
// CHECK-SAME: !prof ![[IMPORTS_PROF_ID:[0-9]+]]
llvm.func @functionEntryCountWithImports() attributes {
More information about the Mlir-commits
mailing list