[llvm-commits] [llvm] r77687 - in /llvm/trunk: include/llvm/Target/TargetLoweringObjectFile.h lib/CodeGen/AsmPrinter/AsmPrinter.cpp lib/CodeGen/ELFWriter.cpp lib/CodeGen/ELFWriter.h lib/Target/ARM/ARMISelLowering.cpp lib/Target/PowerPC/PPCISelLowering.cpp lib/Target/TargetLoweringObjectFile.cpp lib/Target/X86/X86ISelLowering.cpp

Chris Lattner sabre at nondot.org
Fri Jul 31 10:42:42 PDT 2009


Author: lattner
Date: Fri Jul 31 12:42:42 2009
New Revision: 77687

URL: http://llvm.org/viewvc/llvm-project?rev=77687&view=rev
Log:
refactor section construction in TLOF to be through an explicit
initialize method, which can be called when an MCContext is available.

Modified:
    llvm/trunk/include/llvm/Target/TargetLoweringObjectFile.h
    llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
    llvm/trunk/lib/CodeGen/ELFWriter.cpp
    llvm/trunk/lib/CodeGen/ELFWriter.h
    llvm/trunk/lib/Target/ARM/ARMISelLowering.cpp
    llvm/trunk/lib/Target/PowerPC/PPCISelLowering.cpp
    llvm/trunk/lib/Target/TargetLoweringObjectFile.cpp
    llvm/trunk/lib/Target/X86/X86ISelLowering.cpp

