[llvm] [BOLT] Add support for safe-icf (PR #116275)

Alexander Yermolovich via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 13 18:39:56 PST 2024


================
@@ -27,15 +27,49 @@ class IdenticalCodeFolding : public BinaryFunctionPass {
       return false;
     if (BF.hasSDTMarker())
       return false;
+    if (BF.hasAddressTaken())
+      return false;
     return BinaryFunctionPass::shouldOptimize(BF);
   }
 
 public:
+  enum class ICFLevel {
+    None, // No ICF. (Default)
+    Safe, // Safe ICF for all sections.
+    All,  // Aggressive ICF for code.
+  };
   explicit IdenticalCodeFolding(const cl::opt<bool> &PrintPass)
       : BinaryFunctionPass(PrintPass) {}
 
   const char *getName() const override { return "identical-code-folding"; }
   Error runOnFunctions(BinaryContext &BC) override;
+
+private:
+  /// Bit vector of memory addresses of vtables.
+  llvm::BitVector VtableBitVector;
----------------
ayermolo wrote:

BitVector
12:10.63 real,  2190.50 user,   3352.54 sys,    0 amem, 50543836 mmem
12:15.47 real,  2171.61 user,    3110.00 sys,      0 amem, 50486944 mmem
12:15.42 real,  2199.27 user,   3336.12 sys,     0 amem, 50550316 mmem
SparceBItVector
11:56.70 real,  2173.22 user,   3025.61 sys,     0 amem, 50546564 mmem
12:25.82 real,  2196.06 user,   3279.76 sys,    0 amem, 50561464 mmem
11:48.03 real,  2254.86 user,   3216.55 sys,    0 amem, 50547536 mmem

Seems slightly faster with SparseBitVector. 🤷 

https://github.com/llvm/llvm-project/pull/116275


More information about the llvm-commits mailing list