diff options
author | Akshat Oke <Akshat.Oke@amd.com> | 2025-03-03 11:26:17 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-03-03 11:26:17 +0530 |
commit | 69c8312c0ab30e0906a374ecfc88c60ea7ffe5a4 (patch) | |
tree | 029f2d94f54d7c00b92dc5794c2e3dbc6a4f7cae | |
parent | e11867039f0806bdfebeb33bb71d8ce3ba8ee33d (diff) | |
download | llvm-69c8312c0ab30e0906a374ecfc88c60ea7ffe5a4.zip llvm-69c8312c0ab30e0906a374ecfc88c60ea7ffe5a4.tar.gz llvm-69c8312c0ab30e0906a374ecfc88c60ea7ffe5a4.tar.bz2 |
[CodeGen][NewPM] Port MachineCycleInfo to NPM (#114745)
-rw-r--r-- | llvm/include/llvm/CodeGen/MachineCycleAnalysis.h | 22 | ||||
-rw-r--r-- | llvm/include/llvm/InitializePasses.h | 2 | ||||
-rw-r--r-- | llvm/include/llvm/Passes/MachinePassRegistry.def | 3 | ||||
-rw-r--r-- | llvm/lib/CodeGen/CodeGen.cpp | 2 | ||||
-rw-r--r-- | llvm/lib/CodeGen/MachineCycleAnalysis.cpp | 36 | ||||
-rw-r--r-- | llvm/lib/Passes/PassBuilder.cpp | 1 | ||||
-rw-r--r-- | llvm/test/CodeGen/X86/cycle-info.mir | 43 |
7 files changed, 83 insertions, 26 deletions
diff --git a/llvm/include/llvm/CodeGen/MachineCycleAnalysis.h b/llvm/include/llvm/CodeGen/MachineCycleAnalysis.h index 1888dd0..b2af2d5 100644 --- a/llvm/include/llvm/CodeGen/MachineCycleAnalysis.h +++ b/llvm/include/llvm/CodeGen/MachineCycleAnalysis.h @@ -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 { @@ -46,6 +47,27 @@ public: // 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 diff --git a/llvm/include/llvm/InitializePasses.h b/llvm/include/llvm/InitializePasses.h index 2232b8b..0850405 100644 --- a/llvm/include/llvm/InitializePasses.h +++ b/llvm/include/llvm/InitializePasses.h @@ -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 &); diff --git a/llvm/include/llvm/Passes/MachinePassRegistry.def b/llvm/include/llvm/Passes/MachinePassRegistry.def index acb4532..92826ac 100644 --- a/llvm/include/llvm/Passes/MachinePassRegistry.def +++ b/llvm/include/llvm/Passes/MachinePassRegistry.def @@ -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", @@ -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())) @@ -263,7 +265,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) diff --git a/llvm/lib/CodeGen/CodeGen.cpp b/llvm/lib/CodeGen/CodeGen.cpp index 6311ec2..96db2dc 100644 --- a/llvm/lib/CodeGen/CodeGen.cpp +++ b/llvm/lib/CodeGen/CodeGen.cpp @@ -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); diff --git a/llvm/lib/CodeGen/MachineCycleAnalysis.cpp b/llvm/lib/CodeGen/MachineCycleAnalysis.cpp index 57f7a09..33a5b66 100644 --- a/llvm/lib/CodeGen/MachineCycleAnalysis.cpp +++ b/llvm/lib/CodeGen/MachineCycleAnalysis.cpp @@ -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(); diff --git a/llvm/lib/Passes/PassBuilder.cpp b/llvm/lib/Passes/PassBuilder.cpp index ba8790a..a0fb2bc 100644 --- a/llvm/lib/Passes/PassBuilder.cpp +++ b/llvm/lib/Passes/PassBuilder.cpp @@ -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" diff --git a/llvm/test/CodeGen/X86/cycle-info.mir b/llvm/test/CodeGen/X86/cycle-info.mir index 358ccb2..3b33828b 100644 --- a/llvm/test/CodeGen/X86/cycle-info.mir +++ b/llvm/test/CodeGen/X86/cycle-info.mir @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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) @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 |