Skip to content

Commit 9a25866

Browse files
authored
CodeGen: Avoid using MachineFunction::getMMI in MachineModuleSlotTracker (llvm#100310)
1 parent 1ead51a commit 9a25866

File tree

7 files changed

+35
-18
lines changed

7 files changed

+35
-18
lines changed

llvm/include/llvm/CodeGen/MIRPrinter.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ void printMIR(raw_ostream &OS, const Module &M);
4646

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

5152
/// Determine a possible list of successors of a basic block based on the
5253
/// basic block machine operand being used inside the block. This should give

llvm/include/llvm/CodeGen/MachineModuleSlotTracker.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ class MachineModuleSlotTracker : public ModuleSlotTracker {
3333
bool ShouldInitializeAllMetadata);
3434

3535
public:
36-
MachineModuleSlotTracker(const MachineFunction *MF,
36+
MachineModuleSlotTracker(const MachineModuleInfo &MMI,
37+
const MachineFunction *MF,
3738
bool ShouldInitializeAllMetadata = true);
3839
~MachineModuleSlotTracker();
3940

llvm/lib/CodeGen/MIRPrinter.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,15 @@ namespace llvm {
101101
/// format.
102102
class MIRPrinter {
103103
raw_ostream &OS;
104+
const MachineModuleInfo &MMI;
104105
DenseMap<const uint32_t *, unsigned> RegisterMaskIds;
105106
/// Maps from stack object indices to operand indices which will be used when
106107
/// printing frame index machine operands.
107108
DenseMap<int, FrameIndexOperand> StackObjectOperandMapping;
108109

109110
public:
110-
MIRPrinter(raw_ostream &OS) : OS(OS) {}
111+
MIRPrinter(raw_ostream &OS, const MachineModuleInfo &MMI)
112+
: OS(OS), MMI(MMI) {}
111113

112114
void print(const MachineFunction &MF);
113115

@@ -222,7 +224,7 @@ void MIRPrinter::print(const MachineFunction &MF) {
222224
MachineFunctionProperties::Property::TracksDebugUserValues);
223225

224226
convert(YamlMF, MF.getRegInfo(), MF.getSubtarget().getRegisterInfo());
225-
MachineModuleSlotTracker MST(&MF);
227+
MachineModuleSlotTracker MST(MMI, &MF);
226228
MST.incorporateFunction(MF.getFunction());
227229
convert(MST, YamlMF.FrameInfo, MF.getFrameInfo());
228230
convertStackObjects(YamlMF, MF, MST);
@@ -1005,12 +1007,13 @@ void llvm::printMIR(raw_ostream &OS, const Module &M) {
10051007
Out << const_cast<Module &>(M);
10061008
}
10071009

1008-
void llvm::printMIR(raw_ostream &OS, const MachineFunction &MF) {
1010+
void llvm::printMIR(raw_ostream &OS, const MachineModuleInfo &MMI,
1011+
const MachineFunction &MF) {
10091012
// RemoveDIs: as there's no textual form for DbgRecords yet, print debug-info
10101013
// in dbg.value format.
10111014
ScopedDbgInfoFormatSetter FormatSetter(
10121015
const_cast<Function &>(MF.getFunction()), WriteNewDbgInfoFormat);
10131016

1014-
MIRPrinter Printer(OS);
1017+
MIRPrinter Printer(OS, MMI);
10151018
Printer.print(MF);
10161019
}

llvm/lib/CodeGen/MIRPrintingPass.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313

1414
#include "llvm/CodeGen/MIRPrinter.h"
1515
#include "llvm/CodeGen/MachineFunctionPass.h"
16+
#include "llvm/CodeGen/MachineModuleInfo.h"
1617
#include "llvm/CodeGen/Passes.h"
18+
#include "llvm/IR/Function.h"
1719
#include "llvm/InitializePasses.h"
1820

1921
using namespace llvm;
@@ -24,8 +26,13 @@ PreservedAnalyses PrintMIRPreparePass::run(Module &M, ModuleAnalysisManager &) {
2426
}
2527

2628
PreservedAnalyses PrintMIRPass::run(MachineFunction &MF,
27-
MachineFunctionAnalysisManager &) {
28-
printMIR(OS, MF);
29+
MachineFunctionAnalysisManager &MFAM) {
30+
auto &MAMP = MFAM.getResult<ModuleAnalysisManagerMachineFunctionProxy>(MF);
31+
Module *M = MF.getFunction().getParent();
32+
const MachineModuleInfo &MMI =
33+
MAMP.getCachedResult<MachineModuleAnalysis>(*M)->getMMI();
34+
35+
printMIR(OS, MMI, MF);
2936
return PreservedAnalyses::all();
3037
}
3138

@@ -51,7 +58,11 @@ struct MIRPrintingPass : public MachineFunctionPass {
5158
bool runOnMachineFunction(MachineFunction &MF) override {
5259
std::string Str;
5360
raw_string_ostream StrOS(Str);
54-
printMIR(StrOS, MF);
61+
62+
const MachineModuleInfo &MMI =
63+
getAnalysis<MachineModuleInfoWrapperPass>().getMMI();
64+
65+
printMIR(StrOS, MMI, MF);
5566
MachineFunctions.append(Str);
5667
return false;
5768
}

llvm/lib/CodeGen/MachineModuleSlotTracker.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,11 @@ void MachineModuleSlotTracker::collectMachineMDNodes(
6464
}
6565

6666
MachineModuleSlotTracker::MachineModuleSlotTracker(
67-
const MachineFunction *MF, bool ShouldInitializeAllMetadata)
67+
const MachineModuleInfo &MMI, const MachineFunction *MF,
68+
bool ShouldInitializeAllMetadata)
6869
: ModuleSlotTracker(MF->getFunction().getParent(),
6970
ShouldInitializeAllMetadata),
70-
TheFunction(MF->getFunction()), TheMMI(MF->getMMI()) {
71+
TheFunction(MF->getFunction()), TheMMI(MMI) {
7172
setProcessHook([this](AbstractSlotTrackerStorage *AST, const Module *M,
7273
bool ShouldInitializeAllMetadata) {
7374
this->processMachineModule(AST, M, ShouldInitializeAllMetadata);

llvm/tools/llvm-reduce/ReducerWorkItem.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ void ReducerWorkItem::print(raw_ostream &ROS, void *p) const {
432432
printMIR(ROS, *M);
433433
for (Function &F : *M) {
434434
if (auto *MF = MMI->getMachineFunction(F))
435-
printMIR(ROS, *MF);
435+
printMIR(ROS, *MMI, *MF);
436436
}
437437
} else {
438438
M->print(ROS, /*AssemblyAnnotationWriter=*/nullptr,

llvm/unittests/MIR/MachineMetadata.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ body: |
253253
auto *NewMMO = MF->getMachineMemOperand(OldMMO, AAInfo);
254254
MI.setMemRefs(*MF, NewMMO);
255255

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

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

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

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

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

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

0 commit comments

Comments
 (0)