[llvm] [MergeFunctions] Add support to run the pass over a set of function pointers (PR #111045)
Rafael Eckstein via llvm-commits
llvm-commits at lists.llvm.org
Fri Nov 15 11:20:14 PST 2024
================
@@ -409,24 +428,36 @@ static bool isEligibleForMerging(Function &F) {
!hasDistinctMetadataIntrinsic(F);
}
-bool MergeFunctions::runOnModule(Module &M) {
+template <typename FuncContainer>
+bool MergeFunctions::runOnModule(FuncContainer &M) {
bool Changed = false;
- SmallVector<GlobalValue *, 4> UsedV;
- collectUsedGlobalVariables(M, UsedV, /*CompilerUsed=*/false);
- collectUsedGlobalVariables(M, UsedV, /*CompilerUsed=*/true);
- Used.insert(UsedV.begin(), UsedV.end());
+ if constexpr (std::is_same<FuncContainer, Module>::value) {
+ SmallVector<GlobalValue *, 4> UsedV;
+ collectUsedGlobalVariables(M, UsedV, /*CompilerUsed=*/false);
+ collectUsedGlobalVariables(M, UsedV, /*CompilerUsed=*/true);
+ Used.insert(UsedV.begin(), UsedV.end());
+ }
// All functions in the module, ordered by hash. Functions with a unique
// hash value are easily eliminated.
std::vector<std::pair<stable_hash, Function *>> HashedFuncs;
- for (Function &Func : M) {
- if (isEligibleForMerging(Func)) {
- HashedFuncs.push_back({StructuralHash(Func), &Func});
+ if constexpr (std::is_same<FuncContainer, std::set<Function *>>::value) {
+ for (Function *Func : M) {
+ if (isEligibleForMerging(*Func)) {
+ HashedFuncs.push_back({StructuralHash(*Func), Func});
+ }
+ }
+ }
+ if constexpr (std::is_same<FuncContainer, Module>::value) {
+ for (Function &Func : M) {
+ if (isEligibleForMerging(Func)) {
+ HashedFuncs.push_back({StructuralHash(Func), &Func});
+ }
----------------
Casperento wrote:
Resolved in [eae748a](https://github.com/llvm/llvm-project/pull/111045/commits/eae748a33a7c96230cb392d4fe8352af760a687f).
https://github.com/llvm/llvm-project/pull/111045
More information about the llvm-commits
mailing list