Skip to content

Commit d569128

Browse files
committed
[CodeGen] Port MachineCFGPrinter to new pass manager
1 parent c215318 commit d569128

File tree

6 files changed

+32
-1
lines changed

6 files changed

+32
-1
lines changed

llvm/include/llvm/CodeGen/MachineCFGPrinter.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "llvm/CodeGen/MachineBasicBlock.h"
1313
#include "llvm/CodeGen/MachineFunction.h"
1414
#include "llvm/CodeGen/MachineInstr.h"
15+
#include "llvm/CodeGen/MachinePassManager.h"
1516
#include "llvm/Support/DOTGraphTraits.h"
1617

1718
namespace llvm {
@@ -89,4 +90,15 @@ struct DOTGraphTraits<DOTMachineFuncInfo *> : public DefaultDOTGraphTraits {
8990
"' function";
9091
}
9192
};
93+
94+
class MachineCFGPrinterPass : public PassInfoMixin<MachineCFGPrinterPass> {
95+
raw_ostream &OS;
96+
97+
public:
98+
explicit MachineCFGPrinterPass(raw_ostream &OS) : OS(OS) {}
99+
PreservedAnalyses run(MachineFunction &MF,
100+
MachineFunctionAnalysisManager &MFAM);
101+
static bool isRequired() { return true; }
102+
};
103+
92104
} // namespace llvm

llvm/include/llvm/Passes/MachinePassRegistry.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ MACHINE_FUNCTION_PASS("block-placement-stats", MachineBlockPlacementStatsPass())
141141
MACHINE_FUNCTION_PASS("branch-relaxation", BranchRelaxationPass())
142142
MACHINE_FUNCTION_PASS("dead-mi-elimination", DeadMachineInstructionElimPass())
143143
MACHINE_FUNCTION_PASS("detect-dead-lanes", DetectDeadLanesPass())
144+
MACHINE_FUNCTION_PASS("dot-machine-cfg", MachineCFGPrinterPass(errs()))
144145
MACHINE_FUNCTION_PASS("early-ifcvt", EarlyIfConverterPass())
145146
MACHINE_FUNCTION_PASS("early-machinelicm", EarlyMachineLICMPass())
146147
MACHINE_FUNCTION_PASS("early-tailduplication", EarlyTailDuplicatePass())
@@ -288,7 +289,6 @@ DUMMY_MACHINE_FUNCTION_PASS("break-false-deps", BreakFalseDepsPass)
288289
DUMMY_MACHINE_FUNCTION_PASS("cfguard-longjmp", CFGuardLongjmpPass)
289290
DUMMY_MACHINE_FUNCTION_PASS("cfi-fixup", CFIFixupPass)
290291
DUMMY_MACHINE_FUNCTION_PASS("cfi-instr-inserter", CFIInstrInserterPass)
291-
DUMMY_MACHINE_FUNCTION_PASS("dot-machine-cfg", MachineCFGPrinter)
292292
DUMMY_MACHINE_FUNCTION_PASS("fs-profile-loader", MIRProfileLoaderNewPass)
293293
DUMMY_MACHINE_FUNCTION_PASS("funclet-layout", FuncletLayoutPass)
294294
DUMMY_MACHINE_FUNCTION_PASS("gc-empty-basic-blocks", GCEmptyBasicBlocksPass)

llvm/lib/CodeGen/MachineCFGPrinter.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,18 @@ static void writeMCFGToDotFile(MachineFunction &MF) {
5454
errs() << '\n';
5555
}
5656

57+
PreservedAnalyses
58+
MachineCFGPrinterPass::run(MachineFunction &MF,
59+
MachineFunctionAnalysisManager &MFAM) {
60+
if (!MCFGFuncName.empty() && !MF.getName().contains(MCFGFuncName))
61+
return PreservedAnalyses::all();
62+
OS << "Writing Machine CFG for function ";
63+
OS.write_escaped(MF.getName()) << '\n';
64+
65+
writeMCFGToDotFile(MF);
66+
return PreservedAnalyses::all();
67+
}
68+
5769
namespace {
5870

5971
class MachineCFGPrinter : public MachineFunctionPass {

llvm/lib/Passes/PassBuilder.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@
118118
#include "llvm/CodeGen/MachineBlockFrequencyInfo.h"
119119
#include "llvm/CodeGen/MachineBlockPlacement.h"
120120
#include "llvm/CodeGen/MachineBranchProbabilityInfo.h"
121+
#include "llvm/CodeGen/MachineCFGPrinter.h"
121122
#include "llvm/CodeGen/MachineCSE.h"
122123
#include "llvm/CodeGen/MachineCopyPropagation.h"
123124
#include "llvm/CodeGen/MachineCycleAnalysis.h"

llvm/test/Analysis/DotMachineCFG/AMDGPU/functions.mir

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# RUN: llc -mtriple=amdgcn-- -run-pass=dot-machine-cfg -mcfg-dot-filename-prefix=%t -mcfg-func-name=func2 -o - %s 2>&1 > /dev/null
22
# RUN: FileCheck %s -input-file=%t.func2.dot --check-prefix=MCFG
3+
# RUN: llc -mtriple=amdgcn-- -passes=dot-machine-cfg -mcfg-dot-filename-prefix=%t -mcfg-func-name=func2 -o - %s 2>&1 > /dev/null
4+
# RUN: FileCheck %s -input-file=%t.func2.dot --check-prefix=MCFG
35

46
# MCFG-NOT: digraph "Machine CFG for 'func1' function"
57
name: func1

llvm/test/Analysis/DotMachineCFG/AMDGPU/irreducible.mir

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
# RUN: FileCheck %s -input-file=%t.irreducible.dot --check-prefix=MCFG
33
# RUN: llc -mtriple=amdgcn-- -run-pass=dot-machine-cfg -mcfg-dot-filename-prefix=%t -dot-mcfg-only -o - %s 2>&1 > /dev/null
44
# RUN: FileCheck %s -input-file=%t.irreducible.dot --check-prefix=MCFG-ONLY
5+
# RUN: llc -mtriple=amdgcn-- -passes=dot-machine-cfg -mcfg-dot-filename-prefix=%t -o - %s 2>&1 > /dev/null
6+
# RUN: FileCheck %s -input-file=%t.irreducible.dot --check-prefix=MCFG
7+
# RUN: llc -mtriple=amdgcn-- -passes=dot-machine-cfg -mcfg-dot-filename-prefix=%t -dot-mcfg-only -o - %s 2>&1 > /dev/null
8+
# RUN: FileCheck %s -input-file=%t.irreducible.dot --check-prefix=MCFG-ONLY
59

610
# MCFG: digraph "Machine CFG for 'irreducible' function"
711
# MCFG-NEXT: label="Machine CFG for 'irreducible' function"

0 commit comments

Comments
 (0)