[llvm] [LowerTypeTests] Add -reorder-cfi-jump-tables-profiles kill switch (PR #224752)
Vitaly Buka via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 18 14:49:58 PDT 2026
https://github.com/vitalybuka created https://github.com/llvm/llvm-project/pull/224752
Add `-reorder-cfi-jump-tables-profiles` (default: true) to allow
disabling CFI jump table hotness metadata generation and profiling
queries introduced in 50c563998bac.
When set to false, `createCfiFunctionsMetadata` avoids querying
`ProfileSummaryInfo` and `BlockFrequencyInfo`, leaving hotness bits in
`cfi.functions` metadata as 0 (unknown).
Assisted-by: Gemini
>From 45cedaf1e6d92d1f4ef9b3310fc3af4477b46ff1 Mon Sep 17 00:00:00 2001
From: Vitaly Buka <vitalybuka at google.com>
Date: Fri, 18 Sep 2026 14:49:39 -0700
Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20initia?=
=?UTF-8?q?l=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Created using spr 1.3.7
---
llvm/lib/Transforms/IPO/LowerTypeTests.cpp | 12 ++++++++--
.../cfi-functions-hotness.ll | 24 ++++++++++++++++++-
2 files changed, 33 insertions(+), 3 deletions(-)
diff --git a/llvm/lib/Transforms/IPO/LowerTypeTests.cpp b/llvm/lib/Transforms/IPO/LowerTypeTests.cpp
index 49a8c65a352cd..9f6e64fb371ec 100644
--- a/llvm/lib/Transforms/IPO/LowerTypeTests.cpp
+++ b/llvm/lib/Transforms/IPO/LowerTypeTests.cpp
@@ -136,6 +136,10 @@ static cl::opt<bool> EnableJumpTableDebugInfo(
"lowertypetests-jump-table-debug-info", cl::init(true), cl::Hidden,
cl::desc("Enable debug info generation for jump tables"));
+static cl::opt<bool> ReorderCfiJumpTablesProfiles(
+ "reorder-cfi-jump-tables-profiles", cl::init(true), cl::Hidden,
+ cl::desc("Reorder CFI jump tables using profile information"));
+
bool BitSetInfo::containsGlobalOffset(uint64_t Offset) const {
if (Offset < ByteOffset)
return false;
@@ -469,8 +473,12 @@ static void createCfiFunctionsMetadata(
else if (F.hasExternalWeakLinkage())
Linkage = CfiFunctionLinkage::WeakDeclaration;
- uint8_t EncodedLinkage = encodeCfiFunctionLinkage(
- Linkage, CfiFunctionHotness::fromFunction(F, PSI, BFIGetter));
+ CfiFunctionHotness Hotness =
+ ReorderCfiJumpTablesProfiles
+ ? CfiFunctionHotness::fromFunction(F, PSI, BFIGetter)
+ : CfiFunctionHotness();
+
+ uint8_t EncodedLinkage = encodeCfiFunctionLinkage(Linkage, Hotness);
Elts.push_back(ConstantAsMetadata::get(
llvm::ConstantInt::get(Type::getInt8Ty(Ctx), EncodedLinkage)));
diff --git a/llvm/test/Transforms/ThinLTOBitcodeWriter/cfi-functions-hotness.ll b/llvm/test/Transforms/ThinLTOBitcodeWriter/cfi-functions-hotness.ll
index e59cd2b2ae5d3..11477db83c499 100644
--- a/llvm/test/Transforms/ThinLTOBitcodeWriter/cfi-functions-hotness.ll
+++ b/llvm/test/Transforms/ThinLTOBitcodeWriter/cfi-functions-hotness.ll
@@ -1,8 +1,14 @@
; RUN: opt -thinlto-bc -thinlto-split-lto-unit -o %t %s
; RUN: llvm-modextract -b -n 1 -o - %t | llvm-dis | FileCheck %s
+; RUN: opt -thinlto-bc -thinlto-split-lto-unit -reorder-cfi-jump-tables-profiles=false -o %t.disabled %s
+; RUN: llvm-modextract -b -n 1 -o - %t.disabled | llvm-dis | FileCheck --check-prefix=DISABLED %s
+
+; RUN: opt -thinlto-bc -thinlto-split-lto-unit -reorder-cfi-jump-tables-profiles=true -o %t.enabled %s
+; RUN: llvm-modextract -b -n 1 -o - %t.enabled | llvm-dis | FileCheck %s
+
; Check that cfi.functions metadata encodes hotness in bits 2-3 of
-; the linkage operand:
+; the linkage operand when enabled:
; - Hot functions (Attribute::Hot or PSI.isFunctionHotInCallGraph) -> Hot (3)
; - Cold functions (Attribute::Cold or PSI.isFunctionColdInCallGraph) -> Cold (1)
; - Normal functions -> Other (2)
@@ -23,6 +29,22 @@
; CHECK: !"f_decl", i8 1,
; CHECK: !"f_weak_decl", i8 2,
+; When disabled, hotness bits (2-7) are 0:
+; DISABLED: !"f_nocount", i8 0,
+; DISABLED: !"f_entry_count", i8 0
+; DISABLED: !"f_cfg_hot", i8 0
+; DISABLED: !"f_zero", i8 0
+; DISABLED: !"f_one", i8 0
+; DISABLED: !"f_hot_attr", i8 0
+; DISABLED: !"f_cold_attr", i8 0
+; DISABLED: !"f_non_canonical_hot", i8 1
+; DISABLED: !"f_non_canonical_cold", i8 1
+; DISABLED: !"f_non_canonical_nocount", i8 1
+; DISABLED: !"f_other", i8 0
+; DISABLED: !"f_non_canonical_other", i8 1
+; DISABLED: !"f_decl", i8 1,
+; DISABLED: !"f_weak_decl", i8 2,
+
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
More information about the llvm-commits
mailing list