Skip to content
Open
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
12 changes: 12 additions & 0 deletions llvm/include/llvm/CodeGen/MachineCFGPrinter.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "llvm/CodeGen/MachineBasicBlock.h"
#include "llvm/CodeGen/MachineFunction.h"
#include "llvm/CodeGen/MachineInstr.h"
#include "llvm/CodeGen/MachinePassManager.h"
#include "llvm/Support/DOTGraphTraits.h"

namespace llvm {
Expand Down Expand Up @@ -89,4 +90,15 @@ struct DOTGraphTraits<DOTMachineFuncInfo *> : public DefaultDOTGraphTraits {
"' function";
}
};

class MachineCFGPrinterPass : public PassInfoMixin<MachineCFGPrinterPass> {
raw_ostream &OS;

public:
explicit MachineCFGPrinterPass(raw_ostream &OS) : OS(OS) {}
PreservedAnalyses run(MachineFunction &MF,
MachineFunctionAnalysisManager &MFAM);
static bool isRequired() { return true; }
};

} // namespace llvm
2 changes: 1 addition & 1 deletion llvm/include/llvm/Passes/MachinePassRegistry.def
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ MACHINE_FUNCTION_PASS("block-placement-stats", MachineBlockPlacementStatsPass())
MACHINE_FUNCTION_PASS("branch-relaxation", BranchRelaxationPass())
MACHINE_FUNCTION_PASS("dead-mi-elimination", DeadMachineInstructionElimPass())
MACHINE_FUNCTION_PASS("detect-dead-lanes", DetectDeadLanesPass())
MACHINE_FUNCTION_PASS("dot-machine-cfg", MachineCFGPrinterPass(errs()))
MACHINE_FUNCTION_PASS("early-ifcvt", EarlyIfConverterPass())
MACHINE_FUNCTION_PASS("early-machinelicm", EarlyMachineLICMPass())
MACHINE_FUNCTION_PASS("early-tailduplication", EarlyTailDuplicatePass())
Expand Down Expand Up @@ -288,7 +289,6 @@ DUMMY_MACHINE_FUNCTION_PASS("break-false-deps", BreakFalseDepsPass)
DUMMY_MACHINE_FUNCTION_PASS("cfguard-longjmp", CFGuardLongjmpPass)
DUMMY_MACHINE_FUNCTION_PASS("cfi-fixup", CFIFixupPass)
DUMMY_MACHINE_FUNCTION_PASS("cfi-instr-inserter", CFIInstrInserterPass)
DUMMY_MACHINE_FUNCTION_PASS("dot-machine-cfg", MachineCFGPrinter)
DUMMY_MACHINE_FUNCTION_PASS("fs-profile-loader", MIRProfileLoaderNewPass)
DUMMY_MACHINE_FUNCTION_PASS("funclet-layout", FuncletLayoutPass)
DUMMY_MACHINE_FUNCTION_PASS("gc-empty-basic-blocks", GCEmptyBasicBlocksPass)
Expand Down
12 changes: 12 additions & 0 deletions llvm/lib/CodeGen/MachineCFGPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,18 @@ static void writeMCFGToDotFile(MachineFunction &MF) {
errs() << '\n';
}

PreservedAnalyses
MachineCFGPrinterPass::run(MachineFunction &MF,
MachineFunctionAnalysisManager &MFAM) {
if (!MCFGFuncName.empty() && !MF.getName().contains(MCFGFuncName))
return PreservedAnalyses::all();
OS << "Writing Machine CFG for function ";
MF.getFunction().printAsOperand(OS, /*PrintType=*/false);
OS << '\n';
writeMCFGToDotFile(MF);
return PreservedAnalyses::all();
}

namespace {

class MachineCFGPrinter : public MachineFunctionPass {
Expand Down
1 change: 1 addition & 0 deletions llvm/lib/Passes/PassBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@
#include "llvm/CodeGen/MachineBlockFrequencyInfo.h"
#include "llvm/CodeGen/MachineBlockPlacement.h"
#include "llvm/CodeGen/MachineBranchProbabilityInfo.h"
#include "llvm/CodeGen/MachineCFGPrinter.h"
#include "llvm/CodeGen/MachineCSE.h"
#include "llvm/CodeGen/MachineCopyPropagation.h"
#include "llvm/CodeGen/MachineCycleAnalysis.h"
Expand Down
2 changes: 2 additions & 0 deletions llvm/test/Analysis/DotMachineCFG/AMDGPU/functions.mir
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# RUN: llc -mtriple=amdgcn-- -run-pass=dot-machine-cfg -mcfg-dot-filename-prefix=%t -mcfg-func-name=func2 -o - %s 2>&1 > /dev/null
# RUN: FileCheck %s -input-file=%t.func2.dot --check-prefix=MCFG
# RUN: llc -mtriple=amdgcn-- -passes=dot-machine-cfg -mcfg-dot-filename-prefix=%t -mcfg-func-name=func2 -filetype=null %s
# RUN: FileCheck %s -input-file=%t.func2.dot --check-prefix=MCFG

# MCFG-NOT: digraph "Machine CFG for 'func1' function"
name: func1
Expand Down
4 changes: 4 additions & 0 deletions llvm/test/Analysis/DotMachineCFG/AMDGPU/irreducible.mir
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
# RUN: FileCheck %s -input-file=%t.irreducible.dot --check-prefix=MCFG
# RUN: llc -mtriple=amdgcn-- -run-pass=dot-machine-cfg -mcfg-dot-filename-prefix=%t -dot-mcfg-only -o - %s 2>&1 > /dev/null
# RUN: FileCheck %s -input-file=%t.irreducible.dot --check-prefix=MCFG-ONLY
# RUN: llc -mtriple=amdgcn-- -passes=dot-machine-cfg -mcfg-dot-filename-prefix=%t -filetype=null %s
# RUN: FileCheck %s -input-file=%t.irreducible.dot --check-prefix=MCFG
# RUN: llc -mtriple=amdgcn-- -passes=dot-machine-cfg -mcfg-dot-filename-prefix=%t -dot-mcfg-only -filetype=null %s
# RUN: FileCheck %s -input-file=%t.irreducible.dot --check-prefix=MCFG-ONLY

# MCFG: digraph "Machine CFG for 'irreducible' function"
# MCFG-NEXT: label="Machine CFG for 'irreducible' function"
Expand Down