================

----------------
oontvoo wrote:

This is just a suggestion - but perhaps you could avoid repeated call to 
isTargetstubsAndInRange() when `estimatedStubsEnd` is `std:nullopt`

Something like this:

```
// 1. keep the original signature
bool isTargetStubsAndInRange(InputSection* isec, Thunk* thunk, uint64_t 
estimatedStubsEnd);

void finalize() {

 // ....... 
  auto estimatedStubsEnd = estimateStubsEndVA(branchTargets.size());

  // 2. Wrap BOTH loops in a single lambda
  auto processAllBranches = [&](auto hasStubsTag) {
    constexpr bool hasStubs = decltype(hasStubsTag)::value;

    // Loop 1: Deferred Branch Redirects
    for (auto [isec, r, thunk] : deferredBranchRedirects) {
      if (isTargetKnownInRange(*isec, *r))
        continue;
        
      // This whole branch is gone if estimatedStubsEnd didn't have value
      if constexpr (hasStubs) {
        if (isTargetStubsAndInRange(*isec, *r, *estimatedStubsEnd))
          continue;
      }
      
      updateBranchTargetToThunk(*r, thunk);
    }

    // Loop 2: Branches To Process
    for (auto [isec, r] : branchesToProcess) {
      if constexpr (hasStubs) {
        if (isTargetStubsAndInRange(*isec, *r, *estimatedStubsEnd))
          continue;
      }
      
      auto &thunkInfo = thunkMap[*r];
      if (auto *thunk = getThunkInRange(*isec, *r, thunkInfo)) {
        updateBranchTargetToThunk(*r, thunk);
        continue;
      }
      createThunk(*isec, *r, thunkInfo);
    }
  };

  // 3. Dispatch once for the entire processing phase
  if (estimatedStubsEnd.has_value()) {
    processAllBranches(std::true_type{});
  } else {
    processAllBranches(std::false_type{});
  }
}
```

https://github.com/llvm/llvm-project/pull/197049
_______________________________________________
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits

Reply via email to