[llvm] r206003 - Remove lazy-initialization of section caches in MCContext
David Blaikie
dblaikie at gmail.com
Thu Apr 10 16:55:11 PDT 2014
Author: dblaikie
Date: Thu Apr 10 18:55:11 2014
New Revision: 206003
URL: http://llvm.org/viewvc/llvm-project?rev=206003&view=rev
Log:
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).
Modified:
llvm/trunk/include/llvm/MC/MCContext.h
llvm/trunk/lib/MC/MCContext.cpp
Modified: llvm/trunk/include/llvm/MC/MCContext.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCContext.h?rev=206003&r1=206002&r2=206003&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCContext.h (original)
+++ llvm/trunk/include/llvm/MC/MCContext.h Thu Apr 10 18:55:11 2014
@@ -155,7 +155,11 @@ namespace llvm {
/// The Compile Unit ID that we are currently processing.
unsigned DwarfCompileUnitID;
- void *MachOUniquingMap, *ELFUniquingMap, *COFFUniquingMap;
+ typedef std::pair<std::string, std::string> SectionGroupPair;
+
+ StringMap<const MCSectionMachO*> MachOUniquingMap;
+ std::map<SectionGroupPair, const MCSectionELF *> ELFUniquingMap;
+ std::map<SectionGroupPair, const MCSectionCOFF *> COFFUniquingMap;
/// Do automatic reset in destructor
bool AutoReset;
Modified: llvm/trunk/lib/MC/MCContext.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCContext.cpp?rev=206003&r1=206002&r2=206003&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCContext.cpp (original)
+++ llvm/trunk/lib/MC/MCContext.cpp Thu Apr 10 18:55:11 2014
@@ -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 *ma
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, Strin
// 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, Strin
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, unsigne
}
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, unsigne
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 Sect
}
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;
}
More information about the llvm-commits
mailing list