[llvm] [BOLT] Refactor --keep-nops option. NFC. (PR #72228)

Maksim Panchenko via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 14 00:28:26 PST 2023


https://github.com/maksfb created https://github.com/llvm/llvm-project/pull/72228

Run RemoveNops pass only if --keep-nops is set to false (default).

>From 35c17f14ef18ca70dcd1baffb2e0491463264e0d Mon Sep 17 00:00:00 2001
From: Maksim Panchenko <maks at fb.com>
Date: Tue, 14 Nov 2023 00:23:11 -0800
Subject: [PATCH] [BOLT] Refactor --keep-nops option. NFC.

Run RemoveNops pass only if --keep-nops is set to false (default).
---
 bolt/include/bolt/Core/BinaryFunction.h | 2 +-
 bolt/lib/Core/BinaryFunction.cpp        | 4 ----
 bolt/lib/Rewrite/BinaryPassManager.cpp  | 8 +++++++-
 bolt/lib/Utils/CommandLineOpts.cpp      | 5 -----
 4 files changed, 8 insertions(+), 11 deletions(-)

diff --git a/bolt/include/bolt/Core/BinaryFunction.h b/bolt/include/bolt/Core/BinaryFunction.h
index b1adf2da0da3e15..63c0b118db65778 100644
--- a/bolt/include/bolt/Core/BinaryFunction.h
+++ b/bolt/include/bolt/Core/BinaryFunction.h
@@ -1296,7 +1296,7 @@ class BinaryFunction {
   /// Return true if the function body is non-contiguous.
   bool isSplit() const { return isSimple() && getLayout().isSplit(); }
 
-  bool shouldPreserveNops() const;
+  bool shouldPreserveNops() const { return PreserveNops; }
 
   /// Return true if the function has exception handling tables.
   bool hasEHRanges() const { return HasEHRanges; }
diff --git a/bolt/lib/Core/BinaryFunction.cpp b/bolt/lib/Core/BinaryFunction.cpp
index 1f4a7cc35247425..7559c3706f493e1 100644
--- a/bolt/lib/Core/BinaryFunction.cpp
+++ b/bolt/lib/Core/BinaryFunction.cpp
@@ -4367,10 +4367,6 @@ MCInst *BinaryFunction::getInstructionAtOffset(uint64_t Offset) {
   }
 }
 
-bool BinaryFunction::shouldPreserveNops() const {
-  return PreserveNops || opts::KeepNops;
-}
-
 void BinaryFunction::printLoopInfo(raw_ostream &OS) const {
   if (!opts::shouldPrint(*this))
     return;
diff --git a/bolt/lib/Rewrite/BinaryPassManager.cpp b/bolt/lib/Rewrite/BinaryPassManager.cpp
index cd27c71ba2aedf2..37de3eabc6d235d 100644
--- a/bolt/lib/Rewrite/BinaryPassManager.cpp
+++ b/bolt/lib/Rewrite/BinaryPassManager.cpp
@@ -72,6 +72,11 @@ static cl::opt<bool> JTFootprintReductionFlag(
              "instructions at jump sites"),
     cl::cat(BoltOptCategory));
 
+static cl::opt<bool>
+    KeepNops("keep-nops",
+             cl::desc("keep no-op instructions. By default they are removed."),
+             cl::Hidden, cl::cat(BoltOptCategory));
+
 cl::opt<bool> NeverPrint("never-print", cl::desc("never print"),
                          cl::ReallyHidden, cl::cat(BoltOptCategory));
 
@@ -359,7 +364,8 @@ void BinaryFunctionPassManager::runAllPasses(BinaryContext &BC) {
 
   Manager.registerPass(std::make_unique<ShortenInstructions>(NeverPrint));
 
-  Manager.registerPass(std::make_unique<RemoveNops>(NeverPrint));
+  Manager.registerPass(std::make_unique<RemoveNops>(NeverPrint),
+                       !opts::KeepNops);
 
   Manager.registerPass(std::make_unique<NormalizeCFG>(PrintNormalized));
 
diff --git a/bolt/lib/Utils/CommandLineOpts.cpp b/bolt/lib/Utils/CommandLineOpts.cpp
index 0c0e83c4ec9703b..a1df5de26234029 100644
--- a/bolt/lib/Utils/CommandLineOpts.cpp
+++ b/bolt/lib/Utils/CommandLineOpts.cpp
@@ -129,11 +129,6 @@ cl::opt<bool>
                cl::desc("instrument code to generate accurate profile data"),
                cl::cat(BoltOptCategory));
 
-cl::opt<bool>
-    KeepNops("keep-nops",
-             cl::desc("keep no-op instructions. By default they are removed."),
-             cl::Hidden, cl::cat(BoltOptCategory));
-
 cl::opt<std::string>
 OutputFilename("o",
   cl::desc("<output file>"),



More information about the llvm-commits mailing list