[llvm] r274336 - Add support for allowing us to create uniquely identified "COMDAT" or "ELF
Eric Christopher via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 30 23:07:38 PDT 2016
Author: echristo
Date: Fri Jul 1 01:07:38 2016
New Revision: 274336
URL: http://llvm.org/viewvc/llvm-project?rev=274336&view=rev
Log:
Add support for allowing us to create uniquely identified "COMDAT" or "ELF
Group" sections while lowering. In particular, for ELF sections this is
useful for creating function-specific groups that get merged into the
same named section.
Also use const Twine& instead of StringRef for the getELF functions
while we're here.
Differential Revision: http://reviews.llvm.org/D21743
Modified:
llvm/trunk/include/llvm/MC/MCContext.h
llvm/trunk/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
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=274336&r1=274335&r2=274336&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCContext.h (original)
+++ llvm/trunk/include/llvm/MC/MCContext.h Fri Jul 1 01:07:38 2016
@@ -339,48 +339,56 @@ namespace llvm {
BeginSymName);
}
- MCSectionELF *getELFSection(StringRef Section, unsigned Type,
+ MCSectionELF *getELFSection(const Twine &Section, unsigned Type,
unsigned Flags) {
return getELFSection(Section, Type, Flags, nullptr);
}
- MCSectionELF *getELFSection(StringRef Section, unsigned Type,
+ MCSectionELF *getELFSection(const Twine &Section, unsigned Type,
unsigned Flags, const char *BeginSymName) {
return getELFSection(Section, Type, Flags, 0, "", BeginSymName);
}
- MCSectionELF *getELFSection(StringRef Section, unsigned Type,
+ MCSectionELF *getELFSection(const Twine &Section, unsigned Type,
unsigned Flags, unsigned EntrySize,
- StringRef Group) {
+ const Twine &Group) {
return getELFSection(Section, Type, Flags, EntrySize, Group, nullptr);
}
- MCSectionELF *getELFSection(StringRef Section, unsigned Type,
+ MCSectionELF *getELFSection(const Twine &Section, unsigned Type,
unsigned Flags, unsigned EntrySize,
- StringRef Group, const char *BeginSymName) {
+ const Twine &Group, const char *BeginSymName) {
return getELFSection(Section, Type, Flags, EntrySize, Group, ~0,
BeginSymName);
}
- MCSectionELF *getELFSection(StringRef Section, unsigned Type,
+ MCSectionELF *getELFSection(const Twine &Section, unsigned Type,
unsigned Flags, unsigned EntrySize,
- StringRef Group, unsigned UniqueID) {
+ const Twine &Group, unsigned UniqueID) {
return getELFSection(Section, Type, Flags, EntrySize, Group, UniqueID,
nullptr);
}
- MCSectionELF *getELFSection(StringRef Section, unsigned Type,
+ MCSectionELF *getELFSection(const Twine &Section, unsigned Type,
unsigned Flags, unsigned EntrySize,
- StringRef Group, unsigned UniqueID,
+ const Twine &Group, unsigned UniqueID,
const char *BeginSymName);
- MCSectionELF *getELFSection(StringRef Section, unsigned Type,
+ MCSectionELF *getELFSection(const Twine &Section, unsigned Type,
unsigned Flags, unsigned EntrySize,
const MCSymbolELF *Group, unsigned UniqueID,
const char *BeginSymName,
const MCSectionELF *Associated);
- MCSectionELF *createELFRelSection(StringRef Name, unsigned Type,
+ /// Get a section with the provided group identifier. This section is
+ /// named by concatenating \p Prefix with '.' then \p Suffix. The \p Type
+ /// describes the type of the section and \p Flags are used to further
+ /// configure this named section.
+ MCSectionELF *getELFNamedSection(const Twine &Prefix, const Twine &Suffix,
+ unsigned Type, unsigned Flags,
+ unsigned EntrySize = 0);
+
+ MCSectionELF *createELFRelSection(const Twine &Name, unsigned Type,
unsigned Flags, unsigned EntrySize,
const MCSymbolELF *Group,
const MCSectionELF *Associated);
Modified: llvm/trunk/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/TargetLoweringObjectFileImpl.cpp?rev=274336&r1=274335&r2=274336&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/TargetLoweringObjectFileImpl.cpp (original)
+++ llvm/trunk/lib/CodeGen/TargetLoweringObjectFileImpl.cpp Fri Jul 1 01:07:38 2016
@@ -69,11 +69,9 @@ void TargetLoweringObjectFileELF::emitPe
cast<MCSymbolELF>(getContext().getOrCreateSymbol(NameData));
Streamer.EmitSymbolAttribute(Label, MCSA_Hidden);
Streamer.EmitSymbolAttribute(Label, MCSA_Weak);
- StringRef Prefix = ".data.";
- NameData.insert(NameData.begin(), Prefix.begin(), Prefix.end());
unsigned Flags = ELF::SHF_ALLOC | ELF::SHF_WRITE | ELF::SHF_GROUP;
- MCSection *Sec = getContext().getELFSection(NameData, ELF::SHT_PROGBITS,
- Flags, 0, Label->getName());
+ MCSection *Sec = getContext().getELFNamedSection(".data", Label->getName(),
+ ELF::SHT_PROGBITS, Flags, 0);
unsigned Size = DL.getPointerSize();
Streamer.SwitchSection(Sec);
Streamer.EmitValueToAlignment(DL.getPointerABIAlignment());
Modified: llvm/trunk/lib/MC/MCContext.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCContext.cpp?rev=274336&r1=274335&r2=274336&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCContext.cpp (original)
+++ llvm/trunk/lib/MC/MCContext.cpp Fri Jul 1 01:07:38 2016
@@ -309,32 +309,40 @@ void MCContext::renameELFSection(MCSecti
const_cast<MCSectionELF *>(Section)->setSectionName(CachedName);
}
-MCSectionELF *MCContext::createELFRelSection(StringRef Name, unsigned Type,
+MCSectionELF *MCContext::createELFRelSection(const Twine &Name, unsigned Type,
unsigned Flags, unsigned EntrySize,
const MCSymbolELF *Group,
const MCSectionELF *Associated) {
StringMap<bool>::iterator I;
bool Inserted;
- std::tie(I, Inserted) = ELFRelSecNames.insert(std::make_pair(Name, true));
+ std::tie(I, Inserted) =
+ ELFRelSecNames.insert(std::make_pair(Name.str(), true));
return new (ELFAllocator.Allocate())
MCSectionELF(I->getKey(), Type, Flags, SectionKind::getReadOnly(),
EntrySize, Group, true, nullptr, Associated);
}
-MCSectionELF *MCContext::getELFSection(StringRef Section, unsigned Type,
+MCSectionELF *MCContext::getELFNamedSection(const Twine &Prefix,
+ const Twine &Suffix, unsigned Type,
+ unsigned Flags,
+ unsigned EntrySize) {
+ return getELFSection(Prefix + "." + Suffix, Type, Flags, EntrySize, Suffix);
+}
+
+MCSectionELF *MCContext::getELFSection(const Twine &Section, unsigned Type,
unsigned Flags, unsigned EntrySize,
- StringRef Group, unsigned UniqueID,
+ const Twine &Group, unsigned UniqueID,
const char *BeginSymName) {
MCSymbolELF *GroupSym = nullptr;
- if (!Group.empty())
+ if (!Group.isTriviallyEmpty() && !Group.str().empty())
GroupSym = cast<MCSymbolELF>(getOrCreateSymbol(Group));
return getELFSection(Section, Type, Flags, EntrySize, GroupSym, UniqueID,
BeginSymName, nullptr);
}
-MCSectionELF *MCContext::getELFSection(StringRef Section, unsigned Type,
+MCSectionELF *MCContext::getELFSection(const Twine &Section, unsigned Type,
unsigned Flags, unsigned EntrySize,
const MCSymbolELF *GroupSym,
unsigned UniqueID,
@@ -345,7 +353,7 @@ MCSectionELF *MCContext::getELFSection(S
Group = GroupSym->getName();
// Do the lookup, if we have a hit, return it.
auto IterBool = ELFUniquingMap.insert(
- std::make_pair(ELFSectionKey{Section, Group, UniqueID}, nullptr));
+ std::make_pair(ELFSectionKey{Section.str(), Group, UniqueID}, nullptr));
auto &Entry = *IterBool.first;
if (!IterBool.second)
return Entry.second;
More information about the llvm-commits
mailing list