[llvm-commits] [llvm] r53300 - in /llvm/trunk/lib/Target/X86: X86TargetAsmInfo.cpp X86TargetAsmInfo.h

Anton Korobeynikov asl at math.spbu.ru
Wed Jul 9 06:21:09 PDT 2008


Author: asl
Date: Wed Jul  9 08:21:08 2008
New Revision: 53300

URL: http://llvm.org/viewvc/llvm-project?rev=53300&view=rev
Log:
Split PreferredEHDataFormat hook

Modified:
    llvm/trunk/lib/Target/X86/X86TargetAsmInfo.cpp
    llvm/trunk/lib/Target/X86/X86TargetAsmInfo.h

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

==============================================================================
--- llvm/trunk/lib/Target/X86/X86TargetAsmInfo.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86TargetAsmInfo.cpp Wed Jul  9 08:21:08 2008
@@ -210,6 +210,17 @@
   DwarfExceptionSection = ".section __DATA,__gcc_except_tab";
 }
 
+unsigned
+X86DarwinTargetAsmInfo::PreferredEHDataFormat(DwarfEncoding::Target Reason,
+                                              bool Global) const {
+  if (Reason == DwarfEncoding::Functions && Global)
+    return (DW_EH_PE_pcrel | DW_EH_PE_indirect | DW_EH_PE_sdata4);
+  else if (Reason == DwarfEncoding::CodeLabels || !Global)
+    return DW_EH_PE_pcrel;
+  else
+    return DW_EH_PE_absptr;
+}
+
 X86ELFTargetAsmInfo::X86ELFTargetAsmInfo(const X86TargetMachine &TM):
   X86TargetAsmInfo(TM) {
   bool is64Bit = X86TM->getSubtarget<X86Subtarget>().is64Bit();
@@ -254,6 +265,45 @@
     NonexecutableStackDirective = "\t.section\t.note.GNU-stack,\"\", at progbits";
 }
 
+unsigned
+X86ELFTargetAsmInfo::PreferredEHDataFormat(DwarfEncoding::Target Reason,
+                                           bool Global) const {
+  CodeModel::Model CM = X86TM->getCodeModel();
+  bool is64Bit = X86TM->getSubtarget<X86Subtarget>().is64Bit();
+
+  if (X86TM->getRelocationModel() == Reloc::PIC_) {
+    unsigned Format = 0;
+
+    if (!is64Bit)
+      // 32 bit targets always encode pointers as 4 bytes
+      Format = DW_EH_PE_sdata4;
+    else {
+      // 64 bit targets encode pointers in 4 bytes iff:
+      // - code model is small OR
+      // - code model is medium and we're emitting externally visible symbols
+      //   or any code symbols
+      if (CM == CodeModel::Small ||
+          (CM == CodeModel::Medium && (Global ||
+                                       Reason != DwarfEncoding::Data)))
+        Format = DW_EH_PE_sdata4;
+      else
+        Format = DW_EH_PE_sdata8;
+    }
+
+    if (Global)
+      Format |= DW_EH_PE_indirect;
+
+    return (Format | DW_EH_PE_pcrel);
+  } else {
+    if (is64Bit &&
+        (CM == CodeModel::Small ||
+         (CM == CodeModel::Medium && Reason != DwarfEncoding::Data)))
+      return DW_EH_PE_udata4;
+    else
+      return DW_EH_PE_absptr;
+  }
+}
+
 X86COFFTargetAsmInfo::X86COFFTargetAsmInfo(const X86TargetMachine &TM):
   X86TargetAsmInfo(TM) {
   GlobalPrefix = "_";
@@ -312,63 +362,42 @@
   SectionEndDirectiveSuffix = "\tends\n";
 }
 
-/// PreferredEHDataFormat - This hook allows the target to select data
-/// format used for encoding pointers in exception handling data. Reason is
-/// 0 for data, 1 for code labels, 2 for function pointers. Global is true
-/// if the symbol can be relocated.
-unsigned X86TargetAsmInfo::PreferredEHDataFormat(DwarfEncoding::Target Reason,
-                                                 bool Global) const {
-  const X86Subtarget *Subtarget = &X86TM->getSubtarget<X86Subtarget>();
-
-  switch (Subtarget->TargetType) {
-  case X86Subtarget::isDarwin:
-   if (Reason == DwarfEncoding::Functions && Global)
-     return (DW_EH_PE_pcrel | DW_EH_PE_indirect | DW_EH_PE_sdata4);
-   else if (Reason == DwarfEncoding::CodeLabels || !Global)
-     return DW_EH_PE_pcrel;
-   else
-     return DW_EH_PE_absptr;
-
-  case X86Subtarget::isELF:
-  case X86Subtarget::isCygwin:
-  case X86Subtarget::isMingw: {
-    CodeModel::Model CM = X86TM->getCodeModel();
+unsigned
+X86COFFTargetAsmInfo::PreferredEHDataFormat(DwarfEncoding::Target Reason,
+                                            bool Global) const {
+  CodeModel::Model CM = X86TM->getCodeModel();
+  bool is64Bit = X86TM->getSubtarget<X86Subtarget>().is64Bit();
 
-    if (X86TM->getRelocationModel() == Reloc::PIC_) {
-      unsigned Format = 0;
+  if (X86TM->getRelocationModel() == Reloc::PIC_) {
+    unsigned Format = 0;
 
-      if (!Subtarget->is64Bit())
-        // 32 bit targets always encode pointers as 4 bytes
+    if (!is64Bit)
+      // 32 bit targets always encode pointers as 4 bytes
+      Format = DW_EH_PE_sdata4;
+    else {
+      // 64 bit targets encode pointers in 4 bytes iff:
+      // - code model is small OR
+      // - code model is medium and we're emitting externally visible symbols
+      //   or any code symbols
+      if (CM == CodeModel::Small ||
+          (CM == CodeModel::Medium && (Global ||
+                                       Reason != DwarfEncoding::Data)))
         Format = DW_EH_PE_sdata4;
-      else {
-        // 64 bit targets encode pointers in 4 bytes iff:
-        // - code model is small OR
-        // - code model is medium and we're emitting externally visible symbols
-        //   or any code symbols
-        if (CM == CodeModel::Small ||
-            (CM == CodeModel::Medium && (Global ||
-                                         Reason != DwarfEncoding::Data)))
-          Format = DW_EH_PE_sdata4;
-        else
-          Format = DW_EH_PE_sdata8;
-      }
-
-      if (Global)
-        Format |= DW_EH_PE_indirect;
-
-      return (Format | DW_EH_PE_pcrel);
-    } else {
-      if (Subtarget->is64Bit() &&
-          (CM == CodeModel::Small ||
-           (CM == CodeModel::Medium && Reason != DwarfEncoding::Data)))
-        return DW_EH_PE_udata4;
       else
-        return DW_EH_PE_absptr;
+        Format = DW_EH_PE_sdata8;
     }
-  }
 
-  default:
-   return TargetAsmInfo::PreferredEHDataFormat(Reason, Global);
+    if (Global)
+      Format |= DW_EH_PE_indirect;
+
+    return (Format | DW_EH_PE_pcrel);
+  } else {
+    if (is64Bit &&
+        (CM == CodeModel::Small ||
+         (CM == CodeModel::Medium && Reason != DwarfEncoding::Data)))
+      return DW_EH_PE_udata4;
+    else
+      return DW_EH_PE_absptr;
   }
 }
 

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

==============================================================================
--- llvm/trunk/lib/Target/X86/X86TargetAsmInfo.h (original)
+++ llvm/trunk/lib/Target/X86/X86TargetAsmInfo.h Wed Jul  9 08:21:08 2008
@@ -25,8 +25,6 @@
     explicit X86TargetAsmInfo(const X86TargetMachine &TM);
 
     virtual bool ExpandInlineAsm(CallInst *CI) const;
-    virtual unsigned PreferredEHDataFormat(DwarfEncoding::Target Reason,
-                                           bool Global) const;
     virtual std::string SectionForGlobal(const GlobalValue *GV) const;
     virtual std::string UniqueSectionForGlobal(const GlobalValue* GV,
                                                SectionKind::Kind kind) const;
@@ -40,14 +38,20 @@
 
   struct X86DarwinTargetAsmInfo : public X86TargetAsmInfo {
     explicit X86DarwinTargetAsmInfo(const X86TargetMachine &TM);
+    virtual unsigned PreferredEHDataFormat(DwarfEncoding::Target Reason,
+                                           bool Global) const;
   };
 
   struct X86ELFTargetAsmInfo : public X86TargetAsmInfo {
     explicit X86ELFTargetAsmInfo(const X86TargetMachine &TM);
+    virtual unsigned PreferredEHDataFormat(DwarfEncoding::Target Reason,
+                                           bool Global) const;
   };
 
   struct X86COFFTargetAsmInfo : public X86TargetAsmInfo {
     explicit X86COFFTargetAsmInfo(const X86TargetMachine &TM);
+    virtual unsigned PreferredEHDataFormat(DwarfEncoding::Target Reason,
+                                           bool Global) const;
   };
 
   struct X86WinTargetAsmInfo : public X86TargetAsmInfo {





More information about the llvm-commits mailing list