27#define DEBUG_TYPE "aarch64-post-select-optimize"
36 AArch64PostSelectOptimize();
39 return "AArch64 Post Select Optimizer";
54void AArch64PostSelectOptimize::getAnalysisUsage(
AnalysisUsage &AU)
const {
61AArch64PostSelectOptimize::AArch64PostSelectOptimize()
70 case AArch64::SUBSXrr:
71 return AArch64::SUBXrr;
72 case AArch64::SUBSWrr:
73 return AArch64::SUBWrr;
74 case AArch64::SUBSXrs:
75 return AArch64::SUBXrs;
76 case AArch64::SUBSWrs:
77 return AArch64::SUBWrs;
78 case AArch64::SUBSXri:
79 return AArch64::SUBXri;
80 case AArch64::SUBSWri:
81 return AArch64::SUBWri;
82 case AArch64::ADDSXrr:
83 return AArch64::ADDXrr;
84 case AArch64::ADDSWrr:
85 return AArch64::ADDWrr;
86 case AArch64::ADDSXrs:
87 return AArch64::ADDXrs;
88 case AArch64::ADDSWrs:
89 return AArch64::ADDWrs;
90 case AArch64::ADDSXri:
91 return AArch64::ADDXri;
92 case AArch64::ADDSWri:
93 return AArch64::ADDWri;
95 return AArch64::SBCXr;
97 return AArch64::SBCWr;
99 return AArch64::ADCXr;
100 case AArch64::ADCSWr:
101 return AArch64::ADCWr;
106 bool Changed =
false;
108 Changed |= foldSimpleCrossClassCopies(
MI);
113bool AArch64PostSelectOptimize::foldSimpleCrossClassCopies(
MachineInstr &
MI) {
114 auto *MF =
MI.getMF();
115 auto &
MRI = MF->getRegInfo();
120 if (
MI.getOperand(1).getSubReg())
126 if (Src.isPhysical() || Dst.isPhysical())
141 if (!
MRI.hasOneNonDBGUse(Src))
146 if (!
MRI.constrainRegClass(Src, DstRC, 25))
156 MRI.replaceRegWith(Dst, Src);
157 MI.eraseFromParent();
189 bool Changed =
false;
192 const auto &
TII = Subtarget.getInstrInfo();
193 auto TRI = Subtarget.getRegisterInfo();
194 auto RBI = Subtarget.getRegBankInfo();
195 auto &
MRI = MF.getRegInfo();
198 LRU.addLiveOuts(
MBB);
201 bool NZCVDead = LRU.available(AArch64::NZCV);
202 if (NZCVDead && II.definesRegister(AArch64::NZCV)) {
205 int DeadNZCVIdx = II.findRegisterDefOperandIdx(AArch64::NZCV);
206 if (DeadNZCVIdx != -1) {
209 LLVM_DEBUG(
dbgs() <<
"Post-select optimizer: converting flag-setting "
212 II.setDesc(
TII->get(NewOpc));
213 II.removeOperand(DeadNZCVIdx);
218 II.getOperand(0), 0);
223 II.getOperand(DeadNZCVIdx).setIsDead();
227 LRU.stepBackward(II);
232bool AArch64PostSelectOptimize::runOnMachineFunction(
MachineFunction &MF) {
234 MachineFunctionProperties::Property::FailedISel))
237 MachineFunctionProperties::Property::Selected) &&
238 "Expected a selected MF");
240 bool Changed =
false;
241 for (
auto &BB : MF) {
242 Changed |= optimizeNZCVDefs(BB);
243 Changed |= doPeepholeOpts(BB);
248char AArch64PostSelectOptimize::ID = 0;
250 "Optimize AArch64 selected instructions",
258 return new AArch64PostSelectOptimize();
unsigned const MachineRegisterInfo * MRI
unsigned getNonFlagSettingVariant(unsigned Opc)
Optimize AArch64 selected instructions
const HexagonInstrInfo * TII
unsigned const TargetRegisterInfo * TRI
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Target-Independent Code Generator Pass Configuration Options pass.
Represent the analysis usage information of a pass.
AnalysisUsage & addRequired()
void setPreservesCFG()
This function should be called by the pass, iff they do not:
FunctionPass class - This class is used to implement most global optimizations.
A set of register units used to track register liveness.
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
reverse_iterator rbegin()
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...
bool hasProperty(Property P) const
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
const MachineFunctionProperties & getProperties() const
Get the function properties.
Representation of each machine instruction.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
virtual StringRef getPassName() const
getPassName - Return a nice clean name for a pass.
Wrapper class representing virtual and physical registers.
StringRef - Represent a constant reference to a string, i.e.
Target-Independent Code Generator Pass Configuration Options.
bool hasSubClass(const TargetRegisterClass *RC) const
Return true if the specified TargetRegisterClass is a proper sub-class of this TargetRegisterClass.
virtual const TargetRegisterInfo * getRegisterInfo() const
getRegisterInfo - If register information is available, return it.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
This is an optimization pass for GlobalISel generic memory operations.
FunctionPass * createAArch64PostSelectOptimize()
Register constrainOperandRegClass(const MachineFunction &MF, const TargetRegisterInfo &TRI, MachineRegisterInfo &MRI, const TargetInstrInfo &TII, const RegisterBankInfo &RBI, MachineInstr &InsertPt, const TargetRegisterClass &RegClass, MachineOperand &RegMO)
Constrain the Register operand OpIdx, so that it is now constrained to the TargetRegisterClass passed...
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
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...
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
auto instructionsWithoutDebug(IterT It, IterT End, bool SkipPseudoOp=true)
Construct a range iterator which begins at It and moves forwards until End is reached,...
void getSelectionDAGFallbackAnalysisUsage(AnalysisUsage &AU)
Modify analysis usage so it preserves passes required for the SelectionDAG fallback.
void initializeAArch64PostSelectOptimizePass(PassRegistry &)