Skip to content

CodeGen: Avoid using MachineFunction::getMMI in MachineModuleSlotTracker #100310

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion llvm/include/llvm/CodeGen/MIRPrinter.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ void printMIR(raw_ostream &OS, const Module &M);

/// Print a machine function using the MIR serialization format to the given
/// output stream.
void printMIR(raw_ostream &OS, const MachineFunction &MF);
void printMIR(raw_ostream &OS, const MachineModuleInfo &MMI,
const MachineFunction &MF);

/// Determine a possible list of successors of a basic block based on the
/// basic block machine operand being used inside the block. This should give
Expand Down
3 changes: 2 additions & 1 deletion llvm/include/llvm/CodeGen/MachineModuleSlotTracker.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ class MachineModuleSlotTracker : public ModuleSlotTracker {
bool ShouldInitializeAllMetadata);

public:
MachineModuleSlotTracker(const MachineFunction *MF,
MachineModuleSlotTracker(const MachineModuleInfo &MMI,
const MachineFunction *MF,
bool ShouldInitializeAllMetadata = true);
~MachineModuleSlotTracker();

Expand Down
11 changes: 7 additions & 4 deletions llvm/lib/CodeGen/MIRPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,15 @@ namespace llvm {
/// format.
class MIRPrinter {
raw_ostream &OS;
const MachineModuleInfo &MMI;
DenseMap<const uint32_t *, unsigned> RegisterMaskIds;
/// Maps from stack object indices to operand indices which will be used when
/// printing frame index machine operands.
DenseMap<int, FrameIndexOperand> StackObjectOperandMapping;

public:
MIRPrinter(raw_ostream &OS) : OS(OS) {}
MIRPrinter(raw_ostream &OS, const MachineModuleInfo &MMI)
: OS(OS), MMI(MMI) {}

void print(const MachineFunction &MF);

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -1005,12 +1007,13 @@ void llvm::printMIR(raw_ostream &OS, const Module &M) {
Out << const_cast<Module &>(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<Function &>(MF.getFunction()), WriteNewDbgInfoFormat);

MIRPrinter Printer(OS);
MIRPrinter Printer(OS, MMI);
Printer.print(MF);
}
17 changes: 14 additions & 3 deletions llvm/lib/CodeGen/MIRPrintingPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<ModuleAnalysisManagerMachineFunctionProxy>(MF);
Module *M = MF.getFunction().getParent();
const MachineModuleInfo &MMI =
MAMP.getCachedResult<MachineModuleAnalysis>(*M)->getMMI();

printMIR(OS, MMI, MF);
return PreservedAnalyses::all();
}

Expand 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<MachineModuleInfoWrapperPass>().getMMI();

printMIR(StrOS, MMI, MF);
MachineFunctions.append(Str);
return false;
}
Expand Down
5 changes: 3 additions & 2 deletions llvm/lib/CodeGen/MachineModuleSlotTracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion llvm/tools/llvm-reduce/ReducerWorkItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ void ReducerWorkItem::print(raw_ostream &ROS, void *p) const {
printMIR(ROS, *M);
for (Function &F : *M) {
if (auto *MF = MMI->getMachineFunction(F))
printMIR(ROS, *MF);
printMIR(ROS, *MMI, *MF);
}
} else {
M->print(ROS, /*AssemblyAnnotationWriter=*/nullptr,
Expand Down
12 changes: 6 additions & 6 deletions llvm/unittests/MIR/MachineMetadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ body: |
auto *NewMMO = MF->getMachineMemOperand(OldMMO, AAInfo);
MI.setMemRefs(*MF, NewMMO);

MachineModuleSlotTracker MST(MF);
MachineModuleSlotTracker MST(MMI, MF);
// Print that MI with new machine metadata, which slot numbers should be
// assigned.
EXPECT_EQ("%1:gpr32 = LDRWui %0, 0 :: (load (s32) from %ir.p, "
Expand All @@ -277,7 +277,7 @@ body: |
EXPECT_EQ(Collected, Generated);

// FileCheck the output from MIR printer.
std::string Output = print([&](raw_ostream &OS) { printMIR(OS, *MF); });
std::string Output = print([&](raw_ostream &OS) { printMIR(OS, MMI, *MF); });
std::string CheckString = R"(
CHECK: machineMetadataNodes:
CHECK-DAG: ![[MMDOMAIN:[0-9]+]] = distinct !{!{{[0-9]+}}, !"domain"}
Expand Down Expand Up @@ -403,7 +403,7 @@ body: |
auto *NewMMO = MF->getMachineMemOperand(OldMMO, AAInfo);
MI.setMemRefs(*MF, NewMMO);

MachineModuleSlotTracker MST(MF);
MachineModuleSlotTracker MST(MMI, MF);
// Print that MI with new machine metadata, which slot numbers should be
// assigned.
EXPECT_EQ("%1:gr32 = MOV32rm %0, 1, $noreg, 0, $noreg :: (load (s32) from %ir.p, "
Expand All @@ -427,7 +427,7 @@ body: |
EXPECT_EQ(Collected, Generated);

// FileCheck the output from MIR printer.
std::string Output = print([&](raw_ostream &OS) { printMIR(OS, *MF); });
std::string Output = print([&](raw_ostream &OS) { printMIR(OS, MMI, *MF); });
std::string CheckString = R"(
CHECK: machineMetadataNodes:
CHECK-DAG: ![[MMDOMAIN:[0-9]+]] = distinct !{!{{[0-9]+}}, !"domain"}
Expand Down Expand Up @@ -501,7 +501,7 @@ body: |
auto *NewMMO = MF->getMachineMemOperand(OldMMO, AAInfo);
MI.setMemRefs(*MF, NewMMO);

MachineModuleSlotTracker MST(MF);
MachineModuleSlotTracker MST(MMI, MF);
// Print that MI with new machine metadata, which slot numbers should be
// assigned.
EXPECT_EQ(
Expand All @@ -526,7 +526,7 @@ body: |
EXPECT_EQ(Collected, Generated);

// FileCheck the output from MIR printer.
std::string Output = print([&](raw_ostream &OS) { printMIR(OS, *MF); });
std::string Output = print([&](raw_ostream &OS) { printMIR(OS, MMI, *MF); });
std::string CheckString = R"(
CHECK: machineMetadataNodes:
CHECK-DAG: ![[MMDOMAIN:[0-9]+]] = distinct !{!{{[0-9]+}}, !"domain"}
Expand Down
Loading