[llvm-commits] [llvm] r122778 - in /llvm/trunk/lib/Target/MBlaze: MBlazeFrameInfo.cpp MBlazeMachineFunction.h MBlazeRegisterInfo.cpp

Wesley Peck peckw at wesleypeck.com
Mon Jan 3 13:40:26 PST 2011


Author: peckw
Date: Mon Jan  3 15:40:26 2011
New Revision: 122778

URL: http://llvm.org/viewvc/llvm-project?rev=122778&view=rev
Log:
Fix more stack layout issues in the MBlaze backend.

Modified:
    llvm/trunk/lib/Target/MBlaze/MBlazeFrameInfo.cpp
    llvm/trunk/lib/Target/MBlaze/MBlazeMachineFunction.h
    llvm/trunk/lib/Target/MBlaze/MBlazeRegisterInfo.cpp

Modified: llvm/trunk/lib/Target/MBlaze/MBlazeFrameInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/MBlaze/MBlazeFrameInfo.cpp?rev=122778&r1=122777&r2=122778&view=diff
==============================================================================
--- llvm/trunk/lib/Target/MBlaze/MBlazeFrameInfo.cpp (original)
+++ llvm/trunk/lib/Target/MBlaze/MBlazeFrameInfo.cpp Mon Jan  3 15:40:26 2011
@@ -40,6 +40,35 @@
     cl::Hidden);
 }
 
+static void replaceFrameIndexes(MachineFunction &MF, 
+                                SmallVector<std::pair<int,int64_t>, 16> &FR) {
+  MachineFrameInfo *MFI = MF.getFrameInfo();
+  const SmallVector<std::pair<int,int64_t>, 16>::iterator FRB = FR.begin();
+  const SmallVector<std::pair<int,int64_t>, 16>::iterator FRE = FR.end();
+
+  SmallVector<std::pair<int,int64_t>, 16>::iterator FRI = FRB;
+  for (; FRI != FRE; ++FRI) {
+    MFI->RemoveStackObject(FRI->first);
+    int NFI = MFI->CreateFixedObject(4, FRI->second, true);
+
+    for (MachineFunction::iterator MB=MF.begin(), ME=MF.end(); MB!=ME; ++MB) {
+      MachineBasicBlock::iterator MBB = MB->begin();
+      const MachineBasicBlock::iterator MBE = MB->end();
+
+      for (; MBB != MBE; ++MBB) {
+        MachineInstr::mop_iterator MIB = MBB->operands_begin();
+        const MachineInstr::mop_iterator MIE = MBB->operands_end();
+
+        for (MachineInstr::mop_iterator MII = MIB; MII != MIE; ++MII) {
+          if (!MII->isFI() || MII->getIndex() != FRI->first) continue;
+          DEBUG(dbgs() << "FOUND FI#" << MII->getIndex() << "\n");
+          MII->setIndex(NFI);
+        }
+      }
+    }
+  }
+}
+
 //===----------------------------------------------------------------------===//
 //
 // Stack Frame Processing methods
@@ -64,6 +93,7 @@
   MachineRegisterInfo::livein_iterator LIE = MRI.livein_end();
   const SmallVector<int, 16> &LiveInFI = MBlazeFI->getLiveIn();
   SmallVector<MachineInstr*, 16> EraseInstr;
+  SmallVector<std::pair<int,int64_t>, 16> FrameRelocate;
 
   MachineBasicBlock *MBB = MF.getBlockNumbered(0);
   MachineBasicBlock::iterator MIB = MBB->begin();
@@ -87,7 +117,6 @@
   //
   // Additionally, if the SWI operation kills the def of REG then we don't
   // need the LWI operation so we can erase it as well.
-#if 1
   for (unsigned i = 0, e = LiveInFI.size(); i < e; ++i) {
     for (MachineBasicBlock::iterator I=MIB; I != MIE; ++I) {
       if (I->getOpcode() != MBlaze::LWI || I->getNumOperands() != 3 ||
@@ -117,7 +146,7 @@
         EraseInstr.push_back(SI);
         DEBUG(dbgs() << "SWI for FI#" << FI << " removed\n");
 
-        MBlazeFI->recordLoadArgsFI(FI, StackOffset);
+        FrameRelocate.push_back(std::make_pair(FI,StackOffset));
         DEBUG(dbgs() << "FI#" << FI << " relocated to " << StackOffset << "\n");
 
         StackOffset -= 4;
@@ -126,7 +155,6 @@
       }
     }
   }
-#endif
 
   // In this loop we are searching for frame indexes that corrospond to
   // incoming arguments that are in registers. We look for instruction
@@ -139,7 +167,6 @@
   // caller has allocated stack space for it already.  Instead of allocating
   // stack space on our frame, we record the correct location in the callers
   // frame.
-#if 1
   for (MachineRegisterInfo::livein_iterator LI = LII; LI != LIE; ++LI) {
     for (MachineBasicBlock::iterator I=MIB; I != MIE; ++I) {
       if (I->definesRegister(LI->first))
@@ -165,21 +192,21 @@
         }
 
         StackAdjust += 4;
-        MBlazeFI->recordLoadArgsFI(FI, FILoc);
+        FrameRelocate.push_back(std::make_pair(FI,FILoc));
         DEBUG(dbgs() << "FI#" << FI << " relocated to " << FILoc << "\n");
         break;
       }
     }
   }