Modified: llvm/trunk/include/llvm/Target/TargetLoweringObjectFile.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Target/TargetLoweringObjectFile.h?rev=77687&r1=77686&r2=77687&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Target/TargetLoweringObjectFile.h (original)
+++ llvm/trunk/include/llvm/Target/TargetLoweringObjectFile.h Fri Jul 31 12:42:42 2009
@@ -19,6 +19,7 @@
 #include "llvm/Target/TargetAsmInfo.h"
 
 namespace llvm {
+  class MCContext;
 
 /// SectionKind - This is a simple POD value that classifies the properties of
 /// a section.  A global variable is classified into the deepest possible
@@ -256,6 +257,12 @@
   
   virtual ~TargetLoweringObjectFile();
   
+  /// Initialize - this method must be called before any actual lowering is
+  /// done.  This specifies the current context for codegen, and gives the
+  /// lowering implementations a chance to set up their default sections.
+  virtual void Initialize(MCContext &Ctx, const TargetMachine &TM) {}
+  
+  
   const Section *getTextSection() const { return TextSection; }
   const Section *getDataSection() const { return DataSection; }
   
@@ -310,12 +317,17 @@
 
 class TargetLoweringObjectFileELF : public TargetLoweringObjectFile {
   bool AtIsCommentChar;  // True if @ is the comment character on this target.
+  bool HasCrazyBSS;
 public:
   /// ELF Constructor - AtIsCommentChar is true if the CommentCharacter from TAI
   /// is "@".
-  TargetLoweringObjectFileELF(bool AtIsCommentChar = false,
+  TargetLoweringObjectFileELF(bool atIsCommentChar = false,
                               // FIXME: REMOVE AFTER UNIQUING IS FIXED.
-                              bool HasCrazyBSS = false);
+                              bool hasCrazyBSS = false)
+    : AtIsCommentChar(atIsCommentChar), HasCrazyBSS(hasCrazyBSS) {}
+    
+  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
@@ -342,6 +354,8 @@
   const Section *MergeableConst16Section;
 };
 
+  
+  
 class TargetLoweringObjectFileMachO : public TargetLoweringObjectFile {
   const Section *TextCoalSection;
   const Section *ConstTextCoalSection;
@@ -352,7 +366,9 @@
   const Section *EightByteConstantSection;
   const Section *SixteenByteConstantSection;
 public:
-  TargetLoweringObjectFileMachO(const TargetMachine &TM);
+  
+  virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
+
   virtual const Section *
   SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
                          Mangler *Mang, const TargetMachine &TM) const;
@@ -365,7 +381,8 @@
 
 class TargetLoweringObjectFileCOFF : public TargetLoweringObjectFile {
 public:
-  TargetLoweringObjectFileCOFF();
+  virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
+  
   virtual void getSectionFlagsAsString(SectionKind Kind,
                                        SmallVectorImpl<char> &Str) const;
   

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

==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp Fri Jul 31 12:42:42 2009
@@ -173,6 +173,10 @@
 }
 
 bool AsmPrinter::doInitialization(Module &M) {
+  // Initialize TargetLoweringObjectFile.
+  const_cast<TargetLoweringObjectFile&>(getObjFileLowering())
+    .Initialize(OutContext, TM);
+  
   Mang = new Mangler(M, TAI->getGlobalPrefix(), TAI->getPrivateGlobalPrefix(),
                      TAI->getLinkerPrivateGlobalPrefix());
   

Modified: llvm/trunk/lib/CodeGen/ELFWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/ELFWriter.cpp?rev=77687&r1=77686&r2=77687&view=diff

==============================================================================
--- llvm/trunk/lib/CodeGen/ELFWriter.cpp (original)
+++ llvm/trunk/lib/CodeGen/ELFWriter.cpp Fri Jul 31 12:42:42 2009
@@ -42,6 +42,7 @@
 #include "llvm/CodeGen/ObjectCodeEmitter.h"
 #include "llvm/CodeGen/MachineCodeEmitter.h"
 #include "llvm/CodeGen/MachineConstantPool.h"
+#include "llvm/MC/MCContext.h"
 #include "llvm/Target/TargetAsmInfo.h"
 #include "llvm/Target/TargetData.h"
 #include "llvm/Target/TargetELFWriterInfo.h"
@@ -73,6 +74,7 @@
 
 ELFWriter::ELFWriter(raw_ostream &o, TargetMachine &tm)
   : MachineFunctionPass(&ID), O(o), TM(tm),
+    OutContext(*new MCContext()),
     is64Bit(TM.getTargetData()->getPointerSizeInBits() == 64),
     isLittleEndian(TM.getTargetData()->isLittleEndian()),
     ElfHdr(isLittleEndian, is64Bit) {
@@ -89,11 +91,17 @@
 
 ELFWriter::~ELFWriter() {
   delete ElfCE;
+  delete &OutContext;
 }
 
 // doInitialization - Emit the file header and all of the global variables for
 // the module to the ELF file.
 bool ELFWriter::doInitialization(Module &M) {
+  // Initialize TargetLoweringObjectFile.
+  const TargetLoweringObjectFile &TLOF =
+    TM.getTargetLowering()->getObjFileLowering();
+  const_cast<TargetLoweringObjectFile&>(TLOF).Initialize(OutContext, TM);
+  
   Mang = new Mangler(M);
 
   // ELF Header

Modified: llvm/trunk/lib/CodeGen/ELFWriter.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/ELFWriter.h?rev=77687&r1=77686&r2=77687&view=diff

==============================================================================
--- llvm/trunk/lib/CodeGen/ELFWriter.h (original)
+++ llvm/trunk/lib/CodeGen/ELFWriter.h Fri Jul 31 12:42:42 2009
@@ -35,6 +35,7 @@
   class TargetELFWriterInfo;
   class raw_ostream;
   class SectionKind;
+  class MCContext;
 
   typedef std::vector<ELFSym*>::iterator ELFSymIter;
   typedef std::vector<ELFSection*>::iterator ELFSectionIter;
@@ -65,6 +66,8 @@
     /// Target machine description.
     TargetMachine &TM;
 
+    MCContext &OutContext;
+    
     /// Target Elf Writer description.
     const TargetELFWriterInfo *TEW;
 

Modified: llvm/trunk/lib/Target/ARM/ARMISelLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/ARMISelLowering.cpp?rev=77687&r1=77686&r2=77687&view=diff

==============================================================================
--- llvm/trunk/lib/Target/ARM/ARMISelLowering.cpp (original)
+++ llvm/trunk/lib/Target/ARM/ARMISelLowering.cpp Fri Jul 31 12:42:42 2009
@@ -106,7 +106,7 @@
 
 static TargetLoweringObjectFile *createTLOF(TargetMachine &TM) {
   if (TM.getSubtarget<ARMSubtarget>().isTargetDarwin())
-    return new TargetLoweringObjectFileMachO(TM);
+    return new TargetLoweringObjectFileMachO();
   return new TargetLoweringObjectFileELF(true);
 }
 

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

==============================================================================
--- llvm/trunk/lib/Target/PowerPC/PPCISelLowering.cpp (original)
+++ llvm/trunk/lib/Target/PowerPC/PPCISelLowering.cpp Fri Jul 31 12:42:42 2009
@@ -59,7 +59,7 @@
 
 static TargetLoweringObjectFile *CreateTLOF(const PPCTargetMachine &TM) {
   if (TM.getSubtargetImpl()->isDarwin())
-    return new TargetLoweringObjectFileMachO(TM);
+    return new TargetLoweringObjectFileMachO();
   return new TargetLoweringObjectFileELF(false, true);
 }
 

Modified: llvm/trunk/lib/Target/TargetLoweringObjectFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/TargetLoweringObjectFile.cpp?rev=77687&r1=77686&r2=77687&view=diff

==============================================================================
--- llvm/trunk/lib/Target/TargetLoweringObjectFile.cpp (original)
+++ llvm/trunk/lib/Target/TargetLoweringObjectFile.cpp Fri Jul 31 12:42:42 2009
@@ -261,10 +261,8 @@
 //                                  ELF
 //===----------------------------------------------------------------------===//
 
-TargetLoweringObjectFileELF::TargetLoweringObjectFileELF(bool atIsCommentChar,
-                                                         bool HasCrazyBSS)
-  : AtIsCommentChar(atIsCommentChar) {
-    
+void TargetLoweringObjectFileELF::Initialize(MCContext &Ctx,
+                                             const TargetMachine &TM) {
   if (!HasCrazyBSS)
     BSSSection_ = getOrCreateSection("\t.bss", true, SectionKind::BSS);
   else
@@ -480,8 +478,8 @@
 //                                 MachO
 //===----------------------------------------------------------------------===//
 
-TargetLoweringObjectFileMachO::
-TargetLoweringObjectFileMachO(const TargetMachine &TM) {
+void TargetLoweringObjectFileMachO::Initialize(MCContext &Ctx,
+                                               const TargetMachine &TM) {
   TextSection = getOrCreateSection("\t.text", true, SectionKind::Text);
   DataSection = getOrCreateSection("\t.data", true, SectionKind::DataRel);
   
@@ -592,7 +590,8 @@
 //                                  COFF
 //===----------------------------------------------------------------------===//
 
-TargetLoweringObjectFileCOFF::TargetLoweringObjectFileCOFF() {
+void TargetLoweringObjectFileCOFF::Initialize(MCContext &Ctx,
+                                              const TargetMachine &TM) {
   TextSection = getOrCreateSection("\t.text", true, SectionKind::Text);
   DataSection = getOrCreateSection("\t.data", true, SectionKind::DataRel);
 }

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

==============================================================================
--- llvm/trunk/lib/Target/X86/X86ISelLowering.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86ISelLowering.cpp Fri Jul 31 12:42:42 2009
@@ -55,7 +55,7 @@
   switch (TM.getSubtarget<X86Subtarget>().TargetType) {
   default: llvm_unreachable("unknown subtarget type");
   case X86Subtarget::isDarwin:
-    return new TargetLoweringObjectFileMachO(TM);
+    return new TargetLoweringObjectFileMachO();
   case X86Subtarget::isELF:
     return new TargetLoweringObjectFileELF();
   case X86Subtarget::isMingw:





More information about the llvm-commits mailing list