[llvm-branch-commits] [llvm-branch] r123009 - in /llvm/branches/Apple/whitney: include/llvm/Target/TargetRegisterInfo.h lib/CodeGen/LocalStackSlotAllocation.cpp lib/Target/ARM/ARMBaseRegisterInfo.cpp lib/Target/ARM/ARMBaseRegisterInfo.h test/CodeGen/ARM/2010-12-17-LocalStackSlotCrash.ll

Daniel Dunbar daniel at zuster.org
Fri Jan 7 11:32:31 PST 2011


Author: ddunbar
Date: Fri Jan  7 13:32:31 2011
New Revision: 123009

URL: http://llvm.org/viewvc/llvm-project?rev=123009&view=rev
Log:
Merge r122104:
--
Author: Bill Wendling <wendling at apple.com>
Date:   Fri Dec 17 23:09:14 2010 +0000

    During local stack slot allocation, the materializeFrameBaseRegister function
    may be called. If the entry block is empty, the insertion point iterator will be
    the "end()" value. Calling ->getParent() on it (among others) causes problems.

    Modify materializeFrameBaseRegister to take the machine basic block and insert
    the frame base register at the beginning of that block. (It's very similar to
    what the code does all ready. The only difference is that it will always insert
    at the beginning of the entry block instead of after a previous materialization
    of the frame base register. I doubt that that matters here.)

    <rdar://problem/8782198>

Added:
    llvm/branches/Apple/whitney/test/CodeGen/ARM/2010-12-17-LocalStackSlotCrash.ll
Modified:
    llvm/branches/Apple/whitney/include/llvm/Target/TargetRegisterInfo.h
    llvm/branches/Apple/whitney/lib/CodeGen/LocalStackSlotAllocation.cpp
    llvm/branches/Apple/whitney/lib/Target/ARM/ARMBaseRegisterInfo.cpp
    llvm/branches/Apple/whitney/lib/Target/ARM/ARMBaseRegisterInfo.h

Modified: llvm/branches/Apple/whitney/include/llvm/Target/TargetRegisterInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/whitney/include/llvm/Target/TargetRegisterInfo.h?rev=123009&r1=123008&r2=123009&view=diff
==============================================================================
--- llvm/branches/Apple/whitney/include/llvm/Target/TargetRegisterInfo.h (original)
+++ llvm/branches/Apple/whitney/include/llvm/Target/TargetRegisterInfo.h Fri Jan  7 13:32:31 2011
@@ -663,7 +663,7 @@
 
   /// materializeFrameBaseRegister - Insert defining instruction(s) for
   /// BaseReg to be a pointer to FrameIdx before insertion point I.
