Skip to content

Commit 69c8312

Browse files
authored
[CodeGen][NewPM] Port MachineCycleInfo to NPM (#114745)
1 parent e118670 commit 69c8312

File tree

7 files changed

+83
-26
lines changed

7 files changed

+83
-26
lines changed

llvm/include/llvm/CodeGen/MachineCycleAnalysis.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#include "llvm/ADT/GenericCycleInfo.h"
1818
#include "llvm/CodeGen/MachineFunctionPass.h"
19+
#include "llvm/CodeGen/MachinePassManager.h"
1920
#include "llvm/CodeGen/MachineSSAContext.h"
2021

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

50+
class MachineCycleAnalysis : public AnalysisInfoMixin<MachineCycleAnalysis> {
51+
friend AnalysisInfoMixin<MachineCycleAnalysis>;
52+
static AnalysisKey Key;
53+
54+
public:
55+
using Result = MachineCycleInfo;
56+
57+
Result run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM);
58+
};
59+
60+
class MachineCycleInfoPrinterPass
61+
: public PassInfoMixin<MachineCycleInfoPrinterPass> {
62+
raw_ostream &OS;
63+
64+
public:
65+
explicit MachineCycleInfoPrinterPass(raw_ostream &OS) : OS(OS) {}
66+
PreservedAnalyses run(MachineFunction &MF,
67+
MachineFunctionAnalysisManager &MFAM);
68+
static bool isRequired() { return true; }
69+
};
70+
4971
} // end namespace llvm
5072

5173
#endif // LLVM_CODEGEN_MACHINECYCLEANALYSIS_H

llvm/include/llvm/InitializePasses.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ void initializeMachineCFGPrinterPass(PassRegistry &);
191191
void initializeMachineCSELegacyPass(PassRegistry &);
192192
void initializeMachineCombinerPass(PassRegistry &);
193193
void initializeMachineCopyPropagationLegacyPass(PassRegistry &);
194-
void initializeMachineCycleInfoPrinterPassPass(PassRegistry &);
194+
void initializeMachineCycleInfoPrinterLegacyPass(PassRegistry &);
195195
void initializeMachineCycleInfoWrapperPassPass(PassRegistry &);
196196
void initializeMachineDominanceFrontierPass(PassRegistry &);
197197
void initializeMachineDominatorTreeWrapperPassPass(PassRegistry &);

