Move stack slot assignments into LiveRangeEdit.
authorJakob Stoklund Olesen <stoklund@2pi.dk>
Fri, 15 Oct 2010 00:16:55 +0000 (00:16 +0000)
committerJakob Stoklund Olesen <stoklund@2pi.dk>
Fri, 15 Oct 2010 00:16:55 +0000 (00:16 +0000)
All registers created during splitting or spilling are assigned to the same
stack slot as the parent register.

When splitting or rematting, we may not spill at all. In that case the stack
slot is still assigned, but it will be dead.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@116546 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/InlineSpiller.cpp
lib/CodeGen/LiveRangeEdit.cpp
lib/CodeGen/LiveRangeEdit.h
lib/CodeGen/SplitKit.cpp

index 60181d7cdfa4cabf98fec974995b2bcf2b582aa3..94a40c4b3e7e4ae8b6303678f764374fe57357f4 100644 (file)
@@ -371,9 +371,7 @@ void InlineSpiller::spill(LiveRangeEdit &edit) {
     return;
 
   rc_ = mri_.getRegClass(edit.getReg());
-  stackSlot_ = vrm_.getStackSlot(edit.getReg());
-  if (stackSlot_ == VirtRegMap::NO_STACK_SLOT)
-    stackSlot_ = vrm_.assignVirt2StackSlot(edit.getReg());
+  stackSlot_ = edit.assignStackSlot(vrm_);
 
   // Iterate over instructions using register.
   for (MachineRegisterInfo::reg_iterator RI = mri_.reg_begin(edit.getReg());
index 8a123fbe70133902ff0ac7876d92db2bf5adf25e..463ebcb4ae5e299e57b2d30d06e7ce26e6980e60 100644 (file)
 
 using namespace llvm;
 
+int LiveRangeEdit::assignStackSlot(VirtRegMap &vrm) {
+  int ss = vrm.getStackSlot(getReg());
+  if (ss != VirtRegMap::NO_STACK_SLOT)
+    return ss;
+  return vrm.assignVirt2StackSlot(getReg());
+}
+
 LiveInterval &LiveRangeEdit::create(MachineRegisterInfo &mri,
                                     LiveIntervals &lis,
                                     VirtRegMap &vrm) {
   const TargetRegisterClass *RC = mri.getRegClass(parent_.reg);
   unsigned VReg = mri.createVirtualRegister(RC);
   vrm.grow();
+  // Immediately assign to the same stack slot as parent.
+  vrm.assignVirt2StackSlot(VReg, assignStackSlot(vrm));
   LiveInterval &li = lis.getOrCreateInterval(VReg);
   newRegs_.push_back(&li);
   return li;
index 6abeda8a97fb02214b7610d84a3e2133d6cba2b3..d9d9c613e1f4af379c809e31364452dd2b4323e6 100644 (file)
@@ -55,7 +55,12 @@ public:
   iterator begin() const { return newRegs_.begin()+firstNew_; }
   iterator end() const { return newRegs_.end(); }
 
-  /// create - Create a new register with the same class as parentReg_.
+  /// assignStackSlot - Ensure a stack slot is assigned to parent.
+  /// @return the assigned stack slot number.
+  int assignStackSlot(VirtRegMap&);
+
+  /// create - Create a new register with the same class and stack slot as
+  /// parent.
   LiveInterval &create(MachineRegisterInfo&, LiveIntervals&, VirtRegMap&);
 
   /// allUsesAvailableAt - Return true if all registers used by OrigMI at
index ea551bb623a591c8a47126d4e8dba3246321b86e..96ccf3031e83ca815459a3e85f9a97ec294c0c62 100644 (file)
@@ -591,12 +591,6 @@ SplitEditor::SplitEditor(SplitAnalysis &sa, LiveIntervals &lis, VirtRegMap &vrm,
     openli_(lis_, *curli_)
 {
   assert(curli_ && "SplitEditor created from empty SplitAnalysis");
-
-  // Make sure curli_ is assigned a stack slot, so all our intervals get the
-  // same slot as curli_.
-  if (vrm_.getStackSlot(curli_->reg) == VirtRegMap::NO_STACK_SLOT)
-    vrm_.assignVirt2StackSlot(curli_->reg);
-
 }
 
 bool SplitEditor::intervalsLiveAt(SlotIndex Idx) const {