LLVM 23.0.0git
AArch64PostCoalescerPass.cpp
Go to the documentation of this file.
1//===- AArch64PostCoalescerPass.cpp - AArch64 Post Coalescer pass ---------===//
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
10#include "AArch64.h"
15#include "llvm/CodeGen/Passes.h"
17
18using namespace llvm;
19
20#define DEBUG_TYPE "aarch64-post-coalescer"
21
22namespace {
23
24bool runAArch64PostCoalescer(MachineFunction &MF, LiveIntervals &LIS) {
26 if (!FuncInfo->hasStreamingModeChanges())
27 return false;
28
30 bool Changed = false;
31
32 for (MachineBasicBlock &MBB : MF) {
34 switch (MI.getOpcode()) {
35 default:
36 break;
37 case AArch64::COALESCER_BARRIER_FPR16:
38 case AArch64::COALESCER_BARRIER_FPR32:
39 case AArch64::COALESCER_BARRIER_FPR64:
40 case AArch64::COALESCER_BARRIER_FPR128: {
41 Register Src = MI.getOperand(1).getReg();
42 Register Dst = MI.getOperand(0).getReg();
43 if (Src != Dst)
44 MRI.replaceRegWith(Dst, Src);
45
46 if (MI.getOperand(1).isUndef())
47 for (MachineOperand &MO : MRI.use_operands(Dst))
48 MO.setIsUndef();
49
50 // MI must be erased from the basic block before recalculating the live
51 // interval.
53 MI.eraseFromParent();
54
55 LIS.removeInterval(Src);
57
58 Changed = true;
59 break;
60 }
61 }
62 }
63 }
64
65 return Changed;
66}
67
68struct AArch64PostCoalescerLegacy : public MachineFunctionPass {
69 static char ID;
70
71 AArch64PostCoalescerLegacy() : MachineFunctionPass(ID) {}
72
73 bool runOnMachineFunction(MachineFunction &MF) override;
74
75 StringRef getPassName() const override {
76 return "AArch64 Post Coalescer pass";
77 }
78
79 void getAnalysisUsage(AnalysisUsage &AU) const override {
80 AU.setPreservesCFG();
85 }
86};
87
88char AArch64PostCoalescerLegacy::ID = 0;
89
90} // end anonymous namespace
91
92INITIALIZE_PASS_BEGIN(AArch64PostCoalescerLegacy, "aarch64-post-coalescer",
93 "AArch64 Post Coalescer Pass", false, false)
95INITIALIZE_PASS_END(AArch64PostCoalescerLegacy, "aarch64-post-coalescer",
96 "AArch64 Post Coalescer Pass", false, false)
97
98bool AArch64PostCoalescerLegacy::runOnMachineFunction(MachineFunction &MF) {
99 if (skipFunction(MF.getFunction()))
100 return false;
101
102 auto &LIS = getAnalysis<LiveIntervalsWrapperPass>().getLIS();
103 return runAArch64PostCoalescer(MF, LIS);
104}
105
109 auto &LIS = MFAM.getResult<LiveIntervalsAnalysis>(MF);
110 const bool Changed = runAArch64PostCoalescer(MF, LIS);
111 if (!Changed)
112 return PreservedAnalyses::all();
117 return PA;
118}
119
121 return new AArch64PostCoalescerLegacy();
122}
MachineBasicBlock & MBB
IRTranslator LLVM IR MI
#define INITIALIZE_PASS_DEPENDENCY(depName)
Definition PassSupport.h:42
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
Definition PassSupport.h:44
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
Definition PassSupport.h:39
AArch64FunctionInfo - This class is derived from MachineFunctionInfo and contains private AArch64-spe...
PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
Represent the analysis usage information of a pass.
AnalysisUsage & addRequired()
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
LLVM_ABI void setPreservesCFG()
This function should be called by the pass, iff they do not:
Definition Pass.cpp:270
Represents analyses that only rely on functions' control flow.
Definition Analysis.h:73
FunctionPass class - This class is used to implement most global optimizations.
Definition Pass.h:314
void RemoveMachineInstrFromMaps(MachineInstr &MI)
void removeInterval(Register Reg)
Interval removal.
LiveInterval & createAndComputeVirtRegInterval(Register Reg)
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
Representation of each machine instruction.
MachineOperand class - Representation of each machine instruction operand.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
iterator_range< use_iterator > use_operands(Register Reg) const
LLVM_ABI void replaceRegWith(Register FromReg, Register ToReg)
replaceRegWith - Replace all instances of FromReg with ToReg in the machine function.
A set of analyses that are preserved following a run of a transformation pass.
Definition Analysis.h:112
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition Analysis.h:118
PreservedAnalyses & preserveSet()
Mark an analysis set as preserved.
Definition Analysis.h:151
PreservedAnalyses & preserve()
Mark an analysis as preserved.
Definition Analysis.h:132
Wrapper class representing virtual and physical registers.
Definition Register.h:20
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
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.
FunctionPass * createAArch64PostCoalescerPass()
iterator_range< early_inc_iterator_impl< detail::IterOfRange< RangeT > > > make_early_inc_range(RangeT &&Range)
Make a range that does early increment to allow mutation of the underlying range without disrupting i...
Definition STLExtras.h:634
AnalysisManager< MachineFunction > MachineFunctionAnalysisManager
LLVM_ABI PreservedAnalyses getMachineFunctionPassPreservedAnalyses()
Returns the minimum set of Analyses that all machine function passes must preserve.