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
13#include "llvm/CodeGen/Passes.h"
15
16using namespace llvm;
17
18#define DEBUG_TYPE "aarch64-post-coalescer-pass"
19
20namespace {
21
22struct AArch64PostCoalescer : public MachineFunctionPass {
23 static char ID;
24
25 AArch64PostCoalescer() : MachineFunctionPass(ID) {}
26
27 LiveIntervals *LIS;
29
30 bool runOnMachineFunction(MachineFunction &MF) override;
31
32 StringRef getPassName() const override {
33 return "AArch64 Post Coalescer pass";
34 }
35
36 void getAnalysisUsage(AnalysisUsage &AU) const override {
37 AU.setPreservesCFG();
42 }
43};
44
45char AArch64PostCoalescer::ID = 0;
46
47} // end anonymous namespace
48
49INITIALIZE_PASS_BEGIN(AArch64PostCoalescer, "aarch64-post-coalescer-pass",
50 "AArch64 Post Coalescer Pass", false, false)
52INITIALIZE_PASS_END(AArch64PostCoalescer, "aarch64-post-coalescer-pass",
53 "AArch64 Post Coalescer Pass", false, false)
54
55bool AArch64PostCoalescer::runOnMachineFunction(MachineFunction &MF) {
56 if (skipFunction(MF.getFunction()))
57 return false;
58
59 AArch64FunctionInfo *FuncInfo = MF.getInfo<AArch64FunctionInfo>();
60 if (!FuncInfo->hasStreamingModeChanges())
61 return false;
62
63 MRI = &MF.getRegInfo();
64 LIS = &getAnalysis<LiveIntervalsWrapperPass>().getLIS();
65 bool Changed = false;
66
67 for (MachineBasicBlock &MBB : MF) {
69 switch (MI.getOpcode()) {
70 default:
71 break;
72 case AArch64::COALESCER_BARRIER_FPR16:
73 case AArch64::COALESCER_BARRIER_FPR32:
74 case AArch64::COALESCER_BARRIER_FPR64:
75 case AArch64::COALESCER_BARRIER_FPR128: {
76 Register Src = MI.getOperand(1).getReg();
77 Register Dst = MI.getOperand(0).getReg();
78 if (Src != Dst)
79 MRI->replaceRegWith(Dst, Src);
80
81 if (MI.getOperand(1).isUndef())
82 for (MachineOperand &MO : MRI->use_operands(Dst))
83 MO.setIsUndef();
84
85 // MI must be erased from the basic block before recalculating the live
86 // interval.
87 LIS->RemoveMachineInstrFromMaps(MI);
88 MI.eraseFromParent();
89
90 LIS->removeInterval(Src);
91 LIS->createAndComputeVirtRegInterval(Src);
92
93 Changed = true;
94 break;
95 }
96 }
97 }
98 }
99
100 return Changed;
101}
102
104 return new AArch64PostCoalescer();
105}
for(const MachineOperand &MO :llvm::drop_begin(OldMI.operands(), Desc.getNumOperands()))
MachineBasicBlock & MBB
IRTranslator LLVM IR MI
if(PassOpts->AAPipeline)
#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...
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
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...
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
Representation of each machine instruction.
MachineOperand class - Representation of each machine instruction operand.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
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