[llvm-branch-commits] [llvm] d9a0c40 - [MC] Split MCContext::createTempSymbol, default AlwaysAddSuffix to true, and add comments
Fangrui Song via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Mon Dec 21 14:09:32 PST 2020
Author: Fangrui Song
Date: 2020-12-21T14:04:13-08:00
New Revision: d9a0c40bce5f0b1325b89c36785d82fa146547aa
URL: https://github.com/llvm/llvm-project/commit/d9a0c40bce5f0b1325b89c36785d82fa146547aa
DIFF: https://github.com/llvm/llvm-project/commit/d9a0c40bce5f0b1325b89c36785d82fa146547aa.diff
LOG: [MC] Split MCContext::createTempSymbol, default AlwaysAddSuffix to true, and add comments
CanBeUnnamed is rarely false. Splitting to a createNamedTempSymbol makes the
intention clearer and matches the direction of reverted r240130 (to drop the
unneeded parameters).
No behavior change.
Added:
Modified:
llvm/include/llvm/MC/MCContext.h
llvm/lib/CodeGen/MachineModuleInfo.cpp
llvm/lib/MC/MCContext.cpp
llvm/lib/MC/MCDwarf.cpp
llvm/lib/MC/MCObjectStreamer.cpp
llvm/lib/MC/MCSection.cpp
llvm/lib/MC/MCStreamer.cpp
llvm/lib/Target/ARM/ARMAsmPrinter.cpp
llvm/lib/Target/PowerPC/PPCPreEmitPeephole.cpp
llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/MC/MCContext.h b/llvm/include/llvm/MC/MCContext.h
index 75e6dbe069e2..49ab0ce8d6fd 100644
--- a/llvm/include/llvm/MC/MCContext.h
+++ b/llvm/include/llvm/MC/MCContext.h
@@ -397,12 +397,16 @@ namespace llvm {
/// unspecified name.
MCSymbol *createLinkerPrivateTempSymbol();
- /// Create and return a new assembler temporary symbol with a unique but
- /// unspecified name.
- MCSymbol *createTempSymbol(bool CanBeUnnamed = true);
-
- MCSymbol *createTempSymbol(const Twine &Name, bool AlwaysAddSuffix,
- bool CanBeUnnamed = true);
+ /// Create a temporary symbol with a unique name. The name will be omitted
+ /// in the symbol table if UseNamesOnTempLabels is false (default except
+ /// MCAsmStreamer). The overload without Name uses an unspecified name.
+ MCSymbol *createTempSymbol();
+ MCSymbol *createTempSymbol(const Twine &Name, bool AlwaysAddSuffix = true);
+
+ /// Create a temporary symbol with a unique name whose name cannot be
+ /// omitted in the symbol table. This is rarely used.
+ MCSymbol *createNamedTempSymbol();
+ MCSymbol *createNamedTempSymbol(const Twine &Name);
/// Create the definition of a directional local symbol for numbered label
/// (used for "1:" definitions).
diff --git a/llvm/lib/CodeGen/MachineModuleInfo.cpp b/llvm/lib/CodeGen/MachineModuleInfo.cpp
index f75acbb2494b..5c2e2fb16b69 100644
--- a/llvm/lib/CodeGen/MachineModuleInfo.cpp
+++ b/llvm/lib/CodeGen/MachineModuleInfo.cpp
@@ -104,7 +104,8 @@ ArrayRef<MCSymbol *> MMIAddrLabelMap::getAddrLabelSymbolToEmit(BasicBlock *BB) {
BBCallbacks.back().setMap(this);
Entry.Index = BBCallbacks.size() - 1;
Entry.Fn = BB->getParent();
- MCSymbol *Sym = Context.createTempSymbol(!BB->hasAddressTaken());
+ MCSymbol *Sym = BB->hasAddressTaken() ? Context.createNamedTempSymbol()
+ : Context.createTempSymbol();
Entry.Symbols.push_back(Sym);
return Entry.Symbols;
}
diff --git a/llvm/lib/MC/MCContext.cpp b/llvm/lib/MC/MCContext.cpp
index d054c93e37f4..9dab8a6c0910 100644
--- a/llvm/lib/MC/MCContext.cpp
+++ b/llvm/lib/MC/MCContext.cpp
@@ -232,11 +232,16 @@ MCSymbol *MCContext::createSymbol(StringRef Name, bool AlwaysAddSuffix,
llvm_unreachable("Infinite loop");
}
-MCSymbol *MCContext::createTempSymbol(const Twine &Name, bool AlwaysAddSuffix,
- bool CanBeUnnamed) {
+MCSymbol *MCContext::createTempSymbol(const Twine &Name, bool AlwaysAddSuffix) {
SmallString<128> NameSV;
raw_svector_ostream(NameSV) << MAI->getPrivateGlobalPrefix() << Name;
- return createSymbol(NameSV, AlwaysAddSuffix, CanBeUnnamed);
+ return createSymbol(NameSV, AlwaysAddSuffix, true);
+}
+
+MCSymbol *MCContext::createNamedTempSymbol(const Twine &Name) {
+ SmallString<128> NameSV;
+ raw_svector_ostream(NameSV) << MAI->getPrivateGlobalPrefix() << Name;
+ return createSymbol(NameSV, true, false);
}
MCSymbol *MCContext::createLinkerPrivateTempSymbol() {
@@ -245,8 +250,10 @@ MCSymbol *MCContext::createLinkerPrivateTempSymbol() {
return createSymbol(NameSV, true, false);
}
-MCSymbol *MCContext::createTempSymbol(bool CanBeUnnamed) {
- return createTempSymbol("tmp", true, CanBeUnnamed);
+MCSymbol *MCContext::createTempSymbol() { return createTempSymbol("tmp"); }
+
+MCSymbol *MCContext::createNamedTempSymbol() {
+ return createNamedTempSymbol("tmp");
}
unsigned MCContext::NextInstance(unsigned LocalLabelVal) {
@@ -267,7 +274,7 @@ MCSymbol *MCContext::getOrCreateDirectionalLocalSymbol(unsigned LocalLabelVal,
unsigned Instance) {
MCSymbol *&Sym = LocalSymbols[std::make_pair(LocalLabelVal, Instance)];
if (!Sym)
- Sym = createTempSymbol(false);
+ Sym = createNamedTempSymbol();
return Sym;
}
diff --git a/llvm/lib/MC/MCDwarf.cpp b/llvm/lib/MC/MCDwarf.cpp
index 7f72d062b7ac..12a7d9b6e589 100644
--- a/llvm/lib/MC/MCDwarf.cpp
+++ b/llvm/lib/MC/MCDwarf.cpp
@@ -46,10 +46,8 @@
using namespace llvm;
MCSymbol *mcdwarf::emitListsTableHeaderStart(MCStreamer &S) {
- MCSymbol *Start =
- S.getContext().createTempSymbol("debug_list_header_start", true, true);
- MCSymbol *End =
- S.getContext().createTempSymbol("debug_list_header_end", true, true);
+ MCSymbol *Start = S.getContext().createTempSymbol("debug_list_header_start");
+ MCSymbol *End = S.getContext().createTempSymbol("debug_list_header_end");
auto DwarfFormat = S.getContext().getDwarfFormat();
if (DwarfFormat == dwarf::DWARF64) {
S.AddComment("DWARF64 mark");
@@ -1140,7 +1138,7 @@ static MCSymbol *emitGenDwarfRanges(MCStreamer *MCOS) {
MCSymbol *EndSymbol = mcdwarf::emitListsTableHeaderStart(*MCOS);
MCOS->AddComment("Offset entry count");
MCOS->emitInt32(0);
- RangesSymbol = context.createTempSymbol("debug_rnglist0_start", true, true);
+ RangesSymbol = context.createTempSymbol("debug_rnglist0_start");
MCOS->emitLabel(RangesSymbol);
for (MCSection *Sec : Sections) {
const MCSymbol *StartSymbol = Sec->getBeginSymbol();
@@ -1157,7 +1155,7 @@ static MCSymbol *emitGenDwarfRanges(MCStreamer *MCOS) {
MCOS->emitLabel(EndSymbol);
} else {
MCOS->SwitchSection(context.getObjectFileInfo()->getDwarfRangesSection());
- RangesSymbol = context.createTempSymbol("debug_ranges_start", true, true);
+ RangesSymbol = context.createTempSymbol("debug_ranges_start");
MCOS->emitLabel(RangesSymbol);
for (MCSection *Sec : Sections) {
const MCSymbol *StartSymbol = Sec->getBeginSymbol();
diff --git a/llvm/lib/MC/MCObjectStreamer.cpp b/llvm/lib/MC/MCObjectStreamer.cpp
index 2f464f4b58b6..1c23d31f8744 100644
--- a/llvm/lib/MC/MCObjectStreamer.cpp
+++ b/llvm/lib/MC/MCObjectStreamer.cpp
@@ -248,7 +248,7 @@ void MCObjectStreamer::emitValueImpl(const MCExpr *Value, unsigned Size,
}
MCSymbol *MCObjectStreamer::emitCFILabel() {
- MCSymbol *Label = getContext().createTempSymbol("cfi", true);
+ MCSymbol *Label = getContext().createTempSymbol("cfi");
emitLabel(Label);
return Label;
}
diff --git a/llvm/lib/MC/MCSection.cpp b/llvm/lib/MC/MCSection.cpp
index 7c5834895e52..7997b237a7eb 100644
--- a/llvm/lib/MC/MCSection.cpp
+++ b/llvm/lib/MC/MCSection.cpp
@@ -28,7 +28,7 @@ MCSection::MCSection(SectionVariant V, StringRef Name, SectionKind K,
MCSymbol *MCSection::getEndSymbol(MCContext &Ctx) {
if (!End)
- End = Ctx.createTempSymbol("sec_end", true);
+ End = Ctx.createTempSymbol("sec_end");
return End;
}
diff --git a/llvm/lib/MC/MCStreamer.cpp b/llvm/lib/MC/MCStreamer.cpp
index 71a89ad46703..4b5ae3cc202d 100644
--- a/llvm/lib/MC/MCStreamer.cpp
+++ b/llvm/lib/MC/MCStreamer.cpp
@@ -1076,7 +1076,7 @@ void MCStreamer::emitAbsoluteSymbolDiff(const MCSymbol *Hi, const MCSymbol *Lo,
}
// Otherwise, emit with .set (aka assignment).
- MCSymbol *SetLabel = Context.createTempSymbol("set", true);
+ MCSymbol *SetLabel = Context.createTempSymbol("set");
emitAssignment(SetLabel, Diff);
emitSymbolValue(SetLabel, Size);
}
diff --git a/llvm/lib/Target/ARM/ARMAsmPrinter.cpp b/llvm/lib/Target/ARM/ARMAsmPrinter.cpp
index 4ab2ff12d319..04e21867d571 100644
--- a/llvm/lib/Target/ARM/ARMAsmPrinter.cpp
+++ b/llvm/lib/Target/ARM/ARMAsmPrinter.cpp
@@ -1897,7 +1897,7 @@ void ARMAsmPrinter::emitInstruction(const MachineInstr *MI) {
// LSJLJEH:
Register SrcReg = MI->getOperand(0).getReg();
Register ValReg = MI->getOperand(1).getReg();
- MCSymbol *Label = OutContext.createTempSymbol("SJLJEH", true, true);
+ MCSymbol *Label = OutContext.createTempSymbol("SJLJEH");
OutStreamer->AddComment("eh_setjmp begin");
EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::tMOVr)
.addReg(ValReg)
diff --git a/llvm/lib/Target/PowerPC/PPCPreEmitPeephole.cpp b/llvm/lib/Target/PowerPC/PPCPreEmitPeephole.cpp
index a39489d353a2..a8853609a7c8 100644
--- a/llvm/lib/Target/PowerPC/PPCPreEmitPeephole.cpp
+++ b/llvm/lib/Target/PowerPC/PPCPreEmitPeephole.cpp
@@ -338,8 +338,7 @@ static bool hasPCRelativeForm(MachineInstr &Use) {
// Create the symbol.
MCContext &Context = MF->getContext();
- MCSymbol *Symbol =
- Context.createTempSymbol(Twine("pcrel"), true, false);
+ MCSymbol *Symbol = Context.createNamedTempSymbol("pcrel");
MachineOperand PCRelLabel =
MachineOperand::CreateMCSymbol(Symbol, PPCII::MO_PCREL_OPT_FLAG);
Pair->DefInst->addOperand(*MF, PCRelLabel);
diff --git a/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp b/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
index 3225559f6c4d..557c528cfd03 100644
--- a/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
+++ b/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
@@ -2124,8 +2124,7 @@ void RISCVAsmParser::emitAuipcInstPair(MCOperand DestReg, MCOperand TmpReg,
// OP DestReg, TmpReg, %pcrel_lo(TmpLabel)
MCContext &Ctx = getContext();
- MCSymbol *TmpLabel = Ctx.createTempSymbol(
- "pcrel_hi", /* AlwaysAddSuffix */ true, /* CanBeUnnamed */ false);
+ MCSymbol *TmpLabel = Ctx.createNamedTempSymbol("pcrel_hi");
Out.emitLabel(TmpLabel);
const RISCVMCExpr *SymbolHi = RISCVMCExpr::create(Symbol, VKHi, Ctx);
More information about the llvm-branch-commits
mailing list