[llvm-commits] [llvm] r75939 - in /llvm/trunk: lib/Target/SystemZ/SystemZRegisterInfo.cpp lib/Target/SystemZ/SystemZRegisterInfo.h lib/Target/SystemZ/SystemZTargetMachine.cpp test/CodeGen/SystemZ/06-FrameIdxLoad.ll test/CodeGen/SystemZ/06-LocalFrame.ll

Anton Korobeynikov asl at math.spbu.ru
Thu Jul 16 06:49:26 PDT 2009


Author: asl
Date: Thu Jul 16 08:49:25 2009
New Revision: 75939

URL: http://llvm.org/viewvc/llvm-project?rev=75939&view=rev
Log:
Add simple frame index elimination

Added:
    llvm/trunk/test/CodeGen/SystemZ/06-FrameIdxLoad.ll
    llvm/trunk/test/CodeGen/SystemZ/06-LocalFrame.ll
Modified:
    llvm/trunk/lib/Target/SystemZ/SystemZRegisterInfo.cpp
    llvm/trunk/lib/Target/SystemZ/SystemZRegisterInfo.h
    llvm/trunk/lib/Target/SystemZ/SystemZTargetMachine.cpp

Modified: llvm/trunk/lib/Target/SystemZ/SystemZRegisterInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/SystemZ/SystemZRegisterInfo.cpp?rev=75939&r1=75938&r2=75939&view=diff

==============================================================================
--- llvm/trunk/lib/Target/SystemZ/SystemZRegisterInfo.cpp (original)
+++ llvm/trunk/lib/Target/SystemZ/SystemZRegisterInfo.cpp Thu Jul 16 08:49:25 2009
@@ -17,6 +17,7 @@
 #include "llvm/CodeGen/MachineInstrBuilder.h"
 #include "llvm/CodeGen/MachineFrameInfo.h"
 #include "llvm/CodeGen/MachineFunction.h"
+#include "llvm/Target/TargetFrameInfo.h"
 #include "llvm/Target/TargetMachine.h"
 #include "llvm/Target/TargetOptions.h"
 #include "llvm/ADT/BitVector.h"
@@ -77,9 +78,46 @@
   assert(0 && "Not implemented yet!");
 }
 
