58 #define DEBUG_TYPE "hexagon-peephole" 62 cl::desc(
"Disable Peephole Optimization"));
66 cl::desc(
"Disable Optimization of PNotP"));
70 cl::desc(
"Disable Optimization of Sign/Zero Extends"));
74 cl::desc(
"Disable Optimization of extensions to i64."));
96 return "Hexagon optimize redundant zero and size extends";
111 if (skipFunction(MF.getFunction()))
114 QII =
static_cast<const HexagonInstrInfo *
>(MF.getSubtarget().getInstrInfo());
116 MRI = &MF.getRegInfo();
125 MBBb != MBBe; ++MBBb) {
128 PeepholeDoubleRegsMap.
clear();
131 for (
auto I = MBB->
begin(),
E = MBB->
end(), NextI =
I;
I !=
E;
I = NextI) {
132 NextI = std::next(
I);
140 unsigned DstReg = Dst.
getReg();
141 unsigned SrcReg = Src.
getReg();
148 PeepholeMap[DstReg] = SrcReg;
161 unsigned DstReg = Dst.
getReg();
162 unsigned SrcReg = Src2.
getReg();
163 PeepholeMap[DstReg] = SrcReg;
171 if (MI.
getOpcode() == Hexagon::S2_lsr_i_p) {
178 unsigned DstReg = Dst.
getReg();
179 unsigned SrcReg = Src1.
getReg();
180 PeepholeDoubleRegsMap[DstReg] =
181 std::make_pair(*&SrcReg, Hexagon::isub_hi);
189 unsigned DstReg = Dst.
getReg();
190 unsigned SrcReg = Src.
getReg();
197 PeepholeMap[DstReg] = SrcReg;
212 unsigned DstReg = Dst.
getReg();
213 unsigned SrcReg = Src.
getReg();
217 if (
unsigned PeepholeSrc = PeepholeMap.
lookup(SrcReg)) {
223 PeepholeDoubleRegsMap.
find(SrcReg);
224 if (DI != PeepholeDoubleRegsMap.
end()) {
225 std::pair<unsigned,unsigned> PeepholeSrc = DI->second;
228 PeepholeSrc.first,
false ,
false ,
229 false ,
false ,
false ,
230 false , PeepholeSrc.second));
239 if (QII->isPredicated(MI)) {
241 unsigned Reg0 = Op0.
getReg();
243 if (RC0->
getID() == Hexagon::PredRegsRegClassID) {
248 if (
unsigned PeepholeSrc = PeepholeMap.
lookup(Reg0)) {
251 MRI->clearKillFlags(PeepholeSrc);
252 int NewOp = QII->getInvertedPredicatedOpcode(MI.
getOpcode());
264 unsigned PR = 1, S1 = 2, S2 = 3;
267 case Hexagon::C2_mux:
268 case Hexagon::C2_muxii:
271 case Hexagon::C2_muxri:
272 NewOp = Hexagon::C2_muxir;
274 case Hexagon::C2_muxir:
275 NewOp = Hexagon::C2_muxri;
280 if (
unsigned POrig = PeepholeMap.
lookup(PSrc)) {
286 MRI->clearKillFlags(POrig);
300 return new HexagonPeephole();
const MachineInstrBuilder & add(const MachineOperand &MO) const
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
This class represents lattice values for constants.
const DebugLoc & getDebugLoc() const
Returns the debug location id of this MachineInstr.
unsigned getReg() const
getReg - Returns the register number.
static bool isVirtualRegister(unsigned Reg)
Return true if the specified register number is in the virtual register namespace.
unsigned getSubReg() const
static MachineOperand CreateReg(unsigned 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)
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
unsigned getNumOperands() const
Retuns the total number of operands.
void eraseFromParent()
Unlink 'this' from the containing basic block and delete it.
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
INITIALIZE_PASS(HexagonPeephole, "hexagon-peephole", "Hexagon Peephole", false, false) bool HexagonPeephole
static cl::opt< bool > DisablePNotP("disable-hexagon-pnotp", cl::Hidden, cl::ZeroOrMore, cl::init(false), cl::desc("Disable Optimization of PNotP"))
unsigned getID() const
Return the register class ID number.
static cl::opt< bool > DisableOptSZExt("disable-hexagon-optszext", cl::Hidden, cl::ZeroOrMore, cl::init(true), cl::desc("Disable Optimization of Sign/Zero Extends"))
iterator find(const_arg_type_t< KeyT > Val)
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata *> MDs)
initializer< Ty > init(const Ty &Val)
unsigned const MachineRegisterInfo * MRI
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Represent the analysis usage information of a pass.
FunctionPass class - This class is used to implement most global optimizations.
self_iterator getIterator()
void initializeHexagonPeepholePass(PassRegistry &)
Iterator for intrusive lists based on ilist_node.
void setDesc(const MCInstrDesc &tid)
Replace the instruction descriptor (thus opcode) of the current instruction with a new one...
void addOperand(MachineFunction &MF, const MachineOperand &Op)
Add the specified operand to the instruction.
MachineOperand class - Representation of each machine instruction operand.
FunctionPass * createHexagonPeephole()
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
Representation of each machine instruction.
static cl::opt< bool > DisableHexagonPeephole("disable-hexagon-peephole", cl::Hidden, cl::ZeroOrMore, cl::init(false), cl::desc("Disable Peephole Optimization"))
void setReg(unsigned Reg)
Change the register this operand corresponds to.
ValueT lookup(const_arg_type_t< KeyT > Val) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static cl::opt< bool > DisableOptExtTo64("disable-hexagon-opt-ext-to-64", cl::Hidden, cl::ZeroOrMore, cl::init(true), cl::desc("Disable Optimization of extensions to i64."))
StringRef - Represent a constant reference to a string, i.e.
PassRegistry - This class manages the registration and intitialization of the pass subsystem as appli...
void RemoveOperand(unsigned OpNo)
Erase an operand from an instruction, leaving it with one fewer operand than it started with...
const MachineOperand & getOperand(unsigned i) const