[llvm] 792bb70 - [MCContext] Use `const Twine &` in symbol creation methods. NFC
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 21 23:14:05 PDT 2023
Author: paperchalice
Date: 2023-03-21T23:13:59-07:00
New Revision: 792bb70d298554a2fc431ffa7b83f37883336e78
URL: https://github.com/llvm/llvm-project/commit/792bb70d298554a2fc431ffa7b83f37883336e78
DIFF: https://github.com/llvm/llvm-project/commit/792bb70d298554a2fc431ffa7b83f37883336e78.diff
LOG: [MCContext] Use `const Twine &` in symbol creation methods. NFC
All of these methods will invoke `getOrCreateSymbol(const Twine &Name)`, using `Twine` here makes these methods more flexible.
Differential Revision: https://reviews.llvm.org/D145923
Added:
Modified:
llvm/include/llvm/MC/MCContext.h
llvm/lib/MC/MCContext.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/MC/MCContext.h b/llvm/include/llvm/MC/MCContext.h
index 653df37772db8..59f05bbc10cf1 100644
--- a/llvm/include/llvm/MC/MCContext.h
+++ b/llvm/include/llvm/MC/MCContext.h
@@ -506,17 +506,17 @@ class MCContext {
/// variable after codegen.
///
/// \param Idx - The index of a local variable passed to \@llvm.localescape.
- MCSymbol *getOrCreateFrameAllocSymbol(StringRef FuncName, unsigned Idx);
+ MCSymbol *getOrCreateFrameAllocSymbol(const Twine &FuncName, unsigned Idx);
- MCSymbol *getOrCreateParentFrameOffsetSymbol(StringRef FuncName);
+ MCSymbol *getOrCreateParentFrameOffsetSymbol(const Twine &FuncName);
- MCSymbol *getOrCreateLSDASymbol(StringRef FuncName);
+ MCSymbol *getOrCreateLSDASymbol(const Twine &FuncName);
/// Get the symbol for \p Name, or null.
MCSymbol *lookupSymbol(const Twine &Name) const;
/// Set value for a symbol.
- void setSymbolValue(MCStreamer &Streamer, StringRef Sym, uint64_t Val);
+ void setSymbolValue(MCStreamer &Streamer, const Twine &Sym, uint64_t Val);
/// getSymbols - Get a reference for the symbol table for clients that
/// want to, for example, iterate over all symbols. 'const' because we
@@ -664,7 +664,7 @@ class MCContext {
MCSectionWasm *getWasmSection(const Twine &Section, SectionKind K,
unsigned Flags, const MCSymbolWasm *Group,
unsigned UniqueID, const char *BeginSymName);
-
+
/// Get the section for the provided Section name
MCSectionDXContainer *getDXContainerSection(StringRef Section, SectionKind K);
diff --git a/llvm/lib/MC/MCContext.cpp b/llvm/lib/MC/MCContext.cpp
index 40e5e0f2ef24d..80a036a950bc9 100644
--- a/llvm/lib/MC/MCContext.cpp
+++ b/llvm/lib/MC/MCContext.cpp
@@ -211,19 +211,19 @@ MCSymbol *MCContext::getOrCreateSymbol(const Twine &Name) {
return Sym;
}
-MCSymbol *MCContext::getOrCreateFrameAllocSymbol(StringRef FuncName,
+MCSymbol *MCContext::getOrCreateFrameAllocSymbol(const Twine &FuncName,
unsigned Idx) {
- return getOrCreateSymbol(Twine(MAI->getPrivateGlobalPrefix()) + FuncName +
+ return getOrCreateSymbol(MAI->getPrivateGlobalPrefix() + FuncName +
"$frame_escape_" + Twine(Idx));
}
-MCSymbol *MCContext::getOrCreateParentFrameOffsetSymbol(StringRef FuncName) {
- return getOrCreateSymbol(Twine(MAI->getPrivateGlobalPrefix()) + FuncName +
+MCSymbol *MCContext::getOrCreateParentFrameOffsetSymbol(const Twine &FuncName) {
+ return getOrCreateSymbol(MAI->getPrivateGlobalPrefix() + FuncName +
"$parent_frame_offset");
}
-MCSymbol *MCContext::getOrCreateLSDASymbol(StringRef FuncName) {
- return getOrCreateSymbol(Twine(MAI->getPrivateGlobalPrefix()) + "__ehtable$" +
+MCSymbol *MCContext::getOrCreateLSDASymbol(const Twine &FuncName) {
+ return getOrCreateSymbol(MAI->getPrivateGlobalPrefix() + "__ehtable$" +
FuncName);
}
@@ -259,8 +259,8 @@ MCSymbol *MCContext::createSymbolImpl(const StringMapEntry<bool> *Name,
return new (Name, *this)
MCSymbol(MCSymbol::SymbolKindUnset, Name, IsTemporary);
}
- return new (Name, *this) MCSymbol(MCSymbol::SymbolKindUnset, Name,
- IsTemporary);
+ return new (Name, *this)
+ MCSymbol(MCSymbol::SymbolKindUnset, Name, IsTemporary);
}
MCSymbol *MCContext::createSymbol(StringRef Name, bool AlwaysAddSuffix,
@@ -362,9 +362,8 @@ MCSymbol *MCContext::lookupSymbol(const Twine &Name) const {
return Symbols.lookup(NameRef);
}
-void MCContext::setSymbolValue(MCStreamer &Streamer,
- StringRef Sym,
- uint64_t Val) {
+void MCContext::setSymbolValue(MCStreamer &Streamer, const Twine &Sym,
+ uint64_t Val) {
auto Symbol = getOrCreateSymbol(Sym);
Streamer.emitAssignment(Symbol, MCConstantExpr::create(Val, *this));
}
@@ -498,14 +497,13 @@ MCSectionELF *MCContext::createELFSectionImpl(StringRef Section, unsigned Type,
return Ret;
}
-MCSectionELF *MCContext::createELFRelSection(const Twine &Name, unsigned Type,
- unsigned Flags, unsigned EntrySize,
- const MCSymbolELF *Group,
- const MCSectionELF *RelInfoSection) {
+MCSectionELF *
+MCContext::createELFRelSection(const Twine &Name, unsigned Type, unsigned Flags,
+ unsigned EntrySize, const MCSymbolELF *Group,
+ const MCSectionELF *RelInfoSection) {
StringMap<bool>::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.str(), true));
return createELFSectionImpl(
I->getKey(), Type, Flags, SectionKind::getReadOnly(), EntrySize, Group,
@@ -669,7 +667,6 @@ MCSectionCOFF *MCContext::getCOFFSection(StringRef Section,
COMDATSymName = COMDATSymbol->getName();
}
-
// Do the lookup, if we have a hit, return it.
COFFSectionKey T{Section, COMDATSymName, Selection, UniqueID};
auto IterBool = COFFUniquingMap.insert(std::make_pair(T, nullptr));
More information about the llvm-commits
mailing list