LLVM 20.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
14
15using namespace llvm;
16
17#define DEBUG_TYPE "aarch64-post-coalescer-pass"
18
19namespace {
20
21struct AArch64PostCoalescer : public MachineFunctionPass {
22 static char ID;
23
24 AArch64PostCoalescer() : MachineFunctionPass(ID) {
26 }
27
28 LiveIntervals *LIS;
30
31 bool runOnMachineFunction(MachineFunction &MF) override;
32
33 StringRef getPassName() const override {
34 return "AArch64 Post Coalescer pass";
35 }
36
37 void getAnalysisUsage(AnalysisUsage &AU) const override {
38 AU.setPreservesAll();
41 }
42};
43
44char AArch64PostCoalescer::ID = 0;
45
46} // end anonymous namespace
47
48INITIALIZE_PASS_BEGIN(AArch64PostCoalescer, "aarch64-post-coalescer-pass",
49 "AArch64 Post Coalescer Pass", false, false)
51INITIALIZE_PASS_END(AArch64PostCoalescer, "aarch64-post-coalescer-pass",
52 "AArch64 Post Coalescer Pass", false, false)
53
54bool AArch64PostCoalescer::runOnMachineFunction(MachineFunction &MF) {
55 if (skipFunction(MF.getFunction()))
56 return false;
57
58 AArch64FunctionInfo *FuncInfo = MF.getInfo<AArch64FunctionInfo>();
59 if (!FuncInfo->hasStreamingModeChanges())
60 return false;
61
62 MRI = &MF.getRegInfo();
63 LIS = &getAnalysis<LiveIntervalsWrapperPass>().getLIS();
64 bool Changed = false;
65
66 for (MachineBasicBlock &MBB : MF) {
68 switch (MI.getOpcode()) {
69 default:
70 break;
71 case AArch64::COALESCER_BARRIER_FPR16:
72 case AArch64::COALESCER_BARRIER_FPR32:
73 case AArch64::COALESCER_BARRIER_FPR64:
74 case AArch64::COALESCER_BARRIER_FPR128: {
75 Register Src = MI.getOperand(1).getReg();
76 Register Dst = MI.getOperand(0).getReg();
77 if (Src != Dst)
78 MRI->replaceRegWith(Dst, Src);
79
80 // MI must be erased from the basic block before recalculating the live
81 // interval.
82 LIS->RemoveMachineInstrFromMaps(MI);
83 MI.eraseFromParent();
84
85 LIS->removeInterval(Src);
86 LIS->createAndComputeVirtRegInterval(Src);
87
88 Changed = true;
89 break;
90 }
91 }
92 }
93 }
94
95 return Changed;
96}
97
99 return new AArch64PostCoalescer();
100}
unsigned const MachineRegisterInfo * MRI
aarch64 post coalescer pass
MachineBasicBlock & MBB
IRTranslator LLVM IR MI
#define INITIALIZE_PASS_DEPENDENCY(depName)
Definition: PassSupport.h:55
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
Definition: PassSupport.h:57
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
Definition: PassSupport.h:52
register Register Coalescer
register coalescer
AArch64FunctionInfo - This class is derived from MachineFunctionInfo and contains private AArch64-spe...
Represent the analysis usage information of a pass.
AnalysisUsage & addRequired()
void setPreservesAll()
Set by analyses that do not transform their input at all.
FunctionPass class - This class is used to implement most global optimizations.
Definition: Pass.h:310
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.
virtual bool runOnMachineFunction(MachineFunction &MF)=0
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
Representation of each machine instruction.
Definition: MachineInstr.h:69
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
Pass interface - Implemented by all 'passes'.
Definition: Pass.h:94
virtual StringRef getPassName() const
getPassName - Return a nice clean name for a pass.
Definition: Pass.cpp:81
Wrapper class representing virtual and physical registers.
Definition: Register.h:19
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:51
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.
Definition: AddressRanges.h:18
void initializeAArch64PostCoalescerPass(PassRegistry &)
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:657