+int SystemZRegisterInfo::getFrameIndexOffset(MachineFunction &MF, int FI) const {
+  const TargetFrameInfo &TFI = *MF.getTarget().getFrameInfo();
+  MachineFrameInfo *MFI = MF.getFrameInfo();
+  int Offset = MFI->getObjectOffset(FI) + MFI->getOffsetAdjustment();
+  uint64_t StackSize = MFI->getStackSize();
+
+  Offset += StackSize - TFI.getOffsetOfLocalArea();
+
+  // Skip the register save area if we generated the stack frame.
+  if (StackSize)
+    Offset -= TFI.getOffsetOfLocalArea();
+
+  return Offset;
+}
+
 void SystemZRegisterInfo::eliminateFrameIndex(MachineBasicBlock::iterator II,
                                             int SPAdj, RegScavenger *RS) const {
-  assert(0 && "Not implemented yet!");
+  assert(SPAdj == 0 && "Unxpected");
+
+  unsigned i = 0;
+  MachineInstr &MI = *II;
+  MachineFunction &MF = *MI.getParent()->getParent();
+  while (!MI.getOperand(i).isFI()) {
+    ++i;
+    assert(i < MI.getNumOperands() && "Instr doesn't have FrameIndex operand!");
+  }
+
+  int FrameIndex = MI.getOperand(i).getIndex();
+
+  unsigned BasePtr = (hasFP(MF) ? SystemZ::R11D : SystemZ::R15D);
+
+  // This must be part of a rri or ri operand memory reference.  Replace the
+  // FrameIndex with base register with BasePtr.  Add an offset to the
+  // displacement field.
+  MI.getOperand(i).ChangeToRegister(BasePtr, false);
+
+  // Offset is a 20-bit integer.
+  // FIXME: handle "too long" displacements.
+  int Offset = getFrameIndexOffset(MF, FrameIndex) + MI.getOperand(i+1).getImm();
+  MI.getOperand(i+1).ChangeToImmediate(Offset);
 }
 
 void SystemZRegisterInfo::emitPrologue(MachineFunction &MF) const {

Modified: llvm/trunk/lib/Target/SystemZ/SystemZRegisterInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/SystemZ/SystemZRegisterInfo.h?rev=75939&r1=75938&r2=75939&view=diff

==============================================================================
--- llvm/trunk/lib/Target/SystemZ/SystemZRegisterInfo.h (original)
+++ llvm/trunk/lib/Target/SystemZ/SystemZRegisterInfo.h Thu Jul 16 08:49:25 2009
@@ -39,6 +39,8 @@
 
   bool hasFP(const MachineFunction &MF) const;
 
+  int getFrameIndexOffset(MachineFunction &MF, int FI) const;
+
   void eliminateCallFramePseudoInstr(MachineFunction &MF,
                                      MachineBasicBlock &MBB,
                                      MachineBasicBlock::iterator I) const;

Modified: llvm/trunk/lib/Target/SystemZ/SystemZTargetMachine.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/SystemZ/SystemZTargetMachine.cpp?rev=75939&r1=75938&r2=75939&view=diff

==============================================================================
--- llvm/trunk/lib/Target/SystemZ/SystemZTargetMachine.cpp (original)
+++ llvm/trunk/lib/Target/SystemZ/SystemZTargetMachine.cpp Thu Jul 16 08:49:25 2009
@@ -41,7 +41,7 @@
   : Subtarget(*this, M, FS),
     DataLayout("E-p:64:64:64-i1:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-f128:128:128"),
     InstrInfo(*this), TLInfo(*this),
-    FrameInfo(TargetFrameInfo::StackGrowsDown, 8, 0) {
+    FrameInfo(TargetFrameInfo::StackGrowsDown, 8, -160) {
 }
 
 bool SystemZTargetMachine::addInstSelector(PassManagerBase &PM,

Added: llvm/trunk/test/CodeGen/SystemZ/06-FrameIdxLoad.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/SystemZ/06-FrameIdxLoad.ll?rev=75939&view=auto

==============================================================================
--- llvm/trunk/test/CodeGen/SystemZ/06-FrameIdxLoad.ll (added)
+++ llvm/trunk/test/CodeGen/SystemZ/06-FrameIdxLoad.ll Thu Jul 16 08:49:25 2009
@@ -0,0 +1,16 @@
+; RUN: llvm-as < %s | llc | grep 160 | count 1
+; RUN: llvm-as < %s | llc | grep 168 | count 1
+
+target datalayout = "E-p:64:64:64-i1:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-f128:128:128"
+target triple = "s390x-unknown-linux-gnu"
+
+define i64 @foo(i64 %a, i64 %b, i64 %c, i64 %d, i64 %e, i64 %f, i64* %g) nounwind readnone {
+entry:
+        ret i64 %f
+}
+
+define i64 @bar(i64 %a, i64 %b, i64 %c, i64 %d, i64 %e, i64 %f, i64* %g) nounwind readnone {
+entry:
+	%conv = ptrtoint i64* %g to i64		; <i64> [#uses=1]
+	ret i64 %conv
+}

Added: llvm/trunk/test/CodeGen/SystemZ/06-LocalFrame.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/SystemZ/06-LocalFrame.ll?rev=75939&view=auto

==============================================================================
--- llvm/trunk/test/CodeGen/SystemZ/06-LocalFrame.ll (added)
+++ llvm/trunk/test/CodeGen/SystemZ/06-LocalFrame.ll Thu Jul 16 08:49:25 2009
@@ -0,0 +1,12 @@
+; RUN: llvm-as < %s | llc | grep 160 | count 1
+; RUN: llvm-as < %s | llc | grep 328 | count 1
+
+target datalayout = "E-p:64:64:64-i1:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-f128:128:128"
+target triple = "s390x-unknown-linux-gnu"
+
+define noalias i64* @foo(i64 %a, i64 %b, i64 %c, i64 %d, i64 %e, i64 %f) nounwind readnone {
+entry:
+	%g = alloca i64, align 8		; <i64*> [#uses=1]
+	%add.ptr = getelementptr i64* %g, i64 %f		; <i64*> [#uses=1]
+	ret i64* %add.ptr
+}





More information about the llvm-commits mailing list