summaryrefslogtreecommitdiffstats
path: root/lib/MC/MCContext.cpp
diff options
context:
space:
mode:
authorStephen Hines <srhines@google.com>2014-05-29 02:49:00 -0700
committerStephen Hines <srhines@google.com>2014-05-29 02:49:00 -0700
commitdce4a407a24b04eebc6a376f8e62b41aaa7b071f (patch)
treedcebc53f2b182f145a2e659393bf9a0472cedf23 /lib/MC/MCContext.cpp
parent220b921aed042f9e520c26cffd8282a94c66c3d5 (diff)
downloadexternal_llvm-dce4a407a24b04eebc6a376f8e62b41aaa7b071f.zip
external_llvm-dce4a407a24b04eebc6a376f8e62b41aaa7b071f.tar.gz
external_llvm-dce4a407a24b04eebc6a376f8e62b41aaa7b071f.tar.bz2
Update LLVM for 3.5 rebase (r209712).
Change-Id: I149556c940fb7dc92d075273c87ff584f400941f
Diffstat (limited to 'lib/MC/MCContext.cpp')
-rw-r--r--lib/MC/MCContext.cpp102
1 files changed, 40 insertions, 62 deletions
diff --git a/lib/MC/MCContext.cpp b/lib/MC/MCContext.cpp
index 73ffdc0..c163268 100644
--- a/lib/MC/MCContext.cpp
+++ b/lib/MC/MCContext.cpp
@@ -29,19 +29,13 @@
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)
: SrcMgr(mgr), MAI(mai), MRI(mri), MOFI(mofi), Allocator(),
Symbols(Allocator), UsedNames(Allocator), NextUniqueID(0),
CurrentDwarfLoc(0, 0, 0, DWARF2_FLAG_IS_STMT, 0, 0), DwarfLocSeen(false),
- GenDwarfForAssembly(false), GenDwarfFileNumber(0),
+ GenDwarfForAssembly(false), GenDwarfFileNumber(0), DwarfVersion(4),
AllowTemporaryLabels(true), DwarfCompileUnitID(0),
AutoReset(DoAutoReset) {
@@ -49,12 +43,8 @@ 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;
+ SecureLog = nullptr;
SecureLogUsed = false;
if (SrcMgr && SrcMgr->getNumBuffers() > 0)
@@ -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.
@@ -251,42 +232,48 @@ getELFSection(StringRef Section, unsigned Type, unsigned Flags,
return getELFSection(Section, Type, Flags, Kind, 0, "");
}
+void MCContext::renameELFSection(const MCSectionELF *Section, StringRef Name) {
+ StringRef GroupName;
+ if (const MCSymbol *Group = Section->getGroup())
+ GroupName = Group->getName();
+
+ ELFUniquingMap.erase(SectionGroupPair(Section->getSectionName(), GroupName));
+ auto I =
+ ELFUniquingMap.insert(std::make_pair(SectionGroupPair(Name, GroupName),
+ Section)).first;
+ StringRef CachedName = I->first.first;
+ const_cast<MCSectionELF*>(Section)->setSectionName(CachedName);
+}
+
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;
-
- SmallString<32> ZDebugName;
- if (MAI->compressDebugSections() && Section.startswith(".debug_") &&
- Section != ".debug_frame" && Section != ".debug_line")
- Section = (".z" + Section.drop_front(1)).toStringRef(ZDebugName);
-
// Do the lookup, if we have a hit, return it.
- std::pair<ELFUniqueMapTy::iterator, bool> Entry = Map.insert(
- std::make_pair(SectionGroupPair(Section, Group), (MCSectionELF *)0));
- if (!Entry.second) return Entry.first->second;
+ auto IterBool = ELFUniquingMap.insert(
+ std::make_pair(SectionGroupPair(Section, Group), nullptr));
+ auto &Entry = *IterBool.first;
+ if (!IterBool.second) return Entry.second;
// Possibly refine the entry size first.
if (!EntrySize) {
EntrySize = MCSectionELF::DetermineEntrySize(Kind);
}
- MCSymbol *GroupSym = NULL;
+ MCSymbol *GroupSym = nullptr;
if (!Group.empty())
GroupSym = GetOrCreateSymbol(Group);
- MCSectionELF *Result = new (*this) MCSectionELF(
- Entry.first->first.first, Type, Flags, Kind, EntrySize, GroupSym);
- Entry.first->second = Result;
+ StringRef CachedName = Entry.first.first;
+ MCSectionELF *Result = new (*this)
+ MCSectionELF(CachedName, Type, Flags, Kind, EntrySize, GroupSym);
+ Entry.second = Result;
return Result;
}
const MCSectionELF *MCContext::CreateELFGroupSection() {
MCSectionELF *Result =
new (*this) MCSectionELF(".group", ELF::SHT_GROUP, 0,
- SectionKind::getReadOnly(), 4, NULL);
+ SectionKind::getReadOnly(), 4, nullptr);
return Result;
}
@@ -294,26 +281,21 @@ 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, nullptr));
+ auto Iter = IterBool.first;
+ if (!IterBool.second)
return Iter->second;
- const MCSymbol *COMDATSymbol = NULL;
+ const MCSymbol *COMDATSymbol = nullptr;
if (!COMDATSymName.empty())
COMDATSymbol = GetOrCreateSymbol(COMDATSymName);
- MCSectionCOFF *Result =
- new (*this) MCSectionCOFF(Iter->first.first, Characteristics,
- COMDATSymbol, Selection, Assoc, Kind);
+ StringRef CachedName = Iter->first.first;
+ MCSectionCOFF *Result = new (*this) MCSectionCOFF(
+ CachedName, Characteristics, COMDATSymbol, Selection, Assoc, Kind);
Iter->second = Result;
return Result;
@@ -326,14 +308,10 @@ 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())
- return 0;
+ auto Iter = COFFUniquingMap.find(P);
+ if (Iter == COFFUniquingMap.end())
+ return nullptr;
return Iter->second;
}
@@ -361,7 +339,7 @@ bool MCContext::isValidDwarfFileNumber(unsigned FileNumber, unsigned CUID) {
return !MCDwarfFiles[FileNumber].Name.empty();
}
-void MCContext::FatalError(SMLoc Loc, const Twine &Msg) {
+void MCContext::FatalError(SMLoc Loc, const Twine &Msg) const {
// If we have a source manager and a location, use it. Otherwise just
// use the generic report_fatal_error().
if (!SrcMgr || Loc == SMLoc())