53#define DEBUG_TYPE "hexagon-peephole"
57 cl::desc(
"Disable Peephole Optimization"));
60 cl::desc(
"Disable Optimization of PNotP"));
64 cl::desc(
"Disable Optimization of Sign/Zero Extends"));
69 cl::desc(
"Disable Optimization of extensions to i64."));
81 bool runOnMachineFunction(MachineFunction &MF)
override;
83 StringRef getPassName()
const override {
84 return "Hexagon optimize redundant zero and size extends";
87 void getAnalysisUsage(AnalysisUsage &AU)
const override {
93char HexagonPeephole::ID = 0;
99 if (skipFunction(MF.getFunction()))
102 QII =
static_cast<const HexagonInstrInfo *
>(MF.getSubtarget().getInstrInfo());
104 MRI = &MF.getRegInfo();
107 DenseMap<
unsigned, std::pair<unsigned, unsigned> > PeepholeDoubleRegsMap;
114 PeepholeDoubleRegsMap.clear();
131 PeepholeMap[DstReg] = SrcReg;
146 PeepholeMap[DstReg] = SrcReg;
154 if (
MI.getOpcode() == Hexagon::S2_lsr_i_p) {
163 PeepholeDoubleRegsMap[DstReg] =
164 std::make_pair(*&SrcReg, Hexagon::isub_hi);
179 PeepholeMap[DstReg] = SrcReg;
191 if (Src.getSubReg() != Hexagon::isub_lo)
198 if (
unsigned PeepholeSrc = PeepholeMap.lookup(SrcReg)) {
204 PeepholeDoubleRegsMap.find(SrcReg);
205 if (DI != PeepholeDoubleRegsMap.
end()) {
206 std::pair<unsigned,unsigned> PeepholeSrc = DI->second;
209 PeepholeSrc.first,
false ,
false ,
210 false ,
false ,
false ,
211 false , PeepholeSrc.second));
220 if (QII->isPredicated(
MI)) {
224 if (RC0->
getID() == Hexagon::PredRegsRegClassID) {
229 if (
unsigned PeepholeSrc = PeepholeMap.lookup(Reg0)) {
231 MI.getOperand(0).setReg(PeepholeSrc);
232 MRI->clearKillFlags(PeepholeSrc);
233 int NewOp = QII->getInvertedPredicatedOpcode(
MI.getOpcode());
234 MI.setDesc(QII->get(NewOp));
243 unsigned Op =
MI.getOpcode();
245 unsigned PR = 1,
S1 = 2, S2 = 3;
248 case Hexagon::C2_mux:
249 case Hexagon::C2_muxii:
252 case Hexagon::C2_muxri:
253 NewOp = Hexagon::C2_muxir;
255 case Hexagon::C2_muxir:
256 NewOp = Hexagon::C2_muxri;
261 if (
unsigned POrig = PeepholeMap.lookup(PSrc)) {
263 MI.getOperand(0).getReg())
265 .
add(
MI.getOperand(S2))
267 MRI->clearKillFlags(POrig);
268 MI.eraseFromParent();
281 return new HexagonPeephole();
unsigned const MachineRegisterInfo * MRI
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file defines the DenseMap class.
static cl::opt< bool > DisableOptExtTo64("disable-hexagon-opt-ext-to-64", cl::Hidden, cl::init(true), cl::desc("Disable Optimization of extensions to i64."))
static cl::opt< bool > DisableHexagonPeephole("disable-hexagon-peephole", cl::Hidden, cl::desc("Disable Peephole Optimization"))
static cl::opt< bool > DisablePNotP("disable-hexagon-pnotp", cl::Hidden, cl::desc("Disable Optimization of PNotP"))
static cl::opt< bool > DisableOptSZExt("disable-hexagon-optszext", cl::Hidden, cl::init(true), cl::desc("Disable Optimization of Sign/Zero Extends"))
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
FunctionPass class - This class is used to implement most global optimizations.
const HexagonRegisterInfo * getRegisterInfo() const override
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.
const MachineInstrBuilder & add(const MachineOperand &MO) const
const MachineInstrBuilder & addReg(Register RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
Representation of each machine instruction.
MachineOperand class - Representation of each machine instruction operand.
Register getReg() const
getReg - Returns the register number.
static MachineOperand CreateReg(Register Reg, bool isDef, bool isImp=false, bool isKill=false, bool isDead=false, bool isUndef=false, bool isEarlyClobber=false, unsigned SubReg=0, bool isDebug=false, bool isInternalRead=false, bool isRenamable=false)
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
Wrapper class representing virtual and physical registers.
constexpr bool isVirtual() const
Return true if the specified register number is in the virtual register namespace.
unsigned getID() const
Return the register class ID number.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
initializer< Ty > init(const Ty &Val)
This is an optimization pass for GlobalISel generic memory operations.
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
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...
FunctionPass * createHexagonPeephole()
DWARFExpression::Operation Op