1*9880d681SAndroid Build Coastguard Worker //===-- X86InstrInfo.h - X86 Instruction Information ------------*- C++ -*-===//
2*9880d681SAndroid Build Coastguard Worker //
3*9880d681SAndroid Build Coastguard Worker // The LLVM Compiler Infrastructure
4*9880d681SAndroid Build Coastguard Worker //
5*9880d681SAndroid Build Coastguard Worker // This file is distributed under the University of Illinois Open Source
6*9880d681SAndroid Build Coastguard Worker // License. See LICENSE.TXT for details.
7*9880d681SAndroid Build Coastguard Worker //
8*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===//
9*9880d681SAndroid Build Coastguard Worker //
10*9880d681SAndroid Build Coastguard Worker // This file contains the X86 implementation of the TargetInstrInfo class.
11*9880d681SAndroid Build Coastguard Worker //
12*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===//
13*9880d681SAndroid Build Coastguard Worker
14*9880d681SAndroid Build Coastguard Worker #ifndef LLVM_LIB_TARGET_X86_X86INSTRINFO_H
15*9880d681SAndroid Build Coastguard Worker #define LLVM_LIB_TARGET_X86_X86INSTRINFO_H
16*9880d681SAndroid Build Coastguard Worker
17*9880d681SAndroid Build Coastguard Worker #include "MCTargetDesc/X86BaseInfo.h"
18*9880d681SAndroid Build Coastguard Worker #include "X86RegisterInfo.h"
19*9880d681SAndroid Build Coastguard Worker #include "llvm/ADT/DenseMap.h"
20*9880d681SAndroid Build Coastguard Worker #include "llvm/Target/TargetInstrInfo.h"
21*9880d681SAndroid Build Coastguard Worker
22*9880d681SAndroid Build Coastguard Worker #define GET_INSTRINFO_HEADER
23*9880d681SAndroid Build Coastguard Worker #include "X86GenInstrInfo.inc"
24*9880d681SAndroid Build Coastguard Worker
25*9880d681SAndroid Build Coastguard Worker namespace llvm {
26*9880d681SAndroid Build Coastguard Worker class MachineInstrBuilder;
27*9880d681SAndroid Build Coastguard Worker class X86RegisterInfo;
28*9880d681SAndroid Build Coastguard Worker class X86Subtarget;
29*9880d681SAndroid Build Coastguard Worker
30*9880d681SAndroid Build Coastguard Worker namespace X86 {
31*9880d681SAndroid Build Coastguard Worker // X86 specific condition code. These correspond to X86_*_COND in
32*9880d681SAndroid Build Coastguard Worker // X86InstrInfo.td. They must be kept in synch.
33*9880d681SAndroid Build Coastguard Worker enum CondCode {
34*9880d681SAndroid Build Coastguard Worker COND_A = 0,
35*9880d681SAndroid Build Coastguard Worker COND_AE = 1,
36*9880d681SAndroid Build Coastguard Worker COND_B = 2,
37*9880d681SAndroid Build Coastguard Worker COND_BE = 3,
38*9880d681SAndroid Build Coastguard Worker COND_E = 4,
39*9880d681SAndroid Build Coastguard Worker COND_G = 5,
40*9880d681SAndroid Build Coastguard Worker COND_GE = 6,
41*9880d681SAndroid Build Coastguard Worker COND_L = 7,
42*9880d681SAndroid Build Coastguard Worker COND_LE = 8,
43*9880d681SAndroid Build Coastguard Worker COND_NE = 9,
44*9880d681SAndroid Build Coastguard Worker COND_NO = 10,
45*9880d681SAndroid Build Coastguard Worker COND_NP = 11,
46*9880d681SAndroid Build Coastguard Worker COND_NS = 12,
47*9880d681SAndroid Build Coastguard Worker COND_O = 13,
48*9880d681SAndroid Build Coastguard Worker COND_P = 14,
49*9880d681SAndroid Build Coastguard Worker COND_S = 15,
50*9880d681SAndroid Build Coastguard Worker LAST_VALID_COND = COND_S,
51*9880d681SAndroid Build Coastguard Worker
52*9880d681SAndroid Build Coastguard Worker // Artificial condition codes. These are used by AnalyzeBranch
53*9880d681SAndroid Build Coastguard Worker // to indicate a block terminated with two conditional branches that together
54*9880d681SAndroid Build Coastguard Worker // form a compound condition. They occur in code using FCMP_OEQ or FCMP_UNE,
55*9880d681SAndroid Build Coastguard Worker // which can't be represented on x86 with a single condition. These
56*9880d681SAndroid Build Coastguard Worker // are never used in MachineInstrs and are inverses of one another.
57*9880d681SAndroid Build Coastguard Worker COND_NE_OR_P,
58*9880d681SAndroid Build Coastguard Worker COND_E_AND_NP,
59*9880d681SAndroid Build Coastguard Worker
60*9880d681SAndroid Build Coastguard Worker COND_INVALID
61*9880d681SAndroid Build Coastguard Worker };
62*9880d681SAndroid Build Coastguard Worker
63*9880d681SAndroid Build Coastguard Worker // Turn condition code into conditional branch opcode.
64*9880d681SAndroid Build Coastguard Worker unsigned GetCondBranchFromCond(CondCode CC);
65*9880d681SAndroid Build Coastguard Worker
66*9880d681SAndroid Build Coastguard Worker /// \brief Return a set opcode for the given condition and whether it has
67*9880d681SAndroid Build Coastguard Worker /// a memory operand.
68*9880d681SAndroid Build Coastguard Worker unsigned getSETFromCond(CondCode CC, bool HasMemoryOperand = false);
69*9880d681SAndroid Build Coastguard Worker
70*9880d681SAndroid Build Coastguard Worker /// \brief Return a cmov opcode for the given condition, register size in
71*9880d681SAndroid Build Coastguard Worker /// bytes, and operand type.
72*9880d681SAndroid Build Coastguard Worker unsigned getCMovFromCond(CondCode CC, unsigned RegBytes,
73*9880d681SAndroid Build Coastguard Worker bool HasMemoryOperand = false);
74*9880d681SAndroid Build Coastguard Worker
75*9880d681SAndroid Build Coastguard Worker // Turn CMov opcode into condition code.
76*9880d681SAndroid Build Coastguard Worker CondCode getCondFromCMovOpc(unsigned Opc);
77*9880d681SAndroid Build Coastguard Worker
78*9880d681SAndroid Build Coastguard Worker /// GetOppositeBranchCondition - Return the inverse of the specified cond,
79*9880d681SAndroid Build Coastguard Worker /// e.g. turning COND_E to COND_NE.
80*9880d681SAndroid Build Coastguard Worker CondCode GetOppositeBranchCondition(CondCode CC);
81*9880d681SAndroid Build Coastguard Worker } // end namespace X86;
82*9880d681SAndroid Build Coastguard Worker
83*9880d681SAndroid Build Coastguard Worker
84*9880d681SAndroid Build Coastguard Worker /// isGlobalStubReference - Return true if the specified TargetFlag operand is
85*9880d681SAndroid Build Coastguard Worker /// a reference to a stub for a global, not the global itself.
isGlobalStubReference(unsigned char TargetFlag)86*9880d681SAndroid Build Coastguard Worker inline static bool isGlobalStubReference(unsigned char TargetFlag) {
87*9880d681SAndroid Build Coastguard Worker switch (TargetFlag) {
88*9880d681SAndroid Build Coastguard Worker case X86II::MO_DLLIMPORT: // dllimport stub.
89*9880d681SAndroid Build Coastguard Worker case X86II::MO_GOTPCREL: // rip-relative GOT reference.
90*9880d681SAndroid Build Coastguard Worker case X86II::MO_GOT: // normal GOT reference.
91*9880d681SAndroid Build Coastguard Worker case X86II::MO_DARWIN_NONLAZY_PIC_BASE: // Normal $non_lazy_ptr ref.
92*9880d681SAndroid Build Coastguard Worker case X86II::MO_DARWIN_NONLAZY: // Normal $non_lazy_ptr ref.
93*9880d681SAndroid Build Coastguard Worker return true;
94*9880d681SAndroid Build Coastguard Worker default:
95*9880d681SAndroid Build Coastguard Worker return false;
96*9880d681SAndroid Build Coastguard Worker }
97*9880d681SAndroid Build Coastguard Worker }
98*9880d681SAndroid Build Coastguard Worker
99*9880d681SAndroid Build Coastguard Worker /// isGlobalRelativeToPICBase - Return true if the specified global value
100*9880d681SAndroid Build Coastguard Worker /// reference is relative to a 32-bit PIC base (X86ISD::GlobalBaseReg). If this
101*9880d681SAndroid Build Coastguard Worker /// is true, the addressing mode has the PIC base register added in (e.g. EBX).
isGlobalRelativeToPICBase(unsigned char TargetFlag)102*9880d681SAndroid Build Coastguard Worker inline static bool isGlobalRelativeToPICBase(unsigned char TargetFlag) {
103*9880d681SAndroid Build Coastguard Worker switch (TargetFlag) {
104*9880d681SAndroid Build Coastguard Worker case X86II::MO_GOTOFF: // isPICStyleGOT: local global.
105*9880d681SAndroid Build Coastguard Worker case X86II::MO_GOT: // isPICStyleGOT: other global.
106*9880d681SAndroid Build Coastguard Worker case X86II::MO_PIC_BASE_OFFSET: // Darwin local global.
107*9880d681SAndroid Build Coastguard Worker case X86II::MO_DARWIN_NONLAZY_PIC_BASE: // Darwin/32 external global.
108*9880d681SAndroid Build Coastguard Worker case X86II::MO_TLVP: // ??? Pretty sure..
109*9880d681SAndroid Build Coastguard Worker return true;
110*9880d681SAndroid Build Coastguard Worker default:
111*9880d681SAndroid Build Coastguard Worker return false;
112*9880d681SAndroid Build Coastguard Worker }
113*9880d681SAndroid Build Coastguard Worker }
114*9880d681SAndroid Build Coastguard Worker
isScale(const MachineOperand & MO)115*9880d681SAndroid Build Coastguard Worker inline static bool isScale(const MachineOperand &MO) {
116*9880d681SAndroid Build Coastguard Worker return MO.isImm() &&
117*9880d681SAndroid Build Coastguard Worker (MO.getImm() == 1 || MO.getImm() == 2 ||
118*9880d681SAndroid Build Coastguard Worker MO.getImm() == 4 || MO.getImm() == 8);
119*9880d681SAndroid Build Coastguard Worker }
120*9880d681SAndroid Build Coastguard Worker
isLeaMem(const MachineInstr & MI,unsigned Op)121*9880d681SAndroid Build Coastguard Worker inline static bool isLeaMem(const MachineInstr &MI, unsigned Op) {
122*9880d681SAndroid Build Coastguard Worker if (MI.getOperand(Op).isFI())
123*9880d681SAndroid Build Coastguard Worker return true;
124*9880d681SAndroid Build Coastguard Worker return Op + X86::AddrSegmentReg <= MI.getNumOperands() &&
125*9880d681SAndroid Build Coastguard Worker MI.getOperand(Op + X86::AddrBaseReg).isReg() &&
126*9880d681SAndroid Build Coastguard Worker isScale(MI.getOperand(Op + X86::AddrScaleAmt)) &&
127*9880d681SAndroid Build Coastguard Worker MI.getOperand(Op + X86::AddrIndexReg).isReg() &&
128*9880d681SAndroid Build Coastguard Worker (MI.getOperand(Op + X86::AddrDisp).isImm() ||
129*9880d681SAndroid Build Coastguard Worker MI.getOperand(Op + X86::AddrDisp).isGlobal() ||
130*9880d681SAndroid Build Coastguard Worker MI.getOperand(Op + X86::AddrDisp).isCPI() ||
131*9880d681SAndroid Build Coastguard Worker MI.getOperand(Op + X86::AddrDisp).isJTI());
132*9880d681SAndroid Build Coastguard Worker }
133*9880d681SAndroid Build Coastguard Worker
isMem(const MachineInstr & MI,unsigned Op)134*9880d681SAndroid Build Coastguard Worker inline static bool isMem(const MachineInstr &MI, unsigned Op) {
135*9880d681SAndroid Build Coastguard Worker if (MI.getOperand(Op).isFI())
136*9880d681SAndroid Build Coastguard Worker return true;
137*9880d681SAndroid Build Coastguard Worker return Op + X86::AddrNumOperands <= MI.getNumOperands() &&
138*9880d681SAndroid Build Coastguard Worker MI.getOperand(Op + X86::AddrSegmentReg).isReg() && isLeaMem(MI, Op);
139*9880d681SAndroid Build Coastguard Worker }
140*9880d681SAndroid Build Coastguard Worker
141*9880d681SAndroid Build Coastguard Worker class X86InstrInfo final : public X86GenInstrInfo {
142*9880d681SAndroid Build Coastguard Worker X86Subtarget &Subtarget;
143*9880d681SAndroid Build Coastguard Worker const X86RegisterInfo RI;
144*9880d681SAndroid Build Coastguard Worker
145*9880d681SAndroid Build Coastguard Worker /// RegOp2MemOpTable3Addr, RegOp2MemOpTable0, RegOp2MemOpTable1,
146*9880d681SAndroid Build Coastguard Worker /// RegOp2MemOpTable2, RegOp2MemOpTable3 - Load / store folding opcode maps.
147*9880d681SAndroid Build Coastguard Worker ///
148*9880d681SAndroid Build Coastguard Worker typedef DenseMap<unsigned,
149*9880d681SAndroid Build Coastguard Worker std::pair<uint16_t, uint16_t> > RegOp2MemOpTableType;
150*9880d681SAndroid Build Coastguard Worker RegOp2MemOpTableType RegOp2MemOpTable2Addr;
151*9880d681SAndroid Build Coastguard Worker RegOp2MemOpTableType RegOp2MemOpTable0;
152*9880d681SAndroid Build Coastguard Worker RegOp2MemOpTableType RegOp2MemOpTable1;
153*9880d681SAndroid Build Coastguard Worker RegOp2MemOpTableType RegOp2MemOpTable2;
154*9880d681SAndroid Build Coastguard Worker RegOp2MemOpTableType RegOp2MemOpTable3;
155*9880d681SAndroid Build Coastguard Worker RegOp2MemOpTableType RegOp2MemOpTable4;
156*9880d681SAndroid Build Coastguard Worker
157*9880d681SAndroid Build Coastguard Worker /// MemOp2RegOpTable - Load / store unfolding opcode map.
158*9880d681SAndroid Build Coastguard Worker ///
159*9880d681SAndroid Build Coastguard Worker typedef DenseMap<unsigned,
160*9880d681SAndroid Build Coastguard Worker std::pair<uint16_t, uint16_t> > MemOp2RegOpTableType;
161*9880d681SAndroid Build Coastguard Worker MemOp2RegOpTableType MemOp2RegOpTable;
162*9880d681SAndroid Build Coastguard Worker
163*9880d681SAndroid Build Coastguard Worker static void AddTableEntry(RegOp2MemOpTableType &R2MTable,
164*9880d681SAndroid Build Coastguard Worker MemOp2RegOpTableType &M2RTable,
165*9880d681SAndroid Build Coastguard Worker uint16_t RegOp, uint16_t MemOp, uint16_t Flags);
166*9880d681SAndroid Build Coastguard Worker
167*9880d681SAndroid Build Coastguard Worker virtual void anchor();
168*9880d681SAndroid Build Coastguard Worker
169*9880d681SAndroid Build Coastguard Worker bool AnalyzeBranchImpl(MachineBasicBlock &MBB, MachineBasicBlock *&TBB,
170*9880d681SAndroid Build Coastguard Worker MachineBasicBlock *&FBB,
171*9880d681SAndroid Build Coastguard Worker SmallVectorImpl<MachineOperand> &Cond,
172*9880d681SAndroid Build Coastguard Worker SmallVectorImpl<MachineInstr *> &CondBranches,
173*9880d681SAndroid Build Coastguard Worker bool AllowModify) const;
174*9880d681SAndroid Build Coastguard Worker
175*9880d681SAndroid Build Coastguard Worker public:
176*9880d681SAndroid Build Coastguard Worker explicit X86InstrInfo(X86Subtarget &STI);
177*9880d681SAndroid Build Coastguard Worker
178*9880d681SAndroid Build Coastguard Worker /// getRegisterInfo - TargetInstrInfo is a superset of MRegister info. As
179*9880d681SAndroid Build Coastguard Worker /// such, whenever a client has an instance of instruction info, it should
180*9880d681SAndroid Build Coastguard Worker /// always be able to get register info as well (through this method).
181*9880d681SAndroid Build Coastguard Worker ///
getRegisterInfo()182*9880d681SAndroid Build Coastguard Worker const X86RegisterInfo &getRegisterInfo() const { return RI; }
183*9880d681SAndroid Build Coastguard Worker
184*9880d681SAndroid Build Coastguard Worker /// getSPAdjust - This returns the stack pointer adjustment made by
185*9880d681SAndroid Build Coastguard Worker /// this instruction. For x86, we need to handle more complex call
186*9880d681SAndroid Build Coastguard Worker /// sequences involving PUSHes.
187*9880d681SAndroid Build Coastguard Worker int getSPAdjust(const MachineInstr &MI) const override;
188*9880d681SAndroid Build Coastguard Worker
189*9880d681SAndroid Build Coastguard Worker /// isCoalescableExtInstr - Return true if the instruction is a "coalescable"
190*9880d681SAndroid Build Coastguard Worker /// extension instruction. That is, it's like a copy where it's legal for the
191*9880d681SAndroid Build Coastguard Worker /// source to overlap the destination. e.g. X86::MOVSX64rr32. If this returns
192*9880d681SAndroid Build Coastguard Worker /// true, then it's expected the pre-extension value is available as a subreg
193*9880d681SAndroid Build Coastguard Worker /// of the result register. This also returns the sub-register index in
194*9880d681SAndroid Build Coastguard Worker /// SubIdx.
195*9880d681SAndroid Build Coastguard Worker bool isCoalescableExtInstr(const MachineInstr &MI,
196*9880d681SAndroid Build Coastguard Worker unsigned &SrcReg, unsigned &DstReg,
197*9880d681SAndroid Build Coastguard Worker unsigned &SubIdx) const override;
198*9880d681SAndroid Build Coastguard Worker
199*9880d681SAndroid Build Coastguard Worker unsigned isLoadFromStackSlot(const MachineInstr &MI,
200*9880d681SAndroid Build Coastguard Worker int &FrameIndex) const override;
201*9880d681SAndroid Build Coastguard Worker /// isLoadFromStackSlotPostFE - Check for post-frame ptr elimination
202*9880d681SAndroid Build Coastguard Worker /// stack locations as well. This uses a heuristic so it isn't
203*9880d681SAndroid Build Coastguard Worker /// reliable for correctness.
204*9880d681SAndroid Build Coastguard Worker unsigned isLoadFromStackSlotPostFE(const MachineInstr &MI,
205*9880d681SAndroid Build Coastguard Worker int &FrameIndex) const override;
206*9880d681SAndroid Build Coastguard Worker
207*9880d681SAndroid Build Coastguard Worker unsigned isStoreToStackSlot(const MachineInstr &MI,
208*9880d681SAndroid Build Coastguard Worker int &FrameIndex) const override;
209*9880d681SAndroid Build Coastguard Worker /// isStoreToStackSlotPostFE - Check for post-frame ptr elimination
210*9880d681SAndroid Build Coastguard Worker /// stack locations as well. This uses a heuristic so it isn't
211*9880d681SAndroid Build Coastguard Worker /// reliable for correctness.
212*9880d681SAndroid Build Coastguard Worker unsigned isStoreToStackSlotPostFE(const MachineInstr &MI,
213*9880d681SAndroid Build Coastguard Worker int &FrameIndex) const override;
214*9880d681SAndroid Build Coastguard Worker
215*9880d681SAndroid Build Coastguard Worker bool isReallyTriviallyReMaterializable(const MachineInstr &MI,
216*9880d681SAndroid Build Coastguard Worker AliasAnalysis *AA) const override;
217*9880d681SAndroid Build Coastguard Worker void reMaterialize(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI,
218*9880d681SAndroid Build Coastguard Worker unsigned DestReg, unsigned SubIdx,
219*9880d681SAndroid Build Coastguard Worker const MachineInstr &Orig,
220*9880d681SAndroid Build Coastguard Worker const TargetRegisterInfo &TRI) const override;
221*9880d681SAndroid Build Coastguard Worker
222*9880d681SAndroid Build Coastguard Worker /// Given an operand within a MachineInstr, insert preceding code to put it
223*9880d681SAndroid Build Coastguard Worker /// into the right format for a particular kind of LEA instruction. This may
224*9880d681SAndroid Build Coastguard Worker /// involve using an appropriate super-register instead (with an implicit use
225*9880d681SAndroid Build Coastguard Worker /// of the original) or creating a new virtual register and inserting COPY
226*9880d681SAndroid Build Coastguard Worker /// instructions to get the data into the right class.
227*9880d681SAndroid Build Coastguard Worker ///
228*9880d681SAndroid Build Coastguard Worker /// Reference parameters are set to indicate how caller should add this
229*9880d681SAndroid Build Coastguard Worker /// operand to the LEA instruction.
230*9880d681SAndroid Build Coastguard Worker bool classifyLEAReg(MachineInstr &MI, const MachineOperand &Src,
231*9880d681SAndroid Build Coastguard Worker unsigned LEAOpcode, bool AllowSP, unsigned &NewSrc,
232*9880d681SAndroid Build Coastguard Worker bool &isKill, bool &isUndef,
233*9880d681SAndroid Build Coastguard Worker MachineOperand &ImplicitOp) const;
234*9880d681SAndroid Build Coastguard Worker
235*9880d681SAndroid Build Coastguard Worker /// convertToThreeAddress - This method must be implemented by targets that
236*9880d681SAndroid Build Coastguard Worker /// set the M_CONVERTIBLE_TO_3_ADDR flag. When this flag is set, the target
237*9880d681SAndroid Build Coastguard Worker /// may be able to convert a two-address instruction into a true
238*9880d681SAndroid Build Coastguard Worker /// three-address instruction on demand. This allows the X86 target (for
239*9880d681SAndroid Build Coastguard Worker /// example) to convert ADD and SHL instructions into LEA instructions if they
240*9880d681SAndroid Build Coastguard Worker /// would require register copies due to two-addressness.
241*9880d681SAndroid Build Coastguard Worker ///
242*9880d681SAndroid Build Coastguard Worker /// This method returns a null pointer if the transformation cannot be
243*9880d681SAndroid Build Coastguard Worker /// performed, otherwise it returns the new instruction.
244*9880d681SAndroid Build Coastguard Worker ///
245*9880d681SAndroid Build Coastguard Worker MachineInstr *convertToThreeAddress(MachineFunction::iterator &MFI,
246*9880d681SAndroid Build Coastguard Worker MachineInstr &MI,
247*9880d681SAndroid Build Coastguard Worker LiveVariables *LV) const override;
248*9880d681SAndroid Build Coastguard Worker
249*9880d681SAndroid Build Coastguard Worker /// Returns true iff the routine could find two commutable operands in the
250*9880d681SAndroid Build Coastguard Worker /// given machine instruction.
251*9880d681SAndroid Build Coastguard Worker /// The 'SrcOpIdx1' and 'SrcOpIdx2' are INPUT and OUTPUT arguments. Their
252*9880d681SAndroid Build Coastguard Worker /// input values can be re-defined in this method only if the input values
253*9880d681SAndroid Build Coastguard Worker /// are not pre-defined, which is designated by the special value
254*9880d681SAndroid Build Coastguard Worker /// 'CommuteAnyOperandIndex' assigned to it.
255*9880d681SAndroid Build Coastguard Worker /// If both of indices are pre-defined and refer to some operands, then the
256*9880d681SAndroid Build Coastguard Worker /// method simply returns true if the corresponding operands are commutable
257*9880d681SAndroid Build Coastguard Worker /// and returns false otherwise.
258*9880d681SAndroid Build Coastguard Worker ///
259*9880d681SAndroid Build Coastguard Worker /// For example, calling this method this way:
260*9880d681SAndroid Build Coastguard Worker /// unsigned Op1 = 1, Op2 = CommuteAnyOperandIndex;
261*9880d681SAndroid Build Coastguard Worker /// findCommutedOpIndices(MI, Op1, Op2);
262*9880d681SAndroid Build Coastguard Worker /// can be interpreted as a query asking to find an operand that would be
263*9880d681SAndroid Build Coastguard Worker /// commutable with the operand#1.
264*9880d681SAndroid Build Coastguard Worker bool findCommutedOpIndices(MachineInstr &MI, unsigned &SrcOpIdx1,
265*9880d681SAndroid Build Coastguard Worker unsigned &SrcOpIdx2) const override;
266*9880d681SAndroid Build Coastguard Worker
267*9880d681SAndroid Build Coastguard Worker /// Returns true if the routine could find two commutable operands
268*9880d681SAndroid Build Coastguard Worker /// in the given FMA instruction. Otherwise, returns false.
269*9880d681SAndroid Build Coastguard Worker ///
270*9880d681SAndroid Build Coastguard Worker /// \p SrcOpIdx1 and \p SrcOpIdx2 are INPUT and OUTPUT arguments.
271*9880d681SAndroid Build Coastguard Worker /// The output indices of the commuted operands are returned in these
272*9880d681SAndroid Build Coastguard Worker /// arguments. Also, the input values of these arguments may be preset either
273*9880d681SAndroid Build Coastguard Worker /// to indices of operands that must be commuted or be equal to a special
274*9880d681SAndroid Build Coastguard Worker /// value 'CommuteAnyOperandIndex' which means that the corresponding
275*9880d681SAndroid Build Coastguard Worker /// operand index is not set and this method is free to pick any of
276*9880d681SAndroid Build Coastguard Worker /// available commutable operands.
277*9880d681SAndroid Build Coastguard Worker ///
278*9880d681SAndroid Build Coastguard Worker /// For example, calling this method this way:
279*9880d681SAndroid Build Coastguard Worker /// unsigned Idx1 = 1, Idx2 = CommuteAnyOperandIndex;
280*9880d681SAndroid Build Coastguard Worker /// findFMA3CommutedOpIndices(MI, Idx1, Idx2);
281*9880d681SAndroid Build Coastguard Worker /// can be interpreted as a query asking if the operand #1 can be swapped
282*9880d681SAndroid Build Coastguard Worker /// with any other available operand (e.g. operand #2, operand #3, etc.).
283*9880d681SAndroid Build Coastguard Worker ///
284*9880d681SAndroid Build Coastguard Worker /// The returned FMA opcode may differ from the opcode in the given MI.
285*9880d681SAndroid Build Coastguard Worker /// For example, commuting the operands #1 and #3 in the following FMA
286*9880d681SAndroid Build Coastguard Worker /// FMA213 #1, #2, #3
287*9880d681SAndroid Build Coastguard Worker /// results into instruction with adjusted opcode:
288*9880d681SAndroid Build Coastguard Worker /// FMA231 #3, #2, #1
289*9880d681SAndroid Build Coastguard Worker bool findFMA3CommutedOpIndices(MachineInstr &MI, unsigned &SrcOpIdx1,
290*9880d681SAndroid Build Coastguard Worker unsigned &SrcOpIdx2) const;
291*9880d681SAndroid Build Coastguard Worker
292*9880d681SAndroid Build Coastguard Worker /// Returns an adjusted FMA opcode that must be used in FMA instruction that
293*9880d681SAndroid Build Coastguard Worker /// performs the same computations as the given MI but which has the operands
294*9880d681SAndroid Build Coastguard Worker /// \p SrcOpIdx1 and \p SrcOpIdx2 commuted.
295*9880d681SAndroid Build Coastguard Worker /// It may return 0 if it is unsafe to commute the operands.
296*9880d681SAndroid Build Coastguard Worker ///
297*9880d681SAndroid Build Coastguard Worker /// The returned FMA opcode may differ from the opcode in the given \p MI.
298*9880d681SAndroid Build Coastguard Worker /// For example, commuting the operands #1 and #3 in the following FMA
299*9880d681SAndroid Build Coastguard Worker /// FMA213 #1, #2, #3
300*9880d681SAndroid Build Coastguard Worker /// results into instruction with adjusted opcode:
301*9880d681SAndroid Build Coastguard Worker /// FMA231 #3, #2, #1
302*9880d681SAndroid Build Coastguard Worker unsigned getFMA3OpcodeToCommuteOperands(MachineInstr &MI, unsigned SrcOpIdx1,
303*9880d681SAndroid Build Coastguard Worker unsigned SrcOpIdx2) const;
304*9880d681SAndroid Build Coastguard Worker
305*9880d681SAndroid Build Coastguard Worker // Branch analysis.
306*9880d681SAndroid Build Coastguard Worker bool isUnpredicatedTerminator(const MachineInstr &MI) const override;
307*9880d681SAndroid Build Coastguard Worker bool analyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB,
308*9880d681SAndroid Build Coastguard Worker MachineBasicBlock *&FBB,
309*9880d681SAndroid Build Coastguard Worker SmallVectorImpl<MachineOperand> &Cond,
310*9880d681SAndroid Build Coastguard Worker bool AllowModify) const override;
311*9880d681SAndroid Build Coastguard Worker
312*9880d681SAndroid Build Coastguard Worker bool getMemOpBaseRegImmOfs(MachineInstr &LdSt, unsigned &BaseReg,
313*9880d681SAndroid Build Coastguard Worker int64_t &Offset,
314*9880d681SAndroid Build Coastguard Worker const TargetRegisterInfo *TRI) const override;
315*9880d681SAndroid Build Coastguard Worker bool analyzeBranchPredicate(MachineBasicBlock &MBB,
316*9880d681SAndroid Build Coastguard Worker TargetInstrInfo::MachineBranchPredicate &MBP,
317*9880d681SAndroid Build Coastguard Worker bool AllowModify = false) const override;
318*9880d681SAndroid Build Coastguard Worker
319*9880d681SAndroid Build Coastguard Worker unsigned RemoveBranch(MachineBasicBlock &MBB) const override;
320*9880d681SAndroid Build Coastguard Worker unsigned InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB,
321*9880d681SAndroid Build Coastguard Worker MachineBasicBlock *FBB, ArrayRef<MachineOperand> Cond,
322*9880d681SAndroid Build Coastguard Worker const DebugLoc &DL) const override;
323*9880d681SAndroid Build Coastguard Worker bool canInsertSelect(const MachineBasicBlock&, ArrayRef<MachineOperand> Cond,
324*9880d681SAndroid Build Coastguard Worker unsigned, unsigned, int&, int&, int&) const override;
325*9880d681SAndroid Build Coastguard Worker void insertSelect(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI,
326*9880d681SAndroid Build Coastguard Worker const DebugLoc &DL, unsigned DstReg,
327*9880d681SAndroid Build Coastguard Worker ArrayRef<MachineOperand> Cond, unsigned TrueReg,
328*9880d681SAndroid Build Coastguard Worker unsigned FalseReg) const override;
329*9880d681SAndroid Build Coastguard Worker void copyPhysReg(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI,
330*9880d681SAndroid Build Coastguard Worker const DebugLoc &DL, unsigned DestReg, unsigned SrcReg,
331*9880d681SAndroid Build Coastguard Worker bool KillSrc) const override;
332*9880d681SAndroid Build Coastguard Worker void storeRegToStackSlot(MachineBasicBlock &MBB,
333*9880d681SAndroid Build Coastguard Worker MachineBasicBlock::iterator MI,
334*9880d681SAndroid Build Coastguard Worker unsigned SrcReg, bool isKill, int FrameIndex,
335*9880d681SAndroid Build Coastguard Worker const TargetRegisterClass *RC,
336*9880d681SAndroid Build Coastguard Worker const TargetRegisterInfo *TRI) const override;
337*9880d681SAndroid Build Coastguard Worker
338*9880d681SAndroid Build Coastguard Worker void storeRegToAddr(MachineFunction &MF, unsigned SrcReg, bool isKill,
339*9880d681SAndroid Build Coastguard Worker SmallVectorImpl<MachineOperand> &Addr,
340*9880d681SAndroid Build Coastguard Worker const TargetRegisterClass *RC,
341*9880d681SAndroid Build Coastguard Worker MachineInstr::mmo_iterator MMOBegin,
342*9880d681SAndroid Build Coastguard Worker MachineInstr::mmo_iterator MMOEnd,
343*9880d681SAndroid Build Coastguard Worker SmallVectorImpl<MachineInstr*> &NewMIs) const;
344*9880d681SAndroid Build Coastguard Worker
345*9880d681SAndroid Build Coastguard Worker void loadRegFromStackSlot(MachineBasicBlock &MBB,
346*9880d681SAndroid Build Coastguard Worker MachineBasicBlock::iterator MI,
347*9880d681SAndroid Build Coastguard Worker unsigned DestReg, int FrameIndex,
348*9880d681SAndroid Build Coastguard Worker const TargetRegisterClass *RC,
349*9880d681SAndroid Build Coastguard Worker const TargetRegisterInfo *TRI) const override;
350*9880d681SAndroid Build Coastguard Worker
351*9880d681SAndroid Build Coastguard Worker void loadRegFromAddr(MachineFunction &MF, unsigned DestReg,
352*9880d681SAndroid Build Coastguard Worker SmallVectorImpl<MachineOperand> &Addr,
353*9880d681SAndroid Build Coastguard Worker const TargetRegisterClass *RC,
354*9880d681SAndroid Build Coastguard Worker MachineInstr::mmo_iterator MMOBegin,
355*9880d681SAndroid Build Coastguard Worker MachineInstr::mmo_iterator MMOEnd,
356*9880d681SAndroid Build Coastguard Worker SmallVectorImpl<MachineInstr*> &NewMIs) const;
357*9880d681SAndroid Build Coastguard Worker
358*9880d681SAndroid Build Coastguard Worker bool expandPostRAPseudo(MachineInstr &MI) const override;
359*9880d681SAndroid Build Coastguard Worker
360*9880d681SAndroid Build Coastguard Worker /// foldMemoryOperand - If this target supports it, fold a load or store of
361*9880d681SAndroid Build Coastguard Worker /// the specified stack slot into the specified machine instruction for the
362*9880d681SAndroid Build Coastguard Worker /// specified operand(s). If this is possible, the target should perform the
363*9880d681SAndroid Build Coastguard Worker /// folding and return true, otherwise it should return false. If it folds
364*9880d681SAndroid Build Coastguard Worker /// the instruction, it is likely that the MachineInstruction the iterator
365*9880d681SAndroid Build Coastguard Worker /// references has been changed.
366*9880d681SAndroid Build Coastguard Worker MachineInstr *
367*9880d681SAndroid Build Coastguard Worker foldMemoryOperandImpl(MachineFunction &MF, MachineInstr &MI,
368*9880d681SAndroid Build Coastguard Worker ArrayRef<unsigned> Ops,
369*9880d681SAndroid Build Coastguard Worker MachineBasicBlock::iterator InsertPt, int FrameIndex,
370*9880d681SAndroid Build Coastguard Worker LiveIntervals *LIS = nullptr) const override;
371*9880d681SAndroid Build Coastguard Worker
372*9880d681SAndroid Build Coastguard Worker /// foldMemoryOperand - Same as the previous version except it allows folding
373*9880d681SAndroid Build Coastguard Worker /// of any load and store from / to any address, not just from a specific
374*9880d681SAndroid Build Coastguard Worker /// stack slot.
375*9880d681SAndroid Build Coastguard Worker MachineInstr *foldMemoryOperandImpl(
376*9880d681SAndroid Build Coastguard Worker MachineFunction &MF, MachineInstr &MI, ArrayRef<unsigned> Ops,
377*9880d681SAndroid Build Coastguard Worker MachineBasicBlock::iterator InsertPt, MachineInstr &LoadMI,
378*9880d681SAndroid Build Coastguard Worker LiveIntervals *LIS = nullptr) const override;
379*9880d681SAndroid Build Coastguard Worker
380*9880d681SAndroid Build Coastguard Worker /// unfoldMemoryOperand - Separate a single instruction which folded a load or
381*9880d681SAndroid Build Coastguard Worker /// a store or a load and a store into two or more instruction. If this is
382*9880d681SAndroid Build Coastguard Worker /// possible, returns true as well as the new instructions by reference.
383*9880d681SAndroid Build Coastguard Worker bool
384*9880d681SAndroid Build Coastguard Worker unfoldMemoryOperand(MachineFunction &MF, MachineInstr &MI, unsigned Reg,
385*9880d681SAndroid Build Coastguard Worker bool UnfoldLoad, bool UnfoldStore,
386*9880d681SAndroid Build Coastguard Worker SmallVectorImpl<MachineInstr *> &NewMIs) const override;
387*9880d681SAndroid Build Coastguard Worker
388*9880d681SAndroid Build Coastguard Worker bool unfoldMemoryOperand(SelectionDAG &DAG, SDNode *N,
389*9880d681SAndroid Build Coastguard Worker SmallVectorImpl<SDNode*> &NewNodes) const override;
390*9880d681SAndroid Build Coastguard Worker
391*9880d681SAndroid Build Coastguard Worker /// getOpcodeAfterMemoryUnfold - Returns the opcode of the would be new
392*9880d681SAndroid Build Coastguard Worker /// instruction after load / store are unfolded from an instruction of the
393*9880d681SAndroid Build Coastguard Worker /// specified opcode. It returns zero if the specified unfolding is not
394*9880d681SAndroid Build Coastguard Worker /// possible. If LoadRegIndex is non-null, it is filled in with the operand
395*9880d681SAndroid Build Coastguard Worker /// index of the operand which will hold the register holding the loaded
396*9880d681SAndroid Build Coastguard Worker /// value.
397*9880d681SAndroid Build Coastguard Worker unsigned getOpcodeAfterMemoryUnfold(unsigned Opc,
398*9880d681SAndroid Build Coastguard Worker bool UnfoldLoad, bool UnfoldStore,
399*9880d681SAndroid Build Coastguard Worker unsigned *LoadRegIndex = nullptr) const override;
400*9880d681SAndroid Build Coastguard Worker
401*9880d681SAndroid Build Coastguard Worker /// areLoadsFromSameBasePtr - This is used by the pre-regalloc scheduler
402*9880d681SAndroid Build Coastguard Worker /// to determine if two loads are loading from the same base address. It
403*9880d681SAndroid Build Coastguard Worker /// should only return true if the base pointers are the same and the
404*9880d681SAndroid Build Coastguard Worker /// only differences between the two addresses are the offset. It also returns
405*9880d681SAndroid Build Coastguard Worker /// the offsets by reference.
406*9880d681SAndroid Build Coastguard Worker bool areLoadsFromSameBasePtr(SDNode *Load1, SDNode *Load2, int64_t &Offset1,
407*9880d681SAndroid Build Coastguard Worker int64_t &Offset2) const override;
408*9880d681SAndroid Build Coastguard Worker
409*9880d681SAndroid Build Coastguard Worker /// shouldScheduleLoadsNear - This is a used by the pre-regalloc scheduler to
410*9880d681SAndroid Build Coastguard Worker /// determine (in conjunction with areLoadsFromSameBasePtr) if two loads should
411*9880d681SAndroid Build Coastguard Worker /// be scheduled togther. On some targets if two loads are loading from
412*9880d681SAndroid Build Coastguard Worker /// addresses in the same cache line, it's better if they are scheduled
413*9880d681SAndroid Build Coastguard Worker /// together. This function takes two integers that represent the load offsets
414*9880d681SAndroid Build Coastguard Worker /// from the common base address. It returns true if it decides it's desirable
415*9880d681SAndroid Build Coastguard Worker /// to schedule the two loads together. "NumLoads" is the number of loads that
416*9880d681SAndroid Build Coastguard Worker /// have already been scheduled after Load1.
417*9880d681SAndroid Build Coastguard Worker bool shouldScheduleLoadsNear(SDNode *Load1, SDNode *Load2,
418*9880d681SAndroid Build Coastguard Worker int64_t Offset1, int64_t Offset2,
419*9880d681SAndroid Build Coastguard Worker unsigned NumLoads) const override;
420*9880d681SAndroid Build Coastguard Worker
421*9880d681SAndroid Build Coastguard Worker bool shouldScheduleAdjacent(MachineInstr &First,
422*9880d681SAndroid Build Coastguard Worker MachineInstr &Second) const override;
423*9880d681SAndroid Build Coastguard Worker
424*9880d681SAndroid Build Coastguard Worker void getNoopForMachoTarget(MCInst &NopInst) const override;
425*9880d681SAndroid Build Coastguard Worker
426*9880d681SAndroid Build Coastguard Worker bool
427*9880d681SAndroid Build Coastguard Worker ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const override;
428*9880d681SAndroid Build Coastguard Worker
429*9880d681SAndroid Build Coastguard Worker /// isSafeToMoveRegClassDefs - Return true if it's safe to move a machine
430*9880d681SAndroid Build Coastguard Worker /// instruction that defines the specified register class.
431*9880d681SAndroid Build Coastguard Worker bool isSafeToMoveRegClassDefs(const TargetRegisterClass *RC) const override;
432*9880d681SAndroid Build Coastguard Worker
433*9880d681SAndroid Build Coastguard Worker /// isSafeToClobberEFLAGS - Return true if it's safe insert an instruction tha
434*9880d681SAndroid Build Coastguard Worker /// would clobber the EFLAGS condition register. Note the result may be
435*9880d681SAndroid Build Coastguard Worker /// conservative. If it cannot definitely determine the safety after visiting
436*9880d681SAndroid Build Coastguard Worker /// a few instructions in each direction it assumes it's not safe.
437*9880d681SAndroid Build Coastguard Worker bool isSafeToClobberEFLAGS(MachineBasicBlock &MBB,
438*9880d681SAndroid Build Coastguard Worker MachineBasicBlock::iterator I) const;
439*9880d681SAndroid Build Coastguard Worker
440*9880d681SAndroid Build Coastguard Worker /// True if MI has a condition code def, e.g. EFLAGS, that is
441*9880d681SAndroid Build Coastguard Worker /// not marked dead.
442*9880d681SAndroid Build Coastguard Worker bool hasLiveCondCodeDef(MachineInstr &MI) const;
443*9880d681SAndroid Build Coastguard Worker
444*9880d681SAndroid Build Coastguard Worker /// getGlobalBaseReg - Return a virtual register initialized with the
445*9880d681SAndroid Build Coastguard Worker /// the global base register value. Output instructions required to
446*9880d681SAndroid Build Coastguard Worker /// initialize the register in the function entry block, if necessary.
447*9880d681SAndroid Build Coastguard Worker ///
448*9880d681SAndroid Build Coastguard Worker unsigned getGlobalBaseReg(MachineFunction *MF) const;
449*9880d681SAndroid Build Coastguard Worker
450*9880d681SAndroid Build Coastguard Worker std::pair<uint16_t, uint16_t>
451*9880d681SAndroid Build Coastguard Worker getExecutionDomain(const MachineInstr &MI) const override;
452*9880d681SAndroid Build Coastguard Worker
453*9880d681SAndroid Build Coastguard Worker void setExecutionDomain(MachineInstr &MI, unsigned Domain) const override;
454*9880d681SAndroid Build Coastguard Worker
455*9880d681SAndroid Build Coastguard Worker unsigned
456*9880d681SAndroid Build Coastguard Worker getPartialRegUpdateClearance(const MachineInstr &MI, unsigned OpNum,
457*9880d681SAndroid Build Coastguard Worker const TargetRegisterInfo *TRI) const override;
458*9880d681SAndroid Build Coastguard Worker unsigned getUndefRegClearance(const MachineInstr &MI, unsigned &OpNum,
459*9880d681SAndroid Build Coastguard Worker const TargetRegisterInfo *TRI) const override;
460*9880d681SAndroid Build Coastguard Worker void breakPartialRegDependency(MachineInstr &MI, unsigned OpNum,
461*9880d681SAndroid Build Coastguard Worker const TargetRegisterInfo *TRI) const override;
462*9880d681SAndroid Build Coastguard Worker
463*9880d681SAndroid Build Coastguard Worker MachineInstr *foldMemoryOperandImpl(MachineFunction &MF, MachineInstr &MI,
464*9880d681SAndroid Build Coastguard Worker unsigned OpNum,
465*9880d681SAndroid Build Coastguard Worker ArrayRef<MachineOperand> MOs,
466*9880d681SAndroid Build Coastguard Worker MachineBasicBlock::iterator InsertPt,
467*9880d681SAndroid Build Coastguard Worker unsigned Size, unsigned Alignment,
468*9880d681SAndroid Build Coastguard Worker bool AllowCommute) const;
469*9880d681SAndroid Build Coastguard Worker
470*9880d681SAndroid Build Coastguard Worker void
471*9880d681SAndroid Build Coastguard Worker getUnconditionalBranch(MCInst &Branch,
472*9880d681SAndroid Build Coastguard Worker const MCSymbolRefExpr *BranchTarget) const override;
473*9880d681SAndroid Build Coastguard Worker
474*9880d681SAndroid Build Coastguard Worker void getTrap(MCInst &MI) const override;
475*9880d681SAndroid Build Coastguard Worker
476*9880d681SAndroid Build Coastguard Worker unsigned getJumpInstrTableEntryBound() const override;
477*9880d681SAndroid Build Coastguard Worker
478*9880d681SAndroid Build Coastguard Worker bool isHighLatencyDef(int opc) const override;
479*9880d681SAndroid Build Coastguard Worker
480*9880d681SAndroid Build Coastguard Worker bool hasHighOperandLatency(const TargetSchedModel &SchedModel,
481*9880d681SAndroid Build Coastguard Worker const MachineRegisterInfo *MRI,
482*9880d681SAndroid Build Coastguard Worker const MachineInstr &DefMI, unsigned DefIdx,
483*9880d681SAndroid Build Coastguard Worker const MachineInstr &UseMI,
484*9880d681SAndroid Build Coastguard Worker unsigned UseIdx) const override;
485*9880d681SAndroid Build Coastguard Worker
useMachineCombiner()486*9880d681SAndroid Build Coastguard Worker bool useMachineCombiner() const override {
487*9880d681SAndroid Build Coastguard Worker return true;
488*9880d681SAndroid Build Coastguard Worker }
489*9880d681SAndroid Build Coastguard Worker
490*9880d681SAndroid Build Coastguard Worker bool isAssociativeAndCommutative(const MachineInstr &Inst) const override;
491*9880d681SAndroid Build Coastguard Worker
492*9880d681SAndroid Build Coastguard Worker bool hasReassociableOperands(const MachineInstr &Inst,
493*9880d681SAndroid Build Coastguard Worker const MachineBasicBlock *MBB) const override;
494*9880d681SAndroid Build Coastguard Worker
495*9880d681SAndroid Build Coastguard Worker void setSpecialOperandAttr(MachineInstr &OldMI1, MachineInstr &OldMI2,
496*9880d681SAndroid Build Coastguard Worker MachineInstr &NewMI1,
497*9880d681SAndroid Build Coastguard Worker MachineInstr &NewMI2) const override;
498*9880d681SAndroid Build Coastguard Worker
499*9880d681SAndroid Build Coastguard Worker /// analyzeCompare - For a comparison instruction, return the source registers
500*9880d681SAndroid Build Coastguard Worker /// in SrcReg and SrcReg2 if having two register operands, and the value it
501*9880d681SAndroid Build Coastguard Worker /// compares against in CmpValue. Return true if the comparison instruction
502*9880d681SAndroid Build Coastguard Worker /// can be analyzed.
503*9880d681SAndroid Build Coastguard Worker bool analyzeCompare(const MachineInstr &MI, unsigned &SrcReg,
504*9880d681SAndroid Build Coastguard Worker unsigned &SrcReg2, int &CmpMask,
505*9880d681SAndroid Build Coastguard Worker int &CmpValue) const override;
506*9880d681SAndroid Build Coastguard Worker
507*9880d681SAndroid Build Coastguard Worker /// optimizeCompareInstr - Check if there exists an earlier instruction that
508*9880d681SAndroid Build Coastguard Worker /// operates on the same source operands and sets flags in the same way as
509*9880d681SAndroid Build Coastguard Worker /// Compare; remove Compare if possible.
510*9880d681SAndroid Build Coastguard Worker bool optimizeCompareInstr(MachineInstr &CmpInstr, unsigned SrcReg,
511*9880d681SAndroid Build Coastguard Worker unsigned SrcReg2, int CmpMask, int CmpValue,
512*9880d681SAndroid Build Coastguard Worker const MachineRegisterInfo *MRI) const override;
513*9880d681SAndroid Build Coastguard Worker
514*9880d681SAndroid Build Coastguard Worker /// optimizeLoadInstr - Try to remove the load by folding it to a register
515*9880d681SAndroid Build Coastguard Worker /// operand at the use. We fold the load instructions if and only if the
516*9880d681SAndroid Build Coastguard Worker /// def and use are in the same BB. We only look at one load and see
517*9880d681SAndroid Build Coastguard Worker /// whether it can be folded into MI. FoldAsLoadDefReg is the virtual register
518*9880d681SAndroid Build Coastguard Worker /// defined by the load we are trying to fold. DefMI returns the machine
519*9880d681SAndroid Build Coastguard Worker /// instruction that defines FoldAsLoadDefReg, and the function returns
520*9880d681SAndroid Build Coastguard Worker /// the machine instruction generated due to folding.
521*9880d681SAndroid Build Coastguard Worker MachineInstr *optimizeLoadInstr(MachineInstr &MI,
522*9880d681SAndroid Build Coastguard Worker const MachineRegisterInfo *MRI,
523*9880d681SAndroid Build Coastguard Worker unsigned &FoldAsLoadDefReg,
524*9880d681SAndroid Build Coastguard Worker MachineInstr *&DefMI) const override;
525*9880d681SAndroid Build Coastguard Worker
526*9880d681SAndroid Build Coastguard Worker std::pair<unsigned, unsigned>
527*9880d681SAndroid Build Coastguard Worker decomposeMachineOperandsTargetFlags(unsigned TF) const override;
528*9880d681SAndroid Build Coastguard Worker
529*9880d681SAndroid Build Coastguard Worker ArrayRef<std::pair<unsigned, const char *>>
530*9880d681SAndroid Build Coastguard Worker getSerializableDirectMachineOperandTargetFlags() const override;
531*9880d681SAndroid Build Coastguard Worker
532*9880d681SAndroid Build Coastguard Worker protected:
533*9880d681SAndroid Build Coastguard Worker /// Commutes the operands in the given instruction by changing the operands
534*9880d681SAndroid Build Coastguard Worker /// order and/or changing the instruction's opcode and/or the immediate value
535*9880d681SAndroid Build Coastguard Worker /// operand.
536*9880d681SAndroid Build Coastguard Worker ///
537*9880d681SAndroid Build Coastguard Worker /// The arguments 'CommuteOpIdx1' and 'CommuteOpIdx2' specify the operands
538*9880d681SAndroid Build Coastguard Worker /// to be commuted.
539*9880d681SAndroid Build Coastguard Worker ///
540*9880d681SAndroid Build Coastguard Worker /// Do not call this method for a non-commutable instruction or
541*9880d681SAndroid Build Coastguard Worker /// non-commutable operands.
542*9880d681SAndroid Build Coastguard Worker /// Even though the instruction is commutable, the method may still
543*9880d681SAndroid Build Coastguard Worker /// fail to commute the operands, null pointer is returned in such cases.
544*9880d681SAndroid Build Coastguard Worker MachineInstr *commuteInstructionImpl(MachineInstr &MI, bool NewMI,
545*9880d681SAndroid Build Coastguard Worker unsigned CommuteOpIdx1,
546*9880d681SAndroid Build Coastguard Worker unsigned CommuteOpIdx2) const override;
547*9880d681SAndroid Build Coastguard Worker
548*9880d681SAndroid Build Coastguard Worker private:
549*9880d681SAndroid Build Coastguard Worker MachineInstr *convertToThreeAddressWithLEA(unsigned MIOpc,
550*9880d681SAndroid Build Coastguard Worker MachineFunction::iterator &MFI,
551*9880d681SAndroid Build Coastguard Worker MachineInstr &MI,
552*9880d681SAndroid Build Coastguard Worker LiveVariables *LV) const;
553*9880d681SAndroid Build Coastguard Worker
554*9880d681SAndroid Build Coastguard Worker /// Handles memory folding for special case instructions, for instance those
555*9880d681SAndroid Build Coastguard Worker /// requiring custom manipulation of the address.
556*9880d681SAndroid Build Coastguard Worker MachineInstr *foldMemoryOperandCustom(MachineFunction &MF, MachineInstr &MI,
557*9880d681SAndroid Build Coastguard Worker unsigned OpNum,
558*9880d681SAndroid Build Coastguard Worker ArrayRef<MachineOperand> MOs,
559*9880d681SAndroid Build Coastguard Worker MachineBasicBlock::iterator InsertPt,
560*9880d681SAndroid Build Coastguard Worker unsigned Size, unsigned Align) const;
561*9880d681SAndroid Build Coastguard Worker
562*9880d681SAndroid Build Coastguard Worker /// isFrameOperand - Return true and the FrameIndex if the specified
563*9880d681SAndroid Build Coastguard Worker /// operand and follow operands form a reference to the stack frame.
564*9880d681SAndroid Build Coastguard Worker bool isFrameOperand(const MachineInstr &MI, unsigned int Op,
565*9880d681SAndroid Build Coastguard Worker int &FrameIndex) const;
566*9880d681SAndroid Build Coastguard Worker
567*9880d681SAndroid Build Coastguard Worker /// Expand the MOVImmSExti8 pseudo-instructions.
568*9880d681SAndroid Build Coastguard Worker bool ExpandMOVImmSExti8(MachineInstrBuilder &MIB) const;
569*9880d681SAndroid Build Coastguard Worker };
570*9880d681SAndroid Build Coastguard Worker
571*9880d681SAndroid Build Coastguard Worker } // End llvm namespace
572*9880d681SAndroid Build Coastguard Worker
573*9880d681SAndroid Build Coastguard Worker #endif
574