Skip to content

Commit e823136

Browse files
authored
[BOLT] Refactor --keep-nops option. NFC. (#72228)
Run RemoveNops pass only if --keep-nops is set to false (default).
1 parent b7669ed commit e823136

File tree

4 files changed

+8
-11
lines changed

4 files changed

+8
-11
lines changed

bolt/include/bolt/Core/BinaryFunction.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1296,7 +1296,7 @@ class BinaryFunction {
12961296
/// Return true if the function body is non-contiguous.
12971297
bool isSplit() const { return isSimple() && getLayout().isSplit(); }
12981298

1299-
bool shouldPreserveNops() const;
1299+
bool shouldPreserveNops() const { return PreserveNops; }
13001300

13011301
/// Return true if the function has exception handling tables.
13021302
bool hasEHRanges() const { return HasEHRanges; }

bolt/lib/Core/BinaryFunction.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4367,10 +4367,6 @@ MCInst *BinaryFunction::getInstructionAtOffset(uint64_t Offset) {
43674367
}
43684368
}
43694369

4370-
bool BinaryFunction::shouldPreserveNops() const {
4371-
return PreserveNops || opts::KeepNops;
4372-
}
4373-
43744370
void BinaryFunction::printLoopInfo(raw_ostream &OS) const {
43754371
if (!opts::shouldPrint(*this))
43764372
return;

bolt/lib/Rewrite/BinaryPassManager.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ static cl::opt<bool> JTFootprintReductionFlag(
7272
"instructions at jump sites"),
7373
cl::cat(BoltOptCategory));
7474

75+
static cl::opt<bool>
76+
KeepNops("keep-nops",
77+
cl::desc("keep no-op instructions. By default they are removed."),
78+
cl::Hidden, cl::cat(BoltOptCategory));
79+
7580
cl::opt<bool> NeverPrint("never-print", cl::desc("never print"),
7681
cl::ReallyHidden, cl::cat(BoltOptCategory));
7782

@@ -359,7 +364,8 @@ void BinaryFunctionPassManager::runAllPasses(BinaryContext &BC) {
359364

360365
Manager.registerPass(std::make_unique<ShortenInstructions>(NeverPrint));
361366

362-
Manager.registerPass(std::make_unique<RemoveNops>(NeverPrint));
367+
Manager.registerPass(std::make_unique<RemoveNops>(NeverPrint),
368+
!opts::KeepNops);
363369

364370
Manager.registerPass(std::make_unique<NormalizeCFG>(PrintNormalized));
365371

bolt/lib/Utils/CommandLineOpts.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,6 @@ cl::opt<bool>
129129
cl::desc("instrument code to generate accurate profile data"),
130130
cl::cat(BoltOptCategory));
131131

132-
cl::opt<bool>
133-
KeepNops("keep-nops",
134-
cl::desc("keep no-op instructions. By default they are removed."),
135-
cl::Hidden, cl::cat(BoltOptCategory));
136-
137132
cl::opt<std::string>
138133
OutputFilename("o",
139134
cl::desc("<output file>"),

0 commit comments

Comments
 (0)