Skip to content

Commit 6886505

Browse files
authored
[NewPM] Port AArch64RedundantCondBranch to the new pass manager (#190897)
Adds a newPM pass for AArch64RedundantCondBranch - Refactors base logic into an Impl class - Renames old pass with the "Legacy" suffix - Adds the new pass manager pass using refactored logic - Updated existing .mir tests to also test with the New Pass Manager. Context and motivation in https://llvm.org/docs/NewPassManager.html#status-of-the-new-and-legacy-pass-managers
1 parent 058398c commit 6886505

5 files changed

Lines changed: 40 additions & 16 deletions

File tree

llvm/lib/Target/AArch64/AArch64.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ void initializeAArch64PostLegalizerLoweringLegacyPass(PassRegistry &);
162162
void initializeAArch64PreLegalizerCombinerLegacyPass(PassRegistry &);
163163
void initializeAArch64PromoteConstantPass(PassRegistry&);
164164
void initializeAArch64RedundantCopyEliminationLegacyPass(PassRegistry &);
165-
void initializeAArch64RedundantCondBranchPass(PassRegistry &);
165+
void initializeAArch64RedundantCondBranchLegacyPass(PassRegistry &);
166166
void initializeAArch64SIMDInstrOptPass(PassRegistry &);
167167
void initializeAArch64SLSHardeningPass(PassRegistry &);
168168
void initializeAArch64SpeculationHardeningPass(PassRegistry &);
@@ -204,6 +204,13 @@ class AArch64BranchTargetsPass
204204
MachineFunctionAnalysisManager &MFAM);
205205
};
206206

207+
class AArch64RedundantCondBranchPass
208+
: public PassInfoMixin<AArch64RedundantCondBranchPass> {
209+
public:
210+
PreservedAnalyses run(MachineFunction &MF,
211+
MachineFunctionAnalysisManager &MFAM);
212+
};
213+
207214
class AArch64AdvSIMDScalarPass
208215
: public PassInfoMixin<AArch64AdvSIMDScalarPass> {
209216
public:

llvm/lib/Target/AArch64/AArch64PassRegistry.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ MACHINE_FUNCTION_PASS("aarch64-postlegalizer-lowering",
4545
MACHINE_FUNCTION_PASS("aarch64-prelegalizer-combiner",
4646
AArch64PreLegalizerCombinerPass())
4747
MACHINE_FUNCTION_PASS("aarch64-ptrauth", AArch64PointerAuthPass())
48+
MACHINE_FUNCTION_PASS("aarch64-redundantcondbranch", AArch64RedundantCondBranchPass())
4849
MACHINE_FUNCTION_PASS("aarch64-simd-scalar", AArch64AdvSIMDScalarPass())
4950
MACHINE_FUNCTION_PASS("aarch64-O0-prelegalizer-combiner",
5051
AArch64O0PreLegalizerCombinerPass())

llvm/lib/Target/AArch64/AArch64RedundantCondBranchPass.cpp

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,40 +16,38 @@
1616
#include "AArch64.h"
1717
#include "AArch64InstrInfo.h"
1818
#include "llvm/CodeGen/MachineFunctionPass.h"
19-
#include "llvm/CodeGen/MachineInstrBuilder.h"
2019
#include "llvm/CodeGen/TargetInstrInfo.h"
21-
#include "llvm/Support/Debug.h"
2220

2321
using namespace llvm;
2422

2523
#define DEBUG_TYPE "aarch64-redundantcondbranch"
2624

2725
namespace {
28-
class AArch64RedundantCondBranch : public MachineFunctionPass {
26+
27+
class AArch64RedundantCondBranchLegacy : public MachineFunctionPass {
2928
public:
3029
static char ID;
31-
AArch64RedundantCondBranch() : MachineFunctionPass(ID) {}
30+
AArch64RedundantCondBranchLegacy() : MachineFunctionPass(ID) {}
31+
32+
StringRef getPassName() const override {
33+
return "AArch64 Redundant Conditional Branch Elimination";
34+
}
3235

36+
protected:
3337
bool runOnMachineFunction(MachineFunction &MF) override;
3438

3539
MachineFunctionProperties getRequiredProperties() const override {
3640
return MachineFunctionProperties().setNoVRegs();
3741
}
38-
StringRef getPassName() const override {
39-
return "AArch64 Redundant Conditional Branch Elimination";
40-
}
4142
};
42-
char AArch64RedundantCondBranch::ID = 0;
43+
char AArch64RedundantCondBranchLegacy::ID = 0;
4344
} // namespace
4445

45-
INITIALIZE_PASS(AArch64RedundantCondBranch, "aarch64-redundantcondbranch",
46+
INITIALIZE_PASS(AArch64RedundantCondBranchLegacy, "aarch64-redundantcondbranch",
4647
"AArch64 Redundant Conditional Branch Elimination pass", false,
4748
false)
4849

49-
bool AArch64RedundantCondBranch::runOnMachineFunction(MachineFunction &MF) {
50-
if (skipFunction(MF.getFunction()))
51-
return false;
52-
50+
static bool runAArch64RedundantCondBranch(MachineFunction &MF) {
5351
const TargetInstrInfo &TII = *MF.getSubtarget().getInstrInfo();
5452

5553
bool Changed = false;
@@ -58,6 +56,23 @@ bool AArch64RedundantCondBranch::runOnMachineFunction(MachineFunction &MF) {
5856
return Changed;
5957
}
6058

59+
bool AArch64RedundantCondBranchLegacy::runOnMachineFunction(
60+
MachineFunction &MF) {
61+
if (skipFunction(MF.getFunction()))
62+
return false;
63+
64+
return runAArch64RedundantCondBranch(MF);
65+
}
66+
67+
PreservedAnalyses
68+
AArch64RedundantCondBranchPass::run(MachineFunction &MF,
69+
MachineFunctionAnalysisManager &) {
70+
if (runAArch64RedundantCondBranch(MF)) {
71+
return getMachineFunctionPassPreservedAnalyses();
72+
}
73+
return PreservedAnalyses::all();
74+
}
75+
6176
FunctionPass *llvm::createAArch64RedundantCondBranchPass() {
62-
return new AArch64RedundantCondBranch();
77+
return new AArch64RedundantCondBranchLegacy();
6378
}

llvm/lib/Target/AArch64/AArch64TargetMachine.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ LLVMInitializeAArch64Target() {
261261
initializeAArch64PostLegalizerLoweringLegacyPass(PR);
262262
initializeAArch64PromoteConstantPass(PR);
263263
initializeAArch64RedundantCopyEliminationLegacyPass(PR);
264-
initializeAArch64RedundantCondBranchPass(PR);
264+
initializeAArch64RedundantCondBranchLegacyPass(PR);
265265
initializeAArch64StorePairSuppressPass(PR);
266266
initializeFalkorHWPFFixPass(PR);
267267
initializeFalkorMarkStridedAccessesLegacyPass(PR);

llvm/test/CodeGen/AArch64/cbz_wzr.mir

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --version 6
22
# RUN: llc -o - %s -mtriple=aarch64-none-eabi -run-pass=machine-cp,aarch64-redundantcondbranch -mcp-use-is-copy-instr | FileCheck %s
3+
# RUN: llc -o - %s -mtriple=aarch64-none-eabi -passes=machine-cp,aarch64-redundantcondbranch -mcp-use-is-copy-instr | FileCheck %s
34

45
---
56
name: cbz_wzr

0 commit comments

Comments
 (0)