[llvm] [BOLT] Add support for safe-icf (PR #116275)
Davide Italiano via llvm-commits
llvm-commits at lists.llvm.org
Mon Dec 16 07:01:34 PST 2024
================
@@ -27,15 +28,74 @@ 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::SparseBitVector<> VTableBitVector;
+
+ /// Return true if the memory address is in a vtable.
+ bool isAddressInVTable(uint64_t Address) const {
+ return VTableBitVector.test(Address / 8);
+ }
+
+ /// Mark memory address of vtable as used.
+ void setAddressUsedInVTable(uint64_t Address) {
+ VTableBitVector.set(Address / 8);
+ }
+
+ /// Scans symbol table and creates a bit vector of memory addresses of
+ /// vtables.
+ void initVTableReferences(const BinaryContext &BC);
+
+ /// Analyze .text section and relocations and mark functions that are not
+ /// safe to fold.
+ void markFunctionsUnsafeToFold(BinaryContext &BC);
+
+ /// Process static and dynamic relocations in the data sections to identify
+ /// function references, and marks them as unsafe to fold. It filters out
----------------
dcci wrote:
and marks -> and mark.
https://github.com/llvm/llvm-project/pull/116275
More information about the llvm-commits
mailing list