Author: Fangrui Song Date: 2026-04-11T04:50:05Z New Revision: 94a7b6760757826b3dd5583c4fc380a80649d2da
URL: https://github.com/llvm/llvm-project/commit/94a7b6760757826b3dd5583c4fc380a80649d2da DIFF: https://github.com/llvm/llvm-project/commit/94a7b6760757826b3dd5583c4fc380a80649d2da.diff LOG: [MC] Remove MCTargetOptions parameter from MCContext constructor (#191596) Now that MCAsmInfo stores the MCTargetOptions pointer (set by TargetRegistry::createMCAsmInfo #180464), MCContext can retrieve it via MCAsmInfo. Remove the redundant MCTargetOptions parameter from the MCContext constructor and update all callers. Added: Modified: clang/tools/driver/cc1as_main.cpp llvm/include/llvm/MC/MCContext.h llvm/lib/CodeGen/MachineModuleInfo.cpp llvm/lib/DWARFLinker/Classic/DWARFStreamer.cpp llvm/lib/DWARFLinker/Parallel/DWARFEmitterImpl.cpp llvm/lib/DWARFLinker/Parallel/DebugLineSectionEmitter.h llvm/lib/MC/MCContext.cpp llvm/tools/llvm-dwp/llvm-dwp.cpp llvm/tools/llvm-mc/llvm-mc.cpp llvm/unittests/CodeGen/MachineInstrTest.cpp llvm/unittests/MC/SystemZ/SystemZAsmLexerTest.cpp mlir/lib/Target/LLVM/ROCDL/Target.cpp Removed: ################################################################################ diff --git a/clang/tools/driver/cc1as_main.cpp b/clang/tools/driver/cc1as_main.cpp index d6911e46b57e1..8d343fcd634df 100644 --- a/clang/tools/driver/cc1as_main.cpp +++ b/clang/tools/driver/cc1as_main.cpp @@ -506,8 +506,7 @@ static bool ExecuteAssemblerImpl(AssemblerInvocation &Opts, << Opts.CPU << FS.empty() << FS; } - MCContext Ctx(Triple(Opts.Triple), MAI.get(), MRI.get(), STI.get(), &SrcMgr, - &MCOptions); + MCContext Ctx(Triple(Opts.Triple), MAI.get(), MRI.get(), STI.get(), &SrcMgr); bool PIC = false; if (Opts.RelocationModel == "static") { diff --git a/llvm/include/llvm/MC/MCContext.h b/llvm/include/llvm/MC/MCContext.h index 85ce14570866e..7bd74399fb75e 100644 --- a/llvm/include/llvm/MC/MCContext.h +++ b/llvm/include/llvm/MC/MCContext.h @@ -380,7 +380,6 @@ class MCContext { const MCRegisterInfo *MRI, const MCSubtargetInfo *MSTI, const SourceMgr *Mgr = nullptr, - MCTargetOptions const *TargetOpts = nullptr, bool DoAutoReset = true, StringRef Swift5ReflSegmentName = {}); MCContext(const MCContext &) = delete; diff --git a/llvm/lib/CodeGen/MachineModuleInfo.cpp b/llvm/lib/CodeGen/MachineModuleInfo.cpp index b3d0c0ea1b9e2..6b7a8cdfd2951 100644 --- a/llvm/lib/CodeGen/MachineModuleInfo.cpp +++ b/llvm/lib/CodeGen/MachineModuleInfo.cpp @@ -40,7 +40,7 @@ void MachineModuleInfo::finalize() { MachineModuleInfo::MachineModuleInfo(MachineModuleInfo &&MMI) : TM(std::move(MMI.TM)), Context(TM.getTargetTriple(), TM.getMCAsmInfo(), TM.getMCRegisterInfo(), - TM.getMCSubtargetInfo(), nullptr, &TM.Options.MCOptions, false), + TM.getMCSubtargetInfo(), nullptr, false), MachineFunctions(std::move(MMI.MachineFunctions)) { Context.setObjectFileInfo(TM.getObjFileLowering()); ObjFileMMI = MMI.ObjFileMMI; @@ -51,7 +51,7 @@ MachineModuleInfo::MachineModuleInfo(MachineModuleInfo &&MMI) MachineModuleInfo::MachineModuleInfo(const TargetMachine *TM) : TM(*TM), Context(TM->getTargetTriple(), TM->getMCAsmInfo(), TM->getMCRegisterInfo(), TM->getMCSubtargetInfo(), - nullptr, &TM->Options.MCOptions, false) { + nullptr, false) { Context.setObjectFileInfo(TM->getObjFileLowering()); initialize(); } @@ -60,7 +60,7 @@ MachineModuleInfo::MachineModuleInfo(const TargetMachine *TM, MCContext *ExtContext) : TM(*TM), Context(TM->getTargetTriple(), TM->getMCAsmInfo(), TM->getMCRegisterInfo(), TM->getMCSubtargetInfo(), - nullptr, &TM->Options.MCOptions, false), + nullptr, false), ExternalContext(ExtContext) { Context.setObjectFileInfo(TM->getObjFileLowering()); initialize(); diff --git a/llvm/lib/DWARFLinker/Classic/DWARFStreamer.cpp b/llvm/lib/DWARFLinker/Classic/DWARFStreamer.cpp index 268f1a5b6f81b..5e02698670b9f 100644 --- a/llvm/lib/DWARFLinker/Classic/DWARFStreamer.cpp +++ b/llvm/lib/DWARFLinker/Classic/DWARFStreamer.cpp @@ -76,7 +76,7 @@ Error DwarfStreamer::init(Triple TheTriple, TripleName.c_str()); MC.reset(new MCContext(TheTriple, MAI.get(), MRI.get(), MSTI.get(), nullptr, - nullptr, true, Swift5ReflectionSegmentName)); + true, Swift5ReflectionSegmentName)); MOFI.reset(TheTarget->createMCObjectFileInfo(*MC, /*PIC=*/false, false)); MC->setObjectFileInfo(MOFI.get()); diff --git a/llvm/lib/DWARFLinker/Parallel/DWARFEmitterImpl.cpp b/llvm/lib/DWARFLinker/Parallel/DWARFEmitterImpl.cpp index 0049026481110..22580759f3b69 100644 --- a/llvm/lib/DWARFLinker/Parallel/DWARFEmitterImpl.cpp +++ b/llvm/lib/DWARFLinker/Parallel/DWARFEmitterImpl.cpp @@ -56,7 +56,7 @@ Error DwarfEmitterImpl::init(Triple TheTriple, TripleName.c_str()); MC.reset(new MCContext(TheTriple, MAI.get(), MRI.get(), MSTI.get(), nullptr, - nullptr, true, Swift5ReflectionSegmentName)); + true, Swift5ReflectionSegmentName)); MOFI.reset(TheTarget->createMCObjectFileInfo(*MC, /*PIC=*/false, false)); MC->setObjectFileInfo(MOFI.get()); diff --git a/llvm/lib/DWARFLinker/Parallel/DebugLineSectionEmitter.h b/llvm/lib/DWARFLinker/Parallel/DebugLineSectionEmitter.h index aa9d1fe64bc73..7231916a38dbe 100644 --- a/llvm/lib/DWARFLinker/Parallel/DebugLineSectionEmitter.h +++ b/llvm/lib/DWARFLinker/Parallel/DebugLineSectionEmitter.h @@ -92,7 +92,7 @@ class DebugLineSectionEmitter { TripleName.c_str()); MC.reset(new MCContext(TheTriple, MAI.get(), MRI.get(), MSTI.get(), nullptr, - nullptr, true, "__DWARF")); + true, "__DWARF")); return Error::success(); } diff --git a/llvm/lib/MC/MCContext.cpp b/llvm/lib/MC/MCContext.cpp index 93226518eb096..b9fbffbd38389 100644 --- a/llvm/lib/MC/MCContext.cpp +++ b/llvm/lib/MC/MCContext.cpp @@ -64,8 +64,8 @@ static void defaultDiagHandler(const SMDiagnostic &SMD, bool, const SourceMgr &, MCContext::MCContext(const Triple &TheTriple, const MCAsmInfo *mai, const MCRegisterInfo *mri, const MCSubtargetInfo *msti, - const SourceMgr *mgr, MCTargetOptions const *TargetOpts, - bool DoAutoReset, StringRef Swift5ReflSegmentName) + const SourceMgr *mgr, bool DoAutoReset, + StringRef Swift5ReflSegmentName) : Swift5ReflectionSegmentName(Swift5ReflSegmentName), TT(TheTriple), SrcMgr(mgr), InlineSrcMgr(nullptr), DiagHandler(defaultDiagHandler), MAI(mai), MRI(mri), MSTI(msti), Symbols(Allocator), @@ -74,8 +74,6 @@ MCContext::MCContext(const Triple &TheTriple, const MCAsmInfo *mai, AutoReset(DoAutoReset) { assert(MAI && MAI->getTargetOptions() && "MCAsmInfo and MCTargetOptions must be available"); - assert((!TargetOpts || TargetOpts == MAI->getTargetOptions()) && - "MCTargetOptions, if specified, must match MCAsmInfo"); SaveTempLabels = getTargetOptions()->MCSaveTempLabels; if (SaveTempLabels) setUseNamesOnTempLabels(true); diff --git a/llvm/tools/llvm-dwp/llvm-dwp.cpp b/llvm/tools/llvm-dwp/llvm-dwp.cpp index dd45db1f05c50..c0131111ed22d 100644 --- a/llvm/tools/llvm-dwp/llvm-dwp.cpp +++ b/llvm/tools/llvm-dwp/llvm-dwp.cpp @@ -292,9 +292,7 @@ int llvm_dwp_main(int argc, char **argv, const llvm::ToolContext &) { std::unique_ptr<MCObjectFileInfo> MOFI( TheTarget->createMCObjectFileInfo(MC, /*PIC=*/false)); MC.setObjectFileInfo(MOFI.get()); - - MCTargetOptions Options; - auto MAB = TheTarget->createMCAsmBackend(*MSTI, *MRI, Options); + auto MAB = TheTarget->createMCAsmBackend(*MSTI, *MRI, MCOptions); if (!MAB) return error("no asm backend for target " + TripleName, Context); diff --git a/llvm/tools/llvm-mc/llvm-mc.cpp b/llvm/tools/llvm-mc/llvm-mc.cpp index 3c404da586515..5080afb2b108a 100644 --- a/llvm/tools/llvm-mc/llvm-mc.cpp +++ b/llvm/tools/llvm-mc/llvm-mc.cpp @@ -491,8 +491,7 @@ int main(int argc, char **argv) { // FIXME: This is not pretty. MCContext has a ptr to MCObjectFileInfo and // MCObjectFileInfo needs a MCContext reference in order to initialize itself. - MCContext Ctx(TheTriple, MAI.get(), MRI.get(), STI.get(), &SrcMgr, - &MCOptions); + MCContext Ctx(TheTriple, MAI.get(), MRI.get(), STI.get(), &SrcMgr); std::unique_ptr<MCObjectFileInfo> MOFI( TheTarget->createMCObjectFileInfo(Ctx, PIC, LargeCodeModel)); Ctx.setObjectFileInfo(MOFI.get()); diff --git a/llvm/unittests/CodeGen/MachineInstrTest.cpp b/llvm/unittests/CodeGen/MachineInstrTest.cpp index 529adba98669e..d3a33d4ecdc82 100644 --- a/llvm/unittests/CodeGen/MachineInstrTest.cpp +++ b/llvm/unittests/CodeGen/MachineInstrTest.cpp @@ -44,7 +44,7 @@ std::unique_ptr<MCContext> createMCContext(MCAsmInfo *AsmInfo) { Triple TheTriple(/*ArchStr=*/"", /*VendorStr=*/"", /*OSStr=*/"", /*EnvironmentStr=*/"elf"); return std::make_unique<MCContext>(TheTriple, AsmInfo, nullptr, nullptr, - nullptr, nullptr, false); + nullptr, false); } // This test makes sure that MachineInstr::isIdenticalTo handles Defs correctly diff --git a/llvm/unittests/MC/SystemZ/SystemZAsmLexerTest.cpp b/llvm/unittests/MC/SystemZ/SystemZAsmLexerTest.cpp index ec02c1d077cc6..74da8fe77829f 100644 --- a/llvm/unittests/MC/SystemZ/SystemZAsmLexerTest.cpp +++ b/llvm/unittests/MC/SystemZ/SystemZAsmLexerTest.cpp @@ -81,8 +81,7 @@ class SystemZAsmLexerTest : public ::testing::Test { SrcMgr.AddNewSourceBuffer(std::move(Buffer), SMLoc()); EXPECT_EQ(Buffer, nullptr); - Ctx.reset(new MCContext(Triple, MAI.get(), MRI.get(), STI.get(), &SrcMgr, - &MCOptions)); + Ctx.reset(new MCContext(Triple, MAI.get(), MRI.get(), STI.get(), &SrcMgr)); MOFI.reset(TheTarget->createMCObjectFileInfo(*Ctx, /*PIC=*/false, /*LargeCodeModel=*/false)); Ctx->setObjectFileInfo(MOFI.get()); diff --git a/mlir/lib/Target/LLVM/ROCDL/Target.cpp b/mlir/lib/Target/LLVM/ROCDL/Target.cpp index b6656a95d6012..e3ad7cf8b5b04 100644 --- a/mlir/lib/Target/LLVM/ROCDL/Target.cpp +++ b/mlir/lib/Target/LLVM/ROCDL/Target.cpp @@ -303,8 +303,7 @@ mlir::ROCDL::assembleIsa(StringRef isa, StringRef targetTriple, StringRef chip, std::unique_ptr<llvm::MCSubtargetInfo> sti( target->createMCSubtargetInfo(triple, chip, features)); - llvm::MCContext ctx(triple, mai.get(), mri.get(), sti.get(), &srcMgr, - &mcOptions); + llvm::MCContext ctx(triple, mai.get(), mri.get(), sti.get(), &srcMgr); std::unique_ptr<llvm::MCObjectFileInfo> mofi(target->createMCObjectFileInfo( ctx, /*PIC=*/false, /*LargeCodeModel=*/false)); ctx.setObjectFileInfo(mofi.get()); _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
