@@ -164,6 +164,8 @@ class MachineSinking : public MachineFunctionPass {
164164 // / would re-order assignments.
165165 using SeenDbgUser = PointerIntPair<MachineInstr *, 1 >;
166166
167+ using SinkItem = std::pair<MachineInstr *, MachineBasicBlock *>;
168+
167169 // / Record of DBG_VALUE uses of vregs in a block, so that we can identify
168170 // / debug instructions to sink.
169171 SmallDenseMap<unsigned , TinyPtrVector<SeenDbgUser>> SeenDbgUsers;
@@ -259,11 +261,9 @@ class MachineSinking : public MachineFunctionPass {
259261 void FindCycleSinkCandidates (MachineCycle *Cycle, MachineBasicBlock *BB,
260262 SmallVectorImpl<MachineInstr *> &Candidates);
261263
262- bool isDead (const MachineInstr *MI) const ;
263- bool aggressivelySinkIntoCycle (
264- MachineCycle *Cycle, MachineInstr &I,
265- DenseMap<std::pair<MachineInstr *, MachineBasicBlock *>, MachineInstr *>
266- &SunkInstrs);
264+ bool
265+ aggressivelySinkIntoCycle (MachineCycle *Cycle, MachineInstr &I,
266+ DenseMap<SinkItem, MachineInstr *> &SunkInstrs);
267267
268268 bool isProfitableToSinkTo (Register Reg, MachineInstr &MI,
269269 MachineBasicBlock *MBB,
@@ -692,7 +692,7 @@ void MachineSinking::FindCycleSinkCandidates(
692692 for (auto &MI : *BB) {
693693 LLVM_DEBUG (dbgs () << " CycleSink: Analysing candidate: " << MI);
694694 if (MI.isMetaInstruction ()) {
695- LLVM_DEBUG (dbgs () << " CycleSink: Dont sink meta instructions \n " );
695+ LLVM_DEBUG (dbgs () << " CycleSink: not sinking meta instruction \n " );
696696 continue ;
697697 }
698698 if (!TII->shouldSink (MI)) {
@@ -789,8 +789,8 @@ bool MachineSinking::runOnMachineFunction(MachineFunction &MF) {
789789 SmallVector<MachineCycle *, 8 > Cycles (CI->toplevel_cycles ());
790790 SchedModel.init (STI);
791791 bool HasHighPressure;
792- DenseMap<std::pair<MachineInstr *, MachineBasicBlock *>, MachineInstr *>
793- SunkInstrs;
792+
793+ DenseMap<SinkItem, MachineInstr *> SunkInstrs;
794794
795795 enum CycleSinkStage { COPY, LOW_LATENCY, AGGRESSIVE, END };
796796 for (unsigned Stage = CycleSinkStage::COPY; Stage != CycleSinkStage::END;
@@ -1644,52 +1644,14 @@ bool MachineSinking::hasStoreBetween(MachineBasicBlock *From,
16441644 return HasAliasedStore;
16451645}
16461646
1647- bool MachineSinking::isDead (const MachineInstr *MI) const {
1648- // Instructions without side-effects are dead iff they only define dead regs.
1649- // This function is hot and this loop returns early in the common case,
1650- // so only perform additional checks before this if absolutely necessary.
1651-
1652- for (const MachineOperand &MO : MI->all_defs ()) {
1653- Register Reg = MO.getReg ();
1654- if (Reg.isPhysical ())
1655- return false ;
1656-
1657- if (MO.isDead ()) {
1658- #ifndef NDEBUG
1659- // Basic check on the register. All of them should be 'undef'.
1660- for (auto &U : MRI->use_nodbg_operands (Reg))
1661- assert (U.isUndef () && " 'Undef' use on a 'dead' register is found!" );
1662- #endif
1663- continue ;
1664- }
1665-
1666- if (!(MRI->hasAtMostUserInstrs (Reg, 0 )))
1667- return false ;
1668- }
1669-
1670- // Technically speaking inline asm without side effects and no defs can still
1671- // be deleted. But there is so much bad inline asm code out there, we should
1672- // let them be.
1673- if (MI->isInlineAsm ())
1674- return false ;
1675-
1676- // FIXME: See issue #105950 for why LIFETIME markers are considered dead here.
1677- if (MI->isLifetimeMarker ())
1678- return true ;
1679-
1680- // If there are no defs with uses, the instruction might be dead.
1681- return MI->wouldBeTriviallyDead ();
1682- }
1683-
16841647// / Aggressively sink instructions into cycles. This will aggressively try to
16851648// / sink all instructions in the top-most preheaders in an attempt to reduce RP.
16861649// / In particular, it will sink into multiple successor blocks without limits
16871650// / based on the amount of sinking, or the type of ops being sunk (so long as
16881651// / they are safe to sink).
16891652bool MachineSinking::aggressivelySinkIntoCycle (
16901653 MachineCycle *Cycle, MachineInstr &I,
1691- DenseMap<std::pair<MachineInstr *, MachineBasicBlock *>, MachineInstr *>
1692- &SunkInstrs) {
1654+ DenseMap<SinkItem, MachineInstr *> &SunkInstrs) {
16931655 // TODO: support instructions with multiple defs
16941656 if (I.getNumDefs () > 1 )
16951657 return false ;
@@ -1713,7 +1675,7 @@ bool MachineSinking::aggressivelySinkIntoCycle(
17131675 continue ;
17141676 }
17151677 // We cannot sink before the prologue
1716- if (TII-> isBasicBlockPrologue (*MI ) || MI-> isPosition ( )) {
1678+ if (MI-> isPosition ( ) || TII-> isBasicBlockPrologue (*MI )) {
17171679 LLVM_DEBUG (dbgs () << " AggressiveCycleSink: Use is BasicBlock prologue, "
17181680 " can't sink.\n " );
17191681 continue ;
@@ -1726,7 +1688,7 @@ bool MachineSinking::aggressivelySinkIntoCycle(
17261688
17271689 MachineBasicBlock *SinkBlock = MI->getParent ();
17281690 MachineInstr *NewMI = nullptr ;
1729- std::pair<MachineInstr *, MachineBasicBlock *> MapEntry (&I, SinkBlock);
1691+ SinkItem MapEntry (&I, SinkBlock);
17301692
17311693 auto SI = SunkInstrs.find (MapEntry);
17321694
@@ -1772,7 +1734,7 @@ bool MachineSinking::aggressivelySinkIntoCycle(
17721734 UseReg.SubReg , *TRI);
17731735 }
17741736 // If we have replaced all uses, then delete the dead instruction
1775- if (isDead (&I ))
1737+ if (I. isDead (MRI ))
17761738 I.eraseFromParent ();
17771739 return true ;
17781740}
0 commit comments