LLVM 23.0.0git
AArch64RedundantCondBranchPass.cpp
Go to the documentation of this file.
1//=- AArch64RedundantCondBranch.cpp - Remove redundant conditional branches -=//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// Late in the pipeline, especially with zero phi operands propagated after tail
10// duplications, we can end up with CBZ/CBNZ/TBZ/TBNZ with a zero register. This
11// simple pass looks at the terminators to a block, removing the redundant
12// instructions where necessary.
13//
14//===----------------------------------------------------------------------===//
15
16#include "AArch64.h"
17#include "AArch64InstrInfo.h"
20
21using namespace llvm;
22
23#define DEBUG_TYPE "aarch64-redundantcondbranch"
24
25namespace {
26
27class AArch64RedundantCondBranchLegacy : public MachineFunctionPass {
28public:
29 static char ID;
30 AArch64RedundantCondBranchLegacy() : MachineFunctionPass(ID) {}
31
32 StringRef getPassName() const override {
33 return "AArch64 Redundant Conditional Branch Elimination";
34 }
35
36protected:
37 bool runOnMachineFunction(MachineFunction &MF) override;
38
39 MachineFunctionProperties getRequiredProperties() const override {
40 return MachineFunctionProperties().setNoVRegs();
41 }
42};
43char AArch64RedundantCondBranchLegacy::ID = 0;
44} // namespace
45
46INITIALIZE_PASS(AArch64RedundantCondBranchLegacy, "aarch64-redundantcondbranch",
47 "AArch64 Redundant Conditional Branch Elimination pass", false,
48 false)
49
50static bool runAArch64RedundantCondBranch(MachineFunction &MF) {
51 const TargetInstrInfo &TII = *MF.getSubtarget().getInstrInfo();
52
53 bool Changed = false;
54 for (MachineBasicBlock &MBB : MF)
56 return Changed;
57}
58
59bool AArch64RedundantCondBranchLegacy::runOnMachineFunction(
60 MachineFunction &MF) {
61 if (skipFunction(MF.getFunction()))
62 return false;
63
64 return runAArch64RedundantCondBranch(MF);
65}
66
67PreservedAnalyses
70 if (runAArch64RedundantCondBranch(MF)) {
72 }
74}
75
77 return new AArch64RedundantCondBranchLegacy();
78}
MachineBasicBlock & MBB
const HexagonInstrInfo * TII
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
Definition PassSupport.h:56
PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
FunctionPass class - This class is used to implement most global optimizations.
Definition Pass.h:314
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
Properties which a MachineFunction may have at a given point in time.
Function & getFunction()
Return the LLVM function that this machine code represents.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition Analysis.h:118
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
TargetInstrInfo - Interface to description of machine instruction set.
Changed
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition CallingConv.h:24
This is an optimization pass for GlobalISel generic memory operations.
AnalysisManager< MachineFunction > MachineFunctionAnalysisManager
LLVM_ABI PreservedAnalyses getMachineFunctionPassPreservedAnalyses()
Returns the minimum set of Analyses that all machine function passes must preserve.
bool optimizeTerminators(MachineBasicBlock *MBB, const TargetInstrInfo &TII)
FunctionPass * createAArch64RedundantCondBranchPass()