diff options
| author | Chris Lattner <sabre@nondot.org> | 2009-08-13 00:37:15 +0000 | 
|---|---|---|
| committer | Chris Lattner <sabre@nondot.org> | 2009-08-13 00:37:15 +0000 | 
| commit | 38cff389af1d78bd80df0479ef258493e0c5897e (patch) | |
| tree | 7bbbecb058efb77eaf4ab59aac1f6c8a8e168e72 /lib | |
| parent | f991ecf7231436437f6de1a22e93d0a1b380e078 (diff) | |
| download | external_llvm-38cff389af1d78bd80df0479ef258493e0c5897e.zip external_llvm-38cff389af1d78bd80df0479ef258493e0c5897e.tar.gz external_llvm-38cff389af1d78bd80df0479ef258493e0c5897e.tar.bz2 | |
sink uniquing of sections out of MCContext into the ELF and PECOFF TLOF implementations.
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
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/MC/MCContext.cpp | 5 | ||||
| -rw-r--r-- | lib/MC/MCSection.cpp | 18 | ||||
| -rw-r--r-- | lib/Target/TargetLoweringObjectFile.cpp | 38 | 
3 files changed, 34 insertions, 27 deletions
| diff --git a/lib/MC/MCContext.cpp b/lib/MC/MCContext.cpp index 6333835..061d7c2 100644 --- a/lib/MC/MCContext.cpp +++ b/lib/MC/MCContext.cpp @@ -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!"); diff --git a/lib/MC/MCSection.cpp b/lib/MC/MCSection.cpp index f6ac5cc..8b7fcd2 100644 --- a/lib/MC/MCSection.cpp +++ b/lib/MC/MCSection.cpp @@ -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 { diff --git a/lib/Target/TargetLoweringObjectFile.cpp b/lib/Target/TargetLoweringObjectFile.cpp index e7680c8..00f4ffe 100644 --- a/lib/Target/TargetLoweringObjectFile.cpp +++ b/lib/Target/TargetLoweringObjectFile.cpp @@ -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, | 
