diff options
author | David Blaikie <dblaikie@gmail.com> | 2014-04-10 23:55:11 +0000 |
---|---|---|
committer | David Blaikie <dblaikie@gmail.com> | 2014-04-10 23:55:11 +0000 |
commit | 42382d3e37d3e110cabac876fb081b1358489649 (patch) | |
tree | 701e20dcb0056d439aa9dbf888153d2445396441 /lib | |
parent | bc1fd917f09c1ef295231d88a80874689de2ff7f (diff) | |
download | llvm-42382d3e37d3e110cabac876fb081b1358489649.tar.gz llvm-42382d3e37d3e110cabac876fb081b1358489649.tar.bz2 llvm-42382d3e37d3e110cabac876fb081b1358489649.tar.xz |
Remove lazy-initialization of section caches in MCContext
This seems to have been a cargo-culted habit from the very first such
cache which didn't have any specific justification (but might've been a
layering constraint at the time).
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@206003 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/MC/MCContext.cpp | 70 |
1 files changed, 18 insertions, 52 deletions
diff --git a/lib/MC/MCContext.cpp b/lib/MC/MCContext.cpp index 8c2b509530..36e6b565ad 100644 --- a/lib/MC/MCContext.cpp +++ b/lib/MC/MCContext.cpp @@ -29,12 +29,6 @@ using namespace llvm; -typedef std::pair<std::string, std::string> SectionGroupPair; - -typedef StringMap<const MCSectionMachO*> MachOUniqueMapTy; -typedef std::map<SectionGroupPair, const MCSectionELF *> ELFUniqueMapTy; -typedef std::map<SectionGroupPair, const MCSectionCOFF *> COFFUniqueMapTy; - MCContext::MCContext(const MCAsmInfo *mai, const MCRegisterInfo *mri, const MCObjectFileInfo *mofi, const SourceMgr *mgr, bool DoAutoReset) @@ -49,10 +43,6 @@ MCContext::MCContext(const MCAsmInfo *mai, const MCRegisterInfo *mri, if (EC) CompilationDir.clear(); - MachOUniquingMap = 0; - ELFUniquingMap = 0; - COFFUniquingMap = 0; - SecureLogFile = getenv("AS_SECURE_LOG_FILE"); SecureLog = 0; SecureLogUsed = false; @@ -88,13 +78,9 @@ void MCContext::reset() { DwarfCompileUnitID = 0; CurrentDwarfLoc = MCDwarfLoc(0,0,0,DWARF2_FLAG_IS_STMT,0,0); - // If we have the MachO uniquing map, free it. - delete (MachOUniqueMapTy*)MachOUniquingMap; - delete (ELFUniqueMapTy*)ELFUniquingMap; - delete (COFFUniqueMapTy*)COFFUniquingMap; - MachOUniquingMap = 0; - ELFUniquingMap = 0; - COFFUniquingMap = 0; + MachOUniquingMap.clear(); + ELFUniquingMap.clear(); + COFFUniquingMap.clear(); NextUniqueID = 0; AllowTemporaryLabels = true; @@ -225,11 +211,6 @@ getMachOSection(StringRef Segment, StringRef Section, // may not have the same flags as the requested section, if so this should be // diagnosed by the client as an error. - // Create the map if it doesn't already exist. - if (MachOUniquingMap == 0) - MachOUniquingMap = new MachOUniqueMapTy(); - MachOUniqueMapTy &Map = *(MachOUniqueMapTy*)MachOUniquingMap; - // Form the name to look up. SmallString<64> Name; Name += Segment; @@ -237,7 +218,7 @@ getMachOSection(StringRef Segment, StringRef Section, Name += Section; // Do the lookup, if we have a hit, return it. - const MCSectionMachO *&Entry = Map[Name.str()]; + const MCSectionMachO *&Entry = MachOUniquingMap[Name.str()]; if (Entry) return Entry; // Otherwise, return a new section. @@ -252,31 +233,25 @@ getELFSection(StringRef Section, unsigned Type, unsigned Flags, } void MCContext::renameELFSection(const MCSectionELF *Section, StringRef Name) { - if (ELFUniquingMap == 0) - ELFUniquingMap = new ELFUniqueMapTy(); - ELFUniqueMapTy &Map = *(ELFUniqueMapTy*)ELFUniquingMap; - StringRef GroupName; if (const MCSymbol *Group = Section->getGroup()) GroupName = Group->getName(); - Map.erase(SectionGroupPair(Section->getSectionName(), GroupName)); - auto I = Map.insert(std::make_pair(SectionGroupPair(Name, GroupName), - Section)).first; + ELFUniquingMap.erase(SectionGroupPair(Section->getSectionName(), GroupName)); + auto I = + ELFUniquingMap.insert(std::make_pair(SectionGroupPair(Name, GroupName), + Section)).first; const_cast<MCSectionELF*>(Section)->setSectionName(I->first.first); } const MCSectionELF *MCContext:: getELFSection(StringRef Section, unsigned Type, unsigned Flags, SectionKind Kind, unsigned EntrySize, StringRef Group) { - if (ELFUniquingMap == 0) - ELFUniquingMap = new ELFUniqueMapTy(); - ELFUniqueMapTy &Map = *(ELFUniqueMapTy*)ELFUniquingMap; - // Do the lookup, if we have a hit, return it. - std::pair<ELFUniqueMapTy::iterator, bool> Entry = Map.insert( + auto IterBool = ELFUniquingMap.insert( std::make_pair(SectionGroupPair(Section, Group), (MCSectionELF *)0)); - if (!Entry.second) return Entry.first->second; + auto &Entry = *IterBool.first; + if (!IterBool.second) return Entry.second; // Possibly refine the entry size first. if (!EntrySize) { @@ -288,8 +263,8 @@ getELFSection(StringRef Section, unsigned Type, unsigned Flags, GroupSym = GetOrCreateSymbol(Group); MCSectionELF *Result = new (*this) MCSectionELF( - Entry.first->first.first, Type, Flags, Kind, EntrySize, GroupSym); - Entry.first->second = Result; + Entry.first.first, Type, Flags, Kind, EntrySize, GroupSym); + Entry.second = Result; return Result; } @@ -304,17 +279,12 @@ const MCSectionCOFF * MCContext::getCOFFSection(StringRef Section, unsigned Characteristics, SectionKind Kind, StringRef COMDATSymName, int Selection, const MCSectionCOFF *Assoc) { - if (COFFUniquingMap == 0) - COFFUniquingMap = new COFFUniqueMapTy(); - COFFUniqueMapTy &Map = *(COFFUniqueMapTy*)COFFUniquingMap; - // Do the lookup, if we have a hit, return it. SectionGroupPair P(Section, COMDATSymName); - std::pair<COFFUniqueMapTy::iterator, bool> Entry = - Map.insert(std::make_pair(P, (MCSectionCOFF *)0)); - COFFUniqueMapTy::iterator Iter = Entry.first; - if (!Entry.second) + auto IterBool = COFFUniquingMap.insert(std::make_pair(P, (MCSectionCOFF *)0)); + auto Iter = IterBool.first; + if (!IterBool.second) return Iter->second; const MCSymbol *COMDATSymbol = NULL; @@ -336,13 +306,9 @@ MCContext::getCOFFSection(StringRef Section, unsigned Characteristics, } const MCSectionCOFF *MCContext::getCOFFSection(StringRef Section) { - if (COFFUniquingMap == 0) - COFFUniquingMap = new COFFUniqueMapTy(); - COFFUniqueMapTy &Map = *(COFFUniqueMapTy*)COFFUniquingMap; - SectionGroupPair P(Section, ""); - COFFUniqueMapTy::iterator Iter = Map.find(P); - if (Iter == Map.end()) + auto Iter = COFFUniquingMap.find(P); + if (Iter == COFFUniquingMap.end()) return 0; return Iter->second; } |