Skip to content

Commit

Permalink
[MC] Don't evaluate name of unnamed symbols (llvm#95021)
Browse files Browse the repository at this point in the history
There's only one way to create unnamed symbols (createTempSymbol).
Previously, the name was evaluated unconditionally, but often
unnecessarily. Avoid this.

Also the parameter names in the header were wrong, fix these.
  • Loading branch information
aengelke authored Jun 10, 2024
1 parent 23a33a7 commit 4322997
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
2 changes: 1 addition & 1 deletion llvm/include/llvm/MC/MCContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ class MCContext {
std::function<void(SMDiagnostic &, const SourceMgr *)>);

MCSymbol *createSymbolImpl(const StringMapEntry<bool> *Name,
bool CanBeUnnamed);
bool IsTemporary);
MCSymbol *createSymbol(StringRef Name, bool AlwaysAddSuffix,
bool IsTemporary);

Expand Down
9 changes: 4 additions & 5 deletions llvm/lib/MC/MCContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,13 +264,9 @@ MCSymbol *MCContext::createSymbolImpl(const StringMapEntry<bool> *Name,
}

MCSymbol *MCContext::createSymbol(StringRef Name, bool AlwaysAddSuffix,
bool CanBeUnnamed) {
if (CanBeUnnamed && !UseNamesOnTempLabels)
return createSymbolImpl(nullptr, true);

bool IsTemporary) {
// Determine whether this is a user written assembler temporary or normal
// label, if used.
bool IsTemporary = CanBeUnnamed;
if (AllowTemporaryLabels && !IsTemporary)
IsTemporary = Name.starts_with(MAI->getPrivateGlobalPrefix());

Expand Down Expand Up @@ -298,6 +294,9 @@ MCSymbol *MCContext::createSymbol(StringRef Name, bool AlwaysAddSuffix,
}

MCSymbol *MCContext::createTempSymbol(const Twine &Name, bool AlwaysAddSuffix) {
if (!UseNamesOnTempLabels)
return createSymbolImpl(nullptr, /*IsTemporary=*/true);

SmallString<128> NameSV;
raw_svector_ostream(NameSV) << MAI->getPrivateGlobalPrefix() << Name;
return createSymbol(NameSV, AlwaysAddSuffix, true);
Expand Down

0 comments on commit 4322997

Please sign in to comment.