Teach spiller to unfold instructions which modref spill slot when a scratch
register is available and when it's profitable.

e.g.
     xorq  %r12<kill>, %r13
     addq  %rax, -184(%rbp)
     addq  %r13, -184(%rbp)
==>
     xorq  %r12<kill>, %r13
     movq  -184(%rbp), %r12
     addq  %rax, %r12
     addq  %r13, %r12
     movq  %r12, -184(%rbp)

Two more instructions, but fewer memory accesses. It can also open up
opportunities for more optimizations.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@69341 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/Spiller.h b/lib/CodeGen/Spiller.h
index 5a42a82..c0d0837 100644
--- a/lib/CodeGen/Spiller.h
+++ b/lib/CodeGen/Spiller.h
@@ -97,7 +97,7 @@
     const TargetRegisterInfo *getRegInfo() const { return TRI; }
 
     /// getSpillSlotOrReMatPhysReg - If the specified stack slot or remat is
-    /// available in a  physical register, return that PhysReg, otherwise
+    /// available in a physical register, return that PhysReg, otherwise
     /// return 0.
     unsigned getSpillSlotOrReMatPhysReg(int Slot) const {
       std::map<int, unsigned>::const_iterator I =
@@ -284,6 +284,7 @@
     MachineRegisterInfo *RegInfo;
     const TargetRegisterInfo *TRI;
     const TargetInstrInfo *TII;
+    BitVector AllocatableRegs;
     DenseMap<MachineInstr*, unsigned> DistanceMap;
   public:
     bool runOnMachineFunction(MachineFunction &MF, VirtRegMap &VRM);
@@ -291,12 +292,22 @@
     void TransferDeadness(MachineBasicBlock *MBB, unsigned CurDist,
                           unsigned Reg, BitVector &RegKills,
                           std::vector<MachineOperand*> &KillOps);
-    bool PrepForUnfoldOpti(MachineBasicBlock &MBB,
-                           MachineBasicBlock::iterator &MII,
+
+    bool OptimizeByUnfold(MachineBasicBlock &MBB,
+                          MachineBasicBlock::iterator &MII,
+                          std::vector<MachineInstr*> &MaybeDeadStores,
+                          AvailableSpills &Spills, BitVector &RegKills,
+                          std::vector<MachineOperand*> &KillOps,
+                          VirtRegMap &VRM);
+
+    bool OptimizeByUnfold2(unsigned VirtReg, int SS,
+                           MachineBasicBlock &MBB,
+                           MachineBasicBlock::iterator &MII, 
                            std::vector<MachineInstr*> &MaybeDeadStores,
                            AvailableSpills &Spills, BitVector &RegKills,
                            std::vector<MachineOperand*> &KillOps,
                            VirtRegMap &VRM);
+
     bool CommuteToFoldReload(MachineBasicBlock &MBB,
                              MachineBasicBlock::iterator &MII,
                              unsigned VirtReg, unsigned SrcReg, int SS,
@@ -305,6 +316,7 @@
                              std::vector<MachineOperand*> &KillOps,
                              const TargetRegisterInfo *TRI,
                              VirtRegMap &VRM);
+
     void SpillRegToStackSlot(MachineBasicBlock &MBB,
                              MachineBasicBlock::iterator &MII,
                              int Idx, unsigned PhysReg, int StackSlot,
@@ -315,6 +327,7 @@
                              BitVector &RegKills,
                              std::vector<MachineOperand*> &KillOps,
                              VirtRegMap &VRM);
+
     void RewriteMBB(MachineBasicBlock &MBB, VirtRegMap &VRM,
                     AvailableSpills &Spills,
                     BitVector &RegKills, std::vector<MachineOperand*> &KillOps);