From 33666b5b6a92e0bf32aad1e1d917da1e4445ab7f Mon Sep 17 00:00:00 2001 From: Inaki Arrechea Date: Thu, 18 Dec 2025 18:18:07 +0000 Subject: [PATCH 1/9] 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 { + 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 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(BB.getTerminator())) { - if (!BI->isConditional()) + const Instruction *TI = BB.getTerminator(); + const int64_t InstructionSuccessorCount = TI->getNumSuccessors(); + if (isa(TI)) { + BranchInstructionCount += Direction; + BranchSuccessorCount += Direction * InstructionSuccessorCount; + const auto *BI = dyn_cast(TI); + if (BI->isConditional()) + ConditionalBranchCount += Direction; + else UnconditionalBranchCount += Direction; + } else if (isa(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(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 daf6b3d6dbd28..55f1c309aaa95 100644 --- a/llvm/lib/Passes/PassRegistry.def +++ b/llvm/lib/Passes/PassRegistry.def @@ -542,6 +542,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'< %s 2>&1 | FileCheck %s +; RUN: opt -stats -enable-detailed-function-properties -disable-output -passes='thinlto-pre-link' < %s 2>&1 | FileCheck %s +; RUN: opt -stats -enable-detailed-function-properties -disable-output -passes='lto' < %s 2>&1 | FileCheck %s +; RUN: opt -stats -enable-detailed-function-properties -disable-output -passes='default' < %s 2>&1 | FileCheck %s +; RUN: opt -stats -enable-detailed-function-properties -disable-output -passes='default' < %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 cfe6a41d9bc80f827ee0bf7907859d6bef015891 Mon Sep 17 00:00:00 2001 From: Inaki Arrechea Date: Thu, 18 Dec 2025 18:48:38 +0000 Subject: [PATCH 2/9] 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 8fad9c05459226b994292c4640d42a12b072e2bd Mon Sep 17 00:00:00 2001 From: Inaki Arrechea Date: Thu, 18 Dec 2025 18:55:58 +0000 Subject: [PATCH 3/9] 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 0d1c334c163c733f57f6e00b8b77b059bd93b8b8 Mon Sep 17 00:00:00 2001 From: Inaki Arrechea Date: Thu, 18 Dec 2025 18:59:11 +0000 Subject: [PATCH 4/9] 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 0f36c80469a06c73feddd8d485555947bef862d2 Mon Sep 17 00:00:00 2001 From: Inaki Arrechea Date: Thu, 18 Dec 2025 19:01:57 +0000 Subject: [PATCH 5/9] 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 1c00df2d10213b294a2438f7f02fb0e0bfac9dc9 Mon Sep 17 00:00:00 2001 From: Inaki Arrechea Date: Fri, 19 Dec 2025 23:03:53 +0000 Subject: [PATCH 6/9] 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 55f1c309aaa95..520d95ec30e83 100644 --- a/llvm/lib/Passes/PassRegistry.def +++ b/llvm/lib/Passes/PassRegistry.def @@ -441,6 +441,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()) @@ -542,7 +543,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'< %s 2>&1 | FileCheck %s ; RUN: opt -stats -enable-detailed-function-properties -disable-output -passes='thinlto-pre-link' < %s 2>&1 | FileCheck %s ; RUN: opt -stats -enable-detailed-function-properties -disable-output -passes='lto' < %s 2>&1 | FileCheck %s -; RUN: opt -stats -enable-detailed-function-properties -disable-output -passes='default' < %s 2>&1 | FileCheck %s -; RUN: opt -stats -enable-detailed-function-properties -disable-output -passes='default' < %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 deaf0210211ab0ddcd68ee8867c5435d0752d9e8 Mon Sep 17 00:00:00 2001 From: Inaki Arrechea Date: Fri, 26 Dec 2025 17:54:11 +0000 Subject: [PATCH 7/9] Updated colon --- .../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 | 25 ++++++++++--------- llvm/test/Other/instcount.ll | 2 +- 6 files changed, 20 insertions(+), 19 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 { - 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(F); + auto &AnalysisResults = FAM.getResult(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 520d95ec30e83..2cfb5b2592601 100644 --- a/llvm/lib/Passes/PassRegistry.def +++ b/llvm/lib/Passes/PassRegistry.def @@ -441,7 +441,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..e7a526b385e44 100644 --- a/llvm/test/Other/functionpropertiesanalysis.ll +++ b/llvm/test/Other/functionpropertiesanalysis.ll @@ -1,20 +1,21 @@ -; REQUIRES asserts -; RUN: opt -stats -enable-detailed-function-properties -disable-output -passes=func-properties-count < %s 2>&1 | FileCheck %s +; 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-stats < %s 2>&1 | FileCheck %s ; RUN: opt -stats -enable-detailed-function-properties -disable-output -passes='thinlto'< %s 2>&1 | FileCheck %s ; RUN: opt -stats -enable-detailed-function-properties -disable-output -passes='thinlto-pre-link' < %s 2>&1 | FileCheck %s ; RUN: opt -stats -enable-detailed-function-properties -disable-output -passes='lto' < %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() From 9b042e50877f01ab80e6ab5bcf8ca877eb735336 Mon Sep 17 00:00:00 2001 From: Inaki Arrechea Date: Mon, 29 Dec 2025 20:59:27 +0000 Subject: [PATCH 8/9] Added macro with stats --- llvm/include/llvm/IR/FunctionProperties.def | 35 +++++++++++++++++++ .../Analysis/FunctionPropertiesAnalysis.cpp | 34 ++++++------------ 2 files changed, 46 insertions(+), 23 deletions(-) create mode 100644 llvm/include/llvm/IR/FunctionProperties.def diff --git a/llvm/include/llvm/IR/FunctionProperties.def b/llvm/include/llvm/IR/FunctionProperties.def new file mode 100644 index 0000000000000..42ee4b280978a --- /dev/null +++ b/llvm/include/llvm/IR/FunctionProperties.def @@ -0,0 +1,35 @@ +//===-- llvm/FunctionProperties.def - File that describes Function Properties -*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// This file contains descriptions of the various LLVM function properties. This is +// used as a central place for enumerating the different function properties and +// should eventually be the place to put comments about the function properties. +// +//===----------------------------------------------------------------------===// + +// NOTE: NO INCLUDE GUARD DESIRED! + +// Provide definitions of macros so that users of this file do not have to +// define everything to use it... +// + +#ifndef FUNCTION_PROPERTY +#define FUNCTION_PROPERTY(Name, Description) +#endif + +FUNCTION_PROPERTY(BasicBlockCount, "Number of basic blocks") +FUNCTION_PROPERTY(TotalInstructionCount, "Number of instructions (of all types)") +FUNCTION_PROPERTY(ControlFlowEdgeCount, "Number of basic block successors") +FUNCTION_PROPERTY(UnconditionalBranchCount, "Number of unconditional branch instructions") +FUNCTION_PROPERTY(ConditionalBranchCount, "Number of conditional branch instructions") +FUNCTION_PROPERTY(BranchInstructionCount, "Number of branch instructions") +FUNCTION_PROPERTY(BranchSuccessorCount, "Number of branch successors") +FUNCTION_PROPERTY(SwitchInstructionCount, "Number of switch instructions") +FUNCTION_PROPERTY(SwitchSuccessorCount, "Number of switch successors") + +#undef FUNCTION_PROPERTY diff --git a/llvm/lib/Analysis/FunctionPropertiesAnalysis.cpp b/llvm/lib/Analysis/FunctionPropertiesAnalysis.cpp index 8dcda876a1202..c9519ea5d186e 100644 --- a/llvm/lib/Analysis/FunctionPropertiesAnalysis.cpp +++ b/llvm/lib/Analysis/FunctionPropertiesAnalysis.cpp @@ -29,16 +29,9 @@ using namespace llvm; #define DEBUG_TYPE "func-properties-stats" -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"); +#define FUNCTION_PROPERTY(Name, Description) \ + STATISTIC(Total##Name, Description); +#include "llvm/IR/FunctionProperties.def" namespace llvm { LLVM_ABI cl::opt EnableDetailedFunctionProperties( @@ -426,20 +419,15 @@ FunctionPropertiesPrinterPass::run(Function &F, FunctionAnalysisManager &AM) { } PreservedAnalyses -FunctionPropertiesStatisticsPass::run(Function &F, - FunctionAnalysisManager &FAM) { - LLVM_DEBUG(dbgs() << "STATSCOUNT: running on function " << F.getName() - << "\n"); +FunctionPropertiesStatisticsPass::run(Function &F, FunctionAnalysisManager &FAM) { + LLVM_DEBUG(dbgs() << "STATSCOUNT: running on function " << F.getName() << "\n"); auto &AnalysisResults = FAM.getResult(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; + + // Use the macro to generate the summation lines + #define FUNCTION_PROPERTY(Name, Description) \ + Total##Name += AnalysisResults.Name; + #include "llvm/IR/FunctionProperties.def" + return PreservedAnalyses::all(); } From eebacad7897e4443c0b25865e208b3c1dfeafb0b Mon Sep 17 00:00:00 2001 From: Inaki Arrechea Date: Tue, 30 Dec 2025 20:46:28 +0000 Subject: [PATCH 9/9] Clang format --- llvm/include/llvm/IR/FunctionProperties.def | 96 ++++++++++++++++--- .../Analysis/FunctionPropertiesAnalysis.cpp | 82 ++++------------ llvm/test/Other/functionpropertiesanalysis.ll | 2 +- 3 files changed, 105 insertions(+), 75 deletions(-) diff --git a/llvm/include/llvm/IR/FunctionProperties.def b/llvm/include/llvm/IR/FunctionProperties.def index 42ee4b280978a..a212af4859877 100644 --- a/llvm/include/llvm/IR/FunctionProperties.def +++ b/llvm/include/llvm/IR/FunctionProperties.def @@ -1,4 +1,4 @@ -//===-- llvm/FunctionProperties.def - File that describes Function Properties -*- C++ -*-===// +//===-- llvm/FunctionProperties.def - File that describes Function Properties // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -6,30 +6,100 @@ // //===----------------------------------------------------------------------===// // -// This file contains descriptions of the various LLVM function properties. This is -// used as a central place for enumerating the different function properties and -// should eventually be the place to put comments about the function properties. +// This file contains descriptions of the various LLVM function properties. This +// is used as a central place for enumerating the different function properties +// and should eventually be the place to put comments about the function +// properties. // //===----------------------------------------------------------------------===// // NOTE: NO INCLUDE GUARD DESIRED! // Provide definitions of macros so that users of this file do not have to -// define everything to use it... +// define everything to use it. // +// Basic/Standard Properties #ifndef FUNCTION_PROPERTY #define FUNCTION_PROPERTY(Name, Description) #endif +// Detailed Properties (only processed if DETAILED_FUNCTION_PROPERTY is defined) +#ifndef DETAILED_FUNCTION_PROPERTY +#define DETAILED_FUNCTION_PROPERTY(Name, Description) +#endif + FUNCTION_PROPERTY(BasicBlockCount, "Number of basic blocks") -FUNCTION_PROPERTY(TotalInstructionCount, "Number of instructions (of all types)") -FUNCTION_PROPERTY(ControlFlowEdgeCount, "Number of basic block successors") -FUNCTION_PROPERTY(UnconditionalBranchCount, "Number of unconditional branch instructions") -FUNCTION_PROPERTY(ConditionalBranchCount, "Number of conditional branch instructions") -FUNCTION_PROPERTY(BranchInstructionCount, "Number of branch instructions") -FUNCTION_PROPERTY(BranchSuccessorCount, "Number of branch successors") -FUNCTION_PROPERTY(SwitchInstructionCount, "Number of switch instructions") -FUNCTION_PROPERTY(SwitchSuccessorCount, "Number of switch successors") +FUNCTION_PROPERTY(BlocksReachedFromConditionalInstruction, + "Number of blocks reached from a conditional instruction, or " + "that are 'cases' of a SwitchInstr") +FUNCTION_PROPERTY(Uses, "Number of uses of this function, plus 1 if the " + "function is callable outside the module") +FUNCTION_PROPERTY(DirectCallsToDefinedFunctions, + "Number of direct calls made from this function to other " + "functions defined in this module") +FUNCTION_PROPERTY(LoadInstCount, "Load Instruction Count") +FUNCTION_PROPERTY(StoreInstCount, "Store Instruction Count") +FUNCTION_PROPERTY(MaxLoopDepth, "Maximum Loop Depth in the Function") +FUNCTION_PROPERTY(TopLevelLoopCount, + "Number of Top Level Loops in the Function") +FUNCTION_PROPERTY(TotalInstructionCount, + "Number of instructions (of all types)") +DETAILED_FUNCTION_PROPERTY(BasicBlocksWithSingleSuccessor, + "Basic blocks with one successors") +DETAILED_FUNCTION_PROPERTY(BasicBlocksWithTwoSuccessors, + "Basic blocks with two successors") +DETAILED_FUNCTION_PROPERTY(BasicBlocksWithMoreThanTwoSuccessors, + "Basic blocks with more than two successors") +DETAILED_FUNCTION_PROPERTY(BasicBlocksWithSinglePredecessor, + "Basic blocks with one predecessors") +DETAILED_FUNCTION_PROPERTY(BasicBlocksWithTwoPredecessors, + "Basic blocks with two predecessors") +DETAILED_FUNCTION_PROPERTY(BasicBlocksWithMoreThanTwoPredecessors, + "Basic blocks with more than two predecessors") +DETAILED_FUNCTION_PROPERTY(BigBasicBlocks, "Number of big basic blocks") +DETAILED_FUNCTION_PROPERTY(MediumBasicBlocks, "Number of medium basic blocks") +DETAILED_FUNCTION_PROPERTY(SmallBasicBlocks, "Number of small basic blocks") +DETAILED_FUNCTION_PROPERTY(CastInstructionCount, + "The number of cast instructions inside the function") +DETAILED_FUNCTION_PROPERTY( + FloatingPointInstructionCount, + "The number of floating point instructions inside the function") +DETAILED_FUNCTION_PROPERTY(IntegerInstructionCount, + "The number of integer instructions inside the function") +DETAILED_FUNCTION_PROPERTY(ConstantIntOperandCount, "Constant Int Operand Count") +DETAILED_FUNCTION_PROPERTY(ConstantFPOperandCount, "Constant FP Operand Count") +DETAILED_FUNCTION_PROPERTY(ConstantOperandCount, "Constant Operand Count") +DETAILED_FUNCTION_PROPERTY(InstructionOperandCount, "Instruction Operand Count") +DETAILED_FUNCTION_PROPERTY(BasicBlockOperandCount, "Basic Block Operand Count") +DETAILED_FUNCTION_PROPERTY(GlobalValueOperandCount, "Global Value Operand Count") +DETAILED_FUNCTION_PROPERTY(InlineAsmOperandCount, "Inline Asm Operand Count") +DETAILED_FUNCTION_PROPERTY(ArgumentOperandCount, "Argument Operand Count") +DETAILED_FUNCTION_PROPERTY(UnknownOperandCount, "Unknown Operand Count") +DETAILED_FUNCTION_PROPERTY(CriticalEdgeCount, "Critical Edge Count") +DETAILED_FUNCTION_PROPERTY(ControlFlowEdgeCount, "Number of basic block successors") +DETAILED_FUNCTION_PROPERTY(UnconditionalBranchCount, + "Number of unconditional branch instructions") +DETAILED_FUNCTION_PROPERTY(ConditionalBranchCount, + "Number of conditional branch instructions") +DETAILED_FUNCTION_PROPERTY(BranchInstructionCount, "Number of branch instructions") +DETAILED_FUNCTION_PROPERTY(BranchSuccessorCount, "Number of branch successors") +DETAILED_FUNCTION_PROPERTY(SwitchInstructionCount, "Number of switch instructions") +DETAILED_FUNCTION_PROPERTY(SwitchSuccessorCount, "Number of switch successors") +DETAILED_FUNCTION_PROPERTY(IntrinsicCount, "Intrinsic Count") +DETAILED_FUNCTION_PROPERTY(DirectCallCount, "Direct Call Count") +DETAILED_FUNCTION_PROPERTY(IndirectCallCount, "Indirect Call Count") +DETAILED_FUNCTION_PROPERTY(CallReturnsIntegerCount, "Call Returns Integer Count") +DETAILED_FUNCTION_PROPERTY(CallReturnsFloatCount, "Call Returns Float Count") +DETAILED_FUNCTION_PROPERTY(CallReturnsPointerCount, "Call Returns Pointer Count") +DETAILED_FUNCTION_PROPERTY(CallReturnsVectorIntCount, "Call Returns Vector Int Count") +DETAILED_FUNCTION_PROPERTY(CallReturnsVectorFloatCount, + "Call Returns Vector Float Count") +DETAILED_FUNCTION_PROPERTY(CallReturnsVectorPointerCount, + "Call Returns Vector Pointer Count") +DETAILED_FUNCTION_PROPERTY(CallWithManyArgumentsCount, "Call With Many Arguments Count") +DETAILED_FUNCTION_PROPERTY(CallWithPointerArgumentCount, + "Call With Pointer Argument Count") #undef FUNCTION_PROPERTY +#undef DETAILED_FUNCTION_PROPERTY diff --git a/llvm/lib/Analysis/FunctionPropertiesAnalysis.cpp b/llvm/lib/Analysis/FunctionPropertiesAnalysis.cpp index c9519ea5d186e..1f6792dfe30ec 100644 --- a/llvm/lib/Analysis/FunctionPropertiesAnalysis.cpp +++ b/llvm/lib/Analysis/FunctionPropertiesAnalysis.cpp @@ -29,8 +29,10 @@ using namespace llvm; #define DEBUG_TYPE "func-properties-stats" -#define FUNCTION_PROPERTY(Name, Description) \ - STATISTIC(Total##Name, Description); +#define FUNCTION_PROPERTY(Name, Description) \ + STATISTIC(Total##Name, Description); +#define DETAILED_FUNCTION_PROPERTY(Name, Description) \ + STATISTIC(Total##Name, Description); #include "llvm/IR/FunctionProperties.def" namespace llvm { @@ -342,62 +344,17 @@ bool FunctionPropertiesInfo::operator==( } void FunctionPropertiesInfo::print(raw_ostream &OS) const { -#define PRINT_PROPERTY(PROP_NAME) OS << #PROP_NAME ": " << PROP_NAME << "\n"; - - PRINT_PROPERTY(BasicBlockCount) - PRINT_PROPERTY(BlocksReachedFromConditionalInstruction) - PRINT_PROPERTY(Uses) - PRINT_PROPERTY(DirectCallsToDefinedFunctions) - PRINT_PROPERTY(LoadInstCount) - PRINT_PROPERTY(StoreInstCount) - PRINT_PROPERTY(MaxLoopDepth) - PRINT_PROPERTY(TopLevelLoopCount) - PRINT_PROPERTY(TotalInstructionCount) +#define FUNCTION_PROPERTY(Name, Description) OS << #Name ": " << Name << "\n"; - if (EnableDetailedFunctionProperties) { - PRINT_PROPERTY(BasicBlocksWithSingleSuccessor) - PRINT_PROPERTY(BasicBlocksWithTwoSuccessors) - PRINT_PROPERTY(BasicBlocksWithMoreThanTwoSuccessors) - PRINT_PROPERTY(BasicBlocksWithSinglePredecessor) - PRINT_PROPERTY(BasicBlocksWithTwoPredecessors) - PRINT_PROPERTY(BasicBlocksWithMoreThanTwoPredecessors) - PRINT_PROPERTY(BigBasicBlocks) - PRINT_PROPERTY(MediumBasicBlocks) - PRINT_PROPERTY(SmallBasicBlocks) - PRINT_PROPERTY(CastInstructionCount) - PRINT_PROPERTY(FloatingPointInstructionCount) - PRINT_PROPERTY(IntegerInstructionCount) - PRINT_PROPERTY(ConstantIntOperandCount) - PRINT_PROPERTY(ConstantFPOperandCount) - PRINT_PROPERTY(ConstantOperandCount) - PRINT_PROPERTY(InstructionOperandCount) - PRINT_PROPERTY(BasicBlockOperandCount) - PRINT_PROPERTY(GlobalValueOperandCount) - PRINT_PROPERTY(InlineAsmOperandCount) - PRINT_PROPERTY(ArgumentOperandCount) - PRINT_PROPERTY(UnknownOperandCount) - 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) - PRINT_PROPERTY(CallReturnsIntegerCount) - PRINT_PROPERTY(CallReturnsFloatCount) - PRINT_PROPERTY(CallReturnsPointerCount) - PRINT_PROPERTY(CallReturnsVectorIntCount) - PRINT_PROPERTY(CallReturnsVectorFloatCount) - PRINT_PROPERTY(CallReturnsVectorPointerCount) - PRINT_PROPERTY(CallWithManyArgumentsCount) - PRINT_PROPERTY(CallWithPointerArgumentCount) +#define DETAILED_FUNCTION_PROPERTY(Name, Description) \ + if (EnableDetailedFunctionProperties) { \ + OS << #Name ": " << Name << "\n"; \ } -#undef PRINT_PROPERTY +#include "llvm/IR/FunctionProperties.def" + +#undef FUNCTION_PROPERTY +#undef DETAILED_FUNCTION_PROPERTY OS << "\n"; } @@ -419,14 +376,17 @@ FunctionPropertiesPrinterPass::run(Function &F, FunctionAnalysisManager &AM) { } PreservedAnalyses -FunctionPropertiesStatisticsPass::run(Function &F, FunctionAnalysisManager &FAM) { - LLVM_DEBUG(dbgs() << "STATSCOUNT: running on function " << F.getName() << "\n"); +FunctionPropertiesStatisticsPass::run(Function &F, + FunctionAnalysisManager &FAM) { + LLVM_DEBUG(dbgs() << "STATSCOUNT: running on function " << F.getName() + << "\n"); auto &AnalysisResults = FAM.getResult(F); - // Use the macro to generate the summation lines - #define FUNCTION_PROPERTY(Name, Description) \ - Total##Name += AnalysisResults.Name; - #include "llvm/IR/FunctionProperties.def" +#define FUNCTION_PROPERTY(Name, Description) \ + Total##Name += AnalysisResults.Name; +#define DETAILED_FUNCTION_PROPERTY(Name, Description) \ + Total##Name += AnalysisResults.Name; +#include "llvm/IR/FunctionProperties.def" return PreservedAnalyses::all(); } diff --git a/llvm/test/Other/functionpropertiesanalysis.ll b/llvm/test/Other/functionpropertiesanalysis.ll index e7a526b385e44..06da908d63974 100644 --- a/llvm/test/Other/functionpropertiesanalysis.ll +++ b/llvm/test/Other/functionpropertiesanalysis.ll @@ -11,11 +11,11 @@ ; 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: 6 func-properties-stats - Number of unconditional 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) {