llvm/include/llvm/Passes/MachinePassRegistry.def

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ MACHINE_FUNCTION_ANALYSIS("live-vars", LiveVariablesAnalysis())
106106
MACHINE_FUNCTION_ANALYSIS("machine-block-freq", MachineBlockFrequencyAnalysis())
107107
MACHINE_FUNCTION_ANALYSIS("machine-branch-prob",
108108
MachineBranchProbabilityAnalysis())
109+
MACHINE_FUNCTION_ANALYSIS("machine-cycles", MachineCycleAnalysis())
109110
MACHINE_FUNCTION_ANALYSIS("machine-dom-tree", MachineDominatorTreeAnalysis())
110111
MACHINE_FUNCTION_ANALYSIS("machine-loops", MachineLoopAnalysis())
111112
MACHINE_FUNCTION_ANALYSIS("machine-opt-remark-emitter",
@@ -162,6 +163,7 @@ MACHINE_FUNCTION_PASS("print<machine-block-freq>",
162163
MachineBlockFrequencyPrinterPass(errs()))
163164
MACHINE_FUNCTION_PASS("print<machine-branch-prob>",
164165
MachineBranchProbabilityPrinterPass(errs()))
166+
MACHINE_FUNCTION_PASS("print<machine-cycles>", MachineCycleInfoPrinterPass(errs()))
165167
MACHINE_FUNCTION_PASS("print<machine-dom-tree>",
166168
MachineDominatorTreePrinterPass(errs()))
167169
MACHINE_FUNCTION_PASS("print<machine-loops>", MachineLoopPrinterPass(errs()))
@@ -263,7 +265,6 @@ DUMMY_MACHINE_FUNCTION_PASS("mirfs-discriminators", MIRAddFSDiscriminatorsPass)
263265
DUMMY_MACHINE_FUNCTION_PASS("patchable-function", PatchableFunctionPass)
264266
DUMMY_MACHINE_FUNCTION_PASS("postra-machine-sink", PostRAMachineSinkingPass)
265267
DUMMY_MACHINE_FUNCTION_PASS("postrapseudos", ExpandPostRAPseudosPass)
266-
DUMMY_MACHINE_FUNCTION_PASS("print-machine-cycles", MachineCycleInfoPrinterPass)
267268
DUMMY_MACHINE_FUNCTION_PASS("print-machine-uniformity", MachineUniformityInfoPrinterPass)
268269
DUMMY_MACHINE_FUNCTION_PASS("processimpdefs", ProcessImplicitDefsPass)
269270
DUMMY_MACHINE_FUNCTION_PASS("prologepilog", PrologEpilogInserterPass)

llvm/lib/CodeGen/CodeGen.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ void llvm::initializeCodeGen(PassRegistry &Registry) {
7878
initializeMachineCSELegacyPass(Registry);
7979
initializeMachineCombinerPass(Registry);
8080
initializeMachineCopyPropagationLegacyPass(Registry);
81-
initializeMachineCycleInfoPrinterPassPass(Registry);
81+
initializeMachineCycleInfoPrinterLegacyPass(Registry);
8282
initializeMachineCycleInfoWrapperPassPass(Registry);
8383
initializeMachineDominatorTreeWrapperPassPass(Registry);
8484
initializeMachineFunctionPrinterPassPass(Registry);

llvm/lib/CodeGen/MachineCycleAnalysis.cpp

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,43 +54,61 @@ void MachineCycleInfoWrapperPass::releaseMemory() {
5454
F = nullptr;
5555
}
5656

57+
AnalysisKey MachineCycleAnalysis::Key;
58+
59+
MachineCycleInfo
60+
MachineCycleAnalysis::run(MachineFunction &MF,
61+
MachineFunctionAnalysisManager &MFAM) {
62+
MachineCycleInfo MCI;
63+
MCI.compute(MF);
64+
return MCI;
65+
}
66+
5767
namespace {
58-
class MachineCycleInfoPrinterPass : public MachineFunctionPass {
68+
class MachineCycleInfoPrinterLegacy : public MachineFunctionPass {
5969
public:
6070
static char ID;
6171

62-
MachineCycleInfoPrinterPass();
72+
MachineCycleInfoPrinterLegacy();
6373

6474
bool runOnMachineFunction(MachineFunction &F) override;
6575
void getAnalysisUsage(AnalysisUsage &AU) const override;
6676
};
6777
} // namespace
6878

69-
char MachineCycleInfoPrinterPass::ID = 0;
79+
char MachineCycleInfoPrinterLegacy::ID = 0;
7080

71-
MachineCycleInfoPrinterPass::MachineCycleInfoPrinterPass()
81+
MachineCycleInfoPrinterLegacy::MachineCycleInfoPrinterLegacy()
7282
: MachineFunctionPass(ID) {
73-
initializeMachineCycleInfoPrinterPassPass(*PassRegistry::getPassRegistry());
83+
initializeMachineCycleInfoPrinterLegacyPass(*PassRegistry::getPassRegistry());
7484
}
7585

76-
INITIALIZE_PASS_BEGIN(MachineCycleInfoPrinterPass, "print-machine-cycles",
86+
INITIALIZE_PASS_BEGIN(MachineCycleInfoPrinterLegacy, "print-machine-cycles",
7787
"Print Machine Cycle Info Analysis", true, true)
7888
INITIALIZE_PASS_DEPENDENCY(MachineCycleInfoWrapperPass)
79-
INITIALIZE_PASS_END(MachineCycleInfoPrinterPass, "print-machine-cycles",
89+
INITIALIZE_PASS_END(MachineCycleInfoPrinterLegacy, "print-machine-cycles",
8090
"Print Machine Cycle Info Analysis", true, true)
8191

82-
void MachineCycleInfoPrinterPass::getAnalysisUsage(AnalysisUsage &AU) const {
92+
void MachineCycleInfoPrinterLegacy::getAnalysisUsage(AnalysisUsage &AU) const {
8393
AU.setPreservesAll();
8494
AU.addRequired<MachineCycleInfoWrapperPass>();
8595
MachineFunctionPass::getAnalysisUsage(AU);
8696
}
8797

88-
bool MachineCycleInfoPrinterPass::runOnMachineFunction(MachineFunction &F) {
98+
bool MachineCycleInfoPrinterLegacy::runOnMachineFunction(MachineFunction &F) {
8999
auto &CI = getAnalysis<MachineCycleInfoWrapperPass>();
90100
CI.print(errs());
91101
return false;
92102
}
93103

104+
PreservedAnalyses
105+
MachineCycleInfoPrinterPass::run(MachineFunction &MF,
106+
MachineFunctionAnalysisManager &MFAM) {
107+
auto &MCI = MFAM.getResult<MachineCycleAnalysis>(MF);
108+
MCI.print(OS);
109+
return PreservedAnalyses::all();
110+
}
111+
94112
bool llvm::isCycleInvariant(const MachineCycle *Cycle, MachineInstr &I) {
95113
MachineFunction *MF = I.getParent()->getParent();
96114
MachineRegisterInfo *MRI = &MF->getRegInfo();

llvm/lib/Passes/PassBuilder.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@
111111
#include "llvm/CodeGen/MachineBranchProbabilityInfo.h"
112112
#include "llvm/CodeGen/MachineCSE.h"
113113
#include "llvm/CodeGen/MachineCopyPropagation.h"
114+
#include "llvm/CodeGen/MachineCycleAnalysis.h"
114115
#include "llvm/CodeGen/MachineDominators.h"
115116
#include "llvm/CodeGen/MachineFunctionAnalysis.h"
116117
#include "llvm/CodeGen/MachineLICM.h"

llvm/test/CodeGen/X86/cycle-info.mir

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
# RUN: llc -mtriple=x86_64-unknown-linux-gnu -run-pass=print-machine-cycles -o - %s 2>&1 | FileCheck %s
1+
# RUN: llc -mtriple=x86_64-unknown-linux-gnu -run-pass=print-machine-cycles -o - %s 2>&1 | FileCheck %s --check-prefixes=LEGACY,CHECK
2+
3+
# 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
24

35
...
46
---
5-
# CHECK-LABEL: MachineCycleInfo for function: empty
7+
# LEGACY-LABEL: MachineCycleInfo for function: empty
8+
# NPM-LABEL: name: empty
69
name: empty
710
alignment: 16
811
tracksRegLiveness: true
@@ -15,7 +18,8 @@ body: |
1518
1619
...
1720
---
18-
# CHECK-LABEL: MachineCycleInfo for function: simple
21+
# LEGACY-LABEL: MachineCycleInfo for function: simple
22+
# NPM-LABEL: name: simple
1923
# CHECK: depth=1: entries(bb.1)
2024
name: simple
2125
alignment: 16
@@ -40,7 +44,8 @@ body: |
4044
4145
...
4246
---
43-
# CHECK-LABEL: MachineCycleInfo for function: two_latches
47+
# LEGACY-LABEL: MachineCycleInfo for function: two_latches
48+
# NPM-LABEL: name: two_latches
4449
# CHECK: depth=1: entries(bb.1) bb.2
4550
name: two_latches
4651
alignment: 16
@@ -72,7 +77,8 @@ body: |
7277
7378
...
7479
---
75-
# CHECK-LABEL: MachineCycleInfo for function: nested_simple
80+
# LEGACY-LABEL: MachineCycleInfo for function: nested_simple
81+
# NPM-LABEL: name: nested_simple
7682
# CHECK: depth=1: entries(bb.1) bb.3 bb.2
7783
# CHECK: depth=2: entries(bb.2)
7884
name: nested_simple
@@ -108,7 +114,8 @@ body: |
108114
109115
...
110116
---
111-
# CHECK-LABEL: MachineCycleInfo for function: nested_outer_latch_in_inner_loop
117+
# LEGACY-LABEL: MachineCycleInfo for function: nested_outer_latch_in_inner_loop
118+
# NPM-LABEL: name: nested_outer_latch_in_inner_loop
112119
# CHECK: depth=1: entries(bb.1) bb.2 bb.3
113120
# CHECK: depth=2: entries(bb.2) bb.3
114121
name: nested_outer_latch_in_inner_loop
@@ -144,7 +151,8 @@ body: |
144151
145152
...
146153
---
147-
# CHECK-LABEL: MachineCycleInfo for function: sibling_loops
154+
# LEGACY-LABEL: MachineCycleInfo for function: sibling_loops
155+
# NPM-LABEL: name: sibling_loops
148156
# CHECK: depth=1: entries(bb.1)
149157
# CHECK: depth=1: entries(bb.2)
150158
name: sibling_loops
@@ -181,7 +189,8 @@ body: |
181189
182190
...
183191
---
184-
# CHECK-LABEL: MachineCycleInfo for function: serial_loops
192+
# LEGACY-LABEL: MachineCycleInfo for function: serial_loops
193+
# NPM-LABEL: name: serial_loops
185194
# CHECK: depth=1: entries(bb.2)
186195
# CHECK: depth=1: entries(bb.1)
187196
name: serial_loops
@@ -214,7 +223,8 @@ body: |
214223
215224
...
216225
---
217-
# CHECK-LABEL: MachineCycleInfo for function: nested_sibling_loops
226+
# LEGACY-LABEL: MachineCycleInfo for function: nested_sibling_loops
227+
# NPM-LABEL: name: nested_sibling_loops
218228
# CHECK: depth=1: entries(bb.1) bb.4 bb.5 bb.3 bb.2
219229
# CHECK: depth=2: entries(bb.4) bb.5
220230
# CHECK: depth=2: entries(bb.2)
@@ -277,7 +287,8 @@ body: |
277287
278288
...
279289
---
280-
# CHECK-LABEL: MachineCycleInfo for function: deeper_nest
290+
# LEGACY-LABEL: MachineCycleInfo for function: deeper_nest
291+
# NPM-LABEL: name: deeper_nest
281292
# CHECK: depth=1: entries(bb.1) bb.5 bb.2 bb.3 bb.4
282293
# CHECK: depth=2: entries(bb.2) bb.3 bb.4
283294
# CHECK: depth=3: entries(bb.3) bb.4
@@ -324,7 +335,8 @@ body: |
324335
325336
...
326337
---
327-
# CHECK-LABEL: MachineCycleInfo for function: irreducible_basic
338+
# LEGACY-LABEL: MachineCycleInfo for function: irreducible_basic
339+
# NPM-LABEL: name: irreducible_basic
328340
# CHECK: depth=1: entries(bb.2 bb.1)
329341
name: irreducible_basic
330342
alignment: 16
@@ -360,7 +372,8 @@ body: |
360372
361373
...
362374
---
363-
# CHECK-LABEL: MachineCycleInfo for function: irreducible_mess
375+
# LEGACY-LABEL: MachineCycleInfo for function: irreducible_mess
376+
# NPM-LABEL: name: irreducible_mess
364377
# CHECK: depth=1: entries(bb.2 bb.1) bb.6 bb.5 bb.3 bb.4
365378
# CHECK: depth=2: entries(bb.5 bb.3 bb.1) bb.4
366379
# CHECK: depth=3: entries(bb.3 bb.1) bb.4
@@ -436,7 +449,8 @@ body: |
436449
437450
...
438451
---
439-
# CHECK-LABEL: MachineCycleInfo for function: irreducible_into_simple_cycle
452+
# LEGACY-LABEL: MachineCycleInfo for function: irreducible_into_simple_cycle
453+
# NPM-LABEL: name: irreducible_into_simple_cycle
440454
# CHECK: depth=1: entries(bb.2 bb.7 bb.4) bb.6 bb.5 bb.3
441455
name: irreducible_into_simple_cycle
442456
alignment: 16
@@ -495,7 +509,8 @@ body: |
495509
496510
...
497511
---
498-
# CHECK-LABEL: MachineCycleInfo for function: irreducible_mountain_bug
512+
# LEGACY-LABEL: MachineCycleInfo for function: irreducible_mountain_bug
513+
# NPM-LABEL: name: irreducible_mountain_bug
499514
# CHECK: depth=1: entries(bb.6) bb.11 bb.10 bb.8 bb.7 bb.9 bb.12
500515
# CHECK: depth=2: entries(bb.10 bb.7) bb.8 bb.9
501516
# CHECK: depth=3: entries(bb.8 bb.7) bb.9

0 commit comments

Comments
 (0)