[llvm] 31bf16a - [MC] Add MCTargetStreamer::getContext to simplify code
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Sun Mar 2 13:14:15 PST 2025
Author: Fangrui Song
Date: 2025-03-02T13:14:10-08:00
New Revision: 31bf16a7a2e1f5e783af9055fa2a1d815c090da2
URL: https://github.com/llvm/llvm-project/commit/31bf16a7a2e1f5e783af9055fa2a1d815c090da2
DIFF: https://github.com/llvm/llvm-project/commit/31bf16a7a2e1f5e783af9055fa2a1d815c090da2.diff
LOG: [MC] Add MCTargetStreamer::getContext to simplify code
Added:
Modified:
llvm/include/llvm/MC/MCStreamer.h
llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp
llvm/lib/Target/ARM/MCTargetDesc/ARMTargetStreamer.cpp
llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp
llvm/lib/Target/X86/MCTargetDesc/X86WinCOFFTargetStreamer.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/MC/MCStreamer.h b/llvm/include/llvm/MC/MCStreamer.h
index 4fb2158f26e1e..e0178b2392e05 100644
--- a/llvm/include/llvm/MC/MCStreamer.h
+++ b/llvm/include/llvm/MC/MCStreamer.h
@@ -100,6 +100,7 @@ class MCTargetStreamer {
virtual ~MCTargetStreamer();
MCStreamer &getStreamer() { return Streamer; }
+ MCContext &getContext();
// Allow a target to add behavior to the EmitLabel of MCStreamer.
virtual void emitLabel(MCSymbol *Symbol);
@@ -1157,6 +1158,10 @@ class MCStreamer {
unsigned PointerSize) {}
};
+inline MCContext &MCTargetStreamer::getContext() {
+ return Streamer.getContext();
+}
+
/// Create a dummy machine code streamer, which does nothing. This is useful for
/// timing the assembler front end.
MCStreamer *createNullStreamer(MCContext &Ctx);
diff --git a/llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp b/llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp
index ac30a0b7c2a01..4208aa2004627 100644
--- a/llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp
+++ b/llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp
@@ -1138,7 +1138,7 @@ void ARMTargetELFStreamer::finish() {
// section from making the whole .text section non-execute-only, we
// mark it execute-only if it is empty and there is at least one
// execute-only section in the object.
- MCContext &Ctx = getStreamer().getContext();
+ MCContext &Ctx = getContext();
auto &Asm = getStreamer().getAssembler();
if (any_of(Asm, [](const MCSection &Sec) {
return cast<MCSectionELF>(Sec).getFlags() & ELF::SHF_ARM_PURECODE;
diff --git a/llvm/lib/Target/ARM/MCTargetDesc/ARMTargetStreamer.cpp b/llvm/lib/Target/ARM/MCTargetDesc/ARMTargetStreamer.cpp
index 1dc79438d2fc5..b0fa03a35ec04 100644
--- a/llvm/lib/Target/ARM/MCTargetDesc/ARMTargetStreamer.cpp
+++ b/llvm/lib/Target/ARM/MCTargetDesc/ARMTargetStreamer.cpp
@@ -52,7 +52,7 @@ void ARMTargetStreamer::reset() {}
void ARMTargetStreamer::emitInst(uint32_t Inst, char Suffix) {
unsigned Size;
char Buffer[4];
- const bool LittleEndian = getStreamer().getContext().getAsmInfo()->isLittleEndian();
+ const bool LittleEndian = getContext().getAsmInfo()->isLittleEndian();
switch (Suffix) {
case '\0':
diff --git a/llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp b/llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp
index d9843ee6fc512..63920399f5e5c 100644
--- a/llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp
+++ b/llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp
@@ -4290,7 +4290,7 @@ bool MipsAsmParser::expandDivRem(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
}
// Temporary label for first branch traget
- MCContext &Context = TOut.getStreamer().getContext();
+ MCContext &Context = TOut.getContext();
MCSymbol *BrTarget;
MCOperand LabelOp;
@@ -5222,7 +5222,7 @@ bool MipsAsmParser::expandMulO(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
if (useTraps()) {
TOut.emitRRI(Mips::TNE, DstReg, ATReg, 6, IDLoc, STI);
} else {
- MCContext & Context = TOut.getStreamer().getContext();
+ MCContext &Context = TOut.getContext();
MCSymbol * BrTarget = Context.createTempSymbol();
MCOperand LabelOp =
MCOperand::createExpr(MCSymbolRefExpr::create(BrTarget, Context));
@@ -5259,7 +5259,7 @@ bool MipsAsmParser::expandMulOU(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
if (useTraps()) {
TOut.emitRRI(Mips::TNE, ATReg, Mips::ZERO, 6, IDLoc, STI);
} else {
- MCContext & Context = TOut.getStreamer().getContext();
+ MCContext &Context = TOut.getContext();
MCSymbol * BrTarget = Context.createTempSymbol();
MCOperand LabelOp =
MCOperand::createExpr(MCSymbolRefExpr::create(BrTarget, Context));
diff --git a/llvm/lib/Target/X86/MCTargetDesc/X86WinCOFFTargetStreamer.cpp b/llvm/lib/Target/X86/MCTargetDesc/X86WinCOFFTargetStreamer.cpp
index 678a80932f16c..95628277a2c62 100644
--- a/llvm/lib/Target/X86/MCTargetDesc/X86WinCOFFTargetStreamer.cpp
+++ b/llvm/lib/Target/X86/MCTargetDesc/X86WinCOFFTargetStreamer.cpp
@@ -80,8 +80,6 @@ class X86WinCOFFTargetStreamer : public X86TargetStreamer {
MCSymbol *emitFPOLabel();
- MCContext &getContext() { return getStreamer().getContext(); }
-
public:
X86WinCOFFTargetStreamer(MCStreamer &S) : X86TargetStreamer(S) {}
@@ -100,7 +98,7 @@ class X86WinCOFFTargetStreamer : public X86TargetStreamer {
bool X86WinCOFFAsmTargetStreamer::emitFPOProc(const MCSymbol *ProcSym,
unsigned ParamsSize, SMLoc L) {
OS << "\t.cv_fpo_proc\t";
- ProcSym->print(OS, getStreamer().getContext().getAsmInfo());
+ ProcSym->print(OS, getContext().getAsmInfo());
OS << ' ' << ParamsSize << '\n';
return false;
}
More information about the llvm-commits
mailing list