@@ -1703,6 +1703,20 @@ static bool needFuncLabels(const MachineFunction &MF, const AsmPrinter &Asm) {
17031703 classifyEHPersonality (MF.getFunction ().getPersonalityFn ()));
17041704}
17051705
1706+ // Return the mnemonic of a MachineInstr if available, or the MachineInstr
1707+ // opcode name otherwise.
1708+ static StringRef getMIMnemonic (const MachineInstr &MI, MCStreamer &Streamer) {
1709+ const TargetInstrInfo *TII =
1710+ MI.getParent ()->getParent ()->getSubtarget ().getInstrInfo ();
1711+ MCInst MCI;
1712+ MCI.setOpcode (MI.getOpcode ());
1713+ if (StringRef Name = Streamer.getMnemonic (MCI); !Name.empty ())
1714+ return Name;
1715+ StringRef Name = TII->getName (MI.getOpcode ());
1716+ assert (!Name.empty () && " Missing mnemonic and name for opcode" );
1717+ return Name;
1718+ }
1719+
17061720// / EmitFunctionBody - This method emits the body and trailer for a
17071721// / function.
17081722void AsmPrinter::emitFunctionBody () {
@@ -1746,7 +1760,6 @@ void AsmPrinter::emitFunctionBody() {
17461760 if (!MI.isPosition () && !MI.isImplicitDef () && !MI.isKill () &&
17471761 !MI.isDebugInstr ()) {
17481762 HasAnyRealCode = true ;
1749- ++NumInstsInFunction;
17501763 }
17511764
17521765 // If there is a pre-instruction symbol, emit a label for it here.
@@ -1845,12 +1858,25 @@ void AsmPrinter::emitFunctionBody() {
18451858 break ;
18461859 default :
18471860 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 ++;
1861+
1862+ auto CountInstruction = [&](const MachineInstr &MI) {
1863+ // Skip Meta instructions inside bundles.
1864+ if (MI.isMetaInstruction ())
1865+ return ;
1866+ ++NumInstsInFunction;
1867+ if (CanDoExtraAnalysis) {
1868+ StringRef Name = getMIMnemonic (MI, *OutStreamer);
1869+ ++MnemonicCounts[Name];
1870+ }
1871+ };
1872+ if (!MI.isBundle ()) {
1873+ CountInstruction (MI);
1874+ break ;
1875+ }
1876+ // Separately count all the instructions in a bundle.
1877+ for (auto It = std::next (MI.getIterator ());
1878+ It != MBB.end () && It->isInsideBundle (); ++It) {
1879+ CountInstruction (*It);
18541880 }
18551881 break ;
18561882 }
0 commit comments