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