[llvm-commits] [llvm] r107355 - /llvm/trunk/lib/CodeGen/InlineSpiller.cpp

Jakob Stoklund Olesen stoklund at 2pi.dk
Wed Jun 30 17:13:04 PDT 2010


Author: stoklund
Date: Wed Jun 30 19:13:04 2010
New Revision: 107355

URL: http://llvm.org/viewvc/llvm-project?rev=107355&view=rev
Log:
Add memory operand folding support to InlineSpiller.

Modified:
    llvm/trunk/lib/CodeGen/InlineSpiller.cpp

Modified: llvm/trunk/lib/CodeGen/InlineSpiller.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/InlineSpiller.cpp?rev=107355&r1=107354&r2=107355&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/InlineSpiller.cpp (original)
+++ llvm/trunk/lib/CodeGen/InlineSpiller.cpp Wed Jun 30 19:13:04 2010
@@ -59,6 +59,8 @@
              SmallVectorImpl<LiveInterval*> &spillIs,
              SlotIndex *earliestIndex);
   bool reMaterialize(LiveInterval &NewLI, MachineBasicBlock::iterator MI);
+  bool foldMemoryOperand(MachineBasicBlock::iterator MI,
+                         const SmallVectorImpl<unsigned> &Ops);
   void insertReload(LiveInterval &NewLI, MachineBasicBlock::iterator MI);
   void insertSpill(LiveInterval &NewLI, MachineBasicBlock::iterator MI);
 };
@@ -146,6 +148,37 @@
   return true;
 }
 
+/// foldMemoryOperand - Try folding stack slot references in Ops into MI.
+/// Return true on success, and MI will be erased.
+bool InlineSpiller::foldMemoryOperand(MachineBasicBlock::iterator MI,
+                                      const SmallVectorImpl<unsigned> &Ops) {
+  // TargetInstrInfo::foldMemoryOperand only expects explicit, non-tied
+  // operands.
+  SmallVector<unsigned, 8> FoldOps;
+  for (unsigned i = 0, e = Ops.size(); i != e; ++i) {
+    unsigned Idx = Ops[i];
+    MachineOperand &MO = MI->getOperand(Idx);
+    if (MO.isImplicit())
+      continue;
+    // FIXME: Teach targets to deal with subregs.
+    if (MO.getSubReg())
+      return false;
+    // Tied use operands should not be passed to foldMemoryOperand.
+    if (!MI->isRegTiedToDefOperand(Idx))
+      FoldOps.push_back(Idx);
+  }
+
+  MachineInstr *FoldMI = tii_.foldMemoryOperand(mf_, MI, FoldOps, stackSlot_);
+  if (!FoldMI)
+    return false;
+  MachineBasicBlock &MBB = *MI->getParent();
+  lis_.ReplaceMachineInstrInMaps(MI, FoldMI);
+  vrm_.addSpillSlotUse(stackSlot_, FoldMI);
+  MBB.insert(MBB.erase(MI), FoldMI);
+  DEBUG(dbgs() << "\tfolded: " << *FoldMI);
+  return true;
+}
+
 /// insertReload - Insert a reload of NewLI.reg before MI.
 void InlineSpiller::insertReload(LiveInterval &NewLI,
                                  MachineBasicBlock::iterator MI) {
@@ -208,6 +241,10 @@
     // Attempt remat instead of reload.
     bool NeedsReload = Reads && !reMaterialize(NewLI, MI);
 
+    // Attempt to fold memory ops.
+    if (NewLI.empty() && foldMemoryOperand(MI, Ops))
+      continue;
+
     if (NeedsReload)
       insertReload(NewLI, MI);
 





More information about the llvm-commits mailing list