Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
8618bf0
Inst Count implemented for metrics pass
InakiVA Dec 10, 2025
c43bd80
Whitespace fix
InakiVA Dec 10, 2025
777eb40
Whitespace fix
InakiVA Dec 10, 2025
a188066
Merge branch 'main' into 3metrics
InakiVA Dec 10, 2025
77deef8
Format
InakiVA Dec 10, 2025
b04f06d
Merge branch 'main' into 3metrics
InakiVA Dec 10, 2025
d0077b5
Merge branch 'main' into 3metrics
InakiVA Dec 10, 2025
2c16734
Merge branch 'main' into 3metrics
InakiVA Dec 10, 2025
9fd9380
One check on test fix
InakiVA Dec 11, 2025
3c8722d
Test case simplified
InakiVA Dec 11, 2025
5f8a669
Clang format applied
InakiVA Dec 11, 2025
3f158a9
Merge branch 'main' into 3metrics
InakiVA Dec 11, 2025
378d928
Format retry
InakiVA Dec 11, 2025
8e04b3b
Passes test implementation successful
InakiVA Dec 11, 2025
8b303b2
Passes test implementation successful
InakiVA Dec 11, 2025
9a73888
Merge branch 'main' into 3metrics
InakiVA Dec 11, 2025
7d96aa4
Clang format my change
InakiVA Dec 11, 2025
5f44ea3
Merge branch 'main' into 3metrics
InakiVA Dec 11, 2025
388cbc5
PassBuilderPipelines pass updated
InakiVA Dec 11, 2025
5c1651e
Merge branch 'main' into 3metrics
InakiVA Dec 11, 2025
2b43d95
Merge branch 'llvm:main' into 3metrics
InakiVA Dec 11, 2025
b319de5
Use of correct method substitution
InakiVA Dec 11, 2025
ec35728
Merge branch 'main' into 3metrics
InakiVA Dec 11, 2025
10ad117
Merge branch 'main' into 3metrics
InakiVA Dec 12, 2025
92219f9
Merge branch 'main' into 3metrics
InakiVA Dec 12, 2025
40fbac7
Merge branch 'main' into 3metrics
InakiVA Dec 12, 2025
30b0ec3
Merge branch 'main' into 3metrics
InakiVA Dec 12, 2025
ea3b02b
Removed empty line
InakiVA Dec 12, 2025
ea58073
Merge branch 'main' into 3metrics
InakiVA Dec 12, 2025
2d9e5d4
REQUIRES header added to test
InakiVA Dec 12, 2025
d799563
Merge branch 'main' into 3metrics
InakiVA Dec 13, 2025
1c1a69e
Merge branch 'main' into 3metrics
InakiVA Dec 15, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion llvm/lib/Passes/PassBuilderPipelines.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "llvm/Analysis/CtxProfAnalysis.h"
#include "llvm/Analysis/GlobalsModRef.h"
#include "llvm/Analysis/InlineAdvisor.h"
#include "llvm/Analysis/InstCount.h"
#include "llvm/Analysis/ProfileSummaryInfo.h"
#include "llvm/Analysis/ScopedNoAliasAA.h"
#include "llvm/Analysis/TypeBasedAliasAnalysis.h"
Expand Down Expand Up @@ -411,6 +412,9 @@ void PassBuilder::invokePipelineEarlySimplificationEPCallbacks(
// Helper to add AnnotationRemarksPass.
static void addAnnotationRemarksPass(ModulePassManager &MPM) {
MPM.addPass(createModuleToFunctionPassAdaptor(AnnotationRemarksPass()));
// Count the types of instructions used
if (AreStatisticsEnabled())
MPM.addPass(createModuleToFunctionPassAdaptor(InstCountPass()));
}

// Helper to check if the current compilation phase is preparing for LTO
Expand Down Expand Up @@ -2420,7 +2424,8 @@ PassBuilder::buildO0DefaultPipeline(OptimizationLevel Level,
if (isLTOPreLink(Phase))
addRequiredLTOPreLinkPasses(MPM);

MPM.addPass(createModuleToFunctionPassAdaptor(AnnotationRemarksPass()));
// Emit annotation remarks.
addAnnotationRemarksPass(MPM);

return MPM;
}
Expand Down
69 changes: 69 additions & 0 deletions llvm/test/Other/instcount.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
; REQUIRES: asserts
; RUN: opt -stats -passes=instcount -disable-output < %s 2>&1 | FileCheck %s
; RUN: opt -stats -passes='thinlto<O3>' -disable-output < %s 2>&1 | FileCheck %s
; RUN: opt -stats -passes='thinlto-pre-link<O2>' -disable-output < %s 2>&1 | FileCheck %s
; RUN: opt -stats -passes='lto<O1>' -disable-output < %s 2>&1 | FileCheck %s
; RUN: opt -stats -passes='lto-pre-link<Os>' -disable-output < %s 2>&1 | FileCheck %s
; RUN: opt -stats -O3 -disable-output < %s 2>&1 | FileCheck %s
; RUN: opt -stats -O0 -disable-output < %s 2>&1 | FileCheck %s

; CHECK-DAG: 8 instcount - Number of Br insts
; CHECK-DAG: 6 instcount - Number of Call insts
; CHECK-DAG: 2 instcount - Number of ICmp insts
; CHECK-DAG: 1 instcount - Number of Ret insts
; CHECK-DAG: 1 instcount - Number of Switch insts
; CHECK-DAG: 10 instcount - Number of basic blocks
; CHECK-DAG: 1 instcount - Number of non-external functions
; CHECK-DAG: 18 instcount - Number of instructions (of all types)


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()