File tree Expand file tree Collapse file tree 2 files changed +99
-7
lines changed Expand file tree Collapse file tree 2 files changed +99
-7
lines changed Original file line number Diff line number Diff 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.
@@ -1844,13 +1843,31 @@ void AsmPrinter::emitFunctionBody() {
18441843 // actual initialization is needed.
18451844 break ;
18461845 default :
1846+ assert (!MI.isMetaInstruction () &&
1847+ " Meta instructions should be already handled here" );
18471848 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 ++;
1849+
1850+ auto CountInstruction = [&](const MachineInstr &MI) {
1851+ // Skip Meta instructions inside bundles.
1852+ if (MI.isMetaInstruction ())
1853+ return ;
1854+ ++NumInstsInFunction;
1855+ if (CanDoExtraAnalysis) {
1856+ MCInst MCI;
1857+ MCI.setOpcode (MI.getOpcode ());
1858+ auto Name = OutStreamer->getMnemonic (MCI);
1859+ assert (!Name.empty () && " Missing mnemonic for opcode" );
1860+ ++MnemonicCounts[Name];
1861+ }
1862+ };
1863+ if (!MI.isBundle ()) {
1864+ CountInstruction (MI);
1865+ break ;
1866+ }
1867+ // Separately count all the instructions in a bundle.
1868+ for (auto It = std::next (MI.getIterator ());
1869+ It != MBB.end () && It->isInsideBundle (); ++It) {
1870+ CountInstruction (*It);
18541871 }
18551872 break ;
18561873 }
Original file line number Diff line number Diff line change 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+ ...
36+ ---
37+ name : metainstrs
38+ tracksRegLiveness : true
39+ body : |
40+ bb.0:
41+ $x0 = ADDI $x0, 0
42+ $x0 = ADDI $x0, 0
43+ $x0 = ADDI $x0, 0
44+ $x0 = IMPLICIT_DEF
45+ $x0 = LW $x0, 0
46+ $x0 = LW $x0, 0
47+ CFI_INSTRUCTION adjust_cfa_offset 4
48+ $x0 = XORI $x0, 0
49+ DBG_VALUE $x0, 0
50+ ; CHECK: addi : 3
51+ ; CHECK-NEXT: lw : 2
52+ ; CHECK-NEXT: xori : 1
53+ ; CHECK: 6 instructions in function
54+ ...
55+ ---
56+ name : metabundles
57+ tracksRegLiveness : true
58+ body : |
59+ bb.0:
60+ $x0 = ADDI $x0, 0
61+ BUNDLE {
62+ CFI_INSTRUCTION adjust_cfa_offset 4
63+ $x0 = ADDI $x0, 0
64+ $x0 = ADDI $x0, 0
65+ DBG_VALUE $x0, 0
66+ $x0 = LW $x0, 0
67+ }
68+ $x0 = LW $x0, 0
69+ $x0 = IMPLICIT_DEF
70+ $x0 = XORI $x0, 0
71+ ; CHECK: addi : 3
72+ ; CHECK-NEXT: lw : 2
73+ ; CHECK-NEXT: xori : 1
74+ ; CHECK: 6 instructions in function
75+ ...
You can’t perform that action at this time.
0 commit comments