[llvm] [MC] Eliminate two symbol-related hash maps (PR #95464)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 13 13:03:11 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-webassembly
@llvm/pr-subscribers-mc
Author: None (aengelke)
<details>
<summary>Changes</summary>
Previously, a symbol insertion requires (at least) three hash table operations:
- Lookup/create entry in Symbols (main symbol table)
- Lookup NextUniqueID to deduplicate identical temporary labels
- Add entry to UsedNames, which is also used to serve as storage for the symbol name in the MCSymbol.
All three lookups are done with the same name, so combining these into a single table reduces the number of lookups to one. Thus, a pointer to a symbol table entry can be passed to createSymbol to avoid a duplicate lookup of the same name.
The new symbol table entry value is placed in a separate header to avoid including MCContext in MCSymbol or vice versa.
http://llvm-compile-time-tracker.com/compare.php?from=846e47e7b880bcf6b8f5773fe0fe236d486f3239&to=a1e780d1eea6be4d79d40d825d2b3e081e765c55&stat=instructions:u
---
Patch is 24.17 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/95464.diff
14 Files Affected:
- (modified) llvm/include/llvm/MC/MCContext.h (+10-18)
- (modified) llvm/include/llvm/MC/MCSymbol.h (+6-6)
- (modified) llvm/include/llvm/MC/MCSymbolCOFF.h (+2-1)
- (modified) llvm/include/llvm/MC/MCSymbolELF.h (+2-1)
- (modified) llvm/include/llvm/MC/MCSymbolGOFF.h (+2-1)
- (modified) llvm/include/llvm/MC/MCSymbolMachO.h (+2-1)
- (added) llvm/include/llvm/MC/MCSymbolTableEntry.h (+45)
- (modified) llvm/include/llvm/MC/MCSymbolWasm.h (+2-1)
- (modified) llvm/include/llvm/MC/MCSymbolXCOFF.h (+2-1)
- (modified) llvm/lib/MC/MCContext.cpp (+50-50)
- (modified) llvm/lib/MC/MCParser/AsmParser.cpp (+3-2)
- (modified) llvm/lib/MC/MCParser/MasmParser.cpp (+3-2)
- (modified) llvm/lib/MC/MCSymbol.cpp (+1-1)
- (modified) llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp (+2-2)
``````````diff
diff --git a/llvm/include/llvm/MC/MCContext.h b/llvm/include/llvm/MC/MCContext.h
index ad412409b3e13..b0b00fc2c4fba 100644
--- a/llvm/include/llvm/MC/MCContext.h
+++ b/llvm/include/llvm/MC/MCContext.h
@@ -21,6 +21,7 @@
#include "llvm/MC/MCDwarf.h"
#include "llvm/MC/MCPseudoProbe.h"
#include "llvm/MC/MCSection.h"
+#include "llvm/MC/MCSymbolTableEntry.h"
#include "llvm/MC/SectionKind.h"
#include "llvm/Support/Allocator.h"
#include "llvm/Support/Compiler.h"
@@ -80,7 +81,7 @@ struct WasmSignature;
///
class MCContext {
public:
- using SymbolTable = StringMap<MCSymbol *, BumpPtrAllocator &>;
+ using SymbolTable = StringMap<MCSymbolTableValue, BumpPtrAllocator &>;
using DiagHandlerTy =
std::function<void(const SMDiagnostic &, bool, const SourceMgr &,
std::vector<const MDNode *> &)>;
@@ -146,7 +147,7 @@ class MCContext {
SpecificBumpPtrAllocator<wasm::WasmSignature> WasmSignatureAllocator;
- /// Bindings of names to symbols.
+ /// Bindings of names to symbol table values.
SymbolTable Symbols;
/// A mapping from a local label number and an instance count to a symbol.
@@ -157,18 +158,8 @@ class MCContext {
/// We have three labels represented by the pairs (1, 0), (2, 0) and (1, 1)
DenseMap<std::pair<unsigned, unsigned>, MCSymbol *> LocalSymbols;
- /// Keeps tracks of names that were used both for used declared and
- /// artificial symbols. The value is "true" if the name has been used for a
- /// non-section symbol (there can be at most one of those, plus an unlimited
- /// number of section symbols with the same name).
- StringMap<bool, BumpPtrAllocator &> UsedNames;
-
/// Keeps track of labels that are used in inline assembly.
- SymbolTable InlineAsmUsedLabelNames;
-
- /// The next ID to dole out to an unnamed assembler temporary symbol with
- /// a given prefix.
- StringMap<unsigned> NextID;
+ StringMap<MCSymbol *, BumpPtrAllocator &> InlineAsmUsedLabelNames;
/// Instances of directional local labels.
DenseMap<unsigned, MCLabel *> Instances;
@@ -345,10 +336,11 @@ class MCContext {
void reportCommon(SMLoc Loc,
std::function<void(SMDiagnostic &, const SourceMgr *)>);
- MCSymbol *createSymbolImpl(const StringMapEntry<bool> *Name,
- bool IsTemporary);
- MCSymbol *createSymbol(StringRef Name, bool AlwaysAddSuffix,
- bool IsTemporary);
+ MCSymbolTableEntry &getSymbolTableEntry(StringRef Name);
+
+ MCSymbol *createSymbolImpl(const MCSymbolTableEntry *Name, bool IsTemporary);
+ MCSymbol *createSymbol(MCSymbolTableEntry *Entry, StringRef Name,
+ bool AlwaysAddSuffix, bool IsTemporary);
MCSymbol *getOrCreateDirectionalLocalSymbol(unsigned LocalLabelVal,
unsigned Instance);
@@ -360,7 +352,7 @@ class MCContext {
unsigned UniqueID,
const MCSymbolELF *LinkedToSym);
- MCSymbolXCOFF *createXCOFFSymbolImpl(const StringMapEntry<bool> *Name,
+ MCSymbolXCOFF *createXCOFFSymbolImpl(const MCSymbolTableEntry *Name,
bool IsTemporary);
/// Map of currently defined macros.
diff --git a/llvm/include/llvm/MC/MCSymbol.h b/llvm/include/llvm/MC/MCSymbol.h
index a53e53179e471..5f06249b479eb 100644
--- a/llvm/include/llvm/MC/MCSymbol.h
+++ b/llvm/include/llvm/MC/MCSymbol.h
@@ -17,6 +17,7 @@
#include "llvm/ADT/StringRef.h"
#include "llvm/MC/MCExpr.h"
#include "llvm/MC/MCFragment.h"
+#include "llvm/MC/MCSymbolTableEntry.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/MathExtras.h"
#include <cassert>
@@ -156,11 +157,11 @@ class MCSymbol {
/// system, the name is a pointer so isn't going to satisfy the 8 byte
/// alignment of uint64_t. Account for that here.
using NameEntryStorageTy = union {
- const StringMapEntry<bool> *NameEntry;
+ const MCSymbolTableEntry *NameEntry;
uint64_t AlignmentPadding;
};
- MCSymbol(SymbolKind Kind, const StringMapEntry<bool> *Name, bool isTemporary)
+ MCSymbol(SymbolKind Kind, const MCSymbolTableEntry *Name, bool isTemporary)
: IsTemporary(isTemporary), IsRedefinable(false), IsUsed(false),
IsRegistered(false), IsExternal(false), IsPrivateExtern(false),
IsWeakExternal(false), Kind(Kind), IsUsedInReloc(false),
@@ -173,8 +174,7 @@ class MCSymbol {
// Provide custom new/delete as we will only allocate space for a name
// if we need one.
- void *operator new(size_t s, const StringMapEntry<bool> *Name,
- MCContext &Ctx);
+ void *operator new(size_t s, const MCSymbolTableEntry *Name, MCContext &Ctx);
private:
void operator delete(void *);
@@ -188,12 +188,12 @@ class MCSymbol {
}
/// Get a reference to the name field. Requires that we have a name
- const StringMapEntry<bool> *&getNameEntryPtr() {
+ const MCSymbolTableEntry *&getNameEntryPtr() {
assert(HasName && "Name is required");
NameEntryStorageTy *Name = reinterpret_cast<NameEntryStorageTy *>(this);
return (*(Name - 1)).NameEntry;
}
- const StringMapEntry<bool> *&getNameEntryPtr() const {
+ const MCSymbolTableEntry *&getNameEntryPtr() const {
return const_cast<MCSymbol*>(this)->getNameEntryPtr();
}
diff --git a/llvm/include/llvm/MC/MCSymbolCOFF.h b/llvm/include/llvm/MC/MCSymbolCOFF.h
index 7983fff7e6afd..2964c521e8e44 100644
--- a/llvm/include/llvm/MC/MCSymbolCOFF.h
+++ b/llvm/include/llvm/MC/MCSymbolCOFF.h
@@ -11,6 +11,7 @@
#include "llvm/BinaryFormat/COFF.h"
#include "llvm/MC/MCSymbol.h"
+#include "llvm/MC/MCSymbolTableEntry.h"
#include <cstdint>
namespace llvm {
@@ -29,7 +30,7 @@ class MCSymbolCOFF : public MCSymbol {
};
public:
- MCSymbolCOFF(const StringMapEntry<bool> *Name, bool isTemporary)
+ MCSymbolCOFF(const MCSymbolTableEntry *Name, bool isTemporary)
: MCSymbol(SymbolKindCOFF, Name, isTemporary) {}
uint16_t getType() const {
diff --git a/llvm/include/llvm/MC/MCSymbolELF.h b/llvm/include/llvm/MC/MCSymbolELF.h
index 9fc49ea322ce2..13c2c6b13f8e1 100644
--- a/llvm/include/llvm/MC/MCSymbolELF.h
+++ b/llvm/include/llvm/MC/MCSymbolELF.h
@@ -9,6 +9,7 @@
#define LLVM_MC_MCSYMBOLELF_H
#include "llvm/MC/MCSymbol.h"
+#include "llvm/MC/MCSymbolTableEntry.h"
namespace llvm {
class MCSymbolELF : public MCSymbol {
@@ -17,7 +18,7 @@ class MCSymbolELF : public MCSymbol {
const MCExpr *SymbolSize = nullptr;
public:
- MCSymbolELF(const StringMapEntry<bool> *Name, bool isTemporary)
+ MCSymbolELF(const MCSymbolTableEntry *Name, bool isTemporary)
: MCSymbol(SymbolKindELF, Name, isTemporary) {}
void setSize(const MCExpr *SS) { SymbolSize = SS; }
diff --git a/llvm/include/llvm/MC/MCSymbolGOFF.h b/llvm/include/llvm/MC/MCSymbolGOFF.h
index cc4e2bbe246e2..9ca53a5653108 100644
--- a/llvm/include/llvm/MC/MCSymbolGOFF.h
+++ b/llvm/include/llvm/MC/MCSymbolGOFF.h
@@ -14,12 +14,13 @@
#define LLVM_MC_MCSYMBOLGOFF_H
#include "llvm/MC/MCSymbol.h"
+#include "llvm/MC/MCSymbolTableEntry.h"
namespace llvm {
class MCSymbolGOFF : public MCSymbol {
public:
- MCSymbolGOFF(const StringMapEntry<bool> *Name, bool IsTemporary)
+ MCSymbolGOFF(const MCSymbolTableEntry *Name, bool IsTemporary)
: MCSymbol(SymbolKindGOFF, Name, IsTemporary) {}
static bool classof(const MCSymbol *S) { return S->isGOFF(); }
};
diff --git a/llvm/include/llvm/MC/MCSymbolMachO.h b/llvm/include/llvm/MC/MCSymbolMachO.h
index bce0f82da62cd..f75f61c198c11 100644
--- a/llvm/include/llvm/MC/MCSymbolMachO.h
+++ b/llvm/include/llvm/MC/MCSymbolMachO.h
@@ -10,6 +10,7 @@
#include "llvm/ADT/Twine.h"
#include "llvm/MC/MCSymbol.h"
+#include "llvm/MC/MCSymbolTableEntry.h"
namespace llvm {
class MCSymbolMachO : public MCSymbol {
@@ -42,7 +43,7 @@ class MCSymbolMachO : public MCSymbol {
};
public:
- MCSymbolMachO(const StringMapEntry<bool> *Name, bool isTemporary)
+ MCSymbolMachO(const MCSymbolTableEntry *Name, bool isTemporary)
: MCSymbol(SymbolKindMachO, Name, isTemporary) {}
// Reference type methods.
diff --git a/llvm/include/llvm/MC/MCSymbolTableEntry.h b/llvm/include/llvm/MC/MCSymbolTableEntry.h
new file mode 100644
index 0000000000000..e083d5ac2dc4c
--- /dev/null
+++ b/llvm/include/llvm/MC/MCSymbolTableEntry.h
@@ -0,0 +1,45 @@
+//===-- llvm/MC/MCSymbolTableEntry.h - Symbol table entry -------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_MC_MCSYMBOLTABLEENTRY_H
+#define LLVM_MC_MCSYMBOLTABLEENTRY_H
+
+#include "llvm/ADT/StringMapEntry.h"
+
+namespace llvm {
+
+class MCSymbol;
+
+/// The value for an entry in the symbol table of an MCContext.
+///
+/// This is in a separate file, because MCSymbol uses MCSymbolTableEntry (see
+/// below) to reuse the name that is stored in the symbol table.
+struct MCSymbolTableValue {
+ /// The symbol associated with the name, if any.
+ MCSymbol *Symbol = nullptr;
+
+ /// The next ID to dole out to an unnamed assembler temporary symbol with
+ /// the prefix (symbol table key).
+ unsigned NextUniqueID = 0;
+
+ /// Whether the name associated with this value is used for a symbol. This is
+ /// not necessarily true: sometimes, we use a symbol table value without an
+ /// associated symbol for accessing NextUniqueID when a suffix is added to a
+ /// name. However, Used might be true even if Symbol is nullptr: temporary
+ /// named symbols are not added to the symbol table.
+ bool Used = false;
+};
+
+/// MCContext stores MCSymbolTableValue in a string map. To avoid redundant
+/// storage of the name, MCSymbol stores a pointer (8 bytes -- half the size of
+/// a StringRef) to the entry to access it.
+using MCSymbolTableEntry = StringMapEntry<MCSymbolTableValue>;
+
+} // end namespace llvm
+
+#endif
diff --git a/llvm/include/llvm/MC/MCSymbolWasm.h b/llvm/include/llvm/MC/MCSymbolWasm.h
index 0c2b97a594231..e566ad83cd603 100644
--- a/llvm/include/llvm/MC/MCSymbolWasm.h
+++ b/llvm/include/llvm/MC/MCSymbolWasm.h
@@ -10,6 +10,7 @@
#include "llvm/BinaryFormat/Wasm.h"
#include "llvm/MC/MCSymbol.h"
+#include "llvm/MC/MCSymbolTableEntry.h"
namespace llvm {
@@ -33,7 +34,7 @@ class MCSymbolWasm : public MCSymbol {
const MCExpr *SymbolSize = nullptr;
public:
- MCSymbolWasm(const StringMapEntry<bool> *Name, bool isTemporary)
+ MCSymbolWasm(const MCSymbolTableEntry *Name, bool isTemporary)
: MCSymbol(SymbolKindWasm, Name, isTemporary) {}
static bool classof(const MCSymbol *S) { return S->isWasm(); }
diff --git a/llvm/include/llvm/MC/MCSymbolXCOFF.h b/llvm/include/llvm/MC/MCSymbolXCOFF.h
index 3bf4491e8fe2f..8877431a26d45 100644
--- a/llvm/include/llvm/MC/MCSymbolXCOFF.h
+++ b/llvm/include/llvm/MC/MCSymbolXCOFF.h
@@ -11,6 +11,7 @@
#include "llvm/ADT/StringRef.h"
#include "llvm/BinaryFormat/XCOFF.h"
#include "llvm/MC/MCSymbol.h"
+#include "llvm/MC/MCSymbolTableEntry.h"
namespace llvm {
@@ -21,7 +22,7 @@ class MCSymbolXCOFF : public MCSymbol {
enum XCOFFSymbolFlags : uint16_t { SF_EHInfo = 0x0001 };
public:
- MCSymbolXCOFF(const StringMapEntry<bool> *Name, bool isTemporary)
+ MCSymbolXCOFF(const MCSymbolTableEntry *Name, bool isTemporary)
: MCSymbol(SymbolKindXCOFF, Name, isTemporary) {}
static bool classof(const MCSymbol *S) { return S->isXCOFF(); }
diff --git a/llvm/lib/MC/MCContext.cpp b/llvm/lib/MC/MCContext.cpp
index 0522f1bd7c7e4..7ac44f41186bf 100644
--- a/llvm/lib/MC/MCContext.cpp
+++ b/llvm/lib/MC/MCContext.cpp
@@ -70,7 +70,7 @@ MCContext::MCContext(const Triple &TheTriple, const MCAsmInfo *mai,
bool DoAutoReset, StringRef Swift5ReflSegmentName)
: Swift5ReflectionSegmentName(Swift5ReflSegmentName), TT(TheTriple),
SrcMgr(mgr), InlineSrcMgr(nullptr), DiagHandler(defaultDiagHandler),
- MAI(mai), MRI(mri), MSTI(msti), Symbols(Allocator), UsedNames(Allocator),
+ MAI(mai), MRI(mri), MSTI(msti), Symbols(Allocator),
InlineAsmUsedLabelNames(Allocator),
CurrentDwarfLoc(0, 0, 0, DWARF2_FLAG_IS_STMT, 0, 0),
AutoReset(DoAutoReset), TargetOptions(TargetOpts) {
@@ -153,7 +153,6 @@ void MCContext::reset() {
MCSubtargetAllocator.DestroyAll();
InlineAsmUsedLabelNames.clear();
- UsedNames.clear();
Symbols.clear();
Allocator.Reset();
Instances.clear();
@@ -179,7 +178,6 @@ void MCContext::reset() {
ELFEntrySizeMap.clear();
ELFSeenGenericMergeableSections.clear();
- NextID.clear();
DwarfLocSeen = false;
GenDwarfForAssembly = false;
GenDwarfFileNumber = 0;
@@ -205,11 +203,11 @@ MCSymbol *MCContext::getOrCreateSymbol(const Twine &Name) {
assert(!NameRef.empty() && "Normal symbols cannot be unnamed!");
- MCSymbol *&Sym = Symbols[NameRef];
- if (!Sym)
- Sym = createSymbol(NameRef, false, false);
+ MCSymbolTableEntry &Entry = getSymbolTableEntry(NameRef);
+ if (!Entry.second.Symbol)
+ Entry.second.Symbol = createSymbol(&Entry, NameRef, false, false);
- return Sym;
+ return Entry.second.Symbol;
}
MCSymbol *MCContext::getOrCreateFrameAllocSymbol(const Twine &FuncName,
@@ -228,7 +226,11 @@ MCSymbol *MCContext::getOrCreateLSDASymbol(const Twine &FuncName) {
FuncName);
}
-MCSymbol *MCContext::createSymbolImpl(const StringMapEntry<bool> *Name,
+MCSymbolTableEntry &MCContext::getSymbolTableEntry(StringRef Name) {
+ return *Symbols.insert(std::make_pair(Name, MCSymbolTableValue{})).first;
+}
+
+MCSymbol *MCContext::createSymbolImpl(const MCSymbolTableEntry *Name,
bool IsTemporary) {
static_assert(std::is_trivially_destructible<MCSymbolCOFF>(),
"MCSymbol classes must be trivially destructible");
@@ -264,34 +266,33 @@ MCSymbol *MCContext::createSymbolImpl(const StringMapEntry<bool> *Name,
MCSymbol(MCSymbol::SymbolKindUnset, Name, IsTemporary);
}
-MCSymbol *MCContext::createSymbol(StringRef Name, bool AlwaysAddSuffix,
- bool IsTemporary) {
+MCSymbol *MCContext::createSymbol(MCSymbolTableEntry *Entry, StringRef Name,
+ bool AlwaysAddSuffix, bool IsTemporary) {
// Determine whether this is a user written assembler temporary or normal
// label, if used.
if (!SaveTempLabels && !IsTemporary)
IsTemporary = Name.starts_with(MAI->getPrivateGlobalPrefix());
- SmallString<128> NewName = Name;
- bool AddSuffix = AlwaysAddSuffix;
- unsigned &NextUniqueID = NextID[Name];
- while (true) {
- if (AddSuffix) {
+ SmallString<128> NewName;
+
+ if (!Entry)
+ Entry = &getSymbolTableEntry(Name);
+ MCSymbolTableEntry *EntryPtr = Entry;
+ assert((IsTemporary || AlwaysAddSuffix || !EntryPtr->second.Used) &&
+ "Cannot rename non-temporary symbols");
+ while (AlwaysAddSuffix || EntryPtr->second.Used) {
+ AlwaysAddSuffix = false;
+
+ if (NewName.empty())
+ NewName = Name;
+ else
NewName.resize(Name.size());
- raw_svector_ostream(NewName) << NextUniqueID++;
- }
- auto NameEntry = UsedNames.insert(std::make_pair(NewName.str(), true));
- if (NameEntry.second || !NameEntry.first->second) {
- // Ok, we found a name.
- // Mark it as used for a non-section symbol.
- NameEntry.first->second = true;
- // Have the MCSymbol object itself refer to the copy of the string that is
- // embedded in the UsedNames entry.
- return createSymbolImpl(&*NameEntry.first, IsTemporary);
- }
- assert(IsTemporary && "Cannot rename non-temporary symbols");
- AddSuffix = true;
+ raw_svector_ostream(NewName) << Entry->second.NextUniqueID++;
+ EntryPtr = &getSymbolTableEntry(NewName.str());
}
- llvm_unreachable("Infinite loop");
+
+ EntryPtr->second.Used = true;
+ return createSymbolImpl(EntryPtr, IsTemporary);
}
MCSymbol *MCContext::createTempSymbol(const Twine &Name, bool AlwaysAddSuffix) {
@@ -300,13 +301,13 @@ MCSymbol *MCContext::createTempSymbol(const Twine &Name, bool AlwaysAddSuffix) {
SmallString<128> NameSV;
raw_svector_ostream(NameSV) << MAI->getPrivateGlobalPrefix() << Name;
- return createSymbol(NameSV, AlwaysAddSuffix, true);
+ return createSymbol(nullptr, NameSV, AlwaysAddSuffix, true);
}
MCSymbol *MCContext::createNamedTempSymbol(const Twine &Name) {
SmallString<128> NameSV;
raw_svector_ostream(NameSV) << MAI->getPrivateGlobalPrefix() << Name;
- return createSymbol(NameSV, true, false);
+ return createSymbol(nullptr, NameSV, true, false);
}
MCSymbol *MCContext::createLinkerPrivateTempSymbol() {
@@ -316,7 +317,7 @@ MCSymbol *MCContext::createLinkerPrivateTempSymbol() {
MCSymbol *MCContext::createLinkerPrivateSymbol(const Twine &Name) {
SmallString<128> NameSV;
raw_svector_ostream(NameSV) << MAI->getLinkerPrivateGlobalPrefix() << Name;
- return createSymbol(NameSV, true, false);
+ return createSymbol(nullptr, NameSV, true, false);
}
MCSymbol *MCContext::createTempSymbol() { return createTempSymbol("tmp"); }
@@ -363,7 +364,7 @@ MCSymbol *MCContext::getDirectionalLocalSymbol(unsigned LocalLabelVal,
MCSymbol *MCContext::lookupSymbol(const Twine &Name) const {
SmallString<128> NameSV;
StringRef NameRef = Name.toStringRef(NameSV);
- return Symbols.lookup(NameRef);
+ return Symbols.lookup(NameRef).Symbol;
}
void MCContext::setSymbolValue(MCStreamer &Streamer, const Twine &Sym,
@@ -380,9 +381,8 @@ wasm::WasmSignature *MCContext::createWasmSignature() {
return new (WasmSignatureAllocator.Allocate()) wasm::WasmSignature;
}
-MCSymbolXCOFF *
-MCContext::createXCOFFSymbolImpl(const StringMapEntry<bool> *Name,
- bool IsTemporary) {
+MCSymbolXCOFF *MCContext::createXCOFFSymbolImpl(const MCSymbolTableEntry *Name,
+ bool IsTemporary) {
if (!Name)
return new (nullptr, *this) MCSymbolXCOFF(nullptr, IsTemporary);
@@ -422,15 +422,13 @@ MCContext::createXCOFFSymbolImpl(const StringMapEntry<bool> *Name,
else
ValidName.append(InvalidName);
- auto NameEntry = UsedNames.insert(std::make_pair(ValidName.str(), true));
- assert((NameEntry.second || !NameEntry.first->second) &&
- "This name is used somewhere else.");
- // Mark the name as used for a non-section symbol.
- NameEntry.first->second = true;
+ MCSymbolTableEntry &NameEntry = getSymbolTableEntry(ValidName.str());
+ assert(!NameEntry.second.Used && "This name is used somewhere else.");
+ NameEntry.second.Used = true;
// Have the MCSymbol object itself refer to the copy of the string
- // that is embedded in the UsedNames entry.
- MCSymbolXCOFF *XSym = new (&*NameEntry.first, *this)
- MCSymbolXCOFF(&*NameEntry.first, IsTemporary);
+ // that is embedded in the symbol table entry.
+ MCSymbolXCOFF *XSym =
+ new (&NameEntry, *this) MCSymbolXCOFF(&NameEntry, IsTemporary);
XSym->setSymbolTableName(MCSymbolXCOFF::getUnqualifiedName(OriginalName));
return XSym;
}
@@ -476,7 +474,8 @@ MCSectionELF *MCContext::createELFSectionImpl(StringRef Section, unsigned Type,
bool Comdat, unsigned UniqueID,
const MCSymbolELF *LinkedToSym) {
MCSymbolELF *R;
- MCSymbol *&Sym = Symbols[Section];
+ MCSymbolTableEntry &SymEntry = getSymbolTableEntry(Section);
+ MCSymbol *Sym = SymEntry.second.Symbol;
// 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() &&
@@ -485,10 +484,10 @@ MCSectionELF *MCContext::createELFSectionImpl(StringRef Section, unsigned Type,
if (Sym && Sym->isUndefined()) {
R = cast<MCSymbolELF>(Sym);
} else {
- auto NameIter = UsedNames.insert(std::make_pair(Section, false)).first;
- R = new (&*NameIter, *this) MCSymbolELF(&*NameIter, /*isTemporary*/ false);
+ SymEntry.second.Used = true;
+ R = new (&SymEntry, *this) MCSymbolELF(&SymEntry, /*isTemporary*/ false);
if (!Sym)
- Sym = R;
+ SymEntry.second.Symbol = R;
}
R->setBinding(ELF::STB_LOCAL);
R->setType(ELF::STT_SECTION);
@@ -789,8 +788,9 @@ MCSectionWasm *MCContext::...
[truncated]
``````````
</details>
https://github.com/llvm/llvm-project/pull/95464
More information about the llvm-commits
mailing list