@@ -164,6 +164,8 @@ class MachineSinking : public MachineFunctionPass {
164
164
// / would re-order assignments.
165
165
using SeenDbgUser = PointerIntPair<MachineInstr *, 1 >;
166
166
167
+ using SinkItem = std::pair<MachineInstr *, MachineBasicBlock *>;
168
+
167
169
// / Record of DBG_VALUE uses of vregs in a block, so that we can identify
168
170
// / debug instructions to sink.
169
171
SmallDenseMap<unsigned , TinyPtrVector<SeenDbgUser>> SeenDbgUsers;
@@ -259,11 +261,9 @@ class MachineSinking : public MachineFunctionPass {
259
261
void FindCycleSinkCandidates (MachineCycle *Cycle, MachineBasicBlock *BB,
260
262
SmallVectorImpl<MachineInstr *> &Candidates);
261
263
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);
267
267
268
268
bool isProfitableToSinkTo (Register Reg, MachineInstr &MI,
269
269
MachineBasicBlock *MBB,
@@ -692,7 +692,7 @@ void MachineSinking::FindCycleSinkCandidates(
692
692
for (auto &MI : *BB) {
693
693
LLVM_DEBUG (dbgs () << " CycleSink: Analysing candidate: " << MI);
694
694
if (MI.isMetaInstruction ()) {
695
- LLVM_DEBUG (dbgs () << " CycleSink: Dont sink meta instructions \n " );
695
+ LLVM_DEBUG (dbgs () << " CycleSink: not sinking meta instruction \n " );
696
696
continue ;
697
697
}
698
698
if (!TII->shouldSink (MI)) {
@@ -789,8 +789,8 @@ bool MachineSinking::runOnMachineFunction(MachineFunction &MF) {
789
789
SmallVector<MachineCycle *, 8 > Cycles (CI->toplevel_cycles ());
790
790
SchedModel.init (STI);
791
791
bool HasHighPressure;
792
- DenseMap<std::pair<MachineInstr *, MachineBasicBlock *>, MachineInstr *>
793
- SunkInstrs;
792
+
793
+ DenseMap<SinkItem, MachineInstr *> SunkInstrs;
794
794
795
795
enum CycleSinkStage { COPY, LOW_LATENCY, AGGRESSIVE, END };
796
796
for (unsigned Stage = CycleSinkStage::COPY; Stage != CycleSinkStage::END;
@@ -1644,52 +1644,14 @@ bool MachineSinking::hasStoreBetween(MachineBasicBlock *From,
1644
1644
return HasAliasedStore;
1645
1645
}
1646
1646
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
-
1684
1647
// / Aggressively sink instructions into cycles. This will aggressively try to
1685
1648
// / sink all instructions in the top-most preheaders in an attempt to reduce RP.
1686
1649
// / In particular, it will sink into multiple successor blocks without limits
1687
1650
// / based on the amount of sinking, or the type of ops being sunk (so long as
1688
1651
// / they are safe to sink).
1689
1652
bool MachineSinking::aggressivelySinkIntoCycle (
1690
1653
MachineCycle *Cycle, MachineInstr &I,
1691
- DenseMap<std::pair<MachineInstr *, MachineBasicBlock *>, MachineInstr *>
1692
- &SunkInstrs) {
1654
+ DenseMap<SinkItem, MachineInstr *> &SunkInstrs) {
1693
1655
// TODO: support instructions with multiple defs
1694
1656
if (I.getNumDefs () > 1 )
1695
1657
return false ;
@@ -1713,7 +1675,7 @@ bool MachineSinking::aggressivelySinkIntoCycle(
1713
1675
continue ;
1714
1676
}
1715
1677
// We cannot sink before the prologue
1716
- if (TII-> isBasicBlockPrologue (*MI ) || MI-> isPosition ( )) {
1678
+ if (MI-> isPosition ( ) || TII-> isBasicBlockPrologue (*MI )) {
1717
1679
LLVM_DEBUG (dbgs () << " AggressiveCycleSink: Use is BasicBlock prologue, "
1718
1680
" can't sink.\n " );
1719
1681
continue ;
@@ -1726,7 +1688,7 @@ bool MachineSinking::aggressivelySinkIntoCycle(
1726
1688
1727
1689
MachineBasicBlock *SinkBlock = MI->getParent ();
1728
1690
MachineInstr *NewMI = nullptr ;
1729
- std::pair<MachineInstr *, MachineBasicBlock *> MapEntry (&I, SinkBlock);
1691
+ SinkItem MapEntry (&I, SinkBlock);
1730
1692
1731
1693
auto SI = SunkInstrs.find (MapEntry);
1732
1694
@@ -1772,7 +1734,7 @@ bool MachineSinking::aggressivelySinkIntoCycle(
1772
1734
UseReg.SubReg , *TRI);
1773
1735
}
1774
1736
// If we have replaced all uses, then delete the dead instruction
1775
- if (isDead (&I ))
1737
+ if (I. isDead (MRI ))
1776
1738
I.eraseFromParent ();
1777
1739
return true ;
1778
1740
}
0 commit comments