]> granicus.if.org Git - llvm/commitdiff
Some simpliciations to the spill/reload interface
authorChris Lattner <sabre@nondot.org>
Sun, 15 Dec 2002 23:01:26 +0000 (23:01 +0000)
committerChris Lattner <sabre@nondot.org>
Sun, 15 Dec 2002 23:01:26 +0000 (23:01 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@5067 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/RegAllocSimple.cpp

index 0c363dcd1686505806a15bc2cf5f656cd06b0f7d..b299ddd1bf9984988eed09a697157640d9a4778e 100644 (file)
@@ -126,14 +126,12 @@ namespace {
     }
 
     /// Moves value from memory into that register
-    MachineBasicBlock::iterator
-    moveUseToReg(MachineBasicBlock &MBB, MachineBasicBlock::iterator I,
-                 unsigned VirtReg, unsigned &PhysReg);
+    unsigned reloadVirtReg(MachineBasicBlock &MBB,
+                           MachineBasicBlock::iterator &I, unsigned VirtReg);
 
     /// Saves reg value on the stack (maps virtual register to stack value)
-    MachineBasicBlock::iterator
-    saveVirtRegToStack(MachineBasicBlock &MBB, MachineBasicBlock::iterator I,
-                       unsigned VirtReg, unsigned PhysReg);
+    void spillVirtReg(MachineBasicBlock &MBB, MachineBasicBlock::iterator &I,
+                      unsigned VirtReg, unsigned PhysReg);
   };
 
 }
@@ -178,35 +176,31 @@ unsigned RegAllocSimple::getFreeReg(unsigned virtualReg) {
     return getFreeReg(virtualReg);
 }
 
-MachineBasicBlock::iterator
-RegAllocSimple::moveUseToReg (MachineBasicBlock &MBB,
-                              MachineBasicBlock::iterator I,
-                              unsigned VirtReg, unsigned &PhysReg)
-{
+unsigned RegAllocSimple::reloadVirtReg(MachineBasicBlock &MBB,
+                                       MachineBasicBlock::iterator &I,
+                                       unsigned VirtReg) {
   const TargetRegisterClass* regClass = MF->getRegClass(VirtReg);
   unsigned stackOffset = getStackSpaceFor(VirtReg, regClass);
-  PhysReg = getFreeReg(VirtReg);
+  unsigned PhysReg = getFreeReg(VirtReg);
 
   // Add move instruction(s)
   ++NumReloaded;
-  return RegInfo->loadRegOffset2Reg(MBB, I, PhysReg,
-                                    RegInfo->getFramePointer(),
-                                    -stackOffset, regClass->getDataSize());
+  I = RegInfo->loadRegOffset2Reg(MBB, I, PhysReg, RegInfo->getFramePointer(),
+                                 -stackOffset, regClass->getDataSize());
+  return PhysReg;
 }
 
-MachineBasicBlock::iterator
-RegAllocSimple::saveVirtRegToStack (MachineBasicBlock &MBB,
-                                    MachineBasicBlock::iterator I,
-                                    unsigned VirtReg, unsigned PhysReg)
+void RegAllocSimple::spillVirtReg(MachineBasicBlock &MBB,
+                                  MachineBasicBlock::iterator &I,
+                                  unsigned VirtReg, unsigned PhysReg)
 {
   const TargetRegisterClass* regClass = MF->getRegClass(VirtReg);
   unsigned stackOffset = getStackSpaceFor(VirtReg, regClass);
 
   // Add move instruction(s)
   ++NumSpilled;
-  return RegInfo->storeReg2RegOffset(MBB, I, PhysReg,
-                                     RegInfo->getFramePointer(),
-                                     -stackOffset, regClass->getDataSize());
+  I = RegInfo->storeReg2RegOffset(MBB, I, PhysReg, RegInfo->getFramePointer(),
+                                  -stackOffset, regClass->getDataSize());
 }
 
 
@@ -322,11 +316,13 @@ void RegAllocSimple::AllocateBasicBlock(MachineBasicBlock &MBB) {
             } else {
               physReg = getFreeReg(virtualReg);
             }
-            I = --saveVirtRegToStack(MBB, ++I, virtualReg, physReg);
+            ++I;
+            spillVirtReg(MBB, I, virtualReg, physReg);
+            --I;
           } else {
-            I = moveUseToReg(MBB, I, virtualReg, physReg);
+            physReg = reloadVirtReg(MBB, I, virtualReg);
+            Virt2PhysRegMap[virtualReg] = physReg;
           }
-          Virt2PhysRegMap[virtualReg] = physReg;
         }
         MI->SetMachineOperandReg(i, physReg);
         DEBUG(std::cerr << "virt: " << virtualReg <<