[lld] [lld-macho][arm64] Enhance safe ICF with thunk-based deduplication (PR #106573)

Peter Rong via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 3 11:16:24 PDT 2024


================
@@ -251,6 +252,74 @@ void ICF::forEachClassRange(size_t begin, size_t end,
   }
 }
 
+// Given a range of identical icfInputs, replace address significant functions
+// with a thunk that is just a direct branch to the first function in the
+// series. This way we keep only one main body of the function but we still
+// retain the address uniqueness of relevant functions by having them be a
+// direct branch thunk rather than containing a full copy of the actual function
+// body.
+void ICF::applySafeThunksToRange(size_t begin, size_t end) {
+  // If the functions we're dealing with are smaller than the thunk size, then
+  // just leave them all as-is - creating thunks would be a net loss.
+  uint32_t thunkSize = target->getICFSafeThunkSize();
+  if (icfInputs[begin]->data.size() <= thunkSize)
+    return;
+
+  // The standard ICF algorithm will merge all functions in the [begin + 1, end)
+  // range into icfInputs[begin].So, the body of the first function is always
----------------
DataCorrupted wrote:

```suggestion
  // range into icfInputs[begin], so the body of the first function is always
```

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


More information about the llvm-commits mailing list