From 9a258664024d12a06ba8eb9344e270a9bb5f5d87 Mon Sep 17 00:00:00 2001 From: Matt Arsenault Date: Wed, 24 Jul 2024 12:27:00 +0400 Subject: CodeGen: Avoid using MachineFunction::getMMI in MachineModuleSlotTracker (#100310) --- llvm/lib/CodeGen/MIRPrinter.cpp | 11 +++++++---- llvm/lib/CodeGen/MIRPrintingPass.cpp | 17 ++++++++++++++--- llvm/lib/CodeGen/MachineModuleSlotTracker.cpp | 5 +++-- 3 files changed, 24 insertions(+), 9 deletions(-) (limited to 'llvm/lib/CodeGen') diff --git a/llvm/lib/CodeGen/MIRPrinter.cpp b/llvm/lib/CodeGen/MIRPrinter.cpp index 48c3e0d..63fb887 100644 --- a/llvm/lib/CodeGen/MIRPrinter.cpp +++ b/llvm/lib/CodeGen/MIRPrinter.cpp @@ -101,13 +101,15 @@ namespace llvm { /// format. class MIRPrinter { raw_ostream &OS; + const MachineModuleInfo &MMI; DenseMap RegisterMaskIds; /// Maps from stack object indices to operand indices which will be used when /// printing frame index machine operands. DenseMap StackObjectOperandMapping; public: - MIRPrinter(raw_ostream &OS) : OS(OS) {} + MIRPrinter(raw_ostream &OS, const MachineModuleInfo &MMI) + : OS(OS), MMI(MMI) {} void print(const MachineFunction &MF); @@ -222,7 +224,7 @@ void MIRPrinter::print(const MachineFunction &MF) { MachineFunctionProperties::Property::TracksDebugUserValues); convert(YamlMF, MF.getRegInfo(), MF.getSubtarget().getRegisterInfo()); - MachineModuleSlotTracker MST(&MF); + MachineModuleSlotTracker MST(MMI, &MF); MST.incorporateFunction(MF.getFunction()); convert(MST, YamlMF.FrameInfo, MF.getFrameInfo()); convertStackObjects(YamlMF, MF, MST); @@ -1005,12 +1007,13 @@ void llvm::printMIR(raw_ostream &OS, const Module &M) { Out << const_cast(M); } -void llvm::printMIR(raw_ostream &OS, const MachineFunction &MF) { +void llvm::printMIR(raw_ostream &OS, const MachineModuleInfo &MMI, + const MachineFunction &MF) { // RemoveDIs: as there's no textual form for DbgRecords yet, print debug-info // in dbg.value format. ScopedDbgInfoFormatSetter FormatSetter( const_cast(MF.getFunction()), WriteNewDbgInfoFormat); - MIRPrinter Printer(OS); + MIRPrinter Printer(OS, MMI); Printer.print(MF); } diff --git a/llvm/lib/CodeGen/MIRPrintingPass.cpp b/llvm/lib/CodeGen/MIRPrintingPass.cpp index f70c073..fc79410 100644 --- a/llvm/lib/CodeGen/MIRPrintingPass.cpp +++ b/llvm/lib/CodeGen/MIRPrintingPass.cpp @@ -13,7 +13,9 @@ #include "llvm/CodeGen/MIRPrinter.h" #include "llvm/CodeGen/MachineFunctionPass.h" +#include "llvm/CodeGen/MachineModuleInfo.h" #include "llvm/CodeGen/Passes.h" +#include "llvm/IR/Function.h" #include "llvm/InitializePasses.h" using namespace llvm; @@ -24,8 +26,13 @@ PreservedAnalyses PrintMIRPreparePass::run(Module &M, ModuleAnalysisManager &) { } PreservedAnalyses PrintMIRPass::run(MachineFunction &MF, - MachineFunctionAnalysisManager &) { - printMIR(OS, MF); + MachineFunctionAnalysisManager &MFAM) { + auto &MAMP = MFAM.getResult(MF); + Module *M = MF.getFunction().getParent(); + const MachineModuleInfo &MMI = + MAMP.getCachedResult(*M)->getMMI(); + + printMIR(OS, MMI, MF); return PreservedAnalyses::all(); } @@ -51,7 +58,11 @@ struct MIRPrintingPass : public MachineFunctionPass { bool runOnMachineFunction(MachineFunction &MF) override { std::string Str; raw_string_ostream StrOS(Str); - printMIR(StrOS, MF); + + const MachineModuleInfo &MMI = + getAnalysis().getMMI(); + + printMIR(StrOS, MMI, MF); MachineFunctions.append(Str); return false; } diff --git a/llvm/lib/CodeGen/MachineModuleSlotTracker.cpp b/llvm/lib/CodeGen/MachineModuleSlotTracker.cpp index 965539d..8f10435 100644 --- a/llvm/lib/CodeGen/MachineModuleSlotTracker.cpp +++ b/llvm/lib/CodeGen/MachineModuleSlotTracker.cpp @@ -64,10 +64,11 @@ void MachineModuleSlotTracker::collectMachineMDNodes( } MachineModuleSlotTracker::MachineModuleSlotTracker( - const MachineFunction *MF, bool ShouldInitializeAllMetadata) + const MachineModuleInfo &MMI, const MachineFunction *MF, + bool ShouldInitializeAllMetadata) : ModuleSlotTracker(MF->getFunction().getParent(), ShouldInitializeAllMetadata), - TheFunction(MF->getFunction()), TheMMI(MF->getMMI()) { + TheFunction(MF->getFunction()), TheMMI(MMI) { setProcessHook([this](AbstractSlotTrackerStorage *AST, const Module *M, bool ShouldInitializeAllMetadata) { this->processMachineModule(AST, M, ShouldInitializeAllMetadata); -- cgit v1.1