Remove "JumpTableDataSection" from TAI, instead, have AsmPrinter
authorChris Lattner <sabre@nondot.org>
Sat, 1 Aug 2009 23:46:12 +0000 (23:46 +0000)
committerChris Lattner <sabre@nondot.org>
Sat, 1 Aug 2009 23:46:12 +0000 (23:46 +0000)
compute it based on what it knows.  As part of this, rename getSectionForMergeableConstant
to getSectionForConstant because it works for non-mergable constants also.

The only functionality change from this is that Xcore will start dropping
its jump tables into readonly section instead of data section in -static mode.
This should be fine as the linker resolves the relocations.  If this is a
problem, let me know and we'll come up with another solution.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@77833 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Target/TargetAsmInfo.h
include/llvm/Target/TargetLoweringObjectFile.h
lib/CodeGen/AsmPrinter/AsmPrinter.cpp
lib/CodeGen/ELFWriter.cpp
lib/Target/DarwinTargetAsmInfo.cpp
lib/Target/TargetAsmInfo.cpp
lib/Target/TargetLoweringObjectFile.cpp
lib/Target/X86/X86TargetAsmInfo.cpp
lib/Target/XCore/XCoreTargetAsmInfo.cpp

index 0be43ca254fe7bae81e63d542dfaf5b3bd341be8..0facf325777f84b8e392a6566339f5509e5cac38 100644 (file)
@@ -206,11 +206,6 @@ namespace llvm {
     /// section with the section name and this suffix printed.
     const char *SectionEndDirectiveSuffix;// Defaults to null.
     
-    /// JumpTableDataSection - This is the section that we SwitchToSection right
-    /// before emitting the jump tables for a function when the relocation model
-    /// is not PIC.
-    const char *JumpTableDataSection;     // Defaults to "\t.section .rodata"
-    
     /// JumpTableDirective - if non-null, the directive to emit before a jump
     /// table.
     const char *JumpTableDirective;
@@ -538,9 +533,6 @@ namespace llvm {
     const char *getSectionEndDirectiveSuffix() const {
       return SectionEndDirectiveSuffix;
     }
-    const char *getJumpTableDataSection() const {
-      return JumpTableDataSection;
-    }
     const char *getStaticCtorsSection() const {
       return StaticCtorsSection;
     }
index 55d9cd297bf7f8cded50549df0dff99ab8cbd363..f6b1220e6cb8958a7074ff00b59f8c2e2afdb871 100644 (file)
@@ -45,7 +45,9 @@ protected:
   const MCSection *BSSSection;
   
   /// ReadOnlySection - Section that is readonly and can contain arbitrary
-  /// initialized data.
+  /// initialized data.  Targets are not required to have a readonly section.
+  /// If they don't, various bits of code will fall back to using the data
+  /// section for constants.
   const MCSection *ReadOnlySection;
   
 public:
@@ -76,11 +78,9 @@ public:
     return GV != 0;
   }
   
-  /// getSectionForMergeableConstant - Given a mergeable constant with the
-  /// specified size and relocation information, return a section that it
-  /// should be placed in.
-  virtual const MCSection *
-  getSectionForMergeableConstant(SectionKind Kind) const;
+  /// getSectionForConstant - Given a constant with the SectionKind, return a
+  /// section that it should be placed in.
+  virtual const MCSection *getSectionForConstant(SectionKind Kind) const;
   
   /// getKindForNamedSection - If this target wants to be able to override
   /// section flags based on the name of the section specified for a global
@@ -158,11 +158,9 @@ public:
   virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
   
   
-  /// getSectionForMergeableConstant - Given a mergeable constant with the
-  /// specified size and relocation information, return a section that it
-  /// should be placed in.
-  virtual const MCSection *
-  getSectionForMergeableConstant(SectionKind Kind) const;
+  /// getSectionForConstant - Given a constant with the SectionKind, return a
+  /// section that it should be placed in.
+  virtual const MCSection *getSectionForConstant(SectionKind Kind) const;
   
   virtual SectionKind getKindForNamedSection(const char *Section,
                                              SectionKind K) const;
@@ -194,8 +192,7 @@ public:
   SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
                          Mangler *Mang, const TargetMachine &TM) const;
   