-#endif
 
   // Go ahead and erase all of the instructions that we determined were
   // no longer needed.
   for (int i = 0, e = EraseInstr.size(); i < e; ++i)
     MBB->erase(EraseInstr[i]);
 
-  DEBUG(dbgs() << "Final stack adjustment: " << StackAdjust << "\n");
-  MBlazeFI->setStackAdjust(StackAdjust);
+  // Replace all of the frame indexes that we have relocated with new
+  // fixed object frame indexes.
+  replaceFrameIndexes(MF, FrameRelocate);
 }
 
 static void interruptFrameLayout(MachineFunction &MF) {
@@ -282,9 +309,6 @@
   unsigned FrameSize = MFI->getStackSize();
   DEBUG(dbgs() << "Original Frame Size: " << FrameSize << "\n" );
 
-  FrameSize -= MBlazeFI->getStackAdjust();
-  DEBUG(dbgs() << "Adjusted Frame Size: " << FrameSize << "\n" );
-
   // Get the alignments provided by the target, and the maximum alignment
   // (if any) of the fixed frame objects.
   // unsigned MaxAlign = MFI->getMaxAlignment();

Modified: llvm/trunk/lib/Target/MBlaze/MBlazeMachineFunction.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/MBlaze/MBlazeMachineFunction.h?rev=122778&r1=122777&r2=122778&view=diff
==============================================================================
--- llvm/trunk/lib/Target/MBlaze/MBlazeMachineFunction.h (original)
+++ llvm/trunk/lib/Target/MBlaze/MBlazeMachineFunction.h Mon Jan  3 15:40:26 2011
@@ -34,9 +34,6 @@
   /// saved. This is used on Prologue and Epilogue to emit RA save/restore
   int RAStackOffset;
 
-  /// Holds the stack adjustment necessary for each function.
-  int StackAdjust;
-
   /// MBlazeFIHolder - Holds a FrameIndex and it's Stack Pointer Offset
   struct MBlazeFIHolder {
 
@@ -85,9 +82,9 @@
 
 public:
   MBlazeFunctionInfo(MachineFunction& MF)
-  : FPStackOffset(0), RAStackOffset(0), StackAdjust(0), GPHolder(-1,-1),
-    HasLoadArgs(false), HasStoreVarArgs(false), SRetReturnReg(0),
-    GlobalBaseReg(0), VarArgsFrameIndex(0), LiveInFI()
+  : FPStackOffset(0), RAStackOffset(0), GPHolder(-1,-1), HasLoadArgs(false),
+    HasStoreVarArgs(false), SRetReturnReg(0), GlobalBaseReg(0),
+    VarArgsFrameIndex(0), LiveInFI()
   {}
 
   int getFPStackOffset() const { return FPStackOffset; }
@@ -96,9 +93,6 @@
   int getRAStackOffset() const { return RAStackOffset; }
   void setRAStackOffset(int Off) { RAStackOffset = Off; }
 
-  int getStackAdjust() const { return StackAdjust; }
-  void setStackAdjust(int Adj) { StackAdjust = Adj; }
-
   int getGPStackOffset() const { return GPHolder.SPOffset; }
   int getGPFI() const { return GPHolder.FI; }
   void setGPStackOffset(int Off) { GPHolder.SPOffset = Off; }
@@ -125,6 +119,7 @@
     if (!HasLoadArgs) HasLoadArgs=true;
     FnLoadArgs.push_back(MBlazeFIHolder(FI, SPOffset));
   }
+
   void recordStoreVarArgsFI(int FI, int SPOffset) {
     if (!HasStoreVarArgs) HasStoreVarArgs=true;
     FnStoreVarArgs.push_back(MBlazeFIHolder(FI, SPOffset));
@@ -135,6 +130,7 @@
     for (unsigned i = 0, e = FnLoadArgs.size(); i != e; ++i)
       MFI->setObjectOffset(FnLoadArgs[i].FI, FnLoadArgs[i].SPOffset);
   }
+
   void adjustStoreVarArgsFI(MachineFrameInfo *MFI) const {
     if (!hasStoreVarArgs()) return;
     for (unsigned i = 0, e = FnStoreVarArgs.size(); i != e; ++i)

Modified: llvm/trunk/lib/Target/MBlaze/MBlazeRegisterInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/MBlaze/MBlazeRegisterInfo.cpp?rev=122778&r1=122777&r2=122778&view=diff
==============================================================================
--- llvm/trunk/lib/Target/MBlaze/MBlazeRegisterInfo.cpp (original)
+++ llvm/trunk/lib/Target/MBlaze/MBlazeRegisterInfo.cpp Mon Jan  3 15:40:26 2011
@@ -296,11 +296,6 @@
   // and adjust SPOffsets considering the final stack size.
   int Offset = (spOffset < 0) ? (stackSize - spOffset) : spOffset;
   Offset += MI.getOperand(oi).getImm();
-  if (!MFI->isFixedObjectIndex(FrameIndex) && 
-      !MFI->isSpillSlotObjectIndex(FrameIndex) &&
-      !MBlazeFI->isLiveIn(FrameIndex) && 
-      spOffset >= 0)
-    Offset -= MBlazeFI->getStackAdjust();
 
   DEBUG(dbgs() << "Offset     : " << Offset << "\n" << "<--------->\n");
 





More information about the llvm-commits mailing list