[llvm-commits] [llvm] r132131 - in /llvm/trunk: lib/Target/Mips/MipsEmitGPRestore.cpp lib/Target/Mips/MipsFrameLowering.cpp lib/Target/Mips/MipsFrameLowering.h lib/Target/Mips/MipsISelLowering.cpp lib/Target/Mips/MipsMCAsmInfo.cpp lib/Target/Mips/MipsRegisterInfo.cpp test/CodeGen/Mips/blockaddr.ll

Akira Hatanaka ahatanak at gmail.com
Thu May 26 11:59:03 PDT 2011


Author: ahatanak
Date: Thu May 26 13:59:03 2011
New Revision: 132131

URL: http://llvm.org/viewvc/llvm-project?rev=132131&view=rev
Log:
Add support for C++ exception handling.

Modified:
    llvm/trunk/lib/Target/Mips/MipsEmitGPRestore.cpp
    llvm/trunk/lib/Target/Mips/MipsFrameLowering.cpp
    llvm/trunk/lib/Target/Mips/MipsFrameLowering.h
    llvm/trunk/lib/Target/Mips/MipsISelLowering.cpp
    llvm/trunk/lib/Target/Mips/MipsMCAsmInfo.cpp
    llvm/trunk/lib/Target/Mips/MipsRegisterInfo.cpp
    llvm/trunk/test/CodeGen/Mips/blockaddr.ll

Modified: llvm/trunk/lib/Target/Mips/MipsEmitGPRestore.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Mips/MipsEmitGPRestore.cpp?rev=132131&r1=132130&r2=132131&view=diff
==============================================================================
--- llvm/trunk/lib/Target/Mips/MipsEmitGPRestore.cpp (original)
+++ llvm/trunk/lib/Target/Mips/MipsEmitGPRestore.cpp Thu May 26 13:59:03 2011
@@ -55,6 +55,20 @@
     MachineBasicBlock& MBB = *MFI;
     MachineBasicBlock::iterator I = MFI->begin();
 
+    // If MBB is a landing pad, insert instruction that restores $gp after
+    // EH_LABEL.
+    if (MBB.isLandingPad()) {
+      // Find EH_LABEL first.
+      for (; I->getOpcode() != TargetOpcode::EH_LABEL; ++I) ;
+      
+      // Insert lw.
+      ++I;
+      DebugLoc dl = I != MBB.end() ? I->getDebugLoc() : DebugLoc();
+      BuildMI(MBB, I, dl, TII->get(Mips::LW), Mips::GP).addImm(0)
+                                                       .addFrameIndex(FI);
+      Changed = true;
+    }
+
     while (I != MFI->end()) {
       if (I->getOpcode() != Mips::JALR) {
         ++I;

Modified: llvm/trunk/lib/Target/Mips/MipsFrameLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Mips/MipsFrameLowering.cpp?rev=132131&r1=132130&r2=132131&view=diff
==============================================================================
--- llvm/trunk/lib/Target/Mips/MipsFrameLowering.cpp (original)
+++ llvm/trunk/lib/Target/Mips/MipsFrameLowering.cpp Thu May 26 13:59:03 2011
@@ -182,24 +182,49 @@
   if (ATUsed)
     BuildMI(MBB, MBBI, dl, TII.get(Mips::ATMACRO));
 
-  // if framepointer enabled, set it to point to the stack pointer.
-  if (hasFP(MF)) {
-    // Find the instruction past the last instruction that saves a callee-saved
-    // register to the stack.
-    const std::vector<CalleeSavedInfo> &CSI = MFI->getCalleeSavedInfo();
+  // Find the instruction past the last instruction that saves a callee-saved
+  // register to the stack.
+  const std::vector<CalleeSavedInfo> &CSI = MFI->getCalleeSavedInfo();
   
-    for (unsigned i = 0; i < CSI.size(); ++i)
-      ++MBBI;
+  for (unsigned i = 0; i < CSI.size(); ++i)
+    ++MBBI;
  
+  // if framepointer enabled, set it to point to the stack pointer.
+  if (hasFP(MF))
     // Insert instruction "move $fp, $sp" at this location.    
     BuildMI(MBB, MBBI, dl, TII.get(Mips::ADDu), Mips::FP)
       .addReg(Mips::SP).addReg(Mips::ZERO);
-  }
 
   // Restore GP from the saved stack location
   if (MipsFI->needGPSaveRestore())
     BuildMI(MBB, MBBI, dl, TII.get(Mips::CPRESTORE))
       .addImm(MFI->getObjectOffset(MipsFI->getGPFI()));
+
+  // EH Frame infomation.
+  MachineModuleInfo &MMI = MF.getMMI();
+  std::vector<MachineMove> &Moves = MMI.getFrameMoves();
+  MCSymbol *FrameLabel = MMI.getContext().CreateTempSymbol();
+  BuildMI(MBB, MBBI, dl, TII.get(TargetOpcode::PROLOG_LABEL)).addSym(FrameLabel);
+
+  if (hasFP(MF)) {
+    MachineLocation SPDst(Mips::FP);
+    MachineLocation SPSrc(Mips::SP);
+    Moves.push_back(MachineMove(FrameLabel, SPDst, SPSrc)); 
+  }
+    
+  if (StackSize) {
+    MachineLocation SPDst(MachineLocation::VirtualFP);
+    MachineLocation SPSrc(MachineLocation::VirtualFP, -StackSize);
+    Moves.push_back(MachineMove(FrameLabel, SPDst, SPSrc)); 
+  }
+
+  for (std::vector<CalleeSavedInfo>::const_iterator I = CSI.begin(),
+       E = CSI.end(); I != E; ++I) {
+    int64_t Offset = MFI->getObjectOffset(I->getFrameIdx());
+    MachineLocation CSDst(MachineLocation::VirtualFP, Offset);
+    MachineLocation CSSrc(I->getReg());
+    Moves.push_back(MachineMove(FrameLabel, CSDst, CSSrc));
+  }        
 }
 
 void MipsFrameLowering::emitEpilogue(MachineFunction &MF,
@@ -243,6 +268,13 @@
   }
 }
 
