[llvm] [BOLT] Add an option for constant island cloning (PR #165778)
YongKang Zhu via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 30 13:54:31 PDT 2025
https://github.com/yozhu created https://github.com/llvm/llvm-project/pull/165778
Avoid cloning constant island helps to reduce app size, especially for
BOLT optimization in which cloning would happen when a function is split
into multiple fragments. Add an option to make the cloning optional, and
we will introduce a new pass to handle the reference too far error that
may result from disabling constant island cloning.
>From 4f7d3b13cb2951bb2360f0767202bea23604b5fb Mon Sep 17 00:00:00 2001
From: YongKang Zhu <yongzhu at fb.com>
Date: Mon, 22 Sep 2025 15:05:51 -0700
Subject: [PATCH] [BOLT] Add an option for constant island cloning
Avoid cloning constant island helps to reduce app size, especially for
BOLT optimization in which cloning would happen when a function is split
into multiple fragments. Add an option to make the cloning optional, and
we will introduce a new pass to handle the reference too far error that
may result from disabling constant island cloning.
---
bolt/lib/Core/BinaryContext.cpp | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/bolt/lib/Core/BinaryContext.cpp b/bolt/lib/Core/BinaryContext.cpp
index c33540ada8a05..f93a4ed8ee392 100644
--- a/bolt/lib/Core/BinaryContext.cpp
+++ b/bolt/lib/Core/BinaryContext.cpp
@@ -78,6 +78,11 @@ cl::opt<std::string> CompDirOverride(
"to *.dwo files."),
cl::Hidden, cl::init(""), cl::cat(BoltCategory));
+static cl::opt<bool> CloneConstantIsland("clone-constant-island",
+ cl::desc("clone constant islands"),
+ cl::Hidden, cl::init(true),
+ cl::ZeroOrMore, cl::cat(BoltCategory));
+
static cl::opt<bool>
FailOnInvalidPadding("fail-on-invalid-padding", cl::Hidden, cl::init(false),
cl::desc("treat invalid code padding as error"),
@@ -461,7 +466,8 @@ BinaryContext::handleAddressRef(uint64_t Address, BinaryFunction &BF,
// of dynamic relocs, as we currently do not support cloning them.
// Notice: we might fail to link because of this, if the original constant
// island we are referring would be emitted too far away.
- if (IslandIter->second->hasDynamicRelocationAtIsland()) {
+ if (IslandIter->second->hasDynamicRelocationAtIsland() ||
+ !opts::CloneConstantIsland) {
MCSymbol *IslandSym =
IslandIter->second->getOrCreateIslandAccess(Address);
if (IslandSym)
@@ -469,6 +475,12 @@ BinaryContext::handleAddressRef(uint64_t Address, BinaryFunction &BF,
} else if (MCSymbol *IslandSym =
IslandIter->second->getOrCreateProxyIslandAccess(Address,
BF)) {
+ LLVM_DEBUG(
+ dbgs() << "BOLT-DEBUG: clone constant island at address 0x"
+ << Twine::utohexstr(IslandIter->first) << " with size of 0x"
+ << Twine::utohexstr(
+ IslandIter->second->estimateConstantIslandSize())
+ << " bytes, referenced by " << BF << "\n");
BF.createIslandDependency(IslandSym, IslandIter->second);
return std::make_pair(IslandSym, 0);
}
More information about the llvm-commits
mailing list