[llvm] 67fde2b - [FuncSpec] Minor refactoring in statistics and debug messages.

Alexandros Lamprineas via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 15 02:14:27 PDT 2023


Author: Alexandros Lamprineas
Date: 2023-03-15T09:10:06Z
New Revision: 67fde2b932a0b5b4ab23c2ccedeffe44dc1bde50

URL: https://github.com/llvm/llvm-project/commit/67fde2b932a0b5b4ab23c2ccedeffe44dc1bde50
DIFF: https://github.com/llvm/llvm-project/commit/67fde2b932a0b5b4ab23c2ccedeffe44dc1bde50.diff

LOG: [FuncSpec] Minor refactoring in statistics and debug messages.

* Remove redundant variable `NbFunctionsSpecialized` as it is no longer
  used by the cost model.
* Rename statistic `NumFuncSpecialized` to `NumSpecsCreated` as a better
  description (the old name confusingly implied number of functions we have
  created clones for).
* Same for variable `SpecializedFuncs`. Renamed to `Specializations`.
* Move debug message in the destructor (avoids repetition when MaxIters > 1).

Differential Revision: https://reviews.llvm.org/D145375

Added: 
    

Modified: 
    llvm/include/llvm/Transforms/IPO/FunctionSpecialization.h
    llvm/lib/Transforms/IPO/FunctionSpecialization.cpp
    llvm/test/Transforms/FunctionSpecialization/function-specialization-stats.ll

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/Transforms/IPO/FunctionSpecialization.h b/llvm/include/llvm/Transforms/IPO/FunctionSpecialization.h
index 8db246f739ab1..831717c765169 100644
--- a/llvm/include/llvm/Transforms/IPO/FunctionSpecialization.h
+++ b/llvm/include/llvm/Transforms/IPO/FunctionSpecialization.h
@@ -127,11 +127,7 @@ class FunctionSpecializer {
   std::function<TargetTransformInfo &(Function &)> GetTTI;
   std::function<AssumptionCache &(Function &)> GetAC;
 
-  // The number of functions specialised, used for collecting statistics and
-  // also in the cost model.
-  unsigned NbFunctionsSpecialized = 0;
-
-  SmallPtrSet<Function *, 32> SpecializedFuncs;
+  SmallPtrSet<Function *, 32> Specializations;
   SmallPtrSet<Function *, 32> FullySpecialized;
   DenseMap<Function *, CodeMetrics> FunctionMetrics;
 
@@ -144,13 +140,9 @@ class FunctionSpecializer {
       : Solver(Solver), M(M), FAM(FAM), GetTLI(GetTLI), GetTTI(GetTTI),
         GetAC(GetAC) {}
 
-  ~FunctionSpecializer() {
-    // Eliminate dead code.
-    removeDeadFunctions();
-    cleanUpSSA();
-  }
+  ~FunctionSpecializer();
 
-  bool isClonedFunction(Function *F) { return SpecializedFuncs.count(F); }
+  bool isClonedFunction(Function *F) { return Specializations.count(F); }
 
   bool run();
 

diff  --git a/llvm/lib/Transforms/IPO/FunctionSpecialization.cpp b/llvm/lib/Transforms/IPO/FunctionSpecialization.cpp
index 51bc1786fdc79..c59567c709523 100644
--- a/llvm/lib/Transforms/IPO/FunctionSpecialization.cpp
+++ b/llvm/lib/Transforms/IPO/FunctionSpecialization.cpp
@@ -64,7 +64,7 @@ using namespace llvm;
 
 #define DEBUG_TYPE "function-specialization"
 
-STATISTIC(NumFuncSpecialized, "Number of functions specialized");
+STATISTIC(NumSpecsCreated, "Number of specializations created");
 
 static cl::opt<bool> ForceFunctionSpecialization(
     "force-function-specialization", cl::init(false), cl::Hidden,
@@ -234,7 +234,7 @@ static void removeSSACopy(Function &F) {
 
 /// Remove any ssa_copy intrinsics that may have been introduced.
 void FunctionSpecializer::cleanUpSSA() {
-  for (Function *F : SpecializedFuncs)
+  for (Function *F : Specializations)
     removeSSACopy(*F);
 }
 
@@ -253,6 +253,16 @@ template <> struct llvm::DenseMapInfo<SpecSig> {
   }
 };
 
+FunctionSpecializer::~FunctionSpecializer() {
+  LLVM_DEBUG(
+    if (NumSpecsCreated > 0)
+      dbgs() << "FnSpecialization: Created " << NumSpecsCreated
+             << " specializations in module " << M.getName() << "\n");
+  // Eliminate dead code.
+  removeDeadFunctions();
+  cleanUpSSA();
+}
+
 /// Attempt to specialize functions in the module to enable constant
 /// propagation across function boundaries.
 ///
@@ -358,11 +368,6 @@ bool FunctionSpecializer::run() {
   }
 
   promoteConstantStackValues();
-  LLVM_DEBUG(if (NbFunctionsSpecialized) dbgs()
-             << "FnSpecialization: Specialized " << NbFunctionsSpecialized
-             << " functions in module " << M.getName() << "\n");
-
-  NumFuncSpecialized += NbFunctionsSpecialized;
   return true;
 }
 
@@ -506,7 +511,7 @@ bool FunctionSpecializer::isCandidateFunction(Function *F) {
     return false;
 
   // Do not specialize the cloned function again.
-  if (SpecializedFuncs.contains(F))
+  if (Specializations.contains(F))
     return false;
 
   // If we're optimizing the function for size, we shouldn't specialize it.
@@ -540,8 +545,8 @@ Function *FunctionSpecializer::createSpecialization(Function *F, const SpecSig &
   Solver.markBlockExecutable(&Clone->front());
 
   // Mark all the specialized functions
-  SpecializedFuncs.insert(Clone);
-  NbFunctionsSpecialized++;
+  Specializations.insert(Clone);
+  ++NumSpecsCreated;
 
   return Clone;
 }

diff  --git a/llvm/test/Transforms/FunctionSpecialization/function-specialization-stats.ll b/llvm/test/Transforms/FunctionSpecialization/function-specialization-stats.ll
index 42a7676cb54f3..32f521c4393dd 100644
--- a/llvm/test/Transforms/FunctionSpecialization/function-specialization-stats.ll
+++ b/llvm/test/Transforms/FunctionSpecialization/function-specialization-stats.ll
@@ -1,7 +1,7 @@
 ; REQUIRES: asserts
 ; RUN: opt -stats -passes="ipsccp<func-spec>" -S -force-function-specialization < %s 2>&1 | FileCheck %s
 
-; CHECK: 2 function-specialization - Number of functions specialized
+; CHECK: 2 function-specialization - Number of specializations created
 
 define i64 @main(i64 %x, i1 %flag) {
 entry:


        


More information about the llvm-commits mailing list