-  virtual void materializeFrameBaseRegister(MachineBasicBlock::iterator I,
+  virtual void materializeFrameBaseRegister(MachineBasicBlock *MBB,
                                             unsigned BaseReg, int FrameIdx,
                                             int64_t Offset) const {
     assert(0 && "materializeFrameBaseRegister does not exist on this target");

Modified: llvm/branches/Apple/whitney/lib/CodeGen/LocalStackSlotAllocation.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/whitney/lib/CodeGen/LocalStackSlotAllocation.cpp?rev=123009&r1=123008&r2=123009&view=diff
==============================================================================
--- llvm/branches/Apple/whitney/lib/CodeGen/LocalStackSlotAllocation.cpp (original)
+++ llvm/branches/Apple/whitney/lib/CodeGen/LocalStackSlotAllocation.cpp Fri Jan  7 13:32:31 2011
@@ -230,24 +230,25 @@
   const TargetFrameInfo &TFI = *Fn.getTarget().getFrameInfo();
   bool StackGrowsDown =
     TFI.getStackGrowthDirection() == TargetFrameInfo::StackGrowsDown;
-  MachineBasicBlock::iterator InsertionPt = Fn.begin()->begin();
 
   // Collect all of the instructions in the block that reference
   // a frame index. Also store the frame index referenced to ease later
   // lookup. (For any insn that has more than one FI reference, we arbitrarily
   // choose the first one).
   SmallVector<FrameRef, 64> FrameReferenceInsns;
-  // A base register definition is a register+offset pair.
-  SmallVector<std::pair<unsigned, int64_t>, 8> BaseRegisters;
 
+  // A base register definition is a register + offset pair.
+  SmallVector<std::pair<unsigned, int64_t>, 8> BaseRegisters;
 
   for (MachineFunction::iterator BB = Fn.begin(), E = Fn.end(); BB != E; ++BB) {
     for (MachineBasicBlock::iterator I = BB->begin(); I != BB->end(); ++I) {
       MachineInstr *MI = I;
+
       // Debug value instructions can't be out of range, so they don't need
       // any updates.
       if (MI->isDebugValue())
         continue;
+
       // For now, allocate the base register(s) within the basic block
       // where they're used, and don't try to keep them around outside
       // of that. It may be beneficial to try sharing them more broadly
@@ -268,11 +269,13 @@
       }
     }
   }
+
   // Sort the frame references by local offset
   array_pod_sort(FrameReferenceInsns.begin(), FrameReferenceInsns.end());
 
+  MachineBasicBlock *Entry = Fn.begin();
 
-  // Loop throught the frame references and allocate for them as necessary
+  // Loop through the frame references and allocate for them as necessary.
   for (int ref = 0, e = FrameReferenceInsns.size(); ref < e ; ++ref) {
     MachineBasicBlock::iterator I =
       FrameReferenceInsns[ref].getMachineInstr();
@@ -321,10 +324,12 @@
             DEBUG(dbgs() << "  Materializing base register " << BaseReg <<
                   " at frame local offset " <<
                   LocalOffsets[FrameIdx] + InstrOffset << "\n");
+
             // Tell the target to insert the instruction to initialize
             // the base register.
-            TRI->materializeFrameBaseRegister(InsertionPt, BaseReg,
-                                              FrameIdx, InstrOffset);
+            //            MachineBasicBlock::iterator InsertionPt = Entry->begin();
+            TRI->materializeFrameBaseRegister(Entry, BaseReg, FrameIdx,
+                                              InstrOffset);
 
             // The base register already includes any offset specified
             // by the instruction, so account for that so it doesn't get

Modified: llvm/branches/Apple/whitney/lib/Target/ARM/ARMBaseRegisterInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/whitney/lib/Target/ARM/ARMBaseRegisterInfo.cpp?rev=123009&r1=123008&r2=123009&view=diff
==============================================================================
--- llvm/branches/Apple/whitney/lib/Target/ARM/ARMBaseRegisterInfo.cpp (original)
+++ llvm/branches/Apple/whitney/lib/Target/ARM/ARMBaseRegisterInfo.cpp Fri Jan  7 13:32:31 2011
@@ -1477,19 +1477,25 @@
   return true;
 }
 
-/// materializeFrameBaseRegister - Insert defining instruction(s) for
-/// BaseReg to be a pointer to FrameIdx before insertion point I.
+/// materializeFrameBaseRegister - Insert defining instruction(s) for BaseReg to
+/// be a pointer to FrameIdx at the beginning of the basic block.
 void ARMBaseRegisterInfo::
-materializeFrameBaseRegister(MachineBasicBlock::iterator I, unsigned BaseReg,
-                             int FrameIdx, int64_t Offset) const {
-  ARMFunctionInfo *AFI =
-    I->getParent()->getParent()->getInfo<ARMFunctionInfo>();
+materializeFrameBaseRegister(MachineBasicBlock *MBB,
+                             unsigned BaseReg, int FrameIdx,
+                             int64_t Offset) const {
+  ARMFunctionInfo *AFI = MBB->getParent()->getInfo<ARMFunctionInfo>();
   unsigned ADDriOpc = !AFI->isThumbFunction() ? ARM::ADDri :
     (AFI->isThumb1OnlyFunction() ? ARM::tADDrSPi : ARM::t2ADDri);
 
+  MachineBasicBlock::iterator Ins = MBB->begin();
+  DebugLoc DL;                  // Defaults to "unknown"
+  if (Ins != MBB->end())
+    DL = Ins->getDebugLoc();
+
   MachineInstrBuilder MIB =
-    BuildMI(*I->getParent(), I, I->getDebugLoc(), TII.get(ADDriOpc), BaseReg)
+    BuildMI(*MBB, Ins, DL, TII.get(ADDriOpc), BaseReg)
     .addFrameIndex(FrameIdx).addImm(Offset);
+
   if (!AFI->isThumb1OnlyFunction())
     AddDefaultCC(AddDefaultPred(MIB));
 }

Modified: llvm/branches/Apple/whitney/lib/Target/ARM/ARMBaseRegisterInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/whitney/lib/Target/ARM/ARMBaseRegisterInfo.h?rev=123009&r1=123008&r2=123009&view=diff
==============================================================================
--- llvm/branches/Apple/whitney/lib/Target/ARM/ARMBaseRegisterInfo.h (original)
+++ llvm/branches/Apple/whitney/lib/Target/ARM/ARMBaseRegisterInfo.h Fri Jan  7 13:32:31 2011
@@ -107,7 +107,7 @@
   bool needsStackRealignment(const MachineFunction &MF) const;
   int64_t getFrameIndexInstrOffset(const MachineInstr *MI, int Idx) const;
   bool needsFrameBaseReg(MachineInstr *MI, int64_t Offset) const;
-  void materializeFrameBaseRegister(MachineBasicBlock::iterator I,
+  void materializeFrameBaseRegister(MachineBasicBlock *MBB,
                                     unsigned BaseReg, int FrameIdx,
                                     int64_t Offset) const;
   void resolveFrameIndex(MachineBasicBlock::iterator I,

Added: llvm/branches/Apple/whitney/test/CodeGen/ARM/2010-12-17-LocalStackSlotCrash.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/whitney/test/CodeGen/ARM/2010-12-17-LocalStackSlotCrash.ll?rev=123009&view=auto
==============================================================================
--- llvm/branches/Apple/whitney/test/CodeGen/ARM/2010-12-17-LocalStackSlotCrash.ll (added)
+++ llvm/branches/Apple/whitney/test/CodeGen/ARM/2010-12-17-LocalStackSlotCrash.ll Fri Jan  7 13:32:31 2011
@@ -0,0 +1,15 @@
+; RUN: llc < %s -mtriple=armv6-apple-darwin10
+; <rdar://problem/8782198>
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:32:64-v128:32:128-a0:0:64-n32"
+target triple = "armv6-apple-darwin10"
+
+define void @func() nounwind optsize {
+entry:
+  %buf = alloca [8096 x i8], align 1
+  br label %bb
+
+bb:
+  %p.2 = getelementptr [8096 x i8]* %buf, i32 0, i32 0
+  store i8 undef, i8* %p.2, align 1
+  ret void
+}





More information about the llvm-branch-commits mailing list