Skip to content

[CodeGen][NewPM] Port MachineCycleInfo to NPM #114745

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
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
22 changes: 22 additions & 0 deletions llvm/include/llvm/CodeGen/MachineCycleAnalysis.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#include "llvm/ADT/GenericCycleInfo.h"
#include "llvm/CodeGen/MachineFunctionPass.h"
#include "llvm/CodeGen/MachinePassManager.h"
#include "llvm/CodeGen/MachineSSAContext.h"

namespace llvm {
Expand Down Expand Up @@ -46,6 +47,27 @@ class MachineCycleInfoWrapperPass : public MachineFunctionPass {
// version.
bool isCycleInvariant(const MachineCycle *Cycle, MachineInstr &I);

class MachineCycleAnalysis : public AnalysisInfoMixin<MachineCycleAnalysis> {
friend AnalysisInfoMixin<MachineCycleAnalysis>;
static AnalysisKey Key;

public:
using Result = MachineCycleInfo;

Result run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM);
};

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

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

} // end namespace llvm

#endif // LLVM_CODEGEN_MACHINECYCLEANALYSIS_H
2 changes: 1 addition & 1 deletion llvm/include/llvm/InitializePasses.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ void initializeMachineCFGPrinterPass(PassRegistry &);
void initializeMachineCSELegacyPass(PassRegistry &);
void initializeMachineCombinerPass(PassRegistry &);
void initializeMachineCopyPropagationLegacyPass(PassRegistry &);
void initializeMachineCycleInfoPrinterPassPass(PassRegistry &);
void initializeMachineCycleInfoPrinterLegacyPass(PassRegistry &);
void initializeMachineCycleInfoWrapperPassPass(PassRegistry &);
void initializeMachineDominanceFrontierPass(PassRegistry &);
void initializeMachineDominatorTreeWrapperPassPass(PassRegistry &);
Expand Down
3 changes: 2 additions & 1 deletion llvm/include/llvm/Passes/MachinePassRegistry.def
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ MACHINE_FUNCTION_ANALYSIS("live-vars", LiveVariablesAnalysis())
MACHINE_FUNCTION_ANALYSIS("machine-block-freq", MachineBlockFrequencyAnalysis())
MACHINE_FUNCTION_ANALYSIS("machine-branch-prob",
MachineBranchProbabilityAnalysis())
MACHINE_FUNCTION_ANALYSIS("machine-cycles", MachineCycleAnalysis())
MACHINE_FUNCTION_ANALYSIS("machine-dom-tree", MachineDominatorTreeAnalysis())
MACHINE_FUNCTION_ANALYSIS("machine-loops", MachineLoopAnalysis())
MACHINE_FUNCTION_ANALYSIS("machine-opt-remark-emitter",
Expand Down Expand Up @@ -162,6 +163,7 @@ MACHINE_FUNCTION_PASS("print<machine-block-freq>",
MachineBlockFrequencyPrinterPass(errs()))
MACHINE_FUNCTION_PASS("print<machine-branch-prob>",
MachineBranchProbabilityPrinterPass(errs()))
MACHINE_FUNCTION_PASS("print<machine-cycles>", MachineCycleInfoPrinterPass(errs()))
MACHINE_FUNCTION_PASS("print<machine-dom-tree>",
MachineDominatorTreePrinterPass(errs()))
MACHINE_FUNCTION_PASS("print<machine-loops>", MachineLoopPrinterPass(errs()))
Expand Down Expand Up @@ -254,7 +256,6 @@ DUMMY_MACHINE_FUNCTION_PASS("mirfs-discriminators", MIRAddFSDiscriminatorsPass)
DUMMY_MACHINE_FUNCTION_PASS("patchable-function", PatchableFunctionPass)
DUMMY_MACHINE_FUNCTION_PASS("postra-machine-sink", PostRAMachineSinkingPass)
DUMMY_MACHINE_FUNCTION_PASS("postrapseudos", ExpandPostRAPseudosPass)
DUMMY_MACHINE_FUNCTION_PASS("print-machine-cycles", MachineCycleInfoPrinterPass)
DUMMY_MACHINE_FUNCTION_PASS("print-machine-uniformity", MachineUniformityInfoPrinterPass)
DUMMY_MACHINE_FUNCTION_PASS("processimpdefs", ProcessImplicitDefsPass)
DUMMY_MACHINE_FUNCTION_PASS("prologepilog", PrologEpilogInserterPass)
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/CodeGen/CodeGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ void llvm::initializeCodeGen(PassRegistry &Registry) {
initializeMachineCSELegacyPass(Registry);
initializeMachineCombinerPass(Registry);
initializeMachineCopyPropagationLegacyPass(Registry);
initializeMachineCycleInfoPrinterPassPass(Registry);
initializeMachineCycleInfoPrinterLegacyPass(Registry);
initializeMachineCycleInfoWrapperPassPass(Registry);
initializeMachineDominatorTreeWrapperPassPass(Registry);
initializeMachineFunctionPrinterPassPass(Registry);
Expand Down
36 changes: 27 additions & 9 deletions llvm/lib/CodeGen/MachineCycleAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,43 +54,61 @@ void MachineCycleInfoWrapperPass::releaseMemory() {
F = nullptr;
}

AnalysisKey MachineCycleAnalysis::Key;

MachineCycleInfo
MachineCycleAnalysis::run(MachineFunction &MF,
MachineFunctionAnalysisManager &MFAM) {
MachineCycleInfo MCI;
MCI.compute(MF);
return MCI;
}

namespace {
class MachineCycleInfoPrinterPass : public MachineFunctionPass {
class MachineCycleInfoPrinterLegacy : public MachineFunctionPass {
public:
static char ID;

MachineCycleInfoPrinterPass();
MachineCycleInfoPrinterLegacy();

bool runOnMachineFunction(MachineFunction &F) override;
void getAnalysisUsage(AnalysisUsage &AU) const override;
};
} // namespace

char MachineCycleInfoPrinterPass::ID = 0;
char MachineCycleInfoPrinterLegacy::ID = 0;

MachineCycleInfoPrinterPass::MachineCycleInfoPrinterPass()
MachineCycleInfoPrinterLegacy::MachineCycleInfoPrinterLegacy()
: MachineFunctionPass(ID) {
initializeMachineCycleInfoPrinterPassPass(*PassRegistry::getPassRegistry());
initializeMachineCycleInfoPrinterLegacyPass(*PassRegistry::getPassRegistry());
}

INITIALIZE_PASS_BEGIN(MachineCycleInfoPrinterPass, "print-machine-cycles",
INITIALIZE_PASS_BEGIN(MachineCycleInfoPrinterLegacy, "print-machine-cycles",
"Print Machine Cycle Info Analysis", true, true)
INITIALIZE_PASS_DEPENDENCY(MachineCycleInfoWrapperPass)
INITIALIZE_PASS_END(MachineCycleInfoPrinterPass, "print-machine-cycles",
INITIALIZE_PASS_END(MachineCycleInfoPrinterLegacy, "print-machine-cycles",
"Print Machine Cycle Info Analysis", true, true)

void MachineCycleInfoPrinterPass::getAnalysisUsage(AnalysisUsage &AU) const {
void MachineCycleInfoPrinterLegacy::getAnalysisUsage(AnalysisUsage &AU) const {
AU.setPreservesAll();
AU.addRequired<MachineCycleInfoWrapperPass>();
MachineFunctionPass::getAnalysisUsage(AU);
}

bool MachineCycleInfoPrinterPass::runOnMachineFunction(MachineFunction &F) {
bool MachineCycleInfoPrinterLegacy::runOnMachineFunction(MachineFunction &F) {
auto &CI = getAnalysis<MachineCycleInfoWrapperPass>();
CI.print(errs());
return false;
}

PreservedAnalyses
MachineCycleInfoPrinterPass::run(MachineFunction &MF,
MachineFunctionAnalysisManager &MFAM) {
auto &MCI = MFAM.getResult<MachineCycleAnalysis>(MF);
MCI.print(OS);
return PreservedAnalyses::all();
}

bool llvm::isCycleInvariant(const MachineCycle *Cycle, MachineInstr &I) {
MachineFunction *MF = I.getParent()->getParent();
MachineRegisterInfo *MRI = &MF->getRegInfo();
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 @@ -111,6 +111,7 @@
#include "llvm/CodeGen/MachineBranchProbabilityInfo.h"
#include "llvm/CodeGen/MachineCSE.h"
#include "llvm/CodeGen/MachineCopyPropagation.h"
#include "llvm/CodeGen/MachineCycleAnalysis.h"
#include "llvm/CodeGen/MachineDominators.h"
#include "llvm/CodeGen/MachineFunctionAnalysis.h"
#include "llvm/CodeGen/MachineLICM.h"
Expand Down
43 changes: 29 additions & 14 deletions llvm/test/CodeGen/X86/cycle-info.mir
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# RUN: llc -mtriple=x86_64-unknown-linux-gnu -run-pass=print-machine-cycles -o - %s 2>&1 | FileCheck %s
# RUN: llc -mtriple=x86_64-unknown-linux-gnu -run-pass=print-machine-cycles -o - %s 2>&1 | FileCheck %s --check-prefixes=LEGACY,CHECK

# RUN: llc -mtriple=x86_64-unknown-linux-gnu -passes="machine-function(print,print<machine-cycles>)" -o - %s 2>&1 | FileCheck %s --check-prefixes=NPM,CHECK

...
---
# CHECK-LABEL: MachineCycleInfo for function: empty
# LEGACY-LABEL: MachineCycleInfo for function: empty
# NPM-LABEL: name: empty
name: empty
alignment: 16
tracksRegLiveness: true
Expand All @@ -15,7 +18,8 @@ body: |

...
---
# CHECK-LABEL: MachineCycleInfo for function: simple
# LEGACY-LABEL: MachineCycleInfo for function: simple
# NPM-LABEL: name: simple
# CHECK: depth=1: entries(bb.1)
name: simple
alignment: 16
Expand All @@ -40,7 +44,8 @@ body: |

...
---
# CHECK-LABEL: MachineCycleInfo for function: two_latches
# LEGACY-LABEL: MachineCycleInfo for function: two_latches
# NPM-LABEL: name: two_latches
# CHECK: depth=1: entries(bb.1) bb.2
name: two_latches
alignment: 16
Expand Down Expand Up @@ -72,7 +77,8 @@ body: |

...
---
# CHECK-LABEL: MachineCycleInfo for function: nested_simple
# LEGACY-LABEL: MachineCycleInfo for function: nested_simple
# NPM-LABEL: name: nested_simple
# CHECK: depth=1: entries(bb.1) bb.3 bb.2
# CHECK: depth=2: entries(bb.2)
name: nested_simple
Expand Down Expand Up @@ -108,7 +114,8 @@ body: |

...
---
# CHECK-LABEL: MachineCycleInfo for function: nested_outer_latch_in_inner_loop
# LEGACY-LABEL: MachineCycleInfo for function: nested_outer_latch_in_inner_loop
# NPM-LABEL: name: nested_outer_latch_in_inner_loop
# CHECK: depth=1: entries(bb.1) bb.2 bb.3
# CHECK: depth=2: entries(bb.2) bb.3
name: nested_outer_latch_in_inner_loop
Expand Down Expand Up @@ -144,7 +151,8 @@ body: |

...
---
# CHECK-LABEL: MachineCycleInfo for function: sibling_loops
# LEGACY-LABEL: MachineCycleInfo for function: sibling_loops
# NPM-LABEL: name: sibling_loops
# CHECK: depth=1: entries(bb.1)
# CHECK: depth=1: entries(bb.2)
name: sibling_loops
Expand Down Expand Up @@ -181,7 +189,8 @@ body: |

...
---
# CHECK-LABEL: MachineCycleInfo for function: serial_loops
# LEGACY-LABEL: MachineCycleInfo for function: serial_loops
# NPM-LABEL: name: serial_loops
# CHECK: depth=1: entries(bb.2)
# CHECK: depth=1: entries(bb.1)
name: serial_loops
Expand Down Expand Up @@ -214,7 +223,8 @@ body: |

...
---
# CHECK-LABEL: MachineCycleInfo for function: nested_sibling_loops
# LEGACY-LABEL: MachineCycleInfo for function: nested_sibling_loops
# NPM-LABEL: name: nested_sibling_loops
# CHECK: depth=1: entries(bb.1) bb.4 bb.5 bb.3 bb.2
# CHECK: depth=2: entries(bb.4) bb.5
# CHECK: depth=2: entries(bb.2)
Expand Down Expand Up @@ -277,7 +287,8 @@ body: |

...
---
# CHECK-LABEL: MachineCycleInfo for function: deeper_nest
# LEGACY-LABEL: MachineCycleInfo for function: deeper_nest
# NPM-LABEL: name: deeper_nest
# CHECK: depth=1: entries(bb.1) bb.5 bb.2 bb.3 bb.4
# CHECK: depth=2: entries(bb.2) bb.3 bb.4
# CHECK: depth=3: entries(bb.3) bb.4
Expand Down Expand Up @@ -324,7 +335,8 @@ body: |

...
---
# CHECK-LABEL: MachineCycleInfo for function: irreducible_basic
# LEGACY-LABEL: MachineCycleInfo for function: irreducible_basic
# NPM-LABEL: name: irreducible_basic
# CHECK: depth=1: entries(bb.2 bb.1)
name: irreducible_basic
alignment: 16
Expand Down Expand Up @@ -360,7 +372,8 @@ body: |

...
---
# CHECK-LABEL: MachineCycleInfo for function: irreducible_mess
# LEGACY-LABEL: MachineCycleInfo for function: irreducible_mess
# NPM-LABEL: name: irreducible_mess
# CHECK: depth=1: entries(bb.2 bb.1) bb.6 bb.5 bb.3 bb.4
# CHECK: depth=2: entries(bb.5 bb.3 bb.1) bb.4
# CHECK: depth=3: entries(bb.3 bb.1) bb.4
Expand Down Expand Up @@ -436,7 +449,8 @@ body: |

...
---
# CHECK-LABEL: MachineCycleInfo for function: irreducible_into_simple_cycle
# LEGACY-LABEL: MachineCycleInfo for function: irreducible_into_simple_cycle
# NPM-LABEL: name: irreducible_into_simple_cycle
# CHECK: depth=1: entries(bb.2 bb.7 bb.4) bb.6 bb.5 bb.3
name: irreducible_into_simple_cycle
alignment: 16
Expand Down Expand Up @@ -495,7 +509,8 @@ body: |

...
---
# CHECK-LABEL: MachineCycleInfo for function: irreducible_mountain_bug
# LEGACY-LABEL: MachineCycleInfo for function: irreducible_mountain_bug
# NPM-LABEL: name: irreducible_mountain_bug
# CHECK: depth=1: entries(bb.6) bb.11 bb.10 bb.8 bb.7 bb.9 bb.12
# CHECK: depth=2: entries(bb.10 bb.7) bb.8 bb.9
# CHECK: depth=3: entries(bb.8 bb.7) bb.9
Expand Down