[llvm] Make functions always renamable (PR #115226)

Simone Campanoni via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 6 14:07:17 PST 2024


https://github.com/scampanoni created https://github.com/llvm/llvm-project/pull/115226

Functions with non-default sections are currently non renamable. This blocks ThinLTO to optimize code between modules.

It is unclear why functions with non-default sections should not be renamable. This patch makes them always renamable.

Perhaps, we need to block functions with non-default sections to be non renamable for some object formats (please see the RFC "Allow ThinLTO to Rename Local Functions with Sections" for a longer description on this topic).
If that is the case, then we should perhaps make this list of object formats that require special treatment explicit.

>From 6750a6e48be8765d5bb10a75b11650d8979b5c19 Mon Sep 17 00:00:00 2001
From: Simone Campanoni <campanoni at google.com>
Date: Wed, 6 Nov 2024 21:51:33 +0000
Subject: [PATCH] Make functions always renamable

Functions with non-default sections are currently non renamable.
This blocks ThinLTO to optimize between modules.

It is unclear why functions with non-default sections should not be renamable.
This patch makes them always renamable.

Perhaps, we need to block functions with non-default sections to be non
renamable for some object formats (please see the RFC "Allow ThinLTO to
Rename Local Functions with Sections" for a full description and
discussion on this topic).
If that is the case, then we should make this list of object formats
that require special treatment explicit.
---
 llvm/lib/Analysis/ModuleSummaryAnalysis.cpp  | 3 +++
 llvm/test/Bitcode/thinlto-summary-section.ll | 6 +++---
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp b/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
index 04670f2e2d6351..63ea8af1d013a4 100644
--- a/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
+++ b/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
@@ -175,6 +175,9 @@ static CalleeInfo::HotnessType getHotness(uint64_t ProfileCount,
 }
 
 static bool isNonRenamableLocal(const GlobalValue &GV) {
+  if (isa<Function>(&GV)) {
+    return false;
+  }
   return GV.hasSection() && GV.hasLocalLinkage();
 }
 
diff --git a/llvm/test/Bitcode/thinlto-summary-section.ll b/llvm/test/Bitcode/thinlto-summary-section.ll
index 5a2c02e4ac2972..397cf8d8f5f905 100644
--- a/llvm/test/Bitcode/thinlto-summary-section.ll
+++ b/llvm/test/Bitcode/thinlto-summary-section.ll
@@ -4,10 +4,10 @@
 ; RUN: llvm-lto -thinlto -o %t2 %t.o
 ; RUN: llvm-bcanalyzer -dump %t2.thinlto.bc | FileCheck %s --check-prefix=COMBINED
 
-; Flags should be 0x57 (87) for local linkage (0x3), dso_local (0x40) and not being importable
+; Flags should be 0x47 (71) for local linkage (0x3), dso_local (0x40) and being importable
 ; (0x10) due to local linkage plus having a section.
-; CHECK: <PERMODULE_PROFILE {{.*}} op1=87
-; COMBINED-DAG: <COMBINED_PROFILE {{.*}} op2=87
+; CHECK: <PERMODULE_PROFILE {{.*}} op1=71
+; COMBINED-DAG: <COMBINED_PROFILE {{.*}} op2=71
 define internal void @functionWithSection() section "some_section" {
     ret void
 }



More information about the llvm-commits mailing list