[llvm-commits] [llvm] r80428 - in /llvm/trunk: include/llvm/Target/TargetLowering.h lib/CodeGen/AsmPrinter/DwarfException.cpp lib/Target/PowerPC/PPCISelLowering.cpp lib/Target/PowerPC/PPCISelLowering.h lib/Target/X86/X86ISelLowering.cpp lib/Target/X86/X86ISelLowering.h

Bill Wendling isanbard at gmail.com
Sat Aug 29 05:20:54 PDT 2009


Author: void
Date: Sat Aug 29 07:20:54 2009
New Revision: 80428

URL: http://llvm.org/viewvc/llvm-project?rev=80428&view=rev
Log:
- Add target lowering methods to get the preferred format for the FDE and LSDA
  encodings.
- Make some of the values emitted by the FDEs dependent upon the pointer
  size. This is in line with how GCC does things. And it has the benefit of
  working for Darwin in 64-bit mode now.

Modified:
    llvm/trunk/include/llvm/Target/TargetLowering.h
    llvm/trunk/lib/CodeGen/AsmPrinter/DwarfException.cpp
    llvm/trunk/lib/Target/PowerPC/PPCISelLowering.cpp
    llvm/trunk/lib/Target/PowerPC/PPCISelLowering.h
    llvm/trunk/lib/Target/X86/X86ISelLowering.cpp
    llvm/trunk/lib/Target/X86/X86ISelLowering.h

Modified: llvm/trunk/include/llvm/Target/TargetLowering.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Target/TargetLowering.h?rev=80428&r1=80427&r2=80428&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Target/TargetLowering.h (original)
+++ llvm/trunk/include/llvm/Target/TargetLowering.h Sat Aug 29 07:20:54 2009
@@ -32,6 +32,7 @@
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/Support/DebugLoc.h"
+#include "llvm/Support/Dwarf.h"
 #include "llvm/Target/TargetMachine.h"
 #include <climits>
 #include <map>
@@ -750,7 +751,7 @@
   /// getPICJumpTableRelocaBase - Returns relocation base for the given PIC
   /// jumptable.
   virtual SDValue getPICJumpTableRelocBase(SDValue Table,
-                                             SelectionDAG &DAG) const;
+                                           SelectionDAG &DAG) const;
 
   /// isOffsetFoldingLegal - Return true if folding a constant offset
   /// with the given GlobalAddress is legal.  It is frequently not legal in
@@ -760,6 +761,18 @@
   /// getFunctionAlignment - Return the Log2 alignment of this function.
   virtual unsigned getFunctionAlignment(const Function *) const = 0;
 
+  /// getPreferredLSDADataFormat - Return the preferred exception handling data
+  /// format for the LSDA.
+  virtual unsigned getPreferredLSDADataFormat() const {
+    return dwarf::DW_EH_PE_absptr;
+  }
+
+  /// getPreferredFDEDataFormat - Return the preferred exception handling data
+  /// format for the FDE.
+  virtual unsigned getPreferredFDEDataFormat() const {
+    return dwarf::DW_EH_PE_absptr;
+  }
+
   //===--------------------------------------------------------------------===//
   // TargetLowering Optimization Methods
   //

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfException.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfException.cpp?rev=80428&r1=80427&r2=80428&view=diff

==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfException.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfException.cpp Sat Aug 29 07:20:54 2009
@@ -22,6 +22,7 @@
 #include "llvm/Target/TargetData.h"
 #include "llvm/Target/TargetFrameInfo.h"
 #include "llvm/Target/TargetLoweringObjectFile.h"
+#include "llvm/Target/TargetLowering.h"
 #include "llvm/Target/TargetOptions.h"
 #include "llvm/Target/TargetRegisterInfo.h"
 #include "llvm/Support/Dwarf.h"
@@ -80,6 +81,7 @@
   EmitLabel("eh_frame_common_begin", Index);
   Asm->EmitInt32((int)0);
   Asm->EOL("CIE Identifier Tag");
+
   Asm->EmitInt8(dwarf::DW_CIE_VERSION);
   Asm->EOL("CIE Version");
 
@@ -91,23 +93,29 @@
   // Round out reader.
   Asm->EmitULEB128Bytes(1);
   Asm->EOL("CIE Code Alignment Factor");
+
   Asm->EmitSLEB128Bytes(stackGrowth);
   Asm->EOL("CIE Data Alignment Factor");
+
   Asm->EmitInt8(RI->getDwarfRegNum(RI->getRARegister(), true));
   Asm->EOL("CIE Return Address Column");
 
