sink uniquing of sections out of MCContext into the ELF and PECOFF TLOF implementations.
authorChris Lattner <sabre@nondot.org>
Thu, 13 Aug 2009 00:37:15 +0000 (00:37 +0000)
committerChris Lattner <sabre@nondot.org>
Thu, 13 Aug 2009 00:37:15 +0000 (00:37 +0000)
MCContext no longer maintains a string -> section map.

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

include/llvm/MC/MCContext.h
include/llvm/MC/MCSection.h
include/llvm/Target/TargetLoweringObjectFile.h
lib/MC/MCContext.cpp
lib/MC/MCSection.cpp
lib/Target/TargetLoweringObjectFile.cpp

index adf380472a13a14afd89fe167462bea7636e504c..082b515a2e13358a481577d5795c04a3c6c47425 100644 (file)
@@ -46,16 +46,6 @@ namespace llvm {
   public:
     MCContext();
     ~MCContext();
-
-    /// GetSection - Look up a section with the given @param Name, returning
-    /// null if it doesn't exist.
-    MCSection *GetSection(const StringRef &Name) const;
-    
-    void SetSection(const StringRef &Name, MCSection *S) {
-      MCSection *&Entry = Sections[Name];
-      assert(Entry == 0 && "Multiple sections with the same name created");
-      Entry = S;
-    }
     
     /// CreateSymbol - Create a new symbol with the specified @param Name.
     ///
index aa40386bfd92c7cba88907031b4d43a9792a7c6c..b33e8c9b42baeeef3dba4a279c58724a350cd752 100644 (file)
@@ -52,8 +52,9 @@ namespace llvm {
     /// of a syntactic one.
     bool IsDirective;
     
-    MCSectionELF(const StringRef &Name, bool IsDirective, SectionKind K,
-                 MCContext &Ctx);
+    MCSectionELF(const StringRef &name, bool isDirective, SectionKind K)
+      : MCSection(K), Name(name), IsDirective(isDirective) {
+    }
   public:
     
     static MCSectionELF *Create(const StringRef &Name, bool IsDirective, 
@@ -77,8 +78,9 @@ namespace llvm {
     /// of a syntactic one.
     bool IsDirective;
     
-    MCSectionCOFF(const StringRef &Name, bool IsDirective, SectionKind K,
-                  MCContext &Ctx);
+    MCSectionCOFF(const StringRef &name, bool isDirective, SectionKind K)
+      : MCSection(K), Name(name), IsDirective(isDirective) {
+    }
   public:
     
     static MCSectionCOFF *Create(const StringRef &Name, bool IsDirective, 
index 7f74c6b055cf54fa23b945dca6956b7abd1fe8f1..102928b65987eb4ce5498ce527305fcac775f3e7 100644 (file)
@@ -183,6 +183,7 @@ protected:
 
 class TargetLoweringObjectFileELF : public TargetLoweringObjectFile {
   bool HasCrazyBSS;
+  mutable void *UniquingMap;
 protected:
   /// TLSDataSection - Section directive for Thread Local data.
   ///
@@ -208,7 +209,10 @@ protected:
 public:
   TargetLoweringObjectFileELF(// FIXME: REMOVE AFTER UNIQUING IS FIXED.
                               bool hasCrazyBSS = false)
-    : HasCrazyBSS(hasCrazyBSS) {}
+    : HasCrazyBSS(hasCrazyBSS), UniquingMap(0) {}
+  
+  ~TargetLoweringObjectFileELF();
+  
   
   virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
   
@@ -302,7 +306,11 @@ public:
 
 
 class TargetLoweringObjectFileCOFF : public TargetLoweringObjectFile {
+  mutable void *UniquingMap;
 public:
+  TargetLoweringObjectFileCOFF() : UniquingMap(0) {}
+  ~TargetLoweringObjectFileCOFF();
+  
   virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
   
   virtual const MCSection *
index 63338353a1f71c42f287814f0754866db11c47f0..061d7c2498e740fccdb4ce7508f505d145af5c79 100644 (file)
@@ -22,11 +22,6 @@ MCContext::~MCContext() {
   // we don't need to free them here.
 }
 
-MCSection *MCContext::GetSection(const StringRef &Name) const {
-  StringMap<MCSection*>::const_iterator I = Sections.find(Name);
-  return I != Sections.end() ? I->second : 0;
-}
-
 MCSymbol *MCContext::CreateSymbol(const StringRef &Name) {
   assert(Name[0] != '\0' && "Normal symbols cannot be unnamed!");
 
index f6ac5cc5cbd08160dc6556104108c493aa7cdce1..8b7fcd2815c251a0dc31f2726ab9ea41d7b2280e 100644 (file)
@@ -27,16 +27,9 @@ MCSection::~MCSection() {
 
 MCSectionELF *MCSectionELF::
 Create(const StringRef &Name, bool IsDirective, SectionKind K, MCContext &Ctx) {
-  return new (Ctx) MCSectionELF(Name, IsDirective, K, Ctx);
+  return new (Ctx) MCSectionELF(Name, IsDirective, K);
 }
 
-MCSectionELF::MCSectionELF(const StringRef &name, bool isDirective,
-                           SectionKind K, MCContext &Ctx)
-  : MCSection(K), Name(name), IsDirective(isDirective) {
-  Ctx.SetSection(Name, this);
-}
-
-
 void MCSectionELF::PrintSwitchToSection(const TargetAsmInfo &TAI,
                                         raw_ostream &OS) const {
   if (isDirective()) {
@@ -118,16 +111,9 @@ void MCSectionELF::PrintSwitchToSection(const TargetAsmInfo &TAI,
 
 MCSectionCOFF *MCSectionCOFF::
 Create(const StringRef &Name, bool IsDirective, SectionKind K, MCContext &Ctx) {
-  return new (Ctx) MCSectionCOFF(Name, IsDirective, K, Ctx);
+  return new (Ctx) MCSectionCOFF(Name, IsDirective, K);
 }
 
-MCSectionCOFF::MCSectionCOFF(const StringRef &name, bool isDirective,
-                             SectionKind K, MCContext &Ctx)
-  : MCSection(K), Name(name), IsDirective(isDirective) {
-  Ctx.SetSection(Name, this);
-}
-
-
 void MCSectionCOFF::PrintSwitchToSection(const TargetAsmInfo &TAI,
                                          raw_ostream &OS) const {
   
index e7680c8a877442dc9e023a71ad388e224869dd19..00f4ffe56020d085ae98f8a79dd9e8d051a2dc37 100644 (file)
@@ -280,12 +280,25 @@ TargetLoweringObjectFile::getSectionForConstant(SectionKind Kind) const {
 //===----------------------------------------------------------------------===//
 //                                  ELF
 //===----------------------------------------------------------------------===//
+typedef StringMap<const MCSectionELF*> ELFUniqueMapTy;
+
+TargetLoweringObjectFileELF::~TargetLoweringObjectFileELF() {
+  // If we have the section uniquing map, free it.
+  delete (ELFUniqueMapTy*)UniquingMap;
+}
 
 const MCSection *TargetLoweringObjectFileELF::
 getELFSection(const char *Name, bool isDirective, SectionKind Kind) const {
-  if (MCSection *S = getContext().GetSection(Name))
-    return S;
-  return MCSectionELF::Create(Name, isDirective, Kind, getContext());
+  // Create the map if it doesn't already exist.
+  if (UniquingMap == 0)
+    UniquingMap = new ELFUniqueMapTy();
+  ELFUniqueMapTy &Map = *(ELFUniqueMapTy*)UniquingMap;
+  
+  // Do the lookup, if we have a hit, return it.
+  const MCSectionELF *&Entry = Map[Name];
+  if (Entry) return Entry;
+  
+  return Entry = MCSectionELF::Create(Name, isDirective, Kind, getContext());
 }
 
 void TargetLoweringObjectFileELF::Initialize(MCContext &Ctx,
@@ -805,12 +818,25 @@ shouldEmitUsedDirectiveFor(const GlobalValue *GV, Mangler *Mang) const {
 //                                  COFF
 //===----------------------------------------------------------------------===//
 
+typedef StringMap<const MCSectionCOFF*> COFFUniqueMapTy;
+
+TargetLoweringObjectFileCOFF::~TargetLoweringObjectFileCOFF() {
+  delete (COFFUniqueMapTy*)UniquingMap;
+}
+
 
 const MCSection *TargetLoweringObjectFileCOFF::
 getCOFFSection(const char *Name, bool isDirective, SectionKind Kind) const {
-  if (MCSection *S = getContext().GetSection(Name))
-    return S;
-  return MCSectionCOFF::Create(Name, isDirective, Kind, getContext());
+  // Create the map if it doesn't already exist.
+  if (UniquingMap == 0)
+    UniquingMap = new MachOUniqueMapTy();
+  COFFUniqueMapTy &Map = *(COFFUniqueMapTy*)UniquingMap;
+  
+  // Do the lookup, if we have a hit, return it.
+  const MCSectionCOFF *&Entry = Map[Name];
+  if (Entry) return Entry;
+  
+  return Entry = MCSectionCOFF::Create(Name, isDirective, Kind, getContext());
 }
 
 void TargetLoweringObjectFileCOFF::Initialize(MCContext &Ctx,