Index: include/llvm/MC/MCContext.h =================================================================== --- include/llvm/MC/MCContext.h +++ include/llvm/MC/MCContext.h @@ -387,43 +387,41 @@ BeginSymName); } - MCSectionELF *getELFSection(const Twine &Section, unsigned Type, - unsigned Flags) { - return getELFSection(Section, Type, Flags, 0, ""); + MCSectionELF *getELFSection(StringRef Name, unsigned Type, unsigned Flags) { + return getELFSection(Name, Type, Flags, 0, ""); } - MCSectionELF *getELFSection(const Twine &Section, unsigned Type, - unsigned Flags, unsigned EntrySize, - const Twine &Group) { - return getELFSection(Section, Type, Flags, EntrySize, Group, ~0); + MCSectionELF *getELFSection(StringRef Name, unsigned Type, unsigned Flags, + unsigned EntrySize, const Twine &Group) { + return getELFSection(Name, Type, Flags, EntrySize, Group, ~0); } - MCSectionELF *getELFSection(const Twine &Section, unsigned Type, - unsigned Flags, unsigned EntrySize, - const Twine &Group, unsigned UniqueID) { - return getELFSection(Section, Type, Flags, EntrySize, Group, UniqueID, + MCSectionELF *getELFSection(StringRef Name, unsigned Type, unsigned Flags, + unsigned EntrySize, const Twine &Group, + unsigned UniqueID) { + return getELFSection(Name, Type, Flags, EntrySize, Group, UniqueID, nullptr); } - MCSectionELF *getELFSection(const Twine &Section, unsigned Type, - unsigned Flags, unsigned EntrySize, - const Twine &Group, unsigned UniqueID, + MCSectionELF *getELFSection(StringRef Name, unsigned Type, unsigned Flags, + unsigned EntrySize, const Twine &Group, + unsigned UniqueID, const MCSymbolELF *Associated); - MCSectionELF *getELFSection(const Twine &Section, unsigned Type, - unsigned Flags, unsigned EntrySize, - const MCSymbolELF *Group, unsigned UniqueID, + MCSectionELF *getELFSection(StringRef Name, unsigned Type, unsigned Flags, + unsigned EntrySize, const MCSymbolELF *Group, + unsigned UniqueID, const MCSymbolELF *Associated); /// 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, + MCSectionELF *getELFNamedSection(StringRef Prefix, StringRef Suffix, unsigned Type, unsigned Flags, unsigned EntrySize = 0); - MCSectionELF *createELFRelSection(const Twine &Name, unsigned Type, + MCSectionELF *createELFRelSection(StringRef Name, unsigned Type, unsigned Flags, unsigned EntrySize, const MCSymbolELF *Group, const MCSectionELF *RelInfoSection); @@ -432,17 +430,17 @@ MCSectionELF *createELFGroupSection(const MCSymbolELF *Group); - MCSectionCOFF *getCOFFSection(StringRef Section, unsigned Characteristics, + MCSectionCOFF *getCOFFSection(StringRef Name, unsigned Characteristics, SectionKind Kind, StringRef COMDATSymName, int Selection, unsigned UniqueID = GenericSectionID, const char *BeginSymName = nullptr); - MCSectionCOFF *getCOFFSection(StringRef Section, unsigned Characteristics, + MCSectionCOFF *getCOFFSection(StringRef Name, unsigned Characteristics, SectionKind Kind, const char *BeginSymName = nullptr); - MCSectionCOFF *getCOFFSection(StringRef Section); + MCSectionCOFF *getCOFFSection(StringRef Name); /// Gets or creates a section equivalent to Sec that is associated with the /// section containing KeySym. For example, to create a debug info section @@ -452,25 +450,25 @@ getAssociativeCOFFSection(MCSectionCOFF *Sec, const MCSymbol *KeySym, unsigned UniqueID = GenericSectionID); - MCSectionWasm *getWasmSection(const Twine &Section, SectionKind K) { - return getWasmSection(Section, K, nullptr); + MCSectionWasm *getWasmSection(StringRef Name, SectionKind K) { + return getWasmSection(Name, K, nullptr); } - MCSectionWasm *getWasmSection(const Twine &Section, SectionKind K, + MCSectionWasm *getWasmSection(StringRef Name, SectionKind K, const char *BeginSymName) { - return getWasmSection(Section, K, "", ~0, BeginSymName); + return getWasmSection(Name, K, "", ~0, BeginSymName); } - MCSectionWasm *getWasmSection(const Twine &Section, SectionKind K, + MCSectionWasm *getWasmSection(StringRef Name, SectionKind K, const Twine &Group, unsigned UniqueID) { - return getWasmSection(Section, K, Group, UniqueID, nullptr); + return getWasmSection(Name, K, Group, UniqueID, nullptr); } - MCSectionWasm *getWasmSection(const Twine &Section, SectionKind K, + MCSectionWasm *getWasmSection(StringRef Name, SectionKind K, const Twine &Group, unsigned UniqueID, const char *BeginSymName); - MCSectionWasm *getWasmSection(const Twine &Section, SectionKind K, + MCSectionWasm *getWasmSection(StringRef Name, SectionKind K, const MCSymbolWasm *Group, unsigned UniqueID, const char *BeginSymName); Index: lib/MC/MCContext.cpp =================================================================== --- lib/MC/MCContext.cpp +++ lib/MC/MCContext.cpp @@ -313,14 +313,14 @@ const_cast(Section)->setSectionName(CachedName); } -MCSectionELF *MCContext::createELFSectionImpl(StringRef Section, unsigned Type, +MCSectionELF *MCContext::createELFSectionImpl(StringRef Name, unsigned Type, unsigned Flags, SectionKind K, unsigned EntrySize, const MCSymbolELF *Group, unsigned UniqueID, const MCSymbolELF *Associated) { MCSymbolELF *R; - MCSymbol *&Sym = Symbols[Section]; + MCSymbol *&Sym = Symbols[Name]; // A section symbol can not redefine regular symbols. There may be multiple // sections with the same name, in which case the first such section wins. if (Sym && Sym->isDefined() && @@ -329,7 +329,7 @@ if (Sym && Sym->isUndefined()) { R = cast(Sym); } else { - auto NameIter = UsedNames.insert(std::make_pair(Section, false)).first; + auto NameIter = UsedNames.insert(std::make_pair(Name, false)).first; R = new (&*NameIter, *this) MCSymbolELF(&*NameIter, /*isTemporary*/ false); if (!Sym) Sym = R; @@ -338,7 +338,7 @@ R->setType(ELF::STT_SECTION); auto *Ret = new (ELFAllocator.Allocate()) MCSectionELF( - Section, Type, Flags, K, EntrySize, Group, UniqueID, R, Associated); + Name, Type, Flags, K, EntrySize, Group, UniqueID, R, Associated); auto *F = new MCDataFragment(); Ret->getFragmentList().insert(Ret->begin(), F); @@ -348,28 +348,27 @@ return Ret; } -MCSectionELF *MCContext::createELFRelSection(const Twine &Name, unsigned Type, - unsigned Flags, unsigned EntrySize, - const MCSymbolELF *Group, - const MCSectionELF *RelInfoSection) { +MCSectionELF * +MCContext::createELFRelSection(StringRef Name, unsigned Type, unsigned Flags, + unsigned EntrySize, const MCSymbolELF *Group, + const MCSectionELF *RelInfoSection) { StringMap::iterator I; bool Inserted; - std::tie(I, Inserted) = - RelSecNames.insert(std::make_pair(Name.str(), true)); + std::tie(I, Inserted) = RelSecNames.insert(std::make_pair(Name, true)); return createELFSectionImpl( I->getKey(), Type, Flags, SectionKind::getReadOnly(), EntrySize, Group, true, cast(RelInfoSection->getBeginSymbol())); } -MCSectionELF *MCContext::getELFNamedSection(const Twine &Prefix, - const Twine &Suffix, unsigned Type, - unsigned Flags, +MCSectionELF *MCContext::getELFNamedSection(StringRef Prefix, StringRef Suffix, + unsigned Type, unsigned Flags, unsigned EntrySize) { - return getELFSection(Prefix + "." + Suffix, Type, Flags, EntrySize, Suffix); + return getELFSection((Prefix + "." + Suffix).str(), Type, Flags, EntrySize, + Suffix); } -MCSectionELF *MCContext::getELFSection(const Twine &Section, unsigned Type, +MCSectionELF *MCContext::getELFSection(StringRef Name, unsigned Type, unsigned Flags, unsigned EntrySize, const Twine &Group, unsigned UniqueID, const MCSymbolELF *Associated) { @@ -377,11 +376,11 @@ if (!Group.isTriviallyEmpty() && !Group.str().empty()) GroupSym = cast(getOrCreateSymbol(Group)); - return getELFSection(Section, Type, Flags, EntrySize, GroupSym, UniqueID, + return getELFSection(Name, Type, Flags, EntrySize, GroupSym, UniqueID, Associated); } -MCSectionELF *MCContext::getELFSection(const Twine &Section, unsigned Type, +MCSectionELF *MCContext::getELFSection(StringRef Name, unsigned Type, unsigned Flags, unsigned EntrySize, const MCSymbolELF *GroupSym, unsigned UniqueID, @@ -391,7 +390,7 @@ Group = GroupSym->getName(); // Do the lookup, if we have a hit, return it. auto IterBool = ELFUniquingMap.insert( - std::make_pair(ELFSectionKey{Section.str(), Group, UniqueID}, nullptr)); + std::make_pair(ELFSectionKey{Name, Group, UniqueID}, nullptr)); auto &Entry = *IterBool.first; if (!IterBool.second) return Entry.second; @@ -418,7 +417,7 @@ nullptr); } -MCSectionCOFF *MCContext::getCOFFSection(StringRef Section, +MCSectionCOFF *MCContext::getCOFFSection(StringRef Name, unsigned Characteristics, SectionKind Kind, StringRef COMDATSymName, int Selection, @@ -432,7 +431,7 @@ // Do the lookup, if we have a hit, return it. - COFFSectionKey T{Section, COMDATSymName, Selection, UniqueID}; + COFFSectionKey T{Name, COMDATSymName, Selection, UniqueID}; auto IterBool = COFFUniquingMap.insert(std::make_pair(T, nullptr)); auto Iter = IterBool.first; if (!IterBool.second) @@ -487,7 +486,7 @@ "", 0, UniqueID); } -MCSectionWasm *MCContext::getWasmSection(const Twine &Section, SectionKind K, +MCSectionWasm *MCContext::getWasmSection(StringRef Name, SectionKind K, const Twine &Group, unsigned UniqueID, const char *BeginSymName) { MCSymbolWasm *GroupSym = nullptr; @@ -496,10 +495,10 @@ GroupSym->setComdat(true); } - return getWasmSection(Section, K, GroupSym, UniqueID, BeginSymName); + return getWasmSection(Name, K, GroupSym, UniqueID, BeginSymName); } -MCSectionWasm *MCContext::getWasmSection(const Twine &Section, SectionKind Kind, +MCSectionWasm *MCContext::getWasmSection(StringRef Name, SectionKind Kind, const MCSymbolWasm *GroupSym, unsigned UniqueID, const char *BeginSymName) { @@ -508,7 +507,7 @@ Group = GroupSym->getName(); // Do the lookup, if we have a hit, return it. auto IterBool = WasmUniquingMap.insert( - std::make_pair(WasmSectionKey{Section.str(), Group, UniqueID}, nullptr)); + std::make_pair(WasmSectionKey{Name, Group, UniqueID}, nullptr)); auto &Entry = *IterBool.first; if (!IterBool.second) return Entry.second;