+  unsigned Encoding = 0;
+
   // If there is a personality, we need to indicate the function's location.
   if (Personality) {
     Asm->EmitULEB128Bytes(7);
     Asm->EOL("Augmentation Size");
 
     if (MAI->getNeedsIndirectEncoding()) {
-      Asm->EmitInt8(dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4 |
-                    dwarf::DW_EH_PE_indirect);
-      Asm->EOL("Personality (pcrel sdata4 indirect)");
+      Encoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4 |
+        dwarf::DW_EH_PE_indirect;
+      Asm->EmitInt8(Encoding);
+      Asm->EOL("Personality", Encoding);
     } else {
-      Asm->EmitInt8(dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4);
-      Asm->EOL("Personality (pcrel sdata4)");
+      Encoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
+      Asm->EmitInt8(Encoding);
+      Asm->EOL("Personality", Encoding);
     }
 
     PrintRelDirective(true);
@@ -118,17 +126,20 @@
       O << "-" << MAI->getPCSymbol();
     Asm->EOL("Personality");
 
-    Asm->EmitInt8(dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4);
-    Asm->EOL("LSDA Encoding (pcrel sdata4)");
-
-    Asm->EmitInt8(dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4);
-    Asm->EOL("FDE Encoding (pcrel sdata4)");
+    Encoding = Asm->TM.getTargetLowering()->getPreferredLSDADataFormat();
+    Asm->EmitInt8(Encoding);
+    Asm->EOL("LSDA Encoding", Encoding);
+
+    Encoding = Asm->TM.getTargetLowering()->getPreferredFDEDataFormat();
+    Asm->EmitInt8(Encoding);
+    Asm->EOL("FDE Encoding", Encoding);
   } else {
     Asm->EmitULEB128Bytes(1);
     Asm->EOL("Augmentation Size");
 
-    Asm->EmitInt8(dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4);
-    Asm->EOL("FDE Encoding (pcrel sdata4)");
+    Encoding = Asm->TM.getTargetLowering()->getPreferredFDEDataFormat();
+    Asm->EmitInt8(Encoding);
+    Asm->EOL("FDE Encoding", Encoding);
   }
 
   // Indicate locations of general callee saved registers in frame.
@@ -152,6 +163,7 @@
          "Should not emit 'available externally' functions at all");
 
   const Function *TheFunc = EHFrameInfo.function;
+  bool is4Byte = TD->getPointerSize() == sizeof(int32_t);
 
   Asm->OutStreamer.SwitchSection(Asm->getObjFileLowering().getEHFrameSection());
 
@@ -195,23 +207,22 @@
 
     Asm->EOL("FDE CIE offset");
 
-    EmitReference("eh_func_begin", EHFrameInfo.Number, true, true);
+    EmitReference("eh_func_begin", EHFrameInfo.Number, true, is4Byte);
     Asm->EOL("FDE initial location");
+
     EmitDifference("eh_func_end", EHFrameInfo.Number,
-                   "eh_func_begin", EHFrameInfo.Number, true);
+                   "eh_func_begin", EHFrameInfo.Number, is4Byte);
     Asm->EOL("FDE address range");
 
     // If there is a personality and landing pads then point to the language
     // specific data area in the exception table.
     if (MMI->getPersonalities()[0] != NULL) {
-      bool is4Byte = TD->getPointerSize() == sizeof(int32_t);
-
       Asm->EmitULEB128Bytes(is4Byte ? 4 : 8);
       Asm->EOL("Augmentation size");
 
-      if (EHFrameInfo.hasLandingPads)
+      if (EHFrameInfo.hasLandingPads) {
         EmitReference("exception", EHFrameInfo.Number, true, false);
-      else {
+      } else {
 	if (is4Byte)
 	  Asm->EmitInt32((int)0);
 	else
@@ -918,6 +929,8 @@
                             MF->getFunction()));
   }
 
+  MF = 0;
+
   if (TimePassesIsEnabled)
     ExceptionTimer->stopTimer();
 }

Modified: llvm/trunk/lib/Target/PowerPC/PPCISelLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PowerPC/PPCISelLowering.cpp?rev=80428&r1=80427&r2=80428&view=diff

==============================================================================
--- llvm/trunk/lib/Target/PowerPC/PPCISelLowering.cpp (original)
+++ llvm/trunk/lib/Target/PowerPC/PPCISelLowering.cpp Sat Aug 29 07:20:54 2009
@@ -464,6 +464,40 @@
     return 2;
 }
 
+/// getPreferredLSDADataFormat - Return the preferred exception handling data
+/// format for the LSDA.
+unsigned PPCTargetLowering::getPreferredLSDADataFormat() const {
+  if (getTargetMachine().getSubtarget<PPCSubtarget>().isDarwin())
+    return dwarf::DW_EH_PE_pcrel;
+
+  if (PPCSubTarget.isPPC64() ||
+      getTargetMachine().getRelocationModel() == Reloc::PIC_) {
+    unsigned DataTy =
+      (PPCSubTarget.isPPC64() ?
+       dwarf::DW_EH_PE_udata8 : dwarf::DW_EH_PE_udata4);
+    return dwarf::DW_EH_PE_pcrel | DataTy;
+  }
+
+  return dwarf::DW_EH_PE_absptr;
+}
+
+/// getPreferredFDEDataFormat - Return the preferred exception handling data
+/// format for the FDE.
+unsigned PPCTargetLowering::getPreferredFDEDataFormat() const {
+  if (getTargetMachine().getSubtarget<PPCSubtarget>().isDarwin())
+    return dwarf::DW_EH_PE_pcrel;
+
+  if (PPCSubTarget.isPPC64() ||
+      getTargetMachine().getRelocationModel() == Reloc::PIC_) {
+    unsigned DataTy =
+      (PPCSubTarget.isPPC64() ?
+       dwarf::DW_EH_PE_udata8 : dwarf::DW_EH_PE_udata4);
+    return dwarf::DW_EH_PE_pcrel | DataTy;
+  }
+
+  return dwarf::DW_EH_PE_absptr;
+}
+
 //===----------------------------------------------------------------------===//
 // Node matching predicates, for use by the tblgen matching code.
 //===----------------------------------------------------------------------===//

Modified: llvm/trunk/lib/Target/PowerPC/PPCISelLowering.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PowerPC/PPCISelLowering.h?rev=80428&r1=80427&r2=80428&view=diff

==============================================================================
--- llvm/trunk/lib/Target/PowerPC/PPCISelLowering.h (original)
+++ llvm/trunk/lib/Target/PowerPC/PPCISelLowering.h Sat Aug 29 07:20:54 2009
@@ -346,6 +346,14 @@
     /// getFunctionAlignment - Return the Log2 alignment of this function.
     virtual unsigned getFunctionAlignment(const Function *F) const;
 
+    /// getPreferredLSDADataFormat - Return the preferred exception handling data
+    /// format for the LSDA.
+    virtual unsigned getPreferredLSDADataFormat() const;
+
+    /// getPreferredFDEDataFormat - Return the preferred exception handling data
+    /// format for the FDE.
+    virtual unsigned getPreferredFDEDataFormat() const;
+
   private:
     SDValue getFramePointerFrameIndex(SelectionDAG & DAG) const;
     SDValue getReturnAddrFrameIndex(SelectionDAG & DAG) const;

Modified: llvm/trunk/lib/Target/X86/X86ISelLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86ISelLowering.cpp?rev=80428&r1=80427&r2=80428&view=diff

==============================================================================
--- llvm/trunk/lib/Target/X86/X86ISelLowering.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86ISelLowering.cpp Sat Aug 29 07:20:54 2009
@@ -1055,6 +1055,49 @@
   return F->hasFnAttr(Attribute::OptimizeForSize) ? 0 : 4;
 }
 
+/// getPreferredLSDADataFormat - Return the preferred exception handling data
+/// format for the LSDA.
+unsigned X86TargetLowering::getPreferredLSDADataFormat() const {
+  if (Subtarget->isTargetDarwin())
+    return dwarf::DW_EH_PE_pcrel;
+
+  CodeModel::Model M = getTargetMachine().getCodeModel();
+
+  if (getTargetMachine().getRelocationModel() == Reloc::PIC_) {
+    if (!Subtarget->is64Bit() || M == CodeModel::Small)
+      return dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
+
+    return dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata8;
+  }
+
+  if (M == CodeModel::Small)
+    return dwarf::DW_EH_PE_sdata4;
+
+  return dwarf::DW_EH_PE_absptr;
+}
+
+/// getPreferredFDEDataFormat - Return the preferred exception handling data
+/// format for the FDE.
+unsigned X86TargetLowering::getPreferredFDEDataFormat() const {
+  if (Subtarget->isTargetDarwin())
+    return dwarf::DW_EH_PE_pcrel;
+
+  CodeModel::Model M = getTargetMachine().getCodeModel();
+
+  if (getTargetMachine().getRelocationModel() == Reloc::PIC_) {
+    if (!Subtarget->is64Bit() ||
+        M == CodeModel::Small || M == CodeModel::Medium)
+      return dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
+
+    return dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata8;
+  }
+
+  if (M == CodeModel::Small || M == CodeModel::Medium)
+    return dwarf::DW_EH_PE_sdata4;
+
+  return dwarf::DW_EH_PE_absptr;
+}
+
 //===----------------------------------------------------------------------===//
 //               Return Value Calling Convention Implementation
 //===----------------------------------------------------------------------===//

Modified: llvm/trunk/lib/Target/X86/X86ISelLowering.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86ISelLowering.h?rev=80428&r1=80427&r2=80428&view=diff

==============================================================================
--- llvm/trunk/lib/Target/X86/X86ISelLowering.h (original)
+++ llvm/trunk/lib/Target/X86/X86ISelLowering.h Sat Aug 29 07:20:54 2009
@@ -560,6 +560,14 @@
     /// getFunctionAlignment - Return the Log2 alignment of this function.
     virtual unsigned getFunctionAlignment(const Function *F) const;
 
+    /// getPreferredLSDADataFormat - Return the preferred exception handling data
+    /// format for the LSDA.
+    virtual unsigned getPreferredLSDADataFormat() const;
+
+    /// getPreferredFDEDataFormat - Return the preferred exception handling data
+    /// format for the FDE.
+    virtual unsigned getPreferredFDEDataFormat() const;
+
   private:
     /// Subtarget - Keep a pointer to the X86Subtarget around so that we can
     /// make the right decision when generating code for different targets.





More information about the llvm-commits mailing list