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

Amir Ayupov via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 13 12:40:51 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;
+  /// Returns true if the memory address is in the bit vector of vtables.
+  bool isAddressInVTable(uint64_t Address) const {
+    return VtableBitVector.test(Address / 8);
+  }
+  /// Initialize bit vector of memory addresses of vtables.
+  void initVtable() { VtableBitVector.resize((((uint64_t)1) << 32) / 8); }
----------------
aaupov wrote:

Define constants to make it explicit what size do we want to pre-allocate.

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


More information about the llvm-commits mailing list