[llvm] [LLVM] Successor count added to InstCount (PR #171670)

IƱaki V Arrechea via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 26 09:54:28 PST 2025


https://github.com/InakiVA updated https://github.com/llvm/llvm-project/pull/171670

>From cd2e4c93b01437c066e2fd7a881aea5059ac62f3 Mon Sep 17 00:00:00 2001
From: Inaki Arrechea <inakiarrechea at google.com>
Date: Thu, 18 Dec 2025 18:18:07 +0000
Subject: [PATCH 1/7] Format correction and return of InstCount

---
 .../Analysis/FunctionPropertiesAnalysis.h     | 11 +++
 .../Analysis/FunctionPropertiesAnalysis.cpp   | 51 +++++++++++++-
 llvm/lib/Passes/PassBuilderPipelines.cpp      |  5 +-
 llvm/lib/Passes/PassRegistry.def              |  1 +
 llvm/test/Other/functionpropertiesanalysis.ll | 69 +++++++++++++++++++
 llvm/test/Other/instcount.ll                  |  2 +-
 6 files changed, 135 insertions(+), 4 deletions(-)
 create mode 100644 llvm/test/Other/functionpropertiesanalysis.ll

diff --git a/llvm/include/llvm/Analysis/FunctionPropertiesAnalysis.h b/llvm/include/llvm/Analysis/FunctionPropertiesAnalysis.h
index 3dc241c0124e4..a2923f74805da 100644
--- a/llvm/include/llvm/Analysis/FunctionPropertiesAnalysis.h
+++ b/llvm/include/llvm/Analysis/FunctionPropertiesAnalysis.h
@@ -127,6 +127,11 @@ class FunctionPropertiesInfo {
   int64_t CriticalEdgeCount = 0;
   int64_t ControlFlowEdgeCount = 0;
   int64_t UnconditionalBranchCount = 0;
+  int64_t ConditionalBranchCount = 0;
+  int64_t BranchInstructionCount = 0;
+  int64_t BranchSuccessorCount = 0;
+  int64_t SwitchInstructionCount = 0;
+  int64_t SwitchSuccessorCount = 0;
 
   // Call related instructions
   int64_t IntrinsicCount = 0;
@@ -179,6 +184,12 @@ class FunctionPropertiesPrinterPass
   static bool isRequired() { return true; }
 };
 
+/// Statistics pass for the FunctionPropertiesAnalysis results.
+struct FunctionPropertiesStatisticsPass
+    : PassInfoMixin<FunctionPropertiesStatisticsPass> {
+  PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
+};
+
 /// Correctly update FunctionPropertiesInfo post-inlining. A
 /// FunctionPropertiesUpdater keeps the state necessary for tracking the changes
 /// llvm::InlineFunction makes. The idea is that inlining will at most modify
diff --git a/llvm/lib/Analysis/FunctionPropertiesAnalysis.cpp b/llvm/lib/Analysis/FunctionPropertiesAnalysis.cpp
index c52a6de2bb71e..d70814c639d48 100644
--- a/llvm/lib/Analysis/FunctionPropertiesAnalysis.cpp
+++ b/llvm/lib/Analysis/FunctionPropertiesAnalysis.cpp
@@ -14,6 +14,7 @@
 #include "llvm/Analysis/FunctionPropertiesAnalysis.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SetVector.h"
+#include "llvm/ADT/Statistic.h"
 #include "llvm/Analysis/LoopInfo.h"
 #include "llvm/IR/CFG.h"
 #include "llvm/IR/Constants.h"
@@ -26,6 +27,19 @@
 
 using namespace llvm;
 
+#define DEBUG_TYPE "statscount"
+
+STATISTIC(TotalBlocks, "Number of basic blocks");
+STATISTIC(TotalInsts, "Number of instructions (of all types)");
+STATISTIC(TotalSuccs, "Number of basic block successors");
+STATISTIC(TotalUncondBranchInsts,
+          "Number of unconditional branch instructions");
+STATISTIC(TotalCondBranchInsts, "Number of conditional branch instructions");
+STATISTIC(TotalBranchInsts, "Number of branch instructions");
+STATISTIC(TotalBranchSuccs, "Number of branch successors");
+STATISTIC(TotalSwitchInsts, "Number of switch instructions");
+STATISTIC(TotalSwitchSuccs, "Number of switch successors");
+
 namespace llvm {
 LLVM_ABI cl::opt<bool> EnableDetailedFunctionProperties(
     "enable-detailed-function-properties", cl::Hidden, cl::init(false),
@@ -124,9 +138,19 @@ void FunctionPropertiesInfo::updateForBB(const BasicBlock &BB,
 
     ControlFlowEdgeCount += Direction * SuccessorCount;
 
-    if (const auto *BI = dyn_cast<BranchInst>(BB.getTerminator())) {
-      if (!BI->isConditional())
+    const Instruction *TI = BB.getTerminator();
+    const int64_t InstructionSuccessorCount = TI->getNumSuccessors();
+    if (isa<BranchInst>(TI)) {
+      BranchInstructionCount += Direction;
+      BranchSuccessorCount += Direction * InstructionSuccessorCount;
+      const auto *BI = dyn_cast<BranchInst>(TI);
+      if (BI->isConditional())
+        ConditionalBranchCount += Direction;
+      else
         UnconditionalBranchCount += Direction;
+    } else if (isa<SwitchInst>(TI)) {
+      SwitchInstructionCount += Direction;
+      SwitchSuccessorCount += Direction * InstructionSuccessorCount;
     }
 
     for (const Instruction &I : BB.instructionsWithoutDebug()) {
@@ -362,6 +386,11 @@ void FunctionPropertiesInfo::print(raw_ostream &OS) const {
     PRINT_PROPERTY(CriticalEdgeCount)
     PRINT_PROPERTY(ControlFlowEdgeCount)
     PRINT_PROPERTY(UnconditionalBranchCount)
+    PRINT_PROPERTY(ConditionalBranchCount)
+    PRINT_PROPERTY(BranchInstructionCount)
+    PRINT_PROPERTY(BranchSuccessorCount)
+    PRINT_PROPERTY(SwitchInstructionCount)
+    PRINT_PROPERTY(SwitchSuccessorCount)
     PRINT_PROPERTY(IntrinsicCount)
     PRINT_PROPERTY(DirectCallCount)
     PRINT_PROPERTY(IndirectCallCount)
@@ -396,6 +425,24 @@ FunctionPropertiesPrinterPass::run(Function &F, FunctionAnalysisManager &AM) {
   return PreservedAnalyses::all();
 }
 
+PreservedAnalyses
+FunctionPropertiesStatisticsPass::run(Function &F,
+                                      FunctionAnalysisManager &AM) {
+  LLVM_DEBUG(dbgs() << "STATSCOUNT: running on function " << F.getName()
+                    << "\n");
+  auto &AnalysisResults = AM.getResult<FunctionPropertiesAnalysis>(F);
+  TotalBlocks += AnalysisResults.BasicBlockCount;
+  TotalInsts += AnalysisResults.TotalInstructionCount;
+  TotalSuccs += AnalysisResults.ControlFlowEdgeCount;
+  TotalUncondBranchInsts += AnalysisResults.UnconditionalBranchCount;
+  TotalCondBranchInsts += AnalysisResults.ConditionalBranchCount;
+  TotalBranchInsts += AnalysisResults.BranchInstructionCount;
+  TotalBranchSuccs += AnalysisResults.BranchSuccessorCount;
+  TotalSwitchInsts += AnalysisResults.SwitchInstructionCount;
+  TotalSwitchSuccs += AnalysisResults.SwitchSuccessorCount;
+  return PreservedAnalyses::all();
+}
+
 FunctionPropertiesUpdater::FunctionPropertiesUpdater(
     FunctionPropertiesInfo &FPI, CallBase &CB)
     : FPI(FPI), CallSiteBB(*CB.getParent()), Caller(*CallSiteBB.getParent()) {
diff --git a/llvm/lib/Passes/PassBuilderPipelines.cpp b/llvm/lib/Passes/PassBuilderPipelines.cpp
index 67b9a61cc576f..c50b424ce9c5d 100644
--- a/llvm/lib/Passes/PassBuilderPipelines.cpp
+++ b/llvm/lib/Passes/PassBuilderPipelines.cpp
@@ -19,6 +19,7 @@
 #include "llvm/Analysis/BasicAliasAnalysis.h"
 #include "llvm/Analysis/CGSCCPassManager.h"
 #include "llvm/Analysis/CtxProfAnalysis.h"
+#include "llvm/Analysis/FunctionPropertiesAnalysis.h"
 #include "llvm/Analysis/GlobalsModRef.h"
 #include "llvm/Analysis/InlineAdvisor.h"
 #include "llvm/Analysis/InstCount.h"
@@ -413,8 +414,10 @@ void PassBuilder::invokePipelineEarlySimplificationEPCallbacks(
 static void addAnnotationRemarksPass(ModulePassManager &MPM) {
   MPM.addPass(createModuleToFunctionPassAdaptor(AnnotationRemarksPass()));
   // Count the types of instructions used
-  if (AreStatisticsEnabled())
+  if (AreStatisticsEnabled()) {
     MPM.addPass(createModuleToFunctionPassAdaptor(InstCountPass()));
+    MPM.addPass(createModuleToFunctionPassAdaptor(FunctionPropertiesStatisticsPass()));
+  }    
 }
 
 // Helper to check if the current compilation phase is preparing for LTO
diff --git a/llvm/lib/Passes/PassRegistry.def b/llvm/lib/Passes/PassRegistry.def
index cf998f29ef38c..43fd1ee3ea135 100644
--- a/llvm/lib/Passes/PassRegistry.def
+++ b/llvm/lib/Passes/PassRegistry.def
@@ -543,6 +543,7 @@ FUNCTION_PASS("sjlj-eh-prepare", SjLjEHPreparePass(TM))
 FUNCTION_PASS("slp-vectorizer", SLPVectorizerPass())
 FUNCTION_PASS("slsr", StraightLineStrengthReducePass())
 FUNCTION_PASS("stack-protector", StackProtectorPass(*TM))
+FUNCTION_PASS("statscount", FunctionPropertiesStatisticsPass())
 FUNCTION_PASS("strip-gc-relocates", StripGCRelocates())
 FUNCTION_PASS("tailcallelim", TailCallElimPass())
 FUNCTION_PASS("transform-warning", WarnMissedTransformationsPass())
diff --git a/llvm/test/Other/functionpropertiesanalysis.ll b/llvm/test/Other/functionpropertiesanalysis.ll
new file mode 100644
index 0000000000000..54f1363e8fa83
--- /dev/null
+++ b/llvm/test/Other/functionpropertiesanalysis.ll
@@ -0,0 +1,69 @@
+; REQUIRES asserts
+; RUN: opt -stats -enable-detailed-function-properties -disable-output -passes=statscount < %s 2>&1 | FileCheck %s
+; RUN: opt -stats -enable-detailed-function-properties -disable-output -passes='thinlto<O3>'< %s 2>&1 | FileCheck %s
+; RUN: opt -stats -enable-detailed-function-properties -disable-output -passes='thinlto-pre-link<O2>' < %s 2>&1 | FileCheck %s
+; RUN: opt -stats -enable-detailed-function-properties -disable-output -passes='lto<O1>' < %s 2>&1 | FileCheck %s
+; RUN: opt -stats -enable-detailed-function-properties -disable-output -passes='default<O3>' < %s 2>&1 | FileCheck %s
+; RUN: opt -stats -enable-detailed-function-properties -disable-output -passes='default<O0>' < %s 2>&1 | FileCheck %s
+
+; CHECK-DAG: 10 statscount - Number of basic blocks
+; CHECK-DAG: 8 statscount - Number of branch instructions
+; CHECK-DAG: 10 statscount - Number of branch successors
+; CHECK-DAG: 2 statscount - Number of conditional branch instructions
+; CHECK-DAG: 18 statscount - Number of instructions (of all types)
+; CHECK-DAG: 14 statscount - Number of basic block successors
+; CHECK-DAG: 1 statscount - Number of switch instructions
+; CHECK-DAG: 4 statscount - Number of switch successors
+; CHECK-DAG: 6 statscount - Number of unconditional branch instructions
+
+
+define void @foo(i32 %i, i32 %j, i32 %n) {
+entry:
+  %cmp = icmp slt i32 %i, %j
+  br i1 %cmp, label %if.then, label %if.end
+
+if.then:
+  call void @f()
+  br label %if.end
+
+if.end:
+  switch i32 %i, label %sw.default [
+    i32 1, label %sw.bb
+    i32 2, label %sw.bb1
+    i32 3, label %sw.bb1
+  ]
+
+sw.bb:
+  call void @g()
+  br label %sw.epilog
+
+sw.bb1:
+  call void @h()
+  br label %sw.epilog
+
+sw.default:
+  call void @k()
+  br label %sw.epilog
+
+sw.epilog:
+  %cmp2 = icmp sgt i32 %i, %n
+  br i1 %cmp2, label %if.then3, label %if.else
+
+if.then3:
+  call void @l()
+  br label %if.end4
+
+if.else:
+  call void @m()
+  br label %if.end4
+
+if.end4:
+  ret void
+}
+
+declare void @f()
+declare void @g()
+declare void @h()
+declare void @k()
+declare void @l()
+declare void @m()
\ No newline at end of file
diff --git a/llvm/test/Other/instcount.ll b/llvm/test/Other/instcount.ll
index 931d547371958..c9dab9e93cfb7 100644
--- a/llvm/test/Other/instcount.ll
+++ b/llvm/test/Other/instcount.ll
@@ -66,4 +66,4 @@ declare void @g()
 declare void @h()
 declare void @k()
 declare void @l()
-declare void @m()
+declare void @m()
\ No newline at end of file

>From d743ede4c2131d028dc982f6f8d771da8210eb52 Mon Sep 17 00:00:00 2001
From: Inaki Arrechea <inakiarrechea at google.com>
Date: Thu, 18 Dec 2025 18:48:38 +0000
Subject: [PATCH 2/7] Clang format

---
 llvm/lib/Passes/PassBuilderPipelines.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/llvm/lib/Passes/PassBuilderPipelines.cpp b/llvm/lib/Passes/PassBuilderPipelines.cpp
index c50b424ce9c5d..7bb66600ab5e0 100644
--- a/llvm/lib/Passes/PassBuilderPipelines.cpp
+++ b/llvm/lib/Passes/PassBuilderPipelines.cpp
@@ -416,7 +416,8 @@ static void addAnnotationRemarksPass(ModulePassManager &MPM) {
   // Count the types of instructions used
   if (AreStatisticsEnabled()) {
     MPM.addPass(createModuleToFunctionPassAdaptor(InstCountPass()));
-    MPM.addPass(createModuleToFunctionPassAdaptor(FunctionPropertiesStatisticsPass()));
+    MPM.addPass(
+      createModuleToFunctionPassAdaptor(FunctionPropertiesStatisticsPass()));
   }    
 }
 

>From 132e44021993cb8a58be6f8df837d38ae8787b78 Mon Sep 17 00:00:00 2001
From: Inaki Arrechea <inakiarrechea at google.com>
Date: Thu, 18 Dec 2025 18:55:58 +0000
Subject: [PATCH 3/7] Clang format again

---
 llvm/lib/Passes/PassBuilderPipelines.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/lib/Passes/PassBuilderPipelines.cpp b/llvm/lib/Passes/PassBuilderPipelines.cpp
index 7bb66600ab5e0..80497f5d7ca4e 100644
--- a/llvm/lib/Passes/PassBuilderPipelines.cpp
+++ b/llvm/lib/Passes/PassBuilderPipelines.cpp
@@ -413,7 +413,7 @@ void PassBuilder::invokePipelineEarlySimplificationEPCallbacks(
 // Helper to add AnnotationRemarksPass.
 static void addAnnotationRemarksPass(ModulePassManager &MPM) {
   MPM.addPass(createModuleToFunctionPassAdaptor(AnnotationRemarksPass()));
-  // Count the types of instructions used
+  // Count the types of instructions used in a module if statistics are enabled.
   if (AreStatisticsEnabled()) {
     MPM.addPass(createModuleToFunctionPassAdaptor(InstCountPass()));
     MPM.addPass(

>From 88c2dc0f42a11c88421756c20062499dd1f9286a Mon Sep 17 00:00:00 2001
From: Inaki Arrechea <inakiarrechea at google.com>
Date: Thu, 18 Dec 2025 18:59:11 +0000
Subject: [PATCH 4/7] Clang format again and again

---
 llvm/lib/Passes/PassBuilderPipelines.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/lib/Passes/PassBuilderPipelines.cpp b/llvm/lib/Passes/PassBuilderPipelines.cpp
index 80497f5d7ca4e..35300413e8ad2 100644
--- a/llvm/lib/Passes/PassBuilderPipelines.cpp
+++ b/llvm/lib/Passes/PassBuilderPipelines.cpp
@@ -417,7 +417,7 @@ static void addAnnotationRemarksPass(ModulePassManager &MPM) {
   if (AreStatisticsEnabled()) {
     MPM.addPass(createModuleToFunctionPassAdaptor(InstCountPass()));
     MPM.addPass(
-      createModuleToFunctionPassAdaptor(FunctionPropertiesStatisticsPass()));
+        createModuleToFunctionPassAdaptor(FunctionPropertiesStatisticsPass()));
   }    
 }
 

>From 48cab5de8aeb3b30325564b6711aeb686fc5639f Mon Sep 17 00:00:00 2001
From: Inaki Arrechea <inakiarrechea at google.com>
Date: Thu, 18 Dec 2025 19:01:57 +0000
Subject: [PATCH 5/7] Clang format again and again }

---
 llvm/lib/Passes/PassBuilderPipelines.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/lib/Passes/PassBuilderPipelines.cpp b/llvm/lib/Passes/PassBuilderPipelines.cpp
index 35300413e8ad2..89178f678a369 100644
--- a/llvm/lib/Passes/PassBuilderPipelines.cpp
+++ b/llvm/lib/Passes/PassBuilderPipelines.cpp
@@ -418,7 +418,7 @@ static void addAnnotationRemarksPass(ModulePassManager &MPM) {
     MPM.addPass(createModuleToFunctionPassAdaptor(InstCountPass()));
     MPM.addPass(
         createModuleToFunctionPassAdaptor(FunctionPropertiesStatisticsPass()));
-  }    
+  }
 }
 
 // Helper to check if the current compilation phase is preparing for LTO

>From 3fdc10a3502a9fed7cbc9a592644f357fd87eadf Mon Sep 17 00:00:00 2001
From: Inaki Arrechea <inakiarrechea at google.com>
Date: Fri, 19 Dec 2025 23:03:53 +0000
Subject: [PATCH 6/7] func-properties-count name of stat

---
 .../Analysis/FunctionPropertiesAnalysis.cpp   |  2 +-
 llvm/lib/Passes/PassRegistry.def              |  2 +-
 llvm/test/Other/functionpropertiesanalysis.ll | 24 +++++++++----------
 3 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/llvm/lib/Analysis/FunctionPropertiesAnalysis.cpp b/llvm/lib/Analysis/FunctionPropertiesAnalysis.cpp
index d70814c639d48..e6c4b56c5cb04 100644
--- a/llvm/lib/Analysis/FunctionPropertiesAnalysis.cpp
+++ b/llvm/lib/Analysis/FunctionPropertiesAnalysis.cpp
@@ -27,7 +27,7 @@
 
 using namespace llvm;
 
-#define DEBUG_TYPE "statscount"
+#define DEBUG_TYPE "func-properties-count"
 
 STATISTIC(TotalBlocks, "Number of basic blocks");
 STATISTIC(TotalInsts, "Number of instructions (of all types)");
diff --git a/llvm/lib/Passes/PassRegistry.def b/llvm/lib/Passes/PassRegistry.def
index 43fd1ee3ea135..1b5d9d61899dd 100644
--- a/llvm/lib/Passes/PassRegistry.def
+++ b/llvm/lib/Passes/PassRegistry.def
@@ -442,6 +442,7 @@ FUNCTION_PASS("fix-irreducible", FixIrreduciblePass())
 FUNCTION_PASS("flatten-cfg", FlattenCFGPass())
 FUNCTION_PASS("float2int", Float2IntPass())
 FUNCTION_PASS("free-machine-function", FreeMachineFunctionPass())
+FUNCTION_PASS("func-properties-count", FunctionPropertiesStatisticsPass())
 FUNCTION_PASS("gc-lowering", GCLoweringPass())
 FUNCTION_PASS("guard-widening", GuardWideningPass())
 FUNCTION_PASS("gvn-hoist", GVNHoistPass())
@@ -543,7 +544,6 @@ FUNCTION_PASS("sjlj-eh-prepare", SjLjEHPreparePass(TM))
 FUNCTION_PASS("slp-vectorizer", SLPVectorizerPass())
 FUNCTION_PASS("slsr", StraightLineStrengthReducePass())
 FUNCTION_PASS("stack-protector", StackProtectorPass(*TM))
-FUNCTION_PASS("statscount", FunctionPropertiesStatisticsPass())
 FUNCTION_PASS("strip-gc-relocates", StripGCRelocates())
 FUNCTION_PASS("tailcallelim", TailCallElimPass())
 FUNCTION_PASS("transform-warning", WarnMissedTransformationsPass())
diff --git a/llvm/test/Other/functionpropertiesanalysis.ll b/llvm/test/Other/functionpropertiesanalysis.ll
index 54f1363e8fa83..9e1cc948e54f4 100644
--- a/llvm/test/Other/functionpropertiesanalysis.ll
+++ b/llvm/test/Other/functionpropertiesanalysis.ll
@@ -1,20 +1,20 @@
 ; REQUIRES asserts
-; RUN: opt -stats -enable-detailed-function-properties -disable-output -passes=statscount < %s 2>&1 | FileCheck %s
+; RUN: opt -stats -enable-detailed-function-properties -disable-output -passes=func-properties-count < %s 2>&1 | FileCheck %s
 ; RUN: opt -stats -enable-detailed-function-properties -disable-output -passes='thinlto<O3>'< %s 2>&1 | FileCheck %s
 ; RUN: opt -stats -enable-detailed-function-properties -disable-output -passes='thinlto-pre-link<O2>' < %s 2>&1 | FileCheck %s
 ; RUN: opt -stats -enable-detailed-function-properties -disable-output -passes='lto<O1>' < %s 2>&1 | FileCheck %s
-; RUN: opt -stats -enable-detailed-function-properties -disable-output -passes='default<O3>' < %s 2>&1 | FileCheck %s
-; RUN: opt -stats -enable-detailed-function-properties -disable-output -passes='default<O0>' < %s 2>&1 | FileCheck %s
+; RUN: opt -stats -enable-detailed-function-properties -disable-output -O3 < %s 2>&1 | FileCheck %s
+; RUN: opt -stats -enable-detailed-function-properties -disable-output -O0 < %s 2>&1 | FileCheck %s
 
-; CHECK-DAG: 10 statscount - Number of basic blocks
-; CHECK-DAG: 8 statscount - Number of branch instructions
-; CHECK-DAG: 10 statscount - Number of branch successors
-; CHECK-DAG: 2 statscount - Number of conditional branch instructions
-; CHECK-DAG: 18 statscount - Number of instructions (of all types)
-; CHECK-DAG: 14 statscount - Number of basic block successors
-; CHECK-DAG: 1 statscount - Number of switch instructions
-; CHECK-DAG: 4 statscount - Number of switch successors
-; CHECK-DAG: 6 statscount - Number of unconditional branch instructions
+; CHECK-DAG: 10 func-properties-count - Number of basic blocks
+; CHECK-DAG: 8 func-properties-count - Number of branch instructions
+; CHECK-DAG: 10 func-properties-count - Number of branch successors
+; CHECK-DAG: 2 func-properties-count - Number of conditional branch instructions
+; CHECK-DAG: 18 func-properties-count - Number of instructions (of all types)
+; CHECK-DAG: 14 func-properties-count - Number of basic block successors
+; CHECK-DAG: 1 func-properties-count - Number of switch instructions
+; CHECK-DAG: 4 func-properties-count - Number of switch successors
+; CHECK-DAG: 6 func-properties-count - Number of unconditional branch instructions
 
 
 define void @foo(i32 %i, i32 %j, i32 %n) {

>From ce5fbff81e21d5576117d028aeb1398266ffb91c Mon Sep 17 00:00:00 2001
From: Inaki Arrechea <inakiarrechea at google.com>
Date: Fri, 26 Dec 2025 17:54:11 +0000
Subject: [PATCH 7/7] Updated syntax and descriptions

---
 .../Analysis/FunctionPropertiesAnalysis.h     |  2 +-
 .../Analysis/FunctionPropertiesAnalysis.cpp   |  6 ++---
 llvm/lib/Passes/PassBuilderPipelines.cpp      |  2 +-
 llvm/lib/Passes/PassRegistry.def              |  2 +-
 llvm/test/Other/functionpropertiesanalysis.ll | 23 ++++++++++---------
 llvm/test/Other/instcount.ll                  |  2 +-
 6 files changed, 19 insertions(+), 18 deletions(-)

diff --git a/llvm/include/llvm/Analysis/FunctionPropertiesAnalysis.h b/llvm/include/llvm/Analysis/FunctionPropertiesAnalysis.h
index a2923f74805da..1619671d8f7dc 100644
--- a/llvm/include/llvm/Analysis/FunctionPropertiesAnalysis.h
+++ b/llvm/include/llvm/Analysis/FunctionPropertiesAnalysis.h
@@ -187,7 +187,7 @@ class FunctionPropertiesPrinterPass
 /// Statistics pass for the FunctionPropertiesAnalysis results.
 struct FunctionPropertiesStatisticsPass
     : PassInfoMixin<FunctionPropertiesStatisticsPass> {
-  PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
+  PreservedAnalyses run(Function &F, FunctionAnalysisManager &FAM);
 };
 
 /// Correctly update FunctionPropertiesInfo post-inlining. A
diff --git a/llvm/lib/Analysis/FunctionPropertiesAnalysis.cpp b/llvm/lib/Analysis/FunctionPropertiesAnalysis.cpp
index e6c4b56c5cb04..8dcda876a1202 100644
--- a/llvm/lib/Analysis/FunctionPropertiesAnalysis.cpp
+++ b/llvm/lib/Analysis/FunctionPropertiesAnalysis.cpp
@@ -27,7 +27,7 @@
 
 using namespace llvm;
 
-#define DEBUG_TYPE "func-properties-count"
+#define DEBUG_TYPE "func-properties-stats"
 
 STATISTIC(TotalBlocks, "Number of basic blocks");
 STATISTIC(TotalInsts, "Number of instructions (of all types)");
@@ -427,10 +427,10 @@ FunctionPropertiesPrinterPass::run(Function &F, FunctionAnalysisManager &AM) {
 
 PreservedAnalyses
 FunctionPropertiesStatisticsPass::run(Function &F,
-                                      FunctionAnalysisManager &AM) {
+                                      FunctionAnalysisManager &FAM) {
   LLVM_DEBUG(dbgs() << "STATSCOUNT: running on function " << F.getName()
                     << "\n");
-  auto &AnalysisResults = AM.getResult<FunctionPropertiesAnalysis>(F);
+  auto &AnalysisResults = FAM.getResult<FunctionPropertiesAnalysis>(F);
   TotalBlocks += AnalysisResults.BasicBlockCount;
   TotalInsts += AnalysisResults.TotalInstructionCount;
   TotalSuccs += AnalysisResults.ControlFlowEdgeCount;
diff --git a/llvm/lib/Passes/PassBuilderPipelines.cpp b/llvm/lib/Passes/PassBuilderPipelines.cpp
index 89178f678a369..555d96838d758 100644
--- a/llvm/lib/Passes/PassBuilderPipelines.cpp
+++ b/llvm/lib/Passes/PassBuilderPipelines.cpp
@@ -413,7 +413,7 @@ void PassBuilder::invokePipelineEarlySimplificationEPCallbacks(
 // Helper to add AnnotationRemarksPass.
 static void addAnnotationRemarksPass(ModulePassManager &MPM) {
   MPM.addPass(createModuleToFunctionPassAdaptor(AnnotationRemarksPass()));
-  // Count the types of instructions used in a module if statistics are enabled.
+  // Count the stats for InstCount and FunctionPropertiesAnalysis
   if (AreStatisticsEnabled()) {
     MPM.addPass(createModuleToFunctionPassAdaptor(InstCountPass()));
     MPM.addPass(
diff --git a/llvm/lib/Passes/PassRegistry.def b/llvm/lib/Passes/PassRegistry.def
index 1b5d9d61899dd..bf113fae3e611 100644
--- a/llvm/lib/Passes/PassRegistry.def
+++ b/llvm/lib/Passes/PassRegistry.def
@@ -442,7 +442,7 @@ FUNCTION_PASS("fix-irreducible", FixIrreduciblePass())
 FUNCTION_PASS("flatten-cfg", FlattenCFGPass())
 FUNCTION_PASS("float2int", Float2IntPass())
 FUNCTION_PASS("free-machine-function", FreeMachineFunctionPass())
-FUNCTION_PASS("func-properties-count", FunctionPropertiesStatisticsPass())
+FUNCTION_PASS("func-properties-stats", FunctionPropertiesStatisticsPass())
 FUNCTION_PASS("gc-lowering", GCLoweringPass())
 FUNCTION_PASS("guard-widening", GuardWideningPass())
 FUNCTION_PASS("gvn-hoist", GVNHoistPass())
diff --git a/llvm/test/Other/functionpropertiesanalysis.ll b/llvm/test/Other/functionpropertiesanalysis.ll
index 9e1cc948e54f4..a3367cc6ffdd1 100644
--- a/llvm/test/Other/functionpropertiesanalysis.ll
+++ b/llvm/test/Other/functionpropertiesanalysis.ll
@@ -1,20 +1,21 @@
+; Testing with all of the below run lines that the pass gets added to the appropriate pipelines
 ; REQUIRES asserts
-; RUN: opt -stats -enable-detailed-function-properties -disable-output -passes=func-properties-count < %s 2>&1 | FileCheck %s
+; RUN: opt -stats -enable-detailed-function-properties -disable-output -passes=func-properties-stats < %s 2>&1 | FileCheck %s
 ; RUN: opt -stats -enable-detailed-function-properties -disable-output -passes='thinlto<O3>'< %s 2>&1 | FileCheck %s
 ; RUN: opt -stats -enable-detailed-function-properties -disable-output -passes='thinlto-pre-link<O2>' < %s 2>&1 | FileCheck %s
 ; RUN: opt -stats -enable-detailed-function-properties -disable-output -passes='lto<O1>' < %s 2>&1 | FileCheck %s
 ; RUN: opt -stats -enable-detailed-function-properties -disable-output -O3 < %s 2>&1 | FileCheck %s
 ; RUN: opt -stats -enable-detailed-function-properties -disable-output -O0 < %s 2>&1 | FileCheck %s
 
-; CHECK-DAG: 10 func-properties-count - Number of basic blocks
-; CHECK-DAG: 8 func-properties-count - Number of branch instructions
-; CHECK-DAG: 10 func-properties-count - Number of branch successors
-; CHECK-DAG: 2 func-properties-count - Number of conditional branch instructions
-; CHECK-DAG: 18 func-properties-count - Number of instructions (of all types)
-; CHECK-DAG: 14 func-properties-count - Number of basic block successors
-; CHECK-DAG: 1 func-properties-count - Number of switch instructions
-; CHECK-DAG: 4 func-properties-count - Number of switch successors
-; CHECK-DAG: 6 func-properties-count - Number of unconditional branch instructions
+; CHECK-DAG: 10 func-properties-stats - Number of basic blocks
+; CHECK-DAG: 8 func-properties-stats - Number of branch instructions
+; CHECK-DAG: 10 func-properties-stats - Number of branch successors
+; CHECK-DAG: 2 func-properties-stats - Number of conditional branch instructions
+; CHECK-DAG: 18 func-properties-stats - Number of instructions (of all types)
+; CHECK-DAG: 14 func-properties-stats - Number of basic block successors
+; CHECK-DAG: 1 func-properties-stats - Number of switch instructions
+; CHECK-DAG: 4 func-properties-stats - Number of switch successors
+; CHECK-DAG: 6 func-properties-stats - Number of unconditional branch instructions
 
 
 define void @foo(i32 %i, i32 %j, i32 %n) {
@@ -66,4 +67,4 @@ declare void @g()
 declare void @h()
 declare void @k()
 declare void @l()
-declare void @m()
\ No newline at end of file
+declare void @m()
diff --git a/llvm/test/Other/instcount.ll b/llvm/test/Other/instcount.ll
index c9dab9e93cfb7..931d547371958 100644
--- a/llvm/test/Other/instcount.ll
+++ b/llvm/test/Other/instcount.ll
@@ -66,4 +66,4 @@ declare void @g()
 declare void @h()
 declare void @k()
 declare void @l()
-declare void @m()
\ No newline at end of file
+declare void @m()



More information about the llvm-commits mailing list