-  virtual const MCSection *
-  getSectionForMergeableConstant(SectionKind Kind) const;
+  virtual const MCSection *getSectionForConstant(SectionKind Kind) const;
   
   /// shouldEmitUsedDirectiveFor - This hook allows targets to selectively
   /// decide not to emit the UsedDirective for some symbols in llvm.used.
index 7c9fcf5fd6063a9a05894bbcec554ec7c82ae1a1..f9839ddc68cfbffba4fd2684c721350af51d16f5 100644 (file)
@@ -349,8 +349,7 @@ void AsmPrinter::EmitConstantPool(MachineConstantPool *MCP) {
     }
     }
 
-    const MCSection *S =
-      getObjFileLowering().getSectionForMergeableConstant(Kind);
+    const MCSection *S = getObjFileLowering().getSectionForConstant(Kind);
     
     // The number of sections are small, just do a linear search from the
     // last section to the first.
@@ -419,22 +418,21 @@ void AsmPrinter::EmitJumpTableInfo(MachineJumpTableInfo *MJTI,
   // the appropriate section.
   TargetLowering *LoweringInfo = TM.getTargetLowering();
 
-  const char *JumpTableDataSection = TAI->getJumpTableDataSection();
   const Function *F = MF.getFunction();
-  
-  const MCSection *FuncSection =
-    getObjFileLowering().SectionForGlobal(F, Mang, TM);
-
   bool JTInDiffSection = false;
-  if ((IsPic && !LoweringInfo->usesGlobalOffsetTable()) ||
-      !JumpTableDataSection || F->isWeakForLinker()) {
+  if (F->isWeakForLinker() ||
+      (IsPic && !LoweringInfo->usesGlobalOffsetTable())) {
     // In PIC mode, we need to emit the jump table to the same section as the
     // function body itself, otherwise the label differences won't make sense.
     // We should also do if the section name is NULL or function is declared in
     // discardable section.
-    SwitchToSection(FuncSection);
+    SwitchToSection(getObjFileLowering().SectionForGlobal(F, Mang, TM));
   } else {
-    SwitchToDataSection(JumpTableDataSection);
+    // Otherwise, drop it in the readonly section.
+    const MCSection *ReadOnlySection = 
+      getObjFileLowering().getSectionForConstant(
+                                       SectionKind::get(SectionKind::ReadOnly));
+    SwitchToSection(ReadOnlySection);
     JTInDiffSection = true;
   }
   
index 1d33c7e1feffc32cc58242c8b3ff4b18587af63a..be1e6bfe75168f3942e668545dab52d50f93c794 100644 (file)
@@ -178,7 +178,13 @@ void ELFWriter::addExternalSymbol(const char *External) {
 // Get jump table section on the section name returned by TAI
 ELFSection &ELFWriter::getJumpTableSection() {
   unsigned Align = TM.getTargetData()->getPointerABIAlignment();
-  return getSection(TAI->getJumpTableDataSection(),
+  
+  const TargetLoweringObjectFile &TLOF =
+    TM.getTargetLowering()->getObjFileLowering();
+
+  return getSection(TLOF.getSectionForConstant(
+                                      SectionKind::get(SectionKind::ReadOnly))
+                    ->getName(),
                     ELFSection::SHT_PROGBITS,
                     ELFSection::SHF_ALLOC, Align);
 }
@@ -204,7 +210,7 @@ ELFSection &ELFWriter::getConstantPoolSection(MachineConstantPoolEntry &CPE) {
   const TargetLoweringObjectFile &TLOF =
     TM.getTargetLowering()->getObjFileLowering();
 
-  return getSection(TLOF.getSectionForMergeableConstant(Kind)->getName(),
+  return getSection(TLOF.getSectionForConstant(Kind)->getName(),
                     ELFSection::SHT_PROGBITS,
                     ELFSection::SHF_MERGE | ELFSection::SHF_ALLOC,
                     CPE.getAlignment());
index 7000b4f023ce0cd44e1a3bc9463a1a23efb1827a..cca12c01cb02044207c257789ecc44af32084d2c 100644 (file)
@@ -49,8 +49,6 @@ DarwinTargetAsmInfo::DarwinTargetAsmInfo(const TargetMachine &TM)
   HiddenDirective = "\t.private_extern ";
     
   // Sections:
-  JumpTableDataSection = "\t.const";
-
   if (TM.getRelocationModel() == Reloc::Static) {
     StaticCtorsSection = ".constructor";
     StaticDtorsSection = ".destructor";
index 1fb656329592d86d58ea061e91857b0513b88acc..add1dbf5c375dfbfcaa54a2efea2ccf9a1bf023c 100644 (file)
@@ -69,7 +69,6 @@ TargetAsmInfo::TargetAsmInfo(const TargetMachine &tm) : TM(tm) {
   TextSectionStartSuffix = "";
   DataSectionStartSuffix = "";
   SectionEndDirectiveSuffix = 0;
-  JumpTableDataSection = "\t.section .rodata";
   JumpTableDirective = 0;
   // FIXME: Flags are ELFish - replace with normal section stuff.
   StaticCtorsSection = "\t.section .ctors,\"aw\",@progbits";
index 84247790f453b8beb819c79a9e2b740bed0fa64e..7eb9a4a4ebf778b2932e9285202354e93b11e27c 100644 (file)
@@ -228,12 +228,11 @@ TargetLoweringObjectFile::SelectSectionForGlobal(const GlobalValue *GV,
   return getDataSection();
 }
 
-/// getSectionForMergableConstant - Given a mergable constant with the
+/// getSectionForConstant - Given a mergable constant with the
 /// specified size and relocation information, return a section that it
 /// should be placed in.
 const MCSection *
-TargetLoweringObjectFile::
-getSectionForMergeableConstant(SectionKind Kind) const {
+TargetLoweringObjectFile::getSectionForConstant(SectionKind Kind) const {
   if (Kind.isReadOnly() && ReadOnlySection != 0)
     return ReadOnlySection;
   
@@ -459,11 +458,11 @@ SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
   return DataRelROSection;
 }
 
-/// getSectionForMergeableConstant - Given a mergeable constant with the
+/// getSectionForConstant - Given a mergeable constant with the
 /// specified size and relocation information, return a section that it
 /// should be placed in.
 const MCSection *TargetLoweringObjectFileELF::
-getSectionForMergeableConstant(SectionKind Kind) const {
+getSectionForConstant(SectionKind Kind) const {
   if (Kind.isMergeableConst4())
     return MergeableConst4Section;
   if (Kind.isMergeableConst8())
@@ -582,8 +581,7 @@ SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
 }
 
 const MCSection *
-TargetLoweringObjectFileMachO::
-getSectionForMergeableConstant(SectionKind Kind) const {
+TargetLoweringObjectFileMachO::getSectionForConstant(SectionKind Kind) const {
   // If this constant requires a relocation, we have to put it in the data
   // segment, not in the text segment.
   if (Kind.isDataRel())
index c13d9ac3cee4922acf1ee8706ecf5cbf21fc759d..c30f3378b7b100bec447a36073c7a8139916b852 100644 (file)
@@ -228,7 +228,6 @@ X86WinTargetAsmInfo::X86WinTargetAsmInfo(const X86TargetMachine &TM):
 
   AlignmentIsInBytes = true;
 
-  JumpTableDataSection = NULL;
   SwitchToSectionDirective = "";
   TextSectionStartSuffix = "\tSEGMENT PARA 'CODE'";
   DataSectionStartSuffix = "\tSEGMENT PARA 'DATA'";
index 33a7eedc74386cc95b5b6626e8d86e5667190cd8..48502d07f63b672124e96d9f1792a5be05e2c836 100644 (file)
@@ -18,7 +18,7 @@ XCoreTargetAsmInfo::XCoreTargetAsmInfo(const TargetMachine &TM)
   Data64bitsDirective = 0;
   ZeroDirective = "\t.space\t";
   CommentString = "#";
-  JumpTableDataSection = "\t.section\t.dp.data,\"awd\",@progbits";
+    
   PrivateGlobalPrefix = ".L";
   AscizDirective = ".asciiz";
   WeakDefDirective = "\t.weak\t";