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

Kyungwoo Lee via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 4 00:44:00 PDT 2024


================
@@ -335,9 +404,20 @@ void ICF::run() {
   forEachClass([&](size_t begin, size_t end) {
     if (end - begin < 2)
       return;
+    bool useSafeThunks = config->icfLevel == ICFLevel::safe_thunks;
+
+    // For ICF level safe_thunks, replace keepUnique function bodies with
+    // thunks. For all other ICF levles, directly merge the functions.
+    if (useSafeThunks)
+      applySafeThunksToRange(begin, end);
+
     ConcatInputSection *beginIsec = icfInputs[begin];
-    for (size_t i = begin + 1; i < end; ++i)
+    for (size_t i = begin + 1; i < end; ++i) {
+      // When using safe_thunks, keepUnique inputs are already handeled above
+      if (useSafeThunks && icfInputs[i]->keepUnique)
----------------
kyulee-com wrote:

So, we expect to see `icfInputs[i]->keepUnique` entries only under `useSafeThunks`, right? As they've been already folded (not live) to a newly created thunk section, it will be dead, right? Can we simplify this check with some assertions like?
```
if (icfInputs[i]->keepUnique) {
  assert(useSafeThunks);
  assert(!icfInputs[i]->live);
  continue;
}
```

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


More information about the llvm-commits mailing list