Skip to content

Commit 3483c7c

Browse files
author
Francis Visoiu Mistrih
committed
[CodeGen] Fix InstructionCount remarks for MI bundles
For MI bundles, the instruction count remark doesn't count the instructions inside the bundle.
1 parent b1b9b7b commit 3483c7c

File tree

2 files changed

+52
-7
lines changed

2 files changed

+52
-7
lines changed

llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1746,7 +1746,6 @@ void AsmPrinter::emitFunctionBody() {
17461746
if (!MI.isPosition() && !MI.isImplicitDef() && !MI.isKill() &&
17471747
!MI.isDebugInstr()) {
17481748
HasAnyRealCode = true;
1749-
++NumInstsInFunction;
17501749
}
17511750

17521751
// If there is a pre-instruction symbol, emit a label for it here.
@@ -1845,12 +1844,23 @@ void AsmPrinter::emitFunctionBody() {
18451844
break;
18461845
default:
18471846
emitInstruction(&MI);
1848-
if (CanDoExtraAnalysis) {
1849-
MCInst MCI;
1850-
MCI.setOpcode(MI.getOpcode());
1851-
auto Name = OutStreamer->getMnemonic(MCI);
1852-
auto I = MnemonicCounts.insert({Name, 0u});
1853-
I.first->second++;
1847+
auto CountInstruction = [&](unsigned Opcode) {
1848+
++NumInstsInFunction;
1849+
if (CanDoExtraAnalysis) {
1850+
MCInst MCI;
1851+
MCI.setOpcode(Opcode);
1852+
auto Name = OutStreamer->getMnemonic(MCI);
1853+
++MnemonicCounts[Name];
1854+
}
1855+
};
1856+
if (!MI.isBundle()) {
1857+
CountInstruction(MI.getOpcode());
1858+
break;
1859+
}
1860+
// Separately count all the instructions in a bundle.
1861+
for (auto It = std::next(MI.getIterator());
1862+
It != MBB.end() && It->isInsideBundle(); ++It) {
1863+
CountInstruction(It->getOpcode());
18541864
}
18551865
break;
18561866
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# RUN: llc -mtriple=riscv32 -verify-machineinstrs -start-before=riscv-expand-pseudo -simplify-mir -o /dev/null -pass-remarks-analysis=asm-printer %s 2>&1 | FileCheck %s
2+
---
3+
name: instrs
4+
tracksRegLiveness: true
5+
body: |
6+
bb.0:
7+
$x0 = ADDI $x0, 0
8+
$x0 = ADDI $x0, 0
9+
$x0 = ADDI $x0, 0
10+
$x0 = LW $x0, 0
11+
$x0 = LW $x0, 0
12+
$x0 = XORI $x0, 0
13+
; CHECK: addi : 3
14+
; CHECK-NEXT: lw : 2
15+
; CHECK-NEXT: xori : 1
16+
; CHECK: 6 instructions in function
17+
...
18+
---
19+
name: bundles
20+
tracksRegLiveness: true
21+
body: |
22+
bb.0:
23+
$x0 = ADDI $x0, 0
24+
BUNDLE {
25+
$x0 = ADDI $x0, 0
26+
$x0 = ADDI $x0, 0
27+
$x0 = LW $x0, 0
28+
}
29+
$x0 = LW $x0, 0
30+
$x0 = XORI $x0, 0
31+
; CHECK: addi : 3
32+
; CHECK-NEXT: lw : 2
33+
; CHECK-NEXT: xori : 1
34+
; CHECK: 6 instructions in function
35+
...

0 commit comments

Comments
 (0)