[llvm] [MergeFunctions] Add support to run the pass over a set of function pointers (PR #111045)

Stephen Tozer via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 15 06:45:54 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());
+  }
----------------
SLTozer wrote:

Since this runs at the top of the function and is only being used for the module case, which is only called from `run`, this could be moved into `run` before the call to `runOnModule`.

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


More information about the llvm-commits mailing list