+void
+MipsFrameLowering::getInitialFrameState(std::vector<MachineMove> &Moves) const {
+  MachineLocation Dst(MachineLocation::VirtualFP);
+  MachineLocation Src(Mips::SP, 0);
+  Moves.push_back(MachineMove(0, Dst, Src));
+}
+
 void MipsFrameLowering::
 processFunctionBeforeCalleeSavedScan(MachineFunction &MF,
                                      RegScavenger *RS) const {

Modified: llvm/trunk/lib/Target/Mips/MipsFrameLowering.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Mips/MipsFrameLowering.h?rev=132131&r1=132130&r2=132131&view=diff
==============================================================================
--- llvm/trunk/lib/Target/Mips/MipsFrameLowering.h (original)
+++ llvm/trunk/lib/Target/Mips/MipsFrameLowering.h Thu May 26 13:59:03 2011
@@ -39,6 +39,8 @@
 
   bool hasFP(const MachineFunction &MF) const;
 
+  void getInitialFrameState(std::vector<MachineMove> &Moves) const;
+  
   void processFunctionBeforeCalleeSavedScan(MachineFunction &MF,
                                             RegScavenger *RS) const;
 };

Modified: llvm/trunk/lib/Target/Mips/MipsISelLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Mips/MipsISelLowering.cpp?rev=132131&r1=132130&r2=132131&view=diff
==============================================================================
--- llvm/trunk/lib/Target/Mips/MipsISelLowering.cpp (original)
+++ llvm/trunk/lib/Target/Mips/MipsISelLowering.cpp Thu May 26 13:59:03 2011
@@ -141,8 +141,9 @@
   setOperationAction(ISD::FLOG10,            MVT::f32,   Expand);
   setOperationAction(ISD::FEXP,              MVT::f32,   Expand);
 
-  setOperationAction(ISD::EH_LABEL,          MVT::Other, Expand);
-
+  setOperationAction(ISD::EXCEPTIONADDR,     MVT::i32, Expand);
+  setOperationAction(ISD::EHSELECTION,       MVT::i32, Expand);
+  
   setOperationAction(ISD::VAARG,             MVT::Other, Expand);
   setOperationAction(ISD::VACOPY,            MVT::Other, Expand);
   setOperationAction(ISD::VAEND,             MVT::Other, Expand);
@@ -176,6 +177,9 @@
 
   setStackPointerRegisterToSaveRestore(Mips::SP);
   computeRegisterProperties();
+
+  setExceptionPointerRegister(Mips::A0);
+  setExceptionSelectorRegister(Mips::A1);
 }
 
 MVT::SimpleValueType MipsTargetLowering::getSetCCResultType(EVT VT) const {

Modified: llvm/trunk/lib/Target/Mips/MipsMCAsmInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Mips/MipsMCAsmInfo.cpp?rev=132131&r1=132130&r2=132131&view=diff
==============================================================================
--- llvm/trunk/lib/Target/Mips/MipsMCAsmInfo.cpp (original)
+++ llvm/trunk/lib/Target/Mips/MipsMCAsmInfo.cpp Thu May 26 13:59:03 2011
@@ -17,11 +17,15 @@
 MipsMCAsmInfo::MipsMCAsmInfo(const Target &T, StringRef TT) {
   AlignmentIsInBytes          = false;
   Data16bitsDirective         = "\t.half\t";
-  Data32bitsDirective         = "\t.word\t";
+  Data32bitsDirective         = "\t.4byte\t";
   Data64bitsDirective         = 0;
   PrivateGlobalPrefix         = "$";
   CommentString               = "#";
   ZeroDirective               = "\t.space\t";
   GPRel32Directive            = "\t.gpword\t";
   WeakRefDirective            = "\t.weak\t";
+
+  SupportsDebugInformation = true;
+  ExceptionsType = ExceptionHandling::DwarfCFI;
+  HasLEB128 = true;
 }

Modified: llvm/trunk/lib/Target/Mips/MipsRegisterInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Mips/MipsRegisterInfo.cpp?rev=132131&r1=132130&r2=132131&view=diff
==============================================================================
--- llvm/trunk/lib/Target/Mips/MipsRegisterInfo.cpp (original)
+++ llvm/trunk/lib/Target/Mips/MipsRegisterInfo.cpp Thu May 26 13:59:03 2011
@@ -283,8 +283,7 @@
 
 int MipsRegisterInfo::
 getDwarfRegNum(unsigned RegNum, bool isEH) const {
-  llvm_unreachable("What is the dwarf register number");
-  return -1;
+  return MipsGenRegisterInfo::getDwarfRegNumFull(RegNum, 0);
 }
 
 #include "MipsGenRegisterInfo.inc"

Modified: llvm/trunk/test/CodeGen/Mips/blockaddr.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/Mips/blockaddr.ll?rev=132131&r1=132130&r2=132131&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/Mips/blockaddr.ll (original)
+++ llvm/trunk/test/CodeGen/Mips/blockaddr.ll Thu May 26 13:59:03 2011
@@ -8,14 +8,14 @@
   ret i8* %x
 }
 
-; CHECK-PIC: lw  $[[R0:[0-9]+]], %got($tmp1)($gp)
-; CHECK-PIC: addiu ${{[0-9]+}}, $[[R0]], %lo($tmp1)
-; CHECK-PIC: lw  $[[R1:[0-9]+]], %got($tmp2)($gp)
-; CHECK-PIC: addiu ${{[0-9]+}}, $[[R1]], %lo($tmp2)
-; CHECK-STATIC: lui  $[[R2:[0-9]+]], %hi($tmp1)
-; CHECK-STATIC: addiu ${{[0-9]+}}, $[[R2]], %lo($tmp1)
-; CHECK-STATIC: lui   $[[R3:[0-9]+]], %hi($tmp2)
-; CHECK-STATIC: addiu ${{[0-9]+}}, $[[R3]], %lo($tmp2)
+; CHECK-PIC: lw  $[[R0:[0-9]+]], %got($tmp[[T0:[0-9]+]])($gp)
+; CHECK-PIC: addiu ${{[0-9]+}}, $[[R0]], %lo($tmp[[T0]])
+; CHECK-PIC: lw  $[[R1:[0-9]+]], %got($tmp[[T1:[0-9]+]])($gp)
+; CHECK-PIC: addiu ${{[0-9]+}}, $[[R1]], %lo($tmp[[T1]])
+; CHECK-STATIC: lui  $[[R2:[0-9]+]], %hi($tmp[[T0:[0-9]+]])
+; CHECK-STATIC: addiu ${{[0-9]+}}, $[[R2]], %lo($tmp[[T0]])
+; CHECK-STATIC: lui   $[[R3:[0-9]+]], %hi($tmp[[T1:[0-9]+]])
+; CHECK-STATIC: addiu ${{[0-9]+}}, $[[R3]], %lo($tmp[[T1]])
 define void @f() nounwind {
 entry:
   %call = tail call i8* @dummy(i8* blockaddress(@f, %baz))





More information about the llvm-commits mailing list