Skip to content

Commit 562e3bf

Browse files
authored
[BOLT] Add an option for constant island cloning (#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 (#165787).
1 parent c0cb513 commit 562e3bf

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

bolt/lib/Core/BinaryContext.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ cl::opt<std::string> CompDirOverride(
7878
"to *.dwo files."),
7979
cl::Hidden, cl::init(""), cl::cat(BoltCategory));
8080

81+
static cl::opt<bool> CloneConstantIsland("clone-constant-island",
82+
cl::desc("clone constant islands"),
83+
cl::Hidden, cl::init(true),
84+
cl::ZeroOrMore, cl::cat(BoltCategory));
85+
8186
static cl::opt<bool>
8287
FailOnInvalidPadding("fail-on-invalid-padding", cl::Hidden, cl::init(false),
8388
cl::desc("treat invalid code padding as error"),
@@ -461,14 +466,21 @@ BinaryContext::handleAddressRef(uint64_t Address, BinaryFunction &BF,
461466
// of dynamic relocs, as we currently do not support cloning them.
462467
// Notice: we might fail to link because of this, if the original constant
463468
// island we are referring would be emitted too far away.
464-
if (IslandIter->second->hasDynamicRelocationAtIsland()) {
469+
if (IslandIter->second->hasDynamicRelocationAtIsland() ||
470+
!opts::CloneConstantIsland) {
465471
MCSymbol *IslandSym =
466472
IslandIter->second->getOrCreateIslandAccess(Address);
467473
if (IslandSym)
468474
return std::make_pair(IslandSym, 0);
469475
} else if (MCSymbol *IslandSym =
470476
IslandIter->second->getOrCreateProxyIslandAccess(Address,
471477
BF)) {
478+
LLVM_DEBUG(
479+
dbgs() << "BOLT-DEBUG: clone constant island at address 0x"
480+
<< Twine::utohexstr(IslandIter->first) << " with size of 0x"
481+
<< Twine::utohexstr(
482+
IslandIter->second->estimateConstantIslandSize())
483+
<< " bytes, referenced by " << BF << "\n");
472484
BF.createIslandDependency(IslandSym, IslandIter->second);
473485
return std::make_pair(IslandSym, 0);
474486
}

0 commit comments

Comments
 (0)