Split PreferredEHDataFormat hook
authorAnton Korobeynikov <asl@math.spbu.ru>
Wed, 9 Jul 2008 13:21:08 +0000 (13:21 +0000)
committerAnton Korobeynikov <asl@math.spbu.ru>
Wed, 9 Jul 2008 13:21:08 +0000 (13:21 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@53300 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/X86/X86TargetAsmInfo.cpp
lib/Target/X86/X86TargetAsmInfo.h

index 0f5f200a7c6b5246a3d052412e0cd9f807b82955..67b50f92d8174abeba8cec52d67cbd79077ffb14 100644 (file)
@@ -210,6 +210,17 @@ X86DarwinTargetAsmInfo::X86DarwinTargetAsmInfo(const X86TargetMachine &TM):
   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 @@ X86ELFTargetAsmInfo::X86ELFTargetAsmInfo(const X86TargetMachine &TM):
     NonexecutableStackDirective = "\t.section\t.note.GNU-stack,\"\",@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 @@ X86WinTargetAsmInfo::X86WinTargetAsmInfo(const X86TargetMachine &TM):
   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>();
+unsigned
+X86COFFTargetAsmInfo::PreferredEHDataFormat(DwarfEncoding::Target Reason,
+                                            bool Global) const {
+  CodeModel::Model CM = X86TM->getCodeModel();
+  bool is64Bit = X86TM->getSubtarget<X86Subtarget>().is64Bit();
 
-  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();
-
-    if (X86TM->getRelocationModel() == Reloc::PIC_) {
-      unsigned Format = 0;
-
-      if (!Subtarget->is64Bit())
-        // 32 bit targets always encode pointers as 4 bytes
+  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 {
-        // 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;
   }
 }
 
index 510969103c185d54f387f6d5a23876e915b6069a..045db7aa057cf23743228dd6f08f57273e6c9a4c 100644 (file)
@@ -25,8 +25,6 @@ namespace llvm {
     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 @@ namespace llvm {
